Skip to content

Commit e8622df

Browse files
committed
fixing a problem with de-serializing list of strings
1 parent 0cda53d commit e8622df

8 files changed

Lines changed: 5799 additions & 5290 deletions

File tree

biojava3-structure/src/main/java/org/biojava/bio/structure/io/PDBSRSReader.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@
4040
* if no matching PDB code found, returns null
4141
*
4242
* @author Andreas Prlic
43-
*
43+
* @deprecated
4444
*/
45-
46-
public class PDBSRSReader implements StructureIO {
45+
@Deprecated
46+
public class PDBSRSReader {
4747

4848

4949
private BufferedReader getBufferedReader(String pdbId)

biojava3-structure/src/main/java/org/biojava/bio/structure/io/StructureIO.java

Lines changed: 0 additions & 55 deletions
This file was deleted.

biojava3-structure/src/main/java/org/biojava/bio/structure/io/StructureIOFile.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
* and adds a few File specific methods.
3434
* @author Andreas Prlic
3535
*/
36-
public interface StructureIOFile extends StructureIO {
36+
public interface StructureIOFile {
3737

3838
/** Set path to file / connection string to db.
3939
* This is for installations of PDB/mmCif where all files are located in one directory.

biojava3-structure/src/main/java/org/biojava/bio/structure/xtal/SpaceGroup.java

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,14 @@
1616
import javax.xml.bind.Marshaller;
1717
import javax.xml.bind.annotation.XmlAccessType;
1818
import javax.xml.bind.annotation.XmlAccessorType;
19+
import javax.xml.bind.annotation.XmlElement;
20+
import javax.xml.bind.annotation.XmlElementWrapper;
1921
import javax.xml.bind.annotation.XmlRootElement;
22+
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
2023

2124
import org.biojava.bio.structure.jama.EigenvalueDecomposition;
2225
import org.biojava.bio.structure.jama.Matrix;
26+
import org.biojava.bio.structure.xtal.io.TransfAlgebraicAdapter;
2327

2428

2529
/**
@@ -67,9 +71,9 @@ public class SpaceGroup implements Serializable {
6771

6872
private SpaceGroup(){
6973
// required by JAXB
70-
74+
7175
}
72-
76+
7377
public SpaceGroup(int id, int multiplicity, int primitiveMultiplicity, String shortSymbol, String altShortSymbol, BravaisLattice bravLattice) {
7478
this.id = id;
7579
this.multiplicity = multiplicity;
@@ -88,23 +92,29 @@ public void addTransformation(String transfAlgebraic) {
8892
}
8993

9094
protected void initializeCellTranslations() {
95+
if ( cellTranslations != null && cellTranslations.length >0) {
96+
// we already initialized this
97+
return;
98+
}
9199
cellTranslations = new Vector3d[multiplicity/primitiveMultiplicity];
92100
cellTranslations[0] = new Vector3d(0,0,0);
93-
101+
94102
if ( transformations == null){
95103
System.err.println("transformations == null" + this.toXML());
96104
}
97-
105+
98106
if (multiplicity==primitiveMultiplicity) {
99107
return;
100108
}
101109
int fold = multiplicity/primitiveMultiplicity;
102-
103-
104-
110+
111+
112+
105113
for (int n=1;n<fold;n++) {
106-
if ( transformations.size() < (n* primitiveMultiplicity))
107-
System.out.println(this.toXML());
114+
if ( transformations.size() < (n* primitiveMultiplicity)){
115+
System.err.println("WARNING number of transformations < " +(n*primitiveMultiplicity));
116+
System.err.println(this.toXML());
117+
}
108118
Matrix4d t = transformations.get(n*primitiveMultiplicity);
109119
cellTranslations[n] = new Vector3d(t.m03,t.m13,t.m23);
110120
}
@@ -550,8 +560,8 @@ public String toString() {
550560
}
551561

552562
public String toXML(){
553-
554-
563+
564+
555565
JAXBContext jaxbContextStringSortedSet = null;
556566

557567
try {
@@ -570,7 +580,7 @@ public String toXML(){
570580
Marshaller m = jaxbContextStringSortedSet.createMarshaller();
571581

572582
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
573-
583+
574584
m.marshal( this, ps);
575585

576586

@@ -581,24 +591,27 @@ public String toXML(){
581591
return baos.toString();
582592
}
583593

594+
//@XmlElementWrapper(name="transfAlgebraicList", namespace="http://www.biojava.org")
595+
//@XmlElement
596+
@XmlJavaTypeAdapter(TransfAlgebraicAdapter.class)
584597
public List<String> getTransfAlgebraic() {
585598
return transfAlgebraic;
586599
}
587600

588601
public void setTransfAlgebraic(List<String> transfAlgebraic) {
589-
590-
if ( transformations == null)
602+
//System.out.println("setting transfAlgebraic " + transfAlgebraic);
603+
if ( transformations == null || transformations.size() == 0)
591604
transformations = new ArrayList<Matrix4d>(transfAlgebraic.size());
592-
593-
if ( this.transfAlgebraic == null)
605+
606+
if ( this.transfAlgebraic == null || this.transfAlgebraic.size() == 0)
594607
this.transfAlgebraic = new ArrayList<String>(transfAlgebraic.size());
595-
608+
596609
for ( String transf : transfAlgebraic){
597610
addTransformation(transf);
598611
}
599612
}
600613

601-
614+
602615
public int[] getAxisTypes() {
603616
return axisTypes;
604617
}
@@ -640,6 +653,7 @@ public void setId(int id) {
640653
}
641654

642655
public void setMultiplicity(int multiplicity) {
656+
643657
this.multiplicity = multiplicity;
644658
}
645659

biojava3-structure/src/main/java/org/biojava/bio/structure/xtal/SymoplibParser.java

Lines changed: 45 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
package org.biojava.bio.structure.xtal;
22

33
import java.io.BufferedReader;
4+
import java.io.File;
5+
import java.io.FileInputStream;
6+
import java.io.FileOutputStream;
47
import java.io.IOException;
58
import java.io.InputStream;
69
import java.io.InputStreamReader;
10+
import java.io.PrintStream;
11+
import java.net.URL;
712
import java.util.HashMap;
813
import java.util.TreeMap;
914
import java.util.regex.Matcher;
@@ -24,15 +29,24 @@
2429
*/
2530
public class SymoplibParser {
2631
private static final String newline = System.getProperty("line.separator");
27-
32+
2833
private static final String SPACE_GROUPS_FILE = "org/biojava/bio/structure/xtal/spacegroups.xml";
29-
34+
3035
private static final Pattern namePat = Pattern.compile(".*\\s([A-Z]+)(\\s'.+')?\\s+'(.+)'.*");
31-
32-
private static final TreeMap<Integer, SpaceGroup> sgs = parseSpaceGroupsXML();
33-
36+
37+
private static TreeMap<Integer, SpaceGroup> sgs = null ;
38+
39+
40+
static {
41+
try {
42+
sgs = parseSpaceGroupsXML();
43+
} catch (Exception e){
44+
e.printStackTrace();
45+
}
46+
}
47+
3448
private static HashMap<String, SpaceGroup> name2sgs; // map for lookups based on short names
35-
49+
3650
/**
3751
* Gets the space group for the given standard identifier.
3852
* See for example http://en.wikipedia.org/wiki/Space_group
@@ -42,53 +56,54 @@ public class SymoplibParser {
4256
public static SpaceGroup getSpaceGroup(int id) {
4357
return sgs.get(id);
4458
}
45-
46-
59+
60+
4761
/** Load all SpaceGroup information from the file spacegroups.xml
4862
*
4963
* @return a map providing information for all spacegroups
5064
*/
5165
private static TreeMap<Integer, SpaceGroup> parseSpaceGroupsXML() {
52-
66+
5367
InputStream spaceGroupIS = SymoplibParser.class.getClassLoader().getResourceAsStream(SPACE_GROUPS_FILE);
54-
68+
5569
if ( spaceGroupIS == null) {
5670
System.err.println("Could not find resource: " + SPACE_GROUPS_FILE + ". This probably means that your biojava.jar file is corrupt or incorrectly built.");
5771
return null;
5872
}
59-
73+
6074
TreeMap<Integer, SpaceGroup> map = new TreeMap<Integer, SpaceGroup>();
61-
75+
6276
map = parseSpaceGroupsXML(spaceGroupIS);
63-
77+
6478
name2sgs = new HashMap<String, SpaceGroup>();
65-
79+
6680
for (SpaceGroup sg:map.values()) {
81+
6782
sg.initializeCellTranslations();
6883
name2sgs.put(sg.getShortSymbol(), sg);
6984
if (sg.getAltShortSymbol()!=null) {
7085
// we add also alternative name to map so we can look it up
7186
name2sgs.put(sg.getAltShortSymbol(), sg);
7287
}
7388
}
74-
89+
7590
return map;
76-
91+
7792
}
7893

79-
94+
8095
/** Load all SpaceGroup information from the file spacegroups.xml
8196
*
8297
* @return a map providing information for all spacegroups
8398
*/
8499
public static TreeMap<Integer, SpaceGroup> parseSpaceGroupsXML(
85100
InputStream spaceGroupIS) {
86-
101+
87102
String xml = convertStreamToString(spaceGroupIS);
88-
103+
89104
SpaceGroupMapRoot spaceGroups = SpaceGroupMapRoot.fromXML(xml);
90105
return spaceGroups.getMapProperty();
91-
106+
92107
}
93108

94109

@@ -99,7 +114,7 @@ private static String convertStreamToString(InputStream stream){
99114
String line = null;
100115
try {
101116
while ((line = reader.readLine()) != null) {
102-
sb.append(line).append(newline);
117+
sb.append(line).append(newline);
103118
}
104119
} catch (IOException e) {
105120
//e.printStackTrace();
@@ -122,23 +137,23 @@ private static String convertStreamToString(InputStream stream){
122137
*/
123138
public static SpaceGroup getSpaceGroup(String shortName) {
124139
if (shortName==null) return null;
125-
140+
126141
// PDB uses group "P 1-" for 13 racemic mixture entries (as of Sep2011), e.g. 3e7r
127142
// they call the space group "P 1-" unusually (symop.lib and everyone else call it "P -1")
128143
if (shortName.equals("P 1-")) shortName="P -1";
129-
144+
130145
// enantiomorphic space groups contain sometime letters indicating glide planes which should always be lower case
131146
// in some PDB entries like 4gwv they are in upper case, we fix that here: convert any non-first letter to lower case
132147
shortName = shortName.substring(0, 1)+shortName.substring(1).toLowerCase();
133-
148+
134149
return name2sgs.get(shortName);
135150
}
136-
151+
137152
public static TreeMap<Integer,SpaceGroup> getAllSpaceGroups() {
138153
return sgs;
139154
}
140-
141-
155+
156+
142157
/** A parser for the symop.lib file provided by CCP4. Note: this file is not getting re-distributed by BioJava.
143158
* It can be downloaded from:
144159
*
@@ -166,7 +181,7 @@ public static TreeMap<Integer,SpaceGroup> parseSymopLib(InputStream symoplibIS)
166181
name2sgs.put(currentSG.getAltShortSymbol(), currentSG);
167182
}
168183
}
169-
184+
170185
int idxFirstSpace = line.indexOf(' ');
171186
int idxSecondSpace = line.indexOf(' ',idxFirstSpace+1);
172187
int idxThirdSpace = line.indexOf(' ',idxSecondSpace+1);
@@ -196,7 +211,7 @@ public static TreeMap<Integer,SpaceGroup> parseSymopLib(InputStream symoplibIS)
196211
// we add also alternative name to map so we can look it up
197212
name2sgs.put(currentSG.getAltShortSymbol(), currentSG);
198213
}
199-
214+
200215
} catch (IOException e) {
201216
e.printStackTrace();
202217
System.err.println("Fatal error! Can't read symop.lib file. Error: "+e.getMessage()+". ");
@@ -208,7 +223,6 @@ public static TreeMap<Integer,SpaceGroup> parseSymopLib(InputStream symoplibIS)
208223
}
209224
return map;
210225
}
211-
212-
226+
213227

214228
}

biojava3-structure/src/main/java/org/biojava/bio/structure/xtal/io/SpaceGroupMapElements.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,11 @@
2929

3030
public class SpaceGroupMapElements {
3131

32-
@XmlElement public Integer key;
33-
@XmlElement public SpaceGroup value;
32+
@XmlElement
33+
public Integer key;
34+
35+
@XmlElement(name="SpaceGroup", namespace="http://www.biojava.org")
36+
public SpaceGroup value;
3437

3538
private SpaceGroupMapElements(){
3639

0 commit comments

Comments
 (0)