Skip to content

Commit

Permalink
Copy input structure and add comments on rmin
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwthompson committed Oct 9, 2019
1 parent 0f6dd2c commit 76955cd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
3 changes: 2 additions & 1 deletion foyer/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
11 changes: 9 additions & 2 deletions foyer/utils/nbfixes.py
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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
Expand All @@ -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

0 comments on commit 76955cd

Please sign in to comment.