def test_full_itp_vsites(self): """Test full operation to output of .itp file for molecule with vsites.""" options = DummyOptions() options.generate_angles = False measure = BondSet(self.data_dir.joinpath("martini3/naphthalene.bnd"), options) frame = Frame(self.data_dir.joinpath("martini3/naphthalene.gro")) mapping = Mapping(self.data_dir.joinpath("martini3/naphthalene.map"), options) 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("naphthalene_out.itp"), mapping) self.assertTrue( cmp_file_whitespace_float( tmp_path.joinpath("naphthalene_out.itp"), self.data_dir.joinpath("martini3/naphthalene_out.itp"), rtol=0.005, verbose=True, ))
def test_forcefield(self): with tempfile.TemporaryDirectory() as tmpdir: tmp_path = pathlib.Path(tmpdir) args = get_args( "sugar", tmp_path, extra={ "output_forcefield": True, }, ) # Equivalent to # pycgtool <top> <trj> -m <map> -b <bnd> --output-forcefield main.PyCGTOOL(args) # Does not produce itp file self.assertFalse(tmp_path.joinpath("out.itp").exists()) out_ff_dir = tmp_path.joinpath("ffout.ff") self.assertTrue(out_ff_dir.is_dir()) # Compare all files in ffout.ff to reference versions for out_file in out_ff_dir.iterdir(): ref_file = self.data_dir.joinpath(out_file) self.assertTrue( util.cmp_file_whitespace_float(ref_file, out_file))
def test_measure_only(self): with tempfile.TemporaryDirectory() as tmpdir: tmp_path = pathlib.Path(tmpdir) args = get_args( "sugar", tmp_path, extra={ "mapping": None, "trajectory": None, }, ) # Equivalent to # pycgtool <top> -b <bnd> main.PyCGTOOL(args) # Does not produce itp file self.assertFalse(tmp_path.joinpath("out.itp").exists()) # Check bond dump files against reference for bond_type in ["length", "angle", "dihedral"]: out_file = tmp_path.joinpath(f"ALLA_{bond_type}.dat") self.assertTrue(out_file.exists()) self.assertTrue( util.cmp_file_whitespace_float( self.data_dir.joinpath(f"ALLA_{bond_type}_one.dat"), out_file))
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)
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, ))
def test_full(self): with tempfile.TemporaryDirectory() as tmpdir: tmp_path = pathlib.Path(tmpdir) args = get_args("sugar", tmp_path) # Equivalent to # pycgtool <top> <trj> -m <map> -b <bnd> main.PyCGTOOL(args) self.assertTrue( util.cmp_file_whitespace_float( tmp_path.joinpath("out.itp"), self.data_dir.joinpath("sugar_out.itp"), rtol=0.001, verbose=True, )) self.assertTrue( util.compare_trajectories( self.data_dir.joinpath("sugar_out.gro"), tmp_path.joinpath("out.gro"), rtol=0.001, ))