def test_from_string(self): k1 = AdfKey.from_string("CHARGE -1 0") self.assertEqual(k1.key, "CHARGE") self.assertListEqual(k1.options, [-1, 0]) k2 = AdfKey.from_string("step rad=0.15 angle=10.0") self.assertEqual(k2.key, "step") self.assertListEqual(k2.options[0], ['rad', 0.15]) self.assertListEqual(k2.options[1], ['angle', 10.0]) k3 = AdfKey.from_string("GEOMETRY\noptim all\niterations 100\nEND\n") self.assertEqual(k3.key, "GEOMETRY") self.assertEqual(k3.subkeys[0].options[0], "all") self.assertEqual(k3.subkeys[1].options[0], 100) k4 = AdfKey.from_string( """SCF iterations 300 converge 1.0e-7 1.0e-7 mixing 0.2 diis n=100 ok=0.0001 cyc=100 cx=5.0 cxx=10.0 END""" ) self.assertEqual(k4.key, "SCF") self.assertEqual(k4.subkeys[0].key, "iterations") self.assertEqual(k4.subkeys[1].key, "converge") self.assertEqual(k4.subkeys[1].options[0], 1E-7) self.assertEqual(k4.subkeys[2].options[0], 0.2)
def test_from_string(self): k1 = AdfKey.from_string("CHARGE -1 0") self.assertEqual(k1.key, "CHARGE") self.assertListEqual(k1.options, [-1, 0]) k2 = AdfKey.from_string("step rad=0.15 angle=10.0") self.assertEqual(k2.key, "step") self.assertListEqual(k2.options[0], ['rad', 0.15]) self.assertListEqual(k2.options[1], ['angle', 10.0]) k3 = AdfKey.from_string("GEOMETRY\noptim all\niterations 100\nEND\n") self.assertEqual(k3.key, "GEOMETRY") self.assertEqual(k3.subkeys[0].options[0], "all") self.assertEqual(k3.subkeys[1].options[0], 100) k4 = AdfKey.from_string("""SCF iterations 300 converge 1.0e-7 1.0e-7 mixing 0.2 diis n=100 ok=0.0001 cyc=100 cx=5.0 cxx=10.0 END""") self.assertEqual(k4.key, "SCF") self.assertEqual(k4.subkeys[0].key, "iterations") self.assertEqual(k4.subkeys[1].key, "converge") self.assertEqual(k4.subkeys[1].options[0], 1E-7) self.assertEqual(k4.subkeys[2].options[0], 0.2)
def test_subkeys_subkeys(self): atom_dep_quality = AdfKey("AtomDepQuality", subkeys=[AdfKey("10", ["good"]), AdfKey("12", ["normal"])]) zlmfit = AdfKey("zlmfit", subkeys=[atom_dep_quality]) self.assertEqual(str(zlmfit), zlmfit_string) self.assertEqual(str(AdfKey.from_dict(zlmfit.as_dict())), zlmfit_string)
def test_subkeys(self): smooth = AdfKey("smooth", ["conservepoints"]) optim = AdfKey("optim", ["all", "cartesian"]) iterations = AdfKey("iterations", [250]) step = AdfKey("step", [("rad", 0.15), ("angle", 10.0)]) hessupd = AdfKey("hessupd", ["BFGS"]) converge = AdfKey("converge", [("e", 1.0e-3), ("grad", 3.0e-4), ("rad", 1.0e-2), ("angle", 0.5)]) geo = AdfKey("geometry", subkeys=[smooth, optim, iterations, step, hessupd, converge]) self.assertEqual(str(geo), geometry_string) self.assertEqual(str(AdfKey.from_dict(geo.as_dict())), geometry_string) self.assertTrue(geo.has_subkey("optim"))
def test_subkeys_subkeys(self): atom_dep_quality = AdfKey( "AtomDepQuality", subkeys=[AdfKey("10", ["good"]), AdfKey("12", ["normal"])]) zlmfit = AdfKey("zlmfit", subkeys=[atom_dep_quality]) self.assertEqual(str(zlmfit), zlmfit_string) self.assertEqual(str(AdfKey.from_dict(zlmfit.as_dict())), zlmfit_string)
def test_option_operations(self): k1 = AdfKey("Charge", [-1, 0]) k1.add_option(2) self.assertListEqual(k1.options, [-1, 0, 2]) k1.remove_option(0) self.assertListEqual(k1.options, [0, 2]) k2 = AdfKey.from_string("step rad=0.15 angle=10.0") k2.add_option(["length", 0.1]) self.assertListEqual(k2.options[2], ["length", 0.1]) k2.remove_option("rad") self.assertListEqual(k2.options[0], ["angle", 10.0])
def test_simple(self): unrestricted = AdfKey("unrestricted") self.assertEqual(str(unrestricted).strip(), 'UNRESTRICTED')
def test_atom_block_key(self): block = AdfKey("atoms") o = Molecule.from_str(h2oxyz, "xyz") for site in o: block.add_subkey(AdfKey(str(site.specie), list(site.coords))) self.assertEqual(str(block), atoms_string)
def test_end(self): geo = AdfKey("Geometry") self.assertEqual(str(geo), "GEOMETRY\nEND\n")
def test_subkeys(self): smooth = AdfKey("smooth", ["conservepoints"]) optim = AdfKey("optim", ["all", "cartesian"]) iterations = AdfKey("iterations", [250]) step = AdfKey("step", [("rad", 0.15), ("angle", 10.0)]) hessupd = AdfKey("hessupd", ["BFGS"]) converge = AdfKey("converge", [("e", 1.0e-3), ("grad", 3.0e-4), ("rad", 1.0e-2), ("angle", 0.5)]) geo = AdfKey( "geometry", subkeys=[smooth, optim, iterations, step, hessupd, converge]) self.assertEqual(str(geo), geometry_string) self.assertEqual(str(AdfKey.from_dict(geo.as_dict())), geometry_string) self.assertTrue(geo.has_subkey("optim"))
def test_options(self): charge = AdfKey("charge", [-1, 0]) charge_string = "CHARGE -1 0\n" self.assertEqual(str(charge), "CHARGE -1 0\n") self.assertEqual(str(AdfKey.from_dict(charge.as_dict())), charge_string)
task = AdfTask() o = AdfTask.from_dict(task.as_dict()) self.assertEqual(task.title, o.title) self.assertEqual(task.basis_set, o.basis_set) self.assertEqual(task.scf, o.scf) self.assertEqual(task.geo, o.geo) self.assertEqual(task.operation, o.operation) self.assertEqual(task.units, o.units) self.assertEqual(str(task), str(o)) rhb18 = { "title": "RhB18", "basis_set": AdfKey.from_string("BASIS\ntype TZP\ncore small\nEND"), "xc": AdfKey.from_string("XC\nHybrid PBE0\nEND"), "units": AdfKey.from_string("UNITS\nlength angstrom\nEND"), "other_directives": [ AdfKey.from_string("SYMMETRY"), AdfKey.from_string("RELATIVISTIC scalar zora"), AdfKey.from_string("INTEGRATION 6.0 6.0 6.0"), AdfKey.from_string("SAVE TAPE21"), AdfKey.from_string("A1FIT 10.0") ], "geo_subkeys": [ AdfKey.from_string("optim all"), AdfKey.from_string("iterations 300"), AdfKey.from_string("step rad=0.15 angle=10.0"),
self.assertEqual(str(task), energy_task) def test_serialization(self): task = AdfTask() o = AdfTask.from_dict(task.as_dict()) self.assertEqual(task.title, o.title) self.assertEqual(task.basis_set, o.basis_set) self.assertEqual(task.scf, o.scf) self.assertEqual(task.geo, o.geo) self.assertEqual(task.operation, o.operation) self.assertEqual(task.units, o.units) self.assertEqual(str(task), str(o)) rhb18 = {"title": "RhB18", "basis_set": AdfKey.from_string("BASIS\ntype TZP\ncore small\nEND"), "xc": AdfKey.from_string("XC\nHybrid PBE0\nEND"), "units": AdfKey.from_string("UNITS\nlength angstrom\nEND"), "other_directives": [AdfKey.from_string("SYMMETRY"), AdfKey.from_string("RELATIVISTIC scalar zora"), AdfKey.from_string("INTEGRATION 6.0 6.0 6.0"), AdfKey.from_string("SAVE TAPE21"), AdfKey.from_string("A1FIT 10.0")], "geo_subkeys": [AdfKey.from_string("optim all"), AdfKey.from_string("iterations 300"), AdfKey.from_string("step rad=0.15 angle=10.0"), AdfKey.from_string("hessupd BFGS")], "scf": AdfKey.from_string( """SCF iterations 300 converge 1.0e-7 1.0e-7