metasponge 1.1.0
A Python Based AI Molecular Mechanics Simulation Tool
License: Apache 2.0 Licence

# MindSponge based on Cybertroncode
The source code of cybertroncode is forked from: https://gitee.com/helloyesterday/cybertroncode. The mindsponge used to simulate Molecular Dynamics via MindSpore is based on cybertroncode force field. And Meta Dynamics is already developed in this library.

## Quick Start
1. Check if there already exists `mindspore-gpu` in you pip list. And thus excute command bellow in your local computer:
    ```python
    pip install metasponge --upgrade
    ```
2. Start your AIMM research like [this example](https://gitee.com/dechin/cybertroncode/blob/master/examples/main_cba.py).
3. The API documentation (not complete yet) will be updated on [readthedocs](https://mindsponge.readthedocs.io/en/latest/#). And you can download our `.whl` file in [pypi](https://pypi.org/project/mindsponge/) thus you can install `mindsponge` without network.


## Parameters configuration
This part shoud be seperated into many small parts to introduce.
### Parameters of controller

```python
args_opt = Parser(crd='cba_its_mw0_trans.rst7', record='mdcrd.dat',
                  output='mdout.txt', last_hills='last_hills', amber_param='cba.prmtop',
                  box='mdbox.txt', id=1, checkpoint='cba_kcal_mol_A_MolCT-best.ckpt',
                  with_box=1)
```

### MD input configurations
```python
class MdInOfCba(MdIn):
    """MD configure parameters input object.
    MD Args:
        velocity_max: The max velocity of atom moving.
        md_task: The project name in string format.
        dt: Time slice to simulate molecular dynamics.
        skin: Used for cut in neighbor list operations.
        step_limit: The max steps to simulate molecular dynamics.
        langevin_seed: A random seed.
    Meta Args:
        hills: The recorded hills list during molecular simulation.
        smin: The minimum value of collective variables, default to be 0.15.
        smax: The maximum value of collective variables, default to be 0.25.
        ds: The grid size of collective variables, default to be 0.0005.
        omega: The height of Gaussian peaks, default to be 50.
        sigma: The width of Gaussian peaks, default to be 0.005.
        dt: Time step of molecular simulation, default to be 0.001.
        T: The temperature be used in well tempered Meta Dynamics, default to be 300.
        wall_index: The grid index closed to smin, default to be 10.
        grid_num: The grid number of cv space.
        well_tempered: Choose while to use wt or not.
    """
    def __init__(self):
        super(MdInOfCba, self).__init__()
        self.md_task = 'CBA AIMM Task'
        self.mode = 1
        self.dt = 0.001
        self.skin = 2.0
        self.trans_vec = [self.skin, self.skin, self.skin]
        self.trans_vec_minus = -1 * self.trans_vec
        self.step_limit = 20
        self.netfrc = 0
        self.ntwx = 1
        self.ntce = self.step_limit + 1
        self.amber_irest = 1
        self.target_temperature = 300
        self.langevin_gamma = 5.0
        self.langevin_seed = 6
        self.velocity_max = 20
        # Meta Information
        self.meta = 1
        self.smin = 0
        self.smax = 8
        self.meta_grids = 200
        self.meta_interval = 5
        self.wall_index = 10
        self.omega = 50
        self.sigma = 0.005
        self.T = 300
        self.gamma = 6
        self.kappa = 4
        self.factor = 0.1
```
### CV for meta dynamics
```python
class CvOfCba(Cv1D):
    def __init__(self):
        super(CvOfCba, self).__init__()
    def construct(self, crd):
        # Write your cv function.
        return your_cv
```
### Bias for meta dynamics
```python
class BiasOfCba(Bias):
    def __init__(self, *args, **kwargs):
        super(BiasOfCba, self).__init__(*args, **kwargs)
        self.cv1d = CvOfCba()

    def construct(self, crd, hills):
        # Write your bias function
        return your_bias
```
### Fixed atom types
```python
atom_types = Tensor([6,1,6,1,6,1,1,6,1,6,1,6,1,1,8])
```
### Configure the MolCT model
```python
mod = MolCT(min_rbf_dis=0.1,
            max_rbf_dis=10,
            num_rbf=128,
            rbf_sigma=0.2,
            n_interactions=3,
            dim_feature=128,
            n_heads=8,
            max_cycles=1,
            use_time_embedding=True,
            fixed_cycles=True,
            self_dis=0.1,
            unit_length='A',
            use_feed_forward=False)
```
### Define readout network
```python
readout = AtomwiseReadout(n_in=mod.dim_feature,
                          n_interactions=mod.n_interactions,
                          activation=mod.activation,
                          n_out=1,
                          mol_scale=3.0,
                          unit_energy='kcal/mol')
```

### Run your model
After all these pure python configures, you can run your model trained well. For more information you can have a look on this example: [`cybertroncode/mindsponge/main_cba.py`](https://gitee.com/dechin/cybertroncode/blob/master/mindsponge/main_cba.py)