Skip to content

Commit

Permalink
Merge pull request #230 from ahurta92/adrian-Dipole
Browse files Browse the repository at this point in the history
NWCHEM: Adrian dipole/homo/lumo changes
  • Loading branch information
dgasmith committed Mar 4, 2020
2 parents e4e62ff + e563538 commit 4267201
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 24 deletions.
42 changes: 18 additions & 24 deletions qcengine/programs/nwchem/harvester.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,9 +614,7 @@ def harvest_outfile_pass(outtext):
if mobj:
psivar["N ALPHA ELECTRONS"] = mobj.group(2)
psivar["N BETA ELECTRONS"] = mobj.group(3)

if psivar["N ALPHA ELECTRONS"] == psivar["N BETA ELECTRONS"]:

# get HOMO and LUMO energy
mobj = re.search(
r"Vector"
Expand All @@ -629,34 +627,30 @@ def harvest_outfile_pass(outtext):
+ r"E="
+ r"([+-]?\s?\d+[.]\d+)"
+ r"[D]"
+ r"([+-])"
+ r"[0]"
+ r"(\d+)",
+ r"([+-]0\d)",
outtext,
re.MULTILINE,
)
if mobj:
homo = float(mobj.group(1)) * (10 ** (-1 * float(mobj.group(3))))
homo = float(mobj.group(1)) * (10 ** (int(mobj.group(2))))
psivar["HOMO"] = np.array([round(homo, 10)])
mobj = re.search(
r"Vector"
+ r"\s+"
+ r"%d" % (psivar["N ALPHA ELECTRONS"] + 1)
+ r"\s+"
+ r"Occ="
+ r".*"
+ r"\s+"
+ r"E="
+ r"([+-]?\s?\d+[.]\d+)"
+ r"[D]"
+ r"([+-])"
+ r"[0]"
+ r"(\d+)",
outtext,
re.MULTILINE,
)
mobj = re.search(
r"Vector"
+ r"\s+"
+ r"%d" % (psivar["N ALPHA ELECTRONS"] + 1)
+ r"\s+"
+ r"Occ="
+ r".*"
+ r"\s+"
+ r"E="
+ r"([+-]?\s?\d+[.]\d+)"
+ r"[D]"
+ r"([+-]0\d)",
outtext,
re.MULTILINE,
)
if mobj:
lumo = float(mobj.group(1)) * (10 ** (-1 * float(mobj.group(3))))
lumo = float(mobj.group(1)) * (10 ** (int(mobj.group(2))))
psivar["LUMO"] = np.array([round(lumo, 10)])

mobj = re.search(r"AO basis - number of functions:\s+(\d+)\s+number of shells:\s+(\d+)", outtext, re.MULTILINE)
Expand Down
42 changes: 42 additions & 0 deletions qcengine/programs/tests/test_nwchem.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,45 @@ def test_dipole(h20):
assert compare_values(-0.00, float(res["extras"]["qcvars"]["DIPOLE MOMENT"][0]), atol=1e-3)
assert compare_values(-0.00, float(res["extras"]["qcvars"]["DIPOLE MOMENT"][1]), atol=1e-3)
assert compare_values(-0.272949872, float(res["extras"]["qcvars"]["DIPOLE MOMENT"][2]), atol=1e-5)


@pytest.fixture
def h20v2():
water = """
O 0 0 0
H 0 0 1
H 0 1 0
"""
return qcel.models.Molecule.from_data(water)


@using("nwchem")
def test_homo_lumo(h20v2):
# Run NH2
resi = {
"molecule": h20v2,
"driver": "energy",
"model": {"method": "dft", "basis": "3-21g"},
"keywords": {"dft__xc": "b3lyp"},
}
res = qcng.compute(resi, "nwchem", raise_error=True, return_dict=True)

# Make sure the calculation completed successfully
assert compare_values(-75.968095, res["return_result"], atol=1e-3)
assert res["driver"] == "energy"
assert "provenance" in res
assert res["success"] is True

# Check the other status information
assert res["extras"]["qcvars"]["N ALPHA ELECTRONS"] == "5"
assert res["extras"]["qcvars"]["N ATOMS"] == "3"
assert res["extras"]["qcvars"]["N BASIS"] == "13"

# Make sure the properties parsed correctly
assert compare_values(-75.968095, res["properties"]["return_energy"], atol=1e-3)
assert res["properties"]["calcinfo_natom"] == 3
assert res["properties"]["calcinfo_nalpha"] == 5
assert res["properties"]["calcinfo_nbasis"] == 13
# Make sure Dipole Moment and center of charge parsed correctly
assert compare_values(-0.2636515, float(res["extras"]["qcvars"]["HOMO"][0]), atol=1e-5)
assert compare_values(0.08207131, float(res["extras"]["qcvars"]["LUMO"][0]), atol=1e-5)

0 comments on commit 4267201

Please sign in to comment.