def calc_save_property(struct_dir, motif_kwargs={}, output_dir='', overwrite=False): """ Adds motif to the property information of each Structure Arguments --------- struct_dir: file path motif_kwargs: see compute_motif output_dir: file path If no output_dir is provided than Structures will be saved in the struct_dir """ struct_dict = read(struct_dir) for struct_id, struct in struct_dict.items(): motif = compute_motif(struct, **motif_kwargs) struct.set_property('motif', motif) if len(output_dir) == 0: output_dir = struct_dir overwrite = True write(output_dir, struct_dict, file_format='json', overwrite=overwrite)
def calc_and_separate(struct_dir, output_dir, motif_kwargs={}, file_format='json', overwrite=False): """ Calculates the motif for each structure in the directory and then separates structures into sub-directories of the output_dir based on the structural motif. """ struct_dict = read(struct_dir) motif_list = implemented_motifs() motif_dict = {} for i, motif in enumerate(motif_list): motif_dict[motif] = i output_dicts = [{} for x in range(len(motif_list))] for struct_id, struct in struct_dict.items(): motif = compute_motif(struct, **motif_kwargs) index = motif_dict[motif] output_dicts[index][struct_id] = struct for i, motif in enumerate(motif_list): motif_struct_dict = output_dicts[i] output_motif_dir = os.path.join(output_dir, motif) write(output_motif_dir, motif_struct_dict, file_format=file_format, overwrite=overwrite)
def __init__(self, directory_path="", file_format=""): """ Creates StructDict for the optional input directory path. """ if len(directory_path) > 0: if not os.path.isdir(directory_path): raise Exception("Path {} for ".format(directory_path) + "StructDict construction was not a directory.") self.update(read(directory_path, file_format=file_format))
def main(): file_path = sys.argv[-1] if not os.path.exists(file_path): raise Exception("Input file {} was not found".format(file_path)) struct = read(file_path) pv = PredictVolume() pred_sf_volume = pv.calc_struct(struct) print("Predicted Solid-Form Volume of {}: {}".format( struct.struct_id, pred_sf_volume))
def calc(self, struct_obj): """ General calc wrapper Arguments --------- struct_obj: str,dict,Structure Can be a string, a dictionary, or a Structure. str: Assume this is a directory path. dict: Structure dictionary Structure: Currently not supported """ if type(struct_obj) == str: if not os.path.isdir(struct_obj): raise Exception("{} is not a directory".format(struct_obj)) if self.jp.size == 1: self.struct_dict = read(struct_obj) self._comparisons() self.calc_dict(self.struct_dict) else: ### Just read onto rank 0 for efficiency. Jobs will be ### communicated later. if self.jp.rank == 0: self.struct_dict = read(struct_obj) self._comparisons() ## Don't need any arguments for parallel implementation self.calc_dict(None) else: ## Don't need any arguments for parallel implementation self.calc_dict(None) if type(struct_obj) == StructDict or \ type(struct_obj) == dict: self.calc_dict(struct_obj) elif type(struct_obj) == Structure: self.calc_struct(struct_obj)
def _calc(self): my_files = self.get_files(self.struct_path) total = len(my_files) for file_path in my_files: struct = read(file_path) self.pymove_class.calc_struct(struct) temp_dict = {struct.struct_id: struct} write(self.output_path, temp_dict, file_format=self.file_format, overwrite=self.overwrite) total -= 1 if self.verbose: print("{}: {}".format(self.rank, total))
def _calc_write(self): """ Same as _calc but uses calls class.write(output_path) after calculation. """ my_files = self.get_files(self.struct_path) total = len(my_files) for file_path in my_files: struct = read(file_path) self.pymove_class.calc_struct(struct) self.pymove_class.write(self.output_path, file_format=self.file_format, overwrite=self.overwrite) total -= 1 if self.verbose: print("{}: {}".format(self.rank, total))
def items(self): """ Similar to values """ s = None for struct_id, file_name in self.id_dict.items(): ## Check write and quit behaviorm if s != None and self.wq == True: self.update(s) file_path = os.path.join(self.directory_path, file_name) s = read(file_path) if s == None: continue yield struct_id, s ## Write last Structure if s != None and self.wq == True: self.update(s)
def values(self): """ Implemented using generator so only a single file is open at a time as the values are iterated. This is the correct implementation for streaming behavior. """ s = None for struct_id, file_name in self.id_dict.items(): ## Check write and quit behaviorm if s != None and self.wq == True: self.update(s) file_path = os.path.join(self.directory_path, file_name) s = read(file_path) if s == None: continue yield s ## Write last Structure if s != None and self.wq == True: self.update(s)
raise Exception( "Only mean roughness mode is implemented at this time.") class Absorbate(SlabSurface): """ Finding the optimal position for an absorbate on a surface. Algorithm works as follows: 1) Get 2) """ if __name__ == "__main__": from pymove.io import read,write s = read("/Users/ibier/Research/Interfaces/Surface_Contour/20200531_Development/SCF/TETCEN.001.1.0.json")
unique.append(duplicates) [id_used.append(x) for x in duplicates] output_dict = {} output_dict["struct"] = self.duplicates_dict output_dict["dups"] = unique with open(file_name, "w") as f: f.write(json.dumps(output_dict, indent=4)) if __name__ == "__main__": from pymove.io import read, write test_dir = "/Users/ibier/Research/Results/Hab_Project/genarris-runs/GIYHUR/20191103_Full_Relaxation/GIYHUR_Relaxed_spg" s = read(test_dir) keys = [x for x in s.keys()] keys = keys[0:5] test_s = {} for entry in keys: test_s[entry] = s[entry] test_s = read( "/Users/ibier/Research/Results/Hab_Project/GAtor-runs/BZOXZT/20200726_Multi_GAtor_Report_Test/Dup_Check_Test/test" ) dc = DuplicateCheck(test_s) ### Parallel Testing dc.jp.job_list = dc.get_job_list()
def __getitem__(self, key): file_name = self.id_dict[key] file_path = os.path.join(self.directory_path, file_name) s = read(file_path) return s
from pymove.io import read,write from pymove.models.predict import PredictVolume from pymove import volume2density pv = PredictVolume() struct_dict = read("../Example_Structures/molecules") for struct_id,struct in struct_dict.items(): pred_sf_volume = pv.calc(struct) print("Predicted Solid-Form Volume of {}: {}" .format(struct_id, pred_sf_volume)) print("Predicted Density of {}: {}" .format(struct_id, volume2density(struct, pred_sf_volume)))
Returns the topological fragments of each atom for a structure. User is allowed to define a radius that the algorithm traverses to build the neighborhood for each atom. If the radius is 0, this would correspond to just return the atoms im the system. Arguments --------- bond_kw: dict Keyword arguments for the molecule bonding module. The default values are the recommended settings. A user may potentially want to decrease the mult. This value is multiplied by covalent bond radii in the MoleculeBonding class. It's highly recommended that the skin value is kept at 0. """ tf = TopologicalFragments(bond_kw={"mult": 1.20, "skin": 0, "update": True}) struct_dict = read("../Example_Structures/molecules") for struct_id, struct in struct_dict.items(): tf.calc_struct(struct) print("{} Fragments and Counts: {}".format( struct_id, struct.properties["topological_fragments"])) ############################################################################### #### Plotting fragment image results ##### ############################################################################### fi = FragmentImage() fi.calc_dict(struct_dict, figname="Fragment_Image.pdf")
If True, overwrites the conformation setting. Only the formula will be checked to determine uniqueness. """ ############################################################################### #### Example for finding molecules from a single crystal structure #### ############################################################################### fm = FindMolecules( mult=1.05, residues=1, conformation=False, formula_check=False) struct = read("../Example_Structures/crystals/BENZEN.cif") fm.calc_struct(struct) print("{} molecules found: {}".format(struct.struct_id, len(fm.molecules))) print("{} unique molecules: {}".format(struct.struct_id, len(fm.unique))) write(fm.unique[0].struct_id, fm.unique[0], file_format="xyz", overwrite=True) ############################################################################### #### Example to iteratively process multiple crystal structures #### ############################################################################### fm = FindMolecules( mult=1.05, conformation=False, formula_check=False,