Esempio n. 1
0
    def test_clean_json(self):
        #clean_json should have no effect on None types.
        d = {"hello": 1, "world": None}
        clean = clean_json(d)
        self.assertIsNone(clean["world"])
        self.assertEqual(json.dumps(d), json.dumps(clean))

        d = {"hello": self.get_test_structure()}
        self.assertRaises(TypeError, json.dumps, d)
        clean = clean_json(d)
        self.assertIsInstance(clean["hello"], basestring)
        clean_strict = clean_json(d, strict=True)
        self.assertIsInstance(clean_strict["hello"], dict)
Esempio n. 2
0
    def test_clean_json(self):
        #clean_json should have no effect on None types.
        d = {"hello": 1, "world": None}
        clean = clean_json(d)
        self.assertIsNone(clean["world"])
        self.assertEqual(json.dumps(d), json.dumps(clean))

        d = {"hello": self.get_test_structure()}
        self.assertRaises(TypeError, json.dumps, d)
        clean = clean_json(d)
        self.assertIsInstance(clean["hello"], basestring)
        clean_strict = clean_json(d, strict=True)
        self.assertIsInstance(clean_strict["hello"], dict)
Esempio n. 3
0
    def get_dos_dict(self):
        """
        Returns the added doses as a json-serializable dict. Note that if you
        have specified smearing for the DOS plot, the densities returned will
        be the smeared densities, not the original densities.

        Returns:
            Dict of dos data. Generally of the form, {label: {'energies':..,
            'densities': {'up':...}, 'efermi':efermi}}
        """
        return clean_json(self._doses)
Esempio n. 4
0
    def get_dos_dict(self):
        """
        Returns the added doses as a json-serializable dict. Note that if you
        have specified smearing for the DOS plot, the densities returned will
        be the smeared densities, not the original densities.

        Returns:
            Dict of dos data. Generally of the form, {label: {'energies':..,
            'densities': {'up':...}, 'efermi':efermi}}
        """
        return clean_json(self._doses)
Esempio n. 5
0
 def to_dict(self):
     from pymatgen.util.io_utils import clean_json
     results = {'gap': self.gap,
                'mu_steps': self.mu_steps,
                'cond': self.cond,
                'seebeck': self.seebeck,
                'kappa': self.kappa,
                'hall': self.hall,
                'warning': self.warning, 'doping': self.doping,
                'mu_doping': self.mu_doping,
                'seebeck_doping': self.seebeck_doping,
                'cond_doping': self.cond_doping,
                'kappa_doping': self.kappa_doping,
                'hall_doping': self.hall_doping,
                'dos': self.dos.to_dict,
                'carrier_conc': self.carrier_conc,
                'vol': self.vol}
     return clean_json(results)
Esempio n. 6
0
 def to_dict(self):
     from pymatgen.util.io_utils import clean_json
     results = {'gap': self.gap,
                'mu_steps': self.mu_steps,
                'cond': self.cond,
                'seebeck': self.seebeck,
                'kappa': self.kappa,
                'hall': self.hall,
                'warning': self.warning, 'doping': self.doping,
                'mu_doping': self.mu_doping,
                'seebeck_doping': self.seebeck_doping,
                'cond_doping': self.cond_doping,
                'kappa_doping': self.kappa_doping,
                'hall_doping': self.hall_doping,
                'dos': self.dos.to_dict,
                'dos_partial': self._dos_partial,
                'carrier_conc': self.carrier_conc,
                'vol': self.vol}
     return clean_json(results)
Esempio n. 7
0
    def to_dict(self):
        from pymatgen.util.io_utils import clean_json

        results = {
            "gap": self.gap,
            "mu_steps": self.mu_steps,
            "cond": self.cond,
            "seebeck": self.seebeck,
            "kappa": self.kappa,
            "hall": self.hall,
            "warning": self.warning,
            "doping": self.doping,
            "mu_doping": self.mu_doping,
            "seebeck_doping": self.seebeck_doping,
            "cond_doping": self.cond_doping,
            "kappa_doping": self.kappa_doping,
            "hall_doping": self.hall_doping,
            "dos": self.dos.to_dict,
            "dos_partial": self._dos_partial,
            "carrier_conc": self.carrier_conc,
            "vol": self.vol,
        }
        return clean_json(results)
Esempio n. 8
0
    def run_task(self, fw_spec):

        # get the band structure and nelect from files
        """
        prev_dir = get_loc(fw_spec['prev_vasp_dir'])
        vasprun_loc = zpath(os.path.join(prev_dir, 'vasprun.xml'))
        kpoints_loc = zpath(os.path.join(prev_dir, 'KPOINTS'))

        vr = Vasprun(vasprun_loc)
        bs = vr.get_band_structure(kpoints_filename=kpoints_loc)
        """

        # get the band structure and nelect from DB
        block_part = get_block_part(fw_spec['prev_vasp_dir'])

        db_dir = os.environ['DB_LOC']
        assert isinstance(db_dir, object)
        db_path = os.path.join(db_dir, 'tasks_db.json')
        with open(db_path) as f:
            creds = json.load(f)
            connection = MongoClient(creds['host'], creds['port'])
            tdb = connection[creds['database']]
            tdb.authenticate(creds['admin_user'], creds['admin_password'])

            m_task = tdb.tasks.find_one({"dir_name": block_part}, {"calculations": 1, "task_id": 1})
            nelect = m_task['calculations'][0]['input']['parameters']['NELECT']
            bs_id = m_task['calculations'][0]['band_structure_fs_id']
            print bs_id, type(bs_id)
            fs = gridfs.GridFS(tdb, 'band_structure_fs')
            bs_dict = json.loads(fs.get(bs_id).read())
            bs_dict['structure'] = m_task['calculations'][0]['output']['crystal']
            bs = BandStructure.from_dict(bs_dict)
            print 'Band Structure found:', bool(bs)
            print nelect

            # run Boltztrap
            runner = BoltztrapRunner(bs, nelect)
            dir = runner.run(path_dir=os.getcwd())

            # put the data in the database
            bta = BoltztrapAnalyzer.from_files(dir)
            data = bta.to_dict
            data.update(get_meta_from_structure(bs._structure))
            data['snlgroup_id'] = fw_spec['snlgroup_id']
            data['run_tags'] = fw_spec['run_tags']
            data['snl'] = fw_spec['mpsnl']
            data['dir_name_full'] = dir
            data['dir_name'] = get_block_part(dir)
            data['task_id'] = m_task['task_id']
            data['hall'] = {}  # remove because it is too large and not useful
            data['hall_doping'] = {}  # remove because it is too large and not useful
            tdb.boltztrap.insert(clean_json(data))

        update_spec = {'prev_vasp_dir': fw_spec['prev_vasp_dir'],
                       'boltztrap_dir': os.getcwd(),
                       'prev_task_type': fw_spec['task_type'],
                       'mpsnl': fw_spec['mpsnl'],
                       'snlgroup_id': fw_spec['snlgroup_id'],
                       'run_tags': fw_spec['run_tags'], 'parameters': fw_spec.get('parameters')}

        return FWAction(update_spec=update_spec)
Esempio n. 9
0
    def run_task(self, fw_spec):

        # get the band structure and nelect from files
        """
        prev_dir = get_loc(fw_spec['prev_vasp_dir'])
        vasprun_loc = zpath(os.path.join(prev_dir, 'vasprun.xml'))
        kpoints_loc = zpath(os.path.join(prev_dir, 'KPOINTS'))

        vr = Vasprun(vasprun_loc)
        bs = vr.get_band_structure(kpoints_filename=kpoints_loc)
        """

        # get the band structure and nelect from DB
        block_part = get_block_part(fw_spec['prev_vasp_dir'])

        db_dir = os.environ['DB_LOC']
        assert isinstance(db_dir, object)
        db_path = os.path.join(db_dir, 'tasks_db.json')
        with open(db_path) as f:
            creds = json.load(f)
            connection = MongoClient(creds['host'], creds['port'])
            tdb = connection[creds['database']]
            tdb.authenticate(creds['admin_user'], creds['admin_password'])

            m_task = tdb.tasks.find_one({"dir_name": block_part}, {
                "calculations": 1,
                "task_id": 1
            })
            nelect = m_task['calculations'][0]['input']['parameters']['NELECT']
            bs_id = m_task['calculations'][0]['band_structure_fs_id']
            print bs_id, type(bs_id)
            fs = gridfs.GridFS(tdb, 'band_structure_fs')
            bs_dict = json.loads(fs.get(bs_id).read())
            bs_dict['structure'] = m_task['calculations'][0]['output'][
                'crystal']
            bs = BandStructure.from_dict(bs_dict)
            print 'Band Structure found:', bool(bs)
            print nelect

            # run Boltztrap
            runner = BoltztrapRunner(bs, nelect)
            dir = runner.run(path_dir=os.getcwd())

            # put the data in the database
            bta = BoltztrapAnalyzer.from_files(dir)
            data = bta.to_dict
            data.update(get_meta_from_structure(bs._structure))
            data['snlgroup_id'] = fw_spec['snlgroup_id']
            data['run_tags'] = fw_spec['run_tags']
            data['snl'] = fw_spec['mpsnl']
            data['dir_name_full'] = dir
            data['dir_name'] = get_block_part(dir)
            data['task_id'] = m_task['task_id']
            data['hall'] = {}  # remove because it is too large and not useful
            data['hall_doping'] = {
            }  # remove because it is too large and not useful
            tdb.boltztrap.insert(clean_json(data))

        update_spec = {
            'prev_vasp_dir': fw_spec['prev_vasp_dir'],
            'boltztrap_dir': os.getcwd(),
            'prev_task_type': fw_spec['task_type'],
            'mpsnl': fw_spec['mpsnl'],
            'snlgroup_id': fw_spec['snlgroup_id'],
            'run_tags': fw_spec['run_tags'],
            'parameters': fw_spec.get('parameters')
        }

        return FWAction(update_spec=update_spec)