13 #include <protocols/viewer/viewers.hh>
15 #include <protocols/moves/MonteCarlo.hh>
16 #include <protocols/moves/Mover.hh>
18 #include <core/types.hh>
20 #include <core/chemical/AA.hh>
21 #include <core/chemical/ChemicalManager.hh>
22 #include <core/chemical/ResidueTypeSet.fwd.hh>
23 #include <core/scoring/ScoreFunction.hh>
24 #include <core/scoring/ScoreFunctionFactory.hh>
25 #include <core/pose/Pose.hh>
26 #include <core/pose/PDBInfo.hh>
27 #include <core/scoring/electron_density/ElectronDensity.hh>
28 #include <core/import_pose/import_pose.hh>
29 #include <protocols/electron_density/util.hh>
30 #include <protocols/electron_density/SetupForDensityScoringMover.hh>
43 #include <core/kinematics/Jump.hh>
58 using namespace basic;
59 using namespace utility;
60 using namespace protocols;
83 using core::
scoring::electron_density::poseCoords;
84 using core::
scoring::electron_density::poseCoord;
90 std::string atmid = line.substr(12,4);
91 while ( !atmid.empty() && atmid[0] ==
' ' ) atmid = atmid.substr(1,atmid.size()-1);
92 while ( !atmid.empty() && atmid[atmid.size()-1] ==
' ' ) atmid = atmid.substr(0,atmid.size()-1);
93 std::string resname = line.substr(17,3);
94 while ( !resname.empty() && resname[0] ==
' ' ) resname = resname.substr(1,resname.size()-1);
95 while ( !resname.empty() && resname[resname.size()-1] ==
' ' ) resname = resname.substr(0,resname.size()-1);
99 if ( line.substr(0,4) ==
"ATOM" ) {
100 type = atmid.substr(0,2);
101 if ( isdigit(type[0]) ) {
103 if ( !isdigit(type[1]) ) type = atmid.substr(1,1);
104 else type = atmid.substr(2,1);
105 }
else if ( (line[12] ==
' ' && type!=
"Zn" && type!=
"Fe" && type!=
"ZN" && type!=
"FE")
106 || isdigit(type[1]) ) {
107 type = atmid.substr(0,1);
110 if ( resname.substr(0,2) ==
"AS" || resname[0] ==
'N' ) {
111 if ( atmid ==
"AD1" ) type =
"O";
112 if ( atmid ==
"AD2" ) type =
"N";
114 if ( resname.substr(0,3) ==
"HIS" || resname[0] ==
'H' ) {
115 if ( atmid ==
"AD1" || atmid ==
"AE2" ) type =
"N";
116 if ( atmid ==
"AE1" || atmid ==
"AD2" ) type =
"C";
118 if ( resname.substr(0,2) ==
"GL" || resname[0] ==
'Q' ) {
119 if ( atmid ==
"AE1" ) type =
"O";
120 if ( atmid ==
"AE2" ) type =
"N";
122 if ( atmid.substr(0,2) ==
"HH" ) {
125 if ( atmid.substr(0,2) ==
"HD" || atmid.substr(0,2) ==
"HE" || atmid.substr(0,2) ==
"HG" ) {
129 if ( isalpha(atmid[0]) ) {
130 if ( atmid.size() > 2 && (atmid[2] ==
'\0' || atmid[2] ==
' ') ) {
131 type = atmid.substr(0,2);
132 }
else if ( atmid[0] ==
'A' ) {
133 type = atmid.substr(1, atmid.size() - 1);
135 type = atmid.substr(0,1);
137 }
else if ( atmid[0] ==
' ' ) {
138 type = atmid.substr(1,1);
140 type = atmid.substr(1,2);
143 if ( atmid == resname ) {
145 if ( type.size() == 2 ) type[1] = toupper(type[1]);
146 }
else if ( resname ==
"ADR" || resname ==
"COA" || resname ==
"FAD" ||
147 resname ==
"GPG" || resname ==
"NAD" || resname ==
"NAL" ||
148 resname ==
"NDP" || resname ==
"ABA" ) {
149 if ( type.size() > 1 ) type = type.substr(0,1);
150 }
else if ( isdigit(type[0]) ) {
151 type = type.substr(1,1);
152 }
else if ( type.size() > 1 && isdigit(type[1]) ) {
153 type = type.substr(0,1);
154 }
else if ( type.size() > 1 && isalpha(type[1]) ) {
155 if ( type[0] ==
'O' && type[1] ==
'H' ) {
156 type = type.substr(0,1);
157 }
else if ( islower(type[1]) ) {
158 type[1] = toupper(type[1]);
169 std::ifstream inpdb(filename.c_str());
173 if ( buf.substr(0,4)!=
"ATOM" && buf.substr(0,6)!=
"HETATM" )
continue;
176 atom_i.x_[0] = atof(buf.substr(30,8).c_str());
177 atom_i.x_[1] = atof(buf.substr(38,8).c_str());
178 atom_i.x_[2] = atof(buf.substr(46,8).c_str());
179 atom_i.B_ = atof(buf.substr(60,6).c_str());
182 if ( atom_i.elt_ ==
"H" )
continue;
184 atmlist.push_back( atom_i );
193 using namespace protocols::moves;
196 using namespace basic::options::OptionKeys;
199 Size nresobins =
option[ denstools::nresbins ]();
200 bool bin_squared =
option[ denstools::bin_squared ]();
214 bool perres =
option[ denstools::perres ]();
220 if ( hires == 0.0 ) hires = core::scoring::electron_density::getDensityMap().maxNominalRes();
221 if ( truncate_hires == 0.0 ) truncate_hires = core::scoring::electron_density::getDensityMap().maxNominalRes();
228 truncate_lowres = 1.0/truncate_lowres;
229 truncate_hires = 1.0/truncate_hires;
232 std::cout <<
"Stage 1: FFT rho_obs" << std::endl;
234 core::scoring::electron_density::getDensityMap().getIntensities(FrhoO, nresobins,
lowres, hires, mapI, bin_squared);
237 std::cout <<
"Stage 2: model processing" << std::endl;
240 core::scoring::electron_density::getDensityMap().getResolutionBins(nresobins,
lowres, hires, resobins, resobin_counts, bin_squared);
243 if (
option[ denstools::truncate_map ] ) {
245 for (
int i=1; i<=(
int)mapI.size(); ++i ) {
246 if ( resobins[i] <= truncate_lowres || resobins[i] >= truncate_hires ) {
253 core::scoring::electron_density::getDensityMap().scaleIntensities( trunc,
lowres, hires, bin_squared );
254 core::scoring::electron_density::getDensityMap().writeMRC(
"map_trunc.mrc" );
255 std::cout <<
"Wrote truncated map" << std::endl;
266 std::cout <<
" : calc rho_c" << std::endl;
267 core::scoring::electron_density::getDensityMap().calcRhoC(
pose, mask_resolution, rhoC, rhoMask );
271 if (
option[ denstools::maskonly ] ) {
277 for (
int i=0; i<rhoC.u1()*rhoC.u2()*rhoC.u3(); ++i ) {
278 rhoOmask[i] *= core::scoring::electron_density::getDensityMap().get_data()[i];
281 core::scoring::electron_density::getDensityMap().set_data(rhoOmask);
287 if (
option[ denstools::cutonly ] ) {
293 for (
int i=0; i<rhoC.u1()*rhoC.u2()*rhoC.u3(); ++i ) {
294 rhoOmask[i] = (1-rhoOmask[i])*core::scoring::electron_density::getDensityMap().get_data()[i];
297 core::scoring::electron_density::getDensityMap().set_data(rhoOmask);
311 for (
int i=0; i<rhoC.u1()*rhoC.u2()*rhoC.u3(); ++i ) {
312 rhoOmask[i] *= core::scoring::electron_density::getDensityMap().get_data()[i];
317 std::cout <<
" : get intensities" << std::endl;
318 core::scoring::electron_density::getDensityMap().getIntensities(FrhoC, nresobins,
lowres, hires, modelI, bin_squared);
319 core::scoring::electron_density::getDensityMap().getIntensities(FrhoMask, nresobins,
lowres, hires, maskI, bin_squared);
320 core::scoring::electron_density::getDensityMap().getIntensities(FrhoOmask, nresobins,
lowres, hires, maskedmapI, bin_squared);
325 std::cout <<
"Stage 3: map vs map" << std::endl;
326 core::scoring::electron_density::ElectronDensity mapAlt;
327 bool usermap =
option[ edensity::alt_mapfile ].user();
332 std::cout <<
" : load alt_map + FFT" << std::endl;
333 mapAlt.readMRCandResize( mapfile , mapreso , mapsampling );
337 std::cout <<
" : mask alt_map" << std::endl;
339 for (
int i=0; i<rhoC.u1()*rhoC.u2()*rhoC.u3(); ++i ) {
340 rhoO2mask[i] *= mapAlt.get_data()[i];
347 core::scoring::electron_density::getDensityMap().getFSC(FrhoO, FrhoO2, nresobins,
lowres, hires, mapmapFSC, bin_squared);
351 core::scoring::electron_density::getDensityMap().getFSC(FrhoOmask, FrhoO2mask, nresobins,
lowres, hires, mapmapFSC, bin_squared);
356 Real modelMapFSCsum=0, maskedModelMapFSCsum=0, RSCC=0;
358 std::cout <<
"Stage 4: model vs map" << std::endl;
362 core::chemical::ResidueTypeSetCAP rsd_set;
363 rsd_set = core::chemical::ChemicalManager::get_instance()->residue_type_set(
"fa_standard" );
364 core::import_pose::pose_from_file( fullpose,
pdbfile , core::import_pose::PDB_file);
367 perResCC.resize( nres, 0.0 );
369 protocols::electron_density::SetupForDensityScoringMoverOP dockindens(
new protocols::electron_density::SetupForDensityScoringMover );
370 dockindens->apply( fullpose );
372 core::scoring::electron_density::getDensityMap().set_nres( nres );
373 core::scoring::electron_density::getDensityMap().setScoreWindowContext(
true );
374 core::scoring::electron_density::getDensityMap().setWindow(
option[ denstools::rscc_wdw ]() );
376 core::scoring::ScoreFunctionOP
scorefxn = core::scoring::get_score_function();
377 scorefxn->set_weight( core::scoring::elec_dens_window, 1.0 );
378 (*scorefxn)(fullpose);
381 perResCC[r] = core::scoring::electron_density::getDensityMap().matchRes( r , fullpose.residue(r), fullpose, NULL ,
false);
386 core::scoring::electron_density::getDensityMap().getFSC(FrhoO, FrhoC, nresobins,
lowres, hires, modelmapFSC, bin_squared);
387 core::scoring::electron_density::getDensityMap().getFSC(FrhoOmask, FrhoC, nresobins,
lowres, hires, maskedModelMapFSC, bin_squared);
390 RSCC = core::scoring::electron_density::getDensityMap().getRSCC( rhoC, rhoMask );
393 for (
Size i=1; i<=resobins.size(); ++i ) {
394 modelMapFSCsum += modelmapFSC[i];
395 maskedModelMapFSCsum += maskedModelMapFSC[i];
397 modelMapFSCsum /= resobins.size();
398 maskedModelMapFSCsum /= resobins.size();
404 if ( mapI.size() )
std::cerr <<
" I_map";
405 if ( maskedmapI.size() )
std::cerr <<
" I_map_masked";
406 if ( modelI.size() )
std::cerr <<
" I_model" ;
407 if ( maskI.size() )
std::cerr <<
" I_mask" ;
408 if ( mapmapFSC.size() )
std::cerr <<
" FSC_mapmap";
409 if ( modelmapFSC.size() )
std::cerr <<
" FSC_modelmap";
410 if ( maskedModelMapFSC.size() )
std::cerr <<
" FSC_maskedmodelmap";
412 for (
Size i=1; i<=resobins.size(); ++i ) {
413 std::cerr << resobins[i] <<
" " << resobin_counts[i];
414 if ( mapI.size() )
std::cerr <<
" " << mapI[i];
415 if ( maskedmapI.size() )
std::cerr <<
" " << maskedmapI[i];
416 if ( modelI.size() )
std::cerr <<
" " << modelI[i];
417 if ( maskI.size() )
std::cerr <<
" " << maskI[i];
418 if ( mapmapFSC.size() )
std::cerr <<
" " << mapmapFSC[i];
419 if ( modelmapFSC.size() )
std::cerr <<
" " << modelmapFSC[i];
420 if ( maskedModelMapFSC.size() )
std::cerr <<
" " << maskedModelMapFSC[i];
426 if ( userpose &&
option[ denstools::dump_map_and_mask ]() ) {
427 core::scoring::electron_density::getDensityMap().set_data(rhoOmask);
428 core::scoring::electron_density::getDensityMap().writeMRC(
"map_masked.mrc" );
430 core::scoring::electron_density::getDensityMap().set_data(rhoC);
431 core::scoring::electron_density::getDensityMap().writeMRC(
"model_dens.mrc" );
433 core::scoring::electron_density::getDensityMap().set_data(rhoMask);
434 core::scoring::electron_density::getDensityMap().writeMRC(
"model_mask.mrc" );
437 if ( userpose &&
option[ denstools::perres ]() ) {
438 for (
core::uint r = 1; r <= perResCC.size(); ++r ) {
439 std::cerr <<
"PERRESCC residue " << r <<
" " << perResCC[r] << std::endl;
445 std::cerr <<
pdbfile <<
"RSCC/FSC/FSCmask: " << RSCC <<
" " << modelMapFSCsum <<
" " << maskedModelMapFSCsum;
454 main(
int argc,
char * argv [] )
459 NEW_OPT(denstools::hires,
"high res limit", 0.0);
460 NEW_OPT(edensity::alt_mapfile,
"alt mapfile",
"");
461 NEW_OPT(denstools::nresbins,
"# resolution bins for statistics", 200);
462 NEW_OPT(denstools::truncate_map,
"dump map with map I scaled to to model I?",
false);
463 NEW_OPT(denstools::truncate_lowres,
"low res truncation", 1000.0);
464 NEW_OPT(denstools::truncate_hires,
"high res truncation", 0.0);
465 NEW_OPT(denstools::dump_map_and_mask,
"dump mrc of rho_calc and eps_calc",
false);
466 NEW_OPT(denstools::mask,
"mask all calcs",
false);
467 NEW_OPT(denstools::mask_modelmap,
"mask model-map calcs only",
false);
468 NEW_OPT(denstools::mask_resolution,
"radius for masking", 0.0);
469 NEW_OPT(denstools::perres,
"output per-residue stats",
false);
471 NEW_OPT(denstools::super_verbose,
"dump a lot of extra output",
false);
472 NEW_OPT(denstools::bin_squared,
"bin uniformly in 1/res^2 (default bins 1/res)",
false);
473 NEW_OPT(denstools::rscc_wdw,
"sliding window to calculate rscc", 3);
474 NEW_OPT(denstools::maskonly,
"mask",
false);
475 NEW_OPT(denstools::cutonly,
"cut",
false);
480 std::cout <<
"caught exception " << e.
msg() << std::endl;
ocstream cerr(std::cerr)
Wrapper around std::cerr.
#define utility_exit_with_message(m)
Exit with file + line + message.
virtual std::string const msg() const
BooleanOptionKey const lowres
BooleanOptionKey const scoring
std::istream & getline(std::istream &stream, Fstring &s)
Get Line from Stream.
void init(int argc, char *argv[])
Command line init() version.
#define runtime_assert(_Expression)
Assert that the condition holds. Evaluated for both debug and release builds.
Random number generator system.
std::string start_file()
kind of like the old -s – just one file
BooleanOptionKey const edensity
void fft3(ObjexxFCL::FArray3D< std::complex< double > > const &X, ObjexxFCL::FArray3D< std::complex< double > > &fX)
3D fft c->c double
basic::options::OptionKeys collection
StringOptionKey const mapfile
RealOptionKey const grid_spacing("edensity:grid_spacing")
macros to define options on a per-application basis at the top of app files (those with main) ...
StringOptionKey const mapfile("edensity:mapfile")
basic::options::OptionKeys collection
basic::options::OptionKeys collection
rule< Scanner, options_closure::context_t > options
BooleanOptionKey const verbose
#define NEW_OPT(akey, help, adef)
ocstream cout(std::cout)
Wrapper around std::cout.
vector1: std::vector with 1-based indexing
Common numeric constants in varying precisions.
#define OPT_1GRP_KEY(type, grp, key)
Program options global and initialization function.
Fast (x,y,z)-coordinate numeric vector.
RealOptionKey const mapreso("edensity:mapreso")
FileVectorOptionKey const s("in:file:s")
RealOptionKey const mapreso
rule< Scanner, option_closure::context_t > option
FArray3D: Fortran-Compatible 3D Array.