Skip to content

Commit c169aa2

Browse files
committed
Merge branch 'tensile-test' of github.com:chrisjonesBSU/cmeutils into tensile-test
2 parents 5a92937 + 750dbba commit c169aa2

8 files changed

+70
-14
lines changed

.pre-commit-config.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ ci:
1111

1212
repos:
1313
- repo: https://github.com/pre-commit/pre-commit-hooks
14-
rev: v4.5.0
14+
rev: v4.6.0
1515
hooks:
1616
- id: check-yaml
1717
- id: end-of-file-fixer
1818
- id: trailing-whitespace
1919
exclude: 'cmeuitls/tests/assets/.*'
2020
- repo: https://github.com/psf/black
21-
rev: 24.2.0
21+
rev: 24.4.2
2222
hooks:
2323
- id: black
2424
args: [--line-length=80]
@@ -32,7 +32,7 @@ repos:
3232
exclude: 'cmeuitls/tests/assets/.* '
3333

3434
- repo: https://github.com/pycqa/flake8
35-
rev: 7.0.0
35+
rev: 7.1.0
3636
hooks:
3737
- id: flake8
3838
args:

cmeutils/__version__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "1.1.1"
1+
__version__ = "1.3.0"

cmeutils/gsd_utils.py

+13-3
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,21 @@ def get_molecule_cluster(gsd_file=None, snap=None, gsd_frame=-1):
137137
n_query_points = n_points = snap.particles.N
138138
query_point_indices = snap.bonds.group[:, 0]
139139
point_indices = snap.bonds.group[:, 1]
140-
distances = system.box.compute_distances(
141-
system.points[query_point_indices], system.points[point_indices]
140+
box = freud.box.Box(
141+
snap.configuration.box[0],
142+
snap.configuration.box[1],
143+
snap.configuration.box[2],
144+
)
145+
vectors = box.wrap(
146+
snap.particles.position[query_point_indices]
147+
- snap.particles.position[point_indices]
142148
)
143149
nlist = freud.NeighborList.from_arrays(
144-
n_query_points, n_points, query_point_indices, point_indices, distances
150+
num_query_points=n_query_points,
151+
num_points=n_points,
152+
query_point_indices=query_point_indices,
153+
point_indices=point_indices,
154+
vectors=vectors,
145155
)
146156
cluster = freud.cluster.Cluster()
147157
cluster.compute(system=system, neighbors=nlist)

cmeutils/sampling.py

+20
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,23 @@ def is_equilibrated(data, threshold_fraction=0.50, threshold_neff=50, nskip=1):
103103
return [True, t0, g, Neff]
104104
else:
105105
return [False, None, None, None]
106+
107+
108+
def autocorr1D(array):
109+
"""Takes in a linear np array, performs autocorrelation
110+
function and returns normalized array with half the length
111+
of the input.
112+
113+
Parameters
114+
----------
115+
data : numpy.typing.Arraylike, required
116+
1-D series of data to perform autocorrelation on.
117+
118+
Returns
119+
-------
120+
1D np.array
121+
122+
"""
123+
ft = np.fft.rfft(array - np.average(array))
124+
acorr = np.fft.irfft(ft * np.conjugate(ft)) / (len(array) * np.var(array))
125+
return acorr[0 : len(acorr) // 2] # noqa: E203

cmeutils/tests/test_gsd.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def test_ellipsoid_gsd(self, butane_gsd):
5050
def test_create_rigid_snapshot(self):
5151
benzene = mb.load("c1ccccc1", smiles=True)
5252
benzene.name = "Benzene"
53-
box = mb.fill_box(benzene, 5, box=[1, 1, 1])
53+
box = mb.fill_box(benzene, 5, box=[3, 3, 3], seed=42)
5454
box.label_rigid_bodies(discrete_bodies="Benzene")
5555

5656
rigid_init_snap = create_rigid_snapshot(box)
@@ -60,7 +60,7 @@ def test_create_rigid_snapshot(self):
6060
def test_update_rigid_snapshot(self):
6161
benzene = mb.load("c1ccccc1", smiles=True)
6262
benzene.name = "Benzene"
63-
box = mb.fill_box(benzene, 5, box=[1, 1, 1])
63+
box = mb.fill_box(benzene, 5, box=[3, 3, 3], seed=42)
6464
box.label_rigid_bodies(discrete_bodies="Benzene")
6565

6666
rigid_init_snap = create_rigid_snapshot(box)

cmeutils/tests/test_sampling.py

+27-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import numpy as np
22
import pytest
3+
import scipy
34

4-
from cmeutils.sampling import equil_sample, is_equilibrated
5+
from cmeutils.sampling import autocorr1D, equil_sample, is_equilibrated
56
from cmeutils.tests.base_test import BaseTest
67

78

@@ -82,3 +83,28 @@ def test_trim_high_threshold(self, correlated_data_tau100_n10000):
8283
[equil_data, uncorr_indices, prod_start, Neff] = equil_sample(
8384
data, threshold_fraction=0.75, threshold_neff=10000
8485
)
86+
87+
def test_autocorr1D(self):
88+
randoms = np.random.randint(100, size=(100))
89+
integers = np.array(np.arange(100))
90+
91+
autocorrelation_randoms = autocorr1D(randoms)
92+
autocorrelation_integers = autocorr1D(integers)
93+
94+
def expfunc(x, a):
95+
return np.exp(-x / a)
96+
97+
x_values = np.array(range(len(autocorrelation_integers)))
98+
99+
exp_coeff_randoms = scipy.optimize.curve_fit(
100+
expfunc, x_values, autocorrelation_randoms
101+
)[0][0]
102+
exp_coeff_int = scipy.optimize.curve_fit(
103+
expfunc, x_values, autocorrelation_integers
104+
)[0][0]
105+
106+
assert (
107+
round(autocorrelation_integers[0], 10)
108+
and round(autocorrelation_randoms[0], 10) == 1
109+
)
110+
assert exp_coeff_int > 5 and exp_coeff_randoms < 1

environment-dev.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ name: cmeutils-dev
22
channels:
33
- conda-forge
44
dependencies:
5-
- freud =2.13.2
5+
- freud >= 3.0
66
- gmso >=0.11.2
77
- fresnel >=0.13.5
88
- gsd >=3.0
99
- hoomd >=4.0
1010
- mbuild >=0.16.4
1111
- numpy
1212
- pip
13-
- python >= 3.10
13+
- python >= 3.10,<3.12
1414
- matplotlib
1515
- pre-commit
1616
- pymbar >= 4.0

environment.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ name: cmeutils
22
channels:
33
- conda-forge
44
dependencies:
5-
- freud =2.13.2
5+
- freud >= 3.0
66
- gmso >=0.11.2
77
- fresnel >=0.13.5
88
- gsd >=3.0
99
- hoomd >=4.0
1010
- mbuild >=0.16.4
1111
- numpy
1212
- pip
13-
- python >= 3.10
13+
- python >= 3.10,<3.12
1414
- matplotlib
1515
- pymbar >= 4.0
1616
- rowan

0 commit comments

Comments
 (0)