Develop Biology
The language of life
Atom.h
Go to the documentation of this file.
1/*
2 * This file is a part of the Biology project by eons LLC.
3 * Biology (aka Develop Biology) is a framework for approaching software
4 * development from a natural sciences perspective.
5 *
6 * Copyright (C) 2021 Séon O'Shannon & eons LLC
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Affero General Public License as
10 * published by the Free Software Foundation, either version 3 of the
11 * License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Affero General Public License for more details.
17 *
18 * You should have received a copy of the GNU Affero General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22#pragma once
23
24#include "bio/common/Cast.h"
31#include "PeriodicTable.h"
32#include "Bond.h"
33
34namespace bio {
35namespace chemical {
36
37class Symmetry;
38
50class Atom :
51 public physical::Class< Atom >
52{
53public:
54
59 Atom)
60
61
64 explicit Atom();
65
71 explicit Atom(const Atom& other);
72
76 virtual ~Atom();
77
82 virtual physical::Symmetry* Spin() const;
83
89 virtual Code Reify(physical::Symmetry* symmetry);
90
96 virtual Code Attenuate(const Wave* other);
97
103 virtual Code Disattenuate(const Wave* other);
104
110 Wave* GetBonded(Valence position);
111
117 const Wave* GetBonded(Valence position) const;
118
124 template < typename T >
126 {
127 Valence position = GetBondPosition< T >();
128 BIO_SANITIZE(position, ,
129 return NULL);
130 return ForceCast< T >(m_bonds.OptimizedAccess(position)->GetBonded());
131 }
132
138 template < typename T >
139 const T AsBonded() const
140 {
141 Valence position = GetBondPosition< T >();
142
143 BIO_SANITIZE(position, ,
144 return NULL);
145 return ForceCast< const T >(m_bonds.OptimizedAccess(position)->GetBonded());
146 }
147
153 template < typename T >
155 {
156 return Cast< T >(AsBonded< physical::Quantum< T >* >());
157 }
158
164 template < typename T >
165 const T AsBondedQuantum() const
166 {
167 return *AsBonded< physical::Quantum< T >* >();
168 }
169
175 template < typename T >
176 T As()
177 {
178 #if BIO_CPP_VERSION < 11
179 return AsBondedQuantum< T >();
180 #else
181 if (IsPrimitive< T >())
182 {
183 return AsBondedQuantum< T >();
184 }
185 else
186 {
187 return AsBonded< T >();
188 }
189 #endif
190 }
191
198 template < typename T >
199 const T As() const
200 {
201 #if BIO_CPP_VERSION < 11
202 return AsBondedQuantum< T >();
203 #else
204 if (IsPrimitive< T >())
205 {
206 return AsBondedQuantum< T >();
207 }
208 else
209 {
210 return AsBonded< T >();
211 }
212 #endif
213 }
214
215
221 template < typename T >
222 operator T()
223 {
224 return As< T >();
225 }
226
236 template < typename T >
238 T toBond,
239 BondType type = bond_type::Unknown())
240 {
241 #if BIO_CPP_VERSION < 11
242 AtomicNumber bondedId = PeriodicTable::Instance().GetIdFromType< physical::Quantum< T >* >();
244 bondedId,
245 type
246 );
247 #else
248 if (IsPrimitive< T >())
249 {
250 AtomicNumber bondedId = PeriodicTable::Instance().GetIdFromType< physical::Quantum< T >* >();
252 (new physical::Quantum< T >(toBond))->AsWave(),
253 bondedId,
254 type
255 );
256 }
257 else
258 {
259 AtomicNumber bondedId = PeriodicTable::Instance().GetIdFromType< T >();
261 toBond->AsWave(),
262 bondedId,
263 type
264 );
265 }
266 #endif
267 }
268
278 template < typename T >
280 T toDisassociate,
281 BondType type = bond_type::Unknown())
282 {
283 #if BIO_CPP_VERSION < 11
284 return BreakBond< physical::Quantum< T >* >(
285 NULL,
286 type
287 );
288 #else
289 if (IsPrimitive< T >())
290 {
291 return BreakBond< physical::Quantum< T >* >(NULL, type); //T matters, toDisassociate does not.
292 }
293
294 AtomicNumber bondedId = PeriodicTable::Instance().GetIdFromType< T >();
296 toDisassociate,
297 bondedId,
298 type
299 );
300 #endif
301 }
302
303
309 Valence GetBondPosition(AtomicNumber bondedId) const;
310
317 Valence GetBondPosition(Name typeName) const;
318
319
325 template < typename T >
327 {
328 #if BIO_CPP_VERSION < 11
329 return GetBondPosition(PeriodicTable::Instance().GetIdFromType< physical::Quantum< T >* >());
330 #else
331 if (IsPrimitive< T >())
332 {
333 return GetBondPosition(PeriodicTable::Instance().GetIdFromType< physical::Quantum< T >* >());
334 }
335 return GetBondPosition(PeriodicTable::Instance().GetIdFromType< T >());
336 #endif
337 }
338
344 BondType GetBondType(Valence position) const;
345
351 template < typename T >
352 BondType GetBondType() const
353 {
354 #if BIO_CPP_VERSION < 11
356 #else
357 if (IsPrimitive< T >())
358 {
360 }
361 return GetBondType(GetBondPosition< T >());
362 #endif
363 }
364
370
375 const Bonds* GetAllBonds() const;
376
377protected:
379
386 virtual bool FormBondImplementation(
387 Wave* toBond,
388 AtomicNumber id,
389 BondType type
390 );
391
399 virtual bool BreakBondImplementation(
400 Wave* toDisassociate,
401 AtomicNumber id,
402 BondType type
403 );
404};
405
406} //chemical namespace
407} //bio namespace
#define BIO_SANITIZE(test, success, failure)
const T As() const
Definition: Atom.h:199
bool FormBond(T toBond, BondType type=bond_type::Unknown())
Definition: Atom.h:237
virtual physical::Symmetry * Spin() const
Definition: Atom.cpp:198
virtual Code Disattenuate(const Wave *other)
Definition: Atom.cpp:83
Wave * GetBonded(Valence position)
Definition: Atom.cpp:210
virtual bool BreakBondImplementation(Wave *toDisassociate, AtomicNumber id, BondType type)
Definition: Atom.cpp:148
bool BreakBond(T toDisassociate, BondType type=bond_type::Unknown())
Definition: Atom.h:279
Atom(const Atom &other)
Definition: Atom.cpp:29
const T AsBondedQuantum() const
Definition: Atom.h:165
Bonds * GetAllBonds()
Definition: Atom.cpp:224
virtual bool FormBondImplementation(Wave *toBond, AtomicNumber id, BondType type)
Definition: Atom.cpp:117
const T AsBonded() const
Definition: Atom.h:139
virtual ~Atom()
Definition: Atom.cpp:44
virtual Code Reify(physical::Symmetry *symmetry)
Definition: Atom.cpp:204
T AsBondedQuantum()
Definition: Atom.h:154
BIO_DISAMBIGUATE_ALL_CLASS_METHODS(physical, Atom) explicit Atom()
BondType GetBondType() const
Definition: Atom.h:352
virtual Code Attenuate(const Wave *other)
Definition: Atom.cpp:49
Valence GetBondPosition() const
Definition: Atom.h:326
virtual TYPE OptimizedAccess(Index index)
Definition: Arrangement.h:128
virtual Wave * AsWave()
Definition: Class.h:99
Wave(Symmetry *symmetry=NULL)
Definition: Wave.cpp:32
BondType Unknown()
Index Valence
Definition: Types.h:65
uint16_t AtomicNumber
Definition: Types.h:72
Definition: Cell.h:31
const char * Name
Definition: Types.h:46