Skip to content

Commit

Permalink
Merge 4c6fda2 into e1c075c
Browse files Browse the repository at this point in the history
  • Loading branch information
samblau committed Jan 17, 2023
2 parents e1c075c + 4c6fda2 commit 8b71c4b
Show file tree
Hide file tree
Showing 23 changed files with 980,709 additions and 301 deletions.
7 changes: 5 additions & 2 deletions pymatgen/io/qchem/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@

from .utils import lower_and_check_unique, read_pattern, read_table_pattern

__author__ = "Brandon Wood, Samuel Blau, Shyam Dwaraknath, Evan Spotte-Smith, Ryan Kingsbury"
__author__ = "Brandon Wood, Samuel Blau, Shyam Dwaraknath, Julian Self, Evan Spotte-Smith, Ryan Kingsbury"
__copyright__ = "Copyright 2018-2022, The Materials Project"
__version__ = "0.1"
__maintainer__ = "Samuel Blau"
__email__ = "samblau1@gmail.com"
__credits__ = "Xiaohui Qu"

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -913,7 +916,7 @@ def read_nbo(string: str) -> dict:
(dict) nbo parameters.
"""
header = r"^\s*\$nbo"
row = r"\s*([a-zA-Z\_]+)\s*=?\s*(\S+)"
row = r"\s*([a-zA-Z\_\d]+)\s*=?\s*(\S+)"
footer = r"^\s*\$end"
nbo_table = read_table_pattern(string, header_pattern=header, row_pattern=row, footer_pattern=footer)
if nbo_table == []:
Expand Down
670 changes: 537 additions & 133 deletions pymatgen/io/qchem/outputs.py

Large diffs are not rendered by default.

275 changes: 175 additions & 100 deletions pymatgen/io/qchem/sets.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pymatgen/io/qchem/tests/multi_job.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pymatgen/io/qchem/tests/single_job.json

Large diffs are not rendered by default.

33 changes: 33 additions & 0 deletions pymatgen/io/qchem/tests/test_inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

__author__ = "Brandon Wood, Samuel Blau, Shyam Dwaraknath, Julian Self, Evan Spotte-Smith, Ryan Kingsbury"
__copyright__ = "Copyright 2018-2022, The Materials Project"
__version__ = "0.1"
__maintainer__ = "Samuel Blau"
__email__ = "samblau1@gmail.com"
__credits__ = "Xiaohui Qu"

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -1046,6 +1049,36 @@ def test_read_write_nbo7(self):
ref_file.close()
os.remove(os.path.join(os.path.dirname(__file__), "test_nbo7.qin"))

def test_read_write_nbo_e2pert(self):
qcinp = QCInput.from_file(
os.path.join(PymatgenTest.TEST_FILES_DIR, "molecules", "new_qchem_files", "e2pert.qin")
)
qcinp.write_file(os.path.join(os.path.dirname(__file__), "test_e2pert.qin"))
test_file = open(os.path.join(PymatgenTest.TEST_FILES_DIR, "molecules", "new_qchem_files", "e2pert.qin"))
ref_file = open(os.path.join(os.path.dirname(__file__), "test_e2pert.qin"))

for l_test, l_ref in zip(test_file, ref_file):
assert l_test == l_ref

test_file.close()
ref_file.close()
os.remove(os.path.join(os.path.dirname(__file__), "test_e2pert.qin"))

def test_read_write_custom_smd(self):
qcinp = QCInput.from_file(
os.path.join(PymatgenTest.TEST_FILES_DIR, "molecules", "new_qchem_files", "custom_smd.qin")
)
qcinp.write_file(os.path.join(os.path.dirname(__file__), "test_custom_smd.qin"))
test_file = open(os.path.join(PymatgenTest.TEST_FILES_DIR, "molecules", "new_qchem_files", "custom_smd.qin"))
ref_file = open(os.path.join(os.path.dirname(__file__), "test_custom_smd.qin"))

for l_test, l_ref in zip(test_file, ref_file):
assert l_test == l_ref

test_file.close()
ref_file.close()
os.remove(os.path.join(os.path.dirname(__file__), "test_custom_smd.qin"))


if __name__ == "__main__":
unittest.main()
64 changes: 52 additions & 12 deletions pymatgen/io/qchem/tests/test_outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@

try:
from openbabel import openbabel

openbabel # reference openbabel so it's not unused import
have_babel = True
except ImportError:
have_babel = False
openbabel = None

__author__ = "Samuel Blau, Brandon Wood, Shyam Dwaraknath, Evan Spotte-Smith, Ryan Kingsbury"
__copyright__ = "Copyright 2018-2022, The Materials Project"
__version__ = "0.1"
__maintainer__ = "Samuel Blau"
__email__ = "samblau1@gmail.com"

single_job_dict = loadfn(os.path.join(os.path.dirname(__file__), "single_job.json"))
multi_job_dict = loadfn(os.path.join(os.path.dirname(__file__), "multi_job.json"))
Expand Down Expand Up @@ -115,9 +115,13 @@
"exchange_e",
"min_neg_field_e",
"max_pos_field_e",
"norm_of_stepsize",
"version",
"dipoles",
"gap_info",
}

if have_babel:
if openbabel is not None:
property_list.add("structure_change")

single_job_out_names = {
Expand Down Expand Up @@ -188,6 +192,15 @@
"new_qchem_files/cmirs_water_single.qcout",
"new_qchem_files/isosvp_water_single.qcout",
"new_qchem_files/isosvp_dielst10_single.qcout",
"new_qchem_files/custom_gdm_gdmqls_opt.qout",
"new_qchem_files/unable.qout",
"new_qchem_files/unexpected_ts.out",
"new_qchem_files/svd_failed.qout",
"new_qchem_files/v6_old_driver.out",
"new_qchem_files/gap.qout",
"new_qchem_files/3C.qout",
"new_qchem_files/hyper.qout",
"new_qchem_files/os_gap.qout",
}

multi_job_out_names = {
Expand Down Expand Up @@ -240,15 +253,20 @@ def _test_property(self, key, single_outs, multi_outs):
try:
self.assertEqual(outdata.get(key), single_job_dict[name].get(key))
except ValueError:
self.assertArrayEqual(outdata.get(key), single_job_dict[name].get(key))
try:
self.assertArrayEqual(outdata.get(key), single_job_dict[name].get(key))
except AssertionError:
raise RuntimeError("Issue with file: " + name + " Exiting...")
except AssertionError:
raise RuntimeError("Issue with file: " + name + " Exiting...")
for name, outputs in multi_outs.items():
for ii, sub_output in enumerate(outputs):
try:
self.assertEqual(sub_output.data.get(key), multi_job_dict[name][ii].get(key))
except ValueError:
self.assertArrayEqual(sub_output.data.get(key), multi_job_dict[name][ii].get(key))

@unittest.skipIf(not have_babel, "OpenBabel not installed.")
@unittest.skipIf(openbabel is None, "OpenBabel not installed.")
def test_all(self):
self.maxDiff = None
single_outs = {}
Expand All @@ -265,7 +283,7 @@ def test_all(self):
print("Testing ", key)
self._test_property(key, single_outs, multi_outs)

@unittest.skipIf((not have_babel), "OpenBabel not installed.")
@unittest.skipIf((openbabel is None), "OpenBabel not installed.")
def test_structural_change(self):

t1 = Molecule.from_file(os.path.join(PymatgenTest.TEST_FILES_DIR, "molecules", "structural_change", "t1.xyz"))
Expand Down Expand Up @@ -302,10 +320,10 @@ def test_structural_change(self):
def test_NBO_parsing(self):
data = QCOutput(os.path.join(PymatgenTest.TEST_FILES_DIR, "molecules", "new_qchem_files", "nbo.qout")).data
self.assertEqual(len(data["nbo_data"]["natural_populations"]), 3)
self.assertEqual(len(data["nbo_data"]["hybridization_character"]), 4)
self.assertEqual(len(data["nbo_data"]["hybridization_character"]), 6)
self.assertEqual(len(data["nbo_data"]["perturbation_energy"]), 2)
self.assertEqual(data["nbo_data"]["natural_populations"][0]["Density"][5], -0.08624)
self.assertEqual(data["nbo_data"]["hybridization_character"][-1]["atom 2 pol coeff"][35], "-0.7059")
self.assertEqual(data["nbo_data"]["hybridization_character"][4]["atom 2 pol coeff"][35], "-0.7059")
next_to_last = list(data["nbo_data"]["perturbation_energy"][-1]["fock matrix element"])[-2]
self.assertEqual(data["nbo_data"]["perturbation_energy"][-1]["fock matrix element"][next_to_last], 0.071)
self.assertEqual(data["nbo_data"]["perturbation_energy"][0]["acceptor type"][0], "RY*")
Expand Down Expand Up @@ -336,8 +354,8 @@ def test_NBO5_vs_NBO7_hybridization_character(self):
len(data5["nbo_data"]["hybridization_character"]), len(data7["nbo_data"]["hybridization_character"])
)
self.assertEqual(
data5["nbo_data"]["hybridization_character"][3]["atom 2 pol coeff"][9],
data7["nbo_data"]["hybridization_character"][3]["atom 2 pol coeff"][9],
data5["nbo_data"]["hybridization_character"][4]["atom 2 pol coeff"][9],
data7["nbo_data"]["hybridization_character"][4]["atom 2 pol coeff"][9],
)
self.assertEqual(
data5["nbo_data"]["hybridization_character"][0]["s"][0],
Expand Down Expand Up @@ -429,6 +447,28 @@ def test_cmirs_water(self):
self.assertEqual(data["solvent_data"]["cmirs"]["min_neg_field_e"], 0.0004967767)
self.assertEqual(data["solvent_data"]["cmirs"]["max_pos_field_e"], 0.0180445935)

def test_NBO_hyperbonds(self):
data = QCOutput(os.path.join(PymatgenTest.TEST_FILES_DIR, "molecules", "new_qchem_files", "hyper.qout")).data
self.assertEqual(len(data["nbo_data"]["hyperbonds"][0]["hyperbond index"].keys()), 2)
self.assertEqual(data["nbo_data"]["hyperbonds"][0]["BD(A-B)"][1], 106)
self.assertEqual(data["nbo_data"]["hyperbonds"][0]["bond atom 2 symbol"][0], "C")
self.assertEqual(data["nbo_data"]["hyperbonds"][0]["occ"][1], 3.0802)

def test_NBO_3C(self):
data = QCOutput(os.path.join(PymatgenTest.TEST_FILES_DIR, "molecules", "new_qchem_files", "3C.qout")).data
self.assertEqual(len(data["nbo_data"]["hybridization_character"]), 3)
self.assertEqual(data["nbo_data"]["hybridization_character"][2]["type"][0], "3C")
self.assertEqual(data["nbo_data"]["hybridization_character"][2]["type"][10], "3Cn")
self.assertEqual(data["nbo_data"]["hybridization_character"][2]["type"][20], "3C*")
self.assertEqual(data["nbo_data"]["hybridization_character"][2]["atom 3 pol coeff"][15], "0.3643")
self.assertEqual(data["nbo_data"]["hybridization_character"][2]["atom 3 polarization"][8], "56.72")
self.assertEqual(data["nbo_data"]["hybridization_character"][2]["atom 3 symbol"][3], "B")
self.assertEqual(data["nbo_data"]["perturbation_energy"][0]["donor atom 2 number"][2592], 36)
self.assertEqual(data["nbo_data"]["perturbation_energy"][0]["donor atom 2 symbol"][2125], "B12")
self.assertEqual(data["nbo_data"]["perturbation_energy"][0]["donor atom 2 number"][2593], "info_is_from_3C")
self.assertEqual(data["nbo_data"]["perturbation_energy"][0]["acceptor type"][723], "3C*")
self.assertEqual(data["nbo_data"]["perturbation_energy"][0]["perturbation energy"][3209], 3.94)


if __name__ == "__main__":
unittest.main()
4 changes: 2 additions & 2 deletions pymatgen/io/qchem/tests/test_ref.qin
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ $end

$rem
job_type = opt
basis = def2-tzvppd
basis = def2-svpd
max_scf_cycles = 100
gen_scfman = true
xc_grid = 3
Expand All @@ -18,6 +18,6 @@ $rem
resp_charges = true
symmetry = false
sym_ignore = true
method = wb97xd
method = wb97mv
geom_opt_max_cycles = 200
$end
4 changes: 2 additions & 2 deletions pymatgen/io/qchem/tests/test_ref_vdw.qin
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ $end

$rem
job_type = opt
basis = def2-tzvppd
basis = def2-svpd
max_scf_cycles = 100
gen_scfman = true
xc_grid = 3
Expand All @@ -18,7 +18,7 @@ $rem
resp_charges = true
symmetry = false
sym_ignore = true
method = wb97xd
method = wb97mv
geom_opt_max_cycles = 200
$end

Expand Down

0 comments on commit 8b71c4b

Please sign in to comment.