Metadata-Version: 2.1
Name: combinemols3d
Version: 1.0.0
Summary: Combine 2 molecules in 3D by sample.
Home-page: https://github.com/franklalalala/CombineMols3D
Author: Franklalalala
Author-email: franklalalala <1660810667@qq.com>
License: The MIT License (MIT)
        
        Copyright (c) 2024 Franklalalala
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Source, https://github.com/franklalalala/CombineMols3D
Platform: any
Classifier: Programming Language :: Python
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Natural Language :: English
Classifier: Development Status :: 3 - Alpha
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE.txt
Requires-Dist: importlib-metadata
Requires-Dist: ase
Requires-Dist: numpy
Requires-Dist: scipy

# CombineMols3D
Combine 2 molecules in 3D by sample.

![overview](.//overview.png)

<center>Overview of the combination process.</center>

## How it works?
In short, it could be summarized into 2 steps:

1. Translation:
   * The new bond length is determined by the summation of the covalent radii of the two atoms. 
   * Set one atom as the central of a sphere, sample positions on this sphere and calculate the repulsion between the new addon to the whole molecule. (The repulsion is measured by the summation of the inverse distance.)
   * Choose the minimum repulsion position and translate the whole addon molecule as a rigid body.
2. Rotation:
   * Set the bonded site as center and the nearest neighbor as rotation axes. Rotate the addon molecule as a rigid body
   * Sample rotation angles to minimize the repulsion between the addon molecule to the main molecule. (Again, the repulsion is measured by the summation of the inverse distance.)
   * Choose the minimum repulsion image and this is the final combination state.


## Install
```
pip install combinemols3d
```

## Usage
1. Prepare your to-be-bonded molecules as `ase.Atoms` object. (Read  `ase` documentation for format manipulation.)
2. Determine which sites to be bonded together. (dummy sites)
3. Combine them by eliminate the dummy sites.

```python
from ase.visualize import view
from ase.build.molecule import molecule
from combinemols3d.CombineMols3D import combine_2_mols_with_dummy, combine_2_mols

main_mol = molecule('C7NH5')
sub_mol = molecule('BDA')

view(main_mol)
view(sub_mol)

final_mol = combine_2_mols_with_dummy(molecule_1=main_mol.copy(), molecule_2=sub_mol.copy(),
                                      dummy_atom_index_1=11, dummy_atom_index_2=6)
view(final_mol)
```
If you don't want to eliminate the dummy sites, use the `combine_2_mols` instead:
```python
final_mol = combine_2_mols(molecule_1=main_mol, molecule_2=sub_mol,
                                      tgt_atom_1_index=11, tgt_atom_2_index=6)
view(final_mol)
```
Other parameters are same for the two functions:

* Conformation related:

  * `skin`: to get a proper bond length for the new bond. Here we adopt the [covalent radii method](https://en.wikipedia.org/wiki/Covalent_radius). A skin parameter is added to finetune the bond length, though it is 0 by default.
    
    
    
    $R(\mathrm{AB})=r(\mathrm{A})+r(\mathrm{B})+skin$
  
    
    
  * `cutoff_mult`: there are several places to detect neighbors for a specific atom. By default, it is `natural cutoff` as follow equation: 
    
    
    
    $DetectRange(\mathrm{AB})=r(\mathrm{A})+r(\mathrm{B})+0.3$

    
    
    We can enlarge our search scope to multiply the  `natural cutoff` as follow equation:
    
    $DetectRange(\mathrm{AB})=cutoff mult*(r(\mathrm{A})+r(\mathrm{B})+0.3)$
    

* Performance related:
  * `sample_times`: how many times to sample addon positions in translation and angles in rotation.
  * `rotation_times`: In the rotation stage, we will rotate the whole addon molecule as a rigid body. The orientations of the addon site to its neighbors are taken as fixed rotation axes. How many neighbors to be considered could be performance critical.


## Note

Contact me: 1660810667@qq.com
