Skip to content

Commit ffdc278

Browse files
author
Jacob Litman
committed
Extended the interface-implementation paradigm to Bonds and SSBonds. Renamed chain.getParent() and chain.setParent() to chain.getStructure() and chain.setStructure() to deconflict with other APIs. Added a small check to ensure bonds were not added twice.
1 parent 38c1e33 commit ffdc278

File tree

22 files changed

+671
-366
lines changed

22 files changed

+671
-366
lines changed

biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/MMcifTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,8 @@ protected void comparePDB2cif(String id, String chainId){
226226
private void checkGroups(Group g1, Group g2){
227227

228228
//System.out.print("comparing " +g1 + " " + g2);
229-
String pdbId1 = g1.getChain().getParent().getPDBCode();
230-
String pdbId2 = g1.getChain().getParent().getPDBCode();
229+
String pdbId1 = g1.getChain().getStructure().getPDBCode();
230+
String pdbId2 = g1.getChain().getStructure().getPDBCode();
231231
assertEquals(pdbId1, pdbId2);
232232

233233
assertEquals(g1.getType(),g2.getType());

biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/io/TestLongPdbVsMmCifParsing.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,8 +418,8 @@ private void testSingleChain(Chain cPdb, Chain cCif) {
418418
}
419419

420420

421-
assertNotNull("getParent is null in pdb (chain "+chainId+")",cPdb.getParent());
422-
assertNotNull("getParent is null in cif (chain "+chainId+")",cCif.getParent());
421+
assertNotNull("getParent is null in pdb (chain "+chainId+")",cPdb.getStructure());
422+
assertNotNull("getParent is null in cif (chain "+chainId+")",cCif.getStructure());
423423

424424

425425
assertEquals("failed for getAtomLength (chain "+chainId+"):",cPdb.getAtomLength(),cCif.getAtomLength());

biojava-modfinder/src/main/java/org/biojava/nbio/protmod/structure/ProteinModificationIdentifier.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ public void identify(final List<Chain> chains,
288288
if (residues.isEmpty()) {
289289
String pdbId = "?";
290290
if ( chains.size() > 0) {
291-
Structure struc = chains.get(0).getParent();
291+
Structure struc = chains.get(0).getStructure();
292292
if ( struc != null)
293293
pdbId = struc.getPDBCode();
294294
}

biojava-structure-gui/src/main/java/org/biojava/nbio/structure/align/gui/MultipleAlignmentDisplay.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ public static MultipleAlignmentJmol display(MultipleAlignment multAln)
213213

214214
//Assume all atoms are from the same structure
215215
Structure displayS = atomArrays.get(i)[0].getGroup().
216-
getChain().getParent().clone();
216+
getChain().getStructure().clone();
217217
//Get all the atoms and include ligands and hetatoms
218218
Atom[] rotCA = StructureTools.getRepresentativeAtomArray(displayS);
219219
List<Group> hetatms = StructureTools.getUnalignedGroups(rotCA);

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

Lines changed: 77 additions & 168 deletions
Original file line numberDiff line numberDiff line change
@@ -18,171 +18,80 @@
1818
* http://www.biojava.org/
1919
*
2020
*/
21-
/*
22-
* To change this template, choose Tools | Templates
23-
* and open the template in the editor.
24-
*/
25-
26-
package org.biojava.nbio.structure;
27-
28-
import java.io.Serializable;
29-
30-
/**
31-
* A simple bond -- it stores information about two atoms as well as information
32-
* about its bond order.
33-
*
34-
* @author Jules Jacobsen <jacobsen@ebi.ac.uk>
35-
* @author Ulysse Carion
36-
*/
37-
public class Bond implements Serializable {
38-
39-
private static final long serialVersionUID = 8836120946858134380L;
40-
private Atom atomA;
41-
private Atom atomB;
42-
private int bondOrder;
43-
44-
/**
45-
* Constructs a new bond from a pair of atoms and the bond order of the bond
46-
* between them.
47-
* <p>
48-
* Note that by forming a bond between atoms 'A' and 'B' with this
49-
* constructor, atoms 'A' and 'B' will be updated to have this bond in their
50-
* list of bonds. If you do not want this automatic updating, instead use
51-
* {@link #Bond(Atom, Atom, int, boolean)} with the
52-
* <code>addSelfToAtoms</code> flag set to <code>false</code>.
53-
*
54-
* @param atomA
55-
* one of the atoms in this bond
56-
* @param atomB
57-
* the other atom in this bond
58-
* @param bondOrder
59-
* the bond order of this bond
60-
*/
61-
public Bond(Atom atomA, Atom atomB, int bondOrder) {
62-
this(atomA, atomB, bondOrder, true);
63-
}
64-
65-
/**
66-
* Constructs a new bond from a pair of atoms and the bond order of the bond
67-
* between them.
68-
*
69-
* @param atomA
70-
* one of the atoms in this bond
71-
* @param atomB
72-
* the other atom in this bond
73-
* @param bondOrder
74-
* the bond order of this bond
75-
* @param addSelfToAtoms
76-
* if set to true, this bond, once created, will automatically
77-
* add itself to atomA and atomB's bond lists. (If this argument
78-
* is set to false, the list returned from
79-
* {@link Atom#getBonds()} will not contain this bond.)
80-
*/
81-
public Bond(Atom atomA, Atom atomB, int bondOrder, boolean addSelfToAtoms) {
82-
this.atomA = atomA;
83-
this.atomB = atomB;
84-
this.bondOrder = bondOrder;
85-
86-
if (addSelfToAtoms) {
87-
addSelfToAtoms();
88-
}
89-
}
90-
91-
/**
92-
* Adds this Bond to its atoms bond lists. If this method is not called,
93-
* then the list returned from calling {@link Atom#getBonds()} will not
94-
* include this bond.
95-
* <p>
96-
* If you created your Bond with the constructor
97-
* {@link #Bond(Atom, Atom, int)}, this method has already been called for
98-
* you and should not be called again.
99-
*/
100-
// TODO first check if those bonds haven't been made already
101-
public void addSelfToAtoms() {
102-
atomA.addBond(this);
103-
atomB.addBond(this);
104-
}
105-
106-
/**
107-
* Gets atom 'A' of this bond. There is no meaning to which atom is 'A' and
108-
* which is 'B'; the atoms are labeled 'A' or 'B' based on the order in
109-
* which they are passed to this class's constructor.
110-
*
111-
* @see #getAtomB()
112-
* @return one of the two atoms in this bond
113-
*/
114-
public Atom getAtomA() {
115-
return atomA;
116-
}
117-
118-
/**
119-
* Gets atom 'B' of this bond. There is no meaning to which atom is 'A' and
120-
* which is 'B'; the atoms are labeled 'A' or 'B' based on the order in
121-
* which they are passed to this class's constructor.
122-
*
123-
* @see #getAtomA()
124-
* @return one of the two atoms in this bond
125-
*/
126-
public Atom getAtomB() {
127-
return atomB;
128-
}
129-
130-
/**
131-
* A utility method to get the other atom in a bond, given one of its atoms.
132-
* If the atom passed is one of the atoms in this bond, then this method is
133-
* essentially equivalent to saying
134-
* <code>atom == bond.getAtomA() ? bond.getAtomB() : bond.getAtomA()</code>.
135-
* <p>
136-
* <i>Note:</i> Comparison of atoms in this method is done with
137-
* <code>==</code>, not <code>equals</code>.
138-
*
139-
* @param exclude
140-
* the atom of the bond to not return
141-
* @throws IllegalArgumentException
142-
* if the passed atom is not in this bond
143-
* @return the atom in this bond that was not passed as an argument
144-
*/
145-
public Atom getOther(Atom exclude) {
146-
if (exclude != atomA && exclude != atomB) {
147-
throw new IllegalArgumentException(
148-
"Atom to exclude is not in bond.");
149-
}
150-
151-
if (exclude == atomA) {
152-
return atomB;
153-
} else {
154-
return atomA;
155-
}
156-
}
157-
158-
/**
159-
* Gets the bond order of this bond. A return value of '1' corresponds to a
160-
* single bond, '2' to a double bond, etc.
161-
*
162-
* @return this bond's bond order
163-
*/
164-
public int getBondOrder() {
165-
return bondOrder;
166-
}
167-
168-
/**
169-
* Gets the distance between the two atoms of this bond.
170-
* <p>
171-
* This distance is calculated by {@link Calc#getDistance(Atom, Atom)}, but
172-
* this method will suppress the empty threat of a
173-
* {@link StructureException} that method makes.
174-
*
175-
* @return the distance between the two atoms of this bond.
176-
*/
177-
public double getLength() {
178-
179-
return Calc.getDistance(atomA, atomB);
180-
181-
}
182-
183-
@Override
184-
public String toString() {
185-
return "Bond [atomA=" + atomA + ", atomB=" + atomB + ", bondOrder="
186-
+ bondOrder + "]";
187-
}
188-
}
21+
package org.biojava.nbio.structure;
22+
23+
/**
24+
* A simple bond -- it stores information about two atoms as well as information
25+
* about its bond order.
26+
*
27+
* @author Jules Jacobsen <jacobsen@ebi.ac.uk>
28+
* @author Ulysse Carion
29+
*/
30+
public interface Bond {
31+
/**
32+
* Adds this Bond to its atoms bond lists. If this method is not called,
33+
* then the list returned from calling {@link Atom#getBonds()} will not
34+
* include this bond.
35+
* <p>
36+
* If you created your Bond with the constructor
37+
* {@link #Bond(Atom, Atom, int)}, this method has already been called for
38+
* you and should not be called again.
39+
*/
40+
public void addSelfToAtoms();
41+
42+
/**
43+
* Gets atom 'A' of this bond. There is no meaning to which atom is 'A' and
44+
* which is 'B'; the atoms are labeled 'A' or 'B' based on the order in
45+
* which they are passed to this class's constructor.
46+
*
47+
* @see #getAtomB()
48+
* @return one of the two atoms in this bond
49+
*/
50+
public Atom getAtomA();
51+
52+
/**
53+
* Gets atom 'B' of this bond. There is no meaning to which atom is 'A' and
54+
* which is 'B'; the atoms are labeled 'A' or 'B' based on the order in
55+
* which they are passed to this class's constructor.
56+
*
57+
* @see #getAtomA()
58+
* @return one of the two atoms in this bond
59+
*/
60+
public Atom getAtomB();
61+
62+
/**
63+
* A utility method to get the other atom in a bond, given one of its atoms.
64+
* If the atom passed is one of the atoms in this bond, then this method is
65+
* essentially equivalent to saying
66+
* <code>atom == bond.getAtomA() ? bond.getAtomB() : bond.getAtomA()</code>.
67+
* <p>
68+
* <i>Note:</i> Comparison of atoms in this method is done with
69+
* <code>==</code>, not <code>equals</code>.
70+
*
71+
* @param exclude
72+
* the atom of the bond to not return
73+
* @throws IllegalArgumentException
74+
* if the passed atom is not in this bond
75+
* @return the atom in this bond that was not passed as an argument
76+
*/
77+
public Atom getOther(Atom exclude);
78+
79+
/**
80+
* Gets the bond order of this bond. A return value of '1' corresponds to a
81+
* single bond, '2' to a double bond, etc.
82+
*
83+
* @return this bond's bond order
84+
*/
85+
public int getBondOrder();
86+
87+
/**
88+
* Gets the distance between the two atoms of this bond.
89+
* <p>
90+
* This distance is calculated by {@link Calc#getDistance(Atom, Atom)}, but
91+
* this method will suppress the empty threat of a
92+
* {@link StructureException} that method makes.
93+
*
94+
* @return the distance between the two atoms of this bond.
95+
*/
96+
public double getLength();
97+
}

0 commit comments

Comments
 (0)