def __init__(self, nn=pmg_le.CrystalNN(), bbv=0, no_oxi=False, approx_bonds=False, token=' - ', allowed_bonds=None): self.nn = nn self.bbv = bbv self.no_oxi = no_oxi self.approx_bonds = approx_bonds if " " not in token: raise ValueError("A space must be present in the token.") if any([str.isalnum(i) for i in token]): raise ValueError("The token cannot have any alphanumeric " "characters.") token_els = token.split(" ") if len(token_els) != 3 and token != " ": raise ValueError("The token must either be a space or be padded by" "single spaces with no spaces in between.") self.token = token if allowed_bonds is None: self.allowed_bonds = allowed_bonds self.fitted_bonds_ = allowed_bonds else: self.allowed_bonds = self._sanitize_bonds(allowed_bonds) self.fitted_bonds_ = self._sanitize_bonds(allowed_bonds)
def __init__(self, nn_method=pmg_le.CrystalNN()): """ Args: **nn_method: The nearest neighbor method used to determine atomic connectivity. """ self.nn_method = nn_method
def get_structure_coord_df(atoms): atoms_i = atoms structure = AseAtomsAdaptor.get_structure(atoms_i) # CrysNN = local_env.VoronoiNN( # tol=0, # targets=None, # cutoff=13.0, # allow_pathological=False, # weight='solid_angle', # extra_nn_info=True, # compute_adj_neighbors=True, # ) CrysNN = local_env.CrystalNN(weighted_cn=False, cation_anion=False, distance_cutoffs=(0.01, 0.4), x_diff_weight=3.0, porous_adjustment=True, search_cutoff=7, fingerprint_length=None) coord_data_dict = dict() data_master = [] for i_cnt, site_i in enumerate(structure.sites): site_elem_i = site_i.species_string data_dict_i = dict() data_dict_i["element"] = site_elem_i data_dict_i["structure_index"] = i_cnt nn_info_i = CrysNN.get_nn_info(structure, i_cnt) data_dict_i["nn_info"] = nn_info_i neighbor_list = [] for neighbor_j in nn_info_i: neigh_elem_j = neighbor_j["site"].species_string neighbor_list.append(neigh_elem_j) neighbor_count_dict = dict() for i in neighbor_list: neighbor_count_dict[i] = neighbor_count_dict.get(i, 0) + 1 data_dict_i["neighbor_count"] = neighbor_count_dict data_master.append(data_dict_i) df_struct_coord_i = pd.DataFrame(data_master) return (df_struct_coord_i)
def __init__(self, root_dir, max_num_nbr=12, radius=8, nn_method=None, dmin=0, step=0.2, disable_save_torch=False, random_seed=123): self.root_dir = root_dir self.max_num_nbr, self.radius, self.nn_method = max_num_nbr, radius, nn_method self.disable_save_torch = disable_save_torch assert os.path.exists(root_dir), 'root_dir does not exist!' id_prop_file = os.path.join(self.root_dir, 'id_prop.csv') assert os.path.exists(id_prop_file), 'id_prop.csv does not exist!' with open(id_prop_file) as f: reader = csv.reader(f) self.id_prop_data = [[ x.strip().replace('\ufeff', '') for x in row ] for row in reader] random.seed(random_seed) random.shuffle(self.id_prop_data) atom_init_file = os.path.join(self.root_dir, 'atom_init.json') assert os.path.exists(atom_init_file), 'atom_init.json does not exist!' self.ari = AtomCustomJSONInitializer(atom_init_file) self.gdf = GaussianDistance(dmin=dmin, dmax=self.radius, step=step) self.torch_data_path = os.path.join(self.root_dir, 'cifdata') if self.nn_method: if self.nn_method.lower() == 'minimumvirenn': self.nn_object = local_env.MinimumVIRENN() elif self.nn_method.lower() == 'voronoinn': self.nn_object = local_env.VoronoiNN() elif self.nn_method.lower() == 'jmolnn': self.nn_object = local_env.JmolNN() elif self.nn_method.lower() == 'minimumdistancenn': self.nn_object = local_env.MinimumDistanceNN() elif self.nn_method.lower() == 'minimumokeeffenn': self.nn_object = local_env.MinimumOKeeffeNN() elif self.nn_method.lower() == 'brunnernn_real': self.nn_object = local_env.BrunnerNN_real() elif self.nn_method.lower() == 'brunnernn_reciprocal': self.nn_object = local_env.BrunnerNN_reciprocal() elif self.nn_method.lower() == 'brunnernn_relative': self.nn_object = local_env.BrunnerNN_relative() elif self.nn_method.lower() == 'econnn': self.nn_object = local_env.EconNN() elif self.nn_method.lower() == 'cutoffdictnn': #requires a cutoff dictionary located in cgcnn/cut_off_dict.txt self.nn_object = local_env.CutOffDictNN( cut_off_dict='cut_off_dict.txt') elif self.nn_method.lower() == 'critic2nn': self.nn_object = local_env.Critic2NN() elif self.nn_method.lower() == 'openbabelnn': self.nn_object = local_env.OpenBabelNN() elif self.nn_method.lower() == 'covalentbondnn': self.nn_object = local_env.CovalentBondNN() elif self.nn_method.lower() == 'crystalnn': self.nn_object = local_env.CrystalNN() else: raise ValueError('Invalid NN algorithm specified') else: self.nn_object = None
atoms = row_i["atoms"] atoms # view_in_vesta(atoms) # + from pymatgen.analysis import local_env from pymatgen.io.ase import AseAtomsAdaptor structure = AseAtomsAdaptor.get_structure(atoms) CrysNN = local_env.CrystalNN(weighted_cn=False, cation_anion=False, distance_cutoffs=(0.5, 1), x_diff_weight=3.0, porous_adjustment=True, search_cutoff=7, fingerprint_length=None) coord_data_dict = { # "": , } data_master = [] for i_cnt, site_i in enumerate(structure.sites): site_elem_i = site_i.species_string data_dict_i = dict() data_dict_i["element"] = site_elem_i