Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package org.biojava.nbio.structure.test.io;

import static org.junit.Assert.*;

import java.io.IOException;

import javax.vecmath.Matrix4d;

import org.biojava.nbio.structure.Structure;
import org.biojava.nbio.structure.StructureException;
import org.biojava.nbio.structure.StructureIO;
import org.biojava.nbio.structure.align.util.AtomCache;
import org.junit.Test;

public class TestNcsOpsParsing {

/**
* A structure (viral capsid) with struct_ncs_ops
* @throws IOException
* @throws StructureException
*/
@Test
public void test1auy() throws IOException, StructureException {

AtomCache cache = new AtomCache();
StructureIO.setAtomCache(cache);

Structure s = StructureIO.getStructure("1auy");

Matrix4d[] ops = s.getPDBHeader().getCrystallographicInfo().getNcsOperators();

assertNotNull(ops);

// the given operator must not be in our list, only the "generate" operators
assertEquals(14, ops.length);

for (Matrix4d op:ops) {
assertEquals(0, op.m30, 0.000001);
assertEquals(0, op.m31, 0.000001);
assertEquals(0, op.m32, 0.000001);
assertEquals(1, op.m33, 0.000001);
}

}

/**
* A structure with struct_ncs_ops which is not a viral capsid
* @throws IOException
* @throws StructureException
*/
@Test
public void test1a37() throws IOException, StructureException {
AtomCache cache = new AtomCache();
StructureIO.setAtomCache(cache);

Structure s = StructureIO.getStructure("1a37");

Matrix4d[] ops = s.getPDBHeader().getCrystallographicInfo().getNcsOperators();

assertNotNull(ops);

// the given operator must not be in our list, only the "generate" operators
assertEquals(1, ops.length);

}

/**
* A structure without struct_ncs_ops
* @throws IOException
* @throws StructureException
*/
@Test
public void test1smt() throws IOException, StructureException {
AtomCache cache = new AtomCache();
StructureIO.setAtomCache(cache);

Structure s = StructureIO.getStructure("1smt");

Matrix4d[] ops = s.getPDBHeader().getCrystallographicInfo().getNcsOperators();

assertNull(ops);



}


}
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@
* are not valid Java identifiers) by defining a function
* <tt>static Map<String,String> getCIFLabelMap()</tt>
* mapping from the field's name to the correct label.
* @author duarte_j
*
*
* @author Jose Duarte
* @author Spencer Bliven
*/
public class MMCIFFileTools {

Expand Down Expand Up @@ -162,7 +163,7 @@ public static String toMMCIF(String categoryName, Object o) {
* @param c
* @return
*/
private static Field[] getFields(Class<?> c) {
public static Field[] getFields(Class<?> c) {
Field[] allFields = c.getDeclaredFields();
Field[] fields = new Field[allFields.length];
int n = 0;
Expand All @@ -179,16 +180,14 @@ private static Field[] getFields(Class<?> c) {

/**
* Gets the mmCIF record name for each field. This is generally just
* the name of the field, but may be modified by passing a non-null nameMap
* argument.
* the name of the field or the value specified by the {@link CIFLabel @CIFLabel} annotation.
*
* As a side effect, calls {@link Field#setAccessible(boolean) setAccessible(true)}
* on all fields.
* @param fields
* @param nameMap
* @return
*/
private static String[] getFieldNames(Field[] fields) {
public static String[] getFieldNames(Field[] fields) {
String[] names = new String[fields.length];
for(int i=0;i<fields.length;i++) {
Field f = fields[i];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -839,17 +839,7 @@ public void documentEnd() {
structure.getPDBHeader().setBioAssemblies(bioAssemblies);
}

ArrayList<Matrix4d> ncsOperators = new ArrayList<Matrix4d>();
for (StructNcsOper sNcsOper:structNcsOper) {
if (sNcsOper.getCode().equals("generate")) {
ncsOperators.add(sNcsOper.getOperator());
}
}
// we only set it if not empty, otherwise remains null
if (ncsOperators.size()>0) {
structure.getCrystallographicInfo().setNcsOperators(
ncsOperators.toArray(new Matrix4d[ncsOperators.size()]));
}
setStructNcsOps();


Map<String,List<SeqMisMatch>> misMatchMap = new HashMap<String, List<SeqMisMatch>>();
Expand Down Expand Up @@ -1277,6 +1267,53 @@ private void initMaps() {
}
}
}

private void setStructNcsOps() {

ArrayList<Matrix4d> ncsOperators = new ArrayList<Matrix4d>();

for (StructNcsOper sNcsOper:structNcsOper) {

if (!sNcsOper.getCode().equals("generate")) continue;

try {
Matrix4d op = new Matrix4d();
op.setElement(3, 0, 0.0);
op.setElement(3, 1, 0.0);
op.setElement(3, 2, 0.0);
op.setElement(3, 3, 1.0);


op.setElement(0, 0, Double.parseDouble(sNcsOper.getMatrix11()));
op.setElement(0, 1, Double.parseDouble(sNcsOper.getMatrix12()));
op.setElement(0, 2, Double.parseDouble(sNcsOper.getMatrix13()));

op.setElement(1, 0, Double.parseDouble(sNcsOper.getMatrix21()));
op.setElement(1, 1, Double.parseDouble(sNcsOper.getMatrix22()));
op.setElement(1, 2, Double.parseDouble(sNcsOper.getMatrix23()));

op.setElement(2, 0, Double.parseDouble(sNcsOper.getMatrix31()));
op.setElement(2, 1, Double.parseDouble(sNcsOper.getMatrix32()));
op.setElement(2, 2, Double.parseDouble(sNcsOper.getMatrix33()));

op.setElement(0, 3, Double.parseDouble(sNcsOper.getVector1()));
op.setElement(1, 3, Double.parseDouble(sNcsOper.getVector2()));
op.setElement(2, 3, Double.parseDouble(sNcsOper.getVector3()));

ncsOperators.add(op);

} catch (NumberFormatException e) {
logger.warn("Error parsing doubles in NCS operator list, skipping operator {}", structNcsOper.indexOf(sNcsOper)+1);
}

}

// we only set it if not empty, otherwise remains null
if (ncsOperators.size()>0) {
structure.getCrystallographicInfo().setNcsOperators(
ncsOperators.toArray(new Matrix4d[ncsOperators.size()]));
}
}

/** This method will return the parsed protein structure, once the parsing has been finished
*
Expand Down
Loading