Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -797,26 +797,27 @@ public void documentEnd() {
continue;
}
int eId = Integer.parseInt(entityId);
// We didn't add above compounds for nonpolymeric entities, thus here if a chain is nonpolymeric
// its compound won't be found. In biojava Structure data model a nonpolymeric chain does not really
// make much sense, since all small molecules are associated to a polymeric chain (the same data
// model as PDB files).
// In any case it happens in rare cases that a non-polymeric chain is not associated to any polymeric
// chain, e.g.

// Compounds are not added for non-polymeric entities, if a chain is non-polymeric its compound won't be found.
// TODO: add all entities and unique compounds and add methods to directly get polymer or non-polymer
// asyms (chains). Either create a unique StructureImpl or modify existing for a better representation of the
// mmCIF internal data structures but is compatible with Structure interface.
// Some examples of PDB entries with this kind of problem:
// - 2uub: asym_id X, chainId Z, entity_id 24: fully non-polymeric but still with its own chainId
// - 3o6j: asym_id K, chainId Z, entity_id 6 : a single water molecule
// - 1dz9: asym_id K, chainId K, entity_id 6 : a potassium ion alone
// We will discard those chains here, because they don't fit into the current data model and thus
// can cause problems, e.g.
// a) they would not be linked to a compound and give null pointers
// b) StructureTools.getAllAtoms() methods that return all atoms except waters would have
// empty lists for water-only chains

Compound compound = structure.getCompoundById(eId);
if (compound==null) {
logger.warn("Could not find a compound for entity_id {} corresponding to chain id {} (asym id {})."
+ " Most likely it is a purely non-polymeric chain ({} groups). Removing it from this structure.",
eId,chain.getChainID(),chain.getInternalChainID(),chain.getAtomGroups().size());
it.remove();
// Supports the case where the only chain members were from non-polymeric entity that is missing.
// Solved by creating a new Compound(entity) to which this chain will belong.
logger.warn("Could not find a compound for entity_id {}, for chain id {}, creating a new compound.",
eId, chain.getChainID());
compound = new Compound();
compound.setId((long)eId);
compound.addChain(chain);
chain.setCompound(compound);
structure.addCompound(compound);
} else {
logger.debug("Adding chain with chain id {} (asym id {}) to compound with entity_id {}",
chain.getChainID(), chain.getInternalChainID(), eId);
Expand Down Expand Up @@ -1109,12 +1110,20 @@ private void addCompounds(StructAsym asym) {
// get the corresponding Entity
Compound c = structure.getCompoundById(eId);
if ( c == null){
if (e!=null && e.getType().equals("polymer")) {
c = createNewCompoundFromESG(esg, eId);
c.setMolName(e.getPdbx_description());
structure.addCompound(c);
logger.debug("Adding Compound with entity id {} from _entity_src_syn, with name: {}",eId,c.getMolName());
}
if (e!=null) {
if (e.getType().equals("polymer")) {
c = createNewCompoundFromESG(esg, eId);
c.setMolName(e.getPdbx_description());
structure.addCompound(c);
logger.debug("Adding Compound with entity id {} from _entity_src_syn, with name: {}",eId,c.getMolName());
} else if (e.getType().equals("non-solvent")) {
// TODO handle non-polymer compounds.
} else if (e.getType().equals("water")) {
// TODO handle solvent entity.
} else {
logger.warn("Could not add entity id " + esg.getEntity_id() + " that has unknown _entity.type");
}
}
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@
*/
package org.biojava.nbio.structure.io;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.zip.GZIPInputStream;

import org.biojava.nbio.structure.Chain;
import org.biojava.nbio.structure.Structure;
import org.biojava.nbio.structure.StructureException;
Expand All @@ -31,14 +43,6 @@
import org.biojava.nbio.structure.xtal.CrystalCell;
import org.junit.Test;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.zip.GZIPInputStream;

import static org.junit.Assert.*;

/**
* Tests for non-deposited PDB/mmCIF files, i.e. any kind of "raw" file
* lacking significant parts of the headers.
Expand Down Expand Up @@ -285,4 +289,46 @@ public void testRefmacPdbFile() throws IOException {
assertEquals(1, s.getCompounds().size());
}

/**
* This test represents a common situation for a non-deposited structure.
* When building with common crystallography software, the user often adds new
* ligands (or solvent) molecules as new chains. Only prior to deposition
* then relabel them so that they belong to the same chain as the polymeric residues.
*
* In this case, the ligands represent valuable information and should not be discarded.
*/
@Test
public void testNewLigandChain() throws IOException, StructureException {
// Test the file parsing speed when the files are already downloaded.

InputStream pdbStream = new GZIPInputStream(this.getClass().getResourceAsStream("/ligandTest.pdb.gz"));
InputStream cifStream = new GZIPInputStream(this.getClass().getResourceAsStream("/ligandTest.cif.gz"));

assertNotNull(cifStream);
assertNotNull(pdbStream);

FileParsingParameters params = new FileParsingParameters();
PDBFileParser pdbpars = new PDBFileParser();
pdbpars.setFileParsingParameters(params);
Structure s1 = pdbpars.parsePDBFile(pdbStream) ;

// The chain B should be present with 1 ligand HEM
Chain c1 = s1.getChainByPDB("B");
assertNotNull(c1);

int expectedNumLigands = 1;
assertEquals(expectedNumLigands, c1.getAtomGroups().size());

MMcifParser mmcifpars = new SimpleMMcifParser();
SimpleMMcifConsumer consumer = new SimpleMMcifConsumer();
consumer.setFileParsingParameters(params);
mmcifpars.addMMcifConsumer(consumer);
mmcifpars.parse(cifStream) ;
Structure s2 = consumer.getStructure();

// The chain B should be present with 1 ligand HEM
Chain c2 = s2.getChainByPDB("B");
assertNotNull(c2);
assertEquals(expectedNumLigands, c2.getAtomGroups().size());
}
}
Binary file not shown.
Binary file not shown.