forlilab / Meeko

Interface for AutoDock, molecule parameterization
https://meeko.readthedocs.io/
GNU Lesser General Public License v2.1
204 stars 49 forks source link

Report (raise warning or error for) lone hydrogens from bad input PDB #231

Open rwxayheee opened 1 week ago

rwxayheee commented 1 week ago

When input PDB has lone hydrogens (from a strained structure), atom.GetNeighbors() becomes an empty tuple and an error will occur from here: https://github.com/forlilab/Meeko/blob/c938ebdc347bda69f0247dbd3c7566e8e27d1dea/meeko/polymer.py#L2519-L2524

To raise an error:

                if element == "H": 
                    if atom.GetNeighbors(): 
                        nei_idx = atom.GetNeighbors()[0].GetIdx()
                        if nei_idx in mapping_inv: 
                            result[element]["excess"].append(mapping_inv[nei_idx])
                        else:
                            result[element]["excess"].append(-1)
                    else: # lone hydrogen
                        raise ValueError(f"Lone hydrogen {atom.GetMonomerInfo().GetName()} found from input structure")

If we allow the lone hydrogens to pass, the bad residue with lone hydrogens will be deleted silently (no template match results printed) from the result structure.

But alternatively, lone hydrogens can be detected at an earlier point than template matching.

diogomart commented 1 week ago

Wow, this was a sneaky one!