Esempio n. 1
0
    def test_bondset_boltzmann_invert_mdtraj(self):
        logging.disable(logging.WARNING)
        frame = Frame("test/data/sugar.gro",
                      xtc="test/data/sugar.xtc",
                      xtc_reader="mdtraj")
        logging.disable(logging.NOTSET)

        measure = BondSet("test/data/sugar.bnd", DummyOptions)
        mapping = Mapping("test/data/sugar.map", DummyOptions)

        cgframe = mapping.apply(frame)
        while frame.next_frame():
            cgframe = mapping.apply(frame, cgframe=cgframe)
            measure.apply(cgframe)

        measure.boltzmann_invert()
        self.support_check_mean_fc(measure["ALLA"], 1)
Esempio n. 2
0
    def test_bondset_boltzmann_invert_manual_default_fc(self):
        class FuncFormOptions(DummyOptions):
            length_form = "MartiniDefaultLength"
            angle_form = "MartiniDefaultAngle"
            dihedral_form = "MartiniDefaultDihedral"

        measure = BondSet("test/data/sugar.bnd", FuncFormOptions)
        frame = Frame("test/data/sugar.gro", xtc="test/data/sugar.xtc")
        mapping = Mapping("test/data/sugar.map", DummyOptions)

        cgframe = mapping.apply(frame)
        while frame.next_frame():
            cgframe = mapping.apply(frame, cgframe=cgframe)
            measure.apply(cgframe)

        measure.boltzmann_invert()
        self.support_check_mean_fc(measure["ALLA"], 2)
Esempio n. 3
0
    def test_full_itp_sugar(self):
        measure = BondSet("test/data/sugar.bnd", DummyOptions)
        frame = Frame("test/data/sugar.gro", xtc="test/data/sugar.xtc")
        mapping = Mapping("test/data/sugar.map", DummyOptions)
        cgframe = mapping.apply(frame)

        while frame.next_frame():
            cgframe = mapping.apply(frame, cgframe=cgframe)
            measure.apply(cgframe)

        measure.boltzmann_invert()

        logging.disable(logging.WARNING)
        measure.write_itp("sugar_out.itp", mapping)
        logging.disable(logging.NOTSET)

        self.assertTrue(
            cmp_whitespace_float("sugar_out.itp",
                                 "test/data/sugar_out.itp",
                                 float_rel_error=0.001))
Esempio n. 4
0
    def test_dump_bonds(self):
        measure = BondSet(self.data_dir.joinpath("sugar.bnd"), DummyOptions)
        frame = Frame(self.data_dir.joinpath("sugar.gro"),
                      self.data_dir.joinpath("sugar.xtc"))
        mapping = Mapping(self.data_dir.joinpath("sugar.map"), DummyOptions)

        cg_frame = mapping.apply(frame)

        measure.apply(cg_frame)
        measure.boltzmann_invert()
        measure.dump_values()

        filenames = ("ALLA_length.dat", "ALLA_angle.dat", "ALLA_dihedral.dat")
        for filename in filenames:
            self.assertTrue(
                cmp_file_whitespace_float(self.data_dir.joinpath(filename),
                                          filename,
                                          rtol=0.008,
                                          verbose=True))
            os.remove(filename)
Esempio n. 5
0
 def test_bondset_apply(self):
     measure = BondSet("test/data/sugar.bnd", DummyOptions)
     frame = Frame("test/data/sugar-cg.gro")
     measure.apply(frame)
     # First six are bond lengths
     self.assertEqual(1, len(measure["ALLA"][0].values))
     self.assertAlmostEqual(0.2225376,
                            measure["ALLA"][0].values[0],
                            delta=0.2225376 / 500)
     # Second six are angles
     self.assertEqual(1, len(measure["ALLA"][6].values))
     expected = math.radians(77.22779289)
     self.assertAlmostEqual(expected,
                            measure["ALLA"][6].values[0],
                            delta=expected / 500)
     # Final six are dihedrals
     self.assertEqual(1, len(measure["ALLA"][12].values))
     expected = math.radians(-89.5552903)
     self.assertAlmostEqual(expected,
                            measure["ALLA"][12].values[0],
                            delta=abs(expected) / 500)
Esempio n. 6
0
    def test_mapping_duplicate_atom_weight(self):
        """Test that an atom can be duplicated in a bead specification to act as a weighting."""
        frame = Frame(self.data_dir.joinpath("water.gro"))

        mapping = Mapping(self.data_dir.joinpath("water.map"), DummyOptions)
        cg_frame = mapping.apply(frame)

        np.testing.assert_allclose(
            np.array([[0.716, 1.300, 1.198]]),
            cg_frame.residue(0).atom(0).coords,
            atol=0.0005,
        )

        mapping = Mapping(self.data_dir.joinpath("water_double_weight.map"),
                          DummyOptions)
        cg_frame = mapping.apply(frame)

        np.testing.assert_allclose(
            np.array([[0.720, 1.294, 1.195]]),
            cg_frame.residue(0).atom(0).coords,
            atol=0.0005,
        )
Esempio n. 7
0
    def test_full_itp_sugar(self):
        measure = BondSet(self.data_dir.joinpath("sugar.bnd"), DummyOptions)
        frame = Frame(self.data_dir.joinpath("sugar.gro"),
                      self.data_dir.joinpath("sugar.xtc"))
        mapping = Mapping(self.data_dir.joinpath("sugar.map"), DummyOptions)

        cg_frame = mapping.apply(frame)

        measure.apply(cg_frame)
        measure.boltzmann_invert()

        with tempfile.TemporaryDirectory() as tmpdir:
            tmp_path = pathlib.Path(tmpdir)

            measure.write_itp(tmp_path.joinpath("sugar_out.itp"), mapping)

            self.assertTrue(
                cmp_file_whitespace_float(
                    tmp_path.joinpath("sugar_out.itp"),
                    self.data_dir.joinpath("sugar_out.itp"),
                    rtol=0.005,
                    verbose=True,
                ))
Esempio n. 8
0
 def test_frame_add_residue(self):
     residue = Residue()
     frame = Frame()
     frame.add_residue(residue)
     self.assertEqual(residue, frame.residues[0])
     self.assertTrue(residue is frame.residues[0])
Esempio n. 9
0
    def test_frame_simpletraj_read_gro(self):
        frame = Frame("test/data/water.gro", xtc_reader="simpletraj")

        self.helper_read_xtc(frame, first_only=True)
Esempio n. 10
0
    def test_frame_read_gro(self):
        frame = Frame(self.data_dir.joinpath("water.gro"))

        self.check_reference_frame(frame)
Esempio n. 11
0
    def test_frame_add_residue(self):
        frame = Frame()
        residue = frame.add_residue("TEST_RESIDUE")

        self.assertTrue(residue is frame.residue(0))
Esempio n. 12
0
 def test_frame_create(self):
     Frame()
Esempio n. 13
0
 def test_mapping_pbc(self):
     mapping = Mapping("test/data/water.map", DummyOptions)
     frame = Frame("test/data/pbcwater.gro")
     cgframe = mapping.apply(frame)
     np.testing.assert_allclose(frame[0][0].coords, cgframe[0][0].coords)
Esempio n. 14
0
 def test_frame_accept_path(self):
     """Test that Frame accepts :class:`pathlib.Path` arguments."""
     _ = Frame(self.data_dir.joinpath("water.gro"),
               self.data_dir.joinpath("water.xtc"))
Esempio n. 15
0
 def test_frame_read_xtc_simpletraj_numframes(self):
     frame = Frame(gro="test/data/water.gro",
                   xtc="test/data/water.xtc",
                   xtc_reader="simpletraj")
     self.assertEqual(11, frame.numframes)
Esempio n. 16
0
 def test_frame_any_read_unsupported(self):
     with self.assertRaises(UnsupportedFormatException):
         _ = Frame(self.data_dir.joinpath("dppc.map"))
Esempio n. 17
0
 def test_frame_read_zero_box(self):
     frame = Frame(self.data_dir.joinpath("polyethene.gro"))
     self.assertIsNone(frame.unitcell_lengths)
Esempio n. 18
0
    def test_frame_read_pdb_nobox(self):
        """Test reading a PDB with zero box volume."""
        frame = Frame(self.data_dir.joinpath("water-nobox.pdb"))

        self.check_reference_frame(frame, check_box=False)
Esempio n. 19
0
 def test_mapping_weights_geom(self):
     frame = Frame("test/data/two.gro")
     mapping = Mapping("test/data/two.map", DummyOptions)
     cg = mapping.apply(frame)
     np.testing.assert_allclose(np.array([1.5, 1.5, 1.5]), cg[0][0].coords)
Esempio n. 20
0
 def test_frame_simpletraj_read_xtc(self):
     frame = Frame(gro="test/data/water.gro",
                   xtc="test/data/water.xtc",
                   xtc_reader="simpletraj")
     self.helper_read_xtc(frame)
Esempio n. 21
0
 def test_raise_nonmatching_system_mdtraj(self):
     with self.assertRaises(NonMatchingSystemError):
         _ = Frame(self.data_dir.joinpath("water.gro"),
                   self.data_dir.joinpath("sugar.xtc"))
Esempio n. 22
0
 def test_frame_read_xtc_numframes(self):
     frame = Frame(self.data_dir.joinpath("water.gro"),
                   self.data_dir.joinpath("water.xtc"))
     self.assertEqual(11, frame.n_frames)
Esempio n. 23
0
    def test_frame_mdtraj_read_gro(self):
        logging.disable(logging.WARNING)
        frame = Frame("test/data/water.gro", xtc_reader="mdtraj")
        logging.disable(logging.NOTSET)

        self.helper_read_xtc(frame, first_only=True, skip_names=True)
Esempio n. 24
0
    def test_frame_read_xtc(self):
        frame = Frame(self.data_dir.joinpath("water.gro"),
                      self.data_dir.joinpath("water.xtc"))

        self.check_reference_trajectory(frame)
Esempio n. 25
0
 def test_frame_output_gro(self):
     frame = Frame("test/data/water.gro")
     frame.output("water-out.gro", format="gro")
     self.assertTrue(filecmp.cmp("test/data/water.gro", "water-out.gro"))
     os.remove("water-out.gro")