00001
00002
00003
00004 #include "atomsElement.h"
00005
00006 #include <algorithm>
00007 #include <iostream>
00008 #include <iomanip>
00009 #include <sstream>
00010 #include <stdlib.h>
00011
00012
00013
00014
00015 atomElement::atomElement() : _num(-1),_name(""),_fragName("DefaultGroup")
00016 {
00017 _xyz[0] = _xyz[1] = _xyz[2] = 0.0 ;
00018 }
00019 atomElement::~atomElement()
00020 {}
00021 bool atomElement::read(std::stringstream & sline)
00022 {
00023
00024 sline >> _name ;
00025 sline >> _xyz[0] >> _xyz[1] >> _xyz[2] ;
00026
00027
00028
00029 sline >> _num ;
00030
00031 sline >> _fragName;
00032
00033 #if defined (__READ__VERBOSE__)
00034 std::cout <<" "<<_name <<" "<< _xyz[0] <<" "<< _xyz[1] <<" "<< _xyz[2]
00035 <<" "<<_num <<" "<< _fragName << " ";
00036 #endif
00037 if( _num ==-1)
00038 { return false ;}
00039 int nb = 0 ;
00040 sline >> nb ;
00041 if( nb == 0 )
00042 { _connect.resize(nb) ;return false ;}
00043 _connect.resize(nb) ;
00044 for(int i = 0 ; i < nb ; ++i){
00045 sline >> _connect[i] ;
00046 }
00047 #if defined (__READ__VERBOSE__)
00048 std::cout << _connect.size() ;
00049 for(int i = 0 ; i < nb ; ++i){
00050 std::cout << " " << _connect[i] ;
00051 }
00052 std::cout << std::endl;
00053 #endif
00054 return true ;
00055 }
00056 void atomElement::copy(const atomElement & at)
00057 {
00058 _xyz[0] = at._xyz[0] ;
00059 _xyz[1] = at._xyz[1] ;
00060 _xyz[2] = at._xyz[2] ;
00061 _num = at._num ;
00062 _name.assign(at._name) ;
00063 _fragName.assign(at._fragName) ;
00064 _connect.resize(at._connect.size()) ;
00065 for ( int i = 0 ; i < static_cast<int>(_connect.size()); ++i){
00066 _connect[i] = at._connect[i] ;
00067 }
00068 }
00069
00070 void atomElement::set(const int num, const double *xyz, const std::string &name, std::string &fragName ){
00071
00072 _xyz[0] = xyz[0] ;
00073 _xyz[1] = xyz[1] ;
00074 _xyz[2] = xyz[2] ;
00075 _num = num ;
00076 _name.assign(name) ;
00077 _fragName.assign(fragName) ;
00078 }
00079 int atomElement::getFragmentNumber(){
00080 std::string blanc(" ");
00081
00082 std::string frag = _fragName ;
00083 int pos = frag.find_last_of("-") + 1;
00084 for(int i = 0 ; i < pos ; ++i){
00085 frag[i] = blanc[0] ;
00086 }
00087 std::stringstream s ; s << frag ;
00088 int number ; s >> number ;
00089 return number ;
00090 }
00091
00092
00093
00094
00095
00096
00097 DCatomElement::DCatomElement() : atomElement(),_myNum(-1),_markName("NONE")
00098 {}
00099 DCatomElement::~DCatomElement()
00100 {}
00101 bool DCatomElement::read(std::stringstream & sline, const std::string & mark)
00102 {
00103 #if defined (__READ__VERBOSE__)
00104 std::cout << "BEG :"<<sline.str() <<std::endl;
00105 #endif
00106 bool oK = atomElement::read(sline);
00107 int posMark = sline.str().find(mark) ;
00108 #if defined (__READ__VERBOSE__)
00109 std::cout << "END :"<<sline.str() <<std::endl;
00110 #endif
00111 if( posMark > 0 ) {
00112 _markName = mark;
00113 #if defined (__READ__VERBOSE__)
00114 std::cout << "DCatomsElement::read markName : "<< _markName <<std::endl;
00115 #endif
00116 }
00117 #if defined (__READ__VERBOSE__)
00118 std::cout <<std::endl;
00119 #endif
00120
00121
00122 return oK ;
00123
00124 }
00125 void DCatomElement::copy(const DCatomElement & at)
00126 {
00127 this->atomElement::copy(static_cast<atomElement>(at)) ;
00128 _markName = at.markName() ;
00129 _myNum = at.numberOfMySubdomain();
00130
00131 }