def test_write_refs_multiple(self, requests_mock): register_mock_request( mocker=requests_mock, url="http://api.crossref.org/", path="works/10.1021/ja9621760/transform/application/x-bibtex", headers={"accept": "application/x-bibtex"}, text=RESPONSE_BIB_ETHANE_JA962170, ) register_mock_request( mocker=requests_mock, url="http://api.crossref.org/", path="works/10.1021/jp0484579/transform/application/x-bibtex", headers={"accept": "application/x-bibtex"}, text=RESPONSE_BIB_ETHANE_JP0484579, ) mol2 = mb.load(get_fn("ethane.mol2")) oplsaa = Forcefield(forcefield_files=get_fn("refs-multi.xml"), strict=False) ethane = oplsaa.apply( mol2, references_file="ethane-multi.bib", assert_improper_params=False, ) assert os.path.isfile("ethane-multi.bib") with open(get_fn("ethane-multi.bib")) as file1: with open("ethane-multi.bib") as file2: diff = list( difflib.unified_diff(file1.readlines(), file2.readlines(), n=0)) assert not diff
def test_missing_topo_params(self, ff_filename, kwargs): """Test that the user is notified if not all topology parameters are found.""" ethane = mb.load(get_fn("ethane.mol2")) oplsaa_with_typo = Forcefield(forcefield_files=get_fn(ff_filename), strict=False) with pytest.raises(Exception): ethane = oplsaa_with_typo.apply(ethane, assert_improper_params=False) with pytest.warns(UserWarning): ethane = oplsaa_with_typo.apply(ethane, assert_improper_params=False, **kwargs)
def test_write_bad_ref(self, requests_mock): register_mock_request( mocker=requests_mock, url="http://api.crossref.org/", path= "works/10.1021/garbage_bad_44444444jjjj/transform/application/x-bibtex", headers={"accept": "application/x-bibtex"}, status_code=404, ) mol2 = mb.load(get_fn("ethane.mol2"), backend="parmed") oplsaa = Forcefield(forcefield_files=get_fn("refs-bad.xml"), strict=False) with pytest.warns(UserWarning): ethane = oplsaa.apply(mol2, references_file="ethane.bib", assert_improper_params=False)
def test_assert_bonds(self): ff = Forcefield(name="trappe-ua", strict=False) derponium = mb.Compound() at1 = mb.Particle(name="H") at2 = mb.Particle(name="O") at3 = mb.Particle(name="_CH4") derponium.add([at1, at2, at3]) derponium.add_bond((at1, at2)) derponium.add_bond((at2, at3)) with pytest.raises(Exception): ff.apply(derponium, assert_improper_params=False) thing = ff.apply( derponium, assert_bond_params=False, assert_angle_params=False, assert_improper_params=False, ) assert any(b.bond_type is None for b in thing.bonds)
def test_urey_bradley(self): system = mb.Compound() first = mb.Particle(name="_CTL2", pos=[-1, 0, 0]) second = mb.Particle(name="_CL", pos=[0, 0, 0]) third = mb.Particle(name="_OBL", pos=[1, 0, 0]) fourth = mb.Particle(name="_OHL", pos=[0, 1, 0]) system.add([first, second, third, fourth]) system.add_bond((first, second)) system.add_bond((second, third)) system.add_bond((second, fourth)) ff = Forcefield(forcefield_files=[get_fn("charmm36_cooh.xml")], strict=False) struc = ff.apply( system, assert_angle_params=False, assert_dihedral_params=False, assert_improper_params=False, ) assert len(struc.angles) == 3 assert len(struc.angle_types) == 3 # 1 harmonic, 2 Urey Bradley
def test_charmm_improper(self): system = mb.Compound() first = mb.Particle(name="_CTL2", pos=[-1, 0, 0]) second = mb.Particle(name="_CL", pos=[0, 0, 0]) third = mb.Particle(name="_OBL", pos=[1, 0, 0]) fourth = mb.Particle(name="_OHL", pos=[0, 1, 0]) system.add([first, second, third, fourth]) system.add_bond((first, second)) system.add_bond((second, third)) system.add_bond((second, fourth)) ff = Forcefield(forcefield_files=[get_fn("charmm36_cooh.xml")], strict=False) struc = ff.apply( system, assert_angle_params=False, assert_dihedral_params=False, assert_improper_params=False, remove_untyped_connections=False, ) assert len(struc.impropers) == 1 assert len(struc.dihedrals) == 0
def test_remove_untyped(self): mol2 = mb.load(get_fn("ethane.mol2"), backend="parmed") # test removal of untyped each class of connection seperately oplsaa_bond = Forcefield( forcefield_files=get_fn("ethane-missing_bond.xml"), strict=False) oplsaa_angle = Forcefield( forcefield_files=get_fn("ethane-missing_angle.xml"), strict=False) oplsaa_dihedral = Forcefield( forcefield_files=get_fn("ethane-missing_dihedral.xml"), strict=False) ethane1 = oplsaa_bond.apply( mol2, assert_improper_params=False, assert_bond_params=False, remove_untyped_connections=True, ) ethane2 = oplsaa_angle.apply( mol2, assert_improper_params=False, assert_angle_params=False, remove_untyped_connections=True, ) ethane3 = oplsaa_dihedral.apply( mol2, assert_improper_params=False, assert_dihedral_params=False, remove_untyped_connections=True, ) assert ethane1.n_bonds == 1 assert ethane2.n_angles == 6 assert ethane3.n_dihedrals == 0
def test_unsupported_backend(self): with pytest.raises(FoyerError, match=r"Backend not supported"): FF = Forcefield(name="oplsaa", backend="void")
def test_missing_type_definitions(self): with pytest.raises(FoyerError): FF = Forcefield() ethane = mb.load(get_fn("ethane.mol2"), backend="parmed") FF.apply(ethane, assert_improper_params=False)
def test_load_gmso_xml(self): spce_water = get_fn("gmso_spce_water.xml") ff1 = Forcefield(forcefield_files=spce_water, strict=False) assert len(ff1.atomTypeDesc) > 0
def test_load_files(self, ff_file): ff1 = Forcefield(forcefield_files=ff_file, strict=False) assert len(ff1.ff.atom_types) > 0 ff2 = Forcefield(forcefield_files=ff_file, strict=False) assert len(ff1.ff.atom_types) == len(ff2.ff.atom_types)
def oplsaa(self): return Forcefield(name="oplsaa", strict=False)