class PycgtoolTest(unittest.TestCase): config = Options([("output_name", "out"), ("output", "gro"), ("output_xtc", True), ("map_only", False), ("map_center", "geom"), ("constr_threshold", 100000), ("dump_measurements", False), ("dump_n_values", 10000), ("output_forcefield", False), ("temperature", 310), ("default_fc", False), ("generate_angles", True), ("generate_dihedrals", False)]) def test_run_help(self): path = os.path.dirname(os.path.dirname(__file__)) self.assertEqual( 0, subprocess.check_call([os.path.join(path, "pycgtool.py"), "-h"], stdout=subprocess.PIPE)) @unittest.skipIf(not mdtraj_present, "MDTRAJ or Scipy not present") def test_map_only(self): logging.disable(logging.WARNING) map_only(Args("sugar"), self.config) logging.disable(logging.NOTSET) xtc = XtcTrajectory("out.xtc") xtc_ref = XtcTrajectory("test/data/sugar_out.xtc") self.assertEqual(xtc_ref.numframes, xtc.numframes) for i in range(xtc_ref.numframes): xtc.get_frame(i) xtc_ref.get_frame(i) np.testing.assert_array_almost_equal(xtc_ref.box, xtc.box, decimal=3) np.testing.assert_array_almost_equal(xtc_ref.x, xtc.x, decimal=3) def test_full(self): path = os.path.dirname(os.path.dirname(__file__)) self.assertEqual( 0, subprocess.check_call([ os.path.join(path, "pycgtool.py"), "-g", "test/data/sugar.gro", "-x", "test/data/sugar.xtc", "-m", "test/data/sugar_only.map", "-b", "test/data/sugar.bnd", ], stdout=subprocess.PIPE, stderr=subprocess.PIPE)) self.assertTrue( cmp_whitespace_float("out.itp", "test/data/sugar_out.itp", float_rel_error=0.001)) self.assertTrue( cmp_whitespace_float("out.gro", "test/data/sugar_out.gro", float_rel_error=0.001))
def test_options_set(self): opt = Options([("a", True), ("b", 10), ("c", "hello")]) opt.set("a", False) opt.set("b", 11) self.assertEqual(False, opt.a) self.assertEqual(11, opt.b) self.assertEqual("hello", opt.c) opt.set("a", "yEs") opt.set("b", "12") self.assertEqual(True, opt.a) self.assertEqual(12, opt.b) opt.set("a", "f") self.assertEqual(False, opt.a) with self.assertRaises(ValueError): opt.set("a", "hello") with self.assertRaises(ValueError): opt.set("b", "hello")
def test_options_toggle(self): opt = Options([("a", True), ("b", 10), ("c", "hello")]) opt.toggle_boolean("a") self.assertEqual(False, opt.a)
def test_options_init(self): opt = Options([("a", True), ("b", 10), ("c", "hello")]) self.assertEqual(True, opt.a) self.assertEqual(10, opt.b) self.assertEqual("hello", opt.c)
type=int, default=0, help="Frame number to begin") input_files.add_argument('--end', type=int, default=-1, help="Frame number to end") func_forms = FunctionalForms() args = parser.parse_args() config = Options( [("output_name", "out"), ("output", "gro"), ("output_xtc", args.outputxtc), ("map_only", not bool(args.bnd)), ("map_center", "geom"), ("constr_threshold", 100000), ("dump_measurements", bool(args.bnd) and not bool(args.map)), ("dump_n_values", 10000), ("output_forcefield", False), ("temperature", 310), ("default_fc", False), ("generate_angles", True), ("generate_dihedrals", False), ("length_form", "harmonic"), ("angle_form", "cosharmonic"), ("dihedral_form", "harmonic")], args) if not args.map and not args.bnd: parser.error("One or both of -m and -b is required.") if args.advanced: try: config.interactive() except KeyboardInterrupt: sys.exit(0) else: print("Using GRO: {0}".format(args.gro))