private void writeAtomContainer ( IAtomContainerSet som ) throws IOException { //int na = 0; //String info = ""; String sym ; double chrg ; //boolean writecharge = true; for ( int molnum = 0 ; molnum < som . getAtomContainerCount ( ) ; molnum ++ ) { IAtomContainer mol = som . getAtomContainer ( molnum ) ; try { String molname = "mol " + ( molnum + 1 ) + " " + mol . getTitle ( ) ; writer . write ( molname , 0 , molname . length ( ) ) ; writer . write ( ' ' ) ; // Loop through the atoms and write them out: Iterator < IAtom > atoms = mol . atoms ( ) . iterator ( ) ; int i = 0 ; while ( atoms . hasNext ( ) ) { IAtom atom = atoms . next ( ) ; String line = "atom " ; sym = atom . getSymbol ( ) ; chrg = atom . getCharge ( ) ; Point3d point = atom . getPoint3d ( ) ; line = line + Integer . toString ( i + 1 ) + " - " + sym + " ** - " + Double . toString ( chrg ) + " " + Double . toString ( point . x ) + " " + Double . toString ( point . y ) + " " + Double . toString ( point . z ) + " " ; String buf = "" ; int ncon = 0 ; Iterator < IBond > bonds = mol . bonds ( ) . iterator ( ) ; while ( bonds . hasNext ( ) ) { IBond bond = bonds . next ( ) ; if ( bond . contains ( atom ) ) { // current atom is in the bond so lets get the connected atom IAtom connectedAtom = bond . getOther ( atom ) ; IBond . Order bondOrder = bond . getOrder ( ) ; int serial ; String bondType = "" ; // get the serial no for this atom serial = mol . indexOf ( connectedAtom ) ; if ( bondOrder == IBond . Order . SINGLE ) bondType = "s" ; else if ( bondOrder == IBond . Order . DOUBLE ) bondType = "d" ; else if ( bondOrder == IBond . Order . TRIPLE ) bondType = "t" ; else if ( bond . getFlag ( CDKConstants . ISAROMATIC ) ) bondType = "a" ; buf = buf + Integer . toString ( serial + 1 ) + " " + bondType + " " ; ncon ++ ; } } line = line + " " + Integer . toString ( ncon ) + " " + buf ; writer . write ( line , 0 , line . length ( ) ) ; writer . write ( ' ' ) ; i ++ ; } String buf = "endmol " + ( molnum + 1 ) ; writer . write ( buf , 0 , buf . length ( ) ) ; writer . write ( ' ' ) ; } catch ( IOException e ) { throw e ; } } }
writes all the molecules supplied in a MoleculeSet class to a single HIN file . You can also supply a single Molecule object as well