Create a new CDK {@link IAtom} from the Beam Atom. If the element is
unknown (i.e. '*') then an pseudo atom is created.

@param atom an Atom from the Beam Graph
@return the CDK atom to have it's properties set
779519
IAtom newCDKAtom(Atom atom) {
        Element element = atom.element();
        boolean unknown = element == Element.Unknown;
        if (unknown) {
            IPseudoAtom pseudoAtom = builder.newInstance(IPseudoAtom.class, element.symbol());
            pseudoAtom.setSymbol(element.symbol());
            pseudoAtom.setLabel(atom.label());
            return pseudoAtom;
        }
        return createAtom(element);
    }
628751
@Override
    public void setAtoms(IAtom[] atoms) {
        this.atoms = atoms;
        atomCount = atoms.length;
        notifyChanged();
    }
205091
public IAtomContainer generate() throws CDKException {
        boolean structureFound = false;
        boolean bondFormed;
        double order;
        double max, cmax1, cmax2;
        int iteration = 0;
        IAtom partner;
        IAtom atom;
        do {
            iteration++;
            atomContainer.removeAllElectronContainers();
            do {
                bondFormed = false;
                for (int f = 0; f < atomContainer.getAtomCount(); f++) {
                    atom = atomContainer.getAtom(f);

                    if (!satCheck.isSaturated(atom, atomContainer)) {
                        partner = getAnotherUnsaturatedNode(atom);
                        if (partner != null) {
                            cmax1 = satCheck.getCurrentMaxBondOrder(atom, atomContainer);

                            cmax2 = satCheck.getCurrentMaxBondOrder(partner, atomContainer);
                            max = Math.min(cmax1, cmax2);
                            order = Math.min(Math.max(1.0, random.nextInt((int) Math.round(max))), 3.0);
                            logger.debug("Forming bond of order ", order);
                            atomContainer.addBond(atomContainer.getBuilder().newInstance(IBond.class, atom, partner,
                                    BondManipulator.createBondOrder(order)));
                            bondFormed = true;
                        }
                    }
                }
            } while (bondFormed);
            if (ConnectivityChecker.isConnected(atomContainer) && satCheck.allSaturated(atomContainer)) {
                structureFound = true;
            }
        } while (!structureFound && iteration < 20);
        logger.debug("Structure found after #iterations: ", iteration);
        return atomContainer.getBuilder().newInstance(IAtomContainer.class, atomContainer);
    }
1245836
public IAtomContainer getPlacedHeavyAtoms(IAtomContainer molecule, IAtom atom) {

        List<IBond> bonds = molecule.getConnectedBondsList(atom);
        IAtomContainer connectedAtoms = molecule.getBuilder().newInstance(IAtomContainer.class);
        IAtom connectedAtom = null;
        for (IBond bond : bonds) {
            connectedAtom = bond.getOther(atom);
            if (isPlacedHeavyAtom(connectedAtom)) {
                connectedAtoms.addAtom(connectedAtom);
            }
        }
        return connectedAtoms;
    }
290202
@Override
    public DescriptorValue calculate(IAtom atom, IAtomContainer container) {
        int atomValence = AtomValenceTool.getValence(atom);
        return new DescriptorValue(getSpecification(), getParameterNames(), getParameters(), new IntegerResult(
                atomValence), getDescriptorNames());
    }
190576
@Override
    public Iterable<IAtom> atoms() {
        return new Iterable<IAtom>() {

            @Override
            public Iterator<IAtom> iterator() {
                return new AtomsIterator();
            }
        };
    }
281772
@Override
    public StereoEncoder create(IAtomContainer container, int[][] graph) {

        // XXX: this code isn't pretty, the current IAtomContainer
        // implementations are  slow for the queries (i.e. looking at connected
        // atoms/bonds) we need to ask to decide if something is a potential
        // tetrahedral centre. We can help out a little with the adjacency list
        // (int[][]) but this doesn't help with the bonds.

        int n = container.getAtomCount();

        List<StereoEncoder> encoders = new ArrayList<StereoEncoder>();
        Map<IAtom, Integer> elevation = new HashMap<IAtom, Integer>(10);

        ATOMS: for (int i = 0; i < n; i++) {

            int degree = graph[i].length;

            // ignore those which don't have 3 or 4 neighbors
            if (degree < 3 || degree > 4) continue;

            IAtom atom = container.getAtom(i);

            // only create encoders for SP3 hybridized atom. atom typing is
            // currently wrong for some atoms, in sulfoxide for example the atom
            // type sets SP2... but there we don't to fuss about with that here
            if (!sp3(atom)) continue;

            // avoid nitrogen-inversion
            if (Integer.valueOf(7).equals(atom.getAtomicNumber()) && degree == 3) continue;

            // TODO: we could be more strict with our selection, InChI uses C,
            // Si, Ge, P, As, B, Sn, N, P, S, Se but has preconditions for
            // certain cases. An atom or ion N, P, As, S or Se is not stereogenic
            // if it has a terminal H or two terminal neighbors -XHm, -XHn (n+m>0)
            // where X is O, S, Se, Te, or N

            // XXX: likely bottle neck
            List<IBond> bonds = container.getConnectedBondsList(atom);

            // try to create geometric parity
            GeometricParity geometric = geometric(elevation, bonds, i, graph[i], container);

            if (geometric != null) {
                // add a new encoder if a geometric parity
                encoders.add(new GeometryEncoder(i, new BasicPermutationParity(graph[i]), geometric));
            }
        }

        // no encoders, replace with the empty encoder
        return encoders.isEmpty() ? StereoEncoder.EMPTY : new MultiStereoEncoder(encoders);
    }
322141
private IAtomContainer getUnplacedAtoms(IAtom atom) {
        IAtomContainer unplacedAtoms = atom.getBuilder().newInstance(IAtomContainer.class);
        List bonds = molecule.getConnectedBondsList(atom);
        IAtom connectedAtom;
        for (int f = 0; f < bonds.size(); f++) {
            connectedAtom = ((IBond) bonds.get(f)).getOther(atom);
            if (!connectedAtom.getFlag(CDKConstants.ISPLACED)) {
                unplacedAtoms.addAtom(connectedAtom);
            }
        }
        return unplacedAtoms;
    }
713361
public static Chain getRepresentativeAtomsOnly(Chain chain){

		Chain newChain = new ChainImpl();
		newChain.setId(chain.getId());
		newChain.setName(chain.getName());
		newChain.setEntityInfo(chain.getEntityInfo());
		newChain.setSwissprotId(chain.getSwissprotId());

		List<Group> groups = chain.getAtomGroups();

		grouploop:
			for (Group g: groups){
				List<Atom> atoms = g.getAtoms();

				if ( ! (g instanceof AminoAcid))
					continue;

				for (Atom a : atoms){

					if ( a.getName().equals(StructureTools.CA_ATOM_NAME) && a.getElement()==Element.C){
						// we got a CA atom in this group!
						AminoAcid n = new AminoAcidImpl();
						n.setPDBName(g.getPDBName());
						n.setResidueNumber(g.getResidueNumber());
						n.addAtom(a);
						newChain.addGroup(n);
						continue grouploop;

					}
				}

			}
		return newChain;
	}
597660
IAtom toCDKAtom(Atom beamAtom, int hCount) {

        IAtom cdkAtom = newCDKAtom(beamAtom);

        cdkAtom.setImplicitHydrogenCount(hCount);
        cdkAtom.setFormalCharge(beamAtom.charge());

        if (beamAtom.isotope() >= 0) cdkAtom.setMassNumber(beamAtom.isotope());

        if (beamAtom.aromatic()) cdkAtom.setIsAromatic(true);

        if (beamAtom.atomClass() > 0) cdkAtom.setProperty(ATOM_ATOM_MAPPING, beamAtom.atomClass());

        return cdkAtom;
    }
465459
public IAtomContainer assignInductivePartialCharges(IAtomContainer ac) throws Exception {
        if (factory == null) {
            factory = AtomTypeFactory
                    .getInstance("org/openscience/cdk/config/data/jmol_atomtypes.txt", ac.getBuilder());
        }

        int stepsLimit = 9;
        IAtom[] atoms = AtomContainerManipulator.getAtomArray(ac);
        double[] pChInch = new double[atoms.length * (stepsLimit + 1)];
        double[] ElEn = new double[atoms.length * (stepsLimit + 1)];
        double[] pCh = new double[atoms.length * (stepsLimit + 1)];
        double[] startEE = getPaulingElectronegativities(ac, true);
        for (int e = 0; e < atoms.length; e++) {
            ElEn[e] = startEE[e];
            //logger.debug("INDU: initial EE "+startEE[e]);
        }
        //double tmp1 = 0;
        //double tmp2 = 0;
        for (int s = 1; s < 10; s++) {
            for (int a = 0; a < atoms.length; a++) {
                pChInch[a + (s * atoms.length)] = getAtomicChargeIncrement(ac, a, ElEn, s);
                pCh[a + (s * atoms.length)] = pChInch[a + (s * atoms.length)] + pCh[a + ((s - 1) * atoms.length)];
                ElEn[a + (s * atoms.length)] = ElEn[a + ((s - 1) * atoms.length)]
                        + (pChInch[a + (s * atoms.length)] / getAtomicSoftnessCore(ac, a));
                if (s == 9) {
                    atoms[a].setProperty("InductivePartialCharge", new Double(pCh[a + (s * atoms.length)]));
                    atoms[a].setProperty("EffectiveAtomicElectronegativity", new Double(ElEn[a + (s * atoms.length)]));
                }
                //tmp1 = pCh[a + (s * atoms.length)];
                //tmp2 = ElEn[a + (s * atoms.length)];
                //logger.debug("DONE step " + s + ", atom " + atoms[a].getSymbol() + ", ch " + tmp1 + ", ee " + tmp2);
            }
        }
        return ac;
    }
20273
public void writeMolecule(IAtomContainer molecule) throws CDKException {

        try {
            writeHeader();
            int atomNumber = 1;

            String hetatmRecordName = (writeAsHET.isSet()) ? "HETATM" : "ATOM  ";
            String id = molecule.getID();
            String residueName = (id == null || id.equals("")) ? "MOL" : id;
            String terRecordName = "TER";

            // Loop through the atoms and write them out:
            StringBuffer buffer = new StringBuffer();
            Iterator<IAtom> atoms = molecule.atoms().iterator();
            FormatStringBuffer fsb = new FormatStringBuffer("");
            String[] connectRecords = null;
            if (writeCONECTRecords.isSet()) {
                connectRecords = new String[molecule.getAtomCount()];
            }
            while (atoms.hasNext()) {
                buffer.setLength(0);
                buffer.append(hetatmRecordName);
                fsb.reset(SERIAL_FORMAT).format(atomNumber);
                buffer.append(fsb.toString());
                buffer.append(' ');
                IAtom atom = atoms.next();
                String name;
                if (useElementSymbolAsAtomName.isSet()) {
                    name = atom.getSymbol();
                } else {
                    if (atom.getID() == null || atom.getID().equals("")) {
                        name = atom.getSymbol();
                    } else {
                        name = atom.getID();
                    }
                }
                fsb.reset(ATOM_NAME_FORMAT).format(name);
                buffer.append(fsb.toString());
                fsb.reset(RESIDUE_FORMAT).format(residueName);
                buffer.append(fsb).append("     0    ");
                Point3d position = atom.getPoint3d();
                fsb.reset(POSITION_FORMAT).format(position.x);
                buffer.append(fsb.toString());
                fsb.reset(POSITION_FORMAT).format(position.y);
                buffer.append(fsb.toString());
                fsb.reset(POSITION_FORMAT).format(position.z);
                buffer.append(fsb.toString());

                buffer.append("  1.00  0.00           ") // occupancy + temperature factor
                      .append(atom.getSymbol());
                Integer formalCharge = atom.getFormalCharge();
                if (formalCharge == CDKConstants.UNSET) {
                    buffer.append("+0");
                } else {
                    if (formalCharge < 0) {
                        buffer.append(formalCharge);
                    } else {
                        buffer.append('+').append(formalCharge);
                    }
                }

                if (connectRecords != null && writeCONECTRecords.isSet()) {
                    List<IAtom> neighbours = molecule.getConnectedAtomsList(atom);
                    if (neighbours.size() != 0) {
                        StringBuffer connectBuffer = new StringBuffer("CONECT");
                        connectBuffer.append(String.format("%5d", atomNumber));
                        for (IAtom neighbour : neighbours) {
                            int neighbourNumber = molecule.indexOf(neighbour) + 1;
                            connectBuffer.append(String.format("%5d", neighbourNumber));
                        }
                        connectRecords[atomNumber - 1] = connectBuffer.toString();
                    } else {
                        connectRecords[atomNumber - 1] = null;
                    }
                }

                writer.write(buffer.toString(), 0, buffer.length());
                writer.write('\n');
                ++atomNumber;
            }

            if (writeTERRecord.isSet()) {
                writer.write(terRecordName, 0, terRecordName.length());
                writer.write('\n');
            }

            if (connectRecords != null && writeCONECTRecords.isSet()) {
                for (String connectRecord : connectRecords) {
                    if (connectRecord != null) {
                        writer.write(connectRecord);
                        writer.write('\n');
                    }
                }
            }

            if (writeENDRecord.isSet()) {
                writer.write("END   ");
                writer.write('\n');
            }

        } catch (IOException exception) {
            throw new CDKException("Error while writing file: " + exception.getMessage(), exception);
        }
    }
969763
public static CeSymmResult analyze(Atom[] atoms) throws StructureException {
		CESymmParameters params = new CESymmParameters();
		return analyze(atoms, params);
	}
1366819
public IAtomContainer assignMMFF94PartialCharges(IAtomContainer ac) throws CDKException {
        if (!mmff.assignAtomTypes(ac))
            throw new CDKException("Molecule had an atom of unknown MMFF type");
        mmff.partialCharges(ac);
        mmff.clearProps(ac);
        for (IAtom atom : ac.atoms())
            atom.setProperty(MMFF_94_CHARGE, atom.getCharge());
        return ac;
    }
1304941
public double getCurrentMaxBondOrder(IAtom atom, IAtomContainer ac) throws CDKException {
        IAtomType[] atomTypes = getAtomTypeFactory(atom.getBuilder()).getAtomTypes(atom.getSymbol());
        if (atomTypes.length == 0) return 0;
        double bondOrderSum = ac.getBondOrderSum(atom);
        Integer hcount = atom.getImplicitHydrogenCount() == CDKConstants.UNSET ? 0 : atom.getImplicitHydrogenCount();
        double max = 0;
        double current = 0;
        for (int f = 0; f < atomTypes.length; f++) {
            current = hcount + bondOrderSum;
            if (atomTypes[f].getBondOrderSum() - current > max) {
                max = atomTypes[f].getBondOrderSum() - current;
            }
        }
        return max;
    }
1016557
@Override
    public Color getAtomColor(IAtom atom, Color defaultColor) {
        Color color = defaultColor;
        String symbol = atom.getSymbol().toUpperCase();
        if (atom.getAtomicNumber() != null && ATOM_COLORS_MASSNUM.containsKey(atom.getAtomicNumber())) {
            color = ATOM_COLORS_MASSNUM.get(atom.getAtomicNumber()); // lookup by atomic number.
        } else if (ATOM_COLORS_SYMBOL.containsKey(symbol)) {
            color = ATOM_COLORS_SYMBOL.get(symbol); // lookup by atomic symbol.
        }

        return new Color(color.getRed(), color.getGreen(), color.getBlue()); // return atom copy.
    }
318945
public IAtom getUnplacedRingHeavyAtom(IAtomContainer molecule, IAtom atom) {
        List<IBond> bonds = molecule.getConnectedBondsList(atom);
        IAtom connectedAtom = null;
        for (IBond bond : bonds) {
            connectedAtom = bond.getOther(atom);
            if (isUnplacedHeavyAtom(connectedAtom) && connectedAtom.getFlag(CDKConstants.ISINRING)) {
                return connectedAtom;
            }
        }
        return connectedAtom;
    }