Ejemplo n.º 1
0
class GaussianToComputedEntryDroneTest(unittest.TestCase):

    def setUp(self):
        self.test_dir = os.path.join(os.path.dirname(__file__), "..", "..",
                                     "..", "..", 'test_files', "molecules")
        self.drone = GaussianToComputedEntryDrone(data=["corrections"])
        self.structure_drone = GaussianToComputedEntryDrone(True)

    def test_get_valid_paths(self):
        for path in os.walk(self.test_dir):
            if path[0] == self.test_dir:
                self.assertTrue(len(self.drone.get_valid_paths(path)) > 0)

    def test_assimilate(self):
        test_file = os.path.join(self.test_dir, "methane.log")
        entry = self.drone.assimilate(test_file)
        for p in ["functional", "basis_set", "charge", "spin_mult", 'route']:
            self.assertIn(p, entry.parameters)
        for p in ["corrections"]:
            self.assertIn(p, entry.data)

        self.assertEqual(entry.composition.reduced_formula, "H4C")
        self.assertAlmostEqual(entry.energy, -39.9768775602)
        entry = self.structure_drone.assimilate(test_file)
        self.assertEqual(entry.composition.reduced_formula, "H4C")
        self.assertAlmostEqual(entry.energy, -39.9768775602)
        self.assertIsInstance(entry, ComputedStructureEntry)
        self.assertIsNotNone(entry.structure)
        for p in ["properly_terminated", "stationary_type"]:
            self.assertIn(p, entry.data)

    def test_to_from_dict(self):
        d = self.structure_drone.to_dict
        drone = GaussianToComputedEntryDrone.from_dict(d)
        self.assertEqual(type(drone), GaussianToComputedEntryDrone)
Ejemplo n.º 2
0
class GaussianToComputedEntryDroneTest(unittest.TestCase):
    def setUp(self):
        self.test_dir = os.path.join(os.path.dirname(__file__), "..", "..",
                                     "..", "..", 'test_files', "molecules")
        self.drone = GaussianToComputedEntryDrone(data=["corrections"])
        self.structure_drone = GaussianToComputedEntryDrone(True)

    def test_get_valid_paths(self):
        for path in os.walk(self.test_dir):
            if path[0] == self.test_dir:
                self.assertTrue(len(self.drone.get_valid_paths(path)) > 0)

    def test_assimilate(self):
        test_file = os.path.join(self.test_dir, "methane.log")
        entry = self.drone.assimilate(test_file)
        for p in ["functional", "basis_set", "charge", "spin_mult", 'route']:
            self.assertIn(p, entry.parameters)
        for p in ["corrections"]:
            self.assertIn(p, entry.data)

        self.assertEqual(entry.composition.reduced_formula, "H4C")
        self.assertAlmostEqual(entry.energy, -39.9768775602)
        entry = self.structure_drone.assimilate(test_file)
        self.assertEqual(entry.composition.reduced_formula, "H4C")
        self.assertAlmostEqual(entry.energy, -39.9768775602)
        self.assertIsInstance(entry, ComputedStructureEntry)
        self.assertIsNotNone(entry.structure)
        for p in ["properly_terminated", "stationary_type"]:
            self.assertIn(p, entry.data)

    def test_to_from_dict(self):
        d = self.structure_drone.as_dict()
        drone = GaussianToComputedEntryDrone.from_dict(d)
        self.assertEqual(type(drone), GaussianToComputedEntryDrone)
Ejemplo n.º 3
0
 def setUp(self):
     self.test_dir = os.path.join(
         os.path.dirname(__file__), "..", "..", "..", "..", "test_files", "molecules"
     )
     self.drone = GaussianToComputedEntryDrone(data=["corrections"])
     self.structure_drone = GaussianToComputedEntryDrone(True)
     warnings.simplefilter("ignore")
Ejemplo n.º 4
0
def get_energies(rootdir, reanalyze, verbose, pretty):
    if verbose:
        FORMAT = "%(relativeCreated)d msecs : %(message)s"
        logging.basicConfig(level=logging.INFO, format=FORMAT)
    drone = GaussianToComputedEntryDrone(inc_structure=True,
                                         parameters=['filename'])
    ncpus = multiprocessing.cpu_count()
    logging.info('Detected {} cpus'.format(ncpus))
    queen = BorgQueen(drone, number_of_drones=ncpus)
    if os.path.exists(save_file) and not reanalyze:
        msg = 'Using previously assimilated data from {}. ' + \
              'Use -f to force re-analysis'.format(save_file)
        queen.load_data(save_file)
    else:
        queen.parallel_assimilate(rootdir)
        msg = 'Results saved to {} for faster reloading.'.format(save_file)
        queen.save_data(save_file)

    entries = queen.get_data()
    entries = sorted(entries, key=lambda x: x.parameters['filename'])
    all_data = [(e.parameters['filename'].replace("./", ""),
                 re.sub("\s+", "", e.composition.formula),
                 "{}".format(e.parameters['charge']),
                 "{}".format(e.parameters['spin_mult']),
                 "{:.5f}".format(e.energy), "{:.5f}".format(e.energy_per_atom),
                 ) for e in entries]
    headers = ("Directory", "Formula", "Charge", "Spin Mult.", "Energy",
               "E/Atom")
    print(tabulate(all_data, headers=headers))
    print("")
    print(msg)
Ejemplo n.º 5
0
class GaussianToComputedEntryDroneTest(unittest.TestCase):
    def setUp(self):
        self.drone = GaussianToComputedEntryDrone(data=["corrections"])
        self.structure_drone = GaussianToComputedEntryDrone(True)
        warnings.simplefilter("ignore")

    def tearDown(self):
        warnings.simplefilter("default")

    def test_get_valid_paths(self):
        for path in os.walk(os.path.join(PymatgenTest.TEST_FILES_DIR, "molecules")):
            if path[0] == os.path.join(PymatgenTest.TEST_FILES_DIR, "molecules"):
                self.assertTrue(len(self.drone.get_valid_paths(path)) > 0)

    def test_assimilate(self):
        test_file = os.path.join(PymatgenTest.TEST_FILES_DIR, "molecules", "methane.log")
        entry = self.drone.assimilate(test_file)
        for p in [
            "functional",
            "basis_set",
            "charge",
            "spin_multiplicity",
            "route_parameters",
        ]:
            self.assertIn(p, entry.parameters)
        for p in ["corrections"]:
            self.assertIn(p, entry.data)

        self.assertEqual(entry.composition.reduced_formula, "H4C")
        self.assertAlmostEqual(entry.energy, -39.9768775602)
        entry = self.structure_drone.assimilate(test_file)
        self.assertEqual(entry.composition.reduced_formula, "H4C")
        self.assertAlmostEqual(entry.energy, -39.9768775602)
        self.assertIsInstance(entry, ComputedStructureEntry)
        self.assertIsNotNone(entry.structure)
        for p in ["properly_terminated", "stationary_type"]:
            self.assertIn(p, entry.data)

    def test_to_from_dict(self):
        d = self.structure_drone.as_dict()
        drone = GaussianToComputedEntryDrone.from_dict(d)
        self.assertEqual(type(drone), GaussianToComputedEntryDrone)
Ejemplo n.º 6
0
 def setUp(self):
     self.test_dir = os.path.join(os.path.dirname(__file__), "..", "..",
                                  "..", "..", 'test_files', "molecules")
     self.drone = GaussianToComputedEntryDrone(data=["corrections"])
     self.structure_drone = GaussianToComputedEntryDrone(True)
Ejemplo n.º 7
0
 def test_to_from_dict(self):
     d = self.structure_drone.to_dict
     drone = GaussianToComputedEntryDrone.from_dict(d)
     self.assertEqual(type(drone), GaussianToComputedEntryDrone)
Ejemplo n.º 8
0
 def setUp(self):
     self.test_dir = os.path.join(os.path.dirname(__file__), "..", "..",
                                  "..", "..", 'test_files', "molecules")
     self.drone = GaussianToComputedEntryDrone(data=["corrections"])
     self.structure_drone = GaussianToComputedEntryDrone(True)
Ejemplo n.º 9
0
 def test_to_from_dict(self):
     d = self.structure_drone.as_dict()
     drone = GaussianToComputedEntryDrone.from_dict(d)
     self.assertEqual(type(drone), GaussianToComputedEntryDrone)
Ejemplo n.º 10
0
 def setUp(self):
     self.drone = GaussianToComputedEntryDrone(data=["corrections"])
     self.structure_drone = GaussianToComputedEntryDrone(True)
     warnings.simplefilter("ignore")
Ejemplo n.º 11
0
 def setUp(self):
     self.drone = GaussianToComputedEntryDrone(data=["corrections"])
     self.structure_drone = GaussianToComputedEntryDrone(True)