diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md index fb44aa7..f85e966 100644 --- a/ARCHITECTURE.md +++ b/ARCHITECTURE.md @@ -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~ diff --git a/AtomPacker/__init__.py b/AtomPacker/__init__.py index d40ef6a..b36ee06 100644 --- a/AtomPacker/__init__.py +++ b/AtomPacker/__init__.py @@ -9,7 +9,7 @@ the resulting structures. """ -__version__ = "0.6.2" +__version__ = "0.7.0" __name__ = "AtomPacker" license = "GNU GPL-3.0 License" diff --git a/AtomPacker/structure/Cage.py b/AtomPacker/structure/Cage.py index 1e6f06e..ea2bd42 100644 --- a/AtomPacker/structure/Cage.py +++ b/AtomPacker/structure/Cage.py @@ -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, @@ -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]. @@ -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 ----- @@ -383,9 +386,9 @@ 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( @@ -393,7 +396,7 @@ def pack( lattice_type, lattice_constants=lattice_constants, center=self.centroid, - clashing_tolerance=clashing_tolerance, + clash_tolerance=clash_tolerance, angles=angles, translations=translations, optsave=optsave, @@ -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, @@ -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]. @@ -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 @@ -819,7 +825,7 @@ 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 @@ -827,7 +833,7 @@ def _evaluate_cluster_configuration(self, phi, theta, psi, x, y, z, cluster): 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. @@ -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 @@ -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 diff --git a/README.md b/README.md index b6449cf..d5eabc4 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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 diff --git a/docs/about.rst b/docs/about.rst index e2e0879..0cdb1f9 100644 --- a/docs/about.rst +++ b/docs/about.rst @@ -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. ``_. -* (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 ======= diff --git a/docs/installation.rst b/docs/installation.rst index cc52045..fc5781b 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -6,6 +6,7 @@ The requirements for installing AtomPacker are: * ase * biopython +* joblib * MDAnalysis * numpy * pandas diff --git a/docs/tutorial.rst b/docs/tutorial.rst index 6998965..4657d5b 100644 --- a/docs/tutorial.rst +++ b/docs/tutorial.rst @@ -138,7 +138,7 @@ You can also save the cavity structure using the `Cavity.save `_ method will detect the openings. +Next, we will detect the openings of the cavity. The `Cavity.detect_openings `_ method will detect the openings. .. code-block:: python @@ -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 `_ method. @@ -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 `_ method. +You can also save the cluster structure using the `Cluster.save `_ method. .. code-block:: python diff --git a/pyproject.toml b/pyproject.toml index f323887..bf73ac6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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", diff --git a/tests/test_cage.py b/tests/test_cage.py index d08f204..6aa25e9 100644 --- a/tests/test_cage.py +++ b/tests/test_cage.py @@ -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 @@ -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 @@ -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, @@ -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, @@ -385,7 +385,7 @@ 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, @@ -393,7 +393,7 @@ def test_pack_with_invalid_lattice_type(pdb): ) -def test_pack_with_negative_clashing_tolerance(pdb): +def test_pack_with_negative_clash_tolerance(pdb): cage = Cage() cage.load(pdb) @@ -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, @@ -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, @@ -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, diff --git a/tests/test_pipeline.py b/tests/test_pipeline.py index 31f1e4c..3b70b87 100644 --- a/tests/test_pipeline.py +++ b/tests/test_pipeline.py @@ -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, @@ -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,