def testTCLTruncateSegname(self): # Tests providing a chain_id that is longer than one character try: # easier to run_kmc to create monomer_list than recreate it here (adj easier) so doing so # minimize random calls by providing set list of monomer types initial_mono_type_list = [S, S, G, S, S, S, G, S] num_monos = len(initial_mono_type_list) initial_monomers = [ Monomer(mono_type, i) for i, mono_type in enumerate(initial_mono_type_list) ] initial_events = create_initial_events(initial_monomers, DEF_RXN_RATES) initial_state = create_initial_state(initial_events, initial_monomers) # since GROW is not added to event_dict, no additional monomers will be added result = run_kmc(DEF_RXN_RATES, initial_state, sorted(initial_events), t_max=2, random_seed=8) # quick tests to make sure run_kmc gives expected results (not what we want to test here) # self.assertAlmostEqual(result[TIME][-1], 0.000766574526703574) self.assertTrue(len(result[MONO_LIST]) == num_monos) # the function we want to test here is below with capture_stderr(gen_tcl, result[ADJ_MATRIX], result[MONO_LIST], chain_id="lignin", out_dir=SUB_DATA_DIR) as output: self.assertTrue("should be one character" in output) self.assertFalse(diff_lines(TCL_FILE_LOC, GOOD_TCL_SHORT)) finally: silent_remove(TCL_FILE_LOC, disable=DISABLE_REMOVE) pass
def testBadAtomIni(self): test_input = ["-c", BAD_ATOM_INI] if logger.isEnabledFor(logging.DEBUG): main(test_input) with capture_stderr(main, test_input) as output: self.assertTrue("Atom types do not match" in output) silent_remove(PDB_OUT, disable=DISABLE_REMOVE)
def testNoTplIni(self): test_input = ["-c", NO_TPL_INI] try: main(test_input) self.assertFalse(diff_lines(PDB_OUT, GOOD_NO_TPL_OUT)) finally: silent_remove(PDB_OUT, disable=DISABLE_REMOVE)
def testDyn4(self): # also has multiple sg_ratio expected_files = [BOND_V_STEP_PNG, MONO_V_STEP_PNG] try: for fname in expected_files: silent_remove(fname) test_input = [ "-r", "10", "-i", "3", "-m", "20", "-dy", "-a", "1e6", "-n", "4", "-x" ] # main(test_input) with capture_stdout(main, test_input) as output: self.assertTrue( "BO4: 2 BB: 7 B5: 2 B1: 0 5O4: 2 AO4: 0 " " 55: 0" in output) self.assertTrue( "BO4: 6 BB: 3 B5: 4 B1: 0 5O4: 4 AO4: 0 " " 55: 0" in output) self.assertTrue( "BO4: 5 BB: 2 B5: 6 B1: 0 5O4: 2 AO4: 0 " " 55: 1" in output) self.assertTrue( "BO4: 7 BB: 5 B5: 2 B1: 0 5O4: 5 AO4: 0 " " 55: 0" in output) for fname in expected_files: self.assertTrue(os.path.isfile(fname)) finally: for fname in expected_files: silent_remove(fname, disable=DISABLE_REMOVE) pass
def testWrongDir(self): test_input = ["-d", "ghost"] if logger.isEnabledFor(logging.DEBUG): main(test_input) with capture_stderr(main, test_input) as output: self.assertTrue("Could not find" in output) silent_remove(FOR_HARTREE_DIR, disable=DISABLE_REMOVE)
def testLastIni(self): test_input = ["-c", LAST_INI] try: main(test_input) self.assertFalse(diff_lines(PDB_OUT, GOOD_PDB_LAST_OUT)) finally: silent_remove(PDB_OUT, disable=DISABLE_REMOVE)
def testProduction(self): # new_out_dir = os.path.join(DATA_DIR, 'new_plots') plot_input = [ "-x", "-p", # next line: testing "-i", "5", "-m", "100", "-a", "1", "-sg", "1, 10", "-n", "3", "-d", TEMP_DIR, # # alt lines: production # "-i", "2", "-m", "500", "-l", "1e5", "-a", "1e8, 1e6, 1e4, 1e2, 1", # "-sg", "0.1, 0.2, 0.25, 0.33, 0.5, 1, 2, 3, 4, 5, 10", "-n", "100", "-d", new_out_dir, ] try: with capture_stderr(main, plot_input) as output: self.assertFalse(output) finally: silent_remove(TEMP_DIR, dir_with_files=True, disable=DISABLE_REMOVE) pass
def testSubmitMultIni(self): # Create and submit more than one ini temp_file_list = [ 'ethylrad.com', 'ircr.tpl', 'ircf.tpl', 'opt.tpl', 'ethylrad.chk' ] for fname in temp_file_list: with open(fname, 'w') as f: f.write("# for test only\n") test_input = ['ethylrad', "-c", SETUP_IRCS_INI, "-s", "-n"] try: main(test_input) self.assertFalse( diff_lines(SETUP_IRCR_INI_OUT, GOOD_SETUP_IRCR_INI_OUT)) self.assertFalse( diff_lines(SETUP_IRCR_SLM_OUT, GOOD_SETUP_IRCR_SLM_OUT)) self.assertFalse( diff_lines(SETUP_IRCF_INI_OUT, GOOD_SETUP_IRCF_INI_OUT)) self.assertFalse( diff_lines(SETUP_IRCF_SLM_OUT, GOOD_SETUP_IRCF_SLM_OUT)) finally: for fname in temp_file_list + [ SETUP_IRCR_INI_OUT, SETUP_IRCR_SLM_OUT, SETUP_IRCF_INI_OUT, SETUP_IRCF_SLM_OUT ]: silent_remove(fname, disable=DISABLE_REMOVE) pass
def testNoGrowth(self): # Here, all the monomers are available at the beginning of the simulation try: # minimize random calls by providing set list of monomer types mono_type_list = [ S, S, S, S, G, S, S, S, S, S, S, G, S, S, S, S, S, S, S, S, S, S, S, S ] random_num = 24 initial_monomers = [ Monomer(mono_type, i) for i, mono_type in enumerate(mono_type_list) ] initial_events = create_initial_events(initial_monomers, DEF_RXN_RATES) initial_state = create_initial_state(initial_events, initial_monomers) # since GROW is not added to event_dict, no additional monomers will be added result = run_kmc(DEF_RXN_RATES, initial_state, sorted(initial_events), t_max=0.0001, random_seed=random_num) gen_tcl(result[ADJ_MATRIX], result[MONO_LIST], tcl_fname=TCL_FNAME, chain_id="L", out_dir=SUB_DATA_DIR) self.assertFalse(diff_lines(TCL_FILE_LOC, GOOD_TCL_NO_GROW_OUT)) finally: silent_remove(TCL_FILE_LOC, disable=DISABLE_REMOVE) pass
def testTCLGenEmptySegname(self): # tcl_fname="psfgen.tcl", psf_fname='lignin', chain_id="L", toppar_dir="toppar/" # Here, all the monomers are available at the beginning of the simulation # Increases coverage of gen_tcl try: # easier to run_kmc to create monomer_list than recreate it here (adj easier) so doing so # minimize random calls by providing set list of monomer types initial_mono_type_list = [S, S, G, S, S, S, G, S] num_monos = len(initial_mono_type_list) initial_monomers = [Monomer(mono_type, i) for i, mono_type in enumerate(initial_mono_type_list)] initial_events = create_initial_events(initial_monomers, DEF_RXN_RATES) initial_state = create_initial_state(initial_events, initial_monomers) # since GROW is not added to event_dict, no additional monomers will be added result = run_kmc(DEF_RXN_RATES, initial_state, sorted(initial_events), t_max=2, random_seed=8) # quick tests to make sure run_kmc gives expected results (not what we want to test here) self.assertAlmostEqual(result[TIME][-1], 0.00015059250794459398) self.assertTrue(len(result[MONO_LIST]) == num_monos) # the function we want to test here is below with capture_stderr(gen_tcl, result[ADJ_MATRIX], result[MONO_LIST], chain_id=" ", out_dir=SUB_DATA_DIR) as output: self.assertTrue("should be one character" in output) self.assertFalse(diff_lines(TCL_FILE_LOC, GOOD_TCL_SHORT)) finally: silent_remove(TCL_FILE_LOC, disable=DISABLE_REMOVE) pass
def testRouteNoChargeTpl(self): test_input = ["-t", ROUTE_NO_CHARGE_TPL, "-f", CP_COM_IN, "-c"] try: main(test_input) self.assertFalse(diff_lines(CP_COM_OUT, GOOD_ROUTE_ONLY_COM_OUT)) finally: silent_remove(CP_COM_OUT, disable=DISABLE_REMOVE) pass
def testFromFileCase(self): test_input = ["-t", TPL_FILE, "-f", COM_IN_NO_CHARGE_FILE] try: main(test_input) self.assertFalse(diff_lines(MISSING_MULT_COM_OUT_FILE, GOOD_COM_OUT_FILE)) finally: silent_remove(MISSING_MULT_COM_OUT_FILE, disable=DISABLE_REMOVE) pass
def testFileCPTpl(self): test_input = ["-t", CP_COM_TPL, "-f", CP_COM_IN] try: main(test_input) self.assertFalse(diff_lines(CP_COM_OUT, GOOD_CP_COM_OUT)) finally: silent_remove(CP_COM_OUT, disable=DISABLE_REMOVE) pass
def testPinnedTpl(self): test_input = ["-t", PINNED_TPL_FILE, "-f", COM_IN_FILE] try: main(test_input) self.assertFalse(diff_lines(COM_OUT_FILE, GOOD_PINNED_OUT_FILE)) finally: silent_remove(COM_OUT_FILE, disable=DISABLE_REMOVE) pass
def testConflictingOptions(self): test_input = ["-s", "-z"] # main(test_input) # if logger.isEnabledFor(logging.DEBUG): # main(test_input) with capture_stderr(main, test_input) as output: self.assertTrue("Choose either" in output) silent_remove(FOR_HARTREE_DIR, disable=DISABLE_REMOVE)
def testMultPDB(self): test_input = ["-c", MULT_PDB_INI] try: main(test_input) self.assertFalse(diff_lines(MULT_PDB_OUT, GOOD_MULT_PDB_OUT)) finally: silent_remove(MULT_PDB_OUT, disable=DISABLE_REMOVE) pass
def testFragments(self): test_input = ["-t", LOW_E_TPL, "-f", FRAG_LOG_FILE] try: main(test_input) self.assertFalse(diff_lines(FRAG_COM_OUT, GOOD_FRAG_COM_OUT)) finally: silent_remove(FRAG_COM_OUT, disable=DISABLE_REMOVE) pass
def testTemplateTypeMatching(self): test_input = ["-t", TYPE_MATCH_TPL, "-f", TYPE_MATCH_LOG, "-e"] try: main(test_input) self.assertFalse(diff_lines(TYPE_MATCH_OUT, GOOD_TYPE_MATCH_OUT)) finally: silent_remove(TYPE_MATCH_OUT, disable=DISABLE_REMOVE) pass
def testLowEn(self): test_input = ["-t", LOW_E_TPL, "-f", LOG_LOW_E_FILE, "-e"] try: main(test_input) self.assertFalse(diff_lines(COM_LOW_E_OUT, GOOD_COM_LOW_E_FILE)) finally: silent_remove(COM_LOW_E_OUT, disable=DISABLE_REMOVE) pass
def testSingle(self): test_input = ["-c", SINGLE_INI] try: main(test_input) self.assertFalse(diff_lines(SINGLE_OUT, GOOD_SINGLE_OUT)) finally: silent_remove(SINGLE_OUT, disable=DISABLE_REMOVE) pass
def testMultipleHeaderLinesIni(self): test_input = ["-c", MORE_HEADER_LINES_INI] try: main(test_input) self.assertFalse(diff_lines(PDB_MULT_HEADER_OUT, GOOD_PDB_OUT)) finally: silent_remove(PDB_MULT_HEADER_OUT, disable=DISABLE_REMOVE) pass
def testComb2Ini(self): test_input = ["-c", COMB2_INI, "-o", "pet_mono_test_comb.pdb"] try: main(test_input) self.assertFalse(diff_lines(COMB_PDB_OUT, GOOD_COMB_PDB_OUT)) finally: silent_remove(COMB_PDB_OUT, disable=DISABLE_REMOVE) pass
def testAltIni(self): test_input = ["-c", ALT_INI] try: main(test_input) self.assertFalse(diff_lines(ALT_OUT, GOOD_ALT_OUT)) finally: silent_remove(ALT_OUT, disable=DISABLE_REMOVE) pass
def testFromPinnedAtomFileCase(self): test_input = ["-t", TPL_FILE, "-f", PINNED_ATOM_IN] try: main(test_input) self.assertFalse(diff_lines(PINNED_ATOM_OUT, GOOD_COM_OUT_FILE)) finally: silent_remove(PINNED_ATOM_OUT, disable=DISABLE_REMOVE) pass
def testFirstIni(self): test_input = ["-c", DEF_INI, "-a", "-o", 'pet_mono_f1hs_0.pdb'] try: main(test_input) self.assertFalse(diff_lines(ALT_PDB_OUT, GOOD_PDB_FIRST_OUT)) finally: silent_remove(ALT_PDB_OUT, disable=DISABLE_REMOVE) pass
def testSaveSmi(self): try: test_input = ["-r", "10", "-o", TEST_SMI_BASENAME, "-d", SUB_DATA_DIR, "-a", "1.0"] main(test_input) self.assertFalse(diff_lines(TEST_SMI_OUT, GOOD_TEST_SMI_OUT)) finally: silent_remove(TEST_SMI_OUT, disable=DISABLE_REMOVE) pass
def testTCLGenOptions(self): try: test_input = ["-r", "8", "-i", "4", "-m", "4", "-f", "tcl", "-d", SUB_DATA_DIR, "--chain_id", "1", "--psf_fname", "birch", "--toppar_dir", "", "-a", "1.0", "-x"] main(test_input) self.assertFalse(diff_lines(DEF_TCL_OUT, GOOD_TCL_OPTIONS_OUT)) finally: silent_remove(DEF_TCL_OUT, disable=DISABLE_REMOVE) pass
def testDirInBasename(self): # This should ignore the temp_dir; will throw error if it doesn't try: test_input = ["-r", "10", "-o", TEST_SMI_OUT, "-d", TEMP_DIR, "-a", "1.0"] main(test_input) self.assertFalse(diff_lines(TEST_SMI_OUT, GOOD_TEST_SMI_OUT)) finally: silent_remove(TEST_SMI_OUT, disable=DISABLE_REMOVE) pass
def testMixMatchTheory(self): test_input = [UNI_REACT, UNI_TS] try: # main(test_input) with capture_stderr(main, test_input) as output: self.assertTrue("Different basis sets" in output) finally: silent_remove(GOODVIBES_CSV, disable=DISABLE_REMOVE) pass
def testFirstOnly(self): test_input = ["-c", MULTI_FIRST_ONLY_INI] try: main(test_input) self.assertFalse(diff_lines(REMOVE_H_OUT1, GOOD_KEEP_H_OUT1)) self.assertFalse(diff_lines(GAU_OUT1, GOOD_GAU_OUT1)) finally: silent_remove(REMOVE_H_OUT1, disable=DISABLE_REMOVE) silent_remove(GAU_OUT1, disable=DISABLE_REMOVE)