Skip to content
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

Test and fix Molecule.remove_van_der_waals_bonds #1799

Merged
merged 4 commits into from
Nov 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rmgpy/molecule/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -1130,7 +1130,7 @@ def remove_van_der_waals_bonds(self):
"""
Remove all bonds that are definitely only van der Waals bonds.
"""
cython.declare(atom=GroupAtom, bond=GroupBond)
cython.declare(bond=GroupBond)
for bond in self.get_all_edges():
if bond.is_van_der_waals(wildcards=False):
self.remove_bond(bond)
Expand Down
11 changes: 5 additions & 6 deletions rmgpy/molecule/molecule.py
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ def is_van_der_waals(self):
Return ``True`` if the bond represents a van der Waals bond or
``False`` if not.
"""
return self.is_order(0) or self.order == 'vdW' # todo: remove 'vdW'
return self.is_order(0)

def is_order(self, other_order):
"""
Expand Down Expand Up @@ -1092,11 +1092,10 @@ def remove_van_der_waals_bonds(self):
"""
Remove all van der Waals bonds.
"""
cython.declare(atom=Atom, bond=Bond)
for atom in self.atoms:
for bond in atom.edges.values():
if bond.is_van_der_waals():
self.remove_bond(bond)
cython.declare(bond=Bond)
for bond in self.get_all_edges():
if bond.is_van_der_waals():
self.remove_bond(bond)

def sort_atoms(self):
"""
Expand Down
12 changes: 12 additions & 0 deletions rmgpy/molecule/moleculeTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2687,6 +2687,18 @@ def test_count_aromatic_rings(self):

self.assertEqual(result, [2, 1, 0])

def test_remove_van_der_waals_bonds(self):
"""Test we can remove a van-der-Waals bond"""
adjlist = """
1 X u0 p0 c0 {2,vdW}
2 H u0 p0 c0 {1,vdW}, {3,S}
3 H u0 p0 c0 {2,S}
"""
mol = Molecule().from_adjacency_list(adjlist)
self.assertEqual(len(mol.get_all_edges()), 2)
mol.remove_van_der_waals_bonds()
self.assertEqual(len(mol.get_all_edges()), 1)

################################################################################

if __name__ == '__main__':
Expand Down