Skip to content

Commit a50248e

Browse files
committed
Fixing issues with bonds in 3th3 and better logging
1 parent 35ff5a4 commit a50248e

File tree

3 files changed

+80
-7
lines changed

3 files changed

+80
-7
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package org.biojava.nbio.structure.test.io;
2+
3+
import static org.junit.Assert.*;
4+
5+
import java.io.IOException;
6+
7+
import org.biojava.nbio.structure.Chain;
8+
import org.biojava.nbio.structure.Group;
9+
import org.biojava.nbio.structure.ResidueNumber;
10+
import org.biojava.nbio.structure.Structure;
11+
import org.biojava.nbio.structure.StructureException;
12+
import org.biojava.nbio.structure.StructureIO;
13+
import org.biojava.nbio.structure.align.util.AtomCache;
14+
import org.biojava.nbio.structure.io.FileParsingParameters;
15+
import org.junit.Test;
16+
17+
/**
18+
* Test for a difficult for a file some sugar molecules covalently bound to residues
19+
* having same residue number for sugar and residue (chain T, residue 201)
20+
* @author Jose Duarte
21+
*
22+
*/
23+
public class Test3th3 {
24+
25+
@Test
26+
public void test3th3() throws StructureException, IOException {
27+
AtomCache cache = new AtomCache();
28+
29+
FileParsingParameters params = cache.getFileParsingParams();
30+
params.setUseInternalChainId(false);
31+
params.setCreateAtomBonds(true);
32+
StructureIO.setAtomCache(cache);
33+
34+
Structure s = StructureIO.getStructure("3th3");
35+
36+
Chain c = s.getChainByPDB("T");
37+
38+
ResidueNumber rn = ResidueNumber.fromString("201");
39+
rn.setChainId("T");
40+
41+
Group g = c.getGroupByPDB(rn);
42+
43+
assertEquals("LYS", g.getPDBName());
44+
45+
int count = 0;
46+
47+
for (Group gr : c.getAtomGroups()) {
48+
if (gr.getResidueNumber().equals(rn)) count++;
49+
}
50+
51+
assertEquals(2, count);
52+
}
53+
54+
55+
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,11 @@ public void addGroup(Group group) {
284284
*/
285285

286286
// this check is to give in this case the entry priority that is an AminoAcid / comes first...
287+
// a good example of same residue number for 2 residues is 3th3, chain T, residue 201 (a LYS and a sugar BGC covalently attached to it) - JD 2016-03-09
287288
if ( pdbResnumMap.containsKey(pdbResnum)) {
289+
290+
logger.warn("Adding residue {}({}) to chain {} but a residue with same residue number is already present: {}({}). Will add only the aminoacid residue (if any) to the lookup, lookups for that residue number won't work properly.",
291+
pdbResnum, group.getPDBName(), getChainID(), groups.get(pdbResnumMap.get(pdbResnum)).getResidueNumber(), groups.get(pdbResnumMap.get(pdbResnum)).getPDBName());
288292
if ( group instanceof AminoAcid)
289293
pdbResnumMap.put(pdbResnum,pos);
290294
} else

biojava-structure/src/main/java/org/biojava/nbio/structure/io/BondMaker.java

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -347,32 +347,46 @@ public void formBondsFromStructConn(List<StructConn> structConn) {
347347
String altLoc2 = "";
348348
if (!conn.getPdbx_ptnr2_label_alt_id().equals("?")) altLoc2 = conn.getPdbx_ptnr2_label_alt_id();
349349

350+
// TODO: when issue 220 is implemented, add robust symmetry handling to allow bonds between symmetry-related molecules.
351+
if (!conn.getPtnr1_symmetry().equals(symop) || !conn.getPtnr2_symmetry().equals(symop) ) {
352+
logger.info("Skipping bond between atoms {}(residue {}{}) and {}(residue {}{}) belonging to different symmetry partners, because it is not supported yet",
353+
atomName1, seqId1, insCode1, atomName2, seqId2, insCode2);
354+
continue;
355+
}
356+
357+
358+
String altLocStr1 = altLoc1.isEmpty()? "" : "(alt loc "+altLoc1+")";
359+
String altLocStr2 = altLoc2.isEmpty()? "" : "(alt loc "+altLoc2+")";
360+
350361
Atom a1 = null;
351362
Atom a2 = null;
352363

353364
try {
354365
a1 = getAtomFromRecord(atomName1, altLoc1, resName1, chainId1, seqId1, insCode1);
355366

356367
} catch (StructureException e) {
357-
String altLocStr1 = altLoc1.isEmpty()? "" : "(alt loc "+altLoc1+")";
368+
358369
logger.warn("Could not find atom specified in struct_conn record: {}{}({}) in chain {}, atom {} {}", seqId1, insCode1, resName1, chainId1, atomName1, altLocStr1);
359370
continue;
360371
}
361372
try {
362373
a2 = getAtomFromRecord(atomName2, altLoc2, resName2, chainId2, seqId2, insCode2);
363374
} catch (StructureException e) {
364-
String altLocStr2 = altLoc2.isEmpty()? "" : "(alt loc "+altLoc2+")";
375+
365376
logger.warn("Could not find atom specified in struct_conn record: {}{}({}) in chain {}, atom {} {}", seqId2, insCode2, resName2, chainId2, atomName2, altLocStr2);
366377
continue;
367378
}
368379

369-
370-
// TODO: when issue 220 is implemented, add robust symmetry handling to allow bonds between symmetry-related molecules.
371-
if (!conn.getPtnr1_symmetry().equals(symop) || !conn.getPtnr2_symmetry().equals(symop) ) {
372-
logger.info("Skipping bond between atoms {}({}) and {}({}) belonging to different symmetry partners, because it is not supported yet",
373-
a1.getPDBserial(), a1.getName(), a2.getPDBserial(), a2.getName());
380+
if (a1==null) {
381+
// we couldn't find the atom, something must be wrong with the file
382+
logger.warn("Could not find atom {} {} from residue {}{}({}) in chain {} to create bond specified in struct_conn", atomName1, altLocStr1, seqId1, insCode1, resName1, chainId1);
374383
continue;
375384
}
385+
if (a2==null) {
386+
// we couldn't find the atom, something must be wrong with the file
387+
logger.warn("Could not find atom {} {} from residue {}{}({}) in chain {} to create bond specified in struct_conn", atomName2, altLocStr2, seqId2, insCode2, resName2, chainId2);
388+
continue;
389+
}
376390

377391
// assuming order 1 for all bonds, no information is provided by struct_conn
378392
Bond bond = new BondImpl(a1, a2, 1);

0 commit comments

Comments
 (0)