def ufed_model( temp=300 * unit.kelvin, mass=50 * unit.dalton * (unit.nanometer / unit.radians)**2, Ks=1000 * unit.kilojoules_per_mole / unit.radians**2, Ts=1500 * unit.kelvin, limit=180 * unit.degrees, sigma=18 * unit.degrees, height=0.0, frequency=10, enforce_gridless=False, ): model = ufedmm.AlanineDipeptideModel() s_phi = ufedmm.DynamicalVariable('s_phi', -limit, limit, mass, Ts, model.phi, Ks, sigma=sigma) s_psi = ufedmm.DynamicalVariable('s_psi', -limit, limit, mass, Ts, model.psi, Ks, sigma=sigma) return model, ufedmm.UnifiedFreeEnergyDynamics( [s_phi, s_psi], temp, height, frequency, enforce_gridless=enforce_gridless)
def test_radius_of_gyration(): model = ufedmm.AlanineDipeptideModel() R = model.positions._value N = len(R) Rmean = sum(R, openmm.Vec3(0, 0, 0)) / N RgSqVal = 0.0 for r in R: dr = r - Rmean RgSqVal += dr.x**2 + dr.y**2 + dr.z**2 RgSqVal /= N RgSq = cvlib.SquareRadiusOfGyration(range(model.topology._numAtoms)) RgSq.setForceGroup(1) model.system.addForce(RgSq) Rg = cvlib.RadiusOfGyration(range(model.topology._numAtoms)) Rg.setForceGroup(2) model.system.addForce(Rg) integrator = openmm.CustomIntegrator(0) platform = openmm.Platform.getPlatformByName('Reference') context = openmm.Context(model.system, integrator, platform) context.setPositions(model.positions) RgSq = context.getState(getEnergy=True, groups={1}).getPotentialEnergy()._value assert RgSq == pytest.approx(RgSqVal) Rg = context.getState(getEnergy=True, groups={2}).getPotentialEnergy()._value assert Rg * Rg == pytest.approx(RgSqVal)
def test_inner_exceptions(): model = ufedmm.AlanineDipeptideModel() nbforce = next( filter(lambda f: isinstance(f, openmm.NonbondedForce), model.system.getForces())) rs = 0.2 rc = 0.4 ufedmm.add_inner_nonbonded_force(model.system, rs, rc, 1) model.system.getForce(model.system.getNumForces() - 1).setForceGroup(3) platform = openmm.Platform.getPlatformByName('Reference') context = openmm.Context(model.system, openmm.CustomIntegrator(0), platform) context.setPositions(model.positions) forces1 = _standardized( context.getState(getForces=True, groups={3}).getForces()) forces2 = [0 * f for f in forces1] ONE_4PI_EPS0 = 138.93545764438198 for index in range(nbforce.getNumExceptions()): i, j, chargeprod, sigma, epsilon = map( _standardized, nbforce.getExceptionParameters(index)) rij = _standardized(model.positions[i] - model.positions[j]) r = np.linalg.norm(rij) z = (r - rs) / (rc - rs) F = S(z) * (24 * epsilon * (2 * (sigma / r)**12 - (sigma / r)**6) / r + ONE_4PI_EPS0 * chargeprod / r**2) * rij / r forces2[i] += F forces2[j] -= F for f1, f2 in zip(forces1, forces2): for i in range(3): assert f1[i] == pytest.approx(f2[i])
def ufed_model(): model = ufedmm.AlanineDipeptideModel() mass = 50*unit.dalton*(unit.nanometer/unit.radians)**2 Ks = 1000*unit.kilojoules_per_mole/unit.radians**2 Ts = 1500*unit.kelvin limit = 180*unit.degrees sigma = 18*unit.degrees height = 2.0*unit.kilojoules_per_mole frequency = 10 phi = ufedmm.CollectiveVariable('phi', model.phi, -limit, limit, mass, Ks, Ts, sigma) psi = ufedmm.CollectiveVariable('psi', model.psi, -limit, limit, mass, Ks, Ts, sigma) return model, ufedmm.UnifiedFreeEnergyDynamics([phi, psi], 300*unit.kelvin, height, frequency)
def test_in_out_lennard_jones_force(): model = ufedmm.AlanineDipeptideModel(water='tip3p') before = potential_energy(model.system, model.positions, openmm.NonbondedForce) solute_atoms = [ atom.index for atom in model.topology.atoms() if atom.residue.name != 'HOH' ] nbforce = next( filter(lambda f: isinstance(f, openmm.NonbondedForce), model.system.getForces())) in_out_LJ = cvlib.InOutLennardJonesForce(solute_atoms, nbforce) model.system.addForce(in_out_LJ) after = potential_energy( model.system, model.positions, (openmm.NonbondedForce, openmm.CustomNonbondedForce)) assert after / after.unit == pytest.approx(before / before.unit, 1E-2)
choices=waters, default=None) parser.add_argument('--ff', dest='ff', help='the pepdide force field', default='amber03') parser.add_argument('--seed', dest='seed', help='the RNG seed', default=None) parser.add_argument('--platform', dest='platform', help='the computation platform', default='Reference') args = parser.parse_args() seed = random.SystemRandom().randint(0, 2** 31) if args.seed is None else args.seed model = ufedmm.AlanineDipeptideModel(force_field=args.ff, water=args.water) temp = 300 * unit.kelvin gamma = 10 / unit.picoseconds dt = 2 * unit.femtoseconds nsteps = 1000000 mass = 30 * unit.dalton * (unit.nanometer / unit.radians)**2 Ks = 1000 * unit.kilojoules_per_mole / unit.radians**2 Ts = 1500 * unit.kelvin limit = 180 * unit.degrees sigma = 18 * unit.degrees height = 2.0 * unit.kilojoules_per_mole deposition_period = 200 phi = ufedmm.CollectiveVariable('phi', model.phi, -limit, limit, mass, Ks, Ts, sigma) psi = ufedmm.CollectiveVariable('psi', model.psi, -limit, limit, mass, Ks, Ts, sigma)