コード例 #1
0
    def test_linp(self, molecule, control_filepath, delete_tmp_dir):
        ms = MoleculeSystem(molecule)
        ms.int_def.append(
            PerpendicularBendingAngle(indices=[[0, 1, 2, 3]],
                                      value=20,
                                      status="f"))
        assert ms.has_inconsistencies()

        with temp_dir(delete_tmp_dir) as tmp_dir:
            ms.to_file("coord", fmt="coord")
            shutil.copy2(control_filepath, "control")
            dr = DefineRunner(parameters=dr_parameters)
            assert dr.run_update_internal_coords()

            ms_new = MoleculeSystem.from_file("coord")
            assert not ms_new.has_inconsistencies()

            # check that intdef is present and that the value has been updated
            assert len(ms_new.int_def) == 1
            assert ms_new.int_def[0].value == pytest.approx(
                ms.int_def[0].value, abs=1e-4)

            # check that there are the same user-defined bonds
            assert ms.user_defined_bonds == ms_new.user_defined_bonds

            # check that in redundant the coordinate has been taken into account
            dg = DataGroups.from_file("coord")
            redundant = dg.sdg("redundant", strict=True)
            assert re.search(
                r"\d+\s+f\s+1\.0+\s+linp\s+1\s+2\s+3\s+4\s+val=\s*20",
                redundant)

            assert str(ms_new.int_def[0])
コード例 #2
0
    def test_distance(self, molecule, control_filepath, delete_tmp_dir):
        ms = MoleculeSystem(molecule, frozen_indices={2, 3})
        ms.add_distance(0, 1, weights=1.0, value=2.5)
        assert ms.has_inconsistencies()

        with temp_dir(delete_tmp_dir) as tmp_dir:
            ms.to_file("coord", fmt="coord")
            shutil.copy2(control_filepath, "control")
            dr = DefineRunner(parameters=dr_parameters)
            assert dr.run_update_internal_coords()

            ms_new = MoleculeSystem.from_file("coord")
            assert not ms_new.has_inconsistencies()

            # check that intdef is present and that the value has been updated
            assert len(ms_new.int_def) == 1
            assert ms_new.int_def[0].value == pytest.approx(
                ms.int_def[0].value, abs=1e-4)

            # check that there are the same user-defined bonds
            assert ms.user_defined_bonds == ms_new.user_defined_bonds

            # check that in redundant the coordinate has been taken into account
            dg = DataGroups.from_file("coord")
            redundant = dg.sdg("redundant", strict=True)
            assert re.search(r"\d+\s+f\s+1\.0+\s+stre\s+1\s+2\s+val=\s*2.5",
                             redundant)

            # check the presence of the same frozen atoms
            assert ms.frozen_indices == ms_new.frozen_indices

            assert str(ms_new.int_def[0])

            assert_MSONable(ms_new)
コード例 #3
0
    def test_distance_linear_combination(self, molecule, control_filepath,
                                         delete_tmp_dir):
        ms = MoleculeSystem(molecule)
        ms.add_distance([0, 1], [1, 2], weights=[1.0, 1.0], value=None)
        assert not ms.has_inconsistencies()

        with temp_dir(delete_tmp_dir) as tmp_dir:
            ms.to_file("coord", fmt="coord")
            shutil.copy2(control_filepath, "control")
            dr = DefineRunner(parameters=dr_parameters)
            assert dr.run_update_internal_coords()

            ms_new = MoleculeSystem.from_file("coord")
            assert not ms_new.has_inconsistencies()

            # check that intdef is present and that the value has been updated
            assert len(ms_new.int_def) == 1
            assert ms_new.int_def[0].value == pytest.approx(2.70995, abs=1e-4)

            # check that in redundant the coordinate has been taken into account
            dg = DataGroups.from_file("coord")
            redundant = dg.sdg("redundant", strict=True)
            assert re.search(
                r"\d+\s+f\s+1\.0+\s+stre\s+1\s+2\s+val=\s*2\.70\d+\s+1\.0+\s+stre\s+2\s+3\s*$",
                redundant, re.DOTALL | re.MULTILINE)
コード例 #4
0
    def test_to_file(self, molecule, delete_tmp_dir):
        ms = MoleculeSystem(molecule)

        with temp_dir(delete_tmp_dir) as tmp_dir:
            fname = os.path.join(tmp_dir, 'coord_test')
            ms.to_file(filepath=fname, fmt="coord")
            assert os.path.isfile("coord_test")
            dg = DataGroups.from_file("coord_test")
            assert dg.show_data_group("coord") is not None

            ms.to_file("mol_test.xyz")
            assert os.path.isfile("mol_test.xyz")
            assert ms.from_file("mol_test.xyz") is not None
コード例 #5
0
    def test_dummy_atoms(self, molecule_filepath):
        ms = MoleculeSystem.from_file(molecule_filepath, fmt="coord")
        mol = ms.molecule
        print(mol[-1].specie)
        print(mol[-1].specie.__class__)
        # Pymatgen's Specie and DummySpecie have been changed to Species and
        # DummySpecies in v2020.10.9. We keep testing both for backward compatibility.
        assert isinstance(mol[-1].specie, (DummySpecies, DummySpecie))
        assert mol[-1].specie.symbol == "Q"

        test_value2 = """
0.00000000000000 0.00000000000000 -0.12178983933899 o
1.41713420892173 0.00000000000000 0.96657854674257 h
-1.41713420892173 0.00000000000000 0.96657854674257 h
0.00000000000000 0.00000000000000 0.00000000000000 q
"""
        dg = DataGroups(ms.to_coord_string())
        assert len(dg.dg_list) == 2
        check_dg(dg.sdg("coord", strict=True), test_value2)

        assert_MSONable(ms)