Skip to content

Commit b54672d

Browse files
committed
Fixing bug: cloning of compounds wasn't done correctly for multimodels
This changes the behaviour of Compound.getChainIDs() to only return the unique chain ids
1 parent 54d0a66 commit b54672d

2 files changed

Lines changed: 25 additions & 14 deletions

File tree

biojava-structure/src/main/java/org/biojava/nbio/structure/Compound.java

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
import java.util.ArrayList;
3333
import java.util.Collections;
3434
import java.util.List;
35+
import java.util.Set;
36+
import java.util.TreeSet;
3537

3638
/**
3739
* An object to contain the info from the PDB header for a Molecule.
@@ -418,17 +420,23 @@ public void showSource() {
418420
}
419421

420422
/**
421-
* Return the list of member chain IDs that are described by this Compound
422-
* @return the list of ChainIDs that are described by this Compound
423+
* Return the list of member chain IDs that are described by this Compound,
424+
* only unique chain IDs are contained in the list.
425+
* Note that in the case of multimodel structures this will return just the unique
426+
* chain identifiers whilst {@link #getChains()} will return a corresponding chain
427+
* per model.
428+
* @return the list of unique ChainIDs that are described by this Compound
423429
* @see #setChains(List)
424430
* @see #getChains()
425431
*/
426432
public List<String> getChainIds() {
427-
List<String> chainIds = new ArrayList<String>();
428-
for (Chain chain : chains) {
429-
chainIds.add(chain.getChainID());
433+
434+
Set<String> uniqChainIds = new TreeSet<String>();
435+
for (int i=0;i<getChains().size();i++) {
436+
uniqChainIds.add(getChains().get(i).getChainID());
430437
}
431-
return chainIds;
438+
439+
return new ArrayList<String>(uniqChainIds);
432440
}
433441

434442
/**
@@ -812,7 +820,8 @@ public void setExpressionSystemOtherDetails(String expressionSystemOtherDetails)
812820
}
813821

814822
/**
815-
* Get the list of chains that are part of this Compound
823+
* Get the list of chains that are part of this Compound. Note that for multi-model
824+
* structures chains from all models are returned.
816825
*
817826
* @return a List of Chain objects
818827
*/

biojava-structure/src/main/java/org/biojava/nbio/structure/StructureImpl.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -170,15 +170,17 @@ public Structure clone() {
170170
for (Compound compound:this.compounds) {
171171
Compound newCompound = new Compound(compound); // this sets everything but the chains
172172
for (String chainId:compound.getChainIds()) {
173-
try {
173+
174174
for (int modelNr=0;modelNr<n.nrModels();modelNr++) {
175-
Chain newChain = n.getChainByPDB(chainId,modelNr);
176-
newChain.setCompound(newCompound);
177-
newCompound.addChain(newChain);
175+
try {
176+
Chain newChain = n.getChainByPDB(chainId,modelNr);
177+
newChain.setCompound(newCompound);
178+
newCompound.addChain(newChain);
179+
} catch (StructureException e) {
180+
// this actually happens for structure 1msh, which has no chain B for model 29 (clearly a deposition error)
181+
logger.warn("Could not find chain id "+chainId+" of model "+modelNr+" while cloning compound "+compound.getMolId()+". Something is wrong!");
182+
}
178183
}
179-
} catch (StructureException e) {
180-
logger.error("Could not find chain id {} while cloning Structure's compounds. Something is wrong!", e);
181-
}
182184
}
183185
newCompoundList.add(newCompound);
184186
}

0 commit comments

Comments
 (0)