/** * \file em2d_score.cpp \brief A program to score docking models given a list * of transformations for a ligand * * Copyright 2007-2013 IMP Inventors. All rights reserved. * */ #include "Image2D.h" #include "Projection.h" #include "FitResult.h" #include #include #include #include #include #include #include namespace po = boost::program_options; #include #include #include #include namespace { std::vector read_points_from_pdb( std::string pdb_file_name) { // check if file exists std::ifstream in_file(pdb_file_name.c_str()); if(!in_file) { std::cerr << "Can't open file " << pdb_file_name << std::endl; exit(1); } std::vector points; IMP::Model *model = new IMP::Model(); IMP::atom::Hierarchy mhd = IMP::atom::read_pdb(pdb_file_name, model, new IMP::atom::NonWaterNonHydrogenPDBSelector(), true, true); IMP::ParticlesTemp particles = get_by_type(mhd, IMP::atom::ATOM_TYPE); for(unsigned int i=0; i& transforms) { std::ifstream trans_file(file_name.c_str()); if(!trans_file) { std::cerr << "Can't find Transformation file " << file_name << std::endl; exit(1); } IMP::algebra::Vector3D rotation_vec, translation; int trans_number; while(trans_file >> trans_number >> rotation_vec >> translation) { IMP::algebra::Rotation3D rotation = IMP::algebra::get_rotation_from_fixed_xyz(rotation_vec[0], rotation_vec[1], rotation_vec[2]); IMP::algebra::Transformation3D trans(rotation, translation); transforms.push_back(trans); } trans_file.close(); std::cout << transforms.size() << " transforms were read from " << file_name << std::endl; } void compute_zscores(std::vector& fit_results) { float average = 0.0; float std = 0.0; int counter = 0; for(unsigned int i=0; i image_files; std::string rpdb, lpdb, trans_file, out_file_name; po::options_description desc("Usage: \ ..."); desc.add_options() ("help", "produce help message") ("input-files", po::value >(), "input PDB and image files") ("resolution,r", po::value(&resolution)->default_value(10.0), "image resolution (default = 10.0)") ("pixel-size,s", po::value(&pixel_size)->default_value(2.2), "images pixel size (default = 2.2)") ("projection-number,n", po::value(&projection_number)->default_value(40), "number of projections for PDBs") // ("min-diameter,d", po::value(&min_diameter)->default_value(0.0), // "minimal diameter of the complex from the images (default = 0.0)") ("area-threshold,a", po::value(&area_threshold)->default_value(0.4), "maximal percentage of area difference for aligned images (default = 0.4)") ("output_file,o", po::value(&out_file_name)->default_value("em2d_score.res"), "output file name, default name em2d_score.res"); po::positional_options_description p; p.add("input-files", -1); po::variables_map vm; po::store( po::command_line_parser(argc,argv).options(desc).positional(p).run(), vm); po::notify(vm); if(vm.count("help")) { std::cout << desc << "\n"; return 0; } if(vm.count("input-files")) { std::vector files = vm["input-files"].as >(); if(files.size() < 4) { std::cout << desc << "\n"; return 0; } rpdb = files[0]; lpdb = files[1]; trans_file = files[2]; for(unsigned int i=3; i rpoints = read_points_from_pdb(rpdb); std::vector lpoints = read_points_from_pdb(lpdb); // read tranformations std::vector transforms; read_trans_file(trans_file, transforms); std::vector points(rpoints), transformed_lpoints(lpoints); points.resize(rpoints.size()+lpoints.size()); // read images std::vector > images(image_files.size()); double max_distance = 0.0; for(unsigned int i=0; i max_distance) max_distance = curr_max_distance; } max_distance*=pixel_size; std::cerr << "Max distance = " << max_distance << " threshold " << 0.95*max_distance << std::endl; max_distance*=0.9; // create receptor projections boost::ptr_vector rprojections; create_projections(rpoints, projection_number, pixel_size, resolution, rprojections, images[0].get_height()); // write_PGM(rprojections, "rprojections.pgm"); // iterate transformations std::vector fit_results; for(unsigned int t=0; t 0.0) { // // check diameter first // diameter = compute_max_distance(points); // if(diameter < max_distance) { // FitResult fr(t+1, 0.0, true, transforms[t]); // fit_results.push_back(fr); // continue; // } // } boost::ptr_vector projections; // create ligand projections create_projections(points, transformed_lpoints, projection_number, pixel_size, resolution, projections, images[0].get_height()); // add receptor projections for(unsigned int i=0; i area_threshold) continue; ImageTransform curr_transform = images[i].pca_align(projections[j]); if(curr_transform.get_score() > best_transform.get_score()) { best_transform = curr_transform; best_projection_id = projections[j].get_id(); } } std::cerr << "Image " << i << " Best projection " << best_projection_id << " " << best_transform << std::endl; total_score+= best_transform.get_score(); } total_score /= images.size(); FitResult fr(t+1, total_score, false, transforms[t]); fit_results.push_back(fr); std::cerr << "Transform: " << t << " | " << total_score << " | " << transforms[t] << std::endl; //out_file << t+1 << " | " << total_score << " | " << diameter //<< " | " << transformation3d_to_rigidtrans3(transforms[t]) << std::endl; } compute_zscores(fit_results); // output std::ofstream out_file(out_file_name.c_str()); out_file << "receptorPdb (str) " << rpdb << std::endl; out_file << "ligandPdb (str) " << lpdb << std::endl; FitResult::print_header(out_file); for(unsigned int i=0; i