Example #1
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)
Example #2
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)
Example #3
0
    def test_add_distance(self, molecule):
        ms = MoleculeSystem(molecule)
        ms.add_distance(1, 2)
        assert not ms.has_inconsistencies()
        assert len(ms.user_defined_bonds) == 1
        ms.add_distance(0,
                        1,
                        status="k",
                        add_user_def_bonds=False,
                        value=2.058455873547)
        assert not ms.has_inconsistencies()
        assert len(ms.user_defined_bonds) == 1

        ms.add_distance(2, 3, value=10, weights=1.0)
        assert ms.has_inconsistencies()

        ms.add_distance([0, 1], [2, 3])
        assert len(ms.int_def[-1].indices) == 2

        with pytest.raises(ValueError):
            ms.add_distance([1, 2, 3], [1, 2])

        assert_MSONable(ms)