Logo Search packages:      
Sourcecode: cdk version File versions  Download package

void org::openscience::cdk::smiles::SmilesGenerator::parseAtom ( IAtom  a,
StringBuffer  buffer,
IAtomContainer  container,
boolean  chiral,
boolean[]  doubleBondConfiguration,
IAtom  parent,
Vector  atomsInOrderOfSmiles,
Vector  currentChain,
boolean  useAromaticity 
) [inline, private]

Generates the SMILES string for the atom

Parameters:
a the atom to generate the SMILES for.
buffer the string buffer that the atom is to be apended to.
container the AtomContainer to analyze.
chiral is a chiral smiles wished?
parent the atom we came from.
atomsInOrderOfSmiles a vector containing the atoms in the order they are in the smiles.
currentChain The chain we currently deal with.
useAromaticity true=aromaticity or sp2 will trigger lower case letters, wrong=only sp2

Definition at line 1539 of file SmilesGenerator.java.

References generateChargeString(), generateMassString(), org::openscience::cdk::interfaces::IAtomContainer::getBond(), org::openscience::cdk::interfaces::IChemObject::getFlag(), org::openscience::cdk::interfaces::IAtomType::getHybridization(), org::openscience::cdk::interfaces::IBond::getOrder(), org::openscience::cdk::interfaces::IChemObject::getProperty(), getRingOpenings(), org::openscience::cdk::interfaces::IElement::getSymbol(), isEndOfDoubleBond(), and isStartOfDoubleBond().

Referenced by parseChain().

      {
            String symbol = a.getSymbol();
            boolean stereo = BondTools.isStereo(container, a);
            boolean brackets = symbol.equals("B") || symbol.equals("C") || symbol.equals("N") || symbol.equals("O") || symbol.equals("P") || symbol.equals("S") || symbol.equals("F") || symbol.equals("Br") || symbol.equals("I") || symbol.equals("Cl");
            brackets = !brackets;
            //logger.debug("in parseAtom()");
            //Deal with the start of a double bond configuration
            if (isStartOfDoubleBond(container, a, parent, doubleBondConfiguration))
            {
                  buffer.append('/');
            }

            if (a instanceof IPseudoAtom)
            {
                  buffer.append("[*]");
            } else
            {
                  String mass = generateMassString(a);
                  brackets = brackets | !mass.equals("");

                  String charge = generateChargeString(a);
                  brackets = brackets | !charge.equals("");

                  if (chiral && stereo && (BondTools.isTrigonalBipyramidalOrOctahedral(container, a)!=0 || BondTools.isSquarePlanar(container, a) || BondTools.isTetrahedral(container, a,false) != 0 || BondTools.isSquarePlanar(container, a)))
                  {
                        brackets = true;
                  }
                  if (brackets)
                  {
                        buffer.append('[');
                  }
                  buffer.append(mass);
                  if ((useAromaticity && a.getFlag(CDKConstants.ISAROMATIC)) || (a.getHybridization() != CDKConstants.UNSET && a.getHybridization() == CDKConstants.HYBRIDIZATION_SP2))
                  {
                        buffer.append(a.getSymbol().toLowerCase());
                  } else
                  {
                        buffer.append(symbol);
                  }
                  if (a.getProperty(RING_CONFIG) != null && a.getProperty(RING_CONFIG).equals(UP))
                  {
                        buffer.append('/');
                  }
                  if (a.getProperty(RING_CONFIG) != null && a.getProperty(RING_CONFIG).equals(DOWN))
                  {
                        buffer.append('\\');
                  }
                  if (chiral && stereo && (BondTools.isTrigonalBipyramidalOrOctahedral(container, a)!=0 || BondTools.isSquarePlanar(container, a) || BondTools.isTetrahedral(container, a,false) != 0))
                  {
                        buffer.append('@');
                  }
                  if (chiral && stereo && BondTools.isSquarePlanar(container, a))
                  {
                        buffer.append("SP1");
                  }
                  //chiral
                  //hcount
                  buffer.append(charge);
                  if (brackets)
                  {
                        buffer.append(']');
                  }
            }
            //logger.debug("in parseAtom() after dealing with Pseudoatom or not");
            //Deal with the end of a double bond configuration
            if (isEndOfDoubleBond(container, a, parent, doubleBondConfiguration))
            {
                  IAtom viewFrom = null;
                  for (int i = 0; i < currentChain.size(); i++)
                  {
                        if (currentChain.get(i) == parent)
                        {
                              int k = i - 1;
                              while (k > -1)
                              {
                                    if (currentChain.get(k) instanceof IAtom)
                                    {
                                          viewFrom = (IAtom) currentChain.get(k);
                                          break;
                                    }
                                    k--;
                              }
                        }
                  }
                  if (viewFrom == null)
                  {
                        for (int i = 0; i < atomsInOrderOfSmiles.size(); i++)
                        {
                              if (atomsInOrderOfSmiles.get(i) == parent)
                              {
                                    viewFrom = (IAtom) atomsInOrderOfSmiles.get(i - 1);
                              }
                        }
                  }
                  boolean afterThisAtom = false;
                  IAtom viewTo = null;
                  for (int i = 0; i < currentChain.size(); i++)
                  {
                        if (afterThisAtom && currentChain.get(i) instanceof IAtom)
                        {
                              viewTo = (IAtom) currentChain.get(i);
                              break;
                        }
                        if (afterThisAtom && currentChain.get(i) instanceof Vector)
                        {
                              viewTo = (IAtom) ((Vector) currentChain.get(i)).get(0);
                              break;
                        }
                        if (a == currentChain.get(i))
                        {
                              afterThisAtom = true;
                        }
                  }
      try{
        if (BondTools.isCisTrans(viewFrom,a,parent,viewTo,container))
        {
          buffer.append('\\');
        } else
        {
          buffer.append('/');
        }
      }catch(CDKException ex){
        //If the user wants a double bond configuration, where there is none, we ignore this.
      }
            }
            Vector v = new Vector();
            Iterator it = getRingOpenings(a, v).iterator();
            Iterator it2 = v.iterator();
            //logger.debug("in parseAtom() after checking for Ring openings");
            while (it.hasNext())
            {
                  Integer integer = (Integer) it.next();
                  IAtom a2=(IAtom) it2.next();
                  IBond b = container.getBond(a2, a);
                  int type = (int) b.getOrder();
                  if (!(useAromaticity && a.getFlag(CDKConstants.ISAROMATIC) && a2.getFlag(CDKConstants.ISAROMATIC))){
                        if (type == 2) {
                              buffer.append("=");
                        } else if (type == 3) {
                              buffer.append("#");
                        }
                  }
                  buffer.append(integer);
            }
            atomsInOrderOfSmiles.add(a);
            //logger.debug("End of parseAtom()");
      }


Generated by  Doxygen 1.6.0   Back to index