source: sasview/src/sas/sascalc/simulation/pointsmodelpy/libpointsmodelpy/pdb_model.cc @ 94f074c4

magnetic_scattrelease-4.2.2ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249unittest-saveload
Last change on this file since 94f074c4 was d85c194, checked in by Piotr Rozyczko <piotr.rozyczko@…>, 9 years ago

Remaining modules refactored

  • Property mode set to 100644
File size: 3.2 KB
RevLine 
[aa639ea]1/** \file pdb_model.cc */
2
3#include "pdb_model.h"
4#include <fstream>
5#include <string>
6#include <cstdlib>
7#include <cmath>
8#include <stdexcept>
9
10using namespace std;
11
12typedef map<string,double>::const_iterator mymapitr;
13
14PDBModel::PDBModel(){
15  res_sld_["ALA"] = 1.645;  res_sld_["ARG"] = 3.466;
16  res_sld_["ASN"] = 3.456;  res_sld_["ASP"] = 3.845;
17  res_sld_["CYS"] = 1.930;  res_sld_["GLU"] = 3.762;
18  res_sld_["GLN"] = 3.373;  res_sld_["GLY"] = 1.728;
19  res_sld_["HIS"] = 4.959;  res_sld_["LLE"] = 1.396;
20  res_sld_["LEU"] = 1.396;  res_sld_["LYS"] = 1.586;
21  res_sld_["MET"] = 1.763;  res_sld_["PHE"] = 4.139;
22  res_sld_["PRO"] = 2.227;  res_sld_["SER"] = 2.225;
23  res_sld_["THR"] = 2.142;  res_sld_["TRP"] = 6.035;
24  res_sld_["TYR"] = 4.719;  res_sld_["VAL"] = 1.479;
25
26  x_max_ = -10000; x_min_ = 10000;
27  y_max_ = -10000; y_min_ = 10000;
28  z_max_ = -10000; z_min_ = 10000;
29}
30
31void PDBModel::AddPDB(const string &pdbfile)
32{
33  pdbnames_.push_back(pdbfile);
34}
35
36void PDBModel::AddPDB(const char* pdbfile)
37{
38  string sname(pdbfile);
39  pdbnames_.push_back(sname);
40}
41
42int PDBModel::GetPoints(Point3DVector &vp)
43{
44  if (vp.size() != 0){
45    throw runtime_error("PDBModel::GetPoints(Point3DVector &VP):VP has to be empty"); 
46  }
47  vector<string>::iterator itr;
48  for (itr = pdbnames_.begin(); itr!=pdbnames_.end(); ++itr){
49    ifstream infile(itr->c_str());
50    if (!infile){
51      cerr << "error: unable to open input file: " 
52           << infile << endl;
53    }
54    string line;
55    while (getline(infile,line)){
56      size_t len = line.size();
57      string header;
58     
59      //for a line with size >=4, retrieve the header
60      //if the header == "ATOM""
61      //make sure the length of the line >=54, then
62      //retrieve the corresponding coordinates,convert str to double
63      //then assign them to a point3d,which will be append to vp with a SLD
64      if (len >= 4){
65        for (size_t i=0; i !=4; ++i) header += line[i];
66        if (header.compare("ATOM") == 0 && len >53){
67          string strx,stry,strz;
68          double x = 0, y = 0, z = 0;
69          for (size_t j = 30; j!=38; ++j){
70            strx += line[j];
71            stry += line[j+8];
72            strz += line[j+16];
73          }
74          x = atof(strx.c_str());
75          y = atof(stry.c_str());
76          z = atof(strz.c_str());
77         
78          //find residue type, and assign SLD
79          string resname;
80          for (size_t k = 17; k!=20; ++k) resname +=line[k];
81          mymapitr itr = res_sld_.find("ALA");
82         
83          //apoint(x,y,z,sld)
84          Point3D apoint(x,y,z,itr->second);
85          vp.push_back(apoint);
86         
87          //save x y z' max & min to calculate the size boundary
88          x_max_ = x > x_max_ ? x : x_max_;
89          x_min_ = x < x_min_ ? x : x_min_;
90          y_max_ = y > y_max_ ? y : y_max_;
91          y_min_ = y < y_min_ ? y : y_min_;
92          z_max_ = z > z_max_ ? z : z_max_;
93          z_min_ = z < z_min_ ? z : z_min_;
94        }
95      }
96    }
97
98    infile.close();
99  }
100  return vp.size();
101}
102
103double PDBModel::GetDimBound()
104{
105  if (pdbnames_.size() == 0 )
106    return 0;
107
108  //cout <<x_max_<<" "<<x_min_<<" "<<y_max_<<" "<<y_min_<<" "<<z_max_<<" "<<z_min_<<endl;
109  double size = sqrt((x_max_-x_min_)*(x_max_-x_min_)+(y_max_-y_min_)*(y_max_-y_min_)+(z_max_-z_min_)*(z_max_-z_min_));
110  return size;
111}
112
113vector<double> PDBModel::GetCenter()
114{
115
116  vector<double> cen(3);
117  cen[0]= (x_max_+x_min_)/2;
118  cen[1]= (y_max_+y_min_)/2;
119  cen[2]= (z_max_+z_min_)/2;
120  center_ = cen;
121
122  return center_;
123}
Note: See TracBrowser for help on using the repository browser.