Skip to content

Commit 09e4165

Browse files
authored
Merge branch 'master' into issue582
2 parents 8d8b466 + be15fe1 commit 09e4165

5 files changed

Lines changed: 108 additions & 29 deletions

File tree

biojava-structure/src/main/java/org/biojava/nbio/structure/align/util/AlignmentTools.java

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ public static <S,T> Map<S,T> applyAlignment(Map<S, T> alignmentMap, Map<T,S> ide
282282
* @return
283283
*/
284284
public static int getSymmetryOrder(Map<Integer, Integer> alignment,
285-
final int maxSymmetry, final float minimumMetricChange) {
285+
final int maxSymmetry, final float minimumMetricChange) {
286286
return getSymmetryOrder(alignment, new IdentityMap<Integer>(), maxSymmetry, minimumMetricChange);
287287
}
288288
/**
@@ -321,7 +321,7 @@ public static int getSymmetryOrder(Map<Integer, Integer> alignment,
321321
* @see IdentityMap For a simple identity function
322322
*/
323323
public static int getSymmetryOrder(Map<Integer, Integer> alignment, Map<Integer,Integer> identity,
324-
final int maxSymmetry, final float minimumMetricChange) {
324+
final int maxSymmetry, final float minimumMetricChange) {
325325
List<Integer> preimage = new ArrayList<Integer>(alignment.keySet()); // currently unmodified
326326
List<Integer> image = new ArrayList<Integer>(preimage);
327327

@@ -566,7 +566,7 @@ public boolean containsKey(Object key) {
566566
* @see AlignmentTools#replaceOptAln(AFPChain, Atom[], Atom[], Map)
567567
*/
568568
public static AFPChain createAFPChain(Atom[] ca1, Atom[] ca2,
569-
ResidueNumber[] aligned1, ResidueNumber[] aligned2 ) throws StructureException {
569+
ResidueNumber[] aligned1, ResidueNumber[] aligned2 ) throws StructureException {
570570
//input validation
571571
int alnLen = aligned1.length;
572572
if(alnLen != aligned2.length) {
@@ -752,7 +752,7 @@ public static AFPChain replaceOptAln(int[][][] newAlgn, AFPChain afpChain, Atom[
752752
* @see AlignmentTools#createAFPChain(Atom[], Atom[], ResidueNumber[], ResidueNumber[])
753753
*/
754754
public static AFPChain replaceOptAln(AFPChain afpChain, Atom[] ca1, Atom[] ca2,
755-
Map<Integer, Integer> alignment) throws StructureException {
755+
Map<Integer, Integer> alignment) throws StructureException {
756756

757757
// Determine block lengths
758758
// Sort ca1 indices, then start a new block whenever ca2 indices aren't
@@ -817,7 +817,7 @@ public static AFPChain replaceOptAln(AFPChain afpChain, Atom[] ca1, Atom[] ca2,
817817
* @throws StructureException if an error occured during superposition
818818
*/
819819
public static AFPChain replaceOptAln(AFPChain afpChain, Atom[] ca1, Atom[] ca2,
820-
int blockNum, int[] optLens, int[][][] optAln) throws StructureException {
820+
int blockNum, int[] optLens, int[][][] optAln) throws StructureException {
821821
int optLength = 0;
822822
for( int blk=0;blk<blockNum;blk++) {
823823
optLength += optLens[blk];
@@ -904,13 +904,13 @@ public static void updateSuperposition(AFPChain afpChain, Atom[] ca1, Atom[] ca2
904904
}
905905

906906
//Superimpose the two structures in correspondance to the new alignment
907-
Matrix4d trans = SuperPositions.superpose(Calc.atomsToPoints(ca1aligned),
907+
Matrix4d trans = SuperPositions.superpose(Calc.atomsToPoints(ca1aligned),
908908
Calc.atomsToPoints(ca2aligned));
909909

910910
Matrix matrix = Matrices.getRotationJAMA(trans);
911911
Atom shift = Calc.getTranslationVector(trans);
912-
913-
912+
913+
914914
Matrix[] blockMxs = new Matrix[afpChain.getBlockNum()];
915915
Arrays.fill(blockMxs, matrix);
916916
afpChain.setBlockRotationMatrix(blockMxs);
@@ -953,14 +953,14 @@ public static void updateSuperposition(AFPChain afpChain, Atom[] ca1, Atom[] ca2
953953
ca2block = (Atom[]) resizeArray(ca2block, position);
954954
}
955955
//Superimpose the two block structures
956-
Matrix4d transb = SuperPositions.superpose(Calc.atomsToPoints(ca1block),
956+
Matrix4d transb = SuperPositions.superpose(Calc.atomsToPoints(ca1block),
957957
Calc.atomsToPoints(ca2block));
958958

959959
Matrix matrixb = Matrices.getRotationJAMA(trans);
960960
Atom shiftb = Calc.getTranslationVector(trans);
961-
961+
962962
Calc.transform(ca2block, transb);
963-
963+
964964
//Calculate the RMSD and TM score for the block
965965
double rmsdb = Calc.rmsd(ca1block, ca2block);
966966
double tmScoreb = Calc.getTMScore(ca1block, ca2block, ca1.length, ca2.length);
@@ -1155,8 +1155,8 @@ public static int[] calculateBlockGap(int[][][] optAln){
11551155
* @throws IOException
11561156
*/
11571157
public static void alignmentToSIF(Writer out,AFPChain afpChain,
1158-
Atom[] ca1,Atom[] ca2, String backboneInteraction,
1159-
String alignmentInteraction) throws IOException {
1158+
Atom[] ca1,Atom[] ca2, String backboneInteraction,
1159+
String alignmentInteraction) throws IOException {
11601160

11611161
//out.write("Res1\tInteraction\tRes2\n");
11621162
String name1 = afpChain.getName1();
@@ -1210,7 +1210,7 @@ public static void alignmentToSIF(Writer out,AFPChain afpChain,
12101210
}
12111211
}
12121212
}
1213-
1213+
12141214

12151215

12161216
/** get an artificial List of chains containing the Atoms and groups.
@@ -1321,7 +1321,7 @@ public static Group[] prepareGroupsForDisplay(AFPChain afpChain, Atom[] ca1, Ato
13211321

13221322
twistedGroups = AFPTwister.twistOptimized(afpChain, ca1, ca2);
13231323

1324-
//} else if (( blockNum == 1 ) || (afpChain.getAlgorithmName().equals(CeCPMain.algorithmName))) {
1324+
//} else if (( blockNum == 1 ) || (afpChain.getAlgorithmName().equals(CeCPMain.algorithmName))) {
13251325
} else {
13261326

13271327
Matrix m = afpChain.getBlockRotationMatrix()[ 0];
@@ -1355,8 +1355,8 @@ public static Group[] prepareGroupsForDisplay(AFPChain afpChain, Atom[] ca1, Ato
13551355
}
13561356

13571357
/** only shift CA positions.
1358-
*
1359-
*/
1358+
*
1359+
*/
13601360
public static void shiftCA2(AFPChain afpChain, Atom[] ca2, Matrix m, Atom shift, Group[] twistedGroups) {
13611361

13621362
int i = -1;
@@ -1368,14 +1368,14 @@ public static void shiftCA2(AFPChain afpChain, Atom[] ca2, Matrix m, Atom shift
13681368
Calc.shift(g, shift);
13691369

13701370
if (g.hasAltLoc()){
1371-
for (Group alt: g.getAltLocs()){
1372-
for (Atom alta : alt.getAtoms()){
1373-
if ( g.getAtoms().contains(alta))
1374-
continue;
1375-
Calc.rotate(alta,m);
1376-
Calc.shift(alta,shift);
1377-
}
1378-
}
1371+
for (Group alt: g.getAltLocs()){
1372+
for (Atom alta : alt.getAtoms()){
1373+
if ( g.getAtoms().contains(alta))
1374+
continue;
1375+
Calc.rotate(alta,m);
1376+
Calc.shift(alta,shift);
1377+
}
1378+
}
13791379
}
13801380
twistedGroups[i]=g;
13811381
}

biojava-structure/src/main/java/org/biojava/nbio/structure/align/util/AtomCache.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,10 @@ public AtomCache(UserConfiguration config) {
184184
fetchBehavior = config.getFetchBehavior();
185185
obsoleteBehavior = config.getObsoleteBehavior();
186186
useMmCif = config.getFileFormat().equals( UserConfiguration.MMCIF_FORMAT );
187+
188+
if ( useMmCif)
189+
useMmtf = false;
190+
187191
}
188192

189193
/**
@@ -936,6 +940,14 @@ public void setUseMmtf(boolean useMmtf) {
936940

937941
}
938942

943+
/** Returns useMmtf flag
944+
*
945+
* @return true if will load data via mmtf file format
946+
*/
947+
public boolean isUseMmtf(){
948+
return this.useMmtf;
949+
}
950+
939951
private boolean checkLoading(String name) {
940952
return currentlyLoading.contains(name);
941953

@@ -1014,11 +1026,14 @@ public Structure getStructureForPdbId(String pdbId) throws IOException, Structur
10141026

10151027
Structure s;
10161028
if (useMmtf) {
1029+
logger.debug("loading from mmtf");
10171030
s = loadStructureFromMmtfByPdbId(pdbId);
10181031
}
10191032
else if (useMmCif) {
1033+
logger.debug("loading from mmcif");
10201034
s = loadStructureFromCifByPdbId(pdbId);
10211035
} else {
1036+
logger.debug("loading from pdb");
10221037
s = loadStructureFromPdbByPdbId(pdbId);
10231038
}
10241039
return s;

biojava-structure/src/main/java/org/biojava/nbio/structure/align/util/UserConfiguration.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public class UserConfiguration
4646

4747
public static final String PDB_FORMAT = "PDB";
4848
public static final String MMCIF_FORMAT = "mmCif";
49+
public static final String MMTF_FORMAT = "mmtf";
4950

5051
public static final String TMP_DIR = "java.io.tmpdir";
5152

@@ -97,7 +98,7 @@ public UserConfiguration(){
9798
// note that in initCacheFilePath, we set to the provided one (if readable) or to the same as pdbFilePath
9899
cacheFilePath = initCacheFilePath();
99100

100-
fileFormat = MMCIF_FORMAT;
101+
fileFormat = MMTF_FORMAT;
101102
}
102103

103104
private String initPdbFilePath() {

biojava-structure/src/main/java/org/biojava/nbio/structure/io/FileConvert.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -405,9 +405,10 @@ record = "ATOM ";
405405
String serial = String.format("%5d",seri);
406406
String fullName = formatAtomName(a);
407407

408-
409-
410-
Character altLoc = a.getAltLoc() ;
408+
Character altLoc = a.getAltLoc();
409+
if ( altLoc == null)
410+
altLoc = ' ';
411+
411412
String resseq = "" ;
412413
if ( hasInsertionCode(pdbcode) )
413414
resseq = String.format("%5s",pdbcode);

biojava-structure/src/test/java/org/biojava/nbio/structure/TestAtomCache.java

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,4 +212,66 @@ public void testFetchObsolete() throws IOException, StructureException {
212212

213213
}
214214

215+
216+
@Test
217+
public void testSettingFileParsingType(){
218+
219+
AtomCache cache = new AtomCache();
220+
221+
//test defaults
222+
223+
// by default we either use mmtf or mmcif, but not both.
224+
assertNotEquals(cache.isUseMmtf(), cache.isUseMmCif());
225+
226+
// first is mmtf, second is mmcif
227+
testFlags(cache,true,false);
228+
229+
// now change the values
230+
231+
cache.setUseMmCif(true);
232+
233+
testFlags(cache,false,true);
234+
235+
cache.setUseMmtf(true);
236+
237+
testFlags(cache,true,false);
238+
239+
// this sets to use PDB!
240+
cache.setUseMmCif(false);
241+
242+
testFlags(cache,false,false);
243+
244+
// back to defaults
245+
cache.setUseMmtf(true);
246+
247+
testFlags(cache,true,false);
248+
249+
250+
// back to parsing PDB
251+
cache.setUseMmtf(false);
252+
253+
testFlags(cache,false,false);
254+
255+
256+
257+
}
258+
259+
260+
/** test the flags for parsing in the atom cache
261+
*
262+
* @param cache
263+
* @param useMmTf
264+
* @param useMmCif
265+
*/
266+
private void testFlags(AtomCache cache ,boolean useMmTf, boolean useMmCif) {
267+
268+
assertEquals("flag for parsing mmtf is set to " + cache.isUseMmtf() + " but should be " + useMmTf,
269+
cache.isUseMmtf(), useMmTf);
270+
assertEquals("flag for parsing mmcif is set to " + cache.isUseMmCif() + " but should be set to " + useMmCif,
271+
cache.isUseMmCif(), useMmCif);
272+
273+
274+
275+
}
276+
215277
}

0 commit comments

Comments
 (0)