@ Override public StereoEncoder create ( IAtomContainer container , int [ ] [ ] graph ) { int n = container . getAtomCount ( ) ; BondMap map = new BondMap ( n ) ; List < StereoEncoder > encoders = new ArrayList < StereoEncoder > ( 1 ) ; // index double bonds by their atoms for ( IBond bond : container . bonds ( ) ) { if ( isDoubleBond ( bond ) ) map . add ( bond ) ; } Set < IAtom > visited = new HashSet < IAtom > ( n ) ; // find atoms which are connected between two double bonds for ( IAtom a : map . atoms ( ) ) { List < IBond > bonds = map . bonds ( a ) ; if ( bonds . size ( ) == 2 ) { // (s)tart/(e)nd of cumulated system: -s=a=e- IAtom s = bonds . get ( 0 ) . getOther ( a ) ; IAtom e = bonds . get ( 1 ) . getOther ( a ) ; // need the parents to re-use the double bond encoder IAtom sParent = a ; IAtom eParent = a ; visited . add ( a ) ; visited . add ( s ) ; visited . add ( e ) ; int size = 2 ; // expand out from 'l' while ( s != null && map . cumulated ( s ) ) { IAtom p = map . bonds ( s ) . get ( 0 ) . getOther ( s ) ; IAtom q = map . bonds ( s ) . get ( 1 ) . getOther ( s ) ; sParent = s ; s = visited . add ( p ) ? p : visited . add ( q ) ? q : null ; size ++ ; } // expand from 'r' while ( e != null && map . cumulated ( e ) ) { IAtom p = map . bonds ( e ) . get ( 0 ) . getOther ( e ) ; IAtom q = map . bonds ( e ) . get ( 1 ) . getOther ( e ) ; eParent = e ; e = visited . add ( p ) ? p : visited . add ( q ) ? q : null ; size ++ ; } // s and e are null if we had a cumulative cycle... if ( s != null && e != null ) { // system has now be expanded, size is the number of double // bonds. For odd numbers we use E/Z whilst for even are // axial M/P. // \ / // s = = = = e // / \ if ( isOdd ( size ) ) { StereoEncoder encoder = GeometricDoubleBondEncoderFactory . newEncoder ( container , s , sParent , e , eParent , graph ) ; if ( encoder != null ) { encoders . add ( encoder ) ; } } else { StereoEncoder encoder = axialEncoder ( container , s , e ) ; if ( encoder != null ) { encoders . add ( encoder ) ; } } } } } return encoders . isEmpty ( ) ? StereoEncoder . EMPTY : new MultiStereoEncoder ( encoders ) ; }
Create a stereo encoder for cumulative double bonds .