rid.op package

Submodules

rid.op.adjust_trust_level module

class rid.op.adjust_trust_level.AdjustTrustLevel(*args, **kwargs)[source]

Bases: OP

AdjustTrustLeve OP adjust trust level according to the number of cluster (numb_cluster) and the number of cluster threshold (numb_cluster_threshold). If numb_cluster < numb_cluster_threshold, the trust level will be increased. Trust levels won’t increase infinitly. When current trust_lvl_1 > max_level_multiple * init_trust_lvl_1, where init_trust_lvl_1 is the initial trust level, trust_lvl_1 will be tuned to its initial value.

execute(op_in: OPIO) OPIO[source]

Execute the OP.

Parameters

op_in (dict) –

Input dict with components:

  • trust_lvl_1: (float) Trust level 1 in the current iteration, or e0.

  • trust_lvl_2: (float) Trust level 2 in the current iteration, or e1.

  • init_trust_lvl_1: (float) Initial value of trust level 1.

  • init_trust_lvl_1: (float) Initial value of trust level 2.

  • numb_cluster: (int) Number of clusters got from cluster op.

  • numb_cluster_threshold: (int) Threshold for cluster number to adjust trust level adaptively.

    if numb_cluster > numb_cluster_threshold, trust_lvl will be increased.

  • adjust_amplifier: (float) Increasing multiple for trust level.

  • max_level_multiple: (float) The max multiple than trust level can be increased.

Returns

  • Output dict with components

  • - `adjust_trust_lvl_1` ((float) Adjusted Trust level 1 for next iteration.)

  • - `adjust_trust_lvl_2` ((float) Adjusted Trust level 2 for next iteration.)

classmethod get_input_sign()[source]

Get the signature of the inputs

classmethod get_output_sign()[source]

Get the signature of the outputs

rid.op.calc_mf module

class rid.op.calc_mf.CalcMF(*args, **kwargs)[source]

Bases: OP

Calculate mean force with the results of restrained MD.

\[MeanForce = ( Average(CVs) - Initial(CVs) ) * kappa\]

CalcMF will handle periodic CVs by angular_mask. To get the mean value of CVs near equilibrium state under restrained MD, only part of outputs of CV values (the last tail part, for example, the last 90% CV values) are used.

execute(op_in: OPIO) OPIO[source]

Execute the OP.

Parameters

op_in (dict) –

Input dict with components:

  • task_name: (str) Task name, used to make sub-directory for the task.

  • plm_out: (Artifact(Path)) Outputs of CV values from restrained MD simulations.

    These outputs are generated by PLUMED2.

  • kappas: (List[float]) Force constants of harmonic restraints.

  • at: (Artifact(Path)) Files containing initial CV values, or CV centers.

  • tail: (float) Only the last tail of CV values will be used to estimate mean force.

  • angular_mask: (int) Mask list for periodic CVs. 1 represents periodic, 0 represents non-periodic.

    length of angular_mask equals to the dimension of CVs.

Returns

  • forces: (Artifact(Path)) Files containing mean forces.

Return type

Output dict with components

classmethod get_input_sign()[source]

Get the signature of the inputs

classmethod get_output_sign()[source]

Get the signature of the outputs

rid.op.prep_data module

class rid.op.prep_data.CollectData(*args, **kwargs)[source]

Bases: OP

Gather data of different simulations to a single file.

execute(op_in: OPIO) OPIO[source]

Run the OP

classmethod get_input_sign()[source]

Get the signature of the inputs

classmethod get_output_sign()[source]

Get the signature of the outputs

class rid.op.prep_data.MergeData(*args, **kwargs)[source]

Bases: OP

Merge old data and new generated data. If old data not existed, it will return new data. If new data is empty, it will return old data.

execute(op_in: OPIO) OPIO[source]

Run the OP

classmethod get_input_sign()[source]

Get the signature of the inputs

classmethod get_output_sign()[source]

Get the signature of the outputs

rid.op.prep_exploration module

rid.op.prep_label module

rid.op.prep_rid module

class rid.op.prep_rid.PrepRiD(*args, **kwargs)[source]

Bases: OP

Pre-processing of RiD.

  1. Parse RiD configuration JSON file, get default value if parameters are not provided.

  2. Rearrange conformation files.

  3. Make task names and formats.

execute(op_in: OPIO) OPIO[source]

Execute the OP.

Parameters

op_in (dict) –

Input dict with components:

  • confs: (Artifact(Path)) User-provided initial conformation files (.gro) for reinfoced dynamics.

  • rid_config: (Artifact(Path)) Configuration file (.json) of RiD.

    Parameters in this file will be parsed.

Returns

  • Output dict with components

  • - `numb_iters` ((int) Max number of iterations for Ri.)

  • - `numb_walkers` ((int) Number of parallel walkers for exploration.)

  • - `numb_models` ((int) Number of neural network models of RiD.)

  • - `confs` ((Artifact(List[Path])) Rearranged initial conformation files (.gro) for reinfoced dynamics.)

  • - `walker_tags` ((List) Tag formmat for parallel walkers.)

  • - `model_tags` ((List) Tag formmat for neural network models.)

  • - `exploration_config` ((Dict) Configuration of simulations in exploration steps.)

  • - `cv_config` ((Dict) Configuration to create CV in PLUMED2 style.)

  • - `trust_lvl_1` ((List[float]) Trust level 1, or e0.)

  • - `trust_lvl_2` ((List[float]) Trust level 2, or e1.)

  • - `cluster_threshold` ((List[float]) Initial guess of cluster threshold.)

  • - `angular_mask` ((List) Angular mask for periodic collective variables.) – 1 represents periodic, 0 represents non-periodic.

  • - `weights` ((List) Weights for clustering collective variables. see details in cluster algorithms.)

  • - `numb_cluster_upper` ((int) Upper limit of cluster number to make cluster threshold.)

  • - `numb_cluster_lower` ((int) Lower limit of cluster number to make cluster threshold.)

  • - `max_selection` ((int) Max selection number of clusters in Selection steps for each parallel walker.)

  • - `numb_cluster_threshold` ((int) Used to adjust trust level. When cluster number is grater than this threshold,) – trust levels will be increased adaptively.

  • - `dt` ((float) Time interval of exploration MD simulations. Gromacs trjconv commands will need this parameters) – to slice trajectories by -dump tag, see selection steps for detail.

  • - `slice_mode` ((str) Mode to slice trajectories. Either gmx or mdtraj.)

  • - `label_config` ((Dict) Configuration of simulations in labeling steps.)

  • - `kappas` ((List) Force constants of harmonic restraints to perform restrained MD simulations.)

  • - `train_config` ((Dict) Configuration to train neural networks, including training strategy and network structures.)

classmethod get_input_sign()[source]

Get the signature of the inputs

classmethod get_output_sign()[source]

Get the signature of the outputs

rid.op.prep_rid.prep_confs(confs, numb_walkers)[source]

rid.op.prep_select module

class rid.op.prep_select.PrepSelect(*args, **kwargs)[source]

Bases: OP

PrepSelect OP clusters CV outputs of each parallel walker from exploration steps and prepares representative frames of each clusters for further selection steps. RiD-kit employs agglomerative clustering algorithm performed by Scikit-Learn python package. The distance matrix of CVs is pre-calculated, which is defined by Euclidean distance in CV space. For each cluster, one representive frame will be randomly chosen from cluster members. For periodic collective variables, RiD-kit uses angular_mask to identify them and handle their periodic conditions during distance calculation. In the first run of RiD iterations, PrepSelect will make a cluster threshold automatically from the initial guess of this value and make cluter numbers of each parallel walker fall into the interval of [numb_cluster_lower, numb_cluster_upper].

execute(op_in: OPIO) OPIO[source]

Execute the OP.

Parameters

op_in (dict) –

Input dict with components:

  • task_name: (str) Task names, used to make sub-directory for tasks.

  • plm_out: (Artifact(Path)) Outputs of CV values (plumed.out by default) from exploration steps.

  • cluster_threshold: (float) Cluster threshold of agglomerative clustering algorithm

  • angular_mask: (array_like) Mask for periodic collective variables. 1 represents periodic, 0 represents non-periodic.

  • weights: (array_like) Weights to cluster collective variables. see details in cluster parts.

  • numb_cluster_upper: (Optional[float]) Upper limit of cluster number to make cluster threshold.

  • numb_cluster_lower: (Optional[float]) Lower limit of cluster number to make cluster threshold.

  • max_selection: (int) Max selection number of clusters in Selection steps for each parallel walker.

    For each cluster, one representive frame will be randomly chosen from cluster members.

  • if_make_threshold: (bool) whether to make threshold to fit the cluster number interval. Usually True in the 1st

    iteration and False in the further iterations.

Returns

  • Output dict with components

  • - `numb_cluster` ((int) Number of clusters.)

  • - `cluster_threshold` ((float) Cluster threshold of agglomerative clustering algorithm.)

  • - `cluster_selection_index` ((Artifact(Path)) Indice of chosen representive frames of clusters in trajectories.)

  • - `cluster_selection_data` ((Artifact(Path)) Collective variable values of chosen representive frames of clusters.)

classmethod get_input_sign()[source]

Get the signature of the inputs

classmethod get_output_sign()[source]

Get the signature of the outputs

rid.op.recorder module

class rid.op.recorder.Recorder(*args, **kwargs)[source]

Bases: OP

Record iteration index of RiD and make names for block (or iterations).

execute(op_in: OPIO) OPIO[source]

Execute the OP.

Parameters

op_in (dict) –

Input dict with components:

  • iteration: (int) Last iteration index. iteration is None means not any iteration performed before.

Returns

  • Output dict with components

  • - `next_iteration` ((int) Next iteration index.)

  • - `block_tag` ((str) Names for block. See rid.superop.blocks)

classmethod get_input_sign()[source]

Get the signature of the inputs

classmethod get_output_sign()[source]

Get the signature of the outputs

rid.op.run_exploration module

rid.op.run_label module

class rid.op.run_label.RunLabel(*args, **kwargs)[source]

Bases: OP

In RunLabel, labeling processes are achieved by restrained MD simulations wehre harmonnic restraints are exerted on collective variables. RunLabel is able to run in a standard Gromacs-PLUMED2 env.

execute(op_in: OPIO) OPIO[source]

Execute the OP.

Parameters

op_in (dict) –

Input dict with components:

  • task_path: (Artifact(Path)) A directory path containing files for Gromacs MD simulations.

  • label_config: (Dict) Configuration of Gromacs simulations in label steps.

Returns

  • Output dict with components

  • - `plm_out` ((Artifact(Path)) Outputs of CV values (plumed.out by default) from label steps.)

  • - `md_log` ((Artifact(Path)) Log files of Gromacs mdrun commands.)

classmethod get_input_sign()[source]

Get the signature of the inputs

classmethod get_output_sign()[source]

Get the signature of the outputs

rid.op.run_select module

rid.op.run_train module

class rid.op.run_train.TrainModel(*args, **kwargs)[source]

Bases: OP

TrainModel trains a set of neural network models (set by numb_model in train_config). RiD-kit is powered by TensorFlow framework. The output model files are frozen in .pb formats by rid.nn.freeze.

execute(op_in: OPIO) OPIO[source]

Execute the OP.

Parameters

op_in (dict) –

Input dict with components:

  • model_tag: (str) Tags for neural network model files. In formats of model_{model_tag}.pb.

  • angular_mask: (List) Angular mask for periodic collective variables. 1 represents periodic, 0 represents non-periodic.

  • data: (Artifact(Path)) Data files for training. Prepared by rid.op.prep_data.

    data has the shape of [number_conf, 2 * dimension_cv] and contains the CV values and corresponding mean forces.

  • train_config: (Dict) Configuration to train neural networks, including training strategy and network structures.

Returns

  • Output dict with components

  • - `model` ((Artifact(Path)) Neural network models in .pb formats.)

classmethod get_input_sign()[source]

Get the signature of the inputs

classmethod get_output_sign()[source]

Get the signature of the outputs