1 /*
2 !> @file
3 !!  Routines to read YAML position files.
4 !! @author
5 !!    Copyright (C) 2007-2012 BigDFT group
6 !!    This file is distributed under the terms of the
7 !!    GNU General Public License, see ~/COPYING file
8 !!    or http://www.gnu.org/copyleft/gpl.txt .
9 !!    For the list of contributors, see ~/AUTHORS
10 */
11 
12 #ifndef ATOMS_YAML_H
13 #define ATOMS_YAML_H
14 
15 typedef enum
16   {
17     POSINP_BC_FREE,       /* 0, 0, 0 */
18     POSINP_BC_WIRE_Z,     /* 0, 0, 1 */
19     POSINP_BC_WIRE_Y,     /* 0, 1, 0 */
20     POSINP_BC_SURFACE_YZ, /* 0, 1, 1 */
21     POSINP_BC_WIRE_X,     /* 1, 0, 0 */
22     POSINP_BC_SURFACE_XZ, /* 1, 0, 1 */
23     POSINP_BC_SURFACE_XY, /* 1, 1, 0 */
24     POSINP_BC_PERIODIC,   /* 1, 1, 1 */
25     POSINP_N_BC
26   } PosinpBC;
27 
28 typedef enum
29   {
30     POSINP_CELL_UNITS_BOHR,
31     POSINP_CELL_UNITS_ANGSTROEM,
32     POSINP_CELL_N_UNITS
33   } PosinpCellUnits;
34 typedef enum
35   {
36     POSINP_COORD_UNITS_BOHR,
37     POSINP_COORD_UNITS_ANGSTROEM,
38     POSINP_COORD_UNITS_REDUCED,
39     POSINP_COORD_N_UNITS
40   } PosinpCoordUnits;
41 typedef enum
42   {
43     POSINP_FORCE_UNITS_HARTREE_PER_BOHR,
44     POSINP_FORCE_UNITS_EV_PER_ANGSTROEM,
45     POSINP_FORCE_N_UNITS
46   } PosinpForceUnits;
47 typedef enum
48   {
49     POSINP_ENERG_UNITS_HARTREE,
50     POSINP_ENERG_UNITS_EV,
51     POSINP_ENERG_UNITS_RYDBERG,
52     POSINP_ENERG_N_UNITS
53   } PosinpEnergUnits;
54 typedef enum
55   {
56     POSINP_FROZEN_FREE,
57     POSINP_FROZEN_FULL,
58     POSINP_FROZEN_Y,
59     POSINP_FROZEN_XZ,
60     POSINP_N_FROZEN
61   } PosinpFrozenType;
62 typedef enum
63   {
64     POSINP_TYPE_INT,
65     POSINP_TYPE_DBL,
66     POSINP_TYPE_INT_ARR,
67     POSINP_TYPE_DBL_ARR,
68     POSINP_TYPE_STR,
69     POSINP_TYPE_DICT
70   } PosinpTypeId;
71 typedef struct _PosinpDictEntry PosinpDictEntry;
72 typedef struct _PosinpDict PosinpDict;
73 
74 struct _PosinpDict
75 {
76   unsigned int len;
77   PosinpDictEntry *items;
78 };
79 struct _PosinpDictEntry
80 {
81   char *key;
82   PosinpTypeId type;
83   union
84   {
85     int ival;
86     struct
87     {
88       unsigned int len;
89       int *arr;
90     } iarr;
91     double dval;
92     struct
93     {
94       unsigned int len;
95       double *arr;
96     } darr;
97     char *str;
98     PosinpDict dict;
99   } value;
100 };
101 
102 #define POSINP_SIGMA_SIZE 3
103 typedef double PosinpSigma[POSINP_SIGMA_SIZE];
104 typedef struct _PosinpPole
105 {
106   double q0;
107   double q1[3];
108   double q2[5];
109 } PosinpPole;
110 typedef struct _PosinpAtoms
111 {
112   /* The cell. */
113   PosinpBC BC;
114   PosinpCellUnits Units;
115   double acell[3], angdeg[3];
116 
117   /* The positions. */
118   unsigned int nat, ntypes;
119   PosinpCoordUnits units;
120   double *rxyz;
121   char **atomnames;
122 
123   /* Per atoms data. */
124   unsigned int *iatype, *ifrztyp;
125   int *igspin, *igchg;
126   PosinpDict *props;
127 
128   /* The forces. */
129   PosinpForceUnits funits;
130   double fnrm, maxval;
131   double *fxyz;
132 
133   /* External potential. */
134   PosinpCoordUnits punits;
135   unsigned int npots;
136   char **potnames;
137   double *pxyz;
138   PosinpSigma *psigma;
139   PosinpPole *ppoles;
140 
141   /* Additional data. */
142   char *comment;
143   PosinpEnergUnits eunits;
144   double energy;
145   unsigned int converged;
146   double gnrm_wfn;
147 } PosinpAtoms;
148 
149 typedef struct _PosinpList PosinpList;
150 struct _PosinpList
151 {
152   PosinpList *next;
153   PosinpAtoms *data;
154 };
155 
156 void posinp_yaml_parse(PosinpList **out, const char *filename, char **message);
157 void posinp_yaml_free_list(PosinpList *lst);
158 
159 PosinpDict* posinp_yaml_parse_properties(const char *buffer, char **message);
160 void posinp_yaml_free_properties(PosinpDict *dict);
161 
162 #endif
163