コード例 #1
0
 def __init__(self,
              host="127.0.0.1",
              port=27017,
              database="vasp",
              user=None,
              password=None,
              collection="nanoparticles",
              parse_dos=False,
              compress_dos=False,
              simulate_mode=False,
              additional_fields=None,
              update_duplicates=True,
              mapi_key=None,
              use_full_uri=True,
              runs=None):
     VaspToDbTaskDrone.__init__(self,
                                host=host,
                                port=port,
                                database=database,
                                user=user,
                                password=password,
                                collection=collection,
                                parse_dos=parse_dos,
                                compress_dos=compress_dos,
                                simulate_mode=simulate_mode,
                                additional_fields=additional_fields,
                                update_duplicates=update_duplicates,
                                mapi_key=mapi_key,
                                use_full_uri=use_full_uri,
                                runs=runs)
コード例 #2
0
ファイル: caesar.py プロジェクト: jrbp/caesar_py
    def from_files(cls, disp_dir):
        """
        Args:
            disp_dir:
                directory corresponding to this displacement (usually written by caesar as atomn.dispm)

        Returns:
            CaesarDisplacement object
        """
        amplitude = float(
            np.genfromtxt(os.path.join(disp_dir, 'amplitude.dat')))
        disp = np.genfromtxt(os.path.join(disp_dir, 'disp.dat')).tolist()
        #drone = VaspToComputedEntryDrone(inc_structure=True)
        #TODO: Possibly either find another drone or combine Vasprun and Outcar here
        #       because this drone will return a dict, not an object. Don't forget to modify from_dict and the docstring if you make this change.
        drone = VaspToDbTaskDrone(simulate_mode=True)
        print 'assimilating vaspruns in ', disp_dir
        positive = drone.assimilate(os.path.join(disp_dir, 'positive'))
        #returned dict has last_updated as datetime.datetime object which jsanitize complains about
        if 'last_updated' in positive:
            positive['last_updated'] = str(positive['last_updated'])
        negative = drone.assimilate(os.path.join(disp_dir, 'negative'))
        if 'last_updated' in negative:
            negative['last_updated'] = str(negative['last_updated'])
        return cls(amplitude, disp, positive, negative)
コード例 #3
0
    def run_task(self, fw_spec):
        prev_dir = fw_spec['prev_vasp_dir']

        # get the db credentials
        db_dir = os.environ['DB_LOC']
        db_path = os.path.join(db_dir, 'tasks_db.json')

        # use MPDrone to put it in the database
        with open(db_path) as f:
            db_creds = json.load(f)
            drone = VaspToDbTaskDrone(host=db_creds['host'],
                                      port=db_creds['port'],
                                      database=db_creds['database'],
                                      user=db_creds['admin_user'],
                                      password=db_creds['admin_password'],
                                      collection=db_creds['collection'])
            t_id = drone.assimilate(prev_dir)

        if t_id:
            print 'ENTERED task id:', t_id
            stored_data = {'task_id': t_id}
            update_spec = {
                'prev_vasp_dir': prev_dir,
                'prev_task_type': fw_spec['prev_task_type']
            }
            return FWAction(stored_data=stored_data, update_spec=update_spec)
        else:
            raise ValueError("Could not parse entry for database insertion!")
コード例 #4
0
ファイル: database.py プロジェクト: henniggroup/MPInterfaces
 def __init__(self, host="127.0.0.1", port=27017, database="vasp",
              user=None, password=None, collection="nanoparticles",
              parse_dos=False, compress_dos=False,
              simulate_mode=False,
              additional_fields=None, update_duplicates=True,
              mapi_key=None, use_full_uri=True, runs=None):
     VaspToDbTaskDrone.__init__(self, host=host, port=port,
                                database=database, user=user,
                                password=password,
                                collection=collection,
                                parse_dos=parse_dos,
                                compress_dos=compress_dos,
                                simulate_mode=simulate_mode,
                                additional_fields=additional_fields,
                                update_duplicates=update_duplicates,
                                mapi_key=mapi_key,
                                use_full_uri=use_full_uri,
                                runs=runs)
コード例 #5
0
 def setUpClass(cls):
     try:
         drone = VaspToDbTaskDrone(database="qetransmuter_unittest")
         queen = BorgQueen(drone)
         queen.serial_assimilate(
             os.path.join(test_dir, 'db_test', 'success_mp_aflow'))
         cls.conn = MongoClient()
         cls.qe = QueryEngine(database="qetransmuter_unittest")
     except ConnectionFailure:
         cls.qe = None
         cls.conn = None
コード例 #6
0
ファイル: firetasks_ex.py プロジェクト: aykol/MPWorks
    def run_task(self, fw_spec):
        prev_dir = fw_spec['prev_vasp_dir']

        # get the db credentials
        db_dir = os.environ['DB_LOC']
        db_path = os.path.join(db_dir, 'tasks_db.json')

        # use MPDrone to put it in the database
        with open(db_path) as f:
            db_creds = json.load(f)
            drone = VaspToDbTaskDrone(
                host=db_creds['host'], port=db_creds['port'],
                database=db_creds['database'], user=db_creds['admin_user'],
                password=db_creds['admin_password'],
                collection=db_creds['collection'])
            t_id = drone.assimilate(prev_dir)

        if t_id:
            print 'ENTERED task id:', t_id
            stored_data = {'task_id': t_id}
            update_spec = {'prev_vasp_dir': prev_dir, 'prev_task_type': fw_spec['prev_task_type']}
            return FWAction(stored_data=stored_data, update_spec=update_spec)
        else:
            raise ValueError("Could not parse entry for database insertion!")
コード例 #7
0
    def test_assimilate(self):
        """Borg assimilation code.
        This takes too long for a unit test!
        """
        simulate = True if VaspToDbTaskDroneTest.conn is None else False
        drone = VaspToDbTaskDrone(database="creator_unittest",
                                  simulate_mode=simulate,
                                  parse_dos=True,
                                  compress_dos=1)
        queen = BorgQueen(drone)
        queen.serial_assimilate(os.path.join(test_dir, 'db_test'))
        data = queen.get_data()
        self.assertEqual(len(data), 6)
        if VaspToDbTaskDroneTest.conn:
            db = VaspToDbTaskDroneTest.conn["creator_unittest"]
            data = db.tasks.find()
            self.assertEqual(data.count(), 6)
            warnings.warn("Actual db insertion mode.")

        for d in data:
            dir_name = d['dir_name']
            if dir_name.endswith("killed_mp_aflow"):
                self.assertEqual(d['state'], "killed")
                self.assertFalse(d['is_hubbard'])
                self.assertEqual(d['pretty_formula'], "SiO2")
            elif dir_name.endswith("stopped_mp_aflow"):
                self.assertEqual(d['state'], "stopped")
                self.assertEqual(d['pretty_formula'], "ThFe5P3")
            elif dir_name.endswith("success_mp_aflow"):
                self.assertEqual(d['state'], "successful")
                self.assertEqual(d['pretty_formula'], "TbZn(BO2)5")
                self.assertAlmostEqual(d['output']['final_energy'],
                                       -526.66747274, 4)
            elif dir_name.endswith("Li2O_aflow"):
                self.assertEqual(d['state'], "successful")
                self.assertEqual(d['pretty_formula'], "Li2O")
                self.assertAlmostEqual(d['output']['final_energy'],
                                       -14.31446494, 6)
                self.assertEqual(len(d["calculations"]), 2)
                self.assertEqual(d['input']['is_lasph'], False)
                self.assertEqual(d['input']['xc_override'], None)
            elif dir_name.endswith("Li2O"):
                self.assertEqual(d['state'], "successful")
                self.assertEqual(d['pretty_formula'], "Li2O")
                self.assertAlmostEqual(d['output']['final_energy'],
                                       -14.31337758, 6)
                self.assertEqual(len(d["calculations"]), 1)
                self.assertEqual(len(d["custodian"]), 1)
                self.assertEqual(len(d["custodian"][0]["corrections"]), 1)
            elif dir_name.endswith("Li2O_aflow_lasph"):
                self.assertEqual(d['state'], "successful")
                self.assertEqual(d['pretty_formula'], "Li2O")
                self.assertAlmostEqual(d['output']['final_energy'], -13.998171,
                                       6)
                self.assertEqual(len(d["calculations"]), 2)
                self.assertEqual(d['input']['is_lasph'], True)
                self.assertEqual(d['input']['xc_override'], "PS")

        if VaspToDbTaskDroneTest.conn:
            warnings.warn("Testing query engine mode.")
            qe = QueryEngine(database="creator_unittest")
            self.assertEqual(qe.query().count(), 6)
            #Test mappings by query engine.
            for r in qe.query(
                    criteria={"pretty_formula": "Li2O"},
                    properties=["dir_name", "energy", "calculations",
                                "input"]):
                if r["dir_name"].endswith("Li2O_aflow"):
                    self.assertAlmostEqual(r['energy'], -14.31446494, 4)
                    self.assertEqual(len(r["calculations"]), 2)
                    self.assertEqual(r["input"]["is_lasph"], False)
                    self.assertEqual(r['input']['xc_override'], None)
                elif r["dir_name"].endswith("Li2O"):
                    self.assertAlmostEqual(r['energy'], -14.31337758, 4)
                    self.assertEqual(len(r["calculations"]), 1)
                    self.assertEqual(r["input"]["is_lasph"], False)
                    self.assertEqual(r['input']['xc_override'], None)

            #Test lasph
            e = qe.get_entries({"dir_name": {"$regex": "lasph"}})
            self.assertEqual(len(e), 1)
            self.assertEqual(e[0].parameters["is_lasph"], True)
            self.assertEqual(e[0].parameters["xc_override"], "PS")

            # Test query one.
            d = qe.query_one(criteria={"pretty_formula": "TbZn(BO2)5"},
                             properties=["energy"])
            self.assertAlmostEqual(d['energy'], -526.66747274, 4)

            d = qe.get_entries_in_system(["Li", "O"])
            self.assertEqual(len(d), 3)
            self.assertIsInstance(d[0], ComputedEntry)

            s = qe.get_structure_from_id(d[0].entry_id)
            self.assertIsInstance(s, Structure)
            self.assertEqual(s.formula, "Li2 O1")

            self.assertIsInstance(qe.get_dos_from_id(d[0].entry_id),
                                  CompleteDos)
コード例 #8
0
 def test_to_from_dict(self):
     drone = VaspToDbTaskDrone(database="wacky", simulate_mode=True)
     d = drone.as_dict()
     drone = VaspToDbTaskDrone.from_dict(d)
     self.assertTrue(drone.simulate)
     self.assertEqual(drone.database, "wacky")
コード例 #9
0
 def test_get_valid_paths(self):
     drone = VaspToDbTaskDrone(simulate_mode=True)
     all_paths = []
     for path in os.walk(os.path.join(test_dir, 'db_test')):
         all_paths.extend(drone.get_valid_paths(path))
     self.assertEqual(len(all_paths), 6)
コード例 #10
0
"""
#%%

import json
from pynter.data.datasets import Dataset
from pymatgen.io.vasp.inputs import VaspInput, Incar, Kpoints, Poscar, Potcar
from pymatgen.core.structure import Structure

ds = Dataset.from_directory(
    '/home/lorenzo/tests/project-test/tutorials/Si-BS-dataset')

#%%

from matgendb.creator import VaspToDbTaskDrone

drone = VaspToDbTaskDrone(collection='test')

for j in ds:
    drone.assimilate(j.path)

#%%

from matgendb.query_engine import QueryEngine

qe = QueryEngine(collection='test')

# entries = qe.get_entries({'dir_name':'localhost:/home/lorenzo/tests/project-test/tutorials/Si-BS-dataset/3-PBE-BS'})

entries = qe.get_entries({'chemsys': 'Si'},
                         optional_data=['calculations'],
                         inc_structure=True)
コード例 #11
0
 def test_to_from_dict(self):
     drone = VaspToDbTaskDrone(database="wacky", simulate_mode=True)
     d = drone.to_dict
     drone = VaspToDbTaskDrone.from_dict(d)
     self.assertTrue(drone.simulate)
     self.assertEqual(drone.database, "wacky")
コード例 #12
0
 def test_get_valid_paths(self):
     drone = VaspToDbTaskDrone(simulate_mode=True)
     all_paths = []
     for path in os.walk(os.path.join(test_dir, 'db_test')):
         all_paths.extend(drone.get_valid_paths(path))
     self.assertEqual(len(all_paths), 5)
コード例 #13
0
    def run_task(self, fw_spec):

        """
            Required Parameters:
                host (str): See SurfaceWorkflowManager in surface_wf.py
                port (int): See SurfaceWorkflowManager in surface_wf.py
                user (str): See SurfaceWorkflowManager in surface_wf.py
                password (str): See SurfaceWorkflowManager in surface_wf.py
                database (str): See SurfaceWorkflowManager in surface_wf.py
                collection (str): See SurfaceWorkflowManager in surface_wf.py
                struct_type (str): either oriented_unit_cell or slab_cell
                miller_index (list): Miller Index of the oriented
                    unit cell or slab
                loc (str path): Location of the outputs of
                    the vasp calculations
            Optional Parameters:
                surface_area (float): surface area of the slab, obtained
                    from slab object before relaxation
                shift (float): A shift value in Angstrom that determines how
                    much a slab should be shifted. For determining number of
                    terminations, obtained from slab object before relaxation
                vsize (float): Size of vacuum layer of slab in Angstroms,
                    obtained from slab object before relaxation
                ssize (float): Size of slab layer of slab in Angstroms,
                    obtained from slab object before relaxation
        """

        dec = MontyDecoder()
        struct_type = dec.process_decoded(self.get("struct_type"))
        loc = dec.process_decoded(self.get("loc"))
        cwd = dec.process_decoded(self.get("cwd"))
        surface_area = dec.process_decoded(self.get("surface_area", None))
        shift = dec.process_decoded(self.get("shift", None))
        vsize = dec.process_decoded(self.get("vsize", None))
        ssize = dec.process_decoded(self.get("ssize", None))
        miller_index = dec.process_decoded(self.get("miller_index"))

        # Sets default for DB parameters
        if not self["host"]:
            self["host"] = "127.0.0.1"

        if not self["port"]:
            self["port"] = 27017

        if not self["database"]:
            self["database"] = "vasp"

        if not self["collection"]:
            self["collection"] = "tasks"

        # Addtional info relating to slabs
        additional_fields={"author": os.environ.get("USER"),
                           "structure_type": struct_type,
                           "miller_index": miller_index,
                           "surface_area": surface_area, "shift": shift,
                           "vac_size": vsize, "slab_size": ssize}

        drone = VaspToDbTaskDrone(host=self["host"], port=self["port"],
                                  user=self["user"],
                                  password=self["password"],
                                  database=self["database"],
                                  use_full_uri=False,
                                  additional_fields=additional_fields,
                                  collection=self["collection"])
        drone.assimilate(cwd+loc)