Force_field.force_field module

Description

This module defines the ParaMol.Force_field.force_field.ForceField class which is the ParaMol representation of a force field that contains all the information about the force field terms and correspondent parameters (even relatively to those that will not enter the optimization).

class ParaMol.Force_field.force_field.ForceField(openmm_engine)

Bases: object

ParaMol representation of a force field.

Parameters

openmm_engine (ParaMol.MM_engines.openmm.OpenMMEngine) – ParaMol representation of the OpenMMEngine

Variables
  • force_field (dict) – Dictionary that contains as keys force groups names and as values and the correspondent ParaMol.Force_field.force_field_term.FFTerm. This mapping is constructed as given by OpenMM.

  • force_field_optimizable (dict) – Same as before but only containing optimizable force field terms. Force groups that do not have optimizable force field terms will not be part of this dictionary.

  • force_groups (dict) – Dictionary that defines the mapping between force group names and force group numbers, which is defined accordingly to the information obtained form the OpenMM System.

  • optimizable_parameters (list) – List that contains instances of ParaMol.Force_field.force_field_term_parameter.Parameter that are optimizable.

  • optimizable_parameters_values (list of float/int) – List that contains the values of the optimizable force field parameters. This is usually fed into the optimization itself.

create_force_field(opt_bonds=False, opt_angles=False, opt_torsions=False, opt_charges=False, opt_lj=False, opt_sc=False, ff_file=None)

Method that wraps the methods create_force_field_from_openmm/read_ff_file and create_force_field_optimizable in order to ease the procedure of creating a ParaMol representation of a force field.

Notes

If ff_file is not None the force field will be created from the provided file. The system stored in ParaMol.MM_engines.openmm.OpenMMEngine should contain exactly the same forces and force field terms as the ones in this file.

Parameters
  • opt_bonds (bool) – Flag that signals whether or not the bond parameters will be optimized.

  • opt_angles (bool) – Flag that signals whether or not the angle parameters will be optimized.

  • opt_torsions (bool) – Flag that signals whether or not the dihedral parameters will be optimized.

  • opt_charges (bool) – Flag that signal whether or not the charges will be optimized.

  • opt_lj (bool) – Flag that signal whether or not the charges will be optimized.

  • opt_sc (bool) – Flag that signal whether or not the 1-4 Lennard-Jones and electrostatic scaling factor will be optimized.

  • ff_file (str) – Name of the ParaMol force field file to be read.

Returns

force_field (dict) – Dictionary that contains as keys force groups names and as values and the correspondent ParaMol.Force_field.force_field_term.FFTerm.

create_force_field_from_openmm(opt_bonds, opt_angles, opt_torsions, opt_charges, opt_lj, opt_sc)

Method that creates the force field dictionary that contains all the FFTerms of the force field as given by OpenMM. The FFTerms are grouped in lists that can be accessed by the key of the correspondent force group.

Notes

This method constructs the force_groups dictionary, and calls the methods create_harmonic_bond_force_field,create_harmonic_angle_force_field, create_periodic_torsion_force_field, create_nonbonded_force_field in order to construct the force_filed dictionary.

Parameters
  • opt_bonds (bool) – Flag that signals whether or not the bond parameters will be optimized.

  • opt_angles (bool) – Flag that signals whether or not the angle parameters will be optimized.

  • opt_torsions (bool) – Flag that signals whether or not the dihedral parameters will be optimized.

  • opt_charges (bool) – Flag that signal whether or not the charges will be optimized.

  • opt_lj (bool) – Flag that signal whether or not the charges will be optimized.

  • opt_sc (bool) – Flag that signal whether or not the 1-4 Lennard-Jones and electrostatic scaling factor will be optimized.

Returns

force_field (dict) – Dictionary that contains as keys force groups names and as values and the correspondent ParaMol.Force_field.force_field_term.FFTerm.

create_force_field_optimizable()

Method that creates the optimizable force field dictionary that contains all the optimizable FFTerms. The FFTerms are grouped in lists that can be accessed by the key of the correspondent force group.

Returns

force_field_optimizable (dict) – Dictionary that contains as keys force groups names and as values and the correspondent ParaMol.Force_field.force_field_term.FFTerm.

create_harmonic_angle_force_field(opt_angles)

Method that creates the part of the force field regarding OpenMM’s force ‘HarmonicAngleForce’.

Parameters

opt_angles (bool) – Flag that signals whether or not the angle parameters will be optimized.

Returns

force_field (dict) – Dictionary that contains as keys force groups names and as values and the correspondent ParaMol.Force_field.force_field_term.FFTerm.

create_harmonic_bond_force_field(opt_bonds)

Method that creates the part of the force field regarding OpenMM’s force ‘HarmonicBondForce’.

Parameters

opt_bonds (bool) – Flag that signals whether or not the bond parameters will be optimized.

Returns

force_field (dict) – Dictionary that contains as keys force groups names and as values and the correspondent ParaMol.Force_field.force_field_term.FFTerm.

create_nonbonded_force_field(opt_charges, opt_lj, opt_sc)

Method that creates the part of the force field regarding OpenMM’s force ‘NonbondedForce’.

Parameters
  • opt_charges (bool) – Flag that signals whether or not the charge parameters will be optimized.

  • opt_lj (bool) – Flag that signals whether or not the Lennard-Jones 12-6 parameters will be optimized.

  • opt_sc (bool) – Flag that signals whether or not the 1-4 Lennard-Jones and electrostatic scaling factors’s parameters will be optimized.

Returns

force_field (dict) – Dictionary that contains as keys force groups names and as values and the correspondent ParaMol.Force_field.force_field_term.FFTerm.

create_periodic_torsion_force_field(opt_torsions)

Method that creates the part of the force field regarding OpenMM’s force ‘PeriodicTorsionForce’.

Parameters

opt_torsions (bool) – Flag that signals whether or not the torsion parameters will be optimized.

Returns

force_field (dict) – Dictionary that contains as keys force groups names and as values and the correspondent ParaMol.Force_field.force_field_term.FFTerm.

get_optimizable_parameters(symmetry_constrained=True)

Method that gets the lists containing all optimizable Parameter instances and parameter values.

Parameters

symmetry_constrained (bool) – Whether or not the optimization is constrained by symmetries.

Returns

optimizable_parameters, optimizable_parameters_values (list of ParaMol.Force_field.force_field_term_parameter.Parameter, list of int/float) – Attributes of self.

optimize_scaling_constants(atom_pairs, change_other_sc=False, change_other_parameters=False)

Methods that sets as optimizable all parameters of the scaling factors contained in the listed passed as an argument.

Parameters
  • atom_pairs (list of lists) – List of list, wherein the inner lists contain indices of the pair of atoms for which the scaling factors are to be optimized.

  • change_other_sc (bool) – Whether or not the remaining scaling constants’s optimization state is to be set to False. (default is False, i.e., their optimization state is not changed)

  • change_other_parameters (bool) – Whether or not the remaining parameters’ optimization state is to be set to False. (default is False, i.e., their optimization state is not changed)

Returns

force_field (dict) – Dictionary that contains as keys force groups names and as values and the correspondent ParaMol.Force_field.force_field_term.FFTerm.

optimize_selection(lower_idx, upper_idx, change_other=False)

Methods that sets a parameter as optimizable if it belongs to a force field term for which at least one of the atoms’s indices is greather than lower_idx and lower than upper_idx.

Notes

If [10,20] is given a the lower_idx list and [15,25] is given as the upper_idx list, the selection will comprise the atoms between 10-15 and 20-25.

Parameters
  • lower_idx (list of int) – Lower index limits.

  • upper_idx (list of int) – Upper index limits.

  • change_other (bool) – Whether or not the remaining parameter’s optimization state is to be set to False. (default is False, i.e., their optimization state is not change)

Returns

force_field (dict) – Dictionary that contains as keys force groups names and as values and the correspondent ParaMol.Force_field.force_field_term.FFTerm.

optimize_torsions(torsions, change_other_torsions=False, change_other_parameters=False)

Methods that sets as optimizable all parameters of the torsions contained in the listed passed as an argument.

Parameters
  • torsions (list of lists) – List of list, wherein the inner lists contain indices of the quartets of atoms that define the torsion to be optimized.

  • change_other_torsions (bool) – Whether or not the remaining torsions’s optimization state is to be set to False. (default is False, i.e., their optimization state is not changed)

  • change_other_parameters (bool) – Whether or not the remaining parameters’ optimization state is to be set to False. (default is False, i.e., their optimization state is not changed)

Returns

force_field (dict) – Dictionary that contains as keys force groups names and as values and the correspondent ParaMol.Force_field.force_field_term.FFTerm.

optimize_torsions_by_symmetry(torsions, change_other_torsions=False, change_other_parameters=False, set_zero=False)

Methods that sets as optimizable all parameters of the torsions with the same symmetry groups as the ones contained in the listed passed as an argument.

Parameters
  • torsions (list of lists) – List of list, wherein the inner lists contain indices of the quartets of atoms that define the torsion to be optimized.

  • change_other_torsions (bool) – Whether or not the remaining torsions’s optimization state is to be set to False. (default is False, i.e., their optimization state is not changed)

  • change_other_parameters (bool) – Whether or not the remaining parameters’ optimization state is to be set to False. (default is False, i.e., their optimization state is not changed)

  • set_zero (bool) – Whether or not to set the force constant of the optimizable torsions to 0.

Returns

force_field (dict) – Dictionary that contains as keys force groups names and as values and the correspondent ParaMol.Force_field.force_field_term.FFTerm.

read_ff_file(file_name)

Method that reads the force field parameters in the standard format used by ParaMol (usually .ff extension) and creates its ParaMol representation.

Parameters

file_name (str) – Name of the file to be read.

Returns

True if file was closed successfully. False otherwise.

set_parameter_optimization(force_key, sub_force, idx, param_key, optimize)

Method that for the force field term with index idx of the force force_key set the parameter with name param_key to the optimization state in optimize.

Parameters
  • force_key (str) – Name of the force.

  • sub_force (int) – Ocurrence of the force.

  • idx (int) – Index of the force field term.

  • param_key (str) – Name of the parameter.

  • optimize (bool) – Optimization state (0 or 1).

Returns

force_field (dict) – Dictionary that contains as keys force groups names and as values and the correspondent ParaMol.Force_field.force_field_term.FFTerm.

symmetry_group_default = 'X'
update_force_field(optimizable_parameters_values, symmetry_constrained=True)

Method that updates the value of each Parameter object instance.

Parameters
  • optimizable_parameters_values (list of float/int) – List that contains the values of the optimizable force field parameters.

  • symmetry_constrained (bool) – Whether or not the optimization is constrained by symmetries.

Returns

optimizable_parameters (list of ParaMol.Force_field.force_field_term_parameter.Parameter) – List that contains instances of ParaMol.Force_field.force_field_term_parameter.Parameter that are optimizable.

write_ff_file(file_name)

Method that writes the force field parameters in the standard format used by ParaMol (usually .ff extension).

Parameters

file_name (str) – Name of the file to be written.

Returns

True if file was closed successfully. False otherwise.