Skip to content

Commit be83dfa

Browse files
authored
Merge pull request #11 from RuhiRG/aseBindings
ENH: Add bindings to `ase` [Topo1D]
2 parents 2517217 + 846d4e0 commit be83dfa

29 files changed

+11651
-694
lines changed

.github/workflows/build_test.yml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,33 @@ on:
88
- main
99
jobs:
1010
build_test:
11-
runs-on: ubuntu-latest
11+
runs-on: ${{ matrix.os }}
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
# TODO(ruhila): Fix windows-2022, see gh-14
16+
os: [ubuntu-24.04, macos-13, macos-14]
1217
steps:
1318
- uses: actions/checkout@v3
1419

1520
- uses: mamba-org/setup-micromamba@v1
1621
with:
1722
environment-file: environment.yml
1823

19-
- name: Build pyseams
24+
- name: Build pyseams (dev)
2025
shell: bash -l {0}
2126
run: |
2227
micromamba activate pyseamsdev
2328
meson setup bbdir
2429
meson compile -C bbdir
2530
26-
- name: Run a test
31+
- name: Run an import test (dev)
2732
shell: bash -l {0}
2833
run: |
2934
python -c 'import bbdir.cyoda'
35+
36+
- name: Run standard tests
37+
shell: bash -l {0}
38+
run: |
39+
pip install -v .[testing,adapters]
40+
python -m pytest -vvv --approvaltests-add-reporter='PythonNativeReporter'

.github/workflows/ci_precommit.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: pre-commit
2+
on:
3+
pull_request:
4+
push:
5+
branches: [main]
6+
jobs:
7+
pre-commit:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v4
11+
- name: Install Conda environment
12+
uses: mamba-org/setup-micromamba@v1
13+
with:
14+
environment-file: conda-lock.yml
15+
environment-name: pyseamsdev
16+
- name: Run precommit
17+
shell: bash -l {0}
18+
run: |
19+
pre-commit run -a

.pre-commit-config.yaml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Kanged from https://github.com/TheochemUI/eOn
2+
fail_fast: false
3+
exclude: |
4+
(?x)(
5+
approved_files| # autogenerated
6+
subprojects # vendored
7+
)
8+
repos:
9+
- repo: https://github.com/pre-commit/pre-commit-hooks
10+
rev: v4.0.1
11+
hooks:
12+
- id: trailing-whitespace
13+
exclude: |
14+
(?x)^(
15+
docs/.* # Exclude docs folder
16+
)$
17+
- id: end-of-file-fixer
18+
exclude: |
19+
(?x)^(
20+
docs/.* # Exclude docs folder
21+
)$
22+
- id: check-yaml
23+
- id: check-added-large-files
24+
- repo: local
25+
hooks:
26+
- id: cppcheck
27+
name: cppcheck
28+
entry: cppcheck
29+
language: system
30+
types_or: [c++, c]
31+
args: [
32+
"--error-exitcode=1",
33+
"--std=c++20",
34+
"--language=c++",
35+
"--check-level=exhaustive",
36+
]
37+
- id: cpplint
38+
name: cpplint
39+
entry: cpplint
40+
language: system
41+
types_or: [c++, c]
42+
args: [
43+
"--filter=-whitespace/comments,
44+
-runtime/references,
45+
-whitespace/indent,
46+
-whitespace/parens,
47+
-whitespace/braces,
48+
-whitespace/line_length,
49+
-whitespace/newline,
50+
-build/include_order,
51+
-readability/todo,
52+
-readability/fn_size,
53+
-build/namespaces,"
54+
]
55+
- id: clang-format
56+
name: clang-format
57+
entry: clang-format
58+
language: system
59+
types_or: [c, c++, cuda]
60+
args: ["-fallback-style=none", "-style=file", "-i"]
61+
- id: meson-format
62+
name: meson format
63+
entry: meson
64+
language: system
65+
types: [meson]
66+
files: \.build$
67+
args: ["format", "-i"]
68+
- id: ruff-lint-fixes
69+
name: ruff check
70+
entry: ruff
71+
language: system
72+
types_or: [ python, pyi, jupyter ]
73+
args: ["check", "--fix", "--unsafe-fixes", "."]
74+
- id: ruff-format
75+
name: ruff format
76+
entry: ruff
77+
language: system
78+
types_or: [ python, pyi, jupyter ]
79+
args: ["format", "."]

BPring.py

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,51 @@
11
import bbdir.cyoda as cyoda
2-
trajectory ="subprojects/seams-core/input/traj/clathrate-thf.lammpstrj"
32

4-
#Get the frame
3+
trajectory = "subprojects/seams-core/input/traj/clathrate-thf.lammpstrj"
4+
5+
# Get the frame
56
resCloud = cyoda.readLammpsTrjreduced(
6-
filename = trajectory,
7-
targetFrame = 1,
8-
typeI = 1, #oxygenAtomType
9-
isSlice = True,
10-
coordLow = [0,0,0],
11-
coordHigh = [34.728,0,0],
7+
filename=trajectory,
8+
targetFrame=1,
9+
typeI=1, # oxygenAtomType
10+
isSlice=True,
11+
coordLow=[0, 0, 0],
12+
coordHigh=[34.728, 0, 0],
1213
)
1314

14-
#Calculate the neighborlist by ID
15+
# Calculate the neighborlist by ID
1516
nList = cyoda.neighListO(
16-
rcutoff = 3.5,
17-
yCloud = resCloud,
18-
typeI = 1, #oxygenAtomType
17+
rcutoff=3.5,
18+
yCloud=resCloud,
19+
typeI=1, # oxygenAtomType
1920
)
2021

21-
#Get the hydrogen-bonded network for the current frame
22+
# Get the hydrogen-bonded network for the current frame
2223
hbnList = cyoda.populateHbonds(
23-
filename = trajectory,
24-
yCloud = resCloud,
25-
nList = nList,
26-
targetFrame = 1,
27-
Htype = 2, #hydrogen atom type
24+
filename=trajectory,
25+
yCloud=resCloud,
26+
nList=nList,
27+
targetFrame=1,
28+
Htype=2, # hydrogen atom type
2829
)
2930

30-
#Hydrogen-bonded network using indices not IDs
31-
hbnList = cyoda.neighbourListByIndex(
32-
yCloud = resCloud,
33-
nList = hbnList,
31+
# Hydrogen-bonded network using indices not IDs
32+
hbnList = cyoda.neighbourListByIndex(
33+
yCloud=resCloud,
34+
nList=hbnList,
3435
)
3536

36-
#Gets every ring (non-primitives included)
37+
# Gets every ring (non-primitives included)
3738
rings = cyoda.ringNetwork(
38-
nList = hbnList,
39-
maxDepth = 6,
39+
nList=hbnList,
40+
maxDepth=6,
4041
)
4142

42-
#Writes out primitive rings for a bulk system
43+
# Writes out primitive rings for a bulk system
4344
ring = cyoda.bulkPolygonRingAnalysis(
44-
path = "runOne/", #outDir
45-
rings = rings,
46-
nList = hbnList,
47-
yCloud = resCloud,
48-
maxDepth = 6,
49-
firstFrame = 1,
50-
)
45+
path="runOne/", # outDir
46+
rings=rings,
47+
nList=hbnList,
48+
yCloud=resCloud,
49+
maxDepth=6,
50+
firstFrame=1,
51+
)

ase_topo1d.py

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
from pyseams import cyoda
2+
from pyseams.adapters import _ase
3+
import numpy as np
4+
5+
from ase.io import read as aseread
6+
7+
trajectory = "subprojects/seams-core/input/traj/exampleTraj.lammpstrj"
8+
9+
10+
# Get the frame
11+
resCloud = cyoda.readLammpsTrjreduced(
12+
filename=trajectory,
13+
targetFrame=1,
14+
typeI=2, # oxygenAtomType
15+
isSlice=False,
16+
coordLow=[0, 0, 0],
17+
coordHigh=[0, 0, 0],
18+
)
19+
# pprint.pprint(dir(resCloud))
20+
21+
atms = aseread(trajectory)
22+
# In ASE, we want to work with atomic symbols instead of LAMMPS types
23+
lammps_to_ase = {1: "H", 2: "O"}
24+
atms = _ase.map_LAMMPS_IDs_to_atomic_symbols(lammps_to_ase, atms)
25+
openfile = "subprojects/seams-core/input/traj/exampleTraj.lammpstrj"
26+
only_O_mask = [x.symbol == "O" for x in atms]
27+
# user has to provide proper molID for inslice, each molecule must have one molID. for eg: In H2O, both H atoms and O atom must have same molID.
28+
# if one wants molHID, they can just change the last ,1) as ,2) in the following expression:
29+
molOID = np.repeat(np.arange(1, sum(only_O_mask) + 1), 1)
30+
pcd = _ase.to_pointcloud(
31+
atms, lammps_to_ase, only_O_mask, molOID, openfile, currentFrame=[1]
32+
)
33+
34+
# Calculate the neighborlist by ID
35+
nList = cyoda.neighListO(
36+
rcutoff=3.5,
37+
yCloud=resCloud,
38+
typeI=2, # oxygenAtomType
39+
)
40+
nl = cyoda.neighListO(
41+
rcutoff=3.5,
42+
yCloud=pcd,
43+
typeI=2, # oxygenAtomType
44+
)
45+
46+
# Get the hydrogen-bonded network for the current frame
47+
hbnList = cyoda.populateHbonds(
48+
filename=trajectory,
49+
yCloud=resCloud,
50+
nList=nList,
51+
targetFrame=1,
52+
Htype=1, # hydrogen atom type
53+
)
54+
hl = cyoda.populateHbonds(
55+
filename=trajectory,
56+
yCloud=pcd,
57+
nList=nl,
58+
targetFrame=1,
59+
Htype=1, # hydrogen atom type
60+
)
61+
# Hydrogen-bonded network using indices not IDs
62+
hbnList = cyoda.neighbourListByIndex(
63+
yCloud=resCloud,
64+
nList=hbnList,
65+
)
66+
hL = cyoda.neighbourListByIndex(
67+
yCloud=pcd,
68+
nList=hl,
69+
)
70+
# Gets every ring (non-primitives included)
71+
rings = cyoda.ringNetwork(
72+
nList=hbnList,
73+
maxDepth=6,
74+
)
75+
Rgs = cyoda.ringNetwork(
76+
nList=hL,
77+
maxDepth=6,
78+
)
79+
# Does the prism analysis for quasi-one-dimensional ice
80+
cyoda.prismAnalysis(
81+
path="runOne/", # outDir
82+
rings=Rgs,
83+
nList=hL,
84+
yCloud=resCloud,
85+
maxDepth=6,
86+
atomID=0,
87+
firstFrame=1, # targetFrame
88+
currentFrame=1, # frame
89+
doShapeMatching=False,
90+
)
91+
92+
# print(pprint.pformat(nList))

bulktopoC.py

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,49 @@
11
import bbdir.cyoda as cyoda
2-
trajectory ="subprojects/seams-core/input/traj/cluster-417.lammpstrj"
32

4-
#Get the frame
3+
trajectory = "subprojects/seams-core/input/traj/cluster-417.lammpstrj"
4+
5+
# Get the frame
56
resCloud = cyoda.readLammpsTrjreduced(
6-
filename = trajectory,
7-
targetFrame = 1302,
8-
typeI = 1, #oxygenAtomType
9-
isSlice = False,
10-
coordLow = [0,0,0],
11-
coordHigh = [0,0,0],
7+
filename=trajectory,
8+
targetFrame=1302,
9+
typeI=1, # oxygenAtomType
10+
isSlice=False,
11+
coordLow=[0, 0, 0],
12+
coordHigh=[0, 0, 0],
1213
)
1314

14-
#Calculate the neighborlist by ID
15+
# Calculate the neighborlist by ID
1516
nList = cyoda.neighListO(
16-
rcutoff = 3.5,
17-
yCloud = resCloud,
18-
typeI = 1, #oxygenAtomType
17+
rcutoff=3.5,
18+
yCloud=resCloud,
19+
typeI=1, # oxygenAtomType
1920
)
2021
solCloud = cyoda.PointCloudDouble()
2122
iceList = []
2223
clump = cyoda.clusterAnalysis(
23-
path = "runOne/", #outDir
24-
iceCloud = solCloud,
25-
yCloud = resCloud,
26-
nList = nList,
27-
iceNeighbourList = iceList,
28-
cutoff = 3.5,
29-
firstFrame = 1302,
30-
bopAnalysis = "q6",
24+
path="runOne/", # outDir
25+
iceCloud=solCloud,
26+
yCloud=resCloud,
27+
nList=nList,
28+
iceNeighbourList=iceList,
29+
cutoff=3.5,
30+
firstFrame=1302,
31+
bopAnalysis="q6",
3132
)
3233

33-
#Gets every ring (non-primitives included)
34+
# Gets every ring (non-primitives included)
3435
rings = cyoda.ringNetwork(
35-
nList = iceList,
36-
maxDepth = 6,
36+
nList=iceList,
37+
maxDepth=6,
3738
)
3839

39-
#Finds DDCs and HCs
40+
# Finds DDCs and HCs
4041
tum3 = cyoda.topoUnitMatchingBulk(
41-
path = "runOne/", #outDir
42-
rings = rings,
43-
iceNeighbourList = iceList,
44-
yCloud = solCloud,
45-
firstFrame = 1302,
46-
printClusters = True,
47-
onlyTetrahedral = False,
48-
)
42+
path="runOne/", # outDir
43+
rings=rings,
44+
iceNeighbourList=iceList,
45+
yCloud=solCloud,
46+
firstFrame=1302,
47+
printClusters=True,
48+
onlyTetrahedral=False,
49+
)

0 commit comments

Comments
 (0)