3 #include "LatticeParser.h"
5 LatticeParser::LatticeParser(const char *ini_file
) :
6 _ini(false, true, false) {
7 SI_Error rc
= _ini
.LoadFile(ini_file
);
9 throw runtime_error("Failed loading structure ini file: "
10 + CSimpleIni::str_SI_Error(rc
));
13 const CSimpleIni::TKeyVal
*section
= _ini
.GetSection("UnitCell");
15 throw runtime_error("Ini file is missing 'UnitCell' section.");
18 #define ASSIGN_KEY(key_name, name) \
19 tmp = _ini.GetValue("UnitCell", key_name); \
21 throw runtime_error("UnitCell definition is missing " \
23 int name = atoi(tmp); \
25 ASSIGN_KEY("UnitCellSizeX", UnitCellSizeX);
26 ASSIGN_KEY("UnitCellSizeY", UnitCellSizeY
);
27 ASSIGN_KEY("GranularityX", GranularityX
);
28 ASSIGN_KEY("GranularityY", GranularityY
);
31 if (UnitCellSizeX
< 1 || UnitCellSizeY
< 1 || GranularityX
< 1
33 throw runtime_error("Unit cell has unreasonable size.");
35 // increasing Granularity to get proper structure representation
36 // GranularityX = GranularityX + 1;
37 // GranularityY = GranularityY + 1;
40 = new Lattice(UnitCellSizeX
, UnitCellSizeY
, GranularityX
, GranularityY
);
41 _lattice
->surface
= empty
;
42 _lattice
->adsorbates
= empty
;
44 section
= _ini
.GetSection("Surface");
46 throw runtime_error("Ini file is missing 'Surface' section. ");
48 CSimpleIni::TNamesDepend Pd_positions
;
49 _ini
.GetAllValues("Surface", "Pd", Pd_positions
);
50 for (CSimpleIni::TNamesDepend::const_iterator i
= Pd_positions
.begin(); i
51 != Pd_positions
.end(); ++i
) {
52 double x_frac
, y_frac
;
53 if (sscanf(i
->pItem
, "%lf/%lf", &x_frac
, &y_frac
) != 2 || x_frac
< 0
54 || x_frac
>= 1 || y_frac
< 0 || y_frac
>= 1)
55 throw runtime_error("Skrewed coordinates in " + string(i
->pItem
));
57 inter_x
= _lattice
->UnitCellSizeX
* _lattice
->GranularityX
;
58 inter_y
= _lattice
->UnitCellSizeY
* _lattice
->GranularityY
;
59 double double_x
, double_y
;
60 double_x
= inter_x
* x_frac
;
61 double_y
= inter_y
* y_frac
;
63 pos_x
= round(double_x
);
64 pos_y
= round(double_y
);
65 cout
<< "filling (" << pos_x
<< "/" << pos_y
<< ") with Pd" << endl
;
66 _lattice
->surface(pos_x
, pos_y
) = Pd
;
70 section
= _ini
.GetSection("Adsorbates");
72 throw runtime_error("Ini file is missing 'Adsorbates' section. ");
74 CSimpleIni::TNamesDepend CO_positions
;
75 _ini
.GetAllValues("Adsorbates", "CO", CO_positions
);
76 _lattice
->nrCO
= CO_positions
.size();
77 for (CSimpleIni::TNamesDepend::const_iterator i
= CO_positions
.begin(); i
78 != CO_positions
.end(); ++i
) {
79 double x_frac
, y_frac
;
80 if (sscanf(i
->pItem
, "%lf/%lf", &x_frac
, &y_frac
) != 2 || x_frac
< 0
81 || x_frac
>= 1 || y_frac
< 0 || y_frac
>= 1)
82 throw runtime_error("Skrewed coordinates in " + string(i
->pItem
));
84 inter_x
= _lattice
->UnitCellSizeX
* _lattice
->GranularityX
;
85 inter_y
= _lattice
->UnitCellSizeY
* _lattice
->GranularityY
;
86 double double_x
, double_y
;
87 double_x
= inter_x
* x_frac
;
88 double_y
= inter_y
* y_frac
;
90 pos_x
= round(double_x
);
91 pos_y
= round(double_y
);
92 cout
<< "filling (" << pos_x
<< "/" << pos_y
<< ") with CO" << endl
;
93 _lattice
->adsorbates(pos_x
, pos_y
) = CO
;
96 // Parse Symmetry options
98 CSimpleIni::TNamesDepend Symmetry_Operations;
99 _ini.GetAllValues("Symmetry", "Sym_Operation", Symmetry_Operations);
100 for (CSimpleIni::TNamesDepend::const_iterator i =
101 Symmetry_Operations.begin(); i != Symmetry_Operations.end(); ++i) {
102 double x_frac, y_frac;
103 if (sscanf(i->pItem, "%lf/%lf", &x_frac, &y_frac) != 2)
104 throw runtime_error("Skrewed coordinates in " + string(i->pItem));
105 _lattice->_symmetryOperations.directions.push_back(Direction(x_frac,
111 Lattice
*LatticeParser::getLattice() {