Commit 1222fd97 authored by Jacob Durrant's avatar Jacob Durrant

run_with_mol_list() preserves props of input mols.

parent 2b7d29e0
......@@ -86,13 +86,20 @@ print("Output of first test saved to output.smi...")
# Using the dimorphite_dl.run_with_mol_list() function, you can also pass a
# list of RDKit Mol objects. The first argument is always the list.
mols = [Chem.MolFromSmiles(s) for s in ["C[C@](F)(Br)CC(O)=O", "CCCCCN"]]
smiles = ["C[C@](F)(Br)CC(O)=O", "CCCCCN"]
mols = [Chem.MolFromSmiles(s) for s in smiles]
for i, mol in enumerate(mols):
mol.SetProp("msg","Orig SMILES: " + smiles[i])
protonated_mols = dimorphite_dl.run_with_mol_list(
print([Chem.MolToSmiles(m) for m in protonated_mols])
# Note that properties are preserved.
print([m.GetProp("msg") for m in protonated_mols])
......@@ -1022,19 +1022,24 @@ def run_with_mol_list(mol_lst, **kwargs):
# Having reviewed the code, it will be very difficult to rewrite it so
# that a list of Mol objects can be used directly. Intead, convert this
# list of mols to smiles and pass that. Not memory efficient, but it will
# work.
protonated_smiles = []
# list of mols to smiles and pass that. Not efficient, but it will work.
protonated_smiles_and_props = []
for m in mol_lst:
props = m.GetPropsAsDict()
smiles = Chem.MolToSmiles(m, isomericSmiles=True)
kwargs["smiles"] = smiles
[s.split("\t")[0] for s in main(kwargs)]
[(s.split("\t")[0], props) for s in main(kwargs)]
# Now convert the list of protonated smiles strings back to RDKit Mol
# objects.
mols = [Chem.MolFromSmiles(s) for s in protonated_smiles]
# objects. Also, add back in the properties from the original mol objects.
mols = []
for s, props in protonated_smiles_and_props:
m = Chem.MolFromSmiles(s)
for prop, val in props.items():
m.SetProp(prop, val)
return mols
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment