コード例 #1
0
ファイル: pf_task.py プロジェクト: CederGroupHub/MultiFil
    def run_task(self, fw_spec):
        # Edison setting
        # vasp_cmd = ['aprun', '-n', str(fw_spec["_queueadapter"]["mppwidth"]), fw_spec["_fw_env"]['vasp_cmd']]
        # Vesta setting
        cobalt_partname = os.environ['COBALT_PARTNAME']
        vasp_cmd = [
            'runjob', '-n',
            str(fw_spec["_queueadapter"]["nnodes"]), '--block',
            cobalt_partname, '-p', '1', ":", fw_spec["_fw_env"]['vasp_cmd']
        ]
        job = VaspJob(vasp_cmd=vasp_cmd, auto_gamma=False, auto_npar=False)
        if self["handlers"] == "all":
            hnames = [
                "VaspErrorHandler", "MeshSymmetryErrorHandler",
                "UnconvergedErrorHandler", "NonConvergingErrorHandler",
                "PotimErrorHandler", "WalltimeHandler"
            ]
        else:
            hnames = self["handlers"]
        handlers = [load_class("custodian.vasp.handlers", n)() for n in hnames]
        c = Custodian(handlers, [job], **self.get("custodian_params", {}))
        output = c.run()

        chgcar_dir = os.getcwd()

        MyDB.db_access().connect()
        collection = MyDB.db_access().collection(fw_spec['collection'])
        collection.update(
            {
                "mp-id": fw_spec["mp-id"],
                "pair_index": fw_spec["pair_index"]
            }, {"$set": {
                "chgcar_dir": chgcar_dir
            }})
        MyDB.db_access().close()
        return FWAction(stored_data=output)
コード例 #2
0
from pymatgen import Structure, MPRester
from MultiFil_edu.settings.db_singleton import MyDB
from MultiFil_edu.settings.environ import REPO_ROOT

__author__ = 'Ziqin (Shaun) Rong'
__version__ = '0.1'
__maintainer__ = 'Ziqin (Shaun) Rong'
__email__ = '*****@*****.**'


if __name__ == '__main__':
    # Paramters
    col = 'Mg_MV'
    input_file = os.path.join(REPO_ROOT, 'production', 'Mg_approx_neb_example.txt')

    MyDB.db_access().connect()
    collection = MyDB.db_access().collection(col)
    summary = []

    for doc in collection.find({'status': 'success'}):
        if 'MEP_energy' in doc.keys():
            if 'image_0' in doc['MEP_energy'].keys() and 'image_1' in doc['MEP_energy'].keys() and \
                'image_2' in doc['MEP_energy'].keys() and 'image_3' in doc['MEP_energy'].keys() and \
                'image_4' in doc['MEP_energy'].keys() and 'image_5' in doc['MEP_energy'].keys() and \
                'image_6' in doc['MEP_energy'].keys() and 'image_7' in doc['MEP_energy'].keys() and \
                    'image_8' in doc['MEP_energy'].keys():
                if doc['MEP_energy']['image_0']['status'] == 'success' and \
                    doc['MEP_energy']['image_1']['status'] == 'success' and \
                    doc['MEP_energy']['image_2']['status'] == 'success' and \
                    doc['MEP_energy']['image_3']['status'] == 'success' and \
                    doc['MEP_energy']['image_4']['status'] == 'success' and \
コード例 #3
0
from pymatgen.io.vasp import Poscar
from MultiFil_edu.settings.db_singleton import MyDB

__author__ = 'Ziqin (Shaun) Rong'
__version__ = '0.1'
__maintainer__ = 'Ziqin (Shaun) Rong'
__email__ = '*****@*****.**'


# This script runs on Remote servers where we keep the backed-up calculated files

if __name__ == '__main__':
    # The collection you want to run this script over
    col = 'Mg_MV'

    db = MyDB.db_access()
    db.connect()
    collection = db.collection(col)

    for doc in collection.find({"status": "success"}):
        if "MEP_energy" in doc.keys():
            MEP_energy = doc["MEP_energy"]
            for i in range(0, 9):
                if "image_{}".format(i) in doc["MEP_energy"].keys():
                    try:
                        file_path = doc["MEP_energy"]["image_{}".format(i)]["file_path"].split(':')[1]
                        contcar_struct = Poscar.from_file(os.path.join(file_path, "CONTCAR")).structure
                        MEP_energy["image_{}".format(i)]["CONTCAR_struct"] = contcar_struct.as_dict()
                    except OSError:
                        print("mp-id {}, pair_index {}, image {} has no calculation file".format(doc['mp-id'],
                                                                                                 doc['pair_index'],
コード例 #4
0
def multifil_wf(mp_id, specie, col):
    """
    :param mp_id: mp_id for fully discharged Li cathode structures
    :param specie: Moving cation.
    :param db_scripts: default value to rongzq_fw on matgen.mit.edu
    :return: a firework workflow to work on Hopper
    """
    MyDB.db_access().connect()
    collection = MyDB.db_access().collection(col)

    with MPRester('DbftwqIehya780rm') as m:
        response = m.get_data(mp_id, prop='structure')
        formula = m.get_data(mp_id, prop='pretty_formula')
    struct = response[0]['structure']
    struct_copy = struct.copy()
    end_point_finder = EndPointFinder(struct, specie)
    end_point_pairs = end_point_finder.get_end_point_pairs()

    if not end_point_pairs:
        print("No end point pairs found")
        return None
    else:
        struct_orig = []
        for i in range(len(end_point_pairs)):
            struct_orig.append(struct_copy.copy())

        fw_list = []
        fw_depend = {}
        last_fw = None
        for pair in range(len(end_point_pairs)):
            (struct_s1, struct_s2,
             gamma_struct) = end_point_finder.get_gamma_struct(
                 struct_orig[pair], end_point_pairs[pair])
            # Insert into the database
            s1_index = struct_s1.species.index(specie)
            s2_index = struct_s2.species.index(specie)
            collection.insert_one({
                'mp-id':
                mp_id,
                'pretty_formula':
                formula[0]['pretty_formula'],
                'gamma_structure':
                gamma_struct.as_dict(),
                'pair_index':
                pair,
                'cation_diffusion_start':
                struct_s1[s1_index].as_dict(),
                'cation_diffusion_end':
                struct_s2[s2_index].as_dict()
            })
            task1 = WriteGammaInputTask(structure=gamma_struct.as_dict())
            task2 = VaspCustodianTask(handlers='all')
            task3 = PathFinderAnalyze(struct_s1=struct_s1.as_dict(),
                                      struct_s2=struct_s2.as_dict())
            fw = Firework(
                [task1, task2, task3],
                spec={
                    "mp-id": mp_id,
                    'cation_diffusion_start': struct_s1[s1_index].as_dict(),
                    'cation_diffusion_end': struct_s2[s2_index].as_dict(),
                    'moving_cation': specie.as_dict(),
                    'pair_index': pair,
                    "collection": col,
                    "_queueadapter": {
                        'nnodes': 128,
                        'walltime': '12:00:00',
                        'queue': 'Q.JCESR',
                        'job_name': "{}".format(formula[0]['pretty_formula'])
                    }
                })
            fw_list.append(fw)
            if last_fw is not None:
                fw_depend[last_fw] = [fw]
            last_fw = fw
        wf = Workflow(fw_list, fw_depend)
        MyDB.db_access().close()
        return wf
コード例 #5
0
ファイル: pf_task.py プロジェクト: CederGroupHub/MultiFil
    def run_task(self, fw_spec):

        MyDB.db_access().connect()
        collection = MyDB.db_access().collection(fw_spec['collection'])

        with open('vasp.out', 'r') as output:
            content = output.readlines()
        examine = content[-2].strip()
        if examine[0:3] == '1 F':
            chgcar = Chgcar.from_file('CHGCAR')
            s1 = self['struct_s1']
            s2 = self['struct_s2']
            relax_sites = []
            for site_i, site in enumerate(s1.sites):
                if site.specie == fw_spec['moving_cation']:
                    relax_sites.append(site_i)

            pf = NEBPathfinder(s1,
                               s2,
                               relax_sites=relax_sites,
                               v=ChgcarPotential(chgcar).get_v(),
                               n_images=8)
            images = pf.images

            doc = collection.find_one({
                'mp-id': fw_spec["mp-id"],
                'pair_index': fw_spec["pair_index"]
            })
            path = []
            coordination_number = []
            for image in images:
                struct = Structure.from_dict(doc["gamma_structure"])
                site_index = image.species.index(fw_spec['moving_cation'])
                cation_site = image[site_index]
                struct.insert(0,
                              cation_site.specie,
                              cation_site.frac_coords,
                              properties=cation_site.properties)
                path.append(image[site_index].as_dict())
                voro_cn = VoronoiCoordFinder(struct)
                cn = voro_cn.get_coordination_number(0)
                coordination_number.append(cn)

            collection.update(
                {
                    "mp-id": fw_spec["mp-id"],
                    "pair_index": fw_spec["pair_index"]
                }, {
                    "$set": {
                        "status": "success",
                        "CN_path": coordination_number,
                        "path": path
                    }
                })
        else:
            collection.update(
                {
                    "mp-id": fw_spec["mp-id"],
                    "pair_index": fw_spec["pair_index"]
                }, {"$set": {
                    "status": "error"
                }})

        MyDB.db_access().close()

        return FWAction()
コード例 #6
0
def end_point_wf(mp_id, pair_index, image_num, moving_cation, col):
    """

    :param col: collection name
    :param mp_id: mp_id in the db_scripts
    :param pair_index: pair_index in the db_scripts
    :param image_num: index number of the image on the path from the db_scripts
    :param moving_cation: pymatgen.Element object, represeting the moving cation, e.g. Element('Mg')
    :return:
    """
    MyDB.db_access().connect()
    collection = MyDB.db_access().collection(col)

    doc = collection.find_one({'mp-id': mp_id, 'pair_index': pair_index})

    # Calculation that is already successful
    if 'MEP_energy' in doc.keys() and ("image_{}".format(image_num)
                                       in doc['MEP_energy']):
        if doc['MEP_energy']['image_{}'.format(
                image_num)]['status'] == 'success':
            return
        else:
            # Calculation that has halted halfway due to errors
            if 'CONTCAR_struct' in doc['MEP_energy']['image_{}'.format(
                    image_num)].keys():
                struct = Structure.from_dict(doc["MEP_energy"][
                    "image_{}".format(image_num)]["CONTCAR_struct"])
            # Calculation that has not been run before
            else:
                struct = Structure.from_dict(doc['gamma_structure'])
                cation_site = PeriodicSite.from_dict(doc['path'][image_num])
                struct.insert(0,
                              cation_site.specie,
                              cation_site.frac_coords,
                              properties=doc['path'][image_num]['properties'])
    else:
        struct = Structure.from_dict(doc['gamma_structure'])
        cation_site = PeriodicSite.from_dict(doc['path'][image_num])
        struct.insert(0,
                      cation_site.specie,
                      cation_site.frac_coords,
                      properties=doc['path'][image_num]['properties'])

    task1 = WritePointRunInput(structure=struct.as_dict(),
                               moving_cation=moving_cation.as_dict())
    task2 = PointCustodianRun(handlers='all')
    task3 = PointRunAnalyze()

    fw = Firework(
        [task1, task2, task3],
        spec={
            "mp_id": mp_id,
            "pair_index": pair_index,
            "image_num": image_num,
            "collection": col,
            "_queueadapter": {
                'nnodes': 128,
                'walltime': '10:00:00',
                'queue': 'Q.JCESR',
                'job_name': "{}_{}".format(doc["pretty_formula"], image_num)
            }
        })

    wf_list = [fw]
    wf_depend = {}
    wf = Workflow(wf_list, wf_depend)

    MyDB.db_access().close()
    return wf