From 1ffe56437da9e4f0edf581c8005411a10f0e976c Mon Sep 17 00:00:00 2001 From: Saransh Singh Date: Wed, 26 Jan 2022 12:55:58 -0800 Subject: [PATCH 1/3] fix 1 --- hexrd/unitcell.py | 45 ++++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/hexrd/unitcell.py b/hexrd/unitcell.py index 1b6d3ebfc..6581b8017 100644 --- a/hexrd/unitcell.py +++ b/hexrd/unitcell.py @@ -593,36 +593,39 @@ def remove_duplicate_atoms(self, for i in range(atom_pos.shape[0]): pos = atom_pos[i, 0:3] occ = atom_pos[i, 3] + if i == 0: + atom_pos_fixed.append(np.hstack([pos, occ])) - v1, n1 = self.CalcOrbit(pos) + else: + v1, n1 = self.CalcOrbit(pos) - for j in range(i+1, atom_pos.shape[0]): - isclose = False - atom_pos_fixed.append(np.hstack([pos, occ])) - pos = atom_pos[j, 0:3] - occ = atom_pos[j, 3] - v2, n2 = self.CalcOrbit(pos) + for j in range(i+1, atom_pos.shape[0]): + isclose = False + atom_pos_fixed.append(np.hstack([pos, occ])) + pos = atom_pos[j, 0:3] + occ = atom_pos[j, 3] + v2, n2 = self.CalcOrbit(pos) + + for v in v2: + vv = np.tile(v, [v1.shape[0], 1]) + vv = vv - v1 - for v in v2: - vv = np.tile(v, [v1.shape[0], 1]) - vv = vv - v1 + for vvv in vv: - for vvv in vv: + # check if distance less than tol + # the factor of 10 is for A --> nm + if self.CalcLength(vvv, 'd') < tol/10.: + # if true then its a repeated atom + isclose = True + break - # check if distance less than tol - # the factor of 10 is for A --> nm - if self.CalcLength(vvv, 'd') < tol/10.: - # if true then its a repeated atom - isclose = True + if isclose: break if isclose: break - - if isclose: - break - else: - atom_pos_fixed.append(np.hstack([pos, occ])) + else: + atom_pos_fixed.append(np.hstack([pos, occ])) return np.array(atom_pos_fixed) From be474731f657ce105b119225988a843168376049 Mon Sep 17 00:00:00 2001 From: Saransh Singh Date: Thu, 27 Jan 2022 12:02:33 -0800 Subject: [PATCH 2/3] fix some of the logic in unitcell.remove_duplicate_atoms. Automatically update the unitcell after removing the duplicate sites. --- hexrd/unitcell.py | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/hexrd/unitcell.py b/hexrd/unitcell.py index 6581b8017..406aba54f 100644 --- a/hexrd/unitcell.py +++ b/hexrd/unitcell.py @@ -586,7 +586,7 @@ def remove_duplicate_atoms(self, atom_pos = self.atom_pos atom_pos_fixed = [] - + idx = [] """ go through the atom_pos and remove the atoms that are duplicate """ @@ -595,13 +595,12 @@ def remove_duplicate_atoms(self, occ = atom_pos[i, 3] if i == 0: atom_pos_fixed.append(np.hstack([pos, occ])) - - else: + idx.append(i) v1, n1 = self.CalcOrbit(pos) for j in range(i+1, atom_pos.shape[0]): isclose = False - atom_pos_fixed.append(np.hstack([pos, occ])) + # atom_pos_fixed.append(np.hstack([pos, occ])) pos = atom_pos[j, 0:3] occ = atom_pos[j, 3] v2, n2 = self.CalcOrbit(pos) @@ -626,8 +625,32 @@ def remove_duplicate_atoms(self, break else: atom_pos_fixed.append(np.hstack([pos, occ])) + idx.append(i) + + idx = np.array(idx) + atom_pos_fixed = np.array(atom_pos_fixed) + atom_type = self.atom_type[idx] + chargestates = [self.chargestates[i] for i in idx] + + if self.aniU: + U = self.U[idx,:] + else: + U = self.U[idx] + + self.atom_type = atom_type + self.chargestates = chargestates + self.atom_pos = atom_pos_fixed + + self.U = U + ''' + initialize interpolation from table for anomalous scattering + ''' + self.InitializeInterpTable() + + self.CalcPositions() + self.CalcDensity() + self.calc_absorption_length() - return np.array(atom_pos_fixed) def CalcDensity(self): ''' @@ -1579,6 +1602,7 @@ def atom_pos(self, val): if hasattr(self, 'density'): self.CalcDensity() + self.calc_absorption_length() @property def atom_ntype(self): From 69f84abffd5716fb4be107ef7a0b3cf66162a996 Mon Sep 17 00:00:00 2001 From: Saransh Singh Date: Thu, 27 Jan 2022 12:21:23 -0800 Subject: [PATCH 3/3] make function in materials class to remove duplicate atoms --- hexrd/material.py | 9 +++++++++ hexrd/unitcell.py | 5 ++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/hexrd/material.py b/hexrd/material.py index 44d7f4503..c06da0252 100644 --- a/hexrd/material.py +++ b/hexrd/material.py @@ -399,6 +399,15 @@ def compute_powder_overlay(self, p = [t, fwhm] self.powder_overlay += scale*I*_unit_gaussian(p, ttharray) + def remove_duplicate_atoms(self): + """ + this function calls the same function in the + unitcell class and updates planedata structure + factors etc. + """ + self.unitcell.remove_duplicate_atoms() + self._hkls_changed() + def _readCif(self, fcif=DFLT_NAME+'.cif'): """ >> @AUTHOR: Saransh Singh, Lawrence Livermore National Lab, saransh1@llnl.gov diff --git a/hexrd/unitcell.py b/hexrd/unitcell.py index 406aba54f..e08c168d4 100644 --- a/hexrd/unitcell.py +++ b/hexrd/unitcell.py @@ -646,7 +646,7 @@ def remove_duplicate_atoms(self, initialize interpolation from table for anomalous scattering ''' self.InitializeInterpTable() - + self.CalcAnomalous() self.CalcPositions() self.CalcDensity() self.calc_absorption_length() @@ -716,7 +716,6 @@ def InitializeInterpTable(self): self.f1 = {} self.f2 = {} - self.f_anam = {} self.pe_cs = {} data = importlib.resources.open_binary(hexrd.resources, 'Anomalous.h5') @@ -727,13 +726,13 @@ def InitializeInterpTable(self): elem = constants.ptableinverse[Z] gid = fid.get('/'+elem) data = gid.get('data') - self.f1[elem] = interp1d(data[:, 7], data[:, 1]) self.f2[elem] = interp1d(data[:, 7], data[:, 2]) self.pe_cs[elem] = interp1d(data[:,7], data[:,3]+data[:,4]) def CalcAnomalous(self): + self.f_anam = {} for i in range(self.atom_ntype): Z = self.atom_type[i]