Skip to content

Commit

Permalink
add the discrete option in opt_reps
Browse files Browse the repository at this point in the history
  • Loading branch information
qzhu2017 committed Oct 7, 2024
1 parent d81e574 commit 205c131
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
10 changes: 7 additions & 3 deletions pyxtal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pyxtal/database/HM_Full.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 9 additions & 12 deletions pyxtal/lego/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 205c131

Please sign in to comment.