Skip to content

Commit 7180aeb

Browse files
committed
Consolidating on a single method call for all alt loc bond business
1 parent b889140 commit 7180aeb

1 file changed

Lines changed: 57 additions & 70 deletions

File tree

  • biojava-structure/src/main/java/org/biojava/nbio/structure/io

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

Lines changed: 57 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -159,14 +159,48 @@ private void formNucleotideBonds() {
159159
}
160160
}
161161

162+
private void formIntraResidueBonds() {
163+
for (int modelInd=0; modelInd<structure.nrModels(); modelInd++){
164+
for (Chain chain : structure.getChains(modelInd)) {
165+
List<Group> groups = chain.getAtomGroups();
166+
for (Group mainGroup : groups) {
167+
// atoms with no residue number don't have atom information
168+
if (mainGroup.getResidueNumber() == null) {
169+
continue;
170+
}
171+
// Now add support for altLocGroup
172+
List<Group> totList = new ArrayList<Group>();
173+
totList.add(mainGroup);
174+
totList.addAll(mainGroup.getAltLocs());
175+
176+
// Now iterate through this list
177+
for(Group group : totList){
178+
179+
ChemComp aminoChemComp = ChemCompGroupFactory.getChemComp(group.getPDBName());
180+
logger.debug("chemcomp for residue {}-{} has {} atoms and {} bonds",
181+
group.getPDBName(), group.getResidueNumber(), aminoChemComp.getAtoms().size(), aminoChemComp.getBonds().size());
182+
183+
for (ChemCompBond chemCompBond : aminoChemComp.getBonds()) {
184+
// note we don't check distance to make this call not too expensive
185+
formBondAltlocAware(group, chemCompBond.getAtom_id_1(),
186+
group, chemCompBond.getAtom_id_2(), -1, chemCompBond.getNumericalBondOrder());
187+
}
188+
}
189+
}
190+
}
191+
192+
}
193+
}
194+
162195
/**
163196
* Form bond between atoms of the given names and groups, respecting alt loc rules to form bonds:
164-
* no bonds between differently named alt locs (not default) and all bonds for default alt loc to named alt loc.
197+
* no bonds between differently named alt locs (that are not the default alt loc '.')
198+
* and multiple bonds for default alt loc to named alt loc.
165199
* @param g1 first group
166200
* @param name1 name of atom in first group
167201
* @param g2 second group
168202
* @param name2 name of atom in second group
169-
* @param maxAllowedLength max length, if atoms distance above this length no bond will be added
203+
* @param maxAllowedLength max length, if atoms distance above this length no bond will be added. If negative no check on distance is performed.
170204
* @param bondOrder the bond order to be set in the created bond(s)
171205
*/
172206
private void formBondAltlocAware(Group g1, String name1, Group g2, String name2, double maxAllowedLength, int bondOrder) {
@@ -188,8 +222,20 @@ private void formBondAltlocAware(Group g1, String name1, Group g2, String name2,
188222
a1.toString(), a1.getAltLoc(), a2.toString(), a2.getAltLoc());
189223
continue;
190224
}
191-
if (Calc.getDistance(a1, a2) < maxAllowedLength) {
225+
if (maxAllowedLength<0) {
226+
// negative maxAllowedLength means we don't check distance and always add bond
227+
logger.debug("Forming bond between atoms {}-{} and {}-{} with bond order {}",
228+
a1.getPDBserial(), a1.getName(), a2.getPDBserial(), a2.getName(), bondOrder);
192229
new BondImpl(a1, a2, bondOrder);
230+
} else {
231+
if (Calc.getDistance(a1, a2) < maxAllowedLength) {
232+
logger.debug("Forming bond between atoms {}-{} and {}-{} with bond order {}. Distance is below {}",
233+
a1.getPDBserial(), a1.getName(), a2.getPDBserial(), a2.getName(), bondOrder, maxAllowedLength);
234+
new BondImpl(a1, a2, bondOrder);
235+
} else {
236+
logger.debug("Not forming bond between atoms {}-{} and {}-{} with bond order {}, because distance is above {}",
237+
a1.getPDBserial(), a1.getName(), a2.getPDBserial(), a2.getName(), bondOrder, maxAllowedLength);
238+
}
193239
}
194240
}
195241
}
@@ -208,77 +254,18 @@ private List<Atom> getAtoms(Group g, String name) {
208254
groupsWithAltLocs.addAll(g.getAltLocs());
209255
for (Group group : groupsWithAltLocs) {
210256
Atom a = group.getAtom(name);
211-
if (a!=null)
212-
atoms.add(a);
213-
}
214-
return atoms;
215-
}
216-
217-
private void formIntraResidueBonds() {
218-
for (int modelInd=0; modelInd<structure.nrModels(); modelInd++){
219-
for (Chain chain : structure.getChains(modelInd)) {
220-
List<Group> groups = chain.getAtomGroups();
221-
for (Group mainGroup : groups) {
222-
// atoms with no residue number don't have atom information
223-
if (mainGroup.getResidueNumber() == null) {
224-
continue;
225-
}
226-
// Now add support for altLocGroup
227-
List<Group> totList = new ArrayList<Group>();
228-
totList.add(mainGroup);
229-
totList.addAll(mainGroup.getAltLocs());
230-
231-
// Now iterate through this list
232-
for(Group group : totList){
233-
234-
ChemComp aminoChemComp = ChemCompGroupFactory.getChemComp(group.getPDBName());
235-
logger.debug("chemcomp for residue {}-{} has {} atoms and {} bonds",
236-
group.getPDBName(), group.getResidueNumber(), aminoChemComp.getAtoms().size(), aminoChemComp.getBonds().size());
237-
238-
for (ChemCompBond chemCompBond : aminoChemComp.getBonds()) {
239-
Atom a = getAtom(chemCompBond.getAtom_id_1(), group);
240-
Atom b = getAtom(chemCompBond.getAtom_id_2(), group);
241-
if ( a != null && b != null){
242-
243-
// if they are different altlocs (when different from the '.' case) there must be no bond
244-
if (a.getAltLoc() != null && b.getAltLoc()!=null &&
245-
a.getAltLoc()!=' ' && b.getAltLoc()!=' ' &&
246-
a.getAltLoc() != b.getAltLoc()) {
247-
logger.debug("Skipping bond between atoms with differently named alt locs {} (altLoc '{}') -- {} (altLoc '{}')",
248-
a.toString(), a.getAltLoc(), b.toString(), b.getAltLoc());
249-
continue;
250-
}
251-
252-
int bondOrder = chemCompBond.getNumericalBondOrder();
253-
logger.debug("Forming bond between atoms {}-{} and {}-{} with bond order {}",
254-
a.getPDBserial(), a.getName(), b.getPDBserial(), b.getName(), bondOrder);
255-
new BondImpl(a, b, bondOrder);
256-
}
257-
// Else: Some of the atoms were missing. That's fine, there's
258-
// nothing to do in this case.
259-
260-
}
261-
}
262-
}
263-
}
264-
265-
}
266-
}
267-
268-
private Atom getAtom(String atomId, Group group) {
269-
Atom a = group.getAtom(atomId);
270-
271-
// Check for deuteration
272-
if(a==null && atomId.startsWith("H")) {
273-
a = group.getAtom(atomId.replaceFirst("H", "D"));
274-
// Check it is actually deuterated
275-
if(a!=null){
276-
if(!a.getElement().equals(Element.D)){
257+
// Check for deuteration
258+
if (a==null && name.startsWith("H")) {
259+
a = group.getAtom(name.replaceFirst("H", "D"));
260+
// Check it is actually deuterated
261+
if (a!=null && !a.getElement().equals(Element.D)){
277262
a=null;
278263
}
279264
}
265+
if (a!=null)
266+
atoms.add(a);
280267
}
281-
return a;
268+
return atoms;
282269
}
283270

284271
private void trimBondLists() {

0 commit comments

Comments
 (0)