Xmipp  v3.23.11-Nereus
Classes | Public Member Functions | List of all members
cif::pdb::PDBFileParser Class Reference

Public Member Functions

 PDBFileParser ()
 
 ~PDBFileParser ()
 
void Parse (std::istream &is, cif::file &result)
 

Detailed Description

Definition at line 435 of file pdb2cif.cpp.

Constructor & Destructor Documentation

◆ PDBFileParser()

cif::pdb::PDBFileParser::PDBFileParser ( )
inline

Definition at line 438 of file pdb2cif.cpp.

439  : mData(nullptr)
440  , mRec(nullptr)
441  {
442  }

◆ ~PDBFileParser()

cif::pdb::PDBFileParser::~PDBFileParser ( )
inline

Definition at line 444 of file pdb2cif.cpp.

445  {
446  PDBRecord *r = mData;
447  while (r != nullptr)
448  {
449  PDBRecord *d = r;
450  r = d->mNext;
451  delete d;
452  }
453  }
doublereal * d

Member Function Documentation

◆ Parse()

void cif::pdb::PDBFileParser::Parse ( std::istream &  is,
cif::file &  result 
)

Definition at line 5719 of file pdb2cif.cpp.

5720 {
5721  try
5722  {
5723  mDatablock.set_validator(result.get_validator());
5724 
5725  PreParseInput(is);
5726 
5727  mRec = mData;
5728 
5729  ParseTitle();
5730 
5731  ParseRemarks();
5732  ParsePrimaryStructure();
5733  ParseHeterogen();
5734 
5735  ConstructEntities();
5736 
5737  ParseRemark350();
5738 
5739  ParseSecondaryStructure();
5740  ParseConnectivtyAnnotation();
5741  ParseMiscellaneousFeatures();
5742  ParseCrystallographic();
5743  ParseCoordinateTransformation();
5744 
5745  uint32_t modelNr = 1;
5746  bool hasAtoms = false;
5747 
5748  while (mRec->is("MODEL ") or mRec->is("ATOM ") or mRec->is("HETATM"))
5749  {
5750  bool model = false;
5751  if (mRec->is("MODEL "))
5752  {
5753  model = true;
5754 
5755  modelNr = vI(11, 14);
5756 
5757  GetNextRecord();
5758  }
5759 
5760  hasAtoms = hasAtoms or mRec->is("ATOM ") or mRec->is("HETATM");
5761 
5762  ParseCoordinate(modelNr);
5763 
5764  if (model)
5765  {
5766  Match("ENDMDL", true);
5767  GetNextRecord();
5768  }
5769  }
5770 
5771  if (not hasAtoms)
5772  throw std::runtime_error("Either the PDB file has no atom records, or the field " + std::string(mRec->mName) + " is not at the correct location");
5773 
5774  for (auto e : mAtomTypes)
5775  getCategory("atom_type")->emplace({
5776  { "symbol", e } });
5777 
5778  // in V5, atom_type is sorted
5779  getCategory("atom_type")->reorder_by_index();
5780 
5781  ParseConnectivty();
5782  ParseBookkeeping();
5783 
5784  // almost done, now fix some outstanding issued that could not be done before
5785 
5786  try
5787  {
5788  auto r = FindRecord("REMARK 3");
5789 
5790  if (r != nullptr and Remark3Parser::parse(mExpMethod, r, mDatablock))
5791  {
5792  // make sure the "exptl" category is created
5793  auto exptl = getCategory("exptl");
5794  if (exptl->empty())
5795  {
5796  exptl->emplace({
5797  { "entry_id", mStructureID },
5798  { "method", mExpMethod },
5799  { "crystals_number", mRemark200["NUMBER OF CRYSTALS USED"] } });
5800  }
5801  }
5802  }
5803  catch (const std::exception &ex)
5804  {
5805  if (cif::VERBOSE >= 0)
5806  std::cerr << "Error parsing REMARK 3" << std::endl;
5807  throw;
5808  }
5809  //
5810  // auto cat = getCategory("pdbx_refine_tls_group");
5811  // for (Row r: *cat)
5812  // {
5813  // // add the mapped locations
5814  //
5815  // try
5816  // {
5817  // std::string asymID;
5818  // int resNum;
5819  //
5820  // cif::tie(asymID, resNum) = r.get("beg_auth_asym_id", "beg_auth_seq_id");
5821  //
5822  // r["beg_label_asym_id"] = asymID;
5823  // r["beg_label_seq_id"] = resNum;
5824  //
5825  // cif::tie(asymID, resNum) = r.get("end_auth_asym_id", "end_auth_seq_id");
5826  //
5827  // r["end_label_asym_id"] = asymID;
5828  // r["end_label_seq_id"] = resNum;
5829  // }
5830  // catch (const std::exception& ex)
5831  // {
5832  // continue;
5833  // }
5834  // }
5835 
5836  using namespace cif::literals;
5837 
5838  auto &atom_site = *getCategory("atom_site");
5839 
5840  for (auto r : getCategory("struct_conn")->find("pdbx_dist_value"_key == 0 or "pdbx_dist_value"_key == cif::null))
5841  {
5842  const auto &[asym1, seq1, atom1, symm1, asym2, seq2, atom2, symm2] = r.get<std::string, std::string, std::string, std::string, std::string, std::string, std::string, std::string>(
5843  "ptnr1_label_asym_id", "ptnr1_label_seq_id", "ptnr1_label_atom_id", "ptnr1_symmetry",
5844  "ptnr2_label_asym_id", "ptnr2_label_seq_id", "ptnr2_label_atom_id", "ptnr2_symmetry");
5845 
5846  float distance = 1.0f;
5847 
5848  try
5849  {
5850  auto a1 = atom_site.find1("label_asym_id"_key == asym1 and "label_seq_id"_key == seq1 and "label_atom_id"_key == atom1);
5851  auto a2 = atom_site.find1("label_asym_id"_key == asym2 and "label_seq_id"_key == seq2 and "label_atom_id"_key == atom2);
5852 
5853  if (not a1 or not a2)
5854  throw std::runtime_error("cannot find atom");
5855 
5856  const auto &[x1, y1, z1] = a1.get<float, float, float>("cartn_x", "cartn_y", "cartn_z");
5857  const auto &[x2, y2, z2] = a2.get<float, float, float>("cartn_x", "cartn_y", "cartn_z");
5858 
5859  if ((symm1.empty() or symm1 == "1_555") and (symm2.empty() or symm2 == "1_555"))
5860  distance = std::sqrt(
5861  (x1 - x2) * (x1 - x2) +
5862  (y1 - y2) * (y1 - y2) +
5863  (z1 - z2) * (z1 - z2)
5864  );
5865  else if (cif::VERBOSE > 0)
5866  std::cerr << "Cannot calculate distance for link since one of the atoms is in another dimension" << std::endl;
5867  }
5868  catch (std::exception &ex)
5869  {
5870  if (cif::VERBOSE > 0)
5871  std::cerr << "Error finding atom for LINK distance calculation: " << ex.what() << std::endl;
5872  }
5873 
5874  r["pdbx_dist_value"] = distance;
5875  }
5876 
5877  result.emplace_back(std::move(mDatablock));
5878  }
5879  catch (const std::exception &ex)
5880  {
5881  if (cif::VERBOSE >= 0)
5882  {
5883  std::cerr << "Error parsing PDB";
5884  if (mRec != nullptr)
5885  std::cerr << " at line " << mRec->mLineNr;
5886  std::cerr << std::endl;
5887  }
5888  throw;
5889  }
5890 }
void sqrt(Image< double > &op)
std::vector< SelLine >::iterator find(std::vector< SelLine > &text, const std::string &img_name)
Definition: selfile.cpp:553
int VERBOSE
Definition: utilities.cpp:58
TYPE distance(struct Point_T *p, struct Point_T *q)
Definition: point.cpp:28

The documentation for this class was generated from the following file: