Skip to content

Commit 2a2e75d

Browse files
committed
Now using the CIFLabel annotations from cif parser
1 parent e70dcbb commit 2a2e75d

5 files changed

Lines changed: 452 additions & 115 deletions

File tree

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
package org.biojava.nbio.structure.test.io;
2+
3+
import static org.junit.Assert.*;
4+
5+
import java.io.IOException;
6+
7+
import javax.vecmath.Matrix4d;
8+
9+
import org.biojava.nbio.structure.Structure;
10+
import org.biojava.nbio.structure.StructureException;
11+
import org.biojava.nbio.structure.StructureIO;
12+
import org.biojava.nbio.structure.align.util.AtomCache;
13+
import org.junit.Test;
14+
15+
public class TestNcsOpsParsing {
16+
17+
/**
18+
* A structure (viral capsid) with struct_ncs_ops
19+
* @throws IOException
20+
* @throws StructureException
21+
*/
22+
@Test
23+
public void test1auy() throws IOException, StructureException {
24+
25+
AtomCache cache = new AtomCache();
26+
StructureIO.setAtomCache(cache);
27+
28+
Structure s = StructureIO.getStructure("1auy");
29+
30+
Matrix4d[] ops = s.getPDBHeader().getCrystallographicInfo().getNcsOperators();
31+
32+
assertNotNull(ops);
33+
34+
// the given operator must not be in our list, only the "generate" operators
35+
assertEquals(14, ops.length);
36+
37+
for (Matrix4d op:ops) {
38+
assertEquals(0, op.m30, 0.000001);
39+
assertEquals(0, op.m31, 0.000001);
40+
assertEquals(0, op.m32, 0.000001);
41+
assertEquals(1, op.m33, 0.000001);
42+
}
43+
44+
}
45+
46+
/**
47+
* A structure with struct_ncs_ops which is not a viral capsid
48+
* @throws IOException
49+
* @throws StructureException
50+
*/
51+
@Test
52+
public void test1a37() throws IOException, StructureException {
53+
AtomCache cache = new AtomCache();
54+
StructureIO.setAtomCache(cache);
55+
56+
Structure s = StructureIO.getStructure("1a37");
57+
58+
Matrix4d[] ops = s.getPDBHeader().getCrystallographicInfo().getNcsOperators();
59+
60+
assertNotNull(ops);
61+
62+
// the given operator must not be in our list, only the "generate" operators
63+
assertEquals(1, ops.length);
64+
65+
}
66+
67+
/**
68+
* A structure without struct_ncs_ops
69+
* @throws IOException
70+
* @throws StructureException
71+
*/
72+
@Test
73+
public void test1smt() throws IOException, StructureException {
74+
AtomCache cache = new AtomCache();
75+
StructureIO.setAtomCache(cache);
76+
77+
Structure s = StructureIO.getStructure("1smt");
78+
79+
Matrix4d[] ops = s.getPDBHeader().getCrystallographicInfo().getNcsOperators();
80+
81+
assertNull(ops);
82+
83+
84+
85+
}
86+
87+
88+
}

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,9 @@
5656
* are not valid Java identifiers) by defining a function
5757
* <tt>static Map<String,String> getCIFLabelMap()</tt>
5858
* mapping from the field's name to the correct label.
59-
* @author duarte_j
60-
*
59+
*
60+
* @author Jose Duarte
61+
* @author Spencer Bliven
6162
*/
6263
public class MMCIFFileTools {
6364

@@ -162,7 +163,7 @@ public static String toMMCIF(String categoryName, Object o) {
162163
* @param c
163164
* @return
164165
*/
165-
private static Field[] getFields(Class<?> c) {
166+
public static Field[] getFields(Class<?> c) {
166167
Field[] allFields = c.getDeclaredFields();
167168
Field[] fields = new Field[allFields.length];
168169
int n = 0;
@@ -179,16 +180,14 @@ private static Field[] getFields(Class<?> c) {
179180

180181
/**
181182
* Gets the mmCIF record name for each field. This is generally just
182-
* the name of the field, but may be modified by passing a non-null nameMap
183-
* argument.
183+
* the name of the field or the value specified by the {@link CIFLabel @CIFLabel} annotation.
184184
*
185185
* As a side effect, calls {@link Field#setAccessible(boolean) setAccessible(true)}
186186
* on all fields.
187187
* @param fields
188-
* @param nameMap
189188
* @return
190189
*/
191-
private static String[] getFieldNames(Field[] fields) {
190+
public static String[] getFieldNames(Field[] fields) {
192191
String[] names = new String[fields.length];
193192
for(int i=0;i<fields.length;i++) {
194193
Field f = fields[i];

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

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -870,17 +870,7 @@ public void documentEnd() {
870870
structure.getPDBHeader().setBioAssemblies(bioAssemblies);
871871
}
872872

873-
ArrayList<Matrix4d> ncsOperators = new ArrayList<Matrix4d>();
874-
for (StructNcsOper sNcsOper:structNcsOper) {
875-
if (sNcsOper.getCode().equals("generate")) {
876-
ncsOperators.add(sNcsOper.getOperator());
877-
}
878-
}
879-
// we only set it if not empty, otherwise remains null
880-
if (ncsOperators.size()>0) {
881-
structure.getCrystallographicInfo().setNcsOperators(
882-
ncsOperators.toArray(new Matrix4d[ncsOperators.size()]));
883-
}
873+
setStructNcsOps();
884874

885875

886876
Map<String,List<SeqMisMatch>> misMatchMap = new HashMap<String, List<SeqMisMatch>>();
@@ -1236,6 +1226,53 @@ private Compound createNewCompoundFromESS(EntitySrcSyn ess, int eId) {
12361226
return c;
12371227

12381228
}
1229+
1230+
private void setStructNcsOps() {
1231+
1232+
ArrayList<Matrix4d> ncsOperators = new ArrayList<Matrix4d>();
1233+
1234+
for (StructNcsOper sNcsOper:structNcsOper) {
1235+
1236+
if (!sNcsOper.getCode().equals("generate")) continue;
1237+
1238+
try {
1239+
Matrix4d op = new Matrix4d();
1240+
op.setElement(3, 0, 0.0);
1241+
op.setElement(3, 1, 0.0);
1242+
op.setElement(3, 2, 0.0);
1243+
op.setElement(3, 3, 1.0);
1244+
1245+
1246+
op.setElement(0, 0, Double.parseDouble(sNcsOper.getMatrix11()));
1247+
op.setElement(0, 1, Double.parseDouble(sNcsOper.getMatrix12()));
1248+
op.setElement(0, 2, Double.parseDouble(sNcsOper.getMatrix13()));
1249+
1250+
op.setElement(1, 0, Double.parseDouble(sNcsOper.getMatrix21()));
1251+
op.setElement(1, 1, Double.parseDouble(sNcsOper.getMatrix22()));
1252+
op.setElement(1, 2, Double.parseDouble(sNcsOper.getMatrix23()));
1253+
1254+
op.setElement(2, 0, Double.parseDouble(sNcsOper.getMatrix31()));
1255+
op.setElement(2, 1, Double.parseDouble(sNcsOper.getMatrix32()));
1256+
op.setElement(2, 2, Double.parseDouble(sNcsOper.getMatrix33()));
1257+
1258+
op.setElement(0, 3, Double.parseDouble(sNcsOper.getVector1()));
1259+
op.setElement(1, 3, Double.parseDouble(sNcsOper.getVector2()));
1260+
op.setElement(2, 3, Double.parseDouble(sNcsOper.getVector3()));
1261+
1262+
ncsOperators.add(op);
1263+
1264+
} catch (NumberFormatException e) {
1265+
logger.warn("Error parsing doubles in NCS operator list, skipping operator {}", structNcsOper.indexOf(sNcsOper)+1);
1266+
}
1267+
1268+
}
1269+
1270+
// we only set it if not empty, otherwise remains null
1271+
if (ncsOperators.size()>0) {
1272+
structure.getCrystallographicInfo().setNcsOperators(
1273+
ncsOperators.toArray(new Matrix4d[ncsOperators.size()]));
1274+
}
1275+
}
12391276

12401277
/** This method will return the parsed protein structure, once the parsing has been finished
12411278
*

0 commit comments

Comments
 (0)