Пример #1
0
void read_pdb(Model *model, const std::string file,
              std::vector<std::string>& pdb_file_names,
              std::vector<IMP::Particles>& particles_vec,
              bool residue_level, bool heavy_atoms_only, int multi_model_pdb,
              bool explicit_water) {
  IMP::atom::Hierarchies mhds;
  IMP::atom::PDBSelector* selector;
  if (residue_level)  // read CA only
    selector = new IMP::atom::CAlphaPDBSelector();
  else if (heavy_atoms_only) {  // read without hydrogens
    if (explicit_water)
      selector = new IMP::atom::NonHydrogenPDBSelector();
    else
      selector = new IMP::atom::NonWaterNonHydrogenPDBSelector();
  } else { // read with hydrogens
    if (explicit_water)
      selector = new IMP::atom::NonAlternativePDBSelector();
    else
      selector = new IMP::atom::NonWaterPDBSelector();
  }

  if (multi_model_pdb == 2) {
    mhds = read_multimodel_pdb(file, model, selector, true);
  } else {
    if (multi_model_pdb == 3) {
      IMP::atom::Hierarchy mhd =
          IMP::atom::read_pdb(file, model, selector, false, true);
      mhds.push_back(mhd);
    } else {
      IMP::atom::Hierarchy mhd =
          IMP::atom::read_pdb(file, model, selector, true, true);
      mhds.push_back(mhd);
    }
  }

  for (unsigned int h_index = 0; h_index < mhds.size(); h_index++) {
    IMP::ParticlesTemp ps =
        get_by_type(mhds[h_index], IMP::atom::ATOM_TYPE);
    if (ps.size() > 0) {  // pdb file
      std::string pdb_id = file;
      if (mhds.size() > 1) {
        pdb_id = trim_extension(file) + "_m" +
                 std::string(boost::lexical_cast<std::string>(h_index + 1)) +
                 ".pdb";
      }
      pdb_file_names.push_back(pdb_id);
      particles_vec.push_back(IMP::get_as<IMP::Particles>(ps));
      if (mhds.size() > 1) {
        IMP_LOG_TERSE(ps.size() << " atoms were read from PDB file " << file
                      << " MODEL " << h_index + 1 << std::endl);
      } else {
        IMP_LOG_TERSE(ps.size() << " atoms were read from PDB file " << file
                      << std::endl);
      }
    }
  }
}
Пример #2
0
IMP::atom::Residue find_residue(const IMP::ParticlesTemp& residues,
                                int res_index, std::string chain) {
  for(unsigned int i=0; i<residues.size(); i++) {
    IMP::atom::Residue rd = IMP::atom::Residue(residues[i]);
    if(rd.get_index() == res_index &&
       IMP::atom::get_chain(rd).get_id() == chain) return rd;
  }
  std::cerr << "Residue not found " << res_index << chain << std::endl;
  exit(0);
}
Пример #3
0
int main(int argc, char **argv)
{
  // output arguments
  for(int i=0; i<argc; i++) std::cerr << argv[i] << " "; std::cerr << std::endl;

  int number_of_iterations = 100;
  int number_of_nodes = 100;
  int save_configuration_number = 10;
  int number_of_models_in_pdb = 100;
  int number_of_active_dofs = 0;
  float radii_scaling = 0.5;
  bool reset_angles = false;
  std::string configuration_file;
  std::string connect_chains_file;
  po::options_description desc("Options");
  desc.add_options()
    ("help", "PDB file and Rotatable Angles file")
    ("version", "Written by Dina Schneidman.")
    ("number_of_iterations,i", po::value<int>(&number_of_iterations)->default_value(100),
     "number of iterations (default = 100)")
    ("number_of_nodes,n", po::value<int>(&number_of_nodes)->default_value(100),
     "number of nodes (default = 100)")
    ("number_of_path_configurations_saved,p", po::value<int>(&save_configuration_number)->default_value(10),
     "if the path between two nodes is feasible, each Nth configuration on the path will be added to the tree (default = 10?)")
    ("number_of_active_dofs,a", po::value<int>(&number_of_active_dofs)->default_value(0),
     "for many dofs use this option with 10-50 dofs (default = 0)")
    ("radii_scaling,s", po::value<float>(&radii_scaling)->default_value(0.5),
     "radii scaling parameter (0.5 < s < 1.0, default = 0.5)")
    ("reset_angles", "set initial values in rotatable angles to PI (default = false)")
    ("connect_chains_file,c",
     po::value<std::string>(&connect_chains_file),
     "connect chains into one rigid body by adding bonds between specified atoms")
    ("number_of_models_in_pdb,m", po::value<int>(&number_of_models_in_pdb)->default_value(100),
     "number of models in output PDB files (default = 100)")
    ;

  po::options_description hidden("Hidden options");
  hidden.add_options()
    ("input-files", po::value< std::vector<std::string> >(),
     "input PDB and rotatable angles files")
    ("target_configurations,t", po::value<std::string>(&configuration_file),
     "target_configurations")
    ;

  po::options_description cmdline_options;
  cmdline_options.add(desc).add(hidden);

  po::options_description visible("Usage: <pdb_file> <rotatable_angles_file>");
  visible.add(desc);

  po::positional_options_description p;
  p.add("input-files", -1);
  po::variables_map vm;
  po::store(po::command_line_parser(argc,
            argv).options(cmdline_options).positional(p).run(), vm);
  po::notify(vm);

  std::vector<std::string> files;
  if(vm.count("input-files")) {
    files = vm["input-files"].as< std::vector<std::string> >();
  }
  if(vm.count("help") || files.size() == 0) {
    std::cout << visible << "\n";
    return 0;
  }
  if(radii_scaling < 0.5 || radii_scaling > 1.0) {
    std::cerr << "radii_scaling parameter outside allowed range" << radii_scaling << std::endl;
  }
  if(vm.count("reset_angles")) reset_angles=true;

  std::string pdb_name = files[0];
  std::string angle_file_name;
  if(files.size() > 1) angle_file_name = files[1];

  // read in the input protein
  IMP::Pointer<IMP::Model> model = new IMP::Model();
  std::cerr << "Starting reading pdb file " << pdb_name << std::endl;
  IMP::atom::Hierarchy mhd =
    IMP::atom::read_pdb(pdb_name, model,
                        new IMP::atom::NonWaterNonHydrogenPDBSelector(),
                        // don't add radii
                        true, true);

  IMP::ParticlesTemp atoms = IMP::atom::get_by_type(mhd, IMP::atom::ATOM_TYPE);
  IMP::ParticlesTemp residues = IMP::atom::get_by_type(mhd, IMP::atom::RESIDUE_TYPE);

  const std::string topology_file_name = IMP::atom::get_data_path("top_heav.lib");
  const std::string parameter_file_name = IMP::atom::get_data_path("par.lib");
  std::ifstream test(topology_file_name.c_str());
  if(!test) {
    std::cerr << "Please provide topology file " << topology_file_name
              << std::endl;
    exit(1);
  }
  std::ifstream test1(parameter_file_name.c_str());
  if(!test1) {
    std::cerr << "Please provide parameter file " << parameter_file_name
              << std::endl;
    exit(1);
  }

  IMP::atom::CHARMMParameters* ff =
    new IMP::atom::CHARMMParameters(topology_file_name, parameter_file_name);
  IMP::Pointer<IMP::atom::CHARMMTopology> topology =
    ff->create_topology(mhd);

  // We don't want to add/remove any atoms, so we only add atom types
  topology->apply_default_patches();
  //  topology->setup_hierarchy(mhd); //removes atoms
  topology->add_atom_types(mhd);

  IMP::ParticlesTemp bonds =  topology->add_bonds(mhd);

  // create phi/psi joints
  IMP::atom::Residues flexible_residues;
  std::vector<IMP::atom::Atoms> dihedral_angles;
  if(angle_file_name.length()>0) {
    read_angle_file(angle_file_name, residues, atoms,
                    flexible_residues, dihedral_angles);
  } else {
    flexible_residues = residues;
  }

  std::vector<IMP::atom::Atoms> connect_chains_atoms;
  if(connect_chains_file.length() > 0) {
    read_connect_chains_file(connect_chains_file, atoms, connect_chains_atoms);
    for(unsigned i=0; i<connect_chains_atoms.size(); i++) {
      IMP::atom::Bond bond = create_bond(connect_chains_atoms[i]);
      if(bond != IMP::atom::Bond()) bonds.push_back(bond);
    }
  }

  IMP::ParticlesTemp angles = ff->create_angles(bonds);
  IMP::ParticlesTemp dihedrals = ff->create_dihedrals(bonds);
  std::cerr << "# atoms " << atoms.size()
            << " # bonds " << bonds.size()
            << " # angles " << angles.size()
            << " # dihedrals " << dihedrals.size() << std::endl;

  add_missing_bonds(atoms, bonds);

  std::cerr << "# atoms " << atoms.size()
            << " # bonds " << bonds.size()
            << " # angles " << angles.size()
            << " # dihedrals " << dihedrals.size() << std::endl;

  // add radius
  ff->add_radii(mhd, radii_scaling);

  // prepare exclusions list
  IMP_NEW(IMP::atom::StereochemistryPairFilter, pair_filter, ());
  pair_filter->set_bonds(bonds);
  pair_filter->set_angles(angles);
  pair_filter->set_dihedrals(dihedrals);

  // close pair container
  IMP_NEW(IMP::container::ListSingletonContainer, lsc, (atoms));
  IMP_NEW(IMP::container::ClosePairContainer, cpc, (lsc, 15.0));
  cpc->add_pair_filter(pair_filter);

  IMP_NEW(IMP::core::SoftSpherePairScore,  score,(1));
  IMP_NEW(IMP::container::PairsRestraint, pr, (score, cpc));

  // TODO: check why not working: should be much faster
  //IMP::Pointer<IMP::Restraint> pr=
  //   IMP::container::create_restraint(score, cpc);

  ProteinKinematics pk(mhd, flexible_residues, dihedral_angles);
  std::cerr << "ProteinKinematics done" << std::endl;
  DihedralAngleRevoluteJoints joints = pk.get_ordered_joints();
  IMP_NEW(KinematicForestScoreState, kfss, (pk.get_kinematic_forest(),
                                            pk.get_rigid_bodies(),
                                            atoms));
  model->add_score_state(kfss);

  // create dofs
  DOFs dofs;
  for(unsigned int i=0; i<joints.size(); i++) {
    std::cerr << "Angle = " << joints[i]->get_angle() << " " << 180 * joints[i]->get_angle()/IMP::algebra::PI << std::endl;
    if(reset_angles) joints[i]->set_angle(IMP::algebra::PI);
    IMP_NEW(DOF, dof, (joints[i]->get_angle(),
                       -IMP::algebra::PI,
                       IMP::algebra::PI,
                       IMP::algebra::PI/360));
    dofs.push_back(dof);
  }

  DOFValues val(dofs);

  if(reset_angles) {
    kfss->do_before_evaluate();
    for(unsigned int i=0; i<joints.size(); i++) {
      std::cerr << "Angle = " << joints[i]->get_angle() << " " << 180 * joints[i]->get_angle()/IMP::algebra::PI << std::endl;
    }
  }

  DirectionalDOF dd(dofs);

  IMP_NEW(UniformBackboneSampler, ub_sampler, (joints, dofs));
  IMP_NEW(PathLocalPlanner, planner, (model, ub_sampler, &dd,
                                      save_configuration_number));
  std::cerr << "Init  RRT" << std::endl;
  IMP_NEW(RRT, rrt, (model, ub_sampler, planner, dofs, number_of_iterations,
                     number_of_nodes, number_of_active_dofs));
  rrt->set_scoring_function(pr);


  std::cerr << "Start RRT run" << std::endl;
  std::string filename = "node_begin.pdb";
  IMP::atom::write_pdb(mhd, filename);
  rrt->run();
  std::cerr << "Done RRT " << rrt->get_DOFValues().size() << std::endl;

  // output PDBs
  std::ofstream *out = NULL;
  int file_counter = 1;
  int model_counter = 0;

  std::vector<DOFValues> dof_values = rrt->get_DOFValues();
  for(unsigned int i = 0; i<dof_values.size(); i++) {
    ub_sampler->apply(dof_values[i]);
    kfss->do_before_evaluate();

    // open new file if needed
    if(model_counter % number_of_models_in_pdb == 0) { // open new file
      if(out !=NULL) out->close();
      std::string file_name = "nodes" + std::string(boost::lexical_cast<std::string>(file_counter)) + ".pdb";
      out = new std::ofstream(file_name.c_str());
      file_counter++;
      model_counter=0;
    }

    IMP::atom::write_pdb(mhd, *out, model_counter+1);
    model_counter++;
  }
  out->close();
  return 0;
}
Пример #4
0
int main(int argc, char **argv) {

  // Parameters
  po::variables_map vm = get_parameters(argc,argv);
  // vector for options values
  std::vector<str> opt;

  // Read PDB
  IMP_NEW(IMP::Model, smodel, ());
  IMP::Pointer<atom::ATOMPDBSelector> ssel= new atom::ATOMPDBSelector();
  // Read only first model
  if(digest_parameter("i",vm,opt) == false) {
      std::cout << "Input file not found or missing parameter." << std::endl;
      exit(0);
  }
  atom::Hierarchy smh = atom::read_pdb(opt[0],smodel,ssel,true);
  IMP::ParticlesTemp sps = core::get_leaves(smh);
//  atom::add_radii(smh);
  double resolution = vm["res"].as<double>();
  IMP_NEW(em2d::SpiderImageReaderWriter,  srw, ());
  IMP_NEW(em::MRCReaderWriter,  mrw, ());


  // Generate a map
  if(digest_parameter("map",vm,opt)) {
    if( check_parameters(vm,"apix") == false) {
      std::cerr << "The requested --map option is missing "
                   "additional parameters"  << std::endl;
      std::exit(0);
    }
    double apix= vm["apix"].as<double>();
    str fn_map= vm["map"].as<str>();
    std::cout << "Generating map ... " << fn_map << std::endl;
    em::SampledDensityMap *map= new em::SampledDensityMap(sps,resolution,apix);
    em::write_map(map,fn_map.c_str(),mrw);
  }

  // Project IMAGES
  if( vm.count("proj_img")) {
    if(check_parameters(vm,"np,apix,size_i,proj_dist,proj_params") == false) {
      std::cerr << "--proj is missing additional parameters." << std::endl;
      std::exit(0);
    }
    // Parameters
    unsigned int np=vm["np"].as<unsigned int>();
    double apix       = vm["apix"].as<double>();
    digest_parameter("size_i",vm,opt);
    unsigned int cols = std::atoi(opt[0].c_str());
    unsigned int rows =std::atoi(opt[1].c_str());
    digest_parameter("proj_dist",vm,opt);
    em2d::RegistrationResults registration_values=
                            get_registration_values(opt,np);
    em2d::ProjectingOptions options( apix, resolution);
    em2d::Images projections = em2d::get_projections(sps,
                                                     registration_values,
                                                     rows,
                                                     cols,
                                                     options);
    // Normalize and add noise if requested
    np = registration_values.size(); // for the case when the values are read
    if(vm.count("SNR")) {
      double SNR = vm["SNR"].as<double>();
      for (unsigned int i=0;i<np;++i) {
        em2d::do_normalize(projections[i]);
        // Noise added of mean = 0  and stddev = stddev_signal / sqrt(SNR)
        // As the image is normalized, stddev_signal is 1.0
        em2d::add_noise(
                  projections[i]->get_data(),0.0,1./sqrt(SNR), "gaussian");
      }
    }
    // Save projections and projection parameters
    IMP::Strings proj_names;
    if(digest_parameter("proj_names",vm,opt)) {
      proj_names = em2d::read_selection_file(opt[0]);
    } else {
      proj_names = em2d::create_filenames(np,"proj","spi");
    }
    for (unsigned int i=0;i<np;++i) {
      projections[i]->write(proj_names[i],srw);
    }
    if(digest_parameter("proj_params",vm,opt)) {
      em2d::write_registration_results(opt[0],registration_values);
    }
  }

  // Project PDBs
  if(vm.count("proj_pdb")) {
    IMP::String param_error = "More parameters are required with --proj_pdb\n";
    IMP_USAGE_CHECK(check_parameters(vm,"np,proj_dist"),param_error);
    // Parameters
    unsigned int np=vm["np"].as<unsigned int>();
    digest_parameter("proj_dist",vm,opt);
    em2d::RegistrationResults registration_values=
                      get_registration_values(opt,np);
    np = registration_values.size(); // for the case when the values are read
    // Get coordinates
    unsigned int n_atoms=sps.size();
    alg::Vector3Ds pdb_atoms(n_atoms);
    for (unsigned i=0;i<n_atoms;++i ) {
      core::XYZ xyz(sps[i]);
      pdb_atoms[i] = xyz.get_coordinates();
    }
    alg::Vector3D centroid = alg::get_centroid(pdb_atoms);
    // Project
    IMP::Strings proj_names;
    if(vm.count("proj_names")) {
      proj_names=em2d::read_selection_file(vm["proj_names"].as<IMP::String>());
    } else {
      proj_names = em2d::create_filenames(np,"proj","pdb");
    }
    for(unsigned int i=0;i<np;++i) {
      // To project vectors here, the shift is understood a as translation
      alg::Vector3D translation = registration_values[i].get_shift_3d();
      alg::Rotation3D R = registration_values[i].get_rotation();
      alg::Vector2Ds projected_points=
                em2d::do_project_vectors(pdb_atoms,R,translation,centroid);
      // Save projection
      em2d::write_vectors_as_pdb(projected_points,proj_names[i]);
    }
    // Save projection parameters
    if(digest_parameter("proj_params",vm,opt)) {
      em2d::write_registration_results(opt[0],registration_values);
    }
  }
}