3535import org .biojava .nbio .structure .cath .CathFactory ;
3636import org .biojava .nbio .structure .domain .PDPProvider ;
3737import org .biojava .nbio .structure .domain .RemotePDPProvider ;
38- import org .biojava .nbio .structure .io .* ;
38+ import org .biojava .nbio .structure .io .FileParsingParameters ;
3939import org .biojava .nbio .structure .io .LocalPDBDirectory .FetchBehavior ;
4040import org .biojava .nbio .structure .io .LocalPDBDirectory .ObsoleteBehavior ;
41+ import org .biojava .nbio .structure .io .MMCIFFileReader ;
42+ import org .biojava .nbio .structure .io .MMTFFileReader ;
43+ import org .biojava .nbio .structure .io .PDBFileReader ;
4144import org .biojava .nbio .core .util .FileDownloadUtils ;
4245import org .biojava .nbio .structure .quaternary .BiologicalAssemblyBuilder ;
4346import org .biojava .nbio .structure .quaternary .BiologicalAssemblyTransformation ;
@@ -93,17 +96,8 @@ public class AtomCache {
9396
9497 private String path ;
9598
96- /**
97- * The format for structure data to use.
98- */
99- private Format format ;
100- enum Format {
101- PDB ,
102- MMCIF ,
103- MMTF ,
104- CIF ,
105- BCIF
106- }
99+ private boolean useMmCif ;
100+ private boolean useMmtf ;
107101
108102 /**
109103 * Default AtomCache constructor.
@@ -156,7 +150,9 @@ public AtomCache(String pdbFilePath, String cachePath) {
156150 currentlyLoading .clear ();
157151 params = new FileParsingParameters ();
158152
153+ setUseMmCif (false );
159154 setUseMmtf (true );
155+
160156 }
161157
162158 /**
@@ -169,10 +165,11 @@ public AtomCache(UserConfiguration config) {
169165 this (config .getPdbFilePath (), config .getCacheFilePath ());
170166 fetchBehavior = config .getFetchBehavior ();
171167 obsoleteBehavior = config .getObsoleteBehavior ();
168+ useMmCif = config .getFileFormat ().equals ( UserConfiguration .MMCIF_FORMAT );
169+
170+ if ( useMmCif )
171+ useMmtf = false ;
172172
173- if (config .getFileFormat ().equals (UserConfiguration .MMCIF_FORMAT )) {
174- format = Format .MMCIF ;
175- }
176173 }
177174
178175 /**
@@ -300,7 +297,8 @@ public Structure getBiologicalAssembly(String pdbId, int bioAssemblyId, boolean
300297
301298 // if we use mmcif or mmtf, then we need to pass useAsymIds=true
302299 boolean useAsymIds = false ;
303- if (format != Format .PDB ) useAsymIds = true ;
300+ if (useMmCif ) useAsymIds = true ;
301+ if (useMmtf ) useAsymIds = true ;
304302 return builder .rebuildQuaternaryStructure (asymUnit , transformations , useAsymIds , multiModel );
305303
306304 }
@@ -358,7 +356,8 @@ public Structure getBiologicalAssembly(String pdbId, boolean multiModel) throws
358356
359357 // if we use mmcif or mmtf, then we need to pass useAsymIds=true
360358 boolean useAsymIds = false ;
361- if (format != Format .PDB ) useAsymIds = true ;
359+ if (useMmCif ) useAsymIds = true ;
360+ if (useMmtf ) useAsymIds = true ;
362361 return builder .rebuildQuaternaryStructure (asymUnit , transformations , useAsymIds , multiModel );
363362
364363 }
@@ -410,7 +409,8 @@ public List<Structure> getBiologicalAssemblies(String pdbId, boolean multiModel)
410409
411410 // if we use mmcif or mmtf, then we need to pass useAsymIds=true
412411 boolean useAsymIds = false ;
413- if (format != Format .PDB ) useAsymIds = true ;
412+ if (useMmCif ) useAsymIds = true ;
413+ if (useMmtf ) useAsymIds = true ;
414414 Structure s = builder .rebuildQuaternaryStructure (asymUnit , transformations , useAsymIds , multiModel );
415415 assemblies .add (s );
416416 }
@@ -606,7 +606,7 @@ public Structure getStructureForDomain(ScopDomain domain, ScopDatabase scopDatab
606606 }
607607 }
608608 boolean alreadyContains = newChain .getAtomGroups ().contains (group ); // we don't want to add duplicate
609- // ligands
609+ // ligands
610610 if (shouldContain && !alreadyContains ) {
611611
612612 newChain .addGroup (group );
@@ -772,89 +772,37 @@ public void setPdpprovider(PDPProvider pdpprovider) {
772772 * @return the useMmCif
773773 */
774774 public boolean isUseMmCif () {
775- return format == Format . MMCIF ;
775+ return useMmCif ;
776776 }
777777
778778 /**
779779 * @param useMmCif
780780 * the useMmCif to set
781781 */
782782 public void setUseMmCif (boolean useMmCif ) {
783- if ( useMmCif ) {
784- this . format = Format . MMCIF ;
785- }
783+ this . useMmCif = useMmCif ;
784+ // Either way the user wants to use PDB or MMCIF
785+ this . useMmtf = false ;
786786 }
787787
788788 /**
789789 * Set whether to use mmtf.
790790 * @param useMmtf the input boolean to set
791791 */
792792 public void setUseMmtf (boolean useMmtf ) {
793- if (useMmtf ) {
794- this .format = Format .MMTF ;
793+ this .useMmtf = useMmtf ;
794+ if (useMmtf ){
795+ useMmCif =false ;
795796 }
797+
796798 }
797799
798800 /** Returns useMmtf flag
799801 *
800802 * @return true if will load data via mmtf file format
801803 */
802804 public boolean isUseMmtf (){
803- return this .format == Format .MMTF ;
804- }
805-
806- /**
807- * The PDB flag.
808- * @return true if legacy PDB parsing will be employed
809- */
810- public boolean isUsePdb () {
811- return this .format == Format .PDB ;
812- }
813-
814- /**
815- * The experimental Bcif flag.
816- * @return true if experimental Bcif parsing will be employed
817- */
818- public boolean isUseBcif () {
819- return this .format == Format .BCIF ;
820- }
821-
822- /**
823- * The experimental Cif flag.
824- * @return true if experimental Cif parsing will be employed
825- */
826- public boolean isUseCif () {
827- return this .format == Format .CIF ;
828- }
829-
830- /**
831- * Use the experimental Bcif parser to acquire structure data.
832- * @param useBcif use?
833- */
834- public void setUseBcif (boolean useBcif ) {
835- if (useBcif ) {
836- this .format = Format .BCIF ;
837- }
838- }
839-
840- /**
841- * Use the experimental Cif parser to acquire structure data.
842- * @param useCif use?
843- */
844- public void setUseCif (boolean useCif ) {
845- if (useCif ) {
846- this .format = Format .CIF ;
847- }
848- }
849-
850- /**
851- * Use the legacy PDB format to acquire structure data.
852- * @param usePdb use?
853- */
854- public void usePdb (boolean usePdb ) {
855- if (usePdb ) {
856- this .format = Format .PDB ;
857- }
805+ return this .useMmtf ;
858806 }
859807
860808 private boolean checkLoading (String name ) {
@@ -933,25 +881,19 @@ public Structure getStructureForPdbId(String pdbId) throws IOException, Structur
933881
934882 }
935883
936- switch (format ) {
937- case MMTF :
938- logger .debug ("loading from mmtf" );
939- return loadStructureFromMmtfByPdbId (pdbId );
940- case MMCIF :
941- logger .debug ("loading from mmcif" );
942- return loadStructureFromCifByPdbId (pdbId );
943- case CIF :
944- logger .debug ("loading from experimental cif" );
945- return loadStructureFromExperimentalCifByPdbId (pdbId );
946- case PDB :
947- logger .debug ("loading from pdb" );
948- return loadStructureFromPdbByPdbId (pdbId );
949- case BCIF :
950- logger .debug ("loading from bcif" );
951- return loadStructureFromBcifByPdbId (pdbId );
952- default :
953- throw new IllegalArgumentException ("no strategy implemented for format " + format );
884+ Structure s ;
885+ if (useMmtf ) {
886+ logger .debug ("loading from mmtf" );
887+ s = loadStructureFromMmtfByPdbId (pdbId );
888+ }
889+ else if (useMmCif ) {
890+ logger .debug ("loading from mmcif" );
891+ s = loadStructureFromCifByPdbId (pdbId );
892+ } else {
893+ logger .debug ("loading from pdb" );
894+ s = loadStructureFromPdbByPdbId (pdbId );
954895 }
896+ return s ;
955897 }
956898
957899 /**
@@ -969,22 +911,6 @@ private Structure loadStructureFromMmtfByPdbId(String pdbId) throws IOException
969911 return structure ;
970912 }
971913
972- private Structure loadStructureFromBcifByPdbId (String pdbId ) throws IOException {
973- logger .debug ("Loading structure {} from Bcif file." , pdbId );
974- BcifFileReader reader = new BcifFileReader ();
975- reader .setFetchBehavior (fetchBehavior );
976- reader .setObsoleteBehavior (obsoleteBehavior );
977- return reader .getStructureById (pdbId .toLowerCase ());
978- }
979-
980- private Structure loadStructureFromExperimentalCifByPdbId (String pdbId ) throws IOException {
981- logger .debug ("Loading structure {} experimentally from Cif file." , pdbId );
982- CifFileReader reader = new CifFileReader ();
983- reader .setFetchBehavior (fetchBehavior );
984- reader .setObsoleteBehavior (obsoleteBehavior );
985- return reader .getStructureById (pdbId .toLowerCase ());
986- }
987-
988914 protected Structure loadStructureFromCifByPdbId (String pdbId ) throws IOException , StructureException {
989915
990916 logger .debug ("Loading structure {} from mmCIF file {}." , pdbId , path );
@@ -1025,4 +951,4 @@ protected Structure loadStructureFromPdbByPdbId(String pdbId) throws IOException
1025951 return s ;
1026952 }
1027953
1028- }
954+ }
0 commit comments