Commit 3547a8d0 authored by karius's avatar karius

added rmftool

parent 71ff5c52
/*
* CRMFtool.cpp
*
* Created on: Oct 10, 2019
* Author: kkarius
*/
#include <CRMFtool.h>
#include <IMP/rmf/atom_io.h>
#include <IMP/rmf.h>
#include <IMP/atom/Representation.h>
#include <RMF/FileHandle.h>
#include <RMF/FileConstHandle.h>
#include <RMF/infrastructure_macros.h>
#include <RMF/utility.h>
#include <stdio.h>
#include <boost/filesystem/path.hpp>
#include <boost/filesystem.hpp>
CRMFtool::CRMFtool() {
// TODO Auto-generated constructor stub
}
CRMFtool::~CRMFtool() {
// TODO Auto-generated destructor stub
}
int main(int argc, char **argv) {
if (argc == 3) {
printf("Here");
boost::filesystem::path dir(argv[1]);
boost::filesystem::path outfile(argv[2]);
boost::filesystem::directory_iterator it { dir };
RMF::FileHandle orh = RMF::create_rmf_file(outfile.string());
orh.set_producer("Le Kai");
bool first = true;
while (it != boost::filesystem::directory_iterator { }) {
RMF::FileConstHandle rh = RMF::open_rmf_file_read_only(
it->path().string());
if (first) {
RMF::clone_file_info(rh, orh); // creator etc. (not essential)
RMF::clone_hierarchy(rh, orh);
RMF::clone_static_frame(rh, orh);
first = false;
}
orh.set_description(
orh.get_description() + "\n" + rh.get_description());
RMF_FOREACH(RMF::FrameID ni, rh.get_frames()){
rh.set_current_frame(ni);
orh.add_frame(rh.get_name(ni), rh.get_type(ni));
RMF::clone_loaded_frame(rh, orh);
}
printf("Processing file %s\n",it->path().string().c_str());
it++;
}
// RMF::FileHandle out_file = RMF::create_rmf_file(outfile.string());
// IMP_NEW(IMP::Model, model, ());
// IMP::atom::Hierarchy hierarchy;
// printf("Here\n");
// std::list<RMF::FileConstHandle> file_handles;
// if (it != boost::filesystem::directory_iterator { }){
// RMF::FileConstHandle iter_file_handle = RMF::open_rmf_file_read_only(it->path().string());
// hierarchy = IMP::rmf::create_hierarchies(iter_file_handle,model)[0];
// it++;
// IMP::rmf::add_hierarchy(out_file,hierarchy);
// }
// size_t c = 0;
// while (it != boost::filesystem::directory_iterator { }){
// file_handles.push_back(RMF::open_rmf_file_read_only(it->path().string()));
// std::cout << file_handles.back().get_path() << '\n';
// IMP::rmf::load_frame(file_handles.back(),RMF::FrameID(0));
// IMP::rmf::save_frame(out_file,std::to_string(c));
// c++;
// it++;
// }
}
}
/*
* CRMFtool.h
*
* Created on: Oct 10, 2019
* Author: kkarius
*/
#ifndef CRMFTOOL_H_
#define CRMFTOOL_H_
class CRMFtool {
public:
CRMFtool();
virtual ~CRMFtool();
};
#endif /* CRMFTOOL_H_ */
......@@ -6,6 +6,26 @@
*/
#include <CRotationGrid.h>
#include <math.h>
void CRotationGrid::random_close_to_unity(float * &matrix,size_t offset){
float eps = 0.1;
int _rand_max = 1000;
//euler angles
float phi = scaled_rand(_rand_max,eps);
float theta = scaled_rand(_rand_max,eps);
float psi = scaled_rand(_rand_max,eps);
matrix[offset+0] = cos(psi)*cos(phi)-cos(theta)*sin(phi)*sin(psi);
matrix[offset+1] = cos(psi)*sin(phi)+cos(theta)*cos(phi)*sin(psi);
matrix[offset+2] = sin(psi)*sin(theta);
matrix[offset+3] = -sin(psi)*cos(phi)-cos(theta)*sin(phi)*cos(psi);
matrix[offset+4] = -sin(psi)*sin(phi)+cos(theta)*cos(phi)*cos(psi);
matrix[offset+5] = cos(psi)*sin(theta);
matrix[offset+6] = sin(theta)*sin(phi);
matrix[offset+7] = -sin(theta)*cos(phi);
matrix[offset+8] = cos(theta);
}
CRotationGrid::CRotationGrid(std::string rot_file_path, size_t chunksize) : // @suppress("Class members should be properly initialized")
m_filepath(rot_file_path), m_rotation_format(ERotationFormat::eMatrix), m_chunksize(
......@@ -22,6 +42,7 @@ CRotationGrid::CRotationGrid(std::string rot_file_path, size_t chunksize) : // @
m_matrix_chunk = (float *) malloc(9 * chunksize * sizeof(float));
//get first batch into m_matrix_chunk
(*this)++;
m_current_chunk_num--;
}
}
......@@ -40,15 +61,50 @@ CRotationGrid& CRotationGrid::operator++(int inc) {
}
}
}
m_current_chunk_num++;
return *this;
}
void CRotationGrid::print_current(){
if (m_rotation_format == ERotationFormat::eMatrix){
printf("-------------------\n");
for (int i=0;i<3;i++){
for (int j=0;j<3;j++){
if (j!=2){
printf("%f,",m_current_matrix[i*3+j]);
} else {
printf("%f",m_current_matrix[i*3+j]);
}
}
printf("\n");
}
}
}
float *& CRotationGrid::operator *() {
return m_matrix_chunk;
}
bool CRotationGrid::operator!() {
return !m_filestream.eof();
// printf("!:%i\n",m_current_chunk_num);
if (m_current_chunk_num==0)
return true;
return (rotation_num/(m_current_chunk_num*m_chunksize) !=0);
}
void CRotationGrid::reset(){
m_beginning_found = false;
m_filestream.close();
m_filestream.open(m_filepath, std::fstream::in);
m_beginning_found = x_find_beginning();
m_current_chunk_num = 0;
m_current_rot_num = 0;
if (m_beginning_found){
(*this)++;
m_current_chunk_num--;
}
}
bool CRotationGrid::x_find_beginning() {
......@@ -68,6 +124,7 @@ bool CRotationGrid::x_find_beginning() {
break;
}
}
x_parse_line(); //skip identity
return success;
}
......@@ -102,6 +159,18 @@ bool CRotationGrid::x_quat_to_rot_mat() {
- 2 * m_current_quat.z * m_current_quat.z;
return success;
}
size_t CRotationGrid::current_chunk_size(){
if (m_current_chunk_num==0)
return m_chunksize;
if (rotation_num-m_current_chunk_num*m_chunksize<m_chunksize){
return rotation_num-m_current_chunk_num*m_chunksize;
}
else {
return m_chunksize;
}
}
bool CRotationGrid::x_parse_line() {
bool success = true;
std::vector<std::string> strs;
......@@ -120,6 +189,7 @@ bool CRotationGrid::x_parse_line() {
success &= x_quat_to_rot_mat();
}
}
m_current_rot_num++;
return success;
}
......
......@@ -30,6 +30,11 @@ public:
CRotationGrid& operator++(int);
float *&operator*();
bool operator!();
size_t current_chunk_size();
void reset();
void print_current();
static void random_close_to_unity(float * &matrix,size_t offset=0);
private:
size_t m_chunksize;
ERotationFormat m_rotation_format;
......@@ -41,10 +46,16 @@ private:
float * m_matrix_chunk;
float m_current_matrix[9];
float4 m_current_quat;
int m_current_chunk_num=0;
size_t m_current_rot_num=0;
bool x_find_beginning(void);
bool x_parse_line(void);
bool x_quat_to_rot_mat();
};
inline float scaled_rand(int _rand_max, float bound) {
return (float) (rand() % _rand_max) / (float) _rand_max * bound;
}
#endif /* CROTATIONGRID_H_ */
No preview for this file type
No preview for this file type
This diff is collapsed.
CC=gcc
NVCC=nvcc
IMP_INCLUDE = -I/data/git/imp/bin/include/ -I/data/git/imp/build/src/dependency/RMF/include/
EIGEN_INCLUDE = -I/data/tools/eigen-eigen-323c052e1731/
CUDA_INCLUDE = -I./cuda_util_include #most of it comes with nvcc, this is a convenience lib
CFLAGS=-I. $(CUDA_INCLUDE) $(IMP_INCLUDE) $(EIGEN_INCLUDE) -D_GLIBCXX_USE_CXX11_ABI=0 #the latter is for IMP
BOOST_LINKS = -L/usr/local/lib -lboost_filesystem
IMP_LINKS = -L/data/git/imp/build/lib/ -lRMF -limp_core -limp_rmf -limp_kernel -limp_atom -limp_algebra
CUDA_LINKS = -L/usr/local/cuda-10.0/lib64/ -lcusolver -lcudart -lcublas -lcuda
LFLAGS=-L. $(IMP_LINKS) $(BOOST_LINKS) $(CUDA_LINKS)
all:
$(NVCC) $(CFLAGS) $(LFLAGS) CRMFtool.cpp -o rmftool
......@@ -8,16 +8,11 @@ CFLAGS=-I. $(CUDA_INCLUDE) $(IMP_INCLUDE) $(EIGEN_INCLUDE) -D_GLIBCXX_USE_CXX11
BOOST_LINKS = -L/usr/local/lib -lboost_filesystem
IMP_LINKS = -L/data/git/imp/build/lib/ -lRMF -limp_core -limp_rmf -limp_kernel -limp_atom
IMP_LINKS = -L/data/git/imp/build/lib/ -lRMF -limp_core -limp_rmf -limp_kernel -limp_atom -limp_algebra
LFLAGS=-L. $(IMP_LINKS) $(BOOST_LINKS)
all: CudaTest.cu CMrcReader.o CRotationGrid.o
$(NVCC) $(LFLAGS) $(CFLAGS) -o CudaTest CudaTest.cu CMrcReader.o CRotationGrid.o
CMrcReader.o: CMrcReader.cpp
$(NVCC) -c -o $@ $< $(CFLAGS)
LFLAGS=-L. #$(IMP_LINKS) $(BOOST_LINKS)
all: CRotationGrid.o
$(NVCC) $(LFLAGS) $(CFLAGS) -o CudaTest CudaTest.cu CRotationGrid.o
CRotationGrid.o: CRotationGrid.cpp
$(NVCC) -c -o $@ $< $(CFLAGS)
$(NVCC) -c -o $@ $< $(CFLAGS)
\ No newline at end of file
......@@ -8,8 +8,8 @@ CFLAGS=-I. $(CUDA_INCLUDE) $(IMP_INCLUDE) $(EIGEN_INCLUDE) -D_GLIBCXX_USE_CXX11
BOOST_LINKS = -L/usr/local/lib -lboost_filesystem
IMP_LINKS = -L/data/git/imp/build/lib/ -lRMF -limp_core -limp_rmf -limp_kernel -limp_atom
CUDA_LINKS = -L/usr/local/cuda-10.0/lib64/ -lcusolver -lcudart -lcublas
IMP_LINKS = -L/data/git/imp/build/lib/ -lRMF -limp_core -limp_rmf -limp_kernel -limp_atom -limp_algebra
CUDA_LINKS = -L/usr/local/cuda-10.0/lib64/ -lcusolver -lcudart -lcublas -lcuda
LFLAGS=-L. $(IMP_LINKS) $(BOOST_LINKS) $(CUDA_LINKS)
......
No preview for this file type
This diff is collapsed.
File added
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
No preview for this file type
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment