Skip to content

Commit 027d23b

Browse files
committed
updated examples
1 parent a19eb5b commit 027d23b

File tree

2 files changed

+180
-1
lines changed

2 files changed

+180
-1
lines changed
Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "d9f6e0be",
6+
"metadata": {},
7+
"source": [
8+
"The ConformerEnsemble class can also read energies from the comment line on .xyz files."
9+
]
10+
},
11+
{
12+
"cell_type": "code",
13+
"execution_count": null,
14+
"id": "4043bf31",
15+
"metadata": {},
16+
"outputs": [
17+
{
18+
"data": {
19+
"text/plain": [
20+
"(675, 220, 3)"
21+
]
22+
},
23+
"execution_count": 1,
24+
"metadata": {},
25+
"output_type": "execute_result"
26+
}
27+
],
28+
"source": [
29+
"from prism_pruner.conformer_ensemble import ConformerEnsemble\n",
30+
"from prism_pruner.pruner import prune\n",
31+
"from prism_pruner.utils import EH_TO_KCAL # 627.5096080305927\n",
32+
"\n",
33+
"ensemble = ConformerEnsemble.from_xyz(\"../tests/crest_conformers.xyz\", read_energies=True)\n",
34+
"ensemble.coords.shape"
35+
]
36+
},
37+
{
38+
"cell_type": "markdown",
39+
"id": "466dc74d",
40+
"metadata": {},
41+
"source": [
42+
"\n",
43+
"Energy-aware pruning can be useful for larger arrays: using a max_dE of 0.5 kcal/mol, a 28% speedup is observed relative to the normal mode, as a consequence of the fewer number of calls to the similarity evaluation functions. This is of course accompanied by a obtaining a larger, \"less pruned\" ensemble (132 vs 64 structures)."
44+
]
45+
},
46+
{
47+
"cell_type": "code",
48+
"execution_count": null,
49+
"id": "c7ec20b3",
50+
"metadata": {},
51+
"outputs": [
52+
{
53+
"name": "stdout",
54+
"output_type": "stream",
55+
"text": [
56+
"DEBUG: MOIPrunerConfig - k=20, rejected 455 (keeping 220/675), in 0.1 s\n",
57+
"DEBUG: MOIPrunerConfig - k=10, rejected 49 (keeping 171/675), in 0.0 s\n",
58+
"DEBUG: MOIPrunerConfig - k=5, rejected 18 (keeping 153/675), in 0.0 s\n",
59+
"DEBUG: MOIPrunerConfig - k=2, rejected 13 (keeping 140/675), in 0.0 s\n",
60+
"DEBUG: MOIPrunerConfig - k=1, rejected 0 (keeping 140/675), in 0.0 s\n",
61+
"DEBUG: MOIPrunerConfig - keeping 140/675 (0.1 s)\n",
62+
"DEBUG: MOIPrunerConfig - Used cached data 9902/16071 times, 61.61% of total calls\n",
63+
"\n",
64+
"DEBUG: RMSDPrunerConfig - k=5, rejected 4 (keeping 136/140), in 0.3 s\n",
65+
"DEBUG: RMSDPrunerConfig - k=2, rejected 0 (keeping 136/140), in 0.1 s\n",
66+
"DEBUG: RMSDPrunerConfig - k=1, rejected 0 (keeping 136/140), in 0.1 s\n",
67+
"DEBUG: RMSDPrunerConfig - keeping 136/140 (0.5 s)\n",
68+
"DEBUG: RMSDPrunerConfig - Used cached data 6341/7717 times, 82.17% of total calls\n",
69+
"\n",
70+
"DEBUG: prune_by_rmsd_rot_corr - temporarily added edge 92-179 to the graph (will be removed before returning)\n",
71+
"DEBUG: RMSDRotCorrPrunerConfig - k=5, rejected 2 (keeping 134/136), in 27.0 s\n",
72+
"DEBUG: RMSDRotCorrPrunerConfig - k=2, rejected 2 (keeping 132/136), in 7.1 s\n",
73+
"DEBUG: RMSDRotCorrPrunerConfig - k=1, rejected 0 (keeping 132/136), in 0.1 s\n",
74+
"DEBUG: RMSDRotCorrPrunerConfig - keeping 132/136 (34.2 s)\n",
75+
"DEBUG: RMSDRotCorrPrunerConfig - Used cached data 6019/7299 times, 82.46% of total calls\n",
76+
"CPU times: user 35.8 s, sys: 26 ms, total: 35.8 s\n",
77+
"Wall time: 35.8 s\n"
78+
]
79+
}
80+
],
81+
"source": [
82+
"%%time\n",
83+
"pruned, mask = prune(\n",
84+
" ensemble.coords,\n",
85+
" ensemble.atoms,\n",
86+
" energies=ensemble.energies, # energies were provided in Eh: max_dE should be, too\n",
87+
" max_dE = 0.5 / EH_TO_KCAL, # 0.5 kcal, in Eh (7.968...10^-4 Eh)\n",
88+
" rot_corr_rmsd_pruning=True,\n",
89+
" debugfunction=print,\n",
90+
")"
91+
]
92+
},
93+
{
94+
"cell_type": "code",
95+
"execution_count": 8,
96+
"id": "d8c8c551",
97+
"metadata": {},
98+
"outputs": [
99+
{
100+
"name": "stdout",
101+
"output_type": "stream",
102+
"text": [
103+
"DEBUG: MOIPrunerConfig - k=20, rejected 456 (keeping 219/675), in 0.0 s\n",
104+
"DEBUG: MOIPrunerConfig - k=10, rejected 56 (keeping 163/675), in 0.0 s\n",
105+
"DEBUG: MOIPrunerConfig - k=5, rejected 38 (keeping 125/675), in 0.0 s\n",
106+
"DEBUG: MOIPrunerConfig - k=2, rejected 46 (keeping 79/675), in 0.0 s\n",
107+
"DEBUG: MOIPrunerConfig - k=1, rejected 15 (keeping 64/675), in 0.0 s\n",
108+
"DEBUG: MOIPrunerConfig - keeping 64/675 (0.1 s)\n",
109+
"DEBUG: MOIPrunerConfig - Used cached data 5780/15111 times, 38.25% of total calls\n",
110+
"\n",
111+
"DEBUG: RMSDPrunerConfig - k=2, rejected 0 (keeping 64/64), in 0.2 s\n",
112+
"DEBUG: RMSDPrunerConfig - k=1, rejected 0 (keeping 64/64), in 0.2 s\n",
113+
"DEBUG: RMSDPrunerConfig - keeping 64/64 (0.4 s)\n",
114+
"DEBUG: RMSDPrunerConfig - Used cached data 992/3008 times, 32.98% of total calls\n",
115+
"\n",
116+
"DEBUG: prune_by_rmsd_rot_corr - temporarily added edge 35-182 to the graph (will be removed before returning)\n",
117+
"DEBUG: RMSDRotCorrPrunerConfig - k=2, rejected 0 (keeping 64/64), in 23.4 s\n",
118+
"DEBUG: RMSDRotCorrPrunerConfig - k=1, rejected 0 (keeping 64/64), in 25.4 s\n",
119+
"DEBUG: RMSDRotCorrPrunerConfig - keeping 64/64 (48.8 s)\n",
120+
"DEBUG: RMSDRotCorrPrunerConfig - Used cached data 992/3008 times, 32.98% of total calls\n",
121+
"CPU times: user 50 s, sys: 40.1 ms, total: 50 s\n",
122+
"Wall time: 50 s\n"
123+
]
124+
}
125+
],
126+
"source": [
127+
"%%time\n",
128+
"pruned, mask = prune(\n",
129+
" ensemble.coords,\n",
130+
" ensemble.atoms,\n",
131+
" rot_corr_rmsd_pruning=True,\n",
132+
" debugfunction=print,\n",
133+
")"
134+
]
135+
},
136+
{
137+
"cell_type": "code",
138+
"execution_count": 17,
139+
"id": "6e83f8b0",
140+
"metadata": {},
141+
"outputs": [
142+
{
143+
"data": {
144+
"text/plain": [
145+
"'28.4 % speedup'"
146+
]
147+
},
148+
"execution_count": 17,
149+
"metadata": {},
150+
"output_type": "execute_result"
151+
}
152+
],
153+
"source": [
154+
"f\"{(1-(35.8/50))*100:.1f} % speedup\""
155+
]
156+
}
157+
],
158+
"metadata": {
159+
"kernelspec": {
160+
"display_name": "dev",
161+
"language": "python",
162+
"name": "python3"
163+
},
164+
"language_info": {
165+
"codemirror_mode": {
166+
"name": "ipython",
167+
"version": 3
168+
},
169+
"file_extension": ".py",
170+
"mimetype": "text/x-python",
171+
"name": "python",
172+
"nbconvert_exporter": "python",
173+
"pygments_lexer": "ipython3",
174+
"version": "3.14.0"
175+
}
176+
},
177+
"nbformat": 4,
178+
"nbformat_minor": 5
179+
}

examples/example_notebook.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"id": "638ffd44",
66
"metadata": {},
77
"source": [
8-
"The module uses numpy arrays for atomic positions and atomic numbers. You can read structures with ConformerEnsemble.from_xyz. The ensemble object usesd ASE variable names, exposing the \"coords\" and \"atoms\" properties."
8+
"The module uses numpy arrays for atomic positions and atomic numbers. You can read structures with ConformerEnsemble.from_xyz. The ensemble object uses ASE variable names, exposing the \"coords\" and \"atoms\" properties."
99
]
1010
},
1111
{

0 commit comments

Comments
 (0)