Skip to content

Commit

Permalink
HOTFIX: Improve Sybyl atom types, add cyano and CO2 test
Browse files Browse the repository at this point in the history
  • Loading branch information
bertrand-caron committed Mar 7, 2018
1 parent 17b1186 commit 3667651
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 5 deletions.
33 changes: 28 additions & 5 deletions helpers/molecule.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ def __init__(
else:
raise Exception('Invalide type(atoms): {0}'.format(type(atoms)))

self.atoms = validated_atoms_dict(atoms_dict)
try:
self.atoms = validated_atoms_dict(atoms_dict)
except AssertionError:
raise AssertionError('In: {0}'.format(atoms_dict))

self.bonds = set(map(frozenset, bonds))
validate_bond_dict(self.atoms, self.bonds)
self.name = name if name is not None else md5((str(sorted(self.atoms.values())) + str(sorted(bonds))).encode()).hexdigest()
Expand Down Expand Up @@ -384,9 +388,22 @@ def print_to_io(*args):
print(*args, file=io)

def sibyl_atom_type(atom: Atom) -> str:
if atom.element in {'C', 'N', 'O', 'S', 'P'}:
if atom.element is None:
return 'Du'
elif atom.element == 'D':
return 'H'
elif atom.element == 'P':
return 'P.3'
elif atom.element.upper() in {'RU', 'CO'}:
return atom.element.title() + '.oh'
elif atom.element in {'C', 'O', 'N', 'S'}:
if atom.element == 'C':
valence = atom.valence - 1
if atom.valence >= 4:
valence = 3
elif atom.valence == 1:
valence = 1
else:
valence = atom.valence - 1
elif atom.element == 'O':
valence = atom.valence + 1
elif atom.element == 'S':
Expand All @@ -400,12 +417,18 @@ def sibyl_atom_type(atom: Atom) -> str:
valence = 2
else:
valence = atom.valence
assert valence > 0, (atom, valence)
return '{element}.{valence}'.format(
element=atom.element,
element=atom.element.title(),
valence=valence,
)
elif atom.element.upper() in {'TI', 'CR'}:
if atom.valence <= 4:
return atom.element.title() + '.th'
else:
return atom.element.title() + '.oh'
else:
return atom.element
return atom.element.title()

print_to_io('@<TRIPOS>MOLECULE')
print_to_io(self.name)
Expand Down
9 changes: 9 additions & 0 deletions pdbs/cyano.pdb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
HEADER UNCLASSIFIED 04-Mar-18
TITLE ALL ATOM STRUCTURE FOR MOLECULE UNK
AUTHOR GROMOS AUTOMATIC TOPOLOGY BUILDER REVISION 2018-01-17 10:59:17
AUTHOR 2 http://compbio.biosci.uq.edu.au/atb
HETATM 1 C 4GGB 0 0.637 0.000 0.000 1.00 0.00 C
HETATM 2 N 4GGB 0 -0.546 0.000 0.000 1.00 0.00 N
CONECT 1 2
CONECT 2 1
END
43 changes: 43 additions & 0 deletions test_electron_assignment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from sys import stderr
import unittest

from fragment_capping.helpers.types_helpers import Atom
from fragment_capping.helpers.molecule import Molecule, molecule_from_pdb_str

class Test_Capping(unittest.TestCase):
def test_carbon_dioxide(self) -> None:
with open('pdbs/carbon_dioxide.pdb') as fh:
input_molecule = molecule_from_pdb_str(
fh.read(),
name='carbon_dioxide',
)

input_molecule.assign_bond_orders_and_charges_with_ILP(
enforce_octet_rule=True,
)

input_molecule.write_graph(
'',
output_size=(400, 400),
graph_kwargs={'include_atom_index': True},
)

def test_cyano(self) -> None:
with open('pdbs/cyano.pdb') as fh:
input_molecule = molecule_from_pdb_str(
fh.read(),
name='cyano',
)

input_molecule.assign_bond_orders_and_charges_with_ILP(
enforce_octet_rule=True,
)

input_molecule.write_graph(
'',
output_size=(400, 400),
graph_kwargs={'include_atom_index': True},
)

if __name__ == '__main__':
unittest.main(warnings='ignore', verbosity=2)

0 comments on commit 3667651

Please sign in to comment.