Skip to content

Commit 6369854

Browse files
committed
Some updates for when dealing with internal and not public chain ids as the primary id
1 parent a7ce910 commit 6369854

2 files changed

Lines changed: 53 additions & 37 deletions

File tree

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

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@
5151
*
5252
*/
5353
public class BondMaker {
54-
55-
54+
55+
5656
private static final Logger logger = LoggerFactory.getLogger(BondMaker.class);
57-
57+
5858
/**
5959
* The types of bonds that are read from struct_conn (type specified in field conn_type_id)
6060
*/
@@ -68,8 +68,8 @@ public class BondMaker {
6868
BOND_TYPES_TO_PARSE.add("covale_sugar");
6969
BOND_TYPES_TO_PARSE.add("modres");
7070
}
71-
72-
71+
72+
7373
/**
7474
* Maximum peptide (C - N) bond length considered for bond formation
7575
*/
@@ -249,7 +249,7 @@ public void formDisulfideBonds(List<SSBondImpl> disulfideBonds) {
249249
}
250250
structure.setSSBonds(bonds);
251251
}
252-
252+
253253
private Bond formDisulfideBond(SSBondImpl disulfideBond) {
254254
try {
255255
Atom a = getAtomFromRecord("SG", "", "CYS",
@@ -258,25 +258,25 @@ private Bond formDisulfideBond(SSBondImpl disulfideBond) {
258258
Atom b = getAtomFromRecord("SG", "", "CYS",
259259
disulfideBond.getChainID2(), disulfideBond.getResnum2(),
260260
disulfideBond.getInsCode2());
261-
261+
262262
Bond ssbond = new BondImpl(a, b, 1);
263-
263+
264264
structure.addSSBond(ssbond);
265-
265+
266266
return ssbond;
267-
267+
268268
} catch (StructureException e) {
269269
// Note, in Calpha only mode the CYS SG's are not present.
270270
if (! params.isParseCAOnly()) {
271271
logger.warn("Could not find atoms specified in SSBOND record: {}",disulfideBond.toString());
272272
} else {
273273
logger.debug("Could not find atoms specified in SSBOND record while parsing in parseCAonly mode.");
274274
}
275-
275+
276276
return null;
277277
}
278278
}
279-
279+
280280
/**
281281
* Creates bond objects from a LinkRecord as parsed from a PDB file
282282
* @param linkRecord
@@ -308,28 +308,34 @@ public void formLinkRecordBond(LinkRecord linkRecord) {
308308
} else {
309309
logger.debug("Could not find atoms specified in LINK record while parsing in parseCAonly mode.");
310310
}
311-
311+
312312
}
313313
}
314-
314+
315315
public void formBondsFromStructConn(List<StructConn> structConn) {
316-
316+
317317
final String symop = "1_555"; // For now - accept bonds within origin asymmetric unit.
318-
318+
319319
List<Bond> ssbonds = new ArrayList<>();
320-
320+
321321
for (StructConn conn : structConn) {
322-
322+
323323
if (!BOND_TYPES_TO_PARSE.contains(conn.getConn_type_id())) continue;
324-
325-
String chainId1 = conn.getPtnr1_auth_asym_id();
326-
String chainId2 = conn.getPtnr2_auth_asym_id();
327-
324+
String chainId1;
325+
String chainId2;
326+
if(params.isUseInternalChainId()){
327+
chainId1 = conn.getPtnr1_label_asym_id();
328+
chainId2 = conn.getPtnr2_label_asym_id();
329+
}
330+
else{
331+
chainId1 = conn.getPtnr1_auth_asym_id();
332+
chainId2 = conn.getPtnr2_auth_asym_id();
333+
}
328334
String insCode1 = "";
329335
if (!conn.getPdbx_ptnr1_PDB_ins_code().equals("?")) insCode1 = conn.getPdbx_ptnr1_PDB_ins_code();
330336
String insCode2 = "";
331337
if (!conn.getPdbx_ptnr2_PDB_ins_code().equals("?")) insCode2 = conn.getPdbx_ptnr2_PDB_ins_code();
332-
338+
333339
String seqId1 = conn.getPtnr1_auth_seq_id();
334340
String seqId2 = conn.getPtnr2_auth_seq_id();
335341
String resName1 = conn.getPtnr1_label_comp_id();
@@ -340,13 +346,13 @@ public void formBondsFromStructConn(List<StructConn> structConn) {
340346
if (!conn.getPdbx_ptnr1_label_alt_id().equals("?")) altLoc1 = conn.getPdbx_ptnr1_label_alt_id();
341347
String altLoc2 = "";
342348
if (!conn.getPdbx_ptnr2_label_alt_id().equals("?")) altLoc2 = conn.getPdbx_ptnr2_label_alt_id();
343-
349+
344350
Atom a1 = null;
345351
Atom a2 = null;
346-
352+
347353
try {
348354
a1 = getAtomFromRecord(atomName1, altLoc1, resName1, chainId1, seqId1, insCode1);
349-
355+
350356
} catch (StructureException e) {
351357
String altLocStr1 = altLoc1.isEmpty()? "" : "(alt loc "+altLoc1+")";
352358
logger.warn("Could not find atom specified in struct_conn record: {}{}({}) in chain {}, atom {} {}", seqId1, insCode1, resName1, chainId1, atomName1, altLocStr1);
@@ -359,7 +365,7 @@ public void formBondsFromStructConn(List<StructConn> structConn) {
359365
logger.warn("Could not find atom specified in struct_conn record: {}{}({}) in chain {}, atom {} {}", seqId2, insCode2, resName2, chainId2, atomName2, altLocStr2);
360366
continue;
361367
}
362-
368+
363369

364370
// TODO: when issue 220 is implemented, add robust symmetry handling to allow bonds between symmetry-related molecules.
365371
if (!conn.getPtnr1_symmetry().equals(symop) || !conn.getPtnr2_symmetry().equals(symop) ) {
@@ -374,32 +380,31 @@ public void formBondsFromStructConn(List<StructConn> structConn) {
374380
if (conn.getConn_type_id().equals("disulf")) {
375381
ssbonds.add(bond);
376382
}
377-
383+
378384
}
379-
385+
380386
// only for ss bonds we add a specific map in structure, all the rests are linked only from Atom.getBonds
381387
structure.setSSBonds(ssbonds);
382388
}
383-
389+
384390
private Atom getAtomFromRecord(String name, String altLoc, String resName, String chainID, String resSeq, String iCode)
385391
throws StructureException {
386-
392+
387393
if (iCode==null || iCode.isEmpty()) {
388394
iCode = " "; // an insertion code of ' ' is ignored
389395
}
390-
391396
Chain chain = structure.getChainByPDB(chainID);
392397
ResidueNumber resNum = new ResidueNumber(chainID, Integer.parseInt(resSeq), iCode.charAt(0));
393398
Group group = chain.getGroupByPDB(resNum);
394-
399+
395400
Group g = group;
396401
// there is an alternate location
397402
if (!altLoc.isEmpty()) {
398403
g = group.getAltLocGroup(altLoc.charAt(0));
399404
if (g==null)
400405
throw new StructureException("Could not find altLoc code "+altLoc+" in group "+resSeq+iCode+" of chain "+ chainID);
401406
}
402-
407+
403408
return g.getAtom(name);
404409
}
405410
}

biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/SimpleMMcifConsumer.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -931,8 +931,13 @@ private void linkCompounds() {
931931

932932
for (int i =0; i< structure.nrModels() ; i++){
933933
for (Chain chain : structure.getModel(i)) {
934-
935-
String entityId = asymId2entityId.get(chain.getInternalChainID());
934+
String entityId;
935+
if( params.isUseInternalChainId()){
936+
entityId = asymId2entityId.get(chain.getChainID());
937+
}
938+
else{
939+
entityId = asymId2entityId.get(chain.getInternalChainID());
940+
}
936941
if (entityId==null) {
937942
// this can happen for instance if the cif file didn't have _struct_asym category at all
938943
// and thus we have no asymId2entityId mapping at all
@@ -1896,7 +1901,13 @@ private void addSites() {
18961901
String comp_id = siteGen.getLabel_comp_id(); // PDBName
18971902
// Assumption: the author chain ID and residue number for the site is consistent with the original
18981903
// author chain id and residue numbers.
1899-
String chain_id = siteGen.getAuth_asym_id(); // ChainID
1904+
String chain_id;
1905+
if (params.isUseInternalChainId()){
1906+
chain_id = siteGen.getLabel_asym_id();
1907+
}
1908+
else {
1909+
chain_id = siteGen.getAuth_asym_id(); // ChainID
1910+
}
19001911
String auth_seq_id = siteGen.getAuth_seq_id(); // Res num
19011912

19021913
String insCode = siteGen.getPdbx_auth_ins_code();

0 commit comments

Comments
 (0)