3 #include "LatticeParser.h"
5 LatticeParser::LatticeParser(const char *ini_file
)
6 : _ini(false, true, false)
8 SI_Error rc
= _ini
.LoadFile(ini_file
);
10 throw runtime_error("Failed loading structure ini file: " +
11 CSimpleIni::str_SI_Error(rc
));
14 const CSimpleIni::TKeyVal
*section
= _ini
.GetSection("UnitCell");
16 throw runtime_error("Ini file is missing 'UnitCell' section.");
18 #define ASSIGN_KEY(key_name, key_member) \
20 const char *tmp = _ini.GetValue("UnitCell", key_name); \
22 throw runtime_error("UnitCell definition is missing " \
24 _lattice.key_member = atoi(tmp); \
27 ASSIGN_KEY("SizeX", UnitCellSizeX
);
28 ASSIGN_KEY("SizeY", UnitCellSizeY
);
29 ASSIGN_KEY("Longitude", Longitude
);
30 ASSIGN_KEY("Latitude", Latitude
);
33 if (_lattice
.UnitCellSizeX
< 1 || _lattice
.UnitCellSizeY
< 1 ||
34 _lattice
.Longitude
< 1 || _lattice
.Latitude
< 1)
35 throw runtime_error("Unit cell has unreasonable size.");
37 _lattice
.adsorbates
.resize(_lattice
.Longitude
* _lattice
.UnitCellSizeX
+ 1,
38 _lattice
.Latitude
* _lattice
.UnitCellSizeY
+ 1);
39 _lattice
.surface
.resize(_lattice
.adsorbates
.shape());
40 _lattice
.surface
= empty
;
42 section
= _ini
.GetSection("Surface");
44 throw runtime_error("Ini file is missing 'Surface' section. ");
46 CSimpleIni::TNamesDepend Pd_positions
;
47 _ini
.GetAllValues("Surface", "Pd", Pd_positions
);
48 for (CSimpleIni::TNamesDepend::const_iterator i
= Pd_positions
.begin();
49 i
!= Pd_positions
.end(); ++i
) {
50 double x_frac
, y_frac
;
51 if (sscanf(i
->pItem
, "%lf/%lf", &x_frac
, &y_frac
) != 2 ||
52 x_frac
< 0 || x_frac
>= 1 ||
53 y_frac
< 0 || y_frac
>= 1)
54 throw runtime_error("Skrewed coordinates in " +
56 _lattice
.surface((int)(_lattice
.UnitCellSizeX
* x_frac
* _lattice
.Longitude
),
57 (int)(_lattice
.UnitCellSizeY
* y_frac
* _lattice
.Latitude
)) = Pd
;
61 section
= _ini
.GetSection("Adsorbates");
63 throw runtime_error("Ini file is missing 'Adsorbates' section. ");
65 CSimpleIni::TNamesDepend CO_positions
;
66 _ini
.GetAllValues("Adsorbates", "CO", CO_positions
);
67 for (CSimpleIni::TNamesDepend::const_iterator i
= CO_positions
.begin();
68 i
!= CO_positions
.end(); ++i
) {
69 double x_frac
, y_frac
;
70 if (sscanf(i
->pItem
, "%lf/%lf", &x_frac
, &y_frac
) != 2 ||
71 x_frac
< 0 || x_frac
>= 1 ||
72 y_frac
< 0 || y_frac
>= 1)
73 throw runtime_error("Skrewed coordinates in " +
75 _lattice
.adsorbates((int)(_lattice
.UnitCellSizeX
* x_frac
* _lattice
.Longitude
),
76 (int)(_lattice
.UnitCellSizeY
* y_frac
* _lattice
.Latitude
)) = CO
;
80 // Parse Symmetry options
81 CSimpleIni::TNamesDepend Symmetry_Operations
;
82 _ini
.GetAllValues("Symmetry", "Sym_Operation", Symmetry_Operations
);
83 for (CSimpleIni::TNamesDepend::const_iterator i
= Symmetry_Operations
.begin();
84 i
!= Symmetry_Operations
.end(); ++i
) {
85 double x_frac
, y_frac
;
86 if (sscanf(i
->pItem
, "%lf/%lf", &x_frac
, &y_frac
) != 2)
87 throw runtime_error("Skrewed coordinates in " +
89 _lattice
._symmetryOperations
.directions
.push_back(Direction(x_frac
, y_frac
));
92 // _lattice.extendUnitCell();
95 Lattice
LatticeParser::getLattice()