Tissue Forge C++ 0.2.1
Interactive, particle-based physics, chemistry and biology modeling and simulation environment
Loading...
Searching...
No Matches
tfBond.h
Go to the documentation of this file.
1/*******************************************************************************
2 * This file is part of mdcore.
3 * Coypright (c) 2010 Pedro Gonnet (pedro.gonnet@durham.ac.uk)
4 * Coypright (c) 2017 Andy Somogyi (somogyie at indiana dot edu)
5 * Copyright (c) 2022-2024 T.J. Sego
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published
9 * by the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 ******************************************************************************/
21
26
27#ifndef _MDCORE_INCLUDE_TFBOND_H_
28#define _MDCORE_INCLUDE_TFBOND_H_
29
30#include <mdcore_config.h>
31#include <tfParticleList.h>
32
33
34namespace TissueForge {
35
36
37 namespace rendering {
38 struct Style;
39 }
40
41
42 typedef enum BondFlags {
43
44 // none type bonds are initial state, and can be
45 // re-assigned if ref count is 1 (only owned by engine).
46 BOND_NONE = 0,
47 // a non-active and will be over-written in the
48 // next bond_alloc call.
49 BOND_ACTIVE = 1 << 0,
50 } BondFlags;
51
52 // list of pairs...
53 struct Pair {
54 int32_t i;
55 int32_t j;
56 };
57
58 typedef std::vector<Pair> PairList;
59 struct BondHandle;
60 struct ParticleHandle;
61
68 typedef struct CAPI_EXPORT Bond {
69
70 uint32_t flags;
71
72 /* id of particles involved */
73 int32_t i, j;
74
75 uint32_t id;
76
77 uint64_t creation_time;
78
82 FPTYPE half_life;
83
84 /* potential energy required to break this bond */
85 FPTYPE dissociation_energy;
86
87 /* potential energy of this bond */
88 FPTYPE potential_energy;
89
90 struct Potential *potential;
91
92 struct rendering::Style *style;
93
98
112 struct Potential *potential,
113 ParticleHandle *i,
114 ParticleHandle *j,
115 FPTYPE *half_life=NULL,
116 FPTYPE *dissociation_energy=NULL,
117 uint32_t flags=0
118 );
119
123 std::string toString();
124
132 static Bond *fromString(const std::string &str);
133
135
136 struct ParticleType;
137 struct ParticleList;
138
144 struct CAPI_EXPORT BondHandle {
145 int32_t id;
146
153
159 BondHandle() : id(-1) {};
160
166 BondHandle(int id);
167
181 struct TissueForge::Potential *potential,
182 int32_t i,
183 int32_t j,
184 FPTYPE half_life,
185 FPTYPE bond_energy,
186 uint32_t flags
187 );
188
205 const FPTYPE &half_life=-FPTYPE_ONE,
206 const FPTYPE &bond_energy=-FPTYPE_ONE,
207 uint32_t flags=0
208 );
209
213 std::string str() const;
214
221 bool check();
222
237 static std::vector<BondHandle> pairwise(
240 const FPTYPE &cutoff,
241 std::vector<std::pair<TissueForge::ParticleType*, TissueForge::ParticleType*>* > *ppairs,
242 const FPTYPE &half_life,
243 const FPTYPE &bond_energy,
244 uint32_t flags
245 );
246
253
257 static std::vector<BondHandle> items();
258
264 bool decays();
265
266 TissueForge::ParticleHandle *operator[](unsigned int index);
267
269 bool has(const int32_t &pid);
270
272 bool has(ParticleHandle *part);
273
275 FloatP_t getLength();
276
278 FPTYPE getEnergy();
279
281 std::vector<int32_t> getParts();
282
285
288
290 uint32_t getId();
291
294
296 void setDissociationEnergy(const FPTYPE &dissociation_energy);
297
299 FPTYPE getHalfLife();
300
302 void setHalfLife(const FPTYPE &half_life);
303
306
309
311 FPTYPE getAge();
312
313 private:
314
315 HRESULT _init(
316 uint32_t flags,
317 int32_t i,
318 int32_t j,
319 FPTYPE half_life,
320 FPTYPE bond_energy,
321 struct Potential *potential
322 );
323 };
324
325 bool contains_bond(const std::vector<BondHandle> &bonds, int a, int b);
326
334 CAPI_FUNC(HRESULT) Bond_Destroy(Bond *b);
335
342
343 HRESULT Bond_Energy (Bond *b, FPTYPE *epot_out);
344
345 /* associated functions */
346
355 CAPI_FUNC(HRESULT) bond_eval (Bond *b, int N, struct engine *e, FPTYPE *epot_out);
356
369 CAPI_FUNC(HRESULT) bond_evalf (Bond *b, int N, struct engine *e, FPTYPE *f, FPTYPE *epot_out);
370
371
375 std::vector<int32_t> Bond_IdsForParticle(int32_t pid);
376
377 int insert_bond(
378 std::vector<BondHandle> &bonds,
379 int a,
380 int b,
381 Potential *pot,
382 ParticleList *parts
383 );
384
385 inline bool operator< (const TissueForge::BondHandle& lhs, const TissueForge::BondHandle& rhs) { return lhs.id < rhs.id; }
386 inline bool operator> (const TissueForge::BondHandle& lhs, const TissueForge::BondHandle& rhs) { return rhs < lhs; }
387 inline bool operator<=(const TissueForge::BondHandle& lhs, const TissueForge::BondHandle& rhs) { return !(lhs > rhs); }
388 inline bool operator>=(const TissueForge::BondHandle& lhs, const TissueForge::BondHandle& rhs) { return !(lhs < rhs); }
389 inline bool operator==(const TissueForge::BondHandle& lhs, const TissueForge::BondHandle& rhs) { return lhs.id == rhs.id; }
390 inline bool operator!=(const TissueForge::BondHandle& lhs, const TissueForge::BondHandle& rhs) { return !(lhs == rhs); }
391
392
393};
394
395
396inline std::ostream &operator<<(std::ostream& os, const TissueForge::BondHandle &h)
397{
398 os << h.str().c_str();
399 return os;
400}
401
402#endif // _MDCORE_INCLUDE_TFBOND_H_
Tissue Forge rendering and visualization.
Definition tfAngle.h:38
Include Python header, disable linking to pythonX_d.lib on Windows in debug mode.
Definition tfAngleConfig.h:26
HRESULT Bond_Destroy(Bond *b)
HRESULT bond_eval(Bond *b, int N, struct engine *e, FPTYPE *epot_out)
Evaluate a list of bonded interactions.
std::vector< int32_t > Bond_IdsForParticle(int32_t pid)
HRESULT Bond_DestroyAll()
Deletes all bonds in the universe.
struct TissueForge::Bond Bond
Bonds apply a potential to a particular set of particles.
HRESULT bond_evalf(Bond *b, int N, struct engine *e, FPTYPE *f, FPTYPE *epot_out)
Evaluate a list of bonded interactions.
Handle to a bond.
Definition tfBond.h:144
BondHandle(struct TissueForge::Potential *potential, int32_t i, int32_t j, FPTYPE half_life, FPTYPE bond_energy, uint32_t flags)
Construct a new bond handle and underlying bond.
void setStyle(rendering::Style *style)
ParticleList getPartList()
std::string str() const
Get a summary string of the bond.
BondHandle(int id)
Construct a new bond handle from an existing bond id.
bool has(const int32_t &pid)
std::vector< int32_t > getParts()
static std::vector< BondHandle > items()
Gets all bonds in the universe.
HRESULT destroy()
Destroy the bond.
bool has(ParticleHandle *part)
BondHandle()
Construct a new bond handle and do nothing Subsequent usage will require a call to 'init'.
Definition tfBond.h:159
HRESULT init(TissueForge::Potential *pot, TissueForge::ParticleHandle *p1, TissueForge::ParticleHandle *p2, const FPTYPE &half_life=-FPTYPE_ONE, const FPTYPE &bond_energy=-FPTYPE_ONE, uint32_t flags=0)
For initializing a bond after constructing with default constructor.
void setHalfLife(const FPTYPE &half_life)
void setDissociationEnergy(const FPTYPE &dissociation_energy)
rendering::Style * getStyle()
TissueForge::Potential * getPotential()
bool decays()
Tests whether this bond decays.
static std::vector< BondHandle > pairwise(TissueForge::Potential *pot, TissueForge::ParticleList &parts, const FPTYPE &cutoff, std::vector< std::pair< TissueForge::ParticleType *, TissueForge::ParticleType * > * > *ppairs, const FPTYPE &half_life, const FPTYPE &bond_energy, uint32_t flags)
Apply bonds to a list of particles.
TissueForge::Bond * get()
Gets the underlying bond.
bool check()
Check the validity of the handle.
Bonds apply a potential to a particular set of particles.
Definition tfBond.h:68
FPTYPE half_life
Definition tfBond.h:82
static Bond * fromString(const std::string &str)
Create from a JSON string representation.
static rendering::Style * styleDef()
Get the default style.
std::string toString()
Get a JSON string representation.
static BondHandle * create(struct Potential *potential, ParticleHandle *i, ParticleHandle *j, FPTYPE *half_life=NULL, FPTYPE *dissociation_energy=NULL, uint32_t flags=0)
Construct a new bond handle and underlying bond.
Definition tfBond.h:53
A handle to a particle.
Definition tfParticle.h:313
A special list with convenience methods for working with sets of particles.
Definition tfParticleList.h:52
A Potential object is a compiled interpolation of a given function. The Universe applies potentials t...
Definition tfPotential.h:213
Definition tfEngine.h:164
The Tissue Forge style type.
Definition tfStyle.h:46
int32_t HRESULT
Definition tf_port.h:255