Esempio n. 1
0
///
/// @par Detailed description
/// ...
/// @param [in, out] (param1) ...
/// @return ...
/// @note ...
void
sasio::Files::
read_pdb(const std::string &filename)
{
    std::string line, word ;

    std::string element_string ;

    std::ifstream infile(filename) ;

    int count = 0 ;
    int frame = 0 ;

    //string s(line, index, number_characters) ;

    std::vector<float> vector_x;
    std::vector<float> vector_y;
    std::vector<float> vector_z;

    while(getline(infile,line))
    {
        std::istringstream record(line) ;
        record >> word ;

        std::string temp1(word,0,5) ;

        if(temp1 != "ATOM" && temp1 != "HETAT")
        {
            std::cout << "excluding: " << word << std::endl ;
        }
        else
        {
            std::string tmp(line,0,6) ;
            _atom_record().push_back(tmp) ;

            std::string tmp2(line,6,5) ;
            _atom_index().push_back(stoi(tmp2)) ;

            std::string tmp3(line,12,4) ;
            _atom_name().push_back(tmp3) ;

            std::string tmp4(line,16,1) ;
            _atom_altloc().push_back(tmp4) ;

            std::string tmp5(line,17,3) ;
            _atom_resname().push_back(tmp5) ;

            std::string tmp6(line,21,1) ;
            _atom_chain().push_back(tmp6) ;

            std::string tmp7(line,22,4) ;
            _atom_resid().push_back(stoi(tmp7)) ;

            std::string tmp8(line,26,1) ;
            _atom_icode().push_back(tmp8) ;

            std::string tmp9(line,30,8) ;
            vector_x.push_back(stof(tmp9)) ;

            std::string tmp10(line,38,8) ;
            vector_y.push_back(stof(tmp10)) ;

            std::string tmp11(line,46,8) ;
            vector_z.push_back(stof(tmp11)) ;

            try
            {
                std::string tmp12(line,54,6) ;
                if(util::has_only_spaces(tmp12))
                {
                    _atom_occupancy().push_back("0.00") ;
                }
                else
                {
                    _atom_occupancy().push_back(tmp12) ;
                }
            }
            catch(const std::out_of_range& oor)
            {
                _atom_occupancy().push_back("0.00") ;
                std::cerr<<"Occupancy: Out of range error: "<< oor.what() <<std::endl ;
            }

            try
            {
                std::string tmp13(line,60,6) ;
                if(util::has_only_spaces(tmp13))
                {
                    _atom_beta().push_back("0.00") ;
                }
                else
                {
                    _atom_beta().push_back(tmp13) ;
                }
            }
            catch(const std::out_of_range& oor)
            {
                _atom_beta().push_back("0.00") ;
                std::cerr<<"Beta: Out of range error: "<< oor.what() <<std::endl ;
            }

            try
            {
                std::string tmp14(line,72,4) ;
                if(util::has_only_spaces(tmp14))
                {
                    _atom_segname().push_back("SEGN") ;
                }
                else
                {
                    _atom_segname().push_back(tmp14) ;
                }
            }
            catch(const std::out_of_range& oor)
            {
                _atom_segname().push_back("SEGN") ;
                std::cerr<<"Segname: Out of range error: "<< oor.what() <<std::endl ;
            }

            try
            {
                std::string tmp15(line,76,2) ;
                if(util::has_only_spaces(tmp15))
                {
                    std::cout << "Element not found" << std::endl;
                    element_string = element_from_name(tmp3) ;
                    _atom_element().push_back(element_string) ;
                }
                else
                {
                    _atom_element().push_back(tmp15) ;
                }
            }
            catch(const std::out_of_range& oor)
            {
                element_string = element_from_name(tmp3) ;
                _atom_element().push_back(element_string) ;
                std::cerr<<"Element: Out of range error: "<< oor.what() <<std::endl ;
            }

            try
            {
                std::string tmp16(line,78,2) ;
                if(util::has_only_spaces(tmp16))
                {
                    _atom_charge().push_back(" ") ;
                }
                else
                {
                    _atom_charge().push_back(tmp16) ;
                }
            }
            catch(const std::out_of_range& oor)
            {
                _atom_charge().push_back(" ") ;
                std::cerr<<"Charge: Out of range error: "<< oor.what() <<std::endl ;
            }

            count++ ;
        }
    }

    _natoms() = count ;
    infile.close() ;

    int nf = _number_of_frames() ;

    if(_number_of_frames() == 0)
    {
        _x().setZero(_natoms(), 1);
        _y().setZero(_natoms(), 1);
        _z().setZero(_natoms(), 1);
    }
    else
    {
        resize_array() ;
    }

    for(int i = 0 ; i < _natoms() ; ++i)
    {
        _x()(i,_number_of_frames()) = vector_x[i] ;
        _y()(i,_number_of_frames()) = vector_y[i] ;
        _z()(i,_number_of_frames()) = vector_z[i] ;
    }

    std::vector<std::string> s_element ;
    s_element = util::strip_white_space(_atom_element()) ;
    _atom_selement() = s_element ;

    dynamic_cast<sasmol::SasMol*>(this)->calc_mass() ;
    _atom_com() = dynamic_cast<sasmol::SasMol*>(this)->calc_com(frame) ;

    _number_of_frames() += 1 ;

    _set_unique_attributes();

    /*
              1         2         3         4         5         6         7         8
    012345678901234567890123456789012345678901234567890123456789012345678901234567890
             1         2         3         4         5         6         7         8
    12345678901234567890123456789012345678901234567890123456789012345678901234567890
    0    6    1 2   7
    ATOM      1  N   GLY X   1     -21.525 -67.562  86.759  1.00  0.00      GAG  N
    ATOM      2  HT1 GLY X   1     -22.003 -68.460  86.892  1.00  0.00      GAG  H
    ATOM      3  HT2 GLY X   1     -21.905 -66.929  87.525  1.00  0.00      GAG  H

    */
}
Esempio n. 2
0
int runTests(Epetra_Map & map, Epetra_CrsMatrix & A, Epetra_Vector & x, Epetra_Vector & b, Epetra_Vector & xexact, bool verbose) {

  int ierr = 0;

  // Create MultiVectors and put x, b, xexact in both columns of X, B, and Xexact, respectively.
  Epetra_MultiVector X( map, 2, false );
  Epetra_MultiVector B( map, 2, false );
  Epetra_MultiVector Xexact( map, 2, false );

  for (int i=0; i<X.NumVectors(); ++i) {
    *X(i) = x;
    *B(i) = b;
    *Xexact(i) = xexact;
  }
  double residual;
  std::vector<double> residualmv(2);
  residual = A.NormInf(); double rAInf = residual;
  if (verbose) std::cout << "Inf Norm of A                                                     = " << residual << std::endl;
  residual = A.NormOne(); double rAOne = residual;
  if (verbose) std::cout << "One Norm of A                                                     = " << residual << std::endl;
  xexact.Norm2(&residual); double rxx = residual;	
  Xexact.Norm2(&residualmv[0]); std::vector<double> rXX( residualmv );	
  if (verbose) std::cout << "Norm of xexact                                                    = " << residual << std::endl;
  if (verbose) std::cout << "Norm of Xexact                                                    = (" << residualmv[0] << ", " <<residualmv[1] <<")"<< std::endl;
  Epetra_Vector tmp1(map);
  Epetra_MultiVector tmp1mv(map,2,false);
  A.Multiply(false, xexact, tmp1);
  A.Multiply(false, Xexact, tmp1mv);
  tmp1.Norm2(&residual); double rAx = residual;
  tmp1mv.Norm2(&residualmv[0]); std::vector<double> rAX( residualmv );
  if (verbose) std::cout << "Norm of Ax                                                        = " << residual << std::endl;
  if (verbose) std::cout << "Norm of AX                                                        = (" << residualmv[0] << ", " << residualmv[1] <<")"<< std::endl;
  b.Norm2(&residual); double rb = residual;
  B.Norm2(&residualmv[0]); std::vector<double> rB( residualmv );
  if (verbose) std::cout << "Norm of b (should equal norm of Ax)                               = " << residual << std::endl;
  if (verbose) std::cout << "Norm of B (should equal norm of AX)                               = (" << residualmv[0] << ", " << residualmv[1] <<")"<< std::endl;
  tmp1.Update(1.0, b, -1.0);
  tmp1mv.Update(1.0, B, -1.0);
  tmp1.Norm2(&residual);
  tmp1mv.Norm2(&residualmv[0]);
  if (verbose) std::cout << "Norm of difference between compute Ax and Ax from file            = " << residual << std::endl;
  if (verbose) std::cout << "Norm of difference between compute AX and AX from file            = (" << residualmv[0] << ", " << residualmv[1] <<")"<< std::endl;
  map.Comm().Barrier();

  EPETRA_CHK_ERR(EpetraExt::BlockMapToMatrixMarketFile("Test_map.mm", map, "Official EpetraExt test map", 
						       "This is the official EpetraExt test map generated by the EpetraExt regression tests"));

  EPETRA_CHK_ERR(EpetraExt::RowMatrixToMatrixMarketFile("Test_A.mm", A, "Official EpetraExt test matrix", 
							"This is the official EpetraExt test matrix generated by the EpetraExt regression tests"));

  EPETRA_CHK_ERR(EpetraExt::VectorToMatrixMarketFile("Test_x.mm", x, "Official EpetraExt test initial guess", 
						     "This is the official EpetraExt test initial guess generated by the EpetraExt regression tests"));

  EPETRA_CHK_ERR(EpetraExt::MultiVectorToMatrixMarketFile("Test_mvX.mm", X, "Official EpetraExt test initial guess", 
					      	          "This is the official EpetraExt test initial guess generated by the EpetraExt regression tests"));
				       
  EPETRA_CHK_ERR(EpetraExt::VectorToMatrixMarketFile("Test_xexact.mm", xexact, "Official EpetraExt test exact solution", 
						     "This is the official EpetraExt test exact solution generated by the EpetraExt regression tests"));

  EPETRA_CHK_ERR(EpetraExt::MultiVectorToMatrixMarketFile("Test_mvXexact.mm", Xexact, "Official EpetraExt test exact solution", 
						          "This is the official EpetraExt test exact solution generated by the EpetraExt regression tests"));
				       
  EPETRA_CHK_ERR(EpetraExt::VectorToMatrixMarketFile("Test_b.mm", b, "Official EpetraExt test right hand side", 
						     "This is the official EpetraExt test right hand side generated by the EpetraExt regression tests"));

  EPETRA_CHK_ERR(EpetraExt::MultiVectorToMatrixMarketFile("Test_mvB.mm", B, "Official EpetraExt test right hand side", 
						          "This is the official EpetraExt test right hand side generated by the EpetraExt regression tests"));
				       
  EPETRA_CHK_ERR(EpetraExt::MultiVectorToMatlabFile("Test_mvB.mat", B));
 
  EPETRA_CHK_ERR(EpetraExt::RowMatrixToMatlabFile("Test_A.dat", A));

  Epetra_Map * map1;
  Epetra_CrsMatrix * A1; 
  Epetra_CrsMatrix * A2; 
  Epetra_CrsMatrix * A3; 
  Epetra_Vector * x1; 
  Epetra_Vector * b1;
  Epetra_Vector * xexact1;
  Epetra_MultiVector * X1; 
  Epetra_MultiVector * B1;
  Epetra_MultiVector * Xexact1;

  EpetraExt::MatrixMarketFileToMap("Test_map.mm", map.Comm(), map1);

  if (map.SameAs(*map1)) {
    if (verbose) std::cout << "Maps are equal.  In/Out works." << std::endl;
  }
  else {
    if (verbose) std::cout << "Maps are not equal.  In/Out fails." << std::endl;
    ierr += 1;
  }
  EPETRA_CHK_ERR(EpetraExt::MatrixMarketFileToCrsMatrix("Test_A.mm", *map1, A1));
  // If map is zero-based, then we can compare to the convenient reading versions
  if (map1->IndexBase()==0) EPETRA_CHK_ERR(EpetraExt::MatrixMarketFileToCrsMatrix("Test_A.mm", map1->Comm(), A2));
  if (map1->IndexBase()==0) EPETRA_CHK_ERR(EpetraExt::MatlabFileToCrsMatrix("Test_A.dat", map1->Comm(), A3));
  EPETRA_CHK_ERR(EpetraExt::MatrixMarketFileToVector("Test_x.mm", *map1, x1));
  EPETRA_CHK_ERR(EpetraExt::MatrixMarketFileToVector("Test_xexact.mm", *map1, xexact1));
  EPETRA_CHK_ERR(EpetraExt::MatrixMarketFileToVector("Test_b.mm", *map1, b1));
  EPETRA_CHK_ERR(EpetraExt::MatrixMarketFileToMultiVector("Test_mvX.mm", *map1, X1));
  EPETRA_CHK_ERR(EpetraExt::MatrixMarketFileToMultiVector("Test_mvXexact.mm", *map1, Xexact1));
  EPETRA_CHK_ERR(EpetraExt::MatrixMarketFileToMultiVector("Test_mvB.mm", *map1, B1));

  residual = A1->NormInf(); double rA1Inf = residual;
  if (verbose) std::cout << "Inf Norm of A1                                                    = " << residual << std::endl;
  ierr += checkValues(rA1Inf,rAInf,"Inf Norm of A", verbose);

  residual = A1->NormOne(); double rA1One = residual;
  if (verbose) std::cout << "One Norm of A1                                                    = " << residual << std::endl;
  ierr += checkValues(rA1One,rAOne,"One Norm of A", verbose);

  xexact1->Norm2(&residual); double rxx1 = residual;
  if (verbose) std::cout << "Norm of xexact1                                                   = " << residual << std::endl;
  ierr += checkValues(rxx1,rxx,"Norm of xexact", verbose);

  Xexact1->Norm2(&residualmv[0]); std::vector<double> rXX1(residualmv);
  if (verbose) std::cout << "Norm of Xexact1                                                   = (" << residualmv[0] <<", " <<residualmv[1]<<")"<< std::endl;
  ierr += checkValues(rXX1[0],rXX[0],"Norm of Xexact", verbose);
  ierr += checkValues(rXX1[1],rXX[1],"Norm of Xexact", verbose);

  Epetra_Vector tmp11(*map1);
  A1->Multiply(false, *xexact1, tmp11);

  Epetra_MultiVector tmp11mv(*map1,2,false);
  A1->Multiply(false, *Xexact1, tmp11mv);

  tmp11.Norm2(&residual); double rAx1 = residual;
  if (verbose) std::cout << "Norm of A1*x1                                                     = " << residual << std::endl;
  ierr += checkValues(rAx1,rAx,"Norm of A1*x", verbose);

  tmp11mv.Norm2(&residualmv[0]); std::vector<double> rAX1(residualmv);
  if (verbose) std::cout << "Norm of A1*X1                                                     = (" << residualmv[0] <<", "<<residualmv[1]<<")"<< std::endl;
  ierr += checkValues(rAX1[0],rAX[0],"Norm of A1*X", verbose);
  ierr += checkValues(rAX1[1],rAX[1],"Norm of A1*X", verbose);

  if (map1->IndexBase()==0) {
    Epetra_Vector tmp12(*map1);
    A2->Multiply(false, *xexact1, tmp12);
    
    tmp12.Norm2(&residual); double rAx2 = residual;
    if (verbose) std::cout << "Norm of A2*x1                                                     = " << residual << std::endl;
    ierr += checkValues(rAx2,rAx,"Norm of A2*x", verbose);

    Epetra_Vector tmp13(*map1);
    A3->Multiply(false, *xexact1, tmp13);
    
    tmp13.Norm2(&residual); double rAx3 = residual;
    if (verbose) std::cout << "Norm of A3*x1                                                     = " << residual << std::endl;
    ierr += checkValues(rAx3,rAx,"Norm of A3*x", verbose);
  }
  b1->Norm2(&residual); double rb1 = residual;
  if (verbose) std::cout << "Norm of b1 (should equal norm of Ax)                              = " << residual << std::endl;
  ierr += checkValues(rb1,rb,"Norm of b", verbose);

  B1->Norm2(&residualmv[0]); std::vector<double> rB1(residualmv);
  if (verbose) std::cout << "Norm of B1 (should equal norm of AX)                              = (" << residualmv[0] <<", "<<residualmv[1]<<")"<< std::endl;
  ierr += checkValues(rB1[0],rB[0],"Norm of B", verbose);
  ierr += checkValues(rB1[1],rB[1],"Norm of B", verbose);

  tmp11.Update(1.0, *b1, -1.0);
  tmp11.Norm2(&residual);
  if (verbose) std::cout << "Norm of difference between computed A1x1 and A1x1 from file        = " << residual << std::endl;
  ierr += checkValues(residual,0.0,"Norm of difference between computed A1x1 and A1x1 from file", verbose);

  tmp11mv.Update(1.0, *B1, -1.0);
  tmp11mv.Norm2(&residualmv[0]);
  if (verbose) std::cout << "Norm of difference between computed A1X1 and A1X1 from file        = (" << residualmv[0] << ", "<<residualmv[1]<<")"<< std::endl;
  ierr += checkValues(residualmv[0],0.0,"Norm of difference between computed A1X1 and A1X1 from file", verbose);
  ierr += checkValues(residualmv[1],0.0,"Norm of difference between computed A1X1 and A1X1 from file", verbose);

  if (map1->IndexBase()==0) {delete A2; delete A3;}
  delete A1;
  delete x1;
  delete b1;
  delete xexact1;
  delete X1;
  delete B1;
  delete Xexact1;
  delete map1;

  return(ierr);
}
Esempio n. 3
0
void
sasio::Files::
write_pdb(const std::string &filename, int &frame)
{
    std::ofstream outfile(filename) ;

    std::string time_and_user_string ;
    time_and_user_string = util::time_and_user();
    std::string temp_remark = "REMARK PDB FILE WRITTEN ";
    temp_remark += time_and_user_string ;
    std::string remark(temp_remark,0,80) ;
    std::cout << remark << std::endl ;

    outfile << remark << std::endl;
    //std::string dum1 ="         1         2         3         4         5         6         7         8";
    //std::string dum2 ="12345678901234567890123456789012345678901234567890123456789012345678901234567890";
    //outfile << dum1 << std::endl;
    //outfile << dum2 << std::endl;

    std::stringstream line ;
    std::stringstream my_stringstream;

    for(int i = 0 ; i < _natoms() ; ++i)
    {
        line.str( std::string() );
        line.clear() ;
        std::string tmp(_atom_record()[i],0,6) ;
        line << std::setfill(' ') << std::setw(6) << tmp ;

        if(_atom_index()[i] > 99999)
        {
            std::string tmp2(std::to_string(99999),0,5) ;
            line << std::setfill(' ') << std::setw(5) << std::right << tmp2 ;
        }
        else if(_atom_index()[i] < -9999)
        {
            std::string tmp2(std::to_string(-9999),0,5) ;
            line << std::setfill(' ') << std::setw(5) << std::right << tmp2 ;
        }
        else
        {
            std::string tmp2(std::to_string(_atom_index()[i]),0,5) ;
            line << std::setfill(' ') << std::setw(5) << std::right << tmp2 ;
        }

        std::string tmp0 = " ";
        line << tmp0 ;

        std::string tmp3(_atom_name()[i],0,4) ;
        line << std::setfill(' ') << std::setw(4) << std::left << tmp3 ;

        std::string tmp4(_atom_altloc()[i],0,1) ;
        line << std::setw(1) << tmp4 ;

        std::string tmp5(_atom_resname()[i],0,3) ;
        line << std::setfill(' ') << std::setw(4) << std::left << tmp5 ;

        std::string tmp6(_atom_chain()[i],0,1) ;
        line << std::setfill(' ') << std::setw(1) << std::left << tmp6 ;

        if(_atom_resid()[i] > 9999)
        {
            std::string tmp7(std::to_string(9999),0,4) ;
            line << std::setfill(' ') << std::setw(4) << std::right << tmp7 ;
        }
        else if(_atom_resid()[i] < -999)
        {
            std::string tmp7(std::to_string(-999),0,4) ;
            line << std::setfill(' ') << std::setw(4) << std::right << tmp7 ;
        }
        else
        {
            std::string tmp7(std::to_string(_atom_resid()[i]),0,4) ;
            line << std::setfill(' ') << std::setw(4) << std::right << tmp7 ;
        }

        std::string tmp8(_atom_icode()[i],0,1) ;
        line << std::setw(4) << std::left << tmp8 ;

        //std::string f_str = std::to_string(f);

        //here
        //
        my_stringstream << _x()(i,frame) ;
        //my_stringstream << std::to_string(_x()(i,frame)) ;
        //line << std::setfill(' ') << std::setw(8) << std::right << my_stringstream.str() ;
        line << std::setfill(' ') << std::setw(8) << std::right << my_stringstream.str() ;

        my_stringstream << _y()(i,frame) ;
        line << my_stringstream.str() ;

        my_stringstream << _z()(i,frame) ;
        line << my_stringstream.str() ;

        std::string tmp12(_atom_occupancy()[i],0,6) ;
        line << std::setfill(' ') << std::setw(6) << std::right << tmp12 ;

        std::string tmp13(_atom_beta()[i],0,6) ;
        line << std::setfill(' ') << std::setw(6) << std::right << tmp13 ;

        std::string tmp14(_atom_segname()[i],0,4) ;
        line << std::setfill(' ') << std::setw(10) << std::right << tmp14 ;

        std::string tmp15(_atom_element()[i],0,2) ;
        line << std::setfill(' ') << std::setw(2) << std::right << tmp15 ;

        std::string tmp16(_atom_charge()[i],0,2) ;
        line << std::setfill(' ') << std::setw(2) << std::right << tmp16 ;

        outfile << line.str() << std::endl ;
    }

    outfile << "END" << std::endl;
    outfile.close() ;
}