Skip to content

Commit

Permalink
Unit tests for bias.py and umbrella.py
Browse files Browse the repository at this point in the history
Tests the harmonic bias with image and grad functions. Tests umbrella sampling with n windows. Added warning if >1 configurations are identical in US
  • Loading branch information
tristan-j-wood committed Dec 2, 2021
1 parent 0b3d2e1 commit 1bb4e0e
Show file tree
Hide file tree
Showing 8 changed files with 8,083 additions and 8 deletions.
7 changes: 5 additions & 2 deletions mltrain/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from mltrain.system import System
from mltrain.box import Box
from mltrain.bias import Bias
from mltrain.umbrella import UmbrellaSampling
from mltrain import md
from mltrain import potentials
from mltrain.training import selection
Expand All @@ -17,7 +18,9 @@
'Molecule',
'System',
'Box',
'Bias',
'UmbrellaSampling',
'md',
'selection',
'potentials',
'Bias']
'potentials'
]
8 changes: 4 additions & 4 deletions mltrain/bias.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def __init__(self,
{to_add, to_subtract, to_average}: (list) Indices of the atoms
which are combined in some way to define the reaction rxn_coord
"""
self.s = reference
self.ref = reference
self.kappa = kappa

if len(kwargs) != 1:
Expand Down Expand Up @@ -90,14 +90,14 @@ def __init__(self,
def __call__(self, atom_pair_list, atoms):
"""Value of the bias for set of atom pairs in atoms"""

return 0.5 * self.kappa * (self.func(atom_pair_list, atoms) - self.s)**2
return 0.5 * self.kappa * (self.func(atom_pair_list, atoms) - self.ref)**2

def grad(self, atom_pair_list, atoms):
"""Gradient of the biasing potential a set of atom pairs in atoms"""

return (self.kappa
* self.func.grad(atom_pair_list, atoms)
* (self.func(atom_pair_list, atoms) - self.s))
* (self.func(atom_pair_list, atoms) - self.ref))

def adjust_potential_energy(self, atoms):
"""Adjust the energy of a set of atoms using the bias function"""
Expand Down Expand Up @@ -145,7 +145,7 @@ def grad(self, atom_pair_list, atoms):
r_i,m: i (= x, y or z) position of atom in pair m, m'
||r_m||: Euclidean distance between atoms in pair m, m'
"""

derivative = np.zeros(shape=(len(atoms), 3))

num_pairs = len(atom_pair_list)
Expand Down
1 change: 1 addition & 0 deletions mltrain/md.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def run_mlp_md(configuration: 'mltrain.Configuration',

ase_atoms = configuration.ase_atoms
ase_atoms.set_calculator(mlp.ase_calculator)

if bias is not None:
ase_atoms.set_constraint(bias)

Expand Down
8 changes: 8 additions & 0 deletions mltrain/tests/init.xyz
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
6
Lattice="50.000000 0.000000 0.000000 0.000000 50.000000 0.000000 0.000000 0.000000 50.000000" Properties=species:S:1:pos:R:3
C -0.21149 -0.00789 0.00649
Cl 1.61172 0.05744 -0.01468
H -0.55360 -0.55147 -0.87761
H -0.53377 -0.52342 0.91466
H -0.59944 1.01358 -0.00511
Cl -3.31830 -0.12221 0.04350
Loading

0 comments on commit 1bb4e0e

Please sign in to comment.