22
33import java .io .Serializable ;
44import java .util .ArrayList ;
5+ import java .util .HashMap ;
56import java .util .List ;
67import java .util .Map ;
78
@@ -70,6 +71,9 @@ public class MmtfStructureReader implements StructureAdapterInterface, Serializa
7071 /** All the chains */
7172 private List <Chain > chainList ;
7273
74+ /** All the chains as a list of maps */
75+ private List <Map <String ,Chain >> chainMap ;
76+
7377 /**
7478 * Instantiates a new bio java structure decoder.
7579 */
@@ -78,6 +82,7 @@ public MmtfStructureReader() {
7882 modelNumber = 0 ;
7983 entityInfoList = new ArrayList <>();
8084 chainList = new ArrayList <>();
85+ chainMap = new ArrayList <>();
8186 }
8287
8388 /**
@@ -91,15 +96,25 @@ public Structure getStructure() {
9196
9297 @ Override
9398 public void finalizeStructure () {
94- // Ensure all altlocs have all atoms
95- StructureTools .cleanUpAltLocs (structure );
99+
96100 // Number the remaining ones
97101 int counter =0 ;
102+ // Add the entity info
98103 for (EntityInfo entityInfo : entityInfoList ) {
99104 counter ++;
100105 entityInfo .setMolId (counter );
101106 }
102107 structure .setEntityInfos (entityInfoList );
108+ // Add the actual chains
109+ for (int i =0 ; i <chainMap .size (); i ++) {
110+ // Now add the chain information
111+ Map <String , Chain > modelChainMap = chainMap .get (i );
112+ for (Chain modelChain : modelChainMap .values ()){
113+ structure .addChain (modelChain , i );
114+ }
115+ }
116+ // Ensure all altlocs have all atoms
117+ StructureTools .cleanUpAltLocs (structure );
103118 }
104119
105120 @ Override
@@ -118,6 +133,7 @@ public void setModelInfo(int inputModelNumber,
118133 int chainCount ) {
119134 modelNumber = inputModelNumber ;
120135 structure .addModel (new ArrayList <Chain >(chainCount ));
136+ chainMap .add (new HashMap <>());
121137 }
122138
123139 /* (non-Javadoc)
@@ -127,20 +143,17 @@ public void setModelInfo(int inputModelNumber,
127143 @ Override
128144 public void setChainInfo (String chainId , String chainName , int groupCount ) {
129145 // First check to see if the chain exists
130- boolean newChain = true ;
131- for (Chain c : structure .getChains (modelNumber )) {
132- if (c .getId ().equals (chainId )) {
133- newChain = false ;
134- chain = c ;
135- break ;
136- }
146+ Map <String , Chain > modelChainMap = chainMap .get (modelNumber );
147+ if (modelChainMap .containsKey (chainId )){
148+ chain = modelChainMap .get (chainId );
137149 }
138150 // If we need to set a new chain do this
139- if ( newChain ) {
151+ else {
140152 chain = new ChainImpl ();
141153 chain .setId (chainId .trim ());
142154 chain .setName (chainName );
143- structure .addChain (chain , modelNumber );
155+ chain .setAtomGroups (new ArrayList <>(groupCount ));
156+ modelChainMap .put (chainId , chain );
144157 chainList .add (chain );
145158 }
146159 }
@@ -283,7 +296,6 @@ public void setInterGroupBond(int indOne,
283296 // set the new bond
284297 @ SuppressWarnings ("unused" )
285298 BondImpl bond = new BondImpl (atomOne , atomTwo , bondOrder );
286-
287299 }
288300
289301
@@ -383,10 +395,6 @@ private int getGroupTypIndicator(String currentGroupType) {
383395 @ Override
384396 public void setBioAssemblyTrans (int bioAssemblyId , int [] inputChainIndices , double [] inputTransform ) {
385397 PDBHeader pdbHeader = structure .getPDBHeader ();
386- List <Chain > totChainList = new ArrayList <>();
387- for (int i =0 ; i <structure .nrModels (); i ++) {
388- totChainList .addAll (structure .getChains (i ));
389- }
390398 // Get the bioassembly data
391399 Map <Integer , BioAssemblyInfo > bioAssemblies = pdbHeader .getBioAssemblies ();
392400 // Get the bioassembly itself (if it exists
@@ -407,7 +415,7 @@ public void setBioAssemblyTrans(int bioAssemblyId, int[] inputChainIndices, doub
407415 bioAssTrans .setId (transId .toString ());
408416 // If it actually has an index - if it doesn't it is because the chain has no density.
409417 if (currChainIndex !=-1 ){
410- bioAssTrans .setChainId (totChainList .get (currChainIndex ).getId ());
418+ bioAssTrans .setChainId (chainList .get (currChainIndex ).getId ());
411419 }
412420 else {
413421 continue ;
0 commit comments