Skip to content

Commit b122e60

Browse files
committed
Removing duplicate PDB_DIR definitions.
Everything should use UserConfiguration.PDB_DIR
1 parent fa68c28 commit b122e60

6 files changed

Lines changed: 45 additions & 78 deletions

File tree

biojava3-structure-gui/src/main/java/org/biojava/bio/structure/align/gui/ConfigPDBInstallPanel.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,6 @@ public class ConfigPDBInstallPanel extends JPanel
5858
*/
5959
private static final long serialVersionUID = -1055193854675583808L;
6060

61-
/** the system property PDB_DIR can be used to configure the
62-
* default location for PDB files.
63-
*/
64-
public static final String PDB_DIR = "PDB_DIR";
65-
6661
JCheckBox pdbSplit;
6762
JCheckBox fromFtp;
6863
JComboBox fileType;
@@ -84,7 +79,7 @@ private ConfigPDBInstallPanel(){
8479

8580
pdbDir = new JTextField(20);
8681

87-
String conf = System.getProperty(PDB_DIR);
82+
String conf = System.getProperty(UserConfiguration.PDB_DIR);
8883
if ( conf != null){
8984
pdbDir.setText(conf);
9085
}

biojava3-structure-gui/src/main/java/org/biojava/bio/structure/align/webstart/WebStartMain.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
import org.biojava.bio.structure.align.seq.SmithWaterman3Daligner;
4949
import org.biojava.bio.structure.align.util.AtomCache;
5050
import org.biojava.bio.structure.align.util.UserConfiguration;
51-
import org.biojava.bio.structure.gui.util.PDBDirPanel;
5251
import org.biojava.bio.structure.io.PDBFileReader;
5352

5453
public class WebStartMain
@@ -136,7 +135,7 @@ public void run() {
136135

137136
UserConfiguration config = getWebStartConfig();
138137

139-
System.setProperty(PDBDirPanel.PDB_DIR,config.getPdbFilePath());
138+
System.setProperty(UserConfiguration.PDB_DIR,config.getPdbFilePath());
140139
System.out.println("using PDB file path: " + config.getPdbFilePath());
141140

142141
AtomCache cache = new AtomCache(config);
@@ -265,7 +264,7 @@ public static UserConfiguration getWebStartConfig(){
265264
public static UserConfiguration getDefaultConfig(){
266265
userConfig = new UserConfiguration();
267266

268-
String pdbDir = System.getProperty(PDBDirPanel.PDB_DIR);
267+
String pdbDir = System.getProperty(UserConfiguration.PDB_DIR);
269268
if ( pdbDir != null) {
270269
userConfig.setPdbFilePath(pdbDir);
271270

@@ -294,7 +293,7 @@ public static UserConfiguration requestUserConfig(){
294293
//UserConfiguration config = new UserConfiguration();
295294
userConfig = new UserConfiguration();
296295

297-
String pdbDir = System.getProperty(PDBDirPanel.PDB_DIR);
296+
String pdbDir = System.getProperty(UserConfiguration.PDB_DIR);
298297
if ( pdbDir != null) {
299298
userConfig.setPdbFilePath(pdbDir);
300299
return userConfig;
@@ -324,7 +323,7 @@ public static UserConfiguration requestUserConfig(){
324323
System.err.println("did not provide directory, going on level higher! " + file.getAbsolutePath());
325324
file = file.getParentFile();
326325
}
327-
System.setProperty(PDBDirPanel.PDB_DIR, file.getAbsolutePath());
326+
System.setProperty(UserConfiguration.PDB_DIR, file.getAbsolutePath());
328327
userConfig.setPdbFilePath(file.getAbsolutePath());
329328

330329
return userConfig;

biojava3-structure-gui/src/main/java/org/biojava/bio/structure/gui/util/PDBDirPanel.java

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.io.File;
3030
import java.io.IOException;
3131
import java.util.logging.Logger;
32+
3233
import javax.swing.AbstractAction;
3334
import javax.swing.Action;
3435
import javax.swing.BorderFactory;
@@ -39,11 +40,11 @@
3940
import javax.swing.JPanel;
4041
import javax.swing.JTextField;
4142

42-
4343
import org.biojava.bio.structure.Chain;
4444
import org.biojava.bio.structure.Structure;
4545
import org.biojava.bio.structure.StructureException;
4646
import org.biojava.bio.structure.StructureImpl;
47+
import org.biojava.bio.structure.align.util.UserConfiguration;
4748
import org.biojava.bio.structure.io.PDBFileReader;
4849

4950
/** A class to define where a structure for the alignment is coming from
@@ -68,12 +69,6 @@ public class PDBDirPanel
6869
JTextField c1;
6970
JTextField c2;
7071

71-
/** the system property PDB_DIR can be used to configure the
72-
* default location for PDB files.
73-
*/
74-
public static final String PDB_DIR = "PDB_DIR";
75-
76-
7772
public static Logger logger = Logger.getLogger("org.biojava");
7873

7974
/** load the PDB files from a local directory
@@ -85,7 +80,7 @@ public PDBDirPanel() {
8580

8681
pdbDir = new JTextField(20);
8782

88-
String conf = System.getProperty(PDB_DIR);
83+
String conf = System.getProperty(UserConfiguration.PDB_DIR);
8984
if ( conf != null){
9085
pdbDir.setText(conf);
9186
}
@@ -97,12 +92,12 @@ public PDBDirPanel() {
9792

9893
f1 = new JTextField(pdbfSize);
9994
c1 = new JTextField(1);
100-
JPanel p1 = getPDBFilePanel(1,f1,c1);
95+
JPanel p1 = getPDBFilePanel(1,f1,c1);
10196
vBox.add(p1);
10297

10398
f2 = new JTextField(pdbfSize);
10499
c2 = new JTextField(1);
105-
JPanel p2 = getPDBFilePanel(2, f2,c2);
100+
JPanel p2 = getPDBFilePanel(2, f2,c2);
106101
vBox.add(p2);
107102

108103

@@ -127,14 +122,10 @@ private Structure fromPDB(JTextField f, JTextField c) throws StructureException{
127122

128123
// load them from the file system
129124

130-
PDBFileReader reader = new PDBFileReader();
131125

132126

133127
String dir = pdbDir.getText();
134-
if ( dir != null){
135-
System.setProperty(PDB_DIR, dir);
136-
}
137-
reader.setPath(dir);
128+
PDBFileReader reader = new PDBFileReader(dir);
138129

139130
if ( debug )
140131
System.out.println("dir: " + dir);

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import org.biojava.bio.structure.Chain;
66
import org.biojava.bio.structure.Group;
77
import org.biojava.bio.structure.Structure;
8+
import org.biojava.bio.structure.align.util.UserConfiguration;
89
import org.biojava.bio.structure.io.FileParsingParameters;
910
import org.biojava.bio.structure.io.PDBFileReader;
1011
import org.biojava.bio.structure.io.mmcif.AllChemCompProvider;
@@ -44,7 +45,8 @@ public static void main(String[] args){
4445
// you can set the path to the local PDB installation either like this
4546
// reader.setPath(PDB_PATH);
4647
// or via
47-
//System.setProperty(AbstractUserArgumentProcessor.PDB_DIR,PDB_PATH);
48+
// by setting the PDB_PATH environmental variable or system property
49+
// when running the demo (e.g. -DPDB_DIR=/path/to/pdb)
4850

4951
if ( loadChemComp) {
5052

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

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -91,34 +91,18 @@ public static void main(String[] args) throws Exception {
9191
}
9292

9393
/**
94-
* Constructs a new MMCIFFileReader, initialising the extensions member variable.
95-
* The path is initialised in the same way as {@link UserConfiguration},
94+
* Constructs a new MMCIFFileReader, initializing the extensions member variable.
95+
* The path is initialized in the same way as {@link UserConfiguration},
9696
* i.e. to system property/environment variable {@link UserConfiguration#PDB_DIR}.
97-
* Both autoFetch and splitDir are initialised to false
97+
* Both autoFetch and splitDir are initialized to false
9898
*/
9999
public MMCIFFileReader(){
100-
extensions = new ArrayList<String>();
101-
extensions.add(".cif");
102-
extensions.add(".mmcif");
103-
extensions.add(".cif.gz");
104-
extensions.add(".mmcif.gz");
105-
106-
autoFetch = false;
107-
pdbDirectorySplit = false;
108-
109-
params = new FileParsingParameters();
110-
111-
112-
// initialising path from PDB_DIR property/environment variable
113-
UserConfiguration config = new UserConfiguration();
114-
path = new File(config.getPdbFilePath());
115-
logger.debug("Initialising from system property/environment variable to path: {}", path.toString());
116-
100+
this(null);
117101
}
118102

119103
/**
120-
* Constructs a new PDBFileReader, initialising the extensions member variable.
121-
* The path is initialised to the given path, both autoFetch and splitDir are initialised to false.
104+
* Constructs a new PDBFileReader, initializing the extensions member variable.
105+
* The path is initialized to the given path, both autoFetch and splitDir are initialized to false.
122106
*/
123107
public MMCIFFileReader(String path){
124108
extensions = new ArrayList<String>();
@@ -129,12 +113,17 @@ public MMCIFFileReader(String path){
129113

130114
autoFetch = false;
131115
pdbDirectorySplit = false;
132-
116+
133117
params = new FileParsingParameters();
134118

135-
119+
if( path == null) {
120+
UserConfiguration config = new UserConfiguration();
121+
path = config.getPdbFilePath();
122+
logger.debug("Initialising from system property/environment variable to path: {}", path.toString());
123+
} else {
124+
logger.debug("Initialising with path {}", path.toString());
125+
}
136126
this.path = new File(path);
137-
logger.debug("Initialising with path {}", path.toString());
138127
}
139128

140129
public void addExtension(String ext) {

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

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -261,35 +261,22 @@ public static void main(String[] args){
261261

262262

263263
/**
264-
* Constructs a new PDBFileReader, initialising the extensions member variable.
265-
* The path is initialised in the same way as {@link UserConfiguration},
264+
* Constructs a new PDBFileReader, initializing the extensions member variable.
265+
* The path is initialized in the same way as {@link UserConfiguration},
266266
* i.e. to system property/environment variable {@link UserConfiguration#PDB_DIR}.
267-
* Both autoFetch and splitDir are initialised to false
267+
* Both autoFetch and splitDir are initialized to false
268268
*/
269269
public PDBFileReader() {
270-
extensions = new ArrayList<String>();
271-
272-
extensions.add(".ent");
273-
extensions.add(".pdb");
274-
extensions.add(".ent.gz");
275-
extensions.add(".pdb.gz");
276-
extensions.add(".ent.Z");
277-
extensions.add(".pdb.Z");
278-
279-
autoFetch = false;
280-
pdbDirectorySplit = false;
281-
282-
params = new FileParsingParameters();
283-
284-
// initialising path from PDB_DIR property/environment variable
285-
UserConfiguration config = new UserConfiguration();
286-
path = new File(config.getPdbFilePath());
287-
logger.debug("Initialising from system property/environment variable to path: {}", path.toString());
270+
this(null);
288271
}
289272

290273
/**
291-
* Constructs a new PDBFileReader, initialising the extensions member variable.
292-
* The path is initialised to the given path, both autoFetch and splitDir are initialised to false.
274+
* Constructs a new PDBFileReader, initializing the extensions member variable.
275+
* The path is initialized to the given path, both autoFetch and splitDir are initialized to false.
276+
*
277+
* <p>If path is null, initialize using the system property/environment variable
278+
* {@link UserConfiguration#PDB_DIR}.
279+
* @param path Path to the PDB file directory
293280
*/
294281
public PDBFileReader(String path) {
295282
extensions = new ArrayList<String>();
@@ -301,14 +288,18 @@ public PDBFileReader(String path) {
301288
extensions.add(".ent.Z");
302289
extensions.add(".pdb.Z");
303290

304-
autoFetch = false;
291+
autoFetch = false;
305292
pdbDirectorySplit = false;
306293

307294
params = new FileParsingParameters();
308295

296+
if(path == null ) {
297+
path = new UserConfiguration().getPdbFilePath();
298+
logger.debug("Initializing from system property/environment variable to path: {}", path.toString());
299+
} else {
300+
logger.debug("Initialising with path {}", path.toString());
301+
}
309302
this.path = new File(path);
310-
logger.debug("Initialising with path {}", path.toString());
311-
312303
}
313304

314305

0 commit comments

Comments
 (0)