From 205c1311279455dc547544c617a3e22676234e9e Mon Sep 17 00:00:00 2001 From: qzhu2017 Date: Sun, 6 Oct 2024 23:00:31 -0400 Subject: [PATCH] add the discrete option in opt_reps --- pyxtal/__init__.py | 10 +++++++--- pyxtal/database/HM_Full.csv | 2 +- pyxtal/lego/builder.py | 21 +++++++++------------ 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/pyxtal/__init__.py b/pyxtal/__init__.py index bd51dbb9..018b8b2e 100644 --- a/pyxtal/__init__.py +++ b/pyxtal/__init__.py @@ -1638,7 +1638,6 @@ def build(self, group, species, numIons, lattice, sites, tol=1e-2, dim=3, use_ha # msg = 'The input lattice needs to be a pyxtal.lattice.Lattice class' # raise ValueError(msg, lattice) self.lattice = lattice - self.dim = dim self.factor = 1.0 self.PBC = self.group.PBC @@ -1667,12 +1666,14 @@ def build(self, group, species, numIons, lattice, sites, tol=1e-2, dim=3, use_ha elif len(wp) == 4: # tuple: (key, x, y, z) = wp _wp = choose_wyckoff(self.group, site=key, dim=dim) + # print(key, x, y, z, _wp.get_label()) if _wp is not False: if _wp.get_dof() == 0: # fixed pos pt = [0.0, 0.0, 0.0] else: ans = _wp.get_all_positions([x, y, z]) pt = ans[0] if ans is not None else None + # print('debug', ans) if pt is not None: _sites.append(atom_site(_wp, pt, sp)) else: @@ -3853,12 +3854,15 @@ def from_tabular_representation( # ; print(x, y, z, label, xyz[0], xyz[1], xyz[2]) sites.append((label, xyz[0], xyz[1], xyz[2])) numIons += wp.multiplicity + if verbose: + print('add wp', label, xyz) else: if verbose: - print("Cannot find generator from", x, y, z) - print(wp) + print("Cannot get wp in", x, y, z, wp.get_label()) + if len(sites) > 0: try: + # print(sites) self.build(group, ["C"], [numIons], lattice, [sites]) except: print("Invalid Build", number, lattice, numIons, sites) diff --git a/pyxtal/database/HM_Full.csv b/pyxtal/database/HM_Full.csv index a356d357..08032221 100644 --- a/pyxtal/database/HM_Full.csv +++ b/pyxtal/database/HM_Full.csv @@ -50,7 +50,7 @@ Hall,Spg_num,Spg_full,Symbol,P,P^-1,Permutation 49,9,9:-c2,A 1 1 n,"-a-c,a,-b","b,-c,-a-b",1 50,9,9:-c3,I 1 1 a,"c,-a-c,-b","-a-b,-c,a",1 51,9,9:a1,B b 1 1,"b,c,a","c,a,b",1 -52,9,9:a2,C n 1 1,"-b,a,c","b,-a,c",1 +52,9,9:a2,C n 1 1,"b,a,-a-c","b,a,-b-c",1 53,9,9:a3,I c 1 1,"b,-a-c,c","-b-c,a,c",1 54,9,9:-a1,C c 1 1,"-b,a,c","b,-a,c",1 55,9,9:-a2,B n 1 1,"-b,-a-c,a","c,-a,-b-c",1 diff --git a/pyxtal/lego/builder.py b/pyxtal/lego/builder.py index c28af612..704f3a37 100644 --- a/pyxtal/lego/builder.py +++ b/pyxtal/lego/builder.py @@ -208,7 +208,7 @@ def minimize_from_x(x, dim, spg, wps, elements, calculator, ref_environments, except: return None - x0 = x.copy() + x0 = np.array(x.copy()) # Extract variables, call from Pyxtal [N_abc, N_ang] = Lattice.get_dofs(xtal.lattice.ltype) rep = xtal.get_1D_representation() @@ -799,7 +799,7 @@ def optimize_reps(self, reps, ncpu=1, opt_type='local', T=0.2, niter=20, early_quit=0.02, add_db=True, symmetrize=False, minimizers=[('Nelder-Mead', 100), ('L-BFGS-B', 100)], - ): + discrete=False): """ Perform optimization for each structure @@ -809,12 +809,12 @@ def optimize_reps(self, reps, ncpu=1, opt_type='local', """ args = (opt_type, T, niter, early_quit, add_db, symmetrize, minimizers) if ncpu > 1: - valid_xtals = self.optimize_reps_mproc(reps, ncpu, args) + valid_xtals = self.optimize_reps_mproc(reps, ncpu, args, discrete) return valid_xtals else: raise NotImplementedError("optimize_reps works in parallel mode") - def optimize_reps_mproc(self, reps, ncpu, args): + def optimize_reps_mproc(self, reps, ncpu, args, discrete): """ Optimization in multiprocess mode. @@ -847,7 +847,9 @@ def generate_args(): for id in _ids: rep = reps[id] xtal = pyxtal() - xtal.from_tabular_representation(rep, normalize=False) + xtal.from_tabular_representation(rep, + normalize=False, + discrete=discrete) x = xtal.get_1d_rep_x() spg, wps, _ = self.get_input_from_ref_xtal(xtal) wp_libs.append((x, spg, wps)) @@ -1295,13 +1297,8 @@ def process_xtal(self, xtal, sim, count=0, xs=None, energy=None, 'similarity': sim[1], } if xs is not None: - try: - kvp['x_init'] = np.array2string(xs[0]) - kvp['x_opt'] = np.array2string(xs[1]) - except: - print("Error in xs", xs) - kvp['x_init'] = 'N/A' - kvp['x_opt'] = 'N/A' + kvp['x_init'] = np.array2string(xs[0]) + kvp['x_opt'] = np.array2string(xs[1]) if energy is not None: kvp['ff_energy'] = energy if topology is not None: