Skip to content

Commit 63e893a

Browse files
authored
Merge pull request #118 from tjduigna/master
Update to orbital viz., tidied up gaussian parsers
2 parents 49c88c4 + dd3ff64 commit 63e893a

10 files changed

Lines changed: 1014 additions & 215 deletions

File tree

docs/source/notebooks/04_orbitals.ipynb

Lines changed: 595 additions & 0 deletions
Large diffs are not rendered by default.

exatomic/algorithms/basis.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,13 +297,12 @@ def evaluate(self, xs=None, ys=None, zs=None, irrep=None, verbose=False):
297297
if self._meta['gaussian']:
298298
if self._meta.get('symmetrized', False):
299299
func = self._evaluate_gau_bso_sym
300-
elif self._meta['program'] in ['nwchem']:
301-
func = self._evaluate_gau_bso
302300
elif self._meta['program'] in ['molcas']:
303301
func = self._evaluate_gau_mag
302+
else:
303+
func = self._evaluate_gau_bso
304304
else:
305305
func = self._evaluate_sto
306-
# if verbose: print('calling {}'.format(func.__name__))
307306
return func(xs=xs, ys=ys, zs=zs, irrep=irrep)
308307

309308

exatomic/base.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import os
99
from exa.util import isotopes
1010
from platform import system
11+
from IPython.display import display_html
1112

1213
# For numba compiled functions
1314
sysname= system().lower()
@@ -69,3 +70,10 @@ def list_resources():
6970
for path, _, files_ in os.walk(staticdir()):
7071
files.extend(files_)
7172
return files
73+
74+
75+
def display_side_by_side(*args):
76+
"""Simple function to display 2 dataframes side by side in a notebook."""
77+
html_str = ''.join([df.to_html() for df in args])
78+
display_html(html_str.replace('table','table style=\"display:inline\"'),
79+
raw=True)

exatomic/core/basis.py

Lines changed: 75 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,59 @@ def primitives(self, spherical):
162162
#self.gaussian = gaussian
163163

164164

165+
def deduplicate_basis_sets(sets, sp=False):
166+
"""Deduplicate identical basis sets on different centers.
167+
168+
Args:
169+
sets (pd.DataFrame): non-unique basis sets
170+
sp (bool): Whether or not to call _expand_sp (gaussian program only)
171+
172+
Returns:
173+
tup (tuple): deduplicated basis sets and basis set map for atom table
174+
"""
175+
unique, setmap, cnt = [], {}, 0
176+
sets = sets.groupby('center')
177+
chk = ['alpha', 'd']
178+
for center, seht in sets:
179+
for i, other in enumerate(unique):
180+
if other.shape != seht.shape: continue
181+
if np.allclose(other[chk], seht[chk]):
182+
setmap[center] = i
183+
break
184+
else:
185+
unique.append(seht)
186+
setmap[center] = cnt
187+
cnt += 1
188+
if sp: unique = _expand_sp(unique)
189+
sets = pd.concat(unique).reset_index(drop=True)
190+
try: sets.drop([2, 3], axis=1, inplace=True)
191+
except (KeyError, ValueError): pass
192+
sets.rename(columns={'center': 'set'}, inplace=True)
193+
sets['set'] = sets['set'].map(setmap)
194+
sets['frame'] = 0
195+
return sets, setmap
196+
197+
def _expand_sp(unique):
198+
"""Currently only used when 'program' == 'gaussian'."""
199+
expand = []
200+
for seht in unique:
201+
if np.isnan(seht[2]).sum() == seht.shape[0]:
202+
expand.append(seht)
203+
continue
204+
sps = seht[2][~np.isnan(seht[2])].index
205+
shls = len(seht.ix[sps]['shell'].unique())
206+
dupl = seht.ix[sps[0]:sps[-1]].copy()
207+
dupl[1] = dupl[2]
208+
dupl['L'] = 1
209+
dupl['shell'] += shls
210+
last = seht.ix[sps[-1] + 1:].copy()
211+
last['shell'] += shls
212+
expand.append(pd.concat([seht.ix[:sps[0] - 1],
213+
seht.ix[sps[0]:sps[-1]],
214+
dupl, last]))
215+
return expand
216+
217+
165218
class BasisSetOrder(DataFrame):
166219
"""
167220
BasisSetOrder uniquely determines the basis function ordering scheme for
@@ -223,22 +276,38 @@ class Overlap(DataFrame):
223276
_columns = ['chi0', 'chi1', 'coef', 'frame']
224277
_index = 'index'
225278

226-
#@property
227-
#def _constructor(self):
228-
# return Overlap
229279

230-
def square(self, frame=0, column='coef', mocoefs=None):
280+
def square(self, frame=0, column='coef', mocoefs=None, irrep=None):
231281
"""Return a 'square' matrix DataFrame of the Overlap.
232282
233283
Args:
234284
column (str): column of coefficients to reshape
235285
mocoefs (str): alias for `column`
236286
frame (int): default 0
287+
irrep (int): irreducible representation if symmetrized
237288
"""
238289
if mocoefs is not None: column = mocoefs
290+
if 'irrep' in self.columns:
291+
if irrep is None:
292+
irreps, i, j = self.groupby('irrep'), 0, 0
293+
norb = (irreps.chi0.max() + 1).sum()
294+
nchi = (irreps.chi1.max() + 1).sum()
295+
cmat = np.zeros((nchi, norb))
296+
for irrep, grp in irreps:
297+
piv = grp.pivot('chi0', 'chi1', column)
298+
ii, jj = piv.shape
299+
cmat[i : i + ii, j : j + jj] = piv.values
300+
i += ii
301+
j += jj
302+
idx = pd.Index(range(nchi), name='chi0')
303+
orb = pd.Index(range(norb), name='chi1')
304+
return pd.DataFrame(cmat, index=idx, columns=orb)
305+
return self.groupby('irrep').get_group(irrep
306+
).pivot('chi', 'orbital', column)
239307
sq = _square(self[column].values)
240-
return pd.DataFrame(sq, index=pd.Index(range(sq.shape[0]), name='chi0'),
241-
columns=pd.Index(range(sq.shape[1]), name='chi1'))
308+
idx = pd.Index(range(sq.shape[0]), name='chi0')
309+
orb = pd.Index(range(sq.shape[1]), name='chi1')
310+
return pd.DataFrame(sq, index=idx, columns=orb)
242311

243312
@classmethod
244313
def from_column(cls, source):

exatomic/core/universe.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ def enumerate_shells(self, frame=0):
204204
frame (int): state of the universe (default 0)
205205
"""
206206
atom = self.atom.groupby('frame').get_group(frame)
207-
if self.meta['program'] not in ['molcas', 'adf', 'nwchem']:
207+
if self.meta['program'] not in ['molcas', 'adf', 'nwchem', 'gaussian']:
208208
print('Warning: Check spherical shell parameter for {} '
209209
'molecular orbital generation'.format(self.meta['program']))
210210
shls = self.basis_set.shells(self.meta['program'],

0 commit comments

Comments
 (0)