IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
The Integrative Modeling Platform
Charged.h
Go to the documentation of this file.
1/**
2 * \file IMP/atom/Charged.h
3 * \brief A decorator for a point particle that has an electrostatic charge.
4 *
5 * Copyright 2007-2022 IMP Inventors. All rights reserved.
6 *
7 */
8
9#ifndef IMPATOM_CHARGED_H
10#define IMPATOM_CHARGED_H
11
12#include <IMP/atom/atom_config.h>
13
14#include <IMP/core/XYZ.h>
16#include <IMP/internal/constants.h>
17
18#include <vector>
19#include <limits>
20
21IMPATOM_BEGIN_NAMESPACE
22
23//! A decorator for a point particle that has an electrostatic charge.
24/** The charge itself should be given in atomic units; i.e. the charge on
25 a proton is +1 and on an electron, -1.
26
27 \ingroup helper
28 \ingroup decorators
29 \see CoulombPairScore
30 */
31class IMPATOMEXPORT Charged : public IMP::core::XYZ {
32 static void do_setup_particle(Model *m, ParticleIndex pi,
33 const algebra::Vector3D &v, Float charge) {
34 XYZ::setup_particle(m, pi, v);
35 do_setup_particle(m, pi, charge);
36 }
37 static void do_setup_particle(Model *m, ParticleIndex pi,
38 Float charge = 0) {
39 IMP_USAGE_CHECK(XYZ::get_is_setup(m, pi),
40 "Particle must already be an XYZ particle");
41 m->add_attribute(get_charge_key(), pi, charge);
42 }
43
44 public:
46 IMP_DECORATOR_SETUP_1(Charged, Float, charge);
48
49 IMP_DECORATOR_GET_SET(charge, get_charge_key(), Float, Float);
50
51 //! Return true if the particle is an instance of a Charged
52 static bool get_is_setup(Model *m, ParticleIndex pi) {
53 return XYZ::get_is_setup(m, pi) &&
54 m->get_has_attribute(get_charge_key(), pi);
55 }
56
57#ifndef SWIG
58 //! Access the raw attribute data for the charge.
59 /** This array may become invalid if particles or attributes are
60 added or removed. */
61 static const double *get_charge_array(Model *m) {
62 return m->FloatAttributeTable::access_attribute_data(get_charge_key());
63 }
64#endif
65
66 static FloatKey get_charge_key();
67};
68
69IMP_DECORATORS(Charged, Chargeds, core::XYZs);
70
71IMPATOM_END_NAMESPACE
72
73#endif /* IMPATOM_CHARGED_H */
Simple XYZ decorator.
Simple 3D vector class.
#define IMP_USAGE_CHECK(expr, message)
A runtime test for incorrect usage of a class or method.
Class for storing model, its restraints, constraints, and particles.
Definition Model.h:111
static bool get_is_setup(Model *m, ParticleIndex pi)
Return true if the particle is an instance of a Charged.
Definition Charged.h:52
static const double * get_charge_array(Model *m)
Access the raw attribute data for the charge.
Definition Charged.h:61
A decorator for a particle with x,y,z coordinates.
Definition XYZ.h:30
static XYZ setup_particle(Model *m, ParticleIndex pi)
Definition XYZ.h:51
#define IMP_DECORATOR_SETUP_1(Name, FirstArgumentType, first_argument_name)
#define IMP_DECORATOR_GET_SET(name, AttributeKey, Type, ReturnType)
Define methods for getting and setting a particular simple field.
#define IMP_DECORATORS(Name, PluralName, Parent)
Define the types for storing sets of decorators.
#define IMP_DECORATOR_SETUP_2(Name, FirstArgumentType, first_argument_name, SecondArgumentType, second_argument_name)
#define IMP_DECORATOR_METHODS(Name, Parent)
Index< ParticleIndexTag > ParticleIndex
Definition base_types.h:196
double Float
Basic floating-point value (could be float, double...).
Definition types.h:19
VectorD< 3 > Vector3D
Definition VectorD.h:407
Key< 0 > FloatKey
The type used to identify float attributes in the Particles.
Definition base_types.h:32