Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Gaussian harness #442

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
c9c49a4
Create gaussian.py
QuChem Nov 29, 2023
70596ae
Update gaussian.py
QuChem Nov 29, 2023
b4c5d30
Cleaning gaussian.py
QuChem Nov 29, 2023
1aa3522
Removed the empty line
QuChem Nov 30, 2023
10ae387
implement cclib into gaussian.py
QuChem Dec 12, 2023
11fc097
Convert QCElemental inputs to Gaussian inputs
QuChem Dec 20, 2023
ee0dcb4
Convert QCElemental inputs to Gaussian inputs
QuChem Dec 20, 2023
f93420c
Add input generator
QuChem Jan 10, 2024
3050155
Improved the parse_output function
QuChem Jan 10, 2024
b1097be
Add versioning
QuChem Jan 18, 2024
a5265b6
Improved parse_output function
QuChem Jan 23, 2024
5d73c9f
the parse_output function extracts more data
QuChem Feb 1, 2024
6eb55e4
Cleaning gaussian.py
QuChem Feb 14, 2024
aad52cf
Create programs.py
QuChem Feb 16, 2024
ce55302
Add gaussian to base.py
QuChem Feb 16, 2024
0ccc8ef
Delete qcengine/programs.py
QuChem Mar 1, 2024
30e2579
Changed "Gaussian" to "gaussian"
QuChem Mar 14, 2024
d76c5e7
Try to handle .fchk file format in gaussian.py
QuChem Apr 11, 2024
95d16f0
Handle the fchk file in gaussian.py
QuChem Apr 12, 2024
61216dd
Dependency cclib check
QuChem Jun 12, 2024
a2ff5c8
gaussian.py encompasses g09 and g16
QuChem Jun 12, 2024
ab23bb6
Extract different energy values
QuChem Jul 15, 2024
5df8272
reordered the if-else statement
QuChem Jul 16, 2024
6377cb0
Add additional libraries to gaussian.py
QuChem Jan 16, 2025
c7c0c1c
Add major updates to most of the methos in gaussian.py
QuChem Jan 16, 2025
39d565a
Update parse_output method
QuChem Jan 29, 2025
1d04979
Update compute method
QuChem Jan 29, 2025
62b0b9b
Update build_input method
QuChem Jan 29, 2025
3ccdc93
Update the execute method
QuChem Jan 29, 2025
9c39b94
Update the parse_output method
QuChem Jan 31, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Improved parse_output function
QuChem authored Jan 23, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit a5265b651db9c5e87282a3a9d5e7b242092fe10c
97 changes: 41 additions & 56 deletions qcengine/programs/gaussian.py
Original file line number Diff line number Diff line change
@@ -38,7 +38,6 @@ class GaussianHarness(ProgramHarness):
class Config(ProgramHarness.Config):
pass


def found(self, raise_error: bool = False) -> bool:
return which(
"g09",
@@ -51,6 +50,7 @@ def get_version(self) -> str:
self.found(raise_error=True)

which_prog = which("g09")

v_input = '''%mem=20MW
#P HF/sto-3g

@@ -102,6 +102,7 @@ def compute(self, input_model: "AtomicInput", config: TaskConfig) -> "AtomicResu

if 'Error termination via ' in outfile:
raise InputError(proc['outfiles']['output.log'])

else:
# Return UnknownError for error propagation
raise UnknownError(proc["outfiles"]["output.log"])
@@ -112,25 +113,31 @@ def build_input(

# Build keywords
keywords = {k.upper(): v for k, v in input_model.keywords.items()}
keywords = {'scf_damp': 'true',
'scf_diis': 'false'
}

gaussian_kw = []

if input_model.driver == "energy":
keywords["JOBTYPE"] = "sp"
gaussian_kw.append("sp")
elif input_model.driver == "gradient":
keywords["JOBTYPE"] = "force"
gaussian_kw.append("force")
elif input_model.driver == "hessian":
keywords["JOBTYPE"] = "freq"
gaussian_kw.append("freq")
else:
raise InputError(f"Driver {input_model.driver} not implemented for Gaussian.")

if input_model.molecule.fix_com or input_model.molecule.fix_orientation:
keywords["SYM_IGNORE"] = "TRUE"

#if input_model.molecule.fix_com or input_model.molecule.fix_orientation:
# keywords["SYM_IGNORE"] = "TRUE"

Check notice

Code scanning / CodeQL

Commented-out code Note

This comment appears to contain commented-out code.
if 'SCF_CONVERGENCE' in keywords:
gaussian_kw.append('SCF=' + keywords["SCF_CONVERGENCE"])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is the name "SCF_CONVERGENCE" coming from? QCNG tends to want the same keyword names in AtIn.keywords as the experience user would use in the program natively. Is Conver=N on https://gaussian.com/scf/ ("Options" tab) what you're targeting?

if 'POPULATION' in keywords:
gaussian_kw.append('Pop=' + keywords['POPULATION'])

keywords = {'scf_damp': 'true',

Check notice

Code scanning / CodeQL

Unused local variable Note

Variable keywords is not used.
'scf_diis': 'false'}
# Begin input file
input_file = []
input_file.append('%mem={}MW'.format(int(config.memory * 1024 / 100))
input_file.append("#P {}/{}".format(input_model.model.method, input_model.model.basis) + '\n')
input_file.append('%mem={}MB'.format(int(config.memory * 1024)))
input_file.append("#P {}/{}".format(input_model.model.method, input_model.model.basis) + ' ' + ' '.join(gaussian_kw) + '\n')
input_file.append("write your comment here\n")

# Create a mol object
@@ -147,13 +154,14 @@ def build_input(
gaussian_ret = {
'infiles': {'input.inp': '\n'.join(input_file)},
'commands': [which("g09"), 'input.inp', 'output.log'],
'scratch_directory': config.scratch_directory
#'scratch_directory': config.scratch_directory
}

return gaussian_ret

def execute(self,
inputs,
*,
extra_outfiles: Optional[Dict[str, str]] = None,
extra_commands: Optional[List[str]] = None,
scratch_name = None,
@@ -184,65 +192,42 @@ def parse_output(self, outfiles: Dict[str, str], input_model: AtomicInput) -> At
data = cclib.io.ccread(tmp_output_file)

last_occupied_energy = data.moenergies[0][data.homos[0]]

Check notice

Code scanning / CodeQL

Unused local variable Note

Variable last_occupied_energy is not used.
output_data['HOMO ENERGY'] = last_occupied_energy
#print (F'HOMO ENERGY: {last_occupied_energy:2.6f} eV')
#output_data['HOMO ENERGY'] = last_occupied_energy

scf_energy = data.scfenergies[0]
output_data['SCF ENERGY'] = scf_energy
print (F'SCF ENERGY: {scf_energy:3.6f} eV')
scf_energy = data.scfenergies[0] / 27.21138505 # to Hartree
#output_data['SCF ENERGY'] = scf_energy

#if input_model.driver == 'energy':
#output_data['return_result'] =
if input_model.driver == 'energy':
output_data['return_result'] = scf_energy
#print (os.system('ccget --list ' + tmp_output_file)) #data available in the output for parsing

#if input_model.driver == 'energy':
# print (cclib.__version__)
# print (cclib.__version__)
# print (output_data)
#print (input_model)

properties = {
'nuclear_repulsion_energy': Nuclear(data).repulsion_energy(),
'scf_total_energy': scf_energy,
'return_energy': scf_energy
}

#provenance = Provenance(creator="Gaussian", version=self.get_version(), routine="g09").dict()

#properties = {
# 'nuclear_repulsion_energy': Nuclear(data).repulsion_energy(),
# 'scf_total_energy': data.scfenergies[0],
# 'return_energy': data.scfenergies[0]
# }

outtext = ''
cnt = 0
f = open(os.path.join(tmp_output_path, 'output.log'), 'r')
outtext = f.readlines()
for num, line in enumerate(outtext, 1):
if 'Version=' in line:
version_line = line.split('Version=')[-1]
version_line = version_line.strip()
version_line = version_line.split('\\')[0]
print ('version : ', version_line)
#cnt = num + 1
#if cnt == num:
#version_line += line.split("\\")[0]
#print ('version is: ', version_line)

output_data['properties'] = properties
output_data['stdout'] = outfiles['outfiles']['output.log']
output_data['success'] = True
#print ('output_data: ', output_data)

provenance = Provenance(creator="Gaussian 09", version=self.get_version(), routine='g09').dict()
print ('we are in mobj')
mobj = re.search(r"^Job cpu time:*seconds.$", outfiles['output.log'])
print ('we are in mobj')
if (mobj):
print ('mobj true')

stdout = outfiles.pop('stdout')

Check notice

Code scanning / CodeQL

Unused local variable Note

Variable stdout is not used.
stderr = outfiles.pop('stderr')

Check notice

Code scanning / CodeQL

Unused local variable Note

Variable stderr is not used.
#print("\nPRINT STDOUT: \n", stdout)


method = input_model.model.method.lower()

Check notice

Code scanning / CodeQL

Unused local variable Note

Variable method is not used.
#method = method[4:] if method.startswith("") else method

#output_data["stdout"] = stdout
output_data["success"] = True


merged_data = {**input_model.dict(), **output_data}

print('\nPRINT MERGED DATA: \n', merged_data)

return AtomicResult(**merged_data)