Ejemplo n.º 1
0
Archivo: pdb.cpp Proyecto: salilab/imp
IMPATOM_BEGIN_INTERNAL_NAMESPACE

Particle* atom_particle(Model* m, const std::string& atom_type,
                        Element element, bool is_hetatm,
                        int atom_index, int residue_index,
                        double x, double y, double z,
                        double occupancy, double temp_factor) {
  AtomType atom_name;
  std::string string_name = atom_type;
  // determine AtomType
  if (is_hetatm) {
    string_name = "HET:" + string_name;
    if (!get_atom_type_exists(string_name)) {
      atom_name = add_atom_type(string_name, element);
    } else {
      atom_name = AtomType(string_name);
    }
  } else {  // ATOM line
    boost::trim(string_name);
    if (string_name.empty()) {
      string_name = "UNK";
    }
    if (!AtomType::get_key_exists(string_name)) {
      IMP_LOG_VERBOSE("ATOM record type not found: \""
                      << string_name << "\" in PDB file " << std::endl);
      atom_name = add_atom_type(string_name, element);
    } else {
      atom_name = AtomType(string_name);
    }
  }
  // new particle
  Particle* p = new Particle(m);
  p->add_attribute(get_pdb_index_key(), atom_index);
  algebra::Vector3D v(x, y, z);
  // atom decorator
  Atom d = Atom::setup_particle(p, atom_name);
  std::ostringstream oss;
  oss << "Atom " + atom_name.get_string() << " of residue " << residue_index;
  p->set_name(oss.str());
  core::XYZ::setup_particle(p, v).set_coordinates_are_optimized(true);
  d.set_input_index(atom_index);
  d.set_occupancy(occupancy);
  d.set_temperature_factor(temp_factor);
  d.set_element(element);
  // check if the element matches
  Element e2 = get_element_for_atom_type(atom_name);
  if (element != e2) {
    IMP_LOG_VERBOSE(
        "AtomType element and PDB line elements don't match. AtomType "
        << e2 << " vs. determined from PDB " << element << std::endl);
  }
  return p;
}
Ejemplo n.º 2
0
void CHARMMParameters::parse_bond_line(const String& line,
                                       ResidueType curr_res_type,
                                       CHARMMResidueTopologyBase *residue,
                                       bool translate_names_to_pdb)
{
  Strings split_results;
  boost::split(split_results, line, boost::is_any_of(" \t"),
               boost::token_compress_on);
  if(split_results.size() < 3) return; // BOND line has at least 3 fields

  base::Vector<Bond> bonds;
  for(unsigned int i=1; i<split_results.size(); i+=2) {
    if(split_results[i][0] == '!') return;  // comments start
    Strings atom_names = get_atom_names(split_results.begin()+i,
                                        split_results.begin()+i+2,
                                        residue, translate_names_to_pdb);
    if (excess_patch_bond(atom_names, residue, translate_names_to_pdb)) {
      continue;
    }
    residue->add_bond(atom_names);
    // + connects to the next residue
    if (atom_names[0][0] == '+' || atom_names[1][0] == '+') continue;
    // skip 2-residue patch bonds
    if (atom_names[0][0] == '1' || atom_names[0][0] == '2'
        || atom_names[1][0] == '1' || atom_names[1][0] == '2') {
      continue;
    }
    // Ignore bonds to non-existent atoms
    if (AtomType::get_key_exists(atom_names[0])
        && AtomType::get_key_exists(atom_names[1])) {
      AtomType imp_atom_type1 = AtomType(atom_names[0]);
      AtomType imp_atom_type2 = AtomType(atom_names[1]);
      Bond bond(imp_atom_type1, imp_atom_type2);
      bonds.push_back(bond);
    }
  }

  if(residue_bonds_.find(curr_res_type) == residue_bonds_.end()) {
    residue_bonds_[curr_res_type] = bonds;
  } else {
    residue_bonds_[curr_res_type].insert(residue_bonds_[curr_res_type].end(),
                                         bonds.begin(), bonds.end());
  }
}
Ejemplo n.º 3
0
Molecule::AtomType Molecule::addAtom(unsigned char number, Index uniqueId)
{
  if (uniqueId >= static_cast<Index>(m_atomUniqueIds.size()) ||
      m_atomUniqueIds[uniqueId] != MaxIndex) {
    return AtomType();
  }

  m_atomUniqueIds[uniqueId] = atomCount();
  AtomType a = Core::Molecule::addAtom(number);
  return a;
}
Ejemplo n.º 4
0
// Returns the offset from the start of the body of a box of type |aType|
// to the start of its first child.
static uint32_t
BoxOffset(AtomType aType)
{
  const uint32_t FULLBOX_OFFSET = 4;

  if (aType == AtomType("mp4a") || aType == AtomType("enca")) {
    // AudioSampleEntry; ISO 14496-12, section 8.16
    return 28;
  } else if (aType == AtomType("mp4v") || aType == AtomType("encv")) {
    // VideoSampleEntry; ISO 14496-12, section 8.16
    return 78;
  } else if (aType == AtomType("stsd")) {
    // SampleDescriptionBox; ISO 14496-12, section 8.16
    // This is a FullBox, and contains a |count| member before its child
    // boxes.
    return FULLBOX_OFFSET + 4;
  }

  return 0;
}
Ejemplo n.º 5
0
bool
Moof::ProcessCenc()
{
  nsTArray<MediaByteRange> cencRanges;
  if (!GetAuxInfo(AtomType("cenc"), &cencRanges) ||
      cencRanges.Length() != mIndex.Length()) {
    return false;
  }
  for (int i = 0; i < cencRanges.Length(); i++) {
    mIndex[i].mCencRange = cencRanges[i];
  }
  return true;
}
Ejemplo n.º 6
0
void CHARMMParameters::parse_atom_line(const String& line,
                                       ResidueType curr_res_type,
                                       CHARMMResidueTopologyBase *residue,
                                       bool translate_names_to_pdb)
{
  Strings split_results;
  boost::split(split_results, line, boost::is_any_of(" \t"),
               boost::token_compress_on);
  if(split_results.size() < 4) return; // ATOM line has at least 4 fields

  CHARMMAtomTopology atom(get_atom_name(split_results[1], residue,
                                        translate_names_to_pdb));
  atom.set_charmm_type(split_results[2]);
  atom.set_charge(atof(split_results[3].c_str()));
  residue->add_atom(atom);

  AtomType imp_atom_type;
  std::string imp_atom_name = atom.get_name();
  // really need Residue.get_is_protein() and friends here
  if (curr_res_type.get_index() >= HOH.get_index()) {
    imp_atom_name = "HET:" + imp_atom_name;
  }
  if (AtomType::get_key_exists(imp_atom_name)) {
     imp_atom_type = AtomType(imp_atom_name);
  } else {
     imp_atom_type= add_atom_type(imp_atom_name,
                                  get_element_for_type(split_results[2],
                                                       atom_type_to_element_));
  }
  // save in map
  if(atom_res_type_2_force_field_atom_type_.find(curr_res_type) ==
     atom_res_type_2_force_field_atom_type_.end()) {
    atom_res_type_2_force_field_atom_type_[curr_res_type] = AtomTypeMap();
  }
  atom_res_type_2_force_field_atom_type_[curr_res_type].insert(
           std::make_pair(imp_atom_type,
                          std::make_pair(atom.get_charmm_type(),
                                         atom.get_charge())));
}
Ejemplo n.º 7
0
/*>BOOL ConvertPDB2MS(FILE *out, PDB *pdb, BOOL Alt, BOOL GotRad, 
                      BOOL GotType)
   --------------------------------------------------------------
*//**

   Does the actual conversion work

-  24.01.96 Original   By: ACRM
-  29.01.96 Added Alt parameter
-  01.02.96 Added GotRad and GotType handling
*/
BOOL ConvertPDB2MS(FILE *out, PDB *pdb, BOOL Alt, BOOL GotRad, 
                   BOOL GotType)
{
   PDB  *p;
   int  type;
   REAL *typerad = NULL,
        radius;

   if(GotRad)
   {
      for(p=pdb; p!=NULL; NEXT(p))
      {
         radius = p->bval;
         
         if(radius == (REAL)0.0)
         {
            switch(p->atnam[0])
            {
            case 'C':
               if(p->atnam[1] == ' ')
                  radius = 1.76;
               else
                  radius = 1.87;
               break;
            case 'N':
               radius = 1.65;
               break;
            case 'O':
               radius = 1.40;
               break;
            case 'S':
               radius = 1.85;
               break;
            case 'H':
               radius = 1.40;
               break;
            default:
               radius = 1.70;
               break;
            }
         }
         
         if((type=RadiusSeen(typerad, radius))==0)
         {
            if((typerad = StoreRadius(typerad, radius, &type))==NULL)
            {
               fprintf(stderr,"pdb2ms: No memory for radius table\n");
               return(FALSE);
            }
         }

         fprintf(out,"%10.5f%10.5f%10.5f%5d    2    1\n",
                 p->x, p->y, p->z, type);

         WriteRadii(typerad);
      }
   }
   else if(GotType)
   {
      for(p=pdb; p!=NULL; NEXT(p))
      {
         type = (int)p->bval;
         if(type == 0)
            type = AtomType(p->resnam, p->atnam, Alt);

         fprintf(out,"%10.5f%10.5f%10.5f%5d    2    1\n",
                 p->x, p->y, p->z, type);
      }
   }
   else
   {
      for(p=pdb; p!=NULL; NEXT(p))
      {
         if((type = AtomType(p->resnam, p->atnam, Alt))==(-1))
         {
            fprintf(stderr,"Warning, Atom %s %s not known; \
type set to 1\n",
                    p->resnam, p->atnam);
            type = 1;
         }
         fprintf(out,"%10.5f%10.5f%10.5f%5d    2    1\n",
                 p->x, p->y, p->z, type);
      }
   }

   if(typerad != NULL)
      free(typerad);

   return(TRUE);
}