Commit 317b1c98 authored by Lukas Pravda's avatar Lukas Pravda
Browse files

fix rdkit some components that come out of depiction process

parent bfbe856a
......@@ -33,6 +33,7 @@ from pdbeccdutils.utils import config
from rdkit import Chem, Geometry
from rdkit.Chem import AllChem, rdCoordGen
from scipy.spatial import KDTree
from pdbeccdutils.helpers.rdkit_fixtures import fix_conformer
class DepictionManager:
......@@ -108,7 +109,11 @@ class DepictionManager:
results.sort(key=lambda l: (l.score, l.source))
if results:
return results[0]
to_return = results[0]
fix_conformer(to_return.mol.GetConformer(0))
return to_return
return DepictionResult(source=DepictionSource.Failed, template_name='', mol=None, score=1000)
......
#!/usr/bin/env python
# software from PDBe: Protein Data Bank in Europe; https://pdbe.org
#
# Copyright 2018 EMBL - European Bioinformatics Institute
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on
# an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
import numpy as np
import rdkit
def fix_conformer(conformer):
"""In place fixing of rdkit conformer.
In certain cases the resulting conformer (mainly from depiction process)
can contain not valid atom coordinatesp [NaN, NaN, NaN]. This
results in errors in downstream processes so that it is easier
to fix it when the problem occurs
Args:
conformer (rdkit.Chem.rdchem.Conformer): RDKit conformer
"""
positions = conformer.GetPositions()
for index, pos in enumerate(positions):
if all(np.isnan(pos)):
new_pos = rdkit.Chem.rdGeometry.Point3D(0, 0, 0)
conformer.SetAtomPosition(index, new_pos)
import rdkit
import numpy as np
from pdbeccdutils.helpers.rdkit_fixtures import fix_conformer
class TestRDKitFixtures:
@staticmethod
def test_conformer_is_broken_ion():
mol = rdkit.Chem.RWMol()
atom = rdkit.Chem.Atom('H')
mol.AddAtom(atom)
conformer = rdkit.Chem.Conformer(1)
atom_position = rdkit.Chem.rdGeometry.Point3D(np.NaN, np.NaN, np.NaN)
conformer.SetAtomPosition(0, atom_position)
mol.AddConformer(conformer, assignId=True)
m = mol.GetMol()
c = m.GetConformer(0)
fix_conformer(c)
assert c.GetAtomPosition(0).x == 0.0
assert c.GetAtomPosition(0).y == 0.0
assert c.GetAtomPosition(0).z == 0.0
@staticmethod
def test_conformer_has_broken_atom():
mol = rdkit.Chem.RWMol()
o = rdkit.Chem.Atom('O')
h = rdkit.Chem.Atom('H')
mol.AddAtom(o)
mol.AddAtom(h)
mol.AddBond(0, 1, rdkit.Chem.rdchem.BondType(1))
conformer = rdkit.Chem.Conformer(1)
o_position = rdkit.Chem.rdGeometry.Point3D(1, 2, 3)
h_position = rdkit.Chem.rdGeometry.Point3D(np.NaN, np.NaN, np.NaN)
conformer.SetAtomPosition(0, o_position)
conformer.SetAtomPosition(1, h_position)
mol.AddConformer(conformer, assignId=True)
m = mol.GetMol()
c = m.GetConformer(0)
fix_conformer(c)
assert c.GetAtomPosition(0).x != 0.0
assert c.GetAtomPosition(0).y != 0.0
assert c.GetAtomPosition(0).z != 0.0
assert c.GetAtomPosition(1).x == 0.0
assert c.GetAtomPosition(1).y == 0.0
assert c.GetAtomPosition(1).z == 0.0
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