File: conftest_qchem.py

package info (click to toggle)
python-emmet-core 0.84.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 77,220 kB
  • sloc: python: 16,355; makefile: 30
file content (398 lines) | stat: -rw-r--r-- 14,890 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
from pathlib import Path
import pytest
import numpy as np


@pytest.fixture(scope="session")
def test_dir():
    return Path(__file__).parent.parent.parent.joinpath("test_files").resolve()


def assert_schemas_equal(test_schema, valid_schema):
    """
    Recursively test all items in valid_schema are present and equal in test_schema.

    While test_schema can be a pydantic schema or dictionary, the valid schema must
    be a (nested) dictionary. This function automatically handles accessing the
    attributes of classes in the test_schema.

    Args:
        test_schema: A pydantic schema or dictionary of the schema.
        valid_schema: A (nested) dictionary specifying the key and values that must be
            present in test_schema. This is what the generated test_schema will be tested against
    """
    from pydantic import BaseModel

    if isinstance(valid_schema, dict):
        for key, sub_valid_schema in valid_schema.items():
            if isinstance(key, str) and hasattr(test_schema, key):
                sub_test_schema = getattr(test_schema, key)
                if key == "initial_molecule":
                    sub_test_schema = sub_test_schema.as_dict()
                elif key == "optimized_molecule":
                    sub_test_schema = (
                        sub_test_schema.as_dict() if sub_test_schema else {}
                    )
            elif not isinstance(test_schema, BaseModel):
                sub_test_schema = test_schema[key]
            else:
                raise ValueError(f"{type(test_schema)} does not have field: {key}")
            return assert_schemas_equal(sub_test_schema, sub_valid_schema)

    elif isinstance(valid_schema, list):
        for i, sub_valid_schema in enumerate(valid_schema):
            return assert_schemas_equal(test_schema[i], sub_valid_schema)

    elif isinstance(valid_schema, np.ndarray):
        assert np.array_equal(test_schema, valid_schema)

    elif isinstance(valid_schema, float):
        assert test_schema == pytest.approx(valid_schema)
    else:
        assert test_schema == valid_schema


class SchemaTestData:
    """Dummy class to be used to contain all test data information"""


class SinglePointTest(SchemaTestData):
    folder = "qchem_sp_test"
    task_files = {
        "standard": {
            "qcinput_file": "mol.qin.gz",
            "qcoutput_file": "mol.qout.gz",
        }
    }

    objects = {"standard": []}
    task_doc = {
        "calcs_reversed": [
            {
                "output": {
                    "mulliken": [np.array([-0.713178, 0.357278, 0.3559])],
                    "resp": [np.array([-0.872759, 0.436379, 0.436379])],
                    "final_energy": -76.4493700739,
                },
                "input": {
                    "charge": 0,
                    "rem": {
                        "job_type": "sp",
                        "basis": "def2-qzvppd",
                        "max_scf_cycles": "100",
                        "gen_scfman": "true",
                        "xc_grid": "3",
                        "thresh": "14",
                        "s2thresh": "16",
                        "scf_algorithm": "diis",
                        "resp_charges": "true",
                        "symmetry": "false",
                        "sym_ignore": "true",
                        "method": "wb97mv",
                        "solvent_method": "smd",
                        "ideriv": "1",
                    },
                    "job_type": "sp",
                },
            }
        ],
        "input": {
            "initial_molecule": {
                "@module": "pymatgen.core.structure",
                "@class": "Molecule",
                "charge": 0.0,
                "spin_multiplicity": 1,
                "sites": [
                    {
                        "name": "O",
                        "species": [{"element": "O", "occu": 1}],
                        "xyz": [-0.80595, 2.22952, -0.01914],
                        "properties": {},
                        "label": "O",
                    },
                    {
                        "name": "H",
                        "species": [{"element": "H", "occu": 1}],
                        "xyz": [0.18338, 2.20176, 0.01351],
                        "properties": {},
                        "label": "H",
                    },
                    {
                        "name": "H",
                        "species": [{"element": "H", "occu": 1}],
                        "xyz": [-1.09531, 1.61602, 0.70231],
                        "properties": {},
                        "label": "H",
                    },
                ],
            },
            "rem": {
                "job_type": "sp",
                "basis": "def2-qzvppd",
                "max_scf_cycles": "100",
                "gen_scfman": "true",
                "xc_grid": "3",
                "thresh": "14",
                "s2thresh": "16",
                "scf_algorithm": "diis",
                "resp_charges": "true",
                "symmetry": "false",
                "sym_ignore": "true",
                "method": "wb97mv",
                "solvent_method": "smd",
                "ideriv": "1",
            },
            "level_of_theory": "wB97M-V/def2-QZVPPD/SMD",
            "task_type": "Single Point",
            "calc_type": "wB97M-V/def2-QZVPPD/SMD Single Point",
            "solvation_lot_info": "wB97M-V/def2-QZVPPD/SMD(SOLVENT=WATER)",
        },
        "output": {
            "mulliken": [np.array([-0.713178, 0.357278, 0.3559])],
            "resp": [np.array([-0.872759, 0.436379, 0.436379])],
            "final_energy": -76.4493700739,
            "dipoles": {
                "total": 2.4648,
                "dipole": [np.array([1.4227, -1.3039, 1.5333])],
                "RESP_total": 2.5411,
                "RESP_dipole": [np.array([1.4672, -1.3441, 1.5806])],
            },
        },
        "custodian": [
            {
                "job": {
                    "@module": "custodian.qchem.jobs",
                    "@class": "QCJob",
                    "@version": "2022.5.26",
                    "qchem_command": ["qchem"],
                    "max_cores": "40",
                    "multimode": "openmp",
                    "input_file": "mol.qin",
                    "output_file": "mol.qout",
                    "qclog_file": "mol.qclog",
                    "suffix": "",
                    "calc_loc": "/tmp",
                    "nboexe": None,
                    "save_scratch": False,
                    "backup": "true",
                },
                "corrections": [],
            }
        ],
    }


class OptimizationTest(SchemaTestData):
    folder = "qchem_opt_test"
    task_files = {
        "standard": {
            "qcinput_file": "mol.qin.gz",
            "qcoutput_file": "mol.qout.gz",
        }
    }

    objects = {"standard": []}
    task_doc = {
        "calcs_reversed": [
            {
                "output": {
                    "optimized_molecule": {
                        "@module": "pymatgen.core.structure",
                        "@class": "Molecule",
                        "charge": 0,
                        "spin_multiplicity": 1,
                        "sites": [
                            {
                                "name": "O",
                                "species": [{"element": "O", "occu": 1}],
                                "xyz": [-0.8008592596, 2.2248298937, -0.0136245943],
                                "properties": {},
                                "label": "O",
                            },
                            {
                                "name": "H",
                                "species": [{"element": "H", "occu": 1}],
                                "xyz": [0.1637955748, 2.1962925542, 0.0199393927],
                                "properties": {},
                                "label": "H",
                            },
                            {
                                "name": "H",
                                "species": [{"element": "H", "occu": 1}],
                                "xyz": [-1.0808163152, 1.6261775521, 0.6903652017],
                                "properties": {},
                                "label": "H",
                            },
                        ],
                    },
                    "mulliken": [-0.373491, 0.186964, 0.186527],
                    "resp": [-0.89522, 0.44761, 0.44761],
                    "final_energy": -76.358341626913,
                },
                "input": {
                    "charge": 0,
                    "rem": {
                        "job_type": "sp",
                        "basis": "def2-qzvppd",
                        "max_scf_cycles": "100",
                        "gen_scfman": "true",
                        "xc_grid": "3",
                        "thresh": "14",
                        "s2thresh": "16",
                        "scf_algorithm": "diis",
                        "resp_charges": "true",
                        "symmetry": "false",
                        "sym_ignore": "true",
                        "method": "wb97mv",
                        "solvent_method": "smd",
                        "ideriv": "1",
                    },
                    "job_type": "sp",
                },
            }
        ],
        "input": {
            "initial_molecule": {
                "@module": "pymatgen.core.structure",
                "@class": "Molecule",
                "charge": 0.0,
                "spin_multiplicity": 1,
                "sites": [
                    {
                        "name": "O",
                        "species": [{"element": "O", "occu": 1}],
                        "xyz": [-0.80595, 2.22952, -0.01914],
                        "properties": {},
                        "label": "O",
                    },
                    {
                        "name": "H",
                        "species": [{"element": "H", "occu": 1}],
                        "xyz": [0.18338, 2.20176, 0.01351],
                        "properties": {},
                        "label": "H",
                    },
                    {
                        "name": "H",
                        "species": [{"element": "H", "occu": 1}],
                        "xyz": [-1.09531, 1.61602, 0.70231],
                        "properties": {},
                        "label": "H",
                    },
                ],
            },
            "rem": {
                "job_type": "opt",
                "basis": "def2-svpd",
                "max_scf_cycles": "100",
                "gen_scfman": "true",
                "xc_grid": "3",
                "thresh": "14",
                "s2thresh": "16",
                "scf_algorithm": "diis",
                "resp_charges": "true",
                "symmetry": "false",
                "sym_ignore": "true",
                "method": "wb97mv",
                "solvent_method": "smd",
                "ideriv": "1",
                "geom_opt2": "3",
            },
            "level_of_theory": "wB97M-V/def2-SVPD/SMD",
            "task_type": "Geometry Optimization",
            "calc_type": "wB97M-V/def2-SVPD/SMD Geometry Optimization",
            "solvation_lot_info": "wB97M-V/def2-SVPD/SMD(SOLVENT=WATER)",
        },
        "output": {
            "initial_molecule": {
                "@module": "pymatgen.core.structure",
                "@class": "Molecule",
                "charge": 0.0,
                "spin_multiplicity": 1,
                "sites": [
                    {
                        "name": "O",
                        "species": [{"element": "O", "occu": 1}],
                        "xyz": [-0.80595, 2.22952, -0.01914],
                        "properties": {},
                        "label": "O",
                    },
                    {
                        "name": "H",
                        "species": [{"element": "H", "occu": 1}],
                        "xyz": [0.18338, 2.20176, 0.01351],
                        "properties": {},
                        "label": "H",
                    },
                    {
                        "name": "H",
                        "species": [{"element": "H", "occu": 1}],
                        "xyz": [-1.09531, 1.61602, 0.70231],
                        "properties": {},
                        "label": "H",
                    },
                ],
            },
            "optimized_molecule": {
                "@module": "pymatgen.core.structure",
                "@class": "Molecule",
                "charge": 0,
                "spin_multiplicity": 1,
                "sites": [
                    {
                        "name": "O",
                        "species": [{"element": "O", "occu": 1}],
                        "xyz": [-0.8008592596, 2.2248298937, -0.0136245943],
                        "properties": {},
                        "label": "O",
                    },
                    {
                        "name": "H",
                        "species": [{"element": "H", "occu": 1}],
                        "xyz": [0.1637955748, 2.1962925542, 0.0199393927],
                        "properties": {},
                        "label": "H",
                    },
                    {
                        "name": "H",
                        "species": [{"element": "H", "occu": 1}],
                        "xyz": [-1.0808163152, 1.6261775521, 0.6903652017],
                        "properties": {},
                        "label": "H",
                    },
                ],
            },
            "mulliken": [-0.373491, 0.186964, 0.186527],
            "resp": [-0.89522, 0.44761, 0.44761],
            "final_energy": -76.358341626913,
        },
        "custodian": [
            {
                "job": {
                    "@module": "custodian.qchem.jobs",
                    "@class": "QCJob",
                    "@version": "2022.5.26",
                    "qchem_command": ["qchem"],
                    "max_cores": "40",
                    "multimode": "openmp",
                    "input_file": "mol.qin",
                    "output_file": "mol.qout",
                    "qclog_file": "mol.qclog",
                    "suffix": "",
                    "calc_loc": "/tmp",
                    "nboexe": "null",
                    "save_scratch": "false",
                    "backup": "true",
                },
                "corrections": [],
            }
        ],
    }


objects = {cls.__name__: cls for cls in SchemaTestData.__subclasses__()}


def get_test_object(object_name):
    """Get the schema test data object from the class name."""
    return objects[object_name]