def init_ref(self, x): aclus = [] for xx in x: print("transforming ref nebpaths ...") clus = read_zip_clusters(xx) if self.surf is not None: # here we did the surface replacement clus = [ ClusterAtSurface.from_cluster(sc, self.surf) for sc in clus ] for c in clus: labels = c.label.split(":") if "." not in labels[1]: c.tid = int(labels[1]) c.tidx = [int(labels[1]), 0] else: c.tid = int(labels[1].split(".")[0]) c.tidx = [int(p) for p in labels[1].split(".")] c.stidx = ".".join([str(p) for p in c.tidx]) # backup results if not "trans.xyz." in xx: xy = xx.replace(".xyz.", ".trans.xyz.") writter = RecordWritter() writter.write_clusters(xy, clus, False) aclus.extend(clus) return aclus
def __init__(self, parent, ip): self.ip = ip self.p = parent self.iprp = self.ip["reaction-path"] self.surf = None self.init_surface() print(self.iprp["input_file"]) self.clus = read_zip_clusters(self.iprp["input_file"]) if self.surf is not None: self.clus = [ ClusterAtSurface.from_cluster(sc, self.surf) for sc in self.clus ] for sc in self.clus: surface_align(sc) self.nimages = self.iprp["nimages"] self.nisomers = self.iprp.get("nisomers", len(self.clus)) self.clus = self.clus[:self.nisomers] self.max_diff = self.iprp["max_diff"] self.ref_neblocal = self.init_ref(self.iprp.get("path-ref-local", [])) self.ref_nebmax = self.init_ref(self.iprp.get("path-ref-max", [])) if len(self.ref_neblocal) != 0 or len(self.ref_nebmax) != 0: from meta.analysis import read_nebpaths strs = self.ref_neblocal + self.ref_nebmax self.ref_nebpaths, self.ref_nebmin = read_nebpaths( strs, len(self.ref_neblocal)) # for neb path search self.ref_path_dict = {} for np in self.ref_nebpaths.values(): # if np.focus and np.isdirect: if np.focus: ft = "%d.%d" % tuple(np.from_to) self.ref_path_dict[ft] = np else: self.ref_nebpaths, self.ref_nebmin = {}, {}
def init_from_file(self, filename, pre_sort=False): self.clus = read_zip_clusters(filename) self.cn = len(self.clus) # self.an = self.clus[0].n if pre_sort: print('pre-sort structs by energy for filtering.') self.clus = sorted(self.clus, key=lambda x: x.energy) self.flimit = False
def __init__(self, input_file, sample_number=-1, energy_cut=None, shuffle_input=False, last_only=False): if input_file is None: return self.clus = read_zip_clusters(input_file, last_only=last_only) if energy_cut is not None: self.clus = [c for c in self.clus if c.energy < energy_cut] if shuffle_input: random.shuffle(self.clus) if sample_number != -1: self.clus = self.clus[:sample_number] print('%d structures selected. ' % (len(self.clus), ))
def __init__(self, input_file, net_keep): self.net_keep = net_keep # could be zip or normal serial xyz # auto detected self.clus = read_zip_clusters(input_file) self.cn = len(self.clus) self.an = self.clus[0].n self.net_eval = NetEvaluator(self.clus) self.net_eval.load_network(net_keep) self.init_derivatives() self.post_reject = None self.opt_data = [None] * 2 self.opt_data[0] = np.array([c.atoms for c in self.clus]) self.opt_data[1] = np.array([c.energy for c in self.clus])
def __init__(self, input_file, sample_number, sample_ratio, energy_cut=0.0, exp_length=0, min_max_ext_ratio=0.05, scale_lengths=True, second_order=False, energy_unit="hartree", shuffle_input=False, degree=0, param_save=0, diff=False, orig_and_diff=0, pre_nets=[]): self.energy_cut = energy_cut self.sample_number = sample_number self.sample_ratio = sample_ratio self.exp_length = exp_length self.min_max_ext_ratio = min_max_ext_ratio self.scale_lengths = scale_lengths self.second_order = second_order self.energy_factor = Fitting.httoev if energy_unit == "hartree" else 1.0 self.shuffle_input = shuffle_input self.param_save = param_save self.diff = diff self.degree = degree self.orig_and_diff = orig_and_diff self.pre_net_evals = [] self.clus = read_zip_clusters(input_file) if isinstance(energy_cut, float): self.clus = [c for c in self.clus if c.energy < energy_cut] elif isinstance(energy_cut, basestring) and energy_cut.startswith("+"): ec = float(energy_cut[1:]) emin = min([c.energy for c in self.clus]) emax = max([c.energy for c in self.clus]) print('Original Energy: max = %15.6f, min = %15.6f' % (emax, emin)) print('Energy difference: %15.6f, scaled = %15.6f\n' % (emax - emin, self.energy_factor * (emax - emin))) self.clus = [c for c in self.clus if c.energy < emin + ec] emin = min([c.energy for c in self.clus]) emax = max([c.energy for c in self.clus]) emean = np.array([c.energy for c in self.clus]).mean() estd = np.array([c.energy for c in self.clus]).std() print("Structures selected: %d (%s)" % (len(self.clus), energy_cut)) print('Selected Energy: max = %15.6f, min = %15.6f' % (emax, emin)) print('Scaled: mean = %15.6f, std = %15.6f' % (self.energy_factor * emean, self.energy_factor * estd)) print('Energy difference: %15.6f, scaled = %15.6f\n' % (emax - emin, self.energy_factor * (emax - emin))) for c in self.clus: c.new_energy = c.energy if self.shuffle_input: random.shuffle(self.clus) self.cn = self.clus[0].n aclus = np.array([c.atoms for c in self.clus]) plen = get_length(self.cn) al = np.linalg.norm(aclus[:, plen[0]] - aclus[:, plen[1]], axis=2) ae = np.array([c.energy for c in self.clus]) self.emax, self.emin = find_max_min(ae, min_max_ext_ratio) self.lmax, self.lmin = find_max_min(al, min_max_ext_ratio) print('Length: max = %15.6f, min = %15.6f' % (self.lmax, self.lmin)) print('Energy: max = %15.6f, min = %15.6f' % (self.emax, self.emin)) print('Energy difference: %15.6f, scaled = %15.6f' % (self.emax - self.emin, self.energy_factor * (self.emax - self.emin))) if len(pre_nets) != 0: print('Found %d pre-nets ...' % (len(pre_nets))) for net_keep in pre_nets: ne = NetEvaluator(self.clus) ne.load_network(net_keep) ne.predict_all() for ic, c in enumerate(self.clus): c.new_energy -= ne.ener_pre[ic] self.pre_net_evals.append(ne) nae = np.array([c.new_energy for c in self.clus]) self.emax, self.emin = find_max_min(nae, min_max_ext_ratio) print('New energy: max = %15.6f, min = %15.6f' % (self.emax, self.emin)) print('New energy difference: %15.6f, scaled = %15.6f' % (self.emax - self.emin, self.energy_factor * (self.emax - self.emin))) self.net_eval = None
def __init__(self, input_file=None): if input_file is None: self.clus = [] else: self.clus = read_zip_clusters(input_file)