Skip to content

Commit 20ebf83

Browse files
authored
Merge pull request #81 from avmarchenko/master
Minor editor bugfixes and updates to neighbor search syntax and XYZ syntax
2 parents 843656e + eae61fc commit 20ebf83

9 files changed

Lines changed: 243 additions & 31 deletions

File tree

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ var/*
2525
.installed.cfg
2626
*.egg
2727
*.pypirc
28+
win-32
29+
win-64
30+
linux-32
31+
linux-64
32+
osx-64
2833

2934
# PyInstaller
3035
# Usually these files are written by a python script from a template

README.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,21 @@ or `pypi`_.
1616
1717
pip install exatomic
1818
19+
After installation, run the following to set up visualization.
20+
21+
.. code-block:: bash
22+
23+
exa -u
24+
25+
If using conda, make sure to be on up-to-date versions of `ipywidgets` and
26+
`notebook`:
27+
28+
.. code-block:: bash
29+
30+
conda install -c conda-forge notebook ipywidgets
31+
32+
Visualization currently support Chrome and Firefox.
33+
1934
###################
2035
Getting Started
2136
###################

exatomic/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
1919
.. _atomic: https://en.wikipedia.org/wiki/Atomic_units
2020
"""
21-
__exatomic_version__ = (0, 3, 2)
21+
__exatomic_version__ = (0, 3, 3)
2222
__version__ = '.'.join((str(v) for v in __exatomic_version__))
2323

2424

exatomic/algorithms/neighbors.py

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,12 @@ def nearest_molecules(universe, n, sources, restrictions=None, how='atom',
4848
unis (dict): Dictionary of number of neighbors keys, universe values
4949
"""
5050
source_atoms, other_atoms, source_molecules, other_molecules, n = _slice_atoms_molecules(universe, sources, restrictions, n)
51+
print(source_atoms.shape)
52+
print(other_atoms.shape)
53+
print(source_molecules.shape)
54+
print(other_molecules.shape)
5155
ordered_molecules, ordered_twos = _compute_neighbors_by_atom(universe, source_atoms, other_atoms, source_molecules)
56+
print(ordered_molecules.shape)
5257
unis = {}
5358
if free_boundary == True:
5459
for nn in n:
@@ -65,33 +70,50 @@ def _slice_atoms_molecules(universe, sources, restrictions, n):
6570
Initial check of the unvierse data and argument types and creation of atom
6671
and molecule table slices.
6772
"""
68-
if 'classification' not in universe.molecule.columns and any(len(source) > 3 for source in sources):
69-
raise KeyErrror("Column 'classification' not in the molecule table, please classify molecules or select by symbols only.")
7073
if not isinstance(sources, list):
7174
sources = [sources]
7275
if not isinstance(restrictions, list) and restrictions is not None:
7376
restrictions = [restrictions]
7477
if isinstance(n, (int, np.int32, np.int64)):
7578
n = [n]
79+
labels = universe.atom.get_atom_labels()
80+
universe.atom['label'] = labels
81+
labels = labels.unique()
7682
symbols = universe.atom['symbol'].unique()
7783
classification = universe.molecule['classification'].unique()
78-
if all(source in symbols for source in sources):
84+
if all(source in labels for source in sources):
85+
print("all labels")
86+
source_atoms = universe.atom[universe.atom['label'].isin(sources)]
87+
mdx = source_atoms['molecule'].astype(np.int64)
88+
source_molecules = universe.molecule[universe.molecule.index.isin(mdx)]
89+
elif all(source in symbols for source in sources):
90+
print("all symbols")
7991
source_atoms = universe.atom[universe.atom['symbol'].isin(sources)]
8092
mdx = source_atoms['molecule'].astype(np.int64)
8193
source_molecules = universe.molecule[universe.molecule.index.isin(mdx)]
8294
elif all(source in classification for source in sources):
95+
print("all mols")
8396
source_molecules = universe.molecule[universe.molecule['classification'].isin(sources)]
8497
source_atoms = universe.atom[universe.atom['molecule'].isin(source_molecules.index)]
8598
else:
99+
print("all other")
86100
classif = [source for source in sources if source in classification]
87101
syms = [source for source in sources if source in symbols]
102+
lbls = [source for source in sources if source in labels]
88103
source_molecules = universe.molecule[universe.molecule['classification'].isin(classif)]
89104
source_atoms = universe.atom[universe.atom['molecule'].isin(source_molecules.index)]
90-
source_atoms = source_atoms[source_atoms['symbol'].isin(syms)]
105+
if len(syms) > 0:
106+
source_atoms = source_atoms[source_atoms['symbol'].isin(syms)]
107+
if len(lbls) > 0:
108+
source_atoms = source_atoms[source_atoms['label'].isin(lbls)]
91109
other_molecules = universe.molecule[~universe.molecule.index.isin(source_molecules.index)]
92110
other_atoms = universe.atom[~universe.atom.index.isin(source_atoms.index)]
93111
if restrictions is not None:
94-
if all(other in symbols for other in restrictions):
112+
if all(other in labels for other in restrictions):
113+
other_atoms = other_atoms[other_atoms['label'].isin(restrictions)]
114+
mdx = other_atoms['molecule'].astype(np.int64)
115+
other_molecules = other_molecules[other_molecules.index.isin(mdx)]
116+
elif all(other in symbols for other in restrictions):
95117
other_atoms = other_atoms[other_atoms['symbol'].isin(restrictions)]
96118
mdx = other_atoms['molecule'].astype(np.int64)
97119
other_molecules = other_molecules[other_molecules.index.isin(mdx)]
@@ -101,9 +123,14 @@ def _slice_atoms_molecules(universe, sources, restrictions, n):
101123
else:
102124
classif = [other for other in restrictions if other in classification]
103125
syms = [other for other in restrictions if other in symbols]
126+
lbls = [other for other in restrictions if other in labels]
104127
other_molecules = other_molecules[other_molecules['classification'].isin(classif)]
105128
other_atoms = other_atoms[other_atoms['molecule'].isin(other_molecules.index)]
106-
other_atoms = other_atoms[other_atoms['symbol'].isin(syms)]
129+
if len(syms) > 0:
130+
other_atoms = other_atoms[other_atoms['symbol'].isin(syms)]
131+
if len(lbls) > 0:
132+
other_atoms = other_atoms[other_atoms['label'].isin(lbls)]
133+
del universe.atom['label']
107134
return source_atoms, other_atoms, source_molecules, other_molecules, n
108135

109136

exatomic/algorithms/orbital.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,8 @@ def update_molecular_orbitals(universe, *field_params, mocoefs=None, vector=None
407407
universe (exatomic.container.Universe): universe with basis_functions attribute
408408
field_params (pd.Series or rmin, rmax, nr): dimensions of new numerical grid
409409
"""
410-
del universe.__dict__['_field']
410+
if hasattr(universe, '_field'):
411+
del universe.__dict__['_field']
411412
if isinstance(field_params[0], pd.Series):
412413
field_params = field_params[0]
413414
else:

exatomic/algorithms/pcf.py

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
# -*- coding: utf-8 -*-
2-
'''
2+
# Copyright (c) 2015-2016, Exa Analytics Development Team
3+
# Distributed under the terms of the Apache License 2.0
4+
"""
35
Pair Correlation Functions
46
############################
5-
'''
7+
"""
68
import numpy as np
79
import pandas as pd
810
from exatomic import Length
911

1012

1113
def radial_pair_correlation(universe, a, b, dr=0.05, start=1.0, stop=13.0,
12-
length='A', window=1):
13-
'''
14+
length="A", window=1):
15+
"""
1416
Compute the angularly independent pair correlation function.
1517
1618
This function is sometimes called the pair radial distribution function. The
@@ -24,8 +26,8 @@ def radial_pair_correlation(universe, a, b, dr=0.05, start=1.0, stop=13.0,
2426
2527
.. code-block:: Python
2628
27-
pcf = radial_pair_correlation(universe, 'O', 'O')
28-
pcf.plot(secondary_y='Pair Count')
29+
pcf = radial_pair_correlation(universe, "O", "O")
30+
pcf.plot(secondary_y="Pair Count")
2931
3032
.. math::
3133
@@ -57,30 +59,30 @@ def radial_pair_correlation(universe, a, b, dr=0.05, start=1.0, stop=13.0,
5759
the volume sampled during computation of two body properties divided by
5860
the number of properties used in the histogram (the triple summation
5961
above, divided by the normalization for the radial distance outward).
60-
'''
62+
"""
6163
bins = np.arange(start, stop, dr) # Discrete values of r for histogram
62-
symbol = universe.atom['symbol'].astype(str) # To select distances, map to symbols
63-
symbol0 = universe.atom_two['atom0'].map(symbol)
64-
symbol1 = universe.atom_two['atom1'].map(symbol)
64+
symbol = universe.atom["symbol"].astype(str) # To select distances, map to symbols
65+
symbol0 = universe.atom_two["atom0"].map(symbol)
66+
symbol1 = universe.atom_two["atom1"].map(symbol)
6567
symbols = symbol0 + symbol1
6668
indexes = symbols[symbols.isin([a + b, b + a])].index # Distances of interest or those that
67-
distances = universe.atom_two.ix[indexes, 'distance'] # match symbol pairs
69+
distances = universe.atom_two.ix[indexes, "distance"] # match symbol pairs
6870
hist, bins = np.histogram(distances, bins) # Compute histogram
6971
nn = hist.sum() # Number of observations
7072
bmax = bins.max() # Note that bins is unchanged by np.hist..
71-
rx, ry, rz = universe.frame[['rx', 'ry', 'rz']].mean().values
73+
rx, ry, rz = universe.frame[["rx", "ry", "rz"]].mean().values
7274
ratio = (((bmax/rx + bmax/ry + bmax/rz)/3)**3).mean() # Variable actual vol and bin vol
7375
v_shell = bins[1:]**3 - bins[:-1]**3 # Volume of each bin shell
74-
v_cell = universe.frame['cell_volume'].mean() # Actual volume
76+
v_cell = universe.frame["cell_volume"].mean() # Actual volume
7577
g = hist*v_cell*ratio/(v_shell*nn) # Compute pair correlation
76-
na = universe.atom[universe.atom['symbol'] == a].groupby('frame').size().mean()
77-
nb = universe.atom[universe.atom['symbol'] == b].groupby('frame').size().mean()
78+
na = universe.atom[universe.atom["symbol"] == a].groupby("frame").size().mean()
79+
nb = universe.atom[universe.atom["symbol"] == b].groupby("frame").size().mean()
7880
if a == b:
7981
nb -= 1
8082
n = hist.cumsum()/nn*na*nb # Compute pair count
81-
r = (bins[1:] + bins[:-1])/2*Length['au', length]
82-
unit = 'au'
83-
if length in ['A', 'angstrom', 'ang']:
83+
r = (bins[1:] + bins[:-1])/2*Length["au", length]
84+
unit = "au"
85+
if length in ["A", "angstrom", "ang"]:
8486
unit = r"\AA"
8587
rlabel = r"$r\ \mathrm{(" + unit + ")}$"
8688
glabel = r"$g_\mathrm{" + a + b + r"}(r)$"

exatomic/filetypes/xyz.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def write(self, path, trajectory=True, float_format='% .8f'):
7575
with open(path, 'w') as f:
7676
f.write(str(self))
7777
else:
78-
grps = self.atom.grouped()
78+
grps = self.atom.cardinal_groupby()
7979
n = len(str(self.frame.index.max()))
8080
for frame, atom in grps:
8181
filename = str(frame).zfill(n) + '.xyz'
@@ -90,16 +90,25 @@ def write(self, path, trajectory=True, float_format='% .8f'):
9090
quoting=csv.QUOTE_NONE, escapechar=' ')
9191

9292
@classmethod
93-
def from_universe(cls, universe, float_format='% .8f'):
93+
def from_universe(cls, universe, atom_table='atom', float_format='% .8f'):
9494
"""
9595
Create an xyz file editor from a given universe. If the universe has
9696
more than one frame, creates an xyz trajectory format editor.
97+
98+
Args:
99+
universe: The universe
100+
atom_table (str): One of 'atom', 'unit', or 'visual' corresponding to coordinates
101+
float_format (str): Floating point format (for writing)
97102
"""
98103
string = ''
99-
grps = universe.atom.grouped()
104+
grps = universe.atom.cardinal_groupby()
100105
for frame, atom in grps:
101106
string += cls._header.format(nat=len(atom), comment='frame: ' + str(frame))
102107
atom_copy = atom[cls._cols].copy()
108+
if atom_table == 'unit':
109+
atom_copy.update(universe.unit_atom)
110+
elif atom_table == 'visual':
111+
atom_copy.update(universe.visual_atom)
103112
atom_copy['x'] *= Length['au', 'A']
104113
atom_copy['y'] *= Length['au', 'A']
105114
atom_copy['z'] *= Length['au', 'A']

meta.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package:
22
name: exatomic
3-
version: "0.3.2"
3+
version: "0.3.3"
44

55
source:
6-
git_rev: v0.3.2
6+
git_rev: v0.3.3
77
git_url: https://github.com/exa-analytics/exatomic.git
88

99
requirements:
@@ -23,6 +23,7 @@ requirements:
2323
- ipyparallel
2424
- sphinx
2525
- nose
26+
- numba
2627
- exa
2728

2829
run:
@@ -41,6 +42,7 @@ requirements:
4142
- ipyparallel
4243
- sphinx
4344
- nose
45+
- numba
4446
- exa
4547

4648
about:

0 commit comments

Comments
 (0)