Creating a new plugin: 3
Parsing the ATOM records
In part 2, we created an array of String variables, where each entry in the array contained an ATOM record. This is still just text, though, so we need to extract the required data and convert it into the correct format - for example, the three coordinate values must each be converted into a Float and then combined into a single Vector.
First, we will need a structure for each atom. In part 1, we determined which data is needed, though I think now that we will also need the sequence number of the residue (amino acids in a peptide chain are usually referred to as residues) in the chain. The structure will therefore look like this:
struct ProtAtom
{
String atName; // the atom name (NOT the atomic symbol)
String resID; // the residue (amino acid) identifier, e.g. HIS for histidine
String chainID; // the chain identifier, usually A, B, C etc.
Int32 resSeq; // the number of the residue in the chain, normally from 1 to the number of residues
Vector atPos3D; // the coordinates of the atom in 3D space
Int32 atNumber; // the atom's atomic number
};
The fields in the ATOM record can be found online here. We can then use String::Substr() to extract characters from the correct location in the String, and store them in the structure.
Extracting data from a record
Since we know (see the above link) where each data item is located in the record, it's a simple matter to get each piece of data, like so:
String aline, temp;
ProtAtom pat;
Bool berror;
for (Int32 i = 0; i < atomStrings.GetCount(); i++)
{
aline = atomStrings[i];
// atom name
temp = aline.SubStr(12, 4);
temp.Trim() iferr_return;
pat.atName = temp;
// residue ID
temp = aline.SubStr(17, 3);
temp.Trim() iferr_return;
pat.resID = temp;
// residue sequence number
temp = aline.SubStr(22, 4);
temp.Trim() iferr_return;
Int32 inum = temp.ToInt32(&berror);
pat.resSeq = inum;
// repeat for other data items such as chain ID, atom position and atomic number
// ...
// add the completed record to the array
atomStructs.Append(pat) iferr_return;
}
For each record in the array 'atomStrings' we simply find the substring of the text containing each required data item, convert it to a number if necessary, store it into a 'ProtAtom' structure then add that to the array of atoms (the 'atomStructs' array). Once complete, we're ready to create the atoms. That will be in the next part of this series.
Page last updated May 22nd 2026
