Exemplo n.º 1
0
void ProteinLigandRestraint::initialize(Hierarchy protein, Hierarchy ligand) {
  add_protein_ligand_score_data(protein);
  add_protein_ligand_score_data(ligand);
  IMP_IF_CHECK(USAGE) {
    Hierarchies pr = get_by_type(protein, RESIDUE_TYPE);
    for (unsigned int i = 0; i < pr.size(); ++i) {
      IMP_USAGE_CHECK(!get_is_heterogen(pr[i]),
                      "Some of protein is actually a heterogen " << pr[i]);
    }
    Hierarchies lr = get_by_type(ligand, RESIDUE_TYPE);
    for (unsigned int i = 0; i < lr.size(); ++i) {
      IMP_USAGE_CHECK(get_is_heterogen(lr[i]),
                      "Some of ligand is actually protein " << lr[i]);
    }
  }
}
Exemplo n.º 2
0
void read_pdb_ca_atoms(const std::string file_name, IMP::kernel::Particles& particles) {
  IMP::kernel::Model *model = new IMP::kernel::Model();
  IMP::atom::Hierarchy mhd = IMP::atom::read_pdb(file_name, model,
                             new IMP::atom::CAlphaPDBSelector(), true, true);
  particles=IMP::get_as<IMP::kernel::Particles>(get_by_type(mhd, IMP::atom::ATOM_TYPE));
  std::cout << "Number of CA atom particles " << particles.size() << std::endl;
}
Exemplo n.º 3
0
int cmd_uart(struct command *cmd)
{
    int			err;
    char			*dev = NULL;
    struct uart_t		*u = NULL;

    closelog();
    openlog(__argv[0], LOG_PERROR|LOG_PID, LOG_USER);

    if (__argc - optind < 1 || (cmd->cmd == CMD_OPEN_UART && __argc - optind < 2)) {
        print_usage(cmd);
        exit(1);
    }
    if (cmd->cmd != CMD_INIT_UART)
        dev = __argv[optind++];

    if (cmd->cmd != CMD_CLOSE_UART) {
        u = get_by_type(__argv[optind++]);
        if (!u) {
            BTERROR("Device unknown.\n");
            return 1;
        }
        if (!__argv[optind])
            goto next;

        u->speed = atoi(__argv[optind++]);

        if (!__argv[optind])
            goto next;

        /* get 0xXXXX flags */
        if (sscanf(__argv[optind], "0x%x", &u->flags) > 0)
            goto next;
        else {
            /* get symbolic */
            u->flags = 0;
            if (!str2mask(uart_flags, argv2str(__argv + optind), &u->flags)) {
                BTERROR("flags error\n");
                return -1;
            }
        }
next:
        if (cmd->cmd == CMD_OPEN_UART) {
            /* atatch device */
            err = hci_open_uart(dev, u->type, u->proto, uart_speed(u->speed), u->flags);
        } else {
            /* init device */
            err = init_uart(btdev, u);
            if (err < 0)
                BTERROR("Can't init device\n");
        }
    } else {
        err = hci_close_uart(dev);
    }
    if (err)
        BTERROR("%s", hci_error(err));
    return err;
}
Exemplo n.º 4
0
CHARMMTopology *CHARMMParameters::create_topology(Hierarchy hierarchy) const {
  IMP_OBJECT_LOG;
  IMP_NEW(CHARMMTopology, topology, (this));

  Hierarchies chains = get_by_type(hierarchy, CHAIN_TYPE);

  for (Hierarchies::iterator chainit = chains.begin(); chainit != chains.end();
       ++chainit) {
    IMP_NEW(CHARMMSegmentTopology, segment, ());
    Hierarchies residues = get_by_type(*chainit, RESIDUE_TYPE);
    for (Hierarchies::iterator resit = residues.begin();
         resit != residues.end(); ++resit) {
      ResidueType restyp = Residue(*resit).get_residue_type();
      try {
        IMP_NEW(CHARMMResidueTopology, residue, (get_residue_topology(restyp)));
        segment->add_residue(residue);
      }
      catch (base::ValueException) {
        // If residue type is unknown, add empty topology for this residue
        IMP_WARN_ONCE(
            restyp.get_string(),
            "Residue type "
                << restyp
                << " was not found in "
                   "topology library; using empty topology for this residue",
            warn_context_);
        IMP_NEW(CHARMMResidueTopology, residue, (restyp));
        segment->add_residue(residue);
      }
    }
    topology->add_segment(segment);
  }
  // keep clang happy
  bool dumped = false;
  IMP_IF_LOG(VERBOSE) {
    dumped = true;
    warn_context_.dump_warnings();
  }
  if (!dumped) {
    warn_context_.clear_warnings();
  }
  // Topology objects are not designed to be added into other containers
  topology->set_was_used(true);
  return topology.release();
}
Exemplo n.º 5
0
void EMFit::read_pdb_atoms(IMP::Model* model,
                           const std::string file_name,
                           IMP::Particles& particles) {
  IMP::atom::Hierarchy mhd = IMP::atom::read_pdb(
      file_name, model, new IMP::atom::NonWaterNonHydrogenPDBSelector(), true,
      true);
  particles = get_by_type(mhd, IMP::atom::ATOM_TYPE);
  std::cout << "Number of atom particles " << particles.size() << std::endl;
}
Exemplo n.º 6
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);
      }
    }
  }
}
Exemplo n.º 7
0
IMPINTEGRATIVEDOCKING_BEGIN_INTERNAL_NAMESPACE

IMP::atom::Hierarchy read_pdb(const std::string pdb_file_name,
                              IMP::Model* model,
                              IMP::ParticleIndexes& pis) {

  IMP::atom::Hierarchy mhd = IMP::atom::read_pdb(
      pdb_file_name, model, new IMP::atom::NonWaterNonHydrogenPDBSelector(),
      true, true);

  pis = IMP::get_as<IMP::ParticleIndexes>(
      get_by_type(mhd, IMP::atom::ATOM_TYPE));
  std::cout << pis.size() << " atoms read from " << pdb_file_name << std::endl;
  IMP::atom::add_dope_score_data(mhd);
  return mhd;
}
Exemplo n.º 8
0
Hierarchy create_simplified_along_backbone(Hierarchy in,
                                           int num_res,
                                           bool keep_detailed) {
  Hierarchies chains= get_by_type(in, CHAIN_TYPE);
  if (chains.size() > 1) {
    Hierarchy root= Hierarchy::setup_particle(new Particle(in->get_model(),
                                                           in->get_name()));
    for (unsigned int i=0; i< chains.size(); ++i) {
      Chain chain(chains[i].get_particle());
      root.add_child(create_simplified_along_backbone(chain, num_res));
    }
    return root;
  } else if (chains.size()==1) {
    // make sure to cast it to chain to get the right overload
    return create_simplified_along_backbone(Chain(chains[0]), num_res,
                                            keep_detailed);
  } else {
    IMP_THROW("No chains to simplify", ValueException);
  }
}
Exemplo n.º 9
0
int ftp_get(struct obex_session *os, obex_object_t *obj, gboolean *stream,
							void *user_data)
{
	struct ftp_session *ftp = user_data;
	const char *type = obex_get_type(os);
	int ret;

	DBG("%p", ftp);

	if (ftp->folder == NULL)
		return -ENOENT;

	ret = get_by_type(ftp, type);
	if (ret < 0)
		return ret;

	if (stream)
		*stream = TRUE;

	return 0;
}
Exemplo n.º 10
0
// argv[1] file_name_type should contain file type e.g. ".mol2"
void write_mol2(Hierarchy rhd, base::TextOutput file) {
  Hierarchies hs= get_by_type(rhd, RESIDUE_TYPE);
  for(unsigned int i=0; i<hs.size(); ++i) {
    write_molecule_mol2(hs[i], file);
  }
}
Exemplo n.º 11
0
void add_protein_ligand_score_data(Hierarchy h) {
  Hierarchies atoms = get_by_type(h, ATOM_TYPE);
  for (unsigned int i = 0; i < atoms.size(); ++i) {
    add_protein_ligand_score_data(Atom(atoms[i]));
  }
}
Exemplo n.º 12
0
Arquivo: rg.cpp Projeto: AljGaber/imp
int main(int argc, char **argv) {
  // output arguments
  for (int i = 0; i < argc; i++) std::cerr << argv[i] << " ";
  std::cerr << std::endl;

  double end_q_rg = 1.3;
  po::options_description desc(
      "Usage: <pdb_file1> <pdb_file2> \
... <profile_file1> <profile_file2> ...");
  desc.add_options()("help",
                     "Any number of input PDBs and profiles is supported. \
Each PDB will be fitted against each profile.")(
      "input-files", po::value<std::vector<std::string> >(),
      "input PDB and profile files")(
      "end_q_rg,q*rg", po::value<double>(&end_q_rg)->default_value(1.3),
      "end q*rg value for rg computation, q*rg<end_q_rg (default = 1.3), \
use 0.8 for elongated proteins");
  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);

  std::vector<std::string> files, pdb_files, dat_files;
  if (vm.count("input-files")) {
    files = vm["input-files"].as<std::vector<std::string> >();
  }
  if (vm.count("help") || files.size() == 0) {
    std::cout << desc << "\n";
    return 0;
  }

  // 1. read pdbs and profiles, prepare particles
  IMP::Model *model = new IMP::Model();
  IMP::Vector<IMP::Particles> particles_vec;
  IMP::Vector<IMP::saxs::Profile *> exp_profiles;
  for (unsigned int i = 0; i < files.size(); i++) {
    // check if file exists
    std::ifstream in_file(files[i].c_str());
    if (!in_file) {
      std::cerr << "Can't open file " << files[i] << std::endl;
      exit(1);
    }
    // A. try as pdb
    try {
      IMP::atom::Hierarchy mhd = IMP::atom::read_pdb(
          files[i], model, new IMP::atom::NonWaterNonHydrogenPDBSelector(),
          // don't add radii
          true, true);
      IMP::Particles particles =
        IMP::get_as<IMP::Particles>(get_by_type(mhd,
                                                IMP::atom::ATOM_TYPE));
      if (particles.size() > 0) {  // pdb file
        pdb_files.push_back(files[i]);
        particles_vec.push_back(particles);
        std::cout << particles.size() << " atoms were read from PDB file "
                  << files[i] << std::endl;
      }
    }
    catch (IMP::ValueException e) {  // not a pdb file
      // B. try as dat file
      IMP::saxs::Profile *profile = new IMP::saxs::Profile(files[i]);
      if (profile->size() == 0) {
        std::cerr << "can't parse input file " << files[i] << std::endl;
        return 1;
      } else {
        dat_files.push_back(files[i]);
        exp_profiles.push_back(profile);
        std::cout << "Profile read from file " << files[i]
                  << " size = " << profile->size() << std::endl;
      }
    }
  }

  // 2. compute rg for input profiles
  for (unsigned int i = 0; i < dat_files.size(); i++) {
    IMP::saxs::Profile *exp_saxs_profile = exp_profiles[i];
    double rg = exp_saxs_profile->radius_of_gyration(end_q_rg);
    std::cout << dat_files[i] << " Rg= " << rg << std::endl;
  }

  // 3. compute rg for input pdbs
  for (unsigned int i = 0; i < pdb_files.size(); i++) {
    double rg = IMP::saxs::radius_of_gyration(particles_vec[i]);
    std::cout << pdb_files[i] << " Rg= " << rg << std::endl;
  }
  return 0;
}
Exemplo n.º 13
0
int main(int argc, char **argv) {
  // print command
  for(int i=0; i<argc; i++) std::cerr << argv[i] << " "; std::cerr << std::endl;

  // input parsing
  std::string out_file_name;
  bool use_nter = true;
  po::options_description desc("Usage: <mol1> <mol2> <thr>");
  desc.add_options()
    ("help", "returns lys-lys cross links for the two molecules.")
    ("input-files", po::value< std::vector<std::string> >(),
     "input PDBs")
    ("n-ter,n", "use n-termini for cross linking (default = true)")
    ("output_file,o",
      po::value<std::string>(&out_file_name)->default_value("cross_links.dat"),
      "output file name, default name cross_links.dat")
    ;

  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);

  // parse filenames
  std::string receptor_pdb, ligand_pdb;
  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() != 3) {
    std::cout << desc << "\n"; return 0;
  }
  if(vm.count("n-ter")) use_nter = false;

  receptor_pdb = files[0];
  ligand_pdb = files[1];
  float distance_threshold = atof(files[2].c_str());

  // read pdb  files, prepare particles
  IMP::kernel::Model *model = new IMP::kernel::Model();
  IMP::atom::Hierarchy mhd = IMP::atom::read_pdb(receptor_pdb, model,
                   new IMP::atom::NonWaterNonHydrogenPDBSelector(), true, true);
  IMP::kernel::Particles residue_particles1 = get_by_type(mhd, IMP::atom::RESIDUE_TYPE);
  mhd = IMP::atom::read_pdb(ligand_pdb, model,
                   new IMP::atom::NonWaterNonHydrogenPDBSelector(), true, true);
  IMP::kernel::Particles residue_particles2 = get_by_type(mhd, IMP::atom::RESIDUE_TYPE);

  // get CA atoms for residues
  IMP::kernel::Particles ca_atoms1, ca_atoms2;
  for(unsigned int i=0; i<residue_particles1.size(); i++) {
    IMP::atom::Atom at =
      IMP::atom::get_atom(IMP::atom::Residue(residue_particles1[i]),
                          IMP::atom::AT_CA);
    if(at.get_particle() != NULL) ca_atoms1.push_back(at.get_particle());
  }
  for(unsigned int i=0; i<residue_particles2.size(); i++) {
    IMP::atom::Atom at =
      IMP::atom::get_atom(IMP::atom::Residue(residue_particles2[i]),
                          IMP::atom::AT_CA);
    if(at.get_particle() != NULL) ca_atoms2.push_back(at.get_particle());
  }

  // cross link only acessible residues
  IMP::Floats residue_solvent_accessibility1, residue_solvent_accessibility2;
  get_residue_solvent_accessibility(ca_atoms1, residue_solvent_accessibility1);
  get_residue_solvent_accessibility(ca_atoms2, residue_solvent_accessibility2);

  std::vector<CrossLink> cross_links, selected_cross_links;

  bool chain_id1_set = false;
  char curr_chain1 = '-';
  int link_counter = 0;
  // compute distance for all accessible LYS calpha atoms + N-ter calpha
  for(unsigned int i=0; i<ca_atoms1.size(); i++) {
    // get data
    IMP::atom::Residue r1 =
      IMP::atom::get_residue(IMP::atom::Atom(ca_atoms1[i]));
    IMP::atom::ResidueType rt1 = r1.get_residue_type();
    int res_index1 = r1.get_index();
    char chain_id1 =
      IMP::atom::get_chain(IMP::atom::Atom(ca_atoms1[i])).get_id();

    // check if LYS or N-ter
    if(residue_solvent_accessibility1[i] > 0 &&
       (rt1 == IMP::atom::LYS || // LYS residue
        (use_nter && (!chain_id1_set || // first residue
                      // first residue in new chain
                      (chain_id1_set && curr_chain1 != chain_id1))))) {

      IMP::algebra::Vector3D v1 =IMP::core::XYZ(ca_atoms1[i]).get_coordinates();
      //get cb
      IMP::algebra::Vector3D v1cb(0.0,0.0,0.0);
      bool cb1 = false;
      IMP::atom::Atom at = IMP::atom::get_atom(r1, IMP::atom::AT_CB);
      if(at) {
        v1cb = IMP::core::XYZ(at.get_particle()).get_coordinates();
        cb1 = true;
      }

      bool chain_id2_set = false;
      char curr_chain2 = '-';
      // iterate second mol
      for(unsigned int j=0; j<ca_atoms2.size(); j++) {
        // check if LYS or N-ter
        IMP::atom::Residue r2 =
          IMP::atom::get_residue(IMP::atom::Atom(ca_atoms2[j]));
        IMP::atom::ResidueType rt2 = r2.get_residue_type();
        int res_index2 = r2.get_index();
        char chain_id2 =
          IMP::atom::get_chain(IMP::atom::Atom(ca_atoms2[j])).get_id();
        if(residue_solvent_accessibility2[j] > 0 &&
           (rt2 == IMP::atom::LYS ||
            (use_nter && (!chain_id2_set ||
                          (chain_id2_set && curr_chain2 != chain_id2))))) {
          IMP::algebra::Vector3D v2 =
            IMP::core::XYZ(ca_atoms2[j]).get_coordinates();
          //get cb
          IMP::algebra::Vector3D v2cb(0.0,0.0,0.0);
          bool cb2 = false;
          IMP::atom::Atom at = IMP::atom::get_atom(r2, IMP::atom::AT_CB);
          if(at) {
            v2cb = IMP::core::XYZ(at.get_particle()).get_coordinates();
            cb2 = true;
          }

          // compute distance
          float dist = IMP::algebra::get_distance(v1,v2);
          if(dist < distance_threshold) {
            if(cb1 && cb2) { // check cb distance
              float dist_cb = IMP::algebra::get_distance(v1cb,v2cb);
              if(dist_cb < distance_threshold) {
                link_counter++;
                std::cout << res_index1 << ' ' << chain_id1 << ' '
                          << res_index2 << ' ' << chain_id2 << ' '
                          << dist << std::endl;
                CrossLink cl(res_index1, chain_id1, res_index2, chain_id2,
                             3.0, 27.0, dist, dist_cb);
                cross_links.push_back(cl);
              }
            }
          }
        }
        // set chain id2
        if(!chain_id2_set) chain_id2_set = true;
        curr_chain2 = chain_id2;
      }
    }
    // set chain id
    if(!chain_id1_set) chain_id1_set = true;
    curr_chain1 = chain_id1;
  }

  select_cross_links(cross_links, selected_cross_links);
  std::random_shuffle(selected_cross_links.begin(), selected_cross_links.end());

  if(selected_cross_links.size() > 0) {
    write_cross_link_file(out_file_name, selected_cross_links);
    write_cross_link_file("cxms2.dat", selected_cross_links, true);
  }
  write_cross_link_file("cxms_all.dat", cross_links, true);
  std::cerr << link_counter << " links were generated, selected: "
            << selected_cross_links.size () << std::endl;
  return 0;
}