/** adds a atom. * reroutes to addAtom(atom) * @param atom to add * @return added atom or null * @throws RuntimeException if already child or duplicate hash */ public CMLAtom appendChild(CMLAtom atom) { CMLAtom atom0 = this.addAtom(atom); return atom0; }
/** An array of atom IDs. * * Normally an attribute of an array-based element. * --type info-- * * An array of atomRefs. * The atomRefs * cannot be schema- or schematron-validated. Instances of this type will * be used in array-style representation of bonds and atomParitys. * It can also be used for arrays of atomIDTypes such as in complex stereochemistry, * geometrical definitions, atom groupings, etc. * * JUMBO expands this into atoms. If any atoms are already present * throws an error. * * @param atomIDs * @throws RuntimeException duplicate atom, bad id, etc */ public void setAtomID(String[] atomIDs) throws RuntimeException { if (atomIDs == null) { throw new RuntimeException("null atomIDs"); } if (this.getAtoms().size() > 0) { throw new RuntimeException("Cannot use atomID with existing children"); } for (String s : atomIDs) { CMLAtom atom = new CMLAtom(s); this.addAtom(atom); } }
/** add atom. * * only if in same molecule. If already added returns with no-op * cannot add to child molecule. However if 'this' is a child of * a CMLMolecule throws Exception * @param atom * @throws RuntimeException * null, non-uniqueID, etc. */ public void addAtom(CMLAtom atom) throws RuntimeException { if (atom != null) { //ParentNode parent = this.getParent(); //if (parent instanceof CMLMolecule) { // throw new RuntimeException("Cannot add atom to child molecule"); //} CMLAtomArray atomArray = getOrCreateAtomArray(); // should it be atom array that tests this? String id = atom.getId(); if (id == null) { throw new RuntimeException("Null atom ID"); } CMLAtom oldAtom = atomArray.getAtomById(id); if (oldAtom == null) { atomArray.addAtom(atom); } } else { throw new RuntimeException("Cannot add null atom"); } }