public static void createPurelyNonPolyEntities ( List < List < Chain > > nonPolyModels , List < List < Chain > > waterModels , List < EntityInfo > entities ) { if ( nonPolyModels . isEmpty ( ) ) return ; // let's find first the max entity id to assign entity ids to the newly found entities int maxMolId = 0 ; if ( ! entities . isEmpty ( ) ) { maxMolId = Collections . max ( entities , new Comparator < EntityInfo > ( ) { @ Override public int compare ( EntityInfo o1 , EntityInfo o2 ) { return new Integer ( o1 . getMolId ( ) ) . compareTo ( o2 . getMolId ( ) ) ; } } ) . getMolId ( ) ; } // we go one over the max int molId = maxMolId + 1 ; if ( ! nonPolyModels . get ( 0 ) . isEmpty ( ) ) { List < EntityInfo > nonPolyEntities = new ArrayList <> ( ) ; for ( List < Chain > model : nonPolyModels ) { for ( Chain c : model ) { // we assume there's only 1 group per non-poly chain String molecPdbName = c . getAtomGroup ( 0 ) . getPDBName ( ) ; EntityInfo nonPolyEntity = findNonPolyEntityWithDescription ( molecPdbName , nonPolyEntities ) ; if ( nonPolyEntity == null ) { nonPolyEntity = new EntityInfo ( ) ; nonPolyEntity . setDescription ( molecPdbName ) ; nonPolyEntity . setType ( EntityType . NONPOLYMER ) ; nonPolyEntity . setMolId ( molId ++ ) ; nonPolyEntities . add ( nonPolyEntity ) ; } nonPolyEntity . addChain ( c ) ; c . setEntityInfo ( nonPolyEntity ) ; } } entities . addAll ( nonPolyEntities ) ; } if ( ! waterModels . get ( 0 ) . isEmpty ( ) ) { EntityInfo waterEntity = new EntityInfo ( ) ; waterEntity . setType ( EntityType . WATER ) ; waterEntity . setDescription ( "water" ) ; waterEntity . setMolId ( molId ) ; for ( List < Chain > model : waterModels ) { for ( Chain waterChain : model ) { waterEntity . addChain ( waterChain ) ; waterChain . setEntityInfo ( waterEntity ) ; } } entities . add ( waterEntity ) ; } }
Given all chains of all models find entities for the nonpolymers and water chains within them assigning entity ids types and descriptions to them . The result is written back to the passed entities List .