/** * copy node . * * @return Node */ public Node copy() { return new CMLAtomArray(this); }
/** 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; }
void deleteLigandBonds() { List<CMLAtom> atomList = this.getAtoms(); for (CMLAtom atom : atomList) { deleteLigandBonds(atom); } }
private String normalizeConciseAndFormalCharge(String conciseS, int formalCharge) { if (conciseS != null) { CMLAtomArray atomArray = createAndAddAtomArrayAndFormalChargeFromConcise(conciseS); if (atomArray != null) { atomArray.sort(Sort.CHFIRST); conciseS = atomArray.generateConcise(formalCharge); } } return conciseS; }
atomArray = new CMLAtomArray(); setAtomArray(atomArray); atomArray.setElementTypeAndCount(new String[0], new double[0]); System.arraycopy(counts, 0, newCount, 0, nelem); newCount[nelem] = count; atomArray.setElementTypeAndCount(newElem, newCount); } else { atomArray.setElementTypeAndCount(elements, counts); String conciseS = atomArray.generateConcise(formalCharge); super.setConcise(conciseS);
CMLAtomArray ar = new CMLAtomArray(); for (int i = 0; i < residue.getAtomCount(); i++) { CMLAtom cmlAtom = new CMLAtom(); ar.addAtom(cmlAtom); CMLAtomArray ar = new CMLAtomArray(); for (int i = 0; i < chargeGroup.getAtomCount(); i++) { CMLAtom cmlAtom = new CMLAtom(); cmlAtom.addScalar(scalar); ar.addAtom(cmlAtom);
/** 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"); } }
/** * gets atom by id. * * @param id * @return the atom or null */ public CMLAtom getAtomById(String id) { CMLAtom atom = null; if (id != null) { CMLAtomArray atomArray = getAtomArray(); // use atomArray first in case there are child molecules if (atomArray != null) { // crude check for update index if (atomArray.atomMap.size() != atomArray.getAtomElements().size()) { atomArray.indexAtoms(); } atom = atomArray.getAtomById(id); } else if (getMoleculeCount() > 0) { getChildMoleculeAtomMap(); List<CMLAtom> atomList = childMoleculeAtomMap.get(id); if (atomList != null && atomList.size() == 1) { atom = atomList.get(0); } } } return atom; }
CMLAtomArray createAndAddAtomArrayAndFormalChargeFromConcise( String concise) { CMLAtomArray atomArray = new CMLAtomArray(); if (concise != null) { List<String> elements = new ArrayList<String>(); countD[i] = counts.get(i).doubleValue(); atomArray.setElementTypeAndCount((String[]) elements.toArray(new String[0]), countD);
atomArray.setElementTypeAndCount(elems, counts); } else { this.setConcise(concise1); CMLAtomArray fAtomArray = fNew.getAtomArrayElements().get(0); fAtomArray.detach(); this.addAtomArray(fAtomArray); .get(0).generateConcise((int) (this.getFormalCharge() * d)); super.setConcise(concise);
/** * removes a atom. * * @param atom * @return deleted atom or null */ public CMLAtom removeAtom(CMLAtom atom) { CMLAtom deletedAtom = null; if (this.equals(atom.getParent())) { super.removeChild(atom); if (atomMap != null) { atomMap.remove(atom.getId()); } deleteLigandBonds(atom); deletedAtom = atom; } return deletedAtom; }
/** * * mainly used for software such as Jmol which dislikes * child atomArrays */ public void detachAllAtomArraysAsTheyAreAMenace() { CMLElements<CMLAtomArray> atomArrays = this.getAtomArrayElements(); for (CMLAtomArray atomArray : atomArrays) { atomArray.detach(); } }
/** get list of atoms in order. * * @return atoms */ public List<CMLAtom> getAtoms() { List<CMLAtom> atomList = new ArrayList<CMLAtom>(); CMLElements<CMLAtom> atoms = this.getAtomElements(); for (CMLAtom atom : atoms) { atomList.add(atom); } return atomList; }
/** * gets atom by id. * * @param id * @return the atom or null */ public CMLAtom getAtomByIdXX(String id) { CMLAtom atom = null; if (getMoleculeCount() > 0) { getChildMoleculeAtomMap(); List<CMLAtom> atomList = childMoleculeAtomMap.get(id); if (atomList != null && atomList.size() == 1) { atom = atomList.get(0); } } else { CMLAtomArray atomArray = getAtomArray(); if (atomArray != null) { atom = atomArray.getAtomById(id); } } return atom; }
/** formula-specific. * * @param elem * @param count * @throws RuntimeException */ public void setElementTypeAndCount(String[] elem, double[] count) throws RuntimeException { if (elem.length > 0 && count.length > 0) { StringArraySTAttribute att = new StringArraySTAttribute("elementType"); att.setCMLValue(elem); this.addAttribute(att); DoubleArraySTAttribute datt = new DoubleArraySTAttribute("count"); datt.setCMLValue(count); this.addAttribute(datt); } } /** The identity of a chemical element.
/** index all the bonds by atom hash. * and by bond id */ public void indexBonds() { CMLMolecule molecule = this.getMolecule(); if (molecule == null) { throw new RuntimeException("Cannot index bonds without molecule"); } CMLAtomArray atomArray = molecule.getAtomArray(); if (atomArray == null) { throw new RuntimeException("Cannot index bonds without atoms"); } atomArray.clearLigandInfo(); List<CMLBond> bonds = this.getBonds(); bondMap.clear(); bondIdMap.clear(); for (CMLBond bond : bonds) { try { indexBondAndLigands(bond); indexBondId(bond); } catch (RuntimeException e) { LOG.warn("BUG: SKIPPED BOND (maybe coincident)"); } } }
} else if (atomArrays.size() == 1) { atomArray = atomArrays.get(0); atomArray.sort(Sort.CHFIRST); atomArray2Concise = atomArray.generateConcise(formalCharge); atomArray.sort(Sort.CHFIRST); removeZeroAtomCounts();
private void setAtomArray(CMLAtomArray atomArray) { for (CMLAtomArray aa : this.getAtomArrayElements()) { aa.detach(); } super.appendChild(atomArray); }
/** get number of child atoms. * * @return count */ public int size() { return this.getAtomElements().size(); }