diff --git a/biojava-aa-prop/pom.xml b/biojava-aa-prop/pom.xml index e0083abd83..d4d3afb89b 100644 --- a/biojava-aa-prop/pom.xml +++ b/biojava-aa-prop/pom.xml @@ -2,7 +2,7 @@ biojava org.biojava - 4.2.2 + 4.2.3 4.0.0 biojava-aa-prop @@ -70,12 +70,12 @@ org.biojava biojava-core - 4.2.2 + 4.2.3 org.biojava biojava-structure - 4.2.2 + 4.2.3 diff --git a/biojava-alignment/pom.xml b/biojava-alignment/pom.xml index 70f3e659f6..c033b8d1f0 100644 --- a/biojava-alignment/pom.xml +++ b/biojava-alignment/pom.xml @@ -4,7 +4,7 @@ biojava org.biojava - 4.2.2 + 4.2.3 biojava-alignment biojava-alignment @@ -46,7 +46,7 @@ org.biojava biojava-core - 4.2.2 + 4.2.3 compile @@ -74,7 +74,7 @@ org.biojava biojava-phylo - 4.2.2 + 4.2.3 diff --git a/biojava-core/pom.xml b/biojava-core/pom.xml index 352ffa37e8..674c0257f3 100644 --- a/biojava-core/pom.xml +++ b/biojava-core/pom.xml @@ -3,7 +3,7 @@ biojava org.biojava - 4.2.2 + 4.2.3 4.0.0 biojava-core diff --git a/biojava-genome/pom.xml b/biojava-genome/pom.xml index e78cefe396..24d410ee7c 100644 --- a/biojava-genome/pom.xml +++ b/biojava-genome/pom.xml @@ -3,7 +3,7 @@ biojava org.biojava - 4.2.2 + 4.2.3 4.0.0 biojava-genome @@ -79,13 +79,13 @@ org.biojava biojava-core - 4.2.2 + 4.2.3 compile org.biojava biojava-alignment - 4.2.2 + 4.2.3 compile diff --git a/biojava-integrationtest/pom.xml b/biojava-integrationtest/pom.xml index ecdaf3e4a3..61f9a178e4 100644 --- a/biojava-integrationtest/pom.xml +++ b/biojava-integrationtest/pom.xml @@ -4,7 +4,7 @@ biojava org.biojava - 4.2.2 + 4.2.3 biojava-integrationtest jar @@ -32,7 +32,7 @@ org.biojava biojava-structure - 4.2.2 + 4.2.3 diff --git a/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/io/TestNcsOpsParsing.java b/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/io/TestNcsOpsParsing.java new file mode 100644 index 0000000000..166b32c6a7 --- /dev/null +++ b/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/io/TestNcsOpsParsing.java @@ -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); + + + + } + + +} diff --git a/biojava-modfinder/pom.xml b/biojava-modfinder/pom.xml index 8bbe1063cc..0c8c9b759f 100644 --- a/biojava-modfinder/pom.xml +++ b/biojava-modfinder/pom.xml @@ -4,7 +4,7 @@ biojava org.biojava - 4.2.2 + 4.2.3 biojava-modfinder biojava-modfinder @@ -31,7 +31,7 @@ org.biojava biojava-structure - 4.2.2 + 4.2.3 jar compile diff --git a/biojava-ontology/pom.xml b/biojava-ontology/pom.xml index 84879a63eb..b0f4378c55 100644 --- a/biojava-ontology/pom.xml +++ b/biojava-ontology/pom.xml @@ -4,7 +4,7 @@ org.biojava biojava - 4.2.2 + 4.2.3 biojava-ontology diff --git a/biojava-phylo/pom.xml b/biojava-phylo/pom.xml index 4ed6efe7f7..96be175f15 100644 --- a/biojava-phylo/pom.xml +++ b/biojava-phylo/pom.xml @@ -3,7 +3,7 @@ biojava org.biojava - 4.2.2 + 4.2.3 4.0.0 biojava-phylo @@ -44,7 +44,7 @@ org.biojava biojava-core - 4.2.2 + 4.2.3 compile diff --git a/biojava-protein-disorder/pom.xml b/biojava-protein-disorder/pom.xml index f8fe1d4bae..cd338b3b8f 100644 --- a/biojava-protein-disorder/pom.xml +++ b/biojava-protein-disorder/pom.xml @@ -3,7 +3,7 @@ biojava org.biojava - 4.2.2 + 4.2.3 biojava-protein-disorder jar @@ -63,7 +63,7 @@ org.biojava biojava-core - 4.2.2 + 4.2.3 diff --git a/biojava-sequencing/pom.xml b/biojava-sequencing/pom.xml index 99eaee0097..374ea82c69 100644 --- a/biojava-sequencing/pom.xml +++ b/biojava-sequencing/pom.xml @@ -3,7 +3,7 @@ biojava org.biojava - 4.2.2 + 4.2.3 4.0.0 biojava-sequencing @@ -47,7 +47,7 @@ org.biojava biojava-core - 4.2.2 + 4.2.3 compile diff --git a/biojava-structure-gui/pom.xml b/biojava-structure-gui/pom.xml index e6c6de96e1..290c5a3a55 100644 --- a/biojava-structure-gui/pom.xml +++ b/biojava-structure-gui/pom.xml @@ -3,7 +3,7 @@ biojava org.biojava - 4.2.2 + 4.2.3 4.0.0 biojava-structure-gui @@ -25,13 +25,13 @@ org.biojava biojava-structure - 4.2.2 + 4.2.3 compile org.biojava biojava-core - 4.2.2 + 4.2.3 compile diff --git a/biojava-structure/pom.xml b/biojava-structure/pom.xml index 4b3f63ee6f..ddee49b548 100644 --- a/biojava-structure/pom.xml +++ b/biojava-structure/pom.xml @@ -4,7 +4,7 @@ biojava org.biojava - 4.2.2 + 4.2.3 biojava-structure biojava-structure @@ -22,13 +22,13 @@ org.biojava biojava-alignment - 4.2.2 + 4.2.3 compile org.biojava biojava-core - 4.2.2 + 4.2.3 compile diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/contact/StructureInterface.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/contact/StructureInterface.java index f536d9cec6..3c88825041 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/contact/StructureInterface.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/contact/StructureInterface.java @@ -20,7 +20,20 @@ */ package org.biojava.nbio.structure.contact; -import org.biojava.nbio.structure.*; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.TreeMap; + +import org.biojava.nbio.structure.Atom; +import org.biojava.nbio.structure.Chain; +import org.biojava.nbio.structure.Element; +import org.biojava.nbio.structure.Compound; +import org.biojava.nbio.structure.Group; +import org.biojava.nbio.structure.GroupType; +import org.biojava.nbio.structure.ResidueNumber; +import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.asa.AsaCalculator; import org.biojava.nbio.structure.asa.GroupAsa; import org.biojava.nbio.structure.io.FileConvert; @@ -28,17 +41,12 @@ import org.biojava.nbio.structure.io.mmcif.MMCIFFileTools; import org.biojava.nbio.structure.io.mmcif.SimpleMMcifParser; import org.biojava.nbio.structure.io.mmcif.chem.PolymerType; +import org.biojava.nbio.structure.io.mmcif.model.AtomSite; import org.biojava.nbio.structure.io.mmcif.model.ChemComp; import org.biojava.nbio.structure.xtal.CrystalTransform; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.Serializable; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.TreeMap; - /** * An interface between 2 molecules (2 sets of atoms). @@ -753,7 +761,7 @@ public String toMMCIF() { // we reassign atom ids if sym related (otherwise atom ids would be duplicated and some molecular viewers can't cope with that) int atomId = 1; - List atomSites = new ArrayList(); + List atomSites = new ArrayList<>(); for (Atom atom:this.molecules.getFirst()) { if (isSymRelated()) { atomSites.add(MMCIFFileTools.convertAtomToAtomSite(atom, 1, molecId1, molecId1, atomId)); @@ -771,7 +779,7 @@ public String toMMCIF() { atomId++; } - sb.append(MMCIFFileTools.toMMCIF(atomSites)); + sb.append(MMCIFFileTools.toMMCIF(atomSites,AtomSite.class)); return sb.toString(); } diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/FileConvert.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/FileConvert.java index af5b3702db..0d3127b9b4 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/FileConvert.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/FileConvert.java @@ -680,12 +680,10 @@ public String toMMCIF() { str.append(getAtomSiteHeader()); - @SuppressWarnings("unchecked") - List list = - (List) (List) MMCIFFileTools.convertStructureToAtomSites(structure); + List list = MMCIFFileTools.convertStructureToAtomSites(structure); - str.append(MMCIFFileTools.toMMCIF(list)); + str.append(MMCIFFileTools.toMMCIF(list,AtomSite.class)); return str.toString(); } @@ -697,11 +695,9 @@ public static String toMMCIF(Chain chain, String chainId, String internalChainId str.append(getAtomSiteHeader()); - @SuppressWarnings("unchecked") - List list = - (List) (List) MMCIFFileTools.convertChainToAtomSites(chain, 1, chainId, internalChainId); + List list = MMCIFFileTools.convertChainToAtomSites(chain, 1, chainId, internalChainId); - str.append(MMCIFFileTools.toMMCIF(list)); + str.append(MMCIFFileTools.toMMCIF(list,AtomSite.class)); return str.toString(); } diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/MMCIFFileTools.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/MMCIFFileTools.java index fcf62bff48..e5ecbb2455 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/MMCIFFileTools.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/MMCIFFileTools.java @@ -23,6 +23,7 @@ import java.lang.reflect.Field; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.biojava.nbio.structure.Atom; @@ -32,8 +33,11 @@ import org.biojava.nbio.structure.GroupType; import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.io.FileConvert; +import org.biojava.nbio.structure.io.mmcif.model.AbstractBean; import org.biojava.nbio.structure.io.mmcif.model.AtomSite; +import org.biojava.nbio.structure.io.mmcif.model.CIFLabel; import org.biojava.nbio.structure.io.mmcif.model.Cell; +import org.biojava.nbio.structure.io.mmcif.model.IgnoreField; import org.biojava.nbio.structure.io.mmcif.model.Symmetry; import org.biojava.nbio.structure.xtal.CrystalCell; import org.biojava.nbio.structure.xtal.SpaceGroup; @@ -45,9 +49,16 @@ * * See http://www.iucr.org/__data/assets/pdf_file/0019/22618/cifguide.pdf * - * - * @author duarte_j - * + * CIF categories are represented as a simple bean, typically extending {@link AbstractBean}. + * By default, all fields from the bean are taken as the CIF labels. Fields + * may be omitted by annotating them as {@link IgnoreField @IgnoreField}. + * The CIF label for a field may be changed (for instance, for fields that + * are not valid Java identifiers) by defining a function + * static Map getCIFLabelMap() + * mapping from the field's name to the correct label. + * + * @author Jose Duarte + * @author Spencer Bliven */ public class MMCIFFileTools { @@ -81,7 +92,7 @@ public static String toLoopMmCifHeaderString(String categoryName, String classNa Class c = Class.forName(className); - for (Field f : c.getDeclaredFields()) { + for (Field f : getFields(c)) { str.append(categoryName+"."+f.getName()+newline); } @@ -101,33 +112,38 @@ public static String toMMCIF(String categoryName, Object o) { Class c = o.getClass(); - int maxFieldNameLength = getMaxFieldNameLength(o); - for (Field f : c.getDeclaredFields()) { - f.setAccessible(true); + Field[] fields = getFields(c); + String[] names = getFieldNames(fields); - sb.append(categoryName+"."+f.getName()); + int maxFieldNameLength = getMaxStringLength(names); - int spacing = maxFieldNameLength - f.getName().length() + 3; + for (int i=0;i c) { + Field[] allFields = c.getDeclaredFields(); + Field[] fields = new Field[allFields.length]; + int n = 0; + for(Field f : allFields) { + f.setAccessible(true); + IgnoreField anno = f.getAnnotation(IgnoreField.class); + if(anno == null) { + fields[n] = f; + n++; + } + } + return Arrays.copyOf(fields, n); + } + + /** + * Gets the mmCIF record name for each field. This is generally just + * 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 + * @return + */ + public static String[] getFieldNames(Field[] fields) { + String[] names = new String[fields.length]; + for(int i=0;i list) { - int[] sizes = getFieldSizes(list); + public static String toMMCIF(List list, Class klass) { + if (list.isEmpty()) throw new IllegalArgumentException("List of beans is empty!"); + + Field[] fields = getFields(klass); + int[] sizes = getFieldSizes(list,fields); StringBuilder sb = new StringBuilder(); - for (Object o:list) { - sb.append(toSingleLoopLineMmCifString(o, sizes)); + for (T o:list) { + sb.append(toSingleLoopLineMmCifString(o, fields, sizes)); } sb.append(SimpleMMcifParser.COMMENT_CHAR+newline); return sb.toString(); } + /** + * Converts a list of mmCIF beans (see {@link org.biojava.nbio.structure.io.mmcif.model} to + * a String representing them in mmCIF loop format with one record per line. + * @param list + * @return + * @deprecated The {@link #toMMCIF(List, Class)} provides compile-time type safety + * @throws ClassCastException if not all list elements have the same type + */ + @Deprecated + @SuppressWarnings("unchecked") + public static String toMMCIF(List list) { + Class klass = (Class)list.get(0).getClass(); + for(T t : list) { + if( klass != t.getClass() ) { + throw new ClassCastException("Not all loop elements have the same fields"); + } + } + return toMMCIF(list,klass); + } /** * Given a mmCIF bean produces a String representing it in mmCIF loop format as a single record line - * @param a + * @param record + * @param fields Set of fields for the record. If null, will be calculated from the class of the record * @param sizes the size of each of the fields * @return */ - private static String toSingleLoopLineMmCifString(Object a, int[] sizes) { + private static String toSingleLoopLineMmCifString(Object record, Field[] fields, int[] sizes) { StringBuilder str = new StringBuilder(); - Class c = a.getClass(); + Class c = record.getClass(); - if (sizes.length!=c.getDeclaredFields().length) + if(fields == null) + fields = getFields(c); + + if (sizes.length!=fields.length) throw new IllegalArgumentException("The given sizes of fields differ from the number of declared fields"); int i = -1; - for (Field f : c.getDeclaredFields()) { + for (Field f : fields) { i++; f.setAccessible(true); try { - Object obj = f.get(a); + Object obj = f.get(record); String val; if (obj==null) { logger.debug("Field {} is null, will write it out as {}",f.getName(),MMCIF_MISSING_VALUE); @@ -309,9 +400,11 @@ record = "ATOM"; } Character altLoc = a.getAltLoc() ; - String altLocStr = altLoc.toString(); + String altLocStr; if (altLoc==null || altLoc == ' ') { altLocStr = MMCIF_DEFAULT_VALUE; + } else { + altLocStr = altLoc.toString(); } Element e = a.getElement(); @@ -428,22 +521,24 @@ public static List convertStructureToAtomSites(Structure s) { /** * Finds the max length of each of the String values contained in each of the fields of the given list of beans. * Useful for producing mmCIF loop data that is aligned for all columns. - * @param a + * @param list list of objects. All objects should have the same class. + * @param fields Set of fields for the record. If null, will be calculated from the class of the first record * @return - * @see #toMMCIF(List) + * @see #toMMCIF(List, Class) */ - private static int[] getFieldSizes(List list) { + private static int[] getFieldSizes(List list, Field[] fields) { if (list.isEmpty()) throw new IllegalArgumentException("List of beans is empty!"); - int[] sizes = new int [list.get(0).getClass().getDeclaredFields().length]; + if(fields == null) + fields = getFields(list.get(0).getClass()); + int[] sizes = new int [fields.length]; - for (Object a:list) { - Class c = a.getClass(); + for (T a:list) { int i = -1; - for (Field f : c.getDeclaredFields()) { + for (Field f : fields) { i++; f.setAccessible(true); @@ -473,27 +568,19 @@ private static int[] getFieldSizes(List list) { } /** - * Finds the max length of the field strings corresponding to the given mmCIF bean. + * Finds the max length of a list of strings * Useful for producing mmCIF single-record data that is aligned for all values. - * @param a + * @param names * @return * @see #toMMCIF(String, Object) */ - private static int getMaxFieldNameLength(Object a) { - + private static int getMaxStringLength(String[] names) { int size = 0; - - Class c = a.getClass(); - - for (Field f : c.getDeclaredFields()) { - - f.setAccessible(true); - - if (f.getName().length() > size) { - size = f.getName().length(); + for(String s : names) { + if(s.length()>size) { + size = s.length(); } } - return size; } } diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/SimpleMMcifConsumer.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/SimpleMMcifConsumer.java index 8f1fea5747..5ef567c93c 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/SimpleMMcifConsumer.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/SimpleMMcifConsumer.java @@ -870,17 +870,7 @@ public void documentEnd() { structure.getPDBHeader().setBioAssemblies(bioAssemblies); } - ArrayList ncsOperators = new ArrayList(); - 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> misMatchMap = new HashMap>(); @@ -1236,6 +1226,53 @@ private Compound createNewCompoundFromESS(EntitySrcSyn ess, int eId) { return c; } + + private void setStructNcsOps() { + + ArrayList ncsOperators = new ArrayList(); + + 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 * diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/SimpleMMcifParser.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/SimpleMMcifParser.java index 3878890eb2..90b03c8da1 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/SimpleMMcifParser.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/SimpleMMcifParser.java @@ -25,6 +25,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.ArrayList; @@ -34,13 +35,13 @@ import java.util.Map; import java.util.Set; -import javax.vecmath.Matrix4d; import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.io.MMCIFFileReader; import org.biojava.nbio.structure.io.StructureIOFile; import org.biojava.nbio.structure.io.mmcif.model.AtomSite; import org.biojava.nbio.structure.io.mmcif.model.AuditAuthor; +import org.biojava.nbio.structure.io.mmcif.model.CIFLabel; import org.biojava.nbio.structure.io.mmcif.model.Cell; import org.biojava.nbio.structure.io.mmcif.model.ChemComp; import org.biojava.nbio.structure.io.mmcif.model.ChemCompAtom; @@ -55,6 +56,7 @@ import org.biojava.nbio.structure.io.mmcif.model.EntitySrcNat; import org.biojava.nbio.structure.io.mmcif.model.EntitySrcSyn; import org.biojava.nbio.structure.io.mmcif.model.Exptl; +import org.biojava.nbio.structure.io.mmcif.model.IgnoreField; import org.biojava.nbio.structure.io.mmcif.model.PdbxChemCompDescriptor; import org.biojava.nbio.structure.io.mmcif.model.PdbxChemCompIdentifier; import org.biojava.nbio.structure.io.mmcif.model.PdbxEntityNonPoly; @@ -75,7 +77,6 @@ import org.biojava.nbio.structure.io.mmcif.model.StructSite; import org.biojava.nbio.structure.io.mmcif.model.StructSiteGen; import org.biojava.nbio.structure.io.mmcif.model.Symmetry; -import org.biojava.nbio.structure.jama.Matrix; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -670,17 +671,10 @@ private void endLineChecks(String category,List loopFields, List triggerNewSymmetry(symmetry); } else if ( category.equals("_struct_ncs_oper")) { - // this guy is special because of the [] in the field names - StructNcsOper sNcsOper = null; - try{ - sNcsOper = getStructNcsOper(loopFields,lineData); - } - catch(NumberFormatException e){ - logger.warn("Error parsing doubles in NCS operator list"); - } - if(sNcsOper!=null){ - triggerNewStructNcsOper(sNcsOper); - } + StructNcsOper sNcsOper = (StructNcsOper) buildObject( + StructNcsOper.class.getName(), + loopFields, lineData, loopWarnings); + triggerNewStructNcsOper(sNcsOper); } else if ( category.equals("_struct_ref")){ StructRef sref = (StructRef) buildObject( @@ -790,12 +784,12 @@ private void endLineChecks(String category,List loopFields, List triggerNewChemCompDescriptor(ccd); } else if (category.equals("_pdbx_struct_oper_list")) { - // this guy is special since we convert to Matrices and shift vectors... - // and because it contains [] in field names - PdbxStructOperList structOper = getPdbxStructOperList(loopFields,lineData); + PdbxStructOperList structOper = (PdbxStructOperList) buildObject( + PdbxStructOperList.class.getName(), + loopFields, lineData, loopWarnings + ); triggerNewPdbxStructOper(structOper); - } else if (category.equals("_pdbx_struct_assembly")) { PdbxStructAssembly sa = (PdbxStructAssembly) buildObject( PdbxStructAssembly.class.getName(), @@ -846,44 +840,44 @@ private void endLineChecks(String category,List loopFields, List } - private PdbxStructOperList getPdbxStructOperList(List loopFields, - List lineData) { - PdbxStructOperList so = new PdbxStructOperList(); - - //System.out.println(loopFields); - //System.out.println(lineData); - - String id = lineData.get(loopFields.indexOf("id")); - so.setId(id); - so.setType(lineData.get(loopFields.indexOf("type"))); - Matrix matrix = new Matrix(3,3); - for (int i = 1 ; i <=3 ; i++){ - for (int j =1 ; j <= 3 ; j++){ - String max = String.format("matrix[%d][%d]",j,i); - - String val = lineData.get(loopFields.indexOf(max)); - Double d = Double.parseDouble(val); - matrix.set(j-1,i-1,d); - // matrix.set(i-1,j-1,d); - } - } - - double[] coords =new double[3]; - - for ( int i = 1; i <=3 ; i++){ - String v = String.format("vector[%d]",i); - String val = lineData.get(loopFields.indexOf(v)); - Double d = Double.parseDouble(val); - coords[i-1] = d; - } - - so.setMatrix(matrix); - so.setVector(coords); - - - - return so; - } +// private PdbxStructOperList getPdbxStructOperList(List loopFields, +// List lineData) { +// PdbxStructOperList so = new PdbxStructOperList(); +// +// //System.out.println(loopFields); +// //System.out.println(lineData); +// +// String id = lineData.get(loopFields.indexOf("id")); +// so.setId(id); +// so.setType(lineData.get(loopFields.indexOf("type"))); +// Matrix matrix = new Matrix(3,3); +// for (int i = 1 ; i <=3 ; i++){ +// for (int j =1 ; j <= 3 ; j++){ +// String max = String.format("matrix[%d][%d]",j,i); +// +// String val = lineData.get(loopFields.indexOf(max)); +// Double d = Double.parseDouble(val); +// matrix.set(j-1,i-1,d); +// // matrix.set(i-1,j-1,d); +// } +// } +// +// double[] coords =new double[3]; +// +// for ( int i = 1; i <=3 ; i++){ +// String v = String.format("vector[%d]",i); +// String val = lineData.get(loopFields.indexOf(v)); +// Double d = Double.parseDouble(val); +// coords[i-1] = d; +// } +// +// so.setMatrix(matrix); +// so.setVector(coords); +// +// +// +// return so; +// } public void triggerNewPdbxStructOper(PdbxStructOperList structOper) { for(MMcifConsumer c : consumers){ @@ -892,46 +886,6 @@ public void triggerNewPdbxStructOper(PdbxStructOperList structOper) { } - private StructNcsOper getStructNcsOper(List loopFields, List lineData) { - StructNcsOper sNcsOper = new StructNcsOper(); - - int id = Integer.parseInt(lineData.get(loopFields.indexOf("id"))); - sNcsOper.setId(id); - sNcsOper.setCode(lineData.get(loopFields.indexOf("code"))); - - int detailsPos = loopFields.indexOf("details"); - if ( detailsPos > -1) - sNcsOper.setDetails(lineData.get(detailsPos)); - 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); - - - for (int i = 1 ; i <=3 ; i++){ - for (int j =1 ; j <= 3 ; j++){ - String max = String.format("matrix[%d][%d]",i,j); - String val = lineData.get(loopFields.indexOf(max)); - Double d = Double.parseDouble(val); - op.setElement(i-1,j-1,d); - - } - } - - - for ( int i = 1; i <=3 ; i++){ - String v = String.format("vector[%d]",i); - String val = lineData.get(loopFields.indexOf(v)); - Double d = Double.parseDouble(val); - op.setElement(i-1, 3, d); - } - - sNcsOper.setOperator(op); - - return sNcsOper; - } - public void triggerNewStructNcsOper(StructNcsOper sNcsOper) { for(MMcifConsumer c : consumers){ c.newStructNcsOper(sNcsOper); @@ -939,6 +893,23 @@ public void triggerNewStructNcsOper(StructNcsOper sNcsOper) { } + /** + * Populates a bean object from the {@link org.biojava.nbio.structure.io.mmcif.model} package, + * from the data read from a CIF file. + * It uses reflection to lookup the field and setter method names given the category + * found in the CIF file. + *

+ * Due to limitations in variable names in java, not all fields can have names + * exactly as defined in the CIF categories. In those cases the {@link CIFLabel} tag + * can be used in the field names to give the appropriate name that corresponds to the + * CIF category, which is the name that will be then looked up here. + * The {@link IgnoreField} tag can also be used to exclude fields from being looked up. + * @param className + * @param loopFields + * @param lineData + * @param warnings + * @return + */ private Object buildObject(String className, List loopFields, List lineData, Set warnings) { Object o = null; @@ -950,17 +921,16 @@ private Object buildObject(String className, List loopFields, List methodMap = new HashMap(); @@ -968,68 +938,84 @@ private Object buildObject(String className, List loopFields, List names2fields = new HashMap<>(); + for (int i=0;i[] pType = m.getParameterTypes(); + Class[] pType = setter.getParameterTypes(); + try { if ( pType[0].getName().equals(Integer.class.getName())) { if ( val != null && ! val.equals("?") && !val.equals(".")) { Integer intVal = Integer.parseInt(val); - m.invoke(o, intVal); + setter.invoke(o, intVal); + } } else { - // default val is a String - m.invoke(o, val); + // default val is a String + setter.invoke(o, val); } - } catch (IllegalAccessException e) { - logger.error("Could not invoke setter {} with value {} for class {}", methodName, val, className); - } catch (InvocationTargetException e) { - logger.error("Could not invoke setter {} with value {} for class {}", methodName, val, className); - } + } catch (IllegalAccessException|InvocationTargetException e) { + logger.error("Could not invoke setter {} with value {} for class {}", setterMethodName, val, className); + } } return o; } + + private void produceWarning(String key, String val, Class c, Set warnings) { + + String warning = "Trying to set field " + key + " in "+ c.getName() +" found in file, but no corresponding field could be found in model class (value:" + val + ")"; + String warnkey = key+"-"+c.getName(); + // Suppress duplicate warnings or attempts to store empty data + if( val.equals("?") || val.equals(".") || ( warnings != null && warnings.contains(warnkey)) ) { + logger.debug(warning); + } else { + logger.warn(warning); + } + + if(warnings != null) { + warnings.add(warnkey); + } + + } public void triggerGeneric(String category, List loopFields, List lineData){ for(MMcifConsumer c : consumers){ diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/CIFLabel.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/CIFLabel.java new file mode 100644 index 0000000000..54e501eec1 --- /dev/null +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/CIFLabel.java @@ -0,0 +1,18 @@ +package org.biojava.nbio.structure.io.mmcif.model; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Annotation indicating that a specific field of a bean should be mapped to + * a different label + * @author Spencer Bliven + * + */ +@Target(value=ElementType.FIELD) +@Retention(value=RetentionPolicy.RUNTIME) +public @interface CIFLabel { + String label(); +} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/Cell.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/Cell.java index c1bdf81cc9..21fdc56ea1 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/Cell.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/Cell.java @@ -39,6 +39,8 @@ public class Cell extends AbstractBean { String angle_alpha_esd; String angle_beta_esd; String angle_gamma_esd; + + String volume; public String getEntry_id() { return entry_id; @@ -130,6 +132,12 @@ public String getAngle_gamma_esd() { public void setAngle_gamma_esd(String angle_gamma_esd) { this.angle_gamma_esd = angle_gamma_esd; } + public String getVolume() { + return volume; + } + public void setVolume(String volume) { + this.volume = volume; + } } diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/ChemComp.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/ChemComp.java index 90d005dee6..cb38de1755 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/ChemComp.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/ChemComp.java @@ -66,13 +66,19 @@ public class ChemComp implements Serializable, Comparable{ private String pdbx_processing_site; private String mon_nstd_flag; + @IgnoreField private List descriptors = new ArrayList(); + @IgnoreField private List bonds = new ArrayList(); + @IgnoreField private List atoms = new ArrayList(); // and some derived data for easier processing... + @IgnoreField private ResidueType residueType; + @IgnoreField private PolymerType polymerType; + @IgnoreField private boolean standard; @Override diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/IgnoreField.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/IgnoreField.java new file mode 100644 index 0000000000..ddb05de0de --- /dev/null +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/IgnoreField.java @@ -0,0 +1,17 @@ +package org.biojava.nbio.structure.io.mmcif.model; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Annotation indicating that a specific field of a bean should be ignored + * @author Spencer Bliven + * + */ +@Target(value=ElementType.FIELD) +@Retention(value=RetentionPolicy.RUNTIME) +public @interface IgnoreField { + +} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/PdbxStructOperList.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/PdbxStructOperList.java index 5fc6d92f43..34effb0657 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/PdbxStructOperList.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/PdbxStructOperList.java @@ -30,12 +30,31 @@ import java.io.Serializable; import java.util.Arrays; +/** + * The bean for pdbx_struct_oper_list category + *

+ * _pdbx_struct_oper_list.id 
+ * _pdbx_struct_oper_list.type 
+ * _pdbx_struct_oper_list.symmetry_operation
+ * _pdbx_struct_oper_list.matrix[1][1] 
+ * _pdbx_struct_oper_list.matrix[1][2] 
+ * _pdbx_struct_oper_list.matrix[1][3] 
+ * _pdbx_struct_oper_list.vector[1] 
+ * _pdbx_struct_oper_list.matrix[2][1] 
+ * _pdbx_struct_oper_list.matrix[2][2] 
+ * _pdbx_struct_oper_list.matrix[2][3] 
+ * _pdbx_struct_oper_list.vector[2] 
+ * _pdbx_struct_oper_list.matrix[3][1] 
+ * _pdbx_struct_oper_list.matrix[3][2] 
+ * _pdbx_struct_oper_list.matrix[3][3] 
+ * _pdbx_struct_oper_list.vector[3] 
+ * _pdbx_struct_oper_list.name 
+ * 
+ */ @XmlAccessorType(XmlAccessType.PROPERTY) public class PdbxStructOperList implements Serializable{ - /** - * - */ + private static final long serialVersionUID = 8933552854747969787L; @Override @@ -48,14 +67,53 @@ public String toString() { private String id; private String type; - + + private String symmetry_operation; + + @CIFLabel(label="matrix[1][1]") + String matrix11; + @CIFLabel(label="matrix[1][2]") + String matrix12; + @CIFLabel(label="matrix[1][3]") + String matrix13; + + @CIFLabel(label="vector[1]") + String vector1; + + @CIFLabel(label="matrix[2][1]") + String matrix21; + @CIFLabel(label="matrix[2][2]") + String matrix22; + @CIFLabel(label="matrix[2][3]") + String matrix23; + + @CIFLabel(label="vector[2]") + String vector2; + + @CIFLabel(label="matrix[3][1]") + String matrix31; + @CIFLabel(label="matrix[3][2]") + String matrix32; + @CIFLabel(label="matrix[3][3]") + String matrix33; + + @CIFLabel(label="vector[3]") + String vector3; + + String name; + + + // from here fields that are not in the cif category + + @IgnoreField private Matrix matrix; - + @IgnoreField private double[] vector; public PdbxStructOperList(){ matrix = Matrix.identity(3,3); + vector = new double[3]; } @XmlAttribute @@ -91,35 +149,66 @@ public void setId(String id) { this.id = id; } - public void setMatrix11(double val){ - matrix.set(0,0,val); + public void setMatrix11(String val){ + matrix.set(0,0,Double.parseDouble(val)); } - public void setMatrix21(double val){ - matrix.set(1,0,val); + public void setMatrix21(String val){ + matrix.set(1,0,Double.parseDouble(val)); } - public void setMatrix31(double val){ - matrix.set(2,0,val); + public void setMatrix31(String val){ + matrix.set(2,0,Double.parseDouble(val)); } - public void setMatrix12(double val){ - matrix.set(0,1,val); + public void setMatrix12(String val){ + matrix.set(0,1,Double.parseDouble(val)); + } + public void setMatrix22(String val){ + matrix.set(1,1,Double.parseDouble(val)); } - public void setMatrix22(double val){ - matrix.set(1,1,val); + public void setMatrix32(String val){ + matrix.set(2,1,Double.parseDouble(val)); } - public void setMatrix32(double val){ - matrix.set(2,1,val); + public void setMatrix13(String val){ + matrix.set(0,2,Double.parseDouble(val)); } - public void setMatrix13(double val){ - matrix.set(0,2,val); + public void setMatrix23(String val){ + matrix.set(1,2,Double.parseDouble(val)); } - public void setMatrix23(double val){ - matrix.set(1,2,val); + public void setMatrix33(String val){ + matrix.set(2,2,Double.parseDouble(val)); } - public void setMatrix33(double val){ - matrix.set(2,2,val); + + public void setName(String name) { + this.name = name; } + public String getVector1() { + return vector1; + } + public void setVector1(String vector1) { + vector[0] = Double.parseDouble(vector1); + } + public String getVector2() { + return vector2; + } + public void setVector2(String vector2) { + vector[1] = Double.parseDouble(vector2); + } + public String getVector3() { + return vector3; + } + public void setVector3(String vector3) { + vector[2] = Double.parseDouble(vector3); + } + public String getName() { + return name; + } + public String getSymmetry_operation() { + return symmetry_operation; + } + public void setSymmetry_operation(String symmetry_operation) { + this.symmetry_operation = symmetry_operation; + } @XmlElement public double getMatrix11(){ return matrix.get(0,0); diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/Refine.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/Refine.java index 3c7299e542..dceb35b5ac 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/Refine.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/Refine.java @@ -45,7 +45,18 @@ public class Refine { String occupancy_min; String occupancy_max; String B_iso_mean; - String[][] aniso_B; + @CIFLabel(label="aniso_B[1][1]") + String aniso_B11; + @CIFLabel(label="aniso_B[2][2]") + String aniso_B22; + @CIFLabel(label="aniso_B[3][3]") + String aniso_B33; + @CIFLabel(label="aniso_B[1][2]") + String aniso_B12; + @CIFLabel(label="aniso_B[1][3]") + String aniso_B13; + @CIFLabel(label="aniso_B[2][3]") + String aniso_B23; String solvent_model_details ; String solvent_model_param_ksol; String solvent_model_param_bsol; @@ -87,7 +98,7 @@ public class Refine { String ls_number_reflns_R_work; public Refine(){ - aniso_B = new String[3][3]; + //aniso_B = new String[3][3]; } public String getEntry_id() { @@ -284,14 +295,6 @@ public void setB_iso_mean(String b_iso_mean) { B_iso_mean = b_iso_mean; } - public String[][] getAniso_B() { - return aniso_B; - } - - public void setAniso_B(String[][] aniso_B) { - this.aniso_B = aniso_B; - } - public String getSolvent_model_details() { return solvent_model_details; } @@ -603,5 +606,53 @@ public void setLs_number_reflns_R_work(String ls_number_reflns_R_work) { this.ls_number_reflns_R_work = ls_number_reflns_R_work; } + public String getAniso_B11() { + return aniso_B11; + } + + public void setAniso_B11(String aniso_B11) { + this.aniso_B11 = aniso_B11; + } + + public String getAniso_B22() { + return aniso_B22; + } + + public void setAniso_B22(String aniso_B22) { + this.aniso_B22 = aniso_B22; + } + + public String getAniso_B33() { + return aniso_B33; + } + + public void setAniso_B33(String aniso_B33) { + this.aniso_B33 = aniso_B33; + } + + public String getAniso_B12() { + return aniso_B12; + } + + public void setAniso_B12(String aniso_B12) { + this.aniso_B12 = aniso_B12; + } + + public String getAniso_B13() { + return aniso_B13; + } + + public void setAniso_B13(String aniso_B13) { + this.aniso_B13 = aniso_B13; + } + + public String getAniso_B23() { + return aniso_B23; + } + + public void setAniso_B23(String aniso_B23) { + this.aniso_B23 = aniso_B23; + } + } diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/StructNcsOper.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/StructNcsOper.java index 55f0cfbdfc..293c9e4d09 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/StructNcsOper.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/StructNcsOper.java @@ -20,25 +20,78 @@ */ package org.biojava.nbio.structure.io.mmcif.model; -import javax.vecmath.Matrix4d; /** * A class containing the _struct_ncs_oper data - * @author duarte_j - * + * + *
+ *  _struct_ncs_oper.id 
+ *  _struct_ncs_oper.code 
+ *  _struct_ncs_oper.details 
+ * 	_struct_ncs_oper.matrix[1][1] 
+ *	_struct_ncs_oper.matrix[1][2] 
+ *	_struct_ncs_oper.matrix[1][3] 
+ *	_struct_ncs_oper.matrix[2][1] 
+ *	_struct_ncs_oper.matrix[2][2] 
+ *	_struct_ncs_oper.matrix[2][3] 
+ *	_struct_ncs_oper.matrix[3][1] 
+ *	_struct_ncs_oper.matrix[3][2] 
+ *	_struct_ncs_oper.matrix[3][3] 
+ *	_struct_ncs_oper.vector[1] 
+ *	_struct_ncs_oper.vector[2] 
+ *	_struct_ncs_oper.vector[3] 
+ * 
+ * + * @author Jose Duarte */ public class StructNcsOper extends AbstractBean { - private int id; + private String id; private String code; private String details; - private Matrix4d operator; - - public int getId() { + + @CIFLabel(label="matrix[1][1]") + private String matrix11; + + @CIFLabel(label="matrix[1][2]") + private String matrix12; + + @CIFLabel(label="matrix[1][3]") + private String matrix13; + + @CIFLabel(label="matrix[2][1]") + private String matrix21; + + @CIFLabel(label="matrix[2][2]") + private String matrix22; + + @CIFLabel(label="matrix[2][3]") + private String matrix23; + + @CIFLabel(label="matrix[3][1]") + private String matrix31; + + @CIFLabel(label="matrix[3][2]") + private String matrix32; + + @CIFLabel(label="matrix[3][3]") + private String matrix33; + + @CIFLabel(label="vector[1]") + private String vector1; + + @CIFLabel(label="vector[2]") + private String vector2; + + @CIFLabel(label="vector[3]") + private String vector3; + + + public String getId() { return id; } - public void setId(int id) { + public void setId(String id) { this.id = id; } @@ -58,11 +111,172 @@ public void setDetails(String details) { this.details = details; } - public Matrix4d getOperator() { - return operator; + /** + * @return the matrix11 + */ + public String getMatrix11() { + return matrix11; + } + + /** + * @param matrix11 the matrix11 to set + */ + public void setMatrix11(String matrix11) { + this.matrix11 = matrix11; + } + + /** + * @return the matrix12 + */ + public String getMatrix12() { + return matrix12; + } + + /** + * @param matrix12 the matrix12 to set + */ + public void setMatrix12(String matrix12) { + this.matrix12 = matrix12; + } + + /** + * @return the matrix13 + */ + public String getMatrix13() { + return matrix13; + } + + /** + * @param matrix13 the matrix13 to set + */ + public void setMatrix13(String matrix13) { + this.matrix13 = matrix13; + } + + /** + * @return the matrix21 + */ + public String getMatrix21() { + return matrix21; + } + + /** + * @param matrix21 the matrix21 to set + */ + public void setMatrix21(String matrix21) { + this.matrix21 = matrix21; + } + + /** + * @return the matrix22 + */ + public String getMatrix22() { + return matrix22; + } + + /** + * @param matrix22 the matrix22 to set + */ + public void setMatrix22(String matrix22) { + this.matrix22 = matrix22; + } + + /** + * @return the matrix23 + */ + public String getMatrix23() { + return matrix23; + } + + /** + * @param matrix23 the matrix23 to set + */ + public void setMatrix23(String matrix23) { + this.matrix23 = matrix23; } - public void setOperator(Matrix4d operator) { - this.operator = operator; + /** + * @return the matrix31 + */ + public String getMatrix31() { + return matrix31; } + + /** + * @param matrix31 the matrix31 to set + */ + public void setMatrix31(String matrix31) { + this.matrix31 = matrix31; + } + + /** + * @return the matrix32 + */ + public String getMatrix32() { + return matrix32; + } + + /** + * @param matrix32 the matrix32 to set + */ + public void setMatrix32(String matrix32) { + this.matrix32 = matrix32; + } + + /** + * @return the matrix33 + */ + public String getMatrix33() { + return matrix33; + } + + /** + * @param matrix33 the matrix33 to set + */ + public void setMatrix33(String matrix33) { + this.matrix33 = matrix33; + } + + /** + * @return the vector1 + */ + public String getVector1() { + return vector1; + } + + /** + * @param vector1 the vector1 to set + */ + public void setVector1(String vector1) { + this.vector1 = vector1; + } + + /** + * @return the vector2 + */ + public String getVector2() { + return vector2; + } + + /** + * @param vector2 the vector2 to set + */ + public void setVector2(String vector2) { + this.vector2 = vector2; + } + + /** + * @return the vector3 + */ + public String getVector3() { + return vector3; + } + + /** + * @param vector3 the vector3 to set + */ + public void setVector3(String vector3) { + this.vector3 = vector3; + } + } diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/Symmetry.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/Symmetry.java index 09597aaa05..d91ef11718 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/Symmetry.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/Symmetry.java @@ -20,13 +20,13 @@ */ package org.biojava.nbio.structure.io.mmcif.model; + public class Symmetry extends AbstractBean { String entry_id; - // next 2 fields have actually hyphen between H and M i.e. H-M - // but java does not allow hyphens in variable names - // this will have to be solved elsewhere down the line + @CIFLabel(label="space_group_name_H-M") String space_group_name_H_M; + @CIFLabel(label="pdbx_full_space_group_name_H-M") String pdbx_full_space_group_name_H_M; String cell_setting; String Int_Tables_number; diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestMMCIFWriting.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestMMCIFWriting.java index 377297c2e9..5fda97a2af 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestMMCIFWriting.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestMMCIFWriting.java @@ -33,9 +33,12 @@ import org.biojava.nbio.structure.StructureException; import org.biojava.nbio.structure.StructureIO; import org.biojava.nbio.structure.align.util.AtomCache; +import org.biojava.nbio.structure.io.mmcif.MMCIFFileTools; import org.biojava.nbio.structure.io.mmcif.MMcifParser; import org.biojava.nbio.structure.io.mmcif.SimpleMMcifConsumer; import org.biojava.nbio.structure.io.mmcif.SimpleMMcifParser; +import org.biojava.nbio.structure.io.mmcif.model.CIFLabel; +import org.biojava.nbio.structure.io.mmcif.model.IgnoreField; import org.junit.Test; public class TestMMCIFWriting { @@ -55,7 +58,7 @@ public void test1SMT() throws IOException, StructureException { Structure originalStruct = StructureIO.getStructure("1SMT"); File outputFile = File.createTempFile("biojava_testing_", ".cif"); - + outputFile.deleteOnExit(); FileWriter fw = new FileWriter(outputFile); fw.write(originalStruct.toMMCIF()); @@ -93,6 +96,8 @@ public void test1SMT() throws IOException, StructureException { //assertEquals(origChain.getSeqResGroups().size(), readChain.getSeqResGroups().size()); } + // Test cell and symmetry + assertEquals(originalStruct.getCrystallographicInfo().getSpaceGroup(),readStruct.getCrystallographicInfo().getSpaceGroup()); } /** @@ -115,6 +120,7 @@ public void test2N3J() throws IOException, StructureException { Structure originalStruct = StructureIO.getStructure("2N3J"); File outputFile = File.createTempFile("biojava_testing_", ".cif"); + outputFile.deleteOnExit(); FileWriter fw = new FileWriter(outputFile); @@ -179,6 +185,7 @@ public void test1A2C() throws IOException, StructureException { Structure originalStruct = StructureIO.getStructure("1A2C"); File outputFile = File.createTempFile("biojava_testing_", ".cif"); + outputFile.deleteOnExit(); FileWriter fw = new FileWriter(outputFile); @@ -218,5 +225,44 @@ public void test1A2C() throws IOException, StructureException { } } + + private static class DemoBean { + @IgnoreField + String not_a_field; + + @SuppressWarnings("unused")//used by reflection + String default_field; + + @CIFLabel(label="custom_label") + String custom_field; + public void setNot_a_field(String not_a_field) { + this.not_a_field = not_a_field; + } + public void setDefault_field(String default_field) { + this.default_field = default_field; + } + public void setCustom_field(String custom_field) { + this.custom_field = custom_field; + } + } + + @Test + public void testBeanAnnotations() { + DemoBean bean = new DemoBean(); + bean.setCustom_field("custom_field"); + bean.setDefault_field(null); + bean.setNot_a_field("not_a_field"); + + + // Test (1) should have custom_label (@CIFLabel) + // (2) shouldn't have not_a_field (@IgnoreField) + String newline = System.getProperty("line.separator"); + String mmcif = MMCIFFileTools.toMMCIF("_demo", bean); + String expected = + "_demo.default_field ?" + newline + + "_demo.custom_label custom_field" + newline + + "#" + newline; + assertEquals(expected, mmcif); + } } diff --git a/biojava-survival/pom.xml b/biojava-survival/pom.xml index 3b57f7242f..8d2875b813 100644 --- a/biojava-survival/pom.xml +++ b/biojava-survival/pom.xml @@ -4,7 +4,7 @@ org.biojava biojava - 4.2.2 + 4.2.3 biojava-survival diff --git a/biojava-ws/pom.xml b/biojava-ws/pom.xml index fb469e0d69..ecc74b660e 100644 --- a/biojava-ws/pom.xml +++ b/biojava-ws/pom.xml @@ -3,7 +3,7 @@ biojava org.biojava - 4.2.2 + 4.2.3 biojava-ws biojava-ws @@ -19,7 +19,7 @@ org.biojava biojava-core - 4.2.2 + 4.2.3 compile diff --git a/pom.xml b/pom.xml index 864b9d9ff4..2b575db99b 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ org.biojava biojava pom - 4.2.2 + 4.2.3 biojava BioJava is an open-source project dedicated to providing a Java framework for processing biological data. It provides analytical and statistical routines, parsers for common file formats and allows the @@ -44,7 +44,7 @@ scm:git:git@github.com:biojava/biojava.git https://github.com/biojava/biojava - biojava-4.2.2 + biojava-4.2.3