Ejemplo n.º 1
0
Residue ResidueSubstitutionTable::replaceResidue(Residue &_res) {
    // If this residue isn't in our list of residues to be replaced,
    // just return it!
    if( !isResidueInSubstitutionTable(_res) )
        return _res;

    // Clone the current residue, and find the replacement info.
    Residue newRes;
    ReplacementInfo ri = find( _res.getResidueName() )->second;
    string newName = ri.first;
    AtomHash ah = ri.second;

    // Loop over all of the atoms in the residue.
    for(int i=0; i < _res.size(); ++i ){
        Atom &currAtom = _res.getAtom(i);
        string currAtomName = currAtom.getName();
        // If the current atom is in the list of atoms we should keep,
        // add it.
        if( ah.find(currAtomName) != ah.end() )
            newRes.addAtom( currAtom );
    }

    // Set the new name of the residue.
    newRes.setResidueNumber( _res.getResidueNumber() );
    newRes.setResidueIcode( _res.getResidueIcode() );
    newRes.setChainId( _res.getChainId() );
    newRes.setResidueName( newName );

    return newRes;
}
Ejemplo n.º 2
0
Structure* PDBReader::readStructure(Alphabet* alphabet, char* filename, const char* backboneAtomName) {

    FILE* infile = fopen(filename, "r");
    
    if (infile == NULL) {
        return 0;
    }
    
    Structure* structure = new Structure(alphabet, filename);

    // Create the entries from the PDB file.
    char recordType[7];
    char serialNumber[6];
    char atomName[5];
    char altLoc[2];
    char residueName[4];
    char chain[2];
    char resID[5];
    char insertion[2];
    char x[9];
    char y[9];
    char z[9];
  
    // Go through the file and parse out the records.
    char line[1024];
    Coordinate3D backboneCoord;
    Residue* currentResidue = NULL;
    while (!feof(infile)) {
      
        // Get the next line.
        if (fgets(line, 1023, infile) == NULL)
            break;
      
        // Make sure this is an atom or hetatom record.
        parseField(recordType, line, 0, 6);
        if (strcmp(recordType, "ATOM") == 0 || strcmp(recordType, "HETATOM") == 0)
        {
            // Parse the fields.
            parseField(serialNumber, line, 6, 5);
            parseField(atomName, line, 12, 4);
            parseField(altLoc, line, 16, 1);
            parseField(residueName, line, 17, 3);
            parseField(chain, line, 21, 1);
            parseField(resID, line, 22, 4);
            parseField(insertion, line, 26, 1);
            parseField(x, line, 30, 8);
            parseField(y, line, 38, 8);
            parseField(z, line, 46, 8);
            
            // If this is a new residue, save the old one (if we have one) and start over.
            if (currentResidue == NULL || (strcmp(resID, currentResidue->getResID()) != 0 || strcmp(insertion, currentResidue->getInsertionName()) != 0))
            {
                if (currentResidue != NULL)
                {
                    structure->addResidue(currentResidue->getName(), backboneCoord, currentResidue);
                }
                
                // Start the new residue.
                backboneCoord.unset();
                currentResidue = new Residue(residueName, resID, insertion);
            }
            
            // If this is a backbone atom, save it.
            if (strcmp(atomName, backboneAtomName) == 0)
            {
                backboneCoord.set(charToFloat(x), charToFloat(y), charToFloat(z));
            }
            
            // Add the atom to the list.
            currentResidue->addAtom(new Atom(atomName, charToFloat(x),charToFloat(y),charToFloat(z)));
        }
        else if (strcmp(recordType, "TER") == 0)
        {
            break;
        }
    
    }
    
    // If we have one last residue, save it.
    if (currentResidue != NULL)
    {
        structure->addResidue(currentResidue->getName(), backboneCoord, currentResidue);
    }
                
    fclose(infile);

    return structure;
}