Skip to content

Commit

Permalink
Use methyl radical for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
WardLT committed Dec 8, 2023
1 parent 9bf2885 commit 89189b1
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 66 deletions.
2 changes: 1 addition & 1 deletion jitterbug/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def main(args: Optional[list[str]] = None):

# Add multiplicity to the options
if atoms.get_initial_magnetic_moments().sum() > 0:
mult = atoms.get_initial_magnetic_moments().sum() + 1
mult = int(atoms.get_initial_magnetic_moments().sum()) + 1
ase_options['multiplicity'] = int(mult)
logger.info(f'Running with a multiplicity of {mult}')

Expand Down
3 changes: 2 additions & 1 deletion jitterbug/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"""List of methods for which we will use MOPAC"""


def make_calculator(method: str, basis: Optional[str], multiplicity: int = 0, **kwargs) -> Calculator:
def make_calculator(method: str, basis: Optional[str], multiplicity: int = 1, **kwargs) -> Calculator:
"""Make an ASE calculator that implements a desired method.
This function will select the appropriate quantum chemistry code depending
Expand All @@ -26,6 +26,7 @@ def make_calculator(method: str, basis: Optional[str], multiplicity: int = 0, **
Args:
method: Name of the quantum chemistry method
basis: Basis set name, if appropriate
multiplicity: Default multiplicity for the computation
Returns:
Calculator defined according to the user's settings
"""
Expand Down
112 changes: 83 additions & 29 deletions notebooks/0_create-test-set/0_get-exact-answer.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"id": "06732ce7-a249-448d-8b77-bd7974f83c59",
"metadata": {
"tags": []
Expand Down Expand Up @@ -48,7 +48,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"id": "1abbc967-a788-4a2d-8342-6a88c75cebec",
"metadata": {
"tags": [
Expand All @@ -57,7 +57,7 @@
},
"outputs": [],
"source": [
"molecule_name = 'caffeine'\n",
"molecule_name = 'methyl-radical'\n",
"relax_method = 'pm7/None' # Method used to relax geometry \n",
"hess_method = None # Method used to perform Hessian computation, None to use same\n",
"basis = None # Set to None for MOPAC methods\n",
Expand All @@ -75,7 +75,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"id": "2f543fd2-ca4c-4d68-a523-14515f351c4b",
"metadata": {
"tags": []
Expand All @@ -91,12 +91,20 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"id": "aeebbc77-70e4-4709-90a0-b9aaf54d4cd9",
"metadata": {
"tags": []
},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Run name: methyl-radical_pm7_None_at_pm7_None_d=0.01\n"
]
}
],
"source": [
"run_name = f'{molecule_name}_{hess_method}_{hess_basis}_at_{relax_method}_{relax_basis}'\n",
"run_name_with_delta = f'{run_name}_d={delta:.3g}'\n",
Expand All @@ -117,7 +125,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"id": "d52bd814-a353-467f-99a6-02201a64416e",
"metadata": {
"tags": []
Expand Down Expand Up @@ -145,14 +153,23 @@
" for i, c in enumerate('xyz'):\n",
" if c in conf_data:\n",
" positions[:, i] = conf_data[c]\n",
" \n",
" # Build the object \n",
" return Atoms(numbers=atomic_numbers, positions=positions)"
" \n",
" # Build the object\n",
" atoms = Atoms(numbers=atomic_numbers, positions=positions)\n",
"\n",
" # Get the radicals\n",
" magmom = [0] * len(atoms)\n",
" for rad in data['atoms']['radical']:\n",
" aid = rad['aid']\n",
" magmom[aid - 1] = 1\n",
" atoms.set_initial_magnetic_moments(magmom)\n",
" \n",
" return atoms"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"id": "02010c51-39a9-42e6-a4c8-f03d447267ff",
"metadata": {
"tags": []
Expand All @@ -173,14 +190,14 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"id": "7073bdd7-9ee6-45bf-a401-93cfe122413a",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"calc = make_calculator(relax_method, relax_basis, num_threads=threads)"
"calc = make_calculator(relax_method, relax_basis, num_threads=threads, multiplicity=int(atoms.get_initial_magnetic_moments().sum()) + 1)"
]
},
{
Expand All @@ -193,25 +210,42 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 8,
"id": "33f13e91-894e-45b7-9c54-3a4c98e6390e",
"metadata": {
"tags": []
},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Geometry path: data/exact/methyl-radical_pm7_None.xyz\n"
]
}
],
"source": [
"geom_path = out_dir / f'{molecule_name}_{relax_method}_{relax_basis}.xyz'\n",
"print(f'Geometry path: {geom_path}')"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 9,
"id": "ef903a43-5d6c-47fb-a500-837599c95f91",
"metadata": {
"tags": []
},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"CPU times: user 8.12 ms, sys: 102 µs, total: 8.22 ms\n",
"Wall time: 7.84 ms\n"
]
}
],
"source": [
"%%time\n",
"if geom_path.exists():\n",
Expand All @@ -234,7 +268,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 10,
"id": "a695054d-a768-466e-9771-54395a3c2b81",
"metadata": {
"tags": []
Expand All @@ -246,14 +280,14 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 11,
"id": "16317d90-cb1d-4347-9eca-4ba3123bdf4b",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"write(geom_path, atoms)"
"write(geom_path, atoms, format='extxyz')"
]
},
{
Expand All @@ -275,7 +309,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 12,
"id": "a144434b-e478-42e0-a2bd-5c43beab31d0",
"metadata": {
"tags": []
Expand All @@ -296,7 +330,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 13,
"id": "857e38e3-8b92-4246-8469-5ce6f381d56b",
"metadata": {
"tags": []
Expand All @@ -309,12 +343,21 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 14,
"id": "73b9b8bb-1d32-4e29-9380-95002bb1081e",
"metadata": {
"tags": []
},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"CPU times: user 27.1 ms, sys: 71.5 ms, total: 98.5 ms\n",
"Wall time: 596 ms\n"
]
}
],
"source": [
"%%time\n",
"finite_diff_time = perf_counter()\n",
Expand All @@ -333,7 +376,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 15,
"id": "588b0344-ad43-4a6b-b57b-03782327f1e7",
"metadata": {
"tags": []
Expand All @@ -355,12 +398,23 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 16,
"id": "450b9a10-5c0b-434a-8b20-fedf5f1b1f48",
"metadata": {
"tags": []
},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"0.7311369999245021"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"vib_data.get_zero_point_energy()"
]
Expand All @@ -376,7 +430,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 17,
"id": "da5a4aea-134d-4950-8dbd-df83338983a8",
"metadata": {
"tags": []
Expand Down Expand Up @@ -410,7 +464,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 18,
"id": "273b5116-06ec-4098-8b20-537d1f9d7e84",
"metadata": {
"tags": []
Expand Down
31 changes: 6 additions & 25 deletions tests/files/radical.extxyz
Original file line number Diff line number Diff line change
@@ -1,25 +1,6 @@
23
Properties=species:S:1:pos:R:3:initial_charges:R:1:initial_magmoms:R:1 pbc="F F F"
O 3.56356500 -0.07343200 -1.07159000 0.00000000 0.00000000
O 3.57679100 -0.44393800 0.31148900 0.00000000 0.00000000
H 4.25355100 -0.66175000 -1.41284500 0.00000000 0.00000000
C 2.33027900 -1.04915100 0.61786500 0.00000000 0.00000000
C 1.19457800 -0.06270300 0.86604200 0.00000000 0.00000000
H 2.54506700 -1.60574800 1.53750300 0.00000000 0.00000000
H 2.07254300 -1.76832800 -0.17062400 0.00000000 0.00000000
C 0.73494600 0.71800200 -0.36651000 0.00000000 1.00000000
H 0.35756100 -0.64317700 1.27935800 0.00000000 0.00000000
H 1.50826400 0.63649700 1.65188900 0.00000000 0.00000000
C -0.40279800 1.70583400 -0.07793800 0.00000000 0.00000000
H 1.58274100 1.27536500 -0.77438800 0.00000000 0.00000000
H 0.43693700 0.01221400 -1.15417000 0.00000000 0.00000000
C -1.68053800 1.09443900 0.51146600 0.00000000 0.00000000
H -0.04114500 2.47361300 0.61718700 0.00000000 0.00000000
H -0.65605400 2.23037400 -1.00833000 0.00000000 0.00000000
C -2.26128500 0.00470900 -0.36908400 0.00000000 0.00000000
H -1.48935300 0.68462400 1.50980400 0.00000000 0.00000000
H -2.43284200 1.88156000 0.63553800 0.00000000 0.00000000
O -3.52623500 -0.39685500 0.21032900 0.00000000 0.00000000
H -2.45907600 0.35673900 -1.38706500 0.00000000 0.00000000
H -1.62992800 -0.88699900 -0.41783500 0.00000000 0.00000000
O -4.05654100 -1.39224500 -0.44986000 0.00000000 0.00000000
4
Properties=species:S:1:pos:R:3:initial_magmoms:R:1:forces:R:3 energy=1.2128831450736173 dipole="-0.0 -0.0 -0.0" magmom=1 free_energy=1.2128831450736173 pbc="F F F"
C 2.53693226 0.15500772 0.00000000 1.00000000 0.00009839 0.00004930 -0.00000000
H 3.45167377 0.68313888 0.00000000 0.00000000 0.00792262 0.00481992 -0.00000000
H 1.62217458 0.68308556 0.00000000 0.00000000 -0.00818862 0.00431937 -0.00000000
H 2.53691939 -0.90123216 0.00000000 0.00000000 0.00016760 -0.00918855 -0.00000000
10 changes: 7 additions & 3 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@
from os import devnull
from pathlib import Path

from pytest import mark

from jitterbug.cli import main


def test_exact_solver(xyz_path):
@mark.parametrize('xyz', ['water.xyz', 'radical.extxyz'])
def test_exact_solver(file_dir, xyz):
xyz_name = Path(xyz).with_suffix('').name
with open(devnull, 'w') as fo:
with redirect_stdout(fo):
main([
str(xyz_path), '--exact', '--method', 'pm7', 'None'
str(file_dir / xyz), '--exact', '--method', 'hf', 'sto-3g'
])
assert (Path('run') / 'water' / 'pm7_none_exact' / 'hessian.npy').exists()
assert (Path('run') / xyz_name / 'hf_sto-3g_exact' / 'hessian.npy').exists()


def test_parsl_path(xyz_path, file_dir):
Expand Down
Loading

0 comments on commit 89189b1

Please sign in to comment.