Skip to content

Commit 5721d31

Browse files
committed
Change optimization target to Volume diameter (Å), no optimization as default, and add openings_cutoff parameter
1 parent 6650c68 commit 5721d31

File tree

4 files changed

+63
-31
lines changed

4 files changed

+63
-31
lines changed

AtomPacker/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
the resulting structures.
1010
"""
1111

12-
__version__ = "0.4.2"
12+
__version__ = "0.4.3"
1313
__name__ = "AtomPacker"
1414
license = "GNU GPL-3.0 License"
1515

AtomPacker/structure/Cage.py

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,8 @@ def pack(
274274
b: float | None = None,
275275
c: float | None = None,
276276
clashing_tolerance: float = 0.0,
277-
angles: numpy.ndarray | list[float] | None = None,
278-
translations: numpy.ndarray | list[float] | None = None,
277+
angles: numpy.ndarray | list[float] = [0.0],
278+
translations: numpy.ndarray | list[float] = [0.0],
279279
optsave: bool = False,
280280
optdir: str | None = None,
281281
verbose: bool = False,
@@ -299,12 +299,16 @@ def pack(
299299
clashing_tolerance : float, optional
300300
Minimum allowed distance (Å) between cluster and cage atoms.
301301
Default is 0.0.
302-
angles : numpy.ndarray | list[float] | None, optional
303-
Rotation angles for cluster optimization. If None, uses [-75, -50,
304-
-25, 0, 25, 50, 75].
305-
translations : numpy.ndarray | list[float] | None, optional
306-
Translation values for cluster optimization. If None, uses
307-
[-0.2, 0.0, 0.2].
302+
angles : numpy.ndarray | list[float], optional
303+
Rotation angles for cluster optimization. If not specified, no optimization
304+
is performed. Default is [0.0].
305+
If specified, angles should be a list or numpy array of angles in degrees.
306+
Example: [-75, -50, -25, 0, 25, 50, 75].
307+
translations : numpy.ndarray | list[float], optional
308+
Translation values for cluster optimization. If not specified, no optimization
309+
is performed. Default is [0.0].
310+
If specified, translations should be a list or numpy array of translation
311+
values in Angstroms. Example: [-0.2, 0.0, 0.2].
308312
optsave : bool, optional
309313
If True, saves each optimization step as a PDB file. Default is
310314
False.
@@ -556,8 +560,8 @@ def _build_cluster(
556560
lattice_constants: tuple[float, float] | tuple[float] | None,
557561
center: numpy.ndarray,
558562
clashing_tolerance: float = 0.0,
559-
angles: numpy.ndarray | list[float] | None = None,
560-
translations: numpy.ndarray | list[float] | None = None,
563+
angles: numpy.ndarray | list[float] = [0.0],
564+
translations: numpy.ndarray | list[float] = [0.0],
561565
optsave: bool = False,
562566
optdir: str | None = None,
563567
verbose: bool = False,
@@ -582,12 +586,16 @@ def _build_cluster(
582586
clashing_tolerance : float, optional
583587
Minimum allowed distance (Å) between cluster and cage atoms.
584588
Default is 0.0.
585-
angles : numpy.ndarray | list[float] | None, optional
586-
Rotation angles for cluster optimization. If None, uses [-75, -50,
587-
-25, 0, 25, 50, 75].
588-
translations : numpy.ndarray | list[float] | None, optional
589-
Translation values for cluster optimization. If None, uses
590-
[-0.2, 0.0, 0.2].
589+
angles : numpy.ndarray | list[float], optional
590+
Rotation angles for cluster optimization. If not specified, no optimization
591+
is performed. Default is [0.0].
592+
If specified, angles should be a list or numpy array of angles in degrees.
593+
Example: [-75, -50, -25, 0, 25, 50, 75].
594+
translations : numpy.ndarray | list[float], optional
595+
Translation values for cluster optimization. If not specified, no optimization
596+
is performed. Default is [0.0].
597+
If specified, translations should be a list or numpy array of translation
598+
values in Angstroms. Example: [-0.2, 0.0, 0.2].
591599
optsave : bool, optional
592600
If True, saves each optimization step as a PDB file. Default is
593601
False.
@@ -670,13 +678,6 @@ def _build_cluster(
670678
# Get lattice constants for nanocluster
671679
cluster.info.update({"lattice_constants": lattice_constants})
672680

673-
# Create rotation angles and translations for the cluster
674-
if angles is None:
675-
angles = numpy.arange(start=-75, stop=90, step=25)
676-
677-
if translations is None:
678-
translations = numpy.arange(start=-0.2, stop=0.21, step=0.2)
679-
680681
# Iterate over all possible combinations of angles and translations
681682
log = []
682683
combinations = list(
@@ -747,8 +748,8 @@ def _build_cluster(
747748
# Convert optimization to DataFrame
748749
log = pandas.DataFrame(log)
749750

750-
# Get the best cluster based on the maximum diameter
751-
idx = log["Maximum diameter (Å)"].idxmax()
751+
# Get the best cluster based on the volume diameter
752+
idx = log["Volume diameter (Å)"].idxmax()
752753
x, y, z, phi, theta, psi = log.loc[idx, ["x", "y", "z", "phi", "theta", "psi"]]
753754

754755
# Rotate and translate the cluster

AtomPacker/structure/Cavity.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def volume(self) -> numpy.float64:
100100
)
101101
return ((self.grid > 1).sum() * (self._step**3)).round(2)
102102

103-
def detect_openings(self, verbose: bool = False) -> None:
103+
def detect_openings(self, openings_cutoff: int = 1, verbose: bool = False) -> None:
104104
"""
105105
Detect openings in the cavity.
106106
@@ -110,6 +110,9 @@ def detect_openings(self, verbose: bool = False) -> None:
110110
111111
Parameters
112112
----------
113+
openings_cutoff : float, optional
114+
The cutoff value for detecting openings (default is 1). The minimum
115+
number of points in an opening to be considered valid.
113116
verbose : bool, optional
114117
If True, print detailed information during processing (default is False).
115118
@@ -121,7 +124,13 @@ def detect_openings(self, verbose: bool = False) -> None:
121124
if self.grid.max() > 2:
122125
warnings.warn("Cavity has more than one cavity.")
123126

124-
self.openings = Openings(self.grid, self._step, self._vertices, verbose=verbose)
127+
self.openings = Openings(
128+
self.grid,
129+
self._step,
130+
self._vertices,
131+
openings_cutoff=openings_cutoff,
132+
verbose=verbose,
133+
)
125134

126135
def preview(
127136
self,

AtomPacker/structure/Openings.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,14 @@ class Openings:
2929
their properties, and exporting openings data.
3030
"""
3131

32-
def __init__(self, cavities: numpy.ndarray, step: float, vertices: numpy.ndarray, verbose: bool = False):
32+
def __init__(
33+
self,
34+
cavities: numpy.ndarray,
35+
step: float,
36+
vertices: numpy.ndarray,
37+
openings_cutoff: float = 1,
38+
verbose: bool = False,
39+
):
3340
"""
3441
Create a new `AtomPacker.Openings` object.
3542
@@ -41,14 +48,19 @@ def __init__(self, cavities: numpy.ndarray, step: float, vertices: numpy.ndarray
4148
The step size of the grid.
4249
vertices : numpy.ndarray
4350
The vertices (origin, X-axis, Y-axis, Z-axis) of the grid.
51+
openings_cutoff : float, optional
52+
The cutoff value for detecting openings (default is 1). The minimum
53+
number of points in an opening to be considered valid.
4454
verbose : bool, optional
4555
If True, print detailed information during processing (default is False).
4656
"""
4757
self.nopenings: int
4858
self.grid: numpy.ndarray
4959
self.areas: dict[str, float]
5060

51-
self.nopenings, self.grid, self.areas = self._detect(cavities, step, verbose=verbose)
61+
self.nopenings, self.grid, self.areas = self._detect(
62+
cavities, step, openings_cutoff=openings_cutoff, verbose=verbose
63+
)
5264
self.diameters: dict[str, float] = self._get_diameter()
5365

5466
self._step: float = step
@@ -162,6 +174,7 @@ def _detect(
162174
self,
163175
cavities: numpy.ndarray,
164176
step: float,
177+
openings_cutoff: float = 1,
165178
verbose: bool = False,
166179
) -> tuple[int, numpy.ndarray, dict[str, float]]:
167180
"""
@@ -173,6 +186,9 @@ def _detect(
173186
The cavity points.
174187
step : float
175188
The step size of the grid.
189+
openings_cutoff : float, optional
190+
The cutoff value for detecting openings (default is 1). The minimum
191+
number of points in an opening to be considered valid.
176192
verbose : bool, optional
177193
If True, print detailed information during processing (default is False).
178194
@@ -192,7 +208,13 @@ def _detect(
192208
depths, _, _ = depth(cavities, step, verbose=verbose)
193209

194210
# Calculate openings and area of openings
195-
nopenings, grid, aopenings = openings(cavities, depths, step=step, verbose=verbose)
211+
nopenings, grid, aopenings = openings(
212+
cavities,
213+
depths,
214+
step=step,
215+
openings_cutoff=openings_cutoff,
216+
verbose=verbose,
217+
)
196218

197219
# Flatten and sort opening areas
198220
areas = {

0 commit comments

Comments
 (0)