Logo
Toggle Menu
  • home
  • blog
  • about
    • about this site
    • contact
    • privacy policy
  • cinema 4d
    • plugins
    • creating c4d plugins
    • plugin cookbook
    • software
  • models
    • nodes
    • plants 1
    • other models - 1
    • other models - 2
  • osl
    • writing osl shaders
    • osl shaders for download

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

Blog articles

Creating a new plugin: 8 (June 4th 2026)

Creating a new plugin: 7 (May 31st 2026)

Creating a new plugin: 6 (May 28th 2026)

Creating a new plugin: 5 (May 26th 2026)

Creating a new plugin: 4 (May 23rd 2026)

Creating a new plugin: 3 (May 22nd 2026)

Creating a new plugin: 2 (May 20th 2026)

Creating a new plugin: 1 (May 17th 2026)

The 'Space' plugins (May 7th 2026)

Creating PBR materials (March 24th 2026)

Data Storage - Then and Now (March 6th 2026)

Old Poser assets (March 2nd 2026)

More Noise, please (January 18th 2026)

Using GIT in VS 2022 (December 26th 2025)

Handling missing plugins (December 12th 2025)

Plugin compatibility with R2026 (November 24th 2025)

Affinity is now free! (November 3rd 2025)

World Creator 2025.1 (October 10th 2025)

So that was Cinema R2026? (September 19th 2025)

How to browse 3D assets (August 24th 2025)

Using Unity assets in Cinema 4D (August 15th 2025)

Plant Factory->Cinema 4D->World Creator (August 12th 2025)

Viewing glTF files (August 9th 2025)

Tessellation part 2 (August 5th 2025)

Shader writing with OSL - 3 (July 11th 2025)

Tessellation (June 23rd 2025)

Creating plants for C4D (June 15th 2025)

Adobe alternatives (May 28th 2025)

Using Graswald assets in C4D (May 7th 2025)

Which Mac for plugin development? (May 3rd 2025)

Why do plugin writers do it? (April 11th 2025)

Updating StarScape (February 26th 2025)

Using Cinema 4D shaders in Redshift (January 31st 2025)

PHP and MySQL (December 19th 2024)

Shader writing with OSL - 2 (November 11th 2024)

Shader writing with OSL (October 29th 2024)

StarScape (September 25th 2024)

Converting plugins from C4D 2024 to 2025 (September 16th 2024)

Cinema 4D 2025 and macOS plugins (September 15th 2025)

© 2021-2025 Microbion. All Rights Reserved.