Exemplo n.º 1
0
    def gen_all(self):

        wdir_3_mol_relax = self.rootdir + '/3_mol_relax'
        createdir(wdir_3_mol_relax)

        wdir_4_mol_sp = self.rootdir + '/4_mol_sp'
        createdir(wdir_4_mol_sp)

        for i in range(len(self.unique_charges)):
            wdir_3_i = wdir_3_mol_relax + '/mol-{}'.format(i)
            mol = self.unique_mols[i]
            charge = self.unique_charges[i]
            self.gen_mol_rlx(mol, charge, wdir_3_i)
            wdir_4_i = wdir_4_mol_sp + '/mol-{}'.format(i)
            self.gen_mol_sp(mol, charge, wdir_4_i)
            removefile(wdir_4_i + '/POSCAR')

        pbcnelect = 0
        for i in range(len(self.mol_charges)):
            mol = self.pmgmols[i]
            charge = self.mol_charges[i]
            inelect = self.get_mol_nelect(mol, charge)
            pbcnelect += inelect

        wdir_1_pbc_relax = self.rootdir + '/1_pbc_relax'
        createdir(wdir_1_pbc_relax)
        self.gen_pbc_rlx(wdir_1_pbc_relax, pbcnelect)

        wdir_2_pbc_sp = self.rootdir + '/2_pbc_sp'
        createdir(wdir_2_pbc_sp)
        self.gen_pbc_sp(wdir_2_pbc_sp, pbcnelect)
        removefile(wdir_2_pbc_sp + '/POSCAR')
Exemplo n.º 2
0
 def curate_all(self,
                logfolder,
                rawdata_list: [RawData],
                wdir_for_curate,
                unittimelimit=60):
     log_file = '{}/curate_{}.log'.format(logfolder, self.data_access)
     f = open(log_file, 'w')
     sys.stdout = f
     print('curate all at: {}'.format(wdir_for_curate))
     createdir(wdir_for_curate)
     rawdata: RawData
     curated_data_list = []
     classes = OrderedDict({1: [], 2: [], 3: []})
     timeout_entries = []
     for rawdata in rawdata_list:
         print('WORKING ON: {}'.format(rawdata._id))
         this_wdir = '{}/{}'.format(
             wdir_for_curate,
             rawdata.data_properties['basename'].strip('.cif'))
         createdir(this_wdir)
         print('- in folder: {}'.format(this_wdir))
         try:
             with time_limit(unittimelimit):
                 curated_data = self.curate_one(rawdata, this_wdir)
         except TimeoutException as e:
             timeout_entries.append(this_wdir)
             continue
         curated_data_list.append(curated_data)
         integrity_class = curated_data.data_properties['integrity_class']
         print('- integrity_class: {}'.format(integrity_class))
         classes[integrity_class].append(curated_data)
     for integrity_class in classes.keys():
         headermsg = '### integrity class: {} ###'.format(integrity_class)
         print('#' * len(headermsg))
         print(headermsg)
         print('#' * len(headermsg))
         for cdata in classes[integrity_class]:
             print(cdata.data_properties['wdir'] +
                   '/curated_major_config.cif')
         print('\n')
     print('### timeout wdirs ###')
     for timeout_entry in timeout_entries:
         print(timeout_entry)
     f.close()
     sys.stdout = sys.__stdout__
     return curated_data_list, classes
Exemplo n.º 3
0
    def collect_rawdata(self,
                        collect_folder,
                        get_extra_property_from_path=None):
        """
        RawData
            = content (cif_string no diffraction)
                + data_access
                + _id (data_access & cif_header)
        :param collect_folder: a folder to store cif files without diffraction info
        :param get_extra_property_from_path: the path here means the absolute path of a file in self.folder_path
        :return:
            collected_filepaths: absolute path
            raw_data_list: a list of RawData
        """
        filepaths = sorted(
            glob.glob('{}/**/*.cif'.format(self.folder_path), recursive=True))
        print('the path to this contribution is: {}'.format(self.folder_path))
        print('# of cif files: {}'.format(len(filepaths)))
        for cif_property in ['basename', 'md5', 'lattice', 'cifheader']:
            print('---- checking property: {}'.format(cif_property))
            unique_paths, unique_path_to_property, unique_path_to_dup_paths, property_exceptions = get_unique_files(
                filepaths, cif_property)
            print('# of cif files with duplicate: {}'.format(
                len(unique_path_to_dup_paths.keys())))
            for unique_path in unique_path_to_dup_paths.keys():
                print(unique_path)
                for dup in unique_path_to_dup_paths[unique_path]:
                    print('-- {}'.format(dup))
            print('# of cif files with exceptions: {}'.format(
                len(property_exceptions)))
            for exception_path in property_exceptions:
                print(exception_path)
            print('# of cif files unique: {}'.format(len(unique_paths)))
            filepaths = unique_paths
        print('cif without diffraction info will be written to: {}'.format(
            collect_folder))
        print('please note exceptions will not be written')

        createdir(collect_folder)
        collected_filepaths = []

        def get_property(abspath):
            d = OrderedDict({'basename': os.path.basename(abspath)})
            if get_extra_property_from_path is None:
                return d
            else:
                exprops = get_extra_property_from_path(abspath)
                for k in exprops.keys():
                    d[k] = exprops[k]
            return d

        raw_data_list = []
        jsonfiles = []
        for abspath in unique_paths:
            s = read_and_trim(abspath)
            collected_filepath = '{}/{}'.format(collect_folder,
                                                os.path.basename(abspath))
            with open(collected_filepath, 'w') as f:
                f.write(s)
            collected_filepaths.append(collected_filepath)
            raw_data_id = '{}--{}'.format(self.data_access,
                                          get_property_header(abspath))
            raw_data = RawData(s, self.data_access, raw_data_id,
                               get_property(abspath))
            rawdatajson_filepath = '{}/{}.json'.format(
                collect_folder,
                os.path.basename(abspath).strip('.cif'))
            raw_data.to_jsonfile(rawdatajson_filepath)
            raw_data_list.append(raw_data)
            jsonfiles.append(rawdatajson_filepath)
        return collected_filepaths, raw_data_list, jsonfiles
Exemplo n.º 4
0
    def __init__(self, jobname, config, rootdir=None):
        """
        - rootdir
            - 0_mopac
            - 1_pbc_relax
            - 2_pbc_sp
            - 3_mol_relax
                - mol-1
                - mol-2
            - 4_mol_sp
                - mol-1
                - mol-2

        :param jobname:
        :param config:
        :param rootdir:
        """
        if rootdir is None:
            rootdir = jobname
        self.rootdir = rootdir
        mopacwdir = self.rootdir + '/' + '0_mopac'
        createdir(self.rootdir)
        createdir(mopacwdir)
        self.jobname = jobname
        self.config = config
        self.structure = config.unwrap_structure
        self.pmgmols = config.mols
        self.mol_charges = []

        for i in range(len(self.pmgmols)):
            mol = self.pmgmols[i]
            idchgname = '{}_mol-{}'.format(self.jobname, i)
            idchg = IdChg(mol, idchgname, MOPACCMD + ' ' + idchgname)
            idchg.write_inp(mopacwdir)
            d = idchg.run(mopacwdir)
            total_charge = d['total_charge']
            self.mol_charges.append(total_charge)

        self.unique_mols = []
        self.unique_charges = []
        for i in range(len(self.pmgmols)):
            mol = self.pmgmols[i]
            charge = self.mol_charges[i]
            compos = [m.composition for m in self.unique_mols]
            if mol.composition not in compos:
                self.unique_mols.append(mol)
                self.unique_charges.append(charge)

        # so lewis believes the charged radical is close shell
        # it works for small ions, though it thinks ClO4 is 3-, and tfsi is 1+, maybe due to Cl and S
        # also I need to change nelect for pbc as vasp default thinks it's close shell
        for i in range(len(self.unique_charges)):
            if self.unique_charges[i] == 0:
                self.unique_charges[i] = 1
            else:
                self.unique_charges[i] = -1

        for i in range(len(self.mol_charges)):
            if self.mol_charges[i] == 0:
                self.mol_charges[i] = 1
            else:
                self.mol_charges[i] = -1
Exemplo n.º 5
0
 def run(self, d3cmd, wdir):
     createdir(wdir)
     poscarfn = wdir + 'POSCAR_dftd3'
     self.structure.to('poscar', poscarfn)
     result = subprocess.check_output('{} {} {}'.format(d3cmd, poscarfn, self.cmd_option_string), shell=True)
     return result.decode('utf-8')