3131import org .biojava .nbio .core .sequence .ProteinSequence ;
3232import org .biojava .nbio .core .sequence .compound .AminoAcidCompound ;
3333import org .biojava .nbio .structure .Atom ;
34+ import org .biojava .nbio .structure .Chain ;
35+ import org .biojava .nbio .structure .Structure ;
3436import org .biojava .nbio .structure .StructureException ;
3537import org .biojava .nbio .structure .align .StructureAlignment ;
3638import org .biojava .nbio .structure .align .StructureAlignmentFactory ;
4547import org .biojava .nbio .structure .align .multiple .MultipleAlignmentImpl ;
4648import org .biojava .nbio .structure .align .multiple .util .MultipleAlignmentScorer ;
4749import org .biojava .nbio .structure .align .multiple .util .ReferenceSuperimposer ;
50+ import org .biojava .nbio .structure .quaternary .BiologicalAssemblyBuilder ;
4851import org .biojava .nbio .structure .symmetry .core .QuatSymmetrySubunits ;
4952import org .biojava .nbio .structure .symmetry .internal .CESymmParameters ;
5053import org .biojava .nbio .structure .symmetry .internal .CeSymm ;
@@ -178,6 +181,38 @@ public boolean isIdenticalTo(SubunitCluster other) {
178181 return thisSequence .equals (otherSequence );
179182 }
180183
184+ /**
185+ * Tells whether the other SubunitCluster contains exactly the same Subunit.
186+ * This is checked by equality of their entity identifiers if they are present.
187+ *
188+ * @param other
189+ * SubunitCluster
190+ * @return true if the SubunitClusters are identical, false otherwise
191+ */
192+ public boolean isIdenticalByEntityIdTo (SubunitCluster other ) {
193+ Structure thisStruct = this .subunits .get (this .representative ).getStructure ();
194+ Structure otherStruct = other .subunits .get (other .representative ).getStructure ();
195+ String thisName = this .subunits .get (this .representative ).getName ();
196+ String otherName = other .subunits .get (this .representative ).getName ();
197+ Chain thisChain = thisStruct .getChain (thisName );
198+ Chain otherChain = otherStruct .getChain (otherName );
199+ if (thisChain == null || otherChain == null ) {
200+ logger .info ("Can't determine entity ids of SubunitClusters {}-{}. Ignoring identity check by entity id" ,
201+ this .subunits .get (this .representative ).getName (),
202+ other .subunits .get (other .representative ).getName ());
203+ return false ;
204+ }
205+ if (thisChain .getEntityInfo () == null || otherChain .getEntityInfo () == null ) {
206+ logger .info ("Can't determine entity ids of SubunitClusters {}-{}. Ignoring identity check by entity id" ,
207+ this .subunits .get (this .representative ).getName (),
208+ other .subunits .get (other .representative ).getName ());
209+ return false ;
210+ }
211+ int thisEntityId = thisChain .getEntityInfo ().getMolId ();
212+ int otherEntityId = otherChain .getEntityInfo ().getMolId ();
213+ return thisEntityId == otherEntityId ;
214+ }
215+
181216 /**
182217 * Merges the other SubunitCluster into this one if it contains exactly the
183218 * same Subunit. This is checked by {@link #isIdenticalTo(SubunitCluster)}.
@@ -191,7 +226,35 @@ public boolean mergeIdentical(SubunitCluster other) {
191226 if (!isIdenticalTo (other ))
192227 return false ;
193228
194- logger .info ("SubunitClusters are identical" );
229+ logger .info ("SubunitClusters {}-{} are identical in sequence" ,
230+ this .subunits .get (this .representative ).getName (),
231+ other .subunits .get (other .representative ).getName ());
232+
233+ this .subunits .addAll (other .subunits );
234+ this .subunitEQR .addAll (other .subunitEQR );
235+
236+ return true ;
237+ }
238+
239+ /**
240+ * Merges the other SubunitCluster into this one if it contains exactly the
241+ * same Subunit. This is checked by comparing the entity identifiers of the subunits
242+ * if one can be found.
243+ * Thus this only makes sense when the subunits are complete chains of a
244+ * deposited PDB entry. I
245+ *
246+ * @param other
247+ * SubunitCluster
248+ * @return true if the SubunitClusters were merged, false otherwise
249+ */
250+ public boolean mergeIdenticalByEntityId (SubunitCluster other ) {
251+
252+ if (!isIdenticalByEntityIdTo (other ))
253+ return false ;
254+
255+ logger .info ("SubunitClusters {}-{} belong to same entity. Assuming they are identical" ,
256+ this .subunits .get (this .representative ).getName (),
257+ other .subunits .get (other .representative ).getName ());
195258
196259 this .subunits .addAll (other .subunits );
197260 this .subunitEQR .addAll (other .subunitEQR );
0 commit comments