Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete if __name__ == "__main__": unittest.main() #784

Merged
merged 1 commit into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions atomate/common/firetasks/tests/test_glue_tasks.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import unittest

from fireworks import Firework, Workflow
from fireworks.core.rocket_launcher import rapidfire
Expand Down Expand Up @@ -323,7 +322,3 @@ def test_copyfilesfromcalcloc(self):
self.assertTrue(
os.path.exists(get_calc_loc("fw3", calc_locs)["path"] + "/POSCAR_1")
)


if __name__ == "__main__":
unittest.main()
5 changes: 0 additions & 5 deletions atomate/common/firetasks/tests/test_parse_outputs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import unittest

from fireworks import Firework, Workflow
from fireworks.core.rocket_launcher import rapidfire
Expand Down Expand Up @@ -49,7 +48,3 @@ def test_ToDbTask(self):
self.assertEqual(task1["task_id"], 1)
self.assertEqual(task1["dir_name"], "/test")
self.assertEqual(task1["drone"], "Test Drone")


if __name__ == "__main__":
unittest.main()
5 changes: 0 additions & 5 deletions atomate/common/tests/test_powerups.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ def test_set_queue_adapter(self):
self.assertDictEqual(wf.id_fw[-3].spec, {})

def test_add_additional_fields_to_taskdocs(self):

my_wf = copy_wf(self.bsboltz_wf)
meta_dict = {"foo": "bar", "baz": 42}
my_wf = add_additional_fields_to_taskdocs(my_wf, meta_dict)
Expand Down Expand Up @@ -172,7 +171,3 @@ def test_add_metadata(self):

def copy_wf(wf):
return Workflow.from_dict(wf.to_dict())


if __name__ == "__main__":
unittest.main()
5 changes: 0 additions & 5 deletions atomate/feff/firetasks/tests/test_tasks.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import unittest
from glob import glob

from pymatgen.core import Structure
Expand Down Expand Up @@ -39,7 +38,3 @@ def test_write_paths_task(self):
t.run_task({})
with open("paths_answer.dat") as answer, open("paths.dat") as tmp:
self.assertEqual(answer.readlines(), tmp.readlines())


if __name__ == "__main__":
unittest.main()
5 changes: 0 additions & 5 deletions atomate/feff/fireworks/tests/test_fireworks.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import unittest

from pymatgen.core import Structure

Expand Down Expand Up @@ -32,7 +31,3 @@ def test_exafs_paths_fw(self):
"{{atomate.feff.firetasks.parse_outputs.AddPathsToFilepadTask}}",
]
self.assertEqual(answer, [ft["_fw_name"] for ft in fw_dict["spec"]["_tasks"]])


if __name__ == "__main__":
unittest.main()
5 changes: 0 additions & 5 deletions atomate/feff/workflows/tests/test_eels_workflows.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import unittest

from fireworks.core.fworker import FWorker
from fireworks.core.rocket_launcher import rapidfire
Expand Down Expand Up @@ -122,7 +121,3 @@ def _check_run(self, d):
self.assertEqual(d["absorbing_atom"], self.absorbing_atom)
tags = Tags.from_file(os.path.join(run_dir, "feff.inp"))
self.assertEqual(d["input_parameters"], tags.as_dict())


if __name__ == "__main__":
unittest.main()
4 changes: 0 additions & 4 deletions atomate/feff/workflows/tests/test_exafs_scattering_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,3 @@ def test_feff_input_sets(self):
def test_paths(self):
paths = [[249, 0], [85, 0]]
self.assertEqual(paths, self.fw2_dict["spec"]["_tasks"][2]["paths"])


if __name__ == "__main__":
unittest.main()
5 changes: 0 additions & 5 deletions atomate/feff/workflows/tests/test_xas_workflows.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import unittest

import numpy as np
from fireworks.core.fworker import FWorker
Expand Down Expand Up @@ -126,7 +125,3 @@ def _check_run(self, d):
self.assertEqual(d["input_parameters"], tags.as_dict())
xmu = np.loadtxt(os.path.join(run_dir, "xmu.dat"))
self.assertEqual(d["spectrum"], xmu.tolist())


if __name__ == "__main__":
unittest.main()
4 changes: 0 additions & 4 deletions atomate/lammps/tests/test_drone.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,3 @@ def test_assimilate(self):
# 145.4361,
# ]
# self.assertEqual(lmps_output.as_dict()["thermo_data"]["enthalpy"], enthalpy)


if __name__ == "__main__":
unittest.main()
5 changes: 0 additions & 5 deletions atomate/lammps/tests/test_workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ def setUp(self):
)

def test_lammps_wflow(self):

wf = get_wf_basic(
self.input_file_template,
self.user_settings,
Expand Down Expand Up @@ -94,7 +93,3 @@ def _check_run(self, d):
f"{self.reference_files_path}/peo.dcd",
)
)


if __name__ == "__main__":
unittest.main()
4 changes: 0 additions & 4 deletions atomate/qchem/firetasks/tests/test_critic2.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,3 @@ def test_ProcessCritic2(self):
with open("processed_critic2.json") as f:
just_built = json.load(f)
self.assertEqual(reference, just_built)


if __name__ == "__main__":
unittest.main()
5 changes: 0 additions & 5 deletions atomate/qchem/firetasks/tests/test_fragmenter.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import json
import os
import unittest

from monty.serialization import loadfn # , dumpfn

Expand Down Expand Up @@ -468,7 +467,3 @@ def test_EC_neg(self):
frags = ft.unique_fragments
self.assertEqual(len(frags), 7)
self.assertEqual(len(FWAction_patch.call_args[1]["additions"]), 14)


if __name__ == "__main__":
unittest.main()
7 changes: 0 additions & 7 deletions atomate/qchem/firetasks/tests/test_geo_transformations.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import unittest

import numpy as np
from pymatgen.core.structure import Molecule
Expand All @@ -17,7 +16,6 @@
class TestGeoTransformations(AtomateTest):
@classmethod
def setUpClass(cls):

cls.pt_mol = Molecule.from_file(
os.path.join(
module_dir, "..", "..", "test_files", "pt_gs_wb97mv_tz_initial.xyz"
Expand Down Expand Up @@ -52,7 +50,6 @@ def test_rotate_torsion(self):
class TestPerturbGeometry(AtomateTest):
@classmethod
def setUpClass(cls):

cls.ts_init = Molecule.from_file(
os.path.join(module_dir, "..", "..", "test_files", "ts_init.xyz")
)
Expand Down Expand Up @@ -81,7 +78,3 @@ def test_perturb(self):
np.testing.assert_allclose(
self.ts_perturbed.cart_coords, test_mol.cart_coords, atol=0.0001
)


if __name__ == "__main__":
unittest.main()
112 changes: 84 additions & 28 deletions atomate/qchem/firetasks/tests/test_parse_outputs.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import os
import shutil
import unittest

from pymatgen.core import Molecule
from pymatgen.io.qchem.inputs import QCInput
from monty.serialization import loadfn

from atomate.qchem.firetasks.parse_outputs import QChemToDb
from atomate.utils.testing import AtomateTest

from monty.serialization import loadfn

__author__ = "Samuel Blau"
__email__ = "samblau1@gmail.com"

Expand All @@ -24,62 +20,122 @@ def tearDown(self):
pass

def test_parse_grad_good(self):
my_calc_dir = os.path.join(module_dir, "..", "..", "test_files","parse_grad_good")
my_calc_dir = os.path.join(
module_dir, "..", "..", "test_files", "parse_grad_good"
)
ft = QChemToDb(calc_dir=my_calc_dir, parse_grad_file=True)
ft.run_task({})
task_doc = loadfn(os.path.join(my_calc_dir,"task.json"))
task_doc = loadfn(os.path.join(my_calc_dir, "task.json"))
self.assertEqual(task_doc["output"]["final_energy"], -274.6893362188)
self.assertEqual(len(task_doc["output"]["precise_gradients"]), 10)
self.assertEqual(task_doc["output"]["precise_gradients"][0], [0.0090906486788787, 0.016150932052898, 0.0054568671405536])
self.assertEqual(task_doc["output"]["precise_gradients"][-1], [0.0014495621906601, -0.0018570062958895, 0.0012478282193499])
self.assertEqual(
task_doc["output"]["precise_gradients"][0],
[0.0090906486788787, 0.016150932052898, 0.0054568671405536],
)
self.assertEqual(
task_doc["output"]["precise_gradients"][-1],
[0.0014495621906601, -0.0018570062958895, 0.0012478282193499],
)
os.remove(os.path.join(my_calc_dir, "task.json"))

def test_parse_grad_131(self):
my_calc_dir = os.path.join(module_dir, "..", "..", "test_files","tmqm_grad_pcm")
my_calc_dir = os.path.join(
module_dir, "..", "..", "test_files", "tmqm_grad_pcm"
)
ft = QChemToDb(calc_dir=my_calc_dir, parse_grad_file=True)
ft.run_task({})
task_doc = loadfn(os.path.join(my_calc_dir,"task.json"))
task_doc = loadfn(os.path.join(my_calc_dir, "task.json"))
self.assertEqual(task_doc["output"]["final_energy"], -2791.8404057999)
self.assertEqual(len(task_doc["output"]["precise_gradients"]), 25)
self.assertEqual(task_doc["output"]["precise_gradients"][0], [-2.7425178677332305e-05, 1.8017443772144412e-06, -2.3689773769176685e-06])
self.assertEqual(task_doc["output"]["precise_gradients"][-1], [0.0028753270363098644, -0.000392640066359285, 0.004405091870637312])
self.assertEqual(
task_doc["output"]["precise_gradients"][0],
[-2.7425178677332305e-05, 1.8017443772144412e-06, -2.3689773769176685e-06],
)
self.assertEqual(
task_doc["output"]["precise_gradients"][-1],
[0.0028753270363098644, -0.000392640066359285, 0.004405091870637312],
)
os.remove(os.path.join(my_calc_dir, "task.json"))

def test_parse_grad_bad(self):
my_calc_dir = os.path.join(module_dir, "..", "..", "test_files","parse_grad_bad")
my_calc_dir = os.path.join(
module_dir, "..", "..", "test_files", "parse_grad_bad"
)
ft = QChemToDb(calc_dir=my_calc_dir, parse_grad_file=True)
ft.run_task({})
task_doc = loadfn(os.path.join(my_calc_dir,"task.json"))
task_doc = loadfn(os.path.join(my_calc_dir, "task.json"))
self.assertEqual(task_doc["warnings"]["grad_file_missing"], True)
os.remove(os.path.join(my_calc_dir, "task.json"))


class TestParseOutputQChem_hess(AtomateTest):
def setUp(self, lpad=False):
os.makedirs(os.path.join(module_dir, "..", "..", "test_files", "freq_save_hess", "scratch"))
os.makedirs(
os.path.join(
module_dir, "..", "..", "test_files", "freq_save_hess", "scratch"
)
)
shutil.copyfile(
os.path.join(module_dir, "..", "..", "test_files", "freq_save_hess", "BUP_scratch", "132.0"),
os.path.join(module_dir, "..", "..", "test_files", "freq_save_hess", "scratch", "132.0"),
os.path.join(
module_dir,
"..",
"..",
"test_files",
"freq_save_hess",
"BUP_scratch",
"132.0",
),
os.path.join(
module_dir,
"..",
"..",
"test_files",
"freq_save_hess",
"scratch",
"132.0",
),
)
shutil.copyfile(
os.path.join(module_dir, "..", "..", "test_files", "freq_save_hess", "BUP_scratch", "HESS"),
os.path.join(module_dir, "..", "..", "test_files", "freq_save_hess", "scratch", "HESS"),
os.path.join(
module_dir,
"..",
"..",
"test_files",
"freq_save_hess",
"BUP_scratch",
"HESS",
),
os.path.join(
module_dir,
"..",
"..",
"test_files",
"freq_save_hess",
"scratch",
"HESS",
),
)
super().setUp(lpad=False)

def test_parse_hess(self):
my_calc_dir = os.path.join(module_dir, "..", "..", "test_files","freq_save_hess")
my_calc_dir = os.path.join(
module_dir, "..", "..", "test_files", "freq_save_hess"
)
ft = QChemToDb(calc_dir=my_calc_dir, parse_hess_file=True)
ft.run_task({})
task_doc = loadfn(os.path.join(my_calc_dir,"task.json"))
task_doc = loadfn(os.path.join(my_calc_dir, "task.json"))
self.assertEqual(task_doc["output"]["final_energy"], -151.3244603665)
self.assertEqual(task_doc["output"]["hess_data"]["scratch/132.0"][0],0.12636293260949633)
self.assertEqual(task_doc["output"]["hess_data"]["scratch/132.0"][-2],-0.2025032138024329)
self.assertEqual(task_doc["output"]["hess_data"]["scratch/HESS"][-2], ' -0.175476533300377 -0.202503213802433 0.205623571433770 \n')
self.assertEqual(
task_doc["output"]["hess_data"]["scratch/132.0"][0], 0.12636293260949633
)
self.assertEqual(
task_doc["output"]["hess_data"]["scratch/132.0"][-2], -0.2025032138024329
)
self.assertEqual(
task_doc["output"]["hess_data"]["scratch/HESS"][-2],
" -0.175476533300377 -0.202503213802433 0.205623571433770 \n",
)
os.remove(os.path.join(my_calc_dir, "task.json"))

def tearDown(self):
pass

if __name__ == "__main__":
unittest.main()
9 changes: 3 additions & 6 deletions atomate/qchem/firetasks/tests/test_run_calc.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os
import shutil
import unittest

try:
from unittest.mock import patch
Expand Down Expand Up @@ -545,7 +544,9 @@ def test_RunQChemFake(self):
for key in ref_out:
if key == "dipoles":
self.assertEqual(ref_out[key]["total"], this_out[key]["total"])
np.testing.assert_array_equal(ref_out[key]["dipole"], this_out[key]["dipole"])
np.testing.assert_array_equal(
ref_out[key]["dipole"], this_out[key]["dipole"]
)
else:
try:
self.assertEqual(ref_out[key], this_out[key])
Expand All @@ -556,7 +557,3 @@ def test_RunQChemFake(self):
):
self.assertEqual(os.path.isfile(filename), True)
os.chdir(module_dir)


if __name__ == "__main__":
unittest.main()
6 changes: 0 additions & 6 deletions atomate/qchem/firetasks/tests/test_write_inputs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os
import shutil
import unittest

from pymatgen.core import Molecule
from pymatgen.io.qchem.inputs import QCInput
Expand All @@ -21,7 +20,6 @@
class TestWriteInputQChem(AtomateTest):
@classmethod
def setUpClass(cls):

co_species = ["C", "O"]
co_coords = [[0.0, 0.0, 0.0], [1.3, 0.0, 0.0]]
cls.co_mol = Molecule(co_species, co_coords)
Expand Down Expand Up @@ -191,7 +189,3 @@ def test_write_custom_input(self):
test_dict = QCInput.from_file("mol.qin").as_dict()
for k, v in self.co_opt_diff_in.as_dict().items():
self.assertEqual(v, test_dict[k])


if __name__ == "__main__":
unittest.main()
Loading
Loading