code: protected IAtomContainer buildMolecule(int mainChain, List<AttachedGroup> attachedSubstituents,
              List<AttachedGroup> attachedGroups, boolean isMainCyclic, String name) throws ParseException, CDKException {
          //Set up the molecle's name
          currentMolecule.setID(name);
          //Build the main chain
          currentMolecule.add(buildChain(mainChain, isMainCyclic));
  
          //Set the last atom here if a main chain has been built,
          //if not rely on the functional group setting one of it's atoms as last
          if (mainChain != 0) endOfChain = currentMolecule.getAtom(currentMolecule.getAtomCount()-1);
  
          //Add functional groups
          buildFunGroups(attachedGroups);
  
          //Add on further sub chains
          addHeads(attachedSubstituents);
  
          //Add the hydrogens to create a balanced molecule
          CDKAtomTypeMatcher matcher = CDKAtomTypeMatcher.getInstance(currentMolecule.getBuilder());
          Iterator<IAtom> atoms = currentMolecule.atoms().iterator();
          while (atoms.hasNext()) {
              IAtom atom = atoms.next();
              IAtomType type = matcher.findMatchingAtomType(currentMolecule, atom);
              AtomTypeManipulator.configure(atom, type);
          }
          CDKHydrogenAdder hAdder = CDKHydrogenAdder.getInstance(currentMolecule.getBuilder());
          hAdder.addImplicitHydrogens(currentMolecule);
  
          return currentMolecule;
      }
docs: Start of the process of building a molecule from the parsed data. Passes the parsed
  tokens to other functions which build up the Molecule.
  
  @param mainChain The string representation of the length of the main chain.
  @param attachedSubstituents A vector of AttachedGroup's representing substituents.
  @param attachedGroups A vector of AttachedGroup's representing functional groups.
  @param isMainCyclic An indication of if the main chain is cyclic.
  @return The molecule as built from the parsed tokens.