Loading [MathJax]/extensions/tex2jax.js
IMP logo
IMP Reference Guide  develop.59ea52c8fa,2025/04/24
The Integrative Modeling Platform
LennardJonesType.h
Go to the documentation of this file.
1 /**
2  * \file IMP/atom/LennardJonesType.h
3  * \brief Parameters for a Lennard-Jones interaction.
4  *
5  * Copyright 2007-2025 IMP Inventors. All rights reserved.
6  */
7 
8 #ifndef IMPATOM_LENNARD_JONES_TYPE_H
9 #define IMPATOM_LENNARD_JONES_TYPE_H
10 
11 #include <IMP/atom/atom_config.h>
12 #include <IMP/Pointer.h>
13 #include <IMP/Object.h>
14 #include <IMP/object_macros.h>
15 #include <IMP/core/XYZ.h>
16 
17 IMPATOM_BEGIN_NAMESPACE
18 
19 //! Parameters for a Lennard-Jones interaction.
20 /** This type stores a well depth and radius, which can be applied to
21  any number of particles using the LennardJonesTyped decorator and then
22  used by LennardJonesTypedPairScore. The parameters can be changed at
23  any time, which will change the interaction of all particles using this
24  type.
25 
26  Note that there is currently no support for overriding the interaction
27  between two specific types (as is done in the CHARMM forcefield with the
28  NBFIX directive, for example) but that could be added if needed.
29  */
30 class IMPATOMEXPORT LennardJonesType : public Object {
31  double well_depth_;
32  double radius_;
33  int index_;
34 public:
35  LennardJonesType(double well_depth, double radius,
36  std::string name="LennardJonesType%1%");
37 
38  double get_well_depth() const { return well_depth_; }
39 
40  void set_well_depth(double d);
41 
42  double get_radius() const { return radius_; }
43 
44  void set_radius(double r);
45 
46  //! Get the globally unique identifier for this type.
47  int get_index() const { return index_; }
48 
50 };
51 
53 
54 #if !defined(SWIG) && !defined(IMP_DOXYGEN)
55 namespace internal {
56 
57 class IMPATOMEXPORT LennardJonesParameters : public Object {
58  LennardJonesTypes types_;
59 
60 public:
61  // Mapping from LJ types for a particle pair to A factor
62  std::vector<double> aij_;
63 
64  // Mapping from LJ types for a particle pair to B factor
65  std::vector<double> bij_;
66 
67  LennardJonesParameters() : Object("LennardJonesParameters %1%") {}
68 
69  int add(LennardJonesType *typ);
70 
71  LennardJonesType *get(int index);
72 
73  // Calculate aij, bij factors for all types interacting with type i
74  void precalculate(int i);
75 
76  int get_parameter_index(int i, int j) const {
77  // matrix is symmetric so we only need to store half. Roll maxij
78  // first so that we don't have to rearrange the vectors when we add
79  // a new type.
80  int maxij = std::max(i, j);
81  int minij = std::min(i, j);
82  return (maxij+1)*maxij / 2 + minij;
83  }
84 };
85 
86 //! Get the singleton object that stores all parameters
87 IMPATOMEXPORT LennardJonesParameters* get_lj_params();
88 
89 } // namespace internal
90 #endif
91 
92 //! A decorator for a particle that has a Lennard-Jones potential well.
93 /** Such particles must be XYZ particles (they must have a position)
94  but need not be true atoms. Note that if the particle is an XYZR
95  particle, the radius used for Lennard-Jones is the LennardJonesTyped
96  radius, not the XYZR radius.
97 
98  \ingroup helper
99  \ingroup decorators
100  \see LennardJonesType
101  \see LennardJonesTypedPairScore
102  */
103 class IMPATOMEXPORT LennardJonesTyped : public core::XYZ {
104  static void do_setup_particle(Model *m, ParticleIndex pi,
105  LennardJonesType *type) {
106  IMP_USAGE_CHECK(XYZ::get_is_setup(m, pi),
107  "Particle must already be an XYZ particle");
108  m->add_attribute(get_type_key(), pi, type->get_index());
109  }
110  public:
113 
114  static bool get_is_setup(Model *m, ParticleIndex pi) {
115  return XYZ::get_is_setup(m, pi) &&
116  m->get_has_attribute(get_type_key(), pi);
117  }
118 
119  void set_type(LennardJonesType *type) {
120  get_model()->set_attribute(get_type_key(), get_particle_index(),
121  type->get_index());
122  }
123 
124  LennardJonesType* get_type() const {
125  int ind = get_index();
126  return internal::get_lj_params()->get(ind);
127  }
128 
129  int get_index() const {
130  return get_model()->get_attribute(get_type_key(), get_particle_index());
131  }
132 
133  double get_well_depth() const {
134  return get_type()->get_well_depth();
135  }
136 
137  double get_radius() const {
138  return get_type()->get_radius();
139  }
140 
141 #ifndef SWIG
142  //! Access the raw attribute data for the type.
143  /** This array may become invalid if particles or attributes are
144  added or removed. */
145  static const int *get_type_array(Model *m) {
146  return m->IMP::internal::IntAttributeTable::access_attribute_data(
147  get_type_key());
148  }
149 #endif
150 
151  //! Get the key used to store the type.
152  static IntKey get_type_key();
153 };
154 
155 IMP_DECORATORS(LennardJonesTyped, LennardJonesTypedList, core::XYZs);
156 
157 IMPATOM_END_NAMESPACE
158 
159 #endif /* IMPATOM_LENNARD_JONES_TYPE_H */
Helper macros for implementing IMP Objects.
ParticleIndex get_particle_index() const
Returns the particle index decorated by this decorator.
Definition: Decorator.h:211
Parameters for a Lennard-Jones interaction.
#define IMP_DECORATOR_SETUP_1(Name, FirstArgumentType, first_argument_name)
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Definition: object_macros.h:25
A decorator for a particle that has a Lennard-Jones potential well.
Model * get_model() const
Returns the Model containing the particle.
Definition: Decorator.h:214
A more IMP-like version of the std::vector.
Definition: Vector.h:50
Simple XYZ decorator.
Class for storing model, its restraints, constraints, and particles.
Definition: Model.h:86
void add_attribute(TypeKey attribute_key, ParticleIndex particle, Type value)
add particle attribute with the specified key and initial value
Ints get_index(const ParticlesTemp &particles, const Subset &subset, const Subsets &excluded)
Common base class for heavy weight IMP objects.
Definition: Object.h:111
void set_attribute(TypeKey attribute_key, ParticleIndex particle, Type value)
set the value of particle attribute with the specified key
A decorator for a particle with x,y,z coordinates.
Definition: XYZ.h:30
int get_index() const
Get the globally unique identifier for this type.
#define IMP_OBJECTS(Name, PluralName)
Define the types for storing lists of object pointers.
Definition: object_macros.h:44
A nullptr-initialized pointer to an IMP Object.
A shared base class to help in debugging and things.
static const int * get_type_array(Model *m)
Access the raw attribute data for the type.
#define IMP_DECORATOR_METHODS(Name, Parent)
#define IMP_USAGE_CHECK(expr, message)
A runtime test for incorrect usage of a class or method.
Definition: check_macros.h:168
#define IMP_DECORATORS(Name, PluralName, Parent)
Define the types for storing sets of decorators.
bool get_has_attribute(TypeKey attribute_key, ParticleIndex particle) const
return true if particle has attribute with the specified key
Type get_attribute(TypeKey attribute_key, ParticleIndex particle)
get the value of the particle attribute with the specified key