def testBasicUse(self): silent_remove(SUB_SUB_DIR, dir_with_files=True) make_dir(SUB_SUB_DIR) fname_after_run = os.path.join(SUB_SUB_DIR, 'for_hartree', 'pet_mono_637_tzvp.log') silent_remove(fname_after_run) file1_to_copy = os.path.join(SUB_DATA_DIR, 'pet_mono_637_tzvp.tpl') temp_fname1 = os.path.join(SUB_SUB_DIR, 'pet_mono_637_tzvp.log') file2_to_copy = os.path.join(SUB_DATA_DIR, 'me2propprpnt_7.log') temp_fname2 = os.path.join(SUB_SUB_DIR, 'me2propprpnt_7.log') file3_to_copy = os.path.join(SUB_DATA_DIR, 'pet_mono_671_tzvp.log') temp_fname3 = os.path.join(SUB_SUB_DIR, 'pet_mono_671_tzvp.log') good_output = "The following files completed normally:\n" \ " tests/test_data/check_gauss/temp_dir/pet_mono_637_tzvp.log\n" \ "The following files may have failed:\n" \ " tests/test_data/check_gauss/temp_dir/me2propprpnt_7.log\n" \ "The following files may still be running:\n" \ " tests/test_data/check_gauss/temp_dir/pet_mono_671_tzvp.log\n" try: copyfile(file1_to_copy, temp_fname1) copyfile(file2_to_copy, temp_fname2) copyfile(file3_to_copy, temp_fname3) test_input = ["-d", SUB_SUB_DIR] # main(test_input) with capture_stdout(main, test_input) as output: self.assertTrue(good_output in output) self.assertTrue(os.path.isfile(fname_after_run)) finally: silent_remove(SUB_SUB_DIR, dir_with_files=True, disable=DISABLE_REMOVE) pass
def testFewerMaxThanIniMonos(self): test_input = ["-r", "10", "-i", "6", "-m", "4"] # main(test_input) with capture_stderr(main, test_input) as output: self.assertTrue('is less than' in output) with capture_stdout(main, test_input) as output: self.assertTrue("Lignin KMC created 6 monomers" in output)
def testCP(self): test_input = [TEST_LOG5, "--cpu"] # main(test_input) with capture_stderr(main, test_input) as output: self.assertTrue("Could not find frequency" in output) with capture_stdout(main, test_input) as output: self.assertTrue("0 days 0 hrs 27 mins 11 secs" in output)
def testNoArgs(self): with capture_stderr(main, []) as output: self.assertTrue( "WARNING: Problems reading file: Could not read file" in output) with capture_stdout(main, []) as output: self.assertTrue("optional arguments" in output)
def testImplicitWaterVib(self): # Baseline of scaling ZPE and harmonic the same test_input = [TEST_LOG6, "-v", "0.9871", "-f", "0"] # main(test_input) with capture_stdout(main, test_input) as output: self.assertTrue("-229.096161 0.061241 -229.029384 0.032761 0.032761 -229.062144 " "-229.062144" in output)
def testNoSMI(self): test_input = ['-t', GAU_TPL] # main(test_input) with capture_stderr(main, test_input) as output: self.assertTrue("SMILES " in output) with capture_stdout(main, test_input) as output: self.assertTrue("optional arguments" in output)
def testImplicitWaterVibZPEDiff(self): # Only change is to the ZPE test_input = [TEST_LOG6, "-v", "0.9871", "-f", "0", "-z", "0.9754"] # main(test_input) with capture_stdout(main, test_input) as output: self.assertTrue("-229.096161 0.060515 -229.029384 0.032761 0.032761 -229.062144 " "-229.062144" in output)
def testNoArgs(self): test_input = [] # main(test_input) with capture_stderr(main, test_input) as output: self.assertTrue("required" in output) with capture_stdout(main, test_input) as output: self.assertTrue("optional arguments" in output)
def testHelp(self): test_input = ['-h'] # main(test_input) with capture_stderr(main, test_input) as output: self.assertFalse(output) with capture_stdout(main, test_input) as output: self.assertTrue("optional arguments" in output)
def testImplicitWaterAltTemp(self): # checking that results equal those from Gaussian--they do! test_input = [TEST_LOG6, "-v", "1.0", "-f", "0", "-t", "788.15"] # main(test_input) with capture_stdout(main, test_input) as output: self.assertTrue("-229.096161 0.062042 -229.010117 0.114078 0.114078 -229.124195 " "-229.124195" in output)
def testSortByEnthalpy(self): test_input = ["-l", LOG_LIST, '-n'] good_output = ''.join([HEADER, LME2_TS3, LME2_25_T]) + '\n' with capture_stdout(main, test_input) as output: self.assertTrue(good_output in output) with capture_stderr(main, test_input) as output: self.assertTrue('Check convergence' in output)
def testImplicitWater(self): # checking that results equal those from Gaussian--they do! test_input = [TEST_LOG6, "-v", "1.0", "-f", "0"] # main(test_input) with capture_stdout(main, test_input) as output: self.assertTrue("-229.096161 0.062042 -229.028612 0.032709 0.032709 -229.061321 " "-229.061321" in output)
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 get_gauss_results(options, unique_fnames): """ Run hartree and goodvibes only once per file name :param options: user-specified options, used here to determine goodvibes input :param unique_fnames: a set of unique file names (really, file locations) :return: results_dict: dictionary of results from running hartree and goodvibes """ results_dict = defaultdict(dict) for fname in unique_fnames: if fname != REACT_PROD_SEP: base_name = os.path.basename(fname) gauss_results = hartree.read_gaussian(fname) solvent = gauss_results.getSolvent() results_dict[base_name][HARTREE_OUT] = gauss_results results_dict[base_name][SOLV] = solvent results_dict[base_name][FREQS] = gauss_results.getFrequencyValues() # later, a regex will be performed on STOICH, and it will expect a standard string, not a java.lang.String results_dict[base_name][STOICH] = str( gauss_results.getStoichiometry()) vibes_input = [ fname, "--ti", options.temp_range, "-f", options.freq_cutoff ] if solvent: vibes_input += ["-c", "1"] if options.quasiharmonic: vibes_input += ["-q"] if options.vib_scale: vibes_input += ["-v", str(options.vib_scale)] with capture_stdout(gaussian_wrangler.goodvibes_hm.main, vibes_input) as output: results_dict[base_name][GOODVIBES_OUT] = output.split('\n') return results_dict
def testHelp(self): test_input = ['-h'] if logger.isEnabledFor(logging.DEBUG): main(test_input) with capture_stderr(main, test_input) as output: self.assertFalse(output) with capture_stdout(main, test_input) as output: self.assertTrue("optional arguments" in output)
def testUnknownArg(self): test_input = ['--ghost'] if logger.isEnabledFor(logging.DEBUG): main(test_input) with capture_stderr(main, test_input) as output: self.assertTrue("unrecognized arguments" in output) with capture_stdout(main, test_input) as output: self.assertTrue("optional arguments" in output)
def testListFinalConvergence(self): test_input = ["-l", LIST_FILE, "-z"] # main(test_input) good_out = 'File Name Convergence Convergence_Error\n' \ 'hexyl_acrylate_239.log 1.1100 False\n' \ 'hexyl_acrylate_419.log 0.0706 False\n' with capture_stdout(main, test_input) as output: self.assertTrue(good_out in output)
def testAltIniMaxMonosSimLen(self): test_input = ["-r", "10", "-i", "8", "-m", "12", "-l", "0.02", "-a", "1.0"] # main(test_input) good_smiles = "COc1cc(/C=C/CO)cc(OC)c1O.COc1cc(C2OCC3C(c4cc(OC)c([O])c(Oc5c(OC)cc(C6Oc7c(OC)cc(/C=C/CO)cc7C6" \ "CO)cc5OC)c4)OCC23)ccc1O.COc1cc(C2Oc3c(OC)cc(/C=C/CO)cc3C2CO)cc(OC)c1O.COc1cc(C2Oc3c(OC)cc(/C=C" \ "/CO)cc3C2CO)ccc1O" with capture_stdout(main, test_input) as output: self.assertTrue(good_smiles in output)
def testUnrecognizedArg(self): test_input = ["-c", DEF_INI, "--ghost"] # main(test_input) if logger.isEnabledFor(logging.DEBUG): main(test_input) with capture_stderr(main, test_input) as output: self.assertTrue("unrecognized arguments" in output) with capture_stdout(main, test_input) as output: self.assertTrue("optional arguments" in output)
def testWrongKey(self): test_input = ['-ghost'] if logger.isEnabledFor(logging.DEBUG): main(test_input) with capture_stderr(main, test_input) as output: self.assertTrue("unrecognized arguments" in output) with capture_stdout(main, test_input) as output: self.assertTrue("optional arguments" in output) silent_remove(FOR_HARTREE_DIR, disable=DISABLE_REMOVE)
def testAltSGRatio(self): test_input = ["-r", "8", "-sg", "2.5", "-a", "1.0"] # main(test_input) good_smiles = "COc1cc(C(O)C(CO)Oc2c(OC)cc(C(O)C(CO)Oc3c(OC)cc(C(O)C(CO)Oc4c(OC)cc(C5OCC6C(c7cc(OC)c(OC(CO)" \ "C(O)c8cc(OC)c(OC(CO)C(O)c9cc(OC)c(OC(CO)C(O)c%10cc(OC)c(OC(CO)C(O)c%11cc(OC)c%12c(c%11)C(CO)" \ "C(c%11cc(OC)c([O])c(OC)c%11)O%12)c(OC)c%10)c(OC)c9)c(OC)c8)c(OC)c7)OCC56)cc4OC)cc3OC)cc2OC)" \ "cc(OC)c1[O]" with capture_stdout(main, test_input) as output: self.assertTrue(good_smiles in output)
def testNoFreq(self): # also tests that it can skip a blank line test_input = ["-l", LIST_NO_FREQ, "-n"] good_output = ''.join([HEADER, LME2_25_T, LME2_TS3_NO_FREQ]) + '\n' main(test_input) with capture_stdout(main, test_input) as output: self.assertTrue(good_output in output) with capture_stderr(main, test_input) as output: self.assertFalse('Check convergence' in output)
def testBadConfigFile(self): test_input = ["-c", "ghost.ini"] # main(test_input) if logger.isEnabledFor(logging.DEBUG): main(test_input) with capture_stderr(main, test_input) as output: self.assertTrue("Could not find specified configuration file" in output) with capture_stdout(main, test_input) as output: self.assertTrue("optional arguments" in output)
def testNoneFloatVib(self): test_input = ["-l", TPA_LIST, "-d", SUB_DATA_DIR, "-t", "-v", "ghost"] # main(test_input) if logger.isEnabledFor(logging.DEBUG): main(test_input) with capture_stderr(main, test_input) as output: self.assertTrue("not convert string" in output) with capture_stdout(main, test_input) as output: self.assertTrue("optional arguments" in output)
def testHelp(self): test_input = ['-h'] if logger.isEnabledFor(logging.DEBUG): main(test_input) with capture_stderr(main, test_input) as output: self.assertFalse(output) with capture_stdout(main, test_input) as output: self.assertTrue("optional arguments" in output) silent_remove(FOR_HARTREE_DIR, disable=DISABLE_REMOVE)
def testSortByEnthalpyWithCutoff(self): test_input = ["-l", LOG_LIST, '-n', "-m", "1.0"] good_output = (DIFF_HEADER + '"Files within enthalpy cutoff of 1.00 kcal/mol"\n' + LME2_TS3[:-1] + ',0.00\n' + LME2_25_T[:-1] + ',0.01') try: with capture_stdout(main, test_input) as output: self.assertTrue(good_output in output) finally: silent_remove(DEF_OUT_NAME)
def testTempRangeVibConcQAltInput(self): test_input = [TEST_LOG2, "-t", "788.15", "-v", "0.984", "-c", "1", "--ti", "688.15,888.15,25", "-q"] # main(test_input) with capture_stdout(main, test_input) as output: self.assertTrue("688.15 -839.735116 -839.741128 0.212003 0.200263 -839.947119 " "-839.941391" in output) self.assertTrue("788.15 -839.717088 -839.723965 0.261737 0.247365 -839.978825 " "-839.971331" in output) self.assertTrue("888.15 -839.698000 -839.705743 0.314850 0.297737 -840.012851 " "-840.003480" in output)
def testTempRangeVibConcQ(self): test_input = [TEST_LOG1, "-t", "788.15", "-v", "0.984", "-c", "1", "--ti", "688.15,888.15,25", "-q"] # main(test_input) with capture_stdout(main, test_input) as output: self.assertTrue("688.15 -230.149803 -230.150097 0.093304 0.093023 -230.243107 " "-230.243121" in output) self.assertTrue("788.15 -230.144250 -230.144585 0.112457 0.112093 -230.256708 " "-230.256677" in output) self.assertTrue("888.15 -230.138332 -230.138708 0.132665 0.132210 -230.270997 " "-230.270918" in output)
def testTempRangeVibQ(self): test_input = [TEST_LOG1, "-t", "788.15", "-v", "0.984", "--ti", "688.15,888.15,25", "-q"] # main(test_input) with capture_stdout(main, test_input) as output: self.assertTrue("688.15 -230.149803 -230.150097 0.102094 0.101814 -230.251897 " "-230.251911" in output) self.assertTrue("788.15 -230.144250 -230.144585 0.122864 0.122499 -230.267114 " "-230.267084" in output) self.assertTrue("888.15 -230.138332 -230.138708 0.144728 0.144273 -230.283060 " "-230.282981" in output)
def testTempRangeVib(self): test_input = [TEST_LOG1, "-t", "788.15", "-v", "0.984", "--ti", "688.15,888.15,25"] # main(test_input) with capture_stdout(main, test_input) as output: self.assertTrue("688.15 -230.149803 0.102094 0.101814 -230.251897 " "-230.251617" in output) self.assertTrue("788.15 -230.144250 0.122864 0.122499 -230.267114 " "-230.266749" in output) self.assertTrue("888.15 -230.138332 0.144728 0.144273 -230.283060 " "-230.282605" in output)