Skip to content

Commit 1459100

Browse files
authored
Merge pull request #765 from rdguha1995/main
Correcting the Proton Energy FW
2 parents 95c489b + 4550e49 commit 1459100

File tree

3 files changed

+85
-58
lines changed

3 files changed

+85
-58
lines changed

atomate/qchem/firetasks/parse_outputs.py

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,13 @@ class ProtCalcToDb(FiretaskBase):
126126
127127
Optional params:
128128
calc_dir (str): path to dir (on current filesystem) that contains QChem
129-
input and output files for both the H0 and H2+. Default: use current working directory.
129+
input and output files for both the H2O and H3O+ calculations. Default: use current working directory.
130130
calc_loc (str OR bool): if True will set most recent calc_loc. If str
131131
search for the most recent calc_loc with the matching name
132-
input_file_H0 (str): name of the QChem input file for H0 calculation
133-
output_file_H0 (str): name of the QChem output file for H0 calculation
134-
input_file_H2 (str): name of the QChem input file for H2 calculation
135-
output_file_H2 (str): name of the QChem output file for H2 calculation
132+
input_file_H2O (str): name of the QChem input file for H2O calculation
133+
output_file_H2O (str): name of the QChem output file for H2O calculation
134+
input_file_H3O (str): name of the QChem input file for H3O+ calculation
135+
output_file_H3O (str): name of the QChem output file for H3O+ calculation
136136
additional_fields (dict): dict of additional fields to add
137137
db_file (str): path to file containing the database credentials.
138138
Supports env_chk. Default: write data to JSON file.
@@ -143,10 +143,10 @@ class ProtCalcToDb(FiretaskBase):
143143
optional_params = [
144144
"calc_dir",
145145
"calc_loc",
146-
"input_file_H0",
147-
"output_file_H0",
148-
"input_file_H2",
149-
"output_file_H2",
146+
"input_file_H2O",
147+
"output_file_H2O",
148+
"input_file_H3O",
149+
"output_file_H3O",
150150
"additional_fields",
151151
"db_file",
152152
"runs",
@@ -159,10 +159,10 @@ def run_task(self, fw_spec):
159159
calc_dir = self["calc_dir"]
160160
elif self.get("calc_loc"):
161161
calc_dir = get_calc_loc(self["calc_loc"], fw_spec["calc_locs"])["path"]
162-
input_file_H0 = self.get("input_file_H0", "H0.qin")
163-
output_file_H0 = self.get("output_file_H0", "H0.qout")
164-
input_file_H2 = self.get("input_file_H2", "H2_plus.qin")
165-
output_file_H2 = self.get("output_file_H2", "H2_plus.qout")
162+
input_file_H2O = self.get("input_file_H2O", "water.qin")
163+
output_file_H2O = self.get("output_file_H2O", "water.qout")
164+
input_file_H3O = self.get("input_file_H3O", "hydronium.qin")
165+
output_file_H3O = self.get("output_file_H3O", "hydronium.qout")
166166
runs = self.get("runs", None)
167167

168168
# parse the QChem directory
@@ -175,15 +175,15 @@ def run_task(self, fw_spec):
175175
# assimilate (i.e., parse)
176176
task_doc_1 = drone.assimilate(
177177
path=calc_dir,
178-
input_file=input_file_H0,
179-
output_file=output_file_H0,
178+
input_file=input_file_H2O,
179+
output_file=output_file_H2O,
180180
multirun=False,
181181
)
182182

183183
task_doc_2 = drone.assimilate(
184184
path=calc_dir,
185-
input_file=input_file_H2,
186-
output_file=output_file_H2,
185+
input_file=input_file_H3O,
186+
output_file=output_file_H3O,
187187
multirun=False,
188188
)
189189

@@ -195,6 +195,12 @@ def run_task(self, fw_spec):
195195
task_doc_clean["orig"]["molecule"]["spin_multiplicity"] = 1
196196
task_doc_clean["output"]["initial_molecule"]["charge"] = 1
197197
task_doc_clean["output"]["initial_molecule"]["spin_multiplicity"] = 1
198+
task_doc_clean["output"]["initial_molecule"]["sites"] = [{'name': 'H', 'species': [{'element': 'H', 'occu': 1}], 'xyz': [0.0, 0.0, 0.0], 'properties': {}}]
199+
task_doc_clean["output"]["mulliken"] = [+1.000000]
200+
task_doc_clean["output"]["resp"] = [+1.000000]
201+
task_doc_clean["output"]["optimized_molecule"]["charge"] = 1
202+
task_doc_clean["output"]["optimized_molecule"]["spin_multiplicity"] = 1
203+
task_doc_clean["output"]["optimized_molecule"]["sites"] = [{'name': 'H', 'species': [{'element': 'H', 'occu': 1}], 'xyz': [0.0, 0.0, 0.0], 'properties': {}}]
198204
task_doc_clean["output"]["final_energy"] = (
199205
task_doc_2["output"]["final_energy"] - task_doc_1["output"]["final_energy"]
200206
)

atomate/qchem/fireworks/core.py

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,11 @@ def __init__(
117117
"""
118118
For this custom Firework the electronic energy of a proton in a specific solvent environment is approximated.
119119
Since a proton has 0 electrons,running a QChem job would yield an error. The energy can be approximated by
120-
calculating the electronic energy of a proton and a hydrogen atom at infinite separation and then subtracting
121-
the electronic energy of a hydrogen atom. This Firework combines these two calculations and adds a task doc to the
120+
calculating the electronic energy of a hydronium ion and a water molecule and then subtracting
121+
the respective electronic energies. This Firework combines these two calculations and adds a task doc to the
122122
DB with the separate calculation details and the effective energy after subtraction.
123123
124-
Args:
124+
Arg
125125
name (str): Name for the Firework.
126126
qchem_cmd (str): Command to run QChem. Supports env_chk.
127127
multimode (str): Parallelization scheme, either openmp or mpi. Supports env_chk.
@@ -150,21 +150,31 @@ def __init__(
150150

151151
qchem_input_params = qchem_input_params or {}
152152

153-
H_site = Site("H", [0.0, 0.0, 0.0])
154-
H_site_inf = Site("H", [100000.0, 0.0, 0.0])
155-
H0_atom = Molecule.from_sites([H_site])
156-
H2_plus_mol = Molecule.from_sites([H_site, H_site_inf])
157-
H0_atom.set_charge_and_spin(0, 2)
158-
H2_plus_mol.set_charge_and_spin(1, 2)
159-
input_file_1 = "H0.qin"
160-
output_file_1 = "H0.qout"
161-
input_file_2 = "H2_plus.qin"
162-
output_file_2 = "H2_plus.qout"
153+
H_site_1_H2O = Site("H", [0.18338, 2.20176, 0.01351])
154+
H_site_2_H2O = Site("H", [-1.09531, 1.61602, 0.70231])
155+
O_site_H2O = Site("O", [-0.80595, 2.22952, -0.01914])
156+
H2O_molecule = Molecule.from_sites([H_site_1_H2O, H_site_2_H2O, O_site_H2O])
157+
158+
H_site_1_H3O = Site("H", [0.11550, 2.34733, 0.00157])
159+
H_site_2_H3O = Site("H", [-1.17463, 1.77063, 0.67652])
160+
H_site_3_H3O = Site("H", [-1.29839, 2.78012, -0.51436])
161+
O_site_H3O = Site("O", [-0.78481, 1.99137, -0.20661])
162+
H3O_ion = Molecule.from_sites(
163+
[H_site_1_H3O, H_site_2_H3O, H_site_3_H3O, O_site_H3O]
164+
)
165+
166+
H2O_molecule.set_charge_and_spin(0, 1)
167+
H3O_ion.set_charge_and_spin(1, 1)
168+
169+
input_file_1 = "water.qin"
170+
output_file_1 = "water.qout"
171+
input_file_2 = "hydronium.qin"
172+
output_file_2 = "hydronium.qout"
163173
t = []
164174
t.append(
165175
WriteInputFromIOSet(
166-
molecule=H0_atom,
167-
qchem_input_set="SinglePointSet",
176+
molecule=H2O_molecule,
177+
qchem_input_set="OptSet",
168178
input_file=input_file_1,
169179
qchem_input_params=qchem_input_params,
170180
)
@@ -184,8 +194,8 @@ def __init__(
184194

185195
t.append(
186196
WriteInputFromIOSet(
187-
molecule=H2_plus_mol,
188-
qchem_input_set="SinglePointSet",
197+
molecule=H3O_ion,
198+
qchem_input_set="OptSet",
189199
input_file=input_file_2,
190200
qchem_input_params=qchem_input_params,
191201
)
@@ -205,10 +215,10 @@ def __init__(
205215
t.append(
206216
ProtCalcToDb(
207217
db_file=db_file,
208-
input_file_H0=input_file_1,
209-
output_file_H0=output_file_1,
210-
input_file_H2=input_file_2,
211-
output_file_H2=output_file_2,
218+
input_file_H2O=input_file_1,
219+
output_file_H2O=output_file_1,
220+
input_file_H3O=input_file_2,
221+
output_file_H3O=output_file_2,
212222
additional_fields={"task_label": name},
213223
)
214224
)

atomate/qchem/fireworks/tests/test_core.py

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -137,19 +137,30 @@ def test_SinglePointFW_not_defaults(self):
137137
self.assertEqual(firework.name, "special single point")
138138

139139
def test_ProtonEnergyFW(self):
140-
H_site = Site("H", [0.0, 0.0, 0.0])
141-
H_site_inf = Site("H", [100000.0, 0.0, 0.0])
142-
H0_atom = Molecule.from_sites([H_site])
143-
H2_plus_mol = Molecule.from_sites([H_site, H_site_inf])
144-
H0_atom.set_charge_and_spin(0, 2)
145-
H2_plus_mol.set_charge_and_spin(1, 2)
140+
141+
H_site_1_H2O = Site("H", [0.18338, 2.20176, 0.01351])
142+
H_site_2_H2O = Site("H", [-1.09531, 1.61602, 0.70231])
143+
O_site_H2O = Site("O", [-0.80595, 2.22952, -0.01914])
144+
H2O_molecule = Molecule.from_sites([H_site_1_H2O, H_site_2_H2O, O_site_H2O])
145+
146+
H_site_1_H3O = Site("H", [0.11550, 2.34733, 0.00157])
147+
H_site_2_H3O = Site("H", [-1.17463, 1.77063, 0.67652])
148+
H_site_3_H3O = Site("H", [-1.29839, 2.78012, -0.51436])
149+
O_site_H3O = Site("O", [-0.78481, 1.99137, -0.20661])
150+
H3O_ion = Molecule.from_sites(
151+
[H_site_1_H3O, H_site_2_H3O, H_site_3_H3O, O_site_H3O]
152+
)
153+
154+
H2O_molecule.set_charge_and_spin(0, 1)
155+
H3O_ion.set_charge_and_spin(1, 1)
156+
146157
firework = ProtonEnergyFW(qchem_input_params={"smd_solvent": "water"})
147158
self.assertEqual(
148159
firework.tasks[0].as_dict(),
149160
WriteInputFromIOSet(
150-
molecule=H0_atom,
151-
qchem_input_set="SinglePointSet",
152-
input_file="H0.qin",
161+
molecule=H2O_molecule,
162+
qchem_input_set="OptSet",
163+
input_file="water.qin",
153164
qchem_input_params={"smd_solvent": "water"},
154165
).as_dict(),
155166
)
@@ -158,8 +169,8 @@ def test_ProtonEnergyFW(self):
158169
RunQChemCustodian(
159170
qchem_cmd=">>qchem_cmd<<",
160171
multimode=">>multimode<<",
161-
input_file="H0.qin",
162-
output_file="H0.qout",
172+
input_file="water.qin",
173+
output_file="water.qout",
163174
max_cores=">>max_cores<<",
164175
max_errors=5,
165176
job_type="normal",
@@ -169,9 +180,9 @@ def test_ProtonEnergyFW(self):
169180
self.assertEqual(
170181
firework.tasks[2].as_dict(),
171182
WriteInputFromIOSet(
172-
molecule=H2_plus_mol,
173-
qchem_input_set="SinglePointSet",
174-
input_file="H2_plus.qin",
183+
molecule=H3O_ion,
184+
qchem_input_set="OptSet",
185+
input_file="hydronium.qin",
175186
qchem_input_params={"smd_solvent": "water"},
176187
).as_dict(),
177188
)
@@ -180,8 +191,8 @@ def test_ProtonEnergyFW(self):
180191
RunQChemCustodian(
181192
qchem_cmd=">>qchem_cmd<<",
182193
multimode=">>multimode<<",
183-
input_file="H2_plus.qin",
184-
output_file="H2_plus.qout",
194+
input_file="hydronium.qin",
195+
output_file="hydronium.qout",
185196
max_cores=">>max_cores<<",
186197
max_errors=5,
187198
job_type="normal",
@@ -192,10 +203,10 @@ def test_ProtonEnergyFW(self):
192203
firework.tasks[4].as_dict(),
193204
ProtCalcToDb(
194205
db_file=None,
195-
input_file_H0="H0.qin",
196-
output_file_H0="H0.qout",
197-
input_file_H2="H2_plus.qin",
198-
output_file_H2="H2_plus.qout",
206+
input_file_H2O="water.qin",
207+
output_file_H2O="water.qout",
208+
input_file_H3O="hydronium.qin",
209+
output_file_H3O="hydronium.qout",
199210
additional_fields={"task_label": "proton electronic energy"},
200211
).as_dict(),
201212
)

0 commit comments

Comments
 (0)