examples/pl-functions/pdbdistance.h
author Aravindakshan Babu <akshan@stanford.edu>
Thu, 08 Jul 2010 23:50:39 -0700
branchdev
changeset 217 64a272a34cb2
parent 183 0ca59b0ebc47
permissions -rw-r--r--
Added extra functionality to Point class( an iterator ) and PersistenceDiagram( dimension property and __len__ func ). persistence-diagram.h: Added a new read-only dimension member and member function to access it. With a new constructor that that takes in an int type to initialize dimension. persistence-diagram.cpp: Added new bp::init constructor. Takes in an integer type to initialize the dimension. Exposed the dimension property. Exposed the size property via a __len__ method. __init__.py: Added an iterator for Point objects. This iterates over the coords and then the data( if present ).

/*
 * Author: Dmitriy Morozov
 * Department of Computer Science, Duke University, 2005 -- 2006
 *
 * Depends on Daniel Russel's "simple C++ PDB" (aka DSR-PDB).
 */

#ifndef __PDBDISTANCE_H__
#define __PDBDISTANCE_H__

#include <fstream>
#include <string>
#include <dsrpdb/Protein.h>
#include <dsrpdb/iterator.h>
#include <cmath>

#include <boost/serialization/access.hpp>

#include "utilities/types.h"
#include "grid2D.h"

#include <boost/serialization/export.hpp>


class PDBDistanceGrid: public Grid2D
{
	public:
		PDBDistanceGrid()
		{}
	
		PDBDistanceGrid(std::istream& in, bool ca_only = true)
		{
			load_stream(in, ca_only);
		}

		void	load_stream(std::istream& in, bool ca_only = true)
		{
			dsrpdb::Protein p(in);
			typedef std::vector<dsrpdb::Point> PointVector;
			PointVector coordinates;
			if (ca_only)
			{
				PointVector v(ca_coordinates_begin(p), ca_coordinates_end(p));
				coordinates.swap(v);
			}
			else
			{
				PointVector v(backbone_coordinates_begin(p), backbone_coordinates_end(p));
				coordinates.swap(v);
			}

			std::cout << "Coordinatess created, size: " << coordinates.size() << std::endl;

			Grid2D::change_dimensions(coordinates.size(), coordinates.size());
			for (Grid2D::CoordinateIndex i = 0; i < coordinates.size(); ++i)
				for (Grid2D::CoordinateIndex j = 0; j < coordinates.size(); ++j)
				{
					if (i < j)
						Grid2D::operator()(i,j) = distance(coordinates[i], coordinates[j]);
					else
						Grid2D::operator()(i,j) = 0;
				}
		}

	private:
		Grid2D::ValueType distance(dsrpdb::Point p1, dsrpdb::Point p2) const
		{
			dsrpdb::Vector v = p1 - p2;
			return std::sqrt(v*v);
		}

#if 0
	private:
		// Serialization
		friend class boost::serialization::access;
		
		template<class Archive>
		void serialize(Archive& ar, version_type version)
		{
			ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Grid2D);
		}
#endif
};

//BOOST_CLASS_EXPORT(PDBDistanceGrid)

#endif // __PDBDISTANCE_H__