Skip to content

Commit 761799b

Browse files
committed
Fixing issue: no bonds between different altloc atoms
1 parent f232c0e commit 761799b

File tree

4 files changed

+115
-45
lines changed

4 files changed

+115
-45
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ public void setBonds(List<Bond> bonds) {
309309
@Override
310310
public void addBond(Bond bond) {
311311
if (bonds==null) {
312-
bonds = new ArrayList<Bond>(BONDS_INITIAL_CAPACITY);
312+
bonds = new ArrayList<>(BONDS_INITIAL_CAPACITY);
313313
}
314314
bonds.add(bond);
315315
}

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

Lines changed: 11 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public class HetatomImpl implements Group {
7777
* Behaviors for how to balance memory vs. performance.
7878
* @author Andreas Prlic
7979
*/
80-
public static enum PerformanceBehavior {
80+
public enum PerformanceBehavior {
8181

8282
/** use a built-in HashMap for faster access to memory, at the price of more memory consumption */
8383
BETTER_PERFORMANCE_MORE_MEMORY,
@@ -87,7 +87,7 @@ public static enum PerformanceBehavior {
8787

8888
}
8989

90-
public static PerformanceBehavior performanceBehavior=PerformanceBehavior.LESS_MEMORY_SLOWER_PERFORMANCE;
90+
private static PerformanceBehavior performanceBehavior=PerformanceBehavior.LESS_MEMORY_SLOWER_PERFORMANCE;
9191

9292
private Map<String,Atom> atomNameLookup;
9393

@@ -105,42 +105,28 @@ public HetatomImpl() {
105105
pdb_name = null ;
106106

107107
residueNumber = null;
108-
atoms = new ArrayList<Atom>();
109-
properties = new HashMap<String,Object>();
108+
atoms = new ArrayList<>();
109+
properties = new HashMap<>();
110110
parent = null;
111111
chemComp = null;
112112
altLocs = null;
113113

114114
if ( performanceBehavior == PerformanceBehavior.BETTER_PERFORMANCE_MORE_MEMORY)
115-
atomNameLookup = new HashMap<String,Atom>();
115+
atomNameLookup = new HashMap<>();
116116
else
117117
atomNameLookup = null;
118118
}
119119

120-
121-
/**
122-
* returns true or false, depending if this group has 3D coordinates or not.
123-
* @return true if Group has 3D coordinates
124-
*/
125120
@Override
126121
public boolean has3D() {
127122
return pdb_flag;
128123
}
129124

130-
/** flag if group has 3D data.
131-
*
132-
* @param flag true to set flag that this Group has 3D coordinates
133-
*/
134125
@Override
135126
public void setPDBFlag(boolean flag){
136127
pdb_flag = flag ;
137128
}
138129

139-
/** Set three character name of Group .
140-
*
141-
* @param s a String specifying the PDBName value
142-
* @see #getPDBName
143-
*/
144130
@Override
145131
public void setPDBName(String s) {
146132
// hetatoms can have pdb_name length < 3. e.g. CU (see 1a4a position 1200 )
@@ -152,12 +138,6 @@ public void setPDBName(String s) {
152138

153139
}
154140

155-
/**
156-
* Returns the PDBName.
157-
*
158-
* @return a String representing the PDBName value
159-
* @see #setPDBName
160-
*/
161141
@Override
162142
public String getPDBName() { return pdb_name;}
163143

@@ -187,12 +167,8 @@ public void addAtom(Atom atom){
187167
logger.warn("An atom with name " + atom.getName() + " " + altLocStr + " is already present in group: " + this.toString() + ". The atom with serial " + atom.getPDBserial() + " will be ignored in look-ups.");
188168
}
189169
}
190-
};
191-
170+
}
192171

193-
/** remove all atoms
194-
*
195-
*/
196172
@Override
197173
public void clearAtoms() {
198174
atoms.clear();
@@ -245,8 +221,7 @@ public Atom getAtom(String name) {
245221
if ( atomNameLookup != null)
246222
return atomNameLookup.get(name);
247223
else {
248-
/** This is the performance penalty we pay for NOT using the atomnameLookup in PerformanceBehaviour.LESS_MEMORY_SLOWER_PERFORMANCE
249-
*/
224+
// This is the performance penalty we pay for NOT using the atomnameLookup in PerformanceBehaviour.LESS_MEMORY_SLOWER_PERFORMANCE
250225
for (Atom a : atoms) {
251226
if (a.getName().equals(name)) {
252227
return a;
@@ -588,7 +563,7 @@ public boolean hasAltLoc() {
588563
@Override
589564
public List<Group> getAltLocs() {
590565
if ( altLocs == null)
591-
return new ArrayList<Group>();
566+
return new ArrayList<>();
592567
return altLocs;
593568
}
594569

@@ -629,7 +604,7 @@ public Group getAltLocGroup(Character altLoc) {
629604
@Override
630605
public void addAltLoc(Group group) {
631606
if ( altLocs == null) {
632-
altLocs = new ArrayList<Group>();
607+
altLocs = new ArrayList<>();
633608
}
634609
altLocs.add(group);
635610

@@ -663,10 +638,10 @@ public void trimToSize(){
663638
}
664639

665640
// now let's fit the hashmaps to size
666-
properties = new HashMap<String, Object>(properties);
641+
properties = new HashMap<>(properties);
667642

668643
if ( atomNameLookup != null)
669-
atomNameLookup = new HashMap<String,Atom>(atomNameLookup);
644+
atomNameLookup = new HashMap<>(atomNameLookup);
670645

671646
}
672647

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,7 @@ private void formIntraResidueBonds() {
200200
// Now add support for altLocGroup
201201
List<Group> totList = new ArrayList<Group>();
202202
totList.add(mainGroup);
203-
for(Group altLoc: mainGroup.getAltLocs()){
204-
totList.add(altLoc);
205-
}
206-
203+
totList.addAll(mainGroup.getAltLocs());
207204

208205
// Now iterate through this list
209206
for(Group group : totList){
@@ -216,15 +213,19 @@ private void formIntraResidueBonds() {
216213
Atom a = getAtom(chemCompBond.getAtom_id_1(), group);
217214
Atom b = getAtom(chemCompBond.getAtom_id_2(), group);
218215
if ( a != null && b != null){
216+
217+
// if they are different altlocs there must be no bond
218+
if (a.getAltLoc() != b.getAltLoc())
219+
continue;
220+
219221
int bondOrder = chemCompBond.getNumericalBondOrder();
220222
logger.debug("Forming bond between atoms {}-{} and {}-{} with bond order {}",
221223
a.getPDBserial(), a.getName(), b.getPDBserial(), b.getName(), bondOrder);
222224
new BondImpl(a, b, bondOrder);
223225
}
224-
else{
225-
// Some of the atoms were missing. That's fine, there's
226-
// nothing to do in this case.
227-
}
226+
// Else: Some of the atoms were missing. That's fine, there's
227+
// nothing to do in this case.
228+
228229
}
229230
}
230231
}
@@ -235,6 +236,7 @@ private void formIntraResidueBonds() {
235236

236237
private Atom getAtom(String atomId, Group group) {
237238
Atom a = group.getAtom(atomId);
239+
238240
// Check for deuteration
239241
if(a==null && atomId.startsWith("H")) {
240242
a = group.getAtom(atomId.replaceFirst("H", "D"));

biojava-structure/src/test/java/org/biojava/nbio/structure/TestAltLocs.java

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,4 +754,97 @@ public void testMmcifConversionAllAltlocs() throws IOException {
754754

755755
}
756756

757+
/**
758+
* Test that bonds between alt locs link atoms with same altloc codes
759+
* https://github.com/rcsb/mmtf/issues/44
760+
*/
761+
@Test
762+
public void testBondsBetweenAltlocs() throws IOException {
763+
String mmcifData =
764+
"data_test\n" +
765+
"loop_\n" +
766+
"_atom_site.group_PDB \n" +
767+
"_atom_site.id \n" +
768+
"_atom_site.type_symbol \n" +
769+
"_atom_site.label_atom_id \n" +
770+
"_atom_site.label_alt_id \n" +
771+
"_atom_site.label_comp_id \n" +
772+
"_atom_site.label_asym_id \n" +
773+
"_atom_site.label_entity_id \n" +
774+
"_atom_site.label_seq_id \n" +
775+
"_atom_site.pdbx_PDB_ins_code \n" +
776+
"_atom_site.Cartn_x \n" +
777+
"_atom_site.Cartn_y \n" +
778+
"_atom_site.Cartn_z \n" +
779+
"_atom_site.occupancy \n" +
780+
"_atom_site.B_iso_or_equiv \n" +
781+
"_atom_site.pdbx_formal_charge \n" +
782+
"_atom_site.auth_seq_id \n" +
783+
"_atom_site.auth_comp_id \n" +
784+
"_atom_site.auth_asym_id \n" +
785+
"_atom_site.auth_atom_id \n" +
786+
"_atom_site.pdbx_PDB_model_num \n" +
787+
"ATOM 1405 N N A MET A 1 86 ? 10.748 -17.610 -6.975 0.47 16.12 ? 104 MET A N 1 \n" +
788+
"ATOM 1406 N N B MET A 1 86 ? 10.802 -17.694 -6.986 0.53 17.92 ? 104 MET A N 1 \n" +
789+
"ATOM 1407 C CA A MET A 1 86 ? 11.189 -17.392 -5.610 0.47 15.78 ? 104 MET A CA 1 \n" +
790+
"ATOM 1408 C CA B MET A 1 86 ? 11.033 -17.368 -5.587 0.53 18.29 ? 104 MET A CA 1 \n" +
791+
"ATOM 1409 C C A MET A 1 86 ? 10.952 -18.663 -4.810 0.47 15.91 ? 104 MET A C 1 \n" +
792+
"ATOM 1410 C C B MET A 1 86 ? 10.882 -18.643 -4.767 0.53 17.40 ? 104 MET A C 1 \n" +
793+
"ATOM 1411 O O A MET A 1 86 ? 10.120 -19.504 -5.154 0.47 18.21 ? 104 MET A O 1 \n" +
794+
"ATOM 1412 O O B MET A 1 86 ? 10.018 -19.474 -5.052 0.53 20.02 ? 104 MET A O 1 \n" +
795+
"ATOM 1413 C CB A MET A 1 86 ? 10.477 -16.204 -4.933 0.47 17.14 ? 104 MET A CB 1 \n" +
796+
"ATOM 1414 C CB B MET A 1 86 ? 10.001 -16.336 -5.111 0.53 18.92 ? 104 MET A CB 1 \n" +
797+
"ATOM 1415 C CG A MET A 1 86 ? 9.019 -16.476 -4.619 0.47 20.01 ? 104 MET A CG 1 \n" +
798+
"ATOM 1416 C CG B MET A 1 86 ? 10.030 -16.038 -3.634 0.53 19.12 ? 104 MET A CG 1 \n" +
799+
"ATOM 1417 S SD A MET A 1 86 ? 8.207 -15.088 -3.838 0.47 22.06 ? 104 MET A SD 1 \n" +
800+
"ATOM 1418 S SD B MET A 1 86 ? 8.874 -14.724 -3.205 0.53 20.16 ? 104 MET A SD 1 \n" +
801+
"ATOM 1419 C CE A MET A 1 86 ? 9.151 -14.973 -2.340 0.47 25.15 ? 104 MET A CE 1 \n" +
802+
"ATOM 1420 C CE B MET A 1 86 ? 7.269 -15.536 -3.380 0.53 20.38 ? 104 MET A CE 1 \n" +
803+
"ATOM 1421 H H A MET A 1 86 ? 9.931 -18.207 -7.055 0.47 15.58 ? 104 MET A H 1 \n" +
804+
"ATOM 1422 H H B MET A 1 86 ? 10.144 -18.461 -7.109 0.53 18.91 ? 104 MET A H 1 \n" +
805+
"ATOM 1423 H HA A MET A 1 86 ? 12.256 -17.182 -5.644 0.47 15.14 ? 104 MET A HA 1 \n" +
806+
"ATOM 1424 H HA B MET A 1 86 ? 12.033 -16.953 -5.465 0.53 19.55 ? 104 MET A HA 1 \n" +
807+
"ATOM 1425 H HB2 A MET A 1 86 ? 10.986 -15.920 -4.008 0.47 17.68 ? 104 MET A HB2 1 \n" +
808+
"ATOM 1426 H HB3 A MET A 1 86 ? 10.484 -15.364 -5.622 0.47 17.68 ? 104 MET A HB3 1 \n" +
809+
"ATOM 1427 H HB3 B MET A 1 86 ? 9.001 -16.676 -5.398 0.53 20.49 ? 104 MET A HB3 1 \n" +
810+
"ATOM 1428 H HG2 A MET A 1 86 ? 8.490 -16.704 -5.546 0.47 20.93 ? 104 MET A HG2 1 \n" +
811+
"ATOM 1429 H HG3 A MET A 1 86 ? 8.956 -17.315 -3.927 0.47 20.93 ? 104 MET A HG3 1 \n" +
812+
"ATOM 1430 H HE2 A MET A 1 86 ? 9.861 -14.153 -2.440 0.47 27.31 ? 104 MET A HE2 1 \n" +
813+
"ATOM 1431 H HE2 B MET A 1 86 ? 7.346 -16.554 -2.998 0.53 23.03 ? 104 MET A HE2 1 \n" +
814+
"ATOM 1432 H HE3 B MET A 1 86 ? 6.996 -15.566 -4.437 0.53 23.03 ? 104 MET A HE3 1 ";
815+
816+
SimpleMMcifParser parser = new SimpleMMcifParser();
817+
SimpleMMcifConsumer consumer = new SimpleMMcifConsumer();
818+
parser.addMMcifConsumer(consumer);
819+
820+
FileParsingParameters params = new FileParsingParameters();
821+
params.setCreateAtomBonds(true);
822+
consumer.setFileParsingParameters(params);
823+
824+
BufferedReader buf = new BufferedReader(new StringReader(mmcifData));
825+
parser.parse(buf);
826+
buf.close();
827+
828+
Structure s = consumer.getStructure();
829+
Chain c = s.getPolyChains().get(0);
830+
assertEquals(1, c.getAtomGroups().size());
831+
832+
Group g = c.getAtomGroup(0);
833+
834+
assertEquals(1, g.getAltLocs().size());
835+
836+
for (Atom a : g.getAtoms()) {
837+
for (Bond b : a.getBonds()) {
838+
// if (b.getAtomA().getAltLoc() != b.getAtomB().getAltLoc()) {
839+
// System.out.println(
840+
// b.getAtomA().toString() + ":" + b.getAtomA().getAltLoc() + " --- " +
841+
// b.getAtomB().toString() + ":" + b.getAtomB().getAltLoc());
842+
// }
843+
assertEquals(b.getAtomA().toString() + " --- " + b.getAtomB().toString(),
844+
b.getAtomA().getAltLoc(), b.getAtomB().getAltLoc());
845+
}
846+
}
847+
848+
}
849+
757850
}

0 commit comments

Comments
 (0)