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>
48 #include <basic/options/keys/in.OptionKeys.gen.hh>
49 #include <basic/options/keys/edensity.OptionKeys.gen.hh>
58 using namespace basic;
59 using namespace utility;
60 using namespace protocols;
81 using core::scoring::electron_density::poseCoords;
82 using core::scoring::electron_density::poseCoord;
88 std::string atmid = line.substr(12,4);
89 while ( !atmid.empty() && atmid[0] ==
' ' ) atmid = atmid.substr(1,atmid.size()-1);
90 while ( !atmid.empty() && atmid[atmid.size()-1] ==
' ' ) atmid = atmid.substr(0,atmid.size()-1);
91 std::string resname = line.substr(17,3);
92 while ( !resname.empty() && resname[0] ==
' ' ) resname = resname.substr(1,resname.size()-1);
93 while ( !resname.empty() && resname[resname.size()-1] ==
' ' ) resname = resname.substr(0,resname.size()-1);
97 if ( line.substr(0,4) ==
"ATOM" ) {
98 type = atmid.substr(0,2);
99 if ( isdigit(type[0]) ) {
101 if ( !isdigit(type[1]) ) type = atmid.substr(1,1);
102 else type = atmid.substr(2,1);
103 }
else if ( (line[12] ==
' ' && type!=
"Zn" && type!=
"Fe" && type!=
"ZN" && type!=
"FE")
104 || isdigit(type[1]) ) {
105 type = atmid.substr(0,1);
108 if ( resname.substr(0,2) ==
"AS" || resname[0] ==
'N' ) {
109 if ( atmid ==
"AD1" ) type =
"O";
110 if ( atmid ==
"AD2" ) type =
"N";
112 if ( resname.substr(0,3) ==
"HIS" || resname[0] ==
'H' ) {
113 if ( atmid ==
"AD1" || atmid ==
"AE2" ) type =
"N";
114 if ( atmid ==
"AE1" || atmid ==
"AD2" ) type =
"C";
116 if ( resname.substr(0,2) ==
"GL" || resname[0] ==
'Q' ) {
117 if ( atmid ==
"AE1" ) type =
"O";
118 if ( atmid ==
"AE2" ) type =
"N";
120 if ( atmid.substr(0,2) ==
"HH" ) {
123 if ( atmid.substr(0,2) ==
"HD" || atmid.substr(0,2) ==
"HE" || atmid.substr(0,2) ==
"HG" ) {
127 if ( isalpha(atmid[0]) ) {
128 if ( atmid.size() > 2 && (atmid[2] ==
'\0' || atmid[2] ==
' ') ) {
129 type = atmid.substr(0,2);
130 }
else if ( atmid[0] ==
'A' ) {
131 type = atmid.substr(1, atmid.size() - 1);
133 type = atmid.substr(0,1);
135 }
else if ( atmid[0] ==
' ' ) {
136 type = atmid.substr(1,1);
138 type = atmid.substr(1,2);
141 if ( atmid == resname ) {
143 if ( type.size() == 2 ) type[1] = toupper(type[1]);
144 }
else if ( resname ==
"ADR" || resname ==
"COA" || resname ==
"FAD" ||
145 resname ==
"GPG" || resname ==
"NAD" || resname ==
"NAL" ||
146 resname ==
"NDP" || resname ==
"ABA" ) {
147 if ( type.size() > 1 ) type = type.substr(0,1);
148 }
else if ( isdigit(type[0]) ) {
149 type = type.substr(1,1);
150 }
else if ( type.size() > 1 && isdigit(type[1]) ) {
151 type = type.substr(0,1);
152 }
else if ( type.size() > 1 && isalpha(type[1]) ) {
153 if ( type[0] ==
'O' && type[1] ==
'H' ) {
154 type = type.substr(0,1);
155 }
else if ( islower(type[1]) ) {
156 type[1] = toupper(type[1]);
167 std::ifstream inpdb(filename.c_str());
171 if ( buf.substr(0,4)!=
"ATOM" && buf.substr(0,6)!=
"HETATM" )
continue;
174 atom_i.x_[0] = atof(buf.substr(30,8).c_str());
175 atom_i.x_[1] = atof(buf.substr(38,8).c_str());
176 atom_i.x_[2] = atof(buf.substr(46,8).c_str());
177 atom_i.B_ = atof(buf.substr(60,6).c_str());
180 if ( atom_i.elt_ ==
"H" )
continue;
182 atmlist.push_back( atom_i );
191 using namespace protocols::moves;
192 using namespace scoring;
194 using namespace basic::options::OptionKeys;
197 Size nresobins =
option[ denstools::nresbins ]();
198 bool bin_squared =
option[ denstools::bin_squared ]();
212 bool perres =
option[ denstools::perres ]();
218 if ( hires == 0.0 ) hires = core::scoring::electron_density::getDensityMap().maxNominalRes();
219 if ( truncate_hires == 0.0 ) truncate_hires = core::scoring::electron_density::getDensityMap().maxNominalRes();
226 truncate_lowres = 1.0/truncate_lowres;
227 truncate_hires = 1.0/truncate_hires;
230 std::cout <<
"Stage 1: FFT rho_obs" << std::endl;
232 core::scoring::electron_density::getDensityMap().getIntensities(FrhoO, nresobins, lowres, hires, mapI, bin_squared);
235 std::cout <<
"Stage 2: model processing" << std::endl;
241 if ( userpose && !
option[ denstools::truncate_map ] ) {
245 std::cout <<
" : calc rho_c + FFT" << std::endl;
246 core::scoring::electron_density::getDensityMap().calcRhoC(
pose, mask_radius, rhoC, rhoMask );
253 for (
int i=0; i<rhoC.u1()*rhoC.u2()*rhoC.u3(); ++i ) {
254 rhoOmask[i] *= core::scoring::electron_density::getDensityMap().data()[i];
259 std::cout <<
" : get intensities" << std::endl;
260 core::scoring::electron_density::getDensityMap().getIntensities(FrhoC, nresobins, lowres, hires, modelI, bin_squared);
261 core::scoring::electron_density::getDensityMap().getIntensities(FrhoMask, nresobins, lowres, hires, maskI, bin_squared);
262 core::scoring::electron_density::getDensityMap().getIntensities(FrhoOmask, nresobins, lowres, hires, maskedmapI, bin_squared);
265 core::scoring::electron_density::getDensityMap().getResolutionBins(nresobins, lowres, hires, resobins, resobin_counts, bin_squared);
268 if (
option[ denstools::truncate_map ] ) {
270 for (
int i=1; i<=(
int)mapI.size(); ++i ) {
271 if ( resobins[i] <= truncate_lowres || resobins[i] >= truncate_hires ) {
278 core::scoring::electron_density::getDensityMap().scaleIntensities( trunc, lowres, hires, bin_squared );
279 core::scoring::electron_density::getDensityMap().writeMRC(
"map_trunc.mrc" );
280 std::cout <<
"Wrote truncated map" << std::endl;
285 std::cout <<
"Stage 3: map vs map" << std::endl;
286 core::scoring::electron_density::ElectronDensity mapAlt;
287 bool usermap =
option[ edensity::alt_mapfile ].user();
289 std::string mapfile =
option[ edensity::alt_mapfile ];
292 std::cout <<
" : load alt_map + FFT" << std::endl;
293 mapAlt.readMRCandResize( mapfile , mapreso , mapsampling );
297 std::cout <<
" : mask alt_map" << std::endl;
299 for (
int i=0; i<rhoC.u1()*rhoC.u2()*rhoC.u3(); ++i ) {
300 rhoO2mask[i] *= mapAlt.data()[i];
307 core::scoring::electron_density::getDensityMap().getFSC(FrhoO, FrhoO2, nresobins, lowres, hires, mapmapFSC, bin_squared);
311 core::scoring::electron_density::getDensityMap().getFSC(FrhoOmask, FrhoO2mask, nresobins, lowres, hires, mapmapFSC, bin_squared);
316 Real modelMapFSCsum=0, maskedModelMapFSCsum=0, RSCC=0;
318 std::cout <<
"Stage 4: model vs map" << std::endl;
322 core::chemical::ResidueTypeSetCAP rsd_set;
323 rsd_set = core::chemical::ChemicalManager::get_instance()->residue_type_set(
"fa_standard" );
324 core::import_pose::pose_from_pdb( fullpose,
pdbfile );
327 perResCC.resize( nres, 0.0 );
329 protocols::electron_density::SetupForDensityScoringMoverOP dockindens(
new protocols::electron_density::SetupForDensityScoringMover );
330 dockindens->apply( fullpose );
332 core::scoring::electron_density::getDensityMap().set_nres( nres );
333 core::scoring::electron_density::getDensityMap().setScoreWindowContext(
true );
334 core::scoring::electron_density::getDensityMap().setWindow(
option[ denstools::rscc_wdw ]() );
336 core::scoring::ScoreFunctionOP
scorefxn = core::scoring::get_score_function();
337 scorefxn->set_weight( core::scoring::elec_dens_window, 1.0 );
338 (*scorefxn)(fullpose);
341 perResCC[r] = core::scoring::electron_density::getDensityMap().matchRes( r , fullpose.residue(r), fullpose, NULL ,
false);
346 core::scoring::electron_density::getDensityMap().getFSC(FrhoO, FrhoC, nresobins, lowres, hires, modelmapFSC, bin_squared);
347 core::scoring::electron_density::getDensityMap().getFSC(FrhoOmask, FrhoC, nresobins, lowres, hires, maskedModelMapFSC, bin_squared);
350 RSCC = core::scoring::electron_density::getDensityMap().getRSCC( rhoC, rhoMask );
353 for (
Size i=1; i<=resobins.size(); ++i ) {
354 modelMapFSCsum += modelmapFSC[i];
355 maskedModelMapFSCsum += maskedModelMapFSC[i];
357 modelMapFSCsum /= resobins.size();
358 maskedModelMapFSCsum /= resobins.size();
364 if ( mapI.size() )
std::cerr <<
" I_map";
365 if ( maskedmapI.size() )
std::cerr <<
" I_map_masked";
366 if ( modelI.size() )
std::cerr <<
" I_model" ;
367 if ( maskI.size() )
std::cerr <<
" I_mask" ;
368 if ( mapmapFSC.size() )
std::cerr <<
" FSC_mapmap";
369 if ( modelmapFSC.size() )
std::cerr <<
" FSC_modelmap";
370 if ( maskedModelMapFSC.size() )
std::cerr <<
" FSC_maskedmodelmap";
372 for (
Size i=1; i<=resobins.size(); ++i ) {
373 std::cerr << resobins[i] <<
" " << resobin_counts[i];
374 if ( mapI.size() )
std::cerr <<
" " << mapI[i];
375 if ( maskedmapI.size() )
std::cerr <<
" " << maskedmapI[i];
376 if ( modelI.size() )
std::cerr <<
" " << modelI[i];
377 if ( maskI.size() )
std::cerr <<
" " << maskI[i];
378 if ( mapmapFSC.size() )
std::cerr <<
" " << mapmapFSC[i];
379 if ( modelmapFSC.size() )
std::cerr <<
" " << modelmapFSC[i];
380 if ( maskedModelMapFSC.size() )
std::cerr <<
" " << maskedModelMapFSC[i];
386 if ( userpose &&
option[ denstools::dump_map_and_mask ]() ) {
387 core::scoring::electron_density::getDensityMap().set_data(rhoOmask);
388 core::scoring::electron_density::getDensityMap().writeMRC(
"map_masked.mrc" );
390 core::scoring::electron_density::getDensityMap().set_data(rhoC);
391 core::scoring::electron_density::getDensityMap().writeMRC(
"model_dens.mrc" );
393 core::scoring::electron_density::getDensityMap().set_data(rhoMask);
394 core::scoring::electron_density::getDensityMap().writeMRC(
"model_mask.mrc" );
397 if ( userpose &&
option[ denstools::perres ]() ) {
398 for (
core::uint r = 1; r <= perResCC.size(); ++r ) {
399 std::cerr <<
"PERRESCC residue " << r <<
" " << perResCC[r] << std::endl;
405 std::cerr <<
pdbfile <<
"RSCC/FSC/FSCmask: " << RSCC <<
" " << modelMapFSCsum <<
" " << maskedModelMapFSCsum;
414 main(
int argc,
char * argv [] )
418 NEW_OPT(denstools::lowres,
"low res limit", 1000.0);
419 NEW_OPT(denstools::hires,
"high res limit", 0.0);
420 NEW_OPT(edensity::alt_mapfile,
"alt mapfile",
"");
421 NEW_OPT(denstools::nresbins,
"# resolution bins for statistics", 200);
422 NEW_OPT(denstools::truncate_map,
"dump map with map I scaled to to model I?",
false);
423 NEW_OPT(denstools::truncate_lowres,
"low res truncation", 1000.0);
424 NEW_OPT(denstools::truncate_hires,
"high res truncation", 0.0);
425 NEW_OPT(denstools::dump_map_and_mask,
"dump mrc of rho_calc and eps_calc",
false);
426 NEW_OPT(denstools::mask,
"mask all calcs",
false);
427 NEW_OPT(denstools::mask_modelmap,
"mask model-map calcs only",
false);
428 NEW_OPT(denstools::mask_radius,
"radius for masking", 0.0);
429 NEW_OPT(denstools::perres,
"output per-residue stats",
false);
431 NEW_OPT(denstools::super_verbose,
"dump a lot of extra output",
false);
432 NEW_OPT(denstools::bin_squared,
"bin uniformly in 1/res^2 (default bins 1/res)",
false);
433 NEW_OPT(denstools::rscc_wdw,
"sliding window to calculate rscc", 3);
438 std::cout <<
"caught exception " << e.
msg() << std::endl;
ocstream cerr(std::cerr)
Wrapper around std::cerr.
virtual std::string const msg() const
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
void fft3(ObjexxFCL::FArray3D< std::complex< double > > const &X, ObjexxFCL::FArray3D< std::complex< double > > &fX)
3D fft c->c double
basic::options::OptionKeys collection
rule< Scanner, options_closure::context_t > options
#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.
rule< Scanner, option_closure::context_t > option
FArray3D: Fortran-Compatible 3D Array.