From 76955cdc61af9b8b650667903c760772ad4d8aab Mon Sep 17 00:00:00 2001 From: "Matthew W. Thompson" Date: Wed, 9 Oct 2019 13:30:58 -0500 Subject: [PATCH] Copy input structure and add comments on rmin --- foyer/tests/test_utils.py | 3 ++- foyer/utils/nbfixes.py | 11 +++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/foyer/tests/test_utils.py b/foyer/tests/test_utils.py index b54be093..95b402ad 100644 --- a/foyer/tests/test_utils.py +++ b/foyer/tests/test_utils.py @@ -19,9 +19,10 @@ def test_apply_nbfix(): epsilon=50.0, ) - assert ethane.has_NBFIX() + assert not ethane.has_NBFIX() assert ethane_tweaked.has_NBFIX() + # 0.44898.... is rmin, which parmed uses internally in place of sigma for atom in ethane_tweaked: if atom.atom_type.name == 'opls_135': assert np.allclose( diff --git a/foyer/utils/nbfixes.py b/foyer/utils/nbfixes.py index dbf42509..5118a25c 100644 --- a/foyer/utils/nbfixes.py +++ b/foyer/utils/nbfixes.py @@ -1,3 +1,6 @@ +from copy import deepcopy + + def apply_nbfix(struct, atom_type1, atom_type2, sigma, epsilon): """Apply a single nbfix to a particular interaction. @@ -19,7 +22,9 @@ def apply_nbfix(struct, atom_type1, atom_type2, sigma, epsilon): struct : parmed.structure.Structure The input structure with the nbfix applied. """ - atom_types = list({a.atom_type for a in struct.atoms}) + struct_copy = deepcopy(struct) + + atom_types = list({a.atom_type for a in struct_copy.atoms}) for atom_type in sorted(atom_types, key=lambda a: a.name): if atom_type.name == atom_type1: a1 = atom_type @@ -31,8 +36,10 @@ def apply_nbfix(struct, atom_type1, atom_type2, sigma, epsilon): except: raise ValueError('Atom types {} and {} not found ' 'in structure.'.format(atom_type1, atom_type2)) + + # Calculate rmin from sigma because parmed uses it internally rmin = sigma * 2 ** (1 / 6) a1.add_nbfix(a2.name, rmin, epsilon) a2.add_nbfix(a1.name, rmin, epsilon) - return struct + return struct_copy