forked from abacusmodeling/abacus-develop
-
Notifications
You must be signed in to change notification settings - Fork 222
Expand file tree
/
Copy pathread_atoms.cpp
More file actions
121 lines (102 loc) · 4.46 KB
/
read_atoms.cpp
File metadata and controls
121 lines (102 loc) · 4.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include <cstring> // Peize Lin fix bug about strcmp 2016-08-02
#include <cassert>
#include <regex>
#include <fstream>
#include "unitcell.h"
#include "read_atoms_helper.h"
#include "source_io/module_parameter/parameter.h"
#include "print_cell.h"
#include "read_stru.h"
#include "source_estate/read_orb.h"
#include "source_base/timer.h"
#include "source_base/constants.h"
#include "source_base/formatter.h"
#include "source_base/mathzone.h"
#ifdef __LCAO
#include "source_basis/module_ao/ORB_read.h" // to use 'ORB' -- mohan 2021-01-30
#endif
bool unitcell::read_atom_positions(UnitCell& ucell,
std::ifstream &ifpos,
std::ofstream &ofs_running,
std::ofstream &ofs_warning)
{
ModuleBase::TITLE("UnitCell","read_atom_positions");
std::string& Coordinate = ucell.Coordinate;
const int ntype = ucell.ntype;
const int nspin = PARAM.inp.nspin;
assert (nspin==1 || nspin==2 || nspin==4);
if( ModuleBase::GlobalFunc::SCAN_LINE_BEGIN(ifpos, "ATOMIC_POSITIONS"))
{
ModuleBase::GlobalFunc::READ_VALUE(ifpos, Coordinate);
if (!unitcell::validate_coordinate_system(Coordinate, ofs_warning))
{
return false;
}
ucell.nat = 0;
//======================================
// calculate total number of ucell.atoms
// and adjust the order of atom species
//======================================
for (int it = 0;it < ntype; it++)
{
ofs_running << "\n READING ATOM TYPE " << it+1 << std::endl;
bool set_element_mag_zero = false;
if (!unitcell::read_atom_type_header(it, ucell, ifpos, ofs_running,
ofs_warning, set_element_mag_zero))
{
return false;
}
int na = ucell.atoms[it].na;
ucell.nat += na;
if (na > 0)
{
unitcell::allocate_atom_properties(ucell.atoms[it], na, ucell.atom_mass[it]);
for (int ia = 0;ia < na; ia++)
{
// modify the reading of frozen ions and velocities -- Yuanbo Li 2021/8/20
ModuleBase::Vector3<double> v;
ModuleBase::Vector3<int> mv;
ifpos >> v.x >> v.y >> v.z;
mv.x = true ;
mv.y = true ;
mv.z = true ;
ucell.atoms[it].vel[ia].set(0,0,0);
ucell.atoms[it].mag[ia]=ucell.magnet.start_mag[it];
//if this line is used, default startmag_type would be 2
ucell.atoms[it].angle1[ia]=0;
ucell.atoms[it].angle2[ia]=0;
ucell.atoms[it].m_loc_[ia].set(0,0,0);
ucell.atoms[it].lambda[ia].set(0,0,0);
ucell.atoms[it].constrain[ia].set(0,0,0);
bool input_vec_mag=false;
bool input_angle_mag=false;
// Parse optional properties
if (!unitcell::parse_atom_properties(ifpos, ucell.atoms[it], ia, mv,
input_vec_mag, input_angle_mag,
set_element_mag_zero))
{
return false;
}
// Process magnetization
unitcell::process_magnetization(ucell.atoms[it], it, ia, nspin,
input_vec_mag, input_angle_mag, ofs_running);
// Transform coordinates
unitcell::transform_atom_coordinates(ucell.atoms[it], ia, Coordinate,
v, ucell.latvec, ucell.lat0, ucell.latcenter);
// Set movement flags
unitcell::set_atom_movement_flags(ucell.atoms[it], ia, mv);
ucell.atoms[it].dis[ia].set(0, 0, 0);
}//endj
} // end na
// reset some useless parameters
if (set_element_mag_zero)
{
ucell.magnet.start_mag[it] = 0.0;
}
} // end for ntype
// Auto-set magnetization if needed
unitcell::autoset_magnetization(ucell, nspin, ofs_running);
} // end scan_begin
// Final validation and output
return unitcell::finalize_atom_positions(ucell, ofs_running, ofs_warning);
}//end read_atom_positions