Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ class Cage {
+ MDAnalysis.Universe universe
+ detect_cavity(float step, float probe_in, float probe_out, float removal_distance, float volume_cutoff, str surface, int nthreads, bool verbose, dict~str,object~ **kwargs) void
+ load(filename) void
+ pack(str lattice_type, str atom_type, float atom_radius, float a, float b, float c) void
+ pack(str atom_type, str lattice_type, float a, float b, float c, float clash_tolerance, list~float~ angles, list~float~ translations, bool optsave, str optdir, int nthreads, bool verbose) void
+ preview(bool show_cavity, bool show_cluster, str renderer, dict~str,object~ **kwargs) void
# _build_cluster(str atom_type, str lattice_type, tuple~float~ lattice_constants, numpy.ndarray center) tuple~ase.cluster.Cluster, int~
# _filter_clashing_atoms(ase.cluster.Cluster cluster, float clashing_tolerance) ase.cluster.Cluster
# _build_cluster(str atom_type, str lattice_type, tuple~float~ lattice_constants, numpy.ndarray center, float clash_tolerance, list~float~ angles, list~float~ translations, bool optsave, str optdir, int nthreads, bool verbose) tuple~ase.cluster.Cluster, pandas.DataFrame~
# _filter_clashing_atoms(ase.cluster.Cluster cluster, float clash_tolerance) ase.cluster.Cluster
# _filter_outside_cavity(ase.cluster.Cluster cluster) ase.cluster.Cluster
# _get_cluster_layers(str atom_type, float factor) numpy.ndarray
# _get_obb() tuple~numpy.ndarray, numpy.ndarray~
Expand Down
2 changes: 1 addition & 1 deletion AtomPacker/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
the resulting structures.
"""

__version__ = "0.6.2"
__version__ = "0.7.0"
__name__ = "AtomPacker"
license = "GNU GPL-3.0 License"

Expand Down
46 changes: 27 additions & 19 deletions AtomPacker/structure/Cage.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ def pack(
a: float | None = None,
b: float | None = None,
c: float | None = None,
clashing_tolerance: float = 0.0,
clash_tolerance: float = 0.0,
angles: numpy.ndarray | list[float] = [0.0],
translations: numpy.ndarray | list[float] = [0.0],
optsave: bool = False,
Expand All @@ -299,9 +299,12 @@ def pack(
Lattice constant 'b'. If None, uses values from AtomPacker or ASE.
c : float | None, optional
Lattice constant 'c'. If None, uses values from AtomPacker or ASE.
clashing_tolerance : float, optional
Minimum allowed distance (Å) between cluster and cage atoms.
Default is 0.0.
clash_tolerance : float, optional
Allowed overlap (Å) between cluster and cage atoms. A cluster
atom is removed when its distance to any cage atom is shorter
than the sum of their radii minus this tolerance, so positive
values allow closer contacts (e.g., to mimic host flexibility)
and pack more atoms. Must be >= 0. Default is 0.0.
angles : numpy.ndarray | list[float], optional
Rotation angles for cluster optimization. If not specified, no
optimization is performed. Default is [0.0].
Expand All @@ -328,7 +331,7 @@ def pack(
------
ValueError
If the cage is not loaded, cavity is not detected, or
clashing_tolerance < 0.
clash_tolerance < 0.

Warns
-----
Expand Down Expand Up @@ -383,17 +386,17 @@ def pack(
lattice types are: 'bcc', 'fcc', 'hcp', and 'sc'."
)

# Check if clashing tolerance is greater than or equal to 0
if clashing_tolerance < 0:
raise ValueError("Clashing tolerance must be greater than or equal to 0.")
# Check if clash tolerance is greater than or equal to 0
if clash_tolerance < 0:
raise ValueError("Clash tolerance must be greater than or equal to 0.")

# Optimize cluster packing
_cluster, log = self._build_cluster(
atom_type,
lattice_type,
lattice_constants=lattice_constants,
center=self.centroid,
clashing_tolerance=clashing_tolerance,
clash_tolerance=clash_tolerance,
angles=angles,
translations=translations,
optsave=optsave,
Expand Down Expand Up @@ -581,7 +584,7 @@ def _build_cluster(
lattice_type: str,
lattice_constants: tuple[float, float] | tuple[float] | None,
center: numpy.ndarray,
clashing_tolerance: float = 0.0,
clash_tolerance: float = 0.0,
angles: numpy.ndarray | list[float] = [0.0],
translations: numpy.ndarray | list[float] = [0.0],
optsave: bool = False,
Expand All @@ -606,9 +609,12 @@ def _build_cluster(
values from `ase.data` will be used.
center : numpy.ndarray
The center of the cluster.
clashing_tolerance : float, optional
Minimum allowed distance (Å) between cluster and cage atoms.
Default is 0.0.
clash_tolerance : float, optional
Allowed overlap (Å) between cluster and cage atoms. A cluster
atom is removed when its distance to any cage atom is shorter
than the sum of their radii minus this tolerance, so positive
values allow closer contacts (e.g., to mimic host flexibility)
and pack more atoms. Must be >= 0. Default is 0.0.
angles : numpy.ndarray | list[float], optional
Rotation angles for cluster optimization. If not specified, no
optimization is performed. Default is [0.0].
Expand Down Expand Up @@ -730,7 +736,7 @@ def _evaluate_cluster_configuration(self, phi, theta, psi, x, y, z, cluster):

# Filter atoms clashing with the cage
_tmp = self._filter_clashing_atoms(
_tmp, clashing_tolerance=clashing_tolerance
_tmp, clash_tolerance=clash_tolerance
)

# Save the cluster if requested
Expand Down Expand Up @@ -819,15 +825,15 @@ def _evaluate_cluster_configuration(self, phi, theta, psi, x, y, z, cluster):

# Filter atoms clashing with the cage
cluster = self._filter_clashing_atoms(
cluster, clashing_tolerance=clashing_tolerance
cluster, clash_tolerance=clash_tolerance
)

return cluster, log

def _filter_clashing_atoms(
self,
cluster: ase.cluster.Cluster,
clashing_tolerance: float = 0.0,
clash_tolerance: float = 0.0,
) -> ase.cluster.Cluster:
"""
Filter atoms in the cluster that are clashing with the cage.
Expand All @@ -836,8 +842,10 @@ def _filter_clashing_atoms(
----------
cluster : ase.cluster.Cluster
The cluster of atoms.
clashing_tolerance : float, optional
The clashing tolerance (Å), by default 0.0.
clash_tolerance : float, optional
Allowed overlap (Å): an atom clashes when its distance to a cage
atom is shorter than the sum of their radii minus this value,
by default 0.0.
"""
# Get radii of atoms in the cluster
# If cluster has more than one atom, get the minimum distance between
Expand All @@ -850,7 +858,7 @@ def _filter_clashing_atoms(
limits = (
cluster_radii[:, numpy.newaxis]
+ self.universe.atoms.radii
- clashing_tolerance
- clash_tolerance
)

# Get distance between cluster positions and cage positions
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@ Packing nanoparticle atoms, based on ASE nanocluster, and filter atoms inside a
>>> # cage.cavity.openings.save("tests/openings.pdb")
# 4: Pack nanocluster into the cavity
>>> cage.pack(atom_type="Au", lattice_type="fcc", a=None, b=None, c=None)
# Optional: allow a small host-guest overlap (Å) to mimic cage flexibility
>>> # cage.pack(atom_type="Au", lattice_type="fcc", clash_tolerance=0.5)
# Uncomment to preview the cluster structure for quality control.
>>> # cage.cavity.preview()
>>> # cage.cluster.preview()
# Uncomment to save the cluster structure.
>>> # cage.cluster.save("tests/cluster.pdb")
# Uncomment to preview the cage, cavity, openings and cluster structures.
Expand All @@ -77,7 +79,7 @@ If you find `AtomPacker` useful for you, please cite the following references:

- Guerra, J. V. S., Ribeiro-Filho, H. V., Jara, G. E., Bortot, L. O., Pereira, J. G. C., & Lopes-de-Oliveira, P. S. (2021). pyKVFinder: an efficient and integrable Python package for biomolecular cavity detection and characterization in data science. BMC bioinformatics, 22(1), 607. https://doi.org/10.1186/s12859-021-04519-4.

- (manuscript in preparation) Guerra, J. V. S., Jara, G. E., Hokama, R. H., Bourissou, D. & Szalóki, G. (2026) AtomPacker: a Python Package for the Modellization of Confined Nanoparticles.
- (manuscript in preparation) Guerra, J. V. S., Jara, G. E., Hokama, R. H., Bourissou, D. & Szalóki, G. (2026) Modellization of Confined Nanoparticles with AtomPacker.

## License

Expand Down
6 changes: 3 additions & 3 deletions docs/about.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ Scientific team

[2] Laboratoire Hétérochimie Fondamentale et Appliquée, CNRS, Université Toulouse III─Paul Sabatier.

If you have any further questions, inquires or if you wish to contribute to AtomPacker project, please contact us at joao.guerra@lnbio.cnpem.br.
If you have any further questions, inquiries or if you wish to contribute to AtomPacker project, please contact us at joao.guerra@lnbio.cnpem.br.

Citing
======

If you use **AtomPacker** in your reserach, please cite the following references:
If you use **AtomPacker** in your research, please cite the following references:

* Guerra, J. V. S., Ribeiro-Filho, H. V., Jara, G. E., Bortot, L. O., Pereira, J. G. C., & Lopes-de-Oliveira, P. S. (2021). pyKVFinder: an efficient and integrable Python package for biomolecular cavity detection and characterization in data science. BMC bioinformatics, 22(1), 607. `<https://doi.org/10.1186/s12859-021-04519-4>`_.

* (manuscript in preparation) Guerra, J. V. S., Jara, G. E., Lopes-de-Oliveira, P. S., & Szalóki, G. (2024). AtomPacker: a Python package for packing nanocluster into supramolecular cages.
* (manuscript in preparation) Guerra, J. V. S., Jara, G. E., Hokama, R. H., Bourissou, D. & Szalóki, G. (2026). Modellization of Confined Nanoparticles with AtomPacker.

Funding
=======
Expand Down
1 change: 1 addition & 0 deletions docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ The requirements for installing AtomPacker are:

* ase
* biopython
* joblib
* MDAnalysis
* numpy
* pandas
Expand Down
23 changes: 20 additions & 3 deletions docs/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ You can also save the cavity structure using the `Cavity.save <api.html#AtomPack
3. Detect cavity openings
=========================

Next, we will detect the openings of the cavity. The `Cage.Cavity.detect_openings <api.html#AtomPacker.Cage.detect_openings>`_ method will detect the openings.
Next, we will detect the openings of the cavity. The `Cavity.detect_openings <api.html#AtomPacker.Cavity.detect_openings>`_ method will detect the openings.

.. code-block:: python

Expand Down Expand Up @@ -278,13 +278,30 @@ Now that the cavity and its openings have been detected, you can pack nanopartic

.. note::

To apply an optimization algorithm to the packed cluster, set angles and translations. Translations should be a list or numpy array of angles in degrees, and translations should be a list or numpy array of translation values in Angstroms. For example:
To apply an optimization algorithm to the packed cluster, set angles and translations. Angles should be a list or numpy array of angles in degrees, and translations should be a list or numpy array of translation values in Angstroms. For example:

.. code-block:: python

angles = [-75, -50, -25, 0, 25, 50, 75]
translations = [-0.2, 0.0, 0.2]

The rotations (ϕ, θ, ψ) and translations (x, y, z) are combined as a Cartesian product, so these values give
7³ × 3³ = 9,261 configurations. Each configuration is evaluated in parallel (``nthreads``; default
``os.cpu_count() - 1``) and the one with the largest volume-based diameter is kept. All sampled
configurations are reported in ``cage.cluster.log``.

.. note::

By default, a nanoparticle atom is removed when its distance to any cage atom is shorter than the sum of
their radii (rigid cage). The ``clash_tolerance`` parameter (Å) subtracts an allowed overlap from this
contact distance, so positive values allow closer host–guest contacts and pack more atoms. This is a
simple way to account for thermal fluctuations of the cage (e.g., estimated from crystallographic
B-factors). The tolerance does not change the cavity itself.

.. code-block:: python

>>> cage.pack(atom_type="Au", lattice_type="fcc", clash_tolerance=0.5)

The packed cluster will be stored in the ``cluster`` attribute of the Cage object.

If you want to preview the cluster structure for quality control, you can use the `Cluster.preview <api.html#AtomPacker.Cluster.preview>`_ method.
Expand Down Expand Up @@ -345,7 +362,7 @@ You can access the cluster coordinates using the ``coordinates`` attribute of th
[ -2.44353 29.798132 15.913403]
[ -2.44353 31.838133 13.873403]]

You can also save the cavity structure using the `Cluster.save <api.html#AtomPacker.Cluster.save>`_ method.
You can also save the cluster structure using the `Cluster.save <api.html#AtomPacker.Cluster.save>`_ method.

.. code-block:: python

Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ classifiers = [
dependencies = [
"ase>=3.28.0,<4.0.0",
"biopython>=1.7.0",
"joblib>=1.3.0",
"MDAnalysis>=2.9.0,<3.0.0",
"numpy>=2.0.0,<2.5.0",
"pandas>=2.3.0,<3.1.0",
"plotly>=6.0.0,<6.10.0",
"plotly>=6.0.0,<7.2.0",
"pyKVFinder>=0.9.0,<1.0.0",
"scikit-learn>=1.7.0,<2.0.0",
"tqdm>=4.67.0",
Expand Down
18 changes: 9 additions & 9 deletions tests/test_cage.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def test_filter_clashing_atoms(pdb):
cluster.info.update({"radii": 1.441932148})

# Filter clashing atoms
cluster = cage._filter_clashing_atoms(cluster, clashing_tolerance=0.0)
cluster = cage._filter_clashing_atoms(cluster, clash_tolerance=0.0)

assert len(cluster) == 0

Expand Down Expand Up @@ -261,7 +261,7 @@ def test_filter_not_clashing_atoms(pdb):
cluster.info.update({"radii": 1.441932148})

# Filter clashing atoms
cluster = cage._filter_clashing_atoms(cluster, clashing_tolerance=0.0)
cluster = cage._filter_clashing_atoms(cluster, clash_tolerance=0.0)

assert len(cluster) == 1

Expand Down Expand Up @@ -331,7 +331,7 @@ def test_build_cluster(pdb):
lattice_type="fcc",
lattice_constants=4.08,
center=cage.centroid,
clashing_tolerance=0.0,
clash_tolerance=0.0,
angles=[0.0],
translations=[0.0],
optsave=False,
Expand Down Expand Up @@ -364,7 +364,7 @@ def test_pack(pdb):
"Au",
"fcc",
4.08,
clashing_tolerance=0.0,
clash_tolerance=0.0,
angles=[0.0],
translations=[0.0],
optsave=False,
Expand All @@ -385,15 +385,15 @@ def test_pack_with_invalid_lattice_type(pdb):
"Au",
"invalid",
4.08,
clashing_tolerance=0.0,
clash_tolerance=0.0,
angles=[0.0],
translations=[0.0],
optsave=False,
optdir=None,
)


def test_pack_with_negative_clashing_tolerance(pdb):
def test_pack_with_negative_clash_tolerance(pdb):
cage = Cage()
cage.load(pdb)

Expand All @@ -402,7 +402,7 @@ def test_pack_with_negative_clashing_tolerance(pdb):
"Au",
"fcc",
4.08,
clashing_tolerance=-1.0,
clash_tolerance=-1.0,
angles=[0.0],
translations=[0.0],
optsave=False,
Expand All @@ -417,7 +417,7 @@ def test_pack_for_unloaded_cage():
"Au",
"fcc",
4.08,
clashing_tolerance=0.0,
clash_tolerance=0.0,
angles=[0.0],
translations=[0.0],
optsave=False,
Expand All @@ -434,7 +434,7 @@ def test_pack_without_cavity(pdb):
"Au",
"fcc",
4.08,
clashing_tolerance=0.0,
clash_tolerance=0.0,
angles=[0.0],
translations=[0.0],
optsave=False,
Expand Down
4 changes: 2 additions & 2 deletions tests/test_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def test_pipeline_without_optimization(pdb):
a=4.08,
b=None,
c=None,
clashing_tolerance=0.0,
clash_tolerance=0.0,
angles=[0.0],
translations=[0.0],
optsave=False,
Expand All @@ -47,7 +47,7 @@ def test_pipeline_with_optimization(pdb):
a=4.08,
b=None,
c=None,
clashing_tolerance=0.0,
clash_tolerance=0.0,
angles=[-45, 0, 45],
translations=[0.0, 0.2],
optsave=False,
Expand Down
Loading