def test_eq_overall(self): ref = pmd.load_file(get_fn('ethane.top'), xyz=get_fn('ethane.gro')) top1 = from_parmed(ref) top2 = from_parmed(ref) assert top1 != top2
def test_from_parmed_member_types(self): struc = pmd.load_file(get_fn("ethane.top"), xyz=get_fn("ethane.gro")) top = from_parmed(struc) for potential_types in [ getattr(top, attr) for attr in ["bond_types", "angle_types", "dihedral_types"] ]: for potential in potential_types: assert potential.member_types
def test_to_parmed_full(self): struc = pmd.load_file(get_fn('ethane.top'), xyz=get_fn('ethane.gro')) top = from_parmed(struc) struc_from_top = to_parmed(top) assert struc.bond_types == struc_from_top.bond_types assert struc.angle_types == struc_from_top.angle_types assert struc.dihedral_types == struc_from_top.dihedral_types assert struc.rb_torsion_types == struc_from_top.rb_torsion_types # Detail comparisions for i in range(len(struc.atoms)): assert struc_from_top.atoms[i].name == struc.atoms[i].name assert struc_from_top.atoms[i].atom_type == struc.atoms[ i].atom_type for i in range(len(struc.bonds)): assert struc_from_top.bonds[i].atom1.name == struc.bonds[ i].atom1.name assert struc_from_top.bonds[i].atom2.name == struc.bonds[ i].atom2.name assert struc_from_top.bonds[i].type == struc.bonds[i].type for i in range(len(struc.angles)): assert struc_from_top.angles[i].atom1.name == struc.angles[ i].atom1.name assert struc_from_top.angles[i].atom2.name == struc.angles[ i].atom2.name assert struc_from_top.angles[i].atom3.name == struc.angles[ i].atom3.name assert struc_from_top.angles[i].type == struc.angles[i].type for i in range(len(struc.dihedrals)): assert struc_from_top.dihedrals[i].atom1.name == struc.dihedrals[ i].atom1.name assert struc_from_top.dihedrals[i].atom2.name == struc.dihedrals[ i].atom2.name assert struc_from_top.dihedrals[i].atom3.name == struc.dihedrals[ i].atom3.name assert struc_from_top.dihedrals[i].atom4.name == struc.dihedrals[ i].atom4.name assert struc_from_top.dihedrals[i].type == struc.dihedrals[i].type for i in range(len(struc.rb_torsions)): assert struc_from_top.rb_torsions[ i].atom1.name == struc.rb_torsions[i].atom1.name assert struc_from_top.rb_torsions[ i].atom2.name == struc.rb_torsions[i].atom2.name assert struc_from_top.rb_torsions[ i].atom3.name == struc.rb_torsions[i].atom3.name assert struc_from_top.rb_torsions[ i].atom4.name == struc.rb_torsions[i].atom4.name assert struc_from_top.rb_torsions[i].type == struc.rb_torsions[ i].type
def test_eq_bonds(self): ref = pmd.load_file(get_fn('ethane.top'), xyz=get_fn('ethane.gro')) missing_bond = deepcopy(ref) missing_bond.bonds[0].delete() assert ref != missing_bond bad_bond_type = deepcopy(ref) bad_bond_type.bond_types[0].k = 22 assert ref != bad_bond_type
def test_read_gro(self): top = read_gro(get_fn('acn.gro')) assert top.name == 'ACN' assert top.n_sites == 6 assert_allclose_units(top.box.lengths, 4*np.ones(3)*u.nm, rtol=1e-5, atol=1e-8) top = read_gro(get_fn('350-waters.gro')) assert top.name == 'Generic title' assert top.n_sites == 1050 assert_allclose_units(top.box.lengths, 2.20866*np.ones(3)*u.nm, rtol=1e-5, atol=1e-8)
def test_eq_dihedrals(self): ref = pmd.load_file(get_fn('ethane.top'), xyz=get_fn('ethane.gro')) missing_dihedral = deepcopy(ref) missing_dihedral.rb_torsions[0].delete() assert ref != missing_dihedral bad_dihedral_type = deepcopy(ref) bad_dihedral_type.rb_torsion_types[0].k = 22 assert ref != bad_dihedral_type
def test_eq_angles(self): ref = pmd.load_file(get_fn('ethane.top'), xyz=get_fn('ethane.gro')) missing_angle = deepcopy(ref) missing_angle.angles[0].delete() assert ref != missing_angle bad_angle_type = deepcopy(ref) bad_angle_type.angle_types[0].k = 22 assert ref != bad_angle_type
def test_to_parmed_simple(self): struc = pmd.load_file(get_fn('ethane.top'), xyz=get_fn('ethane.gro')) struc.title = "Ethane" top = from_parmed(struc) assert top.name == "Ethane" struc_from_top = to_parmed(top, refer_type=False) assert struc_from_top.title == "Ethane" assert len(struc.atoms) == len(struc_from_top.atoms) assert len(struc.bonds) == len(struc_from_top.bonds) assert len(struc.angles) == len(struc_from_top.angles) assert len(struc.dihedrals) == len(struc_from_top.dihedrals) assert len(struc.rb_torsions) == len(struc_from_top.rb_torsions)
def test_read_xyz(self): top = read_xyz(get_fn("ethane.xyz")) assert top.n_sites == 8 assert top.n_connections == 0 assert set([type(site.position) for site in top.sites]) == {u.unyt_array} assert set([site.position.units for site in top.sites]) == {u.nm} top = read_xyz(get_fn("cu_block.xyz")) assert top.n_sites == 108 assert top.n_connections == 0 assert set([type(site.position) for site in top.sites]) == {u.unyt_array} assert set([site.position.units for site in top.sites]) == {u.nm}
def foyer_periodic(self): if has_foyer: import foyer from foyer.tests.utils import get_fn from_foyer_xml(get_fn("oplsaa-periodic.xml"), overwrite=True) gmso_ff = ForceField("oplsaa-periodic_gmso.xml") return gmso_ff
def foyer_fullerene(self): if has_foyer: import foyer from foyer.tests.utils import get_fn from_foyer_xml(get_fn("fullerene.xml"), overwrite=True) gmso_ff = ForceField("fullerene_gmso.xml") return gmso_ff
def foyer_urey_bradley(self): if has_foyer: import foyer from foyer.tests.utils import get_fn from_foyer_xml(get_fn("charmm36_cooh.xml"), overwrite=True) gmso_ff = ForceField("charmm36_cooh_gmso.xml") return gmso_ff
def test_full_io(self): original_top = read_xyz(get_fn('ethane.xyz')) write_xyz(original_top, 'full_conversion.xyz') new_top = read_xyz('full_conversion.xyz') assert original_top.n_sites == new_top.n_sites assert original_top.n_connections == new_top.n_connections assert allclose(original_top.positions, new_top.positions)
def test_to_parmed_incompatible_expression(self): struc = pmd.load_file(get_fn('ethane.top'), xyz=get_fn('ethane.gro')) top = from_parmed(struc) with pytest.raises(Exception): top.atom_types[0] = "sigma + epsilon" struc_from_top = to_parmed(top) with pytest.raises(Exception): top.bond_types[0] = "k * r_eq" struc_from_top = to_parmed(top) with pytest.raises(Exception): top.angle_types[0] = "k - theta_eq" struc_from_top = to_parmed(top) with pytest.raises(Exception): top.dihedral_types[0] = "c0 - c1 + c2 - c3 + c4 - c5" struc_from_top = to_parmed(top)
def foyer_rb_torsion(self): if has_foyer: import foyer from foyer.tests.utils import get_fn from_foyer_xml(get_fn("refs-multi.xml"), overwrite=True, validate_foyer=True) gmso_ff = ForceField("refs-multi_gmso.xml") return gmso_ff
def test_from_parmed_parametrized_structure(self, angles): struc = pmd.load_file(get_fn('ethane.top'), xyz=get_fn('ethane.gro')) top = from_parmed(struc) assert top.n_sites == 8 assert top.n_bonds == 7 assert top.n_angles == 12 assert top.n_connections == 19 for site in top.sites: assert site.atom_type is not None assert site.charge is not None for connection in top.connections: assert connection.connection_type is not None assert top.box is not None lengths = u.nm * [0.714, 0.7938, 0.6646] assert allclose(top.box.lengths, lengths) assert allclose(top.box.angles, angles)
def _typed_topology(n_sites=100): top = from_mbuild(n_ar_system(n_sites=n_sites)) ff = ForceField(get_fn('ar.xml')) for site in top.sites: site.atom_type = ff.atom_types['Ar'] top.update_topology() return top
def test_from_parmed_parametrized_structure(self, angles): struc = pmd.load_file(get_fn("ethane.top"), xyz=get_fn("ethane.gro")) top = from_parmed(struc) assert top.n_sites == 8 assert top.n_bonds == 7 assert top.n_angles == 12 assert top.n_dihedrals == 9 assert top.n_connections == 28 for site in top.sites: assert site.atom_type is not None assert site.charge is not None for connection in top.connections: assert connection.connection_type is not None assert top.box is not None lengths = u.nm * [0.714, 0.7938, 0.6646] assert_allclose_units(top.box.lengths, lengths, rtol=1e-5, atol=1e-8) assert_allclose_units(top.box.angles, angles, rtol=1e-5, atol=1e-8)
def typed_ar_system(self, ar_system): top = ar_system ff = ForceField(get_fn('ar.xml')) for site in top.sites: site.atom_type = ff.atom_types['Ar'] top.update_topology() return top
def test_full_io(self): original_top = read_xyz(get_fn("ethane.xyz")) write_xyz(original_top, "full_conversion.xyz") new_top = read_xyz("full_conversion.xyz") assert original_top.n_sites == new_top.n_sites assert original_top.n_connections == new_top.n_connections assert_allclose_units(original_top.positions, new_top.positions, rtol=1e-5, atol=1e-8)
def test_from_parmed_basic(self, angles): struc = pmd.load_file(get_fn('ethane.mol2'), structure=True) top = from_parmed(struc, refer_type=False) for site in top.sites: assert site.atom_type is None for connection in top.connections: assert connection.connection_type is None assert top.n_sites == 8 assert top.n_bonds == 7 assert top.box is not None lengths = u.nm * [0.714, 0.7938, 0.6646] assert_allclose_units(top.box.lengths, lengths, rtol=1e-5, atol=1e-8) assert_allclose_units(top.box.angles, angles, rtol=1e-5, atol=1e-8)
def ar_system(): ar = mb.Compound(name='Ar') packed_system = mb.fill_box(compound=ar, n_compounds=100, box=mb.Box([3, 3, 3])) ff = ForceField(get_fn('ar.xml')) top = from_mbuild(packed_system) for site in top.sites: site.atom_type = ff.atom_types['Ar'] top.update_topology() return top
def test_modified_potentials(self, ar_system): top = ar_system ff = gmso.ForceField(get_fn('ar.xml')) for site in top.sites: site.atom_type = ff.atom_types['Ar'] top.update_topology() top.atom_types[0].set_expression('sigma + epsilon*r') with pytest.raises(EngineIncompatibilityError): write_top(top, 'out.top') alternate_lj = '4*epsilon*sigma**12/r**12 - 4*epsilon*sigma**6/r**6' top.atom_types[0].set_expression(alternate_lj) write_top(top, 'ar.top')
def test_write_gro_non_orthogonal(self): top = from_parmed(pmd.load_file(get_fn('ethane.gro'), structure=True)) top.box.angles = u.degree * [90, 90, 120] write_gro(top, 'out.gro')
def test_write_gro(self): top = from_parmed(pmd.load_file(get_fn('ethane.gro'), structure=True)) write_gro(top, 'out.gro')
def test_wrong_n_atoms(self): with pytest.raises(ValueError): read_gro(get_fn('too_few_atoms.gro')) with pytest.raises(ValueError): read_gro(get_fn('too_many_atoms.gro'))
def test_wrong_n_atoms(self): with pytest.raises(ValueError): read_xyz(get_fn("too_few_atoms.xyz")) with pytest.raises(ValueError): read_xyz(get_fn("too_many_atoms.xyz"))
def test_write_xyz(self): top = read_xyz(get_fn("ethane.xyz")) write_xyz(top, "tmp.xyz")
def mb_ethane(self): return mb.load(get_fn("ethane.mol2"))
def ethane(self): return mb.load(get_fn('ethane.mol2'))