-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnergyAPI.cpp
More file actions
126 lines (108 loc) · 3.46 KB
/
EnergyAPI.cpp
File metadata and controls
126 lines (108 loc) · 3.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/***********************************************************************
EnergyAPI - Classes to dynamically load energy computation libraries at
run-time.
Copyright (2) 2003 Oliver Kreylos
***********************************************************************/
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <dlfcn.h>
#include <string>
#include <stdexcept>
#include "Protein.h"
#include "ParsePdbFile.h"
#include "EnergyAPI.h"
/******************************
Methods of class EnergyLibrary:
******************************/
EnergyLibrary::EnergyLibrary(void* sDsoHandle)
:dsoHandle(sDsoHandle)
{
}
EnergyLibrary* EnergyLibrary::load(const char* dsoName)
{
/* Open DSO containing class: */
void* dsoHandle=dlopen(dsoName,RTLD_LAZY|RTLD_GLOBAL);
if(dsoHandle==0) // Check for errors during DSO loading
throw std::runtime_error(std::string("EnergyLibrary::load: Unable to open energy calculation DSO \"")+std::string(dsoName)+std::string("\" due to ")+std::string(dlerror()));
/* Get address to library object creation function: */
CreateEnergyLibraryFunction createEnergyLibrary=(CreateEnergyLibraryFunction)dlsym(dsoHandle,"createEnergyLibrary");
if(createEnergyLibrary==0) // Check for errors during function lookup
{
dlclose(dsoHandle);
throw std::runtime_error(std::string("EnergyLibrary::load: Unable to retrieve energy calculator creation function from DSO due to ")+std::string(dlerror()));
}
/* Create and return library object: */
return createEnergyLibrary(dsoHandle);
}
EnergyLibrary::~EnergyLibrary(void)
{
dlclose(dsoHandle);
}
/*********************************
Methods of class EnergyCalculator:
*********************************/
int EnergyCalculator::getNumAtoms(void) const
{
return protein->getNumAtoms();
}
int EnergyCalculator::getNumResidues(void) const
{
return protein->getNumResidues();
}
void EnergyCalculator::getAtomCoordinates(float x[],float y[],float z[]) const
{
/* Copy atom positions: */
MD::Protein::ConstAtomIterator aIt;
int i;
for(aIt=protein->atomsBegin(),i=0;aIt!=protein->atomsEnd();++aIt,++i)
{
x[i]=float(aIt->getPosition()[0]);
y[i]=float(aIt->getPosition()[1]);
z[i]=float(aIt->getPosition()[2]);
}
}
void EnergyCalculator::getAtomCoordinates(double x[],double y[],double z[]) const
{
/* Copy atom positions: */
MD::Protein::ConstAtomIterator aIt;
int i;
for(aIt=protein->atomsBegin(),i=0;aIt!=protein->atomsEnd();++aIt,++i)
{
x[i]=aIt->getPosition()[0];
y[i]=aIt->getPosition()[1];
z[i]=aIt->getPosition()[2];
}
}
void EnergyCalculator::getAtomCoordinates(float xyz[][3]) const
{
/* Copy atom positions: */
MD::Protein::ConstAtomIterator aIt;
int i;
for(aIt=protein->atomsBegin(),i=0;aIt!=protein->atomsEnd();++aIt,++i)
for(int j=0;j<3;++j)
xyz[i][j]=float(aIt->getPosition()[j]);
}
void EnergyCalculator::getAtomCoordinates(double xyz[][3]) const
{
/* Copy atom positions: */
MD::Protein::ConstAtomIterator aIt;
int i;
for(aIt=protein->atomsBegin(),i=0;aIt!=protein->atomsEnd();++aIt,++i)
for(int j=0;j<3;++j)
xyz[i][j]=aIt->getPosition()[j];
}
EnergyCalculator::EnergyCalculator(const MD::Protein* sProtein)
:protein(sProtein),pdbFileName(new char[256])
{
/* Create temporary PDB file to initialize energy computation state: */
strcpy(pdbFileName,"EFuncPDB.pdb.XXXXXX");
mktemp(pdbFileName);
MD::writePdbFile(*protein,pdbFileName,false);
}
EnergyCalculator::~EnergyCalculator(void)
{
/* Remove temporary PDB file: */
unlink(pdbFileName);
delete[] pdbFileName;
}