def test_eth_00_ras22(self): rasci = dict(self.rem) if do_alpha_beta: rasci.update({'ras_elec_alpha': 1, 'ras_elec_beta': 1}) # create qchem input txt_input = create_qchem_input(self.molecule, **rasci) # calculate and parse qchem output output = get_output_from_qchem(txt_input, processors=4, store_full_output=True, force_recalculation=recalculate) data = parser_rasci(output) filename = self.__class__.__name__ + '_ras22.yaml' # create reference file if ctrl_print: with open(filename, 'w') as outfile: yaml.dump(data, outfile, default_flow_style=False, allow_unicode=True) with open(filename, 'r') as stream: data_loaded = yaml.load(stream, Loader=yaml.Loader) data = standardize_dictionary(data, decimal=2) #print(data) print(data_loaded) data_loaded = standardize_dictionary(data_loaded, decimal=2) self.assertDictEqual(data, data_loaded)
def setUp(self): self.assertDictEqual.__self__.maxDiff = None # generate molecule molecule = Structure(coordinates=[[0.0, 1.0, 0.0], [0.0, 0.0, 1.0], [0.0, 0.0, -1.0]], symbols=['O', 'H', 'H'], charge=0, multiplicity=1) # optimization txt_input = create_qchem_input(molecule, jobtype='opt', exchange='hf', basis='sto-3g', geom_opt_tol_gradient=300, geom_opt_tol_energy=100, geom_opt_coords=-1, geom_opt_tol_displacement=1200) parsed_data = get_output_from_qchem(txt_input, processors=4, parser=basic_optimization, force_recalculation=recalculate, store_full_output=True) self.molecule = parsed_data['optimized_molecule']
def test_srdft(self): # create qchem input qc_input = create_qchem_input( self.molecule, jobtype='sp', exchange='hf', correlation='rasci', basis='6-31G(d,p)', ras_act=2, ras_elec=2, ras_spin_mult=0, ras_roots=2, ras_do_hole=True, ras_sts_tm=True, # rasci sr-dft ras_omega=400, ras_srdft_cor='srpw92', ras_srdft_exc='srpbe', ras_natorb=False, set_iter=30, ras_srdft_damp=0.5) #from pyqchem.cache import SqlCache as CacheSystem #cache = CacheSystem() #cache.list_database() #output = cache.retrieve_calculation_data(qc_input, 'fullout') #print(output) # calculate and parse qchem output output = get_output_from_qchem(qc_input, processors=4, force_recalculation=recalculate, store_full_output=True) print(output) data = parser_rasci(output) filename = dir_path + '/' + self.__class__.__name__ + '_srdft.yaml' if remake_tests: with open(filename, 'w') as outfile: yaml.dump(data, outfile, default_flow_style=False, allow_unicode=True) data = standardize_dictionary(data, decimal=2) with open(filename, 'r') as stream: data_loaded = yaml.load(stream, Loader=yaml.Loader) print(data_loaded) data_loaded = standardize_dictionary(data_loaded, decimal=2) self.assertDictEqual(data, data_loaded)
def test_srdft(self): # create qchem input txt_input = create_qchem_input( self.molecule, jobtype='sp', exchange='hf', correlation='rasci', basis='6-31G(d,p)', ras_act=4, ras_elec=4, ras_spin_mult=0, ras_roots=6, ras_do_hole=True, ras_sts_tm=True, # rasci sr-dft ras_omega=300, ras_srdft_cor='srpbe', ras_srdft_exc='srlsda', ras_natorb=False, set_iter=30, ras_srdft_damp=0.5) print(txt_input.get_txt()) # calculate and parse qchem output output = get_output_from_qchem(txt_input, processors=4, force_recalculation=recalculate, store_full_output=True) print(output) data = parser_rasci(output) print(data) filename = dir_path + '/' + self.__class__.__name__ + '_srdft.yaml' if remake_tests: with open(filename, 'w') as outfile: yaml.dump(data, outfile, default_flow_style=False, allow_unicode=True) data = standardize_dictionary(data) with open(filename, 'r') as stream: data_loaded = yaml.load(stream, Loader=yaml.Loader) print(data_loaded) data_loaded = standardize_dictionary(data_loaded) self.assertDictEqual(data, data_loaded)
def test_rasci(self): # create qchem input txt_input = create_qchem_input(self.molecule, jobtype='sp', exchange='hf', correlation='rasci', basis='sto-3g', ras_act=4, ras_elec=4, ras_spin_mult=1, ras_roots=6, ras_print=5, ras_do_hole=True, ras_sts_tm=True) # calculate and parse qchem output output = get_output_from_qchem(txt_input, processors=4, force_recalculation=recalculate, store_full_output=True) print(output) data = parser_rasci(output) print(data) filename = dir_path + '/' + self.__class__.__name__ + '_rasci.yaml' if remake_tests: with open(filename, 'w') as outfile: yaml.dump(data, outfile, default_flow_style=False, allow_unicode=True) data = standardize_dictionary(data, decimal=2) with open(filename, 'r') as stream: data_loaded = yaml.load(stream, Loader=yaml.Loader) print(data_loaded) data_loaded = standardize_dictionary(data_loaded, decimal=2) self.assertDictEqual(data, data_loaded)
def test_eth_00_ras44(self): rasci = dict(self.rem) rasci.update({'ras_act': 4, 'ras_elec': 4, 'ras_occ': 6}) if do_alpha_beta: rasci.update({'ras_elec_alpha': 2, 'ras_elec_beta': 2}) # create qchem input txt_input = create_qchem_input(self.molecule, **rasci) # calculate and parse qchem output output = get_output_from_qchem(txt_input, processors=4) print(output) data = basic_rasci(output) print(data) filename = self.__class__.__name__ + '_ras44.yaml' # creat reference file if ctrl_print: with open(filename, 'w') as outfile: yaml.dump(data, outfile, default_flow_style=False, allow_unicode=True) with open(filename, 'r') as stream: data_loaded = yaml.safe_load(stream) data = standardize_dictionary(data) print(data_loaded) data_loaded = standardize_dictionary(data_loaded) self.assertDictEqual(data, data_loaded)
coordinates = [[0.0, 1.0, 0.0], [0.0, 0.0, 1.0], [0.0, 0.0, -1.0]] symbols = ['O', 'H', 'H'] molecule = Structure(coordinates=coordinates, symbols=symbols, charge=0, multiplicity=1) print('Initial structure') print(molecule) # calculation qc_input = create_qchem_input(molecule, jobtype='freq', exchange='hf', basis='sto-3g') out, electronic_structure = get_output_from_qchem( qc_input, processors=4, read_fchk=True, force_recalculation=True, remote=remote_data, # Set remote data parser=basic_frequencies) # Show output print(out) # Show Electronic structure data print(electronic_structure)
molecule = Structure(coordinates=[[0.0, 0.0, 0.0]], symbols=[atom], charge=0) parameters.update({'ras_omega': int(omega)}) gap_list = [] for ispin in [True, False]: print(ispin) parameters.update({'ras_srdft_spinpol': ispin}) # singlet parameters.update({'ras_spin_mult': 1}) txt_input = create_qchem_input(molecule, **parameters) data_singlet = get_output_from_qchem(txt_input, processors=4, parser=basic_parser_qchem) # triplet parameters.update({'ras_spin_mult': 3}) txt_input = create_qchem_input(molecule, **parameters) data_triplet = get_output_from_qchem(txt_input, processors=4, parser=basic_parser_qchem) gap = data_triplet['excited states'][0][ 'total energy'] - data_singlet['excited states'][0][ 'total energy'] gap_list.append(gap) except:
coordinates[6:, 1] = coordinates[6:, 1] + slide_y coordinates[6:, 2] = coordinates[6:, 2] + slide_z molecule = Structure(coordinates=coordinates, symbols=[ 'C', 'C', 'H', 'H', 'H', 'H', 'C', 'C', 'H', 'H', 'H', 'H' ], charge=0) txt_input = create_qchem_input(molecule, **parameters) # print(txt_input) data = get_output_from_qchem(txt_input, processors=4, force_recalculation=False, parser=basic_parser_qchem) # if closed shell ocup_orb = (np.sum(molecule.get_atomic_numbers()) - molecule.charge) // 2 n_states = 2 # get list of interesting states interesting_transitions = [] for i, state in enumerate(data['excited states cis']): for transition in state['transitions']: if transition['origin'] > ocup_orb - n_states and transition[ 'target'] <= n_states: interesting_transitions.append([ i + 1, transition['origin'], transition['target'],
symbols=symbols_monomer, charge=0, multiplicity=1) # optimization qchem input qc_input = QchemInput(monomer, jobtype='opt', exchange='hf', basis='sto-3g', geom_opt_tol_gradient=300, geom_opt_tol_energy=100, geom_opt_coords=-1, geom_opt_tol_displacement=1200) parsed_data = get_output_from_qchem(qc_input, processors=4, parser=basic_optimization) opt_monomer = parsed_data['optimized_molecule'] print('Optimized monomer structure') print(opt_monomer) # Build dimer from monomer coor_monomer2 = np.array(opt_monomer.get_coordinates()) coor_monomer2[:, 2] += 4.0 # monomers separation coordinates = opt_monomer.get_coordinates() + coor_monomer2.tolist() symbols_dimer = symbols_monomer * 2 dimer = Structure(coordinates=coordinates,
jobtype='sp', exchange='hf', basis='sto-3g', unrestricted=True, solvent_method='pcm', solvent_params={'Dielectric': 8.93}, # Cl2CH2 pcm_params={'Theory': 'CPCM', 'Method': 'SWIG', 'Solver': 'Inversion', 'Radii': 'Bondi'} ) data, electronic_structure = get_output_from_qchem(qc_input, force_recalculation=True, processors=4, parser=basic_parser_qchem, read_fchk=True) print('scf energy', data['scf_energy'], 'H') print('Orbital energies (H)') print(' {:^10} {:^10}'.format('alpha', 'beta')) for a, b in zip(data['orbital_energies']['alpha'], data['orbital_energies']['beta']): print('{:10.3f} {:10.3f}'.format(a, b)) print('dipole moment:', data['multipole']['dipole_moment'], data['multipole']['dipole_units']) print('quadrupole moment ({}):\n'.format(data['multipole']['quadrupole_units']), np.array(data['multipole']['quadrupole_moment'])) print('octopole moment ({}):\n'.format(data['multipole']['octopole_units']),
molecule.get_coordinates() print('optimize molecule') txt_input = create_qchem_input(molecule, jobtype='opt', method='b3lyp', basis='cc-pVDZ', geom_opt_tol_gradient=50, geom_opt_coords=-1, geom_opt_tol_displacement=800) parsed_data = get_output_from_qchem(txt_input, processors=4, use_mpi=True, parser=basic_optimization, force_recalculation=False) #parsed_data = basic_optimization(data) opt_molecule = parsed_data['optimized_molecule'] print(opt_molecule) print('calculate frequencies') txt_input = create_qchem_input( opt_molecule, jobtype='freq', method='b3lyp', basis='cc-pVDZ', )
exchange='b3lyp', basis=basis_name, cis_n_roots=8, cis_singlets=True, cis_triplets=True, cis_convergence=8, calc_soc=1, n_frozen_core=0, ) for qc_input, parser in [(qc_input_cis, parser_cis), (qc_input_rasci, parser_rasci)]: output = get_output_from_qchem(qc_input, processors=4, force_recalculation=False, parser=parser, store_full_output=True) # print calculation data for i, state in enumerate(output['excited_states']): print('Energy state {} ({}): {: 18.12f} au'.format( i + 1, state['multiplicity'], state['total_energy'])) for j, conf in enumerate(state['configurations']): try: print(' Origin Target Amplitude') print(' {} {} {:8.3f}'.format(conf['origin'], conf['target'], conf['amplitude'])) except KeyError: print(' Alpha Beta Amplitude')
[1.21479, 0.70136, 0.00000], [2.15666, 1.24515, 0.00000]] symbols = ['C', 'H', 'C', 'H', 'C', 'H', 'C', 'H', 'C', 'H', 'C', 'F'] benzene_coordinates = np.array(benzene_coordinates) molecule = Structure(coordinates=benzene_coordinates, symbols=symbols, charge=0) parameters = {'jobtype': 'sp', 'exchange': 'hf', 'basis': '6-31G'} qc_input = create_qchem_input(molecule, **parameters) _, _, fchk_data = get_output_from_qchem(qc_input, processors=4, force_recalculation=True, read_fchk=True) from pyqchem.file_io import build_fchk open('test.fchk', 'w').write(build_fchk(fchk_data)) mo_coeff = _set_zero_to_coefficients(fchk_data['basis'], fchk_data['coefficients'], range(6, 12)) fchk_data['coefficients'] = mo_coeff structure = fchk_data['structure'] print(structure.get_xyz()) txt_fchk = build_fchk(fchk_data) open('test2.fchk', 'w').write(txt_fchk)
# create qchem input qc_input = QchemInput(molecule, jobtype='sp', exchange='b3lyp', unrestricted=False, basis='sto-3g', cis_n_roots=4, cis_convergence=14, cis_singlets=True, cis_triplets=True) # calculate and parse qchem output data = get_output_from_qchem( qc_input, processors=4, parser=basic_cis, store_full_output=True, ) # store energies of excited states states in list energies.append( [data['scf_energy']] + [state['total_energy'] for state in data['excited_states']]) multiplicity_list = ['Singlet'] + [ state['multiplicity'] for state in data['excited_states'] ] # transform energy list in array energies = np.array(energies)
molecule = Structure(coordinates=dimer_ethene, symbols=symbols, charge=0, multiplicity=1) # create Q-Chem input qc_input = create_qchem_input(molecule, jobtype='sp', exchange='hf', basis='6-31G') print(qc_input.get_txt()) # get data from Q-Chem calculation output, electronic_structure = get_output_from_qchem(qc_input, processors=4, force_recalculation=False, read_fchk=True, fchk_only=True) # store original fchk info in file open('test.fchk', 'w').write(build_fchk(electronic_structure)) # get symmetry classification electronic_structure_f1 = crop_electronic_structure(electronic_structure, range_f1) # save test fchk file with new coefficients open('test_f1.fchk', 'w').write(build_fchk(electronic_structure_f1)) # get plane from coordinates coordinates_f1 = electronic_structure['structure'].get_coordinates(
txt_input_freq = create_qchem_input( molecule, jobtype='freq', gui=Test.gui, basis=Test.basis, method=Test.method, max_scf_cycles=Test.max_scf_cycles, geom_opt_max_cycles=Test.geom_opt_max_cycles, scf_convergence=Test.scf_convergence) # The get_output_from_qchem has the added ability of being able to parsed through data if needed try: output = get_output_from_qchem(txt_input, processors=8, force_recalculation=True, store_full_output=True) parsed_data = get_output_from_qchem(txt_input_freq, processors=4, parser=basic_frequencies) except OutputError as e: output = 'Error' print("Calculation ended with errors. Error lines: ") print(e.error_lines) output_filename = args["inputXYZfile"].replace('.xyz', '{}.out'.format(x)) freq_file = output_filename freq_file = freq_file.replace('{}.out'.format(x), 'Freq{}.txt'.format(x))
# create molecule molecule = Structure(coordinates=benzene_coordinates, symbols=symbols, charge=0, multiplicity=1) # define Q-Chem parameters parameters = {'jobtype': 'sp', 'exchange': 'hf', 'basis': '6-31G'} # create Q-Chem input qc_input = create_qchem_input(molecule, **parameters) # get data from Q-Chem calculation output, parsed_fchk = get_output_from_qchem(qc_input, processors=4, force_recalculation=False, read_fchk=True, fchk_only=True) # write .fchk file copy on disk (for checking purpose) txt_fchk = build_fchk(parsed_fchk) open('test_benzene.fchk', 'w').write(txt_fchk) # get orbital type orbital_types = get_orbital_classification(parsed_fchk, center=[0.0, 0.0, 0.0], orientation=[0.0, 0.0, 1.0]) # print results print(' {:5} {:5} {:5}'.format('num', 'type', 'overlap')) for i, ot in enumerate(orbital_types):
symbols=['Se', 'H'], charge=-1, multiplicity=1) # Standard input using 6-31G basis qc_input = QchemInput(molecule, jobtype='sp', exchange='hf', basis='6-31G') # print input print(qc_input.get_txt()) output, electronic_structure = get_output_from_qchem(qc_input, processors=4, force_recalculation=False, read_fchk=True, parser=basic_parser_qchem, store_full_output=False) print('scf_energy 6-31G: ', output['scf_energy']) basis_custom = electronic_structure['basis'] # Standard input using a custom basis obtained from previous calculation qc_input = QchemInput(molecule, jobtype='sp', exchange='hf', basis=basis_custom) output = get_output_from_qchem(qc_input,
basis=basis_custom_repo, ras_elec_alpha=active_spaces['triplet'][0][0], ras_elec_beta=active_spaces['triplet'][0][1], ras_act=active_spaces['triplet'][1], ras_occ=active_spaces['triplet'][2], ras_spin_mult=0, ras_roots=10, calc_soc=1, n_frozen_core=0, set_iter=1000, mem_total=15000, mem_static=900) output_s = get_output_from_qchem( qc_input_s, processors=4, force_recalculation=False, # parser=parser_rasci, store_full_output=True) # print(output_s) with open('qchem_output_{}.out'.format(atom.name), 'w') as f: f.write(output_s) output_s = parser_rasci(output_s) output_t = get_output_from_qchem(qc_input_t, processors=4, force_recalculation=False, parser=parser_rasci, store_full_output=True) print('\n---------------------------------------------')
qc_input = QchemInput(molecule, jobtype='sp', exchange='hf', correlation='rasci', basis='sto-3g', ras_act=2, ras_elec=2, ras_spin_mult=0, ras_roots=2, ras_do_part=False, ras_do_hole=False) # calculate and parse qchem output data = get_output_from_qchem( qc_input, processors=4, parser=parser_rasci, store_full_output=True, ) # store energies of excited states states in list energies.append( [state['total_energy'] for state in data['excited_states']]) multiplicity_list = [state['multiplicity'] for state in data['excited_states']] # transform energy list in array energies = np.array(energies) # print energies print('\ndistance state 1 state 2') print('----------------------------')
jobtype='sp', exchange='b3lyp', basis=basis_name, cis_n_roots=8, cis_singlets=True, cis_triplets=True, cis_convergence=8, calc_soc=1, n_frozen_core=0, ) for qc_input, parser in [(qc_input_cis, parser_cis), (qc_input_rasci, parser_rasci)]: output = get_output_from_qchem(qc_input, processors=4, force_recalculation=True, parser=parser, ) # print calculation data for i, state in enumerate(output['excited_states']): print('Energy state {} ({}): {:18.12f} au'.format(i+1, state['multiplicity'], state['total_energy'])) print('Transition energy {:4.8} eV'.format(state['excitation_energy'])) if qc_input is qc_input_cis: print(' Origin Target Amplitude') else: print(' Alpha Beta Amplitude') for j, conf in enumerate(state['configurations']): try: print(' {} {} {:8.3f}'.format(conf['origin'], conf['target'], conf['amplitude']))
ras_elec=2, ras_spin_mult=0, ras_roots=2, ras_do_part=False, ras_do_hole=False, # ras_srdft_spinpol=True, ras_omega=400, max_scf_cycles=100, ras_srdft_cor='srPBE', # ras_srdft_exc='srPBE' ) # calculate and parse qchem output data, ee = get_output_from_qchem(qc_input, processors=3, parser=parser_rasci, read_fchk=True, # store_full_output=True, ) guess = ee['coefficients'] # store energies of excited states states in list energies.append([state['total_energy'] for state in data['excited_states']]) multiplicity_list = [state['multiplicity'] for state in data['excited_states']] # transform energy list in array energies = np.array(energies) # print energies print('\ndistance state 1 state 2')
multiplicity=1) print('Initial structure') print(molecule) # optimization qc_input = create_qchem_input(molecule, jobtype='opt', exchange='hf', basis='sto-3g', geom_opt_tol_gradient=300, geom_opt_tol_energy=100, geom_opt_coords=-1, geom_opt_tol_displacement=1200) parsed_data, electronic_structure = get_output_from_qchem( qc_input, processors=4, parser=basic_optimization, read_fchk=True) opt_molecule = parsed_data['optimized_molecule'] print('Optimized structure') print(opt_molecule) # frequencies calculation qc_input = create_qchem_input(opt_molecule, jobtype='freq', exchange='hf', basis='sto-3g', scf_guess=electronic_structure['coefficients']) parsed_data = get_output_from_qchem(qc_input, processors=4,
ras_spin_mult=1, # singlets only ras_roots=8, ras_do_hole=False, ras_do_part=False, ras_diabatization_states=[3, 4, 5, 6 ], # adiabatic states selected for diabatization ras_diabatization_scheme=diabatization_scheme, ) print(qc_input.get_txt()) # get data from Q-Chem calculation output, err, electronic_structure = get_output_from_qchem( qc_input, processors=4, force_recalculation=False, read_fchk=True, parser=parser_rasci, store_full_output=True) def is_equal(conf1, conf2): lv = [] for prop in ['alpha', 'beta', 'hole', 'part']: lv.append(conf1[prop] == conf2[prop]) return np.all(lv) def unify_configurations(configurations_list): new_configurations = []
molecule, parser_info = get_molecule(slide_d, slide_y, slide_z) # print molecule (xyz style) print(molecule.get_number_of_atoms()) print('dist: {} y: {} z: {}'.format(slide_d, slide_y, slide_z)) for s, c in zip(molecule.get_symbols(), molecule.get_coordinates()): print('{:2} '.format(s) + '{:10.8f} {:10.8f} {:10.8f}'.format(*c)) txt_input = create_qchem_input(molecule, **parameters) # calculate and parse CIS data data = get_output_from_qchem( txt_input, processors=4, force_recalculation=args.force_recalculation, parser=basic_parser_qchem) #a = data.find('Molecular Point Group') #print('Point group: {}'.format(data[a:a+50].split()[3])) #continue # get interesting states if args.origin is not None and args.target is not None: print('Using defined Orgin-Target orbitals with {} states'. format(args.n_states)) list_states = get_states_from_orbitals( data['excited states cis'], n_states=args.n_states, origin_orbitals=args.origin, target_orbitals=args.target) else: