-
Notifications
You must be signed in to change notification settings - Fork 104
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
Add explicit_hydrogen
parameter
#741
base: interfaces
Are you sure you want to change the base?
Conversation
CodSpeed Performance ReportMerging #741 will not alter performanceComparing Summary
|
mol = EditableMol(Mol()) | ||
|
||
has_charge_annot = "charge" in atoms.get_annotation_categories() | ||
for i in range(atoms.array_length()): | ||
rdkit_atom = Atom(atoms.element[i].capitalize()) | ||
if has_charge_annot: | ||
rdkit_atom.SetFormalCharge(atoms.charge[i].item()) | ||
if explicit_hydrogen: | ||
rdkit_atom.SetNoImplicit(True) |
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.
In the base case where explicity_hydrogen=True
, what would this mean if I just call to_mol
for a typical crystal structure that won't have any hydrogens resolved? Will RDKit infer charges / valences in that case? If so this might lead to broken molecules -- if that were the case, should we check that if explicit hydrogen is true there have to be hydrogens in the structure? (I could see this being sth users will try -- at least I would have tried it :D )
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.
Charges would also not be inferred automatically before this PR. But I am not sure what this means for valence: As the bond types are also explicitly set I guess RDKit assumes a radical, if explicit_hydrogen=True
, but hydrogen atoms are actually missing. Probably, I should test this.
Having a check there sounds like a good idea, especially as I would agree that this could be a common mistake. However, I also think strictly checking for the simple presence of hydrogen atoms might not be sensible enough, as there are valid molecules without hydrogen atoms, although they appear rarely. What do you think about raising a warning as a 'reminder' to the user to check the input?
I checked the different behaviors when an import biotite.interface.rdkit as rdkit_interface
import biotite.structure.info as info
import rdkit.Chem.AllChem as Chem
import rdkit.Chem.Draw as Draw
atoms = info.residue("C")
atoms = atoms[atoms.element != "H"]
mol = rdkit_interface.to_mol(atoms, explicit_hydrogen=True)
Chem.Compute2DCoords(mol)
Draw.MolToFile(mol, "explicit.png")
mol = rdkit_interface.to_mol(atoms, explicit_hydrogen=False)
Chem.Compute2DCoords(mol)
Draw.MolToFile(mol, "non_explicit.png")
So |
I added a warning in case the structure contains no hydrogen atoms. @Croydon-Brixton Could you have a look again? |
This parameter in
interface.rdkit.to_mol()
defines whether hydrogen should be explicitly or implicitly included in the createdMol