Skip to content

Commit 5b6608d

Browse files
committed
Changed documentation to show how to do Calpha contact calculations.
1 parent 4d9b044 commit 5b6608d

6 files changed

Lines changed: 76 additions & 32 deletions

File tree

biojava3-structure/src/main/java/demo/DemoContacts.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class DemoContacts {
2020

2121
public static void main(String[] args) throws IOException, StructureException {
2222

23-
String pdbCode = "1oew";
23+
String pdbCode = "1smt";
2424

2525
demoContacts(pdbCode);
2626
}
@@ -37,7 +37,7 @@ private static void demoContacts(String pdbCode) throws IOException, StructureEx
3737
Chain chain = structure.getChainByPDB("A");
3838

3939

40-
String[] atoms = {"CA"};
40+
String[] atoms = {" CA "};
4141
AtomContactSet contacts = StructureTools.getAtomsInContact(chain, atoms, 8.0);
4242

4343
System.out.println("Contacting residues (on CA atoms)");
@@ -71,12 +71,9 @@ private static void demoContacts(String pdbCode) throws IOException, StructureEx
7171
System.out.println("Total number of residue contacts: "+groupContacts.size());
7272

7373

74-
System.exit(0);
75-
76-
//String[] atoms = {"CA"};
7774
contacts = StructureTools.getAtomsInContact(structure.getChain(0),structure.getChain(1),5.5);
7875

79-
System.out.println("Contacting residues between 2 first chains (on CA atoms)");
76+
System.out.println("Contacting residues between 2 first chains (all non-H non-hetatoms)");
8077

8178
for (AtomContact contact:contacts) {
8279
Atom atom1 = contact.getPair().getFirst();

biojava3-structure/src/main/java/org/biojava/bio/structure/StructureTools.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -992,7 +992,8 @@ public static final Group getGroupByPDBResidueNumber(Structure struc,
992992
* Returns the set of intra-chain contacts for the given chain for given atom names, i.e. the contact map.
993993
* Uses a geometric hashing algorithm that speeds up the calculation without need of full distance matrix.
994994
* @param chain
995-
* @param atomNames the array with atom names to be used, if null all non-H atoms will be used
995+
* @param atomNames the array with atom names to be used. For Calphas use {" CA "},
996+
* if null all non-H atoms of non-hetatoms will be used
996997
* @param cutoff
997998
* @return
998999
*/
@@ -1012,7 +1013,7 @@ public static AtomContactSet getAtomsInContact(Chain chain, String[] atomNames,
10121013
}
10131014

10141015
/**
1015-
* Returns the set of intra-chain contacts for the given chain for all non-H atoms, i.e. the contact map.
1016+
* Returns the set of intra-chain contacts for the given chain for all non-H atoms of non-hetatoms, i.e. the contact map.
10161017
* Uses a geometric hashing algorithm that speeds up the calculation without need of full distance matrix.
10171018
* @param chain
10181019
* @param cutoff
@@ -1027,7 +1028,8 @@ public static AtomContactSet getAtomsInContact(Chain chain, double cutoff) {
10271028
* Uses a geometric hashing algorithm that speeds up the calculation without need of full distance matrix.
10281029
* @param chain1
10291030
* @param chain2
1030-
* @param atomNames the array with atom names to be used, if null all non-H atoms will be used
1031+
* @param atomNames the array with atom names to be used. For Calphas use {" CA "},
1032+
* if null all non-H atoms of non-hetatoms will be used
10311033
* @param cutoff
10321034
* @return
10331035
*/
@@ -1048,7 +1050,7 @@ public static AtomContactSet getAtomsInContact(Chain chain1, Chain chain2, Strin
10481050
}
10491051

10501052
/**
1051-
* Returns the set of inter-chain contacts between the two given chains for all non-H atoms.
1053+
* Returns the set of inter-chain contacts between the two given chains for all non-H atoms of non-hetatoms.
10521054
* Uses a geometric hashing algorithm that speeds up the calculation without need of full distance matrix.
10531055
* @param chain1
10541056
* @param chain2

biojava3-structure/src/main/java/org/biojava/bio/structure/contact/AtomContactSet.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@
66

77
import org.biojava.bio.structure.Atom;
88

9-
9+
/**
10+
* A set of atom-atom contacts to hold the results of intra and inter-chain contact calculations
11+
*
12+
* @author duarte_j
13+
*
14+
*/
1015
public class AtomContactSet implements Iterable<AtomContact> {
1116

1217
private HashMap<Pair<AtomIdentifier>, AtomContact> contacts;

biojava3-structure/src/main/java/org/biojava/bio/structure/contact/Grid.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public void addAtoms(Atom[] atoms, BoundingBox bounds) {
139139
* Checks also if the i and j grid overlap, i.e. the enclosing bounds of
140140
* the 2 grids (i and j) are no more than one cell size apart. If they don't
141141
* overlap then they are too far apart so there's nothing to calculate, we set
142-
* the noOverlap flag and then getDistMatrix will do no calculation at all.
142+
* the noOverlap flag and then {@link #getContacts()} will do no calculation at all.
143143
* @param iAtoms
144144
* @param jAtoms
145145
*/

biojava3-structure/src/main/java/org/biojava/bio/structure/contact/GroupContactSet.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@
77
import org.biojava.bio.structure.Group;
88
import org.biojava.bio.structure.ResidueNumber;
99

10-
10+
/**
11+
* A set of residue-residue contacts
12+
*
13+
* @author duarte_j
14+
*
15+
*/
1116
public class GroupContactSet implements Iterable<GroupContact>{
1217

1318
private HashMap<Pair<ResidueNumber>, GroupContact> contacts;
@@ -16,6 +21,11 @@ public GroupContactSet() {
1621
contacts = new HashMap<Pair<ResidueNumber>, GroupContact>();
1722
}
1823

24+
/**
25+
* Constructs a <code>GroupContactSet</code> by collapsing the given <code>AtomContactSet</code> into
26+
* residue-residue (group-group) contacts.
27+
* @param atomContacts
28+
*/
1929
public GroupContactSet(AtomContactSet atomContacts) {
2030
contacts = new HashMap<Pair<ResidueNumber>, GroupContact>();
2131
atoms2groups(atomContacts);

biojava3-structure/src/test/java/org/biojava/bio/structure/contact/TestContactCalc.java

Lines changed: 49 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class TestContactCalc {
3535
@Test
3636
public void testIntraChainContacts() throws StructureException, IOException {
3737

38-
String[][] cts = {null, {"CA"} , {"CB"}};
38+
String[][] cts = {null, {" CA "} , {"CB"}};
3939
double[] cutoffs = { 5.0, 8.0 , 8.0};
4040

4141
int[] allCMsizes = new int[INTRACHAIN_TESTSET.length];
@@ -77,7 +77,7 @@ public void testIntraChainContacts() throws StructureException, IOException {
7777
contacts.size()<allCMsizes[idx]);
7878

7979
// since the CB contact map will have no contacts for GLYs then the maps should be smaller than the CA
80-
if (cts[i]!=null && cts[i][0].equals("CA"))
80+
if (cts[i]!=null && cts[i][0].equals(" CA "))
8181
assertTrue("size for CA contact map ("+contacts.size()+") should be larger than for CB contact map ("+cbCMsizes[idx]+")",
8282
contacts.size()>cbCMsizes[idx]);
8383
}
@@ -121,37 +121,59 @@ public void testInterChainContacts3HBX() throws StructureException, IOException
121121

122122
@Test
123123
public void testIntraChainContactsVsDistMatrix1SMT() throws IOException, StructureException {
124-
125-
double cutoff = 8;
124+
125+
double cutoff = 5;
126126

127127
Structure structure = StructureIO.getStructure("1smt");
128128

129129
Chain chain = structure.getChainByPDB("A");
130-
String[] atomNames = {"CA"};
131130

132-
checkContactsVsDistMatrix(chain, atomNames, cutoff);
131+
System.out.println("Intra-chain contacts calculation vs distance matrix for 1smtA");
132+
133+
checkContactsVsDistMatrix(chain, cutoff);
133134
}
134135

135136
@Test
136137
public void testIntraChainContactsVsDistMatrix2TRX() throws IOException, StructureException {
137138

138-
double cutoff = 8;
139+
double cutoff = 5;
139140

140141
Structure structure = StructureIO.getStructure("2trx");
141142

142143
Chain chain = structure.getChainByPDB("A");
143-
String[] atomNames = {"CA"};
144144

145-
checkContactsVsDistMatrix(chain, atomNames, cutoff);
145+
System.out.println("Intra-chain contacts calculation vs distance matrix for 2trxA");
146+
147+
checkContactsVsDistMatrix(chain, cutoff);
146148
}
147149

150+
@Test
151+
public void testIntraChainContactsVsDistMatrix1SU4() throws IOException, StructureException {
152+
153+
double cutoff = 5;
154+
155+
Structure structure = StructureIO.getStructure("1su4");
156+
157+
Chain chain = structure.getChainByPDB("A");
158+
159+
System.out.println("Intra-chain contacts calculation vs distance matrix for 1su4A");
160+
161+
checkContactsVsDistMatrix(chain, cutoff);
162+
}
148163

149-
private void checkContactsVsDistMatrix(Chain chain, String[] atomNames, double cutoff) {
150-
AtomContactSet atomContacts = StructureTools.getAtomsInContact(chain, atomNames, cutoff);
164+
private void checkContactsVsDistMatrix(Chain chain, double cutoff) {
165+
long start = System.currentTimeMillis();
166+
AtomContactSet atomContacts = StructureTools.getAtomsInContact(chain, cutoff);
167+
long end = System.currentTimeMillis();
168+
System.out.printf("Calculated contacts in %.3f s\n",((end-start)/1000.0));
151169

152-
Atom[] atoms = StructureTools.getAtomArray(chain, atomNames);
170+
start = System.currentTimeMillis();
171+
Atom[] atoms = StructureTools.getAllNonHAtomArray(chain,false);
172+
double[][] distMatrix = calcDistanceMatrix(atoms);
173+
end = System.currentTimeMillis();
174+
System.out.printf("Calculated distance matrix in %.3f s\n",((end-start)/1000.0));
153175

154-
double[][] distMatrix = calcDistanceMatrix(atoms);
176+
System.out.println("(number of atoms: "+atoms.length+")");
155177

156178
for (int i=0;i<atoms.length;i++) {
157179
for (int j=i+1;j<atoms.length;j++) {
@@ -172,20 +194,28 @@ private void checkContactsVsDistMatrix(Chain chain, String[] atomNames, double c
172194
@Test
173195
public void testInterChainContactsVsDistMatrix2TRX() throws IOException, StructureException {
174196

175-
double cutoff = 8;
197+
double cutoff = 5;
176198

177199
Structure structure = StructureIO.getStructure("2trx");
178200

201+
System.out.println("Inter-chain contacts calculation vs distance matrix for 2trx A-B");
202+
179203
Chain chain1 = structure.getChainByPDB("A");
180204
Chain chain2 = structure.getChainByPDB("B");
181-
String[] atomNames = {"CA"};
182-
183-
AtomContactSet atomContacts = StructureTools.getAtomsInContact(chain1, chain2, atomNames, cutoff);
184205

185-
Atom[] atoms1 = StructureTools.getAtomArray(chain1, atomNames);
186-
Atom[] atoms2 = StructureTools.getAtomArray(chain2, atomNames);
206+
long start = System.currentTimeMillis();
207+
AtomContactSet atomContacts = StructureTools.getAtomsInContact(chain1, chain2, cutoff);
208+
long end = System.currentTimeMillis();
209+
System.out.printf("Calculated contacts in %.3f s\n",((end-start)/1000.0));
187210

211+
start = System.currentTimeMillis();
212+
Atom[] atoms1 = StructureTools.getAllNonHAtomArray(chain1,false);
213+
Atom[] atoms2 = StructureTools.getAllNonHAtomArray(chain2,false);
188214
double[][] distMatrix = calcDistanceMatrix(atoms1, atoms2);
215+
end = System.currentTimeMillis();
216+
System.out.printf("Calculated distance matrix in %.3f s\n",((end-start)/1000.0));
217+
218+
System.out.println("(number of atoms: "+atoms1.length+", "+atoms2.length+")");
189219

190220
for (int i=0;i<atoms1.length;i++) {
191221
for (int j=0;j<atoms2.length;j++) {

0 commit comments

Comments
 (0)