def test_set_docker_python(tempconfigfile): njob = mdt._njobs g1 = mdt.from_smiles('CC') assert mdt._njobs == njob mdt.compute.update_saved_config(run_remote={'openbabel':True}) clean_config() g2 = mdt.from_smiles('CC') assert mdt._njobs == njob + 1
def test_degrees_of_freedom_with_constraints(benzene, h2): water = mdt.from_smiles('[OH2]') water.residues[0].resname = 'HOH' benzene.residues[0].resname = 'UNL' h2.residues[0].resname = 'H2' mol = benzene.combine(h2, water, water) assert mol.num_atoms == 20 # assert I can count assert mol.dynamic_dof == 3 * mol.num_atoms full_dof = mol.dynamic_dof def _constrain_direction(): c = mdt.geom.constraints.FixedCoordinate(mol.atoms[0], np.array([0.0, 0, 1.0])) mol.constraints.append(c) for constrainer, num_dof, args in ((mol.constrain_distance, 1, mol.atoms[:2]), (mol.constrain_angle, 1, mol.atoms[:3]), (mol.constrain_dihedral, 1, mol.atoms[:4]), (mol.constrain_atom, 3, mol.atoms[:1]), (mol.constrain_hbonds, 11, [True]), (_constrain_direction, 1, [])): constrainer(*args) assert mol.dynamic_dof == full_dof-num_dof mol.clear_constraints() assert mol.dynamic_dof == full_dof
def test_constrained_dihedral_minimization(minkey): minimizer = MINIMIZERS[minkey] mol = mdt.from_smiles('C=C') assert mol.atoms[0].atnum == mol.atoms[ 1].atnum == 6 # make sure we're picking the right atoms dihedral = mdt.DihedralMonitor(mol.atoms[0], mol.atoms[1]) assert dihedral.value == 0.0 dihedral.value = 45 * u.degrees constraint = dihedral.constrain() mol.set_energy_model(mdt.models.OpenBabelPotential, forcefield='mmff94s') e0_1 = mol.calculate_potential_energy() p0_1 = mol.positions.copy() if minkey == 'bfgs': # BFGS expected to fail here with pytest.raises(mdt.exceptions.NotSupportedError): minimizer(mol) return traj = minimizer(mol, nsteps=100) assert_something_resembling_minimization_happened(p0_1, e0_1, traj, mol) assert constraint.error() <= 1.0 * u.degree traj_twists = traj.dihedral(mol.atoms[0], mol.atoms[1]) assert (abs(traj_twists - 45 * u.degrees) <= 1.0 * u.degree).all() e0_2 = mol.potential_energy p0_2 = mol.positions.copy() mol.clear_constraints() traj2 = minimizer(mol, nsteps=100) assert_something_resembling_minimization_happened(p0_2, e0_2, traj2, mol) assert dihedral.value <= 5.0 * u.degrees
def test_constrained_dihedral_minimization(minkey): minimizer = MINIMIZERS[minkey] mol = mdt.from_smiles('C=C') assert mol.atoms[0].atnum == mol.atoms[1].atnum == 6 # make sure we're picking the right atoms dihedral = mdt.DihedralMonitor(mol.atoms[0], mol.atoms[1]) assert dihedral.value == 0.0 dihedral.value = 45 * u.degrees constraint = dihedral.constrain() mol.set_energy_model(mdt.models.OpenBabelPotential, forcefield='mmff94s') e0_1 = mol.calculate_potential_energy() p0_1 = mol.positions.copy() if minkey == 'bfgs': # BFGS expected to fail here with pytest.raises(mdt.exceptions.NotSupportedError): minimizer(mol) return traj = minimizer(mol, nsteps=100) assert_something_resembling_minimization_happened(p0_1, e0_1, traj, mol) assert constraint.error() <= 1.0 * u.degree traj_twists = traj.dihedral(mol.atoms[0], mol.atoms[1]) assert (abs(traj_twists - 45 * u.degrees) <= 1.0 * u.degree).all() e0_2 = mol.potential_energy p0_2 = mol.positions.copy() mol.clear_constraints() traj2 = minimizer(mol, nsteps=100) assert_something_resembling_minimization_happened(p0_2, e0_2, traj2, mol) assert dihedral.value <= 5.0 * u.degrees
def h2params(): mol = mdt.from_smiles('[H][H]') mol.atoms[0].name = 'HA' mol.atoms[1].name = 'HB' mol.residues[0].name = 'H2' params = mdt.create_ff_parameters(mol, charges='gasteiger') return mol, params
def scrambled(): mol = mdt.from_smiles('C=C') mol.set_energy_model(mdt.models.OpenBabelPotential, forcefield='mmff94s') mol.com = [0, 0, 0] * u.angstrom _apply_noise(mol, scale=5.0) e0 = mol.calculate_potential_energy() p0 = mol.positions.copy() return mol, e0, p0
def test_parameterize_multiple_identical_small_molecules(): m1 = mdt.from_smiles('O') params = mdt.create_ff_parameters(m1, charges='am1-bcc') assert params is not None m2 = m1.copy() m2.translate([4.0, 0.0, 0.0] * mdt.units.angstrom) mol = m1.combine(m2) ff = mdt.forcefields.DefaultAmber() ff.add_ff(params) ff.assign(mol) _test_succesful_parameterization(mol)
def test_pmi_reorientation_on_linear_molecule(): # note that this will fail if the generated polymer is not perfectly linear mol = mdt.from_smiles('C#CC#CC#C') original_distmat = mol.calc_distance_array().defunits_value() for i in range(5): _randomize_orientation(mol) # calculate PMI and reorient pmi = geom.alignment.PrincipalMomentsOfInertia(mol) pmi.reorient(mol) # Check that everything lies along the z-axis np.testing.assert_allclose(mol.positions[:, :2], 0.0, atol=1e-12) # Check that distance matrix was unchanged under the transformation newdistmat = mol.calc_distance_array() np.testing.assert_allclose(newdistmat.defunits_value(), original_distmat)
def test_pmi_reorientation_on_linear_molecule(): # note that this will fail if the generated polymer is not perfectly linear mol = mdt.from_smiles('C#CC#CC#C') original_distmat = mol.calc_distance_array().defunits_value() for i in range(5): _randomize_orientation(mol) # calculate PMI and reorient pmi = geom.alignment.PrincipalMomentsOfInertia(mol) pmi.reorient(mol) # Check that everything lies along the z-axis np.testing.assert_allclose(mol.positions[:,:2], 0.0, atol=1e-12) # Check that distance matrix was unchanged under the transformation newdistmat = mol.calc_distance_array() np.testing.assert_allclose(newdistmat.defunits_value(), original_distmat)
def test_degrees_of_freedom_with_integrator_constraints(benzene): water = mdt.from_smiles('[OH2]') water.residues[0].resname = 'HOH' mol = benzene.combine(water) full_dof = mol.dynamic_dof assert full_dof == 3 * mol.num_atoms mol.set_energy_model(mdt.models.OpenMMPotential) mol.set_integrator(mdt.integrators.OpenMMLangevin) mol.integrator.params.remove_translation = False mol.integrator.params.remove_rotation = False mol.integrator.params.constrain_hbonds = False mol.integrator.params.constrain_water = False assert mol.dynamic_dof == full_dof mol.integrator.params.constrain_hbonds = True mol.integrator.params.constrain_water = False assert mol.dynamic_dof == full_dof - 8 mol.integrator.params.constrain_hbonds = False mol.integrator.params.constrain_water = True assert mol.dynamic_dof == full_dof - 3 mol.integrator.params.constrain_hbonds = True mol.integrator.params.constrain_water = True assert mol.dynamic_dof == full_dof - 9 mol.clear_constraints() # does nothing, constraints are in the integrator assert mol.dynamic_dof == full_dof - 9 mol.integrator.params.constrain_hbonds = False mol.integrator.params.constrain_water = False assert mol.dynamic_dof == full_dof mol.integrator.params.remove_translation = True mol.integrator.params.remove_rotation = True mol.integrator.params.constrain_hbonds = True mol.integrator.params.constrain_water = True assert mol.dynamic_dof == full_dof - 9 - 6
def bipyridine_smiles(): return mdt.from_smiles('c1ccnc(c1)c2ccccn2')
def ammonium_charged(): return mdt.from_smiles('[NH4+]')
def small_molecule(): return mdt.from_smiles('c1ccccc1')
import moldesign as mdt mol = mdt.from_smiles('CC') mol.draw()
def cached_acetylene_dft_631g(): mol = mdt.from_smiles('C#C') mol.set_energy_model(mdt.models.B3LYP, basis='6-31g') mol.calculate() return mol
def c2_no_hydrogen_from_smiles(): mymol = mdt.from_smiles('[CH0][CH0]') return mymol
def ammonium_nocharge(): return mdt.from_smiles('[NH4]')
def cached_small_molecule(): mol = mdt.from_smiles('CNCOS(=O)C') mol.positions += 0.001*np.random.random(mol.positions.shape)*u.angstrom # move out of minimum return mol
def cached_small_molecule(): mol = mdt.from_smiles('CNCOS(=O)C') mol.positions += 0.001 * np.random.random( mol.positions.shape) * u.angstrom # move out of minimum return mol
def cached_ethylene(): return mdt.from_smiles('C=C')
def cached_benzene(): return mdt.from_smiles('c1ccccc1')
def ethylene_waterbox_2na_2cl(): mol = mdt.from_smiles('C=C') solvated = mdt.add_water(mol, padding=15.0*u.angstrom, ion_concentration=0.6*u.molar) return solvated
def mol_from_smiles(): return mdt.from_smiles('CC')
def ethylene_waterbox_2na_2cl(): mol = mdt.from_smiles('C=C') solvated = mdt.add_water(mol, padding=15.0 * u.angstrom, ion_concentration=0.6 * u.molar) return solvated