Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
MPIBP-Hummer
BioEM
Commits
9768552f
Commit
9768552f
authored
Dec 16, 2015
by
Pilar Cossio
Browse files
Correcting bug accessing ilegal memory in CC mat & tidying up
parent
19bc6d4d
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
CMakeLists.txt
View file @
9768552f
...
...
@@ -6,7 +6,7 @@ option (INCLUDE_CUDA "Build BioEM with CUDA support" ON)
option
(
INCLUDE_OPENMP
"Build BioEM with OpenMP support"
ON
)
option
(
INCLUDE_MPI
"Build BioEM with MPI support"
ON
)
option
(
PRINT_CMAKE_VARIABLES
"List all CMAKE Variables"
OFF
)
option
(
CUDA_FORCE_GCC
"Force GCC as host compiler for CUDA part (If standard host compiler is incompatible with CUDA)"
O
FF
)
option
(
CUDA_FORCE_GCC
"Force GCC as host compiler for CUDA part (If standard host compiler is incompatible with CUDA)"
O
N
)
###Set up general variables
set
(
CMAKE_MODULE_PATH
${
CMAKE_MODULE_PATH
}
"
${
CMAKE_SOURCE_DIR
}
/cmake/Modules/"
)
...
...
@@ -18,9 +18,9 @@ set (BIOEM_ICC_FLAGS "-xHost -O3 -fno-alias -fno-fnalias -unroll -g0 -ipo")
set
(
BIOEM_GCC_FLAGS
"-O3 -march=native -fweb -mfpmath=sse -frename-registers -minline-all-stringops -ftracer -funroll-loops -fpeel-loops -fprefetch-loop-arrays -ffast-math -ggdb"
)
if
(
"
${
CMAKE_CXX_COMPILER_ID
}
"
STREQUAL
"Intel"
)
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
${
BIOEM_ICC_FLAGS
}
"
)
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
${
BIOEM_ICC_FLAGS
}
"
)
else
()
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
${
BIOEM_GCC_FLAGS
}
"
)
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
${
BIOEM_GCC_FLAGS
}
"
)
endif
()
set
(
BIOEM_SOURCE_FILES
"bioem.cpp"
"main.cpp"
"map.cpp"
"model.cpp"
"param.cpp"
"cmodules/timer.cpp"
)
...
...
@@ -43,93 +43,94 @@ include_directories(${Boost_INCLUDE_DIRS})
###Find CUDA
set
(
BIOEM_CUDA_STATUS
"Disabled"
)
if
(
INCLUDE_CUDA
)
set
(
BIOEM_CUDA_STATUS
"Not Found"
)
find_package
(
CUDA
)
set
(
BIOEM_CUDA_STATUS
"Not Found"
)
find_package
(
CUDA
)
endif
()
if
(
CUDA_FOUND
)
if
(
CUDA_FORCE_GCC
)
cmake_minimum_required
(
VERSION 2.8.10.1
)
#Use GCC as host compiler for CUDA even though host compiler for other files is not GCC
set
(
CUDA_HOST_COMPILER gcc
)
endif
()
set
(
CUDA_NVCC_FLAGS
"
${
CUDA_NVCC_FLAGS
}
;--use_fast_math;-ftz=true;-O4;-Xptxas -O4"
)
list
(
APPEND CUDA_NVCC_FLAGS
"-gencode=arch=compute_13,code=sm_13"
)
list
(
APPEND CUDA_NVCC_FLAGS
"-gencode=arch=compute_20,code=sm_20"
)
list
(
APPEND CUDA_NVCC_FLAGS
"-gencode=arch=compute_20,code=sm_21"
)
list
(
APPEND CUDA_NVCC_FLAGS
"-gencode=arch=compute_30,code=sm_30"
)
list
(
APPEND CUDA_NVCC_FLAGS
"-gencode=arch=compute_35,code=sm_35"
)
add_definitions
(
-DWITH_CUDA
)
set
(
BIOEM_CUDA_STATUS
"Found"
)
if
(
CUDA_FORCE_GCC
)
cmake_minimum_required
(
VERSION 2.8.10.1
)
#Use GCC as host compiler for CUDA even though host compiler for other files is not GCC
set
(
CUDA_HOST_COMPILER gcc
)
endif
()
set
(
CUDA_NVCC_FLAGS
"
${
CUDA_NVCC_FLAGS
}
;--use_fast_math;-ftz=true;-O4;-Xptxas -O4"
)
list
(
APPEND CUDA_NVCC_FLAGS
"-gencode=arch=compute_13,code=sm_13"
)
list
(
APPEND CUDA_NVCC_FLAGS
"-gencode=arch=compute_20,code=sm_20"
)
list
(
APPEND CUDA_NVCC_FLAGS
"-gencode=arch=compute_20,code=sm_21"
)
list
(
APPEND CUDA_NVCC_FLAGS
"-gencode=arch=compute_30,code=sm_30"
)
list
(
APPEND CUDA_NVCC_FLAGS
"-gencode=arch=compute_35,code=sm_35"
)
list
(
APPEND CUDA_NVCC_FLAGS
"-gencode=arch=compute_52,code=sm_52"
)
add_definitions
(
-DWITH_CUDA
)
set
(
BIOEM_CUDA_STATUS
"Found"
)
endif
()
###Find OpenMP
set
(
BIOEM_OPENMP_STATUS
"Disabled"
)
if
(
INCLUDE_OPENMP
)
set
(
BIOEM_OPENMP_STATUS
"Not Found"
)
find_package
(
OpenMP
)
set
(
BIOEM_OPENMP_STATUS
"Not Found"
)
find_package
(
OpenMP
)
endif
()
if
(
OPENMP_FOUND
)
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
${
OpenMP_CXX_FLAGS
}
"
)
add_definitions
(
-DWITH_OPENMP
)
set
(
BIOEM_OPENMP_STATUS
"Found"
)
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
${
OpenMP_CXX_FLAGS
}
"
)
add_definitions
(
-DWITH_OPENMP
)
set
(
BIOEM_OPENMP_STATUS
"Found"
)
endif
()
###Find MPI
set
(
BIOEM_MPI_STATUS
"Disabled"
)
if
(
INCLUDE_MPI
)
set
(
BIOEM_MPI_STATUS
"Not Found"
)
find_package
(
MPI
)
set
(
BIOEM_MPI_STATUS
"Not Found"
)
find_package
(
MPI
)
endif
()
if
(
MPI_FOUND
)
include_directories
(
${
MPI_INCLUDE_PATH
}
)
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
${
MPI_COMPILE_FLAGS
}
${
MPI_LINK_FLAGS
}
"
)
add_definitions
(
-DWITH_MPI
)
set
(
BIOEM_MPI_STATUS
"Found"
)
include_directories
(
${
MPI_INCLUDE_PATH
}
)
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
${
MPI_COMPILE_FLAGS
}
${
MPI_LINK_FLAGS
}
"
)
add_definitions
(
-DWITH_MPI
)
set
(
BIOEM_MPI_STATUS
"Found"
)
endif
()
###Build Executable
if
(
CUDA_FOUND
)
set
(
BIOEM_TMP_CMAKE_CXX_FLAGS
${
CMAKE_CXX_FLAGS
}
)
if
(
CUDA_FORCE_GCC
)
#Hack to use GCC flags for GCC host compiler during NVCC compilation, although host compiler is in fact not GCC for other files
set
(
CMAKE_CXX_FLAGS
${
BIOEM_GCC_FLAGS
}
)
endif
()
cuda_add_executable
(
bioEM
${
BIOEM_SOURCE_FILES
}
bioem_cuda.cu
)
set
(
CMAKE_CXX_FLAGS
${
BIOEM_TMP_CMAKE_CXX_FLAGS
}
)
set
(
BIOEM_TMP_CMAKE_CXX_FLAGS
${
CMAKE_CXX_FLAGS
}
)
if
(
CUDA_FORCE_GCC
)
#Hack to use GCC flags for GCC host compiler during NVCC compilation, although host compiler is in fact not GCC for other files
set
(
CMAKE_CXX_FLAGS
${
BIOEM_GCC_FLAGS
}
)
endif
()
cuda_add_executable
(
bioEM
${
BIOEM_SOURCE_FILES
}
bioem_cuda.cu
)
set
(
CMAKE_CXX_FLAGS
${
BIOEM_TMP_CMAKE_CXX_FLAGS
}
)
else
()
add_executable
(
bioEM
${
BIOEM_SOURCE_FILES
}
)
add_executable
(
bioEM
${
BIOEM_SOURCE_FILES
}
)
endif
()
#Additional CXX Flags not used by CUDA compiler
#Additional CXX Flags not used by CUDA compiler
if
(
"
${
CMAKE_CXX_COMPILER_ID
}
"
STREQUAL
"Intel"
)
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
-std=c++11 -Wall -pedantic"
)
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
-std=c++11 -Wall -pedantic"
)
else
()
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
-std=c++11 -Wall -Wno-vla -Wno-unused-result -Wno-unused-local-typedefs -pedantic"
)
endif
()
if
(
NOT OPENMP_FOUND
)
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
-Wno-unknown-pragmas"
)
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
-Wno-vla -Wno-long-long -Wall -pedantic"
)
endif
()
###Add Libraries
if
(
CUDA_FOUND
)
cuda_add_cufft_to_target
(
bioEM
)
target_link_libraries
(
bioEM
${
CUDA_CUDA_LIBRARY
}
)
cuda_add_cufft_to_target
(
bioEM
)
#set(CUDA_LIBRARIES "/afs/ipp/.cs/cuda/6.5-gtx9/amd64_sles11/lib64/stubs/libcuda.so")
#cuda_add_library()
target_link_libraries
(
bioEM
${
CUDA_CUDA_LIBRARY
}
)
# target_link_libraries(bioEM ${CUDA_LIBRARIES})
endif
()
if
(
FFTWF_LIBRARIES
)
target_link_libraries
(
bioEM
${
FFTWF_LIBRARIES
}
)
target_link_libraries
(
bioEM
${
FFTWF_LIBRARIES
}
)
else
()
target_link_libraries
(
bioEM -L
${
FFTW_LIBDIR
}
-lfftw3 -lfftw3f
)
target_link_libraries
(
bioEM -L
${
FFTW_LIBDIR
}
-lfftw3 -lfftw3f
)
endif
()
target_link_libraries
(
bioEM -L
${
Boost_LIBRARY_DIRS
}
-lboost_program_options
)
if
(
MPI_FOUND
)
target_link_libraries
(
bioEM
${
MPI_LIBRARIES
}
)
target_link_libraries
(
bioEM
${
MPI_LIBRARIES
}
)
endif
()
###Show Status
...
...
@@ -137,14 +138,16 @@ message(STATUS "Build Status")
message
(
STATUS
"FFTW library:
${
FFTW_LIBDIR
}
"
)
message
(
STATUS
"Boost directory:
${
Boost_LIBRARY_DIRS
}
"
)
message
(
STATUS
"FFTW includedir:
${
FFTW_INCLUDEDIR
}
"
)
message
(
STATUS
"CUDA libraries:
${
CUDA_CUDA_LIBRARY
}
"
)
message
(
STATUS
"CUDA libraries:
${
CUDA_LIBRARIES
}
"
)
message
(
STATUS
"CUDA:
${
BIOEM_CUDA_STATUS
}
"
)
message
(
STATUS
"OpenMP:
${
BIOEM_OPENMP_STATUS
}
"
)
message
(
STATUS
"MPI:
${
BIOEM_MPI_STATUS
}
"
)
if
(
PRINT_CMAKE_VARIABLES
)
get_cmake_property
(
_variableNames VARIABLES
)
foreach
(
_variableName
${
_variableNames
}
)
message
(
STATUS
"
${
_variableName
}
=
${${
_variableName
}}
"
)
endforeach
()
get_cmake_property
(
_variableNames VARIABLES
)
foreach
(
_variableName
${
_variableNames
}
)
message
(
STATUS
"
${
_variableName
}
=
${${
_variableName
}}
"
)
endforeach
()
endif
()
bioem.cpp
View file @
9768552f
This diff is collapsed.
Click to expand it.
bioem_algorithm.h
View file @
9768552f
This diff is collapsed.
Click to expand it.
map.cpp
View file @
9768552f
...
...
@@ -5,6 +5,12 @@
See license statement for terms of distribution.
Note: This program contains subroutine "read_MRC" of the Situs 2.7.2 program.
Ref: Willy Wriggers. Using Situs for the Integration of Multi-Resolution Structures.
Biophysical Reviews, 2010, Vol. 2, pp. 21-27.
with a GPL lisences version XX.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
#include <fstream>
...
...
@@ -35,6 +41,7 @@ int bioem_RefMap::readRefMaps(bioem_param& param, const char* filemap)
int
allocsize
=
0
;
if
(
param
.
loadMap
)
{
//************** Loading Map from Binary file *******
FILE
*
fp
=
fopen
(
"maps.dump"
,
"rb"
);
if
(
fp
==
NULL
)
{
...
...
@@ -50,12 +57,14 @@ int bioem_RefMap::readRefMaps(bioem_param& param, const char* filemap)
}
else
if
(
readMRC
)
{
//************** Reading MRC file *******
ntotRefMap
=
0
;
if
(
readMultMRC
)
{
cout
<<
"Opening File with MRC list names: "
<<
filemap
<<
"
\n
"
;
//************** Reading Multiple MRC files *************
cout
<<
"Opening File with MRC list names: "
<<
filemap
<<
"
\n
"
;
ifstream
input
(
filemap
);
if
(
!
input
.
good
())
...
...
@@ -74,9 +83,9 @@ int bioem_RefMap::readRefMaps(bioem_param& param, const char* filemap)
input
.
getline
(
line
,
511
);
char
tmpVals
[
100
]
=
{
0
};
string
strline
(
line
);
string
strline
(
line
);
// cout << "MRC File name:" << strline << "\n";
// cout << "MRC File name:" << strline << "\n";
strncpy
(
tmpVals
,
line
,
99
);
...
...
@@ -87,10 +96,10 @@ int bioem_RefMap::readRefMaps(bioem_param& param, const char* filemap)
if
(
strcmp
(
tmpm
,
"XXX"
)
!=
0
)
{
indifile
=
strline
.
c_str
();
indifile
=
strline
.
c_str
();
size_t
foundpos
=
strline
.
find
(
"mrc"
);
size_t
endpos
=
strline
.
find_last_not_of
(
"
\t
"
);
//
size_t foundpos= strline.find("mrc");
//
size_t endpos = strline.find_last_not_of(" \t");
//Reading Multiple MRC
...
...
@@ -106,15 +115,15 @@ int bioem_RefMap::readRefMaps(bioem_param& param, const char* filemap)
else
{
string
strfilename
(
filemap
);
string
strfilename
(
filemap
);
size_t
foundpos
=
strfilename
.
find
(
"mrc"
);
size_t
endpos
=
strfilename
.
find_last_not_of
(
"
\t
"
);
size_t
foundpos
=
strfilename
.
find
(
"mrc"
);
size_t
endpos
=
strfilename
.
find_last_not_of
(
"
\t
"
);
if
(
foundpos
>
endpos
){
cout
<<
"Warining:::: mrc extension NOT dectected in file name::"
<<
filemap
<<
"
\n
"
;
cout
<<
"Warining:::: Are you sure you want to read an MRC?
\n
"
;
}
if
(
foundpos
>
endpos
){
cout
<<
"Warining:::: mrc extension NOT dectected in file name::"
<<
filemap
<<
"
\n
"
;
cout
<<
"Warining:::: Are you sure you want to read an MRC?
\n
"
;
}
read_MRC
(
filemap
,
param
);
cout
<<
"
\n
++++++++++++++++++++++++++++++++++++++++++
\n
"
;
...
...
@@ -123,6 +132,7 @@ int bioem_RefMap::readRefMaps(bioem_param& param, const char* filemap)
}
else
{
//************** Reading Text file *************
int
nummap
=
-
1
;
int
lasti
=
0
;
int
lastj
=
0
;
...
...
@@ -201,7 +211,7 @@ int bioem_RefMap::readRefMaps(bioem_param& param, const char* filemap)
maps
[
nummap
*
refMapSize
+
i
*
numPixels
+
j
]
=
(
myfloat_t
)
z
;
lasti
=
i
;
lastj
=
j
;
// cout << countpix << " " << param.param_device.NumberPixels*param.param_device.NumberPixels << "\n";
// cout << countpix << " " << param.param_device.NumberPixels*param.param_device.NumberPixels << "\n";
}
else
{
...
...
@@ -221,20 +231,21 @@ int bioem_RefMap::readRefMaps(bioem_param& param, const char* filemap)
cout
<<
"Particle Maps read from Standard File: "
<<
ntotRefMap
<<
"
\n
"
;
}
//Dumping Maps
//************* If Dumping Maps *********************
if
(
param
.
dumpMap
)
{
FILE
*
fp
=
fopen
(
"maps.dump"
,
"w+b"
);
if
(
fp
==
NULL
)
{
cout
<<
"Error opening dump file
\n
"
;
exit
(
1
);
}
fwrite
(
&
ntotRefMap
,
sizeof
(
ntotRefMap
),
1
,
fp
);
fwrite
(
maps
,
sizeof
(
myfloat_t
)
*
refMapSize
,
ntotRefMap
,
fp
);
fclose
(
fp
);
}
{
FILE
*
fp
=
fopen
(
"maps.dump"
,
"w+b"
);
if
(
fp
==
NULL
)
{
cout
<<
"Error opening dump file
\n
"
;
exit
(
1
);
}
fwrite
(
&
ntotRefMap
,
sizeof
(
ntotRefMap
),
1
,
fp
);
fwrite
(
maps
,
sizeof
(
myfloat_t
)
*
refMapSize
,
ntotRefMap
,
fp
);
fclose
(
fp
);
}
//*********** To Debug with few Maps ********************
if
(
getenv
(
"BIOEM_DEBUG_NMAPS"
))
{
...
...
@@ -250,7 +261,7 @@ int bioem_RefMap::readRefMaps(bioem_param& param, const char* filemap)
int
bioem_RefMap
::
PreCalculateMapsFFT
(
bioem_param
&
param
)
{
// **************************************************************************************
// ********** Routine that pre-calculates
Kernels
for Convolution **********************
// ********** Routine that pre-calculates
Reference maps FFT
for Convolution
/ Comparison
**********************
// ************************************************************************************
RefMapsFFT
=
new
mycomplex_t
[
ntotRefMap
*
param
.
FFTMapSize
];
...
...
@@ -320,17 +331,19 @@ int bioem_RefMap::precalculate(bioem_param& param, bioem& bio)
void
bioem_Probability
::
init
(
size_t
maps
,
size_t
angles
,
size_t
cc
,
bioem
&
bio
)
{
//********** Initializing pointers *******************
nMaps
=
maps
;
nAngles
=
angles
;
nCC
=
cc
;
ptr
=
bio
.
malloc_device_host
(
get_size
(
maps
,
angles
,
cc
,
bio
.
param
.
param_device
.
writeAngles
,
bio
.
param
.
param_device
.
writeCC
));
cout
<<
"Allocation #Maps "
<<
maps
<<
" #Angles "
<<
angles
<<
" #cross.cor "
<<
cc
<<
"
\n
"
;
//<< " == " << get_size(maps, angles, cc, bio.param.param_device.writeAngles, bio.param.param_device.writeCC)<< "\n";
//<< " == " << get_size(maps, angles, cc, bio.param.param_device.writeAngles, bio.param.param_device.writeCC)<< "\n";
set_pointers
();
}
void
bioem_Probability
::
copyFrom
(
bioem_Probability
*
from
,
bioem
&
bio
)
{
bioem_Probability_map
&
pProbMap
=
getProbMap
(
0
);
bioem_Probability_map
&
pProbMapFrom
=
from
->
getProbMap
(
0
);
memcpy
(
&
pProbMap
,
&
pProbMapFrom
,
from
->
nMaps
*
sizeof
(
bioem_Probability_map
));
...
...
@@ -358,6 +371,12 @@ void bioem_Probability::copyFrom(bioem_Probability* from, bioem& bio)
int
bioem_RefMap
::
read_MRC
(
const
char
*
filename
,
bioem_param
&
param
)
{
/* subroutine "read_MRC" of the Situs 2.7.2 program.
Ref: Willy Wriggers. Using Situs for the Integration of Multi-Resolution Structures.
Biophysical Reviews, 2010, Vol. 2, pp. 21-27.*/
myfloat_t
st
,
st2
;
unsigned
long
count
;
FILE
*
fin
;
...
...
@@ -453,7 +472,7 @@ int bioem_RefMap::read_MRC(const char* filename,bioem_param& param)
if
(
nr
!=
param
.
param_device
.
NumberPixels
||
nc
!=
param
.
param_device
.
NumberPixels
)
{
cout
<<
"PROBLEM INCONSISTENT NUMBER OF PIXELS IN MAPS AND INPUTFILE ( "
<<
param
.
param_device
.
NumberPixels
<<
", i "
<<
nc
<<
", j "
<<
nr
<<
")"
<<
"
\n
"
;
if
(
!
param
.
notsqure
)
exit
(
1
);
if
(
!
param
.
notsqure
)
exit
(
1
);
}
if
(
ntotRefMap
==
0
)
...
...
@@ -498,25 +517,25 @@ int bioem_RefMap::read_MRC(const char* filename,bioem_param& param)
}
else
{
if
(
!
param
.
notsqure
){
maps
[(
nmap
+
ntotRefMap
)
*
refMapSize
+
i
*
numPixels
+
j
]
=
(
myfloat_t
)
currfloat
;
st
+=
currfloat
;
st2
+=
currfloat
*
currfloat
;
}
else
{
if
(
i
>
595
&&
i
<
675
&&
j
>
1250
&&
j
<
1330
&&
nmap
>
230
&&
nmap
<
310
)
cout
<<
"map1: "
<<
i
<<
" "
<<
j
<<
" "
<<
nmap
<<
" "
<<
currfloat
<<
"
\n
"
;
}
if
(
!
param
.
notsqure
){
maps
[(
nmap
+
ntotRefMap
)
*
refMapSize
+
i
*
numPixels
+
j
]
=
(
myfloat_t
)
currfloat
;
st
+=
currfloat
;
st2
+=
currfloat
*
currfloat
;
}
else
{
if
(
i
>
595
&&
i
<
675
&&
j
>
1250
&&
j
<
1330
&&
nmap
>
230
&&
nmap
<
310
)
cout
<<
"map1: "
<<
i
<<
" "
<<
j
<<
" "
<<
nmap
<<
" "
<<
currfloat
<<
"
\n
"
;
}
}
}
if
(
param
.
notsqure
)
exit
(
1
);
if
(
param
.
notsqure
)
exit
(
1
);
//Normaling maps to zero mean and unit standard deviation
if
(
!
param
.
notnormmap
){
st
/=
float
(
nr
*
nc
);
st2
=
sqrt
(
st2
/
float
(
nr
*
nc
)
-
st
*
st
);
for
(
int
j
=
0
;
j
<
nr
;
j
++
)
for
(
int
i
=
0
;
i
<
nc
;
i
++
){
maps
[(
nmap
+
ntotRefMap
)
*
refMapSize
+
i
*
numPixels
+
j
]
=
maps
[(
nmap
+
ntotRefMap
)
*
refMapSize
+
i
*
numPixels
+
j
]
/
st2
-
st
/
st2
;
//cout <<"MAP:: " << i << " " << j << " " << maps[(nmap + ntotRefMap) * refMapSize + i * numPixels + j] << "\n";
}
}
st
/=
float
(
nr
*
nc
);
st2
=
sqrt
(
st2
/
float
(
nr
*
nc
)
-
st
*
st
);
for
(
int
j
=
0
;
j
<
nr
;
j
++
)
for
(
int
i
=
0
;
i
<
nc
;
i
++
){
maps
[(
nmap
+
ntotRefMap
)
*
refMapSize
+
i
*
numPixels
+
j
]
=
maps
[(
nmap
+
ntotRefMap
)
*
refMapSize
+
i
*
numPixels
+
j
]
/
st2
-
st
/
st2
;
//cout <<"MAP:: " << i << " " << j << " " << maps[(nmap + ntotRefMap) * refMapSize + i * numPixels + j] << "\n";
}
}
}
ntotRefMap
+=
ns
;
// cout << ntotRefMap << "\n";
...
...
model.cpp
View file @
9768552f
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
< BioEM software for Bayesian inference of Electron Microscopy images>
Copyright (C) 2014 Pilar Cossio, David Rohr and Gerhard Hummer.
Max Planck Institute of Biophysics, Frankfurt, Germany.
< BioEM software for Bayesian inference of Electron Microscopy images>
Copyright (C) 2014 Pilar Cossio, David Rohr and Gerhard Hummer.
Max Planck Institute of Biophysics, Frankfurt, Germany.
See license statement for terms of distribution.
See license statement for terms of distribution.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
...
...
@@ -20,289 +20,291 @@ using namespace std;
bioem_model
::
bioem_model
()
{
points
=
NULL
;
points
=
NULL
;
}
bioem_model
::~
bioem_model
()
{
if
(
points
)
free
(
points
);
if
(
points
)
free
(
points
);
}
int
bioem_model
::
readModel
(
bioem_param
&
param
,
const
char
*
filemodel
)
{
// **************************************************************************************
// ***************Reading reference Models either PDB or x,y,z,r,d format****************
// **************************************************************************************
// **************************************************************************************
// ***************Reading reference Models either PDB or x,y,z,r,d format****************
// **************************************************************************************
ofstream
exampleReadCoor
;
exampleReadCoor
.
open
(
"COORDREAD"
);
ofstream
exampleReadCoor
;
exampleReadCoor
.
open
(
"COORDREAD"
);
exampleReadCoor
<<
"Text --- Number ---- x ---- y ---- z ---- radius ----
density
\n
"
;
exampleReadCoor
<<
"Text --- Number ---- x ---- y ---- z ---- radius ----
number of electron
\n
"
;
int
allocsize
=
0
;
int
allocsize
=
0
;
std
::
ifstream
input
(
filemodel
);
if
(
readPDB
)
{
ifstream
input
(
filemodel
);
if
(
!
input
.
good
())
{
cout
<<
"PDB Failed to open file"
<<
endl
;
// pdbfilename << " ("<<filename<<")\n";
exit
(
0
);
}
char
line
[
512
]
=
{
0
};
char
tmpLine
[
512
]
=
{
0
};
int
numres
=
0
;
NormDen
=
0.0
;
string
strfilename
(
filemodel
);
std
::
ifstream
input
(
filemodel
);
if
(
readPDB
)
{
//************** Reading PDB files **********************
size_t
foundpos
=
strfilename
.
find
(
".pdb"
);
size_t
endpos
=
strfilename
.
find_last_not_of
(
"
\t
"
);
ifstream
input
(
filemodel
);
if
(
!
input
.
good
())
{
cout
<<
"PDB Failed to open file"
<<
endl
;
// pdbfilename << " ("<<filename<<")\n";
exit
(
0
);
}
if
(
foundpos
>
endpos
){
cout
<<
"Warining:::: .pdb extension NOT dectected in file name
\n
"
;
cout
<<
"Warining:::: Are you sure you want to read a PDB?
\n
"
;
}
char
line
[
512
]
=
{
0
};
char
tmpLine
[
512
]
=
{
0
}
;
int
numres
=
0
;
NormDen
=
0.0
;
string
strfilename
(
filemodel
);
// cout << " HERE " << filemodel ;
// for eachline in the file
while
(
!
input
.
eof
())
{
input
.
getline
(
line
,
511
);
strncpy
(
tmpLine
,
line
,
strlen
(
line
));
char
*
token
=
strtok
(
tmpLine
,
" "
);
if
(
strcmp
(
token
,
"ATOM"
)
==
0
)
// Optional,Mandatory if standard residues exist
{
/*
1-6 "ATOM "
7 - 11 Integer serial Atom serial number.
13 - 16 Atom name Atom name.
17 Character altLoc Alternate location indicator.
18 - 20 Residue name resName Residue name.
22 Character chainID Chain identifier.
23 - 26 Integer resSeq Residue sequence number.
27 AChar iCode Code for insertion of residues.
31 - 38 Real(8.3) x Orthogonal coordinates for X in
39 - 46 Real(8.3) y Orthogonal coordinates for Y in
47 - 54 Real(8.3) z Orthogonal coordinates for Z in
*/
char
name
[
5
]
=
{
0
};
char
resName
[
4
]
=
{
0
};
float
x
=
0.0
;
float
y
=
0.0
;
float
z
=
0.0
;
char
tmp
[
6
]
=
{
0
};
// parse name
strncpy
(
tmp
,
line
+
12
,
4
);
sscanf
(
tmp
,
"%s"
,
name
);
// parse resName
strncpy
(
tmp
,
line
+
17
,
3
);
sscanf
(
tmp
,
"%s"
,
resName
);
// parse x, y, z
char
tmpVals
[
36
]
=
{
0
};
strncpy
(
tmpVals
,
line
+
30
,
8
);
sscanf
(
tmpVals
,
"%f"
,
&
x
);
strncpy
(
tmpVals
,
line
+
38
,
8
);
sscanf
(
tmpVals
,
"%f"
,
&
y
);
strncpy
(
tmpVals
,
line
+
46
,
8
);
sscanf
(
tmpVals
,
"%f"
,
&
z
);
if
(
strcmp
(
name
,
"CA"
)
==
0
)
{
if
(
allocsize
==
0
)
{
allocsize
=
64
;
points
=
(
bioem_model_point
*
)
mallocchk
(
sizeof
(
bioem_model_point
)
*
allocsize
);
}
else
if
(
numres
+
1
>=
allocsize
)
{
allocsize
*=
2
;
points
=
(
bioem_model_point
*
)
reallocchk
(
points
,
sizeof
(
bioem_model_point
)
*
allocsize
);
}
//Getting residue Radius and electron density
points
[
numres
].
radius
=
getAminoAcidRad
(
resName
);
points
[
numres
].
density
=
getAminoAcidDensity
(
resName
);
NormDen
+=
points
[
numres
].
density
;
size_t
foundpos
=
strfilename
.
find
(
".pdb"
);
size_t
endpos
=
strfilename
.
find_last_not_of
(
"
\t
"
);
//Getting the coordinates
points
[
numres
].
point
.
pos
[
0
]
=
(
myfloat_t
)
x
;
points
[
numres
].
point
.
pos
[
1
]
=
(
myfloat_t
)
y
;
points
[
numres
].
point
.
pos
[
2
]
=
(
myfloat_t
)
z
;
exampleReadCoor
<<
"RESIDUE "
<<
numres
<<
" "
<<
points
[
numres
].
point
.
pos
[
0
]
<<
" "
<<
points
[
numres
].
point
.
pos
[
1
]
<<
" "
<<
points
[
numres
].
point
.
pos
[
2
]
<<
" "
<<
points
[
numres
].
radius
<<
" "
<<
points
[
numres
].
density
<<
"
\n
"
;
numres
++
;
}
}
if
(
foundpos
>
endpos
){
cout
<<
"Warining:::: .pdb extension NOT dectected in file name
\n
"
;
cout
<<
"Warining:::: Are you sure you want to read a PDB?
\n
"
;
}
}
nPointsModel
=
numres
;
cout
<<
"Protein structure read from PDB
\n
"
;
}
else
//Reading model from FILE FORMAT x,y,z,rad,density
// cout << " HERE " << filemodel ;
// for eachline in the file
while
(
!
input
.
eof
())
{
char
line
[
128
];
int
numres
=
0
;
NormDen
=
0.0
;
string
strfilename
(
filemodel
);
size_t
foundpos
=
strfilename
.
find
(
".pdb"
);
size_t
endpos
=
strfilename
.
find_last_not_of
(
"
\t
"
);
if
(
foundpos
<
endpos
){
cout
<<
"Warining:::: .pdb dectected in file name whilst using text read
\n
"
;
cout
<<
"Warining:::: Are you sure you do not need --ReadPDB?
\n
"
;
}
FILE
*
file
=
fopen
(
filemodel
,
"r"
);
if
(
file
==
NULL
)
{
cout
<<
"Error opening file "
<<
filemodel
<<
"
\n
"
;
exit
(
1
);
}
while
(
fgets
(
line
,
sizeof
line
,
file
)
!=
NULL
)
input
.
getline
(
line
,
511
);
strncpy
(
tmpLine
,
line
,
strlen
(
line
));
char
*
token
=
strtok
(
tmpLine
,
" "
);
if
(
strcmp
(
token
,
"ATOM"
)
==
0
)
// Optional,Mandatory if standard residues exist
{
/*
1-6 "ATOM "