diff --git a/source/module_cell/read_atoms.cpp b/source/module_cell/read_atoms.cpp index dc517bccd7..4c6bf9c0eb 100644 --- a/source/module_cell/read_atoms.cpp +++ b/source/module_cell/read_atoms.cpp @@ -535,100 +535,101 @@ bool UnitCell::read_atom_positions(std::ifstream &ifpos, std::ofstream &ofs_runn ModuleBase::GlobalFunc::ZEROS(atoms[it].mag,na); for (int ia = 0;ia < na; ia++) { - // modify the reading of frozen ions and velocities -- Yuanbo Li 2021/8/20 - ifpos >> v.x >> v.y >> v.z; - mv.x = true ; - mv.y = true ; - mv.z = true ; - atoms[it].vel[ia].set(0,0,0); - atoms[it].mag[ia]=magnet.start_magnetization[it];//if this line is used, default startmag_type would be 2 - atoms[it].angle1[ia]=0; - atoms[it].angle2[ia]=0; - atoms[it].m_loc_[ia].set(0,0,0); - - std::string tmpid; - tmpid = ifpos.get(); - - if( (int)tmpid[0] < 0 ) - { - std::cout << "read_atom_positions, mismatch in atom number for atom type: " << atoms[it].label << std::endl; - exit(1); - } - - bool input_vec_mag=false; - bool input_angle_mag=false; - while ( (tmpid != "\n") && (ifpos.eof()==false) && (tmpid !="#") ) - { - tmpid = ifpos.get() ; - // old method of reading frozen ions - char tmp = (char)tmpid[0]; - if ( tmp >= 48 && tmp <= 57 ) - { - mv.x = std::stoi(tmpid); - ifpos >> mv.y >> mv.z ; - } - // new method of reading frozen ions and velocities - if ( tmp >= 'a' && tmp <='z') - { - ifpos.putback(tmp); - ifpos >> tmpid; - } - if ( tmpid == "m" ) - { - ifpos >> mv.x >> mv.y >> mv.z ; - } - else if ( tmpid == "v" ||tmpid == "vel" || tmpid == "velocity" ) - { - ifpos >> atoms[it].vel[ia].x >> atoms[it].vel[ia].y >> atoms[it].vel[ia].z; - } - else if ( tmpid == "mag" || tmpid == "magmom") - { - set_element_mag_zero = true; - double tmpamg=0; - ifpos >> tmpamg; - tmp=ifpos.get(); - while (tmp==' ') - { - tmp=ifpos.get(); - } - - if((tmp >= 48 && tmp <= 57) or tmp=='-') - { - ifpos.putback(tmp); - ifpos >> atoms[it].m_loc_[ia].y>>atoms[it].m_loc_[ia].z; - atoms[it].m_loc_[ia].x=tmpamg; - atoms[it].mag[ia]=sqrt(pow(atoms[it].m_loc_[ia].x,2)+pow(atoms[it].m_loc_[ia].y,2)+pow(atoms[it].m_loc_[ia].z,2)); - input_vec_mag=true; - - } - else - { - ifpos.putback(tmp); - atoms[it].mag[ia]=tmpamg; - } - - // atoms[it].mag[ia]; - } - else if ( tmpid == "angle1") - { - ifpos >> atoms[it].angle1[ia]; - atoms[it].angle1[ia]=atoms[it].angle1[ia]/180 *ModuleBase::PI; - input_angle_mag=true; - set_element_mag_zero = true; - } - else if ( tmpid == "angle2") - { - ifpos >> atoms[it].angle2[ia]; - atoms[it].angle2[ia]=atoms[it].angle2[ia]/180 *ModuleBase::PI; - input_angle_mag=true; - set_element_mag_zero = true; - } - - } - while ( (tmpid != "\n") && (ifpos.eof()==false) ) - { - tmpid = ifpos.get(); - } + // modify the reading of frozen ions and velocities -- Yuanbo Li 2021/8/20 + ifpos >> v.x >> v.y >> v.z; + mv.x = true ; + mv.y = true ; + mv.z = true ; + atoms[it].vel[ia].set(0,0,0); + atoms[it].mag[ia]=magnet.start_magnetization[it];//if this line is used, default startmag_type would be 2 + atoms[it].angle1[ia]=0; + atoms[it].angle2[ia]=0; + atoms[it].m_loc_[ia].set(0,0,0); + + std::string tmpid; + tmpid = ifpos.get(); + + if( (int)tmpid[0] < 0 ) + { + std::cout << "read_atom_positions, mismatch in atom number for atom type: " << atoms[it].label << std::endl; + exit(1); + } + + bool input_vec_mag=false; + bool input_angle_mag=false; + // read if catch goodbit before "\n" and "#" + while ( (tmpid != "\n") && (ifpos.good()) && (tmpid !="#") ) + { + tmpid = ifpos.get() ; + // old method of reading frozen ions + char tmp = (char)tmpid[0]; + if ( tmp >= 48 && tmp <= 57 ) + { + mv.x = std::stoi(tmpid); + ifpos >> mv.y >> mv.z ; + } + // new method of reading frozen ions and velocities + if ( tmp >= 'a' && tmp <='z') + { + ifpos.putback(tmp); + ifpos >> tmpid; + } + if ( tmpid == "m" ) + { + ifpos >> mv.x >> mv.y >> mv.z ; + } + else if ( tmpid == "v" ||tmpid == "vel" || tmpid == "velocity" ) + { + ifpos >> atoms[it].vel[ia].x >> atoms[it].vel[ia].y >> atoms[it].vel[ia].z; + } + else if ( tmpid == "mag" || tmpid == "magmom") + { + set_element_mag_zero = true; + double tmpamg=0; + ifpos >> tmpamg; + tmp=ifpos.get(); + while (tmp==' ') + { + tmp=ifpos.get(); + } + + if((tmp >= 48 && tmp <= 57) or tmp=='-') + { + ifpos.putback(tmp); + ifpos >> atoms[it].m_loc_[ia].y>>atoms[it].m_loc_[ia].z; + atoms[it].m_loc_[ia].x=tmpamg; + atoms[it].mag[ia]=sqrt(pow(atoms[it].m_loc_[ia].x,2)+pow(atoms[it].m_loc_[ia].y,2)+pow(atoms[it].m_loc_[ia].z,2)); + input_vec_mag=true; + + } + else + { + ifpos.putback(tmp); + atoms[it].mag[ia]=tmpamg; + } + + // atoms[it].mag[ia]; + } + else if ( tmpid == "angle1") + { + ifpos >> atoms[it].angle1[ia]; + atoms[it].angle1[ia]=atoms[it].angle1[ia]/180 *ModuleBase::PI; + input_angle_mag=true; + set_element_mag_zero = true; + } + else if ( tmpid == "angle2") + { + ifpos >> atoms[it].angle2[ia]; + atoms[it].angle2[ia]=atoms[it].angle2[ia]/180 *ModuleBase::PI; + input_angle_mag=true; + set_element_mag_zero = true; + } + } + // move to next line + while ( (tmpid != "\n") && (ifpos.good()) ) + { + tmpid = ifpos.get(); + } std::string mags; //cout<<"mag"<