1111import org .biojava .nbio .structure .Atom ;
1212import org .biojava .nbio .structure .Calc ;
1313import org .biojava .nbio .structure .StructureException ;
14- import org .biojava .nbio .structure .StructureTools ;
1514import org .biojava .nbio .structure .align .helper .AlignTools ;
1615import org .biojava .nbio .structure .align .model .AFPChain ;
1716import org .biojava .nbio .structure .align .multiple .util .MultipleAlignmentScorer ;
2625 *
2726 */
2827public class MultipleAlignmentEnsembleImpl extends AbstractScoresCache
29- implements MultipleAlignmentEnsemble , Serializable , Cloneable {
28+ implements MultipleAlignmentEnsemble , Serializable , Cloneable {
3029
3130 private static final long serialVersionUID = -5732485866623431898L ;
32-
31+
3332 //Creation Properties
3433 private String algorithmName ;
3534 private String version ;
3635 private Long ioTime ;
3736 private Long calculationTime ;
38-
37+
3938 //Structure Identifiers
4039 private List <String > structureNames ;
4140 private List <Atom []> atomArrays ;
4241 private List <Matrix > distanceMatrix ;
43-
42+
4443 private List <MultipleAlignment > multipleAlignments ;
45-
44+
4645 /**
4746 * Default Constructor. Empty ensemble, no structures assigned.
4847 *
4948 * @return MultipleAlignmentEnsemble an empty ensemble instance.
5049 */
5150 public MultipleAlignmentEnsembleImpl (){
52-
51+
5352 algorithmName = null ;
5453 version = null ;
5554 ioTime = null ;
5655 calculationTime = null ;
57-
56+
5857 structureNames = null ;
5958 atomArrays = null ;
6059 distanceMatrix = null ;
6160 multipleAlignments = null ;
6261 }
63-
62+
6463 /**
6564 * Constructor using structure identifiers.
6665 *
@@ -72,7 +71,7 @@ public MultipleAlignmentEnsembleImpl(List<String> structureNames){
7271 this ();
7372 setStructureNames (structureNames );
7473 }
75-
74+
7675 /**
7776 * Copy constructor. This copies recursively all member variables,
7877 * including MultipleAlignments, Atom arrays and cached variables.
@@ -81,23 +80,13 @@ public MultipleAlignmentEnsembleImpl(List<String> structureNames){
8180 * @return MultipleAlignmentEnsemble identical copy of the input ensemble.
8281 */
8382 public MultipleAlignmentEnsembleImpl (MultipleAlignmentEnsembleImpl e ){
84-
83+
8584 super (e ); //Copy the scores
8685 algorithmName = e .algorithmName ;
8786 version = e .version ;
8887 ioTime = e .ioTime ;
8988 calculationTime = e .calculationTime ;
90-
91- atomArrays = null ;
92- if (e .atomArrays != null ){
93- //Make a deep copy of everything
94- atomArrays = new ArrayList <Atom []>();
95- for (Atom [] array :e .atomArrays ){
96- Atom [] newArray = StructureTools .cloneAtomArray (array );
97- atomArrays .add (newArray );
98- }
99- }
100-
89+
10190 distanceMatrix = null ;
10291 if (e .distanceMatrix !=null ){
10392 //Make a deep copy of everything
@@ -106,7 +95,7 @@ public MultipleAlignmentEnsembleImpl(MultipleAlignmentEnsembleImpl e){
10695 distanceMatrix .add ((Matrix ) mat .clone ());
10796 }
10897 }
109-
98+
11099 multipleAlignments = null ;
111100 if (e .multipleAlignments !=null ){
112101 //Make a deep copy of everything
@@ -117,9 +106,15 @@ public MultipleAlignmentEnsembleImpl(MultipleAlignmentEnsembleImpl e){
117106 multipleAlignments .add (newMSA );
118107 }
119108 }
120- structureNames = new ArrayList <String >(e .structureNames );
109+
110+ if (e .atomArrays != null ){
111+ atomArrays = new ArrayList <Atom []>(e .atomArrays );
112+ }
113+ if (e .structureNames != null ){
114+ structureNames = new ArrayList <String >(e .structureNames );
115+ }
121116 }
122-
117+
123118 /**
124119 * Constructor from an AFPChain instance. Creates an equivalent pairwise
125120 * alignment, but in the MultipleAlignment format.
@@ -132,26 +127,26 @@ public MultipleAlignmentEnsembleImpl(MultipleAlignmentEnsembleImpl e){
132127 */
133128 public MultipleAlignmentEnsembleImpl (
134129 AFPChain afp , Atom [] ca1 , Atom [] ca2 , boolean flexible ){
135-
130+
136131 this ();
137132 //Copy all the creation and algorithm information
138133 atomArrays = Arrays .asList (ca1 ,ca2 );
139134 structureNames = Arrays .asList (afp .getName1 (),afp .getName2 ());
140135 algorithmName = afp .getAlgorithmName ();
141136 version = afp .getVersion ();
142137 calculationTime = afp .getCalculationTime ();
143-
138+
144139 MultipleAlignment msa = new MultipleAlignmentImpl (this );
145140 setMultipleAlignments (Arrays .asList ((MultipleAlignment ) msa ));
146-
141+
147142 //Convert the rotation and translation to a Matrix4D and set it
148143 Matrix4d ident = new Matrix4d ();
149144 ident .setIdentity ();
150145 Matrix rot = afp .getBlockRotationMatrix ()[0 ];
151146 Atom shift = afp .getBlockShiftVector ()[0 ];
152147 Matrix4d transform = Calc .getTransformation (rot , shift );
153148 msa .setTransformations (Arrays .asList (ident , transform ));
154-
149+
155150 //Create a BlockSet for every block in AFPChain if flexible
156151 if (flexible ){
157152 for (int bs =0 ; bs <afp .getBlockNum (); bs ++){
@@ -160,13 +155,13 @@ public MultipleAlignmentEnsembleImpl(
160155 block .setAlignRes (new ArrayList <List <Integer >>());
161156 block .getAlignRes ().add (new ArrayList <Integer >());
162157 block .getAlignRes ().add (new ArrayList <Integer >());
163-
158+
164159 //Set the transformation of the BlockSet
165160 Matrix rotB = afp .getBlockRotationMatrix ()[bs ];
166161 Atom shiftB = afp .getBlockShiftVector ()[bs ];
167162 Matrix4d transformB = Calc .getTransformation (rotB , shiftB );
168163 blockSet .setTransformations (Arrays .asList (ident , transformB ));
169-
164+
170165 //Convert the optimal alignment to a Block
171166 for (int i =0 ; i <afp .getOptAln ()[bs ][0 ].length ; i ++){
172167 block .getAlignRes ().get (0 ).add (afp .getOptAln ()[bs ][0 ][i ]);
@@ -181,27 +176,27 @@ public MultipleAlignmentEnsembleImpl(
181176 block .setAlignRes (new ArrayList <List <Integer >>());
182177 block .getAlignRes ().add (new ArrayList <Integer >());
183178 block .getAlignRes ().add (new ArrayList <Integer >());
184-
179+
185180 //Convert the optimal alignment to a Block
186181 for (int i =0 ; i <afp .getOptAln ()[bs ][0 ].length ; i ++){
187182 block .getAlignRes ().get (0 ).add (afp .getOptAln ()[bs ][0 ][i ]);
188183 block .getAlignRes ().get (1 ).add (afp .getOptAln ()[bs ][1 ][i ]);
189184 }
190185 }
191186 }
192-
187+
193188 //Copy the scores stored in the AFPChain
194189 msa .putScore (MultipleAlignmentScorer .PROBABILITY ,afp .getProbability ());
195190 msa .putScore (MultipleAlignmentScorer .AVGTM_SCORE ,afp .getTMScore ());
196191 msa .putScore (MultipleAlignmentScorer .CE_SCORE ,afp .getAlignScore ());
197192 msa .putScore (MultipleAlignmentScorer .RMSD , afp .getTotalRmsdOpt ());
198193 }
199-
194+
200195 @ Override
201196 public MultipleAlignmentEnsembleImpl clone () {
202197 return new MultipleAlignmentEnsembleImpl (this );
203198 }
204-
199+
205200 @ Override
206201 public String getAlgorithmName () {
207202 return algorithmName ;
@@ -231,7 +226,7 @@ public Long getIoTime() {
231226 public void setIoTime (Long millis ) {
232227 this .ioTime = millis ;
233228 }
234-
229+
235230 @ Override
236231 public Long getCalculationTime () {
237232 return calculationTime ;
@@ -270,7 +265,7 @@ public List<Atom[]> getAtomArrays() {
270265 public void setAtomArrays (List <Atom []> atomArrays ) {
271266 this .atomArrays = atomArrays ;
272267 }
273-
268+
274269 /**
275270 * Force the atom arrays to regenerate based on
276271 * {@link #getStructureNames()}.
@@ -297,10 +292,10 @@ public List<Matrix> getDistanceMatrix() {
297292 * Force recalculation of the distance matrices.
298293 */
299294 public void updateDistanceMatrix () {
300-
295+
301296 //Reset the distance Matrix variable
302297 distanceMatrix = new ArrayList <Matrix >();
303-
298+
304299 for (int s =0 ; s <size (); s ++){
305300 Atom [] ca = atomArrays .get (s );
306301 Matrix distMat =AlignTools .getDistanceMatrix (ca , ca );
@@ -310,7 +305,7 @@ public void updateDistanceMatrix() {
310305
311306 @ Override
312307 public List <MultipleAlignment > getMultipleAlignments () {
313-
308+
314309 if (multipleAlignments == null ){
315310 multipleAlignments = new ArrayList <MultipleAlignment >();
316311 }
@@ -321,7 +316,7 @@ public List<MultipleAlignment> getMultipleAlignments() {
321316 public void setMultipleAlignments (List <MultipleAlignment > alignments ) {
322317 this .multipleAlignments = alignments ;
323318 }
324-
319+
325320 @ Override
326321 public void addMultipleAlignment (MultipleAlignment alignment ) {
327322 if (multipleAlignments == null ){
@@ -337,10 +332,10 @@ public int size() {
337332 else if (atomArrays != null ) return atomArrays .size ();
338333 else {
339334 throw new IndexOutOfBoundsException (
340- "Empty ensemble: names == null && atoms == null" );
335+ "Empty ensemble: names == null && atoms == null" );
341336 }
342337 }
343-
338+
344339 @ Override
345340 public void clear () {
346341 super .clear ();
0 commit comments