Main Page | Namespace List | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | Examples

check_protein.cc

00001 /* Copyright 2004
00002 Stanford University
00003 
00004 This file is part of the DSR PDB Library.
00005 
00006 The DSR PDB Library is free software; you can redistribute it and/or modify
00007 it under the terms of the GNU Lesser General Public License as published by
00008 the Free Software Foundation; either version 2.1 of the License, or (at your
00009 option) any later version.
00010 
00011 The DSR PDB Library is distributed in the hope that it will be useful, but
00012 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
00013 or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
00014 License for more details.
00015 
00016 You should have received a copy of the GNU Lesser General Public License
00017 along with the DSR PDB Library; see the file COPYING.LIB.  If not, write to
00018 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00019 MA 02111-1307, USA. */
00020 
00021 #include "dsrpdb/Protein.h"
00022 #include "dsrpdb/geometry.h"
00023 #include "dsrpdb/iterator.h"
00024 #include <fstream>
00025 #include <cassert>
00026 #include <iterator>
00027 
00028 int main(int argc, char *argv[]){
00029   //dsr::Residue res= dsr::Residue(dsr::Residue::VAL);
00030   //res.write(std::cout);
00031   assert(argc==3);
00032   std::ifstream in(argv[1]);
00033   dsrpdb::Protein p(in);
00034   //p.write(std::cout);
00035   std::ofstream of(argv[2]);
00036   
00037   std::cout << "There are " << p.number_of_residues() << " residues." << std::endl;
00038   
00039   p.write_pdb(of);
00040   //p.dump(std::cout);
00041 
00042   // Demonstrate the geometry functions
00043   std::vector<dsrpdb::Point> atms;
00044   dsrpdb::coordinates(p.atoms_begin(), p.atoms_end(), std::back_inserter(atms));
00045   std::cout << "There are " << atms.size() << " atoms." << std::endl;
00046   assert(std::distance(p.atoms_begin(), p.atoms_end()) == atms.size());
00047   
00048   std::vector<dsrpdb::Protein::Bond> bds(p.bonds_begin(), p.bonds_end());
00049   std::cout << "There are " << bds.size() << " bonds." << std::endl;
00050   
00051 
00052   std::vector<dsrpdb::Point> bb;
00053   dsrpdb::backbone_coordinates(p.atoms_begin(), p.atoms_end(), std::back_inserter(bb));
00054   assert(bb.size() < atms.size());
00055   {
00056     std::vector<std::pair<int,int> > bonds;
00057     std::vector<dsrpdb::Point> points;
00058     dsrpdb::coordinates_and_bonds(p, std::back_inserter(points), std::back_inserter(bonds));
00059     assert(bonds.size() == bds.size());
00060     assert(points.size() == atms.size());
00061   }
00062   {
00063     std::vector<dsrpdb::Point> points;
00064     dsrpdb::coordinates(p.atoms_begin(), p.atoms_end(), std::back_inserter(points));
00065     assert(points.size() == atms.size());
00066   }
00067   {
00068     std::vector<dsrpdb::Point> points;
00069     std::copy(backbone_coordinates_begin(p),
00070               backbone_coordinates_end(p),
00071               std::back_inserter(points));
00072     assert(points.size() == bb.size());
00073   }
00074   {
00075     std::vector<std::pair<int,int> > bonds;
00076     std::vector<dsrpdb::Point> points;
00077     dsrpdb::simplified_coordinates_and_bonds(p, 
00078                                              std::back_inserter(points), 
00079                                              std::back_inserter(bonds));
00080     //std::cerr << bonds.size()  << " " << atms.size() << " " << points.size() << std::endl;
00081     assert(bonds.size() == points.size()-1);
00082     assert(points.size() == 4*p.number_of_residues());
00083   }
00084 
00085   {
00086     for (dsrpdb::Protein::Atoms_iterator it= p.atoms_begin(); it != p.atoms_end(); ++it){
00087       dsrpdb::Atom::Index ind= it->second.index();
00088       dsrpdb::Residue::Atom_label al= it->first;
00089       dsrpdb::Residue& res= p.residue_containing_atom(ind);
00090       assert(&res >= &*p.residues_begin() 
00091              && &res < &*p.residues_begin() + p.number_of_residues());
00092       assert(res.atom_label(ind) != dsrpdb::Residue::AL_INVALID);
00093       assert(res.atom_label(ind) == al);
00094     }
00095   }
00096 
00097   {
00098     for (dsrpdb::Protein::Bonds_iterator it= p.bonds_begin(); it != p.bonds_end(); ++it){
00099       dsrpdb::Atom::Index ind0= it->first;
00100       dsrpdb::Atom::Index ind1= it->second;
00101       assert(p.atom(ind0) != p.atom(dsrpdb::Atom::Index()));
00102       assert(p.atom(ind1) != p.atom(dsrpdb::Atom::Index()));
00103       int ir0= p.residue_containing_atom(ind0).index();
00104       int ir1= p.residue_containing_atom(ind1).index();
00105       int diff = ir1 - ir0;
00106       assert(diff==0 || diff ==1);
00107     }
00108   }
00109 
00110   return EXIT_SUCCESS;
00111 }