-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Read Partial Charges from mol2 and SDF #258
Changes from 18 commits
726ae0b
63b0fff
bedbdb7
2d9492e
31c0d4b
f6699e7
e0f7c53
6741616
2bfa6a2
c7f0fb4
7f1380f
0568941
772c8d9
3c4422c
5995773
d0fd018
86b0eb2
36c3af4
81151af
a2a7984
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,6 @@ | |
|
||
|
||
def cmd_lineparser(): | ||
backend = "rdkit" | ||
|
||
conf_parser = argparse.ArgumentParser( | ||
description=__doc__, | ||
|
@@ -52,7 +51,11 @@ def cmd_lineparser(): | |
if confargs.config_file is not None: | ||
with open(confargs.config_file) as f: | ||
c = json.load(f) | ||
config.update(c) | ||
if any(key not in config for key in c): | ||
print(f"Error: Got unsupported keyword ({key}) for MoleculePreparation from the config file ({confargs.config_file}). ", | ||
file=sys.stderr,) | ||
sys.exit(2) | ||
config.update(c) | ||
|
||
parser = ( | ||
argparse.ArgumentParser() | ||
|
@@ -78,6 +81,10 @@ def cmd_lineparser(): | |
"--name_from_prop", | ||
help="set molecule name from RDKit/SDF property", | ||
) | ||
io_group.add_argument( | ||
"--charge_atom_prop", | ||
help="set atom partial charges from an RDKit atom property based on the input file. The default is 'PartialCharge' for SDF and '_TriposPartialCharge' for MOL2 unless overriden by a user defined property name. ", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would move this next to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok |
||
) | ||
io_group.add_argument( | ||
"-o", | ||
"--out", | ||
|
@@ -214,7 +221,7 @@ def cmd_lineparser(): | |
) | ||
config_group.add_argument( | ||
"--charge_model", | ||
choices=("gasteiger", "espaloma", "zero"), | ||
choices=("gasteiger", "espaloma", "zero", "read"), | ||
help="default is 'gasteiger', 'zero' sets all zeros", | ||
default="gasteiger", | ||
) | ||
|
@@ -293,13 +300,10 @@ def cmd_lineparser(): | |
sys.exit(2) | ||
args.reactive_smarts_idx -= 1 # convert from 1- to 0-index | ||
|
||
# command line arguments override config | ||
for key in config: | ||
if key in args.__dict__: | ||
for key in args.__dict__: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i would like the "command line arguments override config" comment back :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is unnecessary, I would revert that |
||
if key in config: | ||
config[key] = args.__dict__[key] | ||
|
||
config["load_atom_params"] = args.load_atom_params | ||
|
||
if args.add_atom_types_json is not None: | ||
additional_ats = [] | ||
for at in args.add_atom_types_json: | ||
|
@@ -308,7 +312,7 @@ def cmd_lineparser(): | |
additional_ats.append(at) | ||
elif type(at) == list: | ||
additional_ats.extend(at) | ||
config["add_atom_types"] = additional_ats | ||
config["add_atom_types"] += additional_ats | ||
|
||
if args.multimol_output_dir is not None or args.multimol_prefix is not None: | ||
if args.output_pdbqt_filename is not None: | ||
|
@@ -329,7 +333,8 @@ def cmd_lineparser(): | |
num_required_covalent_args += int(args.tether_smarts is not None) | ||
if num_required_covalent_args not in [0, 3]: | ||
print( | ||
"Error: --receptor, --rec_residue, and --tether_smarts are all required for covalent docking." | ||
"Error: --receptor, --rec_residue, and --tether_smarts are all required for covalent docking.", | ||
file=sys.stderr, | ||
) | ||
sys.exit(2) | ||
is_covalent = num_required_covalent_args == 3 | ||
|
@@ -364,7 +369,7 @@ def cmd_lineparser(): | |
indices[0] = indices[0] - 1 # convert from 1- to 0-index | ||
indices[1] = indices[1] - 1 | ||
|
||
return args, config, backend, is_covalent | ||
return args, config, is_covalent | ||
|
||
|
||
class Output: | ||
|
@@ -495,27 +500,27 @@ def get_suffixes(molsetups): | |
return tuple("mk%d" % (i + 1) for i in range(len(molsetups))) | ||
|
||
def main(): | ||
args, config, backend, is_covalent = cmd_lineparser() | ||
args, config, is_covalent = cmd_lineparser() | ||
input_molecule_filename = args.input_molecule_filename | ||
|
||
# read input | ||
input_fname, ext = os.path.splitext(input_molecule_filename) | ||
ext = ext[1:].lower() | ||
if backend == "rdkit": | ||
parsers = { | ||
"sdf": Chem.SDMolSupplier, | ||
"mol2": rdkitutils.Mol2MolSupplier, | ||
"mol": Chem.SDMolSupplier, | ||
} | ||
if not ext in parsers: | ||
print( | ||
"*ERROR* Format [%s] not in supported formats [%s]" | ||
% (ext, "/".join(list(parsers.keys()))) | ||
) | ||
sys.exit(1) | ||
mol_supplier = parsers[ext]( | ||
input_molecule_filename, removeHs=False | ||
) # input must have explicit H | ||
|
||
parsers = { | ||
"sdf": Chem.SDMolSupplier, | ||
"mol2": rdkitutils.Mol2MolSupplier, | ||
"mol": Chem.SDMolSupplier, | ||
} | ||
if not ext in parsers: | ||
print( | ||
"Error: Format [%s] not in supported formats [%s]" | ||
% (ext, "/".join(list(parsers.keys()))) | ||
) | ||
sys.exit(1) | ||
mol_supplier = parsers[ext]( | ||
input_molecule_filename, removeHs=False | ||
) # input must have explicit H | ||
|
||
# configure output writer | ||
if args.output_pdbqt_filename is None: | ||
|
@@ -543,13 +548,24 @@ def main(): | |
rec_prody_mol = prody_parser(rec_filename) | ||
covalent_builder = CovalentBuilder(rec_prody_mol, args.rec_residue) | ||
|
||
input_mol_counter = 0 | ||
input_mol_skipped = 0 | ||
input_mol_with_failure = ( | ||
0 # if reactive or covalent, each mol can yield multiple PDBQT | ||
) | ||
nr_failures = 0 | ||
is_after_first = False | ||
|
||
if config["charge_atom_prop"] is not None: | ||
if config["charge_model"] != "read": | ||
print(f'Error: --charge_atom_prop must be used with --charge_model "read", but the current charge_model is "{config["charge_model"]}". ', | ||
file=sys.stderr,) | ||
sys.exit(1) | ||
elif config["charge_model"] == "read": | ||
if ext=="sdf": | ||
config["charge_atom_prop"] = "PartialCharge" | ||
elif ext=="mol2": | ||
config["charge_atom_prop"] = "_TriposPartialCharge" | ||
|
||
preparator = MoleculePreparation.from_config(config) | ||
for mol in mol_supplier: | ||
if is_after_first and output.is_multimol == False: | ||
|
@@ -561,8 +577,7 @@ def main(): | |
break | ||
|
||
# check that molecule was successfully loaded | ||
if backend == "rdkit": | ||
is_valid = mol is not None | ||
is_valid = mol is not None | ||
input_mol_skipped += int(is_valid == False) | ||
if not is_valid: | ||
continue | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
key is not defined in the f string (that's why we iterate over the keys in MoleculePreparation.from_config)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'm not sure we need to test the keys here,
MoleculePreparation.from_config
does a checkThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right on both. I made the unnecessary changes but I forgot to revert.