Debian Codegraph @

avogadro/core/coordinateblockgenerator.h

raw
1 /******************************************************************************
2 This source file is part of the Avogadro project.
3 This source code is released under the 3-Clause BSD License, (see "LICENSE").
4 ******************************************************************************/
5
6 #ifndef AVOGADRO_CORE_COORDINATEBLOCKGENERATOR_H
7 #define AVOGADRO_CORE_COORDINATEBLOCKGENERATOR_H
8
9 #include "avogadrocoreexport.h"
10
11 #include <sstream>
12 #include <string>
13
14 namespace Avogadro::Core {
15 class Molecule;
16
17 /**
18 * @class CoordinateBlockGenerator coordinateblockgenerator.h
19 * <avogadro/core/coordinateblockgenerator.h>
20 * @brief The CoordinateBlockGenerator class creates an aligned, formatted block
21 * of atomic coordinates.
22 *
23 * See the setSpecification() documentation for details on specifying the block
24 * format.
25 */
26 class AVOGADROCORE_EXPORT CoordinateBlockGenerator
27 {
28 public:
29 /**
30 * Construct the default CoordinateBlockGenerator with an empty specification
31 * and Angstrom distance units.
32 */
33 CoordinateBlockGenerator() = default;
34
35 /**
36 * The molecule used as input.
37 * @}
38 */
39 void setMolecule(const Molecule* mol) { m_molecule = mol; }
40 const Molecule* molecule() const { return m_molecule; }
41 /** @} */
42
43 /**
44 * The specification of the block format.
45 * The characters in the specification string indicate the information needed
46 * about each atom in the coordinate block.
47 * - @c #: Atom index (one-based index)
48 * - @c Z: Atomic number (e.g. "6" for carbon)
49 * - @c L: Atomic label (e.g., "C1" for first carbon)")
50 * - @c G: GAMESS-styled Atomic number (e.g. "6.0" for carbon)
51 * - @c S: Element symbol (e.g. "C" for carbon)
52 * - @c N: Element name (e.g. "Carbon")
53 * - @c x: X cartesian coordinate
54 * - @c y: Y cartesian coordinate
55 * - @c z: Z cartesian coordinate
56 * - @c a: 'a' lattice coordinate (unit cell required)
57 * - @c b: 'b' lattice coordinate (unit cell required)
58 * - @c c: 'c' lattice coordinate (unit cell required)
59 * - @c 0: A literal "0". Useful for optimization flags.
60 * - @c 1: A literal "1". Useful for optimization flags.
61 * - @c _: A space character. Useful for alignment.
62 *
63 * For example, the specification string
64 ~~~
65 __SZxyz110
66 ~~~
67 * will be replaced by a molecule-specific block of text similar to the
68 * following:
69 ~~~
70 C 6 1.126214 0.765886 0.000000 1 1 0
71 C 6 0.819345 -0.564955 0.000000 1 1 0
72 C 6 -0.598383 -0.795127 0.000000 1 1 0
73 C 6 -1.310706 0.370165 0.000000 1 1 0
74 S 16 -0.285330 1.757144 0.000000 1 1 0
75 H 1 2.130424 1.185837 0.000000 1 1 0
76 H 1 1.548377 -1.375303 0.000000 1 1 0
77 H 1 -1.033768 -1.794407 0.000000 1 1 0
78 H 1 -2.396173 0.450760 0.000000 1 1 0
79 ~~~
80 */
81 void setSpecification(const std::string& spec) { m_specification = spec; }
82 std::string specification() const { return m_specification; }
83 /** @} */
84
85 /** Distance unit used in the output. @{ */
86 enum DistanceUnit
87 {
88 Angstrom = 0,
89 Bohr
90 };
91 void setDistanceUnit(DistanceUnit unit) { m_distanceUnit = unit; }
92 DistanceUnit distanceUnit() const { return m_distanceUnit; }
93 /** @} */
94
95 /**
96 * Generate and return the coordinate block.
97 */
98 std::string generateCoordinateBlock();
99
100 private:
101 const Molecule* m_molecule = nullptr;
102 std::string m_specification;
103 DistanceUnit m_distanceUnit = Angstrom;
104 std::stringstream m_stream;
105 };
106
107 } // namespace Avogadro::Core
108
109 #endif // AVOGADRO_CORE_COORDINATEBLOCKGENERATOR_H