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