idx
int64
0
41.2k
question
stringlengths
73
5.81k
target
stringlengths
5
918
28,600
public int [ ] getTopoEquivClassbyHuXu ( IAtomContainer atomContainer ) throws NoSuchAtomException { double nodeSequence [ ] = prepareNode ( atomContainer ) ; nodeMatrix = buildNodeMatrix ( nodeSequence ) ; bondMatrix = buildBondMatrix ( ) ; weight = buildWeightMatrix ( nodeMatrix , bondMatrix ) ; return findTopoEquivClass ( weight ) ; }
Get the topological equivalent class of the molecule .
28,601
public double [ ] [ ] buildNodeMatrix ( double [ ] nodeSequence ) { int i , j , k ; for ( i = 0 ; i < nodeNumber ; i ++ ) { nodeMatrix [ i ] [ 0 ] = nodeSequence [ i ] ; for ( j = 1 ; j <= layerNumber ; j ++ ) { nodeMatrix [ i ] [ j ] = 0.0 ; for ( k = 0 ; k < nodeNumber ; k ++ ) { if ( apspMatrix [ i ] [ k ] == j ) { nodeMatrix [ i ] [ j ] += nodeSequence [ k ] ; } } } } return nodeMatrix ; }
Build node Matrix .
28,602
public double [ ] [ ] buildTrialNodeMatrix ( double [ ] weight ) { int i , j , k ; for ( i = 0 ; i < nodeNumber ; i ++ ) { nodeMatrix [ i ] [ 0 ] = weight [ i + 1 ] ; for ( j = 1 ; j <= layerNumber ; j ++ ) { nodeMatrix [ i ] [ j ] = 0.0 ; for ( k = 0 ; k < nodeNumber ; k ++ ) { if ( apspMatrix [ i ] [ k ] == j ) { nodeMatrix [ i ] [ j ] += weight [ k + 1 ] ; } } } } return nodeMatrix ; }
Build trial node Matrix .
28,603
public double [ ] [ ] buildBondMatrix ( ) { int i , j , k , m ; for ( i = 0 ; i < nodeNumber ; i ++ ) { for ( j = 1 ; j <= layerNumber ; j ++ ) { bondMatrix [ i ] [ j - 1 ] = 0.0 ; for ( k = 0 ; k < nodeNumber ; k ++ ) { if ( j == 1 ) { if ( apspMatrix [ i ] [ k ] == j ) { bondMatrix [ i ] [ j - 1 ] += adjaMatrix [ i ] [ k ] ; } } else { if ( apspMatrix [ i ] [ k ] == j ) { for ( m = 0 ; m < nodeNumber ; m ++ ) { if ( apspMatrix [ i ] [ m ] == ( j - 1 ) ) { bondMatrix [ i ] [ j - 1 ] += adjaMatrix [ k ] [ m ] ; } } } } } } } return bondMatrix ; }
Build bond matrix .
28,604
public double [ ] buildWeightMatrix ( double [ ] [ ] nodeMatrix , double [ ] [ ] bondMatrix ) { for ( int i = 0 ; i < nodeNumber ; i ++ ) { weight [ i + 1 ] = nodeMatrix [ i ] [ 0 ] ; for ( int j = 0 ; j < layerNumber ; j ++ ) { weight [ i + 1 ] += nodeMatrix [ i ] [ j + 1 ] * bondMatrix [ i ] [ j ] * Math . pow ( 10.0 , ( double ) - ( j + 1 ) ) ; } } weight [ 0 ] = 0.0 ; return weight ; }
Build weight array for the given node matrix and bond matrix .
28,605
public int checkDiffNumber ( double [ ] weight ) { double category [ ] = new double [ weight . length ] ; int i , j ; int count = 1 ; double t ; category [ 1 ] = weight [ 1 ] ; for ( i = 2 ; i < weight . length ; i ++ ) { for ( j = 1 ; j <= count ; j ++ ) { t = weight [ i ] - category [ j ] ; if ( t < 0.0 ) t = - t ; if ( t < LOST ) break ; } if ( j > count ) { count += 1 ; category [ count ] = weight [ i ] ; } } return count ; }
Get different number of the given number .
28,606
public int [ ] getEquivalentClass ( double [ ] weight ) { double category [ ] = new double [ weight . length ] ; int equivalentClass [ ] = new int [ weight . length ] ; int i , j ; int count = 1 ; double t ; category [ 1 ] = weight [ 1 ] ; for ( i = 2 ; i < weight . length ; i ++ ) { for ( j = 1 ; j <= count ; j ++ ) { t = weight [ i ] - category [ j ] ; if ( t < 0.0 ) { t = - t ; } if ( t < LOST ) { break ; } } if ( j > count ) { count += 1 ; category [ count ] = weight [ i ] ; } } for ( i = 1 ; i < weight . length ; i ++ ) { for ( j = 1 ; j <= count ; j ++ ) { t = weight [ i ] - category [ j ] ; if ( t < 0.0 ) { t = - t ; } if ( t < LOST ) { equivalentClass [ i ] = j ; } } } equivalentClass [ 0 ] = count ; return equivalentClass ; }
Get the final equivalent class .
28,607
public int [ ] findTopoEquivClass ( double [ ] weight ) { int trialCount , i ; int equivalentClass [ ] = new int [ weight . length ] ; int count = checkDiffNumber ( weight ) ; trialCount = count ; if ( count == nodeNumber ) { for ( i = 1 ; i <= nodeNumber ; i ++ ) { equivalentClass [ i ] = i ; } equivalentClass [ 0 ] = count ; return equivalentClass ; } do { count = trialCount ; double [ ] [ ] trialNodeMatrix = buildTrialNodeMatrix ( weight ) ; double [ ] trialWeight = buildWeightMatrix ( trialNodeMatrix , bondMatrix ) ; trialCount = checkDiffNumber ( trialWeight ) ; if ( trialCount == nodeNumber ) { for ( i = 1 ; i <= nodeNumber ; i ++ ) { equivalentClass [ i ] = i ; } equivalentClass [ 0 ] = count ; return equivalentClass ; } if ( trialCount <= count ) { equivalentClass = getEquivalentClass ( weight ) ; return equivalentClass ; } } while ( trialCount > count ) ; return equivalentClass ; }
Find the topological equivalent class for the given weight .
28,608
public static void prepare ( IAtomContainer container , boolean ringQuery ) { if ( ringQuery ) { SMARTSAtomInvariants . configureDaylightWithRingInfo ( container ) ; } else { SMARTSAtomInvariants . configureDaylightWithoutRingInfo ( container ) ; } }
Do not use - temporary method until the SMARTS packages are cleaned up .
28,609
private ValidationReport validateCharge ( IAtom atom ) { ValidationReport report = new ValidationReport ( ) ; ValidationTest tooCharged = new ValidationTest ( atom , "Atom has an unlikely large positive or negative charge" ) ; if ( atom . getSymbol ( ) . equals ( "O" ) || atom . getSymbol ( ) . equals ( "N" ) || atom . getSymbol ( ) . equals ( "C" ) || atom . getSymbol ( ) . equals ( "H" ) ) { if ( atom . getFormalCharge ( ) == 0 ) { report . addOK ( tooCharged ) ; } else { tooCharged . setDetails ( "Atom " + atom . getSymbol ( ) + " has charge " + atom . getFormalCharge ( ) ) ; if ( atom . getFormalCharge ( ) < - 3 ) { report . addError ( tooCharged ) ; } else if ( atom . getFormalCharge ( ) < - 1 ) { report . addWarning ( tooCharged ) ; } else if ( atom . getFormalCharge ( ) > 3 ) { report . addError ( tooCharged ) ; } else if ( atom . getFormalCharge ( ) > 1 ) { report . addWarning ( tooCharged ) ; } } } else { if ( atom . getFormalCharge ( ) == 0 ) { report . addOK ( tooCharged ) ; } else { tooCharged . setDetails ( "Atom " + atom . getSymbol ( ) + " has charge " + atom . getFormalCharge ( ) ) ; if ( atom . getFormalCharge ( ) < - 4 ) { report . addError ( tooCharged ) ; } else if ( atom . getFormalCharge ( ) < - 3 ) { report . addWarning ( tooCharged ) ; } else if ( atom . getFormalCharge ( ) > 4 ) { report . addError ( tooCharged ) ; } else if ( atom . getFormalCharge ( ) > 3 ) { report . addWarning ( tooCharged ) ; } } } return report ; }
the Atom tests
28,610
private ValidationReport validateStereoChemistry ( IBond bond ) { ValidationReport report = new ValidationReport ( ) ; ValidationTest bondStereo = new ValidationTest ( bond , "Defining stereochemistry on bonds is not safe." , "Use atom based stereochemistry." ) ; if ( bond . getStereo ( ) != IBond . Stereo . NONE ) { report . addWarning ( bondStereo ) ; } else { report . addOK ( bondStereo ) ; } return report ; }
the Bond tests
28,611
public ValidationReport validateIsotopeExistence ( IIsotope isotope ) { ValidationReport report = new ValidationReport ( ) ; ValidationTest isotopeExists = new ValidationTest ( isotope , "Isotope with this mass number is not known for this element." ) ; try { IsotopeFactory isotopeFac = Isotopes . getInstance ( ) ; IIsotope [ ] isotopes = isotopeFac . getIsotopes ( isotope . getSymbol ( ) ) ; if ( isotope . getMassNumber ( ) != null && isotope . getMassNumber ( ) != 0 ) { boolean foundKnownIsotope = false ; for ( int i = 0 ; i < isotopes . length ; i ++ ) { if ( Objects . equals ( isotopes [ i ] . getMassNumber ( ) , isotope . getMassNumber ( ) ) ) { foundKnownIsotope = true ; } } if ( ! foundKnownIsotope ) { report . addError ( isotopeExists ) ; } else { report . addOK ( isotopeExists ) ; } } else { report . addOK ( isotopeExists ) ; } } catch ( Exception exception ) { } return report ; }
the Isotope tests
28,612
private ValidationReport validateBondOrderSum ( IAtom atom , IAtomContainer molecule ) { ValidationReport report = new ValidationReport ( ) ; ValidationTest checkBondSum = new ValidationTest ( atom , "The atom's total bond order is too high." ) ; try { AtomTypeFactory structgenATF = AtomTypeFactory . getInstance ( "org/openscience/cdk/dict/data/cdk-atom-types.owl" , atom . getBuilder ( ) ) ; int bos = ( int ) molecule . getBondOrderSum ( atom ) ; IAtomType [ ] atomTypes = structgenATF . getAtomTypes ( atom . getSymbol ( ) ) ; if ( atomTypes . length == 0 ) { checkBondSum . setDetails ( "Cannot validate bond order sum for atom not in valency atom type list: " + atom . getSymbol ( ) ) ; report . addWarning ( checkBondSum ) ; } else { IAtomType failedOn = null ; boolean foundMatchingAtomType = false ; for ( int j = 0 ; j < atomTypes . length ; j ++ ) { IAtomType type = atomTypes [ j ] ; if ( Objects . equals ( atom . getFormalCharge ( ) , type . getFormalCharge ( ) ) ) { foundMatchingAtomType = true ; if ( bos == type . getBondOrderSum ( ) ) { } else { failedOn = atomTypes [ j ] ; } } } if ( foundMatchingAtomType ) { report . addOK ( checkBondSum ) ; } else { if ( failedOn != null ) { checkBondSum . setDetails ( "Bond order exceeds the one allowed for atom " + atom . getSymbol ( ) + " for which the total bond order is " + failedOn . getBondOrderSum ( ) ) ; } report . addError ( checkBondSum ) ; } } } catch ( Exception exception ) { logger . error ( "Error while performing atom bos validation: " , exception . getMessage ( ) ) ; logger . debug ( exception ) ; } return report ; }
the Molecule tests
28,613
public static IAtomContainerSet detect ( IAtomContainer ac ) { IAtomContainerSet piSystemSet = ac . getBuilder ( ) . newInstance ( IAtomContainerSet . class ) ; for ( int i = 0 ; i < ac . getAtomCount ( ) ; i ++ ) { IAtom atom = ac . getAtom ( i ) ; atom . setFlag ( CDKConstants . VISITED , false ) ; } for ( int i = 0 ; i < ac . getAtomCount ( ) ; i ++ ) { IAtom firstAtom = ac . getAtom ( i ) ; if ( firstAtom . getFlag ( CDKConstants . VISITED ) || checkAtom ( ac , firstAtom ) == - 1 ) { continue ; } IAtomContainer piSystem = ac . getBuilder ( ) . newInstance ( IAtomContainer . class ) ; Stack < IAtom > stack = new Stack < IAtom > ( ) ; piSystem . addAtom ( firstAtom ) ; stack . push ( firstAtom ) ; firstAtom . setFlag ( CDKConstants . VISITED , true ) ; while ( ! stack . empty ( ) ) { IAtom currentAtom = stack . pop ( ) ; List < IAtom > atoms = ac . getConnectedAtomsList ( currentAtom ) ; List < IBond > bonds = ac . getConnectedBondsList ( currentAtom ) ; for ( int j = 0 ; j < atoms . size ( ) ; j ++ ) { IAtom atom = atoms . get ( j ) ; IBond bond = bonds . get ( j ) ; if ( ! atom . getFlag ( CDKConstants . VISITED ) ) { int check = checkAtom ( ac , atom ) ; if ( check == 1 ) { piSystem . addAtom ( atom ) ; piSystem . addBond ( bond ) ; continue ; } else if ( check == 0 ) { piSystem . addAtom ( atom ) ; piSystem . addBond ( bond ) ; stack . push ( atom ) ; } atom . setFlag ( CDKConstants . VISITED , true ) ; } else if ( ! piSystem . contains ( bond ) && piSystem . contains ( atom ) ) { piSystem . addBond ( bond ) ; } } } if ( piSystem . getAtomCount ( ) > 2 ) { piSystemSet . addAtomContainer ( piSystem ) ; } } return piSystemSet ; }
Detect all conjugated pi systems in an AtomContainer . This method returns a AtomContainerSet with Atom and Bond objects from the original AtomContainer . The aromaticity has to be known before calling this method .
28,614
private static int checkAtom ( IAtomContainer ac , IAtom currentAtom ) { int check = - 1 ; List < IAtom > atoms = ac . getConnectedAtomsList ( currentAtom ) ; List < IBond > bonds = ac . getConnectedBondsList ( currentAtom ) ; if ( currentAtom . getFlag ( CDKConstants . ISAROMATIC ) ) { check = 0 ; } else if ( currentAtom . getFormalCharge ( ) == 1 ) { check = 0 ; } else if ( currentAtom . getFormalCharge ( ) == - 1 ) { int counterOfPi = 0 ; for ( IAtom atom : atoms ) { if ( ac . getMaximumBondOrder ( atom ) != IBond . Order . SINGLE ) { counterOfPi ++ ; } } if ( counterOfPi > 0 ) check = 0 ; } else { int se = ac . getConnectedSingleElectronsCount ( currentAtom ) ; if ( se == 1 ) { check = 0 ; } else if ( ac . getConnectedLonePairsCount ( currentAtom ) > 0 ) { check = 0 ; } else { int highOrderBondCount = 0 ; for ( int j = 0 ; j < atoms . size ( ) ; j ++ ) { IBond bond = bonds . get ( j ) ; if ( bond == null || bond . getOrder ( ) != IBond . Order . SINGLE ) { highOrderBondCount ++ ; } else { } } if ( highOrderBondCount == 1 ) { check = 0 ; } else if ( highOrderBondCount > 1 ) { check = 1 ; } } } return check ; }
Check an Atom whether it may be conjugated or not .
28,615
public boolean hasNext ( ) { if ( ! nextAvailableIsKnown ) { hasNext = false ; try { final String line = input . readLine ( ) ; if ( line == null ) { nextAvailableIsKnown = true ; return false ; } hasNext = true ; final String suffix = suffix ( line ) ; nextMolecule = readSmiles ( line ) ; nextMolecule . setTitle ( suffix ) ; } catch ( Exception exception ) { logger . error ( "Unexpected problem: " , exception . getMessage ( ) ) ; logger . debug ( exception ) ; hasNext = false ; } if ( ! hasNext ) nextMolecule = null ; nextAvailableIsKnown = true ; } return hasNext ; }
Checks whether there is another molecule to read .
28,616
private String suffix ( final String line ) { for ( int i = 0 ; i < line . length ( ) ; i ++ ) { char c = line . charAt ( i ) ; if ( c == ' ' || c == '\t' ) return line . substring ( i + 1 ) ; } return "" ; }
Obtain the suffix after a line containing SMILES . The suffix follows any or \ t termination characters .
28,617
private IAtomContainer readSmiles ( final String line ) { try { return sp . parseSmiles ( line ) ; } catch ( CDKException e ) { logger . error ( "Error while reading the SMILES from: " + line + ", " , e ) ; final IAtomContainer empty = builder . newInstance ( IAtomContainer . class , 0 , 0 , 0 , 0 ) ; empty . setProperty ( BAD_SMILES_INPUT , line ) ; return empty ; } }
Read the SMILES given in the input line - or return an empty container .
28,618
private void traverseRing ( int [ ] ringSystem , int v , int rnum ) { ringSystem [ v ] = rnum ; for ( int w : adjList [ v ] ) { if ( ringSystem [ w ] == 0 && bondMap . get ( v , w ) . isInRing ( ) ) traverseRing ( ringSystem , w , rnum ) ; } }
Simple method for marking ring systems with a flood - fill .
28,619
private boolean isCrossed ( Point2d beg1 , Point2d end1 , Point2d beg2 , Point2d end2 ) { return Line2D . linesIntersect ( beg1 . x , beg1 . y , end1 . x , end1 . y , beg2 . x , beg2 . y , end2 . x , end2 . y ) ; }
Check if two bonds are crossing .
28,620
void invert ( Collection < AtomPair > pairs ) { for ( AtomPair pair : pairs ) { if ( congestion . contribution ( pair . fst , pair . snd ) < MIN_SCORE ) continue ; if ( fusionPointInversion ( pair ) ) continue ; if ( macroCycleInversion ( pair ) ) continue ; } }
Special case congestion minimisation rotate terminals bonds around ring systems so they are inside the ring .
28,621
private boolean macroCycleInversion ( AtomPair pair ) { for ( int v : pair . seqAt ) { IAtom atom = mol . getAtom ( v ) ; if ( ! atom . isInRing ( ) || adjList [ v ] . length == 2 ) continue ; if ( atom . getProperty ( MacroCycleLayout . MACROCYCLE_ATOM_HINT ) == null ) continue ; final List < IBond > acyclic = new ArrayList < > ( 2 ) ; final List < IBond > cyclic = new ArrayList < > ( 2 ) ; for ( int w : adjList [ v ] ) { IBond bond = bondMap . get ( v , w ) ; if ( bond . isInRing ( ) ) cyclic . add ( bond ) ; else acyclic . add ( bond ) ; } if ( cyclic . size ( ) > 2 ) continue ; for ( IBond bond : acyclic ) { if ( bfix . contains ( bond ) ) continue ; Arrays . fill ( visited , false ) ; stackBackup . len = visit ( visited , stackBackup . xs , v , idxs . get ( bond . getOther ( atom ) ) , 0 ) ; Point2d a = atom . getPoint2d ( ) ; Point2d b = bond . getOther ( atom ) . getPoint2d ( ) ; Vector2d perp = new Vector2d ( b . x - a . x , b . y - a . y ) ; perp . normalize ( ) ; double score = congestion . score ( ) ; backupCoords ( backup , stackBackup ) ; reflect ( stackBackup , new Point2d ( a . x - perp . y , a . y + perp . x ) , new Point2d ( a . x + perp . y , a . y - perp . x ) ) ; congestion . update ( visited , stackBackup . xs , stackBackup . len ) ; if ( percDiff ( score , congestion . score ( ) ) >= IMPROVEMENT_PERC_THRESHOLD ) { return true ; } restoreCoords ( stackBackup , backup ) ; } } return false ; }
of the ring
28,622
private double stretch ( AtomPair pair , IntStack stack , Point2d [ ] coords , Map < IBond , AtomPair > firstVisit ) { stackBackup . clear ( ) ; final double score = congestion . score ( ) ; double min = score ; for ( IBond bond : pair . bndAt ) { if ( bond . isInRing ( ) ) continue ; if ( bfix . contains ( bond ) ) continue ; AtomPair first = firstVisit . get ( bond ) ; if ( first == null ) firstVisit . put ( bond , first = pair ) ; if ( first != pair ) continue ; final IAtom beg = bond . getBegin ( ) ; final IAtom end = bond . getEnd ( ) ; final int begIdx = idxs . get ( beg ) ; final int endIdx = idxs . get ( end ) ; int begPriority = beg . getProperty ( AtomPlacer . PRIORITY ) ; int endPriority = end . getProperty ( AtomPlacer . PRIORITY ) ; Arrays . fill ( visited , false ) ; if ( begPriority < endPriority ) stack . len = visit ( visited , stack . xs , endIdx , begIdx , 0 ) ; else stack . len = visit ( visited , stack . xs , begIdx , endIdx , 0 ) ; backupCoords ( backup , stack ) ; if ( begPriority < endPriority ) stretch ( stack , end , beg , pair . attempt * STRETCH_STEP ) ; else stretch ( stack , beg , end , pair . attempt * STRETCH_STEP ) ; congestion . update ( visited , stack . xs , stack . len ) ; if ( percDiff ( score , congestion . score ( ) ) >= IMPROVEMENT_PERC_THRESHOLD && congestion . score ( ) < min ) { backupCoords ( coords , stack ) ; min = congestion . score ( ) ; stackBackup . copyFrom ( stack ) ; } restoreCoords ( stack , backup ) ; congestion . update ( visited , stack . xs , stack . len ) ; congestion . score = score ; } stack . copyFrom ( stackBackup ) ; return min ; }
Stretch all bonds in the shortest path between a pair of atoms in an attempt to resolve the overlap . The stretch that produces the minimum congestion is stored in the provided stack and coords with the congestion score returned .
28,623
private void bendOrStretch ( Collection < AtomPair > pairs ) { Map < IBond , AtomPair > bendVisit = new HashMap < > ( ) ; Map < IBond , AtomPair > stretchVisit = new HashMap < > ( ) ; IntStack bendStack = new IntStack ( atoms . length ) ; IntStack stretchStack = new IntStack ( atoms . length ) ; for ( AtomPair pair : pairs ) { double score = congestion . score ( ) ; for ( pair . attempt = 1 ; pair . attempt <= 3 ; pair . attempt ++ ) { bendStack . clear ( ) ; stretchStack . clear ( ) ; double bendScore = bend ( pair , bendStack , buffer1 , bendVisit ) ; double stretchScore = stretch ( pair , stretchStack , buffer2 , stretchVisit ) ; if ( bendScore < stretchScore && bendScore < score ) { restoreCoords ( bendStack , buffer1 ) ; congestion . update ( bendStack . xs , bendStack . len ) ; break ; } else if ( bendScore > stretchScore && stretchScore < score ) { restoreCoords ( stretchStack , buffer2 ) ; congestion . update ( stretchStack . xs , stretchStack . len ) ; break ; } } } }
Resolves conflicts either by bending bonds or stretching bonds in the shortest path between an overlapping pair . Bending and stretch are tried for each pair and the best resolution is used .
28,624
public void refine ( ) { for ( int i = 1 ; i <= MAX_ITERATIONS ; i ++ ) { final List < AtomPair > pairs = findCongestedPairs ( ) ; if ( pairs . isEmpty ( ) ) break ; final double min = congestion . score ( ) ; rotate ( pairs ) ; if ( congestion . score ( ) < min ) continue ; invert ( pairs ) ; if ( congestion . score ( ) < min ) continue ; bendOrStretch ( pairs ) ; if ( congestion . score ( ) < min ) continue ; break ; } }
Refine the 2D coordinates of a layout to reduce overlap and congestion .
28,625
private void stretch ( IntStack stack , IAtom beg , IAtom end , double amount ) { Point2d begPoint = beg . getPoint2d ( ) ; Point2d endPoint = end . getPoint2d ( ) ; if ( begPoint . distance ( endPoint ) + amount > MAX_BOND_LENGTH ) return ; Vector2d vector = new Vector2d ( endPoint . x - begPoint . x , endPoint . y - begPoint . y ) ; vector . normalize ( ) ; vector . scale ( amount ) ; for ( int i = 0 ; i < stack . len ; i ++ ) atoms [ stack . xs [ i ] ] . getPoint2d ( ) . add ( vector ) ; }
Stretch the distance between beg and end moving all atoms provided in the stack .
28,626
private static IAtom getCommon ( IBond bndA , IBond bndB ) { IAtom beg = bndA . getBegin ( ) ; IAtom end = bndA . getEnd ( ) ; if ( bndB . contains ( beg ) ) return beg ; else if ( bndB . contains ( end ) ) return end ; else return null ; }
Access the common atom shared by two bonds .
28,627
String getFormulasString ( ) { StringBuilder sb = new StringBuilder ( ) ; for ( IMolecularFormula mf : getFormulas ( ) ) { if ( sb . length ( ) != 0 ) sb . append ( ", " ) ; sb . append ( MolecularFormulaManipulator . getString ( mf , false , true ) ) ; } return sb . toString ( ) ; }
Pretty - print the MFs of this isotope container .
28,628
public DescriptorValue calculate ( IAtomContainer container ) { int c1sp1 = 0 ; int c2sp1 = 0 ; int c1sp2 = 0 ; int c2sp2 = 0 ; int c3sp2 = 0 ; int c1sp3 = 0 ; int c2sp3 = 0 ; int c3sp3 = 0 ; int c4sp3 = 0 ; for ( IAtom atom : container . atoms ( ) ) { if ( ! atom . getSymbol ( ) . equals ( "C" ) && ! atom . getSymbol ( ) . equals ( "c" ) ) continue ; List < IAtom > connectedAtoms = container . getConnectedAtomsList ( atom ) ; int cc = 0 ; for ( IAtom connectedAtom : connectedAtoms ) { if ( connectedAtom . getSymbol ( ) . equals ( "C" ) || connectedAtom . getSymbol ( ) . equals ( "c" ) ) cc ++ ; } IBond . Order maxBondOrder = getHighestBondOrder ( container , atom ) ; if ( maxBondOrder == IBond . Order . TRIPLE && cc == 1 ) c1sp1 ++ ; else if ( maxBondOrder == IBond . Order . TRIPLE && cc == 2 ) c2sp1 ++ ; else if ( maxBondOrder == IBond . Order . DOUBLE && cc == 1 ) c1sp2 ++ ; else if ( maxBondOrder == IBond . Order . DOUBLE && cc == 2 ) c2sp2 ++ ; else if ( maxBondOrder == IBond . Order . DOUBLE && cc == 3 ) c3sp2 ++ ; else if ( maxBondOrder == IBond . Order . SINGLE && cc == 1 ) c1sp3 ++ ; else if ( maxBondOrder == IBond . Order . SINGLE && cc == 2 ) c2sp3 ++ ; else if ( maxBondOrder == IBond . Order . SINGLE && cc == 3 ) c3sp3 ++ ; else if ( maxBondOrder == IBond . Order . SINGLE && cc == 4 ) c4sp3 ++ ; } IntegerArrayResult retval = new IntegerArrayResult ( 9 ) ; retval . add ( c1sp1 ) ; retval . add ( c2sp1 ) ; retval . add ( c1sp2 ) ; retval . add ( c2sp2 ) ; retval . add ( c3sp2 ) ; retval . add ( c1sp3 ) ; retval . add ( c2sp3 ) ; retval . add ( c3sp3 ) ; retval . add ( c4sp3 ) ; return new DescriptorValue ( getSpecification ( ) , getParameterNames ( ) , getParameters ( ) , retval , getDescriptorNames ( ) ) ; }
Calculates the 9 carbon types descriptors
28,629
private IAtomContainer removingFlagsAromaticity ( IAtomContainer ac ) { Iterator < IAtom > atoms = ac . atoms ( ) . iterator ( ) ; while ( atoms . hasNext ( ) ) atoms . next ( ) . setFlag ( CDKConstants . ISAROMATIC , false ) ; Iterator < IBond > bonds = ac . bonds ( ) . iterator ( ) ; while ( bonds . hasNext ( ) ) bonds . next ( ) . setFlag ( CDKConstants . ISAROMATIC , false ) ; return ac ; }
remove the aromaticity flags .
28,630
private IAtomContainer setFlags ( IAtomContainer container , IAtomContainer ac , boolean b ) { for ( Iterator < IAtom > it = container . atoms ( ) . iterator ( ) ; it . hasNext ( ) ; ) { int positionA = ac . indexOf ( it . next ( ) ) ; ac . getAtom ( positionA ) . setFlag ( CDKConstants . REACTIVE_CENTER , b ) ; } for ( Iterator < IBond > it = container . bonds ( ) . iterator ( ) ; it . hasNext ( ) ; ) { int positionB = ac . indexOf ( it . next ( ) ) ; ac . getBond ( positionB ) . setFlag ( CDKConstants . REACTIVE_CENTER , b ) ; } return ac ; }
Set the Flags to atoms and bonds from an atomContainer .
28,631
private IAtomContainer setAntiFlags ( IAtomContainer container , IAtomContainer ac , int number , boolean b ) { IBond bond = ac . getBond ( number ) ; if ( ! container . contains ( bond ) ) { bond . setFlag ( CDKConstants . REACTIVE_CENTER , b ) ; bond . getBegin ( ) . setFlag ( CDKConstants . REACTIVE_CENTER , b ) ; bond . getEnd ( ) . setFlag ( CDKConstants . REACTIVE_CENTER , b ) ; } else return null ; return ac ; }
Set the Flags to atoms and bonds which are not contained in an atomContainer .
28,632
private double getElectrostaticPotentialN ( IAtomContainer ac , int atom1 , double [ ] ds ) { double CoulombForceConstant = 0.048 ; double sum = 0.0 ; try { if ( factory == null ) factory = AtomTypeFactory . getInstance ( "org/openscience/cdk/config/data/jmol_atomtypes.txt" , ac . getBuilder ( ) ) ; List < IAtom > atoms = ac . getConnectedAtomsList ( ac . getAtom ( atom1 ) ) ; for ( IAtom atom : atoms ) { double covalentradius = 0 ; String symbol = atom . getSymbol ( ) ; IAtomType type = factory . getAtomType ( symbol ) ; covalentradius = type . getCovalentRadius ( ) ; double charge = ds [ STEP_SIZE * atom1 + atom1 + 5 ] ; logger . debug ( "sum_(" + sum + ") = CFC(" + CoulombForceConstant + ")*charge(" + charge + "/ret(" + covalentradius ) ; sum += CoulombForceConstant * charge / ( covalentradius * covalentradius ) ; } } catch ( CDKException e ) { logger . debug ( e ) ; } return sum ; }
get the electrostatic potential of the neighbours of a atom .
28,633
private double getTopologicalFactors ( IAtomContainer atomContainer , IAtomContainer ac ) { int totalNCharge1 = AtomContainerManipulator . getTotalNegativeFormalCharge ( atomContainer ) ; int totalPCharge1 = AtomContainerManipulator . getTotalPositiveFormalCharge ( atomContainer ) ; double fQ = 1.0 ; if ( totalNCharge1 != 0.0 ) { fQ = 0.5 ; for ( int i = 0 ; i < atomContainer . getBondCount ( ) ; i ++ ) { IBond bond = atomContainer . getBond ( i ) ; if ( bond . getBegin ( ) . getFormalCharge ( ) != 0.0 && bond . getEnd ( ) . getFormalCharge ( ) != 0.0 ) { fQ = 0.25 ; break ; } } } double fB = 1.0 ; int numBond1 = 0 ; int numBond2 = 0 ; for ( int i = 0 ; i < atomContainer . getBondCount ( ) ; i ++ ) { if ( atomContainer . getBond ( i ) . getOrder ( ) == IBond . Order . DOUBLE ) numBond1 += 1 ; if ( ac . getBond ( i ) . getOrder ( ) == IBond . Order . DOUBLE ) numBond2 += 1 ; } if ( numBond1 < numBond2 ) fB = 0.8 ; double fPlus = 1.0 ; if ( totalNCharge1 == 0.0 && totalPCharge1 == 0.0 ) fPlus = 0.1 ; double fA = 1.0 ; try { if ( Aromaticity . cdkLegacy ( ) . apply ( ac ) ) if ( ! Aromaticity . cdkLegacy ( ) . apply ( atomContainer ) ) fA = 0.3 ; } catch ( CDKException e ) { e . printStackTrace ( ) ; } logger . debug ( "return " + fQ * fB * fPlus * fA + "= sp:" + fQ + ", dc:" + fB + ", fPlus:" + fPlus + ", fA:" + fA ) ; return fQ * fB * fPlus * fA ; }
get the topological weight factor for each atomContainer .
28,634
private void cleanFlagReactiveCenter ( IAtomContainer ac ) { for ( int j = 0 ; j < ac . getAtomCount ( ) ; j ++ ) ac . getAtom ( j ) . setFlag ( CDKConstants . REACTIVE_CENTER , false ) ; for ( int j = 0 ; j < ac . getBondCount ( ) ; j ++ ) ac . getBond ( j ) . setFlag ( CDKConstants . REACTIVE_CENTER , false ) ; }
clean the flags CDKConstants . REACTIVE_CENTER from the molecule .
28,635
public boolean checkForceFieldType ( String ffname ) { boolean check = false ; for ( int i = 0 ; i < fftypes . length ; i ++ ) { if ( fftypes [ i ] . equals ( ffname ) ) { check = true ; break ; } } if ( ! check ) { return false ; } return true ; }
Sets the forceFieldType attribute of the ForceFieldConfigurator object
28,636
public void setForceFieldConfigurator ( String ffname , IChemObjectBuilder builder ) throws CDKException { ffname = ffname . toLowerCase ( ) ; boolean check = false ; if ( ffname == ffName && parameterSet != null ) { } else { check = this . checkForceFieldType ( ffname ) ; ffName = ffname ; if ( ffName . equals ( "mm2" ) ) { ins = this . getClass ( ) . getClassLoader ( ) . getResourceAsStream ( "org/openscience/cdk/modeling/forcefield/data/mm2.prm" ) ; mm2 = new MM2BasedParameterSetReader ( ) ; mm2 . setInputStream ( ins ) ; try { this . setMM2Parameters ( builder ) ; } catch ( Exception ex1 ) { throw new CDKException ( "Problems with set MM2Parameters due to " + ex1 . toString ( ) , ex1 ) ; } } else if ( ffName . equals ( "mmff94" ) || ! check ) { ins = this . getClass ( ) . getClassLoader ( ) . getResourceAsStream ( "org/openscience/cdk/modeling/forcefield/data/mmff94.prm" ) ; mmff94 = new MMFF94BasedParameterSetReader ( ) ; mmff94 . setInputStream ( ins ) ; try { this . setMMFF94Parameters ( builder ) ; } catch ( Exception ex2 ) { throw new CDKException ( "Problems with set MM2Parameters due to" + ex2 . toString ( ) , ex2 ) ; } } } }
Constructor for the ForceFieldConfigurator object
28,637
public void setMM2Parameters ( IChemObjectBuilder builder ) throws CDKException { try { if ( mm2 == null ) mm2 = new MM2BasedParameterSetReader ( ) ; mm2 . readParameterSets ( builder ) ; } catch ( Exception ex1 ) { throw new CDKException ( "Problem within readParameterSets due to:" + ex1 . toString ( ) , ex1 ) ; } parameterSet = mm2 . getParamterSet ( ) ; atomTypes = mm2 . getAtomTypes ( ) ; }
Sets the parameters attribute of the ForceFieldConfigurator object default is mm2 force field
28,638
private IAtomType getAtomType ( String ID ) throws NoSuchAtomTypeException { IAtomType at = null ; for ( int i = 0 ; i < atomTypes . size ( ) ; i ++ ) { at = ( IAtomType ) atomTypes . get ( i ) ; if ( at . getAtomTypeName ( ) . equals ( ID ) ) { return at ; } } throw new NoSuchAtomTypeException ( "AtomType " + ID + " could not be found" ) ; }
Find the atomType for a id
28,639
private boolean isHeteroRingSystem ( IAtomContainer ac ) { if ( ac != null ) { for ( int i = 0 ; i < ac . getAtomCount ( ) ; i ++ ) { if ( ! ( ac . getAtom ( i ) . getSymbol ( ) ) . equals ( "H" ) && ! ( ac . getAtom ( i ) . getSymbol ( ) ) . equals ( "C" ) ) { return true ; } } } return false ; }
Returns true if atom is in hetero ring system
28,640
private IAtom setAtom ( IAtom atom , String ID ) throws NoSuchAtomTypeException { IAtomType at = null ; String key = "" ; List < ? > data = null ; Double value = null ; at = getAtomType ( ID ) ; if ( atom . getSymbol ( ) == null ) { atom . setSymbol ( at . getSymbol ( ) ) ; } atom . setAtomTypeName ( at . getAtomTypeName ( ) ) ; atom . setFormalNeighbourCount ( at . getFormalNeighbourCount ( ) ) ; key = "vdw" + ID ; data = ( List ) parameterSet . get ( key ) ; value = ( Double ) data . get ( 0 ) ; key = "charge" + ID ; if ( parameterSet . containsKey ( key ) ) { data = ( List ) parameterSet . get ( key ) ; value = ( Double ) data . get ( 0 ) ; atom . setCharge ( value . doubleValue ( ) ) ; } Object color = at . getProperty ( "org.openscience.cdk.renderer.color" ) ; if ( color != null ) { atom . setProperty ( "org.openscience.cdk.renderer.color" , color ) ; } if ( at . getAtomicNumber ( ) != 0 ) { atom . setAtomicNumber ( at . getAtomicNumber ( ) ) ; } if ( at . getExactMass ( ) > 0.0 ) { atom . setExactMass ( at . getExactMass ( ) ) ; } return atom ; }
Assigns an atom type to an atom
28,641
public DescriptorValue calculate ( IAtomContainer atomContainer ) { double zagreb = 0 ; for ( IAtom atom : atomContainer . atoms ( ) ) { if ( atom . getSymbol ( ) . equals ( "H" ) ) continue ; int atomDegree = 0 ; List < IAtom > neighbours = atomContainer . getConnectedAtomsList ( atom ) ; for ( IAtom neighbour : neighbours ) { if ( ! neighbour . getSymbol ( ) . equals ( "H" ) ) { atomDegree += 1 ; } } zagreb += ( atomDegree * atomDegree ) ; } return new DescriptorValue ( getSpecification ( ) , getParameterNames ( ) , getParameters ( ) , new DoubleResult ( zagreb ) , getDescriptorNames ( ) ) ; }
Evaluate the Zagreb Index for a molecule .
28,642
public static long [ ] getNumbers ( IAtomContainer atomContainer ) throws CDKException { String aux = auxInfo ( atomContainer ) ; long [ ] numbers = new long [ atomContainer . getAtomCount ( ) ] ; parseAuxInfo ( aux , numbers ) ; return numbers ; }
Makes an array containing the InChI atom numbers of the non - hydrogen atoms in the atomContainer . It returns zero for all hydrogens .
28,643
public static void parseAuxInfo ( String aux , long [ ] numbers ) { aux = aux . substring ( aux . indexOf ( "/N:" ) + 3 ) ; String numberStringAux = aux . substring ( 0 , aux . indexOf ( '/' ) ) ; int i = 1 ; for ( String numberString : numberStringAux . split ( "[,;]" ) ) numbers [ Integer . valueOf ( numberString ) - 1 ] = i ++ ; }
Parse the atom numbering from the auxinfo .
28,644
private static void exch ( long [ ] values , int i , int j ) { long k = values [ i ] ; values [ i ] = values [ j ] ; values [ j ] = k ; }
Exchange the elements at index i with that at index j .
28,645
static String auxInfo ( IAtomContainer container , INCHI_OPTION ... options ) throws CDKException { InChIGeneratorFactory factory = InChIGeneratorFactory . getInstance ( ) ; boolean org = factory . getIgnoreAromaticBonds ( ) ; factory . setIgnoreAromaticBonds ( true ) ; InChIGenerator gen = factory . getInChIGenerator ( container , Arrays . asList ( options ) ) ; factory . setIgnoreAromaticBonds ( org ) ; if ( gen . getReturnStatus ( ) != INCHI_RET . OKAY && gen . getReturnStatus ( ) != INCHI_RET . WARNING ) throw new CDKException ( "Could not generate InChI Numbers: " + gen . getMessage ( ) ) ; return gen . getAuxInfo ( ) ; }
Obtain the InChI auxiliary info for the provided structure using using the specified InChI options .
28,646
private void checkLineBeginsWith ( String line , String expect , int lineCount ) throws CDKException { if ( line == null ) { throw new CDKException ( "RGFile invalid, empty/null line at #" + lineCount ) ; } if ( ! line . startsWith ( expect ) ) { throw new CDKException ( "RGFile invalid, line #" + lineCount + " should start with:" + expect + "." ) ; } }
Checks that a given line starts as expected according to RGFile format .
28,647
private boolean isBondTypeMatch ( IBond targetBond ) { int reactantBondType = queryBond . getOrder ( ) . numeric ( ) ; int productBondType = targetBond . getOrder ( ) . numeric ( ) ; if ( ( queryBond . getFlag ( CDKConstants . ISAROMATIC ) == targetBond . getFlag ( CDKConstants . ISAROMATIC ) ) && ( reactantBondType == productBondType ) ) { return true ; } else if ( queryBond . getFlag ( CDKConstants . ISAROMATIC ) && targetBond . getFlag ( CDKConstants . ISAROMATIC ) ) { return true ; } return false ; }
Return true if a bond is matched between query and target
28,648
static IAtomContainer apply ( IAtomContainer container ) { int n = container . getAtomCount ( ) ; int [ ] valences = new int [ n ] ; Map < IAtom , Integer > atomToIndex = Maps . newHashMapWithExpectedSize ( n ) ; for ( IAtom atom : container . atoms ( ) ) atomToIndex . put ( atom , atomToIndex . size ( ) ) ; for ( IBond bond : container . bonds ( ) ) { int u = atomToIndex . get ( bond . getBegin ( ) ) ; int v = atomToIndex . get ( bond . getEnd ( ) ) ; int bondOrder = bond . getOrder ( ) . numeric ( ) ; valences [ u ] += bondOrder ; valences [ v ] += bondOrder ; } for ( int i = 0 ; i < n ; i ++ ) { IAtom atom = container . getAtom ( i ) ; Integer charge = atom . getFormalCharge ( ) ; Integer element = atom . getAtomicNumber ( ) ; if ( element == null ) continue ; charge = charge == null ? 0 : charge ; int explicit = valences [ i ] ; if ( atom . getValency ( ) != null ) { atom . setImplicitHydrogenCount ( atom . getValency ( ) - explicit ) ; } else { int implicit = implicitValence ( element , charge , valences [ i ] ) ; atom . setImplicitHydrogenCount ( implicit - explicit ) ; atom . setValency ( implicit ) ; } } return container ; }
Apply the MDL valence model to the provided atom container .
28,649
private boolean checkmArcs ( List < Integer > mArcsT , int neighborBondNumA , int neighborBondNumB ) { int size = neighborBondNumA * neighborBondNumA ; List < Integer > posNumList = new ArrayList < Integer > ( size ) ; for ( int i = 0 ; i < posNumList . size ( ) ; i ++ ) { posNumList . add ( i , 0 ) ; } int yCounter = 0 ; int countEntries = 0 ; for ( int x = 0 ; x < ( neighborBondNumA * neighborBondNumB ) ; x ++ ) { if ( mArcsT . get ( x ) == 1 ) { posNumList . add ( yCounter ++ , x ) ; countEntries ++ ; } } boolean flag = false ; verifyNodes ( posNumList , first , 0 , countEntries ) ; if ( isNewMatrix ( ) ) { flag = true ; } return flag ; }
matrix will be stored in function partsearch .
28,650
public DescriptorValue calculate ( IBond aBond , IAtomContainer atomContainer ) { IAtomContainer ac ; IBond bond ; try { ac = ( IAtomContainer ) atomContainer . clone ( ) ; bond = ac . getBond ( atomContainer . indexOf ( aBond ) ) ; AtomContainerManipulator . percieveAtomTypesAndConfigureAtoms ( ac ) ; } catch ( CDKException e ) { return getDummyDescriptorValue ( e ) ; } catch ( CloneNotSupportedException e ) { return getDummyDescriptorValue ( e ) ; } if ( maxIterations != - 1 && maxIterations != 0 ) electronegativity . setMaxIterations ( maxIterations ) ; double electroAtom1 = electronegativity . calculateSigmaElectronegativity ( ac , bond . getBegin ( ) ) ; double electroAtom2 = electronegativity . calculateSigmaElectronegativity ( ac , bond . getEnd ( ) ) ; return new DescriptorValue ( getSpecification ( ) , getParameterNames ( ) , getParameters ( ) , new DoubleResult ( Math . abs ( electroAtom1 - electroAtom2 ) ) , NAMES ) ; }
The method calculates the sigma electronegativity of a given bond It is needed to call the addExplicitHydrogensToSatisfyValency method from the class tools . HydrogenAdder .
28,651
private List < InvPair > createInvarLabel ( IAtomContainer atomContainer ) { Iterator < IAtom > atoms = atomContainer . atoms ( ) . iterator ( ) ; IAtom a ; StringBuffer inv ; List < InvPair > vect = new ArrayList < InvPair > ( ) ; while ( atoms . hasNext ( ) ) { a = ( IAtom ) atoms . next ( ) ; inv = new StringBuffer ( ) ; inv . append ( atomContainer . getConnectedAtomsList ( a ) . size ( ) + ( a . getImplicitHydrogenCount ( ) == CDKConstants . UNSET ? 0 : a . getImplicitHydrogenCount ( ) ) ) ; inv . append ( atomContainer . getConnectedAtomsList ( a ) . size ( ) ) ; inv . append ( PeriodicTable . getAtomicNumber ( a . getSymbol ( ) ) ) ; Double charge = a . getCharge ( ) ; if ( charge == CDKConstants . UNSET ) charge = 0.0 ; if ( charge < 0 ) inv . append ( 1 ) ; else inv . append ( 0 ) ; inv . append ( ( int ) Math . abs ( ( a . getFormalCharge ( ) == CDKConstants . UNSET ? 0.0 : a . getFormalCharge ( ) ) ) ) ; inv . append ( ( a . getImplicitHydrogenCount ( ) == CDKConstants . UNSET ? 0 : a . getImplicitHydrogenCount ( ) ) ) ; vect . add ( new InvPair ( Long . parseLong ( inv . toString ( ) ) , a ) ) ; } return vect ; }
Create initial invariant labeling corresponds to step 1
28,652
private void primeProduct ( List < InvPair > v , IAtomContainer atomContainer ) { Iterator < InvPair > it = v . iterator ( ) ; Iterator < IAtom > n ; InvPair inv ; IAtom a ; long summ ; while ( it . hasNext ( ) ) { inv = ( InvPair ) it . next ( ) ; List < IAtom > neighbour = atomContainer . getConnectedAtomsList ( inv . getAtom ( ) ) ; n = neighbour . iterator ( ) ; summ = 1 ; while ( n . hasNext ( ) ) { a = n . next ( ) ; int next = ( ( InvPair ) a . getProperty ( InvPair . INVARIANCE_PAIR ) ) . getPrime ( ) ; summ = summ * next ; } inv . setLast ( inv . getCurr ( ) ) ; inv . setCurr ( summ ) ; } }
Calculates the product of the neighbouring primes .
28,653
private void sortArrayList ( List < InvPair > v ) { Collections . sort ( v , new Comparator < InvPair > ( ) { public int compare ( InvPair o1 , InvPair o2 ) { if ( o1 . getCurr ( ) > o2 . getCurr ( ) ) return + 1 ; if ( o1 . getCurr ( ) < o2 . getCurr ( ) ) return - 1 ; return 0 ; } } ) ; Collections . sort ( v , new Comparator < InvPair > ( ) { public int compare ( InvPair o1 , InvPair o2 ) { if ( o1 . getLast ( ) > o2 . getLast ( ) ) return + 1 ; if ( o1 . getLast ( ) < o2 . getLast ( ) ) return - 1 ; return 0 ; } } ) ; }
Sorts the vector according to the current invariance corresponds to step 3
28,654
private void rankArrayList ( List < InvPair > v ) { int num = 1 ; int [ ] temp = new int [ v . size ( ) ] ; InvPair last = ( InvPair ) v . get ( 0 ) ; Iterator < InvPair > it = v . iterator ( ) ; InvPair curr ; for ( int x = 0 ; it . hasNext ( ) ; x ++ ) { curr = ( InvPair ) it . next ( ) ; if ( ! last . equals ( curr ) ) { num ++ ; } temp [ x ] = num ; last = curr ; } it = v . iterator ( ) ; for ( int x = 0 ; it . hasNext ( ) ; x ++ ) { curr = ( InvPair ) it . next ( ) ; curr . setCurr ( temp [ x ] ) ; curr . setPrime ( ) ; } }
Rank atomic vector corresponds to step 4 .
28,655
private boolean isInvPart ( List < InvPair > v ) { if ( ( ( InvPair ) v . get ( v . size ( ) - 1 ) ) . getCurr ( ) == v . size ( ) ) return true ; Iterator < InvPair > it = v . iterator ( ) ; InvPair curr ; while ( it . hasNext ( ) ) { curr = ( InvPair ) it . next ( ) ; if ( curr . getCurr ( ) != curr . getLast ( ) ) return false ; } return true ; }
Checks to see if the vector is invariantly partitioned
28,656
private void breakTies ( List < InvPair > v ) { Iterator < InvPair > it = v . iterator ( ) ; InvPair curr ; InvPair last = null ; int tie = 0 ; boolean found = false ; for ( int x = 0 ; it . hasNext ( ) ; x ++ ) { curr = it . next ( ) ; curr . setCurr ( curr . getCurr ( ) * 2 ) ; curr . setPrime ( ) ; if ( x != 0 && ! found && curr . getCurr ( ) == last . getCurr ( ) ) { tie = x - 1 ; found = true ; } last = curr ; } curr = ( InvPair ) v . get ( tie ) ; curr . setCurr ( curr . getCurr ( ) - 1 ) ; curr . setPrime ( ) ; }
Break ties . Corresponds to step 7
28,657
private void readBioPolymer ( String biopolymerFile ) { try { FileReader fileReader = new FileReader ( biopolymerFile ) ; ISimpleChemObjectReader reader = new ReaderFactory ( ) . createReader ( fileReader ) ; IChemFile chemFile = ( IChemFile ) reader . read ( ( IChemObject ) new ChemFile ( ) ) ; IChemSequence chemSequence = chemFile . getChemSequence ( 0 ) ; IChemModel chemModel = chemSequence . getChemModel ( 0 ) ; IAtomContainerSet setOfMolecules = chemModel . getMoleculeSet ( ) ; protein = ( IBioPolymer ) setOfMolecules . getAtomContainer ( 0 ) ; } catch ( IOException | CDKException exc ) { logger . error ( "Could not read BioPolymer from file>" + biopolymerFile + " due to: " + exc . getMessage ( ) ) ; logger . debug ( exc ) ; } }
Creates from a PDB File a BioPolymer .
28,658
public double [ ] findGridBoundaries ( ) { IAtom [ ] atoms = AtomContainerManipulator . getAtomArray ( protein ) ; double [ ] minMax = new double [ 6 ] ; minMax [ 0 ] = atoms [ 0 ] . getPoint3d ( ) . x ; minMax [ 1 ] = atoms [ 0 ] . getPoint3d ( ) . x ; minMax [ 2 ] = atoms [ 0 ] . getPoint3d ( ) . y ; minMax [ 3 ] = atoms [ 0 ] . getPoint3d ( ) . y ; minMax [ 4 ] = atoms [ 0 ] . getPoint3d ( ) . z ; minMax [ 5 ] = atoms [ 0 ] . getPoint3d ( ) . z ; for ( int i = 0 ; i < atoms . length ; i ++ ) { if ( atoms [ i ] . getPoint3d ( ) . x > minMax [ 1 ] ) { minMax [ 1 ] = atoms [ i ] . getPoint3d ( ) . x ; } else if ( atoms [ i ] . getPoint3d ( ) . y > minMax [ 3 ] ) { minMax [ 3 ] = atoms [ i ] . getPoint3d ( ) . y ; } else if ( atoms [ i ] . getPoint3d ( ) . z > minMax [ 5 ] ) { minMax [ 5 ] = atoms [ i ] . getPoint3d ( ) . z ; } else if ( atoms [ i ] . getPoint3d ( ) . x < minMax [ 0 ] ) { minMax [ 0 ] = atoms [ i ] . getPoint3d ( ) . x ; } else if ( atoms [ i ] . getPoint3d ( ) . y < minMax [ 2 ] ) { minMax [ 2 ] = atoms [ i ] . getPoint3d ( ) . y ; } else if ( atoms [ i ] . getPoint3d ( ) . z < minMax [ 4 ] ) { minMax [ 4 ] = atoms [ i ] . getPoint3d ( ) . z ; } } return minMax ; }
Method determines the minimum and maximum values of a coordinate space up to 3D space .
28,659
public void createCubicGrid ( ) { gridGenerator . setDimension ( findGridBoundaries ( ) , true ) ; gridGenerator . generateGrid ( ) ; this . grid = gridGenerator . getGrid ( ) ; }
Method creates a cubic grid with the grid generator class .
28,660
private void sortPockets ( ) { Hashtable < Integer , List < Integer > > hashPockets = new Hashtable < Integer , List < Integer > > ( ) ; List < Point3d > pocket ; List < List < Point3d > > sortPockets = new ArrayList < List < Point3d > > ( pockets . size ( ) ) ; for ( int i = 0 ; i < pockets . size ( ) ; i ++ ) { pocket = pockets . get ( i ) ; if ( hashPockets . containsKey ( Integer . valueOf ( pocket . size ( ) ) ) ) { List < Integer > tmp = hashPockets . get ( Integer . valueOf ( pocket . size ( ) ) ) ; tmp . add ( i ) ; hashPockets . put ( pocket . size ( ) , tmp ) ; } else { List < Integer > value = new ArrayList < Integer > ( ) ; value . add ( i ) ; hashPockets . put ( pocket . size ( ) , value ) ; } } List < Integer > keys = new ArrayList < Integer > ( hashPockets . keySet ( ) ) ; Collections . sort ( keys ) ; for ( int i = keys . size ( ) - 1 ; i >= 0 ; i -- ) { List < Integer > value = hashPockets . get ( keys . get ( i ) ) ; for ( int j = 0 ; j < value . size ( ) ; j ++ ) { sortPockets . add ( pockets . get ( value . get ( j ) ) ) ; } } pockets = sortPockets ; }
Method sorts the pockets due to its size . The biggest pocket is the first .
28,661
private int [ ] checkBoundaries ( int [ ] minMax , int [ ] dim ) { if ( minMax [ 0 ] < 0 ) { minMax [ 0 ] = 0 ; } if ( minMax [ 1 ] > dim [ 0 ] ) { minMax [ 1 ] = dim [ 0 ] ; } if ( minMax [ 2 ] < 0 ) { minMax [ 2 ] = 0 ; } if ( minMax [ 3 ] > dim [ 1 ] ) { minMax [ 3 ] = dim [ 1 ] ; } if ( minMax [ 4 ] < 0 ) { minMax [ 4 ] = 0 ; } if ( minMax [ 5 ] > dim [ 2 ] ) { minMax [ 5 ] = dim [ 2 ] ; } return minMax ; }
Method checks boundaries .
28,662
private void firePSPEvent ( List < Point3d > line ) { for ( int i = 0 ; i < line . size ( ) ; i ++ ) { this . grid [ ( int ) line . get ( i ) . x ] [ ( int ) line . get ( i ) . y ] [ ( int ) line . get ( i ) . z ] = this . grid [ ( int ) line . get ( i ) . x ] [ ( int ) line . get ( i ) . y ] [ ( int ) line . get ( i ) . z ] + 1 ; } }
Method which assigns upon a PSP event + 1 to these grid points .
28,663
public void diagonalAxisScanXZY ( int dimK , int dimL , int dimM ) { if ( dimM < dimL ) { dimL = dimM ; } List < Point3d > line = new ArrayList < Point3d > ( ) ; int pspEvent = 0 ; int m = 0 ; for ( int j = dimM ; j >= 1 ; j -- ) { line . clear ( ) ; pspEvent = 0 ; for ( int k = 0 ; k <= dimK ; k ++ ) { m = dimM ; line . clear ( ) ; pspEvent = 0 ; for ( int l = dimL ; l >= 0 ; l -- ) { if ( grid [ k ] [ m ] [ l ] < 0 ) { if ( pspEvent < 2 ) { line . clear ( ) ; pspEvent = 1 ; } else if ( pspEvent == 2 ) { firePSPEvent ( line ) ; line . clear ( ) ; pspEvent = 1 ; } } else { if ( pspEvent == 1 | pspEvent == 2 ) { line . add ( new Point3d ( k , m , l ) ) ; pspEvent = 2 ; } } m -- ; } } dimL = j ; } }
Method performs a scan ; works only for cubic grids!
28,664
public void gridToPmesh ( String outPutFileName ) { try { gridGenerator . writeGridInPmeshFormat ( outPutFileName ) ; } catch ( IOException e ) { logger . debug ( e ) ; } }
Method writes the grid to pmesh format .
28,665
public void writePocketsToPMesh ( String outPutFileName ) { try { for ( int i = 0 ; i < pockets . size ( ) ; i ++ ) { BufferedWriter writer = new BufferedWriter ( new FileWriter ( outPutFileName + "-" + i + ".pmesh" ) ) ; List < Point3d > pocket = pockets . get ( i ) ; writer . write ( pocket . size ( ) + "\n" ) ; for ( int j = 0 ; j < pocket . size ( ) ; j ++ ) { Point3d actualGridPoint = ( Point3d ) pocket . get ( j ) ; Point3d coords = gridGenerator . getCoordinatesFromGridPoint ( actualGridPoint ) ; writer . write ( coords . x + "\t" + coords . y + "\t" + coords . z + "\n" ) ; } writer . close ( ) ; } } catch ( IOException e ) { logger . debug ( e ) ; } }
Method writes the pockets to pmesh format .
28,666
public static Vector3d [ ] calcInvertedAxes ( Vector3d aAxis , Vector3d bAxis , Vector3d cAxis ) { double det = aAxis . x * bAxis . y * cAxis . z - aAxis . x * bAxis . z * cAxis . y - aAxis . y * bAxis . x * cAxis . z + aAxis . y * bAxis . z * cAxis . x + aAxis . z * bAxis . x * cAxis . y - aAxis . z * bAxis . y * cAxis . x ; Vector3d [ ] invaxes = new Vector3d [ 3 ] ; invaxes [ 0 ] = new Vector3d ( ) ; invaxes [ 0 ] . x = ( bAxis . y * cAxis . z - bAxis . z * cAxis . y ) / det ; invaxes [ 0 ] . y = ( bAxis . z * cAxis . x - bAxis . x * cAxis . z ) / det ; invaxes [ 0 ] . z = ( bAxis . x * cAxis . y - bAxis . y * cAxis . x ) / det ; invaxes [ 1 ] = new Vector3d ( ) ; invaxes [ 1 ] . x = ( aAxis . z * cAxis . y - aAxis . y * cAxis . z ) / det ; invaxes [ 1 ] . y = ( aAxis . x * cAxis . z - aAxis . z * cAxis . x ) / det ; invaxes [ 1 ] . z = ( aAxis . y * cAxis . x - aAxis . x * cAxis . y ) / det ; invaxes [ 2 ] = new Vector3d ( ) ; invaxes [ 2 ] . x = ( aAxis . y * bAxis . z - aAxis . z * bAxis . y ) / det ; invaxes [ 2 ] . y = ( aAxis . z * bAxis . x - aAxis . x * bAxis . z ) / det ; invaxes [ 2 ] . z = ( aAxis . x * bAxis . y - aAxis . y * bAxis . x ) / det ; return invaxes ; }
Inverts three cell axes .
28,667
public static Vector3d [ ] notionalToCartesian ( double alength , double blength , double clength , double alpha , double beta , double gamma ) { Vector3d [ ] axes = new Vector3d [ 3 ] ; axes [ 0 ] = new Vector3d ( ) ; axes [ 0 ] . x = alength ; axes [ 0 ] . y = 0.0 ; axes [ 0 ] . z = 0.0 ; double toRadians = Math . PI / 180.0 ; double cosalpha = Math . cos ( toRadians * alpha ) ; double cosbeta = Math . cos ( toRadians * beta ) ; double cosgamma = Math . cos ( toRadians * gamma ) ; double singamma = Math . sin ( toRadians * gamma ) ; axes [ 1 ] = new Vector3d ( ) ; axes [ 1 ] . x = blength * cosgamma ; axes [ 1 ] . y = blength * singamma ; axes [ 1 ] . z = 0.0 ; axes [ 2 ] = new Vector3d ( ) ; double volume = alength * blength * clength * Math . sqrt ( 1.0 - cosalpha * cosalpha - cosbeta * cosbeta - cosgamma * cosgamma + 2.0 * cosalpha * cosbeta * cosgamma ) ; axes [ 2 ] . x = clength * cosbeta ; axes [ 2 ] . y = clength * ( cosalpha - cosbeta * cosgamma ) / singamma ; axes [ 2 ] . z = volume / ( alength * blength * singamma ) ; return axes ; }
Calculates Cartesian vectors for unit cell axes from axes lengths and angles between axes .
28,668
public static void fractionalToCartesian ( ICrystal crystal ) { Iterator < IAtom > atoms = crystal . atoms ( ) . iterator ( ) ; Vector3d aAxis = crystal . getA ( ) ; Vector3d bAxis = crystal . getB ( ) ; Vector3d cAxis = crystal . getC ( ) ; while ( atoms . hasNext ( ) ) { IAtom atom = atoms . next ( ) ; Point3d fracPoint = atom . getFractionalPoint3d ( ) ; if ( fracPoint != null ) { atom . setPoint3d ( fractionalToCartesian ( aAxis , bAxis , cAxis , fracPoint ) ) ; } } }
Creates Cartesian coordinates for all Atoms in the Crystal .
28,669
public double getBondLength ( ) { PharmacophoreAtom atom1 = PharmacophoreAtom . get ( getAtom ( 0 ) ) ; PharmacophoreAtom atom2 = PharmacophoreAtom . get ( getAtom ( 1 ) ) ; return atom1 . getPoint3d ( ) . distance ( atom2 . getPoint3d ( ) ) ; }
Get the distance between the two pharmacophore groups that make up the constraint .
28,670
public boolean matches ( IAtom atom ) { PharmacophoreAtom patom = PharmacophoreAtom . get ( atom ) ; return patom . getSymbol ( ) . equals ( getSymbol ( ) ) ; }
Checks whether this query atom matches a target atom .
28,671
Mappings matchRoot ( IAtom root ) { checkCompatibleAPI ( root ) ; IAtomContainer mol = root . getContainer ( ) ; if ( query . getAtomCount ( ) > 0 && ( ( IQueryAtom ) query . getAtom ( 0 ) ) . matches ( root ) ) { DfState local = new DfState ( state ) ; local . setRoot ( root ) ; return filter ( new Mappings ( query , mol , local ) , query , mol ) ; } else { return new Mappings ( query , mol , Collections . < int [ ] > emptySet ( ) ) ; } }
Match the pattern at the provided root .
28,672
public Partition getInitialPartition ( ) { if ( ignoreElements ) { int n = atomContainer . getAtomCount ( ) ; return Partition . unit ( n ) ; } Map < String , SortedSet < Integer > > cellMap = new HashMap < String , SortedSet < Integer > > ( ) ; int numberOfAtoms = atomContainer . getAtomCount ( ) ; for ( int atomIndex = 0 ; atomIndex < numberOfAtoms ; atomIndex ++ ) { String symbol = atomContainer . getAtom ( atomIndex ) . getSymbol ( ) ; SortedSet < Integer > cell ; if ( cellMap . containsKey ( symbol ) ) { cell = cellMap . get ( symbol ) ; } else { cell = new TreeSet < Integer > ( ) ; cellMap . put ( symbol , cell ) ; } cell . add ( atomIndex ) ; } List < String > atomSymbols = new ArrayList < String > ( cellMap . keySet ( ) ) ; Collections . sort ( atomSymbols ) ; Partition elementPartition = new Partition ( ) ; for ( String key : atomSymbols ) { SortedSet < Integer > cell = cellMap . get ( key ) ; elementPartition . addCell ( cell ) ; } return elementPartition ; }
Get the element partition from an atom container which is simply a list of sets of atom indices where all atoms in one set have the same element symbol .
28,673
private void setupConnectionTable ( IAtomContainer atomContainer ) { int atomCount = atomContainer . getAtomCount ( ) ; connectionTable = new int [ atomCount ] [ ] ; if ( ! ignoreBondOrders ) { bondOrders = new int [ atomCount ] [ ] ; } for ( int atomIndex = 0 ; atomIndex < atomCount ; atomIndex ++ ) { IAtom atom = atomContainer . getAtom ( atomIndex ) ; List < IAtom > connectedAtoms = atomContainer . getConnectedAtomsList ( atom ) ; int numConnAtoms = connectedAtoms . size ( ) ; connectionTable [ atomIndex ] = new int [ numConnAtoms ] ; if ( ! ignoreBondOrders ) { bondOrders [ atomIndex ] = new int [ numConnAtoms ] ; } int i = 0 ; for ( IAtom connected : connectedAtoms ) { int index = atomContainer . indexOf ( connected ) ; connectionTable [ atomIndex ] [ i ] = index ; if ( ! ignoreBondOrders ) { IBond bond = atomContainer . getBond ( atom , connected ) ; boolean isArom = bond . getFlag ( CDKConstants . ISAROMATIC ) ; int orderNumber = ( isArom ) ? 5 : bond . getOrder ( ) . numeric ( ) ; bondOrders [ atomIndex ] [ i ] = orderNumber ; if ( orderNumber > maxBondOrder ) { maxBondOrder = orderNumber ; } } i ++ ; } } }
Makes a lookup table for the connection between atoms to avoid looking through the bonds each time .
28,674
public void setInputReader ( Reader reader ) { if ( reader instanceof BufferedReader ) { this . in = ( BufferedReader ) reader ; } else if ( reader == null ) { this . in = null ; } else { this . in = new BufferedReader ( reader ) ; } }
Overwrites the default reader from which the input is taken .
28,675
public void write ( IChemObject object ) throws CDKException { if ( object instanceof IReactionSet ) { writeReactionSet ( ( IReactionSet ) object ) ; } else if ( object instanceof IReaction ) { writeReaction ( ( IReaction ) object ) ; } else { throw new CDKException ( "Only supported is writing ReactionSet, Reaction objects." ) ; } }
Writes a IChemObject to the MDL RXN file formated output . It can only output ChemObjects of type Reaction
28,676
private void writeReactionSet ( IReactionSet reactions ) throws CDKException { for ( IReaction iReaction : reactions . reactions ( ) ) { writeReaction ( iReaction ) ; } }
Writes an array of Reaction to an OutputStream in MDL rdf format .
28,677
private void writeAtomContainerSet ( IAtomContainerSet som ) throws IOException , CDKException { for ( int i = 0 ; i < som . getAtomContainerCount ( ) ; i ++ ) { IAtomContainer mol = som . getAtomContainer ( i ) ; for ( int j = 0 ; j < som . getMultiplier ( i ) ; j ++ ) { StringWriter sw = new StringWriter ( ) ; writer . write ( "$MOL" ) ; writer . write ( '\n' ) ; MDLV2000Writer mdlwriter = null ; try { mdlwriter = new MDLV2000Writer ( sw ) ; } catch ( Exception ex ) { logger . error ( ex . getMessage ( ) ) ; logger . debug ( ex ) ; throw new CDKException ( "Exception while creating MDLWriter: " + ex . getMessage ( ) , ex ) ; } mdlwriter . write ( mol ) ; mdlwriter . close ( ) ; writer . write ( sw . toString ( ) ) ; } } }
Writes a MoleculeSet to an OutputStream for the reaction .
28,678
private String formatMDLInt ( int i , int l ) { String s = "" , fs = "" ; NumberFormat nf = NumberFormat . getNumberInstance ( Locale . ENGLISH ) ; nf . setParseIntegerOnly ( true ) ; nf . setMinimumIntegerDigits ( 1 ) ; nf . setMaximumIntegerDigits ( l ) ; nf . setGroupingUsed ( false ) ; s = nf . format ( i ) ; l = l - s . length ( ) ; for ( int f = 0 ; f < l ; f ++ ) fs += " " ; fs += s ; return fs ; }
Formats an int to fit into the connectiontable and changes it to a String .
28,679
public static SMARTSAtom and ( IQueryAtom left , IQueryAtom right ) { return new Conjunction ( left . getBuilder ( ) , left , right ) ; }
Conjunction the provided expressions .
28,680
public static SMARTSAtom or ( IQueryAtom left , IQueryAtom right ) { return new Disjunction ( left . getBuilder ( ) , left , right ) ; }
Disjunction the provided expressions .
28,681
public PathBuilder quadTo ( Point2d cp , Point2d ep ) { add ( new QuadTo ( cp , ep ) ) ; return this ; }
Make a quadratic curve in the path with one control point .
28,682
public PathBuilder cubicTo ( Point2d cp1 , Point2d cp2 , Point2d ep ) { add ( new CubicTo ( cp1 , cp2 , ep ) ) ; return this ; }
Make a cubic curve in the path with two control points .
28,683
public boolean showCarbon ( IAtom atom , IAtomContainer container , RendererModel model ) { Integer massNumber = atom . getMassNumber ( ) ; if ( massNumber != null ) { try { Integer expectedMassNumber = Isotopes . getInstance ( ) . getMajorIsotope ( atom . getSymbol ( ) ) . getMassNumber ( ) ; if ( ! massNumber . equals ( expectedMassNumber ) ) return true ; } catch ( IOException e ) { logger . warn ( e ) ; } } return super . showCarbon ( atom , container , model ) ; }
Returns true if the mass number of this element is set and not equal the mass number of the most abundant isotope of this element .
28,684
private static String encodePath ( int dist , IAtom a , IAtom b ) { return dist + "_" + a . getSymbol ( ) + "_" + b . getSymbol ( ) ; }
Creates the fingerprint name which is used as a key in our hashes
28,685
private static String encodeHalPath ( int dist , IAtom a , IAtom b ) { return dist + "_" + ( isHalogen ( a ) ? "X" : a . getSymbol ( ) ) + "_" + ( isHalogen ( b ) ? "X" : b . getSymbol ( ) ) ; }
Encodes name for halogen paths
28,686
private void calculate ( List < String > paths , IAtomContainer mol ) { AllPairsShortestPaths apsp = new AllPairsShortestPaths ( mol ) ; int numAtoms = mol . getAtomCount ( ) ; for ( int i = 0 ; i < numAtoms ; i ++ ) { if ( ! include ( mol . getAtom ( i ) ) ) continue ; for ( int j = i + 1 ; j < numAtoms ; j ++ ) { if ( ! include ( mol . getAtom ( j ) ) ) continue ; final int dist = apsp . from ( i ) . distanceTo ( j ) ; if ( dist > MAX_DISTANCE ) continue ; final IAtom beg = mol . getAtom ( i ) ; final IAtom end = mol . getAtom ( j ) ; paths . add ( encodePath ( dist , beg , end ) ) ; paths . add ( encodePath ( dist , end , beg ) ) ; if ( isHalogen ( mol . getAtom ( i ) ) || isHalogen ( mol . getAtom ( j ) ) ) { paths . add ( encodeHalPath ( dist , beg , end ) ) ; paths . add ( encodeHalPath ( dist , end , beg ) ) ; } } } }
This performs the calculations used to generate the fingerprint
28,687
private void init ( ) { boolean success = false ; if ( ! success ) { try { javax . xml . parsers . SAXParserFactory spf = javax . xml . parsers . SAXParserFactory . newInstance ( ) ; spf . setNamespaceAware ( true ) ; javax . xml . parsers . SAXParser saxParser = spf . newSAXParser ( ) ; parser = saxParser . getXMLReader ( ) ; logger . info ( "Using JAXP/SAX XML parser." ) ; success = true ; } catch ( ParserConfigurationException | SAXException e ) { logger . warn ( "Could not instantiate JAXP/SAX XML reader!" ) ; logger . debug ( e ) ; } } if ( ! success ) { try { parser = ( XMLReader ) this . getClass ( ) . getClassLoader ( ) . loadClass ( "gnu.xml.aelfred2.XmlReader" ) . newInstance ( ) ; logger . info ( "Using Aelfred2 XML parser." ) ; success = true ; } catch ( ClassNotFoundException | InstantiationException | IllegalAccessException e ) { logger . warn ( "Could not instantiate Aelfred2 XML reader!" ) ; logger . debug ( e ) ; } } if ( ! success ) { try { parser = ( XMLReader ) this . getClass ( ) . getClassLoader ( ) . loadClass ( "org.apache.xerces.parsers.SAXParser" ) . newInstance ( ) ; logger . info ( "Using Xerces XML parser." ) ; success = true ; } catch ( ClassNotFoundException | InstantiationException | IllegalAccessException e ) { logger . warn ( "Could not instantiate Xerces XML reader!" ) ; logger . debug ( e ) ; } } if ( ! success ) { logger . error ( "Could not instantiate any XML parser!" ) ; } }
Initializes this reader .
28,688
public void add3DCoordinatesForSinglyBondedLigands ( IAtomContainer atomContainer ) throws CDKException { IAtom refAtom = null ; IAtom atomC = null ; int nwanted = 0 ; for ( int i = 0 ; i < atomContainer . getAtomCount ( ) ; i ++ ) { refAtom = atomContainer . getAtom ( i ) ; if ( ! refAtom . getSymbol ( ) . equals ( "H" ) && hasUnsetNeighbour ( refAtom , atomContainer ) ) { IAtomContainer noCoords = getUnsetAtomsInAtomContainer ( refAtom , atomContainer ) ; IAtomContainer withCoords = getPlacedAtomsInAtomContainer ( refAtom , atomContainer ) ; if ( withCoords . getAtomCount ( ) > 0 ) { atomC = getPlacedHeavyAtomInAtomContainer ( withCoords . getAtom ( 0 ) , refAtom , atomContainer ) ; } if ( refAtom . getFormalNeighbourCount ( ) == 0 && refAtom . getSymbol ( ) . equals ( "C" ) ) { nwanted = noCoords . getAtomCount ( ) ; } else if ( refAtom . getFormalNeighbourCount ( ) == 0 && ! refAtom . getSymbol ( ) . equals ( "C" ) ) { nwanted = 4 ; } else { nwanted = refAtom . getFormalNeighbourCount ( ) - withCoords . getAtomCount ( ) ; } Point3d [ ] newPoints = get3DCoordinatesForLigands ( refAtom , noCoords , withCoords , atomC , nwanted , DEFAULT_BOND_LENGTH_H , - 1 ) ; for ( int j = 0 ; j < noCoords . getAtomCount ( ) ; j ++ ) { IAtom ligand = noCoords . getAtom ( j ) ; Point3d newPoint = rescaleBondLength ( refAtom , ligand , newPoints [ j ] ) ; ligand . setPoint3d ( newPoint ) ; ligand . setFlag ( CDKConstants . ISPLACED , true ) ; } noCoords . removeAllElements ( ) ; withCoords . removeAllElements ( ) ; } } }
Generate coordinates for all atoms which are singly bonded and have no coordinates . This is useful when hydrogens are present but have no coordinates . It knows about C O N S only and will give tetrahedral or trigonal geometry elsewhere . Bond lengths are computed from covalent radii or taken out of a parameter set if available . Angles are tetrahedral or trigonal
28,689
public Point3d rescaleBondLength ( IAtom atom1 , IAtom atom2 , Point3d point2 ) { Point3d point1 = atom1 . getPoint3d ( ) ; Double d1 = atom1 . getCovalentRadius ( ) ; Double d2 = atom2 . getCovalentRadius ( ) ; double distance = ( d1 == null || d2 == null ) ? 1.0 : d1 + d2 ; if ( pSet != null ) { distance = getDistanceValue ( atom1 . getAtomTypeName ( ) , atom2 . getAtomTypeName ( ) ) ; } Vector3d vect = new Vector3d ( point2 ) ; vect . sub ( point1 ) ; vect . normalize ( ) ; vect . scale ( distance ) ; Point3d newPoint = new Point3d ( point1 ) ; newPoint . add ( vect ) ; return newPoint ; }
Rescales Point2 so that length 1 - 2 is sum of covalent radii . If covalent radii cannot be found use bond length of 1 . 0
28,690
public Point3d [ ] get3DCoordinatesForSP2Ligands ( IAtom refAtom , IAtomContainer noCoords , IAtomContainer withCoords , IAtom atomC , double length , double angle ) { Point3d newPoints [ ] = new Point3d [ 1 ] ; if ( angle < 0 ) { angle = SP2_ANGLE ; } if ( withCoords . getAtomCount ( ) >= 2 ) { newPoints [ 0 ] = calculate3DCoordinatesSP2_1 ( refAtom . getPoint3d ( ) , ( withCoords . getAtom ( 0 ) ) . getPoint3d ( ) , ( withCoords . getAtom ( 1 ) ) . getPoint3d ( ) , length , - 1 * angle ) ; } else if ( withCoords . getAtomCount ( ) <= 1 ) { newPoints = calculate3DCoordinatesSP2_2 ( refAtom . getPoint3d ( ) , ( withCoords . getAtom ( 0 ) ) . getPoint3d ( ) , ( atomC != null ) ? atomC . getPoint3d ( ) : null , length , angle ) ; } return newPoints ; }
Main method for the calculation of the ligand coordinates for sp2 atoms . Decides if one or two coordinates should be created
28,691
public Point3d [ ] get3DCoordinatesForSP3Ligands ( IAtom refAtom , IAtomContainer noCoords , IAtomContainer withCoords , IAtom atomC , int nwanted , double length , double angle ) { Point3d newPoints [ ] = new Point3d [ 0 ] ; Point3d aPoint = refAtom . getPoint3d ( ) ; int nwithCoords = withCoords . getAtomCount ( ) ; if ( angle < 0 ) { angle = TETRAHEDRAL_ANGLE ; } if ( nwithCoords == 0 ) { newPoints = calculate3DCoordinates0 ( refAtom . getPoint3d ( ) , nwanted , length ) ; } else if ( nwithCoords == 1 ) { newPoints = calculate3DCoordinates1 ( aPoint , ( withCoords . getAtom ( 0 ) ) . getPoint3d ( ) , ( atomC != null ) ? atomC . getPoint3d ( ) : null , nwanted , length , angle ) ; } else if ( nwithCoords == 2 ) { Point3d bPoint = withCoords . getAtom ( 0 ) . getPoint3d ( ) ; Point3d cPoint = withCoords . getAtom ( 1 ) . getPoint3d ( ) ; newPoints = calculate3DCoordinates2 ( aPoint , bPoint , cPoint , nwanted , length , angle ) ; } else if ( nwithCoords == 3 ) { Point3d bPoint = withCoords . getAtom ( 0 ) . getPoint3d ( ) ; Point3d cPoint = withCoords . getAtom ( 1 ) . getPoint3d ( ) ; newPoints = new Point3d [ 1 ] ; Point3d dPoint = withCoords . getAtom ( 2 ) . getPoint3d ( ) ; newPoints [ 0 ] = calculate3DCoordinates3 ( aPoint , bPoint , cPoint , dPoint , length ) ; } return newPoints ; }
Main method for the calculation of the ligand coordinates for sp3 atoms . Decides how many coordinates should be created
28,692
private Vector3d getNonColinearVector ( Vector3d ab ) { Vector3d cr = new Vector3d ( ) ; cr . cross ( ab , XV ) ; if ( cr . length ( ) > 0.00001 ) { return XV ; } else { return YV ; } }
Gets the nonColinearVector attribute of the AtomLigandPlacer3D class
28,693
public static Vector3d rotate ( Vector3d vector , Vector3d axis , double angle ) { Matrix3d rotate = new Matrix3d ( ) ; rotate . set ( new AxisAngle4d ( axis . x , axis . y , axis . z , angle ) ) ; Vector3d result = new Vector3d ( ) ; rotate . transform ( vector , result ) ; return result ; }
Rotates a vector around an axis .
28,694
private double getDistanceValue ( String id1 , String id2 ) { String dkey = "" ; if ( pSet . containsKey ( ( "bond" + id1 + ";" + id2 ) ) ) { dkey = "bond" + id1 + ";" + id2 ; } else if ( pSet . containsKey ( ( "bond" + id2 + ";" + id1 ) ) ) { dkey = "bond" + id2 + ";" + id1 ; } else { return DEFAULT_BOND_LENGTH_H ; } return ( ( Double ) ( ( ( List ) pSet . get ( dkey ) ) . get ( 0 ) ) ) . doubleValue ( ) ; }
Gets the distance between two atoms out of the parameter set .
28,695
public double getSpatproduct ( Vector3d a , Vector3d b , Vector3d c ) { return ( c . x * ( b . y * a . z - b . z * a . y ) + c . y * ( b . z * a . x - b . x * a . z ) + c . z * ( b . x * a . y - b . y * a . x ) ) ; }
Gets the spatproduct of three vectors .
28,696
public double getTorsionAngle ( Point3d a , Point3d b , Point3d c , Point3d d ) { Vector3d ab = new Vector3d ( a . x - b . x , a . y - b . y , a . z - b . z ) ; Vector3d cb = new Vector3d ( c . x - b . x , c . y - b . y , c . z - b . z ) ; Vector3d dc = new Vector3d ( d . x - c . x , d . y - c . y , d . z - c . z ) ; Vector3d bc = new Vector3d ( b . x - c . x , b . y - c . y , b . z - c . z ) ; Vector3d n1 = new Vector3d ( ) ; Vector3d n2 = new Vector3d ( ) ; n1 . cross ( ab , cb ) ; if ( getSpatproduct ( ab , cb , n1 ) > 0 ) { n1 . cross ( cb , ab ) ; } n1 . normalize ( ) ; n2 . cross ( dc , bc ) ; if ( getSpatproduct ( dc , bc , n2 ) < 0 ) { n2 . cross ( bc , dc ) ; } n2 . normalize ( ) ; return n1 . dot ( n2 ) ; }
Calculates the torsionAngle of a - b - c - d .
28,697
public IAtomContainer getPlacedAtomsInAtomContainer ( IAtom atom , IAtomContainer ac ) { List bonds = ac . getConnectedBondsList ( atom ) ; IAtomContainer connectedAtoms = atom . getBuilder ( ) . newInstance ( IAtomContainer . class ) ; IAtom connectedAtom = null ; for ( int i = 0 ; i < bonds . size ( ) ; i ++ ) { connectedAtom = ( ( IBond ) bonds . get ( i ) ) . getOther ( atom ) ; if ( connectedAtom . getFlag ( CDKConstants . ISPLACED ) ) { connectedAtoms . addAtom ( connectedAtom ) ; } } return connectedAtoms ; }
Gets all placed neighbouring atoms of a atom .
28,698
public IAtomContainer getUnsetAtomsInAtomContainer ( IAtom atom , IAtomContainer ac ) { List atoms = ac . getConnectedAtomsList ( atom ) ; IAtomContainer connectedAtoms = atom . getBuilder ( ) . newInstance ( IAtomContainer . class ) ; for ( int i = 0 ; i < atoms . size ( ) ; i ++ ) { IAtom curAtom = ( IAtom ) atoms . get ( i ) ; if ( ! curAtom . getFlag ( CDKConstants . ISPLACED ) ) { connectedAtoms . addAtom ( curAtom ) ; } } return connectedAtoms ; }
Gets the unsetAtomsInAtomContainer attribute of the AtomTetrahedralLigandPlacer3D object .
28,699
public IAtom getPlacedHeavyAtomInAtomContainer ( IAtom atomA , IAtom atomB , IAtomContainer ac ) { List atoms = ac . getConnectedAtomsList ( atomA ) ; IAtom atom = null ; for ( int i = 0 ; i < atoms . size ( ) ; i ++ ) { IAtom curAtom = ( IAtom ) atoms . get ( i ) ; if ( curAtom . getFlag ( CDKConstants . ISPLACED ) && ! curAtom . getSymbol ( ) . equals ( "H" ) && ! Objects . equals ( curAtom , atomB ) ) { return curAtom ; } } return atom ; }
Returns a placed neighbouring atom of a central atom atomA which is not atomB .