From 341f4d10365d8963aa83f5d2ec3612490dba0804 Mon Sep 17 00:00:00 2001 From: Shilpa Rani Date: Sun, 1 Nov 2020 20:55:14 -0600 Subject: [PATCH 001/599] Fixing the flakiness caused by testGetProteinSequenceForStructure --- .../org/biojava/nbio/structure/io/StructureSequenceMatcher.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/StructureSequenceMatcher.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/StructureSequenceMatcher.java index 3c884bbc2d..e3c70452a7 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/StructureSequenceMatcher.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/StructureSequenceMatcher.java @@ -119,7 +119,7 @@ public static ProteinSequence getProteinSequenceForStructure(Structure struct, M for(Chain chain : struct.getChains()) { List groups = chain.getAtomGroups(); - Map chainIndexPosition = new HashMap(); + Map chainIndexPosition = new LinkedHashMap(); int prevLen = seqStr.length(); // get the sequence for this chain From 9b2335e97da0789bd69ba3ea66022f838dda3fda Mon Sep 17 00:00:00 2001 From: Vidishab18 <71988063+Vidishab18@users.noreply.github.com> Date: Fri, 13 Nov 2020 17:44:18 -0800 Subject: [PATCH 002/599] Update StructureSequenceMatcher.java --- .../org/biojava/nbio/structure/io/StructureSequenceMatcher.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/StructureSequenceMatcher.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/StructureSequenceMatcher.java index e3c70452a7..3c884bbc2d 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/StructureSequenceMatcher.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/StructureSequenceMatcher.java @@ -119,7 +119,7 @@ public static ProteinSequence getProteinSequenceForStructure(Structure struct, M for(Chain chain : struct.getChains()) { List groups = chain.getAtomGroups(); - Map chainIndexPosition = new LinkedHashMap(); + Map chainIndexPosition = new HashMap(); int prevLen = seqStr.length(); // get the sequence for this chain From 43f8dcdd80aab451c0b9ad86f8079aa9d3ee9646 Mon Sep 17 00:00:00 2001 From: Vidishab18 <71988063+Vidishab18@users.noreply.github.com> Date: Fri, 13 Nov 2020 17:45:12 -0800 Subject: [PATCH 003/599] Update MmtfStructureReader.java --- .../biojava/nbio/structure/io/mmtf/MmtfStructureReader.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmtf/MmtfStructureReader.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmtf/MmtfStructureReader.java index 09d8ca58a8..fbdf9d3869 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmtf/MmtfStructureReader.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmtf/MmtfStructureReader.java @@ -27,6 +27,7 @@ import java.util.Collections; import java.util.Date; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -105,7 +106,7 @@ public class MmtfStructureReader implements StructureAdapterInterface, Serializa private List chainList; /** All the chains as a list of maps */ - private List> chainMap; + private List> chainMap; private List transformList; @@ -178,7 +179,7 @@ public void setModelInfo(int inputModelNumber, int chainCount) { modelNumber = inputModelNumber; structure.addModel(new ArrayList(chainCount)); - chainMap.add(new HashMap<>()); + chainMap.add(new LinkedHashMap<>()); } /* (non-Javadoc) From 2cbb6c6813ef959dd4dc747478570cf2511da190 Mon Sep 17 00:00:00 2001 From: Vidishab18 <71988063+Vidishab18@users.noreply.github.com> Date: Fri, 13 Nov 2020 17:48:55 -0800 Subject: [PATCH 004/599] Update MmtfStructureReader.java --- .../org/biojava/nbio/structure/io/mmtf/MmtfStructureReader.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmtf/MmtfStructureReader.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmtf/MmtfStructureReader.java index fbdf9d3869..6385b92391 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmtf/MmtfStructureReader.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmtf/MmtfStructureReader.java @@ -106,7 +106,7 @@ public class MmtfStructureReader implements StructureAdapterInterface, Serializa private List chainList; /** All the chains as a list of maps */ - private List> chainMap; + private List> chainMap; private List transformList; From e3bad37bd4bc39bdec3c70d1d76bc98acbec46bb Mon Sep 17 00:00:00 2001 From: JonStargaryen Date: Wed, 18 Nov 2020 15:10:30 -0800 Subject: [PATCH 005/599] detach mmcif.model.DatabasePdbrevRecord - replaced by DatabasePdbRevRecord --- .../nbio/structure/DatabasePdbRevRecord.java | 43 +++++++++++++++++++ .../org/biojava/nbio/structure/PDBHeader.java | 7 ++- .../structure/io/cif/CifFileConsumerImpl.java | 22 +++++----- 3 files changed, 56 insertions(+), 16 deletions(-) create mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/DatabasePdbRevRecord.java diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/DatabasePdbRevRecord.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/DatabasePdbRevRecord.java new file mode 100644 index 0000000000..91ec85549f --- /dev/null +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/DatabasePdbRevRecord.java @@ -0,0 +1,43 @@ +package org.biojava.nbio.structure; + +import java.io.Serializable; + +public class DatabasePdbRevRecord implements Serializable { + private static final long serialVersionUID = -791924804009516791L; + private String rev_num; + private String type; + private String details; + + public String getRev_num() { + return rev_num; + } + + public void setRev_num(String rev_num) { + this.rev_num = rev_num; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getDetails() { + return details; + } + + public void setDetails(String details) { + this.details = details; + } + + @Override + public String toString() { + return "DatabasePdbrevRecord{" + + "rev_num='" + rev_num + '\'' + + ", type='" + type + '\'' + + ", details='" + details + '\'' + + '}'; + } +} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/PDBHeader.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/PDBHeader.java index dbcc0f794c..1071c52c23 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/PDBHeader.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/PDBHeader.java @@ -20,7 +20,6 @@ */ package org.biojava.nbio.structure; -import org.biojava.nbio.structure.io.mmcif.model.DatabasePdbrevRecord; import org.biojava.nbio.structure.quaternary.BioAssemblyInfo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -77,7 +76,7 @@ public class PDBHeader implements PDBRecord { private Map bioAssemblies ; - List revisionRecords; + List revisionRecords; public PDBHeader(){ @@ -663,11 +662,11 @@ public int getNrBioAssemblies() { return this.bioAssemblies.size(); } - public List getRevisionRecords() { + public List getRevisionRecords() { return revisionRecords; } - public void setRevisionRecords(List revisionRecords) { + public void setRevisionRecords(List revisionRecords) { this.revisionRecords = revisionRecords; } diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/CifFileConsumerImpl.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/CifFileConsumerImpl.java index 7a8fae1e5d..a3af75fc91 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/CifFileConsumerImpl.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/CifFileConsumerImpl.java @@ -7,6 +7,7 @@ import org.biojava.nbio.structure.Chain; import org.biojava.nbio.structure.ChainImpl; import org.biojava.nbio.structure.DBRef; +import org.biojava.nbio.structure.DatabasePdbRevRecord; import org.biojava.nbio.structure.Element; import org.biojava.nbio.structure.EntityInfo; import org.biojava.nbio.structure.EntityType; @@ -30,7 +31,6 @@ import org.biojava.nbio.structure.io.FileParsingParameters; import org.biojava.nbio.structure.io.SeqRes2AtomAligner; import org.biojava.nbio.structure.io.mmcif.ChemCompGroupFactory; -import org.biojava.nbio.structure.io.mmcif.model.DatabasePdbrevRecord; import org.biojava.nbio.structure.quaternary.BioAssemblyInfo; import org.biojava.nbio.structure.quaternary.BiologicalAssemblyBuilder; import org.biojava.nbio.structure.quaternary.BiologicalAssemblyTransformation; @@ -97,8 +97,6 @@ import java.util.stream.Collectors; import java.util.stream.IntStream; -// TODO detach the impl from the redundant mmCIF impl - /** * An implementation of a CifFileConsumer for BioJava. Will process the information provided by a CifFile instance and * use it to build up a {@link Structure} object. The implementation is for the most part really close to that in @@ -144,7 +142,7 @@ class CifFileConsumerImpl implements CifFileConsumer { private Map asymId2authorId; private Matrix4d parsedScaleMatrix; - private FileParsingParameters params; + private final FileParsingParameters params; public CifFileConsumerImpl(FileParsingParameters params) { this.params = params; @@ -624,7 +622,7 @@ public void consumeDatabasePDBrev(DatabasePDBRev databasePDBrev) { @Override public void consumeDatabasePDBrevRecord(DatabasePDBRevRecord databasePDBrevRecord) { - List revRecords = pdbHeader.getRevisionRecords(); + List revRecords = pdbHeader.getRevisionRecords(); if (revRecords == null) { revRecords = new ArrayList<>(); pdbHeader.setRevisionRecords(revRecords); @@ -633,10 +631,10 @@ public void consumeDatabasePDBrevRecord(DatabasePDBRevRecord databasePDBrevRecor revRecords.addAll(convert(databasePDBrevRecord)); } - private List convert(DatabasePDBRevRecord databasePDBrevRecord) { - List revRecords = new ArrayList<>(); + private List convert(DatabasePDBRevRecord databasePDBrevRecord) { + List revRecords = new ArrayList<>(); for (int rowIndex = 0; rowIndex < databasePDBrevRecord.getRowCount(); rowIndex++) { - DatabasePdbrevRecord revRecord = new DatabasePdbrevRecord(); + DatabasePdbRevRecord revRecord = new DatabasePdbRevRecord(); revRecord.setDetails(databasePDBrevRecord.getDetails().get(rowIndex)); revRecord.setRev_num(databasePDBrevRecord.getRevNum().getStringData(rowIndex)); revRecord.setType(databasePDBrevRecord.getType().get(rowIndex)); @@ -1297,14 +1295,14 @@ private void addEntity(int asymRowIndex, String entityId, String pdbxDescription } catch (NumberFormatException e) { logger.warn("Could not parse mol_id from string {}. Will use 0 for creating Entity", entityId); } - + int entityRowIndex = IntStream.range(0, entity.getRowCount()) .filter(i -> entity.getId().get(i).equals(entityId)) .findFirst() .orElse(-1); - + EntityInfo entityInfo = structure.getEntityById(eId); - + if (entityInfo == null) { entityInfo = new EntityInfo(); entityInfo.setMolId(eId); @@ -1320,7 +1318,7 @@ private void addEntity(int asymRowIndex, String entityId, String pdbxDescription } addAncilliaryEntityData(asymRowIndex, entityInfo); structure.addEntityInfo(entityInfo); - logger.debug("Adding Entity with entity id {} from _entity, with name: {}", eId, + logger.debug("Adding Entity with entity id {} from _entity, with name: {}", eId, entityInfo.getDescription()); } } From b4ecf191199c91e2fe2f2ec7c25144de30dbfdc7 Mon Sep 17 00:00:00 2001 From: Jose Duarte Date: Sun, 1 Nov 2020 13:35:04 -0800 Subject: [PATCH 006/599] WIP: start of pdbstatus rewrite --- .../org/biojava/nbio/structure/PDBStatus.java | 240 +++++++----------- 1 file changed, 85 insertions(+), 155 deletions(-) diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/PDBStatus.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/PDBStatus.java index dfb95eab8e..1fc54f9410 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/PDBStatus.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/PDBStatus.java @@ -23,6 +23,8 @@ */ package org.biojava.nbio.structure; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.type.TypeFactory; import org.biojava.nbio.structure.align.util.URLConnectionTools; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -43,19 +45,22 @@ * Methods for getting the status of a PDB file (current, obsolete, etc) * and for accessing different versions of the structure. * - *

All methods query the - * - * PDB website. + *

+ * All methods query the + * + * RCSB Data REST API * - *

PDB supersessions form a directed acyclic graph, where edges point from an + *

+ * PDB supersessions form a directed acyclic graph, where edges point from an * obsolete ID to the entry that directly superseded it. For example, here are - * edges from one portion of the graph:
- * + * edges from one portion of the graph: + *

* 1CAT -> 3CAT
* 3CAT -> 7CAT
* 3CAT -> 8CAT
* - *

The methods {@link #getReplaces(String, boolean) getReplaces(pdbId, false)}/ + *

+ * The methods {@link #getReplaces(String, boolean) getReplaces(pdbId, false)}/ * {@link #getReplacement(String, boolean, boolean) getReplacement(pdbId, false, true)} * just get the incoming/outgoing edges for a single node. The recursive versions * ({@link #getReplaces(String, boolean) getReplaces(pdbId, true)}, @@ -63,39 +68,46 @@ * will do a depth-first search up/down the tree and return a list of all nodes ] * reached. * - *

Finally, the getCurrent() method returns a single PDB ID from among the + *

+ * Finally, the {@link #getCurrent(String)} method returns a single PDB ID from among the * results of - * {@link #getReplacement(String, boolean) getReplacement(pdbId, true)}. + * {@link #getReplacement(String, boolean, boolean)}. * To be consistent with the old REST ordering, this is the PDB ID that occurs * last alphabetically. * - *

Results are cached to reduce server load. + *

+ * Results are cached to reduce server load. * - * @author Spencer Bliven + * @author Spencer Bliven * @author Amr AL-Hossary + * @author Jose Duarte * @since 3.0.2 */ public class PDBStatus { private static final Logger logger = LoggerFactory.getLogger(PDBStatus.class); - public static final String DEFAULT_PDB_SERVER = "www.rcsb.org"; - public static final String PDB_SERVER_PROPERTY = "PDB.SERVER"; + //public static final String DEFAULT_PDB_SERVER = "www.rcsb.org"; + public static final String DEFAULT_RCSB_DATA_API_SERVER = "data.rcsb.org"; + public static final String ALL_CURRENT_ENDPOINT = "https://%s/rest/v1/holdings/current/entry_ids"; /** * saves the returned results for further use. * */ - //TODO Use SoftReferences to allow garbage collection - private static Map> recordsCache= new Hashtable>(); + private static final Map> recordsCache= new Hashtable<>(); /** * Represents the status of PDB IDs. 'OBSOLETE' and 'CURRENT' are the most * common. - * @author Spencer Bliven + * @author Spencer Bliven * */ public enum Status { + // this is the list for unreleased: "AUCO" "AUTH" "HOLD" "HPUB" "POLC" "PROC" "REFI" "REPL" "WAIT" "WDRN" + // The remaining from below are removed-related: OBSOLETE, MODEL (not available in Data API). + // In Data API in rcsb_repository_holdings_insilico_models.status_code: 3 values "OBS", "TRSF", "WDRN" and 1 in rcsb_repository_holdings_transferred.status_code: "TRSF" + // for current: CURRENT (not available in current API) OBSOLETE, CURRENT, AUTH, @@ -110,11 +122,7 @@ public enum Status { MODEL, UNKNOWN; - /** - * - * @param statusStr - * @return * @throws IllegalArgumentException If the string is not recognized */ public static Status fromString(String statusStr) { @@ -159,7 +167,7 @@ else if(statusStrUpper.equalsIgnoreCase("UNKNOWN")) * @param pdbId * @return The status, or null if an error occurred. */ - public static Status getStatus(String pdbId) { + public static Status getStatus(String pdbId) throws IOException { Status[] statuses = getStatus(new String[] {pdbId}); if(statuses != null) { assert(statuses.length == 1); @@ -176,7 +184,7 @@ public static Status getStatus(String pdbId) { * @param pdbIds * @return The status array, or null if an error occurred. */ - public static Status[] getStatus(String[] pdbIds) { + public static Status[] getStatus(String[] pdbIds) throws IOException { Status[] statuses = new Status[pdbIds.length]; List> attrList = getStatusIdRecords(pdbIds); @@ -234,8 +242,8 @@ public static Status[] getStatus(String[] pdbIds) { * @param oldPdbId * @return The replacement for oldPdbId, or null if none are found or if an error occurred. */ - public static String getCurrent(String oldPdbId) { - List replacements = getReplacement(oldPdbId,true, false); + public static String getCurrent(String oldPdbId) throws IOException { + List replacements = getReplacement(oldPdbId,true, false); if(replacements != null && !replacements.isEmpty()) return replacements.get(0); else @@ -260,7 +268,7 @@ public static String getCurrent(String oldPdbId) { * current records. A return value of null indicates that the ID has * been removed from the PDB or that an error has occurred. */ - public static List getReplacement(String oldPdbId, boolean recurse, boolean includeObsolete) { + public static List getReplacement(String oldPdbId, boolean recurse, boolean includeObsolete) throws IOException { List> attrList = getStatusIdRecords(new String[] {oldPdbId}); //Expect a single record if(attrList == null || attrList.size() != 1) { @@ -291,7 +299,7 @@ public static List getReplacement(String oldPdbId, boolean recurse, bool } // If we're current, just return - LinkedList results = new LinkedList(); + LinkedList results = new LinkedList<>(); switch(status) { case CURRENT: results.add(oldPdbId); @@ -459,7 +467,7 @@ private static void mergeReversed(List merged, * @return A (possibly empty) list of ID(s) of the ancestor(s) of * newPdbId, or null if an error occurred. */ - public static List getReplaces(String newPdbId, boolean recurse) { + public static List getReplaces(String newPdbId, boolean recurse) throws IOException { List> attrList = getStatusIdRecords(new String[] {newPdbId}); //Expect a single record if(attrList == null || attrList.size() != 1) { @@ -516,34 +524,34 @@ public static void clearCache() { /** * Fetches the status of one or more pdbIDs from the server. * - *

Returns the results as a list of Attributes. + *

+ * Returns the results as a list of Attributes. * Each attribute should contain "structureId" and "status" attributes, and * possibly more. * - *

Example:
+ *

+ * Example: + *

* http://www.rcsb.org/pdb/rest/idStatus?structureID=1HHB,4HHB
- *

<idStatus>
-	 *  <record structureId="1HHB" status="OBSOLETE" replacedBy="4HHB"/>
-	 *  <record structureId="4HHB" status="CURRENT" replaces="1HHB"/>
-	 *</idStatus>
+	 * 
+	 * <idStatus>
+	 *   <record structureId="1HHB" status="OBSOLETE" replacedBy="4HHB"/>
+	 *   <record structureId="4HHB" status="CURRENT" replaces="1HHB"/>
+	 * </idStatus>
 	 * 
* - *

Results are not guaranteed to be returned in the same order as pdbIDs. + *

+ * Results are not guaranteed to be returned in the same order as pdbIDs. * Refer to the structureId property to match them. * - * @param pdbIDs + * @param pdbIDs the PDB identifiers * @return A map between attributes and values */ - private static List> getStatusIdRecords(String[] pdbIDs) { - - List> result = new ArrayList>(pdbIDs.length); + private static List> getStatusIdRecords(String[] pdbIDs) throws IOException { - String serverName = System.getProperty(PDB_SERVER_PROPERTY); + List> result = new ArrayList<>(pdbIDs.length); - if ( serverName == null) - serverName = DEFAULT_PDB_SERVER; - else - logger.info(String.format("Got System property %s=%s",PDB_SERVER_PROPERTY,serverName)); + String serverName = DEFAULT_RCSB_DATA_API_SERVER; // Build REST query URL if(pdbIDs.length < 1) { @@ -566,143 +574,65 @@ private static List> getStatusIdRecords(String[] pdbIDs) { return result; } - try { - logger.info("Fetching {}", urlStr); + logger.info("Fetching {}", urlStr); - URL url = new URL(urlStr); + URL url = new URL(urlStr); - InputStream uStream = url.openStream(); + InputStream uStream = url.openStream(); - InputSource source = new InputSource(uStream); - SAXParserFactory parserFactory = SAXParserFactory.newInstance(); - SAXParser parser = parserFactory.newSAXParser(); - XMLReader reader = parser.getXMLReader(); + InputSource source = new InputSource(uStream); + SAXParserFactory parserFactory = SAXParserFactory.newInstance(); + SAXParser parser = parserFactory.newSAXParser(); + XMLReader reader = parser.getXMLReader(); - PDBStatusXMLHandler handler = new PDBStatusXMLHandler(); + PDBStatusXMLHandler handler = new PDBStatusXMLHandler(); - reader.setContentHandler(handler); - reader.parse(source); + reader.setContentHandler(handler); + reader.parse(source); - // Fetch results of SAX parsing - List> records = handler.getRecords(); + // Fetch results of SAX parsing + List> records = handler.getRecords(); - //add to cache - for(Map record : records) { - String pdbId = record.get("structureId").toUpperCase(); - if(pdbId != null) { - recordsCache.put(pdbId, record); - } + //add to cache + for (Map record : records) { + String pdbId = record.get("structureId").toUpperCase(); + if (pdbId != null) { + recordsCache.put(pdbId, record); } - - // return results - result.addAll(handler.getRecords()); - - // TODO should throw these forward and let the caller log - } catch (IOException e){ - logger.error("Problem getting status for {} from PDB server. Error: {}", Arrays.toString(pdbIDs), e.getMessage()); - return null; - } catch (SAXException e) { - logger.error("Problem getting status for {} from PDB server. Error: {}", Arrays.toString(pdbIDs), e.getMessage()); - return null; - } catch (ParserConfigurationException e) { - logger.error("Problem getting status for {} from PDB server. Error: {}", Arrays.toString(pdbIDs), e.getMessage()); - return null; } + // return results + result.addAll(handler.getRecords()); + return result; } /** - * Handles idStatus xml by storing attributes for all record elements. - * - * @author Spencer Bliven - * - */ - private static class PDBStatusXMLHandler extends DefaultHandler { - private List> records; - - public PDBStatusXMLHandler() { - records = new ArrayList>(); - } - - /** - * @param uri - * @param localName - * @param qName - * @param attributes - * @throws SAXException - * @see org.xml.sax.helpers.DefaultHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes) - */ - @Override - public void startElement(String uri, String localName, String qName, - Attributes attributes) throws SAXException { - //System.out.format("Starting element: uri='%s' localName='%s' qName='%s'\n", uri, localName, qName); - if(qName.equals("record")) { - //Convert attributes into a Map, as it should have been. - //Important since SAX reuses Attributes objects for different calls - Map attrMap = new HashMap(attributes.getLength()*2); - for(int i=0;i> getRecords() { - return records; - } - } - - /** Returns a list of current PDB IDs + * Returns all current PDB IDs * - * @return a list of PDB IDs, or null if a problem occurred + * @return a list of PDB IDs + * @throws IOException if a problem occurs retrieving the information */ - public static SortedSet getCurrentPDBIds() throws IOException { - SortedSet allPDBs = new TreeSet(); - String serverName = System.getProperty(PDB_SERVER_PROPERTY); - - if ( serverName == null) - serverName = DEFAULT_PDB_SERVER; - else - logger.info(String.format("Got System property %s=%s",PDB_SERVER_PROPERTY,serverName)); + //String serverName = System.getProperty(PDB_SERVER_PROPERTY); + String serverName = DEFAULT_RCSB_DATA_API_SERVER; // Build REST query URL - - String urlStr = String.format("http://%s/pdb/rest/getCurrent",serverName); + String urlStr = String.format(ALL_CURRENT_ENDPOINT, serverName); URL u = new URL(urlStr); InputStream stream = URLConnectionTools.getInputStream(u, 60000); - if (stream != null) { - BufferedReader reader = new BufferedReader( - new InputStreamReader(stream)); - - String line = null; - - while ((line = reader.readLine()) != null) { - int index = line.lastIndexOf("structureId="); - if (index > 0) { - allPDBs.add(line.substring(index + 13, index + 17)); - } - } - } - return allPDBs; + ObjectMapper objectMapper = new ObjectMapper(); + TypeFactory typeFactory = objectMapper.getTypeFactory(); + List pdbIdList = objectMapper.readValue(stream, typeFactory.constructCollectionType(List.class, String.class)); + return new TreeSet<>(pdbIdList); } + public static void main(String[] args) throws Exception { + SortedSet all = getCurrentPDBIds(); + System.out.println("Number of current PDB ids is: " + all.size()); + } } From 0a70219111cbb9dfa5def02ec8368849724c2bf5 Mon Sep 17 00:00:00 2001 From: Jose Duarte Date: Sun, 22 Nov 2020 14:44:25 -0800 Subject: [PATCH 007/599] Now PDBStatus uses the current RCSB Data API --- .../org/biojava/nbio/structure/PDBStatus.java | 558 ++---------------- .../nbio/structure/io/LocalPDBDirectory.java | 2 +- .../biojava/nbio/structure/PDBStatusTest.java | 167 +----- 3 files changed, 64 insertions(+), 663 deletions(-) diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/PDBStatus.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/PDBStatus.java index 1fc54f9410..7abd790fb4 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/PDBStatus.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/PDBStatus.java @@ -18,65 +18,29 @@ * http://www.biojava.org/ * */ -/** - * - */ package org.biojava.nbio.structure; +import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.type.TypeFactory; import org.biojava.nbio.structure.align.util.URLConnectionTools; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.xml.sax.*; -import org.xml.sax.helpers.DefaultHandler; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.parsers.SAXParser; -import javax.xml.parsers.SAXParserFactory; -import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; -import java.io.InputStreamReader; import java.net.URL; import java.util.*; /** - * Methods for getting the status of a PDB file (current, obsolete, etc) + * Methods for getting the status of a PDB file (current, obsolete, unreleased) * and for accessing different versions of the structure. * *

* All methods query the * * RCSB Data REST API - * - *

- * PDB supersessions form a directed acyclic graph, where edges point from an - * obsolete ID to the entry that directly superseded it. For example, here are - * edges from one portion of the graph: - *

- * 1CAT -> 3CAT
- * 3CAT -> 7CAT
- * 3CAT -> 8CAT
- * - *

- * The methods {@link #getReplaces(String, boolean) getReplaces(pdbId, false)}/ - * {@link #getReplacement(String, boolean, boolean) getReplacement(pdbId, false, true)} - * just get the incoming/outgoing edges for a single node. The recursive versions - * ({@link #getReplaces(String, boolean) getReplaces(pdbId, true)}, - * {@link #getReplacement(String, boolean, boolean) getReplacement(pdbId, true, false)}) - * will do a depth-first search up/down the tree and return a list of all nodes ] - * reached. - * *

- * Finally, the {@link #getCurrent(String)} method returns a single PDB ID from among the - * results of - * {@link #getReplacement(String, boolean, boolean)}. - * To be consistent with the old REST ordering, this is the PDB ID that occurs - * last alphabetically. - * - *

- * Results are cached to reduce server load. * * @author Spencer Bliven * @author Amr AL-Hossary @@ -87,40 +51,21 @@ public class PDBStatus { private static final Logger logger = LoggerFactory.getLogger(PDBStatus.class); - //public static final String DEFAULT_PDB_SERVER = "www.rcsb.org"; public static final String DEFAULT_RCSB_DATA_API_SERVER = "data.rcsb.org"; public static final String ALL_CURRENT_ENDPOINT = "https://%s/rest/v1/holdings/current/entry_ids"; + public static final String STATUS_ENDPOINT = "https://%s/rest/v1/holdings/status/%s"; + public static final String STATUS_LIST_ENDPOINT = "https://%s/rest/v1/holdings/status?ids=%s"; /** - * saves the returned results for further use. - * - */ - private static final Map> recordsCache= new Hashtable<>(); - - /** - * Represents the status of PDB IDs. 'OBSOLETE' and 'CURRENT' are the most - * common. + * Represents a simplified 3 state status of PDB IDs. * @author Spencer Bliven * */ public enum Status { - // this is the list for unreleased: "AUCO" "AUTH" "HOLD" "HPUB" "POLC" "PROC" "REFI" "REPL" "WAIT" "WDRN" - // The remaining from below are removed-related: OBSOLETE, MODEL (not available in Data API). - // In Data API in rcsb_repository_holdings_insilico_models.status_code: 3 values "OBS", "TRSF", "WDRN" and 1 in rcsb_repository_holdings_transferred.status_code: "TRSF" - // for current: CURRENT (not available in current API) - OBSOLETE, + // the simplified status enum in rcsb_repository_holdings_combined + REMOVED, CURRENT, - AUTH, - HOLD, - HPUB, - POLC, - PROC, - REFI, - REPL, - WAIT, - WDRN, - MODEL, - UNKNOWN; + UNRELEASED; /** * @throws IllegalArgumentException If the string is not recognized @@ -128,32 +73,12 @@ public enum Status { public static Status fromString(String statusStr) { Status status; String statusStrUpper = statusStr.toUpperCase(); - if(statusStrUpper.equalsIgnoreCase("OBSOLETE")) - status = Status.OBSOLETE; + if(statusStrUpper.equalsIgnoreCase("REMOVED")) + status = Status.REMOVED; else if(statusStrUpper.equalsIgnoreCase("CURRENT")) status = Status.CURRENT; - else if(statusStrUpper.equalsIgnoreCase("AUTH")) - status = Status.AUTH; - else if(statusStrUpper.equalsIgnoreCase("HOLD")) - status = Status.HOLD; - else if(statusStrUpper.equalsIgnoreCase("HPUB")) - status = Status.HPUB; - else if(statusStrUpper.equalsIgnoreCase("POLC")) - status = Status.POLC; - else if(statusStrUpper.equalsIgnoreCase("PROC")) - status = Status.PROC; - else if(statusStrUpper.equalsIgnoreCase("REFI")) - status = Status.REFI; - else if(statusStrUpper.equalsIgnoreCase("REPL")) - status = Status.REPL; - else if(statusStrUpper.equalsIgnoreCase("WAIT")) - status = Status.WAIT; - else if(statusStrUpper.equalsIgnoreCase("WDRN")) - status = Status.WDRN; - else if(statusStrUpper.equalsIgnoreCase("MODEL")) - status = Status.MODEL; - else if(statusStrUpper.equalsIgnoreCase("UNKNOWN")) - status = Status.UNKNOWN; + else if(statusStrUpper.equalsIgnoreCase("UNRELEASED")) + status = Status.UNRELEASED; else { throw new IllegalArgumentException("Unable to parse status '"+statusStrUpper+"'."); } @@ -164,447 +89,81 @@ else if(statusStrUpper.equalsIgnoreCase("UNKNOWN")) /** * Get the status of the PDB in question. * - * @param pdbId + * @param pdbId the id * @return The status, or null if an error occurred. */ public static Status getStatus(String pdbId) throws IOException { - Status[] statuses = getStatus(new String[] {pdbId}); - if(statuses != null) { - assert(statuses.length == 1); - return statuses[0]; - } else { - return null; - } + URL url = new URL(String.format(STATUS_ENDPOINT, DEFAULT_RCSB_DATA_API_SERVER, pdbId.toUpperCase())); + ObjectMapper objectMapper = new ObjectMapper(); + JsonNode node = objectMapper.readValue(url.openStream(), JsonNode.class); + return parseStatusRecord(node); } /** * Get the status of the a collection of PDBs in question in a single query. * * @see #getStatus(String) - * @param pdbIds + * @param pdbIds the ids * @return The status array, or null if an error occurred. */ public static Status[] getStatus(String[] pdbIds) throws IOException { - Status[] statuses = new Status[pdbIds.length]; - - List> attrList = getStatusIdRecords(pdbIds); - //Expect a single record - if(attrList == null || attrList.size() != pdbIds.length) { - logger.error("Error getting Status for {} from the PDB website.", Arrays.toString(pdbIds)); - return null; - } + URL url = new URL(String.format(STATUS_LIST_ENDPOINT, DEFAULT_RCSB_DATA_API_SERVER, String.join(",", pdbIds))); - for(int pdbNum = 0;pdbNum attrs : attrList) { + List statuses = new ArrayList<>(); - //Check that the record matches pdbId - String id = attrs.get("structureId"); - if(id == null || !id.equalsIgnoreCase(pdbIds[pdbNum])) { - continue; - } - - //Check that the status is given - String statusStr = attrs.get("status"); - Status status = null; - if(statusStr == null ) { - logger.error("No status returned for {}", pdbIds[pdbNum]); - statuses[pdbNum] = null; - } else { - status = Status.fromString(statusStr); - } - - if(status == null) { - logger.error("Unknown status '{}'", statusStr); - statuses[pdbNum] = null; - } + ObjectMapper objectMapper = new ObjectMapper(); + JsonNode node = objectMapper.readValue(url.openStream(), JsonNode.class); - statuses[pdbNum] = status; - foundAttr = true; - } - if(!foundAttr) { - logger.error("No result found for {}", pdbIds[pdbNum]); - statuses[pdbNum] = null; + if (node !=null && node.isArray()) { + for (JsonNode record : node) { + Status status = parseStatusRecord(record); + statuses.add(status); } } - return statuses; - } - - /** - * Gets the current version of a PDB ID. This is equivalent to selecting - * the first element from - * {@link #getReplacement(String,boolean,boolean) - * - * @param oldPdbId - * @return The replacement for oldPdbId, or null if none are found or if an error occurred. - */ - public static String getCurrent(String oldPdbId) throws IOException { - List replacements = getReplacement(oldPdbId,true, false); - if(replacements != null && !replacements.isEmpty()) - return replacements.get(0); - else - return null; - } - - /** - * Gets the PDB which superseded oldPdbId. For CURRENT IDs, this will - * be itself. For obsolete IDs, the behavior depends on the recursion - * parameter. If false, only IDs which directly supersede oldPdbId are - * returned. If true, the replacements for obsolete records are recursively - * fetched, yielding a list of all current replacements of oldPdbId. - * - * - * - * @param oldPdbId A pdb ID - * @param recurse Indicates whether the replacements for obsolete records - * should be fetched. - * @param includeObsolete Indicates whether obsolete records should be - * included in the results. - * @return The PDB which replaced oldPdbId. This may be oldPdbId itself, for - * current records. A return value of null indicates that the ID has - * been removed from the PDB or that an error has occurred. - */ - public static List getReplacement(String oldPdbId, boolean recurse, boolean includeObsolete) throws IOException { - List> attrList = getStatusIdRecords(new String[] {oldPdbId}); - //Expect a single record - if(attrList == null || attrList.size() != 1) { - logger.error("Error getting Status for {} from the PDB website.", oldPdbId); - return null; - } - - Map attrs = attrList.get(0); - - //Check that the record matches pdbId - String id = attrs.get("structureId"); - if(id == null || !id.equalsIgnoreCase(oldPdbId)) { - logger.error("Results returned from the query don't match {}", oldPdbId); - return null; - } - - //Check that the status is given - String statusStr = attrs.get("status"); - if(statusStr == null ) { - logger.error("No status returned for {}", oldPdbId); - return null; - } - - Status status = Status.fromString(statusStr); - if(status == null ) { - logger.error("Unknown status '{}'", statusStr); - return null; + if (statuses.size() != pdbIds.length) { + logger.warn("RCSB status request was for {} ids, but {} were returned", pdbIds.length, statuses.size()); } - // If we're current, just return - LinkedList results = new LinkedList<>(); - switch(status) { - case CURRENT: - results.add(oldPdbId); - return results; - case OBSOLETE: { - String replacementStr = attrs.get("replacedBy"); - if(replacementStr == null) { - logger.error("{} is OBSOLETE but lacks a replacedBy attribute.", oldPdbId); - return null; - } - replacementStr = replacementStr.toUpperCase(); - //include this result - if(includeObsolete) { - results.add(oldPdbId); - } - // Some PDBs are not replaced. - if(replacementStr.equals("NONE")) { - return results; //empty - } - - String[] replacements = replacementStr.split(" "); - Arrays.sort(replacements, new Comparator() { - @Override - public int compare(String o1, String o2) { - return o2.compareToIgnoreCase(o1); - } - }); - for(String replacement : replacements) { - - // Return the replacement. - if(recurse) { - List others = PDBStatus.getReplacement(replacement, recurse, includeObsolete); - mergeReversed(results,others); - } - else { - if(includeObsolete) { - mergeReversed(results,Arrays.asList(replacement)); - } else { - // check status of replacement - Status replacementStatus = getStatus(replacement); - switch(replacementStatus) { - case OBSOLETE: - //ignore obsolete - break; - case CURRENT: - default: - // include it - mergeReversed(results,Arrays.asList(replacement)); - } - } - } - } - - - return results; - } - case UNKNOWN: - return null; - default: { //TODO handle other cases explicitly. They might have other syntax than "replacedBy" - String replacementStr = attrs.get("replacedBy"); - - if(replacementStr == null) { - // If no "replacedBy" attribute, treat like we're current - // TODO is this correct? - results.add(oldPdbId); - return results; - } - - replacementStr = replacementStr.toUpperCase(); - // Some PDBs are not replaced. - if(replacementStr.equals("NONE")) { - return null; - } - - - //include this result, since it's not obsolete - results.add(oldPdbId); - - String[] replacements = replacementStr.split(" "); - Arrays.sort(replacements, new Comparator() { - @Override - public int compare(String o1, String o2) { - return o2.compareToIgnoreCase(o1); - } - }); - for(String replacement : replacements) { - - // Return the replacement. - if(recurse) { - List others = PDBStatus.getReplacement(replacement, recurse, includeObsolete); - mergeReversed(results,others); - } - else { - mergeReversed(results,Arrays.asList(replacement)); - } - } - - - return results; - } - } + return statuses.toArray(new Status[0]); } - /** - * Takes two reverse sorted lists of strings and merges the second into the - * first. Duplicates are removed. - * - * @param merged A reverse sorted list. Modified by this method to contain - * the contents of other. - * @param other A reverse sorted list. Not modified. - */ - private static void mergeReversed(List merged, - final List other) { - - if(other.isEmpty()) - return; - - if(merged.isEmpty()) { - merged.addAll(other); - return; - } - - ListIterator m = merged.listIterator(); - ListIterator o = other.listIterator(); - - String nextM, prevO; - prevO = o.next(); - while(m.hasNext()) { - // peek at m - nextM = m.next(); - m.previous(); - - //insert from O until exhausted or occurs after nextM - while(prevO.compareTo(nextM) > 0) { - m.add(prevO); - if(!o.hasNext()) { - return; - } - prevO = o.next(); - } - //remove duplicates - if(prevO.equals(nextM)) { - if(!o.hasNext()) { - return; - } - prevO = o.next(); - } - - m.next(); - } - m.add(prevO); - while(o.hasNext()) { - m.add(o.next()); - } - + private static Status parseStatusRecord(JsonNode jsonNode) { + // "rcsb_repository_holdings_combined": { + //"id_code_replaced_by_latest": "4HHB", + //"status": "REMOVED", + //"status_code": "OBS" + //}, + JsonNode rcsbRepoHoldingsNode = jsonNode.get("rcsb_repository_holdings_combined"); + return Status.fromString(rcsbRepoHoldingsNode.get("status").asText()); } - /** - * Get the ID of the protein which was made obsolete by newPdbId. + * Gets the current version of a PDB ID. * - * @param newPdbId PDB ID of the newer structure - * @param recurse If true, return all ancestors of newPdbId. - * Otherwise, just go one step newer than oldPdbId. - * @return A (possibly empty) list of ID(s) of the ancestor(s) of - * newPdbId, or null if an error occurred. + * @param oldPdbId the id + * @return The replacement for oldPdbId, or null if none are found. + * If entry is current then the input PDB id is returned */ - public static List getReplaces(String newPdbId, boolean recurse) throws IOException { - List> attrList = getStatusIdRecords(new String[] {newPdbId}); - //Expect a single record - if(attrList == null || attrList.size() != 1) { - //TODO Is it possible to have multiple record per ID? - // They seem to be combined into one record with space-delimited 'replaces' - logger.error("Error getting Status for {} from the PDB website.", newPdbId); - return null; - } - - Map attrs = attrList.get(0); - - //Check that the record matches pdbId - String id = attrs.get("structureId"); - if(id == null || !id.equals(newPdbId)) { - logger.error("Results returned from the query don't match {}", newPdbId); - return null; - } - - - String replacedList = attrs.get("replaces"); //space-delimited list - if(replacedList == null) { - // no replaces value; assume root - return new ArrayList(); - } - String[] directDescendents = replacedList.split("\\s"); - - // Not the root! Return the replaced PDB. - if(recurse) { - // Note: Assumes a proper directed acyclic graph of revisions - // Cycles will cause infinite loops. - List allDescendents = new LinkedList(); - for(String replaced : directDescendents) { - List roots = PDBStatus.getReplaces(replaced, recurse); - mergeReversed(allDescendents,roots); - } - mergeReversed(allDescendents,Arrays.asList(directDescendents)); - - return allDescendents; + public static String getCurrent(String oldPdbId) throws IOException { + URL url = new URL(String.format(STATUS_ENDPOINT, DEFAULT_RCSB_DATA_API_SERVER, oldPdbId.toUpperCase())); + ObjectMapper objectMapper = new ObjectMapper(); + JsonNode node = objectMapper.readValue(url.openStream(), JsonNode.class); + JsonNode rcsbRepoHoldingsNode = node.get("rcsb_repository_holdings_combined"); + Status st = Status.fromString(rcsbRepoHoldingsNode.get("status").asText()); + if (st == Status.REMOVED) { + JsonNode replacedByNode = rcsbRepoHoldingsNode.get("id_code_replaced_by_latest"); + if (replacedByNode != null) + return replacedByNode.asText(); + else + return null; + } else if (st == Status.CURRENT) { + return oldPdbId; } else { - return Arrays.asList(directDescendents); - } - } - - - /** - * The status of PDB IDs are cached to reduce server overload. - * - * This method clears the cached records. - */ - public static void clearCache() { - recordsCache.clear(); - } - - /** - * Fetches the status of one or more pdbIDs from the server. - * - *

- * Returns the results as a list of Attributes. - * Each attribute should contain "structureId" and "status" attributes, and - * possibly more. - * - *

- * Example: - *

- * http://www.rcsb.org/pdb/rest/idStatus?structureID=1HHB,4HHB
- *

-	 * <idStatus>
-	 *   <record structureId="1HHB" status="OBSOLETE" replacedBy="4HHB"/>
-	 *   <record structureId="4HHB" status="CURRENT" replaces="1HHB"/>
-	 * </idStatus>
-	 * 
- * - *

- * Results are not guaranteed to be returned in the same order as pdbIDs. - * Refer to the structureId property to match them. - * - * @param pdbIDs the PDB identifiers - * @return A map between attributes and values - */ - private static List> getStatusIdRecords(String[] pdbIDs) throws IOException { - - List> result = new ArrayList<>(pdbIDs.length); - - String serverName = DEFAULT_RCSB_DATA_API_SERVER; - - // Build REST query URL - if(pdbIDs.length < 1) { - throw new IllegalArgumentException("No pdbIDs specified"); - } - String urlStr = String.format("http://%s/pdb/rest/idStatus?structureId=",serverName); - for(String pdbId : pdbIDs) { - pdbId = pdbId.toUpperCase(); - //check the cache - if (recordsCache.containsKey(pdbId)) { - //logger.debug("Fetching "+pdbId+" from Cache"); - result.add( recordsCache.get(pdbId) ); - } else { - urlStr += pdbId + ","; - } - } - - // check if any ids still need fetching - if(urlStr.charAt(urlStr.length()-1) == '=') { - return result; - } - - logger.info("Fetching {}", urlStr); - - URL url = new URL(urlStr); - - InputStream uStream = url.openStream(); - - InputSource source = new InputSource(uStream); - SAXParserFactory parserFactory = SAXParserFactory.newInstance(); - SAXParser parser = parserFactory.newSAXParser(); - XMLReader reader = parser.getXMLReader(); - - PDBStatusXMLHandler handler = new PDBStatusXMLHandler(); - - reader.setContentHandler(handler); - reader.parse(source); - - // Fetch results of SAX parsing - List> records = handler.getRecords(); - - //add to cache - for (Map record : records) { - String pdbId = record.get("structureId").toUpperCase(); - if (pdbId != null) { - recordsCache.put(pdbId, record); - } + return null; } - // return results - result.addAll(handler.getRecords()); - - return result; } /** @@ -615,11 +174,8 @@ private static List> getStatusIdRecords(String[] pdbIDs) thr */ public static SortedSet getCurrentPDBIds() throws IOException { - //String serverName = System.getProperty(PDB_SERVER_PROPERTY); - String serverName = DEFAULT_RCSB_DATA_API_SERVER; - // Build REST query URL - String urlStr = String.format(ALL_CURRENT_ENDPOINT, serverName); + String urlStr = String.format(ALL_CURRENT_ENDPOINT, DEFAULT_RCSB_DATA_API_SERVER); URL u = new URL(urlStr); InputStream stream = URLConnectionTools.getInputStream(u, 60000); diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/LocalPDBDirectory.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/LocalPDBDirectory.java index 61735ecfa6..4dd31b25f6 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/LocalPDBDirectory.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/LocalPDBDirectory.java @@ -492,7 +492,7 @@ protected File downloadStructure(String pdbId) throws IOException{ } return downloadStructure(current, splitDirURL,false, existing); } else if(obsoleteBehavior == ObsoleteBehavior.FETCH_OBSOLETE - && PDBStatus.getStatus(pdbId) == Status.OBSOLETE) { + && PDBStatus.getStatus(pdbId) == Status.REMOVED) { return downloadStructure(pdbId, obsoleteDirURL, true, existing); } else { return downloadStructure(pdbId, splitDirURL, false, existing); diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/PDBStatusTest.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/PDBStatusTest.java index 8bcd2d1e98..bda33d98ab 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/PDBStatusTest.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/PDBStatusTest.java @@ -18,17 +18,14 @@ * http://www.biojava.org/ * */ -/** - * - */ package org.biojava.nbio.structure; import org.biojava.nbio.structure.PDBStatus.Status; import org.junit.Assert; import org.junit.Test; -import java.lang.reflect.Method; -import java.util.*; +import java.io.IOException; + /** * @author Spencer Bliven @@ -46,172 +43,20 @@ public class PDBStatusTest { *

*/ @Test - public void testGetStatus() { - Assert.assertEquals(Status.OBSOLETE, PDBStatus.getStatus("1HHB")); + public void testGetStatus() throws IOException { + Assert.assertEquals(Status.REMOVED, PDBStatus.getStatus("1HHB")); Assert.assertEquals(Status.CURRENT, PDBStatus.getStatus("3HHB")); Assert.assertEquals(Status.CURRENT, PDBStatus.getStatus("4HHB")); } @Test - public void testGetReplacement() { - Assert.assertFalse(Arrays.asList("YES").equals(Arrays.asList("NO"))); //check for deep equals - - // 1CMW is replacedBy NONE - Assert.assertEquals(Arrays.asList(), PDBStatus.getReplacement("1CMW", true, false)); - Assert.assertEquals(Arrays.asList("1CMW"), PDBStatus.getReplacement("1CMW", true, true)); - - // 1HHB is replacedBy 2-4HHB - Assert.assertEquals(Arrays.asList("3HHB"), PDBStatus.getReplacement("3HHB", false, false)); - Assert.assertEquals(Arrays.asList("3HHB"), PDBStatus.getReplacement("3HHB", false, true)); - Assert.assertEquals(Arrays.asList("4HHB", "3HHB", "2HHB"), PDBStatus.getReplacement("1HHB", false, false)); - Assert.assertEquals(Arrays.asList("4HHB", "3HHB", "2HHB", "1HHB"), PDBStatus.getReplacement("1HHB", false, true)); - - // 1CAT is replacedBy 3CAT is replacedBy 7-8CAT - Assert.assertEquals(Arrays.asList("8CAT", "7CAT", "3CAT", "1CAT"), PDBStatus.getReplacement("1CAT", true, true)); - Assert.assertEquals(Arrays.asList("8CAT", "7CAT"), PDBStatus.getReplacement("1CAT", true, false)); - Assert.assertEquals(Arrays.asList("8CAT", "7CAT", "3CAT"), PDBStatus.getReplacement("3CAT", true, true)); - Assert.assertEquals(Arrays.asList("8CAT", "7CAT"), PDBStatus.getReplacement("3CAT", true, false)); - } - - - @Test - public void testGetCurrent() { + public void testGetCurrent() throws IOException { Assert.assertEquals("4HHB", PDBStatus.getCurrent("1HHB")); Assert.assertEquals("3HHB", PDBStatus.getCurrent("3HHB")); - Assert.assertEquals(null, PDBStatus.getCurrent("1CMW")); + Assert.assertNull(PDBStatus.getCurrent("1CMW")); Assert.assertEquals("3ENI", PDBStatus.getCurrent("1KSA")); Assert.assertEquals("8CAT", PDBStatus.getCurrent("1CAT")); Assert.assertEquals("8CAT", PDBStatus.getCurrent("3CAT")); Assert.assertEquals("7CAT", PDBStatus.getCurrent("7CAT")); } - - @Test - public void testGetReplaces() { - Assert.assertEquals(new ArrayList(), Arrays.asList(new String[]{})); - - Assert.assertEquals(Arrays.asList("1HHB"), PDBStatus.getReplaces("4HHB", false)); - Assert.assertEquals(Arrays.asList("1HHB"), PDBStatus.getReplaces("3HHB", false)); - Assert.assertEquals(Arrays.asList(), PDBStatus.getReplaces("1HHB", false)); - Assert.assertEquals(Arrays.asList("1M50", "1KSA"), PDBStatus.getReplaces("3ENI", false)); - Assert.assertEquals(Arrays.asList("1M50", "1KSA"), PDBStatus.getReplaces("3ENI", true)); - Assert.assertEquals(Arrays.asList("3CAT"), PDBStatus.getReplaces("8CAT", false)); - Assert.assertEquals(Arrays.asList("3CAT", "1CAT"), PDBStatus.getReplaces("8CAT", true)); - - } - - /** - * Tests a helper method for merging that was giving me problems - */ - @Test - public void testMergeReversed() { - try { - Method mergeReversed = PDBStatus.class.getDeclaredMethod("mergeReversed", - List.class,List.class); - mergeReversed.setAccessible(true); - - - List a,b; - - b = Arrays.asList("F","A"); - a = new LinkedList(); - mergeReversed.invoke(null, a,b); - Assert.assertEquals(Arrays.asList("F", "A"), a); - - a = new LinkedList(); - a.add("B"); - mergeReversed.invoke(null, a,b); - Assert.assertEquals(Arrays.asList("F", "B", "A"), a); - - a = new LinkedList(); - a.add("G"); - mergeReversed.invoke(null, a,b); - Assert.assertEquals(Arrays.asList("G", "F", "A"), a); - - a = new LinkedList(); - a.add("1"); - mergeReversed.invoke(null, a,b); - Assert.assertEquals(Arrays.asList("F", "A", "1"), a); - - a = new LinkedList(); - a.add("G"); - a.add("1"); - mergeReversed.invoke(null, a,b); - Assert.assertEquals(Arrays.asList("G", "F", "A", "1"), a); - - b = Arrays.asList(); - mergeReversed.invoke(null, a,b); - Assert.assertEquals(Arrays.asList("G", "F", "A", "1"), a); - - b = Arrays.asList("G","D","C","A"); - a = new LinkedList(); - a.add("F"); - a.add("B"); - a.add("1"); - mergeReversed.invoke(null, a,b); - Assert.assertEquals(Arrays.asList("G", "F", "D", "C", "B", "A", "1"), a); - - } catch(Exception e) { - e.printStackTrace(); - Assert.fail(e.getMessage()); - } - } - - /** - * Test low-level connectivity to the PDB - */ - @Test - @SuppressWarnings("unchecked") - public void testGetStatusIdRecords() { - try { - Method getStatusIdRecords = PDBStatus.class.getDeclaredMethod("getStatusIdRecords", - String[].class); - getStatusIdRecords.setAccessible(true); - - - List> attrsList; - String[] pdbIds; - Map attrs; - - // Test invocation with a single ID - pdbIds = new String[] {"1HHB"}; - attrsList = (List>) getStatusIdRecords.invoke(null, (Object) pdbIds); - Assert.assertEquals("Wrong number of records.", 1, attrsList.size()); - attrs = attrsList.get(0); - Assert.assertEquals("Wrong number of attributes", 3, attrs.size()); - Assert.assertEquals("Wrong structureId", "1HHB", attrs.get("structureId")); - Assert.assertEquals("Wrong status", "OBSOLETE", attrs.get("status")); - Assert.assertEquals("Wrong replacedBy", "4HHB 3HHB 2HHB", attrs.get("replacedBy")); - - // Test with multiple IDs - pdbIds = new String[] {"1HHB","4HHB"}; - attrsList = (List>) getStatusIdRecords.invoke(null, (Object) pdbIds); - Assert.assertEquals("Wrong number of records.", 2, attrsList.size()); - attrs = attrsList.get(1); - Assert.assertEquals("Wrong number of attributes", 3, attrs.size()); - Assert.assertEquals("Wrong structureId", "4HHB", attrs.get("structureId")); - Assert.assertEquals("Wrong status", "CURRENT", attrs.get("status")); - Assert.assertEquals("Wrong replaces", "1HHB", attrs.get("replaces")); - attrs = attrsList.get(0); - Assert.assertEquals("Wrong number of attributes", 3, attrs.size()); - Assert.assertEquals("Wrong structureId", "1HHB", attrs.get("structureId")); - Assert.assertEquals("Wrong status", "OBSOLETE", attrs.get("status")); - Assert.assertEquals("Wrong replacedBy", "4HHB 3HHB 2HHB", attrs.get("replacedBy")); - - // Test invocation with a single ID - pdbIds = new String[] {"3ENI"}; - attrsList = (List>) getStatusIdRecords.invoke(null, (Object) pdbIds); - Assert.assertEquals("Wrong number of records.", 1, attrsList.size()); - attrs = attrsList.get(0); - Assert.assertEquals("Wrong number of attributes", 3, attrs.size()); - Assert.assertEquals("Wrong structureId", "3ENI", attrs.get("structureId")); - Assert.assertEquals("Wrong status", "CURRENT", attrs.get("status")); - Assert.assertEquals("Wrong replacedBy", "1M50 1KSA", attrs.get("replaces")); - - - } catch(Exception e) { - e.printStackTrace(); - Assert.fail(e.getMessage()); - } - } - } From ef35e93ecfab2f654f14d58299aa75f113e939bf Mon Sep 17 00:00:00 2001 From: Jose Duarte Date: Sun, 22 Nov 2020 15:54:01 -0800 Subject: [PATCH 008/599] Docs --- CHANGELOG.md | 2 ++ .../java/org/biojava/nbio/structure/PDBStatus.java | 10 +++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 00a530e652..22f265c548 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,8 @@ BioJava 6.0.0 (future release) * The whole `org.biojava.nbio.structure.validation` package * The `org.biojava.nbio.structure.domain.PDBDomainProvider` class to pull domain definitions from legacy RCSB PDB APIs * Support for automatically fetching dssp files from RCSB (`org.biojava.nbio.structure.secstruc.DSSPParser.fetch()`) +* `org.biojava.nbio.structure.PDBStatus`: simplified `Status` enum to 3 states, with OBSOLETE now called REMOVED +* `org.biojava.nbio.structure.PDBStatus`: removed `getReplacement` and `getReplaces` BioJava 5.4.0 ============= diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/PDBStatus.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/PDBStatus.java index 7abd790fb4..0ded68c05c 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/PDBStatus.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/PDBStatus.java @@ -59,7 +59,6 @@ public class PDBStatus { /** * Represents a simplified 3 state status of PDB IDs. * @author Spencer Bliven - * */ public enum Status { // the simplified status enum in rcsb_repository_holdings_combined @@ -87,10 +86,10 @@ else if(statusStrUpper.equalsIgnoreCase("UNRELEASED")) } /** - * Get the status of the PDB in question. + * Get the status of a PDB id. * * @param pdbId the id - * @return The status, or null if an error occurred. + * @return The status. */ public static Status getStatus(String pdbId) throws IOException { URL url = new URL(String.format(STATUS_ENDPOINT, DEFAULT_RCSB_DATA_API_SERVER, pdbId.toUpperCase())); @@ -100,11 +99,11 @@ public static Status getStatus(String pdbId) throws IOException { } /** - * Get the status of the a collection of PDBs in question in a single query. + * Get the status of a collection of PDB ids (in a single API query). * * @see #getStatus(String) * @param pdbIds the ids - * @return The status array, or null if an error occurred. + * @return The status array */ public static Status[] getStatus(String[] pdbIds) throws IOException { @@ -130,6 +129,7 @@ public static Status[] getStatus(String[] pdbIds) throws IOException { } private static Status parseStatusRecord(JsonNode jsonNode) { + // e.g. // "rcsb_repository_holdings_combined": { //"id_code_replaced_by_latest": "4HHB", //"status": "REMOVED", From 95db39cc4f17fdce3373e5145e52504f14d8643e Mon Sep 17 00:00:00 2001 From: Jose Duarte Date: Sun, 22 Nov 2020 16:30:08 -0800 Subject: [PATCH 009/599] One more test --- .../java/org/biojava/nbio/structure/PDBStatusTest.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/PDBStatusTest.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/PDBStatusTest.java index bda33d98ab..82e26bd802 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/PDBStatusTest.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/PDBStatusTest.java @@ -26,7 +26,6 @@ import java.io.IOException; - /** * @author Spencer Bliven * @@ -49,6 +48,15 @@ public void testGetStatus() throws IOException { Assert.assertEquals(Status.CURRENT, PDBStatus.getStatus("4HHB")); } + @Test + public void testGetStatusMultipleIds() throws IOException { + String[] ids = {"1HHB", "3HHB", "4HHB"}; + Status[] statuses = PDBStatus.getStatus(ids); + Assert.assertEquals(Status.REMOVED, statuses[0]); + Assert.assertEquals(Status.CURRENT, statuses[1]); + Assert.assertEquals(Status.CURRENT, statuses[2]); + } + @Test public void testGetCurrent() throws IOException { Assert.assertEquals("4HHB", PDBStatus.getCurrent("1HHB")); From 245742d522d12440ece32f5c2d665ff81c465e98 Mon Sep 17 00:00:00 2001 From: Jose Duarte Date: Tue, 24 Nov 2020 14:11:19 -0800 Subject: [PATCH 010/599] Fixing test --- .../test/symmetry/TestQuatSymmetryDetectorExamples.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/symmetry/TestQuatSymmetryDetectorExamples.java b/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/symmetry/TestQuatSymmetryDetectorExamples.java index b5a8a5a2e1..aab2ec5c89 100644 --- a/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/symmetry/TestQuatSymmetryDetectorExamples.java +++ b/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/symmetry/TestQuatSymmetryDetectorExamples.java @@ -240,7 +240,7 @@ public void testLocal() throws IOException, StructureException { testIds.add("BIO:3JC9:1"); testStoichiometries.add("A12B12C12D12E12F12G5H2"); localSymmetries = new HashMap<>(); - localSymmetries.put("A12C12D12E12F12H2","C2"); + localSymmetries.put("A12B12C12D12E12H2","C2"); localSymmetries.put("A12B12C12D12E12F12","C12"); localSymmetries.put("G5","H"); testLocalSymmetries.add(localSymmetries); @@ -268,7 +268,7 @@ public void testLocal() throws IOException, StructureException { for (QuatSymmetryResults local:foundLocal) { logger.info("Found stoichiometry "+local.getStoichiometry().toString()+" with symmetry "+local.getSymmetry()); assertTrue("Stoichiometry "+local.getStoichiometry().toString()+" not expected for "+testIds.get(iTest), - refLocal.keySet().contains(local.getStoichiometry().toString())); + refLocal.containsKey(local.getStoichiometry().toString())); assertEquals("Symmetry "+local.getSymmetry()+" with stoichiometry "+local.getStoichiometry().toString()+ " not expected for "+testIds.get(iTest), From 203f5e38252958bf8ac145861d412d88a888f359 Mon Sep 17 00:00:00 2001 From: Bhat Date: Wed, 25 Nov 2020 13:30:52 -0600 Subject: [PATCH 011/599] Flaky Test Fixed in TestStructureSerialization --- .../src/main/java/org/biojava/nbio/structure/PDBHeader.java | 1 + 1 file changed, 1 insertion(+) diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/PDBHeader.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/PDBHeader.java index dbcc0f794c..eb7245dffa 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/PDBHeader.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/PDBHeader.java @@ -108,6 +108,7 @@ public String toString(){ Class c = Class.forName(PDBHeader.class.getName()); Method[] methods = c.getMethods(); + Arrays.sort(methods, (o1, o2)->o1.getName().compareTo(o2.getName())); for (Method m : methods) { String name = m.getName(); From 846c13f1f0e6257bd24ea1b6ae12380f74b60eb9 Mon Sep 17 00:00:00 2001 From: Jose Duarte Date: Wed, 25 Nov 2020 11:51:37 -0800 Subject: [PATCH 012/599] Corrections suggested in review --- .../org/biojava/nbio/structure/PDBStatus.java | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/PDBStatus.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/PDBStatus.java index 0ded68c05c..29203825a6 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/PDBStatus.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/PDBStatus.java @@ -33,7 +33,7 @@ import java.util.*; /** - * Methods for getting the status of a PDB file (current, obsolete, unreleased) + * Methods for getting the status of a PDB file (current, removed, unreleased) * and for accessing different versions of the structure. * *

@@ -70,18 +70,16 @@ public enum Status { * @throws IllegalArgumentException If the string is not recognized */ public static Status fromString(String statusStr) { - Status status; - String statusStrUpper = statusStr.toUpperCase(); - if(statusStrUpper.equalsIgnoreCase("REMOVED")) - status = Status.REMOVED; - else if(statusStrUpper.equalsIgnoreCase("CURRENT")) - status = Status.CURRENT; - else if(statusStrUpper.equalsIgnoreCase("UNRELEASED")) - status = Status.UNRELEASED; + if (statusStr == null) return null; + if(statusStr.equalsIgnoreCase("REMOVED")) + return Status.REMOVED; + else if(statusStr.equalsIgnoreCase("CURRENT")) + return Status.CURRENT; + else if(statusStr.equalsIgnoreCase("UNRELEASED")) + return Status.UNRELEASED; else { - throw new IllegalArgumentException("Unable to parse status '"+statusStrUpper+"'."); + throw new IllegalArgumentException("Unable to parse status '"+statusStr+"'."); } - return status; } } From f04effa094b239fbba573a110aeb02a75624cfa3 Mon Sep 17 00:00:00 2001 From: Jose Duarte Date: Wed, 25 Nov 2020 11:55:12 -0800 Subject: [PATCH 013/599] Better handlng of null --- .../src/main/java/org/biojava/nbio/structure/PDBStatus.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/PDBStatus.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/PDBStatus.java index 29203825a6..dd69115c91 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/PDBStatus.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/PDBStatus.java @@ -70,7 +70,7 @@ public enum Status { * @throws IllegalArgumentException If the string is not recognized */ public static Status fromString(String statusStr) { - if (statusStr == null) return null; + if (statusStr == null) throw new IllegalArgumentException("Status string can't be null"); if(statusStr.equalsIgnoreCase("REMOVED")) return Status.REMOVED; else if(statusStr.equalsIgnoreCase("CURRENT")) From 13565b17d4d6729d4c3e86d7f42b53871133ce98 Mon Sep 17 00:00:00 2001 From: Spencer Bliven Date: Mon, 7 Dec 2020 17:32:47 +0100 Subject: [PATCH 014/599] Revert "Flaky Test Fixed in TestStructureSerialization" --- .../src/main/java/org/biojava/nbio/structure/PDBHeader.java | 1 - 1 file changed, 1 deletion(-) diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/PDBHeader.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/PDBHeader.java index eb7245dffa..dbcc0f794c 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/PDBHeader.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/PDBHeader.java @@ -108,7 +108,6 @@ public String toString(){ Class c = Class.forName(PDBHeader.class.getName()); Method[] methods = c.getMethods(); - Arrays.sort(methods, (o1, o2)->o1.getName().compareTo(o2.getName())); for (Method m : methods) { String name = m.getName(); From c290ea9af37a8e2c381437c488d426626259a3cd Mon Sep 17 00:00:00 2001 From: JonStargaryen Date: Wed, 13 Jan 2021 11:50:05 -0800 Subject: [PATCH 015/599] wip (most of structure parsing done) --- .../structure/gui/util/PDBUploadPanel.java | 1 - .../java/demo/DemoChangeChemCompProvider.java | 64 +- .../src/main/java/demo/DemoMMCIFReader.java | 1 - .../java/demo/DemoMmcifToPdbConverter.java | 47 +- .../nbio/structure/AtomPositionMap.java | 5 +- .../org/biojava/nbio/structure/Chain.java | 1 - .../org/biojava/nbio/structure/ChainImpl.java | 7 +- .../nbio/structure/DatabasePDBRevRecord.java | 62 + .../nbio/structure/DatabasePdbRevRecord.java | 43 - .../org/biojava/nbio/structure/Group.java | 99 +- .../org/biojava/nbio/structure/GroupType.java | 4 +- .../biojava/nbio/structure/HetatomImpl.java | 22 +- .../org/biojava/nbio/structure/PDBHeader.java | 6 +- .../biojava/nbio/structure/StructureIO.java | 7 +- .../biojava/nbio/structure/URLIdentifier.java | 42 +- .../nbio/structure/align/util/AtomCache.java | 5 +- .../structure/chem/AllChemCompProvider.java | 185 ++ .../biojava/nbio/structure/chem/ChemComp.java | 405 +++ .../nbio/structure/chem/ChemCompAtom.java | 205 ++ .../nbio/structure/chem/ChemCompBond.java | 114 + .../structure/chem/ChemCompContainer.java | 13 + .../structure/chem/ChemCompDescriptor.java | 80 + .../structure/chem/ChemCompGroupFactory.java | 131 + .../nbio/structure/chem/ChemCompProvider.java | 15 + .../nbio/structure/chem/ChemCompTools.java | 209 ++ .../chem/ChemicalComponentDictionary.java | 104 + .../chem/DownloadChemCompProvider.java | 420 ++++ .../nbio/structure/chem/PolymerType.java | 161 ++ .../chem/ReducedChemCompProvider.java | 56 + .../nbio/structure/chem/ResidueType.java | 125 + .../structure/contact/StructureInterface.java | 7 +- .../biojava/nbio/structure/io/BondMaker.java | 69 +- .../nbio/structure/io/FileConvert.java | 64 +- .../nbio/structure/io/MMCIFFileReader.java | 143 -- ...Impl.java => AbstractCifFileSupplier.java} | 68 +- .../structure/io/cif/ChainSupplierImpl.java | 20 + .../structure/io/cif/ChemCompConsumer.java | 14 + .../io/cif/ChemCompConsumerImpl.java | 70 + .../nbio/structure/io/cif/CifBean.java | 12 + .../structure/io/cif/CifFileConsumer.java | 274 +-- .../structure/io/cif/CifFileConverter.java | 52 +- .../structure/io/cif/CifFileSupplier.java | 4 +- .../structure/io/cif/StructureConsumer.java | 320 +++ ...erImpl.java => StructureConsumerImpl.java} | 152 +- .../io/cif/StructureSupplierImpl.java | 28 + .../io/mmcif/AllChemCompProvider.java | 246 -- .../structure/io/mmcif/ChemCompConsumer.java | 327 --- .../io/mmcif/ChemCompGroupFactory.java | 168 -- .../structure/io/mmcif/ChemCompProvider.java | 39 - .../io/mmcif/ChemicalComponentDictionary.java | 143 -- .../io/mmcif/DownloadChemCompProvider.java | 507 ---- .../structure/io/mmcif/MMCIFFileTools.java | 575 ----- .../structure/io/mmcif/MMcifConsumer.java | 116 - .../nbio/structure/io/mmcif/MMcifParser.java | 66 - .../structure/io/mmcif/MetalBondConsumer.java | 294 --- .../structure/io/mmcif/MetalBondParser.java | 86 - .../io/mmcif/ReducedChemCompProvider.java | 91 - .../io/mmcif/SimpleMMcifConsumer.java | 2167 ----------------- .../structure/io/mmcif/SimpleMMcifParser.java | 1281 ---------- .../io/mmcif/ZipChemCompProvider.java | 313 --- .../io/mmcif/chem/ChemCompTools.java | 261 -- .../io/mmcif/chem/MetalBondDistance.java | 76 - .../structure/io/mmcif/chem/PolymerType.java | 191 -- .../structure/io/mmcif/chem/ResidueType.java | 150 -- .../io/mmcif/model/AbstractBean.java | 103 - .../structure/io/mmcif/model/AtomSite.java | 218 -- .../structure/io/mmcif/model/AtomSites.java | 421 ---- .../structure/io/mmcif/model/AuditAuthor.java | 51 - .../structure/io/mmcif/model/CIFLabel.java | 38 - .../nbio/structure/io/mmcif/model/Cell.java | 143 -- .../structure/io/mmcif/model/ChemComp.java | 618 ----- .../io/mmcif/model/ChemCompAtom.java | 219 -- .../io/mmcif/model/ChemCompBond.java | 133 - .../io/mmcif/model/ChemCompDescriptor.java | 136 -- .../io/mmcif/model/DatabasePDBremark.java | 41 - .../io/mmcif/model/DatabasePDBrev.java | 83 - .../io/mmcif/model/DatabasePdbrevRecord.java | 69 - .../nbio/structure/io/mmcif/model/Entity.java | 123 - .../structure/io/mmcif/model/EntityPoly.java | 152 -- .../io/mmcif/model/EntityPolySeq.java | 72 - .../io/mmcif/model/EntitySrcGen.java | 427 ---- .../io/mmcif/model/EntitySrcNat.java | 224 -- .../io/mmcif/model/EntitySrcSyn.java | 75 - .../nbio/structure/io/mmcif/model/Exptl.java | 98 - .../structure/io/mmcif/model/IgnoreField.java | 37 - .../mmcif/model/PdbxAuditRevisionHistory.java | 66 - .../mmcif/model/PdbxChemCompDescriptor.java | 71 - .../mmcif/model/PdbxChemCompIdentifier.java | 73 - .../io/mmcif/model/PdbxDatabaseStatus.java | 101 - .../io/mmcif/model/PdbxEntityNonPoly.java | 51 - .../io/mmcif/model/PdbxNonPolyScheme.java | 107 - .../io/mmcif/model/PdbxPolySeqScheme.java | 117 - .../io/mmcif/model/PdbxStructAssembly.java | 85 - .../io/mmcif/model/PdbxStructAssemblyGen.java | 67 - .../PdbxStructAssemblyGenXMLContainer.java | 101 - .../model/PdbxStructAssemblyXMLContainer.java | 99 - .../io/mmcif/model/PdbxStructOperList.java | 222 -- .../model/PdbxStructOperListXMLContainer.java | 101 - .../nbio/structure/io/mmcif/model/Refine.java | 658 ----- .../nbio/structure/io/mmcif/model/Struct.java | 86 - .../structure/io/mmcif/model/StructAsym.java | 68 - .../structure/io/mmcif/model/StructConn.java | 466 ---- .../io/mmcif/model/StructKeywords.java | 46 - .../io/mmcif/model/StructNcsOper.java | 282 --- .../structure/io/mmcif/model/StructRef.java | 89 - .../io/mmcif/model/StructRefSeq.java | 146 -- .../io/mmcif/model/StructRefSeqDif.java | 147 -- .../structure/io/mmcif/model/StructSite.java | 114 - .../io/mmcif/model/StructSiteGen.java | 166 -- .../structure/io/mmcif/model/Symmetry.java | 71 - .../io/mmcif/model/package-info.java | 24 - .../nbio/structure/io/mmcif/package-info.java | 26 - .../quaternary/BiologicalAssemblyBuilder.java | 157 +- .../biojava/nbio/structure/TestAtomCache.java | 1 - .../structure/align/util/AtomCacheTest.java | 1 - 115 files changed, 3085 insertions(+), 15238 deletions(-) create mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/DatabasePDBRevRecord.java delete mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/DatabasePdbRevRecord.java create mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/chem/AllChemCompProvider.java create mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemComp.java create mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemCompAtom.java create mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemCompBond.java create mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemCompContainer.java create mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemCompDescriptor.java create mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemCompGroupFactory.java create mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemCompProvider.java create mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemCompTools.java create mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemicalComponentDictionary.java create mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/chem/DownloadChemCompProvider.java create mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/chem/PolymerType.java create mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ReducedChemCompProvider.java create mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ResidueType.java delete mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/MMCIFFileReader.java rename biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/{CifFileSupplierImpl.java => AbstractCifFileSupplier.java} (84%) create mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/ChainSupplierImpl.java create mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/ChemCompConsumer.java create mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/ChemCompConsumerImpl.java create mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/CifBean.java create mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/StructureConsumer.java rename biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/{CifFileConsumerImpl.java => StructureConsumerImpl.java} (89%) create mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/StructureSupplierImpl.java delete mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/AllChemCompProvider.java delete mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/ChemCompConsumer.java delete mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/ChemCompGroupFactory.java delete mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/ChemCompProvider.java delete mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/ChemicalComponentDictionary.java delete mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/DownloadChemCompProvider.java delete mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/MMCIFFileTools.java delete mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/MMcifConsumer.java delete mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/MMcifParser.java delete mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/MetalBondConsumer.java delete mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/MetalBondParser.java delete mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/ReducedChemCompProvider.java delete mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/SimpleMMcifConsumer.java delete mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/SimpleMMcifParser.java delete mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/ZipChemCompProvider.java delete mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/chem/ChemCompTools.java delete mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/chem/MetalBondDistance.java delete mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/chem/PolymerType.java delete mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/chem/ResidueType.java delete mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/AbstractBean.java delete mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/AtomSite.java delete mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/AtomSites.java delete mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/AuditAuthor.java delete mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/CIFLabel.java delete mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/Cell.java delete mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/ChemComp.java delete mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/ChemCompAtom.java delete mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/ChemCompBond.java delete mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/ChemCompDescriptor.java delete mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/DatabasePDBremark.java delete mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/DatabasePDBrev.java delete mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/DatabasePdbrevRecord.java delete mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/Entity.java delete mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/EntityPoly.java delete mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/EntityPolySeq.java delete mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/EntitySrcGen.java delete mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/EntitySrcNat.java delete mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/EntitySrcSyn.java delete mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/Exptl.java delete mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/IgnoreField.java delete mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/PdbxAuditRevisionHistory.java delete mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/PdbxChemCompDescriptor.java delete mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/PdbxChemCompIdentifier.java delete mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/PdbxDatabaseStatus.java delete mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/PdbxEntityNonPoly.java delete mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/PdbxNonPolyScheme.java delete mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/PdbxPolySeqScheme.java delete mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/PdbxStructAssembly.java delete mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/PdbxStructAssemblyGen.java delete mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/PdbxStructAssemblyGenXMLContainer.java delete mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/PdbxStructAssemblyXMLContainer.java delete mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/PdbxStructOperList.java delete mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/PdbxStructOperListXMLContainer.java delete mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/Refine.java delete mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/Struct.java delete mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/StructAsym.java delete mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/StructConn.java delete mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/StructKeywords.java delete mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/StructNcsOper.java delete mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/StructRef.java delete mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/StructRefSeq.java delete mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/StructRefSeqDif.java delete mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/StructSite.java delete mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/StructSiteGen.java delete mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/Symmetry.java delete mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/package-info.java delete mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/package-info.java diff --git a/biojava-structure-gui/src/main/java/org/biojava/nbio/structure/gui/util/PDBUploadPanel.java b/biojava-structure-gui/src/main/java/org/biojava/nbio/structure/gui/util/PDBUploadPanel.java index 2c542f0797..92efbeaf36 100644 --- a/biojava-structure-gui/src/main/java/org/biojava/nbio/structure/gui/util/PDBUploadPanel.java +++ b/biojava-structure-gui/src/main/java/org/biojava/nbio/structure/gui/util/PDBUploadPanel.java @@ -26,7 +26,6 @@ import org.biojava.nbio.structure.StructureException; import org.biojava.nbio.structure.StructureTools; import org.biojava.nbio.structure.align.util.UserConfiguration; -import org.biojava.nbio.structure.io.MMCIFFileReader; import org.biojava.nbio.structure.io.PDBFileReader; import org.biojava.nbio.structure.io.StructureIOFile; import org.slf4j.Logger; diff --git a/biojava-structure/src/main/java/demo/DemoChangeChemCompProvider.java b/biojava-structure/src/main/java/demo/DemoChangeChemCompProvider.java index 756c44302f..b8e4eb5430 100644 --- a/biojava-structure/src/main/java/demo/DemoChangeChemCompProvider.java +++ b/biojava-structure/src/main/java/demo/DemoChangeChemCompProvider.java @@ -23,35 +23,33 @@ import org.biojava.nbio.structure.Chain; import org.biojava.nbio.structure.Group; import org.biojava.nbio.structure.Structure; +import org.biojava.nbio.structure.chem.AllChemCompProvider; +import org.biojava.nbio.structure.chem.ChemCompGroupFactory; +import org.biojava.nbio.structure.chem.ChemCompProvider; +import org.biojava.nbio.structure.chem.DownloadChemCompProvider; import org.biojava.nbio.structure.io.FileParsingParameters; import org.biojava.nbio.structure.io.PDBFileReader; -import org.biojava.nbio.structure.io.mmcif.AllChemCompProvider; -import org.biojava.nbio.structure.io.mmcif.ChemCompGroupFactory; -import org.biojava.nbio.structure.io.mmcif.ChemCompProvider; -import org.biojava.nbio.structure.io.mmcif.DownloadChemCompProvider; import java.util.List; - /** - * This demo shows how to use an alternative ChemCompProvider. The default mechanism in BioJava is to access chemical components - * by using the {@link DownloadChemCompProvider}. It fetches and locally caches chemical component definitions as they are encountered during file parsing. - * It can be enabled by using the {@link FileParsingParameters#setLoadChemCompInfo(boolean)} method. + * This demo shows how to use an alternative ChemCompProvider. The default mechanism in BioJava is to access chemical + * componentsby using the {@link DownloadChemCompProvider}. It fetches and locally caches chemical component + * definitions as they are encountered during file parsing. It can be enabled by using the + * {@link FileParsingParameters#setLoadChemCompInfo(boolean)} method. * - * The {@link AllChemCompProvider} downloads and unpacks all chemcomps. It is slower and requires more memory than the default {@link DownloadChemCompProvider}, - * but it avoids network access to the FTP site, if a new chemcomp is detected, that has not been downloaded yet. + * The {@link AllChemCompProvider} downloads and unpacks all chemcomps. It is slower and requires more memory than the + * default {@link DownloadChemCompProvider}, but it avoids network access to the FTP site, if a new chemcomp is + * detected, that has not been downloaded yet. * * Since all chemcomps will be kept in memory, the standard memory that is available to a JVM will not be sufficient * in order to run this demo. Please start with -Xmx200M * * @author Andreas Prlic - * */ public class DemoChangeChemCompProvider { - public static void main(String[] args){ String pdbId = "1O1G"; - boolean loadChemComp = true; ////// @@ -66,82 +64,60 @@ public static void main(String[] args){ // or via // by setting the PDB_PATH environmental variable or system property // when running the demo (e.g. -DPDB_DIR=/path/to/pdb) - - if ( loadChemComp) { - + if (loadChemComp) { // The AllChemCompProvider loads all chem comps at startup. // This is slow (13 sec on my laptop) and requires more // memory than the default DownloadChemCompProvider. // In contrast to it it keeps all definitions in memory. ChemCompProvider all = new AllChemCompProvider(); - ChemCompGroupFactory.setChemCompProvider(all); } DemoChangeChemCompProvider demo = new DemoChangeChemCompProvider(); // run the demo - demo.basicLoad(reader,loadChemComp, pdbId); - + demo.basicLoad(reader, pdbId); } - public void basicLoad(PDBFileReader reader, boolean loadChemComp, String pdbId){ - + public void basicLoad(PDBFileReader reader, String pdbId) { try { // configure the parameters of file parsing - FileParsingParameters params = new FileParsingParameters(); - // should the ATOM and SEQRES residues be aligned when creating the internal data model? // only do this if you need to work with SEQRES sequences. If all you need are ATOMs, then // set it to false to have quicker file loading. params.setAlignSeqRes(true); - // // should secondary structure get parsed from the file params.setParseSecStruc(false); - reader.setFileParsingParameters(params); - Structure struc = reader.getStructureById(pdbId); - printStructure(struc); - - } catch (Exception e){ e.printStackTrace(); } - } private void printStructure(Structure struc) { - System.out.println(struc); - - //Chain c = struc.getChainByPDB("C"); String pdbid = struc.getPDBCode(); for (int i = 0; i < struc.nrModels(); i++) { - // loop chain for (Chain ch : struc.getModel(i)) { - if (! ch.getName().equals("A") ) + if (!ch.getName().equals("A")) { continue; - System.out.println(pdbid + ">>>" + ch.getName() + ">>>" - + ch.getAtomSequence()); - System.out.println(pdbid + ">>>" + ch.getName() + ">>>" - + ch.getSeqResSequence()); + } + System.out.println(pdbid + ">>>" + ch.getName() + ">>>" + ch.getAtomSequence()); + System.out.println(pdbid + ">>>" + ch.getName() + ">>>" + ch.getSeqResSequence()); // Test the getAtomGroups() and getSeqResGroups() method - List group = ch.getSeqResGroups(); int seqPos = 0; for (Group gp : group) { - System.out.println(ch.getName() + ":"+seqPos + ":" + gp.getResidueNumber() + ":" - + gp.getPDBName() + " " + gp.getType()); + System.out.println(ch.getName() + ":" + seqPos + ":" + gp.getResidueNumber() + ":" + + gp.getPDBName() + " " + gp.getType()); seqPos++; } } } - - } } diff --git a/biojava-structure/src/main/java/demo/DemoMMCIFReader.java b/biojava-structure/src/main/java/demo/DemoMMCIFReader.java index 8ed28e9c58..d5ae3fea58 100644 --- a/biojava-structure/src/main/java/demo/DemoMMCIFReader.java +++ b/biojava-structure/src/main/java/demo/DemoMMCIFReader.java @@ -26,7 +26,6 @@ import org.biojava.nbio.structure.*; import org.biojava.nbio.structure.align.util.AtomCache; -import org.biojava.nbio.structure.io.MMCIFFileReader; import org.biojava.nbio.structure.io.StructureProvider; import java.util.List; diff --git a/biojava-structure/src/main/java/demo/DemoMmcifToPdbConverter.java b/biojava-structure/src/main/java/demo/DemoMmcifToPdbConverter.java index 5a5c1a222f..bd84ae8f1e 100644 --- a/biojava-structure/src/main/java/demo/DemoMmcifToPdbConverter.java +++ b/biojava-structure/src/main/java/demo/DemoMmcifToPdbConverter.java @@ -23,9 +23,6 @@ import org.biojava.nbio.structure.Chain; import org.biojava.nbio.structure.Structure; -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 java.io.BufferedReader; import java.io.File; @@ -38,42 +35,32 @@ * An example of how to convert mmCIF file to PDB file * * @author Jose Duarte - * */ -public class DemoMmcifToPdbConverter -{ - +public class DemoMmcifToPdbConverter { public static void main(String[] args) throws Exception { - File inFile = new File(args[0]); File outFile = new File(args[1]); convert(inFile, outFile); } - - public static void convert(File inFile, File outFile) throws IOException { - - MMcifParser parser = new SimpleMMcifParser(); - - SimpleMMcifConsumer consumer = new SimpleMMcifConsumer(); - parser.addMMcifConsumer(consumer); - parser.parse(new BufferedReader(new InputStreamReader(new FileInputStream(inFile)))); - - // now get the protein structure. - Structure cifStructure = consumer.getStructure(); - - // and write it out as PDB format - PrintWriter pr = new PrintWriter(outFile); - for (Chain c : cifStructure.getChains()) { - // we can override the chain name, the mmCIF chain names might have more than 1 character - c.setName(c.getName().substring(0, 1)); - pr.print(c.toPDB()); - pr.println("TER"); - } + MMcifParser parser = new SimpleMMcifParser(); + SimpleMMcifConsumer consumer = new SimpleMMcifConsumer(); + parser.addMMcifConsumer(consumer); + parser.parse(new BufferedReader(new InputStreamReader(new FileInputStream(inFile)))); + + // now get the protein structure. + Structure cifStructure = consumer.getStructure(); + + // and write it out as PDB format + PrintWriter pr = new PrintWriter(outFile); + for (Chain c : cifStructure.getChains()) { + // we can override the chain name, the mmCIF chain names might have more than 1 character + c.setName(c.getName().substring(0, 1)); + pr.print(c.toPDB()); + pr.println("TER"); + } pr.close(); - - } } diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/AtomPositionMap.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/AtomPositionMap.java index b6c806417e..d6d6f778ff 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/AtomPositionMap.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/AtomPositionMap.java @@ -32,9 +32,8 @@ import java.util.NavigableMap; import java.util.TreeMap; -import org.biojava.nbio.structure.io.mmcif.chem.PolymerType; -import org.biojava.nbio.structure.io.mmcif.chem.ResidueType; -import org.biojava.nbio.structure.io.mmcif.model.ChemComp; +import org.biojava.nbio.structure.chem.PolymerType; +import org.biojava.nbio.structure.chem.ResidueType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/Chain.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/Chain.java index 150d806995..c8413228ee 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/Chain.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/Chain.java @@ -25,7 +25,6 @@ import org.biojava.nbio.core.sequence.template.Sequence; import org.biojava.nbio.structure.io.FileParsingParameters; -import org.biojava.nbio.structure.io.mmcif.model.ChemComp; import java.io.Serializable; import java.util.List; diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/ChainImpl.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/ChainImpl.java index 9400333aba..7275fb07a9 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/ChainImpl.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/ChainImpl.java @@ -24,10 +24,9 @@ package org.biojava.nbio.structure; +import org.biojava.nbio.structure.chem.ChemCompGroupFactory; +import org.biojava.nbio.structure.chem.PolymerType; import org.biojava.nbio.structure.io.FileConvert; -import org.biojava.nbio.structure.io.mmcif.ChemCompGroupFactory; -import org.biojava.nbio.structure.io.mmcif.chem.PolymerType; -import org.biojava.nbio.structure.io.mmcif.model.ChemComp; import org.biojava.nbio.core.exceptions.CompoundNotFoundException; import org.biojava.nbio.core.sequence.ProteinSequence; import org.biojava.nbio.core.sequence.compound.AminoAcidCompound; @@ -686,7 +685,7 @@ public String toPDB() { @Override public String toMMCIF() { - return FileConvert.toMMCIF(this, true); + return FileConvert.toMMCIF(this); } @Override diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/DatabasePDBRevRecord.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/DatabasePDBRevRecord.java new file mode 100644 index 0000000000..e14ef16776 --- /dev/null +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/DatabasePDBRevRecord.java @@ -0,0 +1,62 @@ +package org.biojava.nbio.structure; + +import org.biojava.nbio.structure.io.cif.CifBean; + +import java.util.ArrayList; +import java.util.List; + +public class DatabasePDBRevRecord implements CifBean { + private static final long serialVersionUID = 1L; + private String revNum; + private String type; + private String details; + + public DatabasePDBRevRecord() { + + } + + public DatabasePDBRevRecord(String revNum, String type, String details) { + this.revNum = revNum; + this.type = type; + this.details = details; + } + + public DatabasePDBRevRecord(org.rcsb.cif.schema.mm.DatabasePDBRevRecord cif, int row) { + this(cif.getDetails().get(row), + cif.getRevNum().getStringData(row), + cif.getType().get(row)); + } + + public String getRevNum() { + return revNum; + } + + public void setRevNum(String revNum) { + this.revNum = revNum; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getDetails() { + return details; + } + + public void setDetails(String details) { + this.details = details; + } + + @Override + public String toString() { + return "DatabasePDBRevRecord{" + + "revNum='" + revNum + '\'' + + ", type='" + type + '\'' + + ", details='" + details + '\'' + + '}'; + } +} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/DatabasePdbRevRecord.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/DatabasePdbRevRecord.java deleted file mode 100644 index 91ec85549f..0000000000 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/DatabasePdbRevRecord.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.biojava.nbio.structure; - -import java.io.Serializable; - -public class DatabasePdbRevRecord implements Serializable { - private static final long serialVersionUID = -791924804009516791L; - private String rev_num; - private String type; - private String details; - - public String getRev_num() { - return rev_num; - } - - public void setRev_num(String rev_num) { - this.rev_num = rev_num; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public String getDetails() { - return details; - } - - public void setDetails(String details) { - this.details = details; - } - - @Override - public String toString() { - return "DatabasePdbrevRecord{" + - "rev_num='" + rev_num + '\'' + - ", type='" + type + '\'' + - ", details='" + details + '\'' + - '}'; - } -} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/Group.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/Group.java index f2bc5a506a..36b8d3b1cd 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/Group.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/Group.java @@ -23,7 +23,7 @@ */ package org.biojava.nbio.structure; -import org.biojava.nbio.structure.io.mmcif.model.ChemComp; +import org.biojava.nbio.structure.chem.ChemComp; import java.io.Serializable; import java.util.Iterator; @@ -53,29 +53,28 @@ * */ public interface Group extends Serializable { - /** Group property key for secondary structure annotation */ - public static final String SEC_STRUC = "secstruc"; + String SEC_STRUC = "secstruc"; /** * Get number of atoms. * @return number of atoms of this Group */ - public int size(); + int size(); /** * Return true or false, depending if this group has 3D coordinates or not. * * @return true if Group has 3D coordinates */ - public boolean has3D (); + boolean has3D(); /** * Flag if group has 3D data . * * @param flag true to set flag that this Group has 3D coordinates */ - public void setPDBFlag(boolean flag); + void setPDBFlag(boolean flag); /** * Get Type of group, one of {@link GroupType#AMINOACID}, {@link GroupType#HETATM} @@ -83,14 +82,14 @@ public interface Group extends Serializable { * * @return a String representing the type value */ - public GroupType getType(); + GroupType getType(); /** * Add an atom to this group. * * @param atom an Atom object */ - public void addAtom(Atom atom); + void addAtom(Atom atom); /** * Get list of atoms. @@ -98,21 +97,20 @@ public interface Group extends Serializable { * @return a List object representing the atoms * @see #setAtoms(List) */ - public List getAtoms() ; - + List getAtoms(); /** * Set the atoms of this group. * @see Atom * @param atoms a list of atoms */ - public void setAtoms(List atoms); + void setAtoms(List atoms); /** * Remove all atoms from this group. * */ - public void clearAtoms(); + void clearAtoms(); /** * Get an atom given its PDB name. @@ -125,15 +123,15 @@ public interface Group extends Serializable { * @param name a trimmed String representing the atom's PDB name, e.g. "CA" * @return an Atom object or null if no such atom exists within this group */ - public Atom getAtom(String name) ; - + Atom getAtom(String name); + /** * Get at atom by position. * * @param position an int * @return an Atom object or null if no Atom exists for given position */ - public Atom getAtom(int position) ; + Atom getAtom(int position); /** * Tell whether a particular atom exists within this group. @@ -143,7 +141,7 @@ public interface Group extends Serializable { * @param name a trimmed String representing the atom's PDB name, e.g. "CA" * @return true if Atom with name exists within this group */ - public boolean hasAtom(String name); + boolean hasAtom(String name); /** * Get the PDB 3-letter name for this group. (e.g. ALA) @@ -151,7 +149,7 @@ public interface Group extends Serializable { * @return a String representing the PDBName value * @see #setPDBName */ - public String getPDBName(); + String getPDBName(); /** * Set the PDB 3-letter name for this group. (e.g. ALA) @@ -159,8 +157,7 @@ public interface Group extends Serializable { * @param s a String specifying the PDBName value * @see #getPDBName */ - public void setPDBName(String s) ; - + void setPDBName(String s); /** * Calculate if this group has all atoms required for an amino acid backbone. @@ -183,33 +180,28 @@ public interface Group extends Serializable { * @return true if all Atoms required for an AminoAcid are available (N, CA, C, O) * @see #getType */ - public boolean hasAminoAtoms() ; - + boolean hasAminoAtoms(); /** * Check if this group is a polymeric group, from the definition in Chemical Component Dictionary * * @return true if a polymeric group */ - public boolean isPolymeric(); - + boolean isPolymeric(); /** * Check if this group is an aminoacid group, from the definition in Chemical Component Dictionary * * @return true if an amino acid */ - public boolean isAminoAcid(); - + boolean isAminoAcid(); /** * Check if this group is a nucleotide group, from the definition in Chemical Component Dictionary * * @return true if a nucleotide */ - public boolean isNucleotide(); - - + boolean isNucleotide(); /** * Properties of this amino acid. Currently available properties are: @@ -220,7 +212,7 @@ public interface Group extends Serializable { * @param properties a Map object specifying the properties value * @see #getProperties */ - public void setProperties(Map properties) ; + void setProperties(Map properties); /** * Return properties. @@ -228,7 +220,7 @@ public interface Group extends Serializable { * * @return a HashMap object representing the properties value */ - public Map getProperties() ; + Map getProperties(); /** * Set a single property . @@ -237,7 +229,7 @@ public interface Group extends Serializable { * @param value an Object * @see #getProperty */ - public void setProperty(String key, Object value) ; + void setProperty(String key, Object value); /** * Get a single property . @@ -246,21 +238,20 @@ public interface Group extends Serializable { * @return an Object * @see #setProperty */ - public Object getProperty(String key) ; + Object getProperty(String key); /** * Get an Atom Iterator. * * @return an Iterator object */ - public Iterator iterator() ; - + Iterator iterator(); /** * Returns and identical copy of this Group object . * @return and identical copy of this Group object */ - public Object clone(); + Object clone(); /** * Sets the back-reference to its parent Chain. @@ -268,7 +259,7 @@ public interface Group extends Serializable { * @see #getChain() * @since 3.0 */ - public void setChain(Chain chain); + void setChain(Chain chain); /** * Returns the parent Chain of the Group. @@ -277,7 +268,7 @@ public interface Group extends Serializable { * @see #setChain(Chain) * @since 3.0 */ - public Chain getChain() ; + Chain getChain(); /** * Returns a dynamically created ResidueNumber for the group - this @@ -286,15 +277,14 @@ public interface Group extends Serializable { * @return ResidueNumber for the group. * @since 3.0 */ - public ResidueNumber getResidueNumber(); - + ResidueNumber getResidueNumber(); /** * Sets the ResidueNumber for this Group * * @param residueNumber the PDB residueNumber */ - public void setResidueNumber(ResidueNumber residueNumber); + void setResidueNumber(ResidueNumber residueNumber); /** * Utility method to temporarily set a chainID for a group, if a parent chain object does not exist yet. @@ -304,7 +294,7 @@ public interface Group extends Serializable { * @param residueNumber * @param iCode */ - public void setResidueNumber(String chainId, Integer residueNumber, Character iCode); + void setResidueNumber(String chainId, Integer residueNumber, Character iCode); /** * Utility method for returning the chainId of the Group or null if no @@ -314,22 +304,21 @@ public interface Group extends Serializable { * @since 3.0 * @return the ID of the chain */ - public String getChainId(); + String getChainId(); /** * Set the Chemical Component that closer describes this group. * * @param cc the chemical component */ - public void setChemComp(ChemComp cc); + void setChemComp(ChemComp cc); /** * Get the chemical component that closer describes this group. If the information does not exist yet, fetches the information from PDB web site. * * @return the Chemical Component definition for this Group. */ - public ChemComp getChemComp(); - + ChemComp getChemComp(); /** * Check if this group has alternate location groups. @@ -337,8 +326,7 @@ public interface Group extends Serializable { * @return boolean flag if there are alternate locations. * @see #getAltLocs() */ - public boolean hasAltLoc(); - + boolean hasAltLoc(); /** * Get the list of other alternate location groups. @@ -363,14 +351,14 @@ public interface Group extends Serializable { * * @return List of other groups that are on alternate locations */ - public List getAltLocs(); + List getAltLocs(); /** * Add a group that is an alternate location for this group. * * @param g the altloc group to add */ - public void addAltLoc(Group g); + void addAltLoc(Group g); /** * Determines if this group is water. @@ -378,7 +366,7 @@ public interface Group extends Serializable { * @see GroupType#WATERNAMES * @return true if it's water, false otherwise. */ - public boolean isWater(); + boolean isWater(); /** * Gets the alternate location group to this group that has the alt-loc character code passed. @@ -386,21 +374,20 @@ public interface Group extends Serializable { * @param altLoc the alternate location code of the group desired * @return the alternate location group if found, or null otherwise */ - public Group getAltLocGroup(Character altLoc); - + Group getAltLocGroup(Character altLoc); /** * Attempts to reduce the memory imprint of this group by trimming * all internal Collection objects to the required size. * */ - public void trimToSize(); + void trimToSize(); /** * Function to get the Group as an MDL molblock * @return the string of the MDL molblock */ - public String toSDF(); + String toSDF(); /** * Tells whether the group is annotated as HETATM in the file. @@ -408,7 +395,7 @@ public interface Group extends Serializable { * polymeric group is in a ligand chain or not. * @return */ - public boolean isHetAtomInFile(); + boolean isHetAtomInFile(); /** * Sets the field isHetAtomInFile which is intented only for @@ -416,5 +403,5 @@ public interface Group extends Serializable { * or in a polymeric chain. * @param isHetAtomInFile */ - public void setHetAtomInFile(boolean isHetAtomInFile); + void setHetAtomInFile(boolean isHetAtomInFile); } diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/GroupType.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/GroupType.java index 234813ef42..7fa92f7363 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/GroupType.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/GroupType.java @@ -20,8 +20,8 @@ */ package org.biojava.nbio.structure; -import org.biojava.nbio.structure.io.mmcif.chem.PolymerType; -import org.biojava.nbio.structure.io.mmcif.chem.ResidueType; +import org.biojava.nbio.structure.chem.PolymerType; +import org.biojava.nbio.structure.chem.ResidueType; import java.util.*; diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/HetatomImpl.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/HetatomImpl.java index 037dcb2b0b..ddc4f2f636 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/HetatomImpl.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/HetatomImpl.java @@ -23,15 +23,19 @@ */ package org.biojava.nbio.structure; +import org.biojava.nbio.structure.chem.ChemCompGroupFactory; +import org.biojava.nbio.structure.chem.PolymerType; +import org.biojava.nbio.structure.chem.ResidueType; import org.biojava.nbio.structure.io.GroupToSDF; -import org.biojava.nbio.structure.io.mmcif.ChemCompGroupFactory; -import org.biojava.nbio.structure.io.mmcif.chem.PolymerType; -import org.biojava.nbio.structure.io.mmcif.chem.ResidueType; -import org.biojava.nbio.structure.io.mmcif.model.ChemComp; +import org.rcsb.cif.schema.mm.ChemComp; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; /** * @@ -332,9 +336,9 @@ public boolean isAminoAcid() { return getType().equals(GroupType.AMINOACID); - ResidueType rt = cc.getResidueType(); + ResidueType rt = ResidueType.getResidueTypeFromString(cc.getType().get(0)); - if ( rt.equals(ResidueType.nonPolymer)) + if (ResidueType.nonPolymer.equals(rt)) return false; PolymerType pt = rt.getPolymerType(); @@ -351,9 +355,9 @@ public boolean isNucleotide() { if ( cc == null) return getType().equals(GroupType.NUCLEOTIDE); - ResidueType rt = cc.getResidueType(); + ResidueType rt = ResidueType.getResidueTypeFromString(cc.getType().get(0)); - if ( rt.equals(ResidueType.nonPolymer)) + if (ResidueType.nonPolymer.equals(rt)) return false; PolymerType pt = rt.getPolymerType(); diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/PDBHeader.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/PDBHeader.java index 1071c52c23..d65c61ae95 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/PDBHeader.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/PDBHeader.java @@ -76,7 +76,7 @@ public class PDBHeader implements PDBRecord { private Map bioAssemblies ; - List revisionRecords; + List revisionRecords; public PDBHeader(){ @@ -662,11 +662,11 @@ public int getNrBioAssemblies() { return this.bioAssemblies.size(); } - public List getRevisionRecords() { + public List getRevisionRecords() { return revisionRecords; } - public void setRevisionRecords(List revisionRecords) { + public void setRevisionRecords(List revisionRecords) { this.revisionRecords = revisionRecords; } diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/StructureIO.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/StructureIO.java index 193ed78e3d..e0592dfae3 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/StructureIO.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/StructureIO.java @@ -25,8 +25,10 @@ import java.util.List; import org.biojava.nbio.structure.align.util.AtomCache; -import org.biojava.nbio.structure.io.MMCIFFileReader; +import org.biojava.nbio.structure.io.BcifFileReader; +import org.biojava.nbio.structure.io.CifFileReader; import org.biojava.nbio.structure.io.PDBFileReader; +import org.rcsb.cif.binary.BinaryCifReader; /** * A class that provides static access methods for easy lookup of protein structure related components @@ -282,7 +284,8 @@ public static void setPdbPath(String pathToPDBFiles){ public static enum StructureFiletype { PDB( (new PDBFileReader()).getExtensions()), - CIF( new MMCIFFileReader().getExtensions()), + CIF(new CifFileReader().getExtensions()), + BCIF(new BcifFileReader().getExtensions()), UNKNOWN(Collections.emptyList()); private List extensions; diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/URLIdentifier.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/URLIdentifier.java index 653683ee0f..91cccd6a38 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/URLIdentifier.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/URLIdentifier.java @@ -20,10 +20,14 @@ */ package org.biojava.nbio.structure; -import java.io.BufferedReader; +import org.biojava.nbio.structure.StructureIO.StructureFiletype; +import org.biojava.nbio.structure.align.util.AtomCache; +import org.biojava.nbio.structure.io.PDBFileReader; +import org.biojava.nbio.structure.io.cif.CifFileConverter; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; import java.net.MalformedURLException; import java.net.URL; @@ -36,16 +40,6 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.biojava.nbio.core.util.InputStreamProvider; -import org.biojava.nbio.structure.StructureIO.StructureFiletype; -import org.biojava.nbio.structure.align.util.AtomCache; -import org.biojava.nbio.structure.io.PDBFileReader; -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.slf4j.Logger; -import org.slf4j.LoggerFactory; - /** * Represents a structure loaded from a URL (including a file URL) * @@ -159,27 +153,7 @@ public Structure loadStructure(AtomCache cache) throws StructureException, switch(format) { case CIF: - // need to do mmcif parsing! - - InputStreamProvider prov = new InputStreamProvider(); - InputStream inStream = prov.getInputStream(url); - - MMcifParser parser = new SimpleMMcifParser(); - - SimpleMMcifConsumer consumer = new SimpleMMcifConsumer(); - consumer.setFileParsingParameters(cache.getFileParsingParams()); - - - parser.addMMcifConsumer(consumer); - - try { - parser.parse(new BufferedReader(new InputStreamReader(inStream))); - } catch (IOException e){ - e.printStackTrace(); - } - - // now get the protein structure. - return consumer.getStructure(); + return CifFileConverter.fromURL(url); default: case PDB: // pdb file based parsing diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/align/util/AtomCache.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/align/util/AtomCache.java index 4b96d5f433..cc0220da07 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/align/util/AtomCache.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/align/util/AtomCache.java @@ -33,10 +33,10 @@ import org.biojava.nbio.structure.cath.CathDatabase; import org.biojava.nbio.structure.cath.CathDomain; import org.biojava.nbio.structure.cath.CathFactory; +import org.biojava.nbio.structure.io.CifFileReader; import org.biojava.nbio.structure.io.FileParsingParameters; import org.biojava.nbio.structure.io.LocalPDBDirectory.FetchBehavior; import org.biojava.nbio.structure.io.LocalPDBDirectory.ObsoleteBehavior; -import org.biojava.nbio.structure.io.MMCIFFileReader; import org.biojava.nbio.structure.io.MMTFFileReader; import org.biojava.nbio.structure.io.PDBFileReader; import org.biojava.nbio.core.util.FileDownloadUtils; @@ -879,12 +879,11 @@ protected Structure loadStructureFromCifByPdbId(String pdbId) throws IOException Structure s; flagLoading(pdbId); try { - MMCIFFileReader reader = new MMCIFFileReader(path); + CifFileReader reader = new CifFileReader(path); reader.setFetchBehavior(fetchBehavior); reader.setObsoleteBehavior(obsoleteBehavior); reader.setFileParsingParameters(params); s = reader.getStructureById(pdbId.toLowerCase()); - } finally { flagLoadingFinished(pdbId); } diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/AllChemCompProvider.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/AllChemCompProvider.java new file mode 100644 index 0000000000..ef3b7414b8 --- /dev/null +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/AllChemCompProvider.java @@ -0,0 +1,185 @@ +package org.biojava.nbio.structure.chem; + +import org.biojava.nbio.core.util.InputStreamProvider; +import org.biojava.nbio.structure.align.util.UserConfiguration; +import org.biojava.nbio.structure.io.LocalPDBDirectory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.URL; +import java.util.concurrent.atomic.AtomicBoolean; + +/** + * A ChemComp provider that downloads and caches the components.cif file from the wwPDB site. It then loads + * all chemical components at startup and keeps them in memory. This provider is not used as a default + * since it is slower at startup and requires more memory than the {@link DownloadChemCompProvider} that is used by default. + * + * @author Andreas Prlic + * + */ +public class AllChemCompProvider implements ChemCompProvider, Runnable{ + private static final Logger logger = LoggerFactory.getLogger(AllChemCompProvider.class); + public static final String COMPONENTS_FILE_LOCATION = "pub/pdb/data/monomers/components.cif.gz"; + + private static String path; + private static String serverName; + + // there will be only one copy of the dictionary across all instances + // to reduce memory impact + static ChemicalComponentDictionary dict; + + // flags to make sure there is only one thread running that is loading the dictionary + static AtomicBoolean loading = new AtomicBoolean(false); + static AtomicBoolean isInitialized = new AtomicBoolean(false); + + public AllChemCompProvider(){ + if (loading.get()) { + logger.warn("other thread is already loading all chemcomps, no need to init twice"); + return; + } + if (isInitialized.get()) { + return; + } + + loading.set(true); + + Thread t = new Thread(this); + t.start(); + } + + /** + * make sure all paths are initialized correctly + */ + private static void initPath(){ + if (path == null) { + UserConfiguration config = new UserConfiguration(); + path = config.getCacheFilePath(); + } + } + + private static void initServerName() { + if (serverName == null) { + serverName = LocalPDBDirectory.getServerName(); + } + } + + private void ensureFileExists() { + String fileName = getLocalFileName(); + File f = new File(fileName); + + if (!f.exists()) { + try { + downloadFile(); + } catch (IOException e) { + logger.error("Caught IOException", e); + } + } + } + + /** + * Downloads the components.cif.gz file from the wwPDB site. + */ + public static void downloadFile() throws IOException { + initPath(); + initServerName(); + + String localName = getLocalFileName(); + String u = serverName + "/" + COMPONENTS_FILE_LOCATION; + + downloadFileFromRemote(new URL(u), new File(localName)); + } + + private static void downloadFileFromRemote(URL remoteURL, File localFile) throws IOException { + logger.info("Downloading " + remoteURL + " to: " + localFile); + FileOutputStream out = new FileOutputStream(localFile); + + InputStream in = remoteURL.openStream(); + byte[] buf = new byte[4 * 1024]; // 4K buffer + int bytesRead; + while ((bytesRead = in.read(buf)) != -1) { + out.write(buf, 0, bytesRead); + } + in.close(); + out.close(); + } + + private static String getLocalFileName(){ + File dir = new File(path, DownloadChemCompProvider.CHEM_COMP_CACHE_DIRECTORY); + + if (!dir.exists()) { + logger.info("Creating directory {}", dir.toString()); + dir.mkdir(); + } + + return new File(dir, "components.cif.gz").toString(); + } + + /** + * Load all {@link ChemComp} definitions into memory. + */ + private void loadAllChemComps() throws IOException { + String fileName = getLocalFileName(); + logger.debug("Loading " + fileName); + InputStreamProvider isp = new InputStreamProvider(); + + InputStream inStream = isp.getInputStream(fileName); + MMcifParser parser = new SimpleMMcifParser(); + ChemCompConsumer consumer = new ChemCompConsumer(); + + // The Consumer builds up the BioJava - structure object. + // you could also hook in your own and build up you own data model. + parser.addMMcifConsumer(consumer); + parser.parse(new BufferedReader(new InputStreamReader(inStream))); + dict = consumer.getDictionary(); + inStream.close(); + } + + /** + * {@inheritDoc} + */ + @Override + public ChemComp getChemComp(String recordName) { + while (loading.get()) { + // another thread is still initializing the definitions + try { + // wait half a second + Thread.sleep(500); + } catch (InterruptedException e) { + logger.error("Interrupted thread while waiting: " + e.getMessage()); + //e.printStackTrace(); + } + } + + return dict.getChemComp(recordName); + } + + + /** + * Do the actual loading of the dictionary in a thread. + */ + @Override + public void run() { + long timeS = System.currentTimeMillis(); + initPath(); + ensureFileExists(); + + try { + loadAllChemComps(); + + long timeE = System.currentTimeMillis(); + logger.debug("Time to init chem comp dictionary: " + (timeE - timeS) / 1000 + " sec."); + } catch (IOException e) { + logger.error("Could not load chemical components definition file {}. Error: {}", getLocalFileName(), e.getMessage()); + } finally { + loading.set(false); + isInitialized.set(true); + } + } +} + diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemComp.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemComp.java new file mode 100644 index 0000000000..96631fe736 --- /dev/null +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemComp.java @@ -0,0 +1,405 @@ +package org.biojava.nbio.structure.chem; + +import org.biojava.nbio.structure.io.cif.CifBean; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +/** + * Properties of a chemical component. + */ +public class ChemComp implements CifBean, Comparable { + private static final long serialVersionUID = -4736341142030215915L; + + private String id; + private String name; + private String type; + private String pdbxType; + private String formula; + private String monNstdParentCompId; + private String pdbxSynonyms; + private String pdbxFormalCharge; + private String pdbxInitialDate; + private String pdbxModifiedDate; + private String pdbxAmbiguousFlag; + private String pdbxReleaseStatus; + private String pdbxReplacedBy; + private String pdbxReplaces; + private String formulaWeight; + private String oneLetterCode; + private String threeLetterCode; + private String pdbxModelCoordinatesDetails; + private String pdbxModelCoordinatesMissingFlag; + private String pdbxIdealCoordinatesDetails; + private String pdbxIdealCoordinatesMissingFlag; + private String pdbxModelCoordinatesDbCode; + private String pdbxSubcomponentList; + private String pdbxProcessingSite; + private String monNstdFlag; + + private List descriptors = new ArrayList<>(); + private List bonds = new ArrayList<>(); + private List atoms = new ArrayList<>(); + + // and some derived data for easier processing... + private ResidueType residueType; + private PolymerType polymerType; + private boolean standard; + + @Override + public String toString(){ + StringBuffer buf = new StringBuffer("ChemComp "); + buf.append(id) + .append(" ") + .append(oneLetterCode) + .append(" ") + .append(threeLetterCode) + .append(" poly:") + .append(getPolymerType()) + .append(" resi:") + .append(getResidueType()) + .append(isStandard() ? " standard" : " modified") + .append(" ") + .append(name) + .append(" ") + .append(pdbxType) + .append(" ") + .append(formula) + .append(" parent:") + .append(monNstdParentCompId); + return buf.toString(); + } + + public boolean hasParent(){ + String pid = monNstdParentCompId; + return (pid != null) && (!pid.equals("?")); + } + + public boolean isStandard(){ + return standard; + } + + private void setStandardFlag(){ + standard = ChemCompTools.isStandardChemComp(this); + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + this.residueType = ResidueType.getResidueTypeFromString(type); + if (residueType != null) { + polymerType = residueType.polymerType; + } + } + + public ResidueType getResidueType() { + return residueType; + } + + public void setResidueType(ResidueType residueType) { + this.residueType = residueType; + } + + public PolymerType getPolymerType() { + return polymerType; + } + + public void setPolymerType(PolymerType polymerType) { + this.polymerType = polymerType; + } + + public String getPdbxType() { + return pdbxType; + } + + public void setPdbxType(String pdbxType) { + this.pdbxType = pdbxType; + } + + public String getFormula() { + return formula; + } + + public void setFormula(String formula) { + this.formula = formula; + } + + public String getMonNstdParentCompId() { + return monNstdParentCompId; + } + + public void setMonNstdParentCompId(String monNstdParentCompId) { + this.monNstdParentCompId = monNstdParentCompId; + setStandardFlag(); + } + + public String getPdbxSynonyms() { + return pdbxSynonyms; + } + + public void setPdbxSynonyms(String pdbxSynonyms) { + this.pdbxSynonyms = pdbxSynonyms; + } + + public String getPdbxFormalCharge() { + return pdbxFormalCharge; + } + + public void setPdbxFormalCharge(String pdbxFormalCharge) { + this.pdbxFormalCharge = pdbxFormalCharge; + } + + public String getPdbxInitialDate() { + return pdbxInitialDate; + } + + public void setPdbxInitialDate(String pdbxInitialDate) { + this.pdbxInitialDate = pdbxInitialDate; + } + + public String getPdbxModifiedDate() { + return pdbxModifiedDate; + } + + public void setPdbxModifiedDate(String pdbxModifiedDate) { + this.pdbxModifiedDate = pdbxModifiedDate; + } + + public String getPdbxAmbiguousFlag() { + return pdbxAmbiguousFlag; + } + + public void setPdbxAmbiguousFlag(String pdbxAmbiguousFlag) { + this.pdbxAmbiguousFlag = pdbxAmbiguousFlag; + } + + public String getPdbxReleaseStatus() { + return pdbxReleaseStatus; + } + + public void setPdbxReleaseStatus(String pdbxReleaseStatus) { + this.pdbxReleaseStatus = pdbxReleaseStatus; + } + + public String getPdbxReplacedBy() { + return pdbxReplacedBy; + } + + public void setPdbxReplacedBy(String pdbxReplacedBy) { + this.pdbxReplacedBy = pdbxReplacedBy; + } + + public String getPdbxReplaces() { + return pdbxReplaces; + } + + public void setPdbxReplaces(String pdbxReplaces) { + this.pdbxReplaces = pdbxReplaces; + } + + public String getFormulaWeight() { + return formulaWeight; + } + + public void setFormulaWeight(String formulaWeight) { + this.formulaWeight = formulaWeight; + } + + public String getOneLetterCode() { + return oneLetterCode; + } + + public void setOneLetterCode(String oneLetterCode) { + this.oneLetterCode = oneLetterCode; + setStandardFlag(); + } + + public String getThreeLetterCode() { + return threeLetterCode; + } + + public void setThreeLetterCode(String threeLetterCode) { + this.threeLetterCode = threeLetterCode; + } + + public String getPdbxModelCoordinatesDetails() { + return pdbxModelCoordinatesDetails; + } + + public void setPdbxModelCoordinatesDetails(String pdbxModelCoordinatesDetails) { + this.pdbxModelCoordinatesDetails = pdbxModelCoordinatesDetails; + } + + public String getPdbxModelCoordinatesMissingFlag() { + return pdbxModelCoordinatesMissingFlag; + } + + public void setPdbxModelCoordinatesMissingFlag(String pdbxModelCoordinatesMissingFlag) { + this.pdbxModelCoordinatesMissingFlag = pdbxModelCoordinatesMissingFlag; + } + + public String getPdbxIdealCoordinatesDetails() { + return pdbxIdealCoordinatesDetails; + } + + public void setPdbxIdealCoordinatesDetails(String pdbxIdealCoordinatesDetails) { + this.pdbxIdealCoordinatesDetails = pdbxIdealCoordinatesDetails; + } + + public String getPdbxIdealCoordinatesMissingFlag() { + return pdbxIdealCoordinatesMissingFlag; + } + + public void setPdbxIdealCoordinatesMissingFlag(String pdbxIdealCoordinatesMissingFlag) { + this.pdbxIdealCoordinatesMissingFlag = pdbxIdealCoordinatesMissingFlag; + } + + public String getPdbxModelCoordinatesDbCode() { + return pdbxModelCoordinatesDbCode; + } + + public void setPdbxModelCoordinatesDbCode(String pdbxModelCoordinatesDbCode) { + this.pdbxModelCoordinatesDbCode = pdbxModelCoordinatesDbCode; + } + + public String getPdbxSubcomponentList() { + return pdbxSubcomponentList; + } + + public void setPdbxSubcomponentList(String pdbxSubcomponentList) { + this.pdbxSubcomponentList = pdbxSubcomponentList; + } + + public String getPdbxProcessingSite() { + return pdbxProcessingSite; + } + + public void setPdbxProcessingSite(String pdbxProcessingSite) { + this.pdbxProcessingSite = pdbxProcessingSite; + } + + public String getMonNstdFlag() { + return monNstdFlag; + } + + public void setMonNstdFlag(String monNstdFlag) { + this.monNstdFlag = monNstdFlag; + } + + public List getDescriptors() { + return descriptors; + } + + public void setDescriptors(List descriptors) { + this.descriptors = descriptors; + } + + public List getBonds() { + return bonds; + } + + public void setBonds(List bonds) { + this.bonds = bonds; + } + + public List getAtoms() { + return atoms; + } + + public void setAtoms(List atoms) { + this.atoms = atoms; + } + + @Override + public int compareTo(ChemComp arg0) { + if (this.equals(arg0)) + return 0; + return this.getId().compareTo(arg0.getId()); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ChemComp chemComp = (ChemComp) o; + return standard == chemComp.standard && + Objects.equals(id, chemComp.id) && + Objects.equals(name, chemComp.name) && + Objects.equals(type, chemComp.type) && + Objects.equals(pdbxType, chemComp.pdbxType) && + Objects.equals(formula, chemComp.formula) && + Objects.equals(monNstdParentCompId, chemComp.monNstdParentCompId) && + Objects.equals(pdbxSynonyms, chemComp.pdbxSynonyms) && + Objects.equals(pdbxFormalCharge, chemComp.pdbxFormalCharge) && + Objects.equals(pdbxInitialDate, chemComp.pdbxInitialDate) && + Objects.equals(pdbxModifiedDate, chemComp.pdbxModifiedDate) && + Objects.equals(pdbxAmbiguousFlag, chemComp.pdbxAmbiguousFlag) && + Objects.equals(pdbxReleaseStatus, chemComp.pdbxReleaseStatus) && + Objects.equals(pdbxReplacedBy, chemComp.pdbxReplacedBy) && + Objects.equals(pdbxReplaces, chemComp.pdbxReplaces) && + Objects.equals(formulaWeight, chemComp.formulaWeight) && + Objects.equals(oneLetterCode, chemComp.oneLetterCode) && + Objects.equals(threeLetterCode, chemComp.threeLetterCode) && + Objects.equals(pdbxModelCoordinatesDetails, chemComp.pdbxModelCoordinatesDetails) && + Objects.equals(pdbxModelCoordinatesMissingFlag, chemComp.pdbxModelCoordinatesMissingFlag) && + Objects.equals(pdbxIdealCoordinatesDetails, chemComp.pdbxIdealCoordinatesDetails) && + Objects.equals(pdbxIdealCoordinatesMissingFlag, chemComp.pdbxIdealCoordinatesMissingFlag) && + Objects.equals(pdbxModelCoordinatesDbCode, chemComp.pdbxModelCoordinatesDbCode) && + Objects.equals(pdbxSubcomponentList, chemComp.pdbxSubcomponentList) && + Objects.equals(pdbxProcessingSite, chemComp.pdbxProcessingSite) && + Objects.equals(monNstdFlag, chemComp.monNstdFlag) && + Objects.equals(descriptors, chemComp.descriptors) && + Objects.equals(bonds, chemComp.bonds) && + Objects.equals(atoms, chemComp.atoms) && + residueType == chemComp.residueType && + polymerType == chemComp.polymerType; + } + + @Override + public int hashCode() { + return Objects.hash(id, name, type, pdbxType, formula, monNstdParentCompId, pdbxSynonyms, pdbxFormalCharge, pdbxInitialDate, pdbxModifiedDate, pdbxAmbiguousFlag, pdbxReleaseStatus, pdbxReplacedBy, pdbxReplaces, formulaWeight, oneLetterCode, threeLetterCode, pdbxModelCoordinatesDetails, pdbxModelCoordinatesMissingFlag, pdbxIdealCoordinatesDetails, pdbxIdealCoordinatesMissingFlag, pdbxModelCoordinatesDbCode, pdbxSubcomponentList, pdbxProcessingSite, monNstdFlag, descriptors, bonds, atoms, residueType, polymerType, standard); + } + + /** + * Creates a new instance of the dummy empty ChemComp. + * @return a ChemComp + */ + public static ChemComp getEmptyChemComp() { + ChemComp comp = new ChemComp(); + + comp.setOneLetterCode("?"); + comp.setThreeLetterCode("???"); // Main signal for isEmpty() + comp.setPolymerType(PolymerType.unknown); + comp.setResidueType(ResidueType.atomn); + return comp; + } + + /** + * Indicates whether this compound was created with + * @return a boolean + */ + public boolean isEmpty() { + // Is this the best flag for it being empty? + return id == null || getThreeLetterCode() == null || getThreeLetterCode().equals("???"); + } +} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemCompAtom.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemCompAtom.java new file mode 100644 index 0000000000..cad290820e --- /dev/null +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemCompAtom.java @@ -0,0 +1,205 @@ +package org.biojava.nbio.structure.chem; + +import org.biojava.nbio.structure.io.cif.CifBean; + +public class ChemCompAtom implements CifBean { + private static final long serialVersionUID = 4070599340294758941L; + private String compId; + private String atomId; + private String altAtomId; + private String typeSymbol; + private String charge; + private String pdbxAlign; + private String pdbxAromaticFlag; + private String pdbxLeavingAtomFlag; + private String pdbxStereoConfig; + private String modelCartnX; + private String modelCartnY; + private String modelCartnZ; + private String pdbxModelCartnXIdeal; + private String pdbxModelCartnYIdeal; + private String pdbxModelCartnZIdeal; + private String pdbxComponentCompId; + private String pdbxResidueNumbering; + private String pdbxComponentAtomId; + private String pdbxPolymerType; + private String pdbxRefId; + private String pdbxComponentId; + private String pdbxOrdinal; + + public String getCompId() { + return compId; + } + + public void setCompId(String compId) { + this.compId = compId; + } + + public String getAtomId() { + return atomId; + } + + public void setAtomId(String atomId) { + this.atomId = atomId; + } + + public String getAltAtomId() { + return altAtomId; + } + + public void setAltAtomId(String altAtomId) { + this.altAtomId = altAtomId; + } + + public String getTypeSymbol() { + return typeSymbol; + } + + public void setTypeSymbol(String typeSymbol) { + this.typeSymbol = typeSymbol; + } + + public String getCharge() { + return charge; + } + + public void setCharge(String charge) { + this.charge = charge; + } + + public String getPdbxAlign() { + return pdbxAlign; + } + + public void setPdbxAlign(String pdbxAlign) { + this.pdbxAlign = pdbxAlign; + } + + public String getPdbxAromaticFlag() { + return pdbxAromaticFlag; + } + + public void setPdbxAromaticFlag(String pdbxAromaticFlag) { + this.pdbxAromaticFlag = pdbxAromaticFlag; + } + + public String getPdbxLeavingAtomFlag() { + return pdbxLeavingAtomFlag; + } + + public void setPdbxLeavingAtomFlag(String pdbxLeavingAtomFlag) { + this.pdbxLeavingAtomFlag = pdbxLeavingAtomFlag; + } + + public String getPdbxStereoConfig() { + return pdbxStereoConfig; + } + + public void setPdbxStereoConfig(String pdbxStereoConfig) { + this.pdbxStereoConfig = pdbxStereoConfig; + } + + public String getModelCartnX() { + return modelCartnX; + } + + public void setModelCartnX(String modelCartnX) { + this.modelCartnX = modelCartnX; + } + + public String getModelCartnY() { + return modelCartnY; + } + + public void setModelCartnY(String modelCartnY) { + this.modelCartnY = modelCartnY; + } + + public String getModelCartnZ() { + return modelCartnZ; + } + + public void setModelCartnZ(String modelCartnZ) { + this.modelCartnZ = modelCartnZ; + } + + public String getPdbxModelCartnXIdeal() { + return pdbxModelCartnXIdeal; + } + + public void setPdbxModelCartnXIdeal(String pdbxModelCartnXIdeal) { + this.pdbxModelCartnXIdeal = pdbxModelCartnXIdeal; + } + + public String getPdbxModelCartnYIdeal() { + return pdbxModelCartnYIdeal; + } + + public void setPdbxModelCartnYIdeal(String pdbxModelCartnYIdeal) { + this.pdbxModelCartnYIdeal = pdbxModelCartnYIdeal; + } + + public String getPdbxModelCartnZIdeal() { + return pdbxModelCartnZIdeal; + } + + public void setPdbxModelCartnZIdeal(String pdbxModelCartnZIdeal) { + this.pdbxModelCartnZIdeal = pdbxModelCartnZIdeal; + } + + public String getPdbxComponentCompId() { + return pdbxComponentCompId; + } + + public void setPdbxComponentCompId(String pdbxComponentCompId) { + this.pdbxComponentCompId = pdbxComponentCompId; + } + + public String getPdbxResidueNumbering() { + return pdbxResidueNumbering; + } + + public void setPdbxResidueNumbering(String pdbxResidueNumbering) { + this.pdbxResidueNumbering = pdbxResidueNumbering; + } + + public String getPdbxComponentAtomId() { + return pdbxComponentAtomId; + } + + public void setPdbxComponentAtomId(String pdbxComponentAtomId) { + this.pdbxComponentAtomId = pdbxComponentAtomId; + } + + public String getPdbxPolymerType() { + return pdbxPolymerType; + } + + public void setPdbxPolymerType(String pdbxPolymerType) { + this.pdbxPolymerType = pdbxPolymerType; + } + + public String getPdbxRefId() { + return pdbxRefId; + } + + public void setPdbxRefId(String pdbxRefId) { + this.pdbxRefId = pdbxRefId; + } + + public String getPdbxComponentId() { + return pdbxComponentId; + } + + public void setPdbxComponentId(String pdbxComponentId) { + this.pdbxComponentId = pdbxComponentId; + } + + public String getPdbxOrdinal() { + return pdbxOrdinal; + } + + public void setPdbxOrdinal(String pdbxOrdinal) { + this.pdbxOrdinal = pdbxOrdinal; + } +} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemCompBond.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemCompBond.java new file mode 100644 index 0000000000..b5a4d4e7f4 --- /dev/null +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemCompBond.java @@ -0,0 +1,114 @@ +package org.biojava.nbio.structure.chem; + +import org.biojava.nbio.structure.io.cif.CifBean; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class ChemCompBond implements CifBean { + private static final long serialVersionUID = 5905371029161975421L; + private static final Logger logger = LoggerFactory.getLogger(ChemCompBond.class); + + private String compId; + private String atomId1; + private String atomId2; + private String valueOrder; + private String pdbxAromaticFlag; + private String pdbxStereoConfig; + private String pdbxOrdinal; + + public static Logger getLogger() { + return logger; + } + + public String getCompId() { + return compId; + } + + public void setCompId(String compId) { + this.compId = compId; + } + + public String getAtomId1() { + return atomId1; + } + + public void setAtomId1(String atomId1) { + this.atomId1 = atomId1; + } + + public String getAtomId2() { + return atomId2; + } + + public void setAtomId2(String atomId2) { + this.atomId2 = atomId2; + } + + public String getValueOrder() { + return valueOrder; + } + + public void setValueOrder(String valueOrder) { + this.valueOrder = valueOrder; + } + + public String getPdbxAromaticFlag() { + return pdbxAromaticFlag; + } + + public void setPdbxAromaticFlag(String pdbxAromaticFlag) { + this.pdbxAromaticFlag = pdbxAromaticFlag; + } + + public String getPdbxStereoConfig() { + return pdbxStereoConfig; + } + + public void setPdbxStereoConfig(String pdbxStereoConfig) { + this.pdbxStereoConfig = pdbxStereoConfig; + } + + public String getPdbxOrdinal() { + return pdbxOrdinal; + } + + public void setPdbxOrdinal(String pdbxOrdinal) { + this.pdbxOrdinal = pdbxOrdinal; + } + + /** + * Converts this ChemCompBond's value_order attribute into an int using the + * conversion: + * + *

+     * 	SING -> 1
+     * 	DOUB -> 2
+     * 	TRIP -> 3
+     * 	QUAD -> 4
+     * 
+ * + * Any other values will return -1. + *

+ * (Source: + * http://mmcif.rcsb.org/dictionaries/mmcif_mdb.dic/Items/_chem_comp_bond. + * value_order.html) + * + * @return the numerical value of this ChemCompBond's bond order, or -1 if + * the value is non-numeric or unknown. + */ + public int getNumericalBondOrder() { + switch (valueOrder) { + case "SING": + return 1; + case "DOUB": + return 2; + case "TRIP": + return 3; + case "QUAD": + return 4; + default: + logger.error("Unknown or non-numeric value for value_order: " + valueOrder); + return -1; + } + } +} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemCompContainer.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemCompContainer.java new file mode 100644 index 0000000000..322f927895 --- /dev/null +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemCompContainer.java @@ -0,0 +1,13 @@ +package org.biojava.nbio.structure.chem; + +import org.rcsb.cif.schema.mm.ChemComp; + +public class ChemCompContainer { + private final ChemComp delegate; + + public ChemCompContainer(ChemComp chemComp) { + this.delegate = chemComp; + } + + +} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemCompDescriptor.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemCompDescriptor.java new file mode 100644 index 0000000000..7628caef53 --- /dev/null +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemCompDescriptor.java @@ -0,0 +1,80 @@ +package org.biojava.nbio.structure.chem; + +import org.biojava.nbio.structure.io.cif.CifBean; + +import java.util.Objects; + +public class ChemCompDescriptor implements CifBean { + private static final long serialVersionUID = 1078685833800736278L; + private String compId; + private String type; + private String program; + private String programVersion; + private String descriptor; + + public String getCompId() { + return compId; + } + + public void setCompId(String compId) { + this.compId = compId; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getProgram() { + return program; + } + + public void setProgram(String program) { + this.program = program; + } + + public String getProgramVersion() { + return programVersion; + } + + public void setProgramVersion(String programVersion) { + this.programVersion = programVersion; + } + + public String getDescriptor() { + return descriptor; + } + + public void setDescriptor(String descriptor) { + this.descriptor = descriptor; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ChemCompDescriptor that = (ChemCompDescriptor) o; + return Objects.equals(compId, that.compId) && + Objects.equals(type, that.type) && + Objects.equals(program, that.program) && + Objects.equals(programVersion, that.programVersion) && + Objects.equals(descriptor, that.descriptor); + } + + @Override + public int hashCode() { + return Objects.hash(compId, type, program, programVersion, descriptor); + } + + @Override + public String toString() { + return "ChemCompDescriptor [comp_id=" + compId + + ", type=" + type + + ", program=" + program + + ", program_version=" + programVersion + + ", descriptor=" + descriptor + "]"; + } +} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemCompGroupFactory.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemCompGroupFactory.java new file mode 100644 index 0000000000..cad709223f --- /dev/null +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemCompGroupFactory.java @@ -0,0 +1,131 @@ +package org.biojava.nbio.structure.chem; + +import org.biojava.nbio.core.util.SoftHashMap; +import org.biojava.nbio.structure.AminoAcid; +import org.biojava.nbio.structure.AminoAcidImpl; +import org.biojava.nbio.structure.Group; +import org.biojava.nbio.structure.HetatomImpl; +import org.biojava.nbio.structure.NucleotideImpl; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Map; + +public class ChemCompGroupFactory { + private static final Logger logger = LoggerFactory.getLogger(ChemCompGroupFactory.class); + private static ChemCompProvider chemCompProvider = new DownloadChemCompProvider(); + private static Map cache = new SoftHashMap<>(0); + + public static ChemComp getChemComp(String recordName) { + recordName = recordName.toUpperCase().trim(); + + // we are using the cache, to avoid hitting the file system too often. + ChemComp chemComp = cache.get(recordName); + if (chemComp != null) { + logger.debug("Chem comp " + chemComp.getThreeLetterCode() + " read from cache"); + return chemComp; + } + + // not cached, get the chem comp from the provider + logger.debug("Chem comp " + recordName + " read from provider " + chemCompProvider.getClass().getCanonicalName()); + chemComp = chemCompProvider.getChemComp(recordName); + + // Note that this also caches null or empty responses + cache.put(recordName, chemComp); + return chemComp; + } + + /** + * The new ChemCompProvider will be set in the static variable, + * so this provider will be used from now on until it is changed + * again. Note that this change can have unexpected behavior of + * code executed afterwards. + *

+ * Changing the provider also resets the cache, so any groups + * previously accessed will be reread or re-downloaded. + * + * @param provider + */ + public static void setChemCompProvider(ChemCompProvider provider) { + logger.debug("Setting new chem comp provider to " + provider.getClass().getCanonicalName()); + chemCompProvider = provider; + // clear cache + cache.clear(); + } + + public static ChemCompProvider getChemCompProvider(){ + return chemCompProvider; + } + + /** + * Force the in-memory cache to be reset. + * + * Note that the ChemCompProvider may have additional memory or disk caches that need to be cleared too. + */ + public static void clearCache() { + cache.clear(); + } + + public static Group getGroupFromChemCompDictionary(String recordName) { + // make sure we work with upper case records + recordName = recordName.toUpperCase().trim(); + ChemComp chemComp = getChemComp(recordName); + Group group; + + if (chemComp == null) { + return null; + } + + PolymerType polymerType = PolymerType.polymerTypeFromString(chemComp.getType()); + if (PolymerType.PROTEIN_ONLY.contains(polymerType)) { + AminoAcid aminoAcid = new AminoAcidImpl(); + + String oneLetterCode = chemComp.getOneLetterCode(); + if (oneLetterCode == null || oneLetterCode.equals("X") || oneLetterCode.equals("?") || oneLetterCode.length() == 0) { + String parent = chemComp.getMonNstdParentCompId(); + if (parent != null && parent.length() == 3) { + String parentId = chemComp.getMonNstdParentCompId(); + ChemComp parentChemComp = getChemComp(parentId); + oneLetterCode = parentChemComp.getOneLetterCode(); + } + } + + if (oneLetterCode == null || oneLetterCode.length() == 0 || oneLetterCode.equals("?")) { + // e.g. problem with PRR, which probably should have a parent of ALA, but as of 20110127 does not. + logger.warn("Problem with chemical component: " + recordName + " Did not find one letter code! Setting it to 'X'"); + aminoAcid.setAminoType('X'); + } else { + aminoAcid.setAminoType(oneLetterCode.charAt(0)); + } + + group = aminoAcid; + } else if (PolymerType.POLYNUCLEOTIDE_ONLY.contains(polymerType)) { + group = new NucleotideImpl(); + } else { + group = new HetatomImpl(); + } + + group.setChemComp(chemComp); + return group; + } + + public static String getOneLetterCode(ChemComp chemComp) { + String oneLetterCode = chemComp.getOneLetterCode(); + if (oneLetterCode == null || oneLetterCode.equals("X") || oneLetterCode.equals("?")) { + String parentId = chemComp.getMonNstdParentCompId(); + if (parentId == null) { + return oneLetterCode; + } + // cases like OIM have multiple parents (comma separated), we shouldn't try grab a chemcomp for those strings + if (parentId.length() > 3) { + return oneLetterCode; + } + ChemComp parentChemComp = ChemCompGroupFactory.getChemComp(parentId); + if (parentChemComp == null) { + return oneLetterCode; + } + oneLetterCode = parentChemComp.getOneLetterCode(); + } + return oneLetterCode; + } +} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemCompProvider.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemCompProvider.java new file mode 100644 index 0000000000..936f5ef8cf --- /dev/null +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemCompProvider.java @@ -0,0 +1,15 @@ +package org.biojava.nbio.structure.chem; + +/** + * Interface that is implemented by all classes that can provide {@link ChemComp} definitions. + * @author Andreas Prlic + * @since 3.0 + */ +public interface ChemCompProvider { + /** + * Returns a new instance of a chemical component definition. + * @param recordName the ID of the {@link ChemComp} + * @return a new {@link ChemComp} definition. + */ + ChemComp getChemComp(String recordName); +} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemCompTools.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemCompTools.java new file mode 100644 index 0000000000..b24fd5d51a --- /dev/null +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemCompTools.java @@ -0,0 +1,209 @@ +package org.biojava.nbio.structure.chem; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class ChemCompTools { + private static final Character UNKNOWN_ONE_LETTER_CODE = 'X'; + private static final Character UNKNOWN_NUCLEOTIDE = 'N'; + /** + * Lookup table to convert standard amino acid's monomer ids to one-letter-codes + */ + private static final Map AMINO_ACID_LOOKUP_3TO1; + /** + * Lookup table to convert standard amino acid's one-letter-codes to monomer ids + */ + private static final Map AMINO_ACID_LOOKUP_1TO3; + /** + * Lookup table to convert standard nucleic acid's monomer ids to one-letter-codes + */ + private static final Map DNA_LOOKUP_2TO1; + /** + * Lookup table to convert standard nucleic acid's one-letter-codes to monomer ids + */ + private static final Map DNA_LOOKUP_1TO2; + /* + Static block that initializes lookup maps and initializes their ResidueInfo instances + */ + static { + Map foo = new HashMap<>(); + foo.put("ALA", 'A'); + foo.put("ASP", 'D'); + foo.put("ASN", 'N'); + foo.put("ASX", 'B'); + foo.put("ARG", 'R'); + foo.put("CYS", 'C'); + foo.put("GLU", 'E'); + foo.put("GLN", 'Q'); + foo.put("GLY", 'G'); + foo.put("GLX", 'Z'); + foo.put("HIS", 'H'); + foo.put("ILE", 'I'); + foo.put("LYS", 'K'); + foo.put("LEU", 'L'); + foo.put("MET", 'M'); + foo.put("PHE", 'F'); + foo.put("PRO", 'P'); + foo.put("SER", 'S'); + foo.put("THR", 'T'); + foo.put("TRP", 'W'); + foo.put("TYR", 'Y'); + foo.put("VAL", 'V'); + AMINO_ACID_LOOKUP_3TO1 = Collections.unmodifiableMap((Collections.synchronizedMap(foo))); + + Map bar = new HashMap<>(); + bar.put('A', "ALA"); + bar.put('D', "ASP"); + bar.put('N', "ASN"); + bar.put('B', "ASX"); + bar.put('R', "ARG"); + bar.put('C', "CYS"); + bar.put('E', "GLU"); + bar.put('Q', "GLN"); + bar.put('G', "GLY"); + bar.put('Z', "GLX"); + bar.put('H', "HIS"); + bar.put('I', "ILE"); + bar.put('K', "LYS"); + bar.put('L', "LEU"); + bar.put('M', "MET"); + bar.put('F', "PHE"); + bar.put('P', "PRO"); + bar.put('S', "SER"); + bar.put('T', "THR"); + bar.put('W', "TRP"); + bar.put('Y', "TYR"); + bar.put('V', "VAL"); + AMINO_ACID_LOOKUP_1TO3 = Collections.unmodifiableMap(Collections.synchronizedMap(bar)); + + foo = new HashMap<>(); + foo.put("DA",'A'); + foo.put("DC",'C'); + foo.put("DG",'G'); + foo.put("DI",'I'); + foo.put("DU",'U'); + foo.put("DT",'T'); + DNA_LOOKUP_2TO1 = Collections.unmodifiableMap((Collections.synchronizedMap(foo))); + + bar = new HashMap<>(); + bar.put('A',"DA"); + bar.put('C',"DC"); + bar.put('G',"DG"); + bar.put('I',"DI"); + bar.put('U',"DU"); + bar.put('T',"DT"); + DNA_LOOKUP_1TO2 = Collections.unmodifiableMap(Collections.synchronizedMap(bar)); + + + // initialise standard chemical components + List stdMonIds = new ArrayList<>(); + stdMonIds.addAll(AMINO_ACID_LOOKUP_3TO1.keySet()); + stdMonIds.addAll(DNA_LOOKUP_2TO1.keySet()); + } + + public static Character getAminoOneLetter(String chemCompId){ + return AMINO_ACID_LOOKUP_3TO1.get(chemCompId); + } + + public static Character getDNAOneLetter(String chemCompId){ + return DNA_LOOKUP_2TO1.get(chemCompId); + } + + public static String getAminoThreeLetter(Character c){ + return AMINO_ACID_LOOKUP_1TO3.get(c); + } + + public static String getDNATwoLetter(Character c){ + return DNA_LOOKUP_1TO2.get(c); + } + + public static boolean isStandardChemComp(ChemComp cc){ + String pid = cc.getMonNstdParentCompId(); + String one = cc.getOneLetterCode(); + + PolymerType polymerType = cc.getPolymerType(); + + // standard residues have no parent + if ((pid == null) || (pid.equals("?"))) { + // and they have a one letter code + if ((one != null) && (!one.equals("?"))) { + // peptides and dpeptides must not have X + if (polymerType == PolymerType.peptide || polymerType == PolymerType.dpeptide) { + return performPeptideCheck(cc, one); + } + if (polymerType == PolymerType.rna) { + return performRNACheck(cc); + } + if (polymerType == PolymerType.dna) { + return performDNACheck(cc); + } + + //System.err.println("Non standard chem comp: " + cc); + return false; + } + } + return false; + } + + private static boolean performRNACheck(ChemComp cc) { + return cc.getId().length() == 1; + } + + private static boolean performDNACheck(ChemComp cc) { + if (cc.getId().equals(UNKNOWN_NUCLEOTIDE.toString())) { + return false; + } + + Character c = getDNAOneLetter(cc.getId()); + // we did not find it in the list of standard nucleotides + return c != null; + } + + private static boolean performPeptideCheck(ChemComp cc, String one) { + if (one.equals(UNKNOWN_ONE_LETTER_CODE.toString())) { + return false; + } + Character c = getAminoOneLetter(cc.getId()); + // we did not find it in the list of standard aminos + return c != null; + } + + // TODO: component 175 has 3 chars as a one letter code... + // Figure out what to do with it... + // so does: 4F3,5ZA and others + public static Character getOneLetterCode(ChemComp cc, ChemicalComponentDictionary dictionary) { + if (cc.getResidueType() == ResidueType.nonPolymer) { + return null; + } + + if (cc.isStandard()) { + return cc.getOneLetterCode().charAt(0); + } + + ChemComp parent = dictionary.getParent(cc); + if (parent == null) { + //System.err.println("parent is null " + cc); + return cc.getOneLetterCode().charAt(0); + } + PolymerType poly = cc.getPolymerType(); + if (poly == PolymerType.peptide || poly == PolymerType.dpeptide) { + Character c = getAminoOneLetter(parent.getId()); + if (c == null) { + c = UNKNOWN_ONE_LETTER_CODE; + } + return c; + } + if (poly == PolymerType.dna) { + Character c = getDNAOneLetter(parent.getId()); + if (c == null) { + c = UNKNOWN_NUCLEOTIDE; + } + return c; + + } + return cc.getMonNstdParentCompId().charAt(0); + } +} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemicalComponentDictionary.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemicalComponentDictionary.java new file mode 100644 index 0000000000..2f48e612d7 --- /dev/null +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemicalComponentDictionary.java @@ -0,0 +1,104 @@ +package org.biojava.nbio.structure.chem; + +import java.util.HashMap; +import java.util.Map; + +public class ChemicalComponentDictionary { + private final Map dictionary; + private final Map replaces; + private final Map isReplacedBy; + + public ChemicalComponentDictionary() { + this.dictionary = new HashMap<>(); + this.replaces = new HashMap<>(); + this.isReplacedBy = new HashMap<>(); + } + + public boolean isReplaced(ChemComp c) { + return isReplaced(c.getId()); + } + + public boolean isReplaced(String id) { + return isReplacedBy.containsKey(id); + } + + public boolean isReplacer(ChemComp c){ + return isReplacer(c.getId()); + } + + public boolean isReplacer(String id) { + return replaces.containsKey(id); + } + + /** if ChemComp is replaced by another one, get the newer version + * otherwise return the same ChemComp again. + * @param c + * @return get the component that replaced ChemComp. + */ + public ChemComp getReplacer(ChemComp c){ + return getReplacer(c.getId()); + } + + public ChemComp getReplacer(String id){ + if (isReplaced(id)) { + return dictionary.get(isReplacedBy.get(id)); + } + return dictionary.get(id); + } + + /** if ChemComp is replacing another one, get the old version + * otherwise return the same ChemComp again. + * @param c the ChemComp for which older versions should be looked up. + */ + public ChemComp getReplaced(ChemComp c){ + return getReplaced(c.getId()); + } + + public ChemComp getReplaced(String id){ + if (isReplacer(id)) { + return dictionary.get(replaces.get(id)); + } + return dictionary.get(id); + } + + /** + * Get the parent of a component. If component has no parent, return null + * @param c + * @return get the parent component or null if ChemComp has no parent. + */ + public ChemComp getParent(ChemComp c) { + if (c.hasParent()) { + return dictionary.get(c.getMonNstdParentCompId()); + } + return null; + } + + /** + * Add a new component to the dictionary + * @param comp + */ + public void addChemComp(ChemComp comp) { + dictionary.put(comp.getId(), comp); + String rep = comp.getPdbxReplaces(); + if (rep != null && !rep.equals("?")) { + replaces.put(comp.getId(), rep); + } + + String isRep = comp.getPdbxReplacedBy(); + if (isRep != null && !isRep.equals("?")) { + isReplacedBy.put(comp.getId(), isRep); + } + } + + /** + * Returns the number of ChemComps in this dictionary + * @return nr. of ChemComps + */ + public int size(){ + return dictionary.size(); + } + + public ChemComp getChemComp(String id){ + return dictionary.get(id); + } +} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/DownloadChemCompProvider.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/DownloadChemCompProvider.java new file mode 100644 index 0000000000..5b52bcab52 --- /dev/null +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/DownloadChemCompProvider.java @@ -0,0 +1,420 @@ +package org.biojava.nbio.structure.chem; + +import org.biojava.nbio.core.util.InputStreamProvider; +import org.biojava.nbio.structure.align.util.URLConnectionTools; +import org.biojava.nbio.structure.align.util.UserConfiguration; +import org.biojava.nbio.structure.io.LocalPDBDirectory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileOutputStream; +import java.io.FilenameFilter; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.net.URL; +import java.net.URLConnection; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.zip.GZIPOutputStream; + +/** + * This provider of chemical components can download and cache chemical component definition files from the RCSB PDB web + * site. It is the default way to access these definitions. If this provider is called he first time, it will download + * and install all chemical component definitions in a local directory. Once the definition files have been installed, + * it has quick startup time and low memory requirements. + * + * An alternative provider, that keeps all definitions in memory is the {@link AllChemCompProvider}. Another provider, + * that does not require any network access, but only can support a limited set of chemical component definitions, is + * the {@link ReducedChemCompProvider}. + * + * @author Andreas Prlic + */ +public class DownloadChemCompProvider implements ChemCompProvider { + private static final Logger logger = LoggerFactory.getLogger(DownloadChemCompProvider.class); + public static final String CHEM_COMP_CACHE_DIRECTORY = "chemcomp"; + public static final String DEFAULT_SERVER_URL = "http://files.rcsb.org/ligands/download/"; + public static String serverBaseUrl = DEFAULT_SERVER_URL; + + /** + * Use default RCSB server layout (true) or internal RCSB server layout (false) + */ + public static boolean useDefaultUrlLayout = true; + + private static File path; + private static final String NEWLINE = System.getProperty("line.separator"); + + // flags to make sure there is only one thread running that is loading the dictionary + static AtomicBoolean loading = new AtomicBoolean(false); + + static final List protectedIDs = new ArrayList<>(); + static { + protectedIDs.add("CON"); + protectedIDs.add("PRN"); + protectedIDs.add("AUX"); + protectedIDs.add("NUL"); + } + + private static ChemCompProvider fallback = null; // Fallback provider if the download fails + /** + * by default we will download only some of the files. User has to request that all files should be downloaded... + */ + boolean downloadAll = false; + + public DownloadChemCompProvider() { + this(null); + } + + public DownloadChemCompProvider(String cacheFilePath) { + logger.debug("Initialising DownloadChemCompProvider"); + + // note that path is static, so this is just to make sure that all non-static methods will have path initialised + if (cacheFilePath != null) { + path = new File(cacheFilePath); + } + } + + /** + * Get this provider's cache path + * @return + */ + public static File getPath(){ + if (path == null) { + UserConfiguration config = new UserConfiguration(); + path = new File(config.getCacheFilePath()); + } + return path; + } + + /** + * Checks if the chemical components already have been installed into the PDB directory. + * If not, will download the chemical components definitions file and split it up into small + * subfiles. + */ + public void checkDoFirstInstall(){ + if (!downloadAll) { + return; + } + + // this makes sure there is a file separator between every component, + // if path has a trailing file separator or not, it will work for both cases + File dir = new File(getPath(), CHEM_COMP_CACHE_DIRECTORY); + File f = new File(dir, "components.cif.gz"); + + if (!f.exists()) { + downloadAllDefinitions(); + } else { + // file exists.. did it get extracted? + FilenameFilter filter = (dir1, file) -> file.endsWith(".cif.gz"); + String[] files = dir.list(filter); + if (files.length < 500) { + // not all did get unpacked + try { + split(); + } catch (IOException e) { + logger.error("Could not split file {} into individual chemical component files. Error: {}", + f.toString(), e.getMessage()); + } + } + } + } + + private void split() throws IOException { + logger.info("Installing individual chem comp files ..."); + + File dir = new File(getPath(), CHEM_COMP_CACHE_DIRECTORY); + File f = new File(dir, "components.cif.gz"); + + int counter = 0; + InputStreamProvider prov = new InputStreamProvider(); + + try (BufferedReader buf = new BufferedReader(new InputStreamReader(prov.getInputStream(f)))) { + String line; + line = buf.readLine(); + StringWriter writer = new StringWriter(); + + String currentID = null; + while (line != null) { + if (line.startsWith("data_")) { + // a new record found! + if (currentID != null) { + writeID(writer.toString(), currentID); + counter++; + } + + currentID = line.substring(5); + writer = new StringWriter(); + } + + writer.append(line); + writer.append(NEWLINE); + + line = buf.readLine (); + } + + // write the last record... + writeID(writer.toString(), currentID); + counter++; + } + + logger.info("Created " + counter + " chemical component files."); + } + + /** + * Output chemical contents to a file + * @param contents File contents + * @param currentID Chemical ID, used to determine the filename + * @throws IOException + */ + private void writeID(String contents, String currentID) throws IOException { + String localName = getLocalFileName(currentID); + + try (PrintWriter pw = new PrintWriter(new GZIPOutputStream(new FileOutputStream(localName)))) { + pw.print(contents); + pw.flush(); + } + } + + /** + * Loads the definitions for this {@link ChemComp} from a local file and instantiates a new object. + * + * @param recordName the ID of the {@link ChemComp} + * @return a new {@link ChemComp} definition. + */ + @Override + public ChemComp getChemComp(String recordName) { + // make sure we work with upper case records + recordName = recordName.toUpperCase().trim(); + + boolean haveFile = true; + if (recordName.equals("?")) { + return null; + } + + if (fileIsAbsent(recordName)) { + // check if we should install all components + checkDoFirstInstall(); + } + if (fileIsAbsent(recordName)) { + // we previously have installed already the definitions, + // just do an incrememntal update + haveFile = downloadChemCompRecord(recordName); + } + + // Added check that download was successful and chemical component is available. + if (haveFile) { + String filename = getLocalFileName(recordName); + InputStream inStream = null; + try { + InputStreamProvider isp = new InputStreamProvider(); + inStream = isp.getInputStream(filename); + + MMcifParser parser = new SimpleMMcifParser(); + ChemCompConsumer consumer = new ChemCompConsumer(); + + // The Consumer builds up the BioJava - structure object. + // you could also hook in your own and build up you own data model. + parser.addMMcifConsumer(consumer); + parser.parse(new BufferedReader(new InputStreamReader(inStream))); + + ChemicalComponentDictionary dict = consumer.getDictionary(); + ChemComp chemComp = dict.getChemComp(recordName); + + // May be null if the file was corrupt. Fall back on ReducedChemCompProvider in that case + if (chemComp != null) { + return chemComp; + } + } catch (IOException e) { + logger.warn("Could not download chemical component file {} for {}. Error: {}. Now trying to use the " + + "local chemical component definitions.", + filename, recordName, e.getMessage()); + } finally { + // Now close it + if (inStream != null) { + try { + inStream.close(); + } catch (IOException e) { + // This would be weird... + logger.error("Could not close chemical component file {}. A resource leak could occur!!", filename); + } + } + } + } + + // see https://github.com/biojava/biojava/issues/315 + // probably a network error happened. Try to use the ReducedChemCOmpProvider + if (fallback == null) { + fallback = new ReducedChemCompProvider(); + } + + logger.warn("Falling back to ReducedChemCompProvider for {}. This could indicate a network error.", recordName); + return fallback.getChemComp(recordName); + + } + + /** + * Returns the file name that contains the definition for this {@link ChemComp} + * + * @param recordName the ID of the {@link ChemComp} + * @return full path to the file + */ + public static String getLocalFileName(String recordName) { + if (protectedIDs.contains(recordName)) { + recordName = "_" + recordName; + } + + File f = new File(getPath(), CHEM_COMP_CACHE_DIRECTORY); + if (!f.exists()) { + logger.info("Creating directory " + f); + boolean success = f.mkdir(); + // we've checked in initPath that path is writable, so there's no need to check if it succeeds + // in the unlikely case that in the meantime it isn't writable at least we log an error + if (!success) { + logger.error("Directory {} could not be created", f); + } + } + + File theFile = new File(f,recordName + ".cif.gz"); + return theFile.toString(); + } + + private static boolean fileIsAbsent(String recordName){ + String fileName = getLocalFileName(recordName); + File f = new File(fileName); + + // delete files that are too short to have contents + if (f.length() < LocalPDBDirectory.MIN_PDB_FILE_SIZE) { + // Delete defensively. + // Note that if delete is unsuccessful, we re-download the file anyways + f.delete(); + return true; + } + + return !f.exists(); + } + + /** + * @param recordName three-letter name + * @return true if successful download + */ + private static boolean downloadChemCompRecord(String recordName) { + String localName = getLocalFileName(recordName); + File newFile; + try { + newFile = File.createTempFile("chemcomp" + recordName, "cif"); + logger.debug("Will write chem comp file to temp file {}", newFile.toString()); + } catch (IOException e) { + logger.error("Could not write to temp directory {} to create the chemical component download temp file", + System.getProperty("java.io.tmpdir")); + return false; + } + String u; + if (useDefaultUrlLayout) { + u = serverBaseUrl + recordName + ".cif"; + } else { + u = serverBaseUrl + recordName.charAt(0) + "/" + recordName +"/" + recordName + ".cif"; + } + + logger.debug("downloading " + u); + URL url = null; + try { + url = new URL(u); + URLConnection uconn = URLConnectionTools.openURLConnection(url); + + try (PrintWriter pw = new PrintWriter(new GZIPOutputStream(new FileOutputStream(newFile))); + BufferedReader fileBuffer = new BufferedReader(new InputStreamReader(uconn.getInputStream()))) { + + String line; + while ((line = fileBuffer.readLine()) != null) { + pw.println(line); + } + pw.flush(); + } + // Now we move this across to where it actually wants to be + Files.move(newFile.toPath(), Paths.get(localName), StandardCopyOption.REPLACE_EXISTING); + + return true; + } catch (IOException e) { + logger.error("Could not download " + url.toString() + " OR store locally to " + localName + " Error =" + e.getMessage()); + newFile.delete(); + } + return false; + } + + private void downloadAllDefinitions() { + if (loading.get()) { + logger.info("Waiting for other thread to install chemical components..."); + } + + while (loading.get()) { + // another thread is already downloading the components definitions + // wait for the other thread to finish... + try { + // wait half a second + Thread.sleep(500); + } catch (InterruptedException e) { + //e.printStackTrace(); + logger.error("Thread interrupted "+e.getMessage()); + } + + logger.info("Another thread installed the chemical components."); + return; + } + + loading.set(true); + long timeS = System.currentTimeMillis(); + + logger.info("Performing first installation of chemical components."); + logger.info("Downloading components.cif.gz ..."); + + try { + AllChemCompProvider.downloadFile(); + } catch (IOException e) { + logger.error("Could not download the all chemical components file. Error: {}. " + + "Chemical components information won't be available", e.getMessage()); + // no point in trying to split if the file could not be downloaded + loading.set(false); + return; + } + + try { + split(); + } catch (IOException e) { + logger.error("Could not split all chem comp file into individual chemical component files. Error: {}", + e.getMessage()); + // no point in reporting time + loading.set(false); + return; + } + + long timeE = System.currentTimeMillis(); + logger.info("time to install chem comp dictionary: " + (timeE - timeS) / 1000 + " sec."); + loading.set(false); + } + + /** + * By default this provider will download only some of the {@link ChemComp} files. + * The user has to request that all files should be downloaded by setting this parameter to true. + * @return flag if the all components should be downloaded and installed at startup. (default: false) + */ + public boolean isDownloadAll() { + return downloadAll; + } + + /** + * By default this provider will download only some of the {@link ChemComp} files. + * The user has to request that all files should be downloaded by setting this parameter to true. + * @param downloadAll if the all components should be downloaded and installed at startup. (default: false) + */ + public void setDownloadAll(boolean downloadAll) { + this.downloadAll = downloadAll; + } +} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/PolymerType.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/PolymerType.java new file mode 100644 index 0000000000..78bae77f86 --- /dev/null +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/PolymerType.java @@ -0,0 +1,161 @@ +package org.biojava.nbio.structure.chem; + +import java.io.Serializable; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +/** + * Enumerates the classification of polymers. + * This information is derived from the mmcif dictionary + * @author mulvaney + * @author Andreas Prlic + * @see link into mmCIF dictionary + * @since 1.7 + */ +public enum PolymerType implements Serializable { + /** + * polypeptide(L) + */ + peptide("polypeptide(L)"), + /** + * polypeptide(D) + */ + dpeptide("polypeptide(D)"), + /** + * polydeoxyribonucleotide + */ + dna("polydeoxyribonucleotide"), + /** + * polyribonucleotide + */ + rna("polyribonucleotide"), + /** + * polydeoxyribonucleotide/polyribonucleotide hybrid + */ + dnarna("polydeoxyribonucleotide/polyribonucleotide hybrid"), + /** + * polysaccharide(D) + */ + polysaccharide("polysaccharide(D)"), + /** + * polysaccharide(L) + */ + lpolysaccharide("polysaccharide(L)"), + /** + * other + */ + otherPolymer("other"), + /** + * cyclic peptides + */ + cyclicPeptide("cyclic-pseudo-peptide"), + /** + * Peptide nucleic acids + */ + peptideNucleicAcid("peptide nucleic acid"), + /** + * if all else fails... + */ + unknown(null); + + static Map lookupTable = new HashMap<>(); + + static { + for (PolymerType polymerType : PolymerType.values()) { + if (polymerType == unknown) { + continue; + } + + lookupTable.put(polymerType.entity_poly_type,polymerType); + lookupTable.put(polymerType.entity_poly_type.toLowerCase(), polymerType); + } + } + + public final String entity_poly_type; + + PolymerType(String entity_poly_type) { + this.entity_poly_type = entity_poly_type; + } + + public static PolymerType polymerTypeFromString(String polymerTypeString) { + if (polymerTypeString.equalsIgnoreCase(peptide.entity_poly_type)) { + return peptide; + } + + PolymerType lookedUpPolymerType = lookupTable.get(polymerTypeString); + if (lookedUpPolymerType != null) { + return lookedUpPolymerType; + } + + lookedUpPolymerType = lookupTable.get(polymerTypeString.toLowerCase()); + if (lookedUpPolymerType != null) { + return lookedUpPolymerType; + } + + for (PolymerType polymerType : PolymerType.values()) { + if (polymerTypeString.equals(polymerType.entity_poly_type)) { + return polymerType; + } + } + + return unknown; + } + + /** + * Convenience Set of polymer types classified as protein. This only contains {@link #peptide} + */ + public static final Set PROTEIN_ONLY; + + /** + * Convenience Set of polymer types classified as DNA. This only contains {@link #dna} + */ + public static final Set DNA_ONLY; + + /** + * Convenience Set of polymer types classified as RNA. This only contains {@link #rna} + */ + public static final Set RNA_ONLY; + + /** + * Convenience Set of polymer types classified as DNA. This contains: + *

    + *
  • {@link #dna}
  • + *
  • {@link #rna}
  • + *
  • {@link #dnarna}
  • + *
+ */ + public static final Set POLYNUCLEOTIDE_ONLY; + + /** + * Convenience Set of all polymer types. + */ + public static final Set ALL_POLYMER_TYPES; + + static { + Set tmp; + + tmp = new HashSet<>(); + tmp.add(peptide); + PROTEIN_ONLY = Collections.unmodifiableSet(tmp); + + tmp = new HashSet<>(); + tmp.add(dna); + DNA_ONLY = Collections.unmodifiableSet(tmp); + + tmp = new HashSet<>(); + tmp.add(rna); + RNA_ONLY = Collections.unmodifiableSet(tmp); + + tmp = new HashSet<>(); + tmp.add(dna); + tmp.add(rna); + tmp.add(dnarna); + POLYNUCLEOTIDE_ONLY = Collections.unmodifiableSet(tmp); + + ALL_POLYMER_TYPES = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(values()))); + } +} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ReducedChemCompProvider.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ReducedChemCompProvider.java new file mode 100644 index 0000000000..9841fdc161 --- /dev/null +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ReducedChemCompProvider.java @@ -0,0 +1,56 @@ +package org.biojava.nbio.structure.chem; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.zip.GZIPInputStream; + +/** + * Unlike the {@link DownloadChemCompProvider}, this {@link ChemCompProvider} does not download any chem comp + * definitions. It has access to a limited set of files that are part of the biojava distribution. + * @author Andreas Prlic + * @since 3.0 + */ +public class ReducedChemCompProvider implements ChemCompProvider { + private static final Logger logger = LoggerFactory.getLogger(ReducedChemCompProvider.class); + + public ReducedChemCompProvider(){ + logger.debug("Initialising ReducedChemCompProvider"); + } + + @Override + public ChemComp getChemComp(String recordName) { + String name = recordName.toUpperCase().trim(); + try (InputStream inStream = this.getClass().getResourceAsStream("/chemcomp/" + name + ".cif.gz")) { + logger.debug("Reading chemcomp/{}.cif.gz", name); + + if (inStream == null) { + // could not find the chem comp definition for this in the jar file + logger.debug("Getting empty chem comp for {}", name); + ChemComp cc = ChemComp.getEmptyChemComp(); + cc.setId(name); + return cc; + } + + MMcifParser parser = new SimpleMMcifParser(); + ChemCompConsumer consumer = new ChemCompConsumer(); + // The Consumer builds up the BioJava - structure object. + // you could also hook in your own and build up you own data model. + parser.addMMcifConsumer(consumer); + parser.parse(new BufferedReader(new InputStreamReader(new GZIPInputStream(inStream)))); + + ChemicalComponentDictionary dict = consumer.getDictionary(); + return dict.getChemComp(name); + } catch (IOException e){ + logger.error("IOException caught while reading chem comp {}.", name, e); + } + logger.warn("Problem when loading chem comp {}, will use an empty chem comp for it", name); + ChemComp cc = ChemComp.getEmptyChemComp(); + cc.setId(name); + return cc; + } +} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ResidueType.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ResidueType.java new file mode 100644 index 0000000000..ddcaac453c --- /dev/null +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ResidueType.java @@ -0,0 +1,125 @@ +package org.biojava.nbio.structure.chem; + +import java.io.Serializable; +import java.util.HashMap; +import java.util.Map; + +/** + * Enumerates the possible classifications of residues. These are generally more specific than PolymerTypes + * This information is derived from the mmcif dictionary. + * @author mulvaney + * @author Andreas Prlic + * @see link into mmCIF dictionary + * @since 1.7 + */ +public enum ResidueType implements Serializable { + atomn(null, "null"), // present in db for _chem_comp.id_ = 'CFL' but not enumerated in dictionary + // Peptides + dPeptideLinking(PolymerType.dpeptide, "D-peptide linking"), + lPeptideLinking(PolymerType.peptide, "L-peptide linking"), + glycine(PolymerType.peptide,"PEPTIDE LINKING"), + peptideLike(PolymerType.otherPolymer, "peptide-like"), + dPeptideAminoTerminus(PolymerType.dpeptide, "D-peptide NH3 amino terminus"), + lPeptideAminoTerminus(PolymerType.peptide, "L-peptide NH3 amino terminus"), + dPeptideCarboxyTerminus(PolymerType.dpeptide, "D-peptide COOH carboxy terminus"), + lPeptideCarboxyTerminus(PolymerType.peptide, "L-peptide COOH carboxy terminus"), + // Nucleotides + dnaLinking(PolymerType.dna, "DNA linking"), + rnaLinking(PolymerType.rna, "RNA linking"), + dna3PrimeTerminus(PolymerType.dna, "DNA OH 3 prime terminus"), + rna3PrimeTerminus(PolymerType.rna, "RNA OH 3 prime terminus"), + dna5PrimeTerminus(PolymerType.dna, "DNA OH 5 prime terminus"), + rna5PrimeTerminus(PolymerType.rna, "RNA OH 5 prime terminus"), + // Sugars + dSaccharide(PolymerType.polysaccharide, "D-saccharide"), + dSaccharide14and14linking(PolymerType.polysaccharide, "D-saccharide 1,4 and 1,4 linking"), + dSaccharide14and16linking(PolymerType.polysaccharide, "D-saccharide 1,4 and 1,6 linking"), + lSaccharide(PolymerType.lpolysaccharide, "L-saccharide"), + lSaccharide14and14linking(PolymerType.lpolysaccharide, "L-saccharide 1,4 and 1,4 linking"), + lSaccharide14and16linking(PolymerType.lpolysaccharide, "L-saccharide 1,4 and 1,6 linking"), + saccharide(PolymerType.polysaccharide, "saccharide"), + // Iso-peptides + dBetaPeptideCGammaLinking(PolymerType.dpeptide,"D-beta-peptide, C-gamma linking"), + dGammaPeptideCDeltaLinking(PolymerType.dpeptide,"D-gamma-peptide, C-delta linking"), + lBetaPeptideCGammaLinking(PolymerType.peptide,"L-beta-peptide, C-gamma linking"), + lGammaPeptideCDeltaLinking(PolymerType.peptide,"L-gamma-peptide, C-delta linking"), + // L nucleotides. As of 2015-04, these are only found in D-DNA hybrids, so they don't have their own PolymerType + lDNALinking(PolymerType.dna,"L-DNA linking"), + lRNALinking(PolymerType.dna,"L-RNA linking"), + // Other + nonPolymer(null, "non-polymer"), + otherChemComp(null, "other"); + + static Map lookupTable = new HashMap<>(); + + static { + for (ResidueType residueType : ResidueType.values() ) { + lookupTable.put(residueType.chem_comp_type, residueType); + lookupTable.put(residueType.chem_comp_type.toLowerCase(), residueType); + } + } + + ResidueType(PolymerType polymerType, String chem_comp_type) { + this.polymerType = polymerType; + this.chem_comp_type = chem_comp_type; + } + + /** + * The associated {@link PolymerType} + */ + public final PolymerType polymerType; + + /** + * Gets the associated PolymerType, which are less specific + * @return + */ + public PolymerType getPolymerType() { + return polymerType; + } + + /** + * String value of the type + */ + public final String chem_comp_type; + + /** Get ResidueType by chem_comp_type + * + * @param chem_comp_type e.g. L-peptide linking + * @return + */ + public static ResidueType getResidueTypeFromString(String chem_comp_type) { + // Almost all calls to this method are for L-peptide linking. Use this knowledge for a shortcut. + if (chem_comp_type.equalsIgnoreCase(lPeptideLinking.chem_comp_type)) { + return lPeptideLinking; + } + + ResidueType lookedUpResidueType = lookupTable.get(chem_comp_type); + if (lookedUpResidueType != null) { + return lookedUpResidueType; + } + + /* + * Unfortunately it can be guaranteed that chem_comp_type case sensitivity is preserved. + * E.g. mmtf has it all upper-case. As such we need to do a second check + */ + lookedUpResidueType = lookupTable.get(chem_comp_type.toLowerCase()); + if (lookedUpResidueType != null) { + return lookedUpResidueType; + } + + // preserving previous behaviour. Not sure if this is really necessary? + for (ResidueType residueType : ResidueType.values()) { + if(residueType.chem_comp_type.equalsIgnoreCase(chem_comp_type)) { + return residueType; + } + + if (residueType.chem_comp_type.toLowerCase().startsWith(chem_comp_type.toLowerCase())) { + return residueType; + } + if (chem_comp_type.toLowerCase().startsWith(residueType.chem_comp_type.toLowerCase())) { + return residueType; + } + } + return null; + } +} 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 40953a1ee2..b8e10ffbb8 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 @@ -36,13 +36,10 @@ 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.chem.ChemComp; +import org.biojava.nbio.structure.chem.PolymerType; import org.biojava.nbio.structure.io.FileConvert; import org.biojava.nbio.structure.io.FileParsingParameters; -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; diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/BondMaker.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/BondMaker.java index bb92724aa4..aee22b0767 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/BondMaker.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/BondMaker.java @@ -23,12 +23,9 @@ package org.biojava.nbio.structure.io; import org.biojava.nbio.structure.*; -import org.biojava.nbio.structure.io.mmcif.ChemCompGroupFactory; -import org.biojava.nbio.structure.io.mmcif.ChemCompProvider; -import org.biojava.nbio.structure.io.mmcif.model.ChemComp; -import org.biojava.nbio.structure.io.mmcif.model.ChemCompBond; -import org.biojava.nbio.structure.io.mmcif.model.StructConn; import org.biojava.nbio.structure.io.util.PDBTemporaryStorageUtils.LinkRecord; +import org.rcsb.cif.model.ValueKind; +import org.rcsb.cif.schema.mm.StructConn; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -53,8 +50,6 @@ * */ public class BondMaker { - - private static final Logger logger = LoggerFactory.getLogger(BondMaker.class); /** @@ -366,41 +361,44 @@ public void formLinkRecordBond(LinkRecord linkRecord) { } - public void formBondsFromStructConn(List structConn) { - + public void formBondsFromStructConn(StructConn conn) { final String symop = "1_555"; // For now - accept bonds within origin asymmetric unit. - List ssbonds = new ArrayList<>(); - for (StructConn conn : structConn) { - - if (!BOND_TYPES_TO_PARSE.contains(conn.getConn_type_id())) continue; + for (int i = 0; i < conn.getRowCount(); i++) { + if (!BOND_TYPES_TO_PARSE.contains(conn.getConnTypeId().get(i))) continue; String chainId1; String chainId2; - chainId1 = conn.getPtnr1_label_asym_id(); - chainId2 = conn.getPtnr2_label_asym_id(); + chainId1 = conn.getPtnr1LabelAsymId().get(i); + chainId2 = conn.getPtnr2LabelAsymId().get(i); String insCode1 = ""; - if (conn.getPdbx_ptnr1_PDB_ins_code() != null && - !conn.getPdbx_ptnr1_PDB_ins_code().equals("?")) insCode1 = conn.getPdbx_ptnr1_PDB_ins_code(); + if (conn.getPdbxPtnr1PDBInsCode().getValueKind(i) == ValueKind.PRESENT) { + insCode1 = conn.getPdbxPtnr1PDBInsCode().get(i); + } String insCode2 = ""; - if (conn.getPdbx_ptnr2_PDB_ins_code() != null && - !conn.getPdbx_ptnr2_PDB_ins_code().equals("?")) insCode2 = conn.getPdbx_ptnr2_PDB_ins_code(); - - String seqId1 = conn.getPtnr1_auth_seq_id(); - String seqId2 = conn.getPtnr2_auth_seq_id(); - String resName1 = conn.getPtnr1_label_comp_id(); - String resName2 = conn.getPtnr2_label_comp_id(); - String atomName1 = conn.getPtnr1_label_atom_id(); - String atomName2 = conn.getPtnr2_label_atom_id(); + if (conn.getPdbxPtnr2PDBInsCode().getValueKind(i) == ValueKind.PRESENT) { + insCode2 = conn.getPdbxPtnr2PDBInsCode().get(i); + } + + String seqId1 = conn.getPtnr1AuthSeqId().getStringData(i); + String seqId2 = conn.getPtnr2AuthSeqId().getStringData(i); + String resName1 = conn.getPtnr1LabelCompId().get(i); + String resName2 = conn.getPtnr2LabelCompId().get(i); + String atomName1 = conn.getPtnr1LabelAtomId().get(i); + String atomName2 = conn.getPtnr2LabelAtomId().get(i); String altLoc1 = ""; - if (!conn.getPdbx_ptnr1_label_alt_id().equals("?")) altLoc1 = conn.getPdbx_ptnr1_label_alt_id(); + if (conn.getPdbxPtnr1LabelAltId().getValueKind(i) == ValueKind.PRESENT) { + altLoc1 = conn.getPdbxPtnr1LabelAltId().get(i); + } String altLoc2 = ""; - if (!conn.getPdbx_ptnr2_label_alt_id().equals("?")) altLoc2 = conn.getPdbx_ptnr2_label_alt_id(); + if (conn.getPdbxPtnr2LabelAltId().getValueKind(i) == ValueKind.PRESENT) { + altLoc2 = conn.getPdbxPtnr2LabelAltId().get(i); + } // TODO: when issue 220 is implemented, add robust symmetry handling to allow bonds between symmetry-related molecules. - if (!conn.getPtnr1_symmetry().equals(symop) || !conn.getPtnr2_symmetry().equals(symop) ) { + if (!conn.getPtnr1Symmetry().get(i).equals(symop) || !conn.getPtnr2Symmetry().get(i).equals(symop) ) { logger.info("Skipping bond between atoms {}(residue {}{}) and {}(residue {}{}) belonging to different symmetry partners, because it is not supported yet", atomName1, seqId1, insCode1, atomName2, seqId2, insCode2); continue; @@ -441,20 +439,19 @@ public void formBondsFromStructConn(List structConn) { } // assuming order 1 for all bonds, no information is provided by struct_conn - for(int i=0; i list = MMCIFFileTools.convertStructureToAtomSites(structure); - - - str.append(MMCIFFileTools.toMMCIF(list,AtomSite.class)); - - return str.toString(); + public static String toMMCIF(Chain chain, String authId, String asymId) { + return CifFileConverter.toText(chain, authId, asymId); } - public static String toMMCIF(Chain chain, String authId, String asymId, boolean writeHeader) { - StringBuilder str = new StringBuilder(); - - if (writeHeader) - str.append(getAtomSiteHeader()); - - - List list = MMCIFFileTools.convertChainToAtomSites(chain, 1, authId, asymId); - - str.append(MMCIFFileTools.toMMCIF(list,AtomSite.class)); - return str.toString(); - } - - public static String toMMCIF(Chain chain, boolean writeHeader) { - StringBuilder sb = new StringBuilder(); - sb.append(SimpleMMcifParser.MMCIF_TOP_HEADER+"BioJava_mmCIF_file"+newline); - sb.append(toMMCIF(chain, chain.getName(), chain.getId(),writeHeader)); - return sb.toString(); - } - - public static String getAtomSiteHeader() { - String header; - try { - header = MMCIFFileTools.toLoopMmCifHeaderString("_atom_site", AtomSite.class.getName()); - - } catch (ClassNotFoundException e) { - logger.error("Class not found, will not have a header for this MMCIF category: "+e.getMessage()); - header = ""; - } - - return header; + public static String toMMCIF(Chain chain) { + return CifFileConverter.toText(chain); } } diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/MMCIFFileReader.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/MMCIFFileReader.java deleted file mode 100644 index ca91f8d70d..0000000000 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/MMCIFFileReader.java +++ /dev/null @@ -1,143 +0,0 @@ -/* - * BioJava development code - * - * This code may be freely distributed and modified under the - * terms of the GNU Lesser General Public Licence. This should - * be distributed with the code. If you do not have a copy, - * see: - * - * http://www.gnu.org/copyleft/lesser.html - * - * Copyright for this code is held jointly by the individual - * authors. These should be listed in @author doc comments. - * - * For more information on the BioJava project and its aims, - * or to join the biojava-l mailing list, visit the home page - * at: - * - * http://www.biojava.org/ - * - * created at Oct 18, 2008 - */ -package org.biojava.nbio.structure.io; - -import org.biojava.nbio.structure.Structure; -import org.biojava.nbio.structure.align.util.UserConfiguration; -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 java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; - - -/** How to parse an mmCif file: - *
-public static void main(String[] args) throws Exception {
-	String filename =  "/path/to/something.cif.gz" ;
-
-	StructureIOFile reader = new MMCIFFileReader();
-
-	Structure struc = reader.getStructure(filename);
-	System.out.println(struc);
-}
-
- * - * @author Andreas Prlic - * @since 1.7 - * - */ -public class MMCIFFileReader extends LocalPDBDirectory { - - //private static final Logger logger = LoggerFactory.getLogger(MMCIFFileReader.class); - - public static final String[] MMCIF_SPLIT_DIR = new String[]{"data","structures","divided" ,"mmCIF"}; - public static final String[] MMCIF_OBSOLETE_DIR = new String[]{"data","structures","obsolete","mmCIF"}; - - private SimpleMMcifConsumer consumer; - - public static void main(String[] args) throws Exception { - - MMCIFFileReader reader = new MMCIFFileReader(); - FileParsingParameters params = new FileParsingParameters(); - reader.setFileParsingParameters(params); - - - Structure struc = reader.getStructureById("1m4x"); - System.out.println(struc); - System.out.println(struc.toPDB()); - - - } - - /** - * Constructs a new MMCIFFileReader, initializing the extensions member variable. - * The path is initialized in the same way as {@link UserConfiguration}, - * i.e. to system property/environment variable {@link UserConfiguration#PDB_DIR}. - * Both autoFetch and splitDir are initialized to false - */ - public MMCIFFileReader(){ - this(null); - } - - /** - * Constructs a new PDBFileReader, initializing the extensions member variable. - * The path is initialized to the given path, both autoFetch and splitDir are initialized to false. - */ - public MMCIFFileReader(String path){ - super(path); - addExtension(".cif"); - addExtension(".mmcif"); - addExtension(".cif.gz"); - addExtension(".mmcif.gz"); - } - - @Override - public Structure getStructure(InputStream inStream) throws IOException{ - - MMcifParser parser = new SimpleMMcifParser(); - - consumer = new SimpleMMcifConsumer(); - - consumer.setFileParsingParameters(getFileParsingParameters()); - - - // The Consumer builds up the BioJava - structure object. - // you could also hook in your own and build up you own data model. - parser.addMMcifConsumer(consumer); - - parser.parse(new BufferedReader(new InputStreamReader(inStream))); - - - // now get the protein structure. - Structure cifStructure = consumer.getStructure(); - - return cifStructure; - } - - public SimpleMMcifConsumer getMMcifConsumer(){ - return consumer; - } - -// public void setMMCifConsumer(SimpleMMcifConsumer consumer){ -// this.consumer = consumer; -// } - - @Override - protected String getFilename(String pdbId) { - return pdbId.toLowerCase()+".cif.gz"; - } - - @Override - protected String[] getSplitDirPath() { - return MMCIF_SPLIT_DIR; - } - - @Override - protected String[] getObsoleteDirPath() { - return MMCIF_OBSOLETE_DIR; - } - -} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/CifFileSupplierImpl.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/AbstractCifFileSupplier.java similarity index 84% rename from biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/CifFileSupplierImpl.java rename to biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/AbstractCifFileSupplier.java index 6b39cf9c58..0c039467c1 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/CifFileSupplierImpl.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/AbstractCifFileSupplier.java @@ -20,7 +20,6 @@ import org.rcsb.cif.schema.mm.MmCifCategoryBuilder; import org.rcsb.cif.schema.mm.MmCifFileBuilder; -import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -28,13 +27,12 @@ import java.util.stream.Collector; /** - * Convert a BioJava {@link Structure} to a CifFile. + * Convert a BioJava object to a CifFile. * @author Sebastian Bittrich * @since 5.3.0 */ -class CifFileSupplierImpl implements CifFileSupplier { - @Override - public CifFile get(Structure structure) { +public abstract class AbstractCifFileSupplier implements CifFileSupplier { + protected CifFile getInternal(Structure structure, List wrappedAtoms) { // for now BioJava only considered 3 categories for create a Cif representation of a structure // cell @@ -42,7 +40,6 @@ public CifFile get(Structure structure) { // symmetry SpaceGroup spaceGroup = structure.getPDBHeader().getCrystallographicInfo().getSpaceGroup(); // atom_site - List wrappedAtoms = collectWrappedAtoms(structure); Category atomSite = wrappedAtoms.stream().collect(toAtomSite()); MmCifBlockBuilder blockBuilder = CifBuilder.enterFile(StandardSchemata.MMCIF) @@ -94,49 +91,40 @@ public CifFile get(Structure structure) { return blockBuilder.leaveBlock().leaveFile(); } - private static List collectWrappedAtoms(Structure structure) { - List wrappedAtoms = new ArrayList<>(); - - for (int modelIndex = 0; modelIndex < structure.nrModels(); modelIndex++) { - final int model = modelIndex + 1; - for (Chain chain : structure.getChains(modelIndex)) { - final String chainName = chain.getName(); - final String chainId = chain.getId(); - for (Group group : chain.getAtomGroups()) { - // The alt locs can have duplicates, since at parsing time we make sure that all alt loc groups have - // all atoms (see StructureTools#cleanUpAltLocs) - // Thus we have to remove duplicates here by using the atom id - // See issue https://github.com/biojava/biojava/issues/778 and - // TestAltLocs.testMmcifWritingAllAltlocs/testMmcifWritingPartialAltlocs - Map uniqueAtoms = new LinkedHashMap<>(); - for (int atomIndex = 0; atomIndex < group.size(); atomIndex++) { - Atom atom = group.getAtom(atomIndex); + protected void handleChain(Chain chain, int model, List wrappedAtoms) { + final String chainName = chain.getName(); + final String chainId = chain.getId(); + for (Group group : chain.getAtomGroups()) { + // The alt locs can have duplicates, since at parsing time we make sure that all alt loc groups have + // all atoms (see StructureTools#cleanUpAltLocs) + // Thus we have to remove duplicates here by using the atom id + // See issue https://github.com/biojava/biojava/issues/778 and + // TestAltLocs.testMmcifWritingAllAltlocs/testMmcifWritingPartialAltlocs + Map uniqueAtoms = new LinkedHashMap<>(); + for (int atomIndex = 0; atomIndex < group.size(); atomIndex++) { + Atom atom = group.getAtom(atomIndex); + if (atom == null) { + continue; + } + + uniqueAtoms.put(atom.getPDBserial(), new WrappedAtom(chain, model, chainName, chainId, atom, atom.getPDBserial())); + } + + if (group.hasAltLoc()) { + for (Group alt : group.getAltLocs()) { + for (int atomIndex = 0; atomIndex < alt.size(); atomIndex++) { + Atom atom = alt.getAtom(atomIndex); if (atom == null) { continue; } uniqueAtoms.put(atom.getPDBserial(), new WrappedAtom(chain, model, chainName, chainId, atom, atom.getPDBserial())); } - - if (group.hasAltLoc()) { - for (Group alt : group.getAltLocs()) { - for (int atomIndex = 0; atomIndex < alt.size(); atomIndex++) { - Atom atom = alt.getAtom(atomIndex); - if (atom == null) { - continue; - } - - uniqueAtoms.put(atom.getPDBserial(), new WrappedAtom(chain, model, chainName, chainId, atom, atom.getPDBserial())); - } - } - } - - wrappedAtoms.addAll(uniqueAtoms.values()); } } - } - return wrappedAtoms; + wrappedAtoms.addAll(uniqueAtoms.values()); + } } static class WrappedAtom { diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/ChainSupplierImpl.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/ChainSupplierImpl.java new file mode 100644 index 0000000000..08516d47b3 --- /dev/null +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/ChainSupplierImpl.java @@ -0,0 +1,20 @@ +package org.biojava.nbio.structure.io.cif; + +import org.biojava.nbio.structure.Chain; +import org.rcsb.cif.model.CifFile; + +import java.util.ArrayList; +import java.util.List; + +public class ChainSupplierImpl extends AbstractCifFileSupplier { + @Override + public CifFile get(Chain container) { + return getInternal(container.getStructure(), collectWrappedAtoms(container)); + } + + private List collectWrappedAtoms(Chain chain) { + List wrappedAtoms = new ArrayList<>(); + handleChain(chain, 1, wrappedAtoms); + return wrappedAtoms; + } +} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/ChemCompConsumer.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/ChemCompConsumer.java new file mode 100644 index 0000000000..c8553b21c7 --- /dev/null +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/ChemCompConsumer.java @@ -0,0 +1,14 @@ +package org.biojava.nbio.structure.io.cif; + +import org.biojava.nbio.structure.chem.ChemComp; +import org.rcsb.cif.schema.mm.ChemCompAtom; +import org.rcsb.cif.schema.mm.ChemCompBond; +import org.rcsb.cif.schema.mm.PdbxChemCompDescriptor; + +public interface ChemCompConsumer extends CifFileConsumer { + void consumeChemCompAtom(ChemCompAtom chemCompAtom); + + void consumeChemCompBond(ChemCompBond chemCompBond); + + void consumePdbxChemCompDescriptor(PdbxChemCompDescriptor pdbxChemCompDescriptor); +} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/ChemCompConsumerImpl.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/ChemCompConsumerImpl.java new file mode 100644 index 0000000000..f97a89d271 --- /dev/null +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/ChemCompConsumerImpl.java @@ -0,0 +1,70 @@ +package org.biojava.nbio.structure.io.cif; + +import org.biojava.nbio.structure.chem.ChemComp; +import org.biojava.nbio.structure.chem.ChemicalComponentDictionary; +import org.biojava.nbio.structure.chem.ResidueType; +import org.rcsb.cif.schema.mm.ChemCompAtom; +import org.rcsb.cif.schema.mm.ChemCompBond; +import org.rcsb.cif.schema.mm.PdbxChemCompDescriptor; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class ChemCompConsumerImpl implements ChemCompConsumer { + private static final Logger logger = LoggerFactory.getLogger(ChemCompConsumerImpl.class); + private ChemicalComponentDictionary dictionary; + private String latestChemCompId; + + public ChemCompConsumerImpl(){ + dictionary = new ChemicalComponentDictionary(); + } + + @Override + public void prepare() { + + } + + public ChemicalComponentDictionary getDictionary(){ + return dictionary; + } + + @Override + public void consumeChemCompAtom(ChemCompAtom chemCompAtom) { + dictionary.getChemComp(latestChemCompId).getAtoms().add(chemCompAtom); + } + + @Override + public void consumeChemCompBond(ChemCompBond chemCompBond) { + dictionary.getChemComp(latestChemCompId).getBonds().add(chemCompBond); + } + + @Override + public void consumePdbxChemCompDescriptor(PdbxChemCompDescriptor pdbxChemCompDescriptor) { + ChemComp cc = dictionary.getChemComp(latestChemCompId); + cc.getDescriptors().add(pdbxChemCompDescriptor); + } + + @Override + public void finish() { + + } + + @Override + public ChemComp getContainer() { + if (c.getId() == null) + logger.warn("chem comp ID == null " + c); + + latestChemCompId = c.getId(); + dictionary.addChemComp(c); + if (c.getResidueType() == ResidueType.nonPolymer) { + return; + } + + if (c.getResidueType() == ResidueType.saccharide) { + return; + } + + if (c.getResidueType() == ResidueType.dSaccharide) { + return; + } + } +} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/CifBean.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/CifBean.java new file mode 100644 index 0000000000..1196aafada --- /dev/null +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/CifBean.java @@ -0,0 +1,12 @@ +package org.biojava.nbio.structure.io.cif; + +import org.rcsb.cif.model.Category; + +import java.io.Serializable; + +/** + * Flag for BioJava beans that actually resemble categories defined by the mmCIF schema. + * @param the modeled ciftools-java category + */ +public interface CifBean extends Serializable { +} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/CifFileConsumer.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/CifFileConsumer.java index d15c9cc140..198f288305 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/CifFileConsumer.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/CifFileConsumer.java @@ -1,5 +1,7 @@ package org.biojava.nbio.structure.io.cif; +import org.biojava.nbio.structure.chem.ChemCompAtom; +import org.biojava.nbio.structure.chem.ChemCompDescriptor; import org.rcsb.cif.schema.mm.AtomSite; import org.rcsb.cif.schema.mm.AtomSites; import org.rcsb.cif.schema.mm.AuditAuthor; @@ -53,282 +55,12 @@ * @author Sebastian Bittrich * @since 5.3.0 */ -interface CifFileConsumer { +public interface CifFileConsumer { /** * Setup routine which initializes a new container. */ void prepare(); - /** - * Consume a particular Cif category. - * @param atomSite data - */ - void consumeAtomSite(AtomSite atomSite); - - /** - * Consume a particular Cif category. - * @param atomSites data - */ - void consumeAtomSites(AtomSites atomSites); - - /** - * Consume a particular Cif category. - * @param auditAuthor data - */ - void consumeAuditAuthor(AuditAuthor auditAuthor); - - /** - * Consume a particular Cif category. - * @param cell data - */ - void consumeCell(Cell cell); - - /** - * Consume a particular Cif category. - * @param chemComp data - */ - void consumeChemComp(ChemComp chemComp); - - /** - * Consume a particular Cif category. - * @param chemCompBond data - */ - void consumeChemCompBond(ChemCompBond chemCompBond); - - /** - * Consume a particular Cif category. - * @param databasePDBremark data - */ - void consumeDatabasePDBremark(DatabasePDBRemark databasePDBremark); - - /** - * Consume a particular Cif category. - * @param databasePDBrev data - */ - void consumeDatabasePDBrev(DatabasePDBRev databasePDBrev); - - /** - * Consume a particular Cif category. - * @param databasePDBrevRecord data - */ - void consumeDatabasePDBrevRecord(DatabasePDBRevRecord databasePDBrevRecord); - - /** - * Consume a particular Cif category. - * @param entity data - */ - void consumeEntity(Entity entity); - - /** - * Consume a particular Cif category. - * @param entityPoly data - */ - void consumeEntityPoly(EntityPoly entityPoly); - - /** - * Consume a particular Cif category. - * @param entitySrcGen data - */ - void consumeEntitySrcGen(EntitySrcGen entitySrcGen); - - /** - * Consume a particular Cif category. - * @param entitySrcNat data - */ - void consumeEntitySrcNat(EntitySrcNat entitySrcNat); - - /** - * Consume a particular Cif category. - * @param entitySrcSyn data - */ - void consumeEntitySrcSyn(PdbxEntitySrcSyn entitySrcSyn); - - /** - * Consume a particular Cif category. - * @param entityPolySeq data - */ - void consumeEntityPolySeq(EntityPolySeq entityPolySeq); - - /** - * Consume a particular Cif category. - * @param exptl data - */ - void consumeExptl(Exptl exptl); - - /** - * Consume a particular Cif category. - * @param pdbxAuditRevisionHistory data - */ - void consumePdbxAuditRevisionHistory(PdbxAuditRevisionHistory pdbxAuditRevisionHistory); - - /** - * Consume a particular Cif category. - * @param pdbxChemCompIdentifier data - */ - void consumePdbxChemCompIdentifier(PdbxChemCompIdentifier pdbxChemCompIdentifier); - - /** - * Consume a particular Cif category. - * @param pdbxDatabaseStatus data - */ - void consumePdbxDatabaseStatus(PdbxDatabaseStatus pdbxDatabaseStatus); - - /** - * Consume a particular Cif category. - * @param pdbxEntityBranchDescriptor data - */ - void consumePdbxEntityBranchDescriptor(PdbxEntityBranchDescriptor pdbxEntityBranchDescriptor); - - /** - * Consume a particular Cif category. - * @param pdbxMolecule data - */ - void consumePdbxMolecule(PdbxMolecule pdbxMolecule); - - /** - * Consume a particular Cif category. - * @param pdbxMoleculeFeatures data - */ - void consumePdbxMoleculeFeatures(PdbxMoleculeFeatures pdbxMoleculeFeatures); - - /** - * Consume a particular Cif category. - * @param pdbxNonpolyScheme data - */ - void consumePdbxNonpolyScheme(PdbxNonpolyScheme pdbxNonpolyScheme); - - /** - * Consume a particular Cif category. - * @param pdbxReferenceEntityLink data - */ - void consumePdbxReferenceEntityLink(PdbxReferenceEntityLink pdbxReferenceEntityLink); - - /** - * Consume a particular Cif category. - * @param pdbxReferenceEntityList data - */ - void consumePdbxReferenceEntityList(PdbxReferenceEntityList pdbxReferenceEntityList); - - /** - * Consume a particular Cif category. - * @param pdbxReferenceEntityPolyLink data - */ - void consumePdbxReferenceEntityPolyLink(PdbxReferenceEntityPolyLink pdbxReferenceEntityPolyLink); - - /** - * Consume a particular Cif category. - * @param pdbxStructAssembly data - */ - void consumePdbxStructAssembly(PdbxStructAssembly pdbxStructAssembly); - - /** - * Consume a particular Cif category. - * @param pdbxStructAssemblyGen data - */ - void consumePdbxStructAssemblyGen(PdbxStructAssemblyGen pdbxStructAssemblyGen); - - /** - * Consume a particular Cif category. - * @param pdbxStructModResidue data - */ - void consumePdbxStructModResidue(PdbxStructModResidue pdbxStructModResidue); - - /** - * Consume a particular Cif category. - * @param pdbxStructOperList data - */ - void consumePdbxStructOperList(PdbxStructOperList pdbxStructOperList); - - /** - * Consume a particular Cif category. - * @param refine data - */ - void consumeRefine(Refine refine); - - /** - * Consume a particular Cif category. - * @param struct data - */ - void consumeStruct(Struct struct); - - /** - * Consume a particular Cif category. - * @param structAsym data - */ - void consumeStructAsym(StructAsym structAsym); - - /** - * Consume a particular Cif category. - * @param structConf data - */ - void consumeStructConf(StructConf structConf); - - /** - * Consume a particular Cif category. - * @param structConn data - */ - void consumeStructConn(StructConn structConn); - - /** - * Consume a particular Cif category. - * @param structConnType data - */ - void consumeStructConnType(StructConnType structConnType); - - /** - * Consume a particular Cif category. - * @param structKeywords data - */ - void consumeStructKeywords(StructKeywords structKeywords); - - /** - * Consume a particular Cif category. - * @param structNcsOper data - */ - void consumeStructNcsOper(StructNcsOper structNcsOper); - - /** - * Consume a particular Cif category. - * @param structRef data - */ - void consumeStructRef(StructRef structRef); - - /** - * Consume a particular Cif category. - * @param structRefSeq data - */ - void consumeStructRefSeq(StructRefSeq structRefSeq); - - /** - * Consume a particular Cif category. - * @param structRefSeqDif data - */ - void consumeStructRefSeqDif(StructRefSeqDif structRefSeqDif); - - /** - * Consume a particular Cif category. - * @param structSheetRange data - */ - void consumeStructSheetRange(StructSheetRange structSheetRange); - - /** - * Consume a particular Cif category. - * @param structSite data - */ - void consumeStructSite(StructSite structSite); - - /** - * Consume a particular Cif category. - * @param structSiteGen data - */ - void consumeStructSiteGen(StructSiteGen structSiteGen); - - /** - * Consume a particular Cif category. - * @param symmetry data - */ - void consumeSymmetry(Symmetry symmetry); - /** * Ultimate setup which can include steps which require several categories to be available and integrate them into * the final container. diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/CifFileConverter.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/CifFileConverter.java index 8f82e310b6..30e5682b69 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/CifFileConverter.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/CifFileConverter.java @@ -1,5 +1,6 @@ package org.biojava.nbio.structure.io.cif; +import org.biojava.nbio.structure.Chain; import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.io.FileParsingParameters; import org.rcsb.cif.CifIO; @@ -9,6 +10,7 @@ import java.io.IOException; import java.io.InputStream; +import java.io.UncheckedIOException; import java.net.URL; import java.nio.file.Files; import java.nio.file.Path; @@ -99,7 +101,7 @@ public static Structure fromCifFile(CifFile cifFile) { */ public static Structure fromCifFile(CifFile cifFile, FileParsingParameters parameters) { // initialize consumer - CifFileConsumer consumer = new CifFileConsumerImpl(parameters); + StructureConsumer consumer = new StructureConsumerImpl(parameters); // init structure consumer.prepare(); @@ -113,9 +115,9 @@ public static Structure fromCifFile(CifFile cifFile, FileParsingParameters param consumer.consumeCell(cifBlock.getCell()); consumer.consumeChemComp(cifBlock.getChemComp()); consumer.consumeChemCompBond(cifBlock.getChemCompBond()); - consumer.consumeDatabasePDBremark(cifBlock.getDatabasePDBRemark()); - consumer.consumeDatabasePDBrev(cifBlock.getDatabasePDBRev()); - consumer.consumeDatabasePDBrevRecord(cifBlock.getDatabasePDBRevRecord()); + consumer.consumeDatabasePDBRemark(cifBlock.getDatabasePDBRemark()); + consumer.consumeDatabasePDBRev(cifBlock.getDatabasePDBRev()); + consumer.consumeDatabasePDBRevRecord(cifBlock.getDatabasePDBRevRecord()); consumer.consumeEntity(cifBlock.getEntity()); consumer.consumeEntityPoly(cifBlock.getEntityPoly()); consumer.consumeEntitySrcGen(cifBlock.getEntitySrcGen()); @@ -183,20 +185,39 @@ public static void toBinaryFile(Structure structure, Path path) throws IOExcepti * Convert a structure to BCIF format. * @param structure the source * @return the binary representation of the structure - * @throws IOException thrown when writing fails */ - public static byte[] toBinary(Structure structure) throws IOException { - return CifIO.writeText(toCifFile(structure)); + public static byte[] toBinary(Structure structure) { + try { + return CifIO.writeText(toCifFile(structure)); + } catch (IOException e) { + throw new UncheckedIOException(e); + } } /** * Convert a structure to mmCIF format. * @param structure the source * @return the mmCIF String representation of the structure - * @throws IOException thrown when writing fails */ - public static String toText(Structure structure) throws IOException { - return new String(CifIO.writeText(toCifFile(structure))); + public static String toText(Structure structure) { + try { + return new String(CifIO.writeText(toCifFile(structure))); + } catch (IOException e) { + throw new UncheckedIOException(e); + } + } + + /** + * Convert a chain to mmCIF format. + * @param chain the source + * @return the mmCIF String representation of the chain + */ + public static String toText(Chain chain) { + try { + return new String(CifIO.writeText(toCifFile(chain))); + } catch (IOException e) { + throw new UncheckedIOException(e); + } } /** @@ -205,6 +226,15 @@ public static String toText(Structure structure) throws IOException { * @return the target */ public static CifFile toCifFile(Structure structure) { - return new CifFileSupplierImpl().get(structure); + return new AbstractCifFileSupplier().getStructure(structure); + } + + /** + * Convert Chain to CifFile + * @param chain the source + * @return the target + */ + public static CifFile toCifFile(Chain chain) { + return new AbstractCifFileSupplier().getChain(chain); } } diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/CifFileSupplier.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/CifFileSupplier.java index a4fcbe4c90..08f35fce54 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/CifFileSupplier.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/CifFileSupplier.java @@ -2,13 +2,15 @@ import org.rcsb.cif.model.CifFile; +import java.util.function.Supplier; + /** * Create a CifFile instance for a given container of structure data. * @param the container type used as source * @author Sebastian Bittrich * @since 5.3.0 */ -interface CifFileSupplier { +public interface CifFileSupplier { /** * Convert some model instance describing structure information to a CifFile instance. * @param container the source of structure information diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/StructureConsumer.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/StructureConsumer.java new file mode 100644 index 0000000000..9594a2c71d --- /dev/null +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/StructureConsumer.java @@ -0,0 +1,320 @@ +package org.biojava.nbio.structure.io.cif; + +import org.biojava.nbio.structure.Structure; +import org.rcsb.cif.schema.mm.AtomSite; +import org.rcsb.cif.schema.mm.AtomSites; +import org.rcsb.cif.schema.mm.AuditAuthor; +import org.rcsb.cif.schema.mm.Cell; +import org.rcsb.cif.schema.mm.ChemComp; +import org.rcsb.cif.schema.mm.ChemCompBond; +import org.rcsb.cif.schema.mm.DatabasePDBRemark; +import org.rcsb.cif.schema.mm.DatabasePDBRev; +import org.rcsb.cif.schema.mm.DatabasePDBRevRecord; +import org.rcsb.cif.schema.mm.Entity; +import org.rcsb.cif.schema.mm.EntityPoly; +import org.rcsb.cif.schema.mm.EntityPolySeq; +import org.rcsb.cif.schema.mm.EntitySrcGen; +import org.rcsb.cif.schema.mm.EntitySrcNat; +import org.rcsb.cif.schema.mm.Exptl; +import org.rcsb.cif.schema.mm.PdbxAuditRevisionHistory; +import org.rcsb.cif.schema.mm.PdbxChemCompIdentifier; +import org.rcsb.cif.schema.mm.PdbxDatabaseStatus; +import org.rcsb.cif.schema.mm.PdbxEntityBranchDescriptor; +import org.rcsb.cif.schema.mm.PdbxEntitySrcSyn; +import org.rcsb.cif.schema.mm.PdbxMolecule; +import org.rcsb.cif.schema.mm.PdbxMoleculeFeatures; +import org.rcsb.cif.schema.mm.PdbxNonpolyScheme; +import org.rcsb.cif.schema.mm.PdbxReferenceEntityLink; +import org.rcsb.cif.schema.mm.PdbxReferenceEntityList; +import org.rcsb.cif.schema.mm.PdbxReferenceEntityPolyLink; +import org.rcsb.cif.schema.mm.PdbxStructAssembly; +import org.rcsb.cif.schema.mm.PdbxStructAssemblyGen; +import org.rcsb.cif.schema.mm.PdbxStructModResidue; +import org.rcsb.cif.schema.mm.PdbxStructOperList; +import org.rcsb.cif.schema.mm.Refine; +import org.rcsb.cif.schema.mm.Struct; +import org.rcsb.cif.schema.mm.StructAsym; +import org.rcsb.cif.schema.mm.StructConf; +import org.rcsb.cif.schema.mm.StructConn; +import org.rcsb.cif.schema.mm.StructConnType; +import org.rcsb.cif.schema.mm.StructKeywords; +import org.rcsb.cif.schema.mm.StructNcsOper; +import org.rcsb.cif.schema.mm.StructRef; +import org.rcsb.cif.schema.mm.StructRefSeq; +import org.rcsb.cif.schema.mm.StructRefSeqDif; +import org.rcsb.cif.schema.mm.StructSheetRange; +import org.rcsb.cif.schema.mm.StructSite; +import org.rcsb.cif.schema.mm.StructSiteGen; +import org.rcsb.cif.schema.mm.Symmetry; + +public interface StructureConsumer extends CifFileConsumer { + /** + * Consume a particular Cif category. + * @param atomSite data + */ + void consumeAtomSite(AtomSite atomSite); + + /** + * Consume a particular Cif category. + * @param atomSites data + */ + void consumeAtomSites(AtomSites atomSites); + + /** + * Consume a particular Cif category. + * @param auditAuthor data + */ + void consumeAuditAuthor(AuditAuthor auditAuthor); + + /** + * Consume a particular Cif category. + * @param cell data + */ + void consumeCell(Cell cell); + + /** + * Consume a particular Cif category. + * @param chemComp data + */ + void consumeChemComp(ChemComp chemComp); + + /** + * Consume a particular Cif category. + * @param chemCompBond data + */ + void consumeChemCompBond(ChemCompBond chemCompBond); + + /** + * Consume a particular Cif category. + * @param databasePDBremark data + */ + void consumeDatabasePDBRemark(DatabasePDBRemark databasePDBremark); + + /** + * Consume a particular Cif category. + * @param databasePDBrev data + */ + void consumeDatabasePDBRev(DatabasePDBRev databasePDBrev); + + /** + * Consume a particular Cif category. + * @param databasePDBrevRecord data + */ + void consumeDatabasePDBRevRecord(DatabasePDBRevRecord databasePDBrevRecord); + + /** + * Consume a particular Cif category. + * @param entity data + */ + void consumeEntity(Entity entity); + + /** + * Consume a particular Cif category. + * @param entityPoly data + */ + void consumeEntityPoly(EntityPoly entityPoly); + + /** + * Consume a particular Cif category. + * @param entitySrcGen data + */ + void consumeEntitySrcGen(EntitySrcGen entitySrcGen); + + /** + * Consume a particular Cif category. + * @param entitySrcNat data + */ + void consumeEntitySrcNat(EntitySrcNat entitySrcNat); + + /** + * Consume a particular Cif category. + * @param entitySrcSyn data + */ + void consumeEntitySrcSyn(PdbxEntitySrcSyn entitySrcSyn); + + /** + * Consume a particular Cif category. + * @param entityPolySeq data + */ + void consumeEntityPolySeq(EntityPolySeq entityPolySeq); + + /** + * Consume a particular Cif category. + * @param exptl data + */ + void consumeExptl(Exptl exptl); + + /** + * Consume a particular Cif category. + * @param pdbxAuditRevisionHistory data + */ + void consumePdbxAuditRevisionHistory(PdbxAuditRevisionHistory pdbxAuditRevisionHistory); + + /** + * Consume a particular Cif category. + * @param pdbxChemCompIdentifier data + */ + void consumePdbxChemCompIdentifier(PdbxChemCompIdentifier pdbxChemCompIdentifier); + + /** + * Consume a particular Cif category. + * @param pdbxDatabaseStatus data + */ + void consumePdbxDatabaseStatus(PdbxDatabaseStatus pdbxDatabaseStatus); + + /** + * Consume a particular Cif category. + * @param pdbxEntityBranchDescriptor data + */ + void consumePdbxEntityBranchDescriptor(PdbxEntityBranchDescriptor pdbxEntityBranchDescriptor); + + /** + * Consume a particular Cif category. + * @param pdbxMolecule data + */ + void consumePdbxMolecule(PdbxMolecule pdbxMolecule); + + /** + * Consume a particular Cif category. + * @param pdbxMoleculeFeatures data + */ + void consumePdbxMoleculeFeatures(PdbxMoleculeFeatures pdbxMoleculeFeatures); + + /** + * Consume a particular Cif category. + * @param pdbxNonpolyScheme data + */ + void consumePdbxNonpolyScheme(PdbxNonpolyScheme pdbxNonpolyScheme); + + /** + * Consume a particular Cif category. + * @param pdbxReferenceEntityLink data + */ + void consumePdbxReferenceEntityLink(PdbxReferenceEntityLink pdbxReferenceEntityLink); + + /** + * Consume a particular Cif category. + * @param pdbxReferenceEntityList data + */ + void consumePdbxReferenceEntityList(PdbxReferenceEntityList pdbxReferenceEntityList); + + /** + * Consume a particular Cif category. + * @param pdbxReferenceEntityPolyLink data + */ + void consumePdbxReferenceEntityPolyLink(PdbxReferenceEntityPolyLink pdbxReferenceEntityPolyLink); + + /** + * Consume a particular Cif category. + * @param pdbxStructAssembly data + */ + void consumePdbxStructAssembly(PdbxStructAssembly pdbxStructAssembly); + + /** + * Consume a particular Cif category. + * @param pdbxStructAssemblyGen data + */ + void consumePdbxStructAssemblyGen(PdbxStructAssemblyGen pdbxStructAssemblyGen); + + /** + * Consume a particular Cif category. + * @param pdbxStructModResidue data + */ + void consumePdbxStructModResidue(PdbxStructModResidue pdbxStructModResidue); + + /** + * Consume a particular Cif category. + * @param pdbxStructOperList data + */ + void consumePdbxStructOperList(PdbxStructOperList pdbxStructOperList); + + /** + * Consume a particular Cif category. + * @param refine data + */ + void consumeRefine(Refine refine); + + /** + * Consume a particular Cif category. + * @param struct data + */ + void consumeStruct(Struct struct); + + /** + * Consume a particular Cif category. + * @param structAsym data + */ + void consumeStructAsym(StructAsym structAsym); + + /** + * Consume a particular Cif category. + * @param structConf data + */ + void consumeStructConf(StructConf structConf); + + /** + * Consume a particular Cif category. + * @param structConn data + */ + void consumeStructConn(StructConn structConn); + + /** + * Consume a particular Cif category. + * @param structConnType data + */ + void consumeStructConnType(StructConnType structConnType); + + /** + * Consume a particular Cif category. + * @param structKeywords data + */ + void consumeStructKeywords(StructKeywords structKeywords); + + /** + * Consume a particular Cif category. + * @param structNcsOper data + */ + void consumeStructNcsOper(StructNcsOper structNcsOper); + + /** + * Consume a particular Cif category. + * @param structRef data + */ + void consumeStructRef(StructRef structRef); + + /** + * Consume a particular Cif category. + * @param structRefSeq data + */ + void consumeStructRefSeq(StructRefSeq structRefSeq); + + /** + * Consume a particular Cif category. + * @param structRefSeqDif data + */ + void consumeStructRefSeqDif(StructRefSeqDif structRefSeqDif); + + /** + * Consume a particular Cif category. + * @param structSheetRange data + */ + void consumeStructSheetRange(StructSheetRange structSheetRange); + + /** + * Consume a particular Cif category. + * @param structSite data + */ + void consumeStructSite(StructSite structSite); + + /** + * Consume a particular Cif category. + * @param structSiteGen data + */ + void consumeStructSiteGen(StructSiteGen structSiteGen); + + /** + * Consume a particular Cif category. + * @param symmetry data + */ + void consumeSymmetry(Symmetry symmetry); +} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/CifFileConsumerImpl.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/StructureConsumerImpl.java similarity index 89% rename from biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/CifFileConsumerImpl.java rename to biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/StructureConsumerImpl.java index a3af75fc91..d858536847 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/CifFileConsumerImpl.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/StructureConsumerImpl.java @@ -7,7 +7,6 @@ import org.biojava.nbio.structure.Chain; import org.biojava.nbio.structure.ChainImpl; import org.biojava.nbio.structure.DBRef; -import org.biojava.nbio.structure.DatabasePdbRevRecord; import org.biojava.nbio.structure.Element; import org.biojava.nbio.structure.EntityInfo; import org.biojava.nbio.structure.EntityType; @@ -25,12 +24,12 @@ import org.biojava.nbio.structure.StructureException; import org.biojava.nbio.structure.StructureImpl; import org.biojava.nbio.structure.StructureTools; +import org.biojava.nbio.structure.chem.ChemCompGroupFactory; import org.biojava.nbio.structure.io.BondMaker; import org.biojava.nbio.structure.io.ChargeAdder; import org.biojava.nbio.structure.io.EntityFinder; import org.biojava.nbio.structure.io.FileParsingParameters; import org.biojava.nbio.structure.io.SeqRes2AtomAligner; -import org.biojava.nbio.structure.io.mmcif.ChemCompGroupFactory; import org.biojava.nbio.structure.quaternary.BioAssemblyInfo; import org.biojava.nbio.structure.quaternary.BiologicalAssemblyBuilder; import org.biojava.nbio.structure.quaternary.BiologicalAssemblyTransformation; @@ -99,15 +98,12 @@ /** * An implementation of a CifFileConsumer for BioJava. Will process the information provided by a CifFile instance and - * use it to build up a {@link Structure} object. The implementation is for the most part really close to that in - * {@link org.biojava.nbio.structure.io.mmcif.SimpleMMcifConsumer} and associated classes. The main difference is that - * all internally used model classes are generated from the MMCIF schema and a standardized interface to CifFile data is - * provided. This allows to readily parse files in CIF format as well as binary CIF (BCIF) format. + * use it to build up a {@link Structure} object. * @author Sebastian Bittrich - * @since 5.3.0 + * @since 6.0.0 */ -class CifFileConsumerImpl implements CifFileConsumer { - private static final Logger logger = LoggerFactory.getLogger(CifFileConsumerImpl.class); +public class StructureConsumerImpl implements StructureConsumer { + private static final Logger logger = LoggerFactory.getLogger(StructureConsumerImpl.class); private static final DateTimeFormatter DATE_FORMAT = new DateTimeFormatterBuilder() .parseCaseInsensitive() .appendPattern("yyyy-MM-dd") @@ -144,7 +140,7 @@ class CifFileConsumerImpl implements CifFileConsumer { private final FileParsingParameters params; - public CifFileConsumerImpl(FileParsingParameters params) { + public StructureConsumerImpl(FileParsingParameters params) { this.params = params; } @@ -575,7 +571,7 @@ public void consumeChemCompBond(ChemCompBond chemCompBond) { } @Override - public void consumeDatabasePDBremark(DatabasePDBRemark databasePDBremark) { + public void consumeDatabasePDBRemark(DatabasePDBRemark databasePDBremark) { for (int rowIndex = 0; rowIndex < databasePDBremark.getRowCount(); rowIndex++) { int id = databasePDBremark.getId().get(rowIndex); if (id == 2) { @@ -603,7 +599,7 @@ private Date convert(LocalDate localDate) { } @Override - public void consumeDatabasePDBrev(DatabasePDBRev databasePDBrev) { + public void consumeDatabasePDBRev(DatabasePDBRev databasePDBrev) { logger.debug("got a database revision:" + databasePDBrev); for (int rowIndex = 0; rowIndex < databasePDBrev.getRowCount(); rowIndex++) { @@ -621,26 +617,16 @@ public void consumeDatabasePDBrev(DatabasePDBRev databasePDBrev) { } @Override - public void consumeDatabasePDBrevRecord(DatabasePDBRevRecord databasePDBrevRecord) { - List revRecords = pdbHeader.getRevisionRecords(); + public void consumeDatabasePDBRevRecord(DatabasePDBRevRecord databasePDBrevRecord) { + List revRecords = pdbHeader.getRevisionRecords(); if (revRecords == null) { revRecords = new ArrayList<>(); pdbHeader.setRevisionRecords(revRecords); } - revRecords.addAll(convert(databasePDBrevRecord)); - } - - private List convert(DatabasePDBRevRecord databasePDBrevRecord) { - List revRecords = new ArrayList<>(); - for (int rowIndex = 0; rowIndex < databasePDBrevRecord.getRowCount(); rowIndex++) { - DatabasePdbRevRecord revRecord = new DatabasePdbRevRecord(); - revRecord.setDetails(databasePDBrevRecord.getDetails().get(rowIndex)); - revRecord.setRev_num(databasePDBrevRecord.getRevNum().getStringData(rowIndex)); - revRecord.setType(databasePDBrevRecord.getType().get(rowIndex)); - revRecords.add(revRecord); + for (int i = 0; i < databasePDBrevRecord.getRowCount(); i++) { + revRecords.add(new org.biojava.nbio.structure.DatabasePDBRevRecord(databasePDBrevRecord, i)); } - return revRecords; } @Override @@ -1183,25 +1169,24 @@ public void finish() { // the more detailed mapping of chains to rotation operations happens in StructureIO... Map bioAssemblies = new LinkedHashMap<>(); - List structAssemblies = convert(structAssembly); - List structAssemblyGens = convert(structAssemblyGen); - - for (org.biojava.nbio.structure.io.mmcif.model.PdbxStructAssembly pdbxStructAssembly : structAssemblies) { - List pdbxStructAssemblyGens = structAssemblyGens.stream() - .filter(sag -> sag.getAssembly_id().equals(pdbxStructAssembly.getId())) - .collect(Collectors.toList()); - + for (int i = 0; i < structAssembly.getRowCount(); i++) { + String assemblyId = structAssembly.getId().get(i); + List structAssemblyGenIndices = new ArrayList<>(); + for (int j = 0; j < structAssemblyGen.getRowCount(); j++) { + if (structAssemblyGen.getAssemblyId().get(j).equals(assemblyId)) { + structAssemblyGenIndices.add(j); + } + } BiologicalAssemblyBuilder builder = new BiologicalAssemblyBuilder(); - // these are the transformations that need to be applied to our model - List transformations = builder.getBioUnitTransformationList(pdbxStructAssembly, - pdbxStructAssemblyGens, convert(structOpers)); + List transformations = builder.getBioUnitTransformationList(structAssembly, + i, structAssemblyGen, structOpers); int bioAssemblyId = -1; try { - bioAssemblyId = Integer.parseInt(pdbxStructAssembly.getId()); + bioAssemblyId = Integer.parseInt(assemblyId); } catch (NumberFormatException e) { - logger.info("Could not parse a numerical bio assembly id from '{}'", pdbxStructAssembly.getId()); + logger.info("Could not parse a numerical bio assembly id from '{}'", assemblyId); } // if bioassembly id is not numerical we throw it away @@ -1418,68 +1403,6 @@ private void setStructNcsOps() { } } - private List convert(PdbxStructOperList structOpers) { - List re = new ArrayList<>(); - for (int rowIndex = 0; rowIndex < structOpers.getRowCount(); rowIndex++) { - org.biojava.nbio.structure.io.mmcif.model.PdbxStructOperList pdbxStructOperList = - new org.biojava.nbio.structure.io.mmcif.model.PdbxStructOperList(); - - pdbxStructOperList.setId(structOpers.getId().get(rowIndex)); - pdbxStructOperList.setName(structOpers.getName().get(rowIndex)); - pdbxStructOperList.setSymmetry_operation(structOpers.getSymmetryOperation().get(rowIndex)); - pdbxStructOperList.setType(structOpers.getType().get(rowIndex)); - - pdbxStructOperList.setMatrix11(String.valueOf(structOpers.getMatrix11().get(rowIndex))); - pdbxStructOperList.setMatrix12(String.valueOf(structOpers.getMatrix12().get(rowIndex))); - pdbxStructOperList.setMatrix13(String.valueOf(structOpers.getMatrix13().get(rowIndex))); - pdbxStructOperList.setMatrix21(String.valueOf(structOpers.getMatrix21().get(rowIndex))); - pdbxStructOperList.setMatrix22(String.valueOf(structOpers.getMatrix22().get(rowIndex))); - pdbxStructOperList.setMatrix23(String.valueOf(structOpers.getMatrix23().get(rowIndex))); - pdbxStructOperList.setMatrix31(String.valueOf(structOpers.getMatrix31().get(rowIndex))); - pdbxStructOperList.setMatrix32(String.valueOf(structOpers.getMatrix32().get(rowIndex))); - pdbxStructOperList.setMatrix33(String.valueOf(structOpers.getMatrix33().get(rowIndex))); - - pdbxStructOperList.setVector1(String.valueOf(structOpers.getVector1().get(rowIndex))); - pdbxStructOperList.setVector2(String.valueOf(structOpers.getVector2().get(rowIndex))); - pdbxStructOperList.setVector3(String.valueOf(structOpers.getVector3().get(rowIndex))); - - re.add(pdbxStructOperList); - } - return re; - } - - private List convert(PdbxStructAssemblyGen structAssemblyGen) { - List re = new ArrayList<>(); - for (int rowIndex = 0; rowIndex < structAssemblyGen.getRowCount(); rowIndex++) { - org.biojava.nbio.structure.io.mmcif.model.PdbxStructAssemblyGen pdbxStructAssemblyGen = - new org.biojava.nbio.structure.io.mmcif.model.PdbxStructAssemblyGen(); - - pdbxStructAssemblyGen.setAssembly_id(structAssemblyGen.getAssemblyId().get(rowIndex)); - pdbxStructAssemblyGen.setAsym_id_list(structAssemblyGen.getAsymIdList().get(rowIndex)); - pdbxStructAssemblyGen.setOper_expression(structAssemblyGen.getOperExpression().get(rowIndex)); - - re.add(pdbxStructAssemblyGen); - } - return re; - } - - private List convert(PdbxStructAssembly structAssembly) { - List re = new ArrayList<>(); - for (int rowIndex = 0; rowIndex < structAssembly.getRowCount(); rowIndex++) { - org.biojava.nbio.structure.io.mmcif.model.PdbxStructAssembly pdbxStructAssembly = - new org.biojava.nbio.structure.io.mmcif.model.PdbxStructAssembly(); - - pdbxStructAssembly.setDetails(structAssembly.getDetails().get(rowIndex)); - pdbxStructAssembly.setId(structAssembly.getId().get(rowIndex)); - pdbxStructAssembly.setMethod_details(structAssembly.getMethodDetails().get(rowIndex)); - pdbxStructAssembly.setOligomeric_count(structAssembly.getOligomericCount().getStringData(rowIndex)); - pdbxStructAssembly.setOligomeric_details(structAssembly.getOligomericDetails().get(rowIndex)); - - re.add(pdbxStructAssembly); - } - return re; - } - private void setCrystallographicInfoMetadata() { if (parsedScaleMatrix != null) { PDBCrystallographicInfo crystalInfo = structure.getCrystallographicInfo(); @@ -1610,32 +1533,7 @@ private static Chain removeSeqResHeterogeneity(Chain c) { private void addBonds() { BondMaker maker = new BondMaker(structure, params); maker.makeBonds(); - maker.formBondsFromStructConn(convert(structConn)); - } - - private List convert(StructConn structConn) { - return IntStream.range(0, structConn.getRowCount()) - .mapToObj(rowIndex -> { - org.biojava.nbio.structure.io.mmcif.model.StructConn sc = - new org.biojava.nbio.structure.io.mmcif.model.StructConn(); - - sc.setPdbx_ptnr1_PDB_ins_code(structConn.getPdbxPtnr1PDBInsCode().get(rowIndex)); - sc.setPdbx_ptnr2_PDB_ins_code(structConn.getPdbxPtnr2PDBInsCode().get(rowIndex)); - sc.setPtnr1_auth_seq_id(structConn.getPtnr1AuthSeqId().getStringData(rowIndex)); - sc.setPtnr2_auth_seq_id(structConn.getPtnr2AuthSeqId().getStringData(rowIndex)); - sc.setPtnr1_label_comp_id(structConn.getPtnr1LabelCompId().get(rowIndex)); - sc.setPtnr2_label_comp_id(structConn.getPtnr2LabelCompId().get(rowIndex)); - sc.setPtnr1_label_atom_id(structConn.getPtnr1LabelAtomId().get(rowIndex)); - sc.setPtnr2_label_atom_id(structConn.getPtnr2LabelAtomId().get(rowIndex)); - sc.setPdbx_ptnr1_label_alt_id(structConn.getPdbxPtnr1LabelAltId().get(rowIndex)); - sc.setPdbx_ptnr2_label_alt_id(structConn.getPdbxPtnr2LabelAltId().get(rowIndex)); - sc.setPtnr1_symmetry(structConn.getPtnr1Symmetry().get(rowIndex)); - sc.setPtnr2_symmetry(structConn.getPtnr2Symmetry().get(rowIndex)); - sc.setConn_type_id(structConn.getConnTypeId().get(rowIndex)); - - return sc; - }) - .collect(Collectors.toList()); + maker.formBondsFromStructConn(structConn); } private void alignSeqRes() { diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/StructureSupplierImpl.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/StructureSupplierImpl.java new file mode 100644 index 0000000000..ef377ad52a --- /dev/null +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/StructureSupplierImpl.java @@ -0,0 +1,28 @@ +package org.biojava.nbio.structure.io.cif; + +import org.biojava.nbio.structure.Chain; +import org.biojava.nbio.structure.Structure; +import org.rcsb.cif.model.CifFile; + +import java.util.ArrayList; +import java.util.List; + +public class StructureSupplierImpl extends AbstractCifFileSupplier { + @Override + public CifFile get(Structure container) { + return getInternal(container, collectWrappedAtoms(container)); + } + + private List collectWrappedAtoms(Structure structure) { + List wrappedAtoms = new ArrayList<>(); + + for (int modelIndex = 0; modelIndex < structure.nrModels(); modelIndex++) { + final int model = modelIndex + 1; + for (Chain chain : structure.getChains(modelIndex)) { + handleChain(chain, model, wrappedAtoms); + } + } + + return wrappedAtoms; + } +} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/AllChemCompProvider.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/AllChemCompProvider.java deleted file mode 100644 index b2b3222d58..0000000000 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/AllChemCompProvider.java +++ /dev/null @@ -1,246 +0,0 @@ -/* - - * BioJava development code - * - * This code may be freely distributed and modified under the - * terms of the GNU Lesser General Public Licence. This should - * be distributed with the code. If you do not have a copy, - * see: - * - * http://www.gnu.org/copyleft/lesser.html - * - * Copyright for this code is held jointly by the individual - * authors. These should be listed in @author doc comments. - * - * For more information on the BioJava project and its aims, - * or to join the biojava-l mailing list, visit the home page - * at: - * - * http://www.biojava.org/ - * - */ -package org.biojava.nbio.structure.io.mmcif; - -import org.biojava.nbio.structure.align.util.UserConfiguration; -import org.biojava.nbio.structure.io.LocalPDBDirectory; -import org.biojava.nbio.structure.io.mmcif.model.ChemComp; -import org.biojava.nbio.core.util.InputStreamProvider; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.*; -import java.net.URL; -import java.util.concurrent.atomic.AtomicBoolean; - -/** - * A ChemComp provider that downloads and caches the components.cif file from the wwPDB site. It then loads - * all chemical components at startup and keeps them in memory. This provider is not used as a default - * since it is slower at startup and requires more memory than the {@link DownloadChemCompProvider} that is used by default. - * - * @author Andreas Prlic - * - */ -public class AllChemCompProvider implements ChemCompProvider, Runnable{ - - private static final Logger logger = LoggerFactory.getLogger(AllChemCompProvider.class); - - public static final String COMPONENTS_FILE_LOCATION = "pub/pdb/data/monomers/components.cif.gz"; - - - private static String path; - - private static String serverName; - - - // there will be only one copy of the dictionary across all instances - // to reduce memory impact - static ChemicalComponentDictionary dict; - - // flags to make sure there is only one thread running that is loading the dictionary - static AtomicBoolean loading = new AtomicBoolean(false); - static AtomicBoolean isInitialized = new AtomicBoolean(false); - - public AllChemCompProvider(){ - - if ( loading.get()) { - logger.warn("other thread is already loading all chemcomps, no need to init twice"); - return; - } - if ( isInitialized.get()) - return; - - loading.set(true); - - Thread t = new Thread(this); - t.start(); - - } - - - /** make sure all paths are initialized correctly - * - */ - private static void initPath(){ - - if (path==null) { - UserConfiguration config = new UserConfiguration(); - path = config.getCacheFilePath(); - } - } - - private static void initServerName() { - - if (serverName==null) { - serverName = LocalPDBDirectory.getServerName(); - } - } - - private void ensureFileExists() { - - - String fileName = getLocalFileName(); - File f = new File(fileName); - - if ( ! f.exists()) { - try { - downloadFile(); - } catch (IOException e) { - logger.error("Caught IOException",e); - } - } - - - - } - - /** Downloads the components.cif.gz file from the wwPDB site. - * - */ - public static void downloadFile() throws IOException { - - initPath(); - - initServerName(); - - String localName = getLocalFileName(); - - String u = serverName + "/" + COMPONENTS_FILE_LOCATION; - - downloadFileFromRemote(new URL(u), new File(localName)); - - - } - - - private static void downloadFileFromRemote(URL remoteURL, File localFile) throws FileNotFoundException, IOException{ - logger.info("Downloading " + remoteURL + " to: " + localFile); - FileOutputStream out = new FileOutputStream(localFile); - - InputStream in = remoteURL.openStream(); - byte[] buf = new byte[4 * 1024]; // 4K buffer - int bytesRead; - while ((bytesRead = in.read(buf)) != -1) { - out.write(buf, 0, bytesRead); - } - in.close(); - out.close(); - - - } - - - private static String getLocalFileName(){ - - File dir = new File(path, DownloadChemCompProvider.CHEM_COMP_CACHE_DIRECTORY); - - if (! dir.exists()){ - logger.info("Creating directory {}", dir.toString()); - dir.mkdir(); - } - - String fileName = new File(dir, "components.cif.gz").toString(); - - return fileName; - } - - /** Load all {@link ChemComp} definitions into memory. - * - */ - private void loadAllChemComps() throws IOException { - String fileName = getLocalFileName(); - logger.debug("Loading " + fileName); - InputStreamProvider isp = new InputStreamProvider(); - - - InputStream inStream = isp.getInputStream(fileName); - - MMcifParser parser = new SimpleMMcifParser(); - - ChemCompConsumer consumer = new ChemCompConsumer(); - - // The Consumer builds up the BioJava - structure object. - // you could also hook in your own and build up you own data model. - parser.addMMcifConsumer(consumer); - - parser.parse(new BufferedReader(new InputStreamReader(inStream))); - - dict = consumer.getDictionary(); - - inStream.close(); - - } - - - /** {@inheritDoc} - * - */ - @Override - public ChemComp getChemComp(String recordName) { - - while ( loading.get()) { - - // another thread is still initializing the definitions - try { - // wait half a second - - Thread.sleep(500); - } catch (InterruptedException e) { - logger.error("Interrepted thread while waiting: "+e.getMessage()); - //e.printStackTrace(); - } - } - - - - return dict.getChemComp(recordName); - } - - - /** Do the actual loading of the dictionary in a thread. - * - */ - @Override - public void run() { - long timeS = System.currentTimeMillis(); - - initPath(); - - ensureFileExists(); - - try { - loadAllChemComps(); - - long timeE = System.currentTimeMillis(); - logger.debug("Time to init chem comp dictionary: " + (timeE - timeS) / 1000 + " sec."); - - - } catch (IOException e) { - logger.error("Could not load chemical components definition file {}. Error: {}", getLocalFileName(), e.getMessage()); - - } finally { - loading.set(false); - isInitialized.set(true); - } - } - -} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/ChemCompConsumer.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/ChemCompConsumer.java deleted file mode 100644 index f2d043a5b9..0000000000 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/ChemCompConsumer.java +++ /dev/null @@ -1,327 +0,0 @@ -/* - * BioJava development code - * - * This code may be freely distributed and modified under the - * terms of the GNU Lesser General Public Licence. This should - * be distributed with the code. If you do not have a copy, - * see: - * - * http://www.gnu.org/copyleft/lesser.html - * - * Copyright for this code is held jointly by the individual - * authors. These should be listed in @author doc comments. - * - * For more information on the BioJava project and its aims, - * or to join the biojava-l mailing list, visit the home page - * at: - * - * http://www.biojava.org/ - * - */ -package org.biojava.nbio.structure.io.mmcif; - -import org.biojava.nbio.structure.io.FileParsingParameters; -import org.biojava.nbio.structure.io.mmcif.chem.ResidueType; -import org.biojava.nbio.structure.io.mmcif.model.*; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.List; - -public class ChemCompConsumer implements MMcifConsumer { - - private static final Logger logger = LoggerFactory.getLogger(ChemCompConsumer.class); - - ChemicalComponentDictionary dictionary; - - String latestChemCompId; - public ChemCompConsumer(){ - dictionary = new ChemicalComponentDictionary(); - } - - @Override - public void documentStart() { - - - } - - public ChemicalComponentDictionary getDictionary(){ - return dictionary; - } - - @Override - public void newChemComp(ChemComp c) { - - if ( c.getId() == null) - logger.warn("chem comp ID == null " + c); - - latestChemCompId = c.getId(); - dictionary.addChemComp(c); - if ( c.getResidueType() == ResidueType.nonPolymer) - return; - - if ( c.getResidueType() == ResidueType.saccharide) - return; - - if ( c.getResidueType() == ResidueType.dSaccharide) - return; - - //if ( c.isStandard()) - // System.out.println(c); - } - - @Override - public void documentEnd() { - - - } - - @Override - public void newAtomSite(AtomSite atom) { - - - } - - @Override - public void newDatabasePDBremark(DatabasePDBremark remark) { - - - } - - @Override - public void newDatabasePDBrev(DatabasePDBrev dbrev) { - - - } - - @Override - public void newDatabasePDBrevRecord(DatabasePdbrevRecord dbrev) { - - } - - @Override - public void newEntity(Entity entity) { - - - } - - @Override - public void newEntityPolySeq(EntityPolySeq epolseq) { - - - } - - @Override - public void newExptl(Exptl exptl) { - - - } - - @Override - public void newCell(Cell cell) { - - } - - @Override - public void newSymmetry(Symmetry symmetry) { - - } - - @Override - public void newStructNcsOper(StructNcsOper sNcsOper) { - - } - - @Override - public void newAtomSites(AtomSites atomSites) { - - } - - @Override - public void newPdbxEntityNonPoly(PdbxEntityNonPoly pen) { - - - } - - @Override - public void newPdbxNonPolyScheme(PdbxNonPolyScheme ppss) { - - - } - - @Override - public void newPdbxPolySeqScheme(PdbxPolySeqScheme ppss) { - - - } - - @Override - public void newRefine(Refine r) { - - - } - - @Override - public void newStructAsym(StructAsym sasym) { - - - } - - @Override - public void newStructKeywords(StructKeywords kw) { - - - } - - @Override - public void newStructRef(StructRef sref) { - - - } - - @Override - public void newStructRefSeq(StructRefSeq sref) { - - - } - - @Override - public void newStructRefSeqDif(StructRefSeqDif sref) { - - - } - - @Override - public void setStruct(Struct struct) { - - - } - - @Override - public void newGenericData(String category, List loopFields, - List lineData) { - //System.out.println("unhandled category: " + category); - - } - - - @Override - public void newAuditAuthor(AuditAuthor aa) - { - - - } - - @Override - public FileParsingParameters getFileParsingParameters() - { - // can be ingored in this case... - return null; - } - - @Override - public void setFileParsingParameters(FileParsingParameters params) - { - - - } - - @Override - public void newChemCompDescriptor(ChemCompDescriptor ccd) { - ChemComp cc = dictionary.getChemComp(latestChemCompId); - cc.getDescriptors().add(ccd); - - } - - @Override - public void newPdbxStructOperList(PdbxStructOperList structOper) { - - - } - - @Override - public void newPdbxStrucAssembly(PdbxStructAssembly strucAssembly) { - - - } - - @Override - public void newPdbxStrucAssemblyGen(PdbxStructAssemblyGen strucAssembly) { - - - } - - @Override - public void newChemCompAtom(ChemCompAtom atom) { - dictionary.getChemComp(latestChemCompId).getAtoms().add(atom); - } - - @Override - public void newPdbxChemCompIndentifier(PdbxChemCompIdentifier id) { - - - } - - @Override - public void newChemCompBond(ChemCompBond bond) { - dictionary.getChemComp(latestChemCompId).getBonds().add(bond); - } - - @Override - public void newPdbxChemCompDescriptor(PdbxChemCompDescriptor desc) { - - - } - - @Override - public void newEntitySrcGen(EntitySrcGen entitySrcGen) { - - - } - @Override - public void newEntitySrcNat(EntitySrcNat entitySrcNat) { - - - } - - @Override - public void newEntitySrcSyn(EntitySrcSyn entitySrcSyn) { - - - } - - @Override - public void newStructConn(StructConn structConn) { - - - } - - @Override - public void newStructSiteGen(StructSiteGen gen) { - - } - - @Override - public void newStructSite(StructSite site) { - - } - - @Override - public void newEntityPoly(EntityPoly entityPoly) { - - - } - - @Override - public void newPdbxAuditRevisionHistory(PdbxAuditRevisionHistory history) { - // TODO Auto-generated method stub - - } - - @Override - public void newPdbxDatabaseStatus(PdbxDatabaseStatus status) { - // TODO Auto-generated method stub - - } -} - diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/ChemCompGroupFactory.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/ChemCompGroupFactory.java deleted file mode 100644 index 87f6408e86..0000000000 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/ChemCompGroupFactory.java +++ /dev/null @@ -1,168 +0,0 @@ -/* - * BioJava development code - * - * This code may be freely distributed and modified under the - * terms of the GNU Lesser General Public Licence. This should - * be distributed with the code. If you do not have a copy, - * see: - * - * http://www.gnu.org/copyleft/lesser.html - * - * Copyright for this code is held jointly by the individual - * authors. These should be listed in @author doc comments. - * - * For more information on the BioJava project and its aims, - * or to join the biojava-l mailing list, visit the home page - * at: - * - * http://www.biojava.org/ - * - * Created on May 23, 2010 - * - */ -package org.biojava.nbio.structure.io.mmcif; - -import org.biojava.nbio.core.util.SoftHashMap; -import org.biojava.nbio.structure.AminoAcid; -import org.biojava.nbio.structure.AminoAcidImpl; -import org.biojava.nbio.structure.Group; -import org.biojava.nbio.structure.HetatomImpl; -import org.biojava.nbio.structure.NucleotideImpl; -import org.biojava.nbio.structure.io.mmcif.chem.PolymerType; -import org.biojava.nbio.structure.io.mmcif.model.ChemComp; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - - -public class ChemCompGroupFactory { - - private static final Logger logger = LoggerFactory.getLogger(ChemCompGroupFactory.class); - - private static ChemCompProvider chemCompProvider = new DownloadChemCompProvider(); - - private static SoftHashMap cache = new SoftHashMap(0); - - public static ChemComp getChemComp(String recordName){ - - recordName = recordName.toUpperCase().trim(); - - // we are using the cache, to avoid hitting the file system too often. - ChemComp cc = cache.get(recordName); - if ( cc != null) { - logger.debug("Chem comp "+cc.getThree_letter_code()+" read from cache"); - return cc; - } - - // not cached, get the chem comp from the provider - logger.debug("Chem comp "+recordName+" read from provider "+chemCompProvider.getClass().getCanonicalName()); - cc = chemCompProvider.getChemComp(recordName); - - // Note that this also caches null or empty responses - cache.put(recordName, cc); - return cc; - } - - /** - * The new ChemCompProvider will be set in the static variable, - * so this provider will be used from now on until it is changed - * again. Note that this change can have unexpected behavior of - * code executed afterwards. - *

- * Changing the provider also resets the cache, so any groups - * previously accessed will be reread or re-downloaded. - * - * @param provider - */ - public static void setChemCompProvider(ChemCompProvider provider) { - logger.debug("Setting new chem comp provider to "+provider.getClass().getCanonicalName()); - chemCompProvider = provider; - // clear cache - cache.clear(); - } - - public static ChemCompProvider getChemCompProvider(){ - return chemCompProvider; - } - - /** - * Force the in-memory cache to be reset. - * - * Note that the ChemCompProvider may have additional memory or disk caches that need to be cleared too. - */ - public static void clearCache() { - cache.clear(); - } - - public static Group getGroupFromChemCompDictionary(String recordName) { - - // make sure we work with upper case records - recordName = recordName.toUpperCase().trim(); - - Group g = null; - - - ChemComp cc = getChemComp(recordName); - - if ( cc == null) - return null; - - if ( PolymerType.PROTEIN_ONLY.contains( cc.getPolymerType() ) ){ - AminoAcid aa = new AminoAcidImpl(); - - String one_letter = cc.getOne_letter_code(); - if ( one_letter == null || one_letter.equals("X") || one_letter.equals("?") || one_letter.length()==0){ - String parent = cc.getMon_nstd_parent_comp_id(); - if ( parent != null && parent.length() == 3){ - String parentid = cc.getMon_nstd_parent_comp_id() ; - ChemComp parentCC = getChemComp(parentid); - one_letter = parentCC.getOne_letter_code(); - } - } - - if ( one_letter == null || one_letter.length()==0 || one_letter.equals("?")) { - // e.g. problem with PRR, which probably should have a parent of ALA, but as of 20110127 does not. - logger.warn("Problem with chemical component: " + recordName + " Did not find one letter code! Setting it to 'X'"); - aa.setAminoType('X'); - - } else { - aa.setAminoType(one_letter.charAt(0)); - } - - - g = aa; - } else if ( PolymerType.POLYNUCLEOTIDE_ONLY.contains(cc.getPolymerType())) { - NucleotideImpl nuc = new NucleotideImpl(); - - g = nuc; - - - } else { - - g = new HetatomImpl(); - } - - g.setChemComp(cc); - - - return g; - } - - - public static String getOneLetterCode(ChemComp cc){ - String oneLetter = cc.getOne_letter_code(); - if ( oneLetter == null || oneLetter.equals("X") || oneLetter.equals("?")) { - String parentId = cc.getMon_nstd_parent_comp_id() ; - if ( parentId == null) - return oneLetter; - // cases like OIM have multiple parents (comma separated), we shouldn't try grab a chemcomp for those strings - if (parentId.length()>3) - return oneLetter; - ChemComp parentCC = ChemCompGroupFactory.getChemComp(parentId); - if ( parentCC == null) - return oneLetter; - oneLetter = parentCC.getOne_letter_code(); - } - return oneLetter; - } - -} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/ChemCompProvider.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/ChemCompProvider.java deleted file mode 100644 index a31affeaae..0000000000 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/ChemCompProvider.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * BioJava development code - * - * This code may be freely distributed and modified under the - * terms of the GNU Lesser General Public Licence. This should - * be distributed with the code. If you do not have a copy, - * see: - * - * http://www.gnu.org/copyleft/lesser.html - * - * Copyright for this code is held jointly by the individual - * authors. These should be listed in @author doc comments. - * - * For more information on the BioJava project and its aims, - * or to join the biojava-l mailing list, visit the home page - * at: - * - * http://www.biojava.org/ - * - */ -package org.biojava.nbio.structure.io.mmcif; - -import org.biojava.nbio.structure.io.mmcif.model.ChemComp; - -/** Interface that is implemented by all classes that can provide {@link ChemComp} definitions. - * - * @author Andreas Prlic - * @since 3.0 - */ -public interface ChemCompProvider { - - /** Returns a new instance of a chemical component definition. - * - * @param recordName the ID of the {@link ChemComp} - * @return a new {@link ChemComp} definition. - */ - ChemComp getChemComp(String recordName) ; - -} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/ChemicalComponentDictionary.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/ChemicalComponentDictionary.java deleted file mode 100644 index 19c97f9aed..0000000000 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/ChemicalComponentDictionary.java +++ /dev/null @@ -1,143 +0,0 @@ -/* - * BioJava development code - * - * This code may be freely distributed and modified under the - * terms of the GNU Lesser General Public Licence. This should - * be distributed with the code. If you do not have a copy, - * see: - * - * http://www.gnu.org/copyleft/lesser.html - * - * Copyright for this code is held jointly by the individual - * authors. These should be listed in @author doc comments. - * - * For more information on the BioJava project and its aims, - * or to join the biojava-l mailing list, visit the home page - * at: - * - * http://www.biojava.org/ - * - * - */ - -package org.biojava.nbio.structure.io.mmcif; - -import org.biojava.nbio.structure.io.mmcif.model.ChemComp; - -import java.util.HashMap; -import java.util.Map; - -/** A representation of the Chemical Component Dictionary. - * - * @author Andreas Prlic - * @since 1.7 - * @see link into mmCIF dictionary - * - */ -public class ChemicalComponentDictionary { - - private Map dictionary; - private Map replaces; - private Map isreplacedby; - - public ChemicalComponentDictionary(){ - dictionary = new HashMap(); - replaces = new HashMap(); - isreplacedby = new HashMap(); - } - - public boolean isReplaced(ChemComp c){ - return isReplaced(c.getId()); - - } - public boolean isReplaced(String id){ - if ( isreplacedby.containsKey(id)) - return true; - return false; - } - public boolean isReplacer(ChemComp c){ - return isReplacer(c.getId()); - } - public boolean isReplacer(String id){ - if ( replaces.containsKey(id) ) - return true; - return false; - } - - /** if ChemComp is replaced by another one, get the newer version - * otherwise return the same ChemComp again. - * @param c - * @return get the component that replaced ChemComp. - */ - public ChemComp getReplacer(ChemComp c){ - return getReplacer(c.getId()); - } - public ChemComp getReplacer(String id){ - if (isReplaced(id)){ - return dictionary.get(isreplacedby.get(id)); - } - return dictionary.get(id); - } - - /** if ChemComp is replacing another one, get the old version - * otherwise return the same ChemComp again. - * @param c the ChemComp for which older versions should be looked up. - */ - - public ChemComp getReplaced(ChemComp c){ - return getReplaced(c.getId()); - } - public ChemComp getReplaced(String id){ - if (isReplacer(id)){ - return dictionary.get(replaces.get(id)); - } - return dictionary.get(id); - } - - /** Get the parent of a component. If component has no parent, return null - * - * @param c - * @return get the parent component or null if ChemComp has no parent. - */ - public ChemComp getParent(ChemComp c){ - - if (c.hasParent()){ - return dictionary.get(c.getMon_nstd_parent_comp_id()); - } - return null; - } - - - - /** add a new component to the dictionary - * - * @param comp - */ - public void addChemComp(ChemComp comp){ - - dictionary.put(comp.getId(),comp); - String rep = comp.getPdbx_replaces(); - if ( (rep != null) && ( ! rep.equals("?"))){ - replaces.put(comp.getId(),rep); - } - - String isrep = comp.getPdbx_replaced_by(); - if ( (isrep != null) && ( ! isrep.equals("?"))){ - isreplacedby.put(comp.getId(),isrep); - } - } - - /** Returns the number of ChemComps in this dictionary - * - * @return nr. of ChemComps - */ - public int size(){ - - return dictionary.size(); - - } - - public ChemComp getChemComp(String id){ - return dictionary.get(id); - } -} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/DownloadChemCompProvider.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/DownloadChemCompProvider.java deleted file mode 100644 index 86355e40b6..0000000000 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/DownloadChemCompProvider.java +++ /dev/null @@ -1,507 +0,0 @@ -/* - * BioJava development code - * - * This code may be freely distributed and modified under the - * terms of the GNU Lesser General Public Licence. This should - * be distributed with the code. If you do not have a copy, - * see: - * - * http://www.gnu.org/copyleft/lesser.html - * - * Copyright for this code is held jointly by the individual - * authors. These should be listed in @author doc comments. - * - * For more information on the BioJava project and its aims, - * or to join the biojava-l mailing list, visit the home page - * at: - * - * http://www.biojava.org/ - * - */ -package org.biojava.nbio.structure.io.mmcif; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileOutputStream; -import java.io.FilenameFilter; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.PrintWriter; -import java.io.StringWriter; -import java.net.URL; -import java.net.URLConnection; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.nio.file.StandardCopyOption; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.zip.GZIPOutputStream; - -import org.biojava.nbio.core.util.InputStreamProvider; -import org.biojava.nbio.structure.align.util.URLConnectionTools; -import org.biojava.nbio.structure.align.util.UserConfiguration; -import org.biojava.nbio.structure.io.LocalPDBDirectory; -import org.biojava.nbio.structure.io.mmcif.model.ChemComp; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - - - -/** - * This provider of chemical components can download and cache chemical component definition files from the RCSB PDB web site. - * It is the default way to access these definitions. - * If this provider is called he first time, it will download and install all chemical - * component definitions in a local directory. - * Once the definition files have been installed, it has quick startup time and low memory requirements. - * - * An alternative provider, that keeps all definitions in memory is the {@link AllChemCompProvider}. Another provider, that - * does not require any network access, but only can support a limited set of chemical component definitions, is the {@link ReducedChemCompProvider}. - * - * - * @author Andreas Prlic - * - */ -public class DownloadChemCompProvider implements ChemCompProvider { - - private static final Logger logger = LoggerFactory.getLogger(DownloadChemCompProvider.class); - - public static final String CHEM_COMP_CACHE_DIRECTORY = "chemcomp"; - - public static final String DEFAULT_SERVER_URL = "http://files.rcsb.org/ligands/download/"; - - public static String serverBaseUrl = DEFAULT_SERVER_URL; - - /** - * Use default RCSB server layout (true) or internal RCSB server layout (false) - */ - public static boolean useDefaultUrlLayout = true; - - - private static File path; - //private static final String FILE_SEPARATOR = System.getProperty("file.separator"); - private static final String NEWLINE = System.getProperty("line.separator"); - - - // flags to make sure there is only one thread running that is loading the dictionary - static AtomicBoolean loading = new AtomicBoolean(false); - - static final List protectedIDs = new ArrayList (); - static { - protectedIDs.add("CON"); - protectedIDs.add("PRN"); - protectedIDs.add("AUX"); - protectedIDs.add("NUL"); - } - - private static ChemCompProvider fallback = null; // Fallback provider if the download fails - - /** by default we will download only some of the files. User has to request that all files should be downloaded... - * - */ - boolean downloadAll = false; - - public DownloadChemCompProvider(){ - this(null); - } - - public DownloadChemCompProvider(String cacheFilePath){ - logger.debug("Initialising DownloadChemCompProvider"); - - // note that path is static, so this is just to make sure that all non-static methods will have path initialised - if(cacheFilePath != null) { - path = new File(cacheFilePath); - } - } - - /** - * Get this provider's cache path - * @return - */ - public static File getPath(){ - if (path==null) { - UserConfiguration config = new UserConfiguration(); - path = new File(config.getCacheFilePath()); - } - return path; - } - - /** - * Checks if the chemical components already have been installed into the PDB directory. - * If not, will download the chemical components definitions file and split it up into small - * subfiles. - */ - public void checkDoFirstInstall(){ - - if ( ! downloadAll ) { - return; - } - - - // this makes sure there is a file separator between every component, - // if path has a trailing file separator or not, it will work for both cases - File dir = new File(getPath(), CHEM_COMP_CACHE_DIRECTORY); - File f = new File(dir, "components.cif.gz"); - - if ( ! f.exists()) { - - downloadAllDefinitions(); - - } else { - // file exists.. did it get extracted? - - FilenameFilter filter =new FilenameFilter() { - - @Override - public boolean accept(File dir, String file) { - return file.endsWith(".cif.gz"); - } - }; - String[] files = dir.list(filter); - if ( files.length < 500) { - // not all did get unpacked - try { - split(); - } catch (IOException e) { - logger.error("Could not split file {} into individual chemical component files. Error: {}", - f.toString(), e.getMessage()); - } - } - } - } - - private void split() throws IOException { - - logger.info("Installing individual chem comp files ..."); - - File dir = new File(getPath(), CHEM_COMP_CACHE_DIRECTORY); - File f = new File(dir, "components.cif.gz"); - - - int counter = 0; - InputStreamProvider prov = new InputStreamProvider(); - - try( BufferedReader buf = new BufferedReader (new InputStreamReader (prov.getInputStream(f))); - ) { - String line = null; - line = buf.readLine (); - StringWriter writer = new StringWriter(); - - String currentID = null; - while (line != null){ - - if ( line.startsWith("data_")) { - // a new record found! - - if ( currentID != null) { - writeID(writer.toString(), currentID); - counter++; - } - - currentID = line.substring(5); - writer = new StringWriter(); - } - - writer.append(line); - writer.append(NEWLINE); - - line = buf.readLine (); - } - - // write the last record... - writeID(writer.toString(),currentID); - counter++; - - } - - logger.info("Created " + counter + " chemical component files."); - } - - /** - * Output chemical contents to a file - * @param contents File contents - * @param currentID Chemical ID, used to determine the filename - * @throws IOException - */ - private void writeID(String contents, String currentID) throws IOException{ - - String localName = getLocalFileName(currentID); - - try ( PrintWriter pw = new PrintWriter(new GZIPOutputStream(new FileOutputStream(localName))) ) { - - pw.print(contents); - pw.flush(); - } - } - - /** - * Loads the definitions for this {@link ChemComp} from a local file and instantiates a new object. - * - * @param recordName the ID of the {@link ChemComp} - * @return a new {@link ChemComp} definition. - */ - @Override - public ChemComp getChemComp(String recordName) { - - // make sure we work with upper case records - recordName = recordName.toUpperCase().trim(); - - boolean haveFile = true; - if ( recordName.equals("?")){ - return null; - } - - if ( ! fileExists(recordName)) { - // check if we should install all components - checkDoFirstInstall(); - } - if ( ! fileExists(recordName)) { - // we previously have installed already the definitions, - // just do an incrememntal update - haveFile = downloadChemCompRecord(recordName); - } - - // Added check that download was successful and chemical component is available. - if (haveFile) { - String filename = getLocalFileName(recordName); - InputStream inStream = null; - try { - - InputStreamProvider isp = new InputStreamProvider(); - - inStream = isp.getInputStream(filename); - - MMcifParser parser = new SimpleMMcifParser(); - - ChemCompConsumer consumer = new ChemCompConsumer(); - - // The Consumer builds up the BioJava - structure object. - // you could also hook in your own and build up you own data model. - parser.addMMcifConsumer(consumer); - - parser.parse(new BufferedReader(new InputStreamReader(inStream))); - - ChemicalComponentDictionary dict = consumer.getDictionary(); - - ChemComp chemComp = dict.getChemComp(recordName); - - // May be null if the file was corrupt. Fall back on ReducedChemCompProvider in that case - if(chemComp != null) { - return chemComp; - } - - } catch (IOException e) { - - logger.warn( - "Could not download chemical component file {} for {}. Error: {}. Now trying to use the local chemical component definitions.", - filename, recordName, e.getMessage()); - - } - finally{ - // Now close it - if(inStream!=null){ - try { - inStream.close(); - } catch (IOException e) { - // This would be weird... - logger.error("Could not close chemical component file {}. A resource leak could occur!!", filename); - } - } - - } - } - - // see https://github.com/biojava/biojava/issues/315 - // probably a network error happened. Try to use the ReducedChemCOmpProvider - if( fallback == null) { - fallback = new ReducedChemCompProvider(); - } - - logger.warn("Falling back to ReducedChemCompProvider for {}. This could indicate a network error.", recordName); - return fallback.getChemComp(recordName); - - } - - /** - * Returns the file name that contains the definition for this {@link ChemComp} - * - * @param recordName the ID of the {@link ChemComp} - * @return full path to the file - */ - public static String getLocalFileName(String recordName){ - - if ( protectedIDs.contains(recordName)){ - recordName = "_" + recordName; - } - - File f = new File(getPath(), CHEM_COMP_CACHE_DIRECTORY); - if (! f.exists()){ - logger.info("Creating directory " + f); - - boolean success = f.mkdir(); - // we've checked in initPath that path is writable, so there's no need to check if it succeeds - // in the unlikely case that in the meantime it isn't writable at least we log an error - if (!success) - logger.error("Directory {} could not be created",f); - - } - - File theFile = new File(f,recordName + ".cif.gz"); - - return theFile.toString(); - } - - private static boolean fileExists(String recordName){ - - String fileName = getLocalFileName(recordName); - - File f = new File(fileName); - - // delete files that are too short to have contents - if( f.length() < LocalPDBDirectory.MIN_PDB_FILE_SIZE ) { - // Delete defensively. - // Note that if delete is unsuccessful, we re-download the file anyways - f.delete(); - return false; - } - - return f.exists(); - - } - - /** - * @param recordName : three-letter name - * @return true if successful download - */ - private static boolean downloadChemCompRecord(String recordName) { - - String localName = getLocalFileName(recordName); - File newFile; - try{ - newFile = File.createTempFile("chemcomp"+recordName, "cif"); - logger.debug("Will write chem comp file to temp file {}", newFile.toString()); - } - catch(IOException e){ - logger.error("Could not write to temp directory {} to create the chemical component download temp file", System.getProperty("java.io.tmpdir")); - return false; - } - String u; - if(useDefaultUrlLayout){ - u = serverBaseUrl + recordName + ".cif"; - } - else{ - u = serverBaseUrl + recordName.charAt(0) + "/" + recordName +"/" + recordName + ".cif"; - } - - logger.debug("downloading " + u); - - URL url = null; - - - try { - url = new URL(u); - URLConnection uconn = URLConnectionTools.openURLConnection(url); - - try( PrintWriter pw = new PrintWriter(new GZIPOutputStream(new FileOutputStream(newFile))); - BufferedReader fileBuffer = new BufferedReader(new InputStreamReader(uconn.getInputStream())); - ) { - - String line; - - while ((line = fileBuffer.readLine()) != null) { - pw.println(line); - } - - pw.flush(); - } - // Now we move this across to where it actually wants to be - Files.move(newFile.toPath(), Paths.get(localName), StandardCopyOption.REPLACE_EXISTING); - - return true; - } catch (IOException e){ - logger.error("Could not download "+url.toString()+" OR store locally to "+localName+" Error ="+e.getMessage()); - newFile.delete(); - } - return false; - } - - private void downloadAllDefinitions() { - - if ( loading.get()){ - logger.info("Waiting for other thread to install chemical components..."); - } - - while ( loading.get() ) { - - // another thread is already downloading the components definitions - // wait for the other thread to finish... - - try { - // wait half a second - - Thread.sleep(500); - } catch (InterruptedException e) { - //e.printStackTrace(); - logger.error("Thread interrupted "+e.getMessage()); - } - - logger.info("Another thread installed the chemical components."); - return; - - } - - loading.set(true); - long timeS = System.currentTimeMillis(); - - logger.info("Performing first installation of chemical components."); - logger.info("Downloading components.cif.gz ..."); - - - try { - AllChemCompProvider.downloadFile(); - } catch (IOException e){ - logger.error("Could not download the all chemical components file. Error: {}. " - + "Chemical components information won't be available", e.getMessage()); - // no point in trying to split if the file could not be downloaded - loading.set(false); - return; - } - try { - split(); - } catch (IOException e) { - logger.error("Could not split all chem comp file into individual chemical component files. Error: {}", - e.getMessage()); - // no point in reporting time - loading.set(false); - return; - } - long timeE = System.currentTimeMillis(); - logger.info("time to install chem comp dictionary: " + (timeE - timeS) / 1000 + " sec."); - loading.set(false); - - } - - /** By default this provider will download only some of the {@link ChemComp} files. - * The user has to request that all files should be downloaded by setting this parameter to true. - * - * @return flag if the all components should be downloaded and installed at startup. (default: false) - */ - public boolean isDownloadAll() { - return downloadAll; - } - - /** By default this provider will download only some of the {@link ChemComp} files. - * The user has to request that all files should be downloaded by setting this parameter to true. - * - * @param flag if the all components should be downloaded and installed at startup. (default: false) - */ - public void setDownloadAll(boolean downloadAll) { - this.downloadAll = downloadAll; - } - - - - - -} 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 deleted file mode 100644 index 14fdac7d3e..0000000000 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/MMCIFFileTools.java +++ /dev/null @@ -1,575 +0,0 @@ -/* - * BioJava development code - * - * This code may be freely distributed and modified under the - * terms of the GNU Lesser General Public Licence. This should - * be distributed with the code. If you do not have a copy, - * see: - * - * http://www.gnu.org/copyleft/lesser.html - * - * Copyright for this code is held jointly by the individual - * authors. These should be listed in @author doc comments. - * - * For more information on the BioJava project and its aims, - * or to join the biojava-l mailing list, visit the home page - * at: - * - * http://www.biojava.org/ - * - */ -package org.biojava.nbio.structure.io.mmcif; - - -import java.lang.reflect.Field; -import java.util.*; - -import org.biojava.nbio.structure.Atom; -import org.biojava.nbio.structure.Chain; -import org.biojava.nbio.structure.Element; -import org.biojava.nbio.structure.EntityType; -import org.biojava.nbio.structure.Group; -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; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Some tools for mmCIF file writing. - * - * See http://www.iucr.org/__data/assets/pdf_file/0019/22618/cifguide.pdf - * - * 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 { - - private static final Logger logger = LoggerFactory.getLogger(MMCIFFileTools.class); - - private static final String newline = System.getProperty("line.separator"); - - /** - * The character to be printed out in cases where a value is not assigned in mmCIF files - */ - public static final String MMCIF_MISSING_VALUE = "?"; - - /** - * The character to be printed out as a default value in mmCIF files, e.g. for the default alt_locs - */ - public static final String MMCIF_DEFAULT_VALUE = "."; - - - /** - * Produces a mmCIF loop header string for the given categoryName and className. - * className must be one of the beans in the {@link org.biojava.nbio.structure.io.mmcif.model} package - * @param categoryName - * @param className - * @return - * @throws ClassNotFoundException if the given className can not be found - */ - public static String toLoopMmCifHeaderString(String categoryName, String className) throws ClassNotFoundException { - StringBuilder str = new StringBuilder(); - - str.append(SimpleMMcifParser.LOOP_START+newline); - - Class c = Class.forName(className); - - for (Field f : getFields(c)) { - str.append(categoryName+"."+f.getName()+newline); - } - - return str.toString(); - } - - /** - * Converts a mmCIF bean (see {@link org.biojava.nbio.structure.io.mmcif.model} to - * a String representing it in mmCIF (single-record) format. - * @param categoryName - * @param o - * @return - */ - public static String toMMCIF(String categoryName, Object o) { - - StringBuilder sb = new StringBuilder(); - - Class c = o.getClass(); - - - Field[] fields = getFields(c); - String[] names = getFieldNames(fields); - - int maxFieldNameLength = getMaxStringLength(names); - - 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 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 (T o:list) { - sb.append(toSingleLoopLineMmCifString(o, fields, sizes)); - } - - sb.append(SimpleMMcifParser.COMMENT_CHAR+newline); - - return sb.toString(); - } - - /** - * Given a mmCIF bean produces a String representing it in mmCIF loop format as a single record line - * @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 record, Field[] fields, int[] sizes) { - - StringBuilder str = new StringBuilder(); - - Class c = record.getClass(); - - 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 : fields) { - i++; - f.setAccessible(true); - - try { - 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); - val = MMCIF_MISSING_VALUE; - } else { - val = (String) obj; - } - - str.append(String.format("%-"+sizes[i]+"s ", addMmCifQuoting(val))); - - - } catch (IllegalAccessException e) { - logger.warn("Field {} is inaccessible", f.getName()); - continue; - } catch (ClassCastException e) { - logger.warn("Could not cast value to String for field {}",f.getName()); - continue; - } - } - - str.append(newline); - - return str.toString(); - - } - - /** - * Adds quoting to a String according to the STAR format (mmCIF) rules - * @param val - * @return - */ - private static String addMmCifQuoting(String val) { - String newval; - - if (val.contains("'")) { - // double quoting for strings containing single quotes (not strictly necessary but it's what the PDB usually does) - newval = "\""+val+"\""; - } else if (val.contains(" ")) { - // single quoting for stings containing spaces - newval = "'"+val+"'"; - } else { - if (val.contains(" ") && val.contains("'")) { - // TODO deal with this case - logger.warn("Value contains both spaces and single quotes, won't format it: {}. CIF ouptut will likely be invalid.",val); - } - newval = val; - } - // TODO deal with all the other cases: e.g. multi-line quoting with ;; - - return newval; - } - - /** - * Converts a SpaceGroup object to a {@link Symmetry} object. - * @param sg - * @return - */ - public static Symmetry convertSpaceGroupToSymmetry(SpaceGroup sg) { - Symmetry sym = new Symmetry(); - sym.setSpace_group_name_H_M(sg.getShortSymbol()); - // TODO do we need to fill any of the other values? - return sym; - } - - /** - * Converts a CrystalCell object to a {@link Cell} object. - * @param c - * @return - */ - public static Cell convertCrystalCellToCell(CrystalCell c) { - Cell cell = new Cell(); - cell.setLength_a(String.format("%.3f",c.getA())); - cell.setLength_b(String.format("%.3f",c.getB())); - cell.setLength_c(String.format("%.3f",c.getC())); - cell.setAngle_alpha(String.format("%.3f",c.getAlpha())); - cell.setAngle_beta(String.format("%.3f",c.getBeta())); - cell.setAngle_gamma(String.format("%.3f",c.getGamma())); - - return cell; - } - - /** - * Converts an Atom object to an {@link AtomSite} object. - * @param a - * @param model the model number for the output AtomSites - * @param chainName the chain identifier (author id) for the output AtomSites - * @param chainId the internal chain identifier (asym id) for the output AtomSites - * @return - */ - public static AtomSite convertAtomToAtomSite(Atom a, int model, String chainName, String chainId) { - return convertAtomToAtomSite(a, model, chainName, chainId, a.getPDBserial()); - } - - /** - * Converts an Atom object to an {@link AtomSite} object. - * @param a the atom - * @param model the model number for the output AtomSites - * @param chainName the chain identifier (author id) for the output AtomSites - * @param chainId the internal chain identifier (asym id) for the output AtomSites - * @param atomId the atom id to be written to AtomSite - * @return - */ - public static AtomSite convertAtomToAtomSite(Atom a, int model, String chainName, String chainId, int atomId) { - - /* - ATOM 7 C CD . GLU A 1 24 ? -10.109 15.374 38.853 1.00 50.05 ? ? ? ? ? ? 24 GLU A CD 1 - ATOM 8 O OE1 . GLU A 1 24 ? -9.659 14.764 37.849 1.00 49.80 ? ? ? ? ? ? 24 GLU A OE1 1 - ATOM 9 O OE2 . GLU A 1 24 ? -11.259 15.171 39.310 1.00 50.51 ? ? ? ? ? ? 24 GLU A OE2 1 - ATOM 10 N N . LEU A 1 25 ? -5.907 18.743 37.412 1.00 41.55 ? ? ? ? ? ? 25 LEU A N 1 - ATOM 11 C CA . LEU A 1 25 ? -5.168 19.939 37.026 1.00 37.55 ? ? ? ? ? ? 25 LEU A CA 1 - */ - - Group g = a.getGroup(); - - String record ; - if ( g.getType().equals(GroupType.HETATM) ) { - record = "HETATM"; - } else { - record = "ATOM"; - } - - String entityId = "0"; - String labelSeqId = Integer.toString(g.getResidueNumber().getSeqNum()); - if (g.getChain()!=null && g.getChain().getEntityInfo()!=null) { - entityId = Integer.toString(g.getChain().getEntityInfo().getMolId()); - if (g.getChain().getEntityInfo().getType() == EntityType.POLYMER) { - // this only makes sense for polymeric chains, non-polymer chains will never have seqres groups and there's no point in calling getAlignedResIndex - labelSeqId = Integer.toString(g.getChain().getEntityInfo().getAlignedResIndex(g, g.getChain())); - } - } - - Character altLoc = a.getAltLoc(); - String altLocStr; - if (altLoc==null || altLoc == ' ') { - altLocStr = MMCIF_DEFAULT_VALUE; - } else { - altLocStr = altLoc.toString(); - } - - Element e = a.getElement(); - String eString = e.toString().toUpperCase(); - if ( e.equals(Element.R)) { - eString = "X"; - } - - String insCode = MMCIF_MISSING_VALUE; - if (g.getResidueNumber().getInsCode()!=null ) { - insCode = Character.toString(g.getResidueNumber().getInsCode()); - } - - AtomSite atomSite = new AtomSite(); - atomSite.setGroup_PDB(record); - atomSite.setId(Integer.toString(atomId)); - atomSite.setType_symbol(eString); - atomSite.setLabel_atom_id(a.getName()); - atomSite.setLabel_alt_id(altLocStr); - atomSite.setLabel_comp_id(g.getPDBName()); - atomSite.setLabel_asym_id(chainId); - atomSite.setLabel_entity_id(entityId); - atomSite.setLabel_seq_id(labelSeqId); - atomSite.setPdbx_PDB_ins_code(insCode); - atomSite.setCartn_x(FileConvert.d3.format(a.getX())); - atomSite.setCartn_y(FileConvert.d3.format(a.getY())); - atomSite.setCartn_z(FileConvert.d3.format(a.getZ())); - atomSite.setOccupancy(FileConvert.d2.format(a.getOccupancy())); - atomSite.setB_iso_or_equiv(FileConvert.d2.format(a.getTempFactor())); - atomSite.setAuth_seq_id(Integer.toString(g.getResidueNumber().getSeqNum())); - atomSite.setAuth_comp_id(g.getPDBName()); - atomSite.setAuth_asym_id(chainName); - atomSite.setAuth_atom_id(a.getName()); - atomSite.setPdbx_PDB_model_num(Integer.toString(model)); - - return atomSite; - } - - /** - * Converts a Group into a List of {@link AtomSite} objects. - * Atoms in other altloc groups (different from the main group) are also included, removing possible duplicates - * via using the atom identifier to assess uniqueness. - * @param g the group - * @param model the model number for the output AtomSites - * @param chainName the chain identifier (author id) for the output AtomSites - * @param chainId the internal chain identifier (asym id) for the output AtomSites - * @return - */ - public static List convertGroupToAtomSites(Group g, int model, String chainName, String chainId) { - - // The alt locs can have duplicates, since at parsing time we make sure that all alt loc groups have - // all atoms (see StructureTools#cleanUpAltLocs) - // Thus we have to remove duplicates here by using the atom id - // See issue https://github.com/biojava/biojava/issues/778 and TestAltLocs.testMmcifWritingAllAltlocs/testMmcifWritingPartialAltlocs - Map uniqueAtomSites = new LinkedHashMap<>(); - - int groupsize = g.size(); - - for ( int atompos = 0 ; atompos < groupsize; atompos++) { - Atom a = g.getAtom(atompos); - if ( a == null) - continue ; - - uniqueAtomSites.put(a.getPDBserial(), convertAtomToAtomSite(a, model, chainName, chainId)); - } - - if ( g.hasAltLoc()){ - for (Group alt : g.getAltLocs() ) { - for (AtomSite atomSite : convertGroupToAtomSites(alt, model, chainName, chainId)) { - uniqueAtomSites.put(Integer.parseInt(atomSite.getId()), atomSite); - } - } - } - return new ArrayList<>(uniqueAtomSites.values()); - } - - /** - * Converts a Chain into a List of {@link AtomSite} objects - * @param c the chain - * @param model the model number for the output AtomSites - * @param chainName the chain identifier (author id) for the output AtomSites - * @param chainId the internal chain identifier (asym id) for the output AtomSites - * @return - */ - public static List convertChainToAtomSites(Chain c, int model, String chainName, String chainId) { - - List list = new ArrayList<>(); - - if (c.getEntityInfo()==null) { - logger.warn("No entity found for chain {}: entity_id will be set to 0, label_seq_id will be the same as auth_seq_id", c.getName()); - } - - for ( int h=0; h convertStructureToAtomSites(Structure s) { - List list = new ArrayList(); - - for (int m=0;m int[] getFieldSizes(List list, Field[] fields) { - - if (list.isEmpty()) throw new IllegalArgumentException("List of beans is empty!"); - - if(fields == null) - fields = getFields(list.get(0).getClass()); - - int[] sizes = new int [fields.length]; - - - for (T a:list) { - int i = -1; - for (Field f : fields) { - i++; - - f.setAccessible(true); - - try { - Object obj = f.get(a); - int length; - if (obj==null) { - length = MMCIF_MISSING_VALUE.length(); - } else { - String val = (String) obj; - length = addMmCifQuoting(val).length(); - } - - if (length>sizes[i]) sizes[i] = length; - - } catch (IllegalAccessException e) { - logger.warn("Field {} is inaccessible", f.getName()); - continue; - } catch (ClassCastException e) { - logger.warn("Could not cast value to String for field {}",f.getName()); - continue; - } - } - } - return sizes; - } - - /** - * Finds the max length of a list of strings - * Useful for producing mmCIF single-record data that is aligned for all values. - * @param names - * @return - * @see #toMMCIF(String, Object) - */ - private static int getMaxStringLength(String[] names) { - int size = 0; - 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/MMcifConsumer.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/MMcifConsumer.java deleted file mode 100644 index 9284c2ad31..0000000000 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/MMcifConsumer.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * BioJava development code - * - * This code may be freely distributed and modified under the - * terms of the GNU Lesser General Public Licence. This should - * be distributed with the code. If you do not have a copy, - * see: - * - * http://www.gnu.org/copyleft/lesser.html - * - * Copyright for this code is held jointly by the individual - * authors. These should be listed in @author doc comments. - * - * For more information on the BioJava project and its aims, - * or to join the biojava-l mailing list, visit the home page - * at: - * - * http://www.biojava.org/ - * - * created at Mar 4, 2008 - */ -package org.biojava.nbio.structure.io.mmcif; - -import org.biojava.nbio.structure.io.FileParsingParameters; -import org.biojava.nbio.structure.io.mmcif.model.*; - -import java.util.List; - -/** An interface for the events triggered by a MMcifParser. - * The Consumer listens to the events and builds up the protein structure. - * - * @author Andreas Prlic - * @since 1.7 - * - */ -public interface MMcifConsumer { - /** called at start of document - * - */ - public void documentStart(); - - /** called at end of document - * - */ - public void documentEnd(); - - - /** A new AtomSite record has been read. Contains the Atom data - * - * @param atom - */ - public void newAtomSite(AtomSite atom); - public void newEntity(Entity entity); - public void newEntityPoly(EntityPoly entityPoly); - public void newEntityPolySeq(EntityPolySeq epolseq); - public void newStructAsym(StructAsym sasym); - public void setStruct(Struct struct); - public void newDatabasePDBrev(DatabasePDBrev dbrev); - public void newDatabasePDBrevRecord(DatabasePdbrevRecord dbrev); - public void newDatabasePDBremark(DatabasePDBremark remark); - public void newExptl(Exptl exptl); - public void newCell(Cell cell); - public void newSymmetry(Symmetry symmetry); - public void newStructNcsOper(StructNcsOper sNcsOper); - public void newAtomSites(AtomSites atomSites); - public void newStructRef(StructRef sref); - public void newStructRefSeq(StructRefSeq sref); - public void newStructRefSeqDif(StructRefSeqDif sref); - public void newStructSite(StructSite sref); - public void newStructSiteGen(StructSiteGen sref); - public void newPdbxAuditRevisionHistory(PdbxAuditRevisionHistory history); - public void newPdbxDatabaseStatus(PdbxDatabaseStatus status); - public void newPdbxPolySeqScheme(PdbxPolySeqScheme ppss); - public void newPdbxNonPolyScheme(PdbxNonPolyScheme ppss); - public void newPdbxEntityNonPoly(PdbxEntityNonPoly pen); - public void newStructKeywords(StructKeywords kw); - public void newRefine(Refine r); - public void newChemComp(ChemComp c); - public void newChemCompDescriptor(ChemCompDescriptor ccd); - public void newPdbxStructOperList(PdbxStructOperList structOper); - public void newPdbxStrucAssembly(PdbxStructAssembly strucAssembly); - public void newPdbxStrucAssemblyGen(PdbxStructAssemblyGen strucAssembly); - public void newChemCompAtom(ChemCompAtom atom); - public void newPdbxChemCompIndentifier(PdbxChemCompIdentifier id); - public void newChemCompBond(ChemCompBond bond); - public void newPdbxChemCompDescriptor(PdbxChemCompDescriptor desc); - public void newEntitySrcGen(EntitySrcGen entitySrcGen); - public void newEntitySrcNat(EntitySrcNat entitySrcNat); - public void newEntitySrcSyn(EntitySrcSyn entitySrcSyn); - public void newStructConn(StructConn structConn); - - /** AuditAuthor contains the info from the PDB-AUTHOR records. - * - * @param aa - */ - public void newAuditAuthor(AuditAuthor aa); - - /** This method is called if no particular handler for the provided cif category - * has been implemented so far. - * @param category The category that is being processed. - * @param loopFields the fields of this category. - * @param lineData the data that is being provided. - */ - public void newGenericData(String category, List loopFields, List lineData); - - public void setFileParsingParameters(FileParsingParameters params); - public FileParsingParameters getFileParsingParameters(); - - - - - - - - -} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/MMcifParser.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/MMcifParser.java deleted file mode 100644 index e20a35d87c..0000000000 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/MMcifParser.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * BioJava development code - * - * This code may be freely distributed and modified under the - * terms of the GNU Lesser General Public Licence. This should - * be distributed with the code. If you do not have a copy, - * see: - * - * http://www.gnu.org/copyleft/lesser.html - * - * Copyright for this code is held jointly by the individual - * authors. These should be listed in @author doc comments. - * - * For more information on the BioJava project and its aims, - * or to join the biojava-l mailing list, visit the home page - * at: - * - * http://www.biojava.org/ - * - * created at Mar 4, 2008 - */ -package org.biojava.nbio.structure.io.mmcif; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; - -/** Interface that needs to be implemented by an MMcifParser - * - * @author Andreas Prlic - * @since 1.7 - */ -public interface MMcifParser { - - /** Add a MMcifConsumer that listens to even being triggered by the parser and processes the data into a backend provided by the Consumer. - * - * @param consumer a consumer object. - */ - public void addMMcifConsumer(MMcifConsumer consumer); - - /** Remove all consumers from the parser. - * - */ - public void clearConsumers(); - - /** remove a single consumer from the parser - * - * @param consumer - */ - public void removeMMcifConsumer(MMcifConsumer consumer); - - - /** Start the actual parsing. The parser will trigger events that are defined by the MMcifConsumer class. - * - * @param buf a BufferedReader. - */ - public void parse(BufferedReader buf) throws IOException; - - /** Start the actual parsing. The parser will trigger events that are defined by the MMcifConsumer class. - * - * @param inStream InputStream to parse from. - */ - public void parse(InputStream inStream) throws IOException; - - -} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/MetalBondConsumer.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/MetalBondConsumer.java deleted file mode 100644 index dbb91bd71f..0000000000 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/MetalBondConsumer.java +++ /dev/null @@ -1,294 +0,0 @@ -/* - * BioJava development code - * - * This code may be freely distributed and modified under the - * terms of the GNU Lesser General Public Licence. This should - * be distributed with the code. If you do not have a copy, - * see: - * - * http://www.gnu.org/copyleft/lesser.html - * - * Copyright for this code is held jointly by the individual - * authors. These should be listed in @author doc comments. - * - * For more information on the BioJava project and its aims, - * or to join the biojava-l mailing list, visit the home page - * at: - * - * http://www.biojava.org/ - * - */ -package org.biojava.nbio.structure.io.mmcif; - -import org.biojava.nbio.structure.io.FileParsingParameters; -import org.biojava.nbio.structure.io.mmcif.chem.MetalBondDistance; -import org.biojava.nbio.structure.io.mmcif.model.*; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * Created by andreas on 6/9/16. - */ -public class MetalBondConsumer implements MMcifConsumer{ - - - Map> definitions = new HashMap<>(); - - @Override - public void documentStart() { - definitions.clear(); - } - - @Override - public void documentEnd() { - - // minimize memory consumption - - for (List d : definitions.values()){ - ArrayList a = (ArrayList)d; - - a.trimToSize(); - } - - } - - @Override - public void newAtomSite(AtomSite atom) { - - } - - @Override - public void newEntity(Entity entity) { - - } - - @Override - public void newEntityPoly(EntityPoly entityPoly) { - - } - - @Override - public void newEntityPolySeq(EntityPolySeq epolseq) { - - } - - @Override - public void newStructAsym(StructAsym sasym) { - - } - - @Override - public void setStruct(Struct struct) { - - } - - @Override - public void newDatabasePDBrev(DatabasePDBrev dbrev) { - - } - - @Override - public void newDatabasePDBrevRecord(DatabasePdbrevRecord dbrev) { - - } - - @Override - public void newDatabasePDBremark(DatabasePDBremark remark) { - - } - - @Override - public void newExptl(Exptl exptl) { - - } - - @Override - public void newCell(Cell cell) { - - } - - @Override - public void newSymmetry(Symmetry symmetry) { - - } - - @Override - public void newStructNcsOper(StructNcsOper sNcsOper) { - - } - - @Override - public void newAtomSites(AtomSites atomSites) { - - } - - @Override - public void newStructRef(StructRef sref) { - - } - - @Override - public void newStructRefSeq(StructRefSeq sref) { - - } - - @Override - public void newStructRefSeqDif(StructRefSeqDif sref) { - - } - - @Override - public void newStructSite(StructSite sref) { - - } - - @Override - public void newStructSiteGen(StructSiteGen sref) { - - } - - @Override - public void newPdbxPolySeqScheme(PdbxPolySeqScheme ppss) { - - } - - @Override - public void newPdbxNonPolyScheme(PdbxNonPolyScheme ppss) { - - } - - @Override - public void newPdbxEntityNonPoly(PdbxEntityNonPoly pen) { - - } - - @Override - public void newStructKeywords(StructKeywords kw) { - - } - - @Override - public void newRefine(Refine r) { - - } - - @Override - public void newChemComp(ChemComp c) { - - } - - @Override - public void newChemCompDescriptor(ChemCompDescriptor ccd) { - - } - - @Override - public void newPdbxStructOperList(PdbxStructOperList structOper) { - - } - - @Override - public void newPdbxStrucAssembly(PdbxStructAssembly strucAssembly) { - - } - - @Override - public void newPdbxStrucAssemblyGen(PdbxStructAssemblyGen strucAssembly) { - - } - - @Override - public void newChemCompAtom(ChemCompAtom atom) { - - } - - @Override - public void newPdbxChemCompIndentifier(PdbxChemCompIdentifier id) { - - } - - @Override - public void newChemCompBond(ChemCompBond bond) { - - } - - @Override - public void newPdbxChemCompDescriptor(PdbxChemCompDescriptor desc) { - - } - - @Override - public void newEntitySrcGen(EntitySrcGen entitySrcGen) { - - } - - @Override - public void newEntitySrcNat(EntitySrcNat entitySrcNat) { - - } - - @Override - public void newEntitySrcSyn(EntitySrcSyn entitySrcSyn) { - - } - - @Override - public void newStructConn(StructConn structConn) { - - } - - @Override - public void newAuditAuthor(AuditAuthor aa) { - - } - - @Override - public void newGenericData(String category, List loopFields, List lineData) { - - MetalBondDistance d = new MetalBondDistance(); - - d.setAtomType1(lineData.get(0)); - d.setAtomType2(lineData.get(1)); - d.setLowerLimit(Float.parseFloat(lineData.get(2))); - d.setUpperLimit(Float.parseFloat(lineData.get(3))); - - List defs = definitions.get(d.getAtomType1()); - - if ( defs == null){ - defs = new ArrayList<>(); - definitions.put(d.getAtomType1(),defs); - } - - defs.add(d); - - } - - @Override - public void setFileParsingParameters(FileParsingParameters params) { - - } - - @Override - public FileParsingParameters getFileParsingParameters() { - return null; - } - - public Map> getDefinitions(){ - return definitions; - } - - @Override - public void newPdbxAuditRevisionHistory(PdbxAuditRevisionHistory history) { - // TODO Auto-generated method stub - - } - - @Override - public void newPdbxDatabaseStatus(PdbxDatabaseStatus status) { - // TODO Auto-generated method stub - - } -} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/MetalBondParser.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/MetalBondParser.java deleted file mode 100644 index 03d6789c5c..0000000000 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/MetalBondParser.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * BioJava development code - * - * This code may be freely distributed and modified under the - * terms of the GNU Lesser General Public Licence. This should - * be distributed with the code. If you do not have a copy, - * see: - * - * http://www.gnu.org/copyleft/lesser.html - * - * Copyright for this code is held jointly by the individual - * authors. These should be listed in @author doc comments. - * - * For more information on the BioJava project and its aims, - * or to join the biojava-l mailing list, visit the home page - * at: - * - * http://www.biojava.org/ - * - */ -package org.biojava.nbio.structure.io.mmcif; - -import org.biojava.nbio.structure.io.mmcif.chem.MetalBondDistance; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.InputStream; -import java.util.*; - -import java.util.zip.GZIPInputStream; - -/** - * Created by andreas on 6/6/16. - */ -public class MetalBondParser { - - private static final Logger logger = LoggerFactory.getLogger(MetalBondParser.class); - - private static final String BONDS_FILE = "org/biojava/nbio/structure/bond_distance_limits.cif.gz"; - - - static Map> definitions; - - static { - definitions = init(); - } - - - public static Map> getMetalBondDefinitions(){ - return definitions; - - } - - - private static Map> init(){ - - InputStream inputStream = MetalBondParser.class.getClassLoader().getResourceAsStream(BONDS_FILE); - - if (inputStream == null) { - throw new RuntimeException("Could not find resource "+BONDS_FILE+". This probably means that your biojava.jar file is corrupt or incorrectly built."); - } - - try { - GZIPInputStream gzIS = new GZIPInputStream(inputStream); - - SimpleMMcifParser parser = new SimpleMMcifParser(); - - MetalBondConsumer consumer = new MetalBondConsumer(); - parser.addMMcifConsumer(consumer); - - parser.parse(gzIS); - - Map> defs = consumer.getDefinitions(); - - return defs; - - } catch ( Exception e){ - logger.error(e.getMessage(),e); - - } - return null; - } - - - -} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/ReducedChemCompProvider.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/ReducedChemCompProvider.java deleted file mode 100644 index 0d752cea04..0000000000 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/ReducedChemCompProvider.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * BioJava development code - * - * This code may be freely distributed and modified under the - * terms of the GNU Lesser General Public Licence. This should - * be distributed with the code. If you do not have a copy, - * see: - * - * http://www.gnu.org/copyleft/lesser.html - * - * Copyright for this code is held jointly by the individual - * authors. These should be listed in @author doc comments. - * - * For more information on the BioJava project and its aims, - * or to join the biojava-l mailing list, visit the home page - * at: - * - * http://www.biojava.org/ - * - */ -package org.biojava.nbio.structure.io.mmcif; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.util.zip.GZIPInputStream; - -import org.biojava.nbio.structure.io.mmcif.model.ChemComp; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - - -/** Unlike the {@link DownloadChemCompProvider}, this {@link ChemCompProvider} does not download any chem comp definitions. - * It has access to a limited set of files that are part of the biojava distribution. - * - * @author Andreas Prlic - * @since 3.0 - */ -public class ReducedChemCompProvider implements ChemCompProvider { - - private static final Logger logger = LoggerFactory.getLogger(ReducedChemCompProvider.class); - - public ReducedChemCompProvider(){ - logger.debug("Initialising ReducedChemCompProvider"); - } - - - @Override - public ChemComp getChemComp(String recordName) { - String name = recordName.toUpperCase().trim(); - try(InputStream inStream = this.getClass().getResourceAsStream("/chemcomp/"+name + ".cif.gz")) { - - logger.debug("Reading chemcomp/"+name+".cif.gz"); - - if ( inStream == null){ - //System.out.println("Could not find chem comp: " + name + " ... using generic Chem Comp"); - // could not find the chem comp definition for this in the jar file - logger.debug("Getting empty chem comp for {}",name); - ChemComp cc = ChemComp.getEmptyChemComp(); - cc.setId(name); - return cc; - } - - MMcifParser parser = new SimpleMMcifParser(); - - ChemCompConsumer consumer = new ChemCompConsumer(); - - // The Consumer builds up the BioJava - structure object. - // you could also hook in your own and build up you own data model. - parser.addMMcifConsumer(consumer); - - parser.parse(new BufferedReader(new InputStreamReader(new GZIPInputStream(inStream)))); - - ChemicalComponentDictionary dict = consumer.getDictionary(); - - ChemComp chemComp = dict.getChemComp(name); - - return chemComp; - - } catch (IOException e){ - logger.error("IOException caught while reading chem comp {}.",name,e); - } - logger.warn("Problem when loading chem comp {}, will use an empty chem comp for it", name); - ChemComp cc = ChemComp.getEmptyChemComp(); - cc.setId(name); - return cc; - } - - -} 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 deleted file mode 100644 index b0cdecdc14..0000000000 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/SimpleMMcifConsumer.java +++ /dev/null @@ -1,2167 +0,0 @@ -/* - * BioJava development code - * - * This code may be freely distributed and modified under the - * terms of the GNU Lesser General Public Licence. This should - * be distributed with the code. If you do not have a copy, - * see: - * - * http://www.gnu.org/copyleft/lesser.html - * - * Copyright for this code is held jointly by the individual - * authors. These should be listed in @author doc comments. - * - * For more information on the BioJava project and its aims, - * or to join the biojava-l mailing list, visit the home page - * at: - * - * http://www.biojava.org/ - * - * created at Apr 26, 2008 - */ -package org.biojava.nbio.structure.io.mmcif; - -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Locale; -import java.util.Map; - -import javax.vecmath.Matrix4d; - -import org.biojava.nbio.structure.AminoAcid; -import org.biojava.nbio.structure.AminoAcidImpl; -import org.biojava.nbio.structure.Atom; -import org.biojava.nbio.structure.AtomImpl; -import org.biojava.nbio.structure.Chain; -import org.biojava.nbio.structure.ChainImpl; -import org.biojava.nbio.structure.EntityInfo; -import org.biojava.nbio.structure.EntityType; -import org.biojava.nbio.structure.DBRef; -import org.biojava.nbio.structure.Element; -import org.biojava.nbio.structure.Group; -import org.biojava.nbio.structure.GroupType; -import org.biojava.nbio.structure.HetatomImpl; -import org.biojava.nbio.structure.NucleotideImpl; -import org.biojava.nbio.structure.PDBCrystallographicInfo; -import org.biojava.nbio.structure.PDBHeader; -import org.biojava.nbio.structure.ResidueNumber; -import org.biojava.nbio.structure.SeqMisMatch; -import org.biojava.nbio.structure.SeqMisMatchImpl; -import org.biojava.nbio.structure.Site; -import org.biojava.nbio.structure.Structure; -import org.biojava.nbio.structure.StructureException; -import org.biojava.nbio.structure.StructureImpl; -import org.biojava.nbio.structure.StructureTools; -import org.biojava.nbio.structure.io.BondMaker; -import org.biojava.nbio.structure.io.ChargeAdder; -import org.biojava.nbio.structure.io.EntityFinder; -import org.biojava.nbio.structure.io.FileParsingParameters; -import org.biojava.nbio.structure.io.SeqRes2AtomAligner; -import org.biojava.nbio.structure.io.mmcif.model.AtomSite; -import org.biojava.nbio.structure.io.mmcif.model.AtomSites; -import org.biojava.nbio.structure.io.mmcif.model.AuditAuthor; -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; -import org.biojava.nbio.structure.io.mmcif.model.ChemCompBond; -import org.biojava.nbio.structure.io.mmcif.model.ChemCompDescriptor; -import org.biojava.nbio.structure.io.mmcif.model.DatabasePDBremark; -import org.biojava.nbio.structure.io.mmcif.model.DatabasePDBrev; -import org.biojava.nbio.structure.io.mmcif.model.DatabasePdbrevRecord; -import org.biojava.nbio.structure.io.mmcif.model.Entity; -import org.biojava.nbio.structure.io.mmcif.model.EntityPoly; -import org.biojava.nbio.structure.io.mmcif.model.EntityPolySeq; -import org.biojava.nbio.structure.io.mmcif.model.EntitySrcGen; -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.PdbxAuditRevisionHistory; -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.PdbxDatabaseStatus; -import org.biojava.nbio.structure.io.mmcif.model.PdbxEntityNonPoly; -import org.biojava.nbio.structure.io.mmcif.model.PdbxNonPolyScheme; -import org.biojava.nbio.structure.io.mmcif.model.PdbxPolySeqScheme; -import org.biojava.nbio.structure.io.mmcif.model.PdbxStructAssembly; -import org.biojava.nbio.structure.io.mmcif.model.PdbxStructAssemblyGen; -import org.biojava.nbio.structure.io.mmcif.model.PdbxStructOperList; -import org.biojava.nbio.structure.io.mmcif.model.Refine; -import org.biojava.nbio.structure.io.mmcif.model.Struct; -import org.biojava.nbio.structure.io.mmcif.model.StructAsym; -import org.biojava.nbio.structure.io.mmcif.model.StructConn; -import org.biojava.nbio.structure.io.mmcif.model.StructKeywords; -import org.biojava.nbio.structure.io.mmcif.model.StructNcsOper; -import org.biojava.nbio.structure.io.mmcif.model.StructRef; -import org.biojava.nbio.structure.io.mmcif.model.StructRefSeq; -import org.biojava.nbio.structure.io.mmcif.model.StructRefSeqDif; -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.quaternary.BioAssemblyInfo; -import org.biojava.nbio.structure.quaternary.BiologicalAssemblyBuilder; -import org.biojava.nbio.structure.quaternary.BiologicalAssemblyTransformation; -import org.biojava.nbio.structure.xtal.CrystalCell; -import org.biojava.nbio.structure.xtal.SpaceGroup; -import org.biojava.nbio.structure.xtal.SymoplibParser; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * A MMcifConsumer implementation that builds an in-memory representation of the - * content of a mmcif file as a BioJava Structure object. - * - * @author Andreas Prlic - * @since 1.7 - */ - -public class SimpleMMcifConsumer implements MMcifConsumer { - - private static final Logger logger = LoggerFactory.getLogger(SimpleMMcifConsumer.class); - - private Structure structure; - private Chain currentChain; - private Group currentGroup; - - /** - * A temporary data structure to hold all parsed chains - */ - private ArrayList> allModels; - /** - * The current set of chains per model - */ - private List currentModel; - private List entities; - /** - * Needed in header only mode to get mapping between asym ids and author ids - */ - private List entityPolys; - private List strucRefs; - private List seqResChains; - private List entityChains; // needed to link entities, chains and compounds... - private List structAsyms; // needed to link entities, chains and compounds... - private List structOpers ; // - private List strucAssemblies; - private List strucAssemblyGens; - private List entitySrcGens; - private List entitySrcNats; - private List entitySrcSyns; - private List structConn; - private List structNcsOper; - private List sequenceDifs; - private List structSiteGens; - - private Matrix4d parsedScaleMatrix; - - - - /** - * A map of asym ids (internal chain ids) to entity ids extracted from - * the _struct_asym category - */ - private Map asymId2entityId; - - /** - * A map of asym ids (internal chain ids) to author ids extracted from - * the _entity_poly category. Used in header only parsing. - */ - private Map asymId2authorId; - - private String currentNmrModelNumber ; - - private FileParsingParameters params; - - public SimpleMMcifConsumer(){ - params = new FileParsingParameters(); - documentStart(); - - } - - @Override - public void newEntity(Entity entity) { - logger.debug("New entity: {}",entity.toString()); - entities.add(entity); - } - - @Override - public void newEntityPoly(EntityPoly entityPoly) { - entityPolys.add(entityPoly); - } - - @Override - public void newPdbxStructOperList(PdbxStructOperList structOper){ - - structOpers.add(structOper); - } - - @Override - public void newStructAsym(StructAsym sasym){ - - structAsyms.add(sasym); - } - - private Entity getEntity(int entity_id){ - try { - for (Entity e: entities){ - int eId = Integer.parseInt(e.getId()); - if (eId== entity_id){ - return e; - } - } - } catch (NumberFormatException e) { - logger.warn("Entity id does not look like a number: {}", e.getMessage()); - } - return null; - } - - @Override - public void newStructKeywords(StructKeywords kw){ - PDBHeader header = structure.getPDBHeader(); - if ( header == null) - header = new PDBHeader(); - header.setDescription(kw.getPdbx_keywords()); - header.setClassification(kw.getPdbx_keywords()); - } - - @Override - public void setStruct(Struct struct) { - - PDBHeader header = structure.getPDBHeader(); - if ( header == null) - header = new PDBHeader(); - - header.setTitle(struct.getTitle()); - header.setIdCode(struct.getEntry_id()); - //header.setDescription(struct.getPdbx_descriptor()); - //header.setClassification(struct.getPdbx_descriptor()); - //header.setDescription(struct.getPdbx_descriptor()); - - - - structure.setPDBHeader(header); - structure.setPDBCode(struct.getEntry_id()); - } - - /** initiate new group, either Hetatom, Nucleotide, or AminoAcid */ - private Group getNewGroup(String recordName,Character aminoCode1, long seq_id,String groupCode3) { - - Group g = ChemCompGroupFactory.getGroupFromChemCompDictionary(groupCode3); - if ( g != null && !g.getChemComp().isEmpty()) { - if ( g instanceof AminoAcidImpl) { - AminoAcidImpl aa = (AminoAcidImpl) g; - aa.setId(seq_id); - } else if ( g instanceof NucleotideImpl) { - NucleotideImpl nuc = (NucleotideImpl) g; - nuc.setId(seq_id); - } else if ( g instanceof HetatomImpl) { - HetatomImpl het = (HetatomImpl)g; - het.setId(seq_id); - } - return g; - } - - - - Group group; - if ( recordName.equals("ATOM") ) { - if (StructureTools.isNucleotide(groupCode3)) { - // it is a nucleotide - NucleotideImpl nu = new NucleotideImpl(); - group = nu; - nu.setId(seq_id); - - } else if (aminoCode1==null || aminoCode1 == StructureTools.UNKNOWN_GROUP_LABEL){ - HetatomImpl h = new HetatomImpl(); - h.setId(seq_id); - group = h; - - } else { - AminoAcidImpl aa = new AminoAcidImpl() ; - aa.setAminoType(aminoCode1); - aa.setId(seq_id); - group = aa ; - } - } - else { - if (StructureTools.isNucleotide(groupCode3)) { - // it is a nucleotide - NucleotideImpl nu = new NucleotideImpl(); - group = nu; - nu.setId(seq_id); - } - else if (aminoCode1 != null ) { - AminoAcidImpl aa = new AminoAcidImpl() ; - aa.setAminoType(aminoCode1); - aa.setId(seq_id); - group = aa ; - } else { - HetatomImpl h = new HetatomImpl(); - h.setId(seq_id); - group = h; - } - } - return group ; - } - - /** - * Test if the given asymId is already present in the list of chains given. If yes, returns the chain - * otherwise returns null. - */ - private static Chain isKnownChain(String asymId, List chains){ - - for (int i = 0; i< chains.size();i++){ - Chain testchain = chains.get(i); - //System.out.println("comparing chainID >"+chainID+"< against testchain " + i+" >" +testchain.getName()+"<"); - if (asymId.equals(testchain.getId())) { - //System.out.println("chain "+ chainID+" already known ..."); - return testchain; - } - } - - return null; - } - - @Override - public void newAtomSite(AtomSite atom) { - - if (params.isHeaderOnly()) return; - - // Warning: getLabel_asym_id is not the "chain id" in the PDB file - // it is the internally used chain id. - // later on we will fix this... - - // later one needs to map the asym id to the pdb_strand_id - - //TODO: add support for FileParsingParams.getMaxAtoms() - - boolean startOfNewChain = false; - - String asymId = atom.getLabel_asym_id(); - String authId = atom.getAuth_asym_id(); - - String recordName = atom.getGroup_PDB(); - String residueNumberS = atom.getAuth_seq_id(); - Integer residueNrInt = Integer.parseInt(residueNumberS); - - // the 3-letter name of the group: - String groupCode3 = atom.getLabel_comp_id(); - - boolean isHetAtomInFile = false; - - Character aminoCode1 = null; - if ( recordName.equals("ATOM") ) - aminoCode1 = StructureTools.get1LetterCodeAmino(groupCode3); - else { - aminoCode1 = StructureTools.get1LetterCodeAmino(groupCode3); - - // for nucleotides this will be null.. - if (aminoCode1 != null && aminoCode1.equals(StructureTools.UNKNOWN_GROUP_LABEL)) - aminoCode1 = null; - - isHetAtomInFile = true; - } - String insCodeS = atom.getPdbx_PDB_ins_code(); - Character insCode = null; - if (! insCodeS.equals("?")) { - insCode = insCodeS.charAt(0); - } - // we store the internal seq id in the Atom._id field - // this is not a PDB file field but we need this to internally assign the insertion codes later - // from the pdbx_poly_seq entries.. - - long seq_id = -1; - try { - seq_id = Long.parseLong(atom.getLabel_seq_id()); - } catch (NumberFormatException e){ - // non polymer chains (ligands and small molecules) will have a label_seq_id set to '.', thus it is ok to - // silently ignore this - //logger.debug("Could not parse number for _atom_site.label_seq_id: "+e.getMessage()); - } - - String nmrModelNumber = atom.getPdbx_PDB_model_num(); - - if ( currentNmrModelNumber == null) { - currentNmrModelNumber = nmrModelNumber; - } - - if (! currentNmrModelNumber.equals(nmrModelNumber)){ - currentNmrModelNumber = nmrModelNumber; - - // add previous data - if ( currentChain != null ) { - currentChain.addGroup(currentGroup); - currentGroup.trimToSize(); - } - - // we came to the beginning of a new NMR model - allModels.add(currentModel); - currentModel = new ArrayList(); - currentChain = null; - currentGroup = null; - } - - - if (currentChain == null) { - - currentChain = new ChainImpl(); - currentChain.setName(authId); - currentChain.setId(asymId); - currentModel.add(currentChain); - startOfNewChain = true; - } - - //System.out.println("BEFORE: " + chain_id + " " + current_chain.getName()); - if ( ! asymId.equals(currentChain.getId()) ) { - //logger.info("unknown chain. creating new chain. authId:" + authId + " asymId: " + asymId); - startOfNewChain = true; - - // end up old chain... - currentChain.addGroup(currentGroup); - - // see if old chain is known ... - Chain testchain = isKnownChain(asymId,currentModel); - - if ( testchain == null) { - //logger.info("unknown chain. creating new chain. authId:" + authId + " asymId: " + asymId); - - currentChain = new ChainImpl(); - currentChain.setName(authId); - currentChain.setId(asymId); - - } else { - currentChain = testchain; - } - - if ( ! currentModel.contains(currentChain)) - currentModel.add(currentChain); - - } - - - ResidueNumber residueNumber = new ResidueNumber(authId,residueNrInt, insCode); - - if (currentGroup == null) { - - - currentGroup = getNewGroup(recordName,aminoCode1,seq_id, groupCode3); - - currentGroup.setResidueNumber(residueNumber); - currentGroup.setPDBName(groupCode3); - currentGroup.setHetAtomInFile(isHetAtomInFile); - } - - // SET UP THE ALT LOC GROUP - Group altGroup = null; - String altLocS = atom.getLabel_alt_id(); - Character altLoc = ' '; - if ( altLocS.length()>0) { - altLoc = altLocS.charAt(0); - if ( altLoc.equals('.') ) - altLoc = ' '; - - } - // If it's the start of the new chain - if ( startOfNewChain){ - currentGroup = getNewGroup(recordName,aminoCode1,seq_id, groupCode3); - currentGroup.setResidueNumber(residueNumber); - currentGroup.setPDBName(groupCode3); - currentGroup.setHetAtomInFile(isHetAtomInFile); - } - // ANTHONY BRADLEY ADDED THIS -> WE ONLY WAN'T TO CHECK FOR ALT LOCS WHEN IT's NOT THE FIRST GROUP IN CHAIN - else{ - // check if residue number is the same ... - // insertion code is part of residue number - if ( ! residueNumber.equals(currentGroup.getResidueNumber())) { - //System.out.println("end of residue: "+current_group.getPDBCode()+" "+residueNrInt); - currentChain.addGroup(currentGroup); - currentGroup.trimToSize(); - currentGroup = getNewGroup(recordName,aminoCode1,seq_id,groupCode3); - currentGroup.setPDBName(groupCode3); - currentGroup.setResidueNumber(residueNumber); - currentGroup.setHetAtomInFile(isHetAtomInFile); - - - } else { - // same residueNumber, but altLocs... - // test altLoc - - if ( ! altLoc.equals(' ') && ( ! altLoc.equals('.'))) { - logger.debug("found altLoc! " + altLoc + " " + currentGroup + " " + altGroup); - altGroup = getCorrectAltLocGroup( altLoc,recordName,aminoCode1,groupCode3, seq_id); - if (altGroup.getChain()==null) { - altGroup.setChain(currentChain); - } - } - } - } - //atomCount++; - //System.out.println("fixing atom name for >" + atom.getLabel_atom_id() + "< >" + fullname + "<"); - - - if ( params.isParseCAOnly() ){ - // yes , user wants to get CA only - // only parse CA atoms... - if (! (atom.getLabel_atom_id().equals(StructureTools.CA_ATOM_NAME) && atom.getType_symbol().equals("C"))) { - //System.out.println("ignoring " + line); - //atomCount--; - return; - } - } - - //see if chain_id is one of the previous chains ... - - Atom a = convertAtom(atom); - - //see if chain_id is one of the previous chains ... - if ( altGroup != null) { - altGroup.addAtom(a); - altGroup = null; - } - else { - currentGroup.addAtom(a); - } - - - String atomName = a.getName(); - // make sure that main group has all atoms - // GitHub issue: #76 - if ( ! currentGroup.hasAtom(atomName)) { - // Unless it's microheterogenity https://github.com/rcsb/codec-devel/issues/81 - if (currentGroup.getPDBName().equals(a.getGroup().getPDBName())) { - if(!StructureTools.hasNonDeuteratedEquiv(a,currentGroup)){ - currentGroup.addAtom(a); - } - } - - } - } - - /** - * Convert a mmCIF AtomSite object to a BioJava Atom object - * - * @param atom the mmmcif AtomSite record - * @return an Atom - */ - private Atom convertAtom(AtomSite atom){ - - - Atom a = new AtomImpl(); - - a.setPDBserial(Integer.parseInt(atom.getId())); - a.setName(atom.getLabel_atom_id()); - - double x = Double.parseDouble (atom.getCartn_x()); - double y = Double.parseDouble (atom.getCartn_y()); - double z = Double.parseDouble (atom.getCartn_z()); - a.setX(x); - a.setY(y); - a.setZ(z); - - float occupancy = Float.parseFloat (atom.getOccupancy()); - a.setOccupancy(occupancy); - - float temp = Float.parseFloat (atom.getB_iso_or_equiv()); - a.setTempFactor(temp); - - String alt = atom.getLabel_alt_id(); - if (( alt != null ) && ( alt.length() > 0) && (! alt.equals("."))){ - a.setAltLoc(new Character(alt.charAt(0))); - } else { - a.setAltLoc(new Character(' ')); - } - - Element element = Element.R; - try { - element = Element.valueOfIgnoreCase(atom.getType_symbol()); - } catch (IllegalArgumentException e) { - logger.info("Element {} was not recognised as a BioJava-known element, the element will be represented as the generic element {}", atom.getType_symbol(), Element.R.name()); - } - a.setElement(element); - - return a; - - } - - - private Group getCorrectAltLocGroup( Character altLoc, - String recordName, - Character aminoCode1, - String groupCode3, - long seq_id) { - - // see if we know this altLoc already; - List atoms = currentGroup.getAtoms(); - if ( atoms.size() > 0) { - Atom a1 = atoms.get(0); - // we are just adding atoms to the current group - // probably there is a second group following later... - if (a1.getAltLoc().equals(altLoc)) { - - return currentGroup; - } - } - - List altLocs = currentGroup.getAltLocs(); - for ( Group altLocG : altLocs ){ - atoms = altLocG.getAtoms(); - if ( atoms.size() > 0) { - for ( Atom a1 : atoms) { - if (a1.getAltLoc().equals( altLoc)) { - - return altLocG; - } - } - } - } - - // no matching altLoc group found. - // build it up. - - if ( groupCode3.equals(currentGroup.getPDBName())) { - if ( currentGroup.getAtoms().size() == 0) { - //System.out.println("current group is empty " + current_group + " " + altLoc); - return currentGroup; - } - //System.out.println("cloning current group " + current_group + " " + current_group.getAtoms().get(0).getAltLoc() + " altLoc " + altLoc); - Group altLocG = (Group) currentGroup.clone(); - // drop atoms from cloned group... - // https://redmine.open-bio.org/issues/3307 - altLocG.setAtoms(new ArrayList()); - altLocG.getAltLocs().clear(); - currentGroup.addAltLoc(altLocG); - return altLocG; - } - - // System.out.println("new group " + recordName + " " + aminoCode1 + " " +groupCode3); - //String recordName,Character aminoCode1, long seq_id,String groupCode3) { - Group altLocG = getNewGroup(recordName,aminoCode1,seq_id,groupCode3); - - altLocG.setPDBName(groupCode3); - altLocG.setResidueNumber(currentGroup.getResidueNumber()); - currentGroup.addAltLoc(altLocG); - return altLocG; - } - - /** - * Start the parsing - */ - @Override - public void documentStart() { - structure = new StructureImpl(); - - currentChain = null; - currentGroup = null; - currentNmrModelNumber = null; - //atomCount = 0; - - allModels = new ArrayList>(); - currentModel = new ArrayList(); - entities = new ArrayList(); - entityPolys = new ArrayList<>(); - strucRefs = new ArrayList(); - seqResChains = new ArrayList(); - entityChains = new ArrayList(); - structAsyms = new ArrayList(); - - asymId2entityId = new HashMap(); - asymId2authorId = new HashMap<>(); - structOpers = new ArrayList(); - strucAssemblies = new ArrayList(); - strucAssemblyGens = new ArrayList(); - entitySrcGens = new ArrayList(); - entitySrcNats = new ArrayList(); - entitySrcSyns = new ArrayList(); - structConn = new ArrayList(); - structNcsOper = new ArrayList(); - sequenceDifs = new ArrayList(); - structSiteGens = new ArrayList(); - } - - - @Override - public void documentEnd() { - - // Expected that there is one current_chain that needs to be added to the model - // When in headerOnly mode, no Atoms are read, and there will not be an active - // current_chain. - if ( currentChain != null ) { - - currentChain.addGroup(currentGroup); - if (isKnownChain(currentChain.getId(),currentModel) == null) { - currentModel.add(currentChain); - } - } else if (!params.isHeaderOnly()){ - logger.warn("current chain is null at end of document."); - } - - allModels.add(currentModel); - - // this populates the asymId2authorId and asymId2entityId maps, needed in header only mode to get the mapping - // between the 2 chain identifiers. - initMaps(); - - for (StructAsym asym : structAsyms) { - - logger.debug("Entity {} matches asym_id: {}", asym.getEntity_id(), asym.getId() ); - - Chain s = getEntityChain(asym.getEntity_id()); - Chain seqres = (Chain)s.clone(); - // to solve issue #160 (e.g. 3u7t) - seqres = removeSeqResHeterogeneity(seqres); - seqres.setId(asym.getId()); - if (asymId2authorId.get(asym.getId()) !=null ){ - seqres.setName(asymId2authorId.get(asym.getId())); - } else { - seqres.setName(asym.getId()); - } - - EntityType type = null; - try { - Entity ent = getEntity(Integer.parseInt(asym.getEntity_id())); - type = EntityType.entityTypeFromString(ent.getType()); - } catch (NumberFormatException e) { - logger.debug("Could not parse integer from entity id field {}", asym.getEntity_id()); - } - - // we'll only add seqres chains that are polymeric or unknown - if (type==null || type==EntityType.POLYMER ) { - seqResChains.add(seqres); - } - - logger.debug(" seqres: " + asym.getId() + " " + seqres + "<") ; - // adding the entities to structure - addEntities(asym); - - } - - if (structAsyms.isEmpty()) { - logger.warn("No _struct_asym category in file, no SEQRES groups will be added."); - } - - // entities - // In addEntities above we created the entities if they were present in the file - // Now we need to make sure that they are linked to chains and also that if they are not present in the file we need to add them now - linkEntities(); - - // now that we know the entities, we can add all chains to structure so that they are stored - // properly as polymer/nonpolymer/water chains inside structure - for (List model:allModels) { - structure.addModel(model); - } - - // Only align if requested (default) and not when headerOnly mode with no Atoms. - // Otherwise, we store the empty SeqRes Groups unchanged in the right chains. - if ( params.isAlignSeqRes() && !params.isHeaderOnly() ){ - logger.debug("Parsing mode align_seqres, will parse SEQRES and align to ATOM sequence"); - alignSeqRes(); - } else { - logger.debug("Parsing mode unalign_seqres, will parse SEQRES but not align it to ATOM sequence"); - SeqRes2AtomAligner.storeUnAlignedSeqRes(structure, seqResChains, params.isHeaderOnly()); - } - - - // Now make sure all altlocgroups have all the atoms in all the groups - StructureTools.cleanUpAltLocs(structure); - - // NOTE bonds and charges can only be done at this point that the chain id mapping is properly sorted out - if (!params.isHeaderOnly()) { - if ( params.shouldCreateAtomBonds()) { - addBonds(); - } - - if ( params.shouldCreateAtomCharges()) { - addCharges(); - } - } - - if (!params.isHeaderOnly()) { - - // Do structure.setSites(sites) after any chain renaming to be like PDB. - addSites(); - } - - - - // set the oligomeric state info in the header... - if (params.isParseBioAssembly()) { - - // the more detailed mapping of chains to rotation operations happens in StructureIO... - - Map bioAssemblies = new LinkedHashMap(); - - for ( PdbxStructAssembly psa : strucAssemblies){ - - List psags = new ArrayList(1); - - for ( PdbxStructAssemblyGen psag: strucAssemblyGens ) { - if ( psag.getAssembly_id().equals(psa.getId())) { - psags.add(psag); - } - } - - BiologicalAssemblyBuilder builder = new BiologicalAssemblyBuilder(); - - // these are the transformations that need to be applied to our model - List transformations = builder.getBioUnitTransformationList(psa, psags, structOpers); - - int bioAssemblyId = -1; - try { - bioAssemblyId = Integer.parseInt(psa.getId()); - } catch (NumberFormatException e) { - logger.info("Could not parse a numerical bio assembly id from '{}'",psa.getId()); - } - - // if bioassembly id is not numerical we throw it away - // this happens usually for viral capsid entries, like 1ei7 - // see issue #230 in github - if (bioAssemblyId!=-1) { - int mmSize = 0; - // note that the transforms contain asym ids of both polymers and non-polymers - // For the mmsize, we are only interested in the polymers - for (BiologicalAssemblyTransformation transf:transformations) { - Chain c = structure.getChain(transf.getChainId()); - if (c==null) { - logger.info("Could not find asym id {} specified in struct_assembly_gen", transf.getChainId()); - continue; - } - if (c.getEntityType() == EntityType.POLYMER && - // for entries like 4kro, sugars are annotated as polymers but we - // don't want them in the macromolecularSize count - !c.getEntityInfo().getDescription().contains("SUGAR") ) { - - mmSize++; - } - } - - BioAssemblyInfo bioAssembly = new BioAssemblyInfo(); - bioAssembly.setId(bioAssemblyId); - bioAssembly.setMacromolecularSize(mmSize); - bioAssembly.setTransforms(transformations); - bioAssemblies.put(bioAssemblyId,bioAssembly); - } - - } - structure.getPDBHeader().setBioAssemblies(bioAssemblies); - } - - setStructNcsOps(); - - setCrystallographicInfoMetadata(); - - - Map> misMatchMap = new HashMap>(); - for (StructRefSeqDif sdif : sequenceDifs) { - SeqMisMatch misMatch = new SeqMisMatchImpl(); - misMatch.setDetails(sdif.getDetails()); - - String insCode = sdif.getPdbx_pdb_ins_code(); - if ( insCode != null && insCode.equals("?")) - insCode = null; - misMatch.setInsCode(insCode); - misMatch.setOrigGroup(sdif.getDb_mon_id()); - misMatch.setPdbGroup(sdif.getMon_id()); - misMatch.setPdbResNum(sdif.getPdbx_auth_seq_num()); - misMatch.setUniProtId(sdif.getPdbx_seq_db_accession_code()); - misMatch.setSeqNum(sdif.getSeq_num()); - - - List mms = misMatchMap.get(sdif.getPdbx_pdb_strand_id()); - if ( mms == null) { - mms = new ArrayList(); - misMatchMap.put(sdif.getPdbx_pdb_strand_id(),mms); - } - mms.add(misMatch); - - } - - for (String chainId : misMatchMap.keySet()){ - - Chain chain = structure.getPolyChainByPDB(chainId); - - if ( chain == null) { - logger.warn("Could not set mismatches for chain with author id" + chainId); - continue; - } - - chain.setSeqMisMatches(misMatchMap.get(chainId)); - - - } - - } - - /** - * Here we link entities to chains. - * Also if entities are not present in file, this initialises the entities with some heuristics, see {@link org.biojava.nbio.structure.io.EntityFinder} - */ - private void linkEntities() { - - for (int i =0; i< allModels.size() ; i++){ - for (Chain chain : allModels.get(i)) { - //logger.info("linking entities for " + chain.getId() + " " + chain.getName()); - String entityId = asymId2entityId.get(chain.getId()); - - if (entityId==null) { - // this can happen for instance if the cif file didn't have _struct_asym category at all - // and thus we have no asymId2entityId mapping at all - logger.info("No entity id could be found for chain {}", chain.getId()); - continue; - } - int eId = Integer.parseInt(entityId); - - // Entities are not added for non-polymeric entities, if a chain is non-polymeric its entity won't be found. - // TODO: add all entities and unique compounds and add methods to directly get polymer or non-polymer - // asyms (chains). Either create a unique StructureImpl or modify existing for a better representation of the - // mmCIF internal data structures but is compatible with Structure interface. - // Some examples of PDB entries with this kind of problem: - // - 2uub: asym_id X, chainName Z, entity_id 24: fully non-polymeric but still with its own chainName - // - 3o6j: asym_id K, chainName Z, entity_id 6 : a single water molecule - // - 1dz9: asym_id K, chainName K, entity_id 6 : a potassium ion alone - - EntityInfo entityInfo = structure.getEntityById(eId); - if (entityInfo==null) { - // Supports the case where the only chain members were from non-polymeric entity that is missing. - // Solved by creating a new Compound(entity) to which this chain will belong. - logger.info("Could not find an Entity for entity_id {}, for chain id {}, creating a new Entity.", - eId, chain.getId()); - entityInfo = new EntityInfo(); - entityInfo.setMolId(eId); - entityInfo.addChain(chain); - if (chain.isWaterOnly()) { - entityInfo.setType(EntityType.WATER); - } else { - entityInfo.setType(EntityType.NONPOLYMER); - } - chain.setEntityInfo(entityInfo); - structure.addEntityInfo(entityInfo); - } else { - logger.debug("Adding chain with chain id {} (auth id {}) to Entity with entity_id {}", - chain.getId(), chain.getName(), eId); - entityInfo.addChain(chain); - chain.setEntityInfo(entityInfo); - } - - } - - } - - // if no entity information was present in file we then go and find the entities heuristically with EntityFinder - List entityInfos = structure.getEntityInfos(); - if (entityInfos==null || entityInfos.isEmpty()) { - - List> polyModels = new ArrayList<>(); - List> nonPolyModels = new ArrayList<>(); - List> waterModels = new ArrayList<>(); - - for (List model:allModels) { - - List polyChains = new ArrayList<>(); - List nonPolyChains = new ArrayList<>(); - List waterChains = new ArrayList<>(); - - polyModels.add(polyChains); - nonPolyModels.add(nonPolyChains); - waterModels.add(waterChains); - - for (Chain c:model) { - - // we only have entities for polymeric chains, all others are ignored for assigning entities - if (c.isWaterOnly()) { - waterChains.add(c); - - } else if (c.isPureNonPolymer()) { - nonPolyChains.add(c); - - } else { - polyChains.add(c); - } - } - } - - entityInfos = EntityFinder.findPolyEntities(polyModels); - EntityFinder.createPurelyNonPolyEntities(nonPolyModels, waterModels, entityInfos); - - - structure.setEntityInfos(entityInfos); - } - - // final sanity check: it can happen that from the annotated entities some are not linked to any chains - // e.g. 3s26: a sugar entity does not have any chains associated to it (it seems to be happening with many sugar compounds) - // we simply log it, this can sign some other problems if the entities are used down the line - for (EntityInfo e:entityInfos) { - if (e.getChains().isEmpty()) { - logger.info("Entity {} '{}' has no chains associated to it", - e.getMolId()<0?"with no entity id":e.getMolId(), e.getDescription()); - } - } - - } - - private void addCharges() { - ChargeAdder.addCharges(structure); - } - - /** - * The method will return a new reference to a Chain with any consecutive groups - * having same residue numbers removed. - * This is necessary to solve the microheterogeneity issue in entries like 3u7t (see github issue #160) - * @param c - * @return - */ - private static Chain removeSeqResHeterogeneity(Chain c) { - - Chain trimmedChain = new ChainImpl(); - - ResidueNumber lastResNum = null; - - for (Group g:c.getAtomGroups()) { - - // note we have to deep copy this, otherwise they stay linked and would get altered in addGroup(g) - ResidueNumber currentResNum = new ResidueNumber( - g.getResidueNumber().getChainName(), - g.getResidueNumber().getSeqNum(), - g.getResidueNumber().getInsCode()); - - if (lastResNum == null || !lastResNum.equals(currentResNum) ) { - trimmedChain.addGroup(g); - } else { - logger.debug("Removing seqres group because it seems to be repeated in entity_poly_seq, most likely has hetero='y': "+g); - } - - lastResNum = currentResNum; - - } - return trimmedChain; - } - - private void addBonds() { - BondMaker maker = new BondMaker(structure, params); - maker.makeBonds(); - maker.formBondsFromStructConn(structConn); - } - - private void alignSeqRes() { - - logger.debug("Parsing mode align_seqres, will align to ATOM to SEQRES sequence"); - - // fix SEQRES residue numbering for all models - - for (int model=0;model atomList = structure.getModel(model); - - for (Chain seqResChain: seqResChains){ - - // this extracts the matching atom chain from atomList - Chain atomChain = SeqRes2AtomAligner.getMatchingAtomRes(seqResChain, atomList, true); - - if (atomChain == null) { - // most likely there's no observed residues at all for the seqres chain: can't map - // e.g. 3zyb: chains with asym_id L,M,N,O,P have no observed residues - logger.info("Could not map SEQRES chain with asym_id={} to any ATOM chain. Most likely there's no observed residues in the chain.", - seqResChain.getId()); - continue; - } - - //map the atoms to the seqres... - - // we need to first clone the seqres so that they stay independent for different models - List seqResGroups = new ArrayList(); - for (int i=0;i> entityId2asymId = new HashMap<>(); - - for (StructAsym asym : structAsyms) { - - logger.debug("Entity {} matches asym_id: {}", asym.getEntity_id(), asym.getId() ); - - asymId2entityId.put(asym.getId(), asym.getEntity_id()); - - if (entityId2asymId.containsKey(asym.getEntity_id())) { - List asymIds = entityId2asymId.get(asym.getEntity_id()); - asymIds.add(asym.getId()); - } else { - List asymIds = new ArrayList<>(); - asymIds.add(asym.getId()); - entityId2asymId.put(asym.getEntity_id(), asymIds); - } - } - - if (entityPolys==null || entityPolys.isEmpty()) { - logger.info("No _entity_poly category found in file. No asym id to author id mapping will be available for header only parsing"); - return; - } - - for (EntityPoly ep:entityPolys) { - if (ep.getPdbx_strand_id()==null) { - logger.info("_entity_poly.pdbx_strand_id is null for entity {}. Won't be able to map asym ids to author ids for this entity.", ep.getEntity_id()); - continue; - } - String[] chainNames = ep.getPdbx_strand_id().split(","); - List asymIds = entityId2asymId.get(ep.getEntity_id()); - if (chainNames.length!=asymIds.size()) { - logger.warn("The list of asym ids (from _struct_asym) and the list of author ids (from _entity_poly) for entity {} have different lengths! Can't provide a mapping from asym ids to author chain ids", ep.getEntity_id()); - continue; - } - for (int i=0; i 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()])); - } - } - - private void setCrystallographicInfoMetadata() { - if (parsedScaleMatrix!=null) { - - PDBCrystallographicInfo crystalInfo = structure.getCrystallographicInfo(); - - boolean nonStd = false; - if (crystalInfo.getCrystalCell()!=null && !crystalInfo.getCrystalCell().checkScaleMatrix(parsedScaleMatrix)) { - nonStd = true; - } - - crystalInfo.setNonStandardCoordFrameConvention(nonStd); - } - } - - - /** This method will return the parsed protein structure, once the parsing has been finished - * - * @return a BioJava protein structure object - */ - public Structure getStructure() { - - return structure; - } - - @Override - public void newDatabasePDBrevRecord(DatabasePdbrevRecord record) { - - PDBHeader header = structure.getPDBHeader(); - - if ( header == null) { - header = new PDBHeader(); - structure.setPDBHeader(header); - } - - List revRecords = header.getRevisionRecords(); - if ( revRecords == null) { - revRecords = new ArrayList(); - header.setRevisionRecords(revRecords); - } - revRecords.add(record); - - - } - - - @Override - public void newDatabasePDBrev(DatabasePDBrev dbrev) { - - logger.debug("got a database revision:" + dbrev); - - SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd",Locale.US); - PDBHeader header = structure.getPDBHeader(); - - if ( header == null) { - header = new PDBHeader(); - } - - if (dbrev.getNum().equals("1")){ - - try { - Date dep = dateFormat.parse(dbrev.getDate_original()); - header.setDepDate(dep); - - } catch (ParseException e){ - logger.warn("Could not parse date string '{}', deposition date will be unavailable", dbrev.getDate_original()); - } - - try { - Date rel = dateFormat.parse(dbrev.getDate()); - header.setRelDate(rel); - - } catch (ParseException e){ - logger.warn("Could not parse date string '{}', modification date will be unavailable", dbrev.getDate()); - } - - - } else { - try { - - Date mod = dateFormat.parse(dbrev.getDate()); - header.setModDate(mod); - - } catch (ParseException e){ - logger.warn("Could not parse date string '{}', modification date will be unavailable", dbrev.getDate()); - } - } - - structure.setPDBHeader(header); - } - - @Override - public void newPdbxAuditRevisionHistory(PdbxAuditRevisionHistory history) { - - SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd",Locale.US); - PDBHeader header = structure.getPDBHeader(); - - if ( header == null) { - header = new PDBHeader(); - } - - // first entry in revision history is the release date - if (history.getOrdinal().equals("1")){ - try { - Date releaseDate = dateFormat.parse(history.getRevision_date()); - header.setRelDate(releaseDate); - - } catch (ParseException e){ - logger.warn("Could not parse date string '{}', release date will be unavailable", history.getRevision_date()); - } - } else { - // all other dates are revision dates; - // since this method may be called multiple times, - // the last revision date will "stick" - try { - Date revisionDate = dateFormat.parse(history.getRevision_date()); - header.setModDate(revisionDate); - } catch (ParseException e){ - logger.warn("Could not parse date string '{}', revision date will be unavailable", history.getRevision_date()); - } - } - - structure.setPDBHeader(header); - } - - @Override - public void newPdbxDatabaseStatus(PdbxDatabaseStatus status) { - - // the deposition date field is only available in mmCIF 5.0 - - if (status.getRecvd_initial_deposition_date() == null) { - // skip this method for older mmCIF versions - return; - } - - SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd",Locale.US); - PDBHeader header = structure.getPDBHeader(); - - if (header == null) { - header = new PDBHeader(); - } - - try { - Date depositionDate = dateFormat.parse(status.getRecvd_initial_deposition_date()); - header.setDepDate(depositionDate); - } catch (ParseException e){ - logger.warn("Could not parse date string '{}', deposition date will be unavailable", status.getRecvd_initial_deposition_date()); - } - - structure.setPDBHeader(header); - } - - @Override - public void newDatabasePDBremark(DatabasePDBremark remark) { - //System.out.println(remark); - String id = remark.getId(); - if (id.equals("2")){ - - //this remark field contains the resolution information: - String line = remark.getText(); - - int i = line.indexOf("ANGSTROM"); - if ( i > 5) { - // line contains ANGSTROM info... - String resolution = line.substring(i-5,i).trim(); - // convert string to float - float res = 99 ; - try { - res = Float.parseFloat(resolution); - - } catch (NumberFormatException e) { - logger.info("could not parse resolution from line and ignoring it " + line); - return ; - - - } - // support for old style header - - PDBHeader pdbHeader = structure.getPDBHeader(); - pdbHeader.setResolution(res); - - } - - } - } - - @Override - public void newRefine(Refine r){ - - PDBHeader pdbHeader = structure.getPDBHeader(); - // RESOLUTION - // in very rare cases (for instance hybrid methods x-ray + neutron diffraction, e.g. 3ins, 4n9m) - // there are 2 resolution values, one for each method - // we take the last one found so that behaviour is like in PDB file parsing - if (pdbHeader.getResolution()!=PDBHeader.DEFAULT_RESOLUTION) { - logger.warn("More than 1 resolution value present, will use last one {} and discard previous {} " - ,r.getLs_d_res_high(), String.format("%4.2f",pdbHeader.getResolution())); - } - try { - pdbHeader.setResolution(Float.parseFloat(r.getLs_d_res_high())); - } catch (NumberFormatException e){ - logger.info("Could not parse resolution from " + r.getLs_d_res_high() + " " + e.getMessage()); - } - - - // RFREE - if (pdbHeader.getRfree()!=PDBHeader.DEFAULT_RFREE) { - logger.warn("More than 1 Rfree value present, will use last one {} and discard previous {} ", - r.getLs_R_factor_R_free(), String.format("%4.2f",pdbHeader.getRfree())); - } - if (r.getLs_R_factor_R_free()==null) { - // some entries like 2ifo haven't got this field at all - logger.info("_refine.ls_R_factor_R_free not present, not parsing Rfree value"); - } else { - try { - pdbHeader.setRfree(Float.parseFloat(r.getLs_R_factor_R_free())); - } catch (NumberFormatException e){ - // no rfree present ('?') is very usual, that's why we set it to debug - logger.debug("Could not parse Rfree from string '{}'", r.getLs_R_factor_R_free()); - } - } - - // RWORK - if(pdbHeader.getRwork()!=PDBHeader.DEFAULT_RFREE) { - logger.warn("More than 1 R work value present, will use last one {} and discard previous {} ", - r.getLs_R_factor_R_work(), String.format("%4.2f",pdbHeader.getRwork())); - } - if(r.getLs_R_factor_R_work()==null){ - logger.info("_refine.ls_R_factor_R_work not present, not parsing R-work value"); - } - else{ - try{ - pdbHeader.setRwork(Float.parseFloat(r.getLs_R_factor_R_work())); - } - catch (NumberFormatException e){ - logger.debug("Could not parse R-work from string '{}'", r.getLs_R_factor_R_work()); - } - - } - - } - - - @Override - public void newAuditAuthor(AuditAuthor aa){ - - String name = aa.getName(); - - StringBuffer famName = new StringBuffer(); - StringBuffer initials = new StringBuffer(); - boolean afterComma = false; - for ( char c: name.toCharArray()) { - if ( c == ' ') - continue; - if ( c == ','){ - afterComma = true; - continue; - } - - if ( afterComma) - initials.append(c); - else - famName.append(c); - } - - StringBuffer newaa = new StringBuffer(); - newaa.append(initials); - newaa.append(famName); - - PDBHeader header = structure.getPDBHeader(); - String auth = header.getAuthors(); - if (auth == null) { - header.setAuthors(newaa.toString()); - }else { - auth += "," + newaa.toString(); - header.setAuthors(auth); - - } - } - - @Override - public void newExptl(Exptl exptl) { - - PDBHeader pdbHeader = structure.getPDBHeader(); - String method = exptl.getMethod(); - pdbHeader.setExperimentalTechnique(method); - - } - - @Override - public void newCell(Cell cell) { - - try { - float a = Float.parseFloat(cell.getLength_a()); - float b = Float.parseFloat(cell.getLength_b()); - float c = Float.parseFloat(cell.getLength_c()); - float alpha = Float.parseFloat(cell.getAngle_alpha()); - float beta = Float.parseFloat(cell.getAngle_beta()); - float gamma = Float.parseFloat(cell.getAngle_gamma()); - - CrystalCell xtalCell = new CrystalCell(); - xtalCell.setA(a); - xtalCell.setB(b); - xtalCell.setC(c); - xtalCell.setAlpha(alpha); - xtalCell.setBeta(beta); - xtalCell.setGamma(gamma); - - if (!xtalCell.isCellReasonable()) { - // If the entry describes a structure determined by a technique other than X-ray crystallography, - // cell is (sometimes!) a = b = c = 1.0, alpha = beta = gamma = 90 degrees - // if so we don't add and CrystalCell will be null - logger.debug("The crystal cell read from file does not have reasonable dimensions (at least one dimension is below {}), discarding it.", - CrystalCell.MIN_VALID_CELL_SIZE); - return; - } - - structure.getPDBHeader().getCrystallographicInfo().setCrystalCell(xtalCell); - - } catch (NumberFormatException e){ - structure.getPDBHeader().getCrystallographicInfo().setCrystalCell(null); - logger.info("could not parse some cell parameters ("+e.getMessage()+"), ignoring _cell "); - } - } - - @Override - public void newSymmetry(Symmetry symmetry) { - String spaceGroup = symmetry.getSpace_group_name_H_M(); - SpaceGroup sg = SymoplibParser.getSpaceGroup(spaceGroup); - if (sg==null) { - logger.warn("Space group '"+spaceGroup+"' not recognised as a standard space group"); - structure.getPDBHeader().getCrystallographicInfo().setNonStandardSg(true); - } else { - structure.getPDBHeader().getCrystallographicInfo().setSpaceGroup(sg); - structure.getPDBHeader().getCrystallographicInfo().setNonStandardSg(false); - } - } - - @Override - public void newStructNcsOper(StructNcsOper sNcsOper) { - structNcsOper.add(sNcsOper); - } - - public void newAtomSites(AtomSites atomSites) { - - try { - Matrix4d m = new Matrix4d( - Double.parseDouble(atomSites.getFract_transf_matrix11()), Double.parseDouble(atomSites.getFract_transf_matrix12()), Double.parseDouble(atomSites.getFract_transf_matrix13()), Double.parseDouble(atomSites.getFract_transf_vector1()), - Double.parseDouble(atomSites.getFract_transf_matrix21()), Double.parseDouble(atomSites.getFract_transf_matrix22()), Double.parseDouble(atomSites.getFract_transf_matrix23()), Double.parseDouble(atomSites.getFract_transf_vector2()), - Double.parseDouble(atomSites.getFract_transf_matrix31()), Double.parseDouble(atomSites.getFract_transf_matrix32()), Double.parseDouble(atomSites.getFract_transf_matrix33()), Double.parseDouble(atomSites.getFract_transf_vector3()), - 0,0,0,1); - - parsedScaleMatrix = m; - - } catch (NumberFormatException e) { - logger.warn("Some values in _atom_sites.fract_transf_matrix or _atom_sites.fract_transf_vector could not be parsed as numbers. Can't check whether coordinate frame convention is correct! Error: {}", e.getMessage()); - structure.getPDBHeader().getCrystallographicInfo().setNonStandardCoordFrameConvention(false); - - // in this case parsedScaleMatrix stays null and can't be used in documentEnd() - } - } - - @Override - public void newStructRef(StructRef sref) { - logger.debug(sref.toString()); - strucRefs.add(sref); - } - - private StructRef getStructRef(String ref_id){ - for (StructRef structRef : strucRefs) { - - if (structRef.getId().equals(ref_id)){ - return structRef; - } - - } - return null; - - } - - /** - * create a DBRef record from the StrucRefSeq record: - *

-	 * PDB record                    DBREF
-	 * Field Name                    mmCIF Data Item
-	 * Section                       n.a.
-	 * PDB_ID_Code                   _struct_ref_seq.pdbx_PDB_id_code
-	 * Strand_ID                     _struct_ref_seq.pdbx_strand_id
-	 * Begin_Residue_Number          _struct_ref_seq.pdbx_auth_seq_align_beg
-	 * Begin_Ins_Code                _struct_ref_seq.pdbx_seq_align_beg_ins_code
-	 * End_Residue_Number            _struct_ref_seq.pdbx_auth_seq_align_end
-	 * End_Ins_Code                  _struct_ref_seq.pdbx_seq_align_end_ins_code
-	 * Database                      _struct_ref.db_name
-	 * Database_Accession_No         _struct_ref_seq.pdbx_db_accession
-	 * Database_ID_Code              _struct_ref.db_code
-	 * Database_Begin_Residue_Number _struct_ref_seq.db_align_beg
-	 * Databaes_Begin_Ins_Code       _struct_ref_seq.pdbx_db_align_beg_ins_code
-	 * Database_End_Residue_Number   _struct_ref_seq.db_align_end
-	 * Databaes_End_Ins_Code         _struct_ref_seq.pdbx_db_align_end_ins_code
-	 * 
- * - * - */ - @Override - public void newStructRefSeq(StructRefSeq sref) { - DBRef r = new DBRef(); - - r.setIdCode(sref.getPdbx_PDB_id_code()); - r.setDbAccession(sref.getPdbx_db_accession()); - r.setDbIdCode(sref.getPdbx_db_accession()); - - r.setChainName(sref.getPdbx_strand_id()); - StructRef structRef = getStructRef(sref.getRef_id()); - if (structRef == null){ - logger.info("could not find StructRef " + sref.getRef_id() + " for StructRefSeq " + sref); - } else { - r.setDatabase(structRef.getDb_name()); - r.setDbIdCode(structRef.getDb_code()); - } - - int seqbegin; - int seqend; - try{ - seqbegin = Integer.parseInt(sref.getPdbx_auth_seq_align_beg()); - seqend = Integer.parseInt(sref.getPdbx_auth_seq_align_end()); - } - catch(NumberFormatException e){ - // this happens in a few entries, annotation error? e.g. 6eoj - logger.warn("Couldn't parse pdbx_auth_seq_align_beg/end in _struct_ref_seq. Will not store dbref alignment info for accession {}. Error: {}", r.getDbAccession(), e.getMessage()); - return; - } - - Character begin_ins_code = ' '; - if (sref.getPdbx_seq_align_beg_ins_code() != null ) { - begin_ins_code = new Character(sref.getPdbx_seq_align_beg_ins_code().charAt(0)); - } - - Character end_ins_code = ' '; - if (sref.getPdbx_seq_align_end_ins_code() != null) { - end_ins_code = new Character(sref.getPdbx_seq_align_end_ins_code().charAt(0)); - } - - if (begin_ins_code == '?') - begin_ins_code = ' '; - - if (end_ins_code == '?') - end_ins_code = ' '; - - r.setSeqBegin(seqbegin); - r.setInsertBegin(begin_ins_code); - - r.setSeqEnd(seqend); - r.setInsertEnd(end_ins_code); - - int dbseqbegin = Integer.parseInt(sref.getDb_align_beg()); - int dbseqend = Integer.parseInt(sref.getDb_align_end()); - - Character db_begin_in_code = ' '; - if (sref.getPdbx_db_align_beg_ins_code() != null) { - db_begin_in_code = new Character(sref.getPdbx_db_align_beg_ins_code().charAt(0)); - } - - Character db_end_in_code = ' '; - if (sref.getPdbx_db_align_end_ins_code() != null) { - db_end_in_code = new Character(sref.getPdbx_db_align_end_ins_code().charAt(0)); - } - - if (db_begin_in_code == '?') - db_begin_in_code = ' '; - - if (db_end_in_code == '?') - db_end_in_code = ' '; - - - r.setDbSeqBegin(dbseqbegin); - r.setIdbnsBegin(db_begin_in_code); - - r.setDbSeqEnd(dbseqend); - r.setIdbnsEnd(db_end_in_code); - - List dbrefs = structure.getDBRefs(); - if ( dbrefs == null) - dbrefs = new ArrayList(); - dbrefs.add(r); - - logger.debug(r.toPDB()); - - structure.setDBRefs(dbrefs); - - } - - @Override - public void newStructRefSeqDif(StructRefSeqDif sref) { - sequenceDifs.add(sref); - } - - private Chain getEntityChain(String entity_id){ - - for (Chain chain : entityChains) { - if ( chain.getId().equals(entity_id)){ - - return chain; - } - } - // does not exist yet, so create... - - Chain chain = new ChainImpl(); - chain.setId(entity_id); - entityChains.add(chain); - - return chain; - - } - - //private Chain getSeqResChain(String chainID){ - // return getChainFromList(seqResChains, chainID); - //} - - - /** - * Data items in the ENTITY_SRC_GEN category record details of - * the source from which the entity was obtained in cases - * where the source was genetically manipulated. The - * following are treated separately: items pertaining to the tissue - * from which the gene was obtained, items pertaining to the host - * organism for gene expression and items pertaining to the actual - * producing organism (plasmid). - */ - @Override - public void newEntitySrcGen(EntitySrcGen entitySrcGen){ - - // add to internal list. Map to Compound object later on... - entitySrcGens.add(entitySrcGen); - } - - @Override - public void newEntitySrcNat(EntitySrcNat entitySrcNat){ - - // add to internal list. Map to Compound object later on... - entitySrcNats.add(entitySrcNat); - } - - @Override - public void newEntitySrcSyn(EntitySrcSyn entitySrcSyn){ - - // add to internal list. Map to Compound object later on... - entitySrcSyns.add(entitySrcSyn); - } - - /** - * The EntityPolySeq object provide the amino acid sequence objects for the Entities. - * Later on the entities are mapped to the BioJava {@link Chain} and {@link EntityInfo} objects. - * @param epolseq the EntityPolySeq record for one amino acid - */ - @Override - public void newEntityPolySeq(EntityPolySeq epolseq) { - - logger.debug("NEW entity poly seq " + epolseq); - - int eId = -1; - try { - eId = Integer.parseInt(epolseq.getEntity_id()); - } catch (NumberFormatException e) { - logger.warn("Could not parse entity id from EntityPolySeq: "+e.getMessage()); - } - Entity e = getEntity(eId); - - if (e == null){ - logger.info("Could not find entity "+ epolseq.getEntity_id()+". Can not match sequence to it."); - return; - } - - Chain entityChain = getEntityChain(epolseq.getEntity_id()); - - // first we check through the chemcomp provider, if it fails we do some heuristics to guess the type of group - // TODO some of this code is analogous to getNewGroup() and we should try to unify them - JD 2016-03-08 - - Group g = ChemCompGroupFactory.getGroupFromChemCompDictionary(epolseq.getMon_id()); - //int seqId = Integer.parseInt(epolseq.getNum()); - if ( g != null && !g.getChemComp().isEmpty()) { - if ( g instanceof AminoAcidImpl) { - AminoAcidImpl aa = (AminoAcidImpl) g; - aa.setRecordType(AminoAcid.SEQRESRECORD); - //aa.setId(seqId); - } - } else { - - if (epolseq.getMon_id().length()==3 && StructureTools.get1LetterCodeAmino(epolseq.getMon_id())!=null){ - AminoAcidImpl a = new AminoAcidImpl(); - a.setRecordType(AminoAcid.SEQRESRECORD); - Character code1 = StructureTools.get1LetterCodeAmino(epolseq.getMon_id()); - a.setAminoType(code1); - g = a; - - } else if ( StructureTools.isNucleotide(epolseq.getMon_id())) { - // the group is actually a nucleotide group... - NucleotideImpl n = new NucleotideImpl(); - g = n; - - } else { - logger.debug("Residue {} {} is not a standard aminoacid or nucleotide, will create a het group for it", epolseq.getNum(),epolseq.getMon_id()); - HetatomImpl h = new HetatomImpl(); - g = h; - - } - - - } - // at this stage we don't know about author residue numbers (insertion codes) - // we abuse now the ResidueNumber field setting the internal residue numbers (label_seq_id, strictly sequential and follow the seqres sequence 1 to n) - // later the actual ResidueNumbers (author residue numbers) have to be corrected in alignSeqRes() - g.setResidueNumber(ResidueNumber.fromString(epolseq.getNum())); - - g.setPDBName(epolseq.getMon_id()); - - entityChain.addGroup(g); - - } - - @Override - public void newPdbxPolySeqScheme(PdbxPolySeqScheme ppss) { - - //if ( headerOnly) - // return; - - // replace the group asym ids with the real PDB ids! - // replaceGroupSeqPos(ppss); // This might be incorrect in some pdb, to use auth_seq_id of the pdbx_poly_seq_scheme. - - - } - - - @Override - public void newPdbxNonPolyScheme(PdbxNonPolyScheme ppss) { - - //if (headerOnly) - // return; - - // merge the EntityPolySeq info and the AtomSite chains into one... - //already known ignore: - - } - - @Override - public void newPdbxEntityNonPoly(PdbxEntityNonPoly pen){ - // TODO: do something with them... - // not implemented yet... - logger.debug(pen.getEntity_id() + " " + pen.getName() + " " + pen.getComp_id()); - - } - - @Override - public void newChemComp(ChemComp c) { - // TODO: do something with them... - - } - - @Override - public void newGenericData(String category, List loopFields, - List lineData) { - - //logger.debug("unhandled category so far: " + category); - } - - @Override - public FileParsingParameters getFileParsingParameters() - { - return params; - } - - @Override - public void setFileParsingParameters(FileParsingParameters params) - { - this.params = params; - - } - - @Override - public void newChemCompDescriptor(ChemCompDescriptor ccd) { - - // TODO nothing happening here yet. - - } - - - - public List getStructOpers() { - return structOpers; - } - - @Override - public void newPdbxStrucAssembly(PdbxStructAssembly strucAssembly) { - strucAssemblies.add(strucAssembly); - - } - - public List getStructAssemblies(){ - return strucAssemblies; - } - - @Override - public void newPdbxStrucAssemblyGen(PdbxStructAssemblyGen strucAssembly) { - strucAssemblyGens.add(strucAssembly); - - } - - public List getStructAssemblyGens(){ - return strucAssemblyGens; - } - - @Override - public void newChemCompAtom(ChemCompAtom atom) { - - } - - @Override - public void newPdbxChemCompIndentifier(PdbxChemCompIdentifier id) { - - } - - @Override - public void newChemCompBond(ChemCompBond bond) { - - } - - @Override - public void newPdbxChemCompDescriptor(PdbxChemCompDescriptor desc) { - - } - - @Override - public void newStructConn(StructConn structConn) { - this.structConn.add(structConn); - } - - @Override - public void newStructSiteGen(StructSiteGen siteGen) { this.structSiteGens.add(siteGen); } - - @Override - public void newStructSite(StructSite structSite) { - - if (params.isHeaderOnly()) { - return; - } - - // Simply implement the method. - List sites = structure.getSites(); - if (sites == null) sites = new ArrayList(); - - Site site = null; - for (Site asite : sites) { - if (asite.getSiteID().equals(structSite.getId())) { - site = asite; // Prevent duplicate siteIds - } - } - boolean addSite = false; - if (site == null) { site = new Site(); addSite = true; } - site.setSiteID(structSite.getId()); - site.setDescription(structSite.getDetails()); - // site.setPdbxEvidenceCode(structSite.getPdbxEvidenceCode()); // TODO - add addition fields in Sites - if (addSite) sites.add(site); - - structure.setSites(sites); - } - - /** - * Build sites in a BioJava Structure using the original author chain id & residue numbers. - * Sites are built from struct_site_gen records that have been parsed. - */ - private void addSites() { - List sites = structure.getSites(); - if (sites == null) sites = new ArrayList(); - - for (StructSiteGen siteGen : structSiteGens) { - // For each StructSiteGen, find the residues involved, if they exist then - String site_id = siteGen.getSite_id(); // multiple could be in same site. - if (site_id == null) site_id = ""; - String comp_id = siteGen.getLabel_comp_id(); // PDBName - - // Assumption: the author chain ID and residue number for the site is consistent with the original - // author chain id and residue numbers. - - String asymId = siteGen.getLabel_asym_id(); // chain name - String authId = siteGen.getAuth_asym_id(); // chain Id - String auth_seq_id = siteGen.getAuth_seq_id(); // Res num - - String insCode = siteGen.getPdbx_auth_ins_code(); - if ( insCode != null && insCode.equals("?")) - insCode = null; - - // Look for asymID = chainID and seqID = seq_ID. Check that comp_id matches the resname. - Group g = null; - try { - Chain chain = structure.getChain(asymId); - - if (null != chain) { - try { - Character insChar = null; - if (null != insCode && insCode.length() > 0) insChar = insCode.charAt(0); - g = chain.getGroupByPDB(new ResidueNumber(null, Integer.parseInt(auth_seq_id), insChar)); - } catch (NumberFormatException e) { - logger.warn("Could not lookup residue : " + authId + auth_seq_id); - } - } - } catch (StructureException e) { - logger.warn("Problem finding residue in site entry " + siteGen.getSite_id() + " - " + e.getMessage(), e.getMessage()); - } - - if (g != null) { - // 2. find the site_id, if not existing, create anew. - Site site = null; - for (Site asite: sites) { - if (site_id.equals(asite.getSiteID())) site = asite; - } - - boolean addSite = false; - - // 3. add this residue to the site. - if (site == null) { - addSite = true; - site = new Site(); - site.setSiteID(site_id); - } - - List groups = site.getGroups(); - if (groups == null) groups = new ArrayList(); - - // Check the self-consistency of the residue reference from auth_seq_id and chain_id - if (!comp_id.equals(g.getPDBName())) { - logger.warn("comp_id doesn't match the residue at " + authId + " " + auth_seq_id + " - skipping"); - } else { - groups.add(g); - site.setGroups(groups); - } - if (addSite) sites.add(site); - } - } - structure.setSites(sites); - } -} 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 deleted file mode 100644 index 7e9b23d3c2..0000000000 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/SimpleMMcifParser.java +++ /dev/null @@ -1,1281 +0,0 @@ -/* - * BioJava development code - * - * This code may be freely distributed and modified under the - * terms of the GNU Lesser General Public Licence. This should - * be distributed with the code. If you do not have a copy, - * see: - * - * http://www.gnu.org/copyleft/lesser.html - * - * Copyright for this code is held jointly by the individual - * authors. These should be listed in @author doc comments. - * - * For more information on the BioJava project and its aims, - * or to join the biojava-l mailing list, visit the home page - * at: - * - * http://www.biojava.org/ - * - * created at Mar 4, 2008 - */ -package org.biojava.nbio.structure.io.mmcif; - -import java.io.BufferedReader; -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; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - - -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.AtomSites; -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; -import org.biojava.nbio.structure.io.mmcif.model.ChemCompBond; -import org.biojava.nbio.structure.io.mmcif.model.ChemCompDescriptor; -import org.biojava.nbio.structure.io.mmcif.model.DatabasePDBremark; -import org.biojava.nbio.structure.io.mmcif.model.DatabasePDBrev; -import org.biojava.nbio.structure.io.mmcif.model.DatabasePdbrevRecord; -import org.biojava.nbio.structure.io.mmcif.model.Entity; -import org.biojava.nbio.structure.io.mmcif.model.EntityPoly; -import org.biojava.nbio.structure.io.mmcif.model.EntityPolySeq; -import org.biojava.nbio.structure.io.mmcif.model.EntitySrcGen; -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.PdbxAuditRevisionHistory; -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.PdbxDatabaseStatus; -import org.biojava.nbio.structure.io.mmcif.model.PdbxEntityNonPoly; -import org.biojava.nbio.structure.io.mmcif.model.PdbxNonPolyScheme; -import org.biojava.nbio.structure.io.mmcif.model.PdbxPolySeqScheme; -import org.biojava.nbio.structure.io.mmcif.model.PdbxStructAssembly; -import org.biojava.nbio.structure.io.mmcif.model.PdbxStructAssemblyGen; -import org.biojava.nbio.structure.io.mmcif.model.PdbxStructOperList; -import org.biojava.nbio.structure.io.mmcif.model.Refine; -import org.biojava.nbio.structure.io.mmcif.model.Struct; -import org.biojava.nbio.structure.io.mmcif.model.StructAsym; -import org.biojava.nbio.structure.io.mmcif.model.StructConn; -import org.biojava.nbio.structure.io.mmcif.model.StructKeywords; -import org.biojava.nbio.structure.io.mmcif.model.StructNcsOper; -import org.biojava.nbio.structure.io.mmcif.model.StructRef; -import org.biojava.nbio.structure.io.mmcif.model.StructRefSeq; -import org.biojava.nbio.structure.io.mmcif.model.StructRefSeqDif; -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.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * A simple mmCif file parser - * - * - * Usage: - *
-String file = "path/to/mmcif/file";
-StructureIOFile pdbreader = new MMCIFFileReader();
-
-Structure s = pdbreader.getStructure(file);
-System.out.println(s);
-
-// you can convert it to a PDB file...
-System.out.println(s.toPDB());
-
- * 
- * For more documentation see http://biojava.org/wiki/BioJava:CookBook#Protein_Structure. - * - * @author Andreas Prlic - * @author Jose Duarte - * @since 1.7 - */ -public class SimpleMMcifParser implements MMcifParser { - - - - /** - * The header appearing at the beginning of a mmCIF file. - * A "block code" can be added to it of no more than 32 chars. - * See http://www.iucr.org/__data/assets/pdf_file/0019/22618/cifguide.pdf - */ - public static final String MMCIF_TOP_HEADER = "data_"; - - public static final String COMMENT_CHAR = "#"; - public static final String LOOP_START = "loop_"; - public static final String FIELD_LINE = "_"; - - // the following are the 3 valid quoting characters in CIF - /** - * Quoting character ' - */ - private static final char S1 = '\''; - - /** - * Quoting character " - */ - private static final char S2 = '\"'; - - /** - * Quoting character ; (multi-line quoting) - */ - public static final String STRING_LIMIT = ";"; - - - private List consumers ; - - private Struct struct ; - - private static final Logger logger = LoggerFactory.getLogger(SimpleMMcifParser.class); - - public SimpleMMcifParser(){ - consumers = new ArrayList(); - struct = null; - } - - @Override - public void addMMcifConsumer(MMcifConsumer consumer) { - consumers.add(consumer); - - } - - @Override - public void clearConsumers() { - consumers.clear(); - - } - - @Override - public void removeMMcifConsumer(MMcifConsumer consumer) { - consumers.remove(consumer); - } - - public static void main(String[] args){ - String file = "/Users/andreas/WORK/PDB/mmCif/a9/1a9n.cif.gz"; - //String file = "/Users/andreas/WORK/PDB/MMCIF/1gav.mmcif"; - //String file = "/Users/andreas/WORK/PDB/MMCIF/100d.cif"; - //String file = "/Users/andreas/WORK/PDB/MMCIF/1a4a.mmcif"; - System.out.println("parsing " + file); - - StructureIOFile pdbreader = new MMCIFFileReader(); - try { - Structure s = pdbreader.getStructure(file); - System.out.println(s); - // convert it to a PDB file... - System.out.println(s.toPDB()); - } catch (IOException e) { - e.printStackTrace(); - } - - } - - @Override - public void parse(InputStream inStream) throws IOException { - parse(new BufferedReader(new InputStreamReader(inStream))); - - } - - @Override - public void parse(BufferedReader buf) - throws IOException { - - triggerDocumentStart(); - - - // init container objects... - struct = new Struct(); - String line = null; - - boolean inLoop = false; - boolean inLoopData = false; - - - List loopFields = new ArrayList(); - List lineData = new ArrayList(); - Set loopWarnings = new HashSet(); // used only to reduce logging statements - - String category = null; - - boolean foundHeader = false; - - while ( (line = buf.readLine ()) != null ){ - - if (line.isEmpty() || line.startsWith(COMMENT_CHAR)) continue; - - if (!foundHeader) { - // the first non-comment line is a data_PDBCODE line, test if this looks like a mmcif file - if (line.startsWith(MMCIF_TOP_HEADER)){ - foundHeader = true; - continue; - } else { - triggerDocumentEnd(); - throw new IOException("This does not look like a valid mmCIF file! The first line should start with 'data_', but is: '" + line+"'"); - } - } - - logger.debug(inLoop + " " + line); - - if (line.startsWith(MMCIF_TOP_HEADER)){ - // either first line in file, or beginning of new section (data block in CIF parlance) - if ( inLoop) { - //System.out.println("new data and in loop: " + line); - inLoop = false; - inLoopData = false; - lineData.clear(); - loopFields.clear(); - } - - } - - - if ( inLoop) { - - - if ( line.startsWith(LOOP_START)){ - loopFields.clear(); - inLoop = true; - inLoopData = false; - continue; - } - - if ( line.matches("\\s*"+FIELD_LINE+"\\w+.*")) { - - if (inLoopData && line.startsWith(FIELD_LINE)) { - logger.debug("Found a field line after reading loop data. Toggling to inLoop=false"); - inLoop = false; - inLoopData = false; - loopFields.clear(); - - - // a boring normal line - List data = processLine(line, buf, 2); - - if ( data.size() < 1){ - // this can happen if empty lines at end of file - lineData.clear(); - continue; - } - String key = data.get(0); - int pos = key.indexOf("."); - if ( pos < 0 ) { - // looks like a chem_comp file - // line should start with data, otherwise something is wrong! - if (! line.startsWith(MMCIF_TOP_HEADER)){ - logger.warn("This does not look like a valid mmCIF file! The first line should start with 'data_', but is '" + line+"'"); - triggerDocumentEnd(); - return; - } - // ignore the first line... - category=null; - lineData.clear(); - continue; - } - category = key.substring(0,pos); - String value = data.get(1); - loopFields.add(key.substring(pos+1,key.length())); - lineData.add(value); - - logger.debug("Found data for category {}: {}", key, value); - continue; - } - - // found another field. - String txt = line.trim(); - if ( txt.indexOf('.') > -1){ - - String[] spl = txt.split("\\."); - category = spl[0]; - String attribute = spl[1]; - loopFields.add(attribute); - logger.debug("Found category: {}, attribute: {}",category, attribute); - if ( spl.length > 2){ - logger.warn("Found nested attribute in {}, not supported yet!",txt); - } - - } else { - category = txt; - logger.debug("Found category without attribute: {}",category); - } - - - } else { - - // in loop and we found a data line - lineData = processLine(line, buf, loopFields.size()); - logger.debug("Found a loop data line with {} data fields", lineData.size()); - logger.debug("Data fields: {}", lineData.toString()); - if ( lineData.size() != loopFields.size()){ - logger.warn("Expected {} data fields, but found {} in line: {}",loopFields.size(),lineData.size(),line); - - } - - endLineChecks(category, loopFields, lineData, loopWarnings); - - lineData.clear(); - - inLoopData = true; - } - - } else { - // not in loop - - if ( line.startsWith(LOOP_START)){ - if ( category != null) - endLineChecks(category, loopFields, lineData, loopWarnings); - - resetBuffers(loopFields, lineData, loopWarnings); - category = null; - inLoop = true; - inLoopData = false; - logger.debug("Detected LOOP_START: '{}'. Toggling to inLoop=true", LOOP_START); - continue; - } else { - logger.debug("Normal line "); - inLoop = false; - - // a boring normal line - List data = processLine(line, buf, 2); - - if ( data.size() < 1){ - // this can happen if empty lines at end of file - lineData.clear(); - continue; - } - String key = data.get(0); - int pos = key.indexOf("."); - if ( pos < 0 ) { - // looks like a chem_comp file - // line should start with data, otherwise something is wrong! - if (! line.startsWith(MMCIF_TOP_HEADER)){ - logger.warn("This does not look like a valid mmCIF file! The first line should start with 'data_', but is '" + line+"'"); - triggerDocumentEnd(); - return; - } - // ignore the first line... - category=null; - lineData.clear(); - continue; - } - - if (category!=null && !key.substring(0,pos).equals(category)) { - // we've changed category: need to flush the previous one - endLineChecks(category, loopFields, lineData, loopWarnings); - resetBuffers(loopFields, lineData, loopWarnings); - } - - category = key.substring(0,pos); - - String value = data.get(1); - loopFields.add(key.substring(pos+1,key.length())); - lineData.add(value); - - logger.debug("Found data for category {}: {}", key, value); - - } - } - } - - if (category!=null && lineData.size()>0 && lineData.size()==loopFields.size()) { - // the last category in the file will still be missing, we add it now - endLineChecks(category, loopFields, lineData, loopWarnings); - resetBuffers(loopFields, lineData, loopWarnings); - } - - if (struct != null){ - triggerStructData(struct); - } - - triggerDocumentEnd(); - - } - - private void resetBuffers(List loopFields, List lineData, Set loopWarnings) { - loopFields.clear(); - lineData.clear(); - loopWarnings.clear(); - } - - private List processSingleLine(String line){ - - List data = new ArrayList(); - - if ( line.trim().length() == 0){ - return data; - } - - if ( line.trim().length() == 1){ - if ( line.startsWith(STRING_LIMIT)) - return data; - } - boolean inString = false; // semicolon (;) quoting - boolean inS1 = false; // single quote (') quoting - boolean inS2 = false; // double quote (") quoting - String word = ""; - - for (int i=0; i< line.length(); i++ ){ - - Character c = line.charAt(i); - - Character nextC = null; - if (i < line.length() - 1) - nextC = line.charAt(i+1); - - Character prevC = null; - if (i>0) - prevC = line.charAt(i-1); - - if (c == ' ') { - - if ( ! inString){ - if ( ! word.equals("")) - data.add(word.trim()); - word = ""; - } else { - // we are in a string, add the space - word += c; - } - - } else if (c == S1 ) { - - if ( inString){ - - boolean wordEnd = false; - if (! inS2) { - if (nextC==null || Character.isWhitespace(nextC)){ - i++; - wordEnd = true; - } - } - - - if ( wordEnd ) { - - // at end of string - if ( ! word.equals("")) - data.add(word.trim()); - word = ""; - inString = false; - inS1 = false; - } else { - word += c; - } - - } else if (prevC==null || prevC==' ') { - // the beginning of a new string - inString = true; - inS1 = true; - } else { - word += c; - } - } else if ( c == S2 ){ - if ( inString){ - - boolean wordEnd = false; - if (! inS1) { - if (nextC==null || Character.isWhitespace(nextC)){ - i++; - wordEnd = true; - } - } - - if ( wordEnd ) { - - // at end of string - if ( ! word.equals("")) - data.add(word.trim()); - word = ""; - inString = false; - inS2 = false; - } else { - word += c; - } - } else if (prevC==null || prevC==' ') { - // the beginning of a new string - inString = true; - inS2 = true; - } else { - word += c; - } - } else { - word += c; - } - - } - if ( ! word.trim().equals("")) - data.add(word); - - - return data; - - } - - /** - * Get the content of a cif entry - * - * @param line - * @param buf - * @return - */ - private List processLine(String line, - BufferedReader buf, - int fieldLength) - throws IOException{ - - //System.out.println("XX processLine " + fieldLength + " " + line); - // go through the line and process each character - List lineData = new ArrayList(); - - boolean inString = false; - - StringBuilder bigWord = null; - - while ( true ){ - - if ( line.startsWith(STRING_LIMIT)){ - if (! inString){ - - inString = true; - if ( line.length() > 1) - bigWord = new StringBuilder(line.substring(1)); - else - bigWord = new StringBuilder(""); - - - } else { - // the end of a word - lineData.add(bigWord.toString()); - bigWord = null; - inString = false; - - } - } else { - if ( inString ) - bigWord.append(line); - else { - - List dat = processSingleLine(line); - - for (String d : dat){ - lineData.add(d); - } - } - } - - //System.out.println("in process line : " + lineData.size() + " " + fieldLength); - - if ( lineData.size() > fieldLength){ - - logger.warn("wrong data length ("+lineData.size()+ - ") should be ("+fieldLength+") at line " + line + " got lineData: " + lineData); - return lineData; - } - - if ( lineData.size() == fieldLength) - return lineData; - - - line = buf.readLine(); - if ( line == null) - break; - } - return lineData; - - } - - - - private void endLineChecks(String category,List loopFields, List lineData, Set loopWarnings ) throws IOException{ - - logger.debug("Processing category {}, with fields: {}",category,loopFields.toString()); - // System.out.println("parsed the following data: " +category + " fields: "+ - // loopFields + " DATA: " + - // lineData); - - if ( loopFields.size() != lineData.size()){ - logger.warn("looks like we got a problem with nested string quote characters:"); - throw new IOException("data length ("+ lineData.size() + - ") != fields length ("+loopFields.size()+ - ") category: " +category + " fields: "+ - loopFields + " DATA: " + - lineData ); - } - - if ( category.equals("_entity")){ - - Entity e = (Entity) buildObject( - Entity.class.getName(), - loopFields,lineData, loopWarnings); - triggerNewEntity(e); - - } else if (category.equals("_entity_poly")) { - EntityPoly ep = (EntityPoly) buildObject(EntityPoly.class.getName(), loopFields, lineData, loopWarnings); - triggerNewEntityPoly(ep); - - } else if ( category.equals("_struct")){ - - struct = (Struct) buildObject( - Struct.class.getName(), - loopFields, lineData, loopWarnings); - - } else if ( category.equals("_atom_site")){ - - AtomSite a = (AtomSite) buildObject( - AtomSite.class.getName(), - loopFields, lineData, loopWarnings); - triggerNewAtomSite(a); - - } else if ( category.equals("_database_PDB_rev")){ - DatabasePDBrev dbrev = (DatabasePDBrev) buildObject( - DatabasePDBrev.class.getName(), - loopFields, lineData, loopWarnings); - - triggerNewDatabasePDBrev(dbrev); - - } else if ( category.equals("_database_PDB_rev_record")){ - DatabasePdbrevRecord dbrev = (DatabasePdbrevRecord) buildObject( - DatabasePdbrevRecord.class.getName(), - loopFields, lineData, loopWarnings); - - triggerNewDatabasePDBrevRecord(dbrev); - - // MMCIF version 5 dates - } else if ( category.equals("_pdbx_audit_revision_history")) { - PdbxAuditRevisionHistory history = (PdbxAuditRevisionHistory) buildObject( - PdbxAuditRevisionHistory.class.getName(), - loopFields, lineData, loopWarnings); - - triggerNewPdbxAuditRevisionHistory(history); - - // MMCIF version 5 dates - } else if ( category.equals("_pdbx_database_status")) { - PdbxDatabaseStatus status = (PdbxDatabaseStatus) buildObject( - PdbxDatabaseStatus.class.getName(), - loopFields, lineData, loopWarnings); - - triggerNewPdbxDatabaseStatus(status); - - }else if ( category.equals("_database_PDB_remark")){ - DatabasePDBremark remark = (DatabasePDBremark) buildObject( - DatabasePDBremark.class.getName(), - loopFields, lineData, loopWarnings); - - triggerNewDatabasePDBremark(remark); - - } else if ( category.equals("_exptl")){ - Exptl exptl = (Exptl) buildObject( - Exptl.class.getName(), - loopFields,lineData, loopWarnings); - - triggerExptl(exptl); - - } else if ( category.equals("_cell")){ - Cell cell = (Cell) buildObject( - Cell.class.getName(), - loopFields,lineData, loopWarnings); - - triggerNewCell(cell); - - } else if ( category.equals("_symmetry")){ - Symmetry symmetry = (Symmetry) buildObject( - Symmetry.class.getName(), - loopFields,lineData, loopWarnings); - - triggerNewSymmetry(symmetry); - } else if ( category.equals("_struct_ncs_oper")) { - - StructNcsOper sNcsOper = (StructNcsOper) buildObject( - StructNcsOper.class.getName(), - loopFields, lineData, loopWarnings); - triggerNewStructNcsOper(sNcsOper); - } else if ( category.equals("_atom_sites")) { - - AtomSites atomSites = (AtomSites) buildObject( - AtomSites.class.getName(), - loopFields, lineData, loopWarnings); - triggerNewAtomSites(atomSites); - - } else if ( category.equals("_struct_ref")){ - StructRef sref = (StructRef) buildObject( - StructRef.class.getName(), - loopFields,lineData, loopWarnings); - - triggerNewStrucRef(sref); - - } else if ( category.equals("_struct_ref_seq")){ - StructRefSeq sref = (StructRefSeq) buildObject( - StructRefSeq.class.getName(), - loopFields,lineData, loopWarnings); - - triggerNewStrucRefSeq(sref); - } else if ( category.equals("_struct_ref_seq_dif")) { - StructRefSeqDif sref = (StructRefSeqDif) buildObject( - StructRefSeqDif.class.getName(), - loopFields, lineData, loopWarnings); - - triggerNewStrucRefSeqDif(sref); - } else if ( category.equals("_struct_site_gen")) { - StructSiteGen sref = (StructSiteGen) buildObject( - StructSiteGen.class.getName(), - loopFields, lineData, loopWarnings); - - triggerNewStructSiteGen(sref); - } else if ( category.equals("_struct_site")) { - StructSite sref = (StructSite) buildObject( - StructSite.class.getName(), - loopFields, lineData, loopWarnings); - triggerNewStructSite(sref); - } else if ( category.equals("_entity_poly_seq")){ - EntityPolySeq exptl = (EntityPolySeq) buildObject( - EntityPolySeq.class.getName(), - loopFields,lineData, loopWarnings); - - triggerNewEntityPolySeq(exptl); - } else if ( category.equals("_entity_src_gen")){ - EntitySrcGen entitySrcGen = (EntitySrcGen) buildObject( - EntitySrcGen.class.getName(), - loopFields,lineData, loopWarnings); - triggerNewEntitySrcGen(entitySrcGen); - } else if ( category.equals("_entity_src_nat")){ - EntitySrcNat entitySrcNat = (EntitySrcNat) buildObject( - EntitySrcNat.class.getName(), - loopFields,lineData, loopWarnings); - triggerNewEntitySrcNat(entitySrcNat); - } else if ( category.equals("_pdbx_entity_src_syn")){ - EntitySrcSyn entitySrcSyn = (EntitySrcSyn) buildObject( - EntitySrcSyn.class.getName(), - loopFields,lineData, loopWarnings); - triggerNewEntitySrcSyn(entitySrcSyn); - } else if ( category.equals("_struct_asym")){ - StructAsym sasym = (StructAsym) buildObject( - StructAsym.class.getName(), - loopFields,lineData, loopWarnings); - - triggerNewStructAsym(sasym); - - } else if ( category.equals("_pdbx_poly_seq_scheme")){ - PdbxPolySeqScheme ppss = (PdbxPolySeqScheme) buildObject( - PdbxPolySeqScheme.class.getName(), - loopFields,lineData, loopWarnings); - - triggerNewPdbxPolySeqScheme(ppss); - - } else if ( category.equals("_pdbx_nonpoly_scheme")){ - PdbxNonPolyScheme ppss = (PdbxNonPolyScheme) buildObject( - PdbxNonPolyScheme.class.getName(), - loopFields,lineData, loopWarnings); - - triggerNewPdbxNonPolyScheme(ppss); - - } else if ( category.equals("_pdbx_entity_nonpoly")){ - PdbxEntityNonPoly pen = (PdbxEntityNonPoly) buildObject( - PdbxEntityNonPoly.class.getName(), - loopFields,lineData, loopWarnings - ); - triggerNewPdbxEntityNonPoly(pen); - } else if ( category.equals("_struct_keywords")){ - StructKeywords kw = (StructKeywords)buildObject( - StructKeywords.class.getName(), - loopFields,lineData, loopWarnings - ); - triggerNewStructKeywords(kw); - } else if (category.equals("_refine")){ - Refine r = (Refine)buildObject( - Refine.class.getName(), - loopFields,lineData, loopWarnings - ); - triggerNewRefine(r); - } else if (category.equals("_chem_comp")){ - ChemComp c = (ChemComp)buildObject( - ChemComp.class.getName(), - loopFields, lineData, loopWarnings - ); - triggerNewChemComp(c); - } else if (category.equals("_audit_author")) { - AuditAuthor aa = (AuditAuthor)buildObject( - AuditAuthor.class.getName(), - loopFields, lineData, loopWarnings); - triggerNewAuditAuthor(aa); - } else if (category.equals("_pdbx_chem_comp_descriptor")) { - ChemCompDescriptor ccd = (ChemCompDescriptor) buildObject( - ChemCompDescriptor.class.getName(), - loopFields, lineData, loopWarnings); - triggerNewChemCompDescriptor(ccd); - } else if (category.equals("_pdbx_struct_oper_list")) { - - 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(), - loopFields, lineData, loopWarnings); - triggerNewPdbxStructAssembly(sa); - - } else if (category.equals("_pdbx_struct_assembly_gen")) { - PdbxStructAssemblyGen sa = (PdbxStructAssemblyGen) buildObject( - PdbxStructAssemblyGen.class.getName(), - loopFields, lineData, loopWarnings); - triggerNewPdbxStructAssemblyGen(sa); - } else if ( category.equals("_chem_comp_atom")){ - ChemCompAtom atom = (ChemCompAtom)buildObject( - ChemCompAtom.class.getName(), - loopFields,lineData, loopWarnings); - triggerNewChemCompAtom(atom); - - }else if ( category.equals("_chem_comp_bond")){ - ChemCompBond bond = (ChemCompBond)buildObject( - ChemCompBond.class.getName(), - loopFields,lineData, loopWarnings); - triggerNewChemCompBond(bond); - } else if ( category.equals("_pdbx_chem_comp_identifier")){ - PdbxChemCompIdentifier id = (PdbxChemCompIdentifier)buildObject( - PdbxChemCompIdentifier.class.getName(), - loopFields,lineData, loopWarnings); - triggerNewPdbxChemCompIdentifier(id); - } else if ( category.equals("_pdbx_chem_comp_descriptor")){ - PdbxChemCompDescriptor id = (PdbxChemCompDescriptor)buildObject( - PdbxChemCompDescriptor.class.getName(), - loopFields,lineData, loopWarnings); - triggerNewPdbxChemCompDescriptor(id); - } else if ( category.equals("_struct_conn")){ - StructConn id = (StructConn)buildObject( - StructConn.class.getName(), - loopFields,lineData, loopWarnings); - triggerNewStructConn(id); - - } else { - - logger.debug("Using a generic bean for category {}",category); - - // trigger a generic bean that can deal with all missing data types... - triggerGeneric(category,loopFields,lineData); - } - - - } - - -// 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){ - c.newPdbxStructOperList(structOper); - } - - } - - public void triggerNewStructNcsOper(StructNcsOper sNcsOper) { - for(MMcifConsumer c : consumers){ - c.newStructNcsOper(sNcsOper); - } - - } - - public void triggerNewAtomSites(AtomSites atomSites) { - for(MMcifConsumer c : consumers){ - c.newAtomSites(atomSites); - } - } - - /** - * 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; - Class c = null; - - try { - // build up the Entity object from the line data... - c = Class.forName(className); - - o = c.newInstance(); - - } catch (InstantiationException|ClassNotFoundException|IllegalAccessException e){ - logger.error( "Error while constructing {}: {}", className, e.getMessage()); - return null; - } - - // these methods get the fields but also looking at the IgnoreField and CIFLabel annotations - Field[] fields = MMCIFFileTools.getFields(c); - String[] names = MMCIFFileTools.getFieldNames(fields); - - // let's build a map of all methods so that we can look up the setter methods later - Method[] methods = c.getMethods(); - - Map methodMap = new HashMap(); - for (Method m : methods) { - methodMap.put(m.getName(),m); - } - - // and a map of all the fields so that we can lookup them up later - Map names2fields = new HashMap<>(); - for (int i=0;i[] pType = setter.getParameterTypes(); - - - try { - if ( pType[0].getName().equals(Integer.class.getName())) { - if ( val != null && ! val.equals("?") && !val.equals(".")) { - - Integer intVal = Integer.parseInt(val); - setter.invoke(o, intVal); - - } - } else { - // default val is a String - setter.invoke(o, val); - } - } 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.info(warning); - } - - if(warnings != null) { - warnings.add(warnkey); - } - - } - - public void triggerGeneric(String category, List loopFields, List lineData){ - for(MMcifConsumer c : consumers){ - c.newGenericData(category, loopFields, lineData); - } - } - - public void triggerNewEntity(Entity entity){ - for(MMcifConsumer c : consumers){ - c.newEntity(entity); - } - } - - public void triggerNewEntityPoly(EntityPoly entityPoly) { - for(MMcifConsumer c : consumers){ - c.newEntityPoly(entityPoly); - } - } - - public void triggerNewEntityPolySeq(EntityPolySeq epolseq){ - for(MMcifConsumer c : consumers){ - c.newEntityPolySeq(epolseq); - } - } - public void triggerNewEntitySrcGen(EntitySrcGen entitySrcGen){ - for(MMcifConsumer c : consumers){ - c.newEntitySrcGen(entitySrcGen); - } - } - public void triggerNewEntitySrcNat(EntitySrcNat entitySrcNat){ - for(MMcifConsumer c : consumers){ - c.newEntitySrcNat(entitySrcNat); - } - } - public void triggerNewEntitySrcSyn(EntitySrcSyn entitySrcSyn){ - for(MMcifConsumer c : consumers){ - c.newEntitySrcSyn(entitySrcSyn); - } - } - public void triggerNewChemComp(ChemComp cc){ - - for(MMcifConsumer c : consumers){ - c.newChemComp(cc); - } - } - public void triggerNewStructAsym(StructAsym sasym){ - for(MMcifConsumer c : consumers){ - c.newStructAsym(sasym); - } - } - - private void triggerStructData(Struct struct){ - for(MMcifConsumer c : consumers){ - c.setStruct(struct); - } - } - - private void triggerNewAtomSite(AtomSite atom){ - for(MMcifConsumer c : consumers){ - c.newAtomSite(atom); - } - } - - private void triggerNewAuditAuthor(AuditAuthor aa){ - for(MMcifConsumer c : consumers){ - c.newAuditAuthor(aa); - } - } - - private void triggerNewPdbxAuditRevisionHistory(PdbxAuditRevisionHistory history) { - for(MMcifConsumer c : consumers){ - c.newPdbxAuditRevisionHistory(history); - } - } - - private void triggerNewPdbxDatabaseStatus(PdbxDatabaseStatus status) { - for(MMcifConsumer c : consumers){ - c.newPdbxDatabaseStatus(status); - } - } - - private void triggerNewDatabasePDBrev(DatabasePDBrev dbrev){ - for(MMcifConsumer c : consumers){ - c.newDatabasePDBrev(dbrev); - } - } - private void triggerNewDatabasePDBrevRecord(DatabasePdbrevRecord dbrev){ - for(MMcifConsumer c : consumers){ - c.newDatabasePDBrevRecord(dbrev); - } - } - - private void triggerNewDatabasePDBremark(DatabasePDBremark remark){ - for(MMcifConsumer c : consumers){ - c.newDatabasePDBremark(remark); - } - } - - private void triggerExptl(Exptl exptl){ - for(MMcifConsumer c : consumers){ - c.newExptl(exptl); - } - } - - private void triggerNewCell(Cell cell) { - for(MMcifConsumer c : consumers){ - c.newCell(cell); - } - } - - private void triggerNewSymmetry(Symmetry symmetry) { - for(MMcifConsumer c : consumers){ - c.newSymmetry(symmetry); - } - } - - private void triggerNewStrucRef(StructRef sref){ - for(MMcifConsumer c : consumers){ - c.newStructRef(sref); - } - } - - private void triggerNewStrucRefSeq(StructRefSeq sref){ - for(MMcifConsumer c : consumers){ - c.newStructRefSeq(sref); - } - } - - private void triggerNewStrucRefSeqDif(StructRefSeqDif sref){ - for(MMcifConsumer c : consumers){ - c.newStructRefSeqDif(sref); - } - } - - private void triggerNewPdbxPolySeqScheme(PdbxPolySeqScheme ppss){ - for(MMcifConsumer c : consumers){ - c.newPdbxPolySeqScheme(ppss); - } - } - private void triggerNewPdbxNonPolyScheme(PdbxNonPolyScheme ppss){ - for(MMcifConsumer c : consumers){ - c.newPdbxNonPolyScheme(ppss); - } - } - public void triggerNewPdbxEntityNonPoly(PdbxEntityNonPoly pen){ - for (MMcifConsumer c: consumers){ - c.newPdbxEntityNonPoly(pen); - } - } - public void triggerNewStructKeywords(StructKeywords kw){ - for (MMcifConsumer c: consumers){ - c.newStructKeywords(kw); - } - } - public void triggerNewRefine(Refine r){ - for (MMcifConsumer c: consumers){ - c.newRefine(r); - } - } - public void triggerDocumentStart(){ - for(MMcifConsumer c : consumers){ - c.documentStart(); - } - } - public void triggerDocumentEnd(){ - for(MMcifConsumer c : consumers){ - c.documentEnd(); - } - } - public void triggerNewChemCompDescriptor(ChemCompDescriptor ccd) { - for(MMcifConsumer c : consumers){ - c.newChemCompDescriptor(ccd); - } - } - private void triggerNewPdbxStructAssembly(PdbxStructAssembly sa) { - for(MMcifConsumer c : consumers){ - c.newPdbxStrucAssembly(sa); - } - } - private void triggerNewPdbxStructAssemblyGen(PdbxStructAssemblyGen sa) { - for(MMcifConsumer c : consumers){ - c.newPdbxStrucAssemblyGen(sa); - } - } - - private void triggerNewChemCompAtom(ChemCompAtom atom) { - for(MMcifConsumer c : consumers){ - c.newChemCompAtom(atom); - } - } - - private void triggerNewChemCompBond(ChemCompBond bond) { - for(MMcifConsumer c : consumers){ - c.newChemCompBond(bond); - } - } - - private void triggerNewPdbxChemCompIdentifier(PdbxChemCompIdentifier id) { - for(MMcifConsumer c : consumers){ - c.newPdbxChemCompIndentifier(id); - } - } - private void triggerNewPdbxChemCompDescriptor(PdbxChemCompDescriptor id) { - for(MMcifConsumer c : consumers){ - c.newPdbxChemCompDescriptor(id); - } - } - private void triggerNewStructConn(StructConn id) { - for(MMcifConsumer c : consumers){ - c.newStructConn(id); - } - } - private void triggerNewStructSiteGen(StructSiteGen id) { - for (MMcifConsumer c : consumers) { - c.newStructSiteGen(id); - } - } - private void triggerNewStructSite(StructSite id) { - for (MMcifConsumer c : consumers) { - c.newStructSite(id); - } - } -} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/ZipChemCompProvider.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/ZipChemCompProvider.java deleted file mode 100644 index 9475a6d036..0000000000 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/ZipChemCompProvider.java +++ /dev/null @@ -1,313 +0,0 @@ -/* - * BioJava development code - * - * This code may be freely distributed and modified under the - * terms of the GNU Lesser General Public Licence. This should - * be distributed with the code. If you do not have a copy, - * see: - * - * http://www.gnu.org/copyleft/lesser.html - * - * Copyright for this code is held jointly by the individual - * authors. These should be listed in @author doc comments. - * - * For more information on the BioJava project and its aims, - * or to join the biojava-l mailing list, visit the home page - * at: - * - * http://www.biojava.org/ - * - */ -package org.biojava.nbio.structure.io.mmcif; - -import java.io.BufferedOutputStream; -import java.io.File; -import java.io.FileOutputStream; -import java.io.FilenameFilter; -import java.io.IOException; -import java.io.InputStream; -import java.nio.file.FileSystem; -import java.nio.file.FileSystems; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.nio.file.StandardCopyOption; -import java.util.HashSet; -import java.util.Set; -import java.util.zip.GZIPInputStream; -import java.util.zip.ZipEntry; -import java.util.zip.ZipOutputStream; - -import org.biojava.nbio.structure.io.mmcif.chem.PolymerType; -import org.biojava.nbio.structure.io.mmcif.chem.ResidueType; -import org.biojava.nbio.structure.io.mmcif.model.ChemComp; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** This chemical component provider retrieves and caches chemical component definition files from a - * zip archive specified in its construction. If the archive does not contain the record, an attempt is - * made to download it using DownloadChemCompProvider. The downloaded file is then added to the archive. - * - * The class is thread-safe and the same ZipChemCompProvider should be used by all threads to prevent - * simultaneous read or write to the zip archive. A zip archive will be created if missing. - * - * @author edlunde - * @author larsonm - * @since 12/05/12 - * updated 3/5/2016 for Java 7 ZipFileSystem - */ -public class ZipChemCompProvider implements ChemCompProvider{ - private static final Logger s_logger = LoggerFactory.getLogger(ZipChemCompProvider.class); - - private final Path m_tempDir; // Base path where $m_zipRootDir/ will be downloaded to. - private final Path m_zipRootDir; - private final Path m_zipFile; - private final DownloadChemCompProvider m_dlProvider; - - private boolean m_removeCif; - - // Missing IDs from library that cannot be download added here to prevent delays. - private Set unavailable = new HashSet(); - - /** - * ZipChemCompProvider is a Chemical Component provider that stores chemical components - * in a zip archive. Missing chemical components are downloaded and appended to the - * archive. If non-existent a new zip archive will be created. - * - * @param chemicalComponentDictionaryFile : path to zip archive for chemical components. - * @param tempDir : path for temporary directory, (null) defaults to path in property "java.io.tmpdir". - * @throws IOException - */ - public ZipChemCompProvider(String chemicalComponentDictionaryFile, String tempDir) throws IOException { - this.m_zipFile = Paths.get(chemicalComponentDictionaryFile); - - // Use a default temporary directory if not passed a value. - if (tempDir == null || tempDir.equals("")) { - this.m_tempDir = Paths.get(System.getProperty("java.io.tmpdir")); - } else { - this.m_tempDir = Paths.get(tempDir); - } - - this.m_zipRootDir = Paths.get("chemcomp"); - - // Setup an instance of the download chemcomp provider. - this.m_dlProvider = new DownloadChemCompProvider(m_tempDir.toString()); - this.m_removeCif = true; - initializeZip(); - } - - // See comments in addToZipFileSystem for why initialization is required with - // ZipFileSystems - due to URI issues in Java7. - private void initializeZip() throws IOException { - s_logger.info("Using chemical component dictionary: " + m_zipFile.toString()); - final File f = m_zipFile.toFile(); - if (!f.exists()) { - s_logger.info("Creating missing zip archive: " + m_zipFile.toString()); - FileOutputStream fo = new FileOutputStream(f); - ZipOutputStream zip = new ZipOutputStream(new BufferedOutputStream(fo)); - try { - zip.putNextEntry(new ZipEntry("chemcomp/")); - zip.closeEntry(); - } finally { - zip.close(); - } - } - } - - /** - * Remove downloaded .cif.gz after adding to zip archive? - * Default is true. - * @param doRemove - */ - public void setRemoveCif(boolean doRemove) { - m_removeCif = doRemove; - } - - /* (non-Javadoc) - * @see org.biojava.nbio.structure.io.mmcif.ChemCompProvider#getChemComp(java.lang.String) - * - * @param recordName : three letter PDB name for a residue - * @return ChemComp from .zip or ChemComp from repository. Will return empty ChemComp when unable to find a residue and will return null if not provided a valid recordName. - */ - @Override - public ChemComp getChemComp(String recordName) { - if (null == recordName) return null; - - // handle non-existent ChemComp codes and do not repeatedly attempt to add these. - for (String str : unavailable) { - if (recordName.equals(str)) return getEmptyChemComp(recordName); - } - - // Try to pull from zip, if fail then download. - ChemComp cc = getFromZip(recordName); - if (cc == null) { - s_logger.info("File "+recordName+" not found in archive. Attempting download from PDB."); - cc = downloadAndAdd(recordName); - } - - // If a null record or an empty chemcomp, return a default ChemComp and blacklist. - if (cc == null || (null == cc.getName() && cc.getAtoms().size() == 0)) { - s_logger.info("Unable to find or download " + recordName + " - excluding from future searches."); - unavailable.add(recordName); - return getEmptyChemComp(recordName); - } - return cc; - } - - /** Use DownloadChemCompProvider to grab a gzipped cif record from the PDB. - * Zip all downloaded cif.gz files into the dictionary. - * - * @param recordName is the three-letter chemical component code (i.e. residue name). - * @return ChemComp matching recordName - */ - private ChemComp downloadAndAdd(String recordName){ - final ChemComp cc = m_dlProvider.getChemComp(recordName); - - // final File [] files = finder(m_tempDir.resolve("chemcomp").toString(), "cif.gz"); - final File [] files = new File[1]; - Path cif = m_tempDir.resolve("chemcomp").resolve(recordName + ".cif.gz"); - files[0] = cif.toFile(); - if (files[0] != null) { - addToZipFileSystem(m_zipFile, files, m_zipRootDir); - if (m_removeCif) for (File f : files) f.delete(); - } - return cc; - } - - /** - * Cleanup chemical component (.cif.gz) files downloaded to tmpdir. - * @param tempdir : path to temporary directory for chemical components - */ - public static void purgeTempFiles(String tempdir) { - if (tempdir == null) return; - - s_logger.info("Removing: "+tempdir); - Path dlPath = Paths.get(tempdir).resolve("chemcomp"); - File[] chemCompOutFiles = finder(dlPath.toString(), "cif.gz"); - if (null != chemCompOutFiles) for (File f : chemCompOutFiles) f.delete(); - dlPath.toFile().delete(); - } - - /** - * Return an empty ChemComp group for a three-letter resName. - * @param resName - * @return - */ - private ChemComp getEmptyChemComp(String resName){ - String pdbName = ""; // Empty string is default - if (null != resName && resName.length() >= 3) { - pdbName = resName.substring(0,3); - } - final ChemComp comp = new ChemComp(); - comp.setOne_letter_code("?"); - comp.setThree_letter_code(pdbName); - comp.setPolymerType(PolymerType.unknown); - comp.setResidueType(ResidueType.atomn); - return comp; - } - - /** - * Return File(s) in dirName that match suffix. - * @param dirName - * @param suffix - * @return - */ - static private File[] finder( String dirName, final String suffix){ - if (null == dirName || null == suffix) { - return null; - } - - final File dir = new File(dirName); - return dir.listFiles(new FilenameFilter() { - @Override - public boolean accept(File dir, String filename) - { return filename.endsWith(suffix); } - } ); - } - - /** - * This is synchronized, along with addToFileSystem to prevent simulatenous reading/writing. - * @param recordName to find in zipfile. - * @return ChemComp if found or null if missing. - */ - private synchronized ChemComp getFromZip(String recordName) { - ChemComp cc = null; - if (!m_zipFile.toFile().exists()) return cc; - final String filename = "chemcomp/" + recordName+".cif.gz"; - - // try with resources block to read from the filesystem. - try (FileSystem fs = FileSystems.newFileSystem(m_zipFile, (ClassLoader) null)) { - Path cif = fs.getPath(filename); - - if (Files.exists(cif)) { - final InputStream zipStream = Files.newInputStream(cif); - final InputStream inputStream = new GZIPInputStream(zipStream); - s_logger.debug("reading " + recordName + " from " + m_zipFile); - final MMcifParser parser = new SimpleMMcifParser(); - final ChemCompConsumer consumer = new ChemCompConsumer(); - parser.addMMcifConsumer(consumer); - parser.parse(inputStream); - inputStream.close(); - - final ChemicalComponentDictionary dict = consumer.getDictionary(); - cc = dict.getChemComp(recordName); - } - } catch (IOException e) { - s_logger.error("Unable to read from zip file : " + e.getMessage()); - } - - return cc; - } - - /** - * Add an array of files to a zip archive. - * Synchronized to prevent simultaneous reading/writing. - * - * @param zipFile is a destination zip archive - * @param files is an array of files to be added - * @param pathWithinArchive is the path within the archive to add files to - * @return true if successfully appended these files. - */ - private synchronized boolean addToZipFileSystem(Path zipFile, File[] files, Path pathWithinArchive) { - boolean ret = false; - - /* URIs in Java 7 cannot have spaces, must use Path instead - * and so, cannot use the properties map to describe need to create - * a new zip archive. ZipChemCompProvider.initilizeZip to creates the - * missing zip file */ - - /* - // convert the filename to a URI - String uriString = "jar:file:" + zipFile.toUri().getPath(); - final URI uri = URI.create(uriString); - - // if filesystem doesn't exist, create one. - final Map env = new HashMap<>(); - // Create a new zip if one isn't present. - if (!zipFile.toFile().exists()) { - System.out.println("Need to create " + zipFile.toString()); - } - env.put("create", String.valueOf(!zipFile.toFile().exists())); - // Specify the encoding as UTF -8 - env.put("encoding", "UTF-8"); - */ - - // Copy in each file. - try (FileSystem zipfs = FileSystems.newFileSystem(zipFile, null)) { - Files.createDirectories(pathWithinArchive); - for (File f : files) { - if (!f.isDirectory() && f.exists()) { - Path externalFile = f.toPath(); - Path pathInZipFile = zipfs.getPath(pathWithinArchive.resolve(f.getName()).toString()); - Files.copy(externalFile, pathInZipFile, - StandardCopyOption.REPLACE_EXISTING); - } - } - ret = true; - } catch (IOException ex) { - s_logger.error("Unable to add entries to Chemical Component zip archive : " + ex.getMessage()); - ret = false; - } - return ret; - } -} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/chem/ChemCompTools.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/chem/ChemCompTools.java deleted file mode 100644 index d1392f5117..0000000000 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/chem/ChemCompTools.java +++ /dev/null @@ -1,261 +0,0 @@ -/* - * BioJava development code - * - * This code may be freely distributed and modified under the - * terms of the GNU Lesser General Public Licence. This should - * be distributed with the code. If you do not have a copy, - * see: - * - * http://www.gnu.org/copyleft/lesser.html - * - * Copyright for this code is held jointly by the individual - * authors. These should be listed in @author doc comments. - * - * For more information on the BioJava project and its aims, - * or to join the biojava-l mailing list, visit the home page - * at: - * - * http://www.biojava.org/ - * - * created at Mar 4, 2008 - */ -package org.biojava.nbio.structure.io.mmcif.chem; - -import org.biojava.nbio.structure.io.mmcif.ChemicalComponentDictionary; -import org.biojava.nbio.structure.io.mmcif.model.ChemComp; - -import java.util.*; - -/** Some tools for working with chemical compounds. - * - * @author Andreas Prlic - * @since 1.7 - * - */ -public class ChemCompTools { - - private static final Character UNKNOWN_ONE_LETTER_CODE = 'X'; - private static final Character UNKNOWN_NUCLEOTIDE = 'N'; - - /** - * Lookup table to convert standard amino acid's monomer ids to one-letter-codes - */ - private static final Map AMINO_ACID_LOOKUP_3TO1; - - /** - * Lookup table to convert standard amino acid's one-letter-codes to monomer ids - */ - private static final Map AMINO_ACID_LOOKUP_1TO3; - - /** - * Lookup table to convert standard nucleic acid's monomer ids to one-letter-codes - */ - private static final Map DNA_LOOKUP_2TO1; - - /** - * Lookup table to convert standard nucleic acid's one-letter-codes to monomer ids - */ - private static final Map DNA_LOOKUP_1TO2; - - /** - * Static block that initializes lookup maps and initializes their ResidueInfo instances - */ - static - { - Map foo = new HashMap(); - foo.put("ALA", 'A'); - foo.put("ASP", 'D'); - foo.put("ASN", 'N'); - foo.put("ASX", 'B'); - foo.put("ARG", 'R'); - foo.put("CYS", 'C'); - foo.put("GLU", 'E'); - foo.put("GLN", 'Q'); - foo.put("GLY", 'G'); - foo.put("GLX", 'Z'); - foo.put("HIS", 'H'); - foo.put("ILE", 'I'); - foo.put("LYS", 'K'); - foo.put("LEU", 'L'); - foo.put("MET", 'M'); - foo.put("PHE", 'F'); - foo.put("PRO", 'P'); - foo.put("SER", 'S'); - foo.put("THR", 'T'); - foo.put("TRP", 'W'); - foo.put("TYR", 'Y'); - foo.put("VAL", 'V'); - AMINO_ACID_LOOKUP_3TO1 = Collections.unmodifiableMap((Collections.synchronizedMap(foo))); - - Map bar = new HashMap(); - bar.put('A', "ALA"); - bar.put('D', "ASP"); - bar.put('N', "ASN"); - bar.put('B', "ASX"); - bar.put('R', "ARG"); - bar.put('C', "CYS"); - bar.put('E', "GLU"); - bar.put('Q', "GLN"); - bar.put('G', "GLY"); - bar.put('Z', "GLX"); - bar.put('H', "HIS"); - bar.put('I', "ILE"); - bar.put('K', "LYS"); - bar.put('L', "LEU"); - bar.put('M', "MET"); - bar.put('F', "PHE"); - bar.put('P', "PRO"); - bar.put('S', "SER"); - bar.put('T', "THR"); - bar.put('W', "TRP"); - bar.put('Y', "TYR"); - bar.put('V', "VAL"); - AMINO_ACID_LOOKUP_1TO3 = Collections.unmodifiableMap(Collections.synchronizedMap(bar)); - - foo = new HashMap(); - foo.put("DA",'A'); - foo.put("DC",'C'); - foo.put("DG",'G'); - foo.put("DI",'I'); - foo.put("DU",'U'); - foo.put("DT",'T'); - DNA_LOOKUP_2TO1 = Collections.unmodifiableMap((Collections.synchronizedMap(foo))); - - bar = new HashMap(); - bar.put('A',"DA"); - bar.put('C',"DC"); - bar.put('G',"DG"); - bar.put('I',"DI"); - bar.put('U',"DU"); - bar.put('T',"DT"); - DNA_LOOKUP_1TO2 = Collections.unmodifiableMap(Collections.synchronizedMap(bar)); - - - // initialise standard chemical components - List stdMonIds = new ArrayList(); - stdMonIds.addAll(AMINO_ACID_LOOKUP_3TO1.keySet()); - stdMonIds.addAll(DNA_LOOKUP_2TO1.keySet()); - - - - } - - public static Character getAminoOneLetter(String chemCompId){ - return AMINO_ACID_LOOKUP_3TO1.get(chemCompId); - } - - - public static Character getDNAOneLetter(String chemCompId){ - return DNA_LOOKUP_2TO1.get(chemCompId) ; - } - - public static String getAminoThreeLetter(Character c){ - return AMINO_ACID_LOOKUP_1TO3.get(c); - } - - public static String getDNATwoLetter(Character c){ - return DNA_LOOKUP_1TO2.get(c); - } - - public static final boolean isStandardChemComp(ChemComp cc){ - - String pid = cc.getMon_nstd_parent_comp_id(); - String one = cc.getOne_letter_code(); - - PolymerType polymerType = cc.getPolymerType(); - - // standard residues have no parent - if ((pid == null) || (pid.equals("?"))){ - - // and they have a one letter code - if ( ( one != null) && ( ! one.equals("?") )){ - - // peptides and dpeptides must not have X - if ( (polymerType == PolymerType.peptide) || - ( polymerType == PolymerType.dpeptide)) { - return performPeptideCheck(cc, one); - - } - if (polymerType == PolymerType.rna){ - return performRNACheck(cc); - } - if (polymerType == PolymerType.dna) { - - return performDNACheck(cc); - - } - - //System.err.println("Non standard chem comp: " + cc); - return false; - } - } - return false; - } - - - private static boolean performRNACheck(ChemComp cc) { - if (cc.getId().length() == 1) - return true; - else - return false; - } - - - private static boolean performDNACheck(ChemComp cc) { - if ( cc.getId().equals(UNKNOWN_NUCLEOTIDE.toString())) - return false; - - Character c = getDNAOneLetter(cc.getId()); - if ( c==null){ - // we did not find it in the list of standard nucleotides - return false; - } - return true; - } - - - private static boolean performPeptideCheck(ChemComp cc, String one) { - if (one.equals(UNKNOWN_ONE_LETTER_CODE.toString())) { - return false; - } - Character c = getAminoOneLetter(cc.getId()); - if ( c==null){ - // we did not find it in the list of standard aminos - return false; - } - return true; - } - - - // TODO: component 175 has 3 chars as a one letter code... - // Figure out what to do with it... - // so does: 4F3,5ZA and others - public static Character getOneLetterCode(ChemComp cc, ChemicalComponentDictionary dictionary){ - if ( cc.getResidueType() == ResidueType.nonPolymer ) - return null; - - if ( cc.isStandard()) - return cc.getOne_letter_code().charAt(0); - - ChemComp parent = dictionary.getParent(cc); - if ( parent == null){ - //System.err.println("parent is null " + cc); - return cc.getOne_letter_code().charAt(0); - } - PolymerType poly = cc.getPolymerType(); - if (( poly == PolymerType.peptide) || ( poly == PolymerType.dpeptide)){ - Character c = getAminoOneLetter(parent.getId()); - if ( c == null) - c = UNKNOWN_ONE_LETTER_CODE; - return c; - } - if ( poly == PolymerType.dna){ - Character c = getDNAOneLetter(parent.getId()); - if (c == null) - c = UNKNOWN_NUCLEOTIDE; - return c; - - } - return cc.getMon_nstd_parent_comp_id().charAt(0); - } -} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/chem/MetalBondDistance.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/chem/MetalBondDistance.java deleted file mode 100644 index ab2658c7e3..0000000000 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/chem/MetalBondDistance.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * BioJava development code - * - * This code may be freely distributed and modified under the - * terms of the GNU Lesser General Public Licence. This should - * be distributed with the code. If you do not have a copy, - * see: - * - * http://www.gnu.org/copyleft/lesser.html - * - * Copyright for this code is held jointly by the individual - * authors. These should be listed in @author doc comments. - * - * For more information on the BioJava project and its aims, - * or to join the biojava-l mailing list, visit the home page - * at: - * - * http://www.biojava.org/ - * - */ -package org.biojava.nbio.structure.io.mmcif.chem; - -/** A bean that contains cutoffs for correctly detecting metal bonds. - * Definitions are in file bond_distance_limits.cif.gz - * - * Created by andreas on 6/9/16. - */ -public class MetalBondDistance { - - private String atomType1; - private String atomType2; - private float lowerLimit; - private float upperLimit; - - public String getAtomType1() { - return atomType1; - } - - public void setAtomType1(String atomType1) { - this.atomType1 = atomType1; - } - - public String getAtomType2() { - return atomType2; - } - - public void setAtomType2(String atomType2) { - this.atomType2 = atomType2; - } - - public float getLowerLimit() { - return lowerLimit; - } - - public void setLowerLimit(float lowerLimit) { - this.lowerLimit = lowerLimit; - } - - public float getUpperLimit() { - return upperLimit; - } - - public void setUpperLimit(float upperLimit) { - this.upperLimit = upperLimit; - } - - @Override - public String toString() { - return "MetalBindDistance{" + - "atomType1='" + atomType1 + '\'' + - ", atomType2='" + atomType2 + '\'' + - ", lowerLimit=" + lowerLimit + - ", upperLimit=" + upperLimit + - '}'; - } -} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/chem/PolymerType.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/chem/PolymerType.java deleted file mode 100644 index d7b4853cf0..0000000000 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/chem/PolymerType.java +++ /dev/null @@ -1,191 +0,0 @@ -/* - * BioJava development code - * - * This code may be freely distributed and modified under the - * terms of the GNU Lesser General Public Licence. This should - * be distributed with the code. If you do not have a copy, - * see: - * - * http://www.gnu.org/copyleft/lesser.html - * - * Copyright for this code is held jointly by the individual - * authors. These should be listed in @author doc comments. - * - * For more information on the BioJava project and its aims, - * or to join the biojava-l mailing list, visit the home page - * at: - * - * http://www.biojava.org/ - * - * - */ -package org.biojava.nbio.structure.io.mmcif.chem; - -import java.io.Serializable; -import java.util.*; - -/** - * Enumerates the classification of polymers. - * This information is derived from the mmcif dictionary - * @author mulvaney - * @author Andreas Prlic - * @see link into mmCIF dictionary - * @since 1.7 - */ -public enum PolymerType implements Serializable -{ - - /** - * polypeptide(L) - */ - peptide("polypeptide(L)"), - - /** - * polypeptide(D) - */ - dpeptide("polypeptide(D)"), - - /** - * polydeoxyribonucleotide - */ - dna("polydeoxyribonucleotide"), - - /** - * polyribonucleotide - */ - rna("polyribonucleotide"), - - /** - * polydeoxyribonucleotide/polyribonucleotide hybrid - */ - dnarna("polydeoxyribonucleotide/polyribonucleotide hybrid"), - - /** - * polysaccharide(D) - */ - polysaccharide("polysaccharide(D)"), - - /** - * polysaccharide(L) - */ - lpolysaccharide("polysaccharide(L)"), - - /** - * other - */ - otherPolymer("other"), - - /** - * cyclic peptides - */ - cyclicPeptide("cyclic-pseudo-peptide"), - - /** - * Peptide nucleic acids - */ - peptideNucleicAcid("peptide nucleic acid"), - - /** - * if all else fails... - */ - unknown(null); - - static Map lookupTable = new HashMap<>(); - - static { - - for (PolymerType rt : PolymerType.values() ) { - if ( rt == unknown) - continue; - lookupTable.put(rt.entity_poly_type,rt); - lookupTable.put(rt.entity_poly_type.toLowerCase(),rt); - } - } - - - PolymerType(String entity_poly_type) - { - this.entity_poly_type = entity_poly_type; - } - public final String entity_poly_type; - - public static PolymerType polymerTypeFromString(String polymerType) - { - - if ( polymerType.equalsIgnoreCase(peptide.entity_poly_type)) - return peptide; - - PolymerType ptype = lookupTable.get(polymerType); - if ( ptype != null) - return ptype; - - ptype = lookupTable.get(polymerType.toLowerCase()); - if ( ptype != null) - return ptype; - - - for(PolymerType pt : PolymerType.values()) - { - if(polymerType.equals(pt.entity_poly_type)) - { - return pt; - } - } - return unknown; - } - - /** - * Convenience Set of polymer types classified as protein. This only contains {@link #peptide} - */ - public static final Set PROTEIN_ONLY; - - /** - * Convenience Set of polymer types classified as DNA. This only contains {@link #dna} - */ - public static final Set DNA_ONLY; - - /** - * Convenience Set of polymer types classified as RNA. This only contains {@link #rna} - */ - public static final Set RNA_ONLY; - - /** - * Convenience Set of polymer types classified as DNA. This contains: - *

    - *
  • {@link #dna}
  • - *
  • {@link #rna}
  • - *
  • {@link #dnarna}
  • - *
- */ - public static final Set POLYNUCLEOTIDE_ONLY; - - /** - * Convenience Set of all polymer types. - */ - public static final Set ALL_POLYMER_TYPES; - - static { - Set tmp; - - tmp = new HashSet(); - tmp.add(peptide); - PROTEIN_ONLY = Collections.unmodifiableSet(tmp); - - tmp = new HashSet(); - tmp.add(dna); - DNA_ONLY = Collections.unmodifiableSet(tmp); - - tmp = new HashSet(); - tmp.add(rna); - RNA_ONLY = Collections.unmodifiableSet(tmp); - - tmp = new HashSet(); - tmp.add(dna); - tmp.add(rna); - tmp.add(dnarna); - POLYNUCLEOTIDE_ONLY = Collections.unmodifiableSet(tmp); - - ALL_POLYMER_TYPES = Collections.unmodifiableSet(new HashSet(Arrays.asList(values()))); - } - -} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/chem/ResidueType.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/chem/ResidueType.java deleted file mode 100644 index d6f6b0a40a..0000000000 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/chem/ResidueType.java +++ /dev/null @@ -1,150 +0,0 @@ -/* - * BioJava development code - * - * This code may be freely distributed and modified under the - * terms of the GNU Lesser General Public Licence. This should - * be distributed with the code. If you do not have a copy, - * see: - * - * http://www.gnu.org/copyleft/lesser.html - * - * Copyright for this code is held jointly by the individual - * authors. These should be listed in @author doc comments. - * - * For more information on the BioJava project and its aims, - * or to join the biojava-l mailing list, visit the home page - * at: - * - * http://www.biojava.org/ - * - * - */ -package org.biojava.nbio.structure.io.mmcif.chem; - -import java.io.Serializable; -import java.util.HashMap; -import java.util.Map; - - -/** - * Enumerates the possible classifications of residues. These are generally more specific than PolymerTypes - * This information is derived from the mmcif dictionary. - * @author mulvaney - * @author Andreas Prlic - * @see link into mmCIF dictionary - * @since 1.7 - */ - -public enum ResidueType implements Serializable { - - atomn(null, "null"), // present in db for _chem_comp.id_ = 'CFL' but not enumerated in dictionary - // Peptides - dPeptideLinking(PolymerType.dpeptide, "D-peptide linking"), - lPeptideLinking(PolymerType.peptide, "L-peptide linking"), - glycine(PolymerType.peptide,"PEPTIDE LINKING"), - peptideLike(PolymerType.otherPolymer, "peptide-like"), - dPeptideAminoTerminus(PolymerType.dpeptide, "D-peptide NH3 amino terminus"), - lPeptideAminoTerminus(PolymerType.peptide, "L-peptide NH3 amino terminus"), - dPeptideCarboxyTerminus(PolymerType.dpeptide, "D-peptide COOH carboxy terminus"), - lPeptideCarboxyTerminus(PolymerType.peptide, "L-peptide COOH carboxy terminus"), - // Nucleotides - dnaLinking(PolymerType.dna, "DNA linking"), - rnaLinking(PolymerType.rna, "RNA linking"), - dna3PrimeTerminus(PolymerType.dna, "DNA OH 3 prime terminus"), - rna3PrimeTerminus(PolymerType.rna, "RNA OH 3 prime terminus"), - dna5PrimeTerminus(PolymerType.dna, "DNA OH 5 prime terminus"), - rna5PrimeTerminus(PolymerType.rna, "RNA OH 5 prime terminus"), - // Sugars - dSaccharide(PolymerType.polysaccharide, "D-saccharide"), - dSaccharide14and14linking(PolymerType.polysaccharide, "D-saccharide 1,4 and 1,4 linking"), - dSaccharide14and16linking(PolymerType.polysaccharide, "D-saccharide 1,4 and 1,6 linking"), - lSaccharide(PolymerType.lpolysaccharide, "L-saccharide"), - lSaccharide14and14linking(PolymerType.lpolysaccharide, "L-saccharide 1,4 and 1,4 linking"), - lSaccharide14and16linking(PolymerType.lpolysaccharide, "L-saccharide 1,4 and 1,6 linking"), - saccharide(PolymerType.polysaccharide, "saccharide"), - // Iso-peptides - dBetaPeptideCGammaLinking(PolymerType.dpeptide,"D-beta-peptide, C-gamma linking"), - dGammaPeptideCDeltaLinking(PolymerType.dpeptide,"D-gamma-peptide, C-delta linking"), - lBetaPeptideCGammaLinking(PolymerType.peptide,"L-beta-peptide, C-gamma linking"), - lGammaPeptideCDeltaLinking(PolymerType.peptide,"L-gamma-peptide, C-delta linking"), - // L nucleotides. As of 2015-04, these are only found in D-DNA hybrids, so they don't have their own PolymerType - lDNALinking(PolymerType.dna,"L-DNA linking"), - lRNALinking(PolymerType.dna,"L-RNA linking"), - // Other - nonPolymer(null, "non-polymer"), - otherChemComp(null, "other"); - - - static Map lookupTable = new HashMap<>(); - - static { - - for (ResidueType rt : ResidueType.values() ) { - lookupTable.put(rt.chem_comp_type,rt); - lookupTable.put(rt.chem_comp_type.toLowerCase(),rt); - } - } - ResidueType(PolymerType pt, String chem_comp_type) - { - this.polymerType = pt; - this.chem_comp_type = chem_comp_type; - - } - - /** - * The associated {@link PolymerType} - */ - public final PolymerType polymerType; - - /** - * Gets the associated PolymerType, which are less specific - * @return - */ - public PolymerType getPolymerType() {return polymerType;} - - /** - * String value of the type - */ - public final String chem_comp_type; - - /** Get ResidueType by chem_comp_type - * - * @param chem_comp_type e.g. L-peptide linking - * @return - */ - public static ResidueType getResidueTypeFromString(String chem_comp_type) - { - - // Almost all calls to this method are for L-peptide linking. Use this knowledge for a shortcut. - - if ( chem_comp_type.equalsIgnoreCase(lPeptideLinking.chem_comp_type) ) - return lPeptideLinking; - - ResidueType rtype = lookupTable.get(chem_comp_type); - if ( rtype != null) - return rtype; - - /** Unfortunately it can be guaranteed that chem_comp_type case sensitivity is preserved. - * E.g. mmtf has it all upper-case. As such we need to do a second check - */ - rtype = lookupTable.get(chem_comp_type.toLowerCase()); - if ( rtype != null) - return rtype; - - - - // preserving previous behaviour. Not sure if this is really necessary? - for(ResidueType rt : ResidueType.values()) - { - if(rt.chem_comp_type.equalsIgnoreCase(chem_comp_type)) - { - return rt; - } - if ( rt.chem_comp_type.toLowerCase().startsWith(chem_comp_type.toLowerCase())) - return rt; - if ( chem_comp_type.toLowerCase().startsWith(rt.chem_comp_type.toLowerCase())) - return rt; - } - return null; - } -} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/AbstractBean.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/AbstractBean.java deleted file mode 100644 index 7dc7b869f5..0000000000 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/AbstractBean.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * BioJava development code - * - * This code may be freely distributed and modified under the - * terms of the GNU Lesser General Public Licence. This should - * be distributed with the code. If you do not have a copy, - * see: - * - * http://www.gnu.org/copyleft/lesser.html - * - * Copyright for this code is held jointly by the individual - * authors. These should be listed in @author doc comments. - * - * For more information on the BioJava project and its aims, - * or to join the biojava-l mailing list, visit the home page - * at: - * - * http://www.biojava.org/ - * - * created at May 31, 2008 - */ -package org.biojava.nbio.structure.io.mmcif.model; - -import org.biojava.nbio.structure.Chain; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.List; - -/** a generic class that implements the toString method for a bean - * - * @author Andreas Prlic - * - */ -public abstract class AbstractBean { - - private static final Logger logger = LoggerFactory.getLogger(AbstractBean.class); - - @Override - @SuppressWarnings({ "unchecked" }) - public String toString(){ - StringBuffer buf = new StringBuffer(); - buf.append(this.getClass().getName()).append(": "); - /* disabled for the moment - - buf.append(" chains: " ); - Iterator iter = chainList.iterator(); - while (iter.hasNext()){ - Chain c = iter.next(); - buf.append (c.getName() + " "); - } - - */ - try { - Class c = this.getClass(); - Method[] methods = c.getMethods(); - - for (int i = 0; i < methods.length; i++) { - Method m = methods[i]; - - String name = m.getName(); - if ( name.substring(0,3).equals("get")) { - - Object o = m.invoke(this, new Object[]{}); - if ( o instanceof String){ - buf.append(name.substring(3, name.length())+": "+ o + " "); - } - else if ( o instanceof List){ - buf.append(name.substring(3, name.length())).append(": "); - - Listlst = (List)o; - for (Object obj : lst){ - if ( obj instanceof Chain){ - continue; - } - buf.append(obj).append(" "); - } - - } - else { - // ignore... - } - } - - } - - } catch (InvocationTargetException e){ - logger.error("Exception caught while producing toString",e); - } catch (IllegalAccessException e) { - logger.error("Exception caught while producing toString",e); - } - - - //if ( organismScientific != null) - // buf.append(" organism scientific: " + organismScientific); - - - return buf.toString(); - } - -} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/AtomSite.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/AtomSite.java deleted file mode 100644 index 93ded0ca45..0000000000 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/AtomSite.java +++ /dev/null @@ -1,218 +0,0 @@ -/* - * BioJava development code - * - * This code may be freely distributed and modified under the - * terms of the GNU Lesser General Public Licence. This should - * be distributed with the code. If you do not have a copy, - * see: - * - * http://www.gnu.org/copyleft/lesser.html - * - * Copyright for this code is held jointly by the individual - * authors. These should be listed in @author doc comments. - * - * For more information on the BioJava project and its aims, - * or to join the biojava-l mailing list, visit the home page - * at: - * - * http://www.biojava.org/ - * - * created at Apr 26, 2008 - */ -package org.biojava.nbio.structure.io.mmcif.model; - -public class AtomSite extends AbstractBean{ - - String group_PDB; - String id; - String type_symbol; - String label_atom_id; - String label_alt_id; - String label_comp_id; - String label_asym_id; - String label_entity_id; - String label_seq_id; - String pdbx_PDB_ins_code; - - String Cartn_x; - String Cartn_y; - String Cartn_z; - String occupancy; - String B_iso_or_equiv; - - String Cartn_x_esd; - String Cartn_y_esd; - String Cartn_z_esd; - String occupancy_esd; - String B_iso_or_equiv_esd; - String pdbx_formal_charge; - - String auth_seq_id; - String auth_comp_id; - String auth_asym_id; - String auth_atom_id; - String pdbx_PDB_model_num; - - - public String getGroup_PDB() { - return group_PDB; - } - public void setGroup_PDB(String group_PDB) { - this.group_PDB = group_PDB; - } - public String getId() { - return id; - } - public void setId(String id) { - this.id = id; - } - public String getType_symbol() { - return type_symbol; - } - public void setType_symbol(String type_symbol) { - this.type_symbol = type_symbol; - } - - public String getLabel_alt_id() { - return label_alt_id; - } - public void setLabel_alt_id(String label_alt_id) { - this.label_alt_id = label_alt_id; - } - public String getLabel_comp_id() { - return label_comp_id; - } - public void setLabel_comp_id(String label_comp_id) { - this.label_comp_id = label_comp_id; - } - public String getLabel_entity_id() { - return label_entity_id; - } - public void setLabel_entity_id(String label_entity_id) { - this.label_entity_id = label_entity_id; - } - public String getLabel_seq_id() { - return label_seq_id; - } - public void setLabel_seq_id(String label_seq_id) { - this.label_seq_id = label_seq_id; - } - public String getPdbx_PDB_ins_code() { - return pdbx_PDB_ins_code; - } - public void setPdbx_PDB_ins_code(String pdbx_PDB_ins_code) { - this.pdbx_PDB_ins_code = pdbx_PDB_ins_code; - } - public String getCartn_x() { - return Cartn_x; - } - public void setCartn_x(String cartn_x) { - Cartn_x = cartn_x; - } - public String getCartn_y() { - return Cartn_y; - } - public void setCartn_y(String cartn_y) { - Cartn_y = cartn_y; - } - public String getCartn_z() { - return Cartn_z; - } - public void setCartn_z(String cartn_z) { - Cartn_z = cartn_z; - } - public String getOccupancy() { - return occupancy; - } - public void setOccupancy(String occupancy) { - this.occupancy = occupancy; - } - public String getB_iso_or_equiv() { - return B_iso_or_equiv; - } - public void setB_iso_or_equiv(String b_iso_or_equiv) { - B_iso_or_equiv = b_iso_or_equiv; - } - public String getCartn_x_esd() { - return Cartn_x_esd; - } - public void setCartn_x_esd(String cartn_x_esd) { - Cartn_x_esd = cartn_x_esd; - } - public String getCartn_y_esd() { - return Cartn_y_esd; - } - public void setCartn_y_esd(String cartn_y_esd) { - Cartn_y_esd = cartn_y_esd; - } - public String getCartn_z_esd() { - return Cartn_z_esd; - } - public void setCartn_z_esd(String cartn_z_esd) { - Cartn_z_esd = cartn_z_esd; - } - public String getAuth_seq_id() { - return auth_seq_id; - } - public void setAuth_seq_id(String auth_seq_id) { - this.auth_seq_id = auth_seq_id; - } - public String getAuth_comp_id() { - return auth_comp_id; - } - public void setAuth_comp_id(String auth_comp_id) { - this.auth_comp_id = auth_comp_id; - } - public String getAuth_asym_id() { - return auth_asym_id; - } - public void setAuth_asym_id(String auth_asym_id) { - this.auth_asym_id = auth_asym_id; - } - public String getAuth_atom_id() { - return auth_atom_id; - } - public void setAuth_atom_id(String auth_atom_id) { - this.auth_atom_id = auth_atom_id; - } - public String getPdbx_PDB_model_num() { - return pdbx_PDB_model_num; - } - public void setPdbx_PDB_model_num(String pdbx_PDB_model_num) { - this.pdbx_PDB_model_num = pdbx_PDB_model_num; - } - public String getLabel_atom_id() { - return label_atom_id; - } - public void setLabel_atom_id(String label_atom_id) { - this.label_atom_id = label_atom_id; - } - public String getLabel_asym_id() { - return label_asym_id; - } - public void setLabel_asym_id(String label_asym_id) { - this.label_asym_id = label_asym_id; - } - public String getOccupancy_esd() { - return occupancy_esd; - } - public void setOccupancy_esd(String occupancy_esd) { - this.occupancy_esd = occupancy_esd; - } - public String getB_iso_or_equiv_esd() { - return B_iso_or_equiv_esd; - } - public void setB_iso_or_equiv_esd(String b_iso_or_equiv_esd) { - B_iso_or_equiv_esd = b_iso_or_equiv_esd; - } - public String getPdbx_formal_charge() { - return pdbx_formal_charge; - } - public void setPdbx_formal_charge(String pdbx_formal_charge) { - this.pdbx_formal_charge = pdbx_formal_charge; - } - - - - -} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/AtomSites.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/AtomSites.java deleted file mode 100644 index 9e4db8b683..0000000000 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/AtomSites.java +++ /dev/null @@ -1,421 +0,0 @@ -/* - * BioJava development code - * - * This code may be freely distributed and modified under the - * terms of the GNU Lesser General Public Licence. This should - * be distributed with the code. If you do not have a copy, - * see: - * - * http://www.gnu.org/copyleft/lesser.html - * - * Copyright for this code is held jointly by the individual - * authors. These should be listed in @author doc comments. - * - * For more information on the BioJava project and its aims, - * or to join the biojava-l mailing list, visit the home page - * at: - * - * http://www.biojava.org/ - * - */ -package org.biojava.nbio.structure.io.mmcif.model; - -/** - * A class containing the _atom_sites data. Equivalent to the SCALE records in PDB files. - * - * - * @author Jose Duarte - * - */ -public class AtomSites extends AbstractBean { - - String entry_id; - - // to my knowledge this field is not used - JD 2016-11-22 - String Cartn_transform_axes; - - @CIFLabel(label="fract_transf_matrix[1][1]") - String fract_transf_matrix11; - - @CIFLabel(label="fract_transf_matrix[1][2]") - String fract_transf_matrix12; - - @CIFLabel(label="fract_transf_matrix[1][3]") - String fract_transf_matrix13; - - - @CIFLabel(label="fract_transf_matrix[2][1]") - String fract_transf_matrix21; - - @CIFLabel(label="fract_transf_matrix[2][2]") - String fract_transf_matrix22; - - @CIFLabel(label="fract_transf_matrix[2][3]") - String fract_transf_matrix23; - - - @CIFLabel(label="fract_transf_matrix[3][1]") - String fract_transf_matrix31; - - @CIFLabel(label="fract_transf_matrix[3][2]") - String fract_transf_matrix32; - - @CIFLabel(label="fract_transf_matrix[3][3]") - String fract_transf_matrix33; - - - @CIFLabel(label="fract_transf_vector[1]") - String fract_transf_vector1; - - @CIFLabel(label="fract_transf_vector[2]") - String fract_transf_vector2; - - @CIFLabel(label="fract_transf_vector[3]") - String fract_transf_vector3; - - // these fields are unusual but appear in some entries like 5e5j - JD 2016-11-22 - @CIFLabel(label="Cartn_transf_matrix[1][1]") - String Cartn_transf_matrix11; - - @CIFLabel(label="Cartn_transf_matrix[1][2]") - String Cartn_transf_matrix12; - - @CIFLabel(label="Cartn_transf_matrix[1][3]") - String Cartn_transf_matrix13; - - @CIFLabel(label="Cartn_transf_matrix[2][1]") - String Cartn_transf_matrix21; - - @CIFLabel(label="Cartn_transf_matrix[2][2]") - String Cartn_transf_matrix22; - - @CIFLabel(label="Cartn_transf_matrix[2][3]") - String Cartn_transf_matrix23; - - @CIFLabel(label="Cartn_transf_matrix[3][1]") - String Cartn_transf_matrix31; - - @CIFLabel(label="Cartn_transf_matrix[3][2]") - String Cartn_transf_matrix32; - - @CIFLabel(label="Cartn_transf_matrix[3][3]") - String Cartn_transf_matrix33; - - @CIFLabel(label="Cartn_transf_vector[1]") - String Cartn_transf_vector1; - - @CIFLabel(label="Cartn_transf_vector[2]") - String Cartn_transf_vector2; - - @CIFLabel(label="Cartn_transf_vector[3]") - String Cartn_transf_vector3; - - - public String getEntry_id() { - return entry_id; - } - public void setEntry_id(String entry_id) { - this.entry_id = entry_id; - } - /** - * @return the cartn_transform_axes - */ - public String getCartn_transform_axes() { - return Cartn_transform_axes; - } - /** - * @param cartn_transform_axes the cartn_transform_axes to set - */ - public void setCartn_transform_axes(String cartn_transform_axes) { - Cartn_transform_axes = cartn_transform_axes; - } - /** - * @return the fract_transf_matrix11 - */ - public String getFract_transf_matrix11() { - return fract_transf_matrix11; - } - /** - * @param fract_transf_matrix11 the fract_transf_matrix11 to set - */ - public void setFract_transf_matrix11(String fract_transf_matrix11) { - this.fract_transf_matrix11 = fract_transf_matrix11; - } - /** - * @return the fract_transf_matrix12 - */ - public String getFract_transf_matrix12() { - return fract_transf_matrix12; - } - /** - * @param fract_transf_matrix12 the fract_transf_matrix12 to set - */ - public void setFract_transf_matrix12(String fract_transf_matrix12) { - this.fract_transf_matrix12 = fract_transf_matrix12; - } - /** - * @return the fract_transf_matrix13 - */ - public String getFract_transf_matrix13() { - return fract_transf_matrix13; - } - /** - * @param fract_transf_matrix13 the fract_transf_matrix13 to set - */ - public void setFract_transf_matrix13(String fract_transf_matrix13) { - this.fract_transf_matrix13 = fract_transf_matrix13; - } - /** - * @return the fract_transf_matrix21 - */ - public String getFract_transf_matrix21() { - return fract_transf_matrix21; - } - /** - * @param fract_transf_matrix21 the fract_transf_matrix21 to set - */ - public void setFract_transf_matrix21(String fract_transf_matrix21) { - this.fract_transf_matrix21 = fract_transf_matrix21; - } - /** - * @return the fract_transf_matrix22 - */ - public String getFract_transf_matrix22() { - return fract_transf_matrix22; - } - /** - * @param fract_transf_matrix22 the fract_transf_matrix22 to set - */ - public void setFract_transf_matrix22(String fract_transf_matrix22) { - this.fract_transf_matrix22 = fract_transf_matrix22; - } - /** - * @return the fract_transf_matrix23 - */ - public String getFract_transf_matrix23() { - return fract_transf_matrix23; - } - /** - * @param fract_transf_matrix23 the fract_transf_matrix23 to set - */ - public void setFract_transf_matrix23(String fract_transf_matrix23) { - this.fract_transf_matrix23 = fract_transf_matrix23; - } - /** - * @return the fract_transf_matrix31 - */ - public String getFract_transf_matrix31() { - return fract_transf_matrix31; - } - /** - * @param fract_transf_matrix31 the fract_transf_matrix31 to set - */ - public void setFract_transf_matrix31(String fract_transf_matrix31) { - this.fract_transf_matrix31 = fract_transf_matrix31; - } - /** - * @return the fract_transf_matrix32 - */ - public String getFract_transf_matrix32() { - return fract_transf_matrix32; - } - /** - * @param fract_transf_matrix32 the fract_transf_matrix32 to set - */ - public void setFract_transf_matrix32(String fract_transf_matrix32) { - this.fract_transf_matrix32 = fract_transf_matrix32; - } - /** - * @return the fract_transf_matrix33 - */ - public String getFract_transf_matrix33() { - return fract_transf_matrix33; - } - /** - * @param fract_transf_matrix33 the fract_transf_matrix33 to set - */ - public void setFract_transf_matrix33(String fract_transf_matrix33) { - this.fract_transf_matrix33 = fract_transf_matrix33; - } - /** - * @return the fract_transf_vector1 - */ - public String getFract_transf_vector1() { - return fract_transf_vector1; - } - /** - * @param fract_transf_vector1 the fract_transf_vector1 to set - */ - public void setFract_transf_vector1(String fract_transf_vector1) { - this.fract_transf_vector1 = fract_transf_vector1; - } - /** - * @return the fract_transf_vector2 - */ - public String getFract_transf_vector2() { - return fract_transf_vector2; - } - /** - * @param fract_transf_vector2 the fract_transf_vector2 to set - */ - public void setFract_transf_vector2(String fract_transf_vector2) { - this.fract_transf_vector2 = fract_transf_vector2; - } - /** - * @return the fract_transf_vector3 - */ - public String getFract_transf_vector3() { - return fract_transf_vector3; - } - /** - * @param fract_transf_vector3 the fract_transf_vector3 to set - */ - public void setFract_transf_vector3(String fract_transf_vector3) { - this.fract_transf_vector3 = fract_transf_vector3; - } - /** - * @return the cartn_transf_matrix11 - */ - public String getCartn_transf_matrix11() { - return Cartn_transf_matrix11; - } - /** - * @param cartn_transf_matrix11 the cartn_transf_matrix11 to set - */ - public void setCartn_transf_matrix11(String cartn_transf_matrix11) { - Cartn_transf_matrix11 = cartn_transf_matrix11; - } - /** - * @return the cartn_transf_matrix12 - */ - public String getCartn_transf_matrix12() { - return Cartn_transf_matrix12; - } - /** - * @param cartn_transf_matrix12 the cartn_transf_matrix12 to set - */ - public void setCartn_transf_matrix12(String cartn_transf_matrix12) { - Cartn_transf_matrix12 = cartn_transf_matrix12; - } - /** - * @return the cartn_transf_matrix13 - */ - public String getCartn_transf_matrix13() { - return Cartn_transf_matrix13; - } - /** - * @param cartn_transf_matrix13 the cartn_transf_matrix13 to set - */ - public void setCartn_transf_matrix13(String cartn_transf_matrix13) { - Cartn_transf_matrix13 = cartn_transf_matrix13; - } - /** - * @return the cartn_transf_matrix21 - */ - public String getCartn_transf_matrix21() { - return Cartn_transf_matrix21; - } - /** - * @param cartn_transf_matrix21 the cartn_transf_matrix21 to set - */ - public void setCartn_transf_matrix21(String cartn_transf_matrix21) { - Cartn_transf_matrix21 = cartn_transf_matrix21; - } - /** - * @return the cartn_transf_matrix22 - */ - public String getCartn_transf_matrix22() { - return Cartn_transf_matrix22; - } - /** - * @param cartn_transf_matrix22 the cartn_transf_matrix22 to set - */ - public void setCartn_transf_matrix22(String cartn_transf_matrix22) { - Cartn_transf_matrix22 = cartn_transf_matrix22; - } - /** - * @return the cartn_transf_matrix23 - */ - public String getCartn_transf_matrix23() { - return Cartn_transf_matrix23; - } - /** - * @param cartn_transf_matrix23 the cartn_transf_matrix23 to set - */ - public void setCartn_transf_matrix23(String cartn_transf_matrix23) { - Cartn_transf_matrix23 = cartn_transf_matrix23; - } - /** - * @return the cartn_transf_matrix31 - */ - public String getCartn_transf_matrix31() { - return Cartn_transf_matrix31; - } - /** - * @param cartn_transf_matrix31 the cartn_transf_matrix31 to set - */ - public void setCartn_transf_matrix31(String cartn_transf_matrix31) { - Cartn_transf_matrix31 = cartn_transf_matrix31; - } - /** - * @return the cartn_transf_matrix32 - */ - public String getCartn_transf_matrix32() { - return Cartn_transf_matrix32; - } - /** - * @param cartn_transf_matrix32 the cartn_transf_matrix32 to set - */ - public void setCartn_transf_matrix32(String cartn_transf_matrix32) { - Cartn_transf_matrix32 = cartn_transf_matrix32; - } - /** - * @return the cartn_transf_matrix33 - */ - public String getCartn_transf_matrix33() { - return Cartn_transf_matrix33; - } - /** - * @param cartn_transf_matrix33 the cartn_transf_matrix33 to set - */ - public void setCartn_transf_matrix33(String cartn_transf_matrix33) { - Cartn_transf_matrix33 = cartn_transf_matrix33; - } - /** - * @return the cartn_transf_vector1 - */ - public String getCartn_transf_vector1() { - return Cartn_transf_vector1; - } - /** - * @param cartn_transf_vector1 the cartn_transf_vector1 to set - */ - public void setCartn_transf_vector1(String cartn_transf_vector1) { - Cartn_transf_vector1 = cartn_transf_vector1; - } - /** - * @return the cartn_transf_vector2 - */ - public String getCartn_transf_vector2() { - return Cartn_transf_vector2; - } - /** - * @param cartn_transf_vector2 the cartn_transf_vector2 to set - */ - public void setCartn_transf_vector2(String cartn_transf_vector2) { - Cartn_transf_vector2 = cartn_transf_vector2; - } - /** - * @return the cartn_transf_vector3 - */ - public String getCartn_transf_vector3() { - return Cartn_transf_vector3; - } - /** - * @param cartn_transf_vector3 the cartn_transf_vector3 to set - */ - public void setCartn_transf_vector3(String cartn_transf_vector3) { - Cartn_transf_vector3 = cartn_transf_vector3; - } - -} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/AuditAuthor.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/AuditAuthor.java deleted file mode 100644 index 4cfc0962c7..0000000000 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/AuditAuthor.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * PDB web development code - * - * This code may be freely distributed and modified under the - * terms of the GNU Lesser General Public Licence. This should - * be distributed with the code. If you do not have a copy, - * see: - * - * http://www.gnu.org/copyleft/lesser.html - * - * Copyright for this code is held jointly by the individual - * authors. These should be listed in @author doc comments. - * - * - * Created on Jul 25, 2009 - * Created by Andreas Prlic - * - */ - -package org.biojava.nbio.structure.io.mmcif.model; - -public class AuditAuthor -{ - String name; - String pdbx_ordinal; - String address; - public String getName() - { - return name; - } - public void setName(String name) - { - this.name = name; - } - public String getPdbx_ordinal() - { - return pdbx_ordinal; - } - public void setPdbx_ordinal(String pdbx_ordinal) - { - this.pdbx_ordinal = pdbx_ordinal; - } - public String getAddress() { - return address; - } - public void setAddress(String address) { - this.address = address; - } - - -} 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 deleted file mode 100644 index 17775df70f..0000000000 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/CIFLabel.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * BioJava development code - * - * This code may be freely distributed and modified under the - * terms of the GNU Lesser General Public Licence. This should - * be distributed with the code. If you do not have a copy, - * see: - * - * http://www.gnu.org/copyleft/lesser.html - * - * Copyright for this code is held jointly by the individual - * authors. These should be listed in @author doc comments. - * - * For more information on the BioJava project and its aims, - * or to join the biojava-l mailing list, visit the home page - * at: - * - * http://www.biojava.org/ - * - */ -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 deleted file mode 100644 index 59804fa821..0000000000 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/Cell.java +++ /dev/null @@ -1,143 +0,0 @@ -/* - * BioJava development code - * - * This code may be freely distributed and modified under the - * terms of the GNU Lesser General Public Licence. This should - * be distributed with the code. If you do not have a copy, - * see: - * - * http://www.gnu.org/copyleft/lesser.html - * - * Copyright for this code is held jointly by the individual - * authors. These should be listed in @author doc comments. - * - * For more information on the BioJava project and its aims, - * or to join the biojava-l mailing list, visit the home page - * at: - * - * http://www.biojava.org/ - * - */ -package org.biojava.nbio.structure.io.mmcif.model; - -public class Cell extends AbstractBean { - - String entry_id; - String length_a; - String length_b; - String length_c; - String angle_alpha; - String angle_beta; - String angle_gamma; - String Z_PDB; - String pdbx_unique_axis; - - // some PDB entries like 1aac have the extra esd fields - String length_a_esd; - String length_b_esd; - String length_c_esd; - String angle_alpha_esd; - String angle_beta_esd; - String angle_gamma_esd; - - String volume; - - public String getEntry_id() { - return entry_id; - } - public void setEntry_id(String entry_id) { - this.entry_id = entry_id; - } - public String getLength_a() { - return length_a; - } - public void setLength_a(String length_a) { - this.length_a = length_a; - } - public String getLength_b() { - return length_b; - } - public void setLength_b(String length_b) { - this.length_b = length_b; - } - public String getLength_c() { - return length_c; - } - public void setLength_c(String length_c) { - this.length_c = length_c; - } - public String getAngle_alpha() { - return angle_alpha; - } - public void setAngle_alpha(String angle_alpha) { - this.angle_alpha = angle_alpha; - } - public String getAngle_beta() { - return angle_beta; - } - public void setAngle_beta(String angle_beta) { - this.angle_beta = angle_beta; - } - public String getAngle_gamma() { - return angle_gamma; - } - public void setAngle_gamma(String angle_gamma) { - this.angle_gamma = angle_gamma; - } - public String getZ_PDB() { - return Z_PDB; - } - public void setZ_PDB(String z_PDB) { - Z_PDB = z_PDB; - } - public String getPdbx_unique_axis() { - return pdbx_unique_axis; - } - public void setPdbx_unique_axis(String pdbx_unique_axis) { - this.pdbx_unique_axis = pdbx_unique_axis; - } - public String getLength_a_esd() { - return length_a_esd; - } - public void setLength_a_esd(String length_a_esd) { - this.length_a_esd = length_a_esd; - } - public String getLength_b_esd() { - return length_b_esd; - } - public void setLength_b_esd(String length_b_esd) { - this.length_b_esd = length_b_esd; - } - public String getLength_c_esd() { - return length_c_esd; - } - public void setLength_c_esd(String length_c_esd) { - this.length_c_esd = length_c_esd; - } - public String getAngle_alpha_esd() { - return angle_alpha_esd; - } - public void setAngle_alpha_esd(String angle_alpha_esd) { - this.angle_alpha_esd = angle_alpha_esd; - } - public String getAngle_beta_esd() { - return angle_beta_esd; - } - public void setAngle_beta_esd(String angle_beta_esd) { - this.angle_beta_esd = angle_beta_esd; - } - public String getAngle_gamma_esd() { - return angle_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 deleted file mode 100644 index cb38de1755..0000000000 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/ChemComp.java +++ /dev/null @@ -1,618 +0,0 @@ -/* - * BioJava development code - * - * This code may be freely distributed and modified under the - * terms of the GNU Lesser General Public Licence. This should - * be distributed with the code. If you do not have a copy, - * see: - * - * http://www.gnu.org/copyleft/lesser.html - * - * Copyright for this code is held jointly by the individual - * authors. These should be listed in @author doc comments. - * - * For more information on the BioJava project and its aims, - * or to join the biojava-l mailing list, visit the home page - * at: - * - * http://www.biojava.org/ - * - */ -package org.biojava.nbio.structure.io.mmcif.model; - -import org.biojava.nbio.structure.io.mmcif.chem.ChemCompTools; -import org.biojava.nbio.structure.io.mmcif.chem.PolymerType; -import org.biojava.nbio.structure.io.mmcif.chem.ResidueType; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.List; - -/** A definition for a Chemical Component, as maintained by the wwPDB. For access to all definitions, - * please download the components.cif.gz file from the wwPDB website. - * - * @author Andreas Prlic - * - */ -public class ChemComp implements Serializable, Comparable{ - /** - * - */ - private static final long serialVersionUID = -4736341142030215915L; - - private String id ; - private String name; - private String type; - private String pdbx_type; - private String formula; - private String mon_nstd_parent_comp_id; - private String pdbx_synonyms; - private String pdbx_formal_charge; - private String pdbx_initial_date ; - private String pdbx_modified_date; - private String pdbx_ambiguous_flag; - private String pdbx_release_status ; - private String pdbx_replaced_by; - private String pdbx_replaces; - private String formula_weight; - private String one_letter_code; - private String three_letter_code; - private String pdbx_model_coordinates_details; - private String pdbx_model_coordinates_missing_flag; - private String pdbx_ideal_coordinates_details; - private String pdbx_ideal_coordinates_missing_flag; - private String pdbx_model_coordinates_db_code; - private String pdbx_subcomponent_list; - 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 - public String toString(){ - StringBuffer buf = new StringBuffer("ChemComp "); - buf.append(id); - buf.append(" "); - buf.append(one_letter_code); - buf.append(" "); - buf.append(three_letter_code); - buf.append(" poly:"); - buf.append(getPolymerType()); - buf.append(" resi:"); - buf.append(getResidueType()); - if (isStandard()) - buf.append(" standard"); - else - buf.append(" modified"); - buf.append(" "); - - buf.append(name); - buf.append(" "); - buf.append(pdbx_type); - buf.append(" "); - buf.append(formula); - buf.append(" parent:"); - buf.append(mon_nstd_parent_comp_id); - return buf.toString(); - } - - public boolean hasParent(){ - String pid = mon_nstd_parent_comp_id; - if ((pid != null ) && (! pid.equals("?"))){ - return true; - } - return false; - } - - public boolean isStandard(){ - return standard; - } - - private void setStandardFlag(){ - standard = ChemCompTools.isStandardChemComp(this); - } - - - - public String getId() { - return id; - } - public void setId(String id) { - this.id = id; - } - public String getName() { - return name; - } - public void setName(String name) { - this.name = name; - } - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - - residueType = ResidueType.getResidueTypeFromString(type); - if ( residueType != null){ - polymerType = residueType.polymerType; - } - - } - - - public ResidueType getResidueType() { - return residueType; - } - - public void setResidueType(ResidueType residueType) { - this.residueType = residueType; - } - - public PolymerType getPolymerType() { - return polymerType; - } - - public void setPolymerType(PolymerType polymerType) { - this.polymerType = polymerType; - } - - public String getPdbx_type() { - return pdbx_type; - } - public void setPdbx_type(String pdbx_type) { - this.pdbx_type = pdbx_type; - } - public String getFormula() { - return formula; - } - public void setFormula(String formula) { - this.formula = formula; - } - public String getMon_nstd_parent_comp_id() { - return mon_nstd_parent_comp_id; - } - public void setMon_nstd_parent_comp_id(String mon_nstd_parent_comp_id) { - this.mon_nstd_parent_comp_id = mon_nstd_parent_comp_id; - setStandardFlag(); - } - public String getPdbx_synonyms() { - return pdbx_synonyms; - } - public void setPdbx_synonyms(String pdbx_synonyms) { - this.pdbx_synonyms = pdbx_synonyms; - } - public String getPdbx_formal_charge() { - return pdbx_formal_charge; - } - public void setPdbx_formal_charge(String pdbx_formal_charge) { - this.pdbx_formal_charge = pdbx_formal_charge; - } - public String getPdbx_initial_date() { - return pdbx_initial_date; - } - public void setPdbx_initial_date(String pdbx_initial_date) { - this.pdbx_initial_date = pdbx_initial_date; - } - public String getPdbx_modified_date() { - return pdbx_modified_date; - } - public void setPdbx_modified_date(String pdbx_modified_date) { - this.pdbx_modified_date = pdbx_modified_date; - } - public String getPdbx_ambiguous_flag() { - return pdbx_ambiguous_flag; - } - public void setPdbx_ambiguous_flag(String pdbx_ambiguous_flag) { - this.pdbx_ambiguous_flag = pdbx_ambiguous_flag; - } - public String getPdbx_release_status() { - return pdbx_release_status; - } - public void setPdbx_release_status(String pdbx_release_status) { - this.pdbx_release_status = pdbx_release_status; - } - public String getPdbx_replaced_by() { - return pdbx_replaced_by; - } - public void setPdbx_replaced_by(String pdbx_replaced_by) { - this.pdbx_replaced_by = pdbx_replaced_by; - } - public String getPdbx_replaces() { - return pdbx_replaces; - } - public void setPdbx_replaces(String pdbx_replaces) { - this.pdbx_replaces = pdbx_replaces; - } - public String getFormula_weight() { - return formula_weight; - } - public void setFormula_weight(String formula_weight) { - this.formula_weight = formula_weight; - } - public String getOne_letter_code() { - return one_letter_code; - } - public void setOne_letter_code(String one_letter_code) { - this.one_letter_code = one_letter_code; - setStandardFlag(); - } - public String getThree_letter_code() { - return three_letter_code; - } - public void setThree_letter_code(String three_letter_code) { - this.three_letter_code = three_letter_code; - } - public String getPdbx_model_coordinates_details() { - return pdbx_model_coordinates_details; - } - public void setPdbx_model_coordinates_details( - String pdbx_model_coordinates_details) { - this.pdbx_model_coordinates_details = pdbx_model_coordinates_details; - } - public String getPdbx_model_coordinates_missing_flag() { - return pdbx_model_coordinates_missing_flag; - } - public void setPdbx_model_coordinates_missing_flag( - String pdbx_model_coordinates_missing_flag) { - this.pdbx_model_coordinates_missing_flag = pdbx_model_coordinates_missing_flag; - } - public String getPdbx_ideal_coordinates_details() { - return pdbx_ideal_coordinates_details; - } - public void setPdbx_ideal_coordinates_details( - String pdbx_ideal_coordinates_details) { - this.pdbx_ideal_coordinates_details = pdbx_ideal_coordinates_details; - } - public String getPdbx_ideal_coordinates_missing_flag() { - return pdbx_ideal_coordinates_missing_flag; - } - public void setPdbx_ideal_coordinates_missing_flag( - String pdbx_ideal_coordinates_missing_flag) { - this.pdbx_ideal_coordinates_missing_flag = pdbx_ideal_coordinates_missing_flag; - } - public String getPdbx_model_coordinates_db_code() { - return pdbx_model_coordinates_db_code; - } - public void setPdbx_model_coordinates_db_code( - String pdbx_model_coordinates_db_code) { - this.pdbx_model_coordinates_db_code = pdbx_model_coordinates_db_code; - } - public String getPdbx_subcomponent_list() { - return pdbx_subcomponent_list; - } - public void setPdbx_subcomponent_list(String pdbx_subcomponent_list) { - this.pdbx_subcomponent_list = pdbx_subcomponent_list; - } - public String getPdbx_processing_site() { - return pdbx_processing_site; - } - public void setPdbx_processing_site(String pdbx_processing_site) { - this.pdbx_processing_site = pdbx_processing_site; - } - - public void setStandard(boolean standard) { - this.standard = standard; - } - - public String getMon_nstd_flag() - { - return mon_nstd_flag; - } - - public void setMon_nstd_flag(String mon_nstd_flag) - { - this.mon_nstd_flag = mon_nstd_flag; - } - - public List getDescriptors() { - return descriptors; - } - - public void setDescriptors(List descriptors) { - this.descriptors = descriptors; - } - - public List getBonds() { - return bonds; - } - - public void setBonds(List bonds) { - this.bonds = bonds; - } - - public List getAtoms() { - return atoms; - } - - public void setAtoms(List atoms) { - this.atoms = atoms; - } - - @Override - public int compareTo(ChemComp arg0) { - if ( this.equals(arg0)) - return 0; - return this.getId().compareTo(arg0.getId()); - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result - + ((descriptors == null) ? 0 : descriptors.hashCode()); - result = prime * result + ((formula == null) ? 0 : formula.hashCode()); - result = prime * result - + ((formula_weight == null) ? 0 : formula_weight.hashCode()); - result = prime * result + ((id == null) ? 0 : id.hashCode()); - result = prime * result - + ((mon_nstd_flag == null) ? 0 : mon_nstd_flag.hashCode()); - result = prime - * result - + ((mon_nstd_parent_comp_id == null) ? 0 - : mon_nstd_parent_comp_id.hashCode()); - result = prime * result + ((name == null) ? 0 : name.hashCode()); - result = prime * result - + ((one_letter_code == null) ? 0 : one_letter_code.hashCode()); - result = prime - * result - + ((pdbx_ambiguous_flag == null) ? 0 : pdbx_ambiguous_flag - .hashCode()); - result = prime - * result - + ((pdbx_formal_charge == null) ? 0 : pdbx_formal_charge - .hashCode()); - result = prime - * result - + ((pdbx_ideal_coordinates_details == null) ? 0 - : pdbx_ideal_coordinates_details.hashCode()); - result = prime - * result - + ((pdbx_ideal_coordinates_missing_flag == null) ? 0 - : pdbx_ideal_coordinates_missing_flag.hashCode()); - result = prime - * result - + ((pdbx_initial_date == null) ? 0 : pdbx_initial_date - .hashCode()); - result = prime - * result - + ((pdbx_model_coordinates_db_code == null) ? 0 - : pdbx_model_coordinates_db_code.hashCode()); - result = prime - * result - + ((pdbx_model_coordinates_details == null) ? 0 - : pdbx_model_coordinates_details.hashCode()); - result = prime - * result - + ((pdbx_model_coordinates_missing_flag == null) ? 0 - : pdbx_model_coordinates_missing_flag.hashCode()); - result = prime - * result - + ((pdbx_modified_date == null) ? 0 : pdbx_modified_date - .hashCode()); - result = prime - * result - + ((pdbx_processing_site == null) ? 0 : pdbx_processing_site - .hashCode()); - result = prime - * result - + ((pdbx_release_status == null) ? 0 : pdbx_release_status - .hashCode()); - result = prime - * result - + ((pdbx_replaced_by == null) ? 0 : pdbx_replaced_by.hashCode()); - result = prime * result - + ((pdbx_replaces == null) ? 0 : pdbx_replaces.hashCode()); - result = prime - * result - + ((pdbx_subcomponent_list == null) ? 0 - : pdbx_subcomponent_list.hashCode()); - result = prime * result - + ((pdbx_synonyms == null) ? 0 : pdbx_synonyms.hashCode()); - result = prime * result - + ((pdbx_type == null) ? 0 : pdbx_type.hashCode()); - result = prime * result - + ((polymerType == null) ? 0 : polymerType.hashCode()); - result = prime * result - + ((residueType == null) ? 0 : residueType.hashCode()); - result = prime * result + (standard ? 1231 : 1237); - result = prime - * result - + ((three_letter_code == null) ? 0 : three_letter_code - .hashCode()); - result = prime * result + ((type == null) ? 0 : type.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - ChemComp other = (ChemComp) obj; - if (descriptors == null) { - if (other.descriptors != null) - return false; - } else if (!descriptors.equals(other.descriptors)) - return false; - if (formula == null) { - if (other.formula != null) - return false; - } else if (!formula.equals(other.formula)) - return false; - if (formula_weight == null) { - if (other.formula_weight != null) - return false; - } else if (!formula_weight.equals(other.formula_weight)) - return false; - if (id == null) { - if (other.id != null) - return false; - } else if (!id.equals(other.id)) - return false; - if (mon_nstd_flag == null) { - if (other.mon_nstd_flag != null) - return false; - } else if (!mon_nstd_flag.equals(other.mon_nstd_flag)) - return false; - if (mon_nstd_parent_comp_id == null) { - if (other.mon_nstd_parent_comp_id != null) - return false; - } else if (!mon_nstd_parent_comp_id - .equals(other.mon_nstd_parent_comp_id)) - return false; - if (name == null) { - if (other.name != null) - return false; - } else if (!name.equals(other.name)) - return false; - if (one_letter_code == null) { - if (other.one_letter_code != null) - return false; - } else if (!one_letter_code.equals(other.one_letter_code)) - return false; - if (pdbx_ambiguous_flag == null) { - if (other.pdbx_ambiguous_flag != null) - return false; - } else if (!pdbx_ambiguous_flag.equals(other.pdbx_ambiguous_flag)) - return false; - if (pdbx_formal_charge == null) { - if (other.pdbx_formal_charge != null) - return false; - } else if (!pdbx_formal_charge.equals(other.pdbx_formal_charge)) - return false; - if (pdbx_ideal_coordinates_details == null) { - if (other.pdbx_ideal_coordinates_details != null) - return false; - } else if (!pdbx_ideal_coordinates_details - .equals(other.pdbx_ideal_coordinates_details)) - return false; - if (pdbx_ideal_coordinates_missing_flag == null) { - if (other.pdbx_ideal_coordinates_missing_flag != null) - return false; - } else if (!pdbx_ideal_coordinates_missing_flag - .equals(other.pdbx_ideal_coordinates_missing_flag)) - return false; - if (pdbx_initial_date == null) { - if (other.pdbx_initial_date != null) - return false; - } else if (!pdbx_initial_date.equals(other.pdbx_initial_date)) - return false; - if (pdbx_model_coordinates_db_code == null) { - if (other.pdbx_model_coordinates_db_code != null) - return false; - } else if (!pdbx_model_coordinates_db_code - .equals(other.pdbx_model_coordinates_db_code)) - return false; - if (pdbx_model_coordinates_details == null) { - if (other.pdbx_model_coordinates_details != null) - return false; - } else if (!pdbx_model_coordinates_details - .equals(other.pdbx_model_coordinates_details)) - return false; - if (pdbx_model_coordinates_missing_flag == null) { - if (other.pdbx_model_coordinates_missing_flag != null) - return false; - } else if (!pdbx_model_coordinates_missing_flag - .equals(other.pdbx_model_coordinates_missing_flag)) - return false; - if (pdbx_modified_date == null) { - if (other.pdbx_modified_date != null) - return false; - } else if (!pdbx_modified_date.equals(other.pdbx_modified_date)) - return false; - if (pdbx_processing_site == null) { - if (other.pdbx_processing_site != null) - return false; - } else if (!pdbx_processing_site.equals(other.pdbx_processing_site)) - return false; - if (pdbx_release_status == null) { - if (other.pdbx_release_status != null) - return false; - } else if (!pdbx_release_status.equals(other.pdbx_release_status)) - return false; - if (pdbx_replaced_by == null) { - if (other.pdbx_replaced_by != null) - return false; - } else if (!pdbx_replaced_by.equals(other.pdbx_replaced_by)) - return false; - if (pdbx_replaces == null) { - if (other.pdbx_replaces != null) - return false; - } else if (!pdbx_replaces.equals(other.pdbx_replaces)) - return false; - if (pdbx_subcomponent_list == null) { - if (other.pdbx_subcomponent_list != null) - return false; - } else if (!pdbx_subcomponent_list.equals(other.pdbx_subcomponent_list)) - return false; - if (pdbx_synonyms == null) { - if (other.pdbx_synonyms != null) - return false; - } else if (!pdbx_synonyms.equals(other.pdbx_synonyms)) - return false; - if (pdbx_type == null) { - if (other.pdbx_type != null) - return false; - } else if (!pdbx_type.equals(other.pdbx_type)) - return false; - if (polymerType != other.polymerType) - return false; - if (residueType != other.residueType) - return false; - if (standard != other.standard) - return false; - if (three_letter_code == null) { - if (other.three_letter_code != null) - return false; - } else if (!three_letter_code.equals(other.three_letter_code)) - return false; - if (type == null) { - if (other.type != null) - return false; - } else if (!type.equals(other.type)) - return false; - return true; - } - - /** - * Creates a new instance of the dummy empty ChemComp. - * @return - */ - public static ChemComp getEmptyChemComp(){ - ChemComp comp = new ChemComp(); - - comp.setOne_letter_code("?"); - comp.setThree_letter_code("???"); // Main signal for isEmpty() - comp.setPolymerType(PolymerType.unknown); - comp.setResidueType(ResidueType.atomn); - return comp; - } - - /** - * Indicates whether this compound was created with - * @return - */ - public boolean isEmpty() { - // Is this the best flag for it being empty? - return id == null || getThree_letter_code() == null || getThree_letter_code().equals("???"); - } - -} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/ChemCompAtom.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/ChemCompAtom.java deleted file mode 100644 index 81d0f64b4b..0000000000 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/ChemCompAtom.java +++ /dev/null @@ -1,219 +0,0 @@ -/** - * BioJava development code - * - * This code may be freely distributed and modified under the - * terms of the GNU Lesser General Public Licence. This should - * be distributed with the code. If you do not have a copy, - * see: - * - * http://www.gnu.org/copyleft/lesser.html - * - * Copyright for this code is held jointly by the individual - * authors. These should be listed in @author doc comments. - * - * For more information on the BioJava project and its aims, - * or to join the biojava-l mailing list, visit the home page - * at: - * - * http://www.biojava.org/ - * - * Created on Feb 5, 2013 - * Created by Andreas Prlic - * - * @since 3.0.6 - */ -package org.biojava.nbio.structure.io.mmcif.model; - -import java.io.Serializable; - -/** stores these fields: - * - * _chem_comp_atom.comp_id -_chem_comp_atom.atom_id -_chem_comp_atom.alt_atom_id -_chem_comp_atom.type_symbol -_chem_comp_atom.charge -_chem_comp_atom.pdbx_align -_chem_comp_atom.pdbx_aromatic_flag -_chem_comp_atom.pdbx_leaving_atom_flag -_chem_comp_atom.pdbx_stereo_config -_chem_comp_atom.model_Cartn_x -_chem_comp_atom.model_Cartn_y -_chem_comp_atom.model_Cartn_z -_chem_comp_atom.pdbx_model_Cartn_x_ideal -_chem_comp_atom.pdbx_model_Cartn_y_ideal -_chem_comp_atom.pdbx_model_Cartn_z_ideal -_chem_comp_atom.pdbx_component_comp_id -_chem_comp_atom.pdbx_residue_numbering -_chem_comp_atom.pdbx_component_atom_id -_chem_comp_atom.pdbx_polymer_type -_chem_comp_atom.pdbx_ref_id -_chem_comp_atom.pdbx_component_id -_chem_comp_atom.pdbx_ordinal - * - * @author Andreas Prlic - * - */ -public class ChemCompAtom implements Serializable{ - /** - * - */ - private static final long serialVersionUID = 4070599340294758941L; - String comp_id; - String atom_id; - String alt_atom_id; - String type_symbol; - String charge; - String pdbx_align; - String pdbx_aromatic_flag; - String pdbx_leaving_atom_flag; - String pdbx_stereo_config; - String model_Cartn_x; - String model_Cartn_y; - String model_Cartn_z; - String pdbx_model_Cartn_x_ideal; - String pdbx_model_Cartn_y_ideal; - String pdbx_model_Cartn_z_ideal; - String pdbx_component_comp_id; - String pdbx_residue_numbering; - String pdbx_component_atom_id; - String pdbx_polymer_type; - String pdbx_ref_id; - String pdbx_component_id; - String pdbx_ordinal; - public String getComp_id() { - return comp_id; - } - public void setComp_id(String comp_id) { - this.comp_id = comp_id; - } - public String getAtom_id() { - return atom_id; - } - public void setAtom_id(String atom_id) { - this.atom_id = atom_id; - } - public String getAlt_atom_id() { - return alt_atom_id; - } - public void setAlt_atom_id(String alt_atom_id) { - this.alt_atom_id = alt_atom_id; - } - public String getType_symbol() { - return type_symbol; - } - public void setType_symbol(String type_symbol) { - this.type_symbol = type_symbol; - } - public String getCharge() { - return charge; - } - public void setCharge(String charge) { - this.charge = charge; - } - public String getPdbx_align() { - return pdbx_align; - } - public void setPdbx_align(String pdbx_align) { - this.pdbx_align = pdbx_align; - } - public String getPdbx_aromatic_flag() { - return pdbx_aromatic_flag; - } - public void setPdbx_aromatic_flag(String pdbx_aromatic_flag) { - this.pdbx_aromatic_flag = pdbx_aromatic_flag; - } - public String getPdbx_leaving_atom_flag() { - return pdbx_leaving_atom_flag; - } - public void setPdbx_leaving_atom_flag(String pdbx_leaving_atom_flag) { - this.pdbx_leaving_atom_flag = pdbx_leaving_atom_flag; - } - public String getPdbx_stereo_config() { - return pdbx_stereo_config; - } - public void setPdbx_stereo_config(String pdbx_stereo_config) { - this.pdbx_stereo_config = pdbx_stereo_config; - } - public String getModel_Cartn_x() { - return model_Cartn_x; - } - public void setModel_Cartn_x(String model_Cartn_x) { - this.model_Cartn_x = model_Cartn_x; - } - public String getModel_Cartn_y() { - return model_Cartn_y; - } - public void setModel_Cartn_y(String model_Cartn_y) { - this.model_Cartn_y = model_Cartn_y; - } - public String getModel_Cartn_z() { - return model_Cartn_z; - } - public void setModel_Cartn_z(String model_Cartn_z) { - this.model_Cartn_z = model_Cartn_z; - } - public String getPdbx_model_Cartn_x_ideal() { - return pdbx_model_Cartn_x_ideal; - } - public void setPdbx_model_Cartn_x_ideal(String pdbx_model_Cartn_x_ideal) { - this.pdbx_model_Cartn_x_ideal = pdbx_model_Cartn_x_ideal; - } - public String getPdbx_model_Cartn_y_ideal() { - return pdbx_model_Cartn_y_ideal; - } - public void setPdbx_model_Cartn_y_ideal(String pdbx_model_Cartn_y_ideal) { - this.pdbx_model_Cartn_y_ideal = pdbx_model_Cartn_y_ideal; - } - public String getPdbx_model_Cartn_z_ideal() { - return pdbx_model_Cartn_z_ideal; - } - public void setPdbx_model_Cartn_z_ideal(String pdbx_model_Cartn_z_ideal) { - this.pdbx_model_Cartn_z_ideal = pdbx_model_Cartn_z_ideal; - } - public String getPdbx_component_comp_id() { - return pdbx_component_comp_id; - } - public void setPdbx_component_comp_id(String pdbx_component_comp_id) { - this.pdbx_component_comp_id = pdbx_component_comp_id; - } - public String getPdbx_residue_numbering() { - return pdbx_residue_numbering; - } - public void setPdbx_residue_numbering(String pdbx_residue_numbering) { - this.pdbx_residue_numbering = pdbx_residue_numbering; - } - public String getPdbx_component_atom_id() { - return pdbx_component_atom_id; - } - public void setPdbx_component_atom_id(String pdbx_component_atom_id) { - this.pdbx_component_atom_id = pdbx_component_atom_id; - } - public String getPdbx_polymer_type() { - return pdbx_polymer_type; - } - public void setPdbx_polymer_type(String pdbx_polymer_type) { - this.pdbx_polymer_type = pdbx_polymer_type; - } - public String getPdbx_ref_id() { - return pdbx_ref_id; - } - public void setPdbx_ref_id(String pdbx_ref_id) { - this.pdbx_ref_id = pdbx_ref_id; - } - public String getPdbx_component_id() { - return pdbx_component_id; - } - public void setPdbx_component_id(String pdbx_component_id) { - this.pdbx_component_id = pdbx_component_id; - } - public String getPdbx_ordinal() { - return pdbx_ordinal; - } - public void setPdbx_ordinal(String pdbx_ordinal) { - this.pdbx_ordinal = pdbx_ordinal; - } - - - -} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/ChemCompBond.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/ChemCompBond.java deleted file mode 100644 index cd49d3b116..0000000000 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/ChemCompBond.java +++ /dev/null @@ -1,133 +0,0 @@ -/** - * BioJava development code - * - * This code may be freely distributed and modified under the - * terms of the GNU Lesser General Public Licence. This should - * be distributed with the code. If you do not have a copy, - * see: - * - * http://www.gnu.org/copyleft/lesser.html - * - * Copyright for this code is held jointly by the individual - * authors. These should be listed in @author doc comments. - * - * For more information on the BioJava project and its aims, - * or to join the biojava-l mailing list, visit the home page - * at: - * - * http://www.biojava.org/ - * - * Created on Feb 5, 2013 - * Created by Andreas Prlic - * - * @since 3.0.2 - */ -package org.biojava.nbio.structure.io.mmcif.model; - -import java.io.Serializable; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - - -/* - * _chem_comp_bond.comp_id -_chem_comp_bond.atom_id_1 -_chem_comp_bond.atom_id_2 -_chem_comp_bond.value_order -_chem_comp_bond.pdbx_aromatic_flag -_chem_comp_bond.pdbx_stereo_config -_chem_comp_bond.pdbx_ordinal - */ -public class ChemCompBond implements Serializable { - - private static final long serialVersionUID = 5905371029161975421L; - - private static final Logger logger = LoggerFactory.getLogger(ChemCompBond.class); - - String comp_id; - String atom_id_1; - String atom_id_2; - String value_order; - String pdbx_aromatic_flag; - String pdbx_stereo_config; - String pdbx_ordinal; - public String getComp_id() { - return comp_id; - } - public void setComp_id(String comp_id) { - this.comp_id = comp_id; - } - public String getAtom_id_1() { - return atom_id_1; - } - public void setAtom_id_1(String atom_id_1) { - this.atom_id_1 = atom_id_1; - } - public String getAtom_id_2() { - return atom_id_2; - } - public void setAtom_id_2(String atom_id_2) { - this.atom_id_2 = atom_id_2; - } - public String getValue_order() { - return value_order; - } - public void setValue_order(String value_order) { - this.value_order = value_order; - } - public String getPdbx_aromatic_flag() { - return pdbx_aromatic_flag; - } - public void setPdbx_aromatic_flag(String pdbx_aromatic_flag) { - this.pdbx_aromatic_flag = pdbx_aromatic_flag; - } - public String getPdbx_stereo_config() { - return pdbx_stereo_config; - } - public void setPdbx_stereo_config(String pdbx_stereo_config) { - this.pdbx_stereo_config = pdbx_stereo_config; - } - public String getPdbx_ordinal() { - return pdbx_ordinal; - } - public void setPdbx_ordinal(String pdbx_ordinal) { - this.pdbx_ordinal = pdbx_ordinal; - } - - /** - * Converts this ChemCompBond's value_order attribute into an int using the - * conversion: - * - *
-	 * 	SING -> 1
-	 * 	DOUB -> 2
-	 * 	TRIP -> 3
-	 * 	QUAD -> 4
-	 * 
- * - * Any other values will return -1. - *

- * (Source: - * http://mmcif.rcsb.org/dictionaries/mmcif_mdb.dic/Items/_chem_comp_bond. - * value_order.html) - * - * @return the numerical value of this ChemCompBond's bond order, or -1 if - * the value is non-numeric or unknown. - */ - public int getNumericalBondOrder() { - if (value_order.equals("SING")) { - return 1; - } else if (value_order.equals("DOUB")) { - return 2; - } else if (value_order.equals("TRIP")) { - return 3; - } else if (value_order.equals("QUAD")) { - return 4; - } else { - logger.error("Unknown or non-numeric value for value_order: " - + value_order); - return -1; - } - } -} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/ChemCompDescriptor.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/ChemCompDescriptor.java deleted file mode 100644 index 7441e59a5a..0000000000 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/ChemCompDescriptor.java +++ /dev/null @@ -1,136 +0,0 @@ -/* - * BioJava development code - * - * This code may be freely distributed and modified under the - * terms of the GNU Lesser General Public Licence. This should - * be distributed with the code. If you do not have a copy, - * see: - * - * http://www.gnu.org/copyleft/lesser.html - * - * Copyright for this code is held jointly by the individual - * authors. These should be listed in @author doc comments. - * - * For more information on the BioJava project and its aims, - * or to join the biojava-l mailing list, visit the home page - * at: - * - * http://www.biojava.org/ - * - * created at Feb 22, 2011 - */ - -package org.biojava.nbio.structure.io.mmcif.model; - -import java.io.Serializable; - - -/** Container object for _pdbx_chem_comp_descriptor - * - * @author Andreas Prlic - * @since 3.2 - * - */ -public class ChemCompDescriptor implements Serializable { - /** - * - */ - private static final long serialVersionUID = 1078685833800736278L; - String comp_id; - String type; - String program; - String program_version; - String descriptor; - - public ChemCompDescriptor(){ - - } - public String getComp_id() { - return comp_id; - } - public void setComp_id(String comp_id) { - this.comp_id = comp_id; - } - public String getType() { - return type; - } - public void setType(String type) { - this.type = type; - } - public String getProgram() { - return program; - } - public void setProgram(String program) { - this.program = program; - } - public String getProgram_version() { - return program_version; - } - public void setProgram_version(String program_version) { - this.program_version = program_version; - } - public String getDescriptor() { - return descriptor; - } - public void setDescriptor(String descriptor) { - this.descriptor = descriptor; - } - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((comp_id == null) ? 0 : comp_id.hashCode()); - result = prime * result - + ((descriptor == null) ? 0 : descriptor.hashCode()); - result = prime * result + ((program == null) ? 0 : program.hashCode()); - result = prime * result - + ((program_version == null) ? 0 : program_version.hashCode()); - result = prime * result + ((type == null) ? 0 : type.hashCode()); - return result; - } - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - ChemCompDescriptor other = (ChemCompDescriptor) obj; - if (comp_id == null) { - if (other.comp_id != null) - return false; - } else if (!comp_id.equals(other.comp_id)) - return false; - if (descriptor == null) { - if (other.descriptor != null) - return false; - } else if (!descriptor.equals(other.descriptor)) - return false; - if (program == null) { - if (other.program != null) - return false; - } else if (!program.equals(other.program)) - return false; - if (program_version == null) { - if (other.program_version != null) - return false; - } else if (!program_version.equals(other.program_version)) - return false; - if (type == null) { - if (other.type != null) - return false; - } else if (!type.equals(other.type)) - return false; - return true; - } - @Override - public String toString() { - return "ChemCompDescriptor [comp_id=" + comp_id + ", type=" + type - + ", program=" + program + ", program_version=" - + program_version + ", descriptor=" + descriptor + "]"; - } - - - -} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/DatabasePDBremark.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/DatabasePDBremark.java deleted file mode 100644 index cc30c0a226..0000000000 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/DatabasePDBremark.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * BioJava development code - * - * This code may be freely distributed and modified under the - * terms of the GNU Lesser General Public Licence. This should - * be distributed with the code. If you do not have a copy, - * see: - * - * http://www.gnu.org/copyleft/lesser.html - * - * Copyright for this code is held jointly by the individual - * authors. These should be listed in @author doc comments. - * - * For more information on the BioJava project and its aims, - * or to join the biojava-l mailing list, visit the home page - * at: - * - * http://www.biojava.org/ - * - * created at May 31, 2008 - */ -package org.biojava.nbio.structure.io.mmcif.model; - -public class DatabasePDBremark extends AbstractBean { - String id; - String text; - public String getId() { - return id; - } - public void setId(String id) { - this.id = id; - } - public String getText() { - return text; - } - public void setText(String text) { - this.text = text; - } - - -} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/DatabasePDBrev.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/DatabasePDBrev.java deleted file mode 100644 index ef884327e3..0000000000 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/DatabasePDBrev.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * BioJava development code - * - * This code may be freely distributed and modified under the - * terms of the GNU Lesser General Public Licence. This should - * be distributed with the code. If you do not have a copy, - * see: - * - * http://www.gnu.org/copyleft/lesser.html - * - * Copyright for this code is held jointly by the individual - * authors. These should be listed in @author doc comments. - * - * For more information on the BioJava project and its aims, - * or to join the biojava-l mailing list, visit the home page - * at: - * - * http://www.biojava.org/ - * - * created at Apr 27, 2008 - */ -package org.biojava.nbio.structure.io.mmcif.model; - -public class DatabasePDBrev { - String date; - String date_original; - String status; - String replaces; - String mod_type; - String num; - - @Override - public String toString(){ - StringBuffer buf = new StringBuffer(); - buf.append("DatabasePDBrev "); - buf.append("mod_type :"); - buf.append(mod_type); - buf.append(" "); - buf.append(this.getDate()); - buf.append( " "); - buf.append( this.getDate_original()); - - return buf.toString(); - } - public String getNum() { - return num; - } - public void setNum(String num) { - this.num = num; - } - public String getDate() { - return date; - } - public void setDate(String date) { - this.date = date; - } - public String getDate_original() { - return date_original; - } - public void setDate_original(String date_original) { - this.date_original = date_original; - } - public String getStatus() { - return status; - } - public void setStatus(String status) { - this.status = status; - } - public String getReplaces() { - return replaces; - } - public void setReplaces(String replaces) { - this.replaces = replaces; - } - public String getMod_type() { - return mod_type; - } - public void setMod_type(String mod_type) { - this.mod_type = mod_type; - } - - -} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/DatabasePdbrevRecord.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/DatabasePdbrevRecord.java deleted file mode 100644 index 72beda99c8..0000000000 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/DatabasePdbrevRecord.java +++ /dev/null @@ -1,69 +0,0 @@ - -/* - * BioJava development code - * - * This code may be freely distributed and modified under the - * terms of the GNU Lesser General Public Licence. This should - * be distributed with the code. If you do not have a copy, - * see: - * - * http://www.gnu.org/copyleft/lesser.html - * - * Copyright for this code is held jointly by the individual - * authors. These should be listed in @author doc comments. - * - * For more information on the BioJava project and its aims, - * or to join the biojava-l mailing list, visit the home page - * at: - * - * http://www.biojava.org/ - * - * Created by andreas on 10/12/15. - */ - -package org.biojava.nbio.structure.io.mmcif.model; - -import java.io.Serializable; - -public class DatabasePdbrevRecord implements Serializable { - - - private static final long serialVersionUID = 1L; - - String rev_num; - String type; - String details; - - public String getRev_num() { - return rev_num; - } - - public void setRev_num(String rev_num) { - this.rev_num = rev_num; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public String getDetails() { - return details; - } - - public void setDetails(String details) { - this.details = details; - } - - @Override - public String toString() { - return "DatabasePdbrevRecord{" + - "rev_num='" + rev_num + '\'' + - ", type='" + type + '\'' + - ", details='" + details + '\'' + - '}'; - } -} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/Entity.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/Entity.java deleted file mode 100644 index cae779dee2..0000000000 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/Entity.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * BioJava development code - * - * This code may be freely distributed and modified under the - * terms of the GNU Lesser General Public Licence. This should - * be distributed with the code. If you do not have a copy, - * see: - * - * http://www.gnu.org/copyleft/lesser.html - * - * Copyright for this code is held jointly by the individual - * authors. These should be listed in @author doc comments. - * - * For more information on the BioJava project and its aims, - * or to join the biojava-l mailing list, visit the home page - * at: - * - * http://www.biojava.org/ - * - * created at Mar 4, 2008 - */ -package org.biojava.nbio.structure.io.mmcif.model; - -/** A simple class to represent Entity records in mmCif files - * - * @author Andreas Prlic - * - */ -public class Entity { - String id; - - String type; - String src_method; - String pdbx_description; - String formula_weight; - String pdbx_number_of_molecules; - String details; - String pdbx_mutation; - String pdbx_fragment; - String pdbx_ec; - - @Override - public String toString(){ - StringBuffer buf = new StringBuffer(); - - buf.append("Entity - id:").append(id); - - buf.append(" type:").append(type); - buf.append(" src_method:").append(src_method); - buf.append(" pdbx_description:").append(pdbx_description); - buf.append(" formula_weight:").append(formula_weight); - buf.append(" pdbx_number_f_molecules:").append(pdbx_number_of_molecules); - buf.append(" details:").append(details); - buf.append(" pdbx_mutation:").append(pdbx_mutation); - buf.append(" pdbx_fragment:").append(pdbx_fragment); - buf.append(" pdbx_ec:").append(pdbx_ec); - - return buf.toString(); - } - public String getId() { - return id; - } - public void setId(String id) { - this.id = id; - } - - public String getType() { - return type; - } - public void setType(String type) { - this.type = type; - } - public String getSrc_method() { - return src_method; - } - public void setSrc_method(String src_method) { - this.src_method = src_method; - } - public String getPdbx_description() { - return pdbx_description; - } - public void setPdbx_description(String pdbx_description) { - this.pdbx_description = pdbx_description; - } - public String getFormula_weight() { - return formula_weight; - } - public void setFormula_weight(String formula_weight) { - this.formula_weight = formula_weight; - } - public String getPdbx_number_of_molecules() { - return pdbx_number_of_molecules; - } - public void setPdbx_number_of_molecules(String pdbx_number_of_molecules) { - this.pdbx_number_of_molecules = pdbx_number_of_molecules; - } - public String getDetails() { - return details; - } - public void setDetails(String details) { - this.details = details; - } - public String getPdbx_mutation() { - return pdbx_mutation; - } - public void setPdbx_mutation(String pdbx_mutation) { - this.pdbx_mutation = pdbx_mutation; - } - public String getPdbx_fragment() { - return pdbx_fragment; - } - public void setPdbx_fragment(String pdbx_fragment) { - this.pdbx_fragment = pdbx_fragment; - } - public String getPdbx_ec() { - return pdbx_ec; - } - public void setPdbx_ec(String pdbx_ec) { - this.pdbx_ec = pdbx_ec; - } - - -} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/EntityPoly.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/EntityPoly.java deleted file mode 100644 index 9c27e34a14..0000000000 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/EntityPoly.java +++ /dev/null @@ -1,152 +0,0 @@ -/* - * BioJava development code - * - * This code may be freely distributed and modified under the - * terms of the GNU Lesser General Public Licence. This should - * be distributed with the code. If you do not have a copy, - * see: - * - * http://www.gnu.org/copyleft/lesser.html - * - * Copyright for this code is held jointly by the individual - * authors. These should be listed in @author doc comments. - * - * For more information on the BioJava project and its aims, - * or to join the biojava-l mailing list, visit the home page - * at: - * - * http://www.biojava.org/ - * - * created at Jun 1, 2008 - */ -package org.biojava.nbio.structure.io.mmcif.model; - - -/** - * Container for _entity_poly records - * - * - * @since 5.0 - * @author Jose Duarte - */ -public class EntityPoly extends AbstractBean{ - String entity_id; - String type; - String nstd_chirality; - String nstd_linkage; - String nstd_monomer; - String type_details; - String pdbx_seq_one_letter_code; - String pdbx_seq_one_letter_code_can; - String pdbx_strand_id; - String pdbx_target_identifier; - public String getEntity_id() { - return entity_id; - } - public void setEntity_id(String entity_id) { - this.entity_id = entity_id; - } - /** - * @return the type - */ - public String getType() { - return type; - } - /** - * @param type the type to set - */ - public void setType(String type) { - this.type = type; - } - /** - * @return the nstd_chirality - */ - public String getNstd_chirality() { - return nstd_chirality; - } - /** - * @param nstd_chirality the nstd_chirality to set - */ - public void setNstd_chirality(String nstd_chirality) { - this.nstd_chirality = nstd_chirality; - } - /** - * @return the nstd_linkage - */ - public String getNstd_linkage() { - return nstd_linkage; - } - /** - * @param nstd_linkage the nstd_linkage to set - */ - public void setNstd_linkage(String nstd_linkage) { - this.nstd_linkage = nstd_linkage; - } - /** - * @return the nstd_monomer - */ - public String getNstd_monomer() { - return nstd_monomer; - } - /** - * @param nstd_monomer the nstd_monomer to set - */ - public void setNstd_monomer(String nstd_monomer) { - this.nstd_monomer = nstd_monomer; - } - /** - * @return the type_details - */ - public String getType_details() { - return type_details; - } - /** - * @param type_details the type_details to set - */ - public void setType_details(String type_details) { - this.type_details = type_details; - } - /** - * @return the pdbx_seq_one_letter_code - */ - public String getPdbx_seq_one_letter_code() { - return pdbx_seq_one_letter_code; - } - /** - * @param pdbx_seq_one_letter_code the pdbx_seq_one_letter_code to set - */ - public void setPdbx_seq_one_letter_code(String pdbx_seq_one_letter_code) { - this.pdbx_seq_one_letter_code = pdbx_seq_one_letter_code; - } - /** - * @return the pdbx_seq_one_letter_code_can - */ - public String getPdbx_seq_one_letter_code_can() { - return pdbx_seq_one_letter_code_can; - } - /** - * @param pdbx_seq_one_letter_code_can the pdbx_seq_one_letter_code_can to set - */ - public void setPdbx_seq_one_letter_code_can(String pdbx_seq_one_letter_code_can) { - this.pdbx_seq_one_letter_code_can = pdbx_seq_one_letter_code_can; - } - /** - * @return the pdbx_strand_id - */ - public String getPdbx_strand_id() { - return pdbx_strand_id; - } - /** - * @param pdbx_strand_id the pdbx_strand_id to set - */ - public void setPdbx_strand_id(String pdbx_strand_id) { - this.pdbx_strand_id = pdbx_strand_id; - } - public String getPdbx_target_identifier() { - return pdbx_target_identifier; - } - public void setPdbx_target_identifier(String pdbx_target_identifier) { - this.pdbx_target_identifier = pdbx_target_identifier; - } - -} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/EntityPolySeq.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/EntityPolySeq.java deleted file mode 100644 index 968ab47acd..0000000000 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/EntityPolySeq.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * BioJava development code - * - * This code may be freely distributed and modified under the - * terms of the GNU Lesser General Public Licence. This should - * be distributed with the code. If you do not have a copy, - * see: - * - * http://www.gnu.org/copyleft/lesser.html - * - * Copyright for this code is held jointly by the individual - * authors. These should be listed in @author doc comments. - * - * For more information on the BioJava project and its aims, - * or to join the biojava-l mailing list, visit the home page - * at: - * - * http://www.biojava.org/ - * - * created at Jun 1, 2008 - */ -package org.biojava.nbio.structure.io.mmcif.model; - - -/** Container for _entity_poly_seq records - * -

-Field Name     mmCIF Data Item
-Section        n.a.
-Serial_No      n.a.
-Strand_ID      PDB strand ID corresponding to _entity_poly_seq.entity_id (*)
-Strand_Length  derived
-Residue_Names  _entity_poly_seq.mon_id
-
- * (*) Chemically distinct polymer strands are mapped to mmCIF entities. Two - * instances or the same polymer molecule in the PDB data file are mapped to a - * single mmCIF entity (eg. a homodimer). For convenience a table of monomer - * label correspondences is stored in category PDBX_POLY_SEQ_SCHEME - * @author Andreas Prlic - * @since 1.7 - */ -public class EntityPolySeq extends AbstractBean{ - String entity_id; - String num; - String mon_id; - String hetero; - public String getEntity_id() { - return entity_id; - } - public void setEntity_id(String entity_id) { - this.entity_id = entity_id; - } - public String getNum() { - return num; - } - public void setNum(String num) { - this.num = num; - } - public String getMon_id() { - return mon_id; - } - public void setMon_id(String mon_id) { - this.mon_id = mon_id; - } - public String getHetero() { - return hetero; - } - public void setHetero(String hetero) { - this.hetero = hetero; - } - -} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/EntitySrcGen.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/EntitySrcGen.java deleted file mode 100644 index 19082a8932..0000000000 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/EntitySrcGen.java +++ /dev/null @@ -1,427 +0,0 @@ -/* - * BioJava development code - * - * This code may be freely distributed and modified under the - * terms of the GNU Lesser General Public Licence. This should - * be distributed with the code. If you do not have a copy, - * see: - * - * http://www.gnu.org/copyleft/lesser.html - * - * Copyright for this code is held jointly by the individual - * authors. These should be listed in @author doc comments. - * - * For more information on the BioJava project and its aims, - * or to join the biojava-l mailing list, visit the home page - * at: - * - * http://www.biojava.org/ - * - * - */ -package org.biojava.nbio.structure.io.mmcif.model; - - -/** - * Data items in the ENTITY_SRC_GEN category record details of - * the source from which the entity was obtained in cases - * where the source was genetically manipulated. The - * following are treated separately: items pertaining to the tissue - * from which the gene was obtained, items pertaining to the host - * organism for gene expression and items pertaining to the actual - * producing organism (plasmid). - * - * @author Andreas Prlic - * - */ -public class EntitySrcGen { - String entity_id; - String expression_system_id; - String gene_src_common_name; - String gene_src_details ; - String gene_src_dev_stage ; - String gene_src_genus ; - String gene_src_species ; - String gene_src_strain ; - String gene_src_tissue ; - String gene_src_tissue_fraction; - String host_org_common_name ; - String host_org_details ; - String host_org_genus ; - String host_org_species; - String host_org_strain ; - String pdbx_src_id; - String pdbx_seq_type; - String pdbx_alt_source_flag; - String pdbx_beg_seq_num; - String pdbx_end_seq_num; - String pdbx_description; - String pdbx_gene_src_atcc; - String pdbx_gene_src_cell ; - String pdbx_gene_src_cell_line; - String pdbx_gene_src_cellular_location; - String pdbx_gene_src_fragment ; - String pdbx_gene_src_gene ; - String pdbx_gene_src_ncbi_taxonomy_id; - String pdbx_gene_src_organ ; - String pdbx_gene_src_organelle ; - String pdbx_gene_src_plasmid ; - String pdbx_gene_src_plasmid_name ; - String pdbx_gene_src_scientific_name; - String pdbx_gene_src_variant ; - String pdbx_host_org_atcc ; - String pdbx_host_org_cell ; - String pdbx_host_org_cell_line ; - String pdbx_host_org_cellular_location ; - String pdbx_host_org_culture_collection ; - String pdbx_host_org_gene ; - String pdbx_host_org_ncbi_taxonomy_id ; - String pdbx_host_org_organ ; - String pdbx_host_org_organelle ; - String pdbx_host_org_scientific_name ; - String pdbx_host_org_strain ; - String pdbx_host_org_tissue ; - String pdbx_host_org_tissue_fraction ; - String pdbx_host_org_variant ; - String pdbx_host_org_vector ; - String pdbx_host_org_vector_type; - String plasmid_details ; - String plasmid_name ; - String start_construct_id ; - public String getEntity_id() { - return entity_id; - } - public void setEntity_id(String entity_id) { - this.entity_id = entity_id; - } - public String getExpression_system_id() { - return expression_system_id; - } - public void setExpression_system_id(String expression_system_id) { - this.expression_system_id = expression_system_id; - } - public String getGene_src_common_name() { - return gene_src_common_name; - } - public void setGene_src_common_name(String gene_src_common_name) { - this.gene_src_common_name = gene_src_common_name; - } - public String getGene_src_details() { - return gene_src_details; - } - public void setGene_src_details(String gene_src_details) { - this.gene_src_details = gene_src_details; - } - public String getGene_src_dev_stage() { - return gene_src_dev_stage; - } - public void setGene_src_dev_stage(String gene_src_dev_stage) { - this.gene_src_dev_stage = gene_src_dev_stage; - } - public String getGene_src_genus() { - return gene_src_genus; - } - public void setGene_src_genus(String gene_src_genus) { - this.gene_src_genus = gene_src_genus; - } - public String getGene_src_species() { - return gene_src_species; - } - public void setGene_src_species(String gene_src_species) { - this.gene_src_species = gene_src_species; - } - public String getGene_src_strain() { - return gene_src_strain; - } - public void setGene_src_strain(String gene_src_strain) { - this.gene_src_strain = gene_src_strain; - } - public String getGene_src_tissue() { - return gene_src_tissue; - } - public void setGene_src_tissue(String gene_src_tissue) { - this.gene_src_tissue = gene_src_tissue; - } - public String getGene_src_tissue_fraction() { - return gene_src_tissue_fraction; - } - public void setGene_src_tissue_fraction(String gene_src_tissue_fraction) { - this.gene_src_tissue_fraction = gene_src_tissue_fraction; - } - public String getHost_org_common_name() { - return host_org_common_name; - } - public void setHost_org_common_name(String host_org_common_name) { - this.host_org_common_name = host_org_common_name; - } - public String getHost_org_details() { - return host_org_details; - } - public void setHost_org_details(String host_org_details) { - this.host_org_details = host_org_details; - } - public String getHost_org_genus() { - return host_org_genus; - } - public void setHost_org_genus(String host_org_genus) { - this.host_org_genus = host_org_genus; - } - public String getHost_org_species() { - return host_org_species; - } - public void setHost_org_species(String host_org_species) { - this.host_org_species = host_org_species; - } - public String getHost_org_strain() { - return host_org_strain; - } - public void setHost_org_strain(String host_org_strain) { - this.host_org_strain = host_org_strain; - } - public String getPdbx_src_id() { - return pdbx_src_id; - } - public void setPdbx_src_id(String pdbx_src_id) { - this.pdbx_src_id = pdbx_src_id; - } - public String getPdbx_seq_type() { - return pdbx_seq_type; - } - public void setPdbx_seq_type(String pdbx_seq_type) { - this.pdbx_seq_type = pdbx_seq_type; - } - /** - * @return the pdbx_alt_source_flag - */ - public String getPdbx_alt_source_flag() { - return pdbx_alt_source_flag; - } - /** - * @param pdbx_alt_source_flag the pdbx_alt_source_flag to set - */ - public void setPdbx_alt_source_flag(String pdbx_alt_source_flag) { - this.pdbx_alt_source_flag = pdbx_alt_source_flag; - } - public String getPdbx_beg_seq_num() { - return pdbx_beg_seq_num; - } - public void setPdbx_beg_seq_num(String pdbx_beg_seq_num) { - this.pdbx_beg_seq_num = pdbx_beg_seq_num; - } - public String getPdbx_end_seq_num() { - return pdbx_end_seq_num; - } - public void setPdbx_end_seq_num(String pdbx_end_seq_num) { - this.pdbx_end_seq_num = pdbx_end_seq_num; - } - public String getPdbx_description() { - return pdbx_description; - } - public void setPdbx_description(String pdbx_description) { - this.pdbx_description = pdbx_description; - } - public String getPdbx_gene_src_atcc() { - return pdbx_gene_src_atcc; - } - public void setPdbx_gene_src_atcc(String pdbx_gene_src_atcc) { - this.pdbx_gene_src_atcc = pdbx_gene_src_atcc; - } - public String getPdbx_gene_src_cell() { - return pdbx_gene_src_cell; - } - public void setPdbx_gene_src_cell(String pdbx_gene_src_cell) { - this.pdbx_gene_src_cell = pdbx_gene_src_cell; - } - public String getPdbx_gene_src_cell_line() { - return pdbx_gene_src_cell_line; - } - public void setPdbx_gene_src_cell_line(String pdbx_gene_src_cell_line) { - this.pdbx_gene_src_cell_line = pdbx_gene_src_cell_line; - } - public String getPdbx_gene_src_cellular_location() { - return pdbx_gene_src_cellular_location; - } - public void setPdbx_gene_src_cellular_location( - String pdbx_gene_src_cellular_location) { - this.pdbx_gene_src_cellular_location = pdbx_gene_src_cellular_location; - } - public String getPdbx_gene_src_fragment() { - return pdbx_gene_src_fragment; - } - public void setPdbx_gene_src_fragment(String pdbx_gene_src_fragment) { - this.pdbx_gene_src_fragment = pdbx_gene_src_fragment; - } - public String getPdbx_gene_src_gene() { - return pdbx_gene_src_gene; - } - public void setPdbx_gene_src_gene(String pdbx_gene_src_gene) { - this.pdbx_gene_src_gene = pdbx_gene_src_gene; - } - public String getPdbx_gene_src_ncbi_taxonomy_id() { - return pdbx_gene_src_ncbi_taxonomy_id; - } - public void setPdbx_gene_src_ncbi_taxonomy_id( - String pdbx_gene_src_ncbi_taxonomy_id) { - this.pdbx_gene_src_ncbi_taxonomy_id = pdbx_gene_src_ncbi_taxonomy_id; - } - public String getPdbx_gene_src_organ() { - return pdbx_gene_src_organ; - } - public void setPdbx_gene_src_organ(String pdbx_gene_src_organ) { - this.pdbx_gene_src_organ = pdbx_gene_src_organ; - } - public String getPdbx_gene_src_organelle() { - return pdbx_gene_src_organelle; - } - public void setPdbx_gene_src_organelle(String pdbx_gene_src_organelle) { - this.pdbx_gene_src_organelle = pdbx_gene_src_organelle; - } - public String getPdbx_gene_src_plasmid() { - return pdbx_gene_src_plasmid; - } - public void setPdbx_gene_src_plasmid(String pdbx_gene_src_plasmid) { - this.pdbx_gene_src_plasmid = pdbx_gene_src_plasmid; - } - public String getPdbx_gene_src_plasmid_name() { - return pdbx_gene_src_plasmid_name; - } - public void setPdbx_gene_src_plasmid_name(String pdbx_gene_src_plasmid_name) { - this.pdbx_gene_src_plasmid_name = pdbx_gene_src_plasmid_name; - } - public String getPdbx_gene_src_scientific_name() { - return pdbx_gene_src_scientific_name; - } - public void setPdbx_gene_src_scientific_name( - String pdbx_gene_src_scientific_name) { - this.pdbx_gene_src_scientific_name = pdbx_gene_src_scientific_name; - } - public String getPdbx_gene_src_variant() { - return pdbx_gene_src_variant; - } - public void setPdbx_gene_src_variant(String pdbx_gene_src_variant) { - this.pdbx_gene_src_variant = pdbx_gene_src_variant; - } - public String getPdbx_host_org_atcc() { - return pdbx_host_org_atcc; - } - public void setPdbx_host_org_atcc(String pdbx_host_org_atcc) { - this.pdbx_host_org_atcc = pdbx_host_org_atcc; - } - public String getPdbx_host_org_cell() { - return pdbx_host_org_cell; - } - public void setPdbx_host_org_cell(String pdbx_host_org_cell) { - this.pdbx_host_org_cell = pdbx_host_org_cell; - } - public String getPdbx_host_org_cell_line() { - return pdbx_host_org_cell_line; - } - public void setPdbx_host_org_cell_line(String pdbx_host_org_cell_line) { - this.pdbx_host_org_cell_line = pdbx_host_org_cell_line; - } - public String getPdbx_host_org_cellular_location() { - return pdbx_host_org_cellular_location; - } - public void setPdbx_host_org_cellular_location( - String pdbx_host_org_cellular_location) { - this.pdbx_host_org_cellular_location = pdbx_host_org_cellular_location; - } - public String getPdbx_host_org_culture_collection() { - return pdbx_host_org_culture_collection; - } - public void setPdbx_host_org_culture_collection( - String pdbx_host_org_culture_collection) { - this.pdbx_host_org_culture_collection = pdbx_host_org_culture_collection; - } - public String getPdbx_host_org_gene() { - return pdbx_host_org_gene; - } - public void setPdbx_host_org_gene(String pdbx_host_org_gene) { - this.pdbx_host_org_gene = pdbx_host_org_gene; - } - public String getPdbx_host_org_ncbi_taxonomy_id() { - return pdbx_host_org_ncbi_taxonomy_id; - } - public void setPdbx_host_org_ncbi_taxonomy_id( - String pdbx_host_org_ncbi_taxonomy_id) { - this.pdbx_host_org_ncbi_taxonomy_id = pdbx_host_org_ncbi_taxonomy_id; - } - public String getPdbx_host_org_organ() { - return pdbx_host_org_organ; - } - public void setPdbx_host_org_organ(String pdbx_host_org_organ) { - this.pdbx_host_org_organ = pdbx_host_org_organ; - } - public String getPdbx_host_org_organelle() { - return pdbx_host_org_organelle; - } - public void setPdbx_host_org_organelle(String pdbx_host_org_organelle) { - this.pdbx_host_org_organelle = pdbx_host_org_organelle; - } - public String getPdbx_host_org_scientific_name() { - return pdbx_host_org_scientific_name; - } - public void setPdbx_host_org_scientific_name( - String pdbx_host_org_scientific_name) { - this.pdbx_host_org_scientific_name = pdbx_host_org_scientific_name; - } - public String getPdbx_host_org_strain() { - return pdbx_host_org_strain; - } - public void setPdbx_host_org_strain(String pdbx_host_org_strain) { - this.pdbx_host_org_strain = pdbx_host_org_strain; - } - public String getPdbx_host_org_tissue() { - return pdbx_host_org_tissue; - } - public void setPdbx_host_org_tissue(String pdbx_host_org_tissue) { - this.pdbx_host_org_tissue = pdbx_host_org_tissue; - } - public String getPdbx_host_org_tissue_fraction() { - return pdbx_host_org_tissue_fraction; - } - public void setPdbx_host_org_tissue_fraction( - String pdbx_host_org_tissue_fraction) { - this.pdbx_host_org_tissue_fraction = pdbx_host_org_tissue_fraction; - } - public String getPdbx_host_org_variant() { - return pdbx_host_org_variant; - } - public void setPdbx_host_org_variant(String pdbx_host_org_variant) { - this.pdbx_host_org_variant = pdbx_host_org_variant; - } - public String getPdbx_host_org_vector() { - return pdbx_host_org_vector; - } - public void setPdbx_host_org_vector(String pdbx_host_org_vector) { - this.pdbx_host_org_vector = pdbx_host_org_vector; - } - public String getPdbx_host_org_vector_type() { - return pdbx_host_org_vector_type; - } - public void setPdbx_host_org_vector_type(String pdbx_host_org_vector_type) { - this.pdbx_host_org_vector_type = pdbx_host_org_vector_type; - } - public String getPlasmid_details() { - return plasmid_details; - } - public void setPlasmid_details(String plasmid_details) { - this.plasmid_details = plasmid_details; - } - public String getPlasmid_name() { - return plasmid_name; - } - public void setPlasmid_name(String plasmid_name) { - this.plasmid_name = plasmid_name; - } - public String getStart_construct_id() { - return start_construct_id; - } - public void setStart_construct_id(String start_construct_id) { - this.start_construct_id = start_construct_id; - } - - - - -} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/EntitySrcNat.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/EntitySrcNat.java deleted file mode 100644 index 2429751685..0000000000 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/EntitySrcNat.java +++ /dev/null @@ -1,224 +0,0 @@ -/* - * BioJava development code - * - * This code may be freely distributed and modified under the - * terms of the GNU Lesser General Public Licence. This should - * be distributed with the code. If you do t have a copy, - * see: - * - * http://www.gnu.org/copyleft/lesser.html - * - * Copyright for this code is held jointly by the individual - * authors. These should be listed in @author doc comments. - * - * For more information on the BioJava project and its aims, - * or to join the biojava-l mailing list, visit the home page - * at: - * - * http://www.biojava.org/ - * - * created at Aug 12, 2013 - * Author: Andreas Prlic - */ - -package org.biojava.nbio.structure.io.mmcif.model; - -/** Data items in the ENTITY_SRC_NAT category record details of - the source from which the entity was obtained in cases - where the entity was isolated directly from a natural tissue. - */ -public class EntitySrcNat { - String common_name ; - String details ; - String entity_id ; - String genus ; - String pdbx_atcc ; - String pdbx_cell ; - String pdbx_cell_line ; - String pdbx_cellular_location; - String pdbx_fragment ; - String pdbx_ncbi_taxonomy_id; - String pdbx_organ ; - String pdbx_organelle; - String pdbx_organism_scientific; - String pdbx_plasmid_details ; - String pdbx_plasmid_name ; - String pdbx_secretion ; - String pdbx_variant ; - String pdbx_src_id; - String pdbx_alt_source_flag; - String pdbx_beg_seq_num; - String pdbx_end_seq_num; - String pdbx_leaving_atom_flag; - String species ; - String strain ; - String tissue ; - String tissue_fraction; - - public String getCommon_name() { - return common_name; - } - public void setCommon_name(String common_name) { - this.common_name = common_name; - } - public String getDetails() { - return details; - } - public void setDetails(String details) { - this.details = details; - } - public String getEntity_id() { - return entity_id; - } - public void setEntity_id(String entity_id) { - this.entity_id = entity_id; - } - public String getGenus() { - return genus; - } - public void setGenus(String genus) { - this.genus = genus; - } - public String getPdbx_atcc() { - return pdbx_atcc; - } - public void setPdbx_atcc(String pdbx_atcc) { - this.pdbx_atcc = pdbx_atcc; - } - public String getPdbx_cell() { - return pdbx_cell; - } - public void setPdbx_cell(String pdbx_cell) { - this.pdbx_cell = pdbx_cell; - } - public String getPdbx_cell_line() { - return pdbx_cell_line; - } - public void setPdbx_cell_line(String pdbx_cell_line) { - this.pdbx_cell_line = pdbx_cell_line; - } - public String getPdbx_cellular_location() { - return pdbx_cellular_location; - } - public void setPdbx_cellular_location(String pdbx_cellular_location) { - this.pdbx_cellular_location = pdbx_cellular_location; - } - public String getPdbx_fragment() { - return pdbx_fragment; - } - public void setPdbx_fragment(String pdbx_fragment) { - this.pdbx_fragment = pdbx_fragment; - } - public String getPdbx_ncbi_taxonomy_id() { - return pdbx_ncbi_taxonomy_id; - } - public void setPdbx_ncbi_taxonomy_id(String pdbx_ncbi_taxonomy_id) { - this.pdbx_ncbi_taxonomy_id = pdbx_ncbi_taxonomy_id; - } - public String getPdbx_organ() { - return pdbx_organ; - } - public void setPdbx_organ(String pdbx_organ) { - this.pdbx_organ = pdbx_organ; - } - public String getPdbx_organelle() { - return pdbx_organelle; - } - public void setPdbx_organelle(String pdbx_organelle) { - this.pdbx_organelle = pdbx_organelle; - } - public String getPdbx_organism_scientific() { - return pdbx_organism_scientific; - } - public void setPdbx_organism_scientific(String pdbx_organism_scientific) { - this.pdbx_organism_scientific = pdbx_organism_scientific; - } - public String getPdbx_plasmid_details() { - return pdbx_plasmid_details; - } - public void setPdbx_plasmid_details(String pdbx_plasmid_details) { - this.pdbx_plasmid_details = pdbx_plasmid_details; - } - public String getPdbx_plasmid_name() { - return pdbx_plasmid_name; - } - public void setPdbx_plasmid_name(String pdbx_plasmid_name) { - this.pdbx_plasmid_name = pdbx_plasmid_name; - } - public String getPdbx_secretion() { - return pdbx_secretion; - } - public void setPdbx_secretion(String pdbx_secretion) { - this.pdbx_secretion = pdbx_secretion; - } - public String getPdbx_variant() { - return pdbx_variant; - } - public void setPdbx_variant(String pdbx_variant) { - this.pdbx_variant = pdbx_variant; - } - public String getSpecies() { - return species; - } - public void setSpecies(String species) { - this.species = species; - } - public String getStrain() { - return strain; - } - public void setStrain(String strain) { - this.strain = strain; - } - public String getTissue() { - return tissue; - } - public void setTissue(String tissue) { - this.tissue = tissue; - } - public String getTissue_fraction() { - return tissue_fraction; - } - public void setTissue_fraction(String tissue_fraction) { - this.tissue_fraction = tissue_fraction; - } - - public String getPdbx_src_id() { - return pdbx_src_id; - } - - public void setPdbx_src_id(String pdbx_src_id) { - this.pdbx_src_id = pdbx_src_id; - } - - public String getPdbx_alt_source_flag() { - return pdbx_alt_source_flag; - } - - public void setPdbx_alt_source_flag(String pdbx_alt_source_flag) { - this.pdbx_alt_source_flag = pdbx_alt_source_flag; - } - - public String getPdbx_beg_seq_num() { - return pdbx_beg_seq_num; - } - - public void setPdbx_beg_seq_num(String pdbx_beg_seq_num) { - this.pdbx_beg_seq_num = pdbx_beg_seq_num; - } - - public String getPdbx_end_seq_num() { - return pdbx_end_seq_num; - } - - public void setPdbx_end_seq_num(String pdbx_end_seq_num) { - this.pdbx_end_seq_num = pdbx_end_seq_num; - } - - public String getPdbx_leaving_atom_flag() { - return pdbx_leaving_atom_flag; - } - - public void setPdbx_leaving_atom_flag(String pdbx_leaving_atom_flag) { - this.pdbx_leaving_atom_flag = pdbx_leaving_atom_flag; - } -} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/EntitySrcSyn.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/EntitySrcSyn.java deleted file mode 100644 index eb1511990f..0000000000 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/EntitySrcSyn.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * BioJava development code - * - * This code may be freely distributed and modified under the - * terms of the GNU Lesser General Public Licence. This should - * be distributed with the code. If you do not have a copy, - * see: - * - * http://www.gnu.org/copyleft/lesser.html - * - * Copyright for this code is held jointly by the individual - * authors. These should be listed in @author doc comments. - * - * For more information on the BioJava project and its aims, - * or to join the biojava-l mailing list, visit the home page - * at: - * - * http://www.biojava.org/ - * - * created at Aug 12, 2013 - * Author: Andreas Prlic - */ - -package org.biojava.nbio.structure.io.mmcif.model; - -/** - * PDBX_ENTITY_SRC_SYN records the details about each chemically - * synthesized molecule (entity) in the asymmetric unit. - * @author Andreas Prlic - * - */ -public class EntitySrcSyn { - String details; - String entity_id; - String ncbi_taxonomy_id; - String organism_common_name; - String organism_scientific; - String strain; - public String getDetails() { - return details; - } - public void setDetails(String details) { - this.details = details; - } - public String getEntity_id() { - return entity_id; - } - public void setEntity_id(String entity_id) { - this.entity_id = entity_id; - } - public String getNcbi_taxonomy_id() { - return ncbi_taxonomy_id; - } - public void setNcbi_taxonomy_id(String ncbi_taxonomy_id) { - this.ncbi_taxonomy_id = ncbi_taxonomy_id; - } - public String getOrganism_common_name() { - return organism_common_name; - } - public void setOrganism_common_name(String organism_common_name) { - this.organism_common_name = organism_common_name; - } - public String getOrganism_scientific() { - return organism_scientific; - } - public void setOrganism_scientific(String organism_scientific) { - this.organism_scientific = organism_scientific; - } - public String getStrain() { - return strain; - } - public void setStrain(String strain) { - this.strain = strain; - } -} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/Exptl.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/Exptl.java deleted file mode 100644 index ee6644cc34..0000000000 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/Exptl.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * BioJava development code - * - * This code may be freely distributed and modified under the - * terms of the GNU Lesser General Public Licence. This should - * be distributed with the code. If you do not have a copy, - * see: - * - * http://www.gnu.org/copyleft/lesser.html - * - * Copyright for this code is held jointly by the individual - * authors. These should be listed in @author doc comments. - * - * For more information on the BioJava project and its aims, - * or to join the biojava-l mailing list, visit the home page - * at: - * - * http://www.biojava.org/ - * - * created at May 31, 2008 - */ -package org.biojava.nbio.structure.io.mmcif.model; - -public class Exptl extends AbstractBean{ - String entry_id; - String method; - String crystals_number; - String absorpt_coefficient_mu; - String absorpt_correction_T_max; - String absorpt_correction_T_min ; - String absorpt_correction_type ; - String absorpt_process_details ; - String details; - String method_details; - - public String getEntry_id() { - return entry_id; - } - public void setEntry_id(String entry_id) { - this.entry_id = entry_id; - } - public String getMethod() { - return method; - } - public void setMethod(String method) { - this.method = method; - } - public String getCrystals_number() { - return crystals_number; - } - public void setCrystals_number(String crystals_number) { - this.crystals_number = crystals_number; - } - public String getAbsorpt_coefficient_mu() { - return absorpt_coefficient_mu; - } - public void setAbsorpt_coefficient_mu(String absorpt_coefficient_mu) { - this.absorpt_coefficient_mu = absorpt_coefficient_mu; - } - public String getAbsorpt_correction_T_max() { - return absorpt_correction_T_max; - } - public void setAbsorpt_correction_T_max(String absorpt_correction_T_max) { - this.absorpt_correction_T_max = absorpt_correction_T_max; - } - public String getAbsorpt_correction_T_min() { - return absorpt_correction_T_min; - } - public void setAbsorpt_correction_T_min(String absorpt_correction_T_min) { - this.absorpt_correction_T_min = absorpt_correction_T_min; - } - public String getAbsorpt_correction_type() { - return absorpt_correction_type; - } - public void setAbsorpt_correction_type(String absorpt_correction_type) { - this.absorpt_correction_type = absorpt_correction_type; - } - public String getAbsorpt_process_details() { - return absorpt_process_details; - } - public void setAbsorpt_process_details(String absorpt_process_details) { - this.absorpt_process_details = absorpt_process_details; - } - public String getDetails() { - return details; - } - public void setDetails(String details) { - this.details = details; - } - public String getMethod_details() { - return method_details; - } - public void setMethod_details(String method_details) { - this.method_details = method_details; - } - - -} 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 deleted file mode 100644 index 8c6db21e92..0000000000 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/IgnoreField.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * BioJava development code - * - * This code may be freely distributed and modified under the - * terms of the GNU Lesser General Public Licence. This should - * be distributed with the code. If you do not have a copy, - * see: - * - * http://www.gnu.org/copyleft/lesser.html - * - * Copyright for this code is held jointly by the individual - * authors. These should be listed in @author doc comments. - * - * For more information on the BioJava project and its aims, - * or to join the biojava-l mailing list, visit the home page - * at: - * - * http://www.biojava.org/ - * - */ -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/PdbxAuditRevisionHistory.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/PdbxAuditRevisionHistory.java deleted file mode 100644 index 8c298f84f1..0000000000 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/PdbxAuditRevisionHistory.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * BioJava development code - * - * This code may be freely distributed and modified under the - * terms of the GNU Lesser General Public Licence. This should - * be distributed with the code. If you do not have a copy, - * see: - * - * http://www.gnu.org/copyleft/lesser.html - * - * Copyright for this code is held jointly by the individual - * authors. These should be listed in @author doc comments. - * - * For more information on the BioJava project and its aims, - * or to join the biojava-l mailing list, visit the home page - * at: - * - * http://www.biojava.org/ - * - */ -package org.biojava.nbio.structure.io.mmcif.model; - -/** - * Bean to hold data for _pdbx_audit_revision_history mmCIF category. - * - * @author Peter Rose - * @since 5.0 - */ -public class PdbxAuditRevisionHistory extends AbstractBean { - private String ordinal; - private String data_content_type; - private String major_revision; - private String minor_revision; - private String revision_date; - - public String getOrdinal() { - return ordinal; - } - public void setOrdinal(String ordinal) { - this.ordinal = ordinal; - } - public String getData_content_type() { - return data_content_type; - } - public void setData_content_type(String data_content_type) { - this.data_content_type = data_content_type; - } - public String getMajor_revision() { - return major_revision; - } - public void setMajor_revision(String major_revision) { - this.major_revision = major_revision; - } - public String getMinor_revision() { - return minor_revision; - } - public void setMinor_revision(String minor_revision) { - this.minor_revision = minor_revision; - } - public String getRevision_date() { - return revision_date; - } - public void setRevision_date(String revision_date) { - this.revision_date = revision_date; - } -} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/PdbxChemCompDescriptor.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/PdbxChemCompDescriptor.java deleted file mode 100644 index 95eb36ce7a..0000000000 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/PdbxChemCompDescriptor.java +++ /dev/null @@ -1,71 +0,0 @@ -/** - * BioJava development code - * - * This code may be freely distributed and modified under the - * terms of the GNU Lesser General Public Licence. This should - * be distributed with the code. If you do not have a copy, - * see: - * - * http://www.gnu.org/copyleft/lesser.html - * - * Copyright for this code is held jointly by the individual - * authors. These should be listed in @author doc comments. - * - * For more information on the BioJava project and its aims, - * or to join the biojava-l mailing list, visit the home page - * at: - * - * http://www.biojava.org/ - * - * Created on 7 Feb 2013 - * Created by Andreas Prlic - * - * @since 3.0.2 - */ -package org.biojava.nbio.structure.io.mmcif.model; - -/* -_pdbx_chem_comp_descriptor.comp_id -_pdbx_chem_comp_descriptor.type -_pdbx_chem_comp_descriptor.program -_pdbx_chem_comp_descriptor.program_version -_pdbx_chem_comp_descriptor.descriptor - */ -public class PdbxChemCompDescriptor { - String comp_id; - String type; - String program; - String program_version; - String identifier; - - public String getComp_id() { - return comp_id; - } - public void setComp_id(String comp_id) { - this.comp_id = comp_id; - } - public String getType() { - return type; - } - public void setType(String type) { - this.type = type; - } - public String getProgram() { - return program; - } - public void setProgram(String program) { - this.program = program; - } - public String getProgram_version() { - return program_version; - } - public void setProgram_version(String program_version) { - this.program_version = program_version; - } - public String getIdentifier() { - return identifier; - } - public void setIdentifier(String identifier) { - this.identifier = identifier; - } -} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/PdbxChemCompIdentifier.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/PdbxChemCompIdentifier.java deleted file mode 100644 index d47ee1b9d7..0000000000 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/PdbxChemCompIdentifier.java +++ /dev/null @@ -1,73 +0,0 @@ -/** - * BioJava development code - * - * This code may be freely distributed and modified under the - * terms of the GNU Lesser General Public Licence. This should - * be distributed with the code. If you do not have a copy, - * see: - * - * http://www.gnu.org/copyleft/lesser.html - * - * Copyright for this code is held jointly by the individual - * authors. These should be listed in @author doc comments. - * - * For more information on the BioJava project and its aims, - * or to join the biojava-l mailing list, visit the home page - * at: - * - * http://www.biojava.org/ - * - * Created on Feb 5, 2013 - * Created by Andreas Prlic - * - * @since 3.0.2 - */ -package org.biojava.nbio.structure.io.mmcif.model; - - - -/** -_pdbx_chem_comp_identifier.comp_id -_pdbx_chem_comp_identifier.type -_pdbx_chem_comp_identifier.program -_pdbx_chem_comp_identifier.program_version -_pdbx_chem_comp_identifier.identifier - */ -public class PdbxChemCompIdentifier { - String comp_id; - String type; - String program; - String program_version; - String identifier; - - public String getComp_id() { - return comp_id; - } - public void setComp_id(String comp_id) { - this.comp_id = comp_id; - } - public String getType() { - return type; - } - public void setType(String type) { - this.type = type; - } - public String getProgram() { - return program; - } - public void setProgram(String program) { - this.program = program; - } - public String getProgram_version() { - return program_version; - } - public void setProgram_version(String program_version) { - this.program_version = program_version; - } - public String getIdentifier() { - return identifier; - } - public void setIdentifier(String identifier) { - this.identifier = identifier; - } -} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/PdbxDatabaseStatus.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/PdbxDatabaseStatus.java deleted file mode 100644 index e96672c441..0000000000 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/PdbxDatabaseStatus.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * BioJava development code - * - * This code may be freely distributed and modified under the - * terms of the GNU Lesser General Public Licence. This should - * be distributed with the code. If you do not have a copy, - * see: - * - * http://www.gnu.org/copyleft/lesser.html - * - * Copyright for this code is held jointly by the individual - * authors. These should be listed in @author doc comments. - * - * For more information on the BioJava project and its aims, - * or to join the biojava-l mailing list, visit the home page - * at: - * - * http://www.biojava.org/ - * - */ -package org.biojava.nbio.structure.io.mmcif.model; - -/** - * Bean to hold data for _pdbx_database_status mmCIF category. - * - * @author Peter Rose - * @since 5.0 - */ -public class PdbxDatabaseStatus extends AbstractBean { - private String status_code; - private String entry_id; - private String recvd_initial_deposition_date; - private String deposit_site; - private String process_site; - private String SG_entry; - private String pdb_format_compatible; - private String status_code_mr; - private String status_code_sf; - private String status_code_cs; - - public String getStatus_code() { - return status_code; - } - public void setStatus_code(String status_code) { - this.status_code = status_code; - } - public String getEntry_id() { - return entry_id; - } - public void setEntry_id(String entry_id) { - this.entry_id = entry_id; - } - public String getRecvd_initial_deposition_date() { - return recvd_initial_deposition_date; - } - public void setRecvd_initial_deposition_date(String recvd_initial_deposition_date) { - this.recvd_initial_deposition_date = recvd_initial_deposition_date; - } - public String getDeposit_site() { - return deposit_site; - } - public void setDeposit_site(String deposit_site) { - this.deposit_site = deposit_site; - } - public String getProcess_site() { - return process_site; - } - public void setProcess_site(String process_site) { - this.process_site = process_site; - } - public String getSG_entry() { - return SG_entry; - } - public void setSG_entry(String sG_entry) { - SG_entry = sG_entry; - } - public String getPdb_format_compatible() { - return pdb_format_compatible; - } - public void setPdb_format_compatible(String pdb_format_compatible) { - this.pdb_format_compatible = pdb_format_compatible; - } - public String getStatus_code_mr() { - return status_code_mr; - } - public void setStatus_code_mr(String status_code_mr) { - this.status_code_mr = status_code_mr; - } - public String getStatus_code_sf() { - return status_code_sf; - } - public void setStatus_code_sf(String status_code_sf) { - this.status_code_sf = status_code_sf; - } - public String getStatus_code_cs() { - return status_code_cs; - } - public void setStatus_code_cs(String status_code_cs) { - this.status_code_cs = status_code_cs; - } -} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/PdbxEntityNonPoly.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/PdbxEntityNonPoly.java deleted file mode 100644 index f3776d14e7..0000000000 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/PdbxEntityNonPoly.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * BioJava development code - * - * This code may be freely distributed and modified under the - * terms of the GNU Lesser General Public Licence. This should - * be distributed with the code. If you do not have a copy, - * see: - * - * http://www.gnu.org/copyleft/lesser.html - * - * Copyright for this code is held jointly by the individual - * authors. These should be listed in @author doc comments. - * - * For more information on the BioJava project and its aims, - * or to join the biojava-l mailing list, visit the home page - * at: - * - * http://www.biojava.org/ - * - */ -package org.biojava.nbio.structure.io.mmcif.model; - -/** A bean for the Pdbx_entity_nonpoly category. - * - * @author Andreas Prlic - * @since 1.7 - */ -public class PdbxEntityNonPoly { - String entity_id; - String name; - String comp_id; - public String getEntity_id() { - return entity_id; - } - public void setEntity_id(String entity_id) { - this.entity_id = entity_id; - } - public String getName() { - return name; - } - public void setName(String name) { - this.name = name; - } - public String getComp_id() { - return comp_id; - } - public void setComp_id(String comp_id) { - this.comp_id = comp_id; - } - -} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/PdbxNonPolyScheme.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/PdbxNonPolyScheme.java deleted file mode 100644 index 25900b2451..0000000000 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/PdbxNonPolyScheme.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * BioJava development code - * - * This code may be freely distributed and modified under the - * terms of the GNU Lesser General Public Licence. This should - * be distributed with the code. If you do not have a copy, - * see: - * - * http://www.gnu.org/copyleft/lesser.html - * - * Copyright for this code is held jointly by the individual - * authors. These should be listed in @author doc comments. - * - * For more information on the BioJava project and its aims, - * or to join the biojava-l mailing list, visit the home page - * at: - * - * http://www.biojava.org/ - * - */ -package org.biojava.nbio.structure.io.mmcif.model; - -/** A bean for the PDBX_NONPOLY_SCHEME category, which provides residue level nomenclature - * mapping for non-polymer entities. - * @author Andreas Prlic - * @since 1.7 - */ -public class PdbxNonPolyScheme { - String asym_id; - String entity_id; - String seq_id; - String mon_id; - String ndb_seq_num; - String pdb_seq_num ; - String auth_seq_num ; - String pdb_mon_id; - String auth_mon_id; - String pdb_strand_id; - String pdb_ins_code; - public String getAsym_id() { - return asym_id; - } - public void setAsym_id(String asym_id) { - this.asym_id = asym_id; - } - public String getEntity_id() { - return entity_id; - } - public void setEntity_id(String entity_id) { - this.entity_id = entity_id; - } - public String getSeq_id() { - return seq_id; - } - public void setSeq_id(String seq_id) { - this.seq_id = seq_id; - } - public String getMon_id() { - return mon_id; - } - public void setMon_id(String mon_id) { - this.mon_id = mon_id; - } - public String getNdb_seq_num() { - return ndb_seq_num; - } - public void setNdb_seq_num(String ndb_seq_num) { - this.ndb_seq_num = ndb_seq_num; - } - public String getPdb_seq_num() { - return pdb_seq_num; - } - public void setPdb_seq_num(String pdb_seq_num) { - this.pdb_seq_num = pdb_seq_num; - } - public String getAuth_seq_num() { - return auth_seq_num; - } - public void setAuth_seq_num(String auth_seq_num) { - this.auth_seq_num = auth_seq_num; - } - public String getPdb_mon_id() { - return pdb_mon_id; - } - public void setPdb_mon_id(String pdb_mon_id) { - this.pdb_mon_id = pdb_mon_id; - } - public String getAuth_mon_id() { - return auth_mon_id; - } - public void setAuth_mon_id(String auth_mon_id) { - this.auth_mon_id = auth_mon_id; - } - public String getPdb_strand_id() { - return pdb_strand_id; - } - public void setPdb_strand_id(String pdb_strand_id) { - this.pdb_strand_id = pdb_strand_id; - } - public String getPdb_ins_code() { - return pdb_ins_code; - } - public void setPdb_ins_code(String pdb_ins_code) { - this.pdb_ins_code = pdb_ins_code; - } - -} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/PdbxPolySeqScheme.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/PdbxPolySeqScheme.java deleted file mode 100644 index 42f470e0c2..0000000000 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/PdbxPolySeqScheme.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * BioJava development code - * - * This code may be freely distributed and modified under the - * terms of the GNU Lesser General Public Licence. This should - * be distributed with the code. If you do not have a copy, - * see: - * - * http://www.gnu.org/copyleft/lesser.html - * - * Copyright for this code is held jointly by the individual - * authors. These should be listed in @author doc comments. - * - * For more information on the BioJava project and its aims, - * or to join the biojava-l mailing list, visit the home page - * at: - * - * http://www.biojava.org/ - * - * created at Jun 5, 2008 - */ -package org.biojava.nbio.structure.io.mmcif.model; - -/** A bean for the PDBX_POLY_SEQ_SCHEME category, which provides residue level nomenclature - * mapping for polymer entities. - * @author Andreas Prlic - * @since 1.7 - */ - -public class PdbxPolySeqScheme extends AbstractBean{ - String asym_id; - String entity_id; - String seq_id; - String mon_id; - String ndb_seq_num; - String pdb_seq_num ; - String auth_seq_num ; - String pdb_mon_id; - String auth_mon_id; - String pdb_strand_id; - String pdb_ins_code; - String hetero; - public String getAsym_id() { - return asym_id; - } - public void setAsym_id(String asym_id) { - this.asym_id = asym_id; - } - public String getEntity_id() { - return entity_id; - } - public void setEntity_id(String entity_id) { - this.entity_id = entity_id; - } - public String getSeq_id() { - return seq_id; - } - public void setSeq_id(String seq_id) { - this.seq_id = seq_id; - } - public String getMon_id() { - return mon_id; - } - public void setMon_id(String mon_id) { - this.mon_id = mon_id; - } - public String getNdb_seq_num() { - return ndb_seq_num; - } - public void setNdb_seq_num(String ndb_seq_num) { - this.ndb_seq_num = ndb_seq_num; - } - public String getPdb_seq_num() { - return pdb_seq_num; - } - public void setPdb_seq_num(String pdb_seq_num) { - this.pdb_seq_num = pdb_seq_num; - } - public String getAuth_seq_num() { - return auth_seq_num; - } - public void setAuth_seq_num(String auth_seq_num) { - this.auth_seq_num = auth_seq_num; - } - public String getPdb_mon_id() { - return pdb_mon_id; - } - public void setPdb_mon_id(String pdb_mon_id) { - this.pdb_mon_id = pdb_mon_id; - } - public String getAuth_mon_id() { - return auth_mon_id; - } - public void setAuth_mon_id(String auth_mon_id) { - this.auth_mon_id = auth_mon_id; - } - public String getPdb_strand_id() { - return pdb_strand_id; - } - public void setPdb_strand_id(String pdb_strand_id) { - this.pdb_strand_id = pdb_strand_id; - } - public String getPdb_ins_code() { - return pdb_ins_code; - } - public void setPdb_ins_code(String pdb_ins_code) { - this.pdb_ins_code = pdb_ins_code; - } - public String getHetero() { - return hetero; - } - public void setHetero(String hetero) { - this.hetero = hetero; - } - - -} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/PdbxStructAssembly.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/PdbxStructAssembly.java deleted file mode 100644 index 11b40c8a59..0000000000 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/PdbxStructAssembly.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * BioJava development code - * - * This code may be freely distributed and modified under the - * terms of the GNU Lesser General Public Licence. This should - * be distributed with the code. If you do not have a copy, - * see: - * - * http://www.gnu.org/copyleft/lesser.html - * - * Copyright for this code is held jointly by the individual - * authors. These should be listed in @author doc comments. - * - * For more information on the BioJava project and its aims, - * or to join the biojava-l mailing list, visit the home page - * at: - * - * http://www.biojava.org/ - * - */ -package org.biojava.nbio.structure.io.mmcif.model; - - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import java.io.Serializable; - - - -@XmlAccessorType(XmlAccessType.PUBLIC_MEMBER) -public class PdbxStructAssembly implements Serializable{ - - /** - * - */ - private static final long serialVersionUID = 3104504686693887219L; - - String id; - String details; - String method_details; - String oligomeric_details; - String oligomeric_count ; - public String getId() { - return id; - } - public void setId(String id) { - this.id = id; - } - public String getDetails() { - return details; - } - public void setDetails(String details) { - this.details = details; - } - public String getMethod_details() { - return method_details; - } - public void setMethod_details(String method_details) { - this.method_details = method_details; - } - public String getOligomeric_details() { - return oligomeric_details; - } - public void setOligomeric_details(String oligomeric_details) { - this.oligomeric_details = oligomeric_details; - } - public String getOligomeric_count() { - return oligomeric_count; - } - public void setOligomeric_count(String oligomeric_count) { - this.oligomeric_count = oligomeric_count; - } - @Override - public String toString() { - return "PdbxStructAssembly [id=" + id + ", details=" + details - + ", method_details=" + method_details - + ", oligomeric_details=" + oligomeric_details - + ", oligomeric_count=" + oligomeric_count + "]"; - } - - - - - -} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/PdbxStructAssemblyGen.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/PdbxStructAssemblyGen.java deleted file mode 100644 index d672ee9f33..0000000000 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/PdbxStructAssemblyGen.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * BioJava development code - * - * This code may be freely distributed and modified under the - * terms of the GNU Lesser General Public Licence. This should - * be distributed with the code. If you do not have a copy, - * see: - * - * http://www.gnu.org/copyleft/lesser.html - * - * Copyright for this code is held jointly by the individual - * authors. These should be listed in @author doc comments. - * - * For more information on the BioJava project and its aims, - * or to join the biojava-l mailing list, visit the home page - * at: - * - * http://www.biojava.org/ - * - */ -package org.biojava.nbio.structure.io.mmcif.model; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import java.io.Serializable; - -@XmlAccessorType(XmlAccessType.PUBLIC_MEMBER) -public class PdbxStructAssemblyGen implements Serializable{ - /** - * - */ - private static final long serialVersionUID = 6739568389242514332L; - String assembly_id; - String oper_expression; - String asym_id_list; - - - public String getAssembly_id() { - return assembly_id; - } - public void setAssembly_id(String assembly_id) { - this.assembly_id = assembly_id; - } - public String getOper_expression() { - return oper_expression; - } - public void setOper_expression(String oper_expression) { - this.oper_expression = oper_expression; - } - public String getAsym_id_list() { - return asym_id_list; - } - public void setAsym_id_list(String asym_id_list) { - this.asym_id_list = asym_id_list; - } - @Override - public String toString() { - return "PdbxStructAssemblyGen [assembly_id=" + assembly_id - + ", oper_expression=" + oper_expression + ", asym_id_list=" - + asym_id_list + "]"; - } - - - - - -} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/PdbxStructAssemblyGenXMLContainer.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/PdbxStructAssemblyGenXMLContainer.java deleted file mode 100644 index aae7534df2..0000000000 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/PdbxStructAssemblyGenXMLContainer.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * BioJava development code - * - * This code may be freely distributed and modified under the - * terms of the GNU Lesser General Public Licence. This should - * be distributed with the code. If you do not have a copy, - * see: - * - * http://www.gnu.org/copyleft/lesser.html - * - * Copyright for this code is held jointly by the individual - * authors. These should be listed in @author doc comments. - * - * For more information on the BioJava project and its aims, - * or to join the biojava-l mailing list, visit the home page - * at: - * - * http://www.biojava.org/ - * - */ -package org.biojava.nbio.structure.io.mmcif.model; - -import javax.xml.bind.JAXBContext; -import javax.xml.bind.Marshaller; -import javax.xml.bind.Unmarshaller; -import javax.xml.bind.annotation.XmlElementWrapper; -import javax.xml.bind.annotation.XmlRootElement; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.List; - -@XmlRootElement(name="PdbxStructAssemblyGenXMLContainer") -public class PdbxStructAssemblyGenXMLContainer { - - private List data ; - - static JAXBContext jaxbContext; - static { - try { - jaxbContext= JAXBContext.newInstance(PdbxStructAssemblyGenXMLContainer.class); - } catch (Exception e){ - e.printStackTrace(); - } - } - - @XmlElementWrapper - public List getPdbxStructAssemblyGens(){ - return data; - - } - - public void setPdbxStructAssemblies(List d){ - data = d; - } - - public String toXML(){ - - System.out.println("converting to XML: " + data); - - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - - PrintStream ps = new PrintStream(baos); - - try { - - Marshaller m = jaxbContext.createMarshaller(); - - m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); - - m.marshal( this, ps); - - - } catch (Exception e){ - e.printStackTrace(); - } - - return baos.toString(); - - } - - public static PdbxStructAssemblyGenXMLContainer fromXML(String xml){ - - PdbxStructAssemblyGenXMLContainer job = null; - - try { - - Unmarshaller un = jaxbContext.createUnmarshaller(); - - ByteArrayInputStream bais = new ByteArrayInputStream(xml.getBytes()); - - job = (PdbxStructAssemblyGenXMLContainer) un.unmarshal(bais); - - } catch (Exception e){ - e.printStackTrace(); - } - - return job; - } - -} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/PdbxStructAssemblyXMLContainer.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/PdbxStructAssemblyXMLContainer.java deleted file mode 100644 index d9cf2fb167..0000000000 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/PdbxStructAssemblyXMLContainer.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * BioJava development code - * - * This code may be freely distributed and modified under the - * terms of the GNU Lesser General Public Licence. This should - * be distributed with the code. If you do not have a copy, - * see: - * - * http://www.gnu.org/copyleft/lesser.html - * - * Copyright for this code is held jointly by the individual - * authors. These should be listed in @author doc comments. - * - * For more information on the BioJava project and its aims, - * or to join the biojava-l mailing list, visit the home page - * at: - * - * http://www.biojava.org/ - * - */ -package org.biojava.nbio.structure.io.mmcif.model; - -import javax.xml.bind.JAXBContext; -import javax.xml.bind.Marshaller; -import javax.xml.bind.Unmarshaller; -import javax.xml.bind.annotation.XmlElementWrapper; -import javax.xml.bind.annotation.XmlRootElement; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.List; - -@XmlRootElement(name="PdbxStructAssemblyXMLContainer") -public class PdbxStructAssemblyXMLContainer { - - private List data ; - - static JAXBContext jaxbContext; - static { - try { - jaxbContext= JAXBContext.newInstance(PdbxStructAssemblyXMLContainer.class); - } catch (Exception e){ - e.printStackTrace(); - } - } - - @XmlElementWrapper - public List getPdbxStructAssemblies(){ - return data; - - } - - public void setPdbxStructAssemblies(List d){ - data = d; - } - - public String toXML(){ - - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - - PrintStream ps = new PrintStream(baos); - - try { - - Marshaller m = jaxbContext.createMarshaller(); - - m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); - - m.marshal( this, ps); - - - } catch (Exception e){ - e.printStackTrace(); - } - - return baos.toString(); - - } - - public static PdbxStructAssemblyXMLContainer fromXML(String xml){ - - PdbxStructAssemblyXMLContainer job = null; - - try { - - Unmarshaller un = jaxbContext.createUnmarshaller(); - - ByteArrayInputStream bais = new ByteArrayInputStream(xml.getBytes()); - - job = (PdbxStructAssemblyXMLContainer) un.unmarshal(bais); - - } catch (Exception e){ - e.printStackTrace(); - } - - return job; - } - -} 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 deleted file mode 100644 index 4d2f35e614..0000000000 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/PdbxStructOperList.java +++ /dev/null @@ -1,222 +0,0 @@ -/* - * BioJava development code - * - * This code may be freely distributed and modified under the - * terms of the GNU Lesser General Public Licence. This should - * be distributed with the code. If you do not have a copy, - * see: - * - * http://www.gnu.org/copyleft/lesser.html - * - * Copyright for this code is held jointly by the individual - * authors. These should be listed in @author doc comments. - * - * For more information on the BioJava project and its aims, - * or to join the biojava-l mailing list, visit the home page - * at: - * - * http://www.biojava.org/ - * - */ -package org.biojava.nbio.structure.io.mmcif.model; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlAttribute; -import javax.xml.bind.annotation.XmlElement; -import java.io.Serializable; - -/** - * 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 - public String toString() { - return "PdbxStructOperList [id=" + id + ", type=" + type + "]"; - } - - - 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 - - - public PdbxStructOperList(){ - - } - - @XmlAttribute - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - @XmlAttribute - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public void setMatrix11(String val){ - this.matrix11 = val; - } - public void setMatrix21(String val){ - this.matrix21 = val; - } - public void setMatrix31(String val){ - this.matrix31 = val; - } - - public void setMatrix12(String val){ - this.matrix12 = val; - } - public void setMatrix22(String val){ - this.matrix22 = val; - } - public void setMatrix32(String val){ - this.matrix32 = val; - } - public void setMatrix13(String val){ - this.matrix13 = val; - } - public void setMatrix23(String val){ - this.matrix23 = val; - } - public void setMatrix33(String val){ - this.matrix33 =val; - } - - public void setName(String name) { - this.name = name; - } - - public String getVector1() { - return vector1; - } - public void setVector1(String vector1) { - this.vector1 = vector1; - } - public String getVector2() { - return vector2; - } - public void setVector2(String vector2) { - this.vector2 = vector2; - } - public String getVector3() { - return vector3; - } - public void setVector3(String vector3) { - this.vector3 = 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 String getMatrix11(){ - return matrix11; - } - @XmlElement - public String getMatrix21(){ - return matrix21; - } - @XmlElement - public String getMatrix31(){ - return matrix31; - } - @XmlElement - public String getMatrix12(){ - return matrix12; - } - @XmlElement - public String getMatrix22(){ - return matrix22; - } - @XmlElement - public String getMatrix32(){ - return matrix32; - } - @XmlElement - public String getMatrix13(){ - return matrix13; - } - @XmlElement - public String getMatrix23(){ - return matrix23; - } - @XmlElement - public String getMatrix33(){ - return matrix33; - } -} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/PdbxStructOperListXMLContainer.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/PdbxStructOperListXMLContainer.java deleted file mode 100644 index a1e94e4d03..0000000000 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/PdbxStructOperListXMLContainer.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * BioJava development code - * - * This code may be freely distributed and modified under the - * terms of the GNU Lesser General Public Licence. This should - * be distributed with the code. If you do not have a copy, - * see: - * - * http://www.gnu.org/copyleft/lesser.html - * - * Copyright for this code is held jointly by the individual - * authors. These should be listed in @author doc comments. - * - * For more information on the BioJava project and its aims, - * or to join the biojava-l mailing list, visit the home page - * at: - * - * http://www.biojava.org/ - * - */ -package org.biojava.nbio.structure.io.mmcif.model; - -import javax.xml.bind.JAXBContext; -import javax.xml.bind.Marshaller; -import javax.xml.bind.Unmarshaller; -import javax.xml.bind.annotation.XmlElementWrapper; -import javax.xml.bind.annotation.XmlRootElement; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.List; - -@XmlRootElement(name="PdbxStructOperListXMLContainer") -public class PdbxStructOperListXMLContainer { - - - - private List data ; - - static JAXBContext jaxbContext; - static { - try { - jaxbContext= JAXBContext.newInstance(PdbxStructOperList.class); - } catch (Exception e){ - e.printStackTrace(); - } - } - - @XmlElementWrapper - public List getPdbxStructOperLists(){ - return data; - - } - - public void setPdbxStructOperLists(List d){ - data = d; - } - - public String toXML(){ - - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - - PrintStream ps = new PrintStream(baos); - - try { - - Marshaller m = jaxbContext.createMarshaller(); - - m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); - - m.marshal( this, ps); - - - } catch (Exception e){ - e.printStackTrace(); - } - - return baos.toString(); - - } - - public static PdbxStructOperListXMLContainer fromXML(String xml){ - - PdbxStructOperListXMLContainer job = null; - - try { - - Unmarshaller un = jaxbContext.createUnmarshaller(); - - ByteArrayInputStream bais = new ByteArrayInputStream(xml.getBytes()); - - job = (PdbxStructOperListXMLContainer) un.unmarshal(bais); - - } catch (Exception e){ - e.printStackTrace(); - } - - return job; - } - -} 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 deleted file mode 100644 index dceb35b5ac..0000000000 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/Refine.java +++ /dev/null @@ -1,658 +0,0 @@ -/* - * BioJava development code - * - * This code may be freely distributed and modified under the - * terms of the GNU Lesser General Public Licence. This should - * be distributed with the code. If you do not have a copy, - * see: - * - * http://www.gnu.org/copyleft/lesser.html - * - * Copyright for this code is held jointly by the individual - * authors. These should be listed in @author doc comments. - * - * For more information on the BioJava project and its aims, - * or to join the biojava-l mailing list, visit the home page - * at: - * - * http://www.biojava.org/ - * - */ -package org.biojava.nbio.structure.io.mmcif.model; - -public class Refine { - String entry_id; - String ls_number_reflns_obs; - String ls_number_reflns_all; - String pdbx_ls_sigma_I; - String pdbx_ls_sigma_F; - String pdbx_data_cutoff_high_absF; - String pdbx_data_cutoff_low_absF ; - String pdbx_data_cutoff_high_rms_absF; - String ls_d_res_low ; - String ls_d_res_high ; - String ls_percent_reflns_obs; - String ls_R_factor_obs ; - String ls_R_factor_all ; - String ls_R_factor_R_work; - String ls_R_factor_R_free ; - String ls_R_factor_R_free_error; - String ls_R_factor_R_free_error_details; - String ls_percent_reflns_R_free; - String ls_number_reflns_R_free; - String ls_number_parameters; - String ls_number_restraints; - String occupancy_min; - String occupancy_max; - String B_iso_mean; - @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; - String pdbx_ls_cross_valid_method; - String details; - String pdbx_starting_model; - String pdbx_method_to_determine_struct; - String pdbx_isotropic_thermal_model; - String pdbx_stereochemistry_target_values; - String pdbx_stereochem_target_val_spec_case; - String pdbx_R_Free_selection_details; - String pdbx_overall_ESU_R; - String pdbx_overall_ESU_R_Free; - String overall_SU_ML; - String overall_SU_B; - String ls_redundancy_reflns_obs; - String pdbx_overall_phase_error ; - String B_iso_min; - String B_iso_max; - String correlation_coeff_Fo_to_Fc; - String correlation_coeff_Fo_to_Fc_free; - String pdbx_solvent_vdw_probe_radii; - String pdbx_solvent_ion_probe_radii; - String pdbx_solvent_shrinkage_radii; - String overall_SU_R_Cruickshank_DPI; - String overall_SU_R_free; - String ls_wR_factor_R_free; - String ls_wR_factor_R_work; - String overall_FOM_free_R_set; - String overall_FOM_work_R_set; - String pdbx_refine_id; - String pdbx_diffrn_id; - String pdbx_TLS_residual_ADP_flag; - String pdbx_overall_SU_R_free_Cruickshank_DPI; - String pdbx_overall_SU_R_Blow_DPI; - String pdbx_overall_SU_R_free_Blow_DPI; - // these 2 fields are present only in some files (e.g. 4lnc, a hybrid X-RAY/NEUTRON DIFFRACTION) - String ls_matrix_type; - String ls_number_reflns_R_work; - - public Refine(){ - //aniso_B = new String[3][3]; - } - - public String getEntry_id() { - return entry_id; - } - - public void setEntry_id(String entry_id) { - this.entry_id = entry_id; - } - - public String getLs_number_reflns_obs() { - return ls_number_reflns_obs; - } - - public void setLs_number_reflns_obs(String ls_number_reflns_obs) { - this.ls_number_reflns_obs = ls_number_reflns_obs; - } - - public String getLs_number_reflns_all() { - return ls_number_reflns_all; - } - - public void setLs_number_reflns_all(String ls_number_reflns_all) { - this.ls_number_reflns_all = ls_number_reflns_all; - } - - public String getPdbx_ls_sigma_I() { - return pdbx_ls_sigma_I; - } - - public void setPdbx_ls_sigma_I(String pdbx_ls_sigma_I) { - this.pdbx_ls_sigma_I = pdbx_ls_sigma_I; - } - - public String getPdbx_ls_sigma_F() { - return pdbx_ls_sigma_F; - } - - public void setPdbx_ls_sigma_F(String pdbx_ls_sigma_F) { - this.pdbx_ls_sigma_F = pdbx_ls_sigma_F; - } - - public String getPdbx_data_cutoff_high_absF() { - return pdbx_data_cutoff_high_absF; - } - - public void setPdbx_data_cutoff_high_absF(String pdbx_data_cutoff_high_absF) { - this.pdbx_data_cutoff_high_absF = pdbx_data_cutoff_high_absF; - } - - public String getPdbx_data_cutoff_low_absF() { - return pdbx_data_cutoff_low_absF; - } - - public void setPdbx_data_cutoff_low_absF(String pdbx_data_cutoff_low_absF) { - this.pdbx_data_cutoff_low_absF = pdbx_data_cutoff_low_absF; - } - - public String getPdbx_data_cutoff_high_rms_absF() { - return pdbx_data_cutoff_high_rms_absF; - } - - public void setPdbx_data_cutoff_high_rms_absF( - String pdbx_data_cutoff_high_rms_absF) { - this.pdbx_data_cutoff_high_rms_absF = pdbx_data_cutoff_high_rms_absF; - } - - public String getLs_d_res_low() { - return ls_d_res_low; - } - - public void setLs_d_res_low(String ls_d_res_low) { - this.ls_d_res_low = ls_d_res_low; - } - - public String getLs_d_res_high() { - return ls_d_res_high; - } - - public void setLs_d_res_high(String ls_d_res_high) { - this.ls_d_res_high = ls_d_res_high; - } - - public String getLs_percent_reflns_obs() { - return ls_percent_reflns_obs; - } - - public void setLs_percent_reflns_obs(String ls_percent_reflns_obs) { - this.ls_percent_reflns_obs = ls_percent_reflns_obs; - } - - public String getLs_R_factor_obs() { - return ls_R_factor_obs; - } - - public void setLs_R_factor_obs(String ls_R_factor_obs) { - this.ls_R_factor_obs = ls_R_factor_obs; - } - - public String getLs_R_factor_all() { - return ls_R_factor_all; - } - - public void setLs_R_factor_all(String ls_R_factor_all) { - this.ls_R_factor_all = ls_R_factor_all; - } - - public String getLs_R_factor_R_work() { - return ls_R_factor_R_work; - } - - public void setLs_R_factor_R_work(String ls_R_factor_R_work) { - this.ls_R_factor_R_work = ls_R_factor_R_work; - } - - public String getLs_R_factor_R_free() { - return ls_R_factor_R_free; - } - - public void setLs_R_factor_R_free(String ls_R_factor_R_free) { - this.ls_R_factor_R_free = ls_R_factor_R_free; - } - - public String getLs_R_factor_R_free_error() { - return ls_R_factor_R_free_error; - } - - public void setLs_R_factor_R_free_error(String ls_R_factor_R_free_error) { - this.ls_R_factor_R_free_error = ls_R_factor_R_free_error; - } - - public String getLs_R_factor_R_free_error_details() { - return ls_R_factor_R_free_error_details; - } - - public void setLs_R_factor_R_free_error_details( - String ls_R_factor_R_free_error_details) { - this.ls_R_factor_R_free_error_details = ls_R_factor_R_free_error_details; - } - - public String getLs_percent_reflns_R_free() { - return ls_percent_reflns_R_free; - } - - public void setLs_percent_reflns_R_free(String ls_percent_reflns_R_free) { - this.ls_percent_reflns_R_free = ls_percent_reflns_R_free; - } - - public String getLs_number_reflns_R_free() { - return ls_number_reflns_R_free; - } - - public void setLs_number_reflns_R_free(String ls_number_reflns_R_free) { - this.ls_number_reflns_R_free = ls_number_reflns_R_free; - } - - public String getLs_number_parameters() { - return ls_number_parameters; - } - - public void setLs_number_parameters(String ls_number_parameters) { - this.ls_number_parameters = ls_number_parameters; - } - - public String getLs_number_restraints() { - return ls_number_restraints; - } - - public void setLs_number_restraints(String ls_number_restraints) { - this.ls_number_restraints = ls_number_restraints; - } - - public String getOccupancy_min() { - return occupancy_min; - } - - public void setOccupancy_min(String occupancy_min) { - this.occupancy_min = occupancy_min; - } - - public String getOccupancy_max() { - return occupancy_max; - } - - public void setOccupancy_max(String occupancy_max) { - this.occupancy_max = occupancy_max; - } - - public String getB_iso_mean() { - return B_iso_mean; - } - - public void setB_iso_mean(String b_iso_mean) { - B_iso_mean = b_iso_mean; - } - - public String getSolvent_model_details() { - return solvent_model_details; - } - - public void setSolvent_model_details(String solvent_model_details) { - this.solvent_model_details = solvent_model_details; - } - - public String getSolvent_model_param_ksol() { - return solvent_model_param_ksol; - } - - public void setSolvent_model_param_ksol(String solvent_model_param_ksol) { - this.solvent_model_param_ksol = solvent_model_param_ksol; - } - - public String getSolvent_model_param_bsol() { - return solvent_model_param_bsol; - } - - public void setSolvent_model_param_bsol(String solvent_model_param_bsol) { - this.solvent_model_param_bsol = solvent_model_param_bsol; - } - - public String getPdbx_ls_cross_valid_method() { - return pdbx_ls_cross_valid_method; - } - - public void setPdbx_ls_cross_valid_method(String pdbx_ls_cross_valid_method) { - this.pdbx_ls_cross_valid_method = pdbx_ls_cross_valid_method; - } - - public String getDetails() { - return details; - } - - public void setDetails(String details) { - this.details = details; - } - - public String getPdbx_starting_model() { - return pdbx_starting_model; - } - - public void setPdbx_starting_model(String pdbx_starting_model) { - this.pdbx_starting_model = pdbx_starting_model; - } - - public String getPdbx_method_to_determine_struct() { - return pdbx_method_to_determine_struct; - } - - public void setPdbx_method_to_determine_struct( - String pdbx_method_to_determine_struct) { - this.pdbx_method_to_determine_struct = pdbx_method_to_determine_struct; - } - - public String getPdbx_isotropic_thermal_model() { - return pdbx_isotropic_thermal_model; - } - - public void setPdbx_isotropic_thermal_model(String pdbx_isotropic_thermal_model) { - this.pdbx_isotropic_thermal_model = pdbx_isotropic_thermal_model; - } - - public String getPdbx_stereochemistry_target_values() { - return pdbx_stereochemistry_target_values; - } - - public void setPdbx_stereochemistry_target_values( - String pdbx_stereochemistry_target_values) { - this.pdbx_stereochemistry_target_values = pdbx_stereochemistry_target_values; - } - - public String getPdbx_stereochem_target_val_spec_case() { - return pdbx_stereochem_target_val_spec_case; - } - - public void setPdbx_stereochem_target_val_spec_case( - String pdbx_stereochem_target_val_spec_case) { - this.pdbx_stereochem_target_val_spec_case = pdbx_stereochem_target_val_spec_case; - } - - public String getPdbx_R_Free_selection_details() { - return pdbx_R_Free_selection_details; - } - - public void setPdbx_R_Free_selection_details( - String pdbx_R_Free_selection_details) { - this.pdbx_R_Free_selection_details = pdbx_R_Free_selection_details; - } - - public String getPdbx_overall_ESU_R() { - return pdbx_overall_ESU_R; - } - - public void setPdbx_overall_ESU_R(String pdbx_overall_ESU_R) { - this.pdbx_overall_ESU_R = pdbx_overall_ESU_R; - } - - public String getPdbx_overall_ESU_R_Free() { - return pdbx_overall_ESU_R_Free; - } - - public void setPdbx_overall_ESU_R_Free(String pdbx_overall_ESU_R_Free) { - this.pdbx_overall_ESU_R_Free = pdbx_overall_ESU_R_Free; - } - - public String getOverall_SU_ML() { - return overall_SU_ML; - } - - public void setOverall_SU_ML(String overall_SU_ML) { - this.overall_SU_ML = overall_SU_ML; - } - - public String getOverall_SU_B() { - return overall_SU_B; - } - - public void setOverall_SU_B(String overall_SU_B) { - this.overall_SU_B = overall_SU_B; - } - - public String getPdbx_refine_id() { - return pdbx_refine_id; - } - - public void setPdbx_refine_id(String pdbx_refine_id) { - this.pdbx_refine_id = pdbx_refine_id; - } - - public String getLs_redundancy_reflns_obs() { - return ls_redundancy_reflns_obs; - } - - public void setLs_redundancy_reflns_obs(String ls_redundancy_reflns_obs) { - this.ls_redundancy_reflns_obs = ls_redundancy_reflns_obs; - } - - public String getPdbx_overall_phase_error() { - return pdbx_overall_phase_error; - } - - public void setPdbx_overall_phase_error(String pdbx_overall_phase_error) { - this.pdbx_overall_phase_error = pdbx_overall_phase_error; - } - - public String getB_iso_min() { - return B_iso_min; - } - - public void setB_iso_min(String b_iso_min) { - B_iso_min = b_iso_min; - } - - public String getB_iso_max() { - return B_iso_max; - } - - public void setB_iso_max(String b_iso_max) { - B_iso_max = b_iso_max; - } - - public String getCorrelation_coeff_Fo_to_Fc() { - return correlation_coeff_Fo_to_Fc; - } - - public void setCorrelation_coeff_Fo_to_Fc(String correlation_coeff_Fo_to_Fc) { - this.correlation_coeff_Fo_to_Fc = correlation_coeff_Fo_to_Fc; - } - - public String getCorrelation_coeff_Fo_to_Fc_free() { - return correlation_coeff_Fo_to_Fc_free; - } - - public void setCorrelation_coeff_Fo_to_Fc_free( - String correlation_coeff_Fo_to_Fc_free) { - this.correlation_coeff_Fo_to_Fc_free = correlation_coeff_Fo_to_Fc_free; - } - - public String getPdbx_solvent_vdw_probe_radii() { - return pdbx_solvent_vdw_probe_radii; - } - - public void setPdbx_solvent_vdw_probe_radii(String pdbx_solvent_vdw_probe_radii) { - this.pdbx_solvent_vdw_probe_radii = pdbx_solvent_vdw_probe_radii; - } - - public String getPdbx_solvent_ion_probe_radii() { - return pdbx_solvent_ion_probe_radii; - } - - public void setPdbx_solvent_ion_probe_radii(String pdbx_solvent_ion_probe_radii) { - this.pdbx_solvent_ion_probe_radii = pdbx_solvent_ion_probe_radii; - } - - public String getPdbx_solvent_shrinkage_radii() { - return pdbx_solvent_shrinkage_radii; - } - - public void setPdbx_solvent_shrinkage_radii(String pdbx_solvent_shrinkage_radii) { - this.pdbx_solvent_shrinkage_radii = pdbx_solvent_shrinkage_radii; - } - - public String getOverall_SU_R_Cruickshank_DPI() { - return overall_SU_R_Cruickshank_DPI; - } - - public void setOverall_SU_R_Cruickshank_DPI(String overall_SU_R_Cruickshank_DPI) { - this.overall_SU_R_Cruickshank_DPI = overall_SU_R_Cruickshank_DPI; - } - - public String getOverall_SU_R_free() { - return overall_SU_R_free; - } - - public void setOverall_SU_R_free(String overall_SU_R_free) { - this.overall_SU_R_free = overall_SU_R_free; - } - - public String getLs_wR_factor_R_free() { - return ls_wR_factor_R_free; - } - - public void setLs_wR_factor_R_free(String ls_wR_factor_R_free) { - this.ls_wR_factor_R_free = ls_wR_factor_R_free; - } - - public String getLs_wR_factor_R_work() { - return ls_wR_factor_R_work; - } - - public void setLs_wR_factor_R_work(String ls_wR_factor_R_work) { - this.ls_wR_factor_R_work = ls_wR_factor_R_work; - } - - public String getOverall_FOM_free_R_set() { - return overall_FOM_free_R_set; - } - - public void setOverall_FOM_free_R_set(String overall_FOM_free_R_set) { - this.overall_FOM_free_R_set = overall_FOM_free_R_set; - } - - public String getOverall_FOM_work_R_set() { - return overall_FOM_work_R_set; - } - - public void setOverall_FOM_work_R_set(String overall_FOM_work_R_set) { - this.overall_FOM_work_R_set = overall_FOM_work_R_set; - } - - public String getPdbx_diffrn_id() { - return pdbx_diffrn_id; - } - - public void setPdbx_diffrn_id(String pdbx_diffrn_id) { - this.pdbx_diffrn_id = pdbx_diffrn_id; - } - - public String getPdbx_TLS_residual_ADP_flag() { - return pdbx_TLS_residual_ADP_flag; - } - - public void setPdbx_TLS_residual_ADP_flag(String pdbx_TLS_residual_ADP_flag) { - this.pdbx_TLS_residual_ADP_flag = pdbx_TLS_residual_ADP_flag; - } - - public String getPdbx_overall_SU_R_free_Cruickshank_DPI() { - return pdbx_overall_SU_R_free_Cruickshank_DPI; - } - - public void setPdbx_overall_SU_R_free_Cruickshank_DPI( - String pdbx_overall_SU_R_free_Cruickshank_DPI) { - this.pdbx_overall_SU_R_free_Cruickshank_DPI = pdbx_overall_SU_R_free_Cruickshank_DPI; - } - - public String getPdbx_overall_SU_R_Blow_DPI() { - return pdbx_overall_SU_R_Blow_DPI; - } - - public void setPdbx_overall_SU_R_Blow_DPI(String pdbx_overall_SU_R_Blow_DPI) { - this.pdbx_overall_SU_R_Blow_DPI = pdbx_overall_SU_R_Blow_DPI; - } - - public String getPdbx_overall_SU_R_free_Blow_DPI() { - return pdbx_overall_SU_R_free_Blow_DPI; - } - - public void setPdbx_overall_SU_R_free_Blow_DPI( - String pdbx_overall_SU_R_free_Blow_DPI) { - this.pdbx_overall_SU_R_free_Blow_DPI = pdbx_overall_SU_R_free_Blow_DPI; - } - - public String getLs_matrix_type() { - return ls_matrix_type; - } - - public void setLs_matrix_type(String ls_matrix_type) { - this.ls_matrix_type = ls_matrix_type; - } - - public String getLs_number_reflns_R_work() { - return ls_number_reflns_R_work; - } - - 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/Struct.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/Struct.java deleted file mode 100644 index 09a711febe..0000000000 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/Struct.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * BioJava development code - * - * This code may be freely distributed and modified under the - * terms of the GNU Lesser General Public Licence. This should - * be distributed with the code. If you do not have a copy, - * see: - * - * http://www.gnu.org/copyleft/lesser.html - * - * Copyright for this code is held jointly by the individual - * authors. These should be listed in @author doc comments. - * - * For more information on the BioJava project and its aims, - * or to join the biojava-l mailing list, visit the home page - * at: - * - * http://www.biojava.org/ - * - * created at Apr 26, 2008 - */ -package org.biojava.nbio.structure.io.mmcif.model; - -/** a bean to contain the data of the _struct lines - * - * @author Andreas Prlic - * - */ -public class Struct { - String entry_id; - String title; - String pdbx_descriptor; - String pdbx_model_details; - String pdbx_model_type_details; - String pdbx_CASP_flag; - - @Override - public String toString(){ - return "entry_id:" +entry_id + " title:" + title + " pdbx_descriptor:" +pdbx_descriptor + " pdbx_model_details:"+pdbx_model_details; - } - - public String getEntry_id() { - return entry_id; - } - public void setEntry_id(String entry_id) { - this.entry_id = entry_id; - } - public String getTitle() { - return title; - } - public void setTitle(String title) { - this.title = title; - } - public String getPdbx_descriptor() { - return pdbx_descriptor; - } - public void setPdbx_descriptor(String pdbx_descriptor) { - this.pdbx_descriptor = pdbx_descriptor; - } - public String getPdbx_model_details() { - return pdbx_model_details; - } - public void setPdbx_model_details(String pdbx_model_details) { - this.pdbx_model_details = pdbx_model_details; - } - - public String getPdbx_model_type_details() { - return pdbx_model_type_details; - } - - public void setPdbx_model_type_details(String pdbx_model_type_details) { - this.pdbx_model_type_details = pdbx_model_type_details; - } - - public String getPdbx_CASP_flag() { - return pdbx_CASP_flag; - } - - public void setPdbx_CASP_flag(String pdbx_CASP_flag) { - this.pdbx_CASP_flag = pdbx_CASP_flag; - } - - - - -} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/StructAsym.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/StructAsym.java deleted file mode 100644 index f4c182b767..0000000000 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/StructAsym.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * BioJava development code - * - * This code may be freely distributed and modified under the - * terms of the GNU Lesser General Public Licence. This should - * be distributed with the code. If you do not have a copy, - * see: - * - * http://www.gnu.org/copyleft/lesser.html - * - * Copyright for this code is held jointly by the individual - * authors. These should be listed in @author doc comments. - * - * For more information on the BioJava project and its aims, - * or to join the biojava-l mailing list, visit the home page - * at: - * - * http://www.biojava.org/ - * - * created at Jun 1, 2008 - */ -package org.biojava.nbio.structure.io.mmcif.model; - -/** Contains the data for _struct_asym - * - * @author Andreas Prlic - * @since 1.7 - * - */ -public class StructAsym extends AbstractBean{ - String id; - String pdbx_blank_PDB_chainid_flag; - String pdbx_modified; - String entity_id; - String details; - public String getId() { - return id; - } - public void setId(String id) { - this.id = id; - } - public String getPdbx_blank_PDB_chainid_flag() { - return pdbx_blank_PDB_chainid_flag; - } - public void setPdbx_blank_PDB_chainid_flag(String pdbx_blank_PDB_chainid_flag) { - this.pdbx_blank_PDB_chainid_flag = pdbx_blank_PDB_chainid_flag; - } - public String getPdbx_modified() { - return pdbx_modified; - } - public void setPdbx_modified(String pdbx_modified) { - this.pdbx_modified = pdbx_modified; - } - public String getEntity_id() { - return entity_id; - } - public void setEntity_id(String entity_id) { - this.entity_id = entity_id; - } - public String getDetails() { - return details; - } - public void setDetails(String details) { - this.details = details; - } - - -} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/StructConn.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/StructConn.java deleted file mode 100644 index dbcb865dbd..0000000000 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/StructConn.java +++ /dev/null @@ -1,466 +0,0 @@ -/* - * PDB web development code - * - * This code may be freely distributed and modified under the - * terms of the GNU Lesser General Public Licence. This should - * be distributed with the code. If you do not have a copy, - * see: - * - * http://www.gnu.org/copyleft/lesser.html - * - * Copyright for this code is held jointly by the individual - * authors. These should be listed in @author doc comments. - * - * - * Created on Mar 05, 2014 - * Created by Peter Rose - * - */ - -package org.biojava.nbio.structure.io.mmcif.model; -/** - * A bean that stores data from the mmcif category _struct_conn - * @author Peter Rose - * - */ -public class StructConn extends AbstractBean -{ - private String id; - private String conn_type_id; - private String pdbx_PDB_id; - private String ptnr1_label_asym_id; - private String ptnr1_label_comp_id; - private String ptnr1_label_seq_id; - private String ptnr1_label_atom_id; - private String pdbx_ptnr1_label_alt_id; - private String pdbx_ptnr1_PDB_ins_code; - private String pdbx_ptnr1_standard_comp_id; - private String ptnr1_symmetry; - private String ptnr2_label_asym_id; - private String ptnr2_label_comp_id; - private String ptnr2_label_seq_id; - private String ptnr2_label_atom_id; - private String pdbx_ptnr2_label_alt_id; - private String pdbx_ptnr2_PDB_ins_code; - private String ptnr1_auth_asym_id; - private String ptnr1_auth_comp_id; - private String ptnr1_auth_seq_id; - private String ptnr2_auth_asym_id; - private String ptnr2_auth_comp_id; - private String ptnr2_auth_seq_id; - private String ptnr2_symmetry; - private String pdbx_ptnr3_label_atom_id; - private String pdbx_ptnr3_label_seq_id; - private String pdbx_ptnr3_label_comp_id; - private String pdbx_ptnr3_label_asym_id; - private String pdbx_ptnr3_label_alt_id; - private String pdbx_ptnr3_PDB_ins_code; - private String details; - private String pdbx_dist_value; - private String pdbx_value_order; - private String pdbx_leaving_atom_flag; - /** - * @return the id - */ - public String getId() { - return id; - } - /** - * @param id the id to set - */ - public void setId(String id) { - this.id = id; - } - /** - * @return the conn_type_id - */ - public String getConn_type_id() { - return conn_type_id; - } - /** - * @param conn_type_id the conn_type_id to set - */ - public void setConn_type_id(String conn_type_id) { - this.conn_type_id = conn_type_id; - } - /** - * @return the pdbx_PDB_id - */ - public String getPdbx_PDB_id() { - return pdbx_PDB_id; - } - /** - * @param pdbx_PDB_id the pdbx_PDB_id to set - */ - public void setPdbx_PDB_id(String pdbx_PDB_id) { - this.pdbx_PDB_id = pdbx_PDB_id; - } - /** - * @return the ptnr1_label_asym_id - */ - public String getPtnr1_label_asym_id() { - return ptnr1_label_asym_id; - } - /** - * @param ptnr1_label_asym_id the ptnr1_label_asym_id to set - */ - public void setPtnr1_label_asym_id(String ptnr1_label_asym_id) { - this.ptnr1_label_asym_id = ptnr1_label_asym_id; - } - /** - * @return the ptnr1_label_comp_id - */ - public String getPtnr1_label_comp_id() { - return ptnr1_label_comp_id; - } - /** - * @param ptnr1_label_comp_id the ptnr1_label_comp_id to set - */ - public void setPtnr1_label_comp_id(String ptnr1_label_comp_id) { - this.ptnr1_label_comp_id = ptnr1_label_comp_id; - } - /** - * @return the ptnr1_label_seq_id - */ - public String getPtnr1_label_seq_id() { - return ptnr1_label_seq_id; - } - /** - * @param ptnr1_label_seq_id the ptnr1_label_seq_id to set - */ - public void setPtnr1_label_seq_id(String ptnr1_label_seq_id) { - this.ptnr1_label_seq_id = ptnr1_label_seq_id; - } - /** - * @return the ptnr1_label_atom_id - */ - public String getPtnr1_label_atom_id() { - return ptnr1_label_atom_id; - } - /** - * @param ptnr1_label_atom_id the ptnr1_label_atom_id to set - */ - public void setPtnr1_label_atom_id(String ptnr1_label_atom_id) { - this.ptnr1_label_atom_id = ptnr1_label_atom_id; - } - /** - * @return the pdbx_ptnr1_label_alt_id - */ - public String getPdbx_ptnr1_label_alt_id() { - return pdbx_ptnr1_label_alt_id; - } - /** - * @param pdbx_ptnr1_label_alt_id the pdbx_ptnr1_label_alt_id to set - */ - public void setPdbx_ptnr1_label_alt_id(String pdbx_ptnr1_label_alt_id) { - this.pdbx_ptnr1_label_alt_id = pdbx_ptnr1_label_alt_id; - } - /** - * @return the pdbx_ptnr1_PDB_ins_code - */ - public String getPdbx_ptnr1_PDB_ins_code() { - return pdbx_ptnr1_PDB_ins_code; - } - /** - * @param pdbx_ptnr1_PDB_ins_code the pdbx_ptnr1_PDB_ins_code to set - */ - public void setPdbx_ptnr1_PDB_ins_code(String pdbx_ptnr1_PDB_ins_code) { - this.pdbx_ptnr1_PDB_ins_code = pdbx_ptnr1_PDB_ins_code; - } - /** - * @return the pdbx_ptnr1_standard_comp_id - */ - public String getPdbx_ptnr1_standard_comp_id() { - return pdbx_ptnr1_standard_comp_id; - } - /** - * @param pdbx_ptnr1_standard_comp_id the pdbx_ptnr1_standard_comp_id to set - */ - public void setPdbx_ptnr1_standard_comp_id(String pdbx_ptnr1_standard_comp_id) { - this.pdbx_ptnr1_standard_comp_id = pdbx_ptnr1_standard_comp_id; - } - /** - * @return the ptnr1_symmetry - */ - public String getPtnr1_symmetry() { - return ptnr1_symmetry; - } - /** - * @param ptnr1_symmetry the ptnr1_symmetry to set - */ - public void setPtnr1_symmetry(String ptnr1_symmetry) { - this.ptnr1_symmetry = ptnr1_symmetry; - } - /** - * @return the ptnr2_label_asym_id - */ - public String getPtnr2_label_asym_id() { - return ptnr2_label_asym_id; - } - /** - * @param ptnr2_label_asym_id the ptnr2_label_asym_id to set - */ - public void setPtnr2_label_asym_id(String ptnr2_label_asym_id) { - this.ptnr2_label_asym_id = ptnr2_label_asym_id; - } - /** - * @return the ptnr2_label_comp_id - */ - public String getPtnr2_label_comp_id() { - return ptnr2_label_comp_id; - } - /** - * @param ptnr2_label_comp_id the ptnr2_label_comp_id to set - */ - public void setPtnr2_label_comp_id(String ptnr2_label_comp_id) { - this.ptnr2_label_comp_id = ptnr2_label_comp_id; - } - /** - * @return the ptnr2_label_seq_id - */ - public String getPtnr2_label_seq_id() { - return ptnr2_label_seq_id; - } - /** - * @param ptnr2_label_seq_id the ptnr2_label_seq_id to set - */ - public void setPtnr2_label_seq_id(String ptnr2_label_seq_id) { - this.ptnr2_label_seq_id = ptnr2_label_seq_id; - } - /** - * @return the ptnr2_label_atom_id - */ - public String getPtnr2_label_atom_id() { - return ptnr2_label_atom_id; - } - /** - * @param ptnr2_label_atom_id the ptnr2_label_atom_id to set - */ - public void setPtnr2_label_atom_id(String ptnr2_label_atom_id) { - this.ptnr2_label_atom_id = ptnr2_label_atom_id; - } - /** - * @return the pdbx_ptnr2_label_alt_id - */ - public String getPdbx_ptnr2_label_alt_id() { - return pdbx_ptnr2_label_alt_id; - } - /** - * @param pdbx_ptnr2_label_alt_id the pdbx_ptnr2_label_alt_id to set - */ - public void setPdbx_ptnr2_label_alt_id(String pdbx_ptnr2_label_alt_id) { - this.pdbx_ptnr2_label_alt_id = pdbx_ptnr2_label_alt_id; - } - /** - * @return the pdbx_ptnr2_PDB_ins_code - */ - public String getPdbx_ptnr2_PDB_ins_code() { - return pdbx_ptnr2_PDB_ins_code; - } - /** - * @param pdbx_ptnr2_PDB_ins_code the pdbx_ptnr2_PDB_ins_code to set - */ - public void setPdbx_ptnr2_PDB_ins_code(String pdbx_ptnr2_PDB_ins_code) { - this.pdbx_ptnr2_PDB_ins_code = pdbx_ptnr2_PDB_ins_code; - } - /** - * @return the ptnr1_auth_asym_id - */ - public String getPtnr1_auth_asym_id() { - return ptnr1_auth_asym_id; - } - /** - * @param ptnr1_auth_asym_id the ptnr1_auth_asym_id to set - */ - public void setPtnr1_auth_asym_id(String ptnr1_auth_asym_id) { - this.ptnr1_auth_asym_id = ptnr1_auth_asym_id; - } - /** - * @return the ptnr1_auth_comp_id - */ - public String getPtnr1_auth_comp_id() { - return ptnr1_auth_comp_id; - } - /** - * @param ptnr1_auth_comp_id the ptnr1_auth_comp_id to set - */ - public void setPtnr1_auth_comp_id(String ptnr1_auth_comp_id) { - this.ptnr1_auth_comp_id = ptnr1_auth_comp_id; - } - /** - * @return the ptnr1_auth_seq_id - */ - public String getPtnr1_auth_seq_id() { - return ptnr1_auth_seq_id; - } - /** - * @param ptnr1_auth_seq_id the ptnr1_auth_seq_id to set - */ - public void setPtnr1_auth_seq_id(String ptnr1_auth_seq_id) { - this.ptnr1_auth_seq_id = ptnr1_auth_seq_id; - } - /** - * @return the ptnr2_auth_asym_id - */ - public String getPtnr2_auth_asym_id() { - return ptnr2_auth_asym_id; - } - /** - * @param ptnr2_auth_asym_id the ptnr2_auth_asym_id to set - */ - public void setPtnr2_auth_asym_id(String ptnr2_auth_asym_id) { - this.ptnr2_auth_asym_id = ptnr2_auth_asym_id; - } - /** - * @return the ptnr2_auth_comp_id - */ - public String getPtnr2_auth_comp_id() { - return ptnr2_auth_comp_id; - } - /** - * @param ptnr2_auth_comp_id the ptnr2_auth_comp_id to set - */ - public void setPtnr2_auth_comp_id(String ptnr2_auth_comp_id) { - this.ptnr2_auth_comp_id = ptnr2_auth_comp_id; - } - /** - * @return the ptnr2_auth_seq_id - */ - public String getPtnr2_auth_seq_id() { - return ptnr2_auth_seq_id; - } - /** - * @param ptnr2_auth_seq_id the ptnr2_auth_seq_id to set - */ - public void setPtnr2_auth_seq_id(String ptnr2_auth_seq_id) { - this.ptnr2_auth_seq_id = ptnr2_auth_seq_id; - } - /** - * @return the ptnr2_symmetry - */ - public String getPtnr2_symmetry() { - return ptnr2_symmetry; - } - /** - * @param ptnr2_symmetry the ptnr2_symmetry to set - */ - public void setPtnr2_symmetry(String ptnr2_symmetry) { - this.ptnr2_symmetry = ptnr2_symmetry; - } - /** - * @return the pdbx_ptnr3_label_atom_id - */ - public String getPdbx_ptnr3_label_atom_id() { - return pdbx_ptnr3_label_atom_id; - } - /** - * @param pdbx_ptnr3_label_atom_id the pdbx_ptnr3_label_atom_id to set - */ - public void setPdbx_ptnr3_label_atom_id(String pdbx_ptnr3_label_atom_id) { - this.pdbx_ptnr3_label_atom_id = pdbx_ptnr3_label_atom_id; - } - /** - * @return the pdbx_ptnr3_label_seq_id - */ - public String getPdbx_ptnr3_label_seq_id() { - return pdbx_ptnr3_label_seq_id; - } - /** - * @param pdbx_ptnr3_label_seq_id the pdbx_ptnr3_label_seq_id to set - */ - public void setPdbx_ptnr3_label_seq_id(String pdbx_ptnr3_label_seq_id) { - this.pdbx_ptnr3_label_seq_id = pdbx_ptnr3_label_seq_id; - } - /** - * @return the pdbx_ptnr3_label_comp_id - */ - public String getPdbx_ptnr3_label_comp_id() { - return pdbx_ptnr3_label_comp_id; - } - /** - * @param pdbx_ptnr3_label_comp_id the pdbx_ptnr3_label_comp_id to set - */ - public void setPdbx_ptnr3_label_comp_id(String pdbx_ptnr3_label_comp_id) { - this.pdbx_ptnr3_label_comp_id = pdbx_ptnr3_label_comp_id; - } - /** - * @return the pdbx_ptnr3_label_asym_id - */ - public String getPdbx_ptnr3_label_asym_id() { - return pdbx_ptnr3_label_asym_id; - } - /** - * @param pdbx_ptnr3_label_asym_id the pdbx_ptnr3_label_asym_id to set - */ - public void setPdbx_ptnr3_label_asym_id(String pdbx_ptnr3_label_asym_id) { - this.pdbx_ptnr3_label_asym_id = pdbx_ptnr3_label_asym_id; - } - /** - * @return the pdbx_ptnr3_label_alt_id - */ - public String getPdbx_ptnr3_label_alt_id() { - return pdbx_ptnr3_label_alt_id; - } - /** - * @param pdbx_ptnr3_label_alt_id the pdbx_ptnr3_label_alt_id to set - */ - public void setPdbx_ptnr3_label_alt_id(String pdbx_ptnr3_label_alt_id) { - this.pdbx_ptnr3_label_alt_id = pdbx_ptnr3_label_alt_id; - } - /** - * @return the pdbx_ptnr3_PDB_ins_code - */ - public String getPdbx_ptnr3_PDB_ins_code() { - return pdbx_ptnr3_PDB_ins_code; - } - /** - * @param pdbx_ptnr3_PDB_ins_code the pdbx_ptnr3_PDB_ins_code to set - */ - public void setPdbx_ptnr3_PDB_ins_code(String pdbx_ptnr3_PDB_ins_code) { - this.pdbx_ptnr3_PDB_ins_code = pdbx_ptnr3_PDB_ins_code; - } - /** - * @return the details - */ - public String getDetails() { - return details; - } - /** - * @param details the details to set - */ - public void setDetails(String details) { - this.details = details; - } - /** - * @return the pdbx_dist_value - */ - public String getPdbx_dist_value() { - return pdbx_dist_value; - } - /** - * @param pdbx_dist_value the pdbx_dist_value to set - */ - public void setPdbx_dist_value(String pdbx_dist_value) { - this.pdbx_dist_value = pdbx_dist_value; - } - /** - * @return the pdbx_value_order - */ - public String getPdbx_value_order() { - return pdbx_value_order; - } - /** - * @param pdbx_value_order the pdbx_value_order to set - */ - public void setPdbx_value_order(String pdbx_value_order) { - this.pdbx_value_order = pdbx_value_order; - } - - public String getPdbx_leaving_atom_flag() { - return pdbx_leaving_atom_flag; - } - - public void setPdbx_leaving_atom_flag(String pdbx_leaving_atom_flag) { - this.pdbx_leaving_atom_flag = pdbx_leaving_atom_flag; - } -} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/StructKeywords.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/StructKeywords.java deleted file mode 100644 index f09fa63d62..0000000000 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/StructKeywords.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * BioJava development code - * - * This code may be freely distributed and modified under the - * terms of the GNU Lesser General Public Licence. This should - * be distributed with the code. If you do not have a copy, - * see: - * - * http://www.gnu.org/copyleft/lesser.html - * - * Copyright for this code is held jointly by the individual - * authors. These should be listed in @author doc comments. - * - * For more information on the BioJava project and its aims, - * or to join the biojava-l mailing list, visit the home page - * at: - * - * http://www.biojava.org/ - * - */ -package org.biojava.nbio.structure.io.mmcif.model; - -public class StructKeywords { - String entry_id; - String pdbx_keywords; - String text; - public String getEntry_id() { - return entry_id; - } - public void setEntry_id(String entry_id) { - this.entry_id = entry_id; - } - public String getPdbx_keywords() { - return pdbx_keywords; - } - public void setPdbx_keywords(String pdbx_keywords) { - this.pdbx_keywords = pdbx_keywords; - } - public String getText() { - return text; - } - public void setText(String text) { - this.text = text; - } - -} 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 deleted file mode 100644 index 2ec97bfb32..0000000000 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/StructNcsOper.java +++ /dev/null @@ -1,282 +0,0 @@ -/* - * BioJava development code - * - * This code may be freely distributed and modified under the - * terms of the GNU Lesser General Public Licence. This should - * be distributed with the code. If you do not have a copy, - * see: - * - * http://www.gnu.org/copyleft/lesser.html - * - * Copyright for this code is held jointly by the individual - * authors. These should be listed in @author doc comments. - * - * For more information on the BioJava project and its aims, - * or to join the biojava-l mailing list, visit the home page - * at: - * - * http://www.biojava.org/ - * - */ -package org.biojava.nbio.structure.io.mmcif.model; - - -/** - * A class containing the _struct_ncs_oper data - * - *
- *  _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 String id; - private String code; - private String details; - - @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(String id) { - this.id = id; - } - - public String getCode() { - return code; - } - - public void setCode(String code) { - this.code = code; - } - - public String getDetails() { - return details; - } - - public void setDetails(String details) { - this.details = details; - } - - /** - * @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; - } - - /** - * @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/StructRef.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/StructRef.java deleted file mode 100644 index 750f4c7b68..0000000000 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/StructRef.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * BioJava development code - * - * This code may be freely distributed and modified under the - * terms of the GNU Lesser General Public Licence. This should - * be distributed with the code. If you do not have a copy, - * see: - * - * http://www.gnu.org/copyleft/lesser.html - * - * Copyright for this code is held jointly by the individual - * authors. These should be listed in @author doc comments. - * - * For more information on the BioJava project and its aims, - * or to join the biojava-l mailing list, visit the home page - * at: - * - * http://www.biojava.org/ - * - * created at May 31, 2008 - */ -package org.biojava.nbio.structure.io.mmcif.model; - -/** A class to containt the _struct_ref field data - * - * @author Andreas Prlic - * - */ -public class StructRef extends AbstractBean { - String id; - String db_name; - String db_code; - String entity_id; - String pdbx_db_accession; - String pdbx_align_begin; - String pdbx_seq_one_letter_code; - String biol_id; - public String getBiol_id() { - return biol_id; - } - public void setBiol_id(String biol_id) { - this.biol_id = biol_id; - } - public String getId() { - return id; - } - public void setId(String id) { - this.id = id; - } - public String getDb_name() { - return db_name; - } - public void setDb_name(String db_name) { - this.db_name = db_name; - } - public String getDb_code() { - return db_code; - } - public void setDb_code(String db_code) { - this.db_code = db_code; - } - public String getEntity_id() { - return entity_id; - } - public void setEntity_id(String entity_id) { - this.entity_id = entity_id; - } - public String getPdbx_db_accession() { - return pdbx_db_accession; - } - public void setPdbx_db_accession(String pdbx_db_accession) { - this.pdbx_db_accession = pdbx_db_accession; - } - public String getPdbx_align_begin() { - return pdbx_align_begin; - } - public void setPdbx_align_begin(String pdbx_align_begin) { - this.pdbx_align_begin = pdbx_align_begin; - } - public String getPdbx_seq_one_letter_code() { - return pdbx_seq_one_letter_code; - } - public void setPdbx_seq_one_letter_code(String pdbx_seq_one_letter_code) { - this.pdbx_seq_one_letter_code = pdbx_seq_one_letter_code; - } - - - -} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/StructRefSeq.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/StructRefSeq.java deleted file mode 100644 index 32d14314bf..0000000000 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/StructRefSeq.java +++ /dev/null @@ -1,146 +0,0 @@ -/* - * BioJava development code - * - * This code may be freely distributed and modified under the - * terms of the GNU Lesser General Public Licence. This should - * be distributed with the code. If you do not have a copy, - * see: - * - * http://www.gnu.org/copyleft/lesser.html - * - * Copyright for this code is held jointly by the individual - * authors. These should be listed in @author doc comments. - * - * For more information on the BioJava project and its aims, - * or to join the biojava-l mailing list, visit the home page - * at: - * - * http://www.biojava.org/ - * - * created at May 31, 2008 - */ -package org.biojava.nbio.structure.io.mmcif.model; - -public class StructRefSeq extends AbstractBean{ - String align_id; - String ref_id; - String pdbx_PDB_id_code; - String pdbx_strand_id; - String seq_align_beg; - String pdbx_seq_align_beg_ins_code; - String seq_align_end; - String pdbx_seq_align_end_ins_code; - String pdbx_db_accession; - String db_align_beg; - String pdbx_db_align_beg_ins_code; - String db_align_end; - String pdbx_db_align_end_ins_code; - String pdbx_auth_seq_align_beg; - String pdbx_auth_seq_align_end; - String details; - - public StructRefSeq(){ - super(); - pdbx_db_align_beg_ins_code = "?"; - pdbx_db_align_end_ins_code = "?"; - - } - - public String getAlign_id() { - return align_id; - } - public void setAlign_id(String align_id) { - this.align_id = align_id; - } - public String getRef_id() { - return ref_id; - } - public void setRef_id(String ref_id) { - this.ref_id = ref_id; - } - public String getPdbx_PDB_id_code() { - return pdbx_PDB_id_code; - } - public void setPdbx_PDB_id_code(String pdbx_PDB_id_code) { - this.pdbx_PDB_id_code = pdbx_PDB_id_code; - } - public String getPdbx_strand_id() { - return pdbx_strand_id; - } - public void setPdbx_strand_id(String pdbx_strand_id) { - this.pdbx_strand_id = pdbx_strand_id; - } - public String getSeq_align_beg() { - return seq_align_beg; - } - public void setSeq_align_beg(String seq_align_beg) { - this.seq_align_beg = seq_align_beg; - } - public String getPdbx_seq_align_beg_ins_code() { - return pdbx_seq_align_beg_ins_code; - } - public void setPdbx_seq_align_beg_ins_code(String pdbx_seq_align_beg_ins_code) { - this.pdbx_seq_align_beg_ins_code = pdbx_seq_align_beg_ins_code; - } - public String getSeq_align_end() { - return seq_align_end; - } - public void setSeq_align_end(String seq_align_end) { - this.seq_align_end = seq_align_end; - } - public String getPdbx_seq_align_end_ins_code() { - return pdbx_seq_align_end_ins_code; - } - public void setPdbx_seq_align_end_ins_code(String pdbx_seq_align_end_ins_code) { - this.pdbx_seq_align_end_ins_code = pdbx_seq_align_end_ins_code; - } - public String getPdbx_db_accession() { - return pdbx_db_accession; - } - public void setPdbx_db_accession(String pdbx_db_accession) { - this.pdbx_db_accession = pdbx_db_accession; - } - public String getDb_align_beg() { - return db_align_beg; - } - public void setDb_align_beg(String db_align_beg) { - this.db_align_beg = db_align_beg; - } - public String getPdbx_db_align_beg_ins_code() { - return pdbx_db_align_beg_ins_code; - } - public void setPdbx_db_align_beg_ins_code(String pdbx_db_align_beg_ins_code) { - this.pdbx_db_align_beg_ins_code = pdbx_db_align_beg_ins_code; - } - public String getDb_align_end() { - return db_align_end; - } - public void setDb_align_end(String db_align_end) { - this.db_align_end = db_align_end; - } - public String getPdbx_db_align_end_ins_code() { - return pdbx_db_align_end_ins_code; - } - public void setPdbx_db_align_end_ins_code(String pdbx_db_align_end_ins_code) { - this.pdbx_db_align_end_ins_code = pdbx_db_align_end_ins_code; - } - public String getPdbx_auth_seq_align_beg() { - return pdbx_auth_seq_align_beg; - } - public void setPdbx_auth_seq_align_beg(String pdbx_auth_seq_align_beg) { - this.pdbx_auth_seq_align_beg = pdbx_auth_seq_align_beg; - } - public String getPdbx_auth_seq_align_end() { - return pdbx_auth_seq_align_end; - } - public void setPdbx_auth_seq_align_end(String pdbx_auth_seq_align_end) { - this.pdbx_auth_seq_align_end = pdbx_auth_seq_align_end; - } - public String getDetails() { - return details; - } - public void setDetails(String details) { - this.details = details; - } - -} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/StructRefSeqDif.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/StructRefSeqDif.java deleted file mode 100644 index 0b70bcb00e..0000000000 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/StructRefSeqDif.java +++ /dev/null @@ -1,147 +0,0 @@ -package org.biojava.nbio.structure.io.mmcif.model; - -/* - * BioJava development code - * - * This code may be freely distributed and modified under the - * terms of the GNU Lesser General Public Licence. This should - * be distributed with the code. If you do not have a copy, - * see: - * - * http://www.gnu.org/copyleft/lesser.html - * - * Copyright for this code is held jointly by the individual - * authors. These should be listed in @author doc comments. - * - * For more information on the BioJava project and its aims, - * or to join the biojava-l mailing list, visit the home page - * at: - * - * http://www.biojava.org/ - * - * Created by andreas on 9/11/15. - */ - -/** A class to store sequence mismatch annotations - * - */ -public class StructRefSeqDif { - - String align_id; - String pdbx_pdb_id_code; - String mon_id; - String pdbx_pdb_strand_id; - Integer seq_num; - String pdbx_pdb_ins_code; - String pdbx_seq_db_name; - String pdbx_seq_db_accession_code; - String db_mon_id; - String pdbx_seq_db_seq_num; - String details; - String pdbx_auth_seq_num; - Integer pdbx_ordinal; - - public String getAlign_id() { - return align_id; - } - - public void setAlign_id(String align_id) { - this.align_id = align_id; - } - - public String getPdbx_pdb_id_code() { - return pdbx_pdb_id_code; - } - - public void setPdbx_pdb_id_code(String pdbx_pdb_id_code) { - this.pdbx_pdb_id_code = pdbx_pdb_id_code; - } - - public String getMon_id() { - return mon_id; - } - - public void setMon_id(String mon_id) { - this.mon_id = mon_id; - } - - public String getPdbx_pdb_strand_id() { - return pdbx_pdb_strand_id; - } - - public void setPdbx_pdb_strand_id(String pdbx_pdb_strand_id) { - this.pdbx_pdb_strand_id = pdbx_pdb_strand_id; - } - - public Integer getSeq_num() { - return seq_num; - } - - public void setSeq_num(Integer seq_num) { - this.seq_num = seq_num; - } - - public String getPdbx_pdb_ins_code() { - return pdbx_pdb_ins_code; - } - - public void setPdbx_pdb_ins_code(String pdbx_pdb_ins_code) { - this.pdbx_pdb_ins_code = pdbx_pdb_ins_code; - } - - public String getPdbx_seq_db_name() { - return pdbx_seq_db_name; - } - - public void setPdbx_seq_db_name(String pdbx_seq_db_name) { - this.pdbx_seq_db_name = pdbx_seq_db_name; - } - - public String getPdbx_seq_db_accession_code() { - return pdbx_seq_db_accession_code; - } - - public void setPdbx_seq_db_accession_code(String pdbx_seq_db_accession_code) { - this.pdbx_seq_db_accession_code = pdbx_seq_db_accession_code; - } - - public String getDb_mon_id() { - return db_mon_id; - } - - public void setDb_mon_id(String db_mon_id) { - this.db_mon_id = db_mon_id; - } - - public String getPdbx_seq_db_seq_num() { - return pdbx_seq_db_seq_num; - } - - public void setPdbx_seq_db_seq_num(String pdbx_seq_db_seq_num) { - this.pdbx_seq_db_seq_num = pdbx_seq_db_seq_num; - } - - public String getDetails() { - return details; - } - - public void setDetails(String details) { - this.details = details; - } - - public String getPdbx_auth_seq_num() { - return pdbx_auth_seq_num; - } - - public void setPdbx_auth_seq_num(String pdbx_auth_seq_num) { - this.pdbx_auth_seq_num = pdbx_auth_seq_num; - } - - public Integer getPdbx_ordinal() { - return pdbx_ordinal; - } - - public void setPdbx_ordinal(Integer pdbx_ordinal) { - this.pdbx_ordinal = pdbx_ordinal; - } -} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/StructSite.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/StructSite.java deleted file mode 100644 index 21179b51f5..0000000000 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/StructSite.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * BioJava development code - * - * This code may be freely distributed and modified under the - * terms of the GNU Lesser General Public Licence. This should - * be distributed with the code. If you do not have a copy, - * see: - * - * http://www.gnu.org/copyleft/lesser.html - * - * Copyright for this code is held jointly by the individual - * authors. These should be listed in @author doc comments. - * - * For more information on the BioJava project and its aims, - * or to join the biojava-l mailing list, visit the home page - * at: - * - * http://www.biojava.org/ - * - */ -package org.biojava.nbio.structure.io.mmcif.model; - -/** - * Created by Matt on 11/1/2015. - */ -public class StructSite { - String id; - String details; - String pdbx_evidence_code; - String pdbx_auth_asym_id; - String pdbx_auth_comp_id; - String pdbx_auth_seq_id; - String pdbx_num_residues; - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getDetails() { - return details; - } - - public void setDetails(String details) { - this.details = details; - } - - public String getPdbx_evidence_code() { - return pdbx_evidence_code; - } - - public void setPdbx_evidence_code(String pdbx_evidence_code) { - this.pdbx_evidence_code = pdbx_evidence_code; - } - - /** - * @return the pdbx_auth_asym_id - */ - public String getPdbx_auth_asym_id() { - return pdbx_auth_asym_id; - } - - /** - * @param pdbx_auth_asym_id the pdbx_auth_asym_id to set - */ - public void setPdbx_auth_asym_id(String pdbx_auth_asym_id) { - this.pdbx_auth_asym_id = pdbx_auth_asym_id; - } - - /** - * @return the pdbx_auth_comp_id - */ - public String getPdbx_auth_comp_id() { - return pdbx_auth_comp_id; - } - - /** - * @param pdbx_auth_comp_id the pdbx_auth_comp_id to set - */ - public void setPdbx_auth_comp_id(String pdbx_auth_comp_id) { - this.pdbx_auth_comp_id = pdbx_auth_comp_id; - } - - /** - * @return the pdbx_auth_seq_id - */ - public String getPdbx_auth_seq_id() { - return pdbx_auth_seq_id; - } - - /** - * @param pdbx_auth_seq_id the pdbx_auth_seq_id to set - */ - public void setPdbx_auth_seq_id(String pdbx_auth_seq_id) { - this.pdbx_auth_seq_id = pdbx_auth_seq_id; - } - - /** - * @return the pdbx_num_residues - */ - public String getPdbx_num_residues() { - return pdbx_num_residues; - } - - /** - * @param pdbx_num_residues the pdbx_num_residues to set - */ - public void setPdbx_num_residues(String pdbx_num_residues) { - this.pdbx_num_residues = pdbx_num_residues; - } -} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/StructSiteGen.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/StructSiteGen.java deleted file mode 100644 index 8cb91fe6dc..0000000000 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/StructSiteGen.java +++ /dev/null @@ -1,166 +0,0 @@ -/* - * BioJava development code - * - * This code may be freely distributed and modified under the - * terms of the GNU Lesser General Public Licence. This should - * be distributed with the code. If you do not have a copy, - * see: - * - * http://www.gnu.org/copyleft/lesser.html - * - * Copyright for this code is held jointly by the individual - * authors. These should be listed in @author doc comments. - * - * For more information on the BioJava project and its aims, - * or to join the biojava-l mailing list, visit the home page - * at: - * - * http://www.biojava.org/ - * - */ -package org.biojava.nbio.structure.io.mmcif.model; - -/** - * Created by Matt on 10/31/2015. - */ -public class StructSiteGen extends AbstractBean { - String id; - String site_id; - String auth_asym_id; - String auth_atom_id; - String auth_comp_id; - String auth_seq_id; - String label_alt_id; - String label_asym_id; - String label_atom_id; - String label_comp_id; - String label_seq_id; - String details; - String pdbx_auth_ins_code; - String pdbx_num_res; - String symmetry; - - public StructSiteGen() { - super(); - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getSite_id() { - return site_id; - } - - public void setSite_id(String site_id) { - this.site_id = site_id; - } - - public String getAuth_asym_id() { - return auth_asym_id; - } - - public void setAuth_asym_id(String auth_asym_id) { - this.auth_asym_id = auth_asym_id; - } - - public String getAuth_atom_id() { - return auth_atom_id; - } - - public void setAuth_atom_id(String auth_atom_id) { - this.auth_atom_id = auth_atom_id; - } - - public String getAuth_comp_id() { - return auth_comp_id; - } - - public void setAuth_comp_id(String auth_comp_id) { - this.auth_comp_id = auth_comp_id; - } - - public String getAuth_seq_id() { - return auth_seq_id; - } - - public void setAuth_seq_id(String auth_seq_id) { - this.auth_seq_id = auth_seq_id; - } - - public String getLabel_alt_id() { - return label_alt_id; - } - - public void setLabel_alt_id(String label_alt_id) { - this.label_alt_id = label_alt_id; - } - - public String getLabel_asym_id() { - return label_asym_id; - } - - public void setLabel_asym_id(String label_asym_id) { - this.label_asym_id = label_asym_id; - } - - public String getLabel_atom_id() { - return label_atom_id; - } - - public void setLabel_atom_id(String label_atom_id) { - this.label_atom_id = label_atom_id; - } - - public String getLabel_comp_id() { - return label_comp_id; - } - - public void setLabel_comp_id(String label_comp_id) { - this.label_comp_id = label_comp_id; - } - - public String getLabel_seq_id() { - return label_seq_id; - } - - public void setLabel_seq_id(String label_seq_id) { - this.label_seq_id = label_seq_id; - } - - public String getDetails() { - return details; - } - - public void setDetails(String details) { - this.details = details; - } - - public String getPdbx_auth_ins_code() { - return pdbx_auth_ins_code; - } - - public void setPdbx_auth_ins_code(String pdbx_auth_ins_code) { - this.pdbx_auth_ins_code = pdbx_auth_ins_code; - } - - public String getPdbx_num_res() { - return pdbx_num_res; - } - - public void setPdbx_num_res(String pdbx_num_res) { - this.pdbx_num_res = pdbx_num_res; - } - - public String getSymmetry() { - return symmetry; - } - - public void setSymmetry(String symmetry) { - this.symmetry = symmetry; - } -} 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 deleted file mode 100644 index d91ef11718..0000000000 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/Symmetry.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * BioJava development code - * - * This code may be freely distributed and modified under the - * terms of the GNU Lesser General Public Licence. This should - * be distributed with the code. If you do not have a copy, - * see: - * - * http://www.gnu.org/copyleft/lesser.html - * - * Copyright for this code is held jointly by the individual - * authors. These should be listed in @author doc comments. - * - * For more information on the BioJava project and its aims, - * or to join the biojava-l mailing list, visit the home page - * at: - * - * http://www.biojava.org/ - * - */ -package org.biojava.nbio.structure.io.mmcif.model; - - -public class Symmetry extends AbstractBean { - - String entry_id; - @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; - String space_group_name_Hall; - public String getEntry_id() { - return entry_id; - } - public void setEntry_id(String entry_id) { - this.entry_id = entry_id; - } - public String getSpace_group_name_H_M() { - return space_group_name_H_M; - } - public void setSpace_group_name_H_M(String space_group_name_H_M) { - this.space_group_name_H_M = space_group_name_H_M; - } - public String getPdbx_full_space_group_name_H_M() { - return pdbx_full_space_group_name_H_M; - } - public void setPdbx_full_space_group_name_H_M( - String pdbx_full_space_group_name_H_M) { - this.pdbx_full_space_group_name_H_M = pdbx_full_space_group_name_H_M; - } - public String getCell_setting() { - return cell_setting; - } - public void setCell_setting(String cell_setting) { - this.cell_setting = cell_setting; - } - public String getInt_Tables_number() { - return Int_Tables_number; - } - public void setInt_Tables_number(String int_Tables_number) { - Int_Tables_number = int_Tables_number; - } - public String getSpace_group_name_Hall() { - return space_group_name_Hall; - } - public void setSpace_group_name_Hall(String space_group_name_Hall) { - this.space_group_name_Hall = space_group_name_Hall; - } -} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/package-info.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/package-info.java deleted file mode 100644 index 7f362f0d27..0000000000 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/package-info.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * BioJava development code - * - * This code may be freely distributed and modified under the - * terms of the GNU Lesser General Public Licence. This should - * be distributed with the code. If you do not have a copy, - * see: - * - * http://www.gnu.org/copyleft/lesser.html - * - * Copyright for this code is held jointly by the individual - * authors. These should be listed in @author doc comments. - * - * For more information on the BioJava project and its aims, - * or to join the biojava-l mailing list, visit the home page - * at: - * - * http://www.biojava.org/ - * - */ -/** - * Datamodel objects used for processing mmcif files. This are beans that can represent the data from a category in mmcif. - */ -package org.biojava.nbio.structure.io.mmcif.model; \ No newline at end of file diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/package-info.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/package-info.java deleted file mode 100644 index 02a4328875..0000000000 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/package-info.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * BioJava development code - * - * This code may be freely distributed and modified under the - * terms of the GNU Lesser General Public Licence. This should - * be distributed with the code. If you do not have a copy, - * see: - * - * http://www.gnu.org/copyleft/lesser.html - * - * Copyright for this code is held jointly by the individual - * authors. These should be listed in @author doc comments. - * - * For more information on the BioJava project and its aims, - * or to join the biojava-l mailing list, visit the home page - * at: - * - * http://www.biojava.org/ - * - */ -/** - * Input and Output of mmcif files. - * - * See also the BioJava 3 tutorial for more information on mmCif parsing. - */ -package org.biojava.nbio.structure.io.mmcif; \ No newline at end of file diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/quaternary/BiologicalAssemblyBuilder.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/quaternary/BiologicalAssemblyBuilder.java index 502730dcf3..083633c28f 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/quaternary/BiologicalAssemblyBuilder.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/quaternary/BiologicalAssemblyBuilder.java @@ -25,9 +25,9 @@ import org.biojava.nbio.structure.Chain; import org.biojava.nbio.structure.EntityInfo; import org.biojava.nbio.structure.Structure; -import org.biojava.nbio.structure.io.mmcif.model.PdbxStructAssembly; -import org.biojava.nbio.structure.io.mmcif.model.PdbxStructAssemblyGen; -import org.biojava.nbio.structure.io.mmcif.model.PdbxStructOperList; +import org.rcsb.cif.schema.mm.PdbxStructAssembly; +import org.rcsb.cif.schema.mm.PdbxStructAssemblyGen; +import org.rcsb.cif.schema.mm.PdbxStructOperList; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -242,121 +242,118 @@ private void addChainFlattened(Structure s, Chain newChain, String transformId) * Returns a list of transformation matrices for the generation of a macromolecular * assembly for the specified assembly Id. * - * @param psa - * @param psags - * @param operators + * @param pdbxStructAssembly + * @param assemblyIndex + * @param pdbxStructAssemblyGen + * @param pdbxStructOperList * @return list of transformation matrices to generate macromolecular assembly */ - public ArrayList getBioUnitTransformationList(PdbxStructAssembly psa, List psags, List operators) { + public List getBioUnitTransformationList(PdbxStructAssembly pdbxStructAssembly, + int assemblyIndex, + PdbxStructAssemblyGen pdbxStructAssemblyGen, + PdbxStructOperList pdbxStructOperList) { init(); // first we populate the list of all operators from pdbx_struct_oper_list so that we can then // get them from getBioUnitTransformationsListUnaryOperators() and getBioUnitTransformationsListBinaryOperators() - for (PdbxStructOperList oper: operators){ + for (int i = 0; i < pdbxStructOperList.getRowCount(); i++) { try { Matrix4d m = new Matrix4d(); - m.m00 = Double.parseDouble(oper.getMatrix11()); - m.m01 = Double.parseDouble(oper.getMatrix12()); - m.m02 = Double.parseDouble(oper.getMatrix13()); + m.m00 = pdbxStructOperList.getMatrix11().get(i); + m.m01 = pdbxStructOperList.getMatrix12().get(i); + m.m02 = pdbxStructOperList.getMatrix13().get(i); - m.m10 = Double.parseDouble(oper.getMatrix21()); - m.m11 = Double.parseDouble(oper.getMatrix22()); - m.m12 = Double.parseDouble(oper.getMatrix23()); + m.m10 = pdbxStructOperList.getMatrix21().get(i); + m.m11 = pdbxStructOperList.getMatrix22().get(i); + m.m12 = pdbxStructOperList.getMatrix23().get(i); - m.m20 = Double.parseDouble(oper.getMatrix31()); - m.m21 = Double.parseDouble(oper.getMatrix32()); - m.m22 = Double.parseDouble(oper.getMatrix33()); + m.m20 = pdbxStructOperList.getMatrix31().get(i); + m.m21 = pdbxStructOperList.getMatrix32().get(i); + m.m22 = pdbxStructOperList.getMatrix33().get(i); - m.m03 = Double.parseDouble(oper.getVector1()); - m.m13 = Double.parseDouble(oper.getVector2()); - m.m23 = Double.parseDouble(oper.getVector3()); + m.m03 = pdbxStructOperList.getVector1().get(i); + m.m13 = pdbxStructOperList.getVector2().get(i); + m.m23 = pdbxStructOperList.getVector3().get(i); m.m30 = 0; m.m31 = 0; m.m32 = 0; m.m33 = 1; - allTransformations.put(oper.getId(), m); - + allTransformations.put(pdbxStructOperList.getId().get(i), m); } catch (NumberFormatException e) { - logger.warn("Could not parse a matrix value from pdbx_struct_oper_list for id {}. The operator id will be ignored. Error: {}", oper.getId(), e.getMessage()); + logger.warn("Could not parse a matrix value from pdbx_struct_oper_list for id {}. The operator id will be ignored. Error: {}", pdbxStructOperList.getId().get(i), e.getMessage()); } } - ArrayList transformations = getBioUnitTransformationsListUnaryOperators(psa.getId(), psags); - transformations.addAll(getBioUnitTransformationsListBinaryOperators(psa.getId(), psags)); + String assemblyId = pdbxStructAssembly.getId().get(assemblyIndex); + ArrayList transformations = getBioUnitTransformationsListUnaryOperators(assemblyId, pdbxStructAssemblyGen); + transformations.addAll(getBioUnitTransformationsListBinaryOperators(assemblyId, pdbxStructAssemblyGen)); transformations.trimToSize(); return transformations; } - - private ArrayList getBioUnitTransformationsListBinaryOperators(String assemblyId, List psags) { - + private ArrayList getBioUnitTransformationsListBinaryOperators(String assemblyId, PdbxStructAssemblyGen pdbxStructAssemblyGen) { ArrayList transformations = new ArrayList<>(); - List> operators = operatorResolver.getBinaryOperators(); + for (int i = 0; i < pdbxStructAssemblyGen.getRowCount(); i++) { + if (!pdbxStructAssemblyGen.getAssemblyId().get(i).equals(assemblyId)) { + continue; + } - for ( PdbxStructAssemblyGen psag : psags){ - if ( psag.getAssembly_id().equals(assemblyId)) { - - ListasymIds= Arrays.asList(psag.getAsym_id_list().split(",")); - - operatorResolver.parseOperatorExpressionString(psag.getOper_expression()); - - // apply binary operators to the specified chains - // Example 1M4X: generates all products of transformation matrices (1-60)(61-88) - for (String chainId : asymIds) { - - for (OrderedPair operator : operators) { - Matrix4d original1 = allTransformations.get(operator.getElement1()); - Matrix4d original2 = allTransformations.get(operator.getElement2()); - if (original1 == null || original2 == null) { - logger.warn("Could not find matrix operator for operator id {} or {}. Assembly id {} will not contain the composed operator.", operator.getElement1(), operator.getElement2(), assemblyId); - continue; - } - Matrix4d composed = new Matrix4d(original1); - composed.mul(original2); - BiologicalAssemblyTransformation transform = new BiologicalAssemblyTransformation(); - transform.setChainId(chainId); - transform.setId(operator.getElement1() + COMPOSED_OPERATOR_SEPARATOR + operator.getElement2()); - transform.setTransformationMatrix(composed); - transformations.add(transform); + String[] asymIds= pdbxStructAssemblyGen.getAsymIdList().get(i).split(","); + operatorResolver.parseOperatorExpressionString(pdbxStructAssemblyGen.getOperExpression().get(i)); + + // apply binary operators to the specified chains + // Example 1M4X: generates all products of transformation matrices (1-60)(61-88) + for (String chainId : asymIds) { + for (OrderedPair operator : operators) { + Matrix4d original1 = allTransformations.get(operator.getElement1()); + Matrix4d original2 = allTransformations.get(operator.getElement2()); + if (original1 == null || original2 == null) { + logger.warn("Could not find matrix operator for operator id {} or {}. Assembly id {} will not contain the composed operator.", operator.getElement1(), operator.getElement2(), assemblyId); + continue; } + Matrix4d composed = new Matrix4d(original1); + composed.mul(original2); + BiologicalAssemblyTransformation transform = new BiologicalAssemblyTransformation(); + transform.setChainId(chainId); + transform.setId(operator.getElement1() + COMPOSED_OPERATOR_SEPARATOR + operator.getElement2()); + transform.setTransformationMatrix(composed); + transformations.add(transform); } } - } return transformations; } - private ArrayList getBioUnitTransformationsListUnaryOperators(String assemblyId, List psags) { - ArrayList transformations = new ArrayList(); - - - for ( PdbxStructAssemblyGen psag : psags){ - if ( psag.getAssembly_id().equals(assemblyId)) { - - operatorResolver.parseOperatorExpressionString(psag.getOper_expression()); - List operators = operatorResolver.getUnaryOperators(); + private ArrayList getBioUnitTransformationsListUnaryOperators(String assemblyId, PdbxStructAssemblyGen pdbxStructAssemblyGen) { + ArrayList transformations = new ArrayList<>(); - ListasymIds= Arrays.asList(psag.getAsym_id_list().split(",")); + for (int i = 0; i < pdbxStructAssemblyGen.getRowCount(); i++) { + if (!pdbxStructAssemblyGen.getAssemblyId().get(i).equals(assemblyId)) { + continue; + } - // apply unary operators to the specified chains - for (String chainId : asymIds) { - for (String operator : operators) { - Matrix4d original = allTransformations.get(operator); - if (original == null) { - logger.warn("Could not find matrix operator for operator id {}. Assembly id {} will not contain the operator.", operator, assemblyId); - continue; - } - BiologicalAssemblyTransformation transform = new BiologicalAssemblyTransformation(); - transform.setChainId(chainId); - transform.setId(operator); - transform.setTransformationMatrix(original); - transformations.add(transform); + operatorResolver.parseOperatorExpressionString(pdbxStructAssemblyGen.getOperExpression().get(i)); + List operators = operatorResolver.getUnaryOperators(); + String[] asymIds = pdbxStructAssemblyGen.getAsymIdList().get(i).split(","); + + // apply unary operators to the specified chains + for (String chainId : asymIds) { + for (String operator : operators) { + Matrix4d original = allTransformations.get(operator); + if (original == null) { + logger.warn("Could not find matrix operator for operator id {}. Assembly id {} will not contain the operator.", operator, assemblyId); + continue; } + BiologicalAssemblyTransformation transform = new BiologicalAssemblyTransformation(); + transform.setChainId(chainId); + transform.setId(operator); + transform.setTransformationMatrix(original); + transformations.add(transform); } } } @@ -364,8 +361,8 @@ private ArrayList getBioUnitTransformationsLis return transformations; } - private void init(){ - operatorResolver= new OperatorResolver(); + private void init() { + operatorResolver = new OperatorResolver(); allTransformations = new HashMap<>(); } } diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/TestAtomCache.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/TestAtomCache.java index bb46670bae..87fc80a314 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/TestAtomCache.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/TestAtomCache.java @@ -28,7 +28,6 @@ import org.biojava.nbio.structure.io.LocalPDBDirectory; import org.biojava.nbio.structure.io.LocalPDBDirectory.FetchBehavior; import org.biojava.nbio.structure.io.LocalPDBDirectory.ObsoleteBehavior; -import org.biojava.nbio.structure.io.MMCIFFileReader; import org.biojava.nbio.structure.io.PDBFileReader; import org.junit.Before; import org.junit.Test; diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/align/util/AtomCacheTest.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/align/util/AtomCacheTest.java index 58a2623062..6ba61088b4 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/align/util/AtomCacheTest.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/align/util/AtomCacheTest.java @@ -54,7 +54,6 @@ import org.biojava.nbio.structure.io.LocalPDBDirectory; import org.biojava.nbio.structure.io.LocalPDBDirectory.FetchBehavior; import org.biojava.nbio.structure.io.LocalPDBDirectory.ObsoleteBehavior; -import org.biojava.nbio.structure.io.MMCIFFileReader; import org.biojava.nbio.structure.io.mmcif.ChemCompGroupFactory; import org.biojava.nbio.structure.io.mmcif.DownloadChemCompProvider; import org.biojava.nbio.structure.io.mmcif.model.ChemComp; From 993665a74da8e35e27641eebdf6ac0b506455e30 Mon Sep 17 00:00:00 2001 From: JonStargaryen Date: Thu, 14 Jan 2021 09:48:15 -0800 Subject: [PATCH 016/599] wip (TODO chemcomp parsing) --- .../java/demo/DemoChangeChemCompProvider.java | 4 - .../src/main/java/demo/DemoMMCIFReader.java | 3 +- .../nbio/structure/AtomPositionMap.java | 1 + .../org/biojava/nbio/structure/ChainImpl.java | 2 +- .../nbio/structure/DatabasePDBRevRecord.java | 3 - .../biojava/nbio/structure/HetatomImpl.java | 7 +- .../nbio/structure/align/ce/CECalculator.java | 4 +- .../align/ce/CeCalculatorEnhanced.java | 6 +- .../structure/chem/AllChemCompProvider.java | 185 -------- .../biojava/nbio/structure/chem/ChemComp.java | 38 +- .../structure/chem/ChemCompContainer.java | 13 - .../structure/chem/ChemCompGroupFactory.java | 131 ------ .../nbio/structure/chem/ChemCompProvider.java | 15 - .../nbio/structure/chem/ChemCompTools.java | 32 +- .../chem/ChemicalComponentDictionary.java | 54 ++- .../chem/DownloadChemCompProvider.java | 420 ------------------ .../chem/ReducedChemCompProvider.java | 56 --- .../biojava/nbio/structure/io/BondMaker.java | 6 +- .../nbio/structure/io/ChargeAdder.java | 48 +- .../nbio/structure/io/FileConvert.java | 5 +- .../nbio/structure/io/PDBFileParser.java | 6 +- .../nbio/structure/io/SeqRes2AtomAligner.java | 8 +- .../structure/io/cif/ChemCompConsumer.java | 14 - .../io/cif/ChemCompConsumerImpl.java | 70 --- .../structure/io/cif/CifFileConsumer.java | 48 -- .../structure/io/cif/CifFileConverter.java | 4 +- .../io/cif/StructureConsumerImpl.java | 1 - .../io/mmtf/MmtfStructureReader.java | 22 +- .../io/mmtf/MmtfStructureWriter.java | 8 +- .../nbio/structure/io/mmtf/MmtfUtils.java | 12 +- 30 files changed, 135 insertions(+), 1091 deletions(-) delete mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/chem/AllChemCompProvider.java delete mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemCompContainer.java delete mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemCompGroupFactory.java delete mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemCompProvider.java delete mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/chem/DownloadChemCompProvider.java delete mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ReducedChemCompProvider.java delete mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/ChemCompConsumer.java delete mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/ChemCompConsumerImpl.java diff --git a/biojava-structure/src/main/java/demo/DemoChangeChemCompProvider.java b/biojava-structure/src/main/java/demo/DemoChangeChemCompProvider.java index b8e4eb5430..1285d8488b 100644 --- a/biojava-structure/src/main/java/demo/DemoChangeChemCompProvider.java +++ b/biojava-structure/src/main/java/demo/DemoChangeChemCompProvider.java @@ -23,10 +23,6 @@ import org.biojava.nbio.structure.Chain; import org.biojava.nbio.structure.Group; import org.biojava.nbio.structure.Structure; -import org.biojava.nbio.structure.chem.AllChemCompProvider; -import org.biojava.nbio.structure.chem.ChemCompGroupFactory; -import org.biojava.nbio.structure.chem.ChemCompProvider; -import org.biojava.nbio.structure.chem.DownloadChemCompProvider; import org.biojava.nbio.structure.io.FileParsingParameters; import org.biojava.nbio.structure.io.PDBFileReader; diff --git a/biojava-structure/src/main/java/demo/DemoMMCIFReader.java b/biojava-structure/src/main/java/demo/DemoMMCIFReader.java index d5ae3fea58..b94dbd2e19 100644 --- a/biojava-structure/src/main/java/demo/DemoMMCIFReader.java +++ b/biojava-structure/src/main/java/demo/DemoMMCIFReader.java @@ -26,6 +26,7 @@ import org.biojava.nbio.structure.*; import org.biojava.nbio.structure.align.util.AtomCache; +import org.biojava.nbio.structure.io.CifFileReader; import org.biojava.nbio.structure.io.StructureProvider; import java.util.List; @@ -79,7 +80,7 @@ public void loadSimple(){ public void loadFromDirectAccess(){ String pdbId = "1A4W"; - StructureProvider pdbreader = new MMCIFFileReader(); + StructureProvider pdbreader = new CifFileReader(); try { Structure s = pdbreader.getStructureById(pdbId); diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/AtomPositionMap.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/AtomPositionMap.java index d6d6f778ff..efe8822397 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/AtomPositionMap.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/AtomPositionMap.java @@ -32,6 +32,7 @@ import java.util.NavigableMap; import java.util.TreeMap; +import org.biojava.nbio.structure.chem.ChemComp; import org.biojava.nbio.structure.chem.PolymerType; import org.biojava.nbio.structure.chem.ResidueType; import org.slf4j.Logger; diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/ChainImpl.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/ChainImpl.java index 7275fb07a9..8f548be835 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/ChainImpl.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/ChainImpl.java @@ -24,7 +24,7 @@ package org.biojava.nbio.structure; -import org.biojava.nbio.structure.chem.ChemCompGroupFactory; +import org.biojava.nbio.structure.chem.ChemComp; import org.biojava.nbio.structure.chem.PolymerType; import org.biojava.nbio.structure.io.FileConvert; import org.biojava.nbio.core.exceptions.CompoundNotFoundException; diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/DatabasePDBRevRecord.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/DatabasePDBRevRecord.java index e14ef16776..039c2f0cc4 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/DatabasePDBRevRecord.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/DatabasePDBRevRecord.java @@ -2,9 +2,6 @@ import org.biojava.nbio.structure.io.cif.CifBean; -import java.util.ArrayList; -import java.util.List; - public class DatabasePDBRevRecord implements CifBean { private static final long serialVersionUID = 1L; private String revNum; diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/HetatomImpl.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/HetatomImpl.java index ddc4f2f636..c9c05a704c 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/HetatomImpl.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/HetatomImpl.java @@ -23,11 +23,10 @@ */ package org.biojava.nbio.structure; -import org.biojava.nbio.structure.chem.ChemCompGroupFactory; +import org.biojava.nbio.structure.chem.ChemComp; import org.biojava.nbio.structure.chem.PolymerType; import org.biojava.nbio.structure.chem.ResidueType; import org.biojava.nbio.structure.io.GroupToSDF; -import org.rcsb.cif.schema.mm.ChemComp; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -336,7 +335,7 @@ public boolean isAminoAcid() { return getType().equals(GroupType.AMINOACID); - ResidueType rt = ResidueType.getResidueTypeFromString(cc.getType().get(0)); + ResidueType rt = ResidueType.getResidueTypeFromString(cc.getType()); if (ResidueType.nonPolymer.equals(rt)) return false; @@ -355,7 +354,7 @@ public boolean isNucleotide() { if ( cc == null) return getType().equals(GroupType.NUCLEOTIDE); - ResidueType rt = ResidueType.getResidueTypeFromString(cc.getType().get(0)); + ResidueType rt = ResidueType.getResidueTypeFromString(cc.getType()); if (ResidueType.nonPolymer.equals(rt)) return false; diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/align/ce/CECalculator.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/align/ce/CECalculator.java index e70efd5183..2fb8b1184d 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/align/ce/CECalculator.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/align/ce/CECalculator.java @@ -1545,9 +1545,9 @@ public static double[][] updateMatrixWithSequenceConservation(double[][] max, At Atom a2 = ca2[j]; AminoAcidCompound ac1 = - set.getCompoundForString(a1.getGroup().getChemComp().getOne_letter_code()); + set.getCompoundForString(a1.getGroup().getChemComp().getOneLetterCode()); AminoAcidCompound ac2 = - set.getCompoundForString(a2.getGroup().getChemComp().getOne_letter_code()); + set.getCompoundForString(a2.getGroup().getChemComp().getOneLetterCode()); if ( ac1 == null || ac2 == null) diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/align/ce/CeCalculatorEnhanced.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/align/ce/CeCalculatorEnhanced.java index 8610b10d0b..940111d3c8 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/align/ce/CeCalculatorEnhanced.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/align/ce/CeCalculatorEnhanced.java @@ -1442,7 +1442,7 @@ private int optimizeSuperposition(AFPChain afpChain, int nse1, int nse2, int str for ( int i =0 ; i < strBuf1.length; i++){ if ( strBuf1[i] == null) break; - System.out.print(strBuf1[i].getGroup().getChemComp().getOne_letter_code()); + System.out.print(strBuf1[i].getGroup().getChemComp().getOneLetterCode()); } System.out.println(); @@ -1551,9 +1551,9 @@ public static double[][] updateMatrixWithSequenceConservation(double[][] max, At Atom a2 = ca2[j]; AminoAcidCompound ac1 = - set.getCompoundForString(a1.getGroup().getChemComp().getOne_letter_code()); + set.getCompoundForString(a1.getGroup().getChemComp().getOneLetterCode()); AminoAcidCompound ac2 = - set.getCompoundForString(a2.getGroup().getChemComp().getOne_letter_code()); + set.getCompoundForString(a2.getGroup().getChemComp().getOneLetterCode()); if ( ac1 == null || ac2 == null) diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/AllChemCompProvider.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/AllChemCompProvider.java deleted file mode 100644 index ef3b7414b8..0000000000 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/AllChemCompProvider.java +++ /dev/null @@ -1,185 +0,0 @@ -package org.biojava.nbio.structure.chem; - -import org.biojava.nbio.core.util.InputStreamProvider; -import org.biojava.nbio.structure.align.util.UserConfiguration; -import org.biojava.nbio.structure.io.LocalPDBDirectory; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.net.URL; -import java.util.concurrent.atomic.AtomicBoolean; - -/** - * A ChemComp provider that downloads and caches the components.cif file from the wwPDB site. It then loads - * all chemical components at startup and keeps them in memory. This provider is not used as a default - * since it is slower at startup and requires more memory than the {@link DownloadChemCompProvider} that is used by default. - * - * @author Andreas Prlic - * - */ -public class AllChemCompProvider implements ChemCompProvider, Runnable{ - private static final Logger logger = LoggerFactory.getLogger(AllChemCompProvider.class); - public static final String COMPONENTS_FILE_LOCATION = "pub/pdb/data/monomers/components.cif.gz"; - - private static String path; - private static String serverName; - - // there will be only one copy of the dictionary across all instances - // to reduce memory impact - static ChemicalComponentDictionary dict; - - // flags to make sure there is only one thread running that is loading the dictionary - static AtomicBoolean loading = new AtomicBoolean(false); - static AtomicBoolean isInitialized = new AtomicBoolean(false); - - public AllChemCompProvider(){ - if (loading.get()) { - logger.warn("other thread is already loading all chemcomps, no need to init twice"); - return; - } - if (isInitialized.get()) { - return; - } - - loading.set(true); - - Thread t = new Thread(this); - t.start(); - } - - /** - * make sure all paths are initialized correctly - */ - private static void initPath(){ - if (path == null) { - UserConfiguration config = new UserConfiguration(); - path = config.getCacheFilePath(); - } - } - - private static void initServerName() { - if (serverName == null) { - serverName = LocalPDBDirectory.getServerName(); - } - } - - private void ensureFileExists() { - String fileName = getLocalFileName(); - File f = new File(fileName); - - if (!f.exists()) { - try { - downloadFile(); - } catch (IOException e) { - logger.error("Caught IOException", e); - } - } - } - - /** - * Downloads the components.cif.gz file from the wwPDB site. - */ - public static void downloadFile() throws IOException { - initPath(); - initServerName(); - - String localName = getLocalFileName(); - String u = serverName + "/" + COMPONENTS_FILE_LOCATION; - - downloadFileFromRemote(new URL(u), new File(localName)); - } - - private static void downloadFileFromRemote(URL remoteURL, File localFile) throws IOException { - logger.info("Downloading " + remoteURL + " to: " + localFile); - FileOutputStream out = new FileOutputStream(localFile); - - InputStream in = remoteURL.openStream(); - byte[] buf = new byte[4 * 1024]; // 4K buffer - int bytesRead; - while ((bytesRead = in.read(buf)) != -1) { - out.write(buf, 0, bytesRead); - } - in.close(); - out.close(); - } - - private static String getLocalFileName(){ - File dir = new File(path, DownloadChemCompProvider.CHEM_COMP_CACHE_DIRECTORY); - - if (!dir.exists()) { - logger.info("Creating directory {}", dir.toString()); - dir.mkdir(); - } - - return new File(dir, "components.cif.gz").toString(); - } - - /** - * Load all {@link ChemComp} definitions into memory. - */ - private void loadAllChemComps() throws IOException { - String fileName = getLocalFileName(); - logger.debug("Loading " + fileName); - InputStreamProvider isp = new InputStreamProvider(); - - InputStream inStream = isp.getInputStream(fileName); - MMcifParser parser = new SimpleMMcifParser(); - ChemCompConsumer consumer = new ChemCompConsumer(); - - // The Consumer builds up the BioJava - structure object. - // you could also hook in your own and build up you own data model. - parser.addMMcifConsumer(consumer); - parser.parse(new BufferedReader(new InputStreamReader(inStream))); - dict = consumer.getDictionary(); - inStream.close(); - } - - /** - * {@inheritDoc} - */ - @Override - public ChemComp getChemComp(String recordName) { - while (loading.get()) { - // another thread is still initializing the definitions - try { - // wait half a second - Thread.sleep(500); - } catch (InterruptedException e) { - logger.error("Interrupted thread while waiting: " + e.getMessage()); - //e.printStackTrace(); - } - } - - return dict.getChemComp(recordName); - } - - - /** - * Do the actual loading of the dictionary in a thread. - */ - @Override - public void run() { - long timeS = System.currentTimeMillis(); - initPath(); - ensureFileExists(); - - try { - loadAllChemComps(); - - long timeE = System.currentTimeMillis(); - logger.debug("Time to init chem comp dictionary: " + (timeE - timeS) / 1000 + " sec."); - } catch (IOException e) { - logger.error("Could not load chemical components definition file {}. Error: {}", getLocalFileName(), e.getMessage()); - } finally { - loading.set(false); - isInitialized.set(true); - } - } -} - diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemComp.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemComp.java index 96631fe736..52aa39c604 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemComp.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemComp.java @@ -49,26 +49,24 @@ public class ChemComp implements CifBean, Compa @Override public String toString(){ - StringBuffer buf = new StringBuffer("ChemComp "); - buf.append(id) - .append(" ") - .append(oneLetterCode) - .append(" ") - .append(threeLetterCode) - .append(" poly:") - .append(getPolymerType()) - .append(" resi:") - .append(getResidueType()) - .append(isStandard() ? " standard" : " modified") - .append(" ") - .append(name) - .append(" ") - .append(pdbxType) - .append(" ") - .append(formula) - .append(" parent:") - .append(monNstdParentCompId); - return buf.toString(); + return "ChemComp " + id + + " " + + oneLetterCode + + " " + + threeLetterCode + + " poly:" + + getPolymerType() + + " resi:" + + getResidueType() + + (isStandard() ? " standard" : " modified") + + " " + + name + + " " + + pdbxType + + " " + + formula + + " parent:" + + monNstdParentCompId; } public boolean hasParent(){ diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemCompContainer.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemCompContainer.java deleted file mode 100644 index 322f927895..0000000000 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemCompContainer.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.biojava.nbio.structure.chem; - -import org.rcsb.cif.schema.mm.ChemComp; - -public class ChemCompContainer { - private final ChemComp delegate; - - public ChemCompContainer(ChemComp chemComp) { - this.delegate = chemComp; - } - - -} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemCompGroupFactory.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemCompGroupFactory.java deleted file mode 100644 index cad709223f..0000000000 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemCompGroupFactory.java +++ /dev/null @@ -1,131 +0,0 @@ -package org.biojava.nbio.structure.chem; - -import org.biojava.nbio.core.util.SoftHashMap; -import org.biojava.nbio.structure.AminoAcid; -import org.biojava.nbio.structure.AminoAcidImpl; -import org.biojava.nbio.structure.Group; -import org.biojava.nbio.structure.HetatomImpl; -import org.biojava.nbio.structure.NucleotideImpl; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.Map; - -public class ChemCompGroupFactory { - private static final Logger logger = LoggerFactory.getLogger(ChemCompGroupFactory.class); - private static ChemCompProvider chemCompProvider = new DownloadChemCompProvider(); - private static Map cache = new SoftHashMap<>(0); - - public static ChemComp getChemComp(String recordName) { - recordName = recordName.toUpperCase().trim(); - - // we are using the cache, to avoid hitting the file system too often. - ChemComp chemComp = cache.get(recordName); - if (chemComp != null) { - logger.debug("Chem comp " + chemComp.getThreeLetterCode() + " read from cache"); - return chemComp; - } - - // not cached, get the chem comp from the provider - logger.debug("Chem comp " + recordName + " read from provider " + chemCompProvider.getClass().getCanonicalName()); - chemComp = chemCompProvider.getChemComp(recordName); - - // Note that this also caches null or empty responses - cache.put(recordName, chemComp); - return chemComp; - } - - /** - * The new ChemCompProvider will be set in the static variable, - * so this provider will be used from now on until it is changed - * again. Note that this change can have unexpected behavior of - * code executed afterwards. - *

- * Changing the provider also resets the cache, so any groups - * previously accessed will be reread or re-downloaded. - * - * @param provider - */ - public static void setChemCompProvider(ChemCompProvider provider) { - logger.debug("Setting new chem comp provider to " + provider.getClass().getCanonicalName()); - chemCompProvider = provider; - // clear cache - cache.clear(); - } - - public static ChemCompProvider getChemCompProvider(){ - return chemCompProvider; - } - - /** - * Force the in-memory cache to be reset. - * - * Note that the ChemCompProvider may have additional memory or disk caches that need to be cleared too. - */ - public static void clearCache() { - cache.clear(); - } - - public static Group getGroupFromChemCompDictionary(String recordName) { - // make sure we work with upper case records - recordName = recordName.toUpperCase().trim(); - ChemComp chemComp = getChemComp(recordName); - Group group; - - if (chemComp == null) { - return null; - } - - PolymerType polymerType = PolymerType.polymerTypeFromString(chemComp.getType()); - if (PolymerType.PROTEIN_ONLY.contains(polymerType)) { - AminoAcid aminoAcid = new AminoAcidImpl(); - - String oneLetterCode = chemComp.getOneLetterCode(); - if (oneLetterCode == null || oneLetterCode.equals("X") || oneLetterCode.equals("?") || oneLetterCode.length() == 0) { - String parent = chemComp.getMonNstdParentCompId(); - if (parent != null && parent.length() == 3) { - String parentId = chemComp.getMonNstdParentCompId(); - ChemComp parentChemComp = getChemComp(parentId); - oneLetterCode = parentChemComp.getOneLetterCode(); - } - } - - if (oneLetterCode == null || oneLetterCode.length() == 0 || oneLetterCode.equals("?")) { - // e.g. problem with PRR, which probably should have a parent of ALA, but as of 20110127 does not. - logger.warn("Problem with chemical component: " + recordName + " Did not find one letter code! Setting it to 'X'"); - aminoAcid.setAminoType('X'); - } else { - aminoAcid.setAminoType(oneLetterCode.charAt(0)); - } - - group = aminoAcid; - } else if (PolymerType.POLYNUCLEOTIDE_ONLY.contains(polymerType)) { - group = new NucleotideImpl(); - } else { - group = new HetatomImpl(); - } - - group.setChemComp(chemComp); - return group; - } - - public static String getOneLetterCode(ChemComp chemComp) { - String oneLetterCode = chemComp.getOneLetterCode(); - if (oneLetterCode == null || oneLetterCode.equals("X") || oneLetterCode.equals("?")) { - String parentId = chemComp.getMonNstdParentCompId(); - if (parentId == null) { - return oneLetterCode; - } - // cases like OIM have multiple parents (comma separated), we shouldn't try grab a chemcomp for those strings - if (parentId.length() > 3) { - return oneLetterCode; - } - ChemComp parentChemComp = ChemCompGroupFactory.getChemComp(parentId); - if (parentChemComp == null) { - return oneLetterCode; - } - oneLetterCode = parentChemComp.getOneLetterCode(); - } - return oneLetterCode; - } -} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemCompProvider.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemCompProvider.java deleted file mode 100644 index 936f5ef8cf..0000000000 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemCompProvider.java +++ /dev/null @@ -1,15 +0,0 @@ -package org.biojava.nbio.structure.chem; - -/** - * Interface that is implemented by all classes that can provide {@link ChemComp} definitions. - * @author Andreas Prlic - * @since 3.0 - */ -public interface ChemCompProvider { - /** - * Returns a new instance of a chemical component definition. - * @param recordName the ID of the {@link ChemComp} - * @return a new {@link ChemComp} definition. - */ - ChemComp getChemComp(String recordName); -} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemCompTools.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemCompTools.java index b24fd5d51a..6b8f74dbd8 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemCompTools.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemCompTools.java @@ -1,9 +1,7 @@ package org.biojava.nbio.structure.chem; -import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; -import java.util.List; import java.util.Map; public class ChemCompTools { @@ -96,40 +94,42 @@ public class ChemCompTools { bar.put('U',"DU"); bar.put('T',"DT"); DNA_LOOKUP_1TO2 = Collections.unmodifiableMap(Collections.synchronizedMap(bar)); - - - // initialise standard chemical components - List stdMonIds = new ArrayList<>(); - stdMonIds.addAll(AMINO_ACID_LOOKUP_3TO1.keySet()); - stdMonIds.addAll(DNA_LOOKUP_2TO1.keySet()); } - public static Character getAminoOneLetter(String chemCompId){ + public static Character getAminoOneLetter(String chemCompId) { return AMINO_ACID_LOOKUP_3TO1.get(chemCompId); } - public static Character getDNAOneLetter(String chemCompId){ + public static Character getDNAOneLetter(String chemCompId) { return DNA_LOOKUP_2TO1.get(chemCompId); } - public static String getAminoThreeLetter(Character c){ + public static String getAminoThreeLetter(Character c) { return AMINO_ACID_LOOKUP_1TO3.get(c); } - public static String getDNATwoLetter(Character c){ + public static String getDNATwoLetter(Character c) { return DNA_LOOKUP_1TO2.get(c); } - public static boolean isStandardChemComp(ChemComp cc){ + public static PolymerType getPolymerType(ResidueType residueType) { + if (residueType != null) { + return residueType.polymerType; + } + return null; + } + + public static boolean isStandardChemComp(ChemComp cc) { String pid = cc.getMonNstdParentCompId(); String one = cc.getOneLetterCode(); - PolymerType polymerType = cc.getPolymerType(); + ResidueType residueType = ResidueType.getResidueTypeFromString(cc.getType()); + PolymerType polymerType = getPolymerType(residueType); // standard residues have no parent - if ((pid == null) || (pid.equals("?"))) { + if (pid == null || pid.equals("?")) { // and they have a one letter code - if ((one != null) && (!one.equals("?"))) { + if (one != null && !one.equals("?")) { // peptides and dpeptides must not have X if (polymerType == PolymerType.peptide || polymerType == PolymerType.dpeptide) { return performPeptideCheck(cc, one); diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemicalComponentDictionary.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemicalComponentDictionary.java index 2f48e612d7..63b38ed2e2 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemicalComponentDictionary.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemicalComponentDictionary.java @@ -3,15 +3,23 @@ import java.util.HashMap; import java.util.Map; +/** + * A representation of the Chemical Component Dictionary. + * + * @author Andreas Prlic + * @since 1.7 + * @see link into mmCIF dictionary + * + */ public class ChemicalComponentDictionary { - private final Map dictionary; - private final Map replaces; - private final Map isReplacedBy; - - public ChemicalComponentDictionary() { - this.dictionary = new HashMap<>(); - this.replaces = new HashMap<>(); - this.isReplacedBy = new HashMap<>(); + private Map dictionary; + private Map replaces; + private Map isReplacedBy; + + public ChemicalComponentDictionary(){ + dictionary = new HashMap<>(); + replaces = new HashMap<>(); + isReplacedBy = new HashMap<>(); } public boolean isReplaced(ChemComp c) { @@ -22,7 +30,7 @@ public boolean isReplaced(String id) { return isReplacedBy.containsKey(id); } - public boolean isReplacer(ChemComp c){ + public boolean isReplacer(ChemComp c) { return isReplacer(c.getId()); } @@ -30,27 +38,27 @@ public boolean isReplacer(String id) { return replaces.containsKey(id); } - /** if ChemComp is replaced by another one, get the newer version - * otherwise return the same ChemComp again. + /** + * If ChemComp is replaced by another one, get the newer version otherwise return the same ChemComp again. * @param c * @return get the component that replaced ChemComp. */ - public ChemComp getReplacer(ChemComp c){ + public ChemComp getReplacer(ChemComp c) { return getReplacer(c.getId()); } - public ChemComp getReplacer(String id){ + public ChemComp getReplacer(String id) { if (isReplaced(id)) { return dictionary.get(isReplacedBy.get(id)); } return dictionary.get(id); } - /** if ChemComp is replacing another one, get the old version - * otherwise return the same ChemComp again. + /** + * If ChemComp is replacing another one, get the old version otherwise return the same ChemComp again. * @param c the ChemComp for which older versions should be looked up. */ - public ChemComp getReplaced(ChemComp c){ + public ChemComp getReplaced(ChemComp c) { return getReplaced(c.getId()); } @@ -78,15 +86,15 @@ public ChemComp getParent(ChemComp c) { * @param comp */ public void addChemComp(ChemComp comp) { - dictionary.put(comp.getId(), comp); + dictionary.put(comp.getId(),comp); String rep = comp.getPdbxReplaces(); if (rep != null && !rep.equals("?")) { - replaces.put(comp.getId(), rep); + replaces.put(comp.getId(),rep); } - String isRep = comp.getPdbxReplacedBy(); - if (isRep != null && !isRep.equals("?")) { - isReplacedBy.put(comp.getId(), isRep); + String isrep = comp.getPdbxReplacedBy(); + if (isrep != null && !isrep.equals("?")) { + isReplacedBy.put(comp.getId(), isrep); } } @@ -94,11 +102,11 @@ public void addChemComp(ChemComp comp) { * Returns the number of ChemComps in this dictionary * @return nr. of ChemComps */ - public int size(){ + public int size() { return dictionary.size(); } - public ChemComp getChemComp(String id){ + public ChemComp getChemComp(String id) { return dictionary.get(id); } } diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/DownloadChemCompProvider.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/DownloadChemCompProvider.java deleted file mode 100644 index 5b52bcab52..0000000000 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/DownloadChemCompProvider.java +++ /dev/null @@ -1,420 +0,0 @@ -package org.biojava.nbio.structure.chem; - -import org.biojava.nbio.core.util.InputStreamProvider; -import org.biojava.nbio.structure.align.util.URLConnectionTools; -import org.biojava.nbio.structure.align.util.UserConfiguration; -import org.biojava.nbio.structure.io.LocalPDBDirectory; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileOutputStream; -import java.io.FilenameFilter; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.PrintWriter; -import java.io.StringWriter; -import java.net.URL; -import java.net.URLConnection; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.nio.file.StandardCopyOption; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.zip.GZIPOutputStream; - -/** - * This provider of chemical components can download and cache chemical component definition files from the RCSB PDB web - * site. It is the default way to access these definitions. If this provider is called he first time, it will download - * and install all chemical component definitions in a local directory. Once the definition files have been installed, - * it has quick startup time and low memory requirements. - * - * An alternative provider, that keeps all definitions in memory is the {@link AllChemCompProvider}. Another provider, - * that does not require any network access, but only can support a limited set of chemical component definitions, is - * the {@link ReducedChemCompProvider}. - * - * @author Andreas Prlic - */ -public class DownloadChemCompProvider implements ChemCompProvider { - private static final Logger logger = LoggerFactory.getLogger(DownloadChemCompProvider.class); - public static final String CHEM_COMP_CACHE_DIRECTORY = "chemcomp"; - public static final String DEFAULT_SERVER_URL = "http://files.rcsb.org/ligands/download/"; - public static String serverBaseUrl = DEFAULT_SERVER_URL; - - /** - * Use default RCSB server layout (true) or internal RCSB server layout (false) - */ - public static boolean useDefaultUrlLayout = true; - - private static File path; - private static final String NEWLINE = System.getProperty("line.separator"); - - // flags to make sure there is only one thread running that is loading the dictionary - static AtomicBoolean loading = new AtomicBoolean(false); - - static final List protectedIDs = new ArrayList<>(); - static { - protectedIDs.add("CON"); - protectedIDs.add("PRN"); - protectedIDs.add("AUX"); - protectedIDs.add("NUL"); - } - - private static ChemCompProvider fallback = null; // Fallback provider if the download fails - /** - * by default we will download only some of the files. User has to request that all files should be downloaded... - */ - boolean downloadAll = false; - - public DownloadChemCompProvider() { - this(null); - } - - public DownloadChemCompProvider(String cacheFilePath) { - logger.debug("Initialising DownloadChemCompProvider"); - - // note that path is static, so this is just to make sure that all non-static methods will have path initialised - if (cacheFilePath != null) { - path = new File(cacheFilePath); - } - } - - /** - * Get this provider's cache path - * @return - */ - public static File getPath(){ - if (path == null) { - UserConfiguration config = new UserConfiguration(); - path = new File(config.getCacheFilePath()); - } - return path; - } - - /** - * Checks if the chemical components already have been installed into the PDB directory. - * If not, will download the chemical components definitions file and split it up into small - * subfiles. - */ - public void checkDoFirstInstall(){ - if (!downloadAll) { - return; - } - - // this makes sure there is a file separator between every component, - // if path has a trailing file separator or not, it will work for both cases - File dir = new File(getPath(), CHEM_COMP_CACHE_DIRECTORY); - File f = new File(dir, "components.cif.gz"); - - if (!f.exists()) { - downloadAllDefinitions(); - } else { - // file exists.. did it get extracted? - FilenameFilter filter = (dir1, file) -> file.endsWith(".cif.gz"); - String[] files = dir.list(filter); - if (files.length < 500) { - // not all did get unpacked - try { - split(); - } catch (IOException e) { - logger.error("Could not split file {} into individual chemical component files. Error: {}", - f.toString(), e.getMessage()); - } - } - } - } - - private void split() throws IOException { - logger.info("Installing individual chem comp files ..."); - - File dir = new File(getPath(), CHEM_COMP_CACHE_DIRECTORY); - File f = new File(dir, "components.cif.gz"); - - int counter = 0; - InputStreamProvider prov = new InputStreamProvider(); - - try (BufferedReader buf = new BufferedReader(new InputStreamReader(prov.getInputStream(f)))) { - String line; - line = buf.readLine(); - StringWriter writer = new StringWriter(); - - String currentID = null; - while (line != null) { - if (line.startsWith("data_")) { - // a new record found! - if (currentID != null) { - writeID(writer.toString(), currentID); - counter++; - } - - currentID = line.substring(5); - writer = new StringWriter(); - } - - writer.append(line); - writer.append(NEWLINE); - - line = buf.readLine (); - } - - // write the last record... - writeID(writer.toString(), currentID); - counter++; - } - - logger.info("Created " + counter + " chemical component files."); - } - - /** - * Output chemical contents to a file - * @param contents File contents - * @param currentID Chemical ID, used to determine the filename - * @throws IOException - */ - private void writeID(String contents, String currentID) throws IOException { - String localName = getLocalFileName(currentID); - - try (PrintWriter pw = new PrintWriter(new GZIPOutputStream(new FileOutputStream(localName)))) { - pw.print(contents); - pw.flush(); - } - } - - /** - * Loads the definitions for this {@link ChemComp} from a local file and instantiates a new object. - * - * @param recordName the ID of the {@link ChemComp} - * @return a new {@link ChemComp} definition. - */ - @Override - public ChemComp getChemComp(String recordName) { - // make sure we work with upper case records - recordName = recordName.toUpperCase().trim(); - - boolean haveFile = true; - if (recordName.equals("?")) { - return null; - } - - if (fileIsAbsent(recordName)) { - // check if we should install all components - checkDoFirstInstall(); - } - if (fileIsAbsent(recordName)) { - // we previously have installed already the definitions, - // just do an incrememntal update - haveFile = downloadChemCompRecord(recordName); - } - - // Added check that download was successful and chemical component is available. - if (haveFile) { - String filename = getLocalFileName(recordName); - InputStream inStream = null; - try { - InputStreamProvider isp = new InputStreamProvider(); - inStream = isp.getInputStream(filename); - - MMcifParser parser = new SimpleMMcifParser(); - ChemCompConsumer consumer = new ChemCompConsumer(); - - // The Consumer builds up the BioJava - structure object. - // you could also hook in your own and build up you own data model. - parser.addMMcifConsumer(consumer); - parser.parse(new BufferedReader(new InputStreamReader(inStream))); - - ChemicalComponentDictionary dict = consumer.getDictionary(); - ChemComp chemComp = dict.getChemComp(recordName); - - // May be null if the file was corrupt. Fall back on ReducedChemCompProvider in that case - if (chemComp != null) { - return chemComp; - } - } catch (IOException e) { - logger.warn("Could not download chemical component file {} for {}. Error: {}. Now trying to use the " + - "local chemical component definitions.", - filename, recordName, e.getMessage()); - } finally { - // Now close it - if (inStream != null) { - try { - inStream.close(); - } catch (IOException e) { - // This would be weird... - logger.error("Could not close chemical component file {}. A resource leak could occur!!", filename); - } - } - } - } - - // see https://github.com/biojava/biojava/issues/315 - // probably a network error happened. Try to use the ReducedChemCOmpProvider - if (fallback == null) { - fallback = new ReducedChemCompProvider(); - } - - logger.warn("Falling back to ReducedChemCompProvider for {}. This could indicate a network error.", recordName); - return fallback.getChemComp(recordName); - - } - - /** - * Returns the file name that contains the definition for this {@link ChemComp} - * - * @param recordName the ID of the {@link ChemComp} - * @return full path to the file - */ - public static String getLocalFileName(String recordName) { - if (protectedIDs.contains(recordName)) { - recordName = "_" + recordName; - } - - File f = new File(getPath(), CHEM_COMP_CACHE_DIRECTORY); - if (!f.exists()) { - logger.info("Creating directory " + f); - boolean success = f.mkdir(); - // we've checked in initPath that path is writable, so there's no need to check if it succeeds - // in the unlikely case that in the meantime it isn't writable at least we log an error - if (!success) { - logger.error("Directory {} could not be created", f); - } - } - - File theFile = new File(f,recordName + ".cif.gz"); - return theFile.toString(); - } - - private static boolean fileIsAbsent(String recordName){ - String fileName = getLocalFileName(recordName); - File f = new File(fileName); - - // delete files that are too short to have contents - if (f.length() < LocalPDBDirectory.MIN_PDB_FILE_SIZE) { - // Delete defensively. - // Note that if delete is unsuccessful, we re-download the file anyways - f.delete(); - return true; - } - - return !f.exists(); - } - - /** - * @param recordName three-letter name - * @return true if successful download - */ - private static boolean downloadChemCompRecord(String recordName) { - String localName = getLocalFileName(recordName); - File newFile; - try { - newFile = File.createTempFile("chemcomp" + recordName, "cif"); - logger.debug("Will write chem comp file to temp file {}", newFile.toString()); - } catch (IOException e) { - logger.error("Could not write to temp directory {} to create the chemical component download temp file", - System.getProperty("java.io.tmpdir")); - return false; - } - String u; - if (useDefaultUrlLayout) { - u = serverBaseUrl + recordName + ".cif"; - } else { - u = serverBaseUrl + recordName.charAt(0) + "/" + recordName +"/" + recordName + ".cif"; - } - - logger.debug("downloading " + u); - URL url = null; - try { - url = new URL(u); - URLConnection uconn = URLConnectionTools.openURLConnection(url); - - try (PrintWriter pw = new PrintWriter(new GZIPOutputStream(new FileOutputStream(newFile))); - BufferedReader fileBuffer = new BufferedReader(new InputStreamReader(uconn.getInputStream()))) { - - String line; - while ((line = fileBuffer.readLine()) != null) { - pw.println(line); - } - pw.flush(); - } - // Now we move this across to where it actually wants to be - Files.move(newFile.toPath(), Paths.get(localName), StandardCopyOption.REPLACE_EXISTING); - - return true; - } catch (IOException e) { - logger.error("Could not download " + url.toString() + " OR store locally to " + localName + " Error =" + e.getMessage()); - newFile.delete(); - } - return false; - } - - private void downloadAllDefinitions() { - if (loading.get()) { - logger.info("Waiting for other thread to install chemical components..."); - } - - while (loading.get()) { - // another thread is already downloading the components definitions - // wait for the other thread to finish... - try { - // wait half a second - Thread.sleep(500); - } catch (InterruptedException e) { - //e.printStackTrace(); - logger.error("Thread interrupted "+e.getMessage()); - } - - logger.info("Another thread installed the chemical components."); - return; - } - - loading.set(true); - long timeS = System.currentTimeMillis(); - - logger.info("Performing first installation of chemical components."); - logger.info("Downloading components.cif.gz ..."); - - try { - AllChemCompProvider.downloadFile(); - } catch (IOException e) { - logger.error("Could not download the all chemical components file. Error: {}. " - + "Chemical components information won't be available", e.getMessage()); - // no point in trying to split if the file could not be downloaded - loading.set(false); - return; - } - - try { - split(); - } catch (IOException e) { - logger.error("Could not split all chem comp file into individual chemical component files. Error: {}", - e.getMessage()); - // no point in reporting time - loading.set(false); - return; - } - - long timeE = System.currentTimeMillis(); - logger.info("time to install chem comp dictionary: " + (timeE - timeS) / 1000 + " sec."); - loading.set(false); - } - - /** - * By default this provider will download only some of the {@link ChemComp} files. - * The user has to request that all files should be downloaded by setting this parameter to true. - * @return flag if the all components should be downloaded and installed at startup. (default: false) - */ - public boolean isDownloadAll() { - return downloadAll; - } - - /** - * By default this provider will download only some of the {@link ChemComp} files. - * The user has to request that all files should be downloaded by setting this parameter to true. - * @param downloadAll if the all components should be downloaded and installed at startup. (default: false) - */ - public void setDownloadAll(boolean downloadAll) { - this.downloadAll = downloadAll; - } -} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ReducedChemCompProvider.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ReducedChemCompProvider.java deleted file mode 100644 index 9841fdc161..0000000000 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ReducedChemCompProvider.java +++ /dev/null @@ -1,56 +0,0 @@ -package org.biojava.nbio.structure.chem; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.util.zip.GZIPInputStream; - -/** - * Unlike the {@link DownloadChemCompProvider}, this {@link ChemCompProvider} does not download any chem comp - * definitions. It has access to a limited set of files that are part of the biojava distribution. - * @author Andreas Prlic - * @since 3.0 - */ -public class ReducedChemCompProvider implements ChemCompProvider { - private static final Logger logger = LoggerFactory.getLogger(ReducedChemCompProvider.class); - - public ReducedChemCompProvider(){ - logger.debug("Initialising ReducedChemCompProvider"); - } - - @Override - public ChemComp getChemComp(String recordName) { - String name = recordName.toUpperCase().trim(); - try (InputStream inStream = this.getClass().getResourceAsStream("/chemcomp/" + name + ".cif.gz")) { - logger.debug("Reading chemcomp/{}.cif.gz", name); - - if (inStream == null) { - // could not find the chem comp definition for this in the jar file - logger.debug("Getting empty chem comp for {}", name); - ChemComp cc = ChemComp.getEmptyChemComp(); - cc.setId(name); - return cc; - } - - MMcifParser parser = new SimpleMMcifParser(); - ChemCompConsumer consumer = new ChemCompConsumer(); - // The Consumer builds up the BioJava - structure object. - // you could also hook in your own and build up you own data model. - parser.addMMcifConsumer(consumer); - parser.parse(new BufferedReader(new InputStreamReader(new GZIPInputStream(inStream)))); - - ChemicalComponentDictionary dict = consumer.getDictionary(); - return dict.getChemComp(name); - } catch (IOException e){ - logger.error("IOException caught while reading chem comp {}.", name, e); - } - logger.warn("Problem when loading chem comp {}, will use an empty chem comp for it", name); - ChemComp cc = ChemComp.getEmptyChemComp(); - cc.setId(name); - return cc; - } -} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/BondMaker.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/BondMaker.java index aee22b0767..df077cde9b 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/BondMaker.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/BondMaker.java @@ -23,6 +23,8 @@ package org.biojava.nbio.structure.io; import org.biojava.nbio.structure.*; +import org.biojava.nbio.structure.chem.ChemComp; +import org.biojava.nbio.structure.chem.ChemCompBond; import org.biojava.nbio.structure.io.util.PDBTemporaryStorageUtils.LinkRecord; import org.rcsb.cif.model.ValueKind; import org.rcsb.cif.schema.mm.StructConn; @@ -177,8 +179,8 @@ private void formIntraResidueBonds() { for (ChemCompBond chemCompBond : aminoChemComp.getBonds()) { // note we don't check distance to make this call not too expensive - formBondAltlocAware(group, chemCompBond.getAtom_id_1(), - group, chemCompBond.getAtom_id_2(), -1, chemCompBond.getNumericalBondOrder()); + formBondAltlocAware(group, chemCompBond.getAtomId1(), + group, chemCompBond.getAtomId2(), -1, chemCompBond.getNumericalBondOrder()); } } } diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/ChargeAdder.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/ChargeAdder.java index 28fbddb9a9..311414f9da 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/ChargeAdder.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/ChargeAdder.java @@ -28,19 +28,17 @@ import org.biojava.nbio.structure.Chain; import org.biojava.nbio.structure.Group; import org.biojava.nbio.structure.Structure; +import org.biojava.nbio.structure.chem.ChemComp; +import org.biojava.nbio.structure.chem.ChemCompAtom; import org.biojava.nbio.structure.io.mmcif.ChemCompGroupFactory; -import org.biojava.nbio.structure.io.mmcif.model.ChemComp; -import org.biojava.nbio.structure.io.mmcif.model.ChemCompAtom; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * A class to add appropriate charge information to a structure. * @author Anthony Bradley - * */ public class ChargeAdder { - private static final Logger logger = LoggerFactory.getLogger(ChargeAdder.class); /** @@ -48,44 +46,44 @@ public class ChargeAdder { */ public static void addCharges(Structure structure) { // Loop through the models - for(int i=0; i chemAtoms = thisChemComp.getAtoms(); - for(ChemCompAtom chemCompAtom : chemAtoms) { - Atom atom = g.getAtom(chemCompAtom.getAtom_id()); + for (ChemCompAtom chemCompAtom : chemAtoms) { + Atom atom = g.getAtom(chemCompAtom.getAtomId()); String stringCharge = chemCompAtom.getCharge(); short shortCharge = 0; - if (stringCharge!=null){ - if(!stringCharge.equals("?")){ - try{ + if (stringCharge != null) { + if (!stringCharge.equals("?")) { + try { shortCharge = Short.parseShort(stringCharge); + } catch(NumberFormatException e) { + logger.warn("Number format exception. Parsing '{}' to short", stringCharge); } - catch(NumberFormatException e){ - logger.warn("Number format exception. Parsing '"+stringCharge+"' to short"); - } + } else { + logger.warn("? charge on atom {} in group {}", + chemCompAtom.getAtomId(), + thisChemComp.getId()); } - else{ - logger.warn("? charge on atom "+chemCompAtom.getAtom_id()+" in group "+thisChemComp.getId()); - } - } - else{ - logger.warn("Null charge on atom "+chemCompAtom.getAtom_id()+" in group "+thisChemComp.getId()); + } else { + logger.warn("Null charge on atom {} in group {}", + chemCompAtom.getAtomId(), + thisChemComp.getId()); } - if(atom!=null){ + if (atom != null) { atom.setCharge(shortCharge); } // Now do the same for alt locs for (Group altLoc : g.getAltLocs()) { - Atom altAtom = altLoc.getAtom(chemCompAtom.getAtom_id()); - if(altAtom!=null){ + Atom altAtom = altLoc.getAtom(chemCompAtom.getAtomId()); + if (altAtom != null) { altAtom.setCharge(shortCharge); } } } } - } } } 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 7cb62beffc..d6da021e63 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 @@ -593,10 +593,7 @@ else if (name.length()==1) public String toMMCIF() { - return CifFileConverter.toText(this.structure); } - - public static String toMMCIF(Chain chain, String authId, String asymId) { - return CifFileConverter.toText(chain, authId, asymId); + return CifFileConverter.toText(this.structure); } public static String toMMCIF(Chain chain) { diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/PDBFileParser.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/PDBFileParser.java index 41014e1ec4..6200c90b1a 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/PDBFileParser.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/PDBFileParser.java @@ -69,8 +69,8 @@ import org.biojava.nbio.structure.StructureException; import org.biojava.nbio.structure.StructureImpl; import org.biojava.nbio.structure.StructureTools; +import org.biojava.nbio.structure.chem.ChemCompAtom; import org.biojava.nbio.structure.io.mmcif.ChemCompGroupFactory; -import org.biojava.nbio.structure.io.mmcif.model.ChemCompAtom; import org.biojava.nbio.structure.io.util.PDBTemporaryStorageUtils.LinkRecord; import org.biojava.nbio.structure.secstruc.SecStrucInfo; import org.biojava.nbio.structure.secstruc.SecStrucType; @@ -1878,8 +1878,8 @@ private void pdb_ATOM_Handler(String line) { String elementSymbol = null; if (currentGroup.getChemComp() != null) { for (ChemCompAtom a : currentGroup.getChemComp().getAtoms()) { - if (a.getAtom_id().equals(fullname.trim())) { - elementSymbol = a.getType_symbol(); + if (a.getAtomId().equals(fullname.trim())) { + elementSymbol = a.getTypeSymbol(); break; } } diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/SeqRes2AtomAligner.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/SeqRes2AtomAligner.java index 580a8af158..0d677a4161 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/SeqRes2AtomAligner.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/SeqRes2AtomAligner.java @@ -60,9 +60,9 @@ import org.biojava.nbio.structure.NucleotideImpl; import org.biojava.nbio.structure.ResidueNumber; import org.biojava.nbio.structure.Structure; -import org.biojava.nbio.structure.io.mmcif.chem.PolymerType; -import org.biojava.nbio.structure.io.mmcif.chem.ResidueType; -import org.biojava.nbio.structure.io.mmcif.model.ChemComp; +import org.biojava.nbio.structure.chem.ChemComp; +import org.biojava.nbio.structure.chem.PolymerType; +import org.biojava.nbio.structure.chem.ResidueType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -410,7 +410,7 @@ public static String getFullAtomSequence(List groups, Map { - void consumeChemCompAtom(ChemCompAtom chemCompAtom); - - void consumeChemCompBond(ChemCompBond chemCompBond); - - void consumePdbxChemCompDescriptor(PdbxChemCompDescriptor pdbxChemCompDescriptor); -} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/ChemCompConsumerImpl.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/ChemCompConsumerImpl.java deleted file mode 100644 index f97a89d271..0000000000 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/ChemCompConsumerImpl.java +++ /dev/null @@ -1,70 +0,0 @@ -package org.biojava.nbio.structure.io.cif; - -import org.biojava.nbio.structure.chem.ChemComp; -import org.biojava.nbio.structure.chem.ChemicalComponentDictionary; -import org.biojava.nbio.structure.chem.ResidueType; -import org.rcsb.cif.schema.mm.ChemCompAtom; -import org.rcsb.cif.schema.mm.ChemCompBond; -import org.rcsb.cif.schema.mm.PdbxChemCompDescriptor; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class ChemCompConsumerImpl implements ChemCompConsumer { - private static final Logger logger = LoggerFactory.getLogger(ChemCompConsumerImpl.class); - private ChemicalComponentDictionary dictionary; - private String latestChemCompId; - - public ChemCompConsumerImpl(){ - dictionary = new ChemicalComponentDictionary(); - } - - @Override - public void prepare() { - - } - - public ChemicalComponentDictionary getDictionary(){ - return dictionary; - } - - @Override - public void consumeChemCompAtom(ChemCompAtom chemCompAtom) { - dictionary.getChemComp(latestChemCompId).getAtoms().add(chemCompAtom); - } - - @Override - public void consumeChemCompBond(ChemCompBond chemCompBond) { - dictionary.getChemComp(latestChemCompId).getBonds().add(chemCompBond); - } - - @Override - public void consumePdbxChemCompDescriptor(PdbxChemCompDescriptor pdbxChemCompDescriptor) { - ChemComp cc = dictionary.getChemComp(latestChemCompId); - cc.getDescriptors().add(pdbxChemCompDescriptor); - } - - @Override - public void finish() { - - } - - @Override - public ChemComp getContainer() { - if (c.getId() == null) - logger.warn("chem comp ID == null " + c); - - latestChemCompId = c.getId(); - dictionary.addChemComp(c); - if (c.getResidueType() == ResidueType.nonPolymer) { - return; - } - - if (c.getResidueType() == ResidueType.saccharide) { - return; - } - - if (c.getResidueType() == ResidueType.dSaccharide) { - return; - } - } -} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/CifFileConsumer.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/CifFileConsumer.java index 198f288305..d95f7b9422 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/CifFileConsumer.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/CifFileConsumer.java @@ -1,53 +1,5 @@ package org.biojava.nbio.structure.io.cif; -import org.biojava.nbio.structure.chem.ChemCompAtom; -import org.biojava.nbio.structure.chem.ChemCompDescriptor; -import org.rcsb.cif.schema.mm.AtomSite; -import org.rcsb.cif.schema.mm.AtomSites; -import org.rcsb.cif.schema.mm.AuditAuthor; -import org.rcsb.cif.schema.mm.Cell; -import org.rcsb.cif.schema.mm.ChemComp; -import org.rcsb.cif.schema.mm.ChemCompBond; -import org.rcsb.cif.schema.mm.DatabasePDBRemark; -import org.rcsb.cif.schema.mm.DatabasePDBRev; -import org.rcsb.cif.schema.mm.DatabasePDBRevRecord; -import org.rcsb.cif.schema.mm.Entity; -import org.rcsb.cif.schema.mm.EntityPoly; -import org.rcsb.cif.schema.mm.EntityPolySeq; -import org.rcsb.cif.schema.mm.EntitySrcGen; -import org.rcsb.cif.schema.mm.EntitySrcNat; -import org.rcsb.cif.schema.mm.Exptl; -import org.rcsb.cif.schema.mm.PdbxAuditRevisionHistory; -import org.rcsb.cif.schema.mm.PdbxChemCompIdentifier; -import org.rcsb.cif.schema.mm.PdbxDatabaseStatus; -import org.rcsb.cif.schema.mm.PdbxEntityBranchDescriptor; -import org.rcsb.cif.schema.mm.PdbxEntitySrcSyn; -import org.rcsb.cif.schema.mm.PdbxMolecule; -import org.rcsb.cif.schema.mm.PdbxMoleculeFeatures; -import org.rcsb.cif.schema.mm.PdbxNonpolyScheme; -import org.rcsb.cif.schema.mm.PdbxReferenceEntityLink; -import org.rcsb.cif.schema.mm.PdbxReferenceEntityList; -import org.rcsb.cif.schema.mm.PdbxReferenceEntityPolyLink; -import org.rcsb.cif.schema.mm.PdbxStructAssembly; -import org.rcsb.cif.schema.mm.PdbxStructAssemblyGen; -import org.rcsb.cif.schema.mm.PdbxStructModResidue; -import org.rcsb.cif.schema.mm.PdbxStructOperList; -import org.rcsb.cif.schema.mm.Refine; -import org.rcsb.cif.schema.mm.Struct; -import org.rcsb.cif.schema.mm.StructAsym; -import org.rcsb.cif.schema.mm.StructConf; -import org.rcsb.cif.schema.mm.StructConn; -import org.rcsb.cif.schema.mm.StructConnType; -import org.rcsb.cif.schema.mm.StructKeywords; -import org.rcsb.cif.schema.mm.StructNcsOper; -import org.rcsb.cif.schema.mm.StructRef; -import org.rcsb.cif.schema.mm.StructRefSeq; -import org.rcsb.cif.schema.mm.StructRefSeqDif; -import org.rcsb.cif.schema.mm.StructSheetRange; -import org.rcsb.cif.schema.mm.StructSite; -import org.rcsb.cif.schema.mm.StructSiteGen; -import org.rcsb.cif.schema.mm.Symmetry; - /** * Defines a rather generic interface which allows to populate some data structure with data parsed from a CIF file. * diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/CifFileConverter.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/CifFileConverter.java index 30e5682b69..2a53746297 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/CifFileConverter.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/CifFileConverter.java @@ -226,7 +226,7 @@ public static String toText(Chain chain) { * @return the target */ public static CifFile toCifFile(Structure structure) { - return new AbstractCifFileSupplier().getStructure(structure); + return new StructureSupplierImpl().get(structure); } /** @@ -235,6 +235,6 @@ public static CifFile toCifFile(Structure structure) { * @return the target */ public static CifFile toCifFile(Chain chain) { - return new AbstractCifFileSupplier().getChain(chain); + return new ChainSupplierImpl().get(chain); } } diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/StructureConsumerImpl.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/StructureConsumerImpl.java index d858536847..6a952029ee 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/StructureConsumerImpl.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/StructureConsumerImpl.java @@ -24,7 +24,6 @@ import org.biojava.nbio.structure.StructureException; import org.biojava.nbio.structure.StructureImpl; import org.biojava.nbio.structure.StructureTools; -import org.biojava.nbio.structure.chem.ChemCompGroupFactory; import org.biojava.nbio.structure.io.BondMaker; import org.biojava.nbio.structure.io.ChargeAdder; import org.biojava.nbio.structure.io.EntityFinder; diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmtf/MmtfStructureReader.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmtf/MmtfStructureReader.java index 09d8ca58a8..bc5c93cb2c 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmtf/MmtfStructureReader.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmtf/MmtfStructureReader.java @@ -50,9 +50,9 @@ import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.StructureImpl; import org.biojava.nbio.structure.StructureTools; -import org.biojava.nbio.structure.io.mmcif.chem.PolymerType; -import org.biojava.nbio.structure.io.mmcif.chem.ResidueType; -import org.biojava.nbio.structure.io.mmcif.model.ChemComp; +import org.biojava.nbio.structure.chem.ChemComp; +import org.biojava.nbio.structure.chem.PolymerType; +import org.biojava.nbio.structure.chem.ResidueType; import org.biojava.nbio.structure.quaternary.BioAssemblyInfo; import org.biojava.nbio.structure.quaternary.BiologicalAssemblyTransformation; import org.biojava.nbio.structure.xtal.CrystalCell; @@ -69,7 +69,7 @@ * * @author Anthony Bradley * @since 5.0 - * + * */ public class MmtfStructureReader implements StructureAdapterInterface, Serializable { @@ -234,7 +234,7 @@ public void setGroupInfo(String groupName, int groupNumber, } atomsInGroup = new ArrayList<>(); ChemComp chemComp = new ChemComp(); - chemComp.setOne_letter_code(String.valueOf(singleLetterCode)); + chemComp.setOneLetterCode(String.valueOf(singleLetterCode)); chemComp.setType(chemCompType.toUpperCase()); chemComp.setResidueType(residueType); chemComp.setPolymerType(residueType.polymerType); @@ -333,14 +333,14 @@ public void setAtomInfo(String atomName, */ @Override public void setGroupBond(int indOne, int indTwo, int bondOrder) { - + // Get the atoms Atom atomOne = atomsInGroup.get(indOne); Atom atomTwo = atomsInGroup.get(indTwo); - + // set the new bond new BondImpl(atomOne, atomTwo, bondOrder); - + } /* (non-Javadoc) @@ -349,12 +349,12 @@ public void setGroupBond(int indOne, int indTwo, int bondOrder) { */ @Override public void setInterGroupBond(int indOne, int indTwo, int bondOrder) { - + // Get the atoms Atom atomOne = allAtoms[indOne]; Atom atomTwo = allAtoms[indTwo]; - - // set the new bond (this + + // set the new bond (this new BondImpl(atomOne, atomTwo, bondOrder); } diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmtf/MmtfStructureWriter.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmtf/MmtfStructureWriter.java index 47e4fb3d69..c55e67da30 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmtf/MmtfStructureWriter.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmtf/MmtfStructureWriter.java @@ -33,7 +33,7 @@ import org.biojava.nbio.structure.PDBCrystallographicInfo; import org.biojava.nbio.structure.PDBHeader; import org.biojava.nbio.structure.Structure; -import org.biojava.nbio.structure.io.mmcif.model.ChemComp; +import org.biojava.nbio.structure.chem.ChemComp; import org.biojava.nbio.structure.quaternary.BioAssemblyInfo; import org.rcsb.mmtf.api.StructureAdapterInterface; import org.rcsb.mmtf.dataholders.MmtfStructure; @@ -43,7 +43,7 @@ /** * Class to take Biojava structure data and covert to the DataApi for encoding. * Must implement all the functions in {@link StructureAdapterInterface}. - * + * * @author Anthony Bradley * @since 5.0 * @@ -103,8 +103,8 @@ public MmtfStructureWriter(Structure structure, StructureAdapterInterface dataTr insCode=MmtfStructure.UNAVAILABLE_CHAR_VALUE; } char singleLetterCode = 'X'; - if (chemComp.getOne_letter_code().length()==1){ - singleLetterCode = chemComp.getOne_letter_code().charAt(0); + if (chemComp.getOneLetterCode().length()==1){ + singleLetterCode = chemComp.getOneLetterCode().charAt(0); } mmtfDecoderInterface.setGroupInfo(group.getPDBName(), group.getResidueNumber().getSeqNum(), insCode.charValue(), chemComp.getType().toUpperCase(), atomsInGroup.size(), MmtfUtils.getNumBondsInGroup(atomsInGroup), singleLetterCode, diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmtf/MmtfUtils.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmtf/MmtfUtils.java index bbd34c9610..0a6cd9739c 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmtf/MmtfUtils.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmtf/MmtfUtils.java @@ -47,11 +47,11 @@ 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.chem.ChemComp; +import org.biojava.nbio.structure.chem.ChemCompTools; import org.biojava.nbio.structure.io.FileParsingParameters; import org.biojava.nbio.structure.io.mmcif.ChemCompGroupFactory; import org.biojava.nbio.structure.io.mmcif.DownloadChemCompProvider; -import org.biojava.nbio.structure.io.mmcif.chem.ChemCompTools; -import org.biojava.nbio.structure.io.mmcif.model.ChemComp; import org.biojava.nbio.structure.quaternary.BioAssemblyInfo; import org.biojava.nbio.structure.quaternary.BiologicalAssemblyTransformation; import org.biojava.nbio.structure.secstruc.DSSPParser; @@ -499,12 +499,12 @@ public static void insertSeqResGroup(Chain chain, Group group, int sequenceIndex * @param sequence the sequence of the construct */ public static void addSeqRes(Chain modelChain, String sequence) { - + List seqResGroups = modelChain.getSeqResGroups(); GroupType chainType = getChainType(modelChain.getAtomGroups()); - + for(int i=0; i i) { @@ -513,7 +513,7 @@ public static void addSeqRes(Chain modelChain, String sequence) { if(group!=null){ continue; } - + group = getSeqResGroup(singleLetterCode, chainType); addGroupAtId(seqResGroups, group, i); } From 1b164a99720e8b48c928883bb2d471dd994ea46e Mon Sep 17 00:00:00 2001 From: JonStargaryen Date: Wed, 20 Jan 2021 15:35:47 -0800 Subject: [PATCH 017/599] compiling --- .../nbio/structure/test/MMcifTest.java | 295 ------------- .../structure/test/StructureToolsTest.java | 6 +- .../biojava/nbio/structure/test/Test1a4w.java | 17 +- .../cif/CifFileSupplierIntegrationTest.java | 10 +- .../nbio/protmod/structure/StructureUtil.java | 18 +- .../src/main/java/demo/DemoCE.java | 4 +- .../structure/gui/util/PDBUploadPanel.java | 3 +- .../main/java/demo/ChemCompDistribution.java | 5 +- .../java/demo/DemoChangeChemCompProvider.java | 4 + .../java/demo/DemoMmcifToPdbConverter.java | 11 +- .../org/biojava/nbio/structure/ChainImpl.java | 1 + .../biojava/nbio/structure/HetatomImpl.java | 7 +- .../biojava/nbio/structure/URLIdentifier.java | 4 +- .../structure/chem/AllChemCompProvider.java | 167 ++++++++ .../biojava/nbio/structure/chem/ChemComp.java | 12 +- .../nbio/structure/chem/ChemCompAtom.java | 54 +-- .../nbio/structure/chem/ChemCompBond.java | 6 +- .../structure/chem/ChemCompGroupFactory.java | 129 ++++++ .../nbio/structure/chem/ChemCompProvider.java | 15 + .../nbio/structure/chem/ChemCompTools.java | 24 +- .../chem/ChemicalComponentDictionary.java | 6 +- .../chem/DownloadChemCompProvider.java | 403 ++++++++++++++++++ .../structure/chem/MetalBondDistance.java | 56 +++ .../chem/ReducedChemCompProvider.java | 58 +++ .../structure/chem/ZipChemCompProvider.java | 275 ++++++++++++ .../structure/contact/StructureInterface.java | 69 +-- .../nbio/structure/io/BcifFileReader.java | 4 +- .../biojava/nbio/structure/io/BondMaker.java | 1 + .../nbio/structure/io/ChargeAdder.java | 22 +- .../nbio/structure/io/CifFileReader.java | 4 +- .../nbio/structure/io/FileConvert.java | 6 +- .../nbio/structure/io/PDBFileParser.java | 4 +- .../structure/io/cif/ChemCompConsumer.java | 16 + .../io/cif/ChemCompConsumerImpl.java | 108 +++++ .../structure/io/cif/ChemCompConverter.java | 79 ++++ .../structure/io/cif/MetalBondConsumer.java | 11 + .../io/cif/MetalBondConsumerImpl.java | 55 +++ .../structure/io/cif/MetalBondConverter.java | 60 +++ .../io/cif/StructureConsumerImpl.java | 1 + ...Converter.java => StructureConverter.java} | 8 +- .../nbio/structure/io/mmtf/MmtfUtils.java | 4 +- .../biojava/nbio/structure/ChemCompTest.java | 24 +- .../nbio/structure/PdbFileFormat30Test.java | 4 +- .../org/biojava/nbio/structure/Test4hhb.java | 12 +- .../biojava/nbio/structure/TestAltLocs.java | 72 +--- .../biojava/nbio/structure/TestAtomCache.java | 3 +- .../org/biojava/nbio/structure/TestBond.java | 4 +- .../TestDownloadChemCompProvider.java | 4 +- .../nbio/structure/TestNucleotides.java | 8 +- .../structure/align/util/AtomCacheTest.java | 9 +- .../nbio/structure/asa/TestAsaCalc.java | 6 +- .../structure/io/TestDifficultMmCIFFiles.java | 18 +- .../nbio/structure/io/TestHeaderOnly.java | 18 +- .../nbio/structure/io/TestMMCIFWriting.java | 61 +-- .../structure/io/TestMmCIFSpecialCases.java | 82 ---- .../structure/io/TestNonDepositedFiles.java | 37 +- .../structure/io/TestParseMmCIFLigands.java | 6 +- .../io/mmcif/TestChemCompProvider.java | 2 + .../io/mmcif/TestEntityNameAndType.java | 2 + .../structure/io/mmtf/TestBondFinding.java | 4 +- .../structure/io/mmtf/TestMmtfRoundTrip.java | 26 +- .../io/mmtf/TestMmtfStructureReader.java | 36 +- .../io/mmtf/TestMmtfStructureWriter.java | 4 +- .../structure/redmine/Test1DARSeqAlign.java | 8 +- .../structure/test/util/GlobalsHelper.java | 6 +- 65 files changed, 1689 insertions(+), 809 deletions(-) delete mode 100644 biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/MMcifTest.java create mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/chem/AllChemCompProvider.java create mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemCompGroupFactory.java create mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemCompProvider.java create mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/chem/DownloadChemCompProvider.java create mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/chem/MetalBondDistance.java create mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ReducedChemCompProvider.java create mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ZipChemCompProvider.java create mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/ChemCompConsumer.java create mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/ChemCompConsumerImpl.java create mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/ChemCompConverter.java create mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/MetalBondConsumer.java create mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/MetalBondConsumerImpl.java create mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/MetalBondConverter.java rename biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/{CifFileConverter.java => StructureConverter.java} (97%) delete mode 100644 biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestMmCIFSpecialCases.java diff --git a/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/MMcifTest.java b/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/MMcifTest.java deleted file mode 100644 index 4947e0077a..0000000000 --- a/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/MMcifTest.java +++ /dev/null @@ -1,295 +0,0 @@ -/* - * BioJava development code - * - * This code may be freely distributed and modified under the - * terms of the GNU Lesser General Public Licence. This should - * be distributed with the code. If you do not have a copy, - * see: - * - * http://www.gnu.org/copyleft/lesser.html - * - * Copyright for this code is held jointly by the individual - * authors. These should be listed in @author doc comments. - * - * For more information on the BioJava project and its aims, - * or to join the biojava-l mailing list, visit the home page - * at: - * - * http://www.biojava.org/ - * - * created at Apr 26, 2008 - */ -package org.biojava.nbio.structure.test; - -import org.biojava.nbio.structure.*; -import org.biojava.nbio.structure.io.FileParsingParameters; -import org.biojava.nbio.structure.io.PDBFileParser; -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.junit.Test; -import static org.junit.Assert.*; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.util.List; - -public class MMcifTest { - - private static boolean headerOnly; - - @Test - public void testLoad() throws IOException { - - headerOnly = false; - - doTestLoad(); - - } - - @Test - public void testLoadHeaderOnly() throws IOException { - - headerOnly = true; - - doTestLoad(); - - } - - private void doTestLoad() throws IOException { - // a structure with microheterogeneity - //comparePDB2cif("2CI1","A"); - - // test a simple protein - comparePDB2cif("5pti","A"); - - // test a protein with modified residues - comparePDB2cif("1a4w","L"); - comparePDB2cif("1a4w","H"); - comparePDB2cif("1a4w","I"); - //non-standard encoded amino acid - comparePDB2cif("1fdo","A"); - - // test a DNA binding protein - comparePDB2cif("1j59","A"); - //comparePDB2cif("1j59","B"); - //comparePDB2cif("1j59","C"); - //comparePDB2cif("1j59","D"); - comparePDB2cif("1j59","E"); - //comparePDB2cif("1j59","F"); - - // test a NMR protein - comparePDB2cif("2kc9","A"); - } - - private void comparePDB2cif(String id, String chainId) throws IOException { - String fileName = "/"+id+".cif"; - InputStream inStream = this.getClass().getResourceAsStream(fileName); - assertNotNull("Could not find file " + fileName + ". Config problem?" , inStream); - - MMcifParser parser = new SimpleMMcifParser(); - - SimpleMMcifConsumer consumer = new SimpleMMcifConsumer(); - FileParsingParameters params = new FileParsingParameters(); - params.setHeaderOnly(headerOnly); - consumer.setFileParsingParameters(params); - - - parser.addMMcifConsumer(consumer); - parser.parse(new BufferedReader(new InputStreamReader(inStream))); - // remove to avoid memory leaks - parser.clearConsumers(); - Structure cifStructure = consumer.getStructure(); - assertNotNull(cifStructure); - - - // load the PDB file via the PDB parser - Structure pdbStructure = null; - InputStream pinStream = this.getClass().getResourceAsStream("/"+id+".pdb"); - assertNotNull(inStream); - - PDBFileParser pdbpars = new PDBFileParser(); - pdbpars.setFileParsingParameters(params); - - - pdbStructure = pdbpars.parsePDBFile(pinStream) ; - - - assertNotNull(pdbStructure); - - // now compare the results - - - // chech NMR data - assertEquals(id + ": the isNMR flag is not the same!", pdbStructure.isNmr(), cifStructure.isNmr()); - - if ( pdbStructure.isNmr()){ - assertEquals(id + ": the nr of NMR models is not the same!", pdbStructure.nrModels(), pdbStructure.nrModels()); - checkNMR(pdbStructure); - checkNMR(cifStructure); - } - - //System.out.println(pdbStructure); - //System.out.println(cifStructure); - - // compare amino acids in chain 1: - Chain a_pdb = pdbStructure.getPolyChainByPDB(chainId); - Chain a_cif = cifStructure.getPolyChainByPDB(chainId); - //System.out.println(a_pdb.getAtomGroups()); - - //System.out.println(id + "_" + chainName + " pdb atom groups: " + a_pdb.getAtomGroups(GroupType.AMINOACID).size()); - //System.out.println(id + "_" + chainName + " cif atom groups: " + a_cif.getAtomGroups(GroupType.AMINOACID).size()); - - //for (Group g: a_cif.getAtomGroups()){ - // System.out.println(g); - //} - //System.out.println("--"); - String pdb_SEQseq = a_pdb.getSeqResSequence(); - - String cif_SEQseq = a_cif.getSeqResSequence(); - - // System.out.println(id + "_" + chainName + " pdbSEQ: " + pdb_SEQseq); - // System.out.println(id + "_" + chainName + " cifSEQ: " + cif_SEQseq); - - assertEquals(id + ": the SEQRES sequences don't match!", pdb_SEQseq,cif_SEQseq); - - assertEquals(id + ": The nr of ATOM groups does not match!",a_pdb.getAtomGroups(GroupType.AMINOACID).size(),a_cif.getAtomGroups(GroupType.AMINOACID).size() ); - - // actually this check not necessarily works, since there can be waters in PDB that we don;t deal with yet in cif... - //assertEquals("the nr of ATOM record groups is not the same!" , a_pdb.getAtomLength(),a_cif.getAtomLength()); - for (int i = 0 ; i < a_pdb.getAtomGroups(GroupType.AMINOACID).size(); i++){ - Group gp = a_pdb.getAtomGroups(GroupType.AMINOACID).get(i); - - List cifGroups = a_cif.getAtomGroups(GroupType.AMINOACID); - Group gc = cifGroups.get(i); - checkGroups(gp, gc); - } - - - - String pdb_seq = a_pdb.getAtomSequence(); - String cif_seq = a_cif.getAtomSequence(); - - //System.out.println(pdb_seq); - //System.out.println(cif_seq); - - assertEquals("the sequences obtained from PDB and mmCif don't match!",pdb_seq, cif_seq); - - List pdb_dbrefs= pdbStructure.getDBRefs(); - List cif_dbrefs= cifStructure.getDBRefs(); - - assertEquals("nr of DBrefs found does not match!", pdb_dbrefs.size(),cif_dbrefs.size()); - - DBRef p = pdb_dbrefs.get(0); - DBRef c = cif_dbrefs.get(0); - - //System.out.println(p.toPDB()); - //System.out.println(c.toPDB()); - String pdb_dbref = p.toPDB(); - String cif_dbref = c.toPDB(); - assertEquals("DBRef is not equal",pdb_dbref,cif_dbref); - - PDBHeader h1 = pdbStructure.getPDBHeader(); - PDBHeader h2 = cifStructure.getPDBHeader(); - - //compareString(h1.toPDB() ,h2.toPDB()); - //System.out.println(h1.toPDB()); - //System.out.println(h2.toPDB()); - if ( ! h1.toPDB().toUpperCase().equals(h2.toPDB().toUpperCase()) ){ - System.err.println(h1.toPDB()); - System.err.println(h2.toPDB()); - compareString(h1.toPDB(), h2.toPDB()); - } - assertEquals("the PDBHeader.toPDB representation is not equivalent", h1.toPDB().toUpperCase(),h2.toPDB().toUpperCase()); - - // and the ultimate test! - // but we are not there yet... - // TODO: still need to parse SSBOND equivalent info from cif files... - //assertEquals("the Structure.toPDB representation is not equivalent", pdbStructure.toPDB(),cifStructure.toPDB()); - - - - } - - private void checkGroups(Group g1, Group g2){ - - //System.out.print("comparing " +g1 + " " + g2); - String pdbId1 = g1.getChain().getStructure().getPDBCode(); - String pdbId2 = g1.getChain().getStructure().getPDBCode(); - assertEquals(pdbId1, pdbId2); - - assertEquals(g1.getType(),g2.getType()); - assertEquals(g1.getResidueNumber().getSeqNum(),g2.getResidueNumber().getSeqNum()); - assertEquals(g1.getResidueNumber().getInsCode(),g2.getResidueNumber().getInsCode()); - assertEquals(g1.getPDBName(),g2.getPDBName()); - assertEquals(g1.has3D(),g2.has3D()); - - assertEquals(g1.hasAltLoc(), g2.hasAltLoc()); - - assertEquals(pdbId1 + ":" + g1 + " - " + pdbId2+":"+ g2,g1.getAltLocs().size(), g2.getAltLocs().size()); - - assertEquals(pdbId1 + ":" + g1 + " - " + pdbId2+":"+ g2 , g1.getAtoms().size(), g2.getAtoms().size()); - if ( g1.has3D()){ - - Atom a1 = g1.getAtom(0); - Atom a2 = g2.getAtom(0); - if ( a1 == null) - fail("could not get atom for group " + g1); - if (a2 == null) - fail("could not get atom for group " + g2); - assertEquals(a1.getX(),a2.getX(), 0.0001); - assertEquals(a1.getOccupancy(),a2.getOccupancy(), 0.0001); - assertEquals(a1.getTempFactor(),a2.getTempFactor(), 0.0001); - assertEquals(a1.getName(),a2.getName()); - - - } - //System.out.println(" ... done"); - - } - - private void checkNMR(Structure s){ - assertTrue(s.isNmr()); - - int models = s.nrModels(); - assertTrue(models > 0); - - List model0 = s.getModel(0); - - // compare with all others - for (int i = 1 ; i < models; i++){ - List modelX = s.getModel(i); - - assertEquals(model0.size(),modelX.size()); - - // compare lengths: - for (int j=0 ; j< model0.size();j++){ - Chain c1 = model0.get(j); - Chain cx = modelX.get(j); - assertEquals(c1.getAtomLength(),cx.getAtomLength()); - // can;t compare seq res, since this is only done for 1st... - //assertEquals("c1.getSeqResLength(),cx.getSeqResLength()); - assertEquals(c1.getAtomSequence(),cx.getAtomSequence()); - assertEquals(c1.getAtomGroups(GroupType.AMINOACID).size(),cx.getAtomGroups(GroupType.AMINOACID).size()); - assertEquals(c1.getAtomGroups(GroupType.NUCLEOTIDE).size(),cx.getAtomGroups(GroupType.NUCLEOTIDE).size()); - assertEquals(c1.getAtomGroups(GroupType.HETATM).size(),cx.getAtomGroups(GroupType.HETATM).size()); - } - - - } - } - - private void compareString(String t, String pdb){ - for (int i =0 ; i < t.length() ; i++){ - System.out.println(">"+t.charAt(i)+":"+ pdb.charAt(i)+"<"); - if ( Character.toUpperCase(t.charAt(i)) != Character.toUpperCase(pdb.charAt(i))){ - System.out.println("Mismatch!"); - break; - } - } - } - - -} diff --git a/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/StructureToolsTest.java b/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/StructureToolsTest.java index b2ae39611c..170694a6e2 100644 --- a/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/StructureToolsTest.java +++ b/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/StructureToolsTest.java @@ -24,11 +24,11 @@ import org.biojava.nbio.structure.*; import org.biojava.nbio.structure.align.util.AtomCache; +import org.biojava.nbio.structure.chem.ChemCompGroupFactory; +import org.biojava.nbio.structure.chem.ChemCompProvider; +import org.biojava.nbio.structure.chem.DownloadChemCompProvider; import org.biojava.nbio.structure.io.FileParsingParameters; import org.biojava.nbio.structure.io.PDBFileParser; -import org.biojava.nbio.structure.io.mmcif.ChemCompGroupFactory; -import org.biojava.nbio.structure.io.mmcif.ChemCompProvider; -import org.biojava.nbio.structure.io.mmcif.DownloadChemCompProvider; import org.junit.Before; import org.junit.Test; diff --git a/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/Test1a4w.java b/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/Test1a4w.java index 870c74a13a..ba6266cb2b 100644 --- a/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/Test1a4w.java +++ b/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/Test1a4w.java @@ -26,14 +26,13 @@ import org.biojava.nbio.structure.*; import org.biojava.nbio.structure.align.util.AtomCache; +import org.biojava.nbio.structure.io.CifFileReader; import org.biojava.nbio.structure.io.FileParsingParameters; import org.biojava.nbio.structure.io.PDBFileParser; -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.junit.Assert; import org.junit.Before; import org.junit.Test; +import org.rcsb.cif.model.CifFile; import java.io.IOException; import java.io.InputStream; @@ -87,17 +86,11 @@ public void test1a4wPDBFile() throws IOException InputStream inStream = this.getClass().getResourceAsStream("/1a4w.cif"); Assert.assertNotNull(inStream); - MMcifParser pdbpars = new SimpleMMcifParser(); - SimpleMMcifConsumer consumer = new SimpleMMcifConsumer(); FileParsingParameters params = new FileParsingParameters(); params.setAlignSeqRes(true); - consumer.setFileParsingParameters(params); - pdbpars.addMMcifConsumer(consumer); - - pdbpars.parse(inStream) ; - structure2 = consumer.getStructure(); - - + CifFileReader reader = new CifFileReader(); + reader.setFileParsingParameters(params); + structure2 = reader.getStructure(inStream); Assert.assertNotNull(structure2); diff --git a/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/io/cif/CifFileSupplierIntegrationTest.java b/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/io/cif/CifFileSupplierIntegrationTest.java index 03e2f6f060..8e59c8a931 100644 --- a/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/io/cif/CifFileSupplierIntegrationTest.java +++ b/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/io/cif/CifFileSupplierIntegrationTest.java @@ -12,7 +12,7 @@ import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.StructureImpl; import org.biojava.nbio.structure.StructureTools; -import org.biojava.nbio.structure.io.cif.CifFileConverter; +import org.biojava.nbio.structure.io.cif.StructureConverter; import org.junit.Test; import java.io.ByteArrayInputStream; @@ -49,10 +49,10 @@ public void test1A2C() throws IOException { private static void testRoundTrip(String pdbId) throws IOException { URL url = new URL("https://files.rcsb.org/download/" + pdbId + ".cif"); - Structure originalStruct = CifFileConverter.fromURL(url); + Structure originalStruct = StructureConverter.fromURL(url); - InputStream inputStream = new ByteArrayInputStream(CifFileConverter.toText(originalStruct).getBytes()); - Structure readStruct = CifFileConverter.fromInputStream(inputStream); + InputStream inputStream = new ByteArrayInputStream(StructureConverter.toText(originalStruct).getBytes()); + Structure readStruct = StructureConverter.fromInputStream(inputStream); assertNotNull(readStruct); assertEquals(originalStruct.getChains().size(), readStruct.getChains().size()); @@ -113,7 +113,7 @@ private static void testRoundTrip(String pdbId) throws IOException { @Test public void testBiounitWriting() throws IOException { Structure s = createDummyStructure(); - String mmcif = CifFileConverter.toText(s); + String mmcif = StructureConverter.toText(s); String[] lines = mmcif.split("\n"); long atomLines = Arrays.stream(lines).filter(l -> l.startsWith("ATOM")).count(); assertNotNull(mmcif); diff --git a/biojava-modfinder/src/main/java/org/biojava/nbio/protmod/structure/StructureUtil.java b/biojava-modfinder/src/main/java/org/biojava/nbio/protmod/structure/StructureUtil.java index 0245018ca2..4842864b2d 100644 --- a/biojava-modfinder/src/main/java/org/biojava/nbio/protmod/structure/StructureUtil.java +++ b/biojava-modfinder/src/main/java/org/biojava/nbio/protmod/structure/StructureUtil.java @@ -25,8 +25,8 @@ package org.biojava.nbio.protmod.structure; import org.biojava.nbio.structure.*; -import org.biojava.nbio.structure.io.mmcif.MetalBondParser; -import org.biojava.nbio.structure.io.mmcif.chem.MetalBondDistance; +import org.biojava.nbio.structure.chem.MetalBondDistance; +import org.biojava.nbio.structure.io.cif.MetalBondConverter; import java.util.ArrayList; import java.util.Collections; @@ -279,18 +279,14 @@ public static Atom[] findLinkage(final Group group1, final Group group2, } private static boolean hasMetalBond(Atom a1, Atom a2, MetalBondDistance definition) { - - double distance = Calc.getDistance(a1,a2); - - Float min = definition.getLowerLimit(); - Float max = definition.getUpperLimit(); - - return ( min < distance && max > distance); - + double distance = Calc.getDistance(a1, a2); + float min = definition.getLowerLimit(); + float max = definition.getUpperLimit(); + return (min < distance && max > distance); } private static MetalBondDistance getMetalDistanceCutoff(String name1, String name2) { - Map> defs= MetalBondParser.getMetalBondDefinitions(); + Map> defs = MetalBondConverter.getMetalBondDefinitions(); List distances = defs.get(name1); diff --git a/biojava-structure-gui/src/main/java/demo/DemoCE.java b/biojava-structure-gui/src/main/java/demo/DemoCE.java index 5e2bb0aabb..88c5c8f307 100644 --- a/biojava-structure-gui/src/main/java/demo/DemoCE.java +++ b/biojava-structure-gui/src/main/java/demo/DemoCE.java @@ -36,8 +36,8 @@ import org.biojava.nbio.structure.align.model.AfpChainWriter; import org.biojava.nbio.structure.align.util.AFPChainScorer; import org.biojava.nbio.structure.align.util.AtomCache; -import org.biojava.nbio.structure.io.mmcif.ChemCompGroupFactory; -import org.biojava.nbio.structure.io.mmcif.DownloadChemCompProvider; +import org.biojava.nbio.structure.chem.ChemCompGroupFactory; +import org.biojava.nbio.structure.chem.DownloadChemCompProvider; public class DemoCE { diff --git a/biojava-structure-gui/src/main/java/org/biojava/nbio/structure/gui/util/PDBUploadPanel.java b/biojava-structure-gui/src/main/java/org/biojava/nbio/structure/gui/util/PDBUploadPanel.java index 92efbeaf36..0e36624830 100644 --- a/biojava-structure-gui/src/main/java/org/biojava/nbio/structure/gui/util/PDBUploadPanel.java +++ b/biojava-structure-gui/src/main/java/org/biojava/nbio/structure/gui/util/PDBUploadPanel.java @@ -26,6 +26,7 @@ import org.biojava.nbio.structure.StructureException; import org.biojava.nbio.structure.StructureTools; import org.biojava.nbio.structure.align.util.UserConfiguration; +import org.biojava.nbio.structure.io.CifFileReader; import org.biojava.nbio.structure.io.PDBFileReader; import org.biojava.nbio.structure.io.StructureIOFile; import org.slf4j.Logger; @@ -133,7 +134,7 @@ private Structure getStructure(JTextField filePath,JTextField chainId) throws St if ( fileFormat.equals(UserConfiguration.PDB_FORMAT)){ reader = new PDBFileReader(); } else if ( fileFormat.equals(UserConfiguration.MMCIF_FORMAT)){ - reader = new MMCIFFileReader(); + reader = new CifFileReader(); } else { throw new StructureException("Unkown file format " + fileFormat); } diff --git a/biojava-structure/src/main/java/demo/ChemCompDistribution.java b/biojava-structure/src/main/java/demo/ChemCompDistribution.java index 7e4e847e52..a1ae74166b 100644 --- a/biojava-structure/src/main/java/demo/ChemCompDistribution.java +++ b/biojava-structure/src/main/java/demo/ChemCompDistribution.java @@ -20,15 +20,12 @@ */ package demo; -import org.biojava.nbio.structure.io.mmcif.DownloadChemCompProvider; +import org.biojava.nbio.structure.chem.DownloadChemCompProvider; public class ChemCompDistribution { - public static void main(String[] args){ - DownloadChemCompProvider c = new DownloadChemCompProvider(); c.setDownloadAll(true); c.checkDoFirstInstall(); - } } diff --git a/biojava-structure/src/main/java/demo/DemoChangeChemCompProvider.java b/biojava-structure/src/main/java/demo/DemoChangeChemCompProvider.java index 1285d8488b..b8e4eb5430 100644 --- a/biojava-structure/src/main/java/demo/DemoChangeChemCompProvider.java +++ b/biojava-structure/src/main/java/demo/DemoChangeChemCompProvider.java @@ -23,6 +23,10 @@ import org.biojava.nbio.structure.Chain; import org.biojava.nbio.structure.Group; import org.biojava.nbio.structure.Structure; +import org.biojava.nbio.structure.chem.AllChemCompProvider; +import org.biojava.nbio.structure.chem.ChemCompGroupFactory; +import org.biojava.nbio.structure.chem.ChemCompProvider; +import org.biojava.nbio.structure.chem.DownloadChemCompProvider; import org.biojava.nbio.structure.io.FileParsingParameters; import org.biojava.nbio.structure.io.PDBFileReader; diff --git a/biojava-structure/src/main/java/demo/DemoMmcifToPdbConverter.java b/biojava-structure/src/main/java/demo/DemoMmcifToPdbConverter.java index bd84ae8f1e..67de1031c0 100644 --- a/biojava-structure/src/main/java/demo/DemoMmcifToPdbConverter.java +++ b/biojava-structure/src/main/java/demo/DemoMmcifToPdbConverter.java @@ -23,12 +23,10 @@ import org.biojava.nbio.structure.Chain; import org.biojava.nbio.structure.Structure; +import org.biojava.nbio.structure.io.cif.StructureConverter; -import java.io.BufferedReader; import java.io.File; -import java.io.FileInputStream; import java.io.IOException; -import java.io.InputStreamReader; import java.io.PrintWriter; /** @@ -44,13 +42,8 @@ public static void main(String[] args) throws Exception { } public static void convert(File inFile, File outFile) throws IOException { - MMcifParser parser = new SimpleMMcifParser(); - SimpleMMcifConsumer consumer = new SimpleMMcifConsumer(); - parser.addMMcifConsumer(consumer); - parser.parse(new BufferedReader(new InputStreamReader(new FileInputStream(inFile)))); - // now get the protein structure. - Structure cifStructure = consumer.getStructure(); + Structure cifStructure = StructureConverter.fromPath(inFile.toPath()); // and write it out as PDB format PrintWriter pr = new PrintWriter(outFile); diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/ChainImpl.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/ChainImpl.java index 8f548be835..5a395ee417 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/ChainImpl.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/ChainImpl.java @@ -25,6 +25,7 @@ import org.biojava.nbio.structure.chem.ChemComp; +import org.biojava.nbio.structure.chem.ChemCompGroupFactory; import org.biojava.nbio.structure.chem.PolymerType; import org.biojava.nbio.structure.io.FileConvert; import org.biojava.nbio.core.exceptions.CompoundNotFoundException; diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/HetatomImpl.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/HetatomImpl.java index c9c05a704c..27a7e6a3a5 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/HetatomImpl.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/HetatomImpl.java @@ -24,6 +24,7 @@ package org.biojava.nbio.structure; import org.biojava.nbio.structure.chem.ChemComp; +import org.biojava.nbio.structure.chem.ChemCompGroupFactory; import org.biojava.nbio.structure.chem.PolymerType; import org.biojava.nbio.structure.chem.ResidueType; import org.biojava.nbio.structure.io.GroupToSDF; @@ -466,9 +467,11 @@ public void setId(long id) { @Override public ChemComp getChemComp() { - if ( chemComp == null ) { + if (chemComp == null) { chemComp = ChemCompGroupFactory.getChemComp(pdb_name); - if (chemComp == null) logger.info("getChemComp: " + pdb_name); + if (chemComp == null) { + logger.info("getChemComp: {}", pdb_name); + } } return chemComp; } diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/URLIdentifier.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/URLIdentifier.java index 91cccd6a38..a36e93b508 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/URLIdentifier.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/URLIdentifier.java @@ -23,7 +23,7 @@ import org.biojava.nbio.structure.StructureIO.StructureFiletype; import org.biojava.nbio.structure.align.util.AtomCache; import org.biojava.nbio.structure.io.PDBFileReader; -import org.biojava.nbio.structure.io.cif.CifFileConverter; +import org.biojava.nbio.structure.io.cif.StructureConverter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -153,7 +153,7 @@ public Structure loadStructure(AtomCache cache) throws StructureException, switch(format) { case CIF: - return CifFileConverter.fromURL(url); + return StructureConverter.fromURL(url); default: case PDB: // pdb file based parsing diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/AllChemCompProvider.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/AllChemCompProvider.java new file mode 100644 index 0000000000..77881edb44 --- /dev/null +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/AllChemCompProvider.java @@ -0,0 +1,167 @@ +package org.biojava.nbio.structure.chem; + +import org.biojava.nbio.structure.align.util.UserConfiguration; +import org.biojava.nbio.structure.io.LocalPDBDirectory; +import org.biojava.nbio.structure.io.cif.ChemCompConverter; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.nio.file.Paths; +import java.util.concurrent.atomic.AtomicBoolean; + +/** + * A ChemComp provider that downloads and caches the components.cif file from the wwPDB site. It then loads all chemical + * components at startup and keeps them in memory. This provider is not used as a default since it is slower at startup + * and requires more memory than the {@link DownloadChemCompProvider} that is used by default. + * + * @author Andreas Prlic + */ +public class AllChemCompProvider implements ChemCompProvider, Runnable { + private static final Logger logger = LoggerFactory.getLogger(AllChemCompProvider.class); + public static final String COMPONENTS_FILE_LOCATION = "pub/pdb/data/monomers/components.cif.gz"; + private static String path; + private static String serverName; + + // there will be only one copy of the dictionary across all instances + // to reduce memory impact + static ChemicalComponentDictionary dict; + + // flags to make sure there is only one thread running that is loading the dictionary + static AtomicBoolean loading = new AtomicBoolean(false); + static AtomicBoolean isInitialized = new AtomicBoolean(false); + + public AllChemCompProvider() { + if (loading.get()) { + logger.warn("other thread is already loading all chemcomps, no need to init twice"); + return; + } + if (isInitialized.get()) { + return; + } + + loading.set(true); + + Thread t = new Thread(this); + t.start(); + } + + /** + * make sure all paths are initialized correctly + */ + private static void initPath() { + if (path == null) { + UserConfiguration config = new UserConfiguration(); + path = config.getCacheFilePath(); + } + } + + private static void initServerName() { + if (serverName == null) { + serverName = LocalPDBDirectory.getServerName(); + } + } + + private void ensureFileExists() { + String fileName = getLocalFileName(); + File f = new File(fileName); + + if (!f.exists()) { + try { + downloadFile(); + } catch (IOException e) { + logger.error("Caught IOException", e); + } + } + } + + /** + * Downloads the components.cif.gz file from the wwPDB site. + */ + public static void downloadFile() throws IOException { + initPath(); + initServerName(); + String localName = getLocalFileName(); + String u = serverName + "/" + COMPONENTS_FILE_LOCATION; + downloadFileFromRemote(new URL(u), new File(localName)); + } + + private static void downloadFileFromRemote(URL remoteURL, File localFile) throws IOException { + logger.info("Downloading {} to: {}", remoteURL, localFile); + FileOutputStream out = new FileOutputStream(localFile); + + InputStream in = remoteURL.openStream(); + byte[] buf = new byte[4 * 1024]; // 4K buffer + int bytesRead; + while ((bytesRead = in.read(buf)) != -1) { + out.write(buf, 0, bytesRead); + } + in.close(); + out.close(); + } + + private static String getLocalFileName(){ + File dir = new File(path, DownloadChemCompProvider.CHEM_COMP_CACHE_DIRECTORY); + + if (!dir.exists()) { + logger.info("Creating directory {}", dir.toString()); + dir.mkdir(); + } + + return new File(dir, "components.cif.gz").toString(); + } + + /** + * Load all {@link ChemComp} definitions into memory. + */ + private void loadAllChemComps() throws IOException { + String fileName = getLocalFileName(); + logger.debug("Loading {}", fileName); + dict = ChemCompConverter.fromPath(Paths.get(fileName)); + } + + /** + * {@inheritDoc} + */ + @Override + public ChemComp getChemComp(String recordName) { + while (loading.get()) { + // another thread is still initializing the definitions + try { + // wait half a second + Thread.sleep(500); + } catch (InterruptedException e) { + logger.error("Interrepted thread while waiting: {}", e.getMessage()); + //e.printStackTrace(); + } + } + + return dict.getChemComp(recordName); + } + + /** + * Do the actual loading of the dictionary in a thread. + */ + @Override + public void run() { + long timeS = System.currentTimeMillis(); + initPath(); + ensureFileExists(); + + try { + loadAllChemComps(); + long timeE = System.currentTimeMillis(); + logger.debug("Time to init chem comp dictionary: {} sec.", (timeE - timeS) / 1000); + } catch (IOException e) { + logger.error("Could not load chemical components definition file {}. Error: {}", getLocalFileName(), e.getMessage()); + } finally { + loading.set(false); + isInitialized.set(true); + } + } +} + diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemComp.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemComp.java index 52aa39c604..7109d60204 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemComp.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemComp.java @@ -19,14 +19,14 @@ public class ChemComp implements CifBean, Compa private String formula; private String monNstdParentCompId; private String pdbxSynonyms; - private String pdbxFormalCharge; + private int pdbxFormalCharge; private String pdbxInitialDate; private String pdbxModifiedDate; private String pdbxAmbiguousFlag; private String pdbxReleaseStatus; private String pdbxReplacedBy; private String pdbxReplaces; - private String formulaWeight; + private double formulaWeight; private String oneLetterCode; private String threeLetterCode; private String pdbxModelCoordinatesDetails; @@ -159,11 +159,11 @@ public void setPdbxSynonyms(String pdbxSynonyms) { this.pdbxSynonyms = pdbxSynonyms; } - public String getPdbxFormalCharge() { + public int getPdbxFormalCharge() { return pdbxFormalCharge; } - public void setPdbxFormalCharge(String pdbxFormalCharge) { + public void setPdbxFormalCharge(int pdbxFormalCharge) { this.pdbxFormalCharge = pdbxFormalCharge; } @@ -215,11 +215,11 @@ public void setPdbxReplaces(String pdbxReplaces) { this.pdbxReplaces = pdbxReplaces; } - public String getFormulaWeight() { + public double getFormulaWeight() { return formulaWeight; } - public void setFormulaWeight(String formulaWeight) { + public void setFormulaWeight(double formulaWeight) { this.formulaWeight = formulaWeight; } diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemCompAtom.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemCompAtom.java index cad290820e..d87a51e720 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemCompAtom.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemCompAtom.java @@ -8,24 +8,24 @@ public class ChemCompAtom implements CifBean cache = new SoftHashMap<>(0); + + public static ChemComp getChemComp(String recordName) { + recordName = recordName.toUpperCase().trim(); + + // we are using the cache, to avoid hitting the file system too often. + ChemComp cc = cache.get(recordName); + if (cc != null) { + logger.debug("Chem comp {} read from cache", cc.getThreeLetterCode()); + return cc; + } + + // not cached, get the chem comp from the provider + logger.debug("Chem comp {} read from provider {}", recordName, chemCompProvider.getClass().getCanonicalName()); + cc = chemCompProvider.getChemComp(recordName); + + // Note that this also caches null or empty responses + cache.put(recordName, cc); + return cc; + } + + /** + * The new ChemCompProvider will be set in the static variable, + * so this provider will be used from now on until it is changed + * again. Note that this change can have unexpected behavior of + * code executed afterwards. + *

+ * Changing the provider also resets the cache, so any groups + * previously accessed will be reread or re-downloaded. + * + * @param provider + */ + public static void setChemCompProvider(ChemCompProvider provider) { + logger.debug("Setting new chem comp provider to {}", provider.getClass().getCanonicalName()); + chemCompProvider = provider; + // clear cache + cache.clear(); + } + + public static ChemCompProvider getChemCompProvider(){ + return chemCompProvider; + } + + /** + * Force the in-memory cache to be reset. + * + * Note that the ChemCompProvider may have additional memory or disk caches that need to be cleared too. + */ + public static void clearCache() { + cache.clear(); + } + + public static Group getGroupFromChemCompDictionary(String recordName) { + // make sure we work with upper case records + recordName = recordName.toUpperCase().trim(); + Group g; + ChemComp cc = getChemComp(recordName); + + if (cc == null) { + return null; + } + + if (PolymerType.PROTEIN_ONLY.contains(cc.getPolymerType())) { + AminoAcid aa = new AminoAcidImpl(); + + String one_letter = cc.getOneLetterCode(); + if (one_letter == null || one_letter.equals("X") || one_letter.equals("?") || one_letter.length() == 0) { + String parent = cc.getMonNstdParentCompId(); + if (parent != null && parent.length() == 3) { + String parentid = cc.getMonNstdParentCompId(); + ChemComp parentCC = getChemComp(parentid); + one_letter = parentCC.getOneLetterCode(); + } + } + + if (one_letter == null || one_letter.length() == 0 || one_letter.equals("?")) { + // e.g. problem with PRR, which probably should have a parent of ALA, but as of 20110127 does not. + logger.warn("Problem with chemical component: {} Did not find one letter code! Setting it to 'X'", + recordName); + aa.setAminoType('X'); + } else { + aa.setAminoType(one_letter.charAt(0)); + } + + g = aa; + } else if (PolymerType.POLYNUCLEOTIDE_ONLY.contains(cc.getPolymerType())) { + g = new NucleotideImpl(); + } else { + g = new HetatomImpl(); + } + + g.setChemComp(cc); + return g; + } + + public static String getOneLetterCode(ChemComp cc) { + String oneLetter = cc.getOneLetterCode(); + if (oneLetter == null || oneLetter.equals("X") || oneLetter.equals("?")) { + String parentId = cc.getMonNstdParentCompId(); + if (parentId == null) { + return oneLetter; + } + // cases like OIM have multiple parents (comma separated), we shouldn't try grab a chemcomp for those strings + if (parentId.length() > 3) { + return oneLetter; + } + ChemComp parentCC = ChemCompGroupFactory.getChemComp(parentId); + if (parentCC == null) { + return oneLetter; + } + oneLetter = parentCC.getOneLetterCode(); + } + return oneLetter; + } +} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemCompProvider.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemCompProvider.java new file mode 100644 index 0000000000..936f5ef8cf --- /dev/null +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemCompProvider.java @@ -0,0 +1,15 @@ +package org.biojava.nbio.structure.chem; + +/** + * Interface that is implemented by all classes that can provide {@link ChemComp} definitions. + * @author Andreas Prlic + * @since 3.0 + */ +public interface ChemCompProvider { + /** + * Returns a new instance of a chemical component definition. + * @param recordName the ID of the {@link ChemComp} + * @return a new {@link ChemComp} definition. + */ + ChemComp getChemComp(String recordName); +} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemCompTools.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemCompTools.java index 6b8f74dbd8..929223040a 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemCompTools.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemCompTools.java @@ -78,21 +78,21 @@ public class ChemCompTools { AMINO_ACID_LOOKUP_1TO3 = Collections.unmodifiableMap(Collections.synchronizedMap(bar)); foo = new HashMap<>(); - foo.put("DA",'A'); - foo.put("DC",'C'); - foo.put("DG",'G'); - foo.put("DI",'I'); - foo.put("DU",'U'); - foo.put("DT",'T'); + foo.put("DA", 'A'); + foo.put("DC", 'C'); + foo.put("DG", 'G'); + foo.put("DI", 'I'); + foo.put("DU", 'U'); + foo.put("DT", 'T'); DNA_LOOKUP_2TO1 = Collections.unmodifiableMap((Collections.synchronizedMap(foo))); bar = new HashMap<>(); - bar.put('A',"DA"); - bar.put('C',"DC"); - bar.put('G',"DG"); - bar.put('I',"DI"); - bar.put('U',"DU"); - bar.put('T',"DT"); + bar.put('A', "DA"); + bar.put('C', "DC"); + bar.put('G', "DG"); + bar.put('I', "DI"); + bar.put('U', "DU"); + bar.put('T', "DT"); DNA_LOOKUP_1TO2 = Collections.unmodifiableMap(Collections.synchronizedMap(bar)); } diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemicalComponentDictionary.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemicalComponentDictionary.java index 63b38ed2e2..c191e67118 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemicalComponentDictionary.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemicalComponentDictionary.java @@ -12,9 +12,9 @@ * */ public class ChemicalComponentDictionary { - private Map dictionary; - private Map replaces; - private Map isReplacedBy; + private final Map dictionary; + private final Map replaces; + private final Map isReplacedBy; public ChemicalComponentDictionary(){ dictionary = new HashMap<>(); diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/DownloadChemCompProvider.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/DownloadChemCompProvider.java new file mode 100644 index 0000000000..71a17b7292 --- /dev/null +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/DownloadChemCompProvider.java @@ -0,0 +1,403 @@ +package org.biojava.nbio.structure.chem; + +import org.biojava.nbio.core.util.InputStreamProvider; +import org.biojava.nbio.structure.align.util.URLConnectionTools; +import org.biojava.nbio.structure.align.util.UserConfiguration; +import org.biojava.nbio.structure.io.LocalPDBDirectory; +import org.biojava.nbio.structure.io.cif.ChemCompConverter; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileOutputStream; +import java.io.FilenameFilter; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.net.URL; +import java.net.URLConnection; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.zip.GZIPOutputStream; + +/** + * This provider of chemical components can download and cache chemical component definition files from the RCSB PDB web + * site. It is the default way to access these definitions. If this provider is called he first time, it will download + * and install all chemical component definitions in a local directory. Once the definition files have been installed, + * it has quick startup time and low memory requirements. + * + * An alternative provider, that keeps all definitions in memory is the {@link AllChemCompProvider}. Another provider, + * that does not require any network access, but only can support a limited set of chemical component definitions, is + * the {@link ReducedChemCompProvider}. + * + * @author Andreas Prlic + */ +public class DownloadChemCompProvider implements ChemCompProvider { + private static final Logger logger = LoggerFactory.getLogger(DownloadChemCompProvider.class); + + public static final String CHEM_COMP_CACHE_DIRECTORY = "chemcomp"; + public static final String DEFAULT_SERVER_URL = "http://files.rcsb.org/ligands/download/"; + public static String serverBaseUrl = DEFAULT_SERVER_URL; + /** + * Use default RCSB server layout (true) or internal RCSB server layout (false) + */ + public static boolean useDefaultUrlLayout = true; + + private static File path; + //private static final String FILE_SEPARATOR = System.getProperty("file.separator"); + private static final String NEWLINE = System.getProperty("line.separator"); + + + // flags to make sure there is only one thread running that is loading the dictionary + static AtomicBoolean loading = new AtomicBoolean(false); + + static final List protectedIDs = new ArrayList<>(); + static { + protectedIDs.add("CON"); + protectedIDs.add("PRN"); + protectedIDs.add("AUX"); + protectedIDs.add("NUL"); + } + + private static ChemCompProvider fallback = null; // Fallback provider if the download fails + + /** + * by default we will download only some of the files. User has to request that all files should be downloaded... + */ + boolean downloadAll = false; + + public DownloadChemCompProvider() { + this(null); + } + + public DownloadChemCompProvider(String cacheFilePath) { + logger.debug("Initialising DownloadChemCompProvider"); + + // note that path is static, so this is just to make sure that all non-static methods will have path initialised + if (cacheFilePath != null) { + path = new File(cacheFilePath); + } + } + + /** + * Get this provider's cache path + * @return + */ + public static File getPath() { + if (path == null) { + UserConfiguration config = new UserConfiguration(); + path = new File(config.getCacheFilePath()); + } + return path; + } + + /** + * Checks if the chemical components already have been installed into the PDB directory. + * If not, will download the chemical components definitions file and split it up into small + * subfiles. + */ + public void checkDoFirstInstall() { + if (!downloadAll) { + return; + } + + // this makes sure there is a file separator between every component, + // if path has a trailing file separator or not, it will work for both cases + File dir = new File(getPath(), CHEM_COMP_CACHE_DIRECTORY); + File f = new File(dir, "components.cif.gz"); + + if (!f.exists()) { + downloadAllDefinitions(); + } else { + // file exists.. did it get extracted? + FilenameFilter filter = (dir1, file) -> file.endsWith(".cif.gz"); + String[] files = dir.list(filter); + if (files.length < 500) { + // not all did get unpacked + try { + split(); + } catch (IOException e) { + logger.error("Could not split file {} into individual chemical component files. Error: {}", + f.toString(), e.getMessage()); + } + } + } + } + + private void split() throws IOException { + logger.info("Installing individual chem comp files ..."); + + File dir = new File(getPath(), CHEM_COMP_CACHE_DIRECTORY); + File f = new File(dir, "components.cif.gz"); + + int counter = 0; + InputStreamProvider prov = new InputStreamProvider(); + + try (BufferedReader buf = new BufferedReader (new InputStreamReader(prov.getInputStream(f)))) { + String line; + line = buf.readLine (); + StringWriter writer = new StringWriter(); + + String currentID = null; + while (line != null) { + if (line.startsWith("data_")) { + // a new record found! + + if (currentID != null) { + writeID(writer.toString(), currentID); + counter++; + } + + currentID = line.substring(5); + writer = new StringWriter(); + } + + writer.append(line); + writer.append(NEWLINE); + + line = buf.readLine(); + } + + // write the last record... + writeID(writer.toString(), currentID); + counter++; + } + + logger.info("Created {} chemical component files.", counter); + } + + /** + * Output chemical contents to a file + * @param contents File contents + * @param currentID Chemical ID, used to determine the filename + * @throws IOException + */ + private void writeID(String contents, String currentID) throws IOException { + String localName = getLocalFileName(currentID); + try (PrintWriter pw = new PrintWriter(new GZIPOutputStream(new FileOutputStream(localName)))) { + pw.print(contents); + pw.flush(); + } + } + + /** + * Loads the definitions for this {@link ChemComp} from a local file and instantiates a new object. + * + * @param recordName the ID of the {@link ChemComp} + * @return a new {@link ChemComp} definition. + */ + @Override + public ChemComp getChemComp(String recordName) { + // make sure we work with upper case records + recordName = recordName.toUpperCase().trim(); + + boolean haveFile = true; + if (recordName.equals("?")) { + return null; + } + + if (fileIsAbsent(recordName)) { + // check if we should install all components + checkDoFirstInstall(); + } + if (fileIsAbsent(recordName)) { + // we previously have installed already the definitions, + // just do an incrememntal update + haveFile = downloadChemCompRecord(recordName); + } + + // Added check that download was successful and chemical component is available. + if (haveFile) { + String filename = getLocalFileName(recordName); + try { + ChemicalComponentDictionary dict = ChemCompConverter.fromPath(Paths.get(filename)); + ChemComp chemComp = dict.getChemComp(recordName); + + // May be null if the file was corrupt. Fall back on ReducedChemCompProvider in that case + if (chemComp != null) { + return chemComp; + } + } catch (IOException e) { + logger.warn("Could not download chemical component file {} for {}. Error: {}. Now trying to use the " + + "local chemical component definitions.", filename, recordName, e.getMessage()); + } + } + + // see https://github.com/biojava/biojava/issues/315 + // probably a network error happened. Try to use the ReducedChemCOmpProvider + if (fallback == null) { + fallback = new ReducedChemCompProvider(); + } + + logger.warn("Falling back to ReducedChemCompProvider for {}. This could indicate a network error.", recordName); + return fallback.getChemComp(recordName); + } + + /** + * Returns the file name that contains the definition for this {@link ChemComp} + * + * @param recordName the ID of the {@link ChemComp} + * @return full path to the file + */ + public static String getLocalFileName(String recordName) { + if (protectedIDs.contains(recordName)) { + recordName = "_" + recordName; + } + + File f = new File(getPath(), CHEM_COMP_CACHE_DIRECTORY); + if (!f.exists()) { + logger.info("Creating directory {}", f); + + boolean success = f.mkdir(); + // we've checked in initPath that path is writable, so there's no need to check if it succeeds + // in the unlikely case that in the meantime it isn't writable at least we log an error + if (!success) { + logger.error("Directory {} could not be created", f); + } + } + + File theFile = new File(f, recordName + ".cif.gz"); + return theFile.toString(); + } + + private static boolean fileIsAbsent(String recordName) { + String fileName = getLocalFileName(recordName); + File f = new File(fileName); + + // delete files that are too short to have contents + if (f.length() < LocalPDBDirectory.MIN_PDB_FILE_SIZE) { + // Delete defensively. + // Note that if delete is unsuccessful, we re-download the file anyways + f.delete(); + return true; + } + + return !f.exists(); + } + + /** + * @param recordName : three-letter name + * @return true if successful download + */ + private static boolean downloadChemCompRecord(String recordName) { + String localName = getLocalFileName(recordName); + File newFile; + try { + newFile = File.createTempFile("chemcomp" + recordName, "cif"); + logger.debug("Will write chem comp file to temp file {}", newFile.toString()); + } catch(IOException e) { + logger.error("Could not write to temp directory {} to create the chemical component download temp file", System.getProperty("java.io.tmpdir")); + return false; + } + String u; + if (useDefaultUrlLayout) { + u = serverBaseUrl + recordName + ".cif"; + } else { + u = serverBaseUrl + recordName.charAt(0) + "/" + recordName + "/" + recordName + ".cif"; + } + + logger.debug("downloading {}", u); + + URL url = null; + try { + url = new URL(u); + URLConnection uconn = URLConnectionTools.openURLConnection(url); + + try (PrintWriter pw = new PrintWriter(new GZIPOutputStream(new FileOutputStream(newFile))); + BufferedReader fileBuffer = new BufferedReader(new InputStreamReader(uconn.getInputStream()))) { + String line; + while ((line = fileBuffer.readLine()) != null) { + pw.println(line); + } + + pw.flush(); + } + // Now we move this across to where it actually wants to be + Files.move(newFile.toPath(), Paths.get(localName), StandardCopyOption.REPLACE_EXISTING); + + return true; + } catch (IOException e) { + logger.error("Could not download {} OR store locally to {} Error ={}", + url, + localName, + e.getMessage()); + newFile.delete(); + } + return false; + } + + private void downloadAllDefinitions() { + if (loading.get()) { + logger.info("Waiting for other thread to install chemical components..."); + } + + while (loading.get()) { + // another thread is already downloading the components definitions + // wait for the other thread to finish... + try { + // wait half a second + Thread.sleep(500); + } catch (InterruptedException e) { + //e.printStackTrace(); + logger.error("Thread interrupted "+e.getMessage()); + } + + logger.info("Another thread installed the chemical components."); + return; + } + + loading.set(true); + long timeS = System.currentTimeMillis(); + + logger.info("Performing first installation of chemical components."); + logger.info("Downloading components.cif.gz ..."); + + try { + AllChemCompProvider.downloadFile(); + } catch (IOException e) { + logger.error("Could not download the all chemical components file. Error: {}. " + + "Chemical components information won't be available", e.getMessage()); + // no point in trying to split if the file could not be downloaded + loading.set(false); + return; + } + try { + split(); + } catch (IOException e) { + logger.error("Could not split all chem comp file into individual chemical component files. Error: {}", + e.getMessage()); + // no point in reporting time + loading.set(false); + return; + } + long timeE = System.currentTimeMillis(); + logger.info("time to install chem comp dictionary: " + (timeE - timeS) / 1000 + " sec."); + loading.set(false); + } + + /** + * By default this provider will download only some of the {@link ChemComp} files. + * The user has to request that all files should be downloaded by setting this parameter to true. + * + * @return flag if the all components should be downloaded and installed at startup. (default: false) + */ + public boolean isDownloadAll() { + return downloadAll; + } + + /** By default this provider will download only some of the {@link ChemComp} files. + * The user has to request that all files should be downloaded by setting this parameter to true. + * + * @param downloadAll if the all components should be downloaded and installed at startup. (default: false) + */ + public void setDownloadAll(boolean downloadAll) { + this.downloadAll = downloadAll; + } +} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/MetalBondDistance.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/MetalBondDistance.java new file mode 100644 index 0000000000..1b64b73b35 --- /dev/null +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/MetalBondDistance.java @@ -0,0 +1,56 @@ +package org.biojava.nbio.structure.chem; + +/** + * A bean that contains cutoffs for correctly detecting metal bonds. + * Definitions are in file bond_distance_limits.cif.gz + * + * Created by andreas on 6/9/16. + */ +public class MetalBondDistance { + private String atomType1; + private String atomType2; + private float lowerLimit; + private float upperLimit; + + public String getAtomType1() { + return atomType1; + } + + public void setAtomType1(String atomType1) { + this.atomType1 = atomType1; + } + + public String getAtomType2() { + return atomType2; + } + + public void setAtomType2(String atomType2) { + this.atomType2 = atomType2; + } + + public float getLowerLimit() { + return lowerLimit; + } + + public void setLowerLimit(float lowerLimit) { + this.lowerLimit = lowerLimit; + } + + public float getUpperLimit() { + return upperLimit; + } + + public void setUpperLimit(float upperLimit) { + this.upperLimit = upperLimit; + } + + @Override + public String toString() { + return "MetalBindDistance{" + + "atomType1='" + atomType1 + '\'' + + ", atomType2='" + atomType2 + '\'' + + ", lowerLimit=" + lowerLimit + + ", upperLimit=" + upperLimit + + '}'; + } +} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ReducedChemCompProvider.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ReducedChemCompProvider.java new file mode 100644 index 0000000000..5321869139 --- /dev/null +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ReducedChemCompProvider.java @@ -0,0 +1,58 @@ +package org.biojava.nbio.structure.chem; + +import org.biojava.nbio.structure.io.cif.ChemCompConsumer; +import org.biojava.nbio.structure.io.cif.ChemCompConsumerImpl; +import org.biojava.nbio.structure.io.cif.ChemCompConverter; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.zip.GZIPInputStream; + +/** + * Unlike the {@link DownloadChemCompProvider}, this {@link ChemCompProvider} does not download any chem comp + * definitions. It has access to a limited set of files that are part of the biojava distribution. + * + * @author Andreas Prlic + * @since 3.0 + */ +public class ReducedChemCompProvider implements ChemCompProvider { + private static final Logger logger = LoggerFactory.getLogger(ReducedChemCompProvider.class); + + public ReducedChemCompProvider(){ + logger.debug("Initialising ReducedChemCompProvider"); + } + + @Override + public ChemComp getChemComp(String recordName) { + String name = recordName.toUpperCase().trim(); + try (InputStream inStream = this.getClass().getResourceAsStream("/chemcomp/" + name + ".cif.gz")) { + logger.debug("Reading chemcomp/{}.cif.gz", recordName); + + if (inStream == null) { + //System.out.println("Could not find chem comp: " + name + " ... using generic Chem Comp"); + // could not find the chem comp definition for this in the jar file + logger.debug("Getting empty chem comp for {}", name); + ChemComp cc = ChemComp.getEmptyChemComp(); + cc.setId(name); + return cc; + } + + // The Consumer builds up the BioJava - structure object. + // you could also hook in your own and build up you own data model. + ChemicalComponentDictionary dict = ChemCompConverter.fromInputStream(inStream); + + return dict.getChemComp(name); + } catch (IOException e) { + logger.error("IOException caught while reading chem comp {}.", name, e); + } + logger.warn("Problem when loading chem comp {}, will use an empty chem comp for it", name); + ChemComp cc = ChemComp.getEmptyChemComp(); + cc.setId(name); + return cc; + } +} + diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ZipChemCompProvider.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ZipChemCompProvider.java new file mode 100644 index 0000000000..34d7eea4db --- /dev/null +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ZipChemCompProvider.java @@ -0,0 +1,275 @@ +package org.biojava.nbio.structure.chem; + +import org.biojava.nbio.structure.io.cif.ChemCompConverter; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.nio.file.FileSystem; +import java.nio.file.FileSystems; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; +import java.util.HashSet; +import java.util.Set; +import java.util.zip.ZipEntry; +import java.util.zip.ZipOutputStream; + +/** + * This chemical component provider retrieves and caches chemical component definition files from a + * zip archive specified in its construction. If the archive does not contain the record, an attempt is + * made to download it using DownloadChemCompProvider. The downloaded file is then added to the archive. + * + * The class is thread-safe and the same ZipChemCompProvider should be used by all threads to prevent + * simultaneous read or write to the zip archive. A zip archive will be created if missing. + * + * @author edlunde + * @author larsonm + * @since 12/05/12 + * updated 3/5/2016 for Java 7 ZipFileSystem + */ +public class ZipChemCompProvider implements ChemCompProvider{ + private static final Logger s_logger = LoggerFactory.getLogger(ZipChemCompProvider.class); + + private final Path m_tempDir; // Base path where $m_zipRootDir/ will be downloaded to. + private final Path m_zipRootDir; + private final Path m_zipFile; + private final DownloadChemCompProvider m_dlProvider; + + private boolean m_removeCif; + + // Missing IDs from library that cannot be download added here to prevent delays. + private Set unavailable = new HashSet<>(); + + /** + * ZipChemCompProvider is a Chemical Component provider that stores chemical components + * in a zip archive. Missing chemical components are downloaded and appended to the + * archive. If non-existent a new zip archive will be created. + * + * @param chemicalComponentDictionaryFile : path to zip archive for chemical components. + * @param tempDir : path for temporary directory, (null) defaults to path in property "java.io.tmpdir". + * @throws IOException + */ + public ZipChemCompProvider(String chemicalComponentDictionaryFile, String tempDir) throws IOException { + this.m_zipFile = Paths.get(chemicalComponentDictionaryFile); + + // Use a default temporary directory if not passed a value. + if (tempDir == null || tempDir.equals("")) { + this.m_tempDir = Paths.get(System.getProperty("java.io.tmpdir")); + } else { + this.m_tempDir = Paths.get(tempDir); + } + + this.m_zipRootDir = Paths.get("chemcomp"); + + // Setup an instance of the download chemcomp provider. + this.m_dlProvider = new DownloadChemCompProvider(m_tempDir.toString()); + this.m_removeCif = true; + initializeZip(); + } + + // See comments in addToZipFileSystem for why initialization is required with + // ZipFileSystems - due to URI issues in Java7. + private void initializeZip() throws IOException { + s_logger.info("Using chemical component dictionary: {}", m_zipFile.toString()); + final File f = m_zipFile.toFile(); + if (!f.exists()) { + s_logger.info("Creating missing zip archive: {}", m_zipFile.toString()); + FileOutputStream fo = new FileOutputStream(f); + try (ZipOutputStream zip = new ZipOutputStream(new BufferedOutputStream(fo))) { + zip.putNextEntry(new ZipEntry("chemcomp/")); + zip.closeEntry(); + } + } + } + + /** + * Remove downloaded .cif.gz after adding to zip archive? + * Default is true. + * @param doRemove + */ + public void setRemoveCif(boolean doRemove) { + m_removeCif = doRemove; + } + + /** + * (non-Javadoc) + * @see ChemCompProvider#getChemComp(java.lang.String) + * + * @param recordName : three letter PDB name for a residue + * @return ChemComp from .zip or ChemComp from repository. Will return empty ChemComp when unable to find a residue and will return null if not provided a valid recordName. + */ + @Override + public ChemComp getChemComp(String recordName) { + if (null == recordName) return null; + + // handle non-existent ChemComp codes and do not repeatedly attempt to add these. + for (String str : unavailable) { + if (recordName.equals(str)) return getEmptyChemComp(recordName); + } + + // Try to pull from zip, if fail then download. + ChemComp cc = getFromZip(recordName); + if (cc == null) { + s_logger.info("File {} not found in archive. Attempting download from PDB.", recordName); + cc = downloadAndAdd(recordName); + } + + // If a null record or an empty chemcomp, return a default ChemComp and blacklist. + if (cc == null || (null == cc.getName() && cc.getAtoms().size() == 0)) { + s_logger.info("Unable to find or download {} - excluding from future searches.", recordName); + unavailable.add(recordName); + return getEmptyChemComp(recordName); + } + return cc; + } + + /** Use DownloadChemCompProvider to grab a gzipped cif record from the PDB. + * Zip all downloaded cif.gz files into the dictionary. + * + * @param recordName is the three-letter chemical component code (i.e. residue name). + * @return ChemComp matching recordName + */ + private ChemComp downloadAndAdd(String recordName){ + final ChemComp cc = m_dlProvider.getChemComp(recordName); + + // final File [] files = finder(m_tempDir.resolve("chemcomp").toString(), "cif.gz"); + final File [] files = new File[1]; + Path cif = m_tempDir.resolve("chemcomp").resolve(recordName + ".cif.gz"); + files[0] = cif.toFile(); + if (files[0] != null) { + addToZipFileSystem(m_zipFile, files, m_zipRootDir); + if (m_removeCif) for (File f : files) f.delete(); + } + return cc; + } + + /** + * Cleanup chemical component (.cif.gz) files downloaded to tmpdir. + * @param tempdir : path to temporary directory for chemical components + */ + public static void purgeTempFiles(String tempdir) { + if (tempdir == null) return; + + s_logger.info("Removing: "+tempdir); + Path dlPath = Paths.get(tempdir).resolve("chemcomp"); + File[] chemCompOutFiles = finder(dlPath.toString(), "cif.gz"); + if (null != chemCompOutFiles) for (File f : chemCompOutFiles) f.delete(); + dlPath.toFile().delete(); + } + + /** + * Return an empty ChemComp group for a three-letter resName. + * @param resName + * @return + */ + private ChemComp getEmptyChemComp(String resName){ + String pdbName = ""; // Empty string is default + if (null != resName && resName.length() >= 3) { + pdbName = resName.substring(0,3); + } + final ChemComp comp = new ChemComp(); + comp.setOneLetterCode("?"); + comp.setThreeLetterCode(pdbName); + comp.setPolymerType(PolymerType.unknown); + comp.setResidueType(ResidueType.atomn); + return comp; + } + + /** + * Return File(s) in dirName that match suffix. + * @param dirName + * @param suffix + * @return + */ + static private File[] finder(String dirName, final String suffix) { + if (null == dirName || null == suffix) { + return null; + } + + final File dir = new File(dirName); + return dir.listFiles((dir1, filename) -> filename.endsWith(suffix)); + } + + /** + * This is synchronized, along with addToFileSystem to prevent simulatenous reading/writing. + * @param recordName to find in zipfile. + * @return ChemComp if found or null if missing. + */ + private synchronized ChemComp getFromZip(String recordName) { + ChemComp cc = null; + if (!m_zipFile.toFile().exists()) return cc; + final String filename = "chemcomp/" + recordName + ".cif.gz"; + + // try with resources block to read from the filesystem. + try (FileSystem fs = FileSystems.newFileSystem(m_zipFile, null)) { + Path cif = fs.getPath(filename); + + if (Files.exists(cif)) { + s_logger.debug("reading {} from {}", recordName, m_zipFile); + final ChemicalComponentDictionary dict = ChemCompConverter.fromPath(cif); + cc = dict.getChemComp(recordName); + } + } catch (IOException e) { + s_logger.error("Unable to read from zip file : {}", e.getMessage()); + } + + return cc; + } + + /** + * Add an array of files to a zip archive. + * Synchronized to prevent simultaneous reading/writing. + * + * @param zipFile is a destination zip archive + * @param files is an array of files to be added + * @param pathWithinArchive is the path within the archive to add files to + * @return true if successfully appended these files. + */ + private synchronized boolean addToZipFileSystem(Path zipFile, File[] files, Path pathWithinArchive) { + boolean ret = false; + + /* URIs in Java 7 cannot have spaces, must use Path instead + * and so, cannot use the properties map to describe need to create + * a new zip archive. ZipChemCompProvider.initilizeZip to creates the + * missing zip file */ + + /* + // convert the filename to a URI + String uriString = "jar:file:" + zipFile.toUri().getPath(); + final URI uri = URI.create(uriString); + + // if filesystem doesn't exist, create one. + final Map env = new HashMap<>(); + // Create a new zip if one isn't present. + if (!zipFile.toFile().exists()) { + System.out.println("Need to create " + zipFile.toString()); + } + env.put("create", String.valueOf(!zipFile.toFile().exists())); + // Specify the encoding as UTF -8 + env.put("encoding", "UTF-8"); + */ + + // Copy in each file. + try (FileSystem zipfs = FileSystems.newFileSystem(zipFile, null)) { + Files.createDirectories(pathWithinArchive); + for (File f : files) { + if (!f.isDirectory() && f.exists()) { + Path externalFile = f.toPath(); + Path pathInZipFile = zipfs.getPath(pathWithinArchive.resolve(f.getName()).toString()); + Files.copy(externalFile, pathInZipFile, + StandardCopyOption.REPLACE_EXISTING); + } + } + ret = true; + } catch (IOException ex) { + s_logger.error("Unable to add entries to Chemical Component zip archive : {}", ex.getMessage()); + ret = false; + } + return ret; + } +} 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 b8e10ffbb8..de50722b34 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 @@ -750,40 +750,41 @@ public String toPDB() { public String toMMCIF() { StringBuilder sb = new StringBuilder(); - String molecId1 = getMoleculeIds().getFirst(); - String molecId2 = getMoleculeIds().getSecond(); - - if (isSymRelated()) { - // if both chains are named equally we want to still named them differently in the output mmcif file - // so that molecular viewers can handle properly the 2 chains as separate entities - molecId2 = molecId2 + "_" +getTransforms().getSecond().getTransformId(); - } - - sb.append(SimpleMMcifParser.MMCIF_TOP_HEADER).append("BioJava_interface_").append(getId()).append(System.getProperty("line.separator")); - - sb.append(FileConvert.getAtomSiteHeader()); - - // 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<>(); - for (Atom atom:this.molecules.getFirst()) { - if (isSymRelated()) { - atomSites.add(MMCIFFileTools.convertAtomToAtomSite(atom, 1, molecId1, molecId1, atomId)); - } else { - atomSites.add(MMCIFFileTools.convertAtomToAtomSite(atom, 1, molecId1, molecId1)); - } - atomId++; - } - for (Atom atom:this.molecules.getSecond()) { - if (isSymRelated()) { - atomSites.add(MMCIFFileTools.convertAtomToAtomSite(atom, 1, molecId2, molecId2, atomId)); - } else { - atomSites.add(MMCIFFileTools.convertAtomToAtomSite(atom, 1, molecId2, molecId2)); - } - atomId++; - } - - sb.append(MMCIFFileTools.toMMCIF(atomSites,AtomSite.class)); + // TODO impl +// String molecId1 = getMoleculeIds().getFirst(); +// String molecId2 = getMoleculeIds().getSecond(); +// +// if (isSymRelated()) { +// // if both chains are named equally we want to still named them differently in the output mmcif file +// // so that molecular viewers can handle properly the 2 chains as separate entities +// molecId2 = molecId2 + "_" +getTransforms().getSecond().getTransformId(); +// } +// +// sb.append(SimpleMMcifParser.MMCIF_TOP_HEADER).append("BioJava_interface_").append(getId()).append(System.getProperty("line.separator")); +// +// sb.append(FileConvert.getAtomSiteHeader()); +// +// // 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<>(); +// for (Atom atom:this.molecules.getFirst()) { +// if (isSymRelated()) { +// atomSites.add(MMCIFFileTools.convertAtomToAtomSite(atom, 1, molecId1, molecId1, atomId)); +// } else { +// atomSites.add(MMCIFFileTools.convertAtomToAtomSite(atom, 1, molecId1, molecId1)); +// } +// atomId++; +// } +// for (Atom atom:this.molecules.getSecond()) { +// if (isSymRelated()) { +// atomSites.add(MMCIFFileTools.convertAtomToAtomSite(atom, 1, molecId2, molecId2, atomId)); +// } else { +// atomSites.add(MMCIFFileTools.convertAtomToAtomSite(atom, 1, molecId2, molecId2)); +// } +// atomId++; +// } +// +// sb.append(MMCIFFileTools.toMMCIF(atomSites,AtomSite.class)); return sb.toString(); } diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/BcifFileReader.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/BcifFileReader.java index f0325b5b3e..a122158aee 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/BcifFileReader.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/BcifFileReader.java @@ -2,7 +2,7 @@ import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.align.util.UserConfiguration; -import org.biojava.nbio.structure.io.cif.CifFileConverter; +import org.biojava.nbio.structure.io.cif.StructureConverter; import java.io.IOException; import java.io.InputStream; @@ -38,7 +38,7 @@ public BcifFileReader(String path) { @Override public Structure getStructure(InputStream inStream) throws IOException { - return CifFileConverter.fromInputStream(inStream, getFileParsingParameters()); + return StructureConverter.fromInputStream(inStream, getFileParsingParameters()); } @Override diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/BondMaker.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/BondMaker.java index df077cde9b..7c4fe74144 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/BondMaker.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/BondMaker.java @@ -25,6 +25,7 @@ import org.biojava.nbio.structure.*; import org.biojava.nbio.structure.chem.ChemComp; import org.biojava.nbio.structure.chem.ChemCompBond; +import org.biojava.nbio.structure.chem.ChemCompGroupFactory; import org.biojava.nbio.structure.io.util.PDBTemporaryStorageUtils.LinkRecord; import org.rcsb.cif.model.ValueKind; import org.rcsb.cif.schema.mm.StructConn; diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/ChargeAdder.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/ChargeAdder.java index 311414f9da..607cf8e150 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/ChargeAdder.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/ChargeAdder.java @@ -30,7 +30,7 @@ import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.chem.ChemComp; import org.biojava.nbio.structure.chem.ChemCompAtom; -import org.biojava.nbio.structure.io.mmcif.ChemCompGroupFactory; +import org.biojava.nbio.structure.chem.ChemCompGroupFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -53,25 +53,7 @@ public static void addCharges(Structure structure) { List chemAtoms = thisChemComp.getAtoms(); for (ChemCompAtom chemCompAtom : chemAtoms) { Atom atom = g.getAtom(chemCompAtom.getAtomId()); - String stringCharge = chemCompAtom.getCharge(); - short shortCharge = 0; - if (stringCharge != null) { - if (!stringCharge.equals("?")) { - try { - shortCharge = Short.parseShort(stringCharge); - } catch(NumberFormatException e) { - logger.warn("Number format exception. Parsing '{}' to short", stringCharge); - } - } else { - logger.warn("? charge on atom {} in group {}", - chemCompAtom.getAtomId(), - thisChemComp.getId()); - } - } else { - logger.warn("Null charge on atom {} in group {}", - chemCompAtom.getAtomId(), - thisChemComp.getId()); - } + short shortCharge = (short) chemCompAtom.getCharge(); if (atom != null) { atom.setCharge(shortCharge); } diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/CifFileReader.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/CifFileReader.java index a5977931c2..edfe601b8d 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/CifFileReader.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/CifFileReader.java @@ -2,7 +2,7 @@ import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.align.util.UserConfiguration; -import org.biojava.nbio.structure.io.cif.CifFileConverter; +import org.biojava.nbio.structure.io.cif.StructureConverter; import java.io.IOException; import java.io.InputStream; @@ -40,7 +40,7 @@ public CifFileReader(String path) { @Override public Structure getStructure(InputStream inStream) throws IOException{ - return CifFileConverter.fromInputStream(inStream, getFileParsingParameters()); + return StructureConverter.fromInputStream(inStream, getFileParsingParameters()); } @Override 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 d6da021e63..8264fb2b3f 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 @@ -40,7 +40,7 @@ import org.biojava.nbio.structure.PDBHeader; import org.biojava.nbio.structure.Site; import org.biojava.nbio.structure.Structure; -import org.biojava.nbio.structure.io.cif.CifFileConverter; +import org.biojava.nbio.structure.io.cif.StructureConverter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -593,10 +593,10 @@ else if (name.length()==1) public String toMMCIF() { - return CifFileConverter.toText(this.structure); + return StructureConverter.toText(this.structure); } public static String toMMCIF(Chain chain) { - return CifFileConverter.toText(chain); + return StructureConverter.toText(chain); } } diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/PDBFileParser.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/PDBFileParser.java index 6200c90b1a..a1f16e27b6 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/PDBFileParser.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/PDBFileParser.java @@ -70,7 +70,7 @@ import org.biojava.nbio.structure.StructureImpl; import org.biojava.nbio.structure.StructureTools; import org.biojava.nbio.structure.chem.ChemCompAtom; -import org.biojava.nbio.structure.io.mmcif.ChemCompGroupFactory; +import org.biojava.nbio.structure.chem.ChemCompGroupFactory; import org.biojava.nbio.structure.io.util.PDBTemporaryStorageUtils.LinkRecord; import org.biojava.nbio.structure.secstruc.SecStrucInfo; import org.biojava.nbio.structure.secstruc.SecStrucType; @@ -301,7 +301,7 @@ public PDBFileParser() { /** initiate new resNum, either Hetatom, Nucleotide, or AminoAcid */ private Group getNewGroup(String recordName,Character aminoCode1, String aminoCode3) { - Group g = ChemCompGroupFactory.getGroupFromChemCompDictionary(aminoCode3); + Group g = ChemCompGroupFactory.getGroupFromChemCompDictionary(aminoCode3); if ( g != null && !g.getChemComp().isEmpty()) return g; diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/ChemCompConsumer.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/ChemCompConsumer.java new file mode 100644 index 0000000000..5bbb3f7a6a --- /dev/null +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/ChemCompConsumer.java @@ -0,0 +1,16 @@ +package org.biojava.nbio.structure.io.cif; + +import org.biojava.nbio.structure.chem.ChemCompDescriptor; +import org.biojava.nbio.structure.chem.ChemicalComponentDictionary; +import org.rcsb.cif.schema.mm.ChemComp; +import org.rcsb.cif.schema.mm.ChemCompAtom; +import org.rcsb.cif.schema.mm.ChemCompBond; + +public interface ChemCompConsumer extends CifFileConsumer { + void consumeChemComp(ChemComp c); + + void consumeChemCompAtom(ChemCompAtom atom); + + void consumeChemCompBond(ChemCompBond bond); +} + diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/ChemCompConsumerImpl.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/ChemCompConsumerImpl.java new file mode 100644 index 0000000000..ffe61f2d0b --- /dev/null +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/ChemCompConsumerImpl.java @@ -0,0 +1,108 @@ +package org.biojava.nbio.structure.io.cif; + +import org.biojava.nbio.structure.chem.ChemicalComponentDictionary; +import org.rcsb.cif.schema.mm.ChemComp; +import org.rcsb.cif.schema.mm.ChemCompAtom; +import org.rcsb.cif.schema.mm.ChemCompBond; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class ChemCompConsumerImpl implements ChemCompConsumer { + private static final Logger logger = LoggerFactory.getLogger(ChemCompConsumerImpl.class); + private final ChemicalComponentDictionary dictionary; + private String latestChemCompId; + + public ChemCompConsumerImpl() { + this.dictionary = new ChemicalComponentDictionary(); + } + + @Override + public void consumeChemComp(ChemComp c) { + org.biojava.nbio.structure.chem.ChemComp chemComp = new org.biojava.nbio.structure.chem.ChemComp(); + chemComp.setId(c.getId().get(0)); + chemComp.setName(c.getName().get(0)); + chemComp.setType(c.getType().get(0)); + chemComp.setPdbxType(c.getPdbxType().get(0)); + chemComp.setFormula(c.getFormula().get(0)); + chemComp.setMonNstdParentCompId(c.getMonNstdParentCompId().get(0)); + chemComp.setPdbxSynonyms(c.getPdbxSynonyms().get(0)); + chemComp.setPdbxFormalCharge(c.getPdbxFormalCharge().get(0)); + chemComp.setPdbxInitialDate(c.getPdbxInitialDate().get(0)); + chemComp.setPdbxModifiedDate(c.getPdbxModifiedDate().get(0)); + chemComp.setPdbxAmbiguousFlag(c.getPdbxAmbiguousFlag().get(0)); + chemComp.setPdbxReleaseStatus(c.getPdbxReleaseStatus().get(0)); + chemComp.setPdbxReplacedBy(c.getPdbxReplacedBy().get(0)); + chemComp.setPdbxReplaces(c.getPdbxReplaces().get(0)); + chemComp.setFormulaWeight(c.getFormulaWeight().get(0)); + chemComp.setOneLetterCode(c.getOneLetterCode().get(0)); + chemComp.setThreeLetterCode(c.getThreeLetterCode().get(0)); + chemComp.setPdbxModelCoordinatesDetails(c.getPdbxModelCoordinatesDetails().get(0)); + chemComp.setPdbxModelCoordinatesMissingFlag(c.getPdbxModelCoordinatesMissingFlag().get(0)); + chemComp.setPdbxIdealCoordinatesDetails(c.getPdbxIdealCoordinatesDetails().get(0)); + chemComp.setPdbxIdealCoordinatesMissingFlag(c.getPdbxIdealCoordinatesMissingFlag().get(0)); + chemComp.setPdbxModelCoordinatesDbCode(c.getPdbxModelCoordinatesDbCode().get(0)); + chemComp.setPdbxSubcomponentList(c.getPdbxSubcomponentList().get(0)); + chemComp.setPdbxProcessingSite(c.getPdbxProcessingSite().get(0)); + if (chemComp.getId() == null) { + logger.warn("chem comp ID == null {}", c); + } + latestChemCompId = chemComp.getId(); + dictionary.addChemComp(chemComp); + } + + @Override + public void consumeChemCompAtom(ChemCompAtom atom) { + for (int i = 0; i < atom.getRowCount(); i++) { + org.biojava.nbio.structure.chem.ChemCompAtom a = new org.biojava.nbio.structure.chem.ChemCompAtom(); + a.setCompId(atom.getCompId().get(i)); + a.setAtomId(atom.getAtomId().get(i)); + a.setAltAtomId(atom.getAltAtomId().get(i)); + a.setTypeSymbol(atom.getTypeSymbol().get(i)); + a.setCharge(atom.getCharge().get(i)); + a.setPdbxAlign(atom.getPdbxAlign().get(i)); + a.setPdbxAromaticFlag(atom.getPdbxAromaticFlag().get(i)); + a.setPdbxLeavingAtomFlag(atom.getPdbxLeavingAtomFlag().get(i)); + a.setPdbxStereoConfig(atom.getPdbxStereoConfig().get(i)); + a.setModelCartnX(atom.getModelCartnX().get(i)); + a.setModelCartnY(atom.getModelCartnY().get(i)); + a.setModelCartnZ(atom.getModelCartnZ().get(i)); + a.setPdbxModelCartnXIdeal(atom.getPdbxModelCartnXIdeal().get(i)); + a.setPdbxModelCartnYIdeal(atom.getPdbxModelCartnYIdeal().get(i)); + a.setPdbxModelCartnZIdeal(atom.getPdbxModelCartnZIdeal().get(i)); + a.setPdbxComponentAtomId(atom.getPdbxComponentAtomId().get(i)); + a.setPdbxComponentCompId(atom.getPdbxComponentCompId().get(i)); + a.setPdbxOrdinal(atom.getPdbxOrdinal().get(i)); + dictionary.getChemComp(latestChemCompId).getAtoms().add(a); + } + } + + @Override + public void consumeChemCompBond(ChemCompBond bond) { + for (int i = 0; i < bond.getRowCount(); i++) { + org.biojava.nbio.structure.chem.ChemCompBond b = new org.biojava.nbio.structure.chem.ChemCompBond(); + b.setAtomId1(bond.getAtomId1().get(i)); + b.setAtomId2(bond.getAtomId2().get(i)); + b.setCompId(bond.getCompId().get(i)); + b.setPdbxAromaticFlag(bond.getPdbxAromaticFlag().get(i)); + b.setPdbxOrdinal(bond.getPdbxOrdinal().get(i)); + b.setPdbxStereoConfig(bond.getPdbxStereoConfig().get(i)); + b.setValueOrder(bond.getValueOrder().get(i)); + dictionary.getChemComp(latestChemCompId).getBonds().add(b); + } + } + + @Override + public void prepare() { + + } + + @Override + public void finish() { + + } + + @Override + public ChemicalComponentDictionary getContainer() { + return dictionary; + } +} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/ChemCompConverter.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/ChemCompConverter.java new file mode 100644 index 0000000000..d234d27dc4 --- /dev/null +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/ChemCompConverter.java @@ -0,0 +1,79 @@ +package org.biojava.nbio.structure.io.cif; + +import org.biojava.nbio.structure.Structure; +import org.biojava.nbio.structure.chem.ChemicalComponentDictionary; +import org.biojava.nbio.structure.io.FileParsingParameters; +import org.rcsb.cif.CifIO; +import org.rcsb.cif.model.CifFile; +import org.rcsb.cif.schema.StandardSchemata; +import org.rcsb.cif.schema.mm.MmCifBlock; +import org.rcsb.cif.schema.mm.MmCifFile; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.nio.file.Files; +import java.nio.file.Path; + +/** + * Convert CifFiles to chem comps. + * @author Sebastian Bittrich + * @since 6.0.0 + */ +public class ChemCompConverter { + /** + * Read data from a file and convert to chem comp dictionary. + * @param path the source of information - can be gzipped or binary or text data + * @return the target + */ + public static ChemicalComponentDictionary fromPath(Path path) throws IOException { + return fromInputStream(Files.newInputStream(path)); + } + + /** + * Get data from a URL and convert to chem comp dictionary. + * @param url the source of information - can be gzipped or binary or text data + * @return the target + * @throws IOException thrown when reading fails + */ + public static ChemicalComponentDictionary fromURL(URL url) throws IOException { + return fromInputStream(url.openStream()); + } + + /** + * Convert InputStream to chem comp dictionary. + * @param inputStream the InputStream of information - can be gzipped or binary or text data + * @return the target + * @throws IOException thrown when reading fails + * @see StructureConverter#fromInputStream(InputStream, FileParsingParameters) + */ + public static ChemicalComponentDictionary fromInputStream(InputStream inputStream) throws IOException { + return fromCifFile(CifIO.readFromInputStream(inputStream)); + } + + /** + * Convert CifFile to chem comp dictionary. + * @param cifFile the source + * @return the target + */ + public static ChemicalComponentDictionary fromCifFile(CifFile cifFile) { + // initialize consumer + ChemCompConsumer consumer = new ChemCompConsumerImpl(); + + // init structure + consumer.prepare(); + + // feed individual categories to consumer + MmCifFile mmCifFile = cifFile.as(StandardSchemata.MMCIF); + for (MmCifBlock cifBlock : mmCifFile.getBlocks()) { + consumer.consumeChemComp(cifBlock.getChemComp()); + consumer.consumeChemCompAtom(cifBlock.getChemCompAtom()); + consumer.consumeChemCompBond(cifBlock.getChemCompBond()); + } + + // prepare structure to be retrieved + consumer.finish(); + + return consumer.getContainer(); + } +} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/MetalBondConsumer.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/MetalBondConsumer.java new file mode 100644 index 0000000000..d76d91d1e7 --- /dev/null +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/MetalBondConsumer.java @@ -0,0 +1,11 @@ +package org.biojava.nbio.structure.io.cif; + +import org.biojava.nbio.structure.chem.MetalBondDistance; +import org.rcsb.cif.model.Category; + +import java.util.List; +import java.util.Map; + +public interface MetalBondConsumer extends CifFileConsumer>> { + void consume(Category category); +} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/MetalBondConsumerImpl.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/MetalBondConsumerImpl.java new file mode 100644 index 0000000000..28833bc559 --- /dev/null +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/MetalBondConsumerImpl.java @@ -0,0 +1,55 @@ +package org.biojava.nbio.structure.io.cif; + +import org.biojava.nbio.structure.chem.MetalBondDistance; +import org.rcsb.cif.model.Category; +import org.rcsb.cif.model.FloatColumn; +import org.rcsb.cif.model.StrColumn; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * Created by andreas on 6/9/16. + */ +public class MetalBondConsumerImpl implements MetalBondConsumer { + private final Map> definitions = new HashMap<>(); + + @Override + public void prepare() { + definitions.clear(); + } + + @Override + public void finish() { + // minimize memory consumption + for (List d : definitions.values()){ + ((ArrayList) d).trimToSize(); + } + } + + @Override + public void consume(Category category) { + StrColumn atomType1 = (StrColumn) category.getColumn(""); + StrColumn atomType2 = (StrColumn) category.getColumn(""); + FloatColumn lowerLimit = (FloatColumn) category.getColumn(""); + FloatColumn upperLimit = (FloatColumn) category.getColumn(""); + for (int i = 0; i < category.getRowCount(); i++) { + MetalBondDistance d = new MetalBondDistance(); + + d.setAtomType1(atomType1.get(i)); + d.setAtomType2(atomType2.get(i)); + d.setLowerLimit((float) lowerLimit.get(i)); + d.setUpperLimit((float) upperLimit.get(i)); + + List defs = definitions.computeIfAbsent(d.getAtomType1(), k -> new ArrayList<>()); + defs.add(d); + } + } + + @Override + public Map> getContainer(){ + return definitions; + } +} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/MetalBondConverter.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/MetalBondConverter.java new file mode 100644 index 0000000000..0f28fe6493 --- /dev/null +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/MetalBondConverter.java @@ -0,0 +1,60 @@ +package org.biojava.nbio.structure.io.cif; + +import org.biojava.nbio.structure.chem.MetalBondDistance; +import org.rcsb.cif.CifIO; +import org.rcsb.cif.model.Block; +import org.rcsb.cif.model.CifFile; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.InputStream; +import java.util.List; +import java.util.Map; + +/** + * Created by andreas on 6/6/16. + */ +public class MetalBondConverter { + private static final Logger logger = LoggerFactory.getLogger(MetalBondConverter.class); + private static final String BONDS_FILE = "org/biojava/nbio/structure/bond_distance_limits.cif.gz"; + private static Map> definitions; + + static { + definitions = init(); + } + + public static Map> getMetalBondDefinitions() { + return definitions; + } + + private static Map> init() { + InputStream inputStream = MetalBondConverter.class.getClassLoader().getResourceAsStream(BONDS_FILE); + + if (inputStream == null) { + throw new RuntimeException("Could not find resource " + BONDS_FILE + ". This probably means that your " + + "biojava.jar file is corrupt or incorrectly built."); + } + + try { + CifFile cifFile = CifIO.readFromInputStream(inputStream); + // initialize consumer + MetalBondConsumerImpl consumer = new MetalBondConsumerImpl(); + + // init structure + consumer.prepare(); + + // feed individual categories to consumer + for (Block cifBlock : cifFile.getBlocks()) { + cifBlock.categories().forEach(consumer::consume); + } + + // prepare structure to be retrieved + consumer.finish(); + + return consumer.getContainer(); + } catch (Exception e) { + logger.error(e.getMessage(), e); + } + return null; + } +} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/StructureConsumerImpl.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/StructureConsumerImpl.java index 6a952029ee..d858536847 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/StructureConsumerImpl.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/StructureConsumerImpl.java @@ -24,6 +24,7 @@ import org.biojava.nbio.structure.StructureException; import org.biojava.nbio.structure.StructureImpl; import org.biojava.nbio.structure.StructureTools; +import org.biojava.nbio.structure.chem.ChemCompGroupFactory; import org.biojava.nbio.structure.io.BondMaker; import org.biojava.nbio.structure.io.ChargeAdder; import org.biojava.nbio.structure.io.EntityFinder; diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/CifFileConverter.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/StructureConverter.java similarity index 97% rename from biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/CifFileConverter.java rename to biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/StructureConverter.java index 2a53746297..45a5b97c76 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/CifFileConverter.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/StructureConverter.java @@ -18,9 +18,9 @@ /** * Convert BioJava structures to CifFiles and vice versa. * @author Sebastian Bittrich - * @since 5.3.0 + * @since 6.0.0 */ -public class CifFileConverter { +public class StructureConverter { /** * Read data from a file and convert to Structure without any FileParsingParameters. * @param path the source of information - can be gzipped or binary or text data @@ -66,7 +66,7 @@ private static Structure fromURL(URL url, FileParsingParameters parameters) thro * @param inputStream the InputStream of information - can be gzipped or binary or text data * @return the target * @throws IOException thrown when reading fails - * @see CifFileConverter#fromInputStream(InputStream, FileParsingParameters) + * @see StructureConverter#fromInputStream(InputStream, FileParsingParameters) */ public static Structure fromInputStream(InputStream inputStream) throws IOException { return fromInputStream(inputStream, new FileParsingParameters()); @@ -87,7 +87,7 @@ public static Structure fromInputStream(InputStream inputStream, FileParsingPara * Convert CifFile to Structure without any FileParsingParameters. * @param cifFile the source * @return the target - * @see CifFileConverter#fromCifFile(CifFile, FileParsingParameters) + * @see StructureConverter#fromCifFile(CifFile, FileParsingParameters) */ public static Structure fromCifFile(CifFile cifFile) { return fromCifFile(cifFile, new FileParsingParameters()); diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmtf/MmtfUtils.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmtf/MmtfUtils.java index 0a6cd9739c..0f1394424a 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmtf/MmtfUtils.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmtf/MmtfUtils.java @@ -48,10 +48,10 @@ import org.biojava.nbio.structure.StructureIO; import org.biojava.nbio.structure.align.util.AtomCache; import org.biojava.nbio.structure.chem.ChemComp; +import org.biojava.nbio.structure.chem.ChemCompGroupFactory; import org.biojava.nbio.structure.chem.ChemCompTools; +import org.biojava.nbio.structure.chem.DownloadChemCompProvider; import org.biojava.nbio.structure.io.FileParsingParameters; -import org.biojava.nbio.structure.io.mmcif.ChemCompGroupFactory; -import org.biojava.nbio.structure.io.mmcif.DownloadChemCompProvider; import org.biojava.nbio.structure.quaternary.BioAssemblyInfo; import org.biojava.nbio.structure.quaternary.BiologicalAssemblyTransformation; import org.biojava.nbio.structure.secstruc.DSSPParser; diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/ChemCompTest.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/ChemCompTest.java index fd37644fd4..c937ad0978 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/ChemCompTest.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/ChemCompTest.java @@ -20,13 +20,13 @@ */ package org.biojava.nbio.structure; -import org.biojava.nbio.structure.io.mmcif.ChemCompGroupFactory; -import org.biojava.nbio.structure.io.mmcif.ChemCompProvider; -import org.biojava.nbio.structure.io.mmcif.DownloadChemCompProvider; -import org.biojava.nbio.structure.io.mmcif.ReducedChemCompProvider; -import org.biojava.nbio.structure.io.mmcif.chem.PolymerType; -import org.biojava.nbio.structure.io.mmcif.chem.ResidueType; -import org.biojava.nbio.structure.io.mmcif.model.ChemComp; +import org.biojava.nbio.structure.chem.ChemComp; +import org.biojava.nbio.structure.chem.ChemCompGroupFactory; +import org.biojava.nbio.structure.chem.ChemCompProvider; +import org.biojava.nbio.structure.chem.DownloadChemCompProvider; +import org.biojava.nbio.structure.chem.PolymerType; +import org.biojava.nbio.structure.chem.ReducedChemCompProvider; +import org.biojava.nbio.structure.chem.ResidueType; import org.junit.Test; import static org.junit.Assert.*; @@ -69,9 +69,9 @@ public void testMEA(){ assertTrue(" is not mea" , cc.getId().equals(chemID)); - assertEquals(" one letter code is not correct", "F", cc.getOne_letter_code()); + assertEquals(" one letter code is not correct", "F", cc.getOneLetterCode()); - assertEquals("MEA",cc.getThree_letter_code()); + assertEquals("MEA",cc.getThreeLetterCode()); assertNotNull(cc.getPolymerType()); @@ -141,7 +141,7 @@ public void testChangingProviders(){ assertTrue(" is not mea" , cc.getId().equals(chemID)); - assertEquals("MEA",cc.getThree_letter_code()); + assertEquals("MEA",cc.getThreeLetterCode()); @@ -157,7 +157,7 @@ public void testChangingProviders(){ assertTrue(" is not mea" , cc.getId().equals(chemID)); - assertEquals("MEA",cc.getThree_letter_code()); + assertEquals("MEA",cc.getThreeLetterCode()); // now we change to reduced chem comp provider ChemCompGroupFactory.setChemCompProvider(new ReducedChemCompProvider()); @@ -169,7 +169,7 @@ public void testChangingProviders(){ assertTrue(" is not mea" , cc.getId().equals(chemID)); //the cached description contains all information even with the ReducedProvider - assertNotNull(cc.getThree_letter_code()); + assertNotNull(cc.getThreeLetterCode()); } diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/PdbFileFormat30Test.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/PdbFileFormat30Test.java index 9daf7d7e18..f6968c7af5 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/PdbFileFormat30Test.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/PdbFileFormat30Test.java @@ -23,10 +23,10 @@ package org.biojava.nbio.structure; +import org.biojava.nbio.structure.chem.ChemCompGroupFactory; +import org.biojava.nbio.structure.chem.ReducedChemCompProvider; import org.biojava.nbio.structure.io.FileParsingParameters; import org.biojava.nbio.structure.io.PDBFileParser; -import org.biojava.nbio.structure.io.mmcif.ChemCompGroupFactory; -import org.biojava.nbio.structure.io.mmcif.ReducedChemCompProvider; import java.io.IOException; import java.io.InputStream; diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/Test4hhb.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/Test4hhb.java index afb5de1d59..bcf289cebc 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/Test4hhb.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/Test4hhb.java @@ -26,9 +26,7 @@ import org.biojava.nbio.structure.io.FileParsingParameters; import org.biojava.nbio.structure.io.PDBFileParser; -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.cif.StructureConverter; import org.junit.Test; import java.io.IOException; @@ -75,15 +73,9 @@ public void test4hhbPDBFile() throws IOException inStream = new GZIPInputStream(this.getClass().getResourceAsStream("/4hhb.cif.gz")); assertNotNull(inStream); - MMcifParser mmcifpars = new SimpleMMcifParser(); - SimpleMMcifConsumer consumer = new SimpleMMcifConsumer(); params = new FileParsingParameters(); params.setAlignSeqRes(true); - consumer.setFileParsingParameters(params); - mmcifpars.addMMcifConsumer(consumer); - - mmcifpars.parse(inStream) ; - structure2 = consumer.getStructure(); + structure2 = StructureConverter.fromInputStream(inStream, params); assertNotNull(structure2); diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/TestAltLocs.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/TestAltLocs.java index d1c6779e7c..3aa86bacd0 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/TestAltLocs.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/TestAltLocs.java @@ -21,19 +21,17 @@ package org.biojava.nbio.structure; import org.biojava.nbio.structure.align.util.AtomCache; +import org.biojava.nbio.structure.chem.ChemComp; +import org.biojava.nbio.structure.chem.ChemCompBond; +import org.biojava.nbio.structure.chem.ChemCompGroupFactory; +import org.biojava.nbio.structure.chem.PolymerType; +import org.biojava.nbio.structure.chem.ResidueType; import org.biojava.nbio.structure.io.FileParsingParameters; -import org.biojava.nbio.structure.io.mmcif.ChemCompGroupFactory; -import org.biojava.nbio.structure.io.mmcif.MMCIFFileTools; -import org.biojava.nbio.structure.io.mmcif.SimpleMMcifConsumer; -import org.biojava.nbio.structure.io.mmcif.SimpleMMcifParser; -import org.biojava.nbio.structure.io.mmcif.chem.PolymerType; -import org.biojava.nbio.structure.io.mmcif.chem.ResidueType; -import org.biojava.nbio.structure.io.mmcif.model.AtomSite; -import org.biojava.nbio.structure.io.mmcif.model.ChemComp; -import org.biojava.nbio.structure.io.mmcif.model.ChemCompBond; +import org.biojava.nbio.structure.io.cif.StructureConverter; import org.junit.Test; import java.io.BufferedReader; +import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.StringReader; import java.util.ArrayList; @@ -397,10 +395,10 @@ public void testAddBondsDoesntChangeGroups() throws IOException, StructureExcept for (ChemCompBond chemCompBond : aminoChemComp.getBonds()) { // - if(chemCompBond.getAtom_id_1().equals(atomA.getName())){ + if(chemCompBond.getAtomId1().equals(atomA.getName())){ // Get the other atom in the group for(Atom atomB : atomsList) { - if(chemCompBond.getAtom_id_2().equals(atomB.getName())){ + if(chemCompBond.getAtomId2().equals(atomB.getName())){ int bondOrder = chemCompBond.getNumericalBondOrder(); new BondImpl(atomA, atomB, bondOrder); } @@ -641,15 +639,7 @@ public void testMmcifConversionPartialAltlocs() throws IOException { "ATOM 117 N NH2 A ARG A 1 13 ? 7.812 17.972 17.172 0.50 24.80 ? 102 ARG A NH2 1\n" + "ATOM 118 N NH2 B ARG A 1 13 ? 8.013 18.115 17.888 0.50 26.52 ? 102 ARG A NH2 1\n"; - SimpleMMcifParser parser = new SimpleMMcifParser(); - SimpleMMcifConsumer consumer = new SimpleMMcifConsumer(); - parser.addMMcifConsumer(consumer); - - BufferedReader buf = new BufferedReader(new StringReader(mmcifData)); - parser.parse(buf); - buf.close(); - - Structure s = consumer.getStructure(); + Structure s = StructureConverter.fromInputStream(new ByteArrayInputStream(mmcifData.getBytes())); Chain c = s.getPolyChains().get(0); assertEquals(1, c.getAtomGroups().size()); Group g = c.getAtomGroup(0); @@ -681,8 +671,9 @@ public void testMmcifConversionPartialAltlocs() throws IOException { assertEquals('B', a.getAltLoc().charValue()); } - List atomSites = MMCIFFileTools.convertChainToAtomSites(c, 1, "A", "A"); - assertEquals(17, atomSites.size()); + // TODO reimpl +// List atomSites = MMCIFFileTools.convertChainToAtomSites(c, 1, "A", "A"); +// assertEquals(17, atomSites.size()); } @@ -727,15 +718,7 @@ public void testMmcifConversionAllAltlocs() throws IOException { "ATOM 216 C CD A PRO A 1 23 ? 14.980 32.886 23.580 0.50 6.98 ? 112 PRO A CD 1 \n" + "ATOM 217 C CD B PRO A 1 23 ? 14.558 33.235 23.153 0.50 14.91 ? 112 PRO A CD 1 \n"; - SimpleMMcifParser parser = new SimpleMMcifParser(); - SimpleMMcifConsumer consumer = new SimpleMMcifConsumer(); - parser.addMMcifConsumer(consumer); - - BufferedReader buf = new BufferedReader(new StringReader(mmcifData)); - parser.parse(buf); - buf.close(); - - Structure s = consumer.getStructure(); + Structure s = StructureConverter.fromInputStream(new ByteArrayInputStream(mmcifData.getBytes())); Chain c = s.getPolyChains().get(0); assertEquals(1, c.getAtomGroups().size()); @@ -751,8 +734,9 @@ public void testMmcifConversionAllAltlocs() throws IOException { assertEquals('B', a.getAltLoc().charValue()); } - List atomSites = MMCIFFileTools.convertChainToAtomSites(c, 1, "A", "A"); - assertEquals(14, atomSites.size()); + // TODO reimpl +// List atomSites = MMCIFFileTools.convertChainToAtomSites(c, 1, "A", "A"); +// assertEquals(14, atomSites.size()); } @@ -816,19 +800,10 @@ public void testIntraResidueBondsBetweenAltlocs() throws IOException { "ATOM 1431 H HE2 B MET A 1 86 ? 7.346 -16.554 -2.998 0.53 23.03 ? 104 MET A HE2 1 \n" + "ATOM 1432 H HE3 B MET A 1 86 ? 6.996 -15.566 -4.437 0.53 23.03 ? 104 MET A HE3 1 "; - SimpleMMcifParser parser = new SimpleMMcifParser(); - SimpleMMcifConsumer consumer = new SimpleMMcifConsumer(); - parser.addMMcifConsumer(consumer); - FileParsingParameters params = new FileParsingParameters(); params.setCreateAtomBonds(true); - consumer.setFileParsingParameters(params); - - BufferedReader buf = new BufferedReader(new StringReader(mmcifData)); - parser.parse(buf); - buf.close(); - Structure s = consumer.getStructure(); + Structure s = StructureConverter.fromInputStream(new ByteArrayInputStream(mmcifData.getBytes()), params); Chain c = s.getPolyChains().get(0); assertEquals(1, c.getAtomGroups().size()); @@ -971,19 +946,10 @@ public void testInterResidueBondsBetweenAltlocs() throws IOException { "ATOM 1431 H HE2 B MET A 1 2 ? 7.346 -16.554 -2.998 0.53 23.03 ? 104 MET A HE2 1 \n" + "ATOM 1432 H HE3 B MET A 1 2 ? 6.996 -15.566 -4.437 0.53 23.03 ? 104 MET A HE3 1 "; - SimpleMMcifParser parser = new SimpleMMcifParser(); - SimpleMMcifConsumer consumer = new SimpleMMcifConsumer(); - parser.addMMcifConsumer(consumer); - FileParsingParameters params = new FileParsingParameters(); params.setCreateAtomBonds(true); - consumer.setFileParsingParameters(params); - - BufferedReader buf = new BufferedReader(new StringReader(mmcifData)); - parser.parse(buf); - buf.close(); - Structure s = consumer.getStructure(); + Structure s = StructureConverter.fromInputStream(new ByteArrayInputStream(mmcifData.getBytes()), params); Chain c = s.getPolyChains().get(0); assertEquals(2, c.getAtomGroups().size()); diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/TestAtomCache.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/TestAtomCache.java index 87fc80a314..d3c61130ae 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/TestAtomCache.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/TestAtomCache.java @@ -25,6 +25,7 @@ package org.biojava.nbio.structure; import org.biojava.nbio.structure.align.util.AtomCache; +import org.biojava.nbio.structure.io.CifFileReader; import org.biojava.nbio.structure.io.LocalPDBDirectory; import org.biojava.nbio.structure.io.LocalPDBDirectory.FetchBehavior; import org.biojava.nbio.structure.io.LocalPDBDirectory.ObsoleteBehavior; @@ -54,7 +55,7 @@ public void setUp() throws IOException { }; List readers = new ArrayList(); - readers.add(new MMCIFFileReader(cache.getPath()) ); + readers.add(new CifFileReader(cache.getPath()) ); readers.add(new PDBFileReader(cache.getPath()) ); for(LocalPDBDirectory reader : readers) { reader.setFetchBehavior(cache.getFetchBehavior()); diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/TestBond.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/TestBond.java index d1b7b24122..9a3022d0a1 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/TestBond.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/TestBond.java @@ -25,9 +25,9 @@ import java.util.List; import org.biojava.nbio.structure.align.util.AtomCache; +import org.biojava.nbio.structure.chem.ChemCompGroupFactory; +import org.biojava.nbio.structure.chem.DownloadChemCompProvider; import org.biojava.nbio.structure.io.FileParsingParameters; -import org.biojava.nbio.structure.io.mmcif.ChemCompGroupFactory; -import org.biojava.nbio.structure.io.mmcif.DownloadChemCompProvider; import org.junit.BeforeClass; import org.junit.Test; import org.slf4j.Logger; diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/TestDownloadChemCompProvider.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/TestDownloadChemCompProvider.java index bc2a8dcd41..3c1b1626db 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/TestDownloadChemCompProvider.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/TestDownloadChemCompProvider.java @@ -21,9 +21,9 @@ package org.biojava.nbio.structure; import org.biojava.nbio.core.util.FlatFileCache; +import org.biojava.nbio.structure.chem.ChemComp; +import org.biojava.nbio.structure.chem.DownloadChemCompProvider; import org.biojava.nbio.structure.io.LocalPDBDirectory; -import org.biojava.nbio.structure.io.mmcif.DownloadChemCompProvider; -import org.biojava.nbio.structure.io.mmcif.model.ChemComp; import org.junit.Test; import static org.junit.Assert.*; diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/TestNucleotides.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/TestNucleotides.java index dc865eb366..1eb7f88cfa 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/TestNucleotides.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/TestNucleotides.java @@ -25,12 +25,12 @@ package org.biojava.nbio.structure; import org.biojava.nbio.structure.align.util.AtomCache; +import org.biojava.nbio.structure.chem.ChemCompGroupFactory; +import org.biojava.nbio.structure.chem.ChemCompProvider; +import org.biojava.nbio.structure.chem.DownloadChemCompProvider; +import org.biojava.nbio.structure.chem.PolymerType; import org.biojava.nbio.structure.io.FileParsingParameters; import org.biojava.nbio.structure.io.PDBFileReader; -import org.biojava.nbio.structure.io.mmcif.ChemCompGroupFactory; -import org.biojava.nbio.structure.io.mmcif.ChemCompProvider; -import org.biojava.nbio.structure.io.mmcif.DownloadChemCompProvider; -import org.biojava.nbio.structure.io.mmcif.chem.PolymerType; import org.junit.BeforeClass; import org.junit.Test; diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/align/util/AtomCacheTest.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/align/util/AtomCacheTest.java index 6ba61088b4..0882ae08a1 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/align/util/AtomCacheTest.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/align/util/AtomCacheTest.java @@ -51,12 +51,13 @@ import org.biojava.nbio.structure.StructureIdentifier; import org.biojava.nbio.structure.StructureTools; import org.biojava.nbio.structure.SubstructureIdentifier; +import org.biojava.nbio.structure.chem.ChemComp; +import org.biojava.nbio.structure.chem.ChemCompGroupFactory; +import org.biojava.nbio.structure.chem.DownloadChemCompProvider; +import org.biojava.nbio.structure.io.CifFileReader; import org.biojava.nbio.structure.io.LocalPDBDirectory; import org.biojava.nbio.structure.io.LocalPDBDirectory.FetchBehavior; import org.biojava.nbio.structure.io.LocalPDBDirectory.ObsoleteBehavior; -import org.biojava.nbio.structure.io.mmcif.ChemCompGroupFactory; -import org.biojava.nbio.structure.io.mmcif.DownloadChemCompProvider; -import org.biojava.nbio.structure.io.mmcif.model.ChemComp; import org.biojava.nbio.structure.scop.ScopDatabase; import org.biojava.nbio.structure.scop.ScopFactory; import org.biojava.nbio.structure.test.util.GlobalsHelper; @@ -203,7 +204,7 @@ public void testNewInstanceWithTilder() throws Exception { public void testFetchBehavior() throws IOException, ParseException { // really more of a LocalPDBDirectory test, but throw it in with AtomCache String pdbId = "1hh0"; // A small structure, since we download it multiple times - LocalPDBDirectory reader = new MMCIFFileReader(cache.getPath()); + LocalPDBDirectory reader = new CifFileReader(cache.getPath()); // delete reader.deleteStructure(pdbId); diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/asa/TestAsaCalc.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/asa/TestAsaCalc.java index 79598bd410..72a8fb57a0 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/asa/TestAsaCalc.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/asa/TestAsaCalc.java @@ -28,10 +28,10 @@ import org.biojava.nbio.structure.StructureException; import org.biojava.nbio.structure.StructureIO; import org.biojava.nbio.structure.StructureTools; -import org.biojava.nbio.structure.io.mmcif.ChemCompGroupFactory; -import org.biojava.nbio.structure.io.mmcif.DownloadChemCompProvider; import static org.junit.Assert.*; +import org.biojava.nbio.structure.chem.ChemCompGroupFactory; +import org.biojava.nbio.structure.chem.DownloadChemCompProvider; import org.junit.Test; import java.io.IOException; @@ -116,7 +116,7 @@ public void testNeighborIndicesFinding() throws StructureException, IOException } } } - + // for (int i = 0; i seqres) { for (Group g : seqres) { ChemComp c = g.getChemComp(); - sb.append(c.getOne_letter_code()); + sb.append(c.getOneLetterCode()); } return sb.toString(); 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 f64d5595a5..31d4b86dd8 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 @@ -44,12 +44,7 @@ import org.biojava.nbio.structure.StructureImpl; import org.biojava.nbio.structure.StructureTools; 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.biojava.nbio.structure.io.cif.StructureConverter; import org.junit.Test; public class TestMMCIFWriting { @@ -77,46 +72,6 @@ public void test1A2C() throws IOException, StructureException { testRoundTrip("1A2C"); } - 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); - } - private static void testRoundTrip(String pdbId) throws IOException, StructureException { AtomCache cache = new AtomCache(); @@ -138,21 +93,9 @@ private static void testRoundTrip(String pdbId) throws IOException, StructureExc fw.write(originalStruct.toMMCIF()); fw.close(); - - MMcifParser parser = new SimpleMMcifParser(); - - SimpleMMcifConsumer consumer = new SimpleMMcifConsumer(); - FileParsingParameters fileParsingParams = new FileParsingParameters(); fileParsingParams.setAlignSeqRes(true); - - consumer.setFileParsingParameters(fileParsingParams); - - parser.addMMcifConsumer(consumer); - - parser.parse(new BufferedReader(new FileReader(outputFile))); - - Structure readStruct = consumer.getStructure(); + Structure readStruct = StructureConverter.fromPath(outputFile.toPath(), params); assertNotNull(readStruct); diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestMmCIFSpecialCases.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestMmCIFSpecialCases.java deleted file mode 100644 index 95bb0c29b9..0000000000 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestMmCIFSpecialCases.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * BioJava development code - * - * This code may be freely distributed and modified under the - * terms of the GNU Lesser General Public Licence. This should - * be distributed with the code. If you do not have a copy, - * see: - * - * http://www.gnu.org/copyleft/lesser.html - * - * Copyright for this code is held jointly by the individual - * authors. These should be listed in @author doc comments. - * - * For more information on the BioJava project and its aims, - * or to join the biojava-l mailing list, visit the home page - * at: - * - * http://www.biojava.org/ - * - */ -package org.biojava.nbio.structure.io; - -//import static org.junit.Assert.*; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.StringReader; - -import org.biojava.nbio.structure.io.mmcif.SimpleMMcifParser; -import org.junit.Test; - -public class TestMmCIFSpecialCases { - - /** - * This tests for cases where dots appear in integer fields. - * Unusual but it happens in some PDB entries like 1s32 - * See issue https://github.com/biojava/biojava/issues/368 - * @throws IOException - */ - @Test - public void testDotsInIntFields() throws IOException { - - // taken from 1s32 - String mmcifStr = - "data_\n" + - "loop_\n" + - "_struct_ref_seq_dif.align_id\n" + - "_struct_ref_seq_dif.pdbx_pdb_id_code\n"+ - "_struct_ref_seq_dif.mon_id\n"+ - "_struct_ref_seq_dif.pdbx_pdb_strand_id\n"+ - "_struct_ref_seq_dif.seq_num\n"+ // integer field that contains '.' - "_struct_ref_seq_dif.pdbx_seq_db_name\n"+ - "_struct_ref_seq_dif.pdbx_seq_db_accession_code\n"+ - "_struct_ref_seq_dif.db_mon_id\n"+ - "_struct_ref_seq_dif.pdbx_seq_db_seq_num\n"+ - "_struct_ref_seq_dif.details\n"+ - "_struct_ref_seq_dif.pdbx_auth_seq_num\n"+ - "_struct_ref_seq_dif.pdbx_pdb_ins_code\n"+ - "_struct_ref_seq_dif.pdbx_ordinal\n"+ - "1 1S32 . A . GB 30268544 MET 1 'INTIATING METHIONINE' ? ? 1\n"+ - "2 1S32 . E . GB 30268544 MET 1 'INTIATING METHIONINE' ? ? 2\n"+ - "3 1S32 . B . UNP P02304 MET 0 'INTIATING METHIONINE' ? ? 3\n"+ - "4 1S32 . F . UNP P02304 MET 0 'INTIATING METHIONINE' ? ? 4\n"+ - "5 1S32 . C . GB 30268540 MET 1 'INTIATING METHIONINE' ? ? 5\n"+ - "6 1S32 . G . GB 30268540 MET 1 'INTIATING METHIONINE' ? ? 6\n"+ - "7 1S32 . D . GB 30268542 MET 1 'INTIATING METHIONINE' ? ? 7\n"+ - "8 1S32 . H . GB 30268542 MET 1 'INTIATING METHIONINE' ? ? 8" ; - - SimpleMMcifParser parser = new SimpleMMcifParser(); - - BufferedReader buf = new BufferedReader(new StringReader(mmcifStr)); - - parser.parse(buf); - - buf.close(); - - // nothing to assert, the test just makes sure it doesn't throw an exception - - - } - -} diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestNonDepositedFiles.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestNonDepositedFiles.java index 2e9ecc6140..b0c7c8fe55 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestNonDepositedFiles.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestNonDepositedFiles.java @@ -38,9 +38,7 @@ 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.MMcifParser; -import org.biojava.nbio.structure.io.mmcif.SimpleMMcifConsumer; -import org.biojava.nbio.structure.io.mmcif.SimpleMMcifParser; +import org.biojava.nbio.structure.io.cif.StructureConverter; import org.biojava.nbio.structure.xtal.CrystalCell; import org.junit.Test; @@ -207,20 +205,10 @@ private void checkChains(Structure s) { @Test public void testPhenixCifFile() throws IOException { InputStream inStream = new GZIPInputStream(this.getClass().getResourceAsStream("/org/biojava/nbio/structure/io/4lup_phenix_output.cif.gz")); - MMcifParser parser = new SimpleMMcifParser(); - - SimpleMMcifConsumer consumer = new SimpleMMcifConsumer(); FileParsingParameters fileParsingParams = new FileParsingParameters(); fileParsingParams.setAlignSeqRes(true); - - consumer.setFileParsingParameters(fileParsingParams); - - parser.addMMcifConsumer(consumer); - - parser.parse(new BufferedReader(new InputStreamReader(inStream))); - - Structure s = consumer.getStructure(); + Structure s = StructureConverter.fromInputStream(inStream, fileParsingParams); assertNotNull(s); @@ -344,12 +332,7 @@ public void testNewLigandChain() throws IOException { int expectedNumLigands = 1; assertEquals(expectedNumLigands, c1.getAtomGroups().size()); - MMcifParser mmcifpars = new SimpleMMcifParser(); - SimpleMMcifConsumer consumer = new SimpleMMcifConsumer(); - consumer.setFileParsingParameters(params); - mmcifpars.addMMcifConsumer(consumer); - mmcifpars.parse(cifStream) ; - Structure s2 = consumer.getStructure(); + Structure s2 = StructureConverter.fromInputStream(cifStream, params); // The chain B should be present with 1 ligand HEM Chain c2 = s2.getNonPolyChainsByPDB("B").get(0); @@ -389,11 +372,7 @@ public void testWaterOnlyChainCif() throws IOException { // following file is cut-down versions of 4a10 InputStream cifStream = new GZIPInputStream(this.getClass().getResourceAsStream("/org/biojava/nbio/structure/io/4a10_short.cif.gz")); - MMcifParser mmcifpars = new SimpleMMcifParser(); - SimpleMMcifConsumer consumer = new SimpleMMcifConsumer(); - mmcifpars.addMMcifConsumer(consumer); - mmcifpars.parse(cifStream) ; - Structure s2 = consumer.getStructure(); + Structure s2 = StructureConverter.fromInputStream(cifStream); assertEquals(2, s2.getChains().size()); @@ -451,13 +430,7 @@ public void testStructureWithBranchedEntities() throws IOException { URL url = new URL("https://raw.githubusercontent.com/pdbxmmcifwg/carbohydrate-extension/master/examples/models/1B5F-carb.cif"); InputStream inStream = url.openStream(); - MMcifParser parser = new SimpleMMcifParser(); - - SimpleMMcifConsumer consumer = new SimpleMMcifConsumer(); - parser.addMMcifConsumer(consumer); - parser.parse(new BufferedReader(new InputStreamReader(inStream))); - - Structure structure = consumer.getStructure(); + Structure structure = StructureConverter.fromInputStream(inStream); assertEquals(7, structure.getEntityInfos().size()); diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestParseMmCIFLigands.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestParseMmCIFLigands.java index c97aed8d88..2a997118f2 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestParseMmCIFLigands.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestParseMmCIFLigands.java @@ -31,9 +31,9 @@ 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.ChemCompGroupFactory; -import org.biojava.nbio.structure.io.mmcif.DownloadChemCompProvider; -import org.biojava.nbio.structure.io.mmcif.chem.PolymerType; +import org.biojava.nbio.structure.chem.ChemCompGroupFactory; +import org.biojava.nbio.structure.chem.DownloadChemCompProvider; +import org.biojava.nbio.structure.chem.PolymerType; import org.junit.Test; /** diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmcif/TestChemCompProvider.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmcif/TestChemCompProvider.java index 4791f21fe7..89af60dc65 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmcif/TestChemCompProvider.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmcif/TestChemCompProvider.java @@ -33,6 +33,8 @@ import org.biojava.nbio.structure.StructureIO; import org.biojava.nbio.structure.align.util.AtomCache; import org.biojava.nbio.structure.align.util.UserConfiguration; +import org.biojava.nbio.structure.chem.ChemCompGroupFactory; +import org.biojava.nbio.structure.chem.ZipChemCompProvider; import org.biojava.nbio.structure.io.FileParsingParameters; import org.biojava.nbio.structure.io.PDBFileReader; import org.junit.Test; diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmcif/TestEntityNameAndType.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmcif/TestEntityNameAndType.java index 780aad41c4..94a9a18fa5 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmcif/TestEntityNameAndType.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmcif/TestEntityNameAndType.java @@ -30,6 +30,8 @@ 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.chem.ChemCompGroupFactory; +import org.biojava.nbio.structure.chem.DownloadChemCompProvider; import org.biojava.nbio.structure.io.FileParsingParameters; import org.junit.Test; /** diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmtf/TestBondFinding.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmtf/TestBondFinding.java index ab5268578c..9e850585b6 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmtf/TestBondFinding.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmtf/TestBondFinding.java @@ -20,6 +20,8 @@ */ package org.biojava.nbio.structure.io.mmtf; +import org.biojava.nbio.structure.chem.ChemCompGroupFactory; +import org.biojava.nbio.structure.chem.DownloadChemCompProvider; import org.junit.Test; import static org.junit.Assert.*; @@ -36,8 +38,6 @@ import org.biojava.nbio.structure.align.util.AtomCache; import org.biojava.nbio.structure.io.FileParsingParameters; import org.biojava.nbio.structure.io.LocalPDBDirectory.FetchBehavior; -import org.biojava.nbio.structure.io.mmcif.ChemCompGroupFactory; -import org.biojava.nbio.structure.io.mmcif.DownloadChemCompProvider; /** * Test bond finding in BioJava diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmtf/TestMmtfRoundTrip.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmtf/TestMmtfRoundTrip.java index f787b1e908..96f9dd8c43 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmtf/TestMmtfRoundTrip.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmtf/TestMmtfRoundTrip.java @@ -39,12 +39,10 @@ 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.chem.ChemCompGroupFactory; +import org.biojava.nbio.structure.chem.DownloadChemCompProvider; import org.biojava.nbio.structure.io.FileParsingParameters; -import org.biojava.nbio.structure.io.mmcif.ChemCompGroupFactory; -import org.biojava.nbio.structure.io.mmcif.DownloadChemCompProvider; -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.cif.StructureConverter; import org.biojava.nbio.structure.quaternary.BioAssemblyInfo; import org.biojava.nbio.structure.quaternary.BiologicalAssemblyTransformation; import org.junit.Test; @@ -76,7 +74,7 @@ public void testRoundTrip() throws IOException, StructureException { params.setParseBioAssembly(true); cache.setFileParsingParams(params); cache.setUseMmCif(true); - + StructureIO.setAtomCache(cache); ChemCompGroupFactory.setChemCompProvider(new DownloadChemCompProvider()); @@ -146,11 +144,11 @@ private boolean checkIfAtomsSame(Structure structOne, Structure structTwo) { System.out.println(groupTwo.getPDBName() + " and type: "+groupTwo.getType());; } // Check the single letter amino acid is correct - if(groupOne.getChemComp().getOne_letter_code().length()==1 && groupTwo.getChemComp().getOne_letter_code().length()==1){ - if(!groupOne.getChemComp().getOne_letter_code().equals(groupTwo.getChemComp().getOne_letter_code())){ + if(groupOne.getChemComp().getOneLetterCode().length()==1 && groupTwo.getChemComp().getOneLetterCode().length()==1){ + if(!groupOne.getChemComp().getOneLetterCode().equals(groupTwo.getChemComp().getOneLetterCode())){ System.out.println(groupOne.getPDBName()); } - assertEquals(groupOne.getChemComp().getOne_letter_code(), groupTwo.getChemComp().getOne_letter_code()); + assertEquals(groupOne.getChemComp().getOneLetterCode(), groupTwo.getChemComp().getOneLetterCode()); } assertEquals(groupOne.getType(), groupTwo.getType()); assertEquals(groupOne.getPDBName(), groupTwo.getPDBName()); @@ -307,7 +305,7 @@ private void checkSeqresGroups(Chain chainOne, Chain chainTwo) { Group gTwo = chainTwo.getSeqResGroup(i); assertNotNull(gOne.getChemComp()); assertNotNull(gTwo.getChemComp()); - assertEquals(gOne.getChemComp().getOne_letter_code(), gTwo.getChemComp().getOne_letter_code()); + assertEquals(gOne.getChemComp().getOneLetterCode(), gTwo.getChemComp().getOneLetterCode()); assertEquals(gOne.getResidueNumber(), gTwo.getResidueNumber()); //assertEquals(gOne.getPDBName(), gTwo.getPDBName()); @@ -361,13 +359,7 @@ public void testStructWithBranchedEntitiesRoundTrip() throws IOException { URL url = new URL("https://raw.githubusercontent.com/pdbxmmcifwg/carbohydrate-extension/master/examples/models/1B5F-carb.cif"); InputStream inStream = url.openStream(); - MMcifParser parser = new SimpleMMcifParser(); - - SimpleMMcifConsumer consumer = new SimpleMMcifConsumer(); - parser.addMMcifConsumer(consumer); - parser.parse(new BufferedReader(new InputStreamReader(inStream))); - - Structure structure = consumer.getStructure(); + Structure structure = StructureConverter.fromInputStream(inStream); AdapterToStructureData writerToEncoder = new AdapterToStructureData(); new MmtfStructureWriter(structure, writerToEncoder); diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmtf/TestMmtfStructureReader.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmtf/TestMmtfStructureReader.java index ac2d81e8d5..0bed40a6be 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmtf/TestMmtfStructureReader.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmtf/TestMmtfStructureReader.java @@ -11,16 +11,16 @@ 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.chem.ChemCompGroupFactory; +import org.biojava.nbio.structure.chem.DownloadChemCompProvider; import org.biojava.nbio.structure.io.FileParsingParameters; -import org.biojava.nbio.structure.io.mmcif.ChemCompGroupFactory; -import org.biojava.nbio.structure.io.mmcif.DownloadChemCompProvider; import org.junit.Ignore; import org.junit.Test; import static org.junit.Assert.*; /** * Test the Biojava MMTF reader. - * + * * @author Anthony Bradley * @author Aleix Lafita * @@ -32,50 +32,50 @@ public class TestMmtfStructureReader { */ @Test public void testRead() throws IOException { - + // Get the MMTF file from the resources folder ClassLoader classLoader = getClass().getClassLoader(); String resource = "org/biojava/nbio/structure/io/mmtf/4CUP.mmtf"; - + // Load the structure into memory Structure structure = MmtfActions.readFromFile(( Paths.get(classLoader.getResource(resource).getPath()))); - + // Check header properties of the structure assertEquals(structure.getPDBCode(), "4CUP"); - assertEquals(MmtfUtils.dateToIsoString(structure.getPDBHeader().getDepDate()), + assertEquals(MmtfUtils.dateToIsoString(structure.getPDBHeader().getDepDate()), "2014-03-21"); - + assertEquals(structure.getChains().size(), 6); } - + /** * Compare structures loaded from MMCIF and MMTF files. */ @Test public void compareMmcif() throws IOException, StructureException { - + // Get the MMTF and MMCIF files from the resources folder ClassLoader classLoader = getClass().getClassLoader(); String resource = "org/biojava/nbio/structure/io/mmtf/4CUP"; - + // Load the structures into memory Structure mmtf = MmtfActions.readFromFile(( Paths.get(classLoader.getResource(resource + ".mmtf").getPath()))); Structure mmcif = StructureIO.getStructure(classLoader.getResource(resource + ".cif").getPath()); - + // Compare the dates of the structure - assertEquals(mmcif.getPDBHeader().getDepDate(), + assertEquals(mmcif.getPDBHeader().getDepDate(), mmtf.getPDBHeader().getDepDate()); - + // Compare the experimental method - assertEquals(mmcif.getPDBHeader().getExperimentalTechniques(), + assertEquals(mmcif.getPDBHeader().getExperimentalTechniques(), mmtf.getPDBHeader().getExperimentalTechniques()); - + // Compare the SEQRES, see issue https://github.com/biojava/biojava/issues/671 - assertEquals(mmcif.getChainByIndex(0).getSeqResSequence(), + assertEquals(mmcif.getChainByIndex(0).getSeqResSequence(), mmtf.getChainByIndex(0).getSeqResSequence()); - + } /** diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmtf/TestMmtfStructureWriter.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmtf/TestMmtfStructureWriter.java index 6f98b250d3..efc9929916 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmtf/TestMmtfStructureWriter.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmtf/TestMmtfStructureWriter.java @@ -37,7 +37,7 @@ import org.biojava.nbio.structure.ResidueNumber; import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.StructureImpl; -import org.biojava.nbio.structure.io.mmcif.model.ChemComp; +import org.biojava.nbio.structure.chem.ChemComp; import org.junit.Rule; import org.junit.Test; import static org.junit.Assert.*; @@ -95,7 +95,7 @@ public void testWrite() throws IOException { group.setPDBName("FKF"); ChemComp chemComp = new ChemComp(); chemComp.setType("TYPfdl"); - chemComp.setOne_letter_code("A"); + chemComp.setOneLetterCode("A"); group.setChemComp(chemComp); // Create one Atom diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/redmine/Test1DARSeqAlign.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/redmine/Test1DARSeqAlign.java index 4f351d3c74..0aefbc5713 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/redmine/Test1DARSeqAlign.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/redmine/Test1DARSeqAlign.java @@ -23,10 +23,10 @@ import org.biojava.nbio.structure.*; import org.biojava.nbio.structure.align.util.AtomCache; +import org.biojava.nbio.structure.chem.ChemCompGroupFactory; +import org.biojava.nbio.structure.chem.ChemCompProvider; +import org.biojava.nbio.structure.chem.DownloadChemCompProvider; import org.biojava.nbio.structure.io.FileParsingParameters; -import org.biojava.nbio.structure.io.mmcif.ChemCompGroupFactory; -import org.biojava.nbio.structure.io.mmcif.ChemCompProvider; -import org.biojava.nbio.structure.io.mmcif.DownloadChemCompProvider; import org.junit.Test; import static org.junit.Assert.*; @@ -50,7 +50,7 @@ public void test1DAR() throws StructureException, IOException { boolean usingReducedChemCompProvider = false; - ChemCompProvider ccp =ChemCompGroupFactory.getChemCompProvider(); + ChemCompProvider ccp = ChemCompGroupFactory.getChemCompProvider(); if (ccp.getClass().getName().contains("ReducedChemCompProvider") ) { usingReducedChemCompProvider = true; diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/test/util/GlobalsHelper.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/test/util/GlobalsHelper.java index 9d7e5ae57d..0d5766d8f9 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/test/util/GlobalsHelper.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/test/util/GlobalsHelper.java @@ -28,9 +28,9 @@ import org.biojava.nbio.structure.StructureIO; import org.biojava.nbio.structure.align.util.AtomCache; import org.biojava.nbio.structure.align.util.UserConfiguration; -import org.biojava.nbio.structure.io.mmcif.ChemCompGroupFactory; -import org.biojava.nbio.structure.io.mmcif.ChemCompProvider; -import org.biojava.nbio.structure.io.mmcif.DownloadChemCompProvider; +import org.biojava.nbio.structure.chem.ChemCompGroupFactory; +import org.biojava.nbio.structure.chem.ChemCompProvider; +import org.biojava.nbio.structure.chem.DownloadChemCompProvider; import org.biojava.nbio.structure.scop.ScopDatabase; import org.biojava.nbio.structure.scop.ScopFactory; From b992e74865f878dd054e367e1a3bb05ae6897707 Mon Sep 17 00:00:00 2001 From: JonStargaryen Date: Mon, 25 Jan 2021 11:14:35 -0800 Subject: [PATCH 018/599] metal parsing --- .../nbio/structure/io/cif/MetalBondConsumerImpl.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/MetalBondConsumerImpl.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/MetalBondConsumerImpl.java index 28833bc559..d9d03a9590 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/MetalBondConsumerImpl.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/MetalBondConsumerImpl.java @@ -31,10 +31,10 @@ public void finish() { @Override public void consume(Category category) { - StrColumn atomType1 = (StrColumn) category.getColumn(""); - StrColumn atomType2 = (StrColumn) category.getColumn(""); - FloatColumn lowerLimit = (FloatColumn) category.getColumn(""); - FloatColumn upperLimit = (FloatColumn) category.getColumn(""); + StrColumn atomType1 = (StrColumn) category.getColumn("atom_type_1"); + StrColumn atomType2 = (StrColumn) category.getColumn("atom_type_2"); + FloatColumn lowerLimit = (FloatColumn) category.getColumn("lower_limit"); + FloatColumn upperLimit = (FloatColumn) category.getColumn("upper_limit"); for (int i = 0; i < category.getRowCount(); i++) { MetalBondDistance d = new MetalBondDistance(); From 61bd8e8f51479951d4dd13b661f58b0f9c56c0b9 Mon Sep 17 00:00:00 2001 From: JonStargaryen Date: Mon, 25 Jan 2021 12:50:40 -0800 Subject: [PATCH 019/599] new filetype param --- .../structure/test/StructureToolsTest.java | 4 +- .../biojava/nbio/structure/test/Test1o2f.java | 3 +- .../test/io/TestAtomCachePerformance.java | 5 +- .../structure/test/io/TestBioassemblies.java | 9 +- .../test/io/TestCrystallographicMetadata.java | 7 +- .../test/io/TestLongPdbVsMmCifParsing.java | 4 +- .../io/TestStructWithMultiparentChemComp.java | 3 +- .../TestQuatSymmetryDetectorExamples.java | 9 +- .../test/xtal/TestCrystalBuilder.java | 17 +- .../main/java/demo/DemoQuatSymmetryJmol.java | 3 +- .../main/java/demo/DemoShowLargeAssembly.java | 3 +- .../src/main/java/demo/DemoAsa.java | 3 +- .../src/main/java/demo/DemoContacts.java | 2 +- .../main/java/demo/DemoCrystalInterfaces.java | 5 +- .../src/main/java/demo/DemoLoadSecStruc.java | 3 +- .../src/main/java/demo/DemoMMCIFReader.java | 5 +- .../nbio/structure/StructureFiletype.java | 36 ++++ .../biojava/nbio/structure/StructureIO.java | 85 ++------ .../biojava/nbio/structure/URLIdentifier.java | 74 +++---- .../nbio/structure/align/util/AtomCache.java | 198 +++++++----------- .../align/util/UserConfiguration.java | 166 ++++++--------- .../biojava/nbio/structure/chem/ChemComp.java | 3 +- .../nbio/structure/io/mmtf/MmtfUtils.java | 5 +- .../org/biojava/nbio/structure/Test2JA5.java | 4 +- .../biojava/nbio/structure/TestAltLocs.java | 14 +- .../biojava/nbio/structure/TestAtomCache.java | 36 ++-- .../org/biojava/nbio/structure/TestBond.java | 2 +- .../biojava/nbio/structure/TestCloning.java | 2 +- .../structure/TestEntityResIndexMapping.java | 4 +- .../structure/TestExperimentalTechniques.java | 16 +- .../structure/TestLoadStructureFromURL.java | 3 +- .../nbio/structure/TestParsingCalcium.java | 2 +- .../TestStructureCrossReferences.java | 8 +- .../structure/align/util/AtomCacheTest.java | 5 +- .../structure/io/TestDifficultMmCIFFiles.java | 13 +- .../nbio/structure/io/TestHardBioUnits.java | 4 +- .../nbio/structure/io/TestHeaderOnly.java | 9 +- .../nbio/structure/io/TestMMCIFWriting.java | 3 +- .../io/TestMMcifOrganismParsing.java | 3 +- .../structure/io/TestNonDepositedFiles.java | 3 +- .../structure/io/TestParseMmCIFFeatures.java | 9 +- .../structure/io/TestParseMmCIFLigands.java | 9 +- .../nbio/structure/io/TestParseOnAsymId.java | 3 +- .../io/TestQuaternaryStructureProviders.java | 8 +- .../nbio/structure/io/TestTitleParsing.java | 5 +- .../io/TestWriteLargeCoordinatePDB.java | 3 +- .../io/mmcif/TestChemCompProvider.java | 6 +- .../io/mmcif/TestEntityNameAndType.java | 3 +- .../io/mmcif/TestParseInternalChainId.java | 3 +- .../io/mmcif/TestParseMmcifHeader.java | 3 +- .../structure/io/mmtf/TestBondFinding.java | 3 +- .../structure/io/mmtf/TestMmtfRoundTrip.java | 3 +- .../io/mmtf/TestMmtfStructureReader.java | 4 +- .../nbio/structure/xtal/TestCrystalInfo.java | 16 +- .../xtal/TestInterfaceClustering.java | 5 +- 55 files changed, 392 insertions(+), 474 deletions(-) create mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/StructureFiletype.java diff --git a/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/StructureToolsTest.java b/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/StructureToolsTest.java index 170694a6e2..510b071200 100644 --- a/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/StructureToolsTest.java +++ b/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/StructureToolsTest.java @@ -186,12 +186,12 @@ public void testCAmmCIF() throws StructureException { //mmCIF files left justify their atom names (eg "CA "), so can have different behavior AtomCache pdbCache = new AtomCache(); - pdbCache.setUseMmCif(false); + pdbCache.setFiletype(StructureFiletype.PDB); FileParsingParameters params = new FileParsingParameters(); pdbCache.setFileParsingParams(params); AtomCache mmcifCache = new AtomCache(); - mmcifCache.setUseMmCif(true); + mmcifCache.setFiletype(StructureFiletype.CIF); FileParsingParameters params2 = new FileParsingParameters(); mmcifCache.setFileParsingParams(params2); diff --git a/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/Test1o2f.java b/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/Test1o2f.java index 7acde4166e..af1ec695f7 100644 --- a/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/Test1o2f.java +++ b/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/Test1o2f.java @@ -22,6 +22,7 @@ import org.biojava.nbio.structure.Chain; import org.biojava.nbio.structure.Structure; +import org.biojava.nbio.structure.StructureFiletype; import org.biojava.nbio.structure.StructureIO; import org.biojava.nbio.structure.align.util.AtomCache; import org.biojava.nbio.structure.io.LocalPDBDirectory.FetchBehavior; @@ -38,7 +39,7 @@ public class Test1o2f { @Before public void setUp() throws Exception { AtomCache cache = new AtomCache(); - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.CIF); cache.setFetchBehavior(FetchBehavior.FETCH_FILES); StructureIO.setAtomCache(cache); String pdbId = "1O2F"; diff --git a/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/io/TestAtomCachePerformance.java b/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/io/TestAtomCachePerformance.java index 7df8c8bb10..03bf297484 100644 --- a/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/io/TestAtomCachePerformance.java +++ b/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/io/TestAtomCachePerformance.java @@ -22,6 +22,7 @@ import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.StructureException; +import org.biojava.nbio.structure.StructureFiletype; import org.biojava.nbio.structure.align.util.AtomCache; import org.biojava.nbio.structure.io.LocalPDBDirectory.FetchBehavior; import org.junit.BeforeClass; @@ -94,14 +95,14 @@ public void testDownload() throws IOException, StructureException { } private Structure getCifStructure(String pdbId) throws IOException, StructureException { - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.CIF); return cache.getStructure(pdbId); } private Structure getPdbStructure(String pdbId) throws IOException, StructureException { - cache.setUseMmCif(false); + cache.setFiletype(StructureFiletype.PDB); return cache.getStructure(pdbId); diff --git a/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/io/TestBioassemblies.java b/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/io/TestBioassemblies.java index 23a73a7ae8..001dd5434e 100644 --- a/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/io/TestBioassemblies.java +++ b/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/io/TestBioassemblies.java @@ -28,6 +28,7 @@ import org.biojava.nbio.structure.Chain; import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.StructureException; +import org.biojava.nbio.structure.StructureFiletype; import org.biojava.nbio.structure.StructureIO; import org.biojava.nbio.structure.align.util.AtomCache; import org.junit.Test; @@ -47,7 +48,7 @@ public void test1E17() throws IOException, StructureException { AtomCache prevAtomCache = StructureIO.getAtomCache(); AtomCache cache = new AtomCache(); - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.CIF); StructureIO.setAtomCache(cache); List multiModelBioAssemblies = StructureIO.getBiologicalAssemblies("1E17", true); @@ -79,7 +80,7 @@ public void test4TTX() throws IOException, StructureException { AtomCache prevAtomCache = StructureIO.getAtomCache(); AtomCache cache = new AtomCache(); - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.CIF); StructureIO.setAtomCache(cache); List multiModelBioAssemblies = StructureIO.getBiologicalAssemblies("4TTX", true); @@ -124,7 +125,7 @@ public void test1M4X() throws IOException, StructureException { AtomCache prevAtomCache = StructureIO.getAtomCache(); AtomCache cache = new AtomCache(); - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.CIF); StructureIO.setAtomCache(cache); Structure flattenedBioAssembly5 = StructureIO.getBiologicalAssembly("1M4X" , 5); @@ -153,7 +154,7 @@ public void test4OPJ() throws IOException, StructureException { AtomCache prevAtomCache = StructureIO.getAtomCache(); AtomCache cache = new AtomCache(); - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.CIF); StructureIO.setAtomCache(cache); List multiModelBioAssemblies = StructureIO.getBiologicalAssemblies("4OPJ", true); diff --git a/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/io/TestCrystallographicMetadata.java b/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/io/TestCrystallographicMetadata.java index 26f83b7a28..c41ac34410 100644 --- a/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/io/TestCrystallographicMetadata.java +++ b/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/io/TestCrystallographicMetadata.java @@ -20,6 +20,7 @@ */ package org.biojava.nbio.structure.test.io; +import org.biojava.nbio.structure.StructureFiletype; import org.junit.Test; import static org.junit.Assert.*; @@ -46,7 +47,7 @@ public void test4hhb() throws Exception { AtomCache cache = new AtomCache(); // at the moment implemented only in mmcif - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.CIF); StructureIO.setAtomCache(cache); Structure s = StructureIO.getStructure("4hhb"); @@ -64,7 +65,7 @@ public void test1smt() throws Exception { AtomCache cache = new AtomCache(); // at the moment implemented only in mmcif - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.CIF); StructureIO.setAtomCache(cache); Structure s = StructureIO.getStructure("1smt"); @@ -82,7 +83,7 @@ public void test1smt() throws Exception { public void test1zna() throws Exception { AtomCache cache = new AtomCache(); // at the moment implemented only in mmcif - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.CIF); StructureIO.setAtomCache(cache); Structure s = StructureIO.getStructure("1zna"); diff --git a/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/io/TestLongPdbVsMmCifParsing.java b/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/io/TestLongPdbVsMmCifParsing.java index daadcc7023..fc529b75e3 100644 --- a/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/io/TestLongPdbVsMmCifParsing.java +++ b/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/io/TestLongPdbVsMmCifParsing.java @@ -567,7 +567,7 @@ private void testSingleChain(Chain cPdb, Chain cCif) { private Structure getPdbStructure(String pdbId) throws IOException, StructureException { - cache.setUseMmCif(false); + cache.setFiletype(StructureFiletype.PDB); // set parsing params here: params.setAlignSeqRes(true); //params.setLoadChemCompInfo(true); @@ -578,7 +578,7 @@ private Structure getPdbStructure(String pdbId) throws IOException, StructureExc } private Structure getCifStructure(String pdbId) throws IOException, StructureException { - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.CIF); // set parsing params here: params.setAlignSeqRes(true); //params.setLoadChemCompInfo(true); diff --git a/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/io/TestStructWithMultiparentChemComp.java b/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/io/TestStructWithMultiparentChemComp.java index cbedb5b108..83059e7ea4 100644 --- a/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/io/TestStructWithMultiparentChemComp.java +++ b/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/io/TestStructWithMultiparentChemComp.java @@ -20,6 +20,7 @@ */ package org.biojava.nbio.structure.test.io; +import org.biojava.nbio.structure.StructureFiletype; import org.junit.Test; import static org.junit.Assert.*; @@ -35,7 +36,7 @@ public class TestStructWithMultiparentChemComp { public void test4Q7U() throws Exception { AtomCache cache = new AtomCache(); - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.CIF); StructureIO.setAtomCache(cache); Structure s = StructureIO.getStructure("4q7u"); diff --git a/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/symmetry/TestQuatSymmetryDetectorExamples.java b/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/symmetry/TestQuatSymmetryDetectorExamples.java index b5a8a5a2e1..3c153cde22 100644 --- a/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/symmetry/TestQuatSymmetryDetectorExamples.java +++ b/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/symmetry/TestQuatSymmetryDetectorExamples.java @@ -27,6 +27,7 @@ import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.StructureException; +import org.biojava.nbio.structure.StructureFiletype; import org.biojava.nbio.structure.StructureIO; import org.biojava.nbio.structure.StructureTools; import org.biojava.nbio.structure.align.util.AtomCache; @@ -146,7 +147,7 @@ public void testPseudosymmetry() throws IOException, StructureException { public void testLocal() throws IOException, StructureException { AtomCache atomCache = new AtomCache(); - atomCache.setUseMmtf(true); + atomCache.setFiletype(StructureFiletype.MMTF); List testIds = new ArrayList<>(); List testStoichiometries = new ArrayList<>(); @@ -376,8 +377,7 @@ public void testPseudoIdentity95() throws IOException, StructureException { @Test public void testSymDetectionWithClusteringByEntityId() throws IOException, StructureException { AtomCache cache = new AtomCache(); - cache.setUseMmtf(false); - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.CIF); FileParsingParameters params = new FileParsingParameters(); params.setAlignSeqRes(true); cache.setFileParsingParams(params); @@ -404,8 +404,7 @@ public void testSymDetectionWithClusteringByEntityId() throws IOException, Struc @Test public void testSymDetectionPerformanceLargeCapsid() throws IOException, StructureException { AtomCache cache = new AtomCache(); - cache.setUseMmtf(false); - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.CIF); FileParsingParameters params = new FileParsingParameters(); params.setAlignSeqRes(true); params.setParseBioAssembly(true); diff --git a/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/xtal/TestCrystalBuilder.java b/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/xtal/TestCrystalBuilder.java index 898e108a8e..4851c03ba9 100644 --- a/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/xtal/TestCrystalBuilder.java +++ b/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/xtal/TestCrystalBuilder.java @@ -22,6 +22,7 @@ import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.StructureException; +import org.biojava.nbio.structure.StructureFiletype; import org.biojava.nbio.structure.StructureIO; import org.biojava.nbio.structure.align.util.AtomCache; import org.biojava.nbio.structure.contact.StructureInterfaceList; @@ -46,7 +47,7 @@ public void test1NMR() throws IOException, StructureException { StructureIO.setAtomCache(cache); - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.CIF); Structure s1 = StructureIO.getStructure("1NMR"); CrystalBuilder cb = new CrystalBuilder(s1); @@ -64,7 +65,7 @@ public void test1B8G() throws IOException, StructureException { StructureIO.setAtomCache(cache); - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.CIF); Structure s1 = StructureIO.getStructure("1B8G"); CrystalBuilder cb = new CrystalBuilder(s1); StructureInterfaceList interfaces = cb.getUniqueInterfaces(5.5); @@ -82,7 +83,7 @@ public void test2MFZ() throws IOException, StructureException { StructureIO.setAtomCache(cache); - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.CIF); Structure s1 = StructureIO.getStructure("2MFZ"); CrystalBuilder cb = new CrystalBuilder(s1); StructureInterfaceList interfaces = cb.getUniqueInterfaces(5.5); @@ -99,7 +100,7 @@ public void test4MF8() throws IOException, StructureException { StructureIO.setAtomCache(cache); - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.CIF); Structure s1 = StructureIO.getStructure("4MF8"); CrystalBuilder cb = new CrystalBuilder(s1); StructureInterfaceList interfaces = cb.getUniqueInterfaces(5.5); @@ -112,7 +113,7 @@ public void test1AUY() throws IOException, StructureException { // a virus with NCS operators AtomCache cache = new AtomCache(); StructureIO.setAtomCache(cache); - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.CIF); Structure s1 = StructureIO.getStructure("1AUY"); Map chainNcsOps = new HashMap<>(); @@ -139,7 +140,7 @@ public void test1A37() throws IOException, StructureException { // a smaller structure with NCS operators AtomCache cache = new AtomCache(); StructureIO.setAtomCache(cache); - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.CIF); Structure s1 = StructureIO.getStructure("1A37"); Map chainNcsOps = new HashMap<>(); @@ -164,7 +165,7 @@ public void test2H2Z() throws IOException, StructureException { StructureIO.setAtomCache(cache); - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.CIF); Structure s1 = StructureIO.getStructure("2H2Z"); CrystalBuilder cb = new CrystalBuilder(s1); StructureInterfaceList interfaces = cb.getUniqueInterfaces(5.5); @@ -181,7 +182,7 @@ public void test4HHB() throws IOException, StructureException { StructureIO.setAtomCache(cache); - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.CIF); Structure s1 = StructureIO.getStructure("4HHB"); CrystalBuilder cb = new CrystalBuilder(s1); StructureInterfaceList interfaces = cb.getUniqueInterfaces(5.5); diff --git a/biojava-structure-gui/src/main/java/demo/DemoQuatSymmetryJmol.java b/biojava-structure-gui/src/main/java/demo/DemoQuatSymmetryJmol.java index deadf35e43..674c846d4a 100644 --- a/biojava-structure-gui/src/main/java/demo/DemoQuatSymmetryJmol.java +++ b/biojava-structure-gui/src/main/java/demo/DemoQuatSymmetryJmol.java @@ -22,6 +22,7 @@ import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.StructureException; +import org.biojava.nbio.structure.StructureFiletype; import org.biojava.nbio.structure.align.util.AtomCache; import org.biojava.nbio.structure.cluster.SubunitClustererMethod; import org.biojava.nbio.structure.cluster.SubunitClustererParameters; @@ -65,7 +66,7 @@ public static void main(String[] args) throws IOException, // Download the biological assembly AtomCache cache = new AtomCache(); - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.CIF); Structure structure = cache.getStructure("BIO:" + name + ":1"); QuatSymmetryParameters sp = new QuatSymmetryParameters(); diff --git a/biojava-structure-gui/src/main/java/demo/DemoShowLargeAssembly.java b/biojava-structure-gui/src/main/java/demo/DemoShowLargeAssembly.java index c626e90f8a..4aa053e70a 100644 --- a/biojava-structure-gui/src/main/java/demo/DemoShowLargeAssembly.java +++ b/biojava-structure-gui/src/main/java/demo/DemoShowLargeAssembly.java @@ -1,6 +1,7 @@ package demo; import org.biojava.nbio.structure.Structure; +import org.biojava.nbio.structure.StructureFiletype; import org.biojava.nbio.structure.StructureTools; import org.biojava.nbio.structure.align.util.AtomCache; import org.biojava.nbio.structure.io.FileParsingParameters; @@ -77,7 +78,7 @@ public static Structure readStructure(String pdbId, int bioAssemblyId) { // we just need this to track where to store PDB files // this checks the PDB_DIR property (and uses a tmp location if not set) AtomCache cache = new AtomCache(); - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.CIF); FileParsingParameters p = cache.getFileParsingParams(); // some bio assemblies are large, we want an all atom representation and avoid diff --git a/biojava-structure/src/main/java/demo/DemoAsa.java b/biojava-structure/src/main/java/demo/DemoAsa.java index caeacbd5d0..1df3d9feeb 100644 --- a/biojava-structure/src/main/java/demo/DemoAsa.java +++ b/biojava-structure/src/main/java/demo/DemoAsa.java @@ -24,6 +24,7 @@ import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.StructureException; +import org.biojava.nbio.structure.StructureFiletype; import org.biojava.nbio.structure.StructureIO; import org.biojava.nbio.structure.align.util.AtomCache; import org.biojava.nbio.structure.asa.AsaCalculator; @@ -46,7 +47,7 @@ public static void main(String[] args) throws IOException, StructureException { private static void demoAsa(String pdbCode, int numThreads) throws IOException, StructureException { AtomCache cache = new AtomCache(); - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.CIF); StructureIO.setAtomCache(cache); diff --git a/biojava-structure/src/main/java/demo/DemoContacts.java b/biojava-structure/src/main/java/demo/DemoContacts.java index 0d2d95ab82..0eed99e807 100644 --- a/biojava-structure/src/main/java/demo/DemoContacts.java +++ b/biojava-structure/src/main/java/demo/DemoContacts.java @@ -42,7 +42,7 @@ public static void main(String[] args) throws IOException, StructureException { private static void demoContacts(String pdbCode) throws IOException, StructureException { AtomCache cache = new AtomCache(); - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.CIF); StructureIO.setAtomCache(cache); diff --git a/biojava-structure/src/main/java/demo/DemoCrystalInterfaces.java b/biojava-structure/src/main/java/demo/DemoCrystalInterfaces.java index caeef006ed..76fd4f6823 100644 --- a/biojava-structure/src/main/java/demo/DemoCrystalInterfaces.java +++ b/biojava-structure/src/main/java/demo/DemoCrystalInterfaces.java @@ -23,6 +23,7 @@ import org.biojava.nbio.structure.Group; import org.biojava.nbio.structure.Structure; +import org.biojava.nbio.structure.StructureFiletype; import org.biojava.nbio.structure.align.util.AtomCache; import org.biojava.nbio.structure.contact.*; import org.biojava.nbio.structure.io.FileParsingParameters; @@ -60,12 +61,10 @@ public class DemoCrystalInterfaces { * @param args */ public static void main(String[] args) throws Exception { - - String pdbCode = "1smt"; AtomCache cache = new AtomCache(); - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.CIF); FileParsingParameters params = new FileParsingParameters(); params.setAlignSeqRes(true); diff --git a/biojava-structure/src/main/java/demo/DemoLoadSecStruc.java b/biojava-structure/src/main/java/demo/DemoLoadSecStruc.java index 8684ba1257..e0efc501c7 100644 --- a/biojava-structure/src/main/java/demo/DemoLoadSecStruc.java +++ b/biojava-structure/src/main/java/demo/DemoLoadSecStruc.java @@ -25,6 +25,7 @@ import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.StructureException; +import org.biojava.nbio.structure.StructureFiletype; import org.biojava.nbio.structure.align.util.AtomCache; import org.biojava.nbio.structure.io.FileParsingParameters; import org.biojava.nbio.structure.secstruc.DSSPParser; @@ -55,7 +56,7 @@ public static void main(String[] args) throws IOException, cache.setFileParsingParams(params); // Use PDB format, because SS cannot be parsed from mmCIF yet - cache.setUseMmCif(false); + cache.setFiletype(StructureFiletype.CIF); // The loaded Structure contains the SS assigned by Author (simple) Structure s = cache.getStructure(pdbID); diff --git a/biojava-structure/src/main/java/demo/DemoMMCIFReader.java b/biojava-structure/src/main/java/demo/DemoMMCIFReader.java index b94dbd2e19..e6b5eab186 100644 --- a/biojava-structure/src/main/java/demo/DemoMMCIFReader.java +++ b/biojava-structure/src/main/java/demo/DemoMMCIFReader.java @@ -57,15 +57,12 @@ public void loadSimple(){ String pdbId = "4hhb"; AtomCache cache = new AtomCache(); - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.CIF); StructureIO.setAtomCache(cache); - try { Structure s = StructureIO.getStructure(pdbId); - System.out.println(pdbId + " has nr atoms: " + StructureTools.getNrAtoms(s)); - } catch (Exception e){ e.printStackTrace(); } diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/StructureFiletype.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/StructureFiletype.java new file mode 100644 index 0000000000..6d56257f24 --- /dev/null +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/StructureFiletype.java @@ -0,0 +1,36 @@ +package org.biojava.nbio.structure; + +import org.biojava.nbio.structure.io.BcifFileReader; +import org.biojava.nbio.structure.io.CifFileReader; +import org.biojava.nbio.structure.io.MMTFFileReader; +import org.biojava.nbio.structure.io.PDBFileReader; + +import java.util.Collections; +import java.util.List; + +/** + * An enum of supported file formats. + */ +public enum StructureFiletype { + PDB(new PDBFileReader().getExtensions()), + CIF(new CifFileReader().getExtensions()), + BCIF(new BcifFileReader().getExtensions()), + MMTF(new MMTFFileReader().getExtensions()), + UNKNOWN(Collections.emptyList()); + + private final List extensions; + + /** + * @param extensions List of supported extensions, including leading period + */ + StructureFiletype(List extensions) { + this.extensions = extensions; + } + + /** + * @return a list of file extensions associated with this type + */ + public List getExtensions() { + return extensions; + } +} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/StructureIO.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/StructureIO.java index e0592dfae3..fb2967b101 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/StructureIO.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/StructureIO.java @@ -20,16 +20,11 @@ */ package org.biojava.nbio.structure; +import org.biojava.nbio.structure.align.util.AtomCache; + import java.io.IOException; -import java.util.Collections; import java.util.List; -import org.biojava.nbio.structure.align.util.AtomCache; -import org.biojava.nbio.structure.io.BcifFileReader; -import org.biojava.nbio.structure.io.CifFileReader; -import org.biojava.nbio.structure.io.PDBFileReader; -import org.rcsb.cif.binary.BinaryCifReader; - /** * A class that provides static access methods for easy lookup of protein structure related components * @@ -38,12 +33,8 @@ * @since 3.0.5 */ public class StructureIO { - - //private static final Logger logger = LoggerFactory.getLogger(StructureIO.class); - private static AtomCache cache ; - /** * Loads a structure based on a name. Supported naming conventions are: * @@ -94,22 +85,16 @@ public class StructureIO { * @throws StructureException The name appeared valid but did not correspond to a structure. * Also thrown by some submethods upon errors, eg for poorly formatted subranges. */ - public static Structure getStructure(String name) throws IOException, StructureException{ - + public static Structure getStructure(String name) throws IOException, StructureException { checkInitAtomCache(); - // delegate this functionality to AtomCache... - return cache.getStructure(name); - } - private static void checkInitAtomCache() { - if ( cache == null){ + if (cache == null) { cache = new AtomCache(); } - } public static void setAtomCache(AtomCache c){ @@ -121,7 +106,6 @@ public static AtomCache getAtomCache() { return cache; } - /** * Returns the first biological assembly that is available for the given PDB id. *

@@ -146,15 +130,10 @@ public static AtomCache getAtomCache() { * @throws StructureException * @throws IOException */ - public static Structure getBiologicalAssembly(String pdbId, boolean multiModel) throws IOException, StructureException{ - + public static Structure getBiologicalAssembly(String pdbId, boolean multiModel) throws IOException, StructureException { checkInitAtomCache(); - pdbId = pdbId.toLowerCase(); - - Structure s = cache.getBiologicalAssembly(pdbId, multiModel); - - return s; + return cache.getBiologicalAssembly(pdbId, multiModel); } /** @@ -170,7 +149,7 @@ public static Structure getBiologicalAssembly(String pdbId, boolean multiModel) * @throws StructureException * @throws IOException */ - public static Structure getBiologicalAssembly(String pdbId) throws IOException, StructureException{ + public static Structure getBiologicalAssembly(String pdbId) throws IOException, StructureException { return getBiologicalAssembly(pdbId, AtomCache.DEFAULT_BIOASSEMBLY_STYLE); } @@ -195,14 +174,9 @@ public static Structure getBiologicalAssembly(String pdbId) throws IOException, * @throws IOException */ public static Structure getBiologicalAssembly(String pdbId, int biolAssemblyNr, boolean multiModel) throws IOException, StructureException { - checkInitAtomCache(); - pdbId = pdbId.toLowerCase(); - - Structure s = cache.getBiologicalAssembly(pdbId, biolAssemblyNr, multiModel); - - return s; + return cache.getBiologicalAssembly(pdbId, biolAssemblyNr, multiModel); } /** @@ -218,7 +192,6 @@ public static Structure getBiologicalAssembly(String pdbId, int biolAssemblyNr) return getBiologicalAssembly(pdbId, biolAssemblyNr, AtomCache.DEFAULT_BIOASSEMBLY_STYLE); } - /** * Returns all biological assemblies for the given PDB id. *

@@ -241,15 +214,9 @@ public static Structure getBiologicalAssembly(String pdbId, int biolAssemblyNr) * @since 5.0 */ public static List getBiologicalAssemblies(String pdbId, boolean multiModel) throws IOException, StructureException { - checkInitAtomCache(); - pdbId = pdbId.toLowerCase(); - - List s = cache.getBiologicalAssemblies(pdbId, multiModel); - - return s; - + return cache.getBiologicalAssemblies(pdbId, multiModel); } /** @@ -267,7 +234,6 @@ public static List getBiologicalAssemblies(String pdbId) throws IOExc return getBiologicalAssemblies(pdbId, AtomCache.DEFAULT_BIOASSEMBLY_STYLE); } - private static final String FILE_SEPARATOR = System.getProperty("file.separator"); /** @@ -275,34 +241,11 @@ public static List getBiologicalAssemblies(String pdbId) throws IOExc * * @param pathToPDBFiles */ - public static void setPdbPath(String pathToPDBFiles){ - - if ( ! pathToPDBFiles.endsWith(FILE_SEPARATOR)) + public static void setPdbPath(String pathToPDBFiles) { + if (!pathToPDBFiles.endsWith(FILE_SEPARATOR)) pathToPDBFiles += FILE_SEPARATOR; } - - public static enum StructureFiletype { - PDB( (new PDBFileReader()).getExtensions()), - CIF(new CifFileReader().getExtensions()), - BCIF(new BcifFileReader().getExtensions()), - UNKNOWN(Collections.emptyList()); - - private List extensions; - /** - * @param extensions List of supported extensions, including leading period - */ - private StructureFiletype(List extensions) { - this.extensions = extensions; - } - /** - * @return a list of file extensions associated with this type - */ - public List getExtensions() { - return extensions; - } - } - /** * Attempts to guess the type of a structure file based on the extension * @param filename @@ -310,9 +253,9 @@ public List getExtensions() { */ public static StructureFiletype guessFiletype(String filename) { String lower = filename.toLowerCase(); - for(StructureFiletype type : StructureFiletype.values()) { - for(String ext : type.getExtensions()) { - if(lower.endsWith(ext.toLowerCase())) { + for (StructureFiletype type : StructureFiletype.values()) { + for (String ext : type.getExtensions()) { + if (lower.endsWith(ext.toLowerCase())) { return type; } } diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/URLIdentifier.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/URLIdentifier.java index a36e93b508..00b624d95f 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/URLIdentifier.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/URLIdentifier.java @@ -20,10 +20,11 @@ */ package org.biojava.nbio.structure; -import org.biojava.nbio.structure.StructureIO.StructureFiletype; +import org.biojava.nbio.structure.StructureFiletype; import org.biojava.nbio.structure.align.util.AtomCache; import org.biojava.nbio.structure.io.PDBFileReader; import org.biojava.nbio.structure.io.cif.StructureConverter; +import org.biojava.nbio.structure.io.mmtf.MmtfActions; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -57,13 +58,11 @@ * */ public class URLIdentifier implements StructureIdentifier { - private static final long serialVersionUID = -5161230822868926035L; - private static final Logger logger = LoggerFactory.getLogger(URLIdentifier.class); // Used for guessing the PDB ID from the filename - private static final Pattern PDBID_REGEX = Pattern.compile("^([0-9][a-z0-9]{3})([._-]|\\s).*",Pattern.CASE_INSENSITIVE); + private static final Pattern PDBID_REGEX = Pattern.compile("^([0-9][a-z0-9]{3})([._-]|\\s).*", Pattern.CASE_INSENSITIVE); /** URL parameter specifying the file format (PDB or CIF) */ public static final String FORMAT_PARAM = "format"; @@ -73,7 +72,8 @@ public class URLIdentifier implements StructureIdentifier { //TODO: should this get renamed to chainname or asymid? public static final String CHAINID_PARAM = "chainid"; - /** URL parameter specifying residue ranges to include, e.g. residues=A:1-70 + /** + * URL parameter specifying residue ranges to include, e.g. residues=A:1-70 * @see SubstructureIdentifier */ public static final String RESIDUES_PARAM = "residues"; @@ -90,6 +90,7 @@ public URLIdentifier(String url) throws MalformedURLException { public URL getURL() { return url; } + @Override public String getIdentifier() { return url.toString(); @@ -104,20 +105,20 @@ public SubstructureIdentifier toCanonical() { List ranges = Collections.emptyList(); try { Map params = parseQuery(url); - if(params.containsKey(PDBID_PARAM)) { + if (params.containsKey(PDBID_PARAM)) { pdbId = params.get(PDBID_PARAM); } - if(params.containsKey(RESIDUES_PARAM)) { + if (params.containsKey(RESIDUES_PARAM)) { ranges = ResidueRange.parseMultiple(params.get(RESIDUES_PARAM)); - } else if(params.containsKey(CHAINID_PARAM)) { - ranges = Arrays.asList(new ResidueRange(params.get(CHAINID_PARAM),(ResidueNumber)null,(ResidueNumber)null)); + } else if (params.containsKey(CHAINID_PARAM)) { + ranges = Collections.singletonList(new ResidueRange(params.get(CHAINID_PARAM), (ResidueNumber) null, (ResidueNumber) null)); } } catch (UnsupportedEncodingException e) { - logger.error("Unable to decode URL "+url,e); + logger.error("Unable to decode URL {}", url, e); } - if(pdbId == null) { + if (pdbId == null) { String path = url.getPath(); - pdbId = guessPDBID(path.substring(path.lastIndexOf("/")+1)); + pdbId = guessPDBID(path.substring(path.lastIndexOf("/") + 1)); } return new SubstructureIdentifier(pdbId, ranges); } @@ -126,47 +127,46 @@ public SubstructureIdentifier toCanonical() { public Structure reduce(Structure input) throws StructureException { return toCanonical().reduce(input); } + /** * Load the structure from the URL * @return null */ @Override - public Structure loadStructure(AtomCache cache) throws StructureException, - IOException { + public Structure loadStructure(AtomCache cache) throws StructureException, IOException { StructureFiletype format = StructureFiletype.UNKNOWN; // Use user-specified format try { Map params = parseQuery(url); - if(params.containsKey(FORMAT_PARAM)) { + if (params.containsKey(FORMAT_PARAM)) { String formatStr = params.get(FORMAT_PARAM); - format = StructureIO.guessFiletype("."+formatStr); + format = StructureIO.guessFiletype("." + formatStr); } } catch (UnsupportedEncodingException e) { - logger.error("Unable to decode URL "+url,e); + logger.error("Unable to decode URL {}", url, e); } // Guess format from extension - if(format == StructureFiletype.UNKNOWN) { + if (format == StructureFiletype.UNKNOWN) { format = StructureIO.guessFiletype(url.getPath()); } switch(format) { - case CIF: - return StructureConverter.fromURL(url); - default: - case PDB: - // pdb file based parsing - - PDBFileReader reader = new PDBFileReader(cache.getPath()); - reader.setFetchBehavior(cache.getFetchBehavior()); - reader.setObsoleteBehavior(cache.getObsoleteBehavior()); - reader.setFileParsingParameters(cache.getFileParsingParams()); - return reader.getStructure(url); + case CIF: case BCIF: + return StructureConverter.fromURL(url); + case MMTF: + return MmtfActions.readFromInputStream(url.openStream()); + default: case PDB: + // pdb file based parsing + PDBFileReader reader = new PDBFileReader(cache.getPath()); + reader.setFetchBehavior(cache.getFetchBehavior()); + reader.setObsoleteBehavior(cache.getObsoleteBehavior()); + reader.setFileParsingParameters(cache.getFileParsingParams()); + return reader.getStructure(url); } } - /** * Recognizes PDB IDs that occur at the beginning of name followed by some * delimiter. @@ -175,7 +175,7 @@ public Structure loadStructure(AtomCache cache) throws StructureException, */ public static String guessPDBID(String name) { Matcher match = PDBID_REGEX.matcher(name); - if(match.matches()) { + if (match.matches()) { return match.group(1).toUpperCase(); } else { // Give up if doesn't match @@ -191,22 +191,22 @@ public static String guessPDBID(String name) { * @throws UnsupportedEncodingException */ private static Map parseQuery(URL url) throws UnsupportedEncodingException { - Map params = new LinkedHashMap(); + Map params = new LinkedHashMap<>(); String query = url.getQuery(); - if( query == null || query.isEmpty()) { + if (query == null || query.isEmpty()) { // empty query return params; } String[] pairs = url.getQuery().split("&"); - for(String pair: pairs) { + for (String pair : pairs) { int i = pair.indexOf("="); String key = pair; - if(i > 0) { + if (i > 0) { key = URLDecoder.decode(pair.substring(0, i), "UTF-8"); } String value = null; - if(i > 0 && pair.length() > i+1) { - value = URLDecoder.decode(pair.substring(i+1), "UTF-8"); + if(i > 0 && pair.length() > i + 1) { + value = URLDecoder.decode(pair.substring(i + 1), "UTF-8"); } // note that this uses the last instance if a parameter is specified multiple times params.put(key.toLowerCase(), value); diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/align/util/AtomCache.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/align/util/AtomCache.java index cc0220da07..4181792515 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/align/util/AtomCache.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/align/util/AtomCache.java @@ -33,6 +33,7 @@ import org.biojava.nbio.structure.cath.CathDatabase; import org.biojava.nbio.structure.cath.CathDomain; import org.biojava.nbio.structure.cath.CathFactory; +import org.biojava.nbio.structure.io.BcifFileReader; import org.biojava.nbio.structure.io.CifFileReader; import org.biojava.nbio.structure.io.FileParsingParameters; import org.biojava.nbio.structure.io.LocalPDBDirectory.FetchBehavior; @@ -61,7 +62,6 @@ * @since 3.0 */ public class AtomCache { - private static final Logger logger = LoggerFactory.getLogger(AtomCache.class); /** @@ -73,25 +73,20 @@ public class AtomCache { public static final String BIOL_ASSEMBLY_IDENTIFIER = "BIO:"; public static final String CHAIN_NR_SYMBOL = ":"; public static final String CHAIN_SPLIT_SYMBOL = "."; - public static final String UNDERSCORE = "_"; private static final String FILE_SEPARATOR = System.getProperty("file.separator"); protected FileParsingParameters params; - private FetchBehavior fetchBehavior; private ObsoleteBehavior obsoleteBehavior; - private String cachePath; // make sure IDs are loaded uniquely - private Collection currentlyLoading = Collections.synchronizedCollection(new TreeSet()); + private final Collection currentlyLoading = Collections.synchronizedCollection(new TreeSet<>()); private String path; - - private boolean useMmCif; - private boolean useMmtf; + private StructureFiletype filetype = StructureFiletype.BCIF; /** * Default AtomCache constructor. @@ -122,9 +117,7 @@ public AtomCache(String pdbFilePath) { * @param cachePath */ public AtomCache(String pdbFilePath, String cachePath) { - - logger.debug("Initialising AtomCache with pdbFilePath={}, cachePath={}",pdbFilePath, cachePath); - + logger.debug("Initialising AtomCache with pdbFilePath={}, cachePath={}", pdbFilePath, cachePath); if (!pdbFilePath.endsWith(FILE_SEPARATOR)) { pdbFilePath += FILE_SEPARATOR; } @@ -144,9 +137,7 @@ public AtomCache(String pdbFilePath, String cachePath) { currentlyLoading.clear(); params = new FileParsingParameters(); - setUseMmCif(false); - setUseMmtf(true); - + setFiletype(StructureFiletype.BCIF); } /** @@ -159,11 +150,7 @@ public AtomCache(UserConfiguration config) { this(config.getPdbFilePath(), config.getCacheFilePath()); fetchBehavior = config.getFetchBehavior(); obsoleteBehavior = config.getObsoleteBehavior(); - useMmCif = config.getFileFormat().equals( UserConfiguration.MMCIF_FORMAT ); - - if ( useMmCif) - useMmtf = false; - + filetype = config.getStructureFiletype(); } /** @@ -180,21 +167,20 @@ public AtomCache(UserConfiguration config) { public Atom[] getAtoms(String name) throws IOException, StructureException { return getAtoms(new StructureName(name)); } - public Atom[] getAtoms(StructureIdentifier name) throws IOException, StructureException { - Atom[] atoms = null; + public Atom[] getAtoms(StructureIdentifier name) throws IOException, StructureException { + Atom[] atoms; // System.out.println("loading " + name); Structure s = getStructure(name); - atoms = StructureTools.getAtomCAArray(s); /* * synchronized (cache){ cache.put(name, atoms); } */ - return atoms; } + /** * Returns the representative atoms for the provided name. * See {@link #getStructure(String)} for supported naming conventions. @@ -210,17 +196,14 @@ public Atom[] getRepresentativeAtoms(String name) throws IOException, StructureE } public Atom[] getRepresentativeAtoms(StructureIdentifier name) throws IOException, StructureException { - - Atom[] atoms = null; + Atom[] atoms; Structure s = getStructure(name); - atoms = StructureTools.getRepresentativeAtomArray(s); /* * synchronized (cache){ cache.put(name, atoms); } */ - return atoms; } @@ -246,7 +229,6 @@ public Atom[] getRepresentativeAtoms(StructureIdentifier name) throws IOExceptio */ public Structure getBiologicalAssembly(String pdbId, int bioAssemblyId, boolean multiModel) throws StructureException, IOException { - if (bioAssemblyId < 0) { throw new StructureException("bioAssemblyID must be nonnegative: " + pdbId + " bioAssemblyId " + bioAssemblyId); @@ -262,14 +244,14 @@ public Structure getBiologicalAssembly(String pdbId, int bioAssemblyId, boolean getFileParsingParams().setParseBioAssembly(prevIsParseBioAssembly); - if (asymUnit.getPDBHeader() == null || asymUnit.getPDBHeader().getBioAssemblies()==null) { + if (asymUnit.getPDBHeader() == null || asymUnit.getPDBHeader().getBioAssemblies() == null) { logger.info("No bioassembly information found for {}, returning asymmetric unit as biological assembly", pdbId); return asymUnit; } // 0 ... asym unit - if ( bioAssemblyId == 0) { - logger.info("Requested biological assembly 0 for PDB id "+pdbId+", returning asymmetric unit"); + if (bioAssemblyId == 0) { + logger.info("Requested biological assembly 0 for PDB id {}, returning asymmetric unit", pdbId); return asymUnit; } // does it exist? @@ -281,20 +263,18 @@ public Structure getBiologicalAssembly(String pdbId, int bioAssemblyId, boolean asymUnit.getPDBHeader().getBioAssemblies().get(bioAssemblyId).getTransforms(); - if ( transformations == null || transformations.size() == 0){ - + if (transformations == null || transformations.size() == 0) { throw new StructureException("Could not load transformations to recreate biological assembly id " + bioAssemblyId + " of " + pdbId); - } BiologicalAssemblyBuilder builder = new BiologicalAssemblyBuilder(); // if we use mmcif or mmtf, then we need to pass useAsymIds=true boolean useAsymIds = false; - if (useMmCif) useAsymIds = true; - if (useMmtf) useAsymIds = true; + if (filetype == StructureFiletype.CIF || filetype == StructureFiletype.BCIF || filetype == StructureFiletype.MMTF) { + useAsymIds = true; + } return builder.rebuildQuaternaryStructure(asymUnit, transformations, useAsymIds, multiModel); - } /** @@ -312,7 +292,6 @@ public Structure getBiologicalAssembly(String pdbId, int bioAssemblyId, boolean * @since 4.2 */ public Structure getBiologicalAssembly(String pdbId, boolean multiModel) throws StructureException, IOException { - boolean prevIsParseBioAssembly = getFileParsingParams().isParseBioAssembly(); if (!getFileParsingParams().isParseBioAssembly()) { @@ -320,11 +299,10 @@ public Structure getBiologicalAssembly(String pdbId, boolean multiModel) throws } Structure asymUnit = getStructureForPdbId(pdbId); - getFileParsingParams().setParseBioAssembly(prevIsParseBioAssembly); - if (asymUnit.getPDBHeader() == null || asymUnit.getPDBHeader().getBioAssemblies()==null) { + if (asymUnit.getPDBHeader() == null || asymUnit.getPDBHeader().getBioAssemblies() == null) { logger.info("No bioassembly information found for {}, returning asymmetric unit as biological assembly", pdbId); return asymUnit; } @@ -340,20 +318,18 @@ public Structure getBiologicalAssembly(String pdbId, boolean multiModel) throws asymUnit.getPDBHeader().getBioAssemblies().get(bioAssemblyId).getTransforms(); - if ( transformations == null || transformations.size() == 0){ - + if (transformations == null || transformations.size() == 0) { throw new StructureException("Could not load transformations to recreate biological assembly id " + bioAssemblyId + " of " + pdbId); - } BiologicalAssemblyBuilder builder = new BiologicalAssemblyBuilder(); // if we use mmcif or mmtf, then we need to pass useAsymIds=true boolean useAsymIds = false; - if (useMmCif) useAsymIds = true; - if (useMmtf) useAsymIds = true; + if (filetype == StructureFiletype.CIF || filetype == StructureFiletype.BCIF || filetype == StructureFiletype.MMTF) { + useAsymIds = true; + } return builder.rebuildQuaternaryStructure(asymUnit, transformations, useAsymIds, multiModel); - } /** @@ -367,7 +343,6 @@ public Structure getBiologicalAssembly(String pdbId, boolean multiModel) throws * @since 5.0 */ public List getBiologicalAssemblies(String pdbId, boolean multiModel) throws StructureException, IOException { - List assemblies = new ArrayList<>(); boolean prevIsParseBioAssembly = getFileParsingParams().isParseBioAssembly(); @@ -377,25 +352,21 @@ public List getBiologicalAssemblies(String pdbId, boolean multiModel) } Structure asymUnit = getStructureForPdbId(pdbId); - getFileParsingParams().setParseBioAssembly(prevIsParseBioAssembly); - - if (asymUnit.getPDBHeader() == null || asymUnit.getPDBHeader().getBioAssemblies()==null) { + if (asymUnit.getPDBHeader() == null || asymUnit.getPDBHeader().getBioAssemblies() == null) { logger.info("No bioassembly information found for {}, returning asymmetric unit as the only biological assembly", pdbId); assemblies.add(asymUnit); return assemblies; } - for (int bioAssemblyId : asymUnit.getPDBHeader().getBioAssemblies().keySet()) { List transformations = asymUnit.getPDBHeader().getBioAssemblies().get(bioAssemblyId).getTransforms(); - - if ( transformations == null || transformations.size() == 0){ - - logger.info("Could not load transformations to recreate biological assembly id " + bioAssemblyId + " of " + pdbId+". Assembly id will be missing in biological assemblies."); + if (transformations == null || transformations.size() == 0) { + logger.info("Could not load transformations to recreate biological assembly id {} of {}. Assembly " + + "id will be missing in biological assemblies.", bioAssemblyId, pdbId); continue; } @@ -403,8 +374,9 @@ public List getBiologicalAssemblies(String pdbId, boolean multiModel) // if we use mmcif or mmtf, then we need to pass useAsymIds=true boolean useAsymIds = false; - if (useMmCif) useAsymIds = true; - if (useMmtf) useAsymIds = true; + if (filetype == StructureFiletype.CIF || filetype == StructureFiletype.BCIF || filetype == StructureFiletype.MMTF) { + useAsymIds = true; + } Structure s = builder.rebuildQuaternaryStructure(asymUnit, transformations, useAsymIds, multiModel); assemblies.add(s); } @@ -483,7 +455,6 @@ public String getPath() { */ public Structure getStructure(String name) throws IOException, StructureException { StructureName structureName = new StructureName(name); - return getStructure(structureName); } @@ -552,7 +523,6 @@ public Structure getStructureForDomain(ScopDomain domain, ScopDatabase scopDatab */ public Structure getStructureForDomain(ScopDomain domain, ScopDatabase scopDatabase, boolean strictLigandHandling) throws IOException, StructureException { - String pdbId = domain.getPdbId(); Structure fullStructure = getStructureForPdbId(pdbId); Structure structure = domain.reduce(fullStructure); @@ -569,13 +539,12 @@ public Structure getStructureForDomain(ScopDomain domain, ScopDatabase scopDatab rrs = ResidueRangeAndLength.parseMultiple(domain.getRanges(), map); } for (Chain chain : fullStructure.getNonPolyChains()) { - if (!structure.hasPdbChain(chain.getName())) { continue; // we can't do anything with a chain our domain } Chain newChain; - if (! structure.hasNonPolyChain(chain.getId())) { + if (!structure.hasNonPolyChain(chain.getId())) { newChain = new ChainImpl(); newChain.setId(chain.getId()); newChain.setName(chain.getName()); @@ -584,6 +553,7 @@ public Structure getStructureForDomain(ScopDomain domain, ScopDatabase scopDatab } else { newChain = structure.getNonPolyChain(chain.getId()); } + List ligands = StructureTools.filterLigands(chain.getAtomGroups()); for (Group group : ligands) { boolean shouldContain = true; @@ -598,9 +568,7 @@ public Structure getStructureForDomain(ScopDomain domain, ScopDatabase scopDatab boolean alreadyContains = newChain.getAtomGroups().contains(group); // we don't want to add duplicate // ligands if (shouldContain && !alreadyContains) { - newChain.addGroup(group); - } } } @@ -619,7 +587,6 @@ public Structure getStructureForDomain(ScopDomain domain, ScopDatabase scopDatab structure.getPDBHeader().setDescription(header.toString()); return structure; - } /** @@ -665,7 +632,6 @@ public void setFileParsingParams(FileParsingParameters params) { this.params = params; } - /** * [Optional] This method changes the behavior when obsolete entries * are requested. Current behaviors are: @@ -712,6 +678,7 @@ public ObsoleteBehavior getObsoleteBehavior() { public FetchBehavior getFetchBehavior() { return fetchBehavior; } + /** * Set the behavior for fetching files from the server * @param fetchBehavior @@ -731,45 +698,23 @@ public void setPath(String path) { } /** - * @return the useMmCif + * Returns the currently active file type that will be parsed. + * @return a StructureFiletype */ - public boolean isUseMmCif() { - return useMmCif; + public StructureFiletype getFiletype() { + return filetype; } /** - * @param useMmCif - * the useMmCif to set - */ - public void setUseMmCif(boolean useMmCif) { - this.useMmCif = useMmCif; - // Either way the user wants to use PDB or MMCIF - this.useMmtf = false; - } - - /** - * Set whether to use mmtf. - * @param useMmtf the input boolean to set - */ - public void setUseMmtf(boolean useMmtf) { - this.useMmtf = useMmtf; - if(useMmtf){ - useMmCif=false; - } - - } - - /** Returns useMmtf flag - * - * @return true if will load data via mmtf file format + * Set the file type that will be parsed. + * @param filetype a StructureFiletype */ - public boolean isUseMmtf(){ - return this.useMmtf; + public void setFiletype(StructureFiletype filetype) { + this.filetype = filetype; } private boolean checkLoading(String name) { return currentlyLoading.contains(name); - } /** @@ -784,17 +729,15 @@ public Structure getStructureForCathDomain(StructureName structureName) throws I * Returns a {@link Structure} corresponding to the CATH identifier supplied in {@code structureName}, using the specified {@link CathDatabase}. */ public Structure getStructureForCathDomain(StructureName structureName, CathDatabase cathInstall) throws IOException, StructureException { - CathDomain cathDomain = cathInstall.getDomainByCathId(structureName.getIdentifier()); Structure s = getStructureForPdbId(cathDomain.getIdentifier()); Structure n = cathDomain.reduce(s); // add the ligands of the chain... - Chain newChain = n.getPolyChainByPDB(structureName.getChainId()); List origChains = s.getNonPolyChainsByPDB(structureName.getChainId()); - for ( Chain origChain : origChains) { + for (Chain origChain : origChains) { List ligands = origChain.getAtomGroups(); for (Group g : ligands) { @@ -815,7 +758,6 @@ protected void flagLoading(String name) { } protected void flagLoadingFinished(String name) { - currentlyLoading.remove(name); } @@ -827,10 +769,10 @@ protected void flagLoadingFinished(String name) { * @throws StructureException */ public Structure getStructureForPdbId(String pdbId) throws IOException, StructureException { - if(pdbId == null) + if (pdbId == null) return null; - if(pdbId.length() != 4) { - throw new StructureException("Unrecognized PDB ID: "+pdbId); + if (pdbId.length() != 4) { + throw new StructureException("Unrecognized PDB ID: " + pdbId); } while (checkLoading(pdbId)) { // waiting for loading to be finished... @@ -840,22 +782,22 @@ public Structure getStructureForPdbId(String pdbId) throws IOException, Structur } catch (InterruptedException e) { logger.error(e.getMessage()); } - } - Structure s; - if (useMmtf) { - logger.debug("loading from mmtf"); - s = loadStructureFromMmtfByPdbId(pdbId); - } - else if (useMmCif) { - logger.debug("loading from mmcif"); - s = loadStructureFromCifByPdbId(pdbId); - } else { - logger.debug("loading from pdb"); - s = loadStructureFromPdbByPdbId(pdbId); + switch (filetype) { + case CIF: + logger.debug("loading from mmcif"); + return loadStructureFromCifByPdbId(pdbId); + case BCIF: + logger.debug("loading from bcif"); + return loadStructureFromBcifByPdbId(pdbId); + case MMTF: + logger.debug("loading from mmtf"); + return loadStructureFromMmtfByPdbId(pdbId); + case PDB: default: + logger.debug("loading from pdb"); + return loadStructureFromPdbByPdbId(pdbId); } - return s; } /** @@ -869,12 +811,10 @@ private Structure loadStructureFromMmtfByPdbId(String pdbId) throws IOException MMTFFileReader reader = new MMTFFileReader(); reader.setFetchBehavior(fetchBehavior); reader.setObsoleteBehavior(obsoleteBehavior); - Structure structure = reader.getStructureById(pdbId.toLowerCase()); - return structure; + return reader.getStructureById(pdbId.toLowerCase()); } - protected Structure loadStructureFromCifByPdbId(String pdbId) throws IOException, StructureException { - + protected Structure loadStructureFromCifByPdbId(String pdbId) throws IOException { logger.debug("Loading structure {} from mmCIF file {}.", pdbId, path); Structure s; flagLoading(pdbId); @@ -891,8 +831,24 @@ protected Structure loadStructureFromCifByPdbId(String pdbId) throws IOException return s; } - protected Structure loadStructureFromPdbByPdbId(String pdbId) throws IOException, StructureException { + protected Structure loadStructureFromBcifByPdbId(String pdbId) throws IOException { + logger.debug("Loading structure {} from BinaryCIF file {}.", pdbId, path); + Structure s; + flagLoading(pdbId); + try { + BcifFileReader reader = new BcifFileReader(path); + reader.setFetchBehavior(fetchBehavior); + reader.setObsoleteBehavior(obsoleteBehavior); + reader.setFileParsingParameters(params); + s = reader.getStructureById(pdbId.toLowerCase()); + } finally { + flagLoadingFinished(pdbId); + } + + return s; + } + protected Structure loadStructureFromPdbByPdbId(String pdbId) throws IOException { logger.debug("Loading structure {} from PDB file {}.", pdbId, path); Structure s; flagLoading(pdbId); @@ -904,12 +860,10 @@ protected Structure loadStructureFromPdbByPdbId(String pdbId) throws IOException reader.setFileParsingParameters(params); s = reader.getStructureById(pdbId.toLowerCase()); - } finally { flagLoadingFinished(pdbId); } return s; } - } diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/align/util/UserConfiguration.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/align/util/UserConfiguration.java index e23f8e6db1..ebcf3aaba6 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/align/util/UserConfiguration.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/align/util/UserConfiguration.java @@ -19,6 +19,7 @@ package org.biojava.nbio.structure.align.util; +import org.biojava.nbio.structure.StructureFiletype; import org.biojava.nbio.structure.align.ce.StartupParameters; import org.biojava.nbio.structure.io.LocalPDBDirectory.FetchBehavior; import org.biojava.nbio.structure.io.LocalPDBDirectory.ObsoleteBehavior; @@ -33,19 +34,17 @@ import java.util.Map; import java.util.concurrent.atomic.AtomicBoolean; - -/** A container to persist config to the file system +/** + * A container to persist config to the file system * * @author Andreas Prlic - * */ -public class UserConfiguration -{ - +public class UserConfiguration { private static final Logger logger = LoggerFactory.getLogger(UserConfiguration.class); public static final String PDB_FORMAT = "PDB"; - public static final String MMCIF_FORMAT = "mmCif"; + public static final String MMCIF_FORMAT = "cif"; + public static final String BINARY_CIF = "bcif"; public static final String MMTF_FORMAT = "mmtf"; public static final String TMP_DIR = "java.io.tmpdir"; @@ -63,8 +62,7 @@ public class UserConfiguration private String fileFormat; - private static AtomicBoolean warningShown = new AtomicBoolean(false); - + private static final AtomicBoolean warningShown = new AtomicBoolean(false); /** * Default UserConfiguration: @@ -98,66 +96,51 @@ public UserConfiguration(){ // note that in initCacheFilePath, we set to the provided one (if readable) or to the same as pdbFilePath cacheFilePath = initCacheFilePath(); - fileFormat = MMTF_FORMAT; + fileFormat = BINARY_CIF; } private String initPdbFilePath() { - String path = null; - String propertyName = PDB_DIR; - String userProvidedDir = System.getProperty(propertyName); - if ( userProvidedDir != null && !userProvidedDir.trim().isEmpty()) { - + if (userProvidedDir != null && !userProvidedDir.trim().isEmpty()) { path = userProvidedDir; logger.debug("Read PDB dir from system property {}: {}", propertyName, path); File f = new File(path); if (!f.isDirectory()) { - logger.warn( - "Provided path {} (with system property {}) is not a directory. Using system's temp directory instead {}", - path, propertyName, System.getProperty(TMP_DIR)); + logger.warn("Provided path {} (with system property {}) is not a directory. Using system's temp " + + "directory instead {}", path, propertyName, System.getProperty(TMP_DIR)); path = System.getProperty(TMP_DIR); } else if (!f.canWrite()) { - logger.warn( - "Provided path {} (with system property {}) is not writable. Will not be able to write cached files.", - path, propertyName); + logger.warn("Provided path {} (with system property {}) is not writable. Will not be able to write " + + "cached files.", path, propertyName); // we don't require the PDB_DIR to be writable, so that it can be used with a pre-rsynced dir // thus if not writable, we only warn and go ahead using it } - - } else { Map env = System.getenv(); - - if( env.containsKey(propertyName) && !env.get(propertyName).trim().isEmpty()) { + if (env.containsKey(propertyName) && !env.get(propertyName).trim().isEmpty()) { path = env.get(propertyName); logger.debug("Read dir from environment variable {}: {}", propertyName, path); File f = new File(path); if (!f.isDirectory()) { - logger.warn( - "Provided path {} (with environment variable {}) is not a directory. Using system's temp directory instead {}", - path, propertyName, System.getProperty(TMP_DIR)); + logger.warn("Provided path {} (with environment variable {}) is not a directory. Using system's " + + "temp directory instead {}", path, propertyName, System.getProperty(TMP_DIR)); path = System.getProperty(TMP_DIR); } else if (!f.canWrite()) { - logger.warn( - "Provided path {} (with environment variable {}) is not writable. Will not be able to write cached files", - path, propertyName); + logger.warn("Provided path {} (with environment variable {}) is not writable. Will not be able " + + "to write cached files", path, propertyName); // we don't require the PDB_DIR to be writable, so that it can be used with a pre-rsynced dir // thus if not writable, we only warn and go ahead using it } - } else { path = System.getProperty(TMP_DIR); - if ( ! warningShown.get()) { - - logger.warn("Could not read dir from system property {} or environment variable {}, " - + "using system's temp directory {}", - propertyName, propertyName, path); - + if (! warningShown.get()) { + logger.warn("Could not read dir from system property {} or environment variable {}, " + + "using system's temp directory {}", propertyName, propertyName, path); warningShown.set(true); } @@ -165,95 +148,79 @@ private String initPdbFilePath() { } } - if ( ! path.endsWith(lineSplit) ) + if (!path.endsWith(lineSplit)) { path = path + lineSplit; + } return path; - } private String initCacheFilePath() { - String path = null; - String propertyName = PDB_CACHE_DIR; - String userProvidedDir = System.getProperty(propertyName); - if ( userProvidedDir != null ) { - + if (userProvidedDir != null) { path = userProvidedDir; logger.debug("Read cache dir from system property {}: {}", propertyName, path); File f = new File(path); if (!f.isDirectory()) { - logger.warn( - "Provided path {} (with system property {}) is not a directory. Using system's temp directory instead {}", - path, propertyName, System.getProperty(TMP_DIR)); + logger.warn("Provided path {} (with system property {}) is not a directory. Using system's temp " + + "directory instead {}", path, propertyName, System.getProperty(TMP_DIR)); path = System.getProperty(TMP_DIR); } else if (!f.canWrite()) { - logger.warn( - "Provided path {} (with system property {}) is not writable. Using system's temp directory instead {}", - path, propertyName, System.getProperty(TMP_DIR)); + logger.warn("Provided path {} (with system property {}) is not writable. Using system's temp " + + "directory instead {}", path, propertyName, System.getProperty(TMP_DIR)); path = System.getProperty(TMP_DIR); System.setProperty(propertyName,path); } - - } else { Map env = System.getenv(); - if( env.containsKey(propertyName)) { + if (env.containsKey(propertyName)) { path = env.get(propertyName); logger.debug("Read dir from environment variable {}: {}", propertyName, path); File f = new File(path); if (!f.isDirectory()) { - logger.warn( - "Provided path {} (with environment variable {}) is not a directory. Using system's temp directory instead {}", - path, propertyName, System.getProperty(TMP_DIR)); + logger.warn("Provided path {} (with environment variable {}) is not a directory. Using system's " + + "temp directory instead {}", path, propertyName, System.getProperty(TMP_DIR)); path = System.getProperty(TMP_DIR); } else if (!f.canWrite()) { - logger.warn( - "Provided path {} (with environment variable {}) is not writable. Using system's temp directory instead {}", - path, propertyName, System.getProperty(TMP_DIR)); + logger.warn("Provided path {} (with environment variable {}) is not writable. Using system's " + + "temp directory instead {}", path, propertyName, System.getProperty(TMP_DIR)); path = System.getProperty(TMP_DIR); } - } else { // NOTE in case of not provided, then it is set to same as pdbFilePath // as PDB_DIR is not checked for being writable, we have to do that check here in case if (new File(pdbFilePath).canWrite()){ path = pdbFilePath; - logger.info("Could not read cache dir from system property {} or environment variable {}, " - + "using PDB directory instead {}", - propertyName, propertyName, path); + logger.info("Could not read cache dir from system property {} or environment variable {}, " + + "using PDB directory instead {}", propertyName, propertyName, path); System.setProperty(propertyName,path); - } else { path = System.getProperty(TMP_DIR); logger.warn("Could not read cache dir from system property {} or environment variable {}, " + "and PDB directory {} is not writable. Using system's temp directory instead {}", propertyName, propertyName, pdbFilePath, path); System.setProperty(propertyName,path); - } } } - if ( ! path.endsWith(lineSplit) ) + if (!path.endsWith(lineSplit)) { path = path + lineSplit; + } return path; - } - public String getPdbFilePath() - { + public String getPdbFilePath() { return pdbFilePath; } - public void setPdbFilePath(String pdbFilePath) - { + public void setPdbFilePath(String pdbFilePath) { this.pdbFilePath = pdbFilePath; } @@ -281,24 +248,22 @@ public void setObsoleteBehavior(ObsoleteBehavior obsoleteBehavior) { this.obsoleteBehavior = obsoleteBehavior; } - /** convert Configuration to an XML file so it can be serialized + /** + * convert Configuration to an XML file so it can be serialized * * @param pw * @return XMLWriter * @throws IOException */ - public XMLWriter toXML(PrintWriter pw) - throws IOException - { - - XMLWriter xw = new PrettyXMLWriter( pw); - + public XMLWriter toXML(PrintWriter pw) throws IOException { + XMLWriter xw = new PrettyXMLWriter(pw); toXML(xw); - return xw ; - } + return xw; + } - /** convert Configuration to an XML file so it can be serialized + /** + * convert Configuration to an XML file so it can be serialized * add to an already existing xml file. * * @param xw the XML writer to use @@ -306,10 +271,7 @@ public XMLWriter toXML(PrintWriter pw) * @throws IOException * @see org.biojava.nbio.structure.align.webstart.ConfigXMLHandler */ - - public XMLWriter toXML(XMLWriter xw) - throws IOException - { + public XMLWriter toXML(XMLWriter xw) throws IOException { xw.printRaw(""); //xw.printRaw(""); xw.openTag("JFatCatConfig"); @@ -317,18 +279,18 @@ public XMLWriter toXML(XMLWriter xw) xw.openTag("PDBFILEPATH"); // we don;t serialize the tempdir... String tempdir = System.getProperty(TMP_DIR); - if (! pdbFilePath.equals(tempdir)) + if (!pdbFilePath.equals(tempdir)) { xw.attribute("path", pdbFilePath); + } - xw.attribute("fetchBehavior", fetchBehavior+""); - xw.attribute("obsoleteBehavior", obsoleteBehavior+""); + xw.attribute("fetchBehavior", fetchBehavior + ""); + xw.attribute("obsoleteBehavior", obsoleteBehavior + ""); xw.attribute("fileFormat", fileFormat); xw.closeTag("PDBFILEPATH"); xw.closeTag("JFatCatConfig"); return xw ; - - } + } public static UserConfiguration fromStartupParams(StartupParameters params) { UserConfiguration config = new UserConfiguration(); @@ -349,14 +311,22 @@ public void setFileFormat (String fileFormat){ this.fileFormat = fileFormat; } - public String getFileFormat() - { + public String getFileFormat() { return fileFormat; } - - - - - + public StructureFiletype getStructureFiletype() { + switch (fileFormat) { + case MMCIF_FORMAT: + return StructureFiletype.CIF; + case BINARY_CIF: + return StructureFiletype.BCIF; + case MMTF_FORMAT: + return StructureFiletype.MMTF; + case PDB_FORMAT: + return StructureFiletype.PDB; + default: + return StructureFiletype.BCIF; + } + } } diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemComp.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemComp.java index 7109d60204..f550d82a96 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemComp.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemComp.java @@ -228,7 +228,8 @@ public String getOneLetterCode() { } public void setOneLetterCode(String oneLetterCode) { - this.oneLetterCode = oneLetterCode; + // backwards compatibility that treats missing olc as ? + this.oneLetterCode = "".equals(oneLetterCode) ? "?" : oneLetterCode; setStandardFlag(); } diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmtf/MmtfUtils.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmtf/MmtfUtils.java index 0f1394424a..53d4c6e42f 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmtf/MmtfUtils.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmtf/MmtfUtils.java @@ -45,6 +45,7 @@ import org.biojava.nbio.structure.PDBCrystallographicInfo; import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.StructureException; +import org.biojava.nbio.structure.StructureFiletype; import org.biojava.nbio.structure.StructureIO; import org.biojava.nbio.structure.align.util.AtomCache; import org.biojava.nbio.structure.chem.ChemComp; @@ -80,7 +81,7 @@ public class MmtfUtils { public static AtomCache setUpBioJava() { // Set up the atom cache etc AtomCache cache = new AtomCache(); - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.MMTF); FileParsingParameters params = cache.getFileParsingParams(); params.setCreateAtomBonds(true); params.setAlignSeqRes(true); @@ -101,7 +102,7 @@ public static AtomCache setUpBioJava() { public static AtomCache setUpBioJava(String extraUrl) { // Set up the atom cache etc AtomCache cache = new AtomCache(); - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.MMTF); FileParsingParameters params = cache.getFileParsingParams(); params.setCreateAtomBonds(true); params.setAlignSeqRes(true); diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/Test2JA5.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/Test2JA5.java index 8d42461300..eb7008d0cb 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/Test2JA5.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/Test2JA5.java @@ -41,7 +41,7 @@ public void test2JA5() throws IOException, StructureException { fileParsingParameters.setHeaderOnly(false); // Need header only off to have chains to match. AtomCache cache = new AtomCache(); - cache.setUseMmCif(false); + cache.setFiletype(StructureFiletype.PDB); cache.setFileParsingParams(fileParsingParameters); StructureIO.setAtomCache(cache); @@ -70,7 +70,7 @@ public void test2JA5noHeader() throws IOException, StructureException { fileParsingParameters.setHeaderOnly(true); AtomCache cache = new AtomCache(); - cache.setUseMmCif(false); + cache.setFiletype(StructureFiletype.PDB); cache.setFileParsingParams(fileParsingParameters); StructureIO.setAtomCache(cache); diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/TestAltLocs.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/TestAltLocs.java index 3aa86bacd0..ef9f830ae1 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/TestAltLocs.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/TestAltLocs.java @@ -47,7 +47,7 @@ public class TestAltLocs { public void testAltLocParsing() throws StructureException, IOException{ AtomCache cache = new AtomCache(); - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.CIF); Structure s = cache.getStructure("2CI1"); Chain a = s.getPolyChainByPDB("A"); @@ -210,7 +210,7 @@ private void ensureAllAtomsSameAltCode(Group groupInputAltLocGroup, Group inputM public void test1AAC() throws IOException, StructureException{ AtomCache cache = new AtomCache(); - cache.setUseMmCif(false); + cache.setFiletype(StructureFiletype.PDB); StructureIO.setAtomCache(cache); Structure s = StructureIO.getStructure("1AAC"); @@ -221,7 +221,7 @@ public void test1AAC() throws IOException, StructureException{ testCBAtomInMainGroup(g); cache = new AtomCache(); - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.CIF); StructureIO.setAtomCache(cache); Structure s1 = cache.getStructure("1AAC"); @@ -262,7 +262,7 @@ public void test3PIUpdb() throws IOException, StructureException{ StructureIO.setAtomCache(cache); - cache.setUseMmCif(false); + cache.setFiletype(StructureFiletype.PDB); Structure structure = StructureIO.getStructure("3PIU"); @@ -428,7 +428,7 @@ public void test4CUPBonds() throws IOException, StructureException{ StructureIO.setAtomCache(cache); - cache.setUseMmCif(false); + cache.setFiletype(StructureFiletype.PDB); Structure structure = StructureIO.getStructure("4CUP"); @@ -489,7 +489,7 @@ public void test3PIUmmcif() throws IOException, StructureException{ StructureIO.setAtomCache(cache); - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.CIF); Structure structure = StructureIO.getStructure("3PIU"); @@ -549,7 +549,7 @@ public void test3U7Tmmcif() throws IOException, StructureException{ StructureIO.setAtomCache(cache); - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.CIF); FileParsingParameters params = new FileParsingParameters(); params.setAlignSeqRes(true); cache.setFileParsingParams(params); diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/TestAtomCache.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/TestAtomCache.java index d3c61130ae..17c6836a4f 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/TestAtomCache.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/TestAtomCache.java @@ -156,7 +156,7 @@ public void testObsoleteId() throws StructureException, IOException { cache.setObsoleteBehavior(ObsoleteBehavior.THROW_EXCEPTION); // OBSOLETE PDB; should throw an exception - cache.setUseMmCif(false); + cache.setFiletype(StructureFiletype.PDB); cache.getStructure("1HHB"); } @@ -168,13 +168,13 @@ public void testFetchCurrent1CMW() throws IOException, StructureException { cache.setObsoleteBehavior(ObsoleteBehavior.FETCH_CURRENT); // OBSOLETE PDB; should throw an exception - cache.setUseMmCif(false); + cache.setFiletype(StructureFiletype.PDB); try { cache.getStructure("1CMW"); fail("Obsolete structure should throw exception"); } catch(IOException e) {} - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.CIF); try { cache.getStructure("1CMW"); fail("Obsolete structure should throw exception"); @@ -188,11 +188,11 @@ public void testFetchCurrent1HHB() throws IOException, StructureException { cache.setFetchBehavior(FetchBehavior.FETCH_FILES); cache.setObsoleteBehavior(ObsoleteBehavior.FETCH_CURRENT); - cache.setUseMmCif(false); + cache.setFiletype(StructureFiletype.PDB); Structure s = cache.getStructure("1HHB"); assertEquals("Failed to get the current ID for 1HHB.","4HHB",s.getPDBCode()); - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.CIF); s = cache.getStructure("1HHB"); assertEquals("Failed to get the current ID for 1HHB.","4HHB",s.getPDBCode()); } @@ -204,15 +204,14 @@ public void testFetchObsolete() throws IOException, StructureException { cache.setObsoleteBehavior(ObsoleteBehavior.FETCH_OBSOLETE); Structure s; - cache.setUseMmtf(false); - cache.setUseMmCif(false); + cache.setFiletype(StructureFiletype.PDB); s = cache.getStructure("1CMW"); assertEquals("Failed to get OBSOLETE file 1CMW.","1CMW", s.getPDBCode()); s = cache.getStructure("1HHB"); assertEquals("Failed to get OBSOLETE file 1HHB.","1HHB", s.getPDBCode()); - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.CIF); s = cache.getStructure("1CMW"); assertEquals("Failed to get OBSOLETE file 1CMW.","1CMW", s.getPDBCode()); @@ -229,35 +228,32 @@ public void testSettingFileParsingType(){ //test defaults - // by default we either use mmtf or mmcif, but not both. - assertNotEquals(cache.isUseMmtf(), cache.isUseMmCif()); - // first is mmtf, second is mmcif testFlags(cache,true,false); // now change the values - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.CIF); testFlags(cache,false,true); - cache.setUseMmtf(true); + cache.setFiletype(StructureFiletype.MMTF); testFlags(cache,true,false); // this sets to use PDB! - cache.setUseMmCif(false); + cache.setFiletype(StructureFiletype.PDB); testFlags(cache,false,false); // back to defaults - cache.setUseMmtf(true); + cache.setFiletype(StructureFiletype.MMTF); testFlags(cache,true,false); // back to parsing PDB - cache.setUseMmtf(false); + cache.setFiletype(StructureFiletype.PDB); testFlags(cache,false,false); @@ -274,10 +270,10 @@ public void testSettingFileParsingType(){ */ private void testFlags(AtomCache cache ,boolean useMmTf, boolean useMmCif) { - assertEquals("flag for parsing mmtf is set to " + cache.isUseMmtf() + " but should be " + useMmTf, - cache.isUseMmtf(), useMmTf); - assertEquals("flag for parsing mmcif is set to " + cache.isUseMmCif() + " but should be set to " + useMmCif, - cache.isUseMmCif(), useMmCif); + assertEquals("flag for parsing mmtf is set to " + cache.getFiletype() + " but should be " + useMmTf, + cache.getFiletype() == StructureFiletype.MMTF, useMmTf); + assertEquals("flag for parsing mmcif is set to " + cache.getFiletype() + " but should be set to " + useMmCif, + cache.getFiletype() == StructureFiletype.CIF, useMmCif); diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/TestBond.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/TestBond.java index 9a3022d0a1..cd64006861 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/TestBond.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/TestBond.java @@ -52,7 +52,7 @@ public static void setUp() { cache = new AtomCache(); - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.CIF); FileParsingParameters params = cache.getFileParsingParams(); diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/TestCloning.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/TestCloning.java index ac8b728d93..4ce757bc91 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/TestCloning.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/TestCloning.java @@ -191,7 +191,7 @@ private void compareCloned(final Structure s, final Structure c) throws Structur public void testBondCloning() throws IOException, StructureException { final AtomCache cache = new AtomCache(); - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.CIF); final FileParsingParameters params = cache.getFileParsingParams(); params.setCreateAtomBonds(true); diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/TestEntityResIndexMapping.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/TestEntityResIndexMapping.java index f0926364b9..401a42f2cb 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/TestEntityResIndexMapping.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/TestEntityResIndexMapping.java @@ -54,7 +54,7 @@ public void test1B8G() throws IOException, StructureException { StructureIO.setAtomCache(cache); - cache.setUseMmCif(false); + cache.setFiletype(StructureFiletype.PDB); Structure s = StructureIO.getStructure("1B8G"); Chain chainA = s.getPolyChainByPDB("A"); @@ -76,7 +76,7 @@ public void test1SMT() throws IOException, StructureException { StructureIO.setAtomCache(cache); - cache.setUseMmCif(false); + cache.setFiletype(StructureFiletype.PDB); Structure s = StructureIO.getStructure("1SMT"); Chain chainA = s.getPolyChainByPDB("A"); diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/TestExperimentalTechniques.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/TestExperimentalTechniques.java index 25436297a6..6ef6224f8d 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/TestExperimentalTechniques.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/TestExperimentalTechniques.java @@ -39,9 +39,9 @@ public void test6F2Q() throws IOException, StructureException { StructureIO.setAtomCache(cache); - cache.setUseMmCif(false); + cache.setFiletype(StructureFiletype.PDB); Structure sPdb = StructureIO.getStructure("6F2Q"); - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.CIF); Structure sCif = StructureIO.getStructure("6F2Q"); comparePdbToCif(sPdb, sCif); @@ -69,9 +69,9 @@ public void test3ZPK() throws IOException, StructureException { StructureIO.setAtomCache(cache); - cache.setUseMmCif(false); + cache.setFiletype(StructureFiletype.PDB); Structure sPdb = StructureIO.getStructure("3ZPK"); - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.CIF); Structure sCif = StructureIO.getStructure("3ZPK"); comparePdbToCif(sPdb, sCif); @@ -99,9 +99,9 @@ public void test2B6O() throws IOException, StructureException { StructureIO.setAtomCache(cache); - cache.setUseMmCif(false); + cache.setFiletype(StructureFiletype.PDB); Structure sPdb = StructureIO.getStructure("2B6O"); - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.CIF); Structure sCif = StructureIO.getStructure("2B6O"); comparePdbToCif(sPdb, sCif); @@ -129,9 +129,9 @@ public void test4CSO() throws IOException, StructureException { StructureIO.setAtomCache(cache); - cache.setUseMmCif(false); + cache.setFiletype(StructureFiletype.PDB); Structure sPdb = StructureIO.getStructure("4CSO"); - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.CIF); Structure sCif = StructureIO.getStructure("4CSO"); comparePdbToCif(sPdb, sCif); diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/TestLoadStructureFromURL.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/TestLoadStructureFromURL.java index c7cf3ede33..fb182535f1 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/TestLoadStructureFromURL.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/TestLoadStructureFromURL.java @@ -50,8 +50,7 @@ public void testLoadStructureFromURL() throws IOException, StructureException{ f.mkdir(); } AtomCache c = new AtomCache(f.toString(), f.toString()); - c.setUseMmCif(false); - c.setUseMmtf(false); + c.setFiletype(StructureFiletype.PDB); // fetch a random small structure c.getStructure("1znf"); diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/TestParsingCalcium.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/TestParsingCalcium.java index 783ca74dba..c3212fac8c 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/TestParsingCalcium.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/TestParsingCalcium.java @@ -46,7 +46,7 @@ public void testCalciumParsing() throws StructureException, IOException { AtomCache cache = new AtomCache(); Structure s = cache.getStructure(pdbID); - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.CIF); Structure m = cache.getStructure(pdbID); diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/TestStructureCrossReferences.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/TestStructureCrossReferences.java index d2c5b2d0b8..ebcea45acf 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/TestStructureCrossReferences.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/TestStructureCrossReferences.java @@ -50,7 +50,7 @@ public void testCrossReferencesMmCif() throws IOException, StructureException { boolean emptySeqRes = true; AtomCache cache = new AtomCache(); - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.CIF); FileParsingParameters params = new FileParsingParameters(); params.setAlignSeqRes(false); // Store empty seqres groups. @@ -73,7 +73,7 @@ public void testCrossReferencesMmCifAlignSeqRes() throws IOException, StructureE boolean emptySeqRes = false; AtomCache cache = new AtomCache(); - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.CIF); FileParsingParameters params = new FileParsingParameters(); params.setAlignSeqRes(true); @@ -97,7 +97,7 @@ public void testCrossReferencesMmCifAlignSeqRes() throws IOException, StructureE public void testCrossReferencesPdb() throws IOException, StructureException { boolean emptySeqRes = true; AtomCache cache = new AtomCache(); - cache.setUseMmCif(false); + cache.setFiletype(StructureFiletype.PDB); FileParsingParameters params = new FileParsingParameters(); params.setAlignSeqRes(false); // Store empty seqres groups @@ -119,7 +119,7 @@ public void testCrossReferencesPdb() throws IOException, StructureException { public void testCrossReferencesPdbAlignSeqRes() throws IOException, StructureException { boolean emptySeqRes = false; AtomCache cache = new AtomCache(); - cache.setUseMmCif(false); + cache.setFiletype(StructureFiletype.PDB); FileParsingParameters params = new FileParsingParameters(); params.setAlignSeqRes(true); diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/align/util/AtomCacheTest.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/align/util/AtomCacheTest.java index 0882ae08a1..1b30f95ad6 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/align/util/AtomCacheTest.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/align/util/AtomCacheTest.java @@ -47,6 +47,7 @@ import org.biojava.nbio.structure.ResidueRangeAndLength; import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.StructureException; +import org.biojava.nbio.structure.StructureFiletype; import org.biojava.nbio.structure.StructureIO; import org.biojava.nbio.structure.StructureIdentifier; import org.biojava.nbio.structure.StructureTools; @@ -372,7 +373,7 @@ public void testEmptyChemComp() throws IOException, StructureException { try { cache.setPath(tmpCache.toString()); cache.setCachePath(tmpCache.toString()); - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.CIF); ChemCompGroupFactory.setChemCompProvider(new DownloadChemCompProvider(tmpCache.toString())); // Create an empty chemcomp @@ -431,7 +432,7 @@ public void testEmptyGZChemComp() throws IOException, StructureException { try { cache.setPath(tmpCache.toString()); cache.setCachePath(tmpCache.toString()); - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.CIF); ChemCompGroupFactory.setChemCompProvider(new DownloadChemCompProvider(tmpCache.toString())); diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestDifficultMmCIFFiles.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestDifficultMmCIFFiles.java index 81695918a9..690f877f08 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestDifficultMmCIFFiles.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestDifficultMmCIFFiles.java @@ -42,6 +42,7 @@ import org.biojava.nbio.structure.ResidueNumber; import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.StructureException; +import org.biojava.nbio.structure.StructureFiletype; import org.biojava.nbio.structure.StructureIO; import org.biojava.nbio.structure.align.util.AtomCache; import org.biojava.nbio.structure.io.cif.StructureConverter; @@ -77,7 +78,7 @@ public void test2KSA() throws IOException, StructureException { StructureIO.setAtomCache(cache); - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.CIF); Structure sCif = StructureIO.getStructure("2KSA"); assertNotNull(sCif); @@ -105,7 +106,7 @@ public void test2BI6() throws IOException, StructureException { StructureIO.setAtomCache(cache); - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.CIF); Structure sCif = StructureIO.getStructure("2BI6"); assertNotNull(sCif); @@ -134,10 +135,10 @@ public void test1GQO() throws IOException, StructureException { params.setParseBioAssembly(true); StructureIO.setAtomCache(cache); - cache.setUseMmCif(false); + cache.setFiletype(StructureFiletype.PDB); Structure sPdb = StructureIO.getStructure("1GQO"); - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.CIF); Structure sCif = StructureIO.getStructure("1GQO"); assertNotNull(sCif); @@ -168,7 +169,7 @@ public void test1GQO() throws IOException, StructureException { @Test public void testResidueNumbers() throws IOException, StructureException { AtomCache cache = new AtomCache(); - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.CIF); Structure s = cache.getStructure("2PTC"); Chain c = s.getChainByIndex(0); @@ -248,7 +249,7 @@ public void test2KLI() throws IOException, StructureException { StructureIO.setAtomCache(cache); - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.CIF); Structure sCif = StructureIO.getStructure("2KLI"); assertNotNull(sCif); diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestHardBioUnits.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestHardBioUnits.java index 6362dc2a84..b205bd2140 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestHardBioUnits.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestHardBioUnits.java @@ -24,6 +24,7 @@ import org.biojava.nbio.structure.Chain; import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.StructureException; +import org.biojava.nbio.structure.StructureFiletype; import org.biojava.nbio.structure.StructureIO; import org.biojava.nbio.structure.StructureTools; import org.biojava.nbio.structure.align.util.AtomCache; @@ -56,8 +57,7 @@ public void test4A1Immcif() throws IOException, StructureException { int biolAssemblyNr = 2; AtomCache cache = new AtomCache(); - cache.setUseMmCif(true); - cache.setUseMmtf(false); + cache.setFiletype(StructureFiletype.CIF); StructureIO.setAtomCache(cache); Structure bioAssembly = StructureIO.getBiologicalAssembly(pdbId,biolAssemblyNr); diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestHeaderOnly.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestHeaderOnly.java index f447953a32..7d246fc25e 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestHeaderOnly.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestHeaderOnly.java @@ -31,6 +31,7 @@ import org.biojava.nbio.structure.Group; import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.StructureException; +import org.biojava.nbio.structure.StructureFiletype; import org.biojava.nbio.structure.StructureIO; import org.biojava.nbio.structure.align.util.AtomCache; import org.biojava.nbio.structure.chem.ChemComp; @@ -60,7 +61,7 @@ public void testHeaderOnly() throws StructureException, IOException { // Test 1: with PDB AtomCache cache = new AtomCache(); - cache.setUseMmCif(false); + cache.setFiletype(StructureFiletype.PDB); FileParsingParameters params = new FileParsingParameters(); params.setHeaderOnly(true); @@ -74,7 +75,7 @@ public void testHeaderOnly() throws StructureException, IOException { Assert.assertEquals(false, doSeqResHaveAtoms(sPDB)); // Test 2: with mmCIF - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.CIF); Structure sCIF = StructureIO.getStructure(pdbID); Assert.assertEquals(false, doSeqResHaveAtoms(sCIF)); @@ -95,7 +96,7 @@ public void testAlignSeqres() throws StructureException, IOException { // Test 1: with PDB AtomCache cache = new AtomCache(); - cache.setUseMmCif(false); + cache.setFiletype(StructureFiletype.PDB); FileParsingParameters params = new FileParsingParameters(); params.setHeaderOnly(false); @@ -109,7 +110,7 @@ public void testAlignSeqres() throws StructureException, IOException { check1REPChainC(sPDB); // Check particular residues to be aligned. // Test 2: with mmCIF - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.CIF); Structure sCIF = StructureIO.getStructure(pdbID); Assert.assertEquals(true, doSeqResHaveAtoms(sCIF)); 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 31d4b86dd8..6187f2127b 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 @@ -40,6 +40,7 @@ import org.biojava.nbio.structure.ResidueNumber; import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.StructureException; +import org.biojava.nbio.structure.StructureFiletype; import org.biojava.nbio.structure.StructureIO; import org.biojava.nbio.structure.StructureImpl; import org.biojava.nbio.structure.StructureTools; @@ -77,7 +78,7 @@ private static void testRoundTrip(String pdbId) throws IOException, StructureExc StructureIO.setAtomCache(cache); - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.CIF); FileParsingParameters params = new FileParsingParameters(); params.setAlignSeqRes(true); diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestMMcifOrganismParsing.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestMMcifOrganismParsing.java index 71733aabaa..31c309f68e 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestMMcifOrganismParsing.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestMMcifOrganismParsing.java @@ -28,6 +28,7 @@ import org.biojava.nbio.structure.EntityType; import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.StructureException; +import org.biojava.nbio.structure.StructureFiletype; import org.biojava.nbio.structure.StructureIO; import org.biojava.nbio.structure.align.util.AtomCache; import org.junit.BeforeClass; @@ -48,7 +49,7 @@ public class TestMMcifOrganismParsing { public static void setUp() throws Exception { AtomCache cache = new AtomCache(); - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.CIF); StructureIO.setAtomCache(cache); } diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestNonDepositedFiles.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestNonDepositedFiles.java index b0c7c8fe55..a604fffcaa 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestNonDepositedFiles.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestNonDepositedFiles.java @@ -36,6 +36,7 @@ import org.biojava.nbio.structure.EntityType; import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.StructureException; +import org.biojava.nbio.structure.StructureFiletype; import org.biojava.nbio.structure.StructureIO; import org.biojava.nbio.structure.align.util.AtomCache; import org.biojava.nbio.structure.io.cif.StructureConverter; @@ -117,7 +118,7 @@ public void test1B8G() throws IOException, StructureException { StructureIO.setAtomCache(cache); - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.CIF); Structure s = StructureIO.getStructure("1B8G"); System.out.println("Chains from full deposited file: "); diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestParseMmCIFFeatures.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestParseMmCIFFeatures.java index f0c10f5e17..f4d5a6d9d2 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestParseMmCIFFeatures.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestParseMmCIFFeatures.java @@ -31,6 +31,7 @@ import org.biojava.nbio.structure.Site; import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.StructureException; +import org.biojava.nbio.structure.StructureFiletype; import org.biojava.nbio.structure.StructureIO; import org.biojava.nbio.structure.align.util.AtomCache; import org.junit.Test; @@ -45,7 +46,7 @@ public void testSSBond()throws IOException, StructureException { StructureIO.setAtomCache(cache); - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.CIF); FileParsingParameters params = new FileParsingParameters(); params.setCreateAtomBonds(true); cache.setFileParsingParams(params); @@ -77,7 +78,7 @@ public void testSSBondAltLocs() throws IOException, StructureException { StructureIO.setAtomCache(cache); - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.CIF); FileParsingParameters params = new FileParsingParameters(); params.setCreateAtomBonds(true); cache.setFileParsingParams(params); @@ -147,7 +148,7 @@ public void testSites()throws IOException, StructureException { StructureIO.setAtomCache(cache); - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.CIF); Structure sCif = StructureIO.getStructure("4HHB"); assertNotNull(sCif); @@ -181,7 +182,7 @@ public void testSites1a4w()throws IOException, StructureException { StructureIO.setAtomCache(cache); - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.CIF); Structure sCif = StructureIO.getStructure("1A4W"); assertNotNull(sCif); diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestParseMmCIFLigands.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestParseMmCIFLigands.java index 2a997118f2..76d7d74a3d 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestParseMmCIFLigands.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestParseMmCIFLigands.java @@ -29,6 +29,7 @@ import org.biojava.nbio.structure.Group; import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.StructureException; +import org.biojava.nbio.structure.StructureFiletype; import org.biojava.nbio.structure.StructureIO; import org.biojava.nbio.structure.align.util.AtomCache; import org.biojava.nbio.structure.chem.ChemCompGroupFactory; @@ -50,10 +51,10 @@ public class TestParseMmCIFLigands { public void testLigandConnections()throws IOException, StructureException { AtomCache cache = new AtomCache(); // This needs MMCIF - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.CIF); StructureIO.setAtomCache(cache); - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.CIF); ChemCompGroupFactory.setChemCompProvider(new DownloadChemCompProvider()); FileParsingParameters params = cache.getFileParsingParams(); @@ -93,10 +94,10 @@ private int countBondedAtomsInLigandGroups(Structure s){ public void testMultipleConformations()throws IOException, StructureException { AtomCache cache = new AtomCache(); // This needs MMCIF - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.CIF); StructureIO.setAtomCache(cache); - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.CIF); ChemCompGroupFactory.setChemCompProvider(new DownloadChemCompProvider()); FileParsingParameters params = cache.getFileParsingParams(); diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestParseOnAsymId.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestParseOnAsymId.java index 448aed4750..fda734d668 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestParseOnAsymId.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestParseOnAsymId.java @@ -27,6 +27,7 @@ import org.biojava.nbio.structure.Chain; import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.StructureException; +import org.biojava.nbio.structure.StructureFiletype; import org.biojava.nbio.structure.StructureIO; import org.biojava.nbio.structure.align.util.AtomCache; import org.junit.Test; @@ -39,7 +40,7 @@ public class TestParseOnAsymId { public void test4cup() throws IOException, StructureException { AtomCache cache = new AtomCache(); - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.CIF); FileParsingParameters params = cache.getFileParsingParams(); cache.setFileParsingParams(params); diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestQuaternaryStructureProviders.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestQuaternaryStructureProviders.java index c2d4ec71ad..0b67e66aaa 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestQuaternaryStructureProviders.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestQuaternaryStructureProviders.java @@ -59,7 +59,7 @@ public void test5LDH() throws IOException, StructureException{ boolean gotException = false; try { AtomCache cache = new AtomCache(); - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.CIF); StructureIO.setAtomCache(cache); StructureIO.getBiologicalAssembly("5LDH",3); } catch (StructureException e) { @@ -72,7 +72,7 @@ public void test5LDH() throws IOException, StructureException{ gotException = false; try { AtomCache cache = new AtomCache(); - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.CIF); StructureIO.setAtomCache(cache); StructureIO.getBiologicalAssembly("5LDH",2); } catch (StructureException e) { @@ -198,7 +198,7 @@ private void comparePdbVsMmcif(String pdbId, int bioMolecule, int mmSize) throws private Structure getPdbBioAssembly(String pdbId, int bioMolecule, boolean multiModel) throws IOException, StructureException { // get bio assembly from PDB file AtomCache cache = new AtomCache(); - cache.setUseMmCif(false); + cache.setFiletype(StructureFiletype.PDB); StructureIO.setAtomCache(cache); Structure pdbS = StructureIO.getBiologicalAssembly(pdbId, bioMolecule, multiModel); return pdbS; @@ -207,7 +207,7 @@ private Structure getPdbBioAssembly(String pdbId, int bioMolecule, boolean multi private Structure getMmcifBioAssembly(String pdbId, int bioMolecule, boolean multiModel) throws IOException, StructureException { // get bio assembly from mmcif file AtomCache cache = new AtomCache(); - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.CIF); StructureIO.setAtomCache(cache); Structure mmcifS = StructureIO.getBiologicalAssembly(pdbId, bioMolecule, multiModel); return mmcifS; diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestTitleParsing.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestTitleParsing.java index 6b0be0663e..40b1368027 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestTitleParsing.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestTitleParsing.java @@ -22,6 +22,7 @@ import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.StructureException; +import org.biojava.nbio.structure.StructureFiletype; import org.biojava.nbio.structure.StructureIO; import org.biojava.nbio.structure.align.util.AtomCache; import org.junit.Test; @@ -48,9 +49,9 @@ public void test2W6E() throws IOException, StructureException { StructureIO.setAtomCache(cache); - cache.setUseMmCif(false); + cache.setFiletype(StructureFiletype.PDB); Structure sPdb = StructureIO.getStructure("2W6E"); - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.CIF); Structure sCif = StructureIO.getStructure("2W6E"); diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestWriteLargeCoordinatePDB.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestWriteLargeCoordinatePDB.java index 78137f73e2..0588d54d01 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestWriteLargeCoordinatePDB.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestWriteLargeCoordinatePDB.java @@ -28,6 +28,7 @@ import org.biojava.nbio.structure.Group; import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.StructureException; +import org.biojava.nbio.structure.StructureFiletype; import org.biojava.nbio.structure.StructureIO; import org.biojava.nbio.structure.align.util.AtomCache; import org.junit.Test; @@ -41,7 +42,7 @@ public class TestWriteLargeCoordinatePDB { public void TestWrite5D9Q() throws IOException, StructureException { AtomCache cache = new AtomCache(); - cache.setUseMmCif(false); + cache.setFiletype(StructureFiletype.PDB); FileParsingParameters params = new FileParsingParameters(); params.setHeaderOnly(false); diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmcif/TestChemCompProvider.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmcif/TestChemCompProvider.java index 89af60dc65..cf818c5c18 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmcif/TestChemCompProvider.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmcif/TestChemCompProvider.java @@ -46,7 +46,6 @@ public class TestChemCompProvider { // Short test with bad ligand name (QNA is bogus) final String DNAexample = - "ATOM 1 H MET A 1 11.756 -15.759 11.647 1.00 7.95\n" + "ATOM 2 N MET A 1 12.461 -16.373 11.329 1.00 7.95\n" + "ATOM 3 CA MET A 1 12.297 -17.782 11.674 1.00 7.95\n" + @@ -181,7 +180,7 @@ public void testNormalStructure() throws StructureException, IOException { long startTime = System.currentTimeMillis(); StructureIO.getStructure("4HHM"); long finishTime = System.currentTimeMillis(); - s_logger.info("ZipChemComp time: "+(finishTime-startTime)+ " ms"); + s_logger.info("ZipChemComp time: {} ms", finishTime - startTime); // Not wanted here for testing, but useful for cleaning up downloaded .cif.gz files. // ZipChemCompProvider.purgeTempFiles(pdbdir.toString()); @@ -189,7 +188,6 @@ public void testNormalStructure() throws StructureException, IOException { @Test public void testGetOneLetterCode() throws Exception { - String oneLetter; oneLetter = ChemCompGroupFactory.getOneLetterCode(ChemCompGroupFactory.getChemComp("ALA")); @@ -202,7 +200,5 @@ public void testGetOneLetterCode() throws Exception { // multiparent case, we should return ? oneLetter = ChemCompGroupFactory.getOneLetterCode(ChemCompGroupFactory.getChemComp("OIM")); assertEquals("?", oneLetter); - } - } diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmcif/TestEntityNameAndType.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmcif/TestEntityNameAndType.java index 94a9a18fa5..9f1fea5eb4 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmcif/TestEntityNameAndType.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmcif/TestEntityNameAndType.java @@ -28,6 +28,7 @@ import org.biojava.nbio.structure.EntityInfo; import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.StructureException; +import org.biojava.nbio.structure.StructureFiletype; import org.biojava.nbio.structure.StructureIO; import org.biojava.nbio.structure.align.util.AtomCache; import org.biojava.nbio.structure.chem.ChemCompGroupFactory; @@ -46,7 +47,7 @@ public void testEntityId() throws IOException, StructureException { // Set up the atom cache to parse on Internal chain id AtomCache cache = new AtomCache(); - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.CIF); FileParsingParameters params = cache.getFileParsingParams(); DownloadChemCompProvider cc = new DownloadChemCompProvider(); diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmcif/TestParseInternalChainId.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmcif/TestParseInternalChainId.java index 0132d29de4..8c4084745d 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmcif/TestParseInternalChainId.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmcif/TestParseInternalChainId.java @@ -26,6 +26,7 @@ import org.biojava.nbio.structure.Chain; import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.StructureException; +import org.biojava.nbio.structure.StructureFiletype; import org.biojava.nbio.structure.align.util.AtomCache; import org.junit.Test; import static org.junit.Assert.*; @@ -40,7 +41,7 @@ public void test2I13() throws IOException, StructureException { AtomCache cache = new AtomCache(); - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.CIF); Structure s = cache.getStructure("2I13"); diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmcif/TestParseMmcifHeader.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmcif/TestParseMmcifHeader.java index 52c76422ec..c0d2423d35 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmcif/TestParseMmcifHeader.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmcif/TestParseMmcifHeader.java @@ -31,6 +31,7 @@ import org.biojava.nbio.structure.PDBHeader; import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.StructureException; +import org.biojava.nbio.structure.StructureFiletype; import org.biojava.nbio.structure.StructureIO; import org.biojava.nbio.structure.align.util.AtomCache; import org.junit.Test; @@ -51,7 +52,7 @@ public class TestParseMmcifHeader { public void testRfactors() throws IOException, StructureException { AtomCache atomCache = new AtomCache(); - atomCache.setUseMmCif(true); + atomCache.setFiletype(StructureFiletype.CIF); Structure structure = atomCache.getStructure("4cup"); diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmtf/TestBondFinding.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmtf/TestBondFinding.java index 9e850585b6..e400465ecb 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmtf/TestBondFinding.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmtf/TestBondFinding.java @@ -20,6 +20,7 @@ */ package org.biojava.nbio.structure.io.mmtf; +import org.biojava.nbio.structure.StructureFiletype; import org.biojava.nbio.structure.chem.ChemCompGroupFactory; import org.biojava.nbio.structure.chem.DownloadChemCompProvider; import org.junit.Test; @@ -81,7 +82,7 @@ public int getInterBonds(String pdbId) throws IOException, StructureException { // Download parameters AtomCache cache = new AtomCache(); - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.CIF); cache.setFetchBehavior(FetchBehavior.FETCH_FILES); FileParsingParameters params = cache.getFileParsingParams(); params.setCreateAtomBonds(true); diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmtf/TestMmtfRoundTrip.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmtf/TestMmtfRoundTrip.java index 96f9dd8c43..04e4cc93df 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmtf/TestMmtfRoundTrip.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmtf/TestMmtfRoundTrip.java @@ -37,6 +37,7 @@ import org.biojava.nbio.structure.Group; import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.StructureException; +import org.biojava.nbio.structure.StructureFiletype; import org.biojava.nbio.structure.StructureIO; import org.biojava.nbio.structure.align.util.AtomCache; import org.biojava.nbio.structure.chem.ChemCompGroupFactory; @@ -73,7 +74,7 @@ public void testRoundTrip() throws IOException, StructureException { FileParsingParameters params = new FileParsingParameters(); params.setParseBioAssembly(true); cache.setFileParsingParams(params); - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.CIF); StructureIO.setAtomCache(cache); diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmtf/TestMmtfStructureReader.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmtf/TestMmtfStructureReader.java index 0bed40a6be..acf23d4f88 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmtf/TestMmtfStructureReader.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmtf/TestMmtfStructureReader.java @@ -9,6 +9,7 @@ import org.biojava.nbio.structure.Group; import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.StructureException; +import org.biojava.nbio.structure.StructureFiletype; import org.biojava.nbio.structure.StructureIO; import org.biojava.nbio.structure.align.util.AtomCache; import org.biojava.nbio.structure.chem.ChemCompGroupFactory; @@ -89,8 +90,7 @@ public void checkNonStandardAminoSeqresGroupsPopulated() throws StructureExcepti AtomCache cache = new AtomCache(); FileParsingParameters params = new FileParsingParameters(); cache.setFileParsingParams(params); - cache.setUseMmCif(false); - cache.setUseMmtf(true); + cache.setFiletype(StructureFiletype.MMTF); StructureIO.setAtomCache(cache); diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/xtal/TestCrystalInfo.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/xtal/TestCrystalInfo.java index 501d6eb2af..775588a2ae 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/xtal/TestCrystalInfo.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/xtal/TestCrystalInfo.java @@ -45,13 +45,13 @@ public void test1NMR() throws IOException, StructureException { StructureIO.setAtomCache(cache); - cache.setUseMmCif(false); + cache.setFiletype(StructureFiletype.PDB); Structure s1 = StructureIO.getStructure("1NMR"); assertFalse(s1.isCrystallographic()); assertTrue(s1.isNmr()); assertEquals(s1.getPDBHeader().getExperimentalTechniques().iterator().next(),ExperimentalTechnique.SOLUTION_NMR); - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.CIF); Structure s2 = StructureIO.getStructure("1NMR"); assertFalse(s2.isCrystallographic()); assertTrue(s2.isNmr()); @@ -69,14 +69,14 @@ public void test1B8G() throws IOException, StructureException { StructureIO.setAtomCache(cache); - cache.setUseMmCif(false); + cache.setFiletype(StructureFiletype.PDB); Structure s1 = StructureIO.getStructure("1B8G"); assertTrue(s1.isCrystallographic()); assertFalse(s1.isNmr()); assertEquals(s1.getPDBHeader().getExperimentalTechniques().iterator().next(),ExperimentalTechnique.XRAY_DIFFRACTION); - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.CIF); Structure s2 = StructureIO.getStructure("1B8G"); assertTrue(s2.isCrystallographic()); assertFalse(s2.isNmr()); @@ -95,7 +95,7 @@ public void test4M7P() throws IOException, StructureException { StructureIO.setAtomCache(cache); - cache.setUseMmCif(false); + cache.setFiletype(StructureFiletype.PDB); Structure s1 = StructureIO.getStructure("4M7P"); assertTrue(s1.isCrystallographic()); assertFalse(s1.isNmr()); @@ -103,7 +103,7 @@ public void test4M7P() throws IOException, StructureException { assertEquals(s1.getPDBHeader().getExperimentalTechniques().iterator().next(),ExperimentalTechnique.XRAY_DIFFRACTION); - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.CIF); Structure s2 = StructureIO.getStructure("4M7P"); assertTrue(s2.isCrystallographic()); assertFalse(s2.isNmr()); @@ -123,7 +123,7 @@ public void test2MBQ() throws IOException, StructureException { StructureIO.setAtomCache(cache); - cache.setUseMmCif(false); + cache.setFiletype(StructureFiletype.PDB); Structure s1 = StructureIO.getStructure("2MBQ"); assertFalse(s1.isCrystallographic()); assertTrue(s1.isNmr()); @@ -131,7 +131,7 @@ public void test2MBQ() throws IOException, StructureException { assertEquals(s1.getPDBHeader().getExperimentalTechniques().iterator().next(),ExperimentalTechnique.SOLUTION_NMR); - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.CIF); Structure s2 = StructureIO.getStructure("2MBQ"); assertFalse(s2.isCrystallographic()); assertTrue(s2.isNmr()); diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/xtal/TestInterfaceClustering.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/xtal/TestInterfaceClustering.java index af80c99ae1..bb5fe0b74c 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/xtal/TestInterfaceClustering.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/xtal/TestInterfaceClustering.java @@ -32,6 +32,7 @@ import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.StructureException; +import org.biojava.nbio.structure.StructureFiletype; import org.biojava.nbio.structure.StructureIO; import org.biojava.nbio.structure.align.util.AtomCache; import org.biojava.nbio.structure.asa.GroupAsa; @@ -55,7 +56,7 @@ public void test3DDO() throws IOException, StructureException { FileParsingParameters params = new FileParsingParameters(); params.setAlignSeqRes(true); cache.setFileParsingParams(params); - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.CIF); StructureIO.setAtomCache(cache); @@ -103,7 +104,7 @@ public void test1AUY() throws IOException, StructureException { FileParsingParameters params = new FileParsingParameters(); params.setAlignSeqRes(true); cache.setFileParsingParams(params); - cache.setUseMmCif(true); + cache.setFiletype(StructureFiletype.CIF); StructureIO.setAtomCache(cache); From e7f563d78c31227d4f09736f5e6c6050da2d6a7d Mon Sep 17 00:00:00 2001 From: JonStargaryen Date: Mon, 25 Jan 2021 13:13:45 -0800 Subject: [PATCH 020/599] fix bcif download --- .../org/biojava/nbio/structure/io/LocalPDBDirectory.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/LocalPDBDirectory.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/LocalPDBDirectory.java index 61735ecfa6..72ff6dee38 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/LocalPDBDirectory.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/LocalPDBDirectory.java @@ -517,8 +517,11 @@ private File downloadStructure(String pdbId, String pathOnServer, boolean obsole String ftp; - if (getFilename(pdbId).endsWith(".mmtf.gz")){ + String filename = getFilename(pdbId); + if (filename.endsWith(".mmtf.gz")){ ftp = CodecUtils.getMmtfEntryUrl(pdbId, true, false); + } else if (filename.endsWith(".bcif") || filename.endsWith(".bcif.gz")) { + ftp = "https://models.rcsb.org/" + filename; } else { ftp = String.format("%s%s/%s/%s", serverName, pathOnServer, pdbId.substring(1,3).toLowerCase(), getFilename(pdbId)); From 0c00caca270976872b4423d0d344e00bd1e8fe28 Mon Sep 17 00:00:00 2001 From: JonStargaryen Date: Mon, 25 Jan 2021 15:59:53 -0800 Subject: [PATCH 021/599] fix chemcomp type --- .../java/org/biojava/nbio/structure/chem/ResidueType.java | 4 ++++ .../nbio/structure/io/mmcif/TestEntityNameAndType.java | 3 +++ 2 files changed, 7 insertions(+) diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ResidueType.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ResidueType.java index ddcaac453c..33390df136 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ResidueType.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ResidueType.java @@ -88,6 +88,10 @@ public PolymerType getPolymerType() { * @return */ public static ResidueType getResidueTypeFromString(String chem_comp_type) { + if (chem_comp_type == null) { + return null; + } + // Almost all calls to this method are for L-peptide linking. Use this knowledge for a shortcut. if (chem_comp_type.equalsIgnoreCase(lPeptideLinking.chem_comp_type)) { return lPeptideLinking; diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmcif/TestEntityNameAndType.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmcif/TestEntityNameAndType.java index 9f1fea5eb4..88b5c3cc40 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmcif/TestEntityNameAndType.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmcif/TestEntityNameAndType.java @@ -23,6 +23,7 @@ import static org.junit.Assert.assertArrayEquals; import java.io.IOException; +import java.util.Arrays; import org.biojava.nbio.structure.Chain; import org.biojava.nbio.structure.EntityInfo; @@ -97,6 +98,8 @@ public void testEntityId() throws IOException, StructureException { assertArrayEquals(descriptionInformation, testDescInfo); assertArrayEquals(typeInformation, testTypeInfo); // Now check these work too + System.out.println(Arrays.toString(geneSourceSciName)); + System.out.println(Arrays.toString(testGeneSourceSciName)); assertArrayEquals(geneSourceSciName, testGeneSourceSciName); assertArrayEquals(geneSourceTaxId, testGeneSourceTaxId); assertArrayEquals(hostOrganismSciName, testHostOrganismSciName); From 85b6c6b3e7794f38a2cf916c865e8981163f9028 Mon Sep 17 00:00:00 2001 From: JonStargaryen Date: Tue, 26 Jan 2021 10:39:34 -0800 Subject: [PATCH 022/599] chem comp parsing errors & missing crystal translation --- .../chem/DownloadChemCompProvider.java | 11 ++++-- .../structure/io/cif/ChemCompConverter.java | 1 - .../io/cif/StructureConsumerImpl.java | 3 ++ .../biojava/nbio/structure/TestAtomCache.java | 36 ++++++------------- 4 files changed, 22 insertions(+), 29 deletions(-) diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/DownloadChemCompProvider.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/DownloadChemCompProvider.java index 71a17b7292..e250a1ebd8 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/DownloadChemCompProvider.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/DownloadChemCompProvider.java @@ -5,6 +5,7 @@ import org.biojava.nbio.structure.align.util.UserConfiguration; import org.biojava.nbio.structure.io.LocalPDBDirectory; import org.biojava.nbio.structure.io.cif.ChemCompConverter; +import org.rcsb.cif.ParsingException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -217,8 +218,14 @@ public ChemComp getChemComp(String recordName) { if (haveFile) { String filename = getLocalFileName(recordName); try { - ChemicalComponentDictionary dict = ChemCompConverter.fromPath(Paths.get(filename)); - ChemComp chemComp = dict.getChemComp(recordName); + ChemComp chemComp; + try { + ChemicalComponentDictionary dict = ChemCompConverter.fromPath(Paths.get(filename)); + chemComp = dict.getChemComp(recordName); + } catch (ParsingException e) { + // happens for corrupt files + chemComp = null; + } // May be null if the file was corrupt. Fall back on ReducedChemCompProvider in that case if (chemComp != null) { diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/ChemCompConverter.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/ChemCompConverter.java index d234d27dc4..aec300e717 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/ChemCompConverter.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/ChemCompConverter.java @@ -1,6 +1,5 @@ package org.biojava.nbio.structure.io.cif; -import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.chem.ChemicalComponentDictionary; import org.biojava.nbio.structure.io.FileParsingParameters; import org.rcsb.cif.CifIO; diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/StructureConsumerImpl.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/StructureConsumerImpl.java index d858536847..346ac12d41 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/StructureConsumerImpl.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/StructureConsumerImpl.java @@ -1377,14 +1377,17 @@ private void setStructNcsOps() { operator.setElement(0, 0, structNcsOper.getMatrix11().get(rowIndex)); operator.setElement(0, 1, structNcsOper.getMatrix12().get(rowIndex)); operator.setElement(0, 2, structNcsOper.getMatrix13().get(rowIndex)); + operator.setElement(0, 3, structNcsOper.getVector1().get(rowIndex)); operator.setElement(1, 0, structNcsOper.getMatrix21().get(rowIndex)); operator.setElement(1, 1, structNcsOper.getMatrix22().get(rowIndex)); operator.setElement(1, 2, structNcsOper.getMatrix23().get(rowIndex)); + operator.setElement(1, 3, structNcsOper.getVector2().get(rowIndex)); operator.setElement(2, 0, structNcsOper.getMatrix31().get(rowIndex)); operator.setElement(2, 1, structNcsOper.getMatrix32().get(rowIndex)); operator.setElement(2, 2, structNcsOper.getMatrix33().get(rowIndex)); + operator.setElement(2, 3, structNcsOper.getVector3().get(rowIndex)); operator.setElement(3, 0, 0); operator.setElement(3, 1, 0); diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/TestAtomCache.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/TestAtomCache.java index 17c6836a4f..5de3eca23a 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/TestAtomCache.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/TestAtomCache.java @@ -220,45 +220,32 @@ public void testFetchObsolete() throws IOException, StructureException { } - @Test public void testSettingFileParsingType(){ - AtomCache cache = new AtomCache(); //test defaults - // first is mmtf, second is mmcif - testFlags(cache,true,false); + testFlags(cache, false, false, true); // now change the values - cache.setFiletype(StructureFiletype.CIF); - - testFlags(cache,false,true); + testFlags(cache, false, true, false); cache.setFiletype(StructureFiletype.MMTF); - - testFlags(cache,true,false); + testFlags(cache, true, false, false); // this sets to use PDB! cache.setFiletype(StructureFiletype.PDB); + testFlags(cache, false, false, false); - testFlags(cache,false,false); - - // back to defaults + // back to MMTF cache.setFiletype(StructureFiletype.MMTF); - - testFlags(cache,true,false); - + testFlags(cache, true, false, false); // back to parsing PDB cache.setFiletype(StructureFiletype.PDB); - - testFlags(cache,false,false); - - - + testFlags(cache, false, false, false); } @@ -268,15 +255,12 @@ public void testSettingFileParsingType(){ * @param useMmTf * @param useMmCif */ - private void testFlags(AtomCache cache ,boolean useMmTf, boolean useMmCif) { - + private void testFlags(AtomCache cache ,boolean useMmTf, boolean useMmCif, boolean useBcif) { assertEquals("flag for parsing mmtf is set to " + cache.getFiletype() + " but should be " + useMmTf, cache.getFiletype() == StructureFiletype.MMTF, useMmTf); assertEquals("flag for parsing mmcif is set to " + cache.getFiletype() + " but should be set to " + useMmCif, cache.getFiletype() == StructureFiletype.CIF, useMmCif); - - - + assertEquals("flag for parsing bcif is set to " + cache.getFiletype() + " but should be set to " + useBcif, + cache.getFiletype() == StructureFiletype.BCIF, useBcif); } - } From e9c59f677f33a4d89bb539be80df36dd91af2e9b Mon Sep 17 00:00:00 2001 From: JonStargaryen Date: Tue, 26 Jan 2021 11:10:00 -0800 Subject: [PATCH 023/599] fix entity parsing --- .../nbio/structure/io/cif/StructureConsumerImpl.java | 6 +++--- .../nbio/structure/io/mmcif/TestEntityNameAndType.java | 2 -- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/StructureConsumerImpl.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/StructureConsumerImpl.java index 346ac12d41..e49d9aaefe 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/StructureConsumerImpl.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/StructureConsumerImpl.java @@ -1315,7 +1315,7 @@ private void addAncilliaryEntityData(int asymRowIndex, EntityInfo entityInfo) { // This is a potentially huge assumption... for (int rowIndex = 0; rowIndex < entitySrcGen.getRowCount(); rowIndex++) { - if (entitySrcGen.getEntityId().get(rowIndex).equals(structAsym.getEntityId().get(asymRowIndex))) { + if (!entitySrcGen.getEntityId().get(rowIndex).equals(structAsym.getEntityId().get(asymRowIndex))) { continue; } @@ -1323,7 +1323,7 @@ private void addAncilliaryEntityData(int asymRowIndex, EntityInfo entityInfo) { } for (int rowIndex = 0; rowIndex < entitySrcNat.getRowCount(); rowIndex++) { - if (entitySrcNat.getEntityId().get(rowIndex).equals(structAsym.getEntityId().get(asymRowIndex))) { + if (!entitySrcNat.getEntityId().get(rowIndex).equals(structAsym.getEntityId().get(asymRowIndex))) { continue; } @@ -1331,7 +1331,7 @@ private void addAncilliaryEntityData(int asymRowIndex, EntityInfo entityInfo) { } for (int rowIndex = 0; rowIndex < entitySrcSyn.getRowCount(); rowIndex++) { - if (entitySrcSyn.getEntityId().get(rowIndex).equals(structAsym.getEntityId().get(asymRowIndex))) { + if (!entitySrcSyn.getEntityId().get(rowIndex).equals(structAsym.getEntityId().get(asymRowIndex))) { continue; } diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmcif/TestEntityNameAndType.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmcif/TestEntityNameAndType.java index 88b5c3cc40..444a7b800e 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmcif/TestEntityNameAndType.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmcif/TestEntityNameAndType.java @@ -98,8 +98,6 @@ public void testEntityId() throws IOException, StructureException { assertArrayEquals(descriptionInformation, testDescInfo); assertArrayEquals(typeInformation, testTypeInfo); // Now check these work too - System.out.println(Arrays.toString(geneSourceSciName)); - System.out.println(Arrays.toString(testGeneSourceSciName)); assertArrayEquals(geneSourceSciName, testGeneSourceSciName); assertArrayEquals(geneSourceTaxId, testGeneSourceTaxId); assertArrayEquals(hostOrganismSciName, testHostOrganismSciName); From c30ab8f4a329279b04c0c2d7e351678cb6533f28 Mon Sep 17 00:00:00 2001 From: Jose Duarte Date: Tue, 26 Jan 2021 11:19:17 -0800 Subject: [PATCH 024/599] Solving jaxb warning --- pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 411aa6d1be..66521c8b2f 100644 --- a/pom.xml +++ b/pom.xml @@ -519,17 +519,17 @@ javax.xml.bind jaxb-api - 2.3.0 + 2.3.1 com.sun.xml.bind jaxb-core - 2.3.0 + 2.3.0.1 com.sun.xml.bind jaxb-impl - 2.3.0 + 2.3.3 javax.activation From 28815dbd5c5d08cdad8a7b2e486cefb3b7a02106 Mon Sep 17 00:00:00 2001 From: JonStargaryen Date: Tue, 26 Jan 2021 11:41:12 -0800 Subject: [PATCH 025/599] handle missing rfree/rwork --- .../biojava/nbio/structure/io/cif/StructureConsumerImpl.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/StructureConsumerImpl.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/StructureConsumerImpl.java index e49d9aaefe..35f46dc066 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/StructureConsumerImpl.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/StructureConsumerImpl.java @@ -39,6 +39,7 @@ import org.rcsb.cif.model.FloatColumn; import org.rcsb.cif.model.IntColumn; import org.rcsb.cif.model.StrColumn; +import org.rcsb.cif.model.ValueKind; import org.rcsb.cif.schema.mm.AtomSite; import org.rcsb.cif.schema.mm.AtomSites; import org.rcsb.cif.schema.mm.AuditAuthor; @@ -829,7 +830,7 @@ public void consumeRefine(Refine refine) { logger.warn("More than 1 Rfree value present, will use last one {} and discard previous {}", lsRFactorRFree, String.format("%4.2f",pdbHeader.getRfree())); } - if (lsRFactorRFree.isDefined()) { + if (lsRFactorRFree.isDefined() && lsRFactorRFree.getValueKind(rowIndex) == ValueKind.PRESENT) { pdbHeader.setRfree((float) lsRFactorRFree.get(rowIndex)); } else { // some entries like 2ifo haven't got this field at all @@ -842,7 +843,7 @@ public void consumeRefine(Refine refine) { logger.warn("More than 1 R work value present, will use last one {} and discard previous {} ", lsRFactorRWork, String.format("%4.2f",pdbHeader.getRwork())); } - if (lsRFactorRWork.isDefined()) { + if (lsRFactorRWork.isDefined() && lsRFactorRWork.getValueKind(rowIndex) == ValueKind.PRESENT) { pdbHeader.setRwork((float) lsRFactorRWork.get(rowIndex)); } else { logger.info("_refine.ls_R_factor_R_work not present, not parsing R-work value"); From f36f82cb601895aa2f78f1dd440a072762cb0516 Mon Sep 17 00:00:00 2001 From: JonStargaryen Date: Tue, 26 Jan 2021 11:59:45 -0800 Subject: [PATCH 026/599] SCOP hack to force loading of MMTF --- .../nbio/structure/align/util/AtomCache.java | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/align/util/AtomCache.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/align/util/AtomCache.java index 4181792515..3067e5955d 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/align/util/AtomCache.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/align/util/AtomCache.java @@ -524,7 +524,8 @@ public Structure getStructureForDomain(ScopDomain domain, ScopDatabase scopDatab public Structure getStructureForDomain(ScopDomain domain, ScopDatabase scopDatabase, boolean strictLigandHandling) throws IOException, StructureException { String pdbId = domain.getPdbId(); - Structure fullStructure = getStructureForPdbId(pdbId); + // SMB 1/26/21 - forcing loading MMTF here - TODO why doesn't mmCIF/CIF/BCIF parsing work here? + Structure fullStructure = getStructureForPdbIdByMmtf(pdbId); Structure structure = domain.reduce(fullStructure); // TODO It would be better to move all of this into the reduce method, @@ -800,6 +801,33 @@ public Structure getStructureForPdbId(String pdbId) throws IOException, Structur } } + /** + * SCOP parsing depends on MMTF, this a dedicated method to allow for that. + * @param pdbId what to load + * @return a Structure object + * @throws IOException + * @throws StructureException + */ + private Structure getStructureForPdbIdByMmtf(String pdbId) throws IOException, StructureException { + if (pdbId == null) + return null; + if (pdbId.length() != 4) { + throw new StructureException("Unrecognized PDB ID: " + pdbId); + } + while (checkLoading(pdbId)) { + // waiting for loading to be finished... + + try { + Thread.sleep(100); + } catch (InterruptedException e) { + logger.error(e.getMessage()); + } + } + + logger.debug("loading from mmtf"); + return loadStructureFromMmtfByPdbId(pdbId); + } + /** * Load a {@link Structure} from MMTF either from the local file system. * @param pdbId the input PDB id From 63d2ee7d2e25f929b9630cc5eebe4b102fa4bb58 Mon Sep 17 00:00:00 2001 From: JonStargaryen Date: Tue, 26 Jan 2021 12:23:10 -0800 Subject: [PATCH 027/599] bcif/models URL is a constant --- .../org/biojava/nbio/structure/io/LocalPDBDirectory.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/LocalPDBDirectory.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/LocalPDBDirectory.java index d207c5c886..2db30b046f 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/LocalPDBDirectory.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/LocalPDBDirectory.java @@ -63,6 +63,11 @@ public abstract class LocalPDBDirectory implements StructureIOFile { public static final String DEFAULT_PDB_FILE_SERVER = "http://ftp.wwpdb.org"; public static final String PDB_FILE_SERVER_PROPERTY = "PDB.FILE.SERVER"; + /** + * The default server to retrieve BinaryCIF files. + */ + public static final String DEFAULT_BCIF_FILE_SERVER = "https://models.rcsb.org/"; + /** * Behaviors for when an obsolete structure is requested. * @author Spencer Bliven @@ -521,7 +526,8 @@ private File downloadStructure(String pdbId, String pathOnServer, boolean obsole if (filename.endsWith(".mmtf.gz")){ ftp = CodecUtils.getMmtfEntryUrl(pdbId, true, false); } else if (filename.endsWith(".bcif") || filename.endsWith(".bcif.gz")) { - ftp = "https://models.rcsb.org/" + filename; + // TODO this should be configurable + ftp = DEFAULT_BCIF_FILE_SERVER + filename; } else { ftp = String.format("%s%s/%s/%s", serverName, pathOnServer, pdbId.substring(1,3).toLowerCase(), getFilename(pdbId)); From 2d4cc74edd6f3a88689a6de40b579a701230a351 Mon Sep 17 00:00:00 2001 From: JonStargaryen Date: Tue, 26 Jan 2021 14:41:25 -0800 Subject: [PATCH 028/599] StructureInterface#toMMCIF --- .../structure/contact/StructureInterface.java | 95 ++++++++++--------- .../io/cif/AbstractCifFileSupplier.java | 20 ++-- .../structure/io/cif/CifFileSupplier.java | 2 - 3 files changed, 59 insertions(+), 58 deletions(-) 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 de50722b34..72a4cc2178 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,12 +20,6 @@ */ package org.biojava.nbio.structure.contact; -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; @@ -40,10 +34,24 @@ import org.biojava.nbio.structure.chem.PolymerType; import org.biojava.nbio.structure.io.FileConvert; import org.biojava.nbio.structure.io.FileParsingParameters; +import org.biojava.nbio.structure.io.cif.AbstractCifFileSupplier; import org.biojava.nbio.structure.xtal.CrystalTransform; +import org.rcsb.cif.CifBuilder; +import org.rcsb.cif.CifIO; +import org.rcsb.cif.model.Category; +import org.rcsb.cif.schema.StandardSchemata; +import org.rcsb.cif.schema.mm.MmCifBlockBuilder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.IOException; +import java.io.Serializable; +import java.io.UncheckedIOException; +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). @@ -748,45 +756,46 @@ public String toPDB() { * @return the mmCIF-formatted string */ public String toMMCIF() { - StringBuilder sb = new StringBuilder(); + String molecId1 = getMoleculeIds().getFirst(); + String molecId2 = getMoleculeIds().getSecond(); - // TODO impl -// String molecId1 = getMoleculeIds().getFirst(); -// String molecId2 = getMoleculeIds().getSecond(); -// -// if (isSymRelated()) { -// // if both chains are named equally we want to still named them differently in the output mmcif file -// // so that molecular viewers can handle properly the 2 chains as separate entities -// molecId2 = molecId2 + "_" +getTransforms().getSecond().getTransformId(); -// } -// -// sb.append(SimpleMMcifParser.MMCIF_TOP_HEADER).append("BioJava_interface_").append(getId()).append(System.getProperty("line.separator")); -// -// sb.append(FileConvert.getAtomSiteHeader()); -// -// // 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<>(); -// for (Atom atom:this.molecules.getFirst()) { -// if (isSymRelated()) { -// atomSites.add(MMCIFFileTools.convertAtomToAtomSite(atom, 1, molecId1, molecId1, atomId)); -// } else { -// atomSites.add(MMCIFFileTools.convertAtomToAtomSite(atom, 1, molecId1, molecId1)); -// } -// atomId++; -// } -// for (Atom atom:this.molecules.getSecond()) { -// if (isSymRelated()) { -// atomSites.add(MMCIFFileTools.convertAtomToAtomSite(atom, 1, molecId2, molecId2, atomId)); -// } else { -// atomSites.add(MMCIFFileTools.convertAtomToAtomSite(atom, 1, molecId2, molecId2)); -// } -// atomId++; -// } -// -// sb.append(MMCIFFileTools.toMMCIF(atomSites,AtomSite.class)); + if (isSymRelated()) { + // if both chains are named equally we want to still named them differently in the output mmcif file + // so that molecular viewers can handle properly the 2 chains as separate entities + molecId2 = molecId2 + "_" + getTransforms().getSecond().getTransformId(); + } - return sb.toString(); + MmCifBlockBuilder mmCifBlockBuilder = CifBuilder.enterFile(StandardSchemata.MMCIF) + .enterBlock("BioJava_interface_" + getId()); + + // 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 wrappedAtoms = new ArrayList<>(); + for (Atom atom : this.molecules.getFirst()) { + if (isSymRelated()) { + wrappedAtoms.add(new AbstractCifFileSupplier.WrappedAtom(1, molecId1, molecId1, atom, atomId)); + } else { + wrappedAtoms.add(new AbstractCifFileSupplier.WrappedAtom(1, molecId1, molecId1, atom, atom.getPDBserial())); + } + atomId++; + } + for (Atom atom : this.molecules.getSecond()) { + if (isSymRelated()) { + wrappedAtoms.add(new AbstractCifFileSupplier.WrappedAtom(1, molecId2, molecId2, atom, atomId)); + } else { + wrappedAtoms.add(new AbstractCifFileSupplier.WrappedAtom(1, molecId2, molecId2, atom, atom.getPDBserial())); + } + atomId++; + } + + Category atomSite = wrappedAtoms.stream().collect(AbstractCifFileSupplier.toAtomSite()); + mmCifBlockBuilder.addCategory(atomSite); + + try { + return new String(CifIO.writeText(mmCifBlockBuilder.leaveBlock().leaveFile())); + } catch (IOException e) { + throw new UncheckedIOException(e); + } } @Override diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/AbstractCifFileSupplier.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/AbstractCifFileSupplier.java index 0c039467c1..2cb5e11acf 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/AbstractCifFileSupplier.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/AbstractCifFileSupplier.java @@ -107,7 +107,7 @@ protected void handleChain(Chain chain, int model, List wrappedAtom continue; } - uniqueAtoms.put(atom.getPDBserial(), new WrappedAtom(chain, model, chainName, chainId, atom, atom.getPDBserial())); + uniqueAtoms.put(atom.getPDBserial(), new WrappedAtom(model, chainName, chainId, atom, atom.getPDBserial())); } if (group.hasAltLoc()) { @@ -118,7 +118,7 @@ protected void handleChain(Chain chain, int model, List wrappedAtom continue; } - uniqueAtoms.put(atom.getPDBserial(), new WrappedAtom(chain, model, chainName, chainId, atom, atom.getPDBserial())); + uniqueAtoms.put(atom.getPDBserial(), new WrappedAtom(model, chainName, chainId, atom, atom.getPDBserial())); } } } @@ -127,16 +127,14 @@ protected void handleChain(Chain chain, int model, List wrappedAtom } } - static class WrappedAtom { - private final Chain chain; + public static class WrappedAtom { private final int model; private final String chainName; private final String chainId; private final Atom atom; private final int atomId; - WrappedAtom(Chain chain, int model, String chainName, String chainId, Atom atom, int atomId) { - this.chain = chain; + public WrappedAtom(int model, String chainName, String chainId, Atom atom, int atomId) { this.model = model; this.chainName = chainName; this.chainId = chainId; @@ -144,10 +142,6 @@ static class WrappedAtom { this.atomId = atomId; } - Chain getChain() { - return chain; - } - int getModel() { return model; } @@ -169,7 +163,7 @@ int getAtomId() { } } - private static Collector toAtomSite() { + public static Collector toAtomSite() { return Collector.of(AtomSiteCollector::new, AtomSiteCollector::accept, AtomSiteCollector::combine, @@ -255,7 +249,7 @@ public void accept(WrappedAtom wrappedAtom) { labelEntityId.add(entityId); labelSeqId.add(seqId); String insCode = ""; - if (group.getResidueNumber().getInsCode() != null ) { + if (group.getResidueNumber().getInsCode() != null) { insCode = Character.toString(group.getResidueNumber().getInsCode()); } if (insCode.isEmpty()) { @@ -276,7 +270,7 @@ public void accept(WrappedAtom wrappedAtom) { } AtomSiteCollector combine(AtomSiteCollector other) { - throw new UnsupportedOperationException("impl by calling addAll for all collection"); + throw new UnsupportedOperationException("impl by calling addAll for all collections"); } Category get() { diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/CifFileSupplier.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/CifFileSupplier.java index 08f35fce54..e46a0bf058 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/CifFileSupplier.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/CifFileSupplier.java @@ -2,8 +2,6 @@ import org.rcsb.cif.model.CifFile; -import java.util.function.Supplier; - /** * Create a CifFile instance for a given container of structure data. * @param the container type used as source From b7a40c545ff7aad55ee12433a51ea87fc8e09957 Mon Sep 17 00:00:00 2001 From: JonStargaryen Date: Tue, 26 Jan 2021 18:04:43 -0800 Subject: [PATCH 029/599] TODO TestHardBioUnits --- .../java/org/biojava/nbio/structure/io/TestHardBioUnits.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestHardBioUnits.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestHardBioUnits.java index b205bd2140..2c73fe0e0d 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestHardBioUnits.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestHardBioUnits.java @@ -108,6 +108,10 @@ public void test4A1I() throws IOException, StructureException { String pdbId = "4A1I"; int biolAssemblyNr = 2; + AtomCache atomCache = new AtomCache(); + // TODO there seem to be numerical instabilities when parsing BCIF + atomCache.setFiletype(StructureFiletype.CIF); + StructureIO.setAtomCache(atomCache); Structure bioAssembly = StructureIO.getBiologicalAssembly(pdbId,biolAssemblyNr); if ( bioAssembly == null){ From 2f91dbf2d3085076f2b38f0e90c5c304c2c86727 Mon Sep 17 00:00:00 2001 From: JonStargaryen Date: Tue, 26 Jan 2021 18:23:12 -0800 Subject: [PATCH 030/599] those aren't the FloatColumns you're looking for --- .../nbio/structure/io/cif/MetalBondConsumerImpl.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/MetalBondConsumerImpl.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/MetalBondConsumerImpl.java index d9d03a9590..4d484e5465 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/MetalBondConsumerImpl.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/MetalBondConsumerImpl.java @@ -33,15 +33,15 @@ public void finish() { public void consume(Category category) { StrColumn atomType1 = (StrColumn) category.getColumn("atom_type_1"); StrColumn atomType2 = (StrColumn) category.getColumn("atom_type_2"); - FloatColumn lowerLimit = (FloatColumn) category.getColumn("lower_limit"); - FloatColumn upperLimit = (FloatColumn) category.getColumn("upper_limit"); + StrColumn lowerLimit = (StrColumn) category.getColumn("lower_limit"); + StrColumn upperLimit = (StrColumn) category.getColumn("upper_limit"); for (int i = 0; i < category.getRowCount(); i++) { MetalBondDistance d = new MetalBondDistance(); d.setAtomType1(atomType1.get(i)); d.setAtomType2(atomType2.get(i)); - d.setLowerLimit((float) lowerLimit.get(i)); - d.setUpperLimit((float) upperLimit.get(i)); + d.setLowerLimit(Float.parseFloat(lowerLimit.get(i))); + d.setUpperLimit(Float.parseFloat(upperLimit.get(i))); List defs = definitions.computeIfAbsent(d.getAtomType1(), k -> new ArrayList<>()); defs.add(d); From 9f42c9c142207737970489115a9880096cacc111 Mon Sep 17 00:00:00 2001 From: JonStargaryen Date: Tue, 26 Jan 2021 18:51:31 -0800 Subject: [PATCH 031/599] trigger build --- .../org/biojava/nbio/structure/io/cif/MetalBondConsumerImpl.java | 1 - 1 file changed, 1 deletion(-) diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/MetalBondConsumerImpl.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/MetalBondConsumerImpl.java index 4d484e5465..7a5d600c79 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/MetalBondConsumerImpl.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/MetalBondConsumerImpl.java @@ -2,7 +2,6 @@ import org.biojava.nbio.structure.chem.MetalBondDistance; import org.rcsb.cif.model.Category; -import org.rcsb.cif.model.FloatColumn; import org.rcsb.cif.model.StrColumn; import java.util.ArrayList; From 454830a223fb4a2b90c7d7650033b99ffad4783c Mon Sep 17 00:00:00 2001 From: JonStargaryen Date: Wed, 27 Jan 2021 09:20:52 -0800 Subject: [PATCH 032/599] docs --- .../structure/test/StructureToolsTest.java | 1 + .../biojava/nbio/structure/test/Test1o2f.java | 2 +- .../test/io/TestAtomCachePerformance.java | 2 +- .../structure/test/io/TestBioassemblies.java | 2 +- .../test/io/TestCrystallographicMetadata.java | 2 +- .../test/io/TestLongPdbVsMmCifParsing.java | 1 + .../io/TestStructWithMultiparentChemComp.java | 2 +- .../cif/CifFileSupplierIntegrationTest.java | 10 +- .../TestQuatSymmetryDetectorExamples.java | 2 +- .../test/xtal/TestCrystalBuilder.java | 2 +- .../main/java/demo/DemoQuatSymmetryJmol.java | 2 +- .../main/java/demo/DemoShowLargeAssembly.java | 2 +- .../src/main/java/demo/DemoAsa.java | 2 +- .../src/main/java/demo/DemoContacts.java | 1 + .../main/java/demo/DemoCrystalInterfaces.java | 2 +- .../src/main/java/demo/DemoLoadSecStruc.java | 2 +- .../src/main/java/demo/DemoMMCIFReader.java | 1 + .../java/demo/DemoMmcifToPdbConverter.java | 4 +- .../org/biojava/nbio/structure/Chain.java | 1 + .../nbio/structure/DatabasePDBRevRecord.java | 7 +- .../org/biojava/nbio/structure/Group.java | 103 ++++++------ .../biojava/nbio/structure/StructureIO.java | 1 + .../biojava/nbio/structure/URLIdentifier.java | 7 +- .../nbio/structure/align/util/AtomCache.java | 1 + .../align/util/UserConfiguration.java | 156 +++++++++++------- .../biojava/nbio/structure/chem/ChemComp.java | 4 +- .../nbio/structure/chem/ChemCompAtom.java | 7 +- .../nbio/structure/chem/ChemCompBond.java | 7 +- .../structure/chem/ChemCompDescriptor.java | 7 +- .../nbio/structure/io/BcifFileReader.java | 6 +- .../nbio/structure/io/CifFileReader.java | 6 +- .../nbio/structure/io/FileConvert.java | 15 +- .../structure/{ => io}/StructureFiletype.java | 9 +- .../io/cif/AbstractCifFileSupplier.java | 28 +++- .../structure/io/cif/ChemCompConsumer.java | 18 +- .../io/cif/ChemCompConsumerImpl.java | 4 + .../structure/io/cif/ChemCompConverter.java | 4 +- .../nbio/structure/io/cif/CifBean.java | 9 +- ...ierImpl.java => CifChainSupplierImpl.java} | 6 +- .../structure/io/cif/CifFileConsumer.java | 3 +- .../structure/io/cif/CifFileSupplier.java | 2 +- ...onsumer.java => CifStructureConsumer.java} | 7 +- ...mpl.java => CifStructureConsumerImpl.java} | 8 +- ...verter.java => CifStructureConverter.java} | 14 +- ...mpl.java => CifStructureSupplierImpl.java} | 6 +- .../structure/io/cif/MetalBondConsumer.java | 7 +- .../structure/io/cif/MetalBondConverter.java | 2 +- .../nbio/structure/io/mmtf/MmtfUtils.java | 3 +- .../org/biojava/nbio/structure/Test2JA5.java | 1 + .../org/biojava/nbio/structure/Test4hhb.java | 4 +- .../biojava/nbio/structure/TestAltLocs.java | 13 +- .../biojava/nbio/structure/TestAtomCache.java | 1 + .../org/biojava/nbio/structure/TestBond.java | 1 + .../biojava/nbio/structure/TestCloning.java | 1 + .../structure/TestEntityResIndexMapping.java | 1 + .../structure/TestExperimentalTechniques.java | 1 + .../structure/TestLoadStructureFromURL.java | 1 + .../nbio/structure/TestParsingCalcium.java | 1 + .../TestStructureCrossReferences.java | 1 + .../structure/align/util/AtomCacheTest.java | 2 +- .../structure/io/TestDifficultMmCIFFiles.java | 7 +- .../nbio/structure/io/TestHardBioUnits.java | 1 - .../nbio/structure/io/TestHeaderOnly.java | 5 +- .../nbio/structure/io/TestMMCIFWriting.java | 7 +- .../io/TestMMcifOrganismParsing.java | 1 - .../structure/io/TestNonDepositedFiles.java | 13 +- .../structure/io/TestParseMmCIFFeatures.java | 1 - .../structure/io/TestParseMmCIFLigands.java | 1 - .../nbio/structure/io/TestParseOnAsymId.java | 1 - .../nbio/structure/io/TestTitleParsing.java | 1 - .../io/TestWriteLargeCoordinatePDB.java | 1 - .../io/mmcif/TestEntityNameAndType.java | 3 +- .../io/mmcif/TestParseInternalChainId.java | 2 +- .../io/mmcif/TestParseMmcifHeader.java | 2 +- .../structure/io/mmtf/TestBondFinding.java | 2 +- .../structure/io/mmtf/TestMmtfRoundTrip.java | 8 +- .../io/mmtf/TestMmtfStructureReader.java | 2 +- .../nbio/structure/xtal/TestCrystalInfo.java | 1 + .../xtal/TestInterfaceClustering.java | 2 +- 79 files changed, 357 insertions(+), 232 deletions(-) rename biojava-structure/src/main/java/org/biojava/nbio/structure/{ => io}/StructureFiletype.java (75%) rename biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/{ChainSupplierImpl.java => CifChainSupplierImpl.java} (77%) rename biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/{StructureConsumer.java => CifStructureConsumer.java} (98%) rename biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/{StructureConsumerImpl.java => CifStructureConsumerImpl.java} (99%) rename biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/{StructureConverter.java => CifStructureConverter.java} (95%) rename biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/{StructureSupplierImpl.java => CifStructureSupplierImpl.java} (83%) diff --git a/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/StructureToolsTest.java b/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/StructureToolsTest.java index 510b071200..53bf6fe9ad 100644 --- a/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/StructureToolsTest.java +++ b/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/StructureToolsTest.java @@ -29,6 +29,7 @@ import org.biojava.nbio.structure.chem.DownloadChemCompProvider; import org.biojava.nbio.structure.io.FileParsingParameters; import org.biojava.nbio.structure.io.PDBFileParser; +import org.biojava.nbio.structure.io.StructureFiletype; import org.junit.Before; import org.junit.Test; diff --git a/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/Test1o2f.java b/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/Test1o2f.java index af1ec695f7..d2795e28c4 100644 --- a/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/Test1o2f.java +++ b/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/Test1o2f.java @@ -22,7 +22,7 @@ import org.biojava.nbio.structure.Chain; import org.biojava.nbio.structure.Structure; -import org.biojava.nbio.structure.StructureFiletype; +import org.biojava.nbio.structure.io.StructureFiletype; import org.biojava.nbio.structure.StructureIO; import org.biojava.nbio.structure.align.util.AtomCache; import org.biojava.nbio.structure.io.LocalPDBDirectory.FetchBehavior; diff --git a/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/io/TestAtomCachePerformance.java b/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/io/TestAtomCachePerformance.java index 03bf297484..5a89995450 100644 --- a/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/io/TestAtomCachePerformance.java +++ b/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/io/TestAtomCachePerformance.java @@ -22,7 +22,7 @@ import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.StructureException; -import org.biojava.nbio.structure.StructureFiletype; +import org.biojava.nbio.structure.io.StructureFiletype; import org.biojava.nbio.structure.align.util.AtomCache; import org.biojava.nbio.structure.io.LocalPDBDirectory.FetchBehavior; import org.junit.BeforeClass; diff --git a/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/io/TestBioassemblies.java b/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/io/TestBioassemblies.java index 001dd5434e..f85c2a275b 100644 --- a/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/io/TestBioassemblies.java +++ b/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/io/TestBioassemblies.java @@ -28,7 +28,7 @@ import org.biojava.nbio.structure.Chain; import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.StructureException; -import org.biojava.nbio.structure.StructureFiletype; +import org.biojava.nbio.structure.io.StructureFiletype; import org.biojava.nbio.structure.StructureIO; import org.biojava.nbio.structure.align.util.AtomCache; import org.junit.Test; diff --git a/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/io/TestCrystallographicMetadata.java b/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/io/TestCrystallographicMetadata.java index c41ac34410..1c4db79571 100644 --- a/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/io/TestCrystallographicMetadata.java +++ b/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/io/TestCrystallographicMetadata.java @@ -20,7 +20,7 @@ */ package org.biojava.nbio.structure.test.io; -import org.biojava.nbio.structure.StructureFiletype; +import org.biojava.nbio.structure.io.StructureFiletype; import org.junit.Test; import static org.junit.Assert.*; diff --git a/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/io/TestLongPdbVsMmCifParsing.java b/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/io/TestLongPdbVsMmCifParsing.java index fc529b75e3..3d788e830c 100644 --- a/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/io/TestLongPdbVsMmCifParsing.java +++ b/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/io/TestLongPdbVsMmCifParsing.java @@ -24,6 +24,7 @@ import org.biojava.nbio.structure.align.util.AtomCache; import org.biojava.nbio.structure.io.FileParsingParameters; import org.biojava.nbio.structure.io.LocalPDBDirectory.ObsoleteBehavior; +import org.biojava.nbio.structure.io.StructureFiletype; import org.biojava.nbio.structure.quaternary.BioAssemblyInfo; import org.biojava.nbio.structure.xtal.CrystalCell; import org.junit.After; diff --git a/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/io/TestStructWithMultiparentChemComp.java b/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/io/TestStructWithMultiparentChemComp.java index 83059e7ea4..8aa6643fa4 100644 --- a/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/io/TestStructWithMultiparentChemComp.java +++ b/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/io/TestStructWithMultiparentChemComp.java @@ -20,7 +20,7 @@ */ package org.biojava.nbio.structure.test.io; -import org.biojava.nbio.structure.StructureFiletype; +import org.biojava.nbio.structure.io.StructureFiletype; import org.junit.Test; import static org.junit.Assert.*; diff --git a/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/io/cif/CifFileSupplierIntegrationTest.java b/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/io/cif/CifFileSupplierIntegrationTest.java index 8e59c8a931..5cda83225d 100644 --- a/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/io/cif/CifFileSupplierIntegrationTest.java +++ b/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/io/cif/CifFileSupplierIntegrationTest.java @@ -12,7 +12,7 @@ import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.StructureImpl; import org.biojava.nbio.structure.StructureTools; -import org.biojava.nbio.structure.io.cif.StructureConverter; +import org.biojava.nbio.structure.io.cif.CifStructureConverter; import org.junit.Test; import java.io.ByteArrayInputStream; @@ -49,10 +49,10 @@ public void test1A2C() throws IOException { private static void testRoundTrip(String pdbId) throws IOException { URL url = new URL("https://files.rcsb.org/download/" + pdbId + ".cif"); - Structure originalStruct = StructureConverter.fromURL(url); + Structure originalStruct = CifStructureConverter.fromURL(url); - InputStream inputStream = new ByteArrayInputStream(StructureConverter.toText(originalStruct).getBytes()); - Structure readStruct = StructureConverter.fromInputStream(inputStream); + InputStream inputStream = new ByteArrayInputStream(CifStructureConverter.toText(originalStruct).getBytes()); + Structure readStruct = CifStructureConverter.fromInputStream(inputStream); assertNotNull(readStruct); assertEquals(originalStruct.getChains().size(), readStruct.getChains().size()); @@ -113,7 +113,7 @@ private static void testRoundTrip(String pdbId) throws IOException { @Test public void testBiounitWriting() throws IOException { Structure s = createDummyStructure(); - String mmcif = StructureConverter.toText(s); + String mmcif = CifStructureConverter.toText(s); String[] lines = mmcif.split("\n"); long atomLines = Arrays.stream(lines).filter(l -> l.startsWith("ATOM")).count(); assertNotNull(mmcif); diff --git a/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/symmetry/TestQuatSymmetryDetectorExamples.java b/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/symmetry/TestQuatSymmetryDetectorExamples.java index c46087eb58..08946e3e0a 100644 --- a/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/symmetry/TestQuatSymmetryDetectorExamples.java +++ b/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/symmetry/TestQuatSymmetryDetectorExamples.java @@ -27,7 +27,7 @@ import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.StructureException; -import org.biojava.nbio.structure.StructureFiletype; +import org.biojava.nbio.structure.io.StructureFiletype; import org.biojava.nbio.structure.StructureIO; import org.biojava.nbio.structure.StructureTools; import org.biojava.nbio.structure.align.util.AtomCache; diff --git a/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/xtal/TestCrystalBuilder.java b/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/xtal/TestCrystalBuilder.java index 4851c03ba9..d90241dbe0 100644 --- a/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/xtal/TestCrystalBuilder.java +++ b/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/xtal/TestCrystalBuilder.java @@ -22,7 +22,7 @@ import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.StructureException; -import org.biojava.nbio.structure.StructureFiletype; +import org.biojava.nbio.structure.io.StructureFiletype; import org.biojava.nbio.structure.StructureIO; import org.biojava.nbio.structure.align.util.AtomCache; import org.biojava.nbio.structure.contact.StructureInterfaceList; diff --git a/biojava-structure-gui/src/main/java/demo/DemoQuatSymmetryJmol.java b/biojava-structure-gui/src/main/java/demo/DemoQuatSymmetryJmol.java index 674c846d4a..999e4305fc 100644 --- a/biojava-structure-gui/src/main/java/demo/DemoQuatSymmetryJmol.java +++ b/biojava-structure-gui/src/main/java/demo/DemoQuatSymmetryJmol.java @@ -22,7 +22,7 @@ import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.StructureException; -import org.biojava.nbio.structure.StructureFiletype; +import org.biojava.nbio.structure.io.StructureFiletype; import org.biojava.nbio.structure.align.util.AtomCache; import org.biojava.nbio.structure.cluster.SubunitClustererMethod; import org.biojava.nbio.structure.cluster.SubunitClustererParameters; diff --git a/biojava-structure-gui/src/main/java/demo/DemoShowLargeAssembly.java b/biojava-structure-gui/src/main/java/demo/DemoShowLargeAssembly.java index 4aa053e70a..343e50d226 100644 --- a/biojava-structure-gui/src/main/java/demo/DemoShowLargeAssembly.java +++ b/biojava-structure-gui/src/main/java/demo/DemoShowLargeAssembly.java @@ -1,7 +1,7 @@ package demo; import org.biojava.nbio.structure.Structure; -import org.biojava.nbio.structure.StructureFiletype; +import org.biojava.nbio.structure.io.StructureFiletype; import org.biojava.nbio.structure.StructureTools; import org.biojava.nbio.structure.align.util.AtomCache; import org.biojava.nbio.structure.io.FileParsingParameters; diff --git a/biojava-structure/src/main/java/demo/DemoAsa.java b/biojava-structure/src/main/java/demo/DemoAsa.java index 1df3d9feeb..72d2b096d5 100644 --- a/biojava-structure/src/main/java/demo/DemoAsa.java +++ b/biojava-structure/src/main/java/demo/DemoAsa.java @@ -24,7 +24,7 @@ import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.StructureException; -import org.biojava.nbio.structure.StructureFiletype; +import org.biojava.nbio.structure.io.StructureFiletype; import org.biojava.nbio.structure.StructureIO; import org.biojava.nbio.structure.align.util.AtomCache; import org.biojava.nbio.structure.asa.AsaCalculator; diff --git a/biojava-structure/src/main/java/demo/DemoContacts.java b/biojava-structure/src/main/java/demo/DemoContacts.java index 0eed99e807..f5ee18934c 100644 --- a/biojava-structure/src/main/java/demo/DemoContacts.java +++ b/biojava-structure/src/main/java/demo/DemoContacts.java @@ -25,6 +25,7 @@ import org.biojava.nbio.structure.contact.AtomContact; import org.biojava.nbio.structure.contact.AtomContactSet; import org.biojava.nbio.structure.contact.GroupContactSet; +import org.biojava.nbio.structure.io.StructureFiletype; import java.io.IOException; diff --git a/biojava-structure/src/main/java/demo/DemoCrystalInterfaces.java b/biojava-structure/src/main/java/demo/DemoCrystalInterfaces.java index 76fd4f6823..f5b76d86bf 100644 --- a/biojava-structure/src/main/java/demo/DemoCrystalInterfaces.java +++ b/biojava-structure/src/main/java/demo/DemoCrystalInterfaces.java @@ -23,7 +23,7 @@ import org.biojava.nbio.structure.Group; import org.biojava.nbio.structure.Structure; -import org.biojava.nbio.structure.StructureFiletype; +import org.biojava.nbio.structure.io.StructureFiletype; import org.biojava.nbio.structure.align.util.AtomCache; import org.biojava.nbio.structure.contact.*; import org.biojava.nbio.structure.io.FileParsingParameters; diff --git a/biojava-structure/src/main/java/demo/DemoLoadSecStruc.java b/biojava-structure/src/main/java/demo/DemoLoadSecStruc.java index 3254ff64ae..a9eaf67e41 100644 --- a/biojava-structure/src/main/java/demo/DemoLoadSecStruc.java +++ b/biojava-structure/src/main/java/demo/DemoLoadSecStruc.java @@ -25,7 +25,7 @@ import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.StructureException; -import org.biojava.nbio.structure.StructureFiletype; +import org.biojava.nbio.structure.io.StructureFiletype; import org.biojava.nbio.structure.align.util.AtomCache; import org.biojava.nbio.structure.io.FileParsingParameters; import org.biojava.nbio.structure.secstruc.SecStrucCalc; diff --git a/biojava-structure/src/main/java/demo/DemoMMCIFReader.java b/biojava-structure/src/main/java/demo/DemoMMCIFReader.java index e6b5eab186..1954ad99a4 100644 --- a/biojava-structure/src/main/java/demo/DemoMMCIFReader.java +++ b/biojava-structure/src/main/java/demo/DemoMMCIFReader.java @@ -28,6 +28,7 @@ import org.biojava.nbio.structure.align.util.AtomCache; import org.biojava.nbio.structure.io.CifFileReader; import org.biojava.nbio.structure.io.StructureProvider; +import org.biojava.nbio.structure.io.StructureFiletype; import java.util.List; diff --git a/biojava-structure/src/main/java/demo/DemoMmcifToPdbConverter.java b/biojava-structure/src/main/java/demo/DemoMmcifToPdbConverter.java index 67de1031c0..e5c9f5cda6 100644 --- a/biojava-structure/src/main/java/demo/DemoMmcifToPdbConverter.java +++ b/biojava-structure/src/main/java/demo/DemoMmcifToPdbConverter.java @@ -23,7 +23,7 @@ import org.biojava.nbio.structure.Chain; import org.biojava.nbio.structure.Structure; -import org.biojava.nbio.structure.io.cif.StructureConverter; +import org.biojava.nbio.structure.io.cif.CifStructureConverter; import java.io.File; import java.io.IOException; @@ -43,7 +43,7 @@ public static void main(String[] args) throws Exception { public static void convert(File inFile, File outFile) throws IOException { // now get the protein structure. - Structure cifStructure = StructureConverter.fromPath(inFile.toPath()); + Structure cifStructure = CifStructureConverter.fromPath(inFile.toPath()); // and write it out as PDB format PrintWriter pr = new PrintWriter(outFile); diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/Chain.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/Chain.java index c8413228ee..73827d2434 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/Chain.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/Chain.java @@ -24,6 +24,7 @@ package org.biojava.nbio.structure; import org.biojava.nbio.core.sequence.template.Sequence; +import org.biojava.nbio.structure.chem.ChemComp; import org.biojava.nbio.structure.io.FileParsingParameters; import java.io.Serializable; diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/DatabasePDBRevRecord.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/DatabasePDBRevRecord.java index 039c2f0cc4..ad6945ac70 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/DatabasePDBRevRecord.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/DatabasePDBRevRecord.java @@ -2,7 +2,12 @@ import org.biojava.nbio.structure.io.cif.CifBean; -public class DatabasePDBRevRecord implements CifBean { +/** + * Represents revision records for use by {@link PDBHeader}. + * @author Sebastian Bittrich + * @since 6.0.0 + */ +public class DatabasePDBRevRecord implements CifBean { private static final long serialVersionUID = 1L; private String revNum; private String type; diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/Group.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/Group.java index 36b8d3b1cd..d1e5f34963 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/Group.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/Group.java @@ -53,28 +53,29 @@ * */ public interface Group extends Serializable { + /** Group property key for secondary structure annotation */ - String SEC_STRUC = "secstruc"; + public static final String SEC_STRUC = "secstruc"; /** * Get number of atoms. * @return number of atoms of this Group */ - int size(); + public int size(); /** * Return true or false, depending if this group has 3D coordinates or not. * * @return true if Group has 3D coordinates */ - boolean has3D(); + public boolean has3D (); /** * Flag if group has 3D data . * * @param flag true to set flag that this Group has 3D coordinates */ - void setPDBFlag(boolean flag); + public void setPDBFlag(boolean flag); /** * Get Type of group, one of {@link GroupType#AMINOACID}, {@link GroupType#HETATM} @@ -82,14 +83,14 @@ public interface Group extends Serializable { * * @return a String representing the type value */ - GroupType getType(); + public GroupType getType(); /** * Add an atom to this group. * * @param atom an Atom object */ - void addAtom(Atom atom); + public void addAtom(Atom atom); /** * Get list of atoms. @@ -97,33 +98,32 @@ public interface Group extends Serializable { * @return a List object representing the atoms * @see #setAtoms(List) */ - List getAtoms(); + public List getAtoms() ; + /** * Set the atoms of this group. - * @see Atom + * @see {@link Atom} * @param atoms a list of atoms */ - void setAtoms(List atoms); + public void setAtoms(List atoms); - /** - * Remove all atoms from this group. + /** Remove all atoms from this group. * */ - void clearAtoms(); + public void clearAtoms(); /** * Get an atom given its PDB name. * Beware that some PDB atom names are ambiguous (e.g. CA, which means C-alpha or Calcium), * ambiguities should not occur within the same group though. To solve these ambiguities * one would need to check the atom returned for the required element with {@link Atom#getElement()} - *

- * Note this method will return only the atom in the default alternative location (be it '.' or a letter). * * @param name a trimmed String representing the atom's PDB name, e.g. "CA" * @return an Atom object or null if no such atom exists within this group */ - Atom getAtom(String name); + public Atom getAtom(String name) ; + /** * Get at atom by position. @@ -131,7 +131,7 @@ public interface Group extends Serializable { * @param position an int * @return an Atom object or null if no Atom exists for given position */ - Atom getAtom(int position); + public Atom getAtom(int position) ; /** * Tell whether a particular atom exists within this group. @@ -141,7 +141,7 @@ public interface Group extends Serializable { * @param name a trimmed String representing the atom's PDB name, e.g. "CA" * @return true if Atom with name exists within this group */ - boolean hasAtom(String name); + public boolean hasAtom(String name); /** * Get the PDB 3-letter name for this group. (e.g. ALA) @@ -149,7 +149,7 @@ public interface Group extends Serializable { * @return a String representing the PDBName value * @see #setPDBName */ - String getPDBName(); + public String getPDBName(); /** * Set the PDB 3-letter name for this group. (e.g. ALA) @@ -157,7 +157,8 @@ public interface Group extends Serializable { * @param s a String specifying the PDBName value * @see #getPDBName */ - void setPDBName(String s); + public void setPDBName(String s) ; + /** * Calculate if this group has all atoms required for an amino acid backbone. @@ -180,28 +181,33 @@ public interface Group extends Serializable { * @return true if all Atoms required for an AminoAcid are available (N, CA, C, O) * @see #getType */ - boolean hasAminoAtoms(); + public boolean hasAminoAtoms() ; + /** * Check if this group is a polymeric group, from the definition in Chemical Component Dictionary * * @return true if a polymeric group */ - boolean isPolymeric(); + public boolean isPolymeric(); + /** * Check if this group is an aminoacid group, from the definition in Chemical Component Dictionary * * @return true if an amino acid */ - boolean isAminoAcid(); + public boolean isAminoAcid(); + /** * Check if this group is a nucleotide group, from the definition in Chemical Component Dictionary * * @return true if a nucleotide */ - boolean isNucleotide(); + public boolean isNucleotide(); + + /** * Properties of this amino acid. Currently available properties are: @@ -212,7 +218,7 @@ public interface Group extends Serializable { * @param properties a Map object specifying the properties value * @see #getProperties */ - void setProperties(Map properties); + public void setProperties(Map properties) ; /** * Return properties. @@ -220,7 +226,7 @@ public interface Group extends Serializable { * * @return a HashMap object representing the properties value */ - Map getProperties(); + public Map getProperties() ; /** * Set a single property . @@ -229,7 +235,7 @@ public interface Group extends Serializable { * @param value an Object * @see #getProperty */ - void setProperty(String key, Object value); + public void setProperty(String key, Object value) ; /** * Get a single property . @@ -238,20 +244,21 @@ public interface Group extends Serializable { * @return an Object * @see #setProperty */ - Object getProperty(String key); + public Object getProperty(String key) ; /** * Get an Atom Iterator. * * @return an Iterator object */ - Iterator iterator(); + public Iterator iterator() ; + /** * Returns and identical copy of this Group object . * @return and identical copy of this Group object */ - Object clone(); + public Object clone(); /** * Sets the back-reference to its parent Chain. @@ -259,7 +266,7 @@ public interface Group extends Serializable { * @see #getChain() * @since 3.0 */ - void setChain(Chain chain); + public void setChain(Chain chain); /** * Returns the parent Chain of the Group. @@ -268,7 +275,7 @@ public interface Group extends Serializable { * @see #setChain(Chain) * @since 3.0 */ - Chain getChain(); + public Chain getChain() ; /** * Returns a dynamically created ResidueNumber for the group - this @@ -277,14 +284,15 @@ public interface Group extends Serializable { * @return ResidueNumber for the group. * @since 3.0 */ - ResidueNumber getResidueNumber(); + public ResidueNumber getResidueNumber(); + /** * Sets the ResidueNumber for this Group * * @param residueNumber the PDB residueNumber */ - void setResidueNumber(ResidueNumber residueNumber); + public void setResidueNumber(ResidueNumber residueNumber); /** * Utility method to temporarily set a chainID for a group, if a parent chain object does not exist yet. @@ -294,7 +302,7 @@ public interface Group extends Serializable { * @param residueNumber * @param iCode */ - void setResidueNumber(String chainId, Integer residueNumber, Character iCode); + public void setResidueNumber(String chainId, Integer residueNumber, Character iCode); /** * Utility method for returning the chainId of the Group or null if no @@ -304,21 +312,22 @@ public interface Group extends Serializable { * @since 3.0 * @return the ID of the chain */ - String getChainId(); + public String getChainId(); /** * Set the Chemical Component that closer describes this group. * * @param cc the chemical component */ - void setChemComp(ChemComp cc); + public void setChemComp(ChemComp cc); /** * Get the chemical component that closer describes this group. If the information does not exist yet, fetches the information from PDB web site. * * @return the Chemical Component definition for this Group. */ - ChemComp getChemComp(); + public ChemComp getChemComp(); + /** * Check if this group has alternate location groups. @@ -326,7 +335,8 @@ public interface Group extends Serializable { * @return boolean flag if there are alternate locations. * @see #getAltLocs() */ - boolean hasAltLoc(); + public boolean hasAltLoc(); + /** * Get the list of other alternate location groups. @@ -351,14 +361,14 @@ public interface Group extends Serializable { * * @return List of other groups that are on alternate locations */ - List getAltLocs(); + public List getAltLocs(); /** * Add a group that is an alternate location for this group. * * @param g the altloc group to add */ - void addAltLoc(Group g); + public void addAltLoc(Group g); /** * Determines if this group is water. @@ -366,7 +376,7 @@ public interface Group extends Serializable { * @see GroupType#WATERNAMES * @return true if it's water, false otherwise. */ - boolean isWater(); + public boolean isWater(); /** * Gets the alternate location group to this group that has the alt-loc character code passed. @@ -374,20 +384,21 @@ public interface Group extends Serializable { * @param altLoc the alternate location code of the group desired * @return the alternate location group if found, or null otherwise */ - Group getAltLocGroup(Character altLoc); + public Group getAltLocGroup(Character altLoc); + /** * Attempts to reduce the memory imprint of this group by trimming * all internal Collection objects to the required size. * */ - void trimToSize(); + public void trimToSize(); /** * Function to get the Group as an MDL molblock * @return the string of the MDL molblock */ - String toSDF(); + public String toSDF(); /** * Tells whether the group is annotated as HETATM in the file. @@ -395,7 +406,7 @@ public interface Group extends Serializable { * polymeric group is in a ligand chain or not. * @return */ - boolean isHetAtomInFile(); + public boolean isHetAtomInFile(); /** * Sets the field isHetAtomInFile which is intented only for @@ -403,5 +414,5 @@ public interface Group extends Serializable { * or in a polymeric chain. * @param isHetAtomInFile */ - void setHetAtomInFile(boolean isHetAtomInFile); + public void setHetAtomInFile(boolean isHetAtomInFile); } diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/StructureIO.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/StructureIO.java index fb2967b101..c556d4444c 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/StructureIO.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/StructureIO.java @@ -21,6 +21,7 @@ package org.biojava.nbio.structure; import org.biojava.nbio.structure.align.util.AtomCache; +import org.biojava.nbio.structure.io.StructureFiletype; import java.io.IOException; import java.util.List; diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/URLIdentifier.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/URLIdentifier.java index 00b624d95f..69b5833766 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/URLIdentifier.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/URLIdentifier.java @@ -20,10 +20,10 @@ */ package org.biojava.nbio.structure; -import org.biojava.nbio.structure.StructureFiletype; import org.biojava.nbio.structure.align.util.AtomCache; import org.biojava.nbio.structure.io.PDBFileReader; -import org.biojava.nbio.structure.io.cif.StructureConverter; +import org.biojava.nbio.structure.io.cif.CifStructureConverter; +import org.biojava.nbio.structure.io.StructureFiletype; import org.biojava.nbio.structure.io.mmtf.MmtfActions; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -33,7 +33,6 @@ import java.net.MalformedURLException; import java.net.URL; import java.net.URLDecoder; -import java.util.Arrays; import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; @@ -154,7 +153,7 @@ public Structure loadStructure(AtomCache cache) throws StructureException, IOExc switch(format) { case CIF: case BCIF: - return StructureConverter.fromURL(url); + return CifStructureConverter.fromURL(url); case MMTF: return MmtfActions.readFromInputStream(url.openStream()); default: case PDB: diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/align/util/AtomCache.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/align/util/AtomCache.java index 3067e5955d..552f0427ef 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/align/util/AtomCache.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/align/util/AtomCache.java @@ -41,6 +41,7 @@ import org.biojava.nbio.structure.io.MMTFFileReader; import org.biojava.nbio.structure.io.PDBFileReader; import org.biojava.nbio.core.util.FileDownloadUtils; +import org.biojava.nbio.structure.io.StructureFiletype; import org.biojava.nbio.structure.quaternary.BiologicalAssemblyBuilder; import org.biojava.nbio.structure.quaternary.BiologicalAssemblyTransformation; import org.biojava.nbio.structure.scop.ScopDatabase; diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/align/util/UserConfiguration.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/align/util/UserConfiguration.java index ebcf3aaba6..70e85acec3 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/align/util/UserConfiguration.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/align/util/UserConfiguration.java @@ -19,12 +19,12 @@ package org.biojava.nbio.structure.align.util; -import org.biojava.nbio.structure.StructureFiletype; import org.biojava.nbio.structure.align.ce.StartupParameters; import org.biojava.nbio.structure.io.LocalPDBDirectory.FetchBehavior; import org.biojava.nbio.structure.io.LocalPDBDirectory.ObsoleteBehavior; import org.biojava.nbio.core.util.PrettyXMLWriter; import org.biojava.nbio.core.util.XMLWriter; +import org.biojava.nbio.structure.io.StructureFiletype; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -34,18 +34,21 @@ import java.util.Map; import java.util.concurrent.atomic.AtomicBoolean; -/** - * A container to persist config to the file system + +/** A container to persist config to the file system * * @author Andreas Prlic + * */ -public class UserConfiguration { +public class UserConfiguration +{ + private static final Logger logger = LoggerFactory.getLogger(UserConfiguration.class); public static final String PDB_FORMAT = "PDB"; - public static final String MMCIF_FORMAT = "cif"; - public static final String BINARY_CIF = "bcif"; + public static final String MMCIF_FORMAT = "mmCif"; public static final String MMTF_FORMAT = "mmtf"; + public static final String BCIF_FORMAT = "bcif"; public static final String TMP_DIR = "java.io.tmpdir"; @@ -62,7 +65,8 @@ public class UserConfiguration { private String fileFormat; - private static final AtomicBoolean warningShown = new AtomicBoolean(false); + private static AtomicBoolean warningShown = new AtomicBoolean(false); + /** * Default UserConfiguration: @@ -96,51 +100,66 @@ public UserConfiguration(){ // note that in initCacheFilePath, we set to the provided one (if readable) or to the same as pdbFilePath cacheFilePath = initCacheFilePath(); - fileFormat = BINARY_CIF; + fileFormat = BCIF_FORMAT; } private String initPdbFilePath() { + String path = null; + String propertyName = PDB_DIR; + String userProvidedDir = System.getProperty(propertyName); - if (userProvidedDir != null && !userProvidedDir.trim().isEmpty()) { + if ( userProvidedDir != null && !userProvidedDir.trim().isEmpty()) { + path = userProvidedDir; logger.debug("Read PDB dir from system property {}: {}", propertyName, path); File f = new File(path); if (!f.isDirectory()) { - logger.warn("Provided path {} (with system property {}) is not a directory. Using system's temp " + - "directory instead {}", path, propertyName, System.getProperty(TMP_DIR)); + logger.warn( + "Provided path {} (with system property {}) is not a directory. Using system's temp directory instead {}", + path, propertyName, System.getProperty(TMP_DIR)); path = System.getProperty(TMP_DIR); } else if (!f.canWrite()) { - logger.warn("Provided path {} (with system property {}) is not writable. Will not be able to write " + - "cached files.", path, propertyName); + logger.warn( + "Provided path {} (with system property {}) is not writable. Will not be able to write cached files.", + path, propertyName); // we don't require the PDB_DIR to be writable, so that it can be used with a pre-rsynced dir // thus if not writable, we only warn and go ahead using it } + + } else { Map env = System.getenv(); - if (env.containsKey(propertyName) && !env.get(propertyName).trim().isEmpty()) { + + if( env.containsKey(propertyName) && !env.get(propertyName).trim().isEmpty()) { path = env.get(propertyName); logger.debug("Read dir from environment variable {}: {}", propertyName, path); File f = new File(path); if (!f.isDirectory()) { - logger.warn("Provided path {} (with environment variable {}) is not a directory. Using system's " + - "temp directory instead {}", path, propertyName, System.getProperty(TMP_DIR)); + logger.warn( + "Provided path {} (with environment variable {}) is not a directory. Using system's temp directory instead {}", + path, propertyName, System.getProperty(TMP_DIR)); path = System.getProperty(TMP_DIR); } else if (!f.canWrite()) { - logger.warn("Provided path {} (with environment variable {}) is not writable. Will not be able " + - "to write cached files", path, propertyName); + logger.warn( + "Provided path {} (with environment variable {}) is not writable. Will not be able to write cached files", + path, propertyName); // we don't require the PDB_DIR to be writable, so that it can be used with a pre-rsynced dir // thus if not writable, we only warn and go ahead using it } + } else { path = System.getProperty(TMP_DIR); - if (! warningShown.get()) { - logger.warn("Could not read dir from system property {} or environment variable {}, " + - "using system's temp directory {}", propertyName, propertyName, path); + if ( ! warningShown.get()) { + + logger.warn("Could not read dir from system property {} or environment variable {}, " + + "using system's temp directory {}", + propertyName, propertyName, path); + warningShown.set(true); } @@ -148,79 +167,95 @@ private String initPdbFilePath() { } } - if (!path.endsWith(lineSplit)) { + if ( ! path.endsWith(lineSplit) ) path = path + lineSplit; - } return path; + } private String initCacheFilePath() { + String path = null; + String propertyName = PDB_CACHE_DIR; + String userProvidedDir = System.getProperty(propertyName); - if (userProvidedDir != null) { + if ( userProvidedDir != null ) { + path = userProvidedDir; logger.debug("Read cache dir from system property {}: {}", propertyName, path); File f = new File(path); if (!f.isDirectory()) { - logger.warn("Provided path {} (with system property {}) is not a directory. Using system's temp " + - "directory instead {}", path, propertyName, System.getProperty(TMP_DIR)); + logger.warn( + "Provided path {} (with system property {}) is not a directory. Using system's temp directory instead {}", + path, propertyName, System.getProperty(TMP_DIR)); path = System.getProperty(TMP_DIR); } else if (!f.canWrite()) { - logger.warn("Provided path {} (with system property {}) is not writable. Using system's temp " + - "directory instead {}", path, propertyName, System.getProperty(TMP_DIR)); + logger.warn( + "Provided path {} (with system property {}) is not writable. Using system's temp directory instead {}", + path, propertyName, System.getProperty(TMP_DIR)); path = System.getProperty(TMP_DIR); System.setProperty(propertyName,path); } + + } else { Map env = System.getenv(); - if (env.containsKey(propertyName)) { + if( env.containsKey(propertyName)) { path = env.get(propertyName); logger.debug("Read dir from environment variable {}: {}", propertyName, path); File f = new File(path); if (!f.isDirectory()) { - logger.warn("Provided path {} (with environment variable {}) is not a directory. Using system's " + - "temp directory instead {}", path, propertyName, System.getProperty(TMP_DIR)); + logger.warn( + "Provided path {} (with environment variable {}) is not a directory. Using system's temp directory instead {}", + path, propertyName, System.getProperty(TMP_DIR)); path = System.getProperty(TMP_DIR); } else if (!f.canWrite()) { - logger.warn("Provided path {} (with environment variable {}) is not writable. Using system's " + - "temp directory instead {}", path, propertyName, System.getProperty(TMP_DIR)); + logger.warn( + "Provided path {} (with environment variable {}) is not writable. Using system's temp directory instead {}", + path, propertyName, System.getProperty(TMP_DIR)); path = System.getProperty(TMP_DIR); } + } else { // NOTE in case of not provided, then it is set to same as pdbFilePath // as PDB_DIR is not checked for being writable, we have to do that check here in case if (new File(pdbFilePath).canWrite()){ path = pdbFilePath; - logger.info("Could not read cache dir from system property {} or environment variable {}, " + - "using PDB directory instead {}", propertyName, propertyName, path); + logger.info("Could not read cache dir from system property {} or environment variable {}, " + + "using PDB directory instead {}", + propertyName, propertyName, path); System.setProperty(propertyName,path); + } else { path = System.getProperty(TMP_DIR); logger.warn("Could not read cache dir from system property {} or environment variable {}, " + "and PDB directory {} is not writable. Using system's temp directory instead {}", propertyName, propertyName, pdbFilePath, path); System.setProperty(propertyName,path); + } } } - if (!path.endsWith(lineSplit)) { + if ( ! path.endsWith(lineSplit) ) path = path + lineSplit; - } return path; + } - public String getPdbFilePath() { + public String getPdbFilePath() + { return pdbFilePath; } - public void setPdbFilePath(String pdbFilePath) { + public void setPdbFilePath(String pdbFilePath) + { this.pdbFilePath = pdbFilePath; } @@ -248,22 +283,24 @@ public void setObsoleteBehavior(ObsoleteBehavior obsoleteBehavior) { this.obsoleteBehavior = obsoleteBehavior; } - /** - * convert Configuration to an XML file so it can be serialized + /** convert Configuration to an XML file so it can be serialized * * @param pw * @return XMLWriter * @throws IOException */ - public XMLWriter toXML(PrintWriter pw) throws IOException { - XMLWriter xw = new PrettyXMLWriter(pw); + public XMLWriter toXML(PrintWriter pw) + throws IOException + { + + XMLWriter xw = new PrettyXMLWriter( pw); + toXML(xw); - return xw; - } + return xw ; + } - /** - * convert Configuration to an XML file so it can be serialized + /** convert Configuration to an XML file so it can be serialized * add to an already existing xml file. * * @param xw the XML writer to use @@ -271,7 +308,10 @@ public XMLWriter toXML(PrintWriter pw) throws IOException { * @throws IOException * @see org.biojava.nbio.structure.align.webstart.ConfigXMLHandler */ - public XMLWriter toXML(XMLWriter xw) throws IOException { + + public XMLWriter toXML(XMLWriter xw) + throws IOException + { xw.printRaw(""); //xw.printRaw(""); xw.openTag("JFatCatConfig"); @@ -279,18 +319,18 @@ public XMLWriter toXML(XMLWriter xw) throws IOException { xw.openTag("PDBFILEPATH"); // we don;t serialize the tempdir... String tempdir = System.getProperty(TMP_DIR); - if (!pdbFilePath.equals(tempdir)) { + if (! pdbFilePath.equals(tempdir)) xw.attribute("path", pdbFilePath); - } - xw.attribute("fetchBehavior", fetchBehavior + ""); - xw.attribute("obsoleteBehavior", obsoleteBehavior + ""); + xw.attribute("fetchBehavior", fetchBehavior+""); + xw.attribute("obsoleteBehavior", obsoleteBehavior+""); xw.attribute("fileFormat", fileFormat); xw.closeTag("PDBFILEPATH"); xw.closeTag("JFatCatConfig"); return xw ; - } + + } public static UserConfiguration fromStartupParams(StartupParameters params) { UserConfiguration config = new UserConfiguration(); @@ -311,7 +351,8 @@ public void setFileFormat (String fileFormat){ this.fileFormat = fileFormat; } - public String getFileFormat() { + public String getFileFormat() + { return fileFormat; } @@ -319,12 +360,11 @@ public StructureFiletype getStructureFiletype() { switch (fileFormat) { case MMCIF_FORMAT: return StructureFiletype.CIF; - case BINARY_CIF: - return StructureFiletype.BCIF; - case MMTF_FORMAT: - return StructureFiletype.MMTF; case PDB_FORMAT: return StructureFiletype.PDB; + case MMTF_FORMAT: + return StructureFiletype.MMTF; + case BCIF_FORMAT: default: return StructureFiletype.BCIF; } diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemComp.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemComp.java index f550d82a96..76043374fc 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemComp.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemComp.java @@ -8,8 +8,10 @@ /** * Properties of a chemical component. + * @author Sebastian Bittrich + * @since 6.0.0 */ -public class ChemComp implements CifBean, Comparable { +public class ChemComp implements CifBean, Comparable { private static final long serialVersionUID = -4736341142030215915L; private String id; diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemCompAtom.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemCompAtom.java index d87a51e720..f99b3d6f74 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemCompAtom.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemCompAtom.java @@ -2,7 +2,12 @@ import org.biojava.nbio.structure.io.cif.CifBean; -public class ChemCompAtom implements CifBean { +/** + * Properties of an atom of a chemical component. + * @author Sebastian Bittrich + * @since 6.0.0 + */ +public class ChemCompAtom implements CifBean { private static final long serialVersionUID = 4070599340294758941L; private String compId; private String atomId; diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemCompBond.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemCompBond.java index 6ac2ea25fd..8bc3b1ebdb 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemCompBond.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemCompBond.java @@ -4,7 +4,12 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class ChemCompBond implements CifBean { +/** + * Properties of a bond in a chemical component. + * @author Sebastian Bittrich + * @since 6.0.0 + */ +public class ChemCompBond implements CifBean { private static final long serialVersionUID = 5905371029161975421L; private static final Logger logger = LoggerFactory.getLogger(ChemCompBond.class); diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemCompDescriptor.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemCompDescriptor.java index 7628caef53..eb0cb13b5f 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemCompDescriptor.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemCompDescriptor.java @@ -4,7 +4,12 @@ import java.util.Objects; -public class ChemCompDescriptor implements CifBean { +/** + * Properties of the chemical component descriptor. + * @author Sebastian Bittrich + * @since 6.0.0 + */ +public class ChemCompDescriptor implements CifBean { private static final long serialVersionUID = 1078685833800736278L; private String compId; private String type; diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/BcifFileReader.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/BcifFileReader.java index a122158aee..70e4b5fcf5 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/BcifFileReader.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/BcifFileReader.java @@ -2,14 +2,14 @@ import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.align.util.UserConfiguration; -import org.biojava.nbio.structure.io.cif.StructureConverter; +import org.biojava.nbio.structure.io.cif.CifStructureConverter; import java.io.IOException; import java.io.InputStream; /** * Parse binary Cif files and provide capabilities to store them locally. - * @author Sebastian Bittrich + * @author Sebastian Bittrich * @since 5.3.0 */ public class BcifFileReader extends LocalPDBDirectory { @@ -38,7 +38,7 @@ public BcifFileReader(String path) { @Override public Structure getStructure(InputStream inStream) throws IOException { - return StructureConverter.fromInputStream(inStream, getFileParsingParameters()); + return CifStructureConverter.fromInputStream(inStream, getFileParsingParameters()); } @Override diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/CifFileReader.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/CifFileReader.java index edfe601b8d..6afaf14717 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/CifFileReader.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/CifFileReader.java @@ -2,14 +2,14 @@ import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.align.util.UserConfiguration; -import org.biojava.nbio.structure.io.cif.StructureConverter; +import org.biojava.nbio.structure.io.cif.CifStructureConverter; import java.io.IOException; import java.io.InputStream; /** * Parse text Cif files and provide capabilities to store them locally. - * @author Sebastian Bittrich + * @author Sebastian Bittrich * @since 5.3.0 */ public class CifFileReader extends LocalPDBDirectory { @@ -40,7 +40,7 @@ public CifFileReader(String path) { @Override public Structure getStructure(InputStream inStream) throws IOException{ - return StructureConverter.fromInputStream(inStream, getFileParsingParameters()); + return CifStructureConverter.fromInputStream(inStream, getFileParsingParameters()); } @Override 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 8264fb2b3f..35654bcb17 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 @@ -40,7 +40,7 @@ import org.biojava.nbio.structure.PDBHeader; import org.biojava.nbio.structure.Site; import org.biojava.nbio.structure.Structure; -import org.biojava.nbio.structure.io.cif.StructureConverter; +import org.biojava.nbio.structure.io.cif.CifStructureConverter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -592,11 +592,20 @@ else if (name.length()==1) } + /** + * Convert this structure to its CIF representation. + * @return a String representing this structure as CIF + */ public String toMMCIF() { - return StructureConverter.toText(this.structure); + return CifStructureConverter.toText(this.structure); } + /** + * Convert a chain to its CIF representation. + * @param chain data + * @return a String representing this chain as CIF + */ public static String toMMCIF(Chain chain) { - return StructureConverter.toText(chain); + return CifStructureConverter.toText(chain); } } diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/StructureFiletype.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/StructureFiletype.java similarity index 75% rename from biojava-structure/src/main/java/org/biojava/nbio/structure/StructureFiletype.java rename to biojava-structure/src/main/java/org/biojava/nbio/structure/io/StructureFiletype.java index 6d56257f24..04a74a6220 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/StructureFiletype.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/StructureFiletype.java @@ -1,15 +1,12 @@ -package org.biojava.nbio.structure; - -import org.biojava.nbio.structure.io.BcifFileReader; -import org.biojava.nbio.structure.io.CifFileReader; -import org.biojava.nbio.structure.io.MMTFFileReader; -import org.biojava.nbio.structure.io.PDBFileReader; +package org.biojava.nbio.structure.io; import java.util.Collections; import java.util.List; /** * An enum of supported file formats. + * @author Sebastian Bittrich + * @since 6.0.0 */ public enum StructureFiletype { PDB(new PDBFileReader().getExtensions()), diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/AbstractCifFileSupplier.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/AbstractCifFileSupplier.java index 2cb5e11acf..4b9c3045b6 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/AbstractCifFileSupplier.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/AbstractCifFileSupplier.java @@ -28,7 +28,7 @@ /** * Convert a BioJava object to a CifFile. - * @author Sebastian Bittrich + * @author Sebastian Bittrich * @since 5.3.0 */ public abstract class AbstractCifFileSupplier implements CifFileSupplier { @@ -127,6 +127,10 @@ protected void handleChain(Chain chain, int model, List wrappedAtom } } + /** + * Wrapped atoms represent individual atoms enriched with model- and chain-level information. Also, gives control + * over the atomId field. Useful to convert structures (and subsets thereof) to their mmCIF representation. + */ public static class WrappedAtom { private final int model; private final String chainName; @@ -134,6 +138,14 @@ public static class WrappedAtom { private final Atom atom; private final int atomId; + /** + * Construct a new atoms. + * @param model the model number + * @param chainName the label_asym_id + * @param chainId the auth_asym_id + * @param atom the atom instance itself + * @param atomId the label_atom_id + */ public WrappedAtom(int model, String chainName, String chainId, Atom atom, int atomId) { this.model = model; this.chainName = chainName; @@ -142,27 +154,31 @@ public WrappedAtom(int model, String chainName, String chainId, Atom atom, int a this.atomId = atomId; } - int getModel() { + public int getModel() { return model; } - String getChainName() { + public String getChainName() { return chainName; } - String getChainId() { + public String getChainId() { return chainId; } - Atom getAtom() { + public Atom getAtom() { return atom; } - int getAtomId() { + public int getAtomId() { return atomId; } } + /** + * Collects {@link WrappedAtom} instances into one {@link org.rcsb.cif.schema.mm.AtomSite}. + * @return an atom site record containing all atoms + */ public static Collector toAtomSite() { return Collector.of(AtomSiteCollector::new, AtomSiteCollector::accept, diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/ChemCompConsumer.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/ChemCompConsumer.java index 5bbb3f7a6a..26bd53884d 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/ChemCompConsumer.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/ChemCompConsumer.java @@ -1,16 +1,32 @@ package org.biojava.nbio.structure.io.cif; -import org.biojava.nbio.structure.chem.ChemCompDescriptor; import org.biojava.nbio.structure.chem.ChemicalComponentDictionary; import org.rcsb.cif.schema.mm.ChemComp; import org.rcsb.cif.schema.mm.ChemCompAtom; import org.rcsb.cif.schema.mm.ChemCompBond; +/** + * Create the {@link ChemicalComponentDictionary} from CIF data. + * @author Sebastian Bittrich + * @since 6.0.0 + */ public interface ChemCompConsumer extends CifFileConsumer { + /** + * Consume a particular Cif category. + * @param c data + */ void consumeChemComp(ChemComp c); + /** + * Consume a particular Cif category. + * @param atom data + */ void consumeChemCompAtom(ChemCompAtom atom); + /** + * Consume a particular Cif category. + * @param bond data + */ void consumeChemCompBond(ChemCompBond bond); } diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/ChemCompConsumerImpl.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/ChemCompConsumerImpl.java index ffe61f2d0b..584d8c6dfa 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/ChemCompConsumerImpl.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/ChemCompConsumerImpl.java @@ -7,6 +7,10 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +/** + * Consumes a CCD file to create the {@link ChemicalComponentDictionary}. + * @author Sebastian Bittrich + */ public class ChemCompConsumerImpl implements ChemCompConsumer { private static final Logger logger = LoggerFactory.getLogger(ChemCompConsumerImpl.class); private final ChemicalComponentDictionary dictionary; diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/ChemCompConverter.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/ChemCompConverter.java index aec300e717..497af0f0da 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/ChemCompConverter.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/ChemCompConverter.java @@ -16,7 +16,7 @@ /** * Convert CifFiles to chem comps. - * @author Sebastian Bittrich + * @author Sebastian Bittrich * @since 6.0.0 */ public class ChemCompConverter { @@ -44,7 +44,7 @@ public static ChemicalComponentDictionary fromURL(URL url) throws IOException { * @param inputStream the InputStream of information - can be gzipped or binary or text data * @return the target * @throws IOException thrown when reading fails - * @see StructureConverter#fromInputStream(InputStream, FileParsingParameters) + * @see CifStructureConverter#fromInputStream(InputStream, FileParsingParameters) */ public static ChemicalComponentDictionary fromInputStream(InputStream inputStream) throws IOException { return fromCifFile(CifIO.readFromInputStream(inputStream)); diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/CifBean.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/CifBean.java index 1196aafada..9adf3b3e43 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/CifBean.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/CifBean.java @@ -1,12 +1,11 @@ package org.biojava.nbio.structure.io.cif; -import org.rcsb.cif.model.Category; - import java.io.Serializable; /** - * Flag for BioJava beans that actually resemble categories defined by the mmCIF schema. - * @param the modeled ciftools-java category + * Flag for BioJava beans that resemble categories defined by the mmCIF schema. + * @author Sebastian Bittrich + * @since 6.0.0 */ -public interface CifBean extends Serializable { +public interface CifBean extends Serializable { } diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/ChainSupplierImpl.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/CifChainSupplierImpl.java similarity index 77% rename from biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/ChainSupplierImpl.java rename to biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/CifChainSupplierImpl.java index 08516d47b3..98e9da2f4e 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/ChainSupplierImpl.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/CifChainSupplierImpl.java @@ -6,7 +6,11 @@ import java.util.ArrayList; import java.util.List; -public class ChainSupplierImpl extends AbstractCifFileSupplier { +/** + * Convert a chain to a {@link CifFile}. + * @author Sebastian Bittrich + */ +public class CifChainSupplierImpl extends AbstractCifFileSupplier { @Override public CifFile get(Chain container) { return getInternal(container.getStructure(), collectWrappedAtoms(container)); diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/CifFileConsumer.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/CifFileConsumer.java index d95f7b9422..565868e516 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/CifFileConsumer.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/CifFileConsumer.java @@ -2,9 +2,8 @@ /** * Defines a rather generic interface which allows to populate some data structure with data parsed from a CIF file. - * * @param the type of container an implementing class will return - * @author Sebastian Bittrich + * @author Sebastian Bittrich * @since 5.3.0 */ public interface CifFileConsumer { diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/CifFileSupplier.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/CifFileSupplier.java index e46a0bf058..0ea1e06bd7 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/CifFileSupplier.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/CifFileSupplier.java @@ -5,7 +5,7 @@ /** * Create a CifFile instance for a given container of structure data. * @param the container type used as source - * @author Sebastian Bittrich + * @author Sebastian Bittrich * @since 5.3.0 */ public interface CifFileSupplier { diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/StructureConsumer.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/CifStructureConsumer.java similarity index 98% rename from biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/StructureConsumer.java rename to biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/CifStructureConsumer.java index 9594a2c71d..c6c5318217 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/StructureConsumer.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/CifStructureConsumer.java @@ -47,7 +47,12 @@ import org.rcsb.cif.schema.mm.StructSiteGen; import org.rcsb.cif.schema.mm.Symmetry; -public interface StructureConsumer extends CifFileConsumer { +/** + * Defines the categories to consume during CIF parsing. + * @author Sebastian Bittrich + * @since 6.0.0 + */ +public interface CifStructureConsumer extends CifFileConsumer { /** * Consume a particular Cif category. * @param atomSite data diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/StructureConsumerImpl.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/CifStructureConsumerImpl.java similarity index 99% rename from biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/StructureConsumerImpl.java rename to biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/CifStructureConsumerImpl.java index 35f46dc066..c64f1ac412 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/StructureConsumerImpl.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/CifStructureConsumerImpl.java @@ -100,11 +100,11 @@ /** * An implementation of a CifFileConsumer for BioJava. Will process the information provided by a CifFile instance and * use it to build up a {@link Structure} object. - * @author Sebastian Bittrich + * @author Sebastian Bittrich * @since 6.0.0 */ -public class StructureConsumerImpl implements StructureConsumer { - private static final Logger logger = LoggerFactory.getLogger(StructureConsumerImpl.class); +public class CifStructureConsumerImpl implements CifStructureConsumer { + private static final Logger logger = LoggerFactory.getLogger(CifStructureConsumerImpl.class); private static final DateTimeFormatter DATE_FORMAT = new DateTimeFormatterBuilder() .parseCaseInsensitive() .appendPattern("yyyy-MM-dd") @@ -141,7 +141,7 @@ public class StructureConsumerImpl implements StructureConsumer { private final FileParsingParameters params; - public StructureConsumerImpl(FileParsingParameters params) { + public CifStructureConsumerImpl(FileParsingParameters params) { this.params = params; } diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/StructureConverter.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/CifStructureConverter.java similarity index 95% rename from biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/StructureConverter.java rename to biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/CifStructureConverter.java index 45a5b97c76..98ef24561b 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/StructureConverter.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/CifStructureConverter.java @@ -17,10 +17,10 @@ /** * Convert BioJava structures to CifFiles and vice versa. - * @author Sebastian Bittrich + * @author Sebastian Bittrich * @since 6.0.0 */ -public class StructureConverter { +public class CifStructureConverter { /** * Read data from a file and convert to Structure without any FileParsingParameters. * @param path the source of information - can be gzipped or binary or text data @@ -66,7 +66,7 @@ private static Structure fromURL(URL url, FileParsingParameters parameters) thro * @param inputStream the InputStream of information - can be gzipped or binary or text data * @return the target * @throws IOException thrown when reading fails - * @see StructureConverter#fromInputStream(InputStream, FileParsingParameters) + * @see CifStructureConverter#fromInputStream(InputStream, FileParsingParameters) */ public static Structure fromInputStream(InputStream inputStream) throws IOException { return fromInputStream(inputStream, new FileParsingParameters()); @@ -87,7 +87,7 @@ public static Structure fromInputStream(InputStream inputStream, FileParsingPara * Convert CifFile to Structure without any FileParsingParameters. * @param cifFile the source * @return the target - * @see StructureConverter#fromCifFile(CifFile, FileParsingParameters) + * @see CifStructureConverter#fromCifFile(CifFile, FileParsingParameters) */ public static Structure fromCifFile(CifFile cifFile) { return fromCifFile(cifFile, new FileParsingParameters()); @@ -101,7 +101,7 @@ public static Structure fromCifFile(CifFile cifFile) { */ public static Structure fromCifFile(CifFile cifFile, FileParsingParameters parameters) { // initialize consumer - StructureConsumer consumer = new StructureConsumerImpl(parameters); + CifStructureConsumer consumer = new CifStructureConsumerImpl(parameters); // init structure consumer.prepare(); @@ -226,7 +226,7 @@ public static String toText(Chain chain) { * @return the target */ public static CifFile toCifFile(Structure structure) { - return new StructureSupplierImpl().get(structure); + return new CifStructureSupplierImpl().get(structure); } /** @@ -235,6 +235,6 @@ public static CifFile toCifFile(Structure structure) { * @return the target */ public static CifFile toCifFile(Chain chain) { - return new ChainSupplierImpl().get(chain); + return new CifChainSupplierImpl().get(chain); } } diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/StructureSupplierImpl.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/CifStructureSupplierImpl.java similarity index 83% rename from biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/StructureSupplierImpl.java rename to biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/CifStructureSupplierImpl.java index ef377ad52a..4b0eb79eb3 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/StructureSupplierImpl.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/CifStructureSupplierImpl.java @@ -7,7 +7,11 @@ import java.util.ArrayList; import java.util.List; -public class StructureSupplierImpl extends AbstractCifFileSupplier { +/** + * Convert a structure to a CifFile. + * @author Sebastian Bittrich + */ +public class CifStructureSupplierImpl extends AbstractCifFileSupplier { @Override public CifFile get(Structure container) { return getInternal(container, collectWrappedAtoms(container)); diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/MetalBondConsumer.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/MetalBondConsumer.java index d76d91d1e7..df86c2c216 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/MetalBondConsumer.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/MetalBondConsumer.java @@ -6,6 +6,11 @@ import java.util.List; import java.util.Map; -public interface MetalBondConsumer extends CifFileConsumer>> { +/** + * Consume metal bond data. + * @author Sebastian Bittrich + * @since 6.0.0 + */ +public interface MetalBondConsumer extends CifFileConsumer>> { void consume(Category category); } diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/MetalBondConverter.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/MetalBondConverter.java index 0f28fe6493..c1ac0f3d2c 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/MetalBondConverter.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/MetalBondConverter.java @@ -17,7 +17,7 @@ public class MetalBondConverter { private static final Logger logger = LoggerFactory.getLogger(MetalBondConverter.class); private static final String BONDS_FILE = "org/biojava/nbio/structure/bond_distance_limits.cif.gz"; - private static Map> definitions; + private static final Map> definitions; static { definitions = init(); diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmtf/MmtfUtils.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmtf/MmtfUtils.java index a6c52c95bd..c41eb33033 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmtf/MmtfUtils.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmtf/MmtfUtils.java @@ -45,7 +45,7 @@ import org.biojava.nbio.structure.PDBCrystallographicInfo; import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.StructureException; -import org.biojava.nbio.structure.StructureFiletype; +import org.biojava.nbio.structure.io.StructureFiletype; import org.biojava.nbio.structure.StructureIO; import org.biojava.nbio.structure.align.util.AtomCache; import org.biojava.nbio.structure.chem.ChemComp; @@ -55,7 +55,6 @@ import org.biojava.nbio.structure.io.FileParsingParameters; import org.biojava.nbio.structure.quaternary.BioAssemblyInfo; import org.biojava.nbio.structure.quaternary.BiologicalAssemblyTransformation; -import org.biojava.nbio.structure.secstruc.DSSPParser; import org.biojava.nbio.structure.secstruc.SecStrucCalc; import org.biojava.nbio.structure.secstruc.SecStrucState; import org.biojava.nbio.structure.secstruc.SecStrucType; diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/Test2JA5.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/Test2JA5.java index eb7008d0cb..0d2a6d5742 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/Test2JA5.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/Test2JA5.java @@ -26,6 +26,7 @@ import org.biojava.nbio.structure.align.util.AtomCache; import org.biojava.nbio.structure.io.FileParsingParameters; +import org.biojava.nbio.structure.io.StructureFiletype; import org.junit.Test; /** diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/Test4hhb.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/Test4hhb.java index bcf289cebc..52e088261e 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/Test4hhb.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/Test4hhb.java @@ -26,7 +26,7 @@ import org.biojava.nbio.structure.io.FileParsingParameters; import org.biojava.nbio.structure.io.PDBFileParser; -import org.biojava.nbio.structure.io.cif.StructureConverter; +import org.biojava.nbio.structure.io.cif.CifStructureConverter; import org.junit.Test; import java.io.IOException; @@ -75,7 +75,7 @@ public void test4hhbPDBFile() throws IOException params = new FileParsingParameters(); params.setAlignSeqRes(true); - structure2 = StructureConverter.fromInputStream(inStream, params); + structure2 = CifStructureConverter.fromInputStream(inStream, params); assertNotNull(structure2); diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/TestAltLocs.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/TestAltLocs.java index ef9f830ae1..9c5bdcf0be 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/TestAltLocs.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/TestAltLocs.java @@ -27,13 +27,12 @@ import org.biojava.nbio.structure.chem.PolymerType; import org.biojava.nbio.structure.chem.ResidueType; import org.biojava.nbio.structure.io.FileParsingParameters; -import org.biojava.nbio.structure.io.cif.StructureConverter; +import org.biojava.nbio.structure.io.cif.CifStructureConverter; +import org.biojava.nbio.structure.io.StructureFiletype; import org.junit.Test; -import java.io.BufferedReader; import java.io.ByteArrayInputStream; import java.io.IOException; -import java.io.StringReader; import java.util.ArrayList; import java.util.HashSet; import java.util.List; @@ -639,7 +638,7 @@ public void testMmcifConversionPartialAltlocs() throws IOException { "ATOM 117 N NH2 A ARG A 1 13 ? 7.812 17.972 17.172 0.50 24.80 ? 102 ARG A NH2 1\n" + "ATOM 118 N NH2 B ARG A 1 13 ? 8.013 18.115 17.888 0.50 26.52 ? 102 ARG A NH2 1\n"; - Structure s = StructureConverter.fromInputStream(new ByteArrayInputStream(mmcifData.getBytes())); + Structure s = CifStructureConverter.fromInputStream(new ByteArrayInputStream(mmcifData.getBytes())); Chain c = s.getPolyChains().get(0); assertEquals(1, c.getAtomGroups().size()); Group g = c.getAtomGroup(0); @@ -718,7 +717,7 @@ public void testMmcifConversionAllAltlocs() throws IOException { "ATOM 216 C CD A PRO A 1 23 ? 14.980 32.886 23.580 0.50 6.98 ? 112 PRO A CD 1 \n" + "ATOM 217 C CD B PRO A 1 23 ? 14.558 33.235 23.153 0.50 14.91 ? 112 PRO A CD 1 \n"; - Structure s = StructureConverter.fromInputStream(new ByteArrayInputStream(mmcifData.getBytes())); + Structure s = CifStructureConverter.fromInputStream(new ByteArrayInputStream(mmcifData.getBytes())); Chain c = s.getPolyChains().get(0); assertEquals(1, c.getAtomGroups().size()); @@ -803,7 +802,7 @@ public void testIntraResidueBondsBetweenAltlocs() throws IOException { FileParsingParameters params = new FileParsingParameters(); params.setCreateAtomBonds(true); - Structure s = StructureConverter.fromInputStream(new ByteArrayInputStream(mmcifData.getBytes()), params); + Structure s = CifStructureConverter.fromInputStream(new ByteArrayInputStream(mmcifData.getBytes()), params); Chain c = s.getPolyChains().get(0); assertEquals(1, c.getAtomGroups().size()); @@ -949,7 +948,7 @@ public void testInterResidueBondsBetweenAltlocs() throws IOException { FileParsingParameters params = new FileParsingParameters(); params.setCreateAtomBonds(true); - Structure s = StructureConverter.fromInputStream(new ByteArrayInputStream(mmcifData.getBytes()), params); + Structure s = CifStructureConverter.fromInputStream(new ByteArrayInputStream(mmcifData.getBytes()), params); Chain c = s.getPolyChains().get(0); assertEquals(2, c.getAtomGroups().size()); diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/TestAtomCache.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/TestAtomCache.java index 5de3eca23a..bb9ec5ba2a 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/TestAtomCache.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/TestAtomCache.java @@ -30,6 +30,7 @@ import org.biojava.nbio.structure.io.LocalPDBDirectory.FetchBehavior; import org.biojava.nbio.structure.io.LocalPDBDirectory.ObsoleteBehavior; import org.biojava.nbio.structure.io.PDBFileReader; +import org.biojava.nbio.structure.io.StructureFiletype; import org.junit.Before; import org.junit.Test; diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/TestBond.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/TestBond.java index cd64006861..6cc9b2d05e 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/TestBond.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/TestBond.java @@ -28,6 +28,7 @@ import org.biojava.nbio.structure.chem.ChemCompGroupFactory; import org.biojava.nbio.structure.chem.DownloadChemCompProvider; import org.biojava.nbio.structure.io.FileParsingParameters; +import org.biojava.nbio.structure.io.StructureFiletype; import org.junit.BeforeClass; import org.junit.Test; import org.slf4j.Logger; diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/TestCloning.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/TestCloning.java index 4ce757bc91..516e96fce5 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/TestCloning.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/TestCloning.java @@ -30,6 +30,7 @@ import org.biojava.nbio.structure.align.util.AtomCache; import org.biojava.nbio.structure.io.FileParsingParameters; +import org.biojava.nbio.structure.io.StructureFiletype; import org.junit.Test; import static org.junit.Assert.*; diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/TestEntityResIndexMapping.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/TestEntityResIndexMapping.java index 401a42f2cb..61b3812a46 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/TestEntityResIndexMapping.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/TestEntityResIndexMapping.java @@ -31,6 +31,7 @@ import org.biojava.nbio.structure.align.util.AtomCache; import org.biojava.nbio.structure.io.FileParsingParameters; import org.biojava.nbio.structure.io.PDBFileParser; +import org.biojava.nbio.structure.io.StructureFiletype; import org.junit.Ignore; import org.junit.Test; diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/TestExperimentalTechniques.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/TestExperimentalTechniques.java index 6ef6224f8d..1edea84097 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/TestExperimentalTechniques.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/TestExperimentalTechniques.java @@ -21,6 +21,7 @@ package org.biojava.nbio.structure; import org.biojava.nbio.structure.align.util.AtomCache; +import org.biojava.nbio.structure.io.StructureFiletype; import org.junit.Test; import java.io.IOException; diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/TestLoadStructureFromURL.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/TestLoadStructureFromURL.java index fb182535f1..5ba56deb19 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/TestLoadStructureFromURL.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/TestLoadStructureFromURL.java @@ -23,6 +23,7 @@ import org.biojava.nbio.structure.align.util.AtomCache; import org.biojava.nbio.structure.align.util.UserConfiguration; import org.biojava.nbio.structure.io.PDBFileReader; +import org.biojava.nbio.structure.io.StructureFiletype; import org.junit.Test; import java.io.File; diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/TestParsingCalcium.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/TestParsingCalcium.java index c3212fac8c..096dff1e1a 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/TestParsingCalcium.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/TestParsingCalcium.java @@ -25,6 +25,7 @@ package org.biojava.nbio.structure; import org.biojava.nbio.structure.align.util.AtomCache; +import org.biojava.nbio.structure.io.StructureFiletype; import org.junit.Test; import java.io.IOException; diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/TestStructureCrossReferences.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/TestStructureCrossReferences.java index ebcea45acf..816d817231 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/TestStructureCrossReferences.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/TestStructureCrossReferences.java @@ -33,6 +33,7 @@ import org.biojava.nbio.structure.contact.StructureInterface; import org.biojava.nbio.structure.contact.StructureInterfaceList; import org.biojava.nbio.structure.io.FileParsingParameters; +import org.biojava.nbio.structure.io.StructureFiletype; import org.biojava.nbio.structure.xtal.CrystalBuilder; import org.junit.Test; import org.slf4j.Logger; diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/align/util/AtomCacheTest.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/align/util/AtomCacheTest.java index 1b30f95ad6..25a711e0b1 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/align/util/AtomCacheTest.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/align/util/AtomCacheTest.java @@ -47,7 +47,7 @@ import org.biojava.nbio.structure.ResidueRangeAndLength; import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.StructureException; -import org.biojava.nbio.structure.StructureFiletype; +import org.biojava.nbio.structure.io.StructureFiletype; import org.biojava.nbio.structure.StructureIO; import org.biojava.nbio.structure.StructureIdentifier; import org.biojava.nbio.structure.StructureTools; diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestDifficultMmCIFFiles.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestDifficultMmCIFFiles.java index 690f877f08..0edf607c86 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestDifficultMmCIFFiles.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestDifficultMmCIFFiles.java @@ -27,11 +27,9 @@ import static org.junit.Assume.assumeNotNull; import static org.junit.Assume.assumeTrue; -import java.io.BufferedReader; import java.io.File; import java.io.IOException; import java.io.InputStream; -import java.io.InputStreamReader; import java.net.URISyntaxException; import java.net.URL; import java.util.List; @@ -42,10 +40,9 @@ import org.biojava.nbio.structure.ResidueNumber; import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.StructureException; -import org.biojava.nbio.structure.StructureFiletype; import org.biojava.nbio.structure.StructureIO; import org.biojava.nbio.structure.align.util.AtomCache; -import org.biojava.nbio.structure.io.cif.StructureConverter; +import org.biojava.nbio.structure.io.cif.CifStructureConverter; import org.biojava.nbio.structure.quaternary.BioAssemblyInfo; import org.junit.Test; @@ -222,7 +219,7 @@ public void testQuotingCornerCase () throws IOException { FileParsingParameters fileParsingParams = new FileParsingParameters(); fileParsingParams.setAlignSeqRes(true); - Structure s = StructureConverter.fromInputStream(inStream, fileParsingParams); + Structure s = CifStructureConverter.fromInputStream(inStream, fileParsingParams); assertNotNull(s); diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestHardBioUnits.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestHardBioUnits.java index 2c73fe0e0d..b50b4524fc 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestHardBioUnits.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestHardBioUnits.java @@ -24,7 +24,6 @@ import org.biojava.nbio.structure.Chain; import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.StructureException; -import org.biojava.nbio.structure.StructureFiletype; import org.biojava.nbio.structure.StructureIO; import org.biojava.nbio.structure.StructureTools; import org.biojava.nbio.structure.align.util.AtomCache; diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestHeaderOnly.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestHeaderOnly.java index 7d246fc25e..5ac9537412 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestHeaderOnly.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestHeaderOnly.java @@ -31,12 +31,11 @@ import org.biojava.nbio.structure.Group; import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.StructureException; -import org.biojava.nbio.structure.StructureFiletype; import org.biojava.nbio.structure.StructureIO; import org.biojava.nbio.structure.align.util.AtomCache; import org.biojava.nbio.structure.chem.ChemComp; import org.biojava.nbio.structure.io.LocalPDBDirectory.FetchBehavior; -import org.biojava.nbio.structure.io.cif.StructureConverter; +import org.biojava.nbio.structure.io.cif.CifStructureConverter; import org.junit.Assert; import org.junit.Test; import org.slf4j.Logger; @@ -170,7 +169,7 @@ public void testSpeed2() throws StructureException, IOException { logger.info("Testing mmCIF parsing speed"); start = System.nanoTime(); - Structure s2 = StructureConverter.fromInputStream(cifStream, params); + Structure s2 = CifStructureConverter.fromInputStream(cifStream, params); stop = System.nanoTime(); diff = (stop - start) / 1000000000.0; logger.info(String.format("[%s] Elapsed time: %.3f s", s2.getIdentifier(), diff)); 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 6187f2127b..12b3d1a3b7 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 @@ -22,9 +22,7 @@ import static org.junit.Assert.*; -import java.io.BufferedReader; import java.io.File; -import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.Arrays; @@ -40,12 +38,11 @@ import org.biojava.nbio.structure.ResidueNumber; import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.StructureException; -import org.biojava.nbio.structure.StructureFiletype; import org.biojava.nbio.structure.StructureIO; import org.biojava.nbio.structure.StructureImpl; import org.biojava.nbio.structure.StructureTools; import org.biojava.nbio.structure.align.util.AtomCache; -import org.biojava.nbio.structure.io.cif.StructureConverter; +import org.biojava.nbio.structure.io.cif.CifStructureConverter; import org.junit.Test; public class TestMMCIFWriting { @@ -96,7 +93,7 @@ private static void testRoundTrip(String pdbId) throws IOException, StructureExc FileParsingParameters fileParsingParams = new FileParsingParameters(); fileParsingParams.setAlignSeqRes(true); - Structure readStruct = StructureConverter.fromPath(outputFile.toPath(), params); + Structure readStruct = CifStructureConverter.fromPath(outputFile.toPath(), params); assertNotNull(readStruct); diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestMMcifOrganismParsing.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestMMcifOrganismParsing.java index 31c309f68e..8d018f6c0a 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestMMcifOrganismParsing.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestMMcifOrganismParsing.java @@ -28,7 +28,6 @@ import org.biojava.nbio.structure.EntityType; import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.StructureException; -import org.biojava.nbio.structure.StructureFiletype; import org.biojava.nbio.structure.StructureIO; import org.biojava.nbio.structure.align.util.AtomCache; import org.junit.BeforeClass; diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestNonDepositedFiles.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestNonDepositedFiles.java index a604fffcaa..a04deda47d 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestNonDepositedFiles.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestNonDepositedFiles.java @@ -22,11 +22,9 @@ import static org.junit.Assert.*; -import java.io.BufferedReader; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; -import java.io.InputStreamReader; import java.net.URL; import java.util.List; import java.util.zip.GZIPInputStream; @@ -36,10 +34,9 @@ import org.biojava.nbio.structure.EntityType; import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.StructureException; -import org.biojava.nbio.structure.StructureFiletype; import org.biojava.nbio.structure.StructureIO; import org.biojava.nbio.structure.align.util.AtomCache; -import org.biojava.nbio.structure.io.cif.StructureConverter; +import org.biojava.nbio.structure.io.cif.CifStructureConverter; import org.biojava.nbio.structure.xtal.CrystalCell; import org.junit.Test; @@ -209,7 +206,7 @@ public void testPhenixCifFile() throws IOException { FileParsingParameters fileParsingParams = new FileParsingParameters(); fileParsingParams.setAlignSeqRes(true); - Structure s = StructureConverter.fromInputStream(inStream, fileParsingParams); + Structure s = CifStructureConverter.fromInputStream(inStream, fileParsingParams); assertNotNull(s); @@ -333,7 +330,7 @@ public void testNewLigandChain() throws IOException { int expectedNumLigands = 1; assertEquals(expectedNumLigands, c1.getAtomGroups().size()); - Structure s2 = StructureConverter.fromInputStream(cifStream, params); + Structure s2 = CifStructureConverter.fromInputStream(cifStream, params); // The chain B should be present with 1 ligand HEM Chain c2 = s2.getNonPolyChainsByPDB("B").get(0); @@ -373,7 +370,7 @@ public void testWaterOnlyChainCif() throws IOException { // following file is cut-down versions of 4a10 InputStream cifStream = new GZIPInputStream(this.getClass().getResourceAsStream("/org/biojava/nbio/structure/io/4a10_short.cif.gz")); - Structure s2 = StructureConverter.fromInputStream(cifStream); + Structure s2 = CifStructureConverter.fromInputStream(cifStream); assertEquals(2, s2.getChains().size()); @@ -431,7 +428,7 @@ public void testStructureWithBranchedEntities() throws IOException { URL url = new URL("https://raw.githubusercontent.com/pdbxmmcifwg/carbohydrate-extension/master/examples/models/1B5F-carb.cif"); InputStream inStream = url.openStream(); - Structure structure = StructureConverter.fromInputStream(inStream); + Structure structure = CifStructureConverter.fromInputStream(inStream); assertEquals(7, structure.getEntityInfos().size()); diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestParseMmCIFFeatures.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestParseMmCIFFeatures.java index f4d5a6d9d2..3042cc6269 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestParseMmCIFFeatures.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestParseMmCIFFeatures.java @@ -31,7 +31,6 @@ import org.biojava.nbio.structure.Site; import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.StructureException; -import org.biojava.nbio.structure.StructureFiletype; import org.biojava.nbio.structure.StructureIO; import org.biojava.nbio.structure.align.util.AtomCache; import org.junit.Test; diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestParseMmCIFLigands.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestParseMmCIFLigands.java index 76d7d74a3d..43017bf5d9 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestParseMmCIFLigands.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestParseMmCIFLigands.java @@ -29,7 +29,6 @@ import org.biojava.nbio.structure.Group; import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.StructureException; -import org.biojava.nbio.structure.StructureFiletype; import org.biojava.nbio.structure.StructureIO; import org.biojava.nbio.structure.align.util.AtomCache; import org.biojava.nbio.structure.chem.ChemCompGroupFactory; diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestParseOnAsymId.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestParseOnAsymId.java index fda734d668..45ca5f2211 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestParseOnAsymId.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestParseOnAsymId.java @@ -27,7 +27,6 @@ import org.biojava.nbio.structure.Chain; import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.StructureException; -import org.biojava.nbio.structure.StructureFiletype; import org.biojava.nbio.structure.StructureIO; import org.biojava.nbio.structure.align.util.AtomCache; import org.junit.Test; diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestTitleParsing.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestTitleParsing.java index 40b1368027..06e9f48484 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestTitleParsing.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestTitleParsing.java @@ -22,7 +22,6 @@ import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.StructureException; -import org.biojava.nbio.structure.StructureFiletype; import org.biojava.nbio.structure.StructureIO; import org.biojava.nbio.structure.align.util.AtomCache; import org.junit.Test; diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestWriteLargeCoordinatePDB.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestWriteLargeCoordinatePDB.java index 0588d54d01..eeb488a5d4 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestWriteLargeCoordinatePDB.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestWriteLargeCoordinatePDB.java @@ -28,7 +28,6 @@ import org.biojava.nbio.structure.Group; import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.StructureException; -import org.biojava.nbio.structure.StructureFiletype; import org.biojava.nbio.structure.StructureIO; import org.biojava.nbio.structure.align.util.AtomCache; import org.junit.Test; diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmcif/TestEntityNameAndType.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmcif/TestEntityNameAndType.java index 444a7b800e..5c6b132cbb 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmcif/TestEntityNameAndType.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmcif/TestEntityNameAndType.java @@ -23,13 +23,12 @@ import static org.junit.Assert.assertArrayEquals; import java.io.IOException; -import java.util.Arrays; import org.biojava.nbio.structure.Chain; import org.biojava.nbio.structure.EntityInfo; import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.StructureException; -import org.biojava.nbio.structure.StructureFiletype; +import org.biojava.nbio.structure.io.StructureFiletype; import org.biojava.nbio.structure.StructureIO; import org.biojava.nbio.structure.align.util.AtomCache; import org.biojava.nbio.structure.chem.ChemCompGroupFactory; diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmcif/TestParseInternalChainId.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmcif/TestParseInternalChainId.java index 8c4084745d..01fcc953c3 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmcif/TestParseInternalChainId.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmcif/TestParseInternalChainId.java @@ -26,7 +26,7 @@ import org.biojava.nbio.structure.Chain; import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.StructureException; -import org.biojava.nbio.structure.StructureFiletype; +import org.biojava.nbio.structure.io.StructureFiletype; import org.biojava.nbio.structure.align.util.AtomCache; import org.junit.Test; import static org.junit.Assert.*; diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmcif/TestParseMmcifHeader.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmcif/TestParseMmcifHeader.java index c0d2423d35..8c789ea2d6 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmcif/TestParseMmcifHeader.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmcif/TestParseMmcifHeader.java @@ -31,7 +31,7 @@ import org.biojava.nbio.structure.PDBHeader; import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.StructureException; -import org.biojava.nbio.structure.StructureFiletype; +import org.biojava.nbio.structure.io.StructureFiletype; import org.biojava.nbio.structure.StructureIO; import org.biojava.nbio.structure.align.util.AtomCache; import org.junit.Test; diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmtf/TestBondFinding.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmtf/TestBondFinding.java index e400465ecb..fd94dff8f5 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmtf/TestBondFinding.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmtf/TestBondFinding.java @@ -20,7 +20,7 @@ */ package org.biojava.nbio.structure.io.mmtf; -import org.biojava.nbio.structure.StructureFiletype; +import org.biojava.nbio.structure.io.StructureFiletype; import org.biojava.nbio.structure.chem.ChemCompGroupFactory; import org.biojava.nbio.structure.chem.DownloadChemCompProvider; import org.junit.Test; diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmtf/TestMmtfRoundTrip.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmtf/TestMmtfRoundTrip.java index 04e4cc93df..e362c2a35f 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmtf/TestMmtfRoundTrip.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmtf/TestMmtfRoundTrip.java @@ -20,10 +20,8 @@ */ package org.biojava.nbio.structure.io.mmtf; -import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; -import java.io.InputStreamReader; import java.net.URL; import java.util.ArrayList; import java.util.Collections; @@ -37,13 +35,13 @@ import org.biojava.nbio.structure.Group; import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.StructureException; -import org.biojava.nbio.structure.StructureFiletype; +import org.biojava.nbio.structure.io.StructureFiletype; import org.biojava.nbio.structure.StructureIO; import org.biojava.nbio.structure.align.util.AtomCache; import org.biojava.nbio.structure.chem.ChemCompGroupFactory; import org.biojava.nbio.structure.chem.DownloadChemCompProvider; import org.biojava.nbio.structure.io.FileParsingParameters; -import org.biojava.nbio.structure.io.cif.StructureConverter; +import org.biojava.nbio.structure.io.cif.CifStructureConverter; import org.biojava.nbio.structure.quaternary.BioAssemblyInfo; import org.biojava.nbio.structure.quaternary.BiologicalAssemblyTransformation; import org.junit.Test; @@ -360,7 +358,7 @@ public void testStructWithBranchedEntitiesRoundTrip() throws IOException { URL url = new URL("https://raw.githubusercontent.com/pdbxmmcifwg/carbohydrate-extension/master/examples/models/1B5F-carb.cif"); InputStream inStream = url.openStream(); - Structure structure = StructureConverter.fromInputStream(inStream); + Structure structure = CifStructureConverter.fromInputStream(inStream); AdapterToStructureData writerToEncoder = new AdapterToStructureData(); new MmtfStructureWriter(structure, writerToEncoder); diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmtf/TestMmtfStructureReader.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmtf/TestMmtfStructureReader.java index acf23d4f88..095deecb64 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmtf/TestMmtfStructureReader.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmtf/TestMmtfStructureReader.java @@ -9,7 +9,7 @@ import org.biojava.nbio.structure.Group; import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.StructureException; -import org.biojava.nbio.structure.StructureFiletype; +import org.biojava.nbio.structure.io.StructureFiletype; import org.biojava.nbio.structure.StructureIO; import org.biojava.nbio.structure.align.util.AtomCache; import org.biojava.nbio.structure.chem.ChemCompGroupFactory; diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/xtal/TestCrystalInfo.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/xtal/TestCrystalInfo.java index 775588a2ae..4e48bab634 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/xtal/TestCrystalInfo.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/xtal/TestCrystalInfo.java @@ -22,6 +22,7 @@ import org.biojava.nbio.structure.*; import org.biojava.nbio.structure.align.util.AtomCache; +import org.biojava.nbio.structure.io.StructureFiletype; import org.junit.Test; import java.io.IOException; diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/xtal/TestInterfaceClustering.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/xtal/TestInterfaceClustering.java index bb5fe0b74c..d69ce237d3 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/xtal/TestInterfaceClustering.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/xtal/TestInterfaceClustering.java @@ -32,7 +32,7 @@ import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.StructureException; -import org.biojava.nbio.structure.StructureFiletype; +import org.biojava.nbio.structure.io.StructureFiletype; import org.biojava.nbio.structure.StructureIO; import org.biojava.nbio.structure.align.util.AtomCache; import org.biojava.nbio.structure.asa.GroupAsa; From 9e501a9e3bfee814f00bd5d23746ea2a01debcb5 Mon Sep 17 00:00:00 2001 From: Jose Duarte Date: Wed, 27 Jan 2021 12:27:26 -0800 Subject: [PATCH 033/599] Further optimization: sort by distance. Achieves ~1/3 of runtime --- .../nbio/structure/asa/AsaCalculator.java | 83 +++++++++++-------- 1 file changed, 47 insertions(+), 36 deletions(-) diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/asa/AsaCalculator.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/asa/AsaCalculator.java index 19ece0ab72..59ba0dc138 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/asa/AsaCalculator.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/asa/AsaCalculator.java @@ -30,8 +30,7 @@ import java.util.*; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; - - +import java.util.stream.Collectors; /** @@ -86,8 +85,8 @@ public class AsaCalculator { private class AsaCalcWorker implements Runnable { - private int i; - private double[] asas; + private final int i; + private final double[] asas; public AsaCalcWorker(int i, double[] asas) { this.i = i; @@ -100,12 +99,21 @@ public void run() { } } + private static class IndexAndDistance { + private final int index; + private final double dist; + public IndexAndDistance(int index, double dist) { + this.index = index; + this.dist = dist; + } + } + - private Point3d[] atomCoords; - private Atom[] atoms; - private double[] radii; - private double probe; - private int nThreads; + private final Point3d[] atomCoords; + private final Atom[] atoms; + private final double[] radii; + private final double probe; + private final int nThreads; private Point3d[] spherePoints; private double cons; private int[][] neighborIndices; @@ -123,7 +131,6 @@ public void run() { * @param nThreads the number of parallel threads to use for the calculation * @param hetAtoms if true HET residues are considered, if false they aren't, equivalent to * NACCESS' -h option - * @see StructureTools#getAllNonHAtomArray */ public AsaCalculator(Structure structure, double probe, int nSpherePoints, int nThreads, boolean hetAtoms) { this.atoms = StructureTools.getAllNonHAtomArray(structure, hetAtoms); @@ -312,10 +319,8 @@ public double[] calculateAsas() { //12 threads, time: 0.9s -- x11.4 - ExecutorService threadPool = Executors.newFixedThreadPool(nThreads); - for (int i=0;i contactList = calcContacts(); - Map> indices = new HashMap<>(atomCoords.length); + Map> indices = new HashMap<>(atomCoords.length); for (Contact contact : contactList) { // note contacts are stored 1-way only, with j>i int i = contact.getI(); int j = contact.getJ(); - List iIndices; - List jIndices; + List iIndices; + List jIndices; if (!indices.containsKey(i)) { iIndices = new ArrayList<>(initialCapacity); indices.put(i, iIndices); @@ -428,17 +433,21 @@ int[][] findNeighborIndicesSpatialHashing() { double radius = radii[i] + probe + probe; double dist = contact.getDistance(); if (dist < radius + radii[j]) { - iIndices.add(j); - jIndices.add(i); + iIndices.add(new IndexAndDistance(j, dist)); + jIndices.add(new IndexAndDistance(i, dist)); } } // convert map to array for fast access int[][] nbsIndices = new int[atomCoords.length][]; - for (Map.Entry> entry : indices.entrySet()) { - List list = entry.getValue(); + for (Map.Entry> entry : indices.entrySet()) { + List list = entry.getValue(); + // Sorting by closest to farthest away neighbors achieves faster runtimes when checking for occluded sphere sample points in calcSingleAsa. + // This follows the ideas exposed in Eisenhaber et al, J Comp Chemistry 1994 (https://onlinelibrary.wiley.com/doi/epdf/10.1002/jcc.540160303) + list = list.stream().sorted(Comparator.comparingDouble(o -> o.dist)).collect(Collectors.toList()); int[] indicesArray = new int[list.size()]; - for (int i=0;i Date: Wed, 27 Jan 2021 14:51:55 -0800 Subject: [PATCH 034/599] Small optimisation: avoid recalculating radii --- .../nbio/structure/asa/AsaCalculator.java | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/asa/AsaCalculator.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/asa/AsaCalculator.java index 59ba0dc138..9a5f6edd75 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/asa/AsaCalculator.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/asa/AsaCalculator.java @@ -491,22 +491,31 @@ private double calcSingleAsa(int i) { int[] numDistsCalced = null; if (logger.isDebugEnabled()) numDistsCalced = new int[n_neighbor]; + // now we precalculate the squared j radii to compare to in inner loop (which does not depend on each sphere point, but only on i, j + double[] sqRadii = new double[n_neighbor]; + for (int nbArrayInd =0; nbArrayInd Date: Wed, 27 Jan 2021 17:11:11 -0800 Subject: [PATCH 035/599] Another optimisation from Eisenhaber 1994 --- .../nbio/structure/asa/AsaCalculator.java | 64 ++++++++++--------- .../nbio/structure/asa/TestAsaCalc.java | 20 +++--- 2 files changed, 43 insertions(+), 41 deletions(-) diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/asa/AsaCalculator.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/asa/AsaCalculator.java index 9a5f6edd75..2deed82865 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/asa/AsaCalculator.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/asa/AsaCalculator.java @@ -27,6 +27,7 @@ import org.slf4j.LoggerFactory; import javax.vecmath.Point3d; +import javax.vecmath.Vector3d; import java.util.*; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -99,9 +100,9 @@ public void run() { } } - private static class IndexAndDistance { - private final int index; - private final double dist; + public static class IndexAndDistance { + public final int index; + public final double dist; public IndexAndDistance(int index, double dist) { this.index = index; this.dist = dist; @@ -116,7 +117,7 @@ public IndexAndDistance(int index, double dist) { private final int nThreads; private Point3d[] spherePoints; private double cons; - private int[][] neighborIndices; + private IndexAndDistance[][] neighborIndices; private boolean useSpatialHashingForNeighbors; @@ -369,17 +370,17 @@ private Point3d[] generateSpherePoints(int nSpherePoints) { * Returns the 2-dimensional array with neighbor indices for every atom. * @return 2-dimensional array of size: n_atoms x n_neighbors_per_atom */ - int[][] findNeighborIndices() { + IndexAndDistance[][] findNeighborIndices() { // looking at a typical protein case, number of neighbours are from ~10 to ~50, with an average of ~30 int initialCapacity = 60; - int[][] nbsIndices = new int[atomCoords.length][]; + IndexAndDistance[][] nbsIndices = new IndexAndDistance[atomCoords.length][]; for (int k=0; k thisNbIndices = new ArrayList<>(initialCapacity); + List thisNbIndices = new ArrayList<>(initialCapacity); for (int i = 0; i < atomCoords.length; i++) { if (i == k) continue; @@ -387,12 +388,11 @@ int[][] findNeighborIndices() { double dist = atomCoords[i].distance(atomCoords[k]); if (dist < radius + radii[i]) { - thisNbIndices.add(i); + thisNbIndices.add(new IndexAndDistance(i, dist)); } } - int[] indicesArray = new int[thisNbIndices.size()]; - for (int i=0;i> entry : indices.entrySet()) { List list = entry.getValue(); // Sorting by closest to farthest away neighbors achieves faster runtimes when checking for occluded sphere sample points in calcSingleAsa. // This follows the ideas exposed in Eisenhaber et al, J Comp Chemistry 1994 (https://onlinelibrary.wiley.com/doi/epdf/10.1002/jcc.540160303) list = list.stream().sorted(Comparator.comparingDouble(o -> o.dist)).collect(Collectors.toList()); - int[] indicesArray = new int[list.size()]; - for (int i=0; i sqRadii[nbArrayInd]) { is_accessible = false; break; } @@ -527,11 +529,11 @@ private double calcSingleAsa(int i) { if (numDistsCalced!=null) { int sum = 0; - for (int j = 0; j < n_neighbor; j++) sum += numDistsCalced[j]; + for (int nbArrayInd = 0; nbArrayInd < n_neighbor; nbArrayInd++) sum += numDistsCalced[nbArrayInd]; logger.debug("Number of sample points distances calculated for neighbors of i={} : average {}, all {}", i, (double) sum / (double) n_neighbor, numDistsCalced); } - return cons*n_accessible_point*radius*radius; + return cons*n_accessible_point*radius_i*radius_i; } /** diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/asa/TestAsaCalc.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/asa/TestAsaCalc.java index 79598bd410..941d85c06d 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/asa/TestAsaCalc.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/asa/TestAsaCalc.java @@ -98,19 +98,19 @@ public void testNeighborIndicesFinding() throws StructureException, IOException AsaCalculator.DEFAULT_PROBE_SIZE, 1000, 1, false); - int[][] allNbsSh = asaCalc.findNeighborIndicesSpatialHashing(); + AsaCalculator.IndexAndDistance[][] allNbsSh = asaCalc.findNeighborIndicesSpatialHashing(); - int[][] allNbs = asaCalc.findNeighborIndices(); + AsaCalculator.IndexAndDistance[][] allNbs = asaCalc.findNeighborIndices(); for (int indexToTest =0; indexToTest < asaCalc.getAtomCoords().length; indexToTest++) { //int indexToTest = 198; - int[] nbsSh = allNbsSh[indexToTest]; - int[] nbs = allNbs[indexToTest]; + AsaCalculator.IndexAndDistance[] nbsSh = allNbsSh[indexToTest]; + AsaCalculator.IndexAndDistance[] nbs = allNbs[indexToTest]; List listOfMatchingIndices = new ArrayList<>(); for (int i = 0; i < nbsSh.length; i++) { for (int j = 0; j < nbs.length; j++) { - if (nbs[j] == nbsSh[i]) { + if (nbs[j].index == nbsSh[i].index) { listOfMatchingIndices.add(j); break; } @@ -201,21 +201,21 @@ public void testNoNeighborsIssue() { AsaCalculator.DEFAULT_PROBE_SIZE, 1000, 1); - int[][] allNbsSh = asaCalc.findNeighborIndicesSpatialHashing(); + AsaCalculator.IndexAndDistance[][] allNbsSh = asaCalc.findNeighborIndicesSpatialHashing(); - int[][] allNbs = asaCalc.findNeighborIndices(); + AsaCalculator.IndexAndDistance[][] allNbs = asaCalc.findNeighborIndices(); assertEquals(3, allNbs.length); assertEquals(3, allNbsSh.length); for (int indexToTest =0; indexToTest < asaCalc.getAtomCoords().length; indexToTest++) { - int[] nbsSh = allNbsSh[indexToTest]; - int[] nbs = allNbs[indexToTest]; + AsaCalculator.IndexAndDistance[] nbsSh = allNbsSh[indexToTest]; + AsaCalculator.IndexAndDistance[] nbs = allNbs[indexToTest]; List listOfMatchingIndices = new ArrayList<>(); for (int i = 0; i < nbsSh.length; i++) { for (int j = 0; j < nbs.length; j++) { - if (nbs[j] == nbsSh[i]) { + if (nbs[j].index == nbsSh[i].index) { listOfMatchingIndices.add(j); break; } From f3e7e00977bcfe21c2b831411f17f402e5f556a8 Mon Sep 17 00:00:00 2001 From: Jose Duarte Date: Wed, 27 Jan 2021 22:30:06 -0800 Subject: [PATCH 036/599] Some reorg and docs --- .../nbio/structure/asa/AsaCalculator.java | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/asa/AsaCalculator.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/asa/AsaCalculator.java index 2deed82865..6693490029 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/asa/AsaCalculator.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/asa/AsaCalculator.java @@ -31,7 +31,6 @@ import java.util.*; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import java.util.stream.Collectors; /** @@ -42,6 +41,9 @@ * (now source is available at https://github.com/boscoh/asa). * Thanks to Bosco K. Ho for a great piece of code and for his fantastic blog. *

+ * A few optimizations come from Eisenhaber et al, J Comp Chemistry 1994 + * (https://onlinelibrary.wiley.com/doi/epdf/10.1002/jcc.540160303) + *

* See * Shrake, A., and J. A. Rupley. "Environment and Exposure to Solvent of Protein Atoms. * Lysozyme and Insulin." JMB (1973) 79:351-371. @@ -49,7 +51,6 @@ * Static Accessibility" JMB (1971) 55:379-400 * * @author Jose Duarte - * */ public class AsaCalculator { @@ -251,7 +252,7 @@ public GroupAsa[] getGroupAsas() { } } - return asas.values().toArray(new GroupAsa[asas.size()]); + return asas.values().toArray(new GroupAsa[0]); } /** @@ -442,11 +443,7 @@ IndexAndDistance[][] findNeighborIndicesSpatialHashing() { IndexAndDistance[][] nbsIndices = new IndexAndDistance[atomCoords.length][]; for (Map.Entry> entry : indices.entrySet()) { List list = entry.getValue(); - // Sorting by closest to farthest away neighbors achieves faster runtimes when checking for occluded sphere sample points in calcSingleAsa. - // This follows the ideas exposed in Eisenhaber et al, J Comp Chemistry 1994 (https://onlinelibrary.wiley.com/doi/epdf/10.1002/jcc.540160303) - list = list.stream().sorted(Comparator.comparingDouble(o -> o.dist)).collect(Collectors.toList()); IndexAndDistance[] indexAndDistances = list.toArray(new IndexAndDistance[0]); - nbsIndices[entry.getKey()] = indexAndDistances; } @@ -483,6 +480,11 @@ private double calcSingleAsa(int i) { int n_neighbor = neighborIndices[i].length; IndexAndDistance[] neighbor_indices = neighborIndices[i]; + // Sorting by closest to farthest away neighbors achieves faster runtimes when checking for occluded + // sphere sample points below. This follows the ideas exposed in + // Eisenhaber et al, J Comp Chemistry 1994 (https://onlinelibrary.wiley.com/doi/epdf/10.1002/jcc.540160303) + Arrays.sort(neighbor_indices, Comparator.comparingDouble(o -> o.dist)); + double radius_i = probe + radii[i]; int n_accessible_point = 0; @@ -508,11 +510,13 @@ private double calcSingleAsa(int i) { boolean is_accessible = true; // note that the neighbors are sorted by distance, achieving optimal performance in this inner loop - // See Eisenhaber et al, J Comp Chemistry 1994 (https://onlinelibrary.wiley.com/doi/epdf/10.1002/jcc.540160303) + // See Eisenhaber et al, J Comp Chemistry 1994 for (int nbArrayInd =0; nbArrayInd Date: Wed, 27 Jan 2021 22:47:26 -0800 Subject: [PATCH 037/599] A scaling test (ignored) --- .../nbio/structure/asa/AsaCalculator.java | 35 ------------------- .../nbio/structure/asa/TestAsaCalc.java | 30 +++++++++++++++- 2 files changed, 29 insertions(+), 36 deletions(-) diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/asa/AsaCalculator.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/asa/AsaCalculator.java index 6693490029..ad6b464805 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/asa/AsaCalculator.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/asa/AsaCalculator.java @@ -285,41 +285,6 @@ public double[] calculateAsas() { } else { logger.debug("Will use {} threads for ASA calculation", nThreads); - // NOTE the multithreaded calculation does not scale up well in some systems, - // why? I guess some memory/garbage collect problem? I tried increasing Xmx in pc8201 but didn't help - - // Following scaling tests are for 3hbx, calculating ASA of full asym unit (6 chains): - - // SCALING test done in merlinl01 (12 cores, Xeon X5670 @ 2.93GHz, 24GB RAM) - //1 threads, time: 8.8s -- x1.0 - //2 threads, time: 4.4s -- x2.0 - //3 threads, time: 2.9s -- x3.0 - //4 threads, time: 2.2s -- x3.9 - //5 threads, time: 1.8s -- x4.9 - //6 threads, time: 1.6s -- x5.5 - //7 threads, time: 1.4s -- x6.5 - //8 threads, time: 1.3s -- x6.9 - - // SCALING test done in pc8201 (4 cores, Core2 Quad Q9550 @ 2.83GHz, 8GB RAM) - //1 threads, time: 17.2s -- x1.0 - //2 threads, time: 9.7s -- x1.8 - //3 threads, time: 7.7s -- x2.2 - //4 threads, time: 7.9s -- x2.2 - - // SCALING test done in eppic01 (16 cores, Xeon E5-2650 0 @ 2.00GHz, 128GB RAM) - //1 threads, time: 10.7s -- x1.0 - //2 threads, time: 5.6s -- x1.9 - //3 threads, time: 3.6s -- x3.0 - //4 threads, time: 2.8s -- x3.9 - //5 threads, time: 2.3s -- x4.8 - //6 threads, time: 1.8s -- x6.0 - //7 threads, time: 1.6s -- x6.8 - //8 threads, time: 1.3s -- x8.0 - //9 threads, time: 1.3s -- x8.5 - //10 threads, time: 1.1s -- x10.0 - //11 threads, time: 1.0s -- x10.9 - //12 threads, time: 0.9s -- x11.4 - ExecutorService threadPool = Executors.newFixedThreadPool(nThreads); diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/asa/TestAsaCalc.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/asa/TestAsaCalc.java index 941d85c06d..7add4cf1e7 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/asa/TestAsaCalc.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/asa/TestAsaCalc.java @@ -32,6 +32,7 @@ import org.biojava.nbio.structure.io.mmcif.DownloadChemCompProvider; import static org.junit.Assert.*; +import org.junit.Ignore; import org.junit.Test; import java.io.IOException; @@ -57,7 +58,6 @@ public void testAsa3PIU() throws StructureException, IOException { Structure structure = StructureIO.getStructure("3PIU"); - AsaCalculator asaCalc = new AsaCalculator(structure, AsaCalculator.DEFAULT_PROBE_SIZE, 1000, 1, false); @@ -86,6 +86,34 @@ public void testAsa3PIU() throws StructureException, IOException { } + @Ignore("This is a performance test to be run manually") + @Test + public void testMultithreadScaling() throws StructureException, IOException { + + // important: without this the tests can fail when running in maven (but not in IDE) + // that's because it depends on the order on how tests were run - JD 2018-03-10 + ChemCompGroupFactory.setChemCompProvider(new DownloadChemCompProvider()); + + Structure structure = StructureIO.getStructure("3hbx"); + int[] numThreads = {1, 2, 3, 4}; + long timeSingleThread = 0; + for (int numThread : numThreads) { + AsaCalculator asaCalc = new AsaCalculator(structure, + AsaCalculator.DEFAULT_PROBE_SIZE, + 100, numThread, false); + + long start = System.currentTimeMillis(); + asaCalc.calculateAsas(); + long end = System.currentTimeMillis(); + long time = end - start; + if (numThread == 1) { + timeSingleThread = time; + } + System.out.printf("%6d threads : %6d ms (x%3.1f)\n", numThread, time, (double)timeSingleThread/time); + } + // nothing to assert + } + @Test public void testNeighborIndicesFinding() throws StructureException, IOException { // important: without this the tests can fail when running in maven (but not in IDE) From 8e9535c070fdafea32609bd9f5065b00b641dd27 Mon Sep 17 00:00:00 2001 From: Jose Duarte Date: Wed, 27 Jan 2021 22:52:22 -0800 Subject: [PATCH 038/599] Logging --- .../java/org/biojava/nbio/structure/asa/AsaCalculator.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/asa/AsaCalculator.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/asa/AsaCalculator.java index ad6b464805..4edb428df0 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/asa/AsaCalculator.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/asa/AsaCalculator.java @@ -568,7 +568,7 @@ else if (atomCode.equals("CA") || atomCode.equals("CB") || else if (atomCode.equals("CG")) return TETRAHEDRAL_CARBON_VDW; default: - logger.info("Unexpected carbon atom "+atomCode+" for aminoacid "+aa+", assigning its standard vdw radius"); + logger.info("Unexpected carbon atom {} for aminoacid {}, assigning its standard vdw radius", atomCode, aa); return Element.C.getVDWRadius(); } } @@ -576,8 +576,7 @@ else if (atomCode.equals("CA") || atomCode.equals("CB") || // not any of the expected atoms } else { // non standard aas, (e.g. MSE, LLP) will always have this problem, - logger.info("Unexpected atom "+atomCode+" for aminoacid "+aa+ " ("+amino.getPDBName()+"), assigning its standard vdw radius"); - + logger.debug("Unexpected atom {} for aminoacid {} ({}), assigning its standard vdw radius", atomCode, aa, amino.getPDBName()); return atom.getElement().getVDWRadius(); } From f27295efe12f15a8b7ff196682da9ae7726375ca Mon Sep 17 00:00:00 2001 From: Jose Duarte Date: Thu, 28 Jan 2021 09:57:29 -0800 Subject: [PATCH 039/599] Visibility --- .../org/biojava/nbio/structure/asa/AsaCalculator.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/asa/AsaCalculator.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/asa/AsaCalculator.java index 4edb428df0..387e60ed68 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/asa/AsaCalculator.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/asa/AsaCalculator.java @@ -90,7 +90,7 @@ private class AsaCalcWorker implements Runnable { private final int i; private final double[] asas; - public AsaCalcWorker(int i, double[] asas) { + private AsaCalcWorker(int i, double[] asas) { this.i = i; this.asas = asas; } @@ -101,10 +101,10 @@ public void run() { } } - public static class IndexAndDistance { - public final int index; - public final double dist; - public IndexAndDistance(int index, double dist) { + static class IndexAndDistance { + final int index; + final double dist; + IndexAndDistance(int index, double dist) { this.index = index; this.dist = dist; } From 6a447d61226aeb1ab287750f99b5be8dc72ab84a Mon Sep 17 00:00:00 2001 From: Jose Duarte Date: Thu, 28 Jan 2021 11:52:05 -0800 Subject: [PATCH 040/599] Use Vector3d for points, more docs --- .../nbio/structure/asa/AsaCalculator.java | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/asa/AsaCalculator.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/asa/AsaCalculator.java index 387e60ed68..144bcd1209 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/asa/AsaCalculator.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/asa/AsaCalculator.java @@ -116,7 +116,7 @@ static class IndexAndDistance { private final double[] radii; private final double probe; private final int nThreads; - private Point3d[] spherePoints; + private Vector3d[] spherePoints; private double cons; private IndexAndDistance[][] neighborIndices; @@ -314,20 +314,20 @@ void setUseSpatialHashingForNeighbors(boolean useSpatialHashingForNeighbors) { } /** - * Returns list of 3d coordinates of points on a sphere using the + * Returns list of 3d coordinates of points on a unit sphere using the * Golden Section Spiral algorithm. * @param nSpherePoints the number of points to be used in generating the spherical dot-density - * @return + * @return the array of points as Vector3d objects */ - private Point3d[] generateSpherePoints(int nSpherePoints) { - Point3d[] points = new Point3d[nSpherePoints]; + private Vector3d[] generateSpherePoints(int nSpherePoints) { + Vector3d[] points = new Vector3d[nSpherePoints]; double inc = Math.PI * (3.0 - Math.sqrt(5.0)); double offset = 2.0 / nSpherePoints; for (int k=0;k o.dist)); double radius_i = probe + radii[i]; int n_accessible_point = 0; - + // purely for debugging int[] numDistsCalced = null; if (logger.isDebugEnabled()) numDistsCalced = new int[n_neighbor]; @@ -471,7 +473,7 @@ private double calcSingleAsa(int i) { aj_minus_ais[nbArrayInd] = aj_minus_ai; } - for (Point3d point: spherePoints){ + for (Vector3d point: spherePoints){ boolean is_accessible = true; // note that the neighbors are sorted by distance, achieving optimal performance in this inner loop @@ -482,7 +484,7 @@ private double calcSingleAsa(int i) { // see equation 3 in Eisenhaber 1994. This is slightly more efficient than // calculating distances to the actual sphere points on atom_i (which would be obtained with: // Point3d test_point = new Point3d(point.x*radius + atom_i.x,point.y*radius + atom_i.y,point.z*radius + atom_i.z)) - double dotProd = aj_minus_ais[nbArrayInd].dot(new Vector3d(point)); + double dotProd = aj_minus_ais[nbArrayInd].dot(point); if (numDistsCalced!=null) numDistsCalced[nbArrayInd]++; @@ -496,6 +498,7 @@ private double calcSingleAsa(int i) { } } + // purely for debugging if (numDistsCalced!=null) { int sum = 0; for (int numDistCalcedForJ : numDistsCalced) sum += numDistCalcedForJ; From 4f44fce6e278582f612286b23eed866e5bb67ebc Mon Sep 17 00:00:00 2001 From: JonStargaryen Date: Mon, 1 Feb 2021 15:33:36 -0800 Subject: [PATCH 041/599] Group.java from upstream --- .../src/main/java/org/biojava/nbio/structure/Group.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/Group.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/Group.java index d1e5f34963..8b7b5cb809 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/Group.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/Group.java @@ -103,12 +103,13 @@ public interface Group extends Serializable { /** * Set the atoms of this group. - * @see {@link Atom} + * @see Atom * @param atoms a list of atoms */ public void setAtoms(List atoms); - /** Remove all atoms from this group. + /** + * Remove all atoms from this group. * */ public void clearAtoms(); @@ -118,13 +119,14 @@ public interface Group extends Serializable { * Beware that some PDB atom names are ambiguous (e.g. CA, which means C-alpha or Calcium), * ambiguities should not occur within the same group though. To solve these ambiguities * one would need to check the atom returned for the required element with {@link Atom#getElement()} + *

+ * Note this method will return only the atom in the default alternative location (be it '.' or a letter). * * @param name a trimmed String representing the atom's PDB name, e.g. "CA" * @return an Atom object or null if no such atom exists within this group */ public Atom getAtom(String name) ; - /** * Get at atom by position. * From 53982b0ba820e020c37596d25d6af27639f4a053 Mon Sep 17 00:00:00 2001 From: JonStargaryen Date: Tue, 2 Feb 2021 09:37:02 -0800 Subject: [PATCH 042/599] update CHANGELOG.md --- CHANGELOG.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 22f265c548..2403e0f6ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,16 @@ BioJava 6.0.0 (future release) * Support for automatically fetching dssp files from RCSB (`org.biojava.nbio.structure.secstruc.DSSPParser.fetch()`) * `org.biojava.nbio.structure.PDBStatus`: simplified `Status` enum to 3 states, with OBSOLETE now called REMOVED * `org.biojava.nbio.structure.PDBStatus`: removed `getReplacement` and `getReplaces` +* Removed `org.biojava.nbio.structure.io.mmcif` package +* Removed functionality to write isolated CIF headers from `FileConvert` + +### Breaking API changes +* Extracted `StructureIO.StructureFiletype` enum to `org.biojava.nbio.structure.io.StructureFiletype` (supports `PDB`, `MMTF`, `CIF`, and `BCIF`) +* `org.biojava.nbio.structure.align.util.AtomCache`: removed `setUseMmCif`, `setUseMmtf`, `isUseMmCif`, and `isUseMmtf` - replaced by `setFiletype` and `getFiletype` that controls parsed content via the `StructureFiletype` +* `org.biojava.nbio.structure.io.MMCIFFileReader` is now effectively `org.biojava.nbio.structure.io.CifFileReader` +* Moved `org.biojava.nbio.structure.io.mmcif.model.DatabasePdbrevRecord` to `org.biojava.nbio.structure.DatabasePDBRevRecord.java` +* Moved all chem-comp model classes from `org.biojava.nbio.structure.io.mmcif.chem` to `org.biojava.nbio.structure.chem` +* Moved all chem-comp parsing classes from `org.biojava.nbio.structure.io.mmcif.chem` to `org.biojava.nbio.structure.io.cif` BioJava 5.4.0 ============= From 19766ca1414f3cc701a03e99e918c466a070d516 Mon Sep 17 00:00:00 2001 From: JonStargaryen Date: Tue, 2 Feb 2021 17:29:15 -0800 Subject: [PATCH 043/599] update AtomCacheTest --- .../nbio/structure/align/util/AtomCache.java | 30 +------------------ .../structure/align/util/AtomCacheTest.java | 11 ++++--- 2 files changed, 6 insertions(+), 35 deletions(-) diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/align/util/AtomCache.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/align/util/AtomCache.java index 552f0427ef..d4d1638c12 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/align/util/AtomCache.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/align/util/AtomCache.java @@ -525,8 +525,7 @@ public Structure getStructureForDomain(ScopDomain domain, ScopDatabase scopDatab public Structure getStructureForDomain(ScopDomain domain, ScopDatabase scopDatabase, boolean strictLigandHandling) throws IOException, StructureException { String pdbId = domain.getPdbId(); - // SMB 1/26/21 - forcing loading MMTF here - TODO why doesn't mmCIF/CIF/BCIF parsing work here? - Structure fullStructure = getStructureForPdbIdByMmtf(pdbId); + Structure fullStructure = getStructureForPdbId(pdbId); Structure structure = domain.reduce(fullStructure); // TODO It would be better to move all of this into the reduce method, @@ -802,33 +801,6 @@ public Structure getStructureForPdbId(String pdbId) throws IOException, Structur } } - /** - * SCOP parsing depends on MMTF, this a dedicated method to allow for that. - * @param pdbId what to load - * @return a Structure object - * @throws IOException - * @throws StructureException - */ - private Structure getStructureForPdbIdByMmtf(String pdbId) throws IOException, StructureException { - if (pdbId == null) - return null; - if (pdbId.length() != 4) { - throw new StructureException("Unrecognized PDB ID: " + pdbId); - } - while (checkLoading(pdbId)) { - // waiting for loading to be finished... - - try { - Thread.sleep(100); - } catch (InterruptedException e) { - logger.error(e.getMessage()); - } - } - - logger.debug("loading from mmtf"); - return loadStructureFromMmtfByPdbId(pdbId); - } - /** * Load a {@link Structure} from MMTF either from the local file system. * @param pdbId the input PDB id diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/align/util/AtomCacheTest.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/align/util/AtomCacheTest.java index 25a711e0b1..ce332f4f70 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/align/util/AtomCacheTest.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/align/util/AtomCacheTest.java @@ -178,13 +178,12 @@ public void testGetStructureForChainlessDomains() throws IOException, StructureE int expectedLengthA = 135; assertEquals(expectedLengthA, a.getAtomGroups().size()); + assertEquals(2, structure.getNonPolyChains().size()); - assertTrue(structure.hasNonPolyChain("G")); - assertTrue(structure.hasNonPolyChain("H")); - - Chain copper = structure.getNonPolyChain("I"); - assertEquals(1,copper.getAtomGroups().size()); - + Chain copperM = structure.getNonPolyChain("M"); + assertEquals(1, copperM.getAtomGroups().size()); + Chain copperN = structure.getNonPolyChain("N"); + assertEquals(1, copperN.getAtomGroups().size()); } @Test From e94f047cad95ccc1bf1acd4f6341f5569cf8a75c Mon Sep 17 00:00:00 2001 From: JonStargaryen Date: Wed, 10 Feb 2021 11:04:07 -0800 Subject: [PATCH 044/599] increase QCP precision threshold (try to fix #914) --- .../org/biojava/nbio/structure/geometry/SuperPositionQCP.java | 2 +- .../java/org/biojava/nbio/structure/io/TestHardBioUnits.java | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/geometry/SuperPositionQCP.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/geometry/SuperPositionQCP.java index a3d5728f19..a45a854bbf 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/geometry/SuperPositionQCP.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/geometry/SuperPositionQCP.java @@ -111,7 +111,7 @@ public final class SuperPositionQCP extends SuperPositionAbstract { private static final Logger logger = LoggerFactory.getLogger(SuperPositionQCP.class); - private double evec_prec = 1E-6; + private double evec_prec = 1E-3; private double eval_prec = 1E-11; private Point3d[] x; diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestHardBioUnits.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestHardBioUnits.java index b50b4524fc..797307d0c0 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestHardBioUnits.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestHardBioUnits.java @@ -107,10 +107,6 @@ public void test4A1I() throws IOException, StructureException { String pdbId = "4A1I"; int biolAssemblyNr = 2; - AtomCache atomCache = new AtomCache(); - // TODO there seem to be numerical instabilities when parsing BCIF - atomCache.setFiletype(StructureFiletype.CIF); - StructureIO.setAtomCache(atomCache); Structure bioAssembly = StructureIO.getBiologicalAssembly(pdbId,biolAssemblyNr); if ( bioAssembly == null){ From 83cf763e0f4b91da5b45fb2deaa8bb63ecbe9857 Mon Sep 17 00:00:00 2001 From: JonStargaryen Date: Thu, 11 Feb 2021 16:57:33 -0800 Subject: [PATCH 045/599] Revert "increase QCP precision threshold (try to fix #914)" This reverts commit e94f047c --- .../org/biojava/nbio/structure/geometry/SuperPositionQCP.java | 2 +- .../java/org/biojava/nbio/structure/io/TestHardBioUnits.java | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/geometry/SuperPositionQCP.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/geometry/SuperPositionQCP.java index a45a854bbf..a3d5728f19 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/geometry/SuperPositionQCP.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/geometry/SuperPositionQCP.java @@ -111,7 +111,7 @@ public final class SuperPositionQCP extends SuperPositionAbstract { private static final Logger logger = LoggerFactory.getLogger(SuperPositionQCP.class); - private double evec_prec = 1E-3; + private double evec_prec = 1E-6; private double eval_prec = 1E-11; private Point3d[] x; diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestHardBioUnits.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestHardBioUnits.java index 797307d0c0..b50b4524fc 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestHardBioUnits.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestHardBioUnits.java @@ -107,6 +107,10 @@ public void test4A1I() throws IOException, StructureException { String pdbId = "4A1I"; int biolAssemblyNr = 2; + AtomCache atomCache = new AtomCache(); + // TODO there seem to be numerical instabilities when parsing BCIF + atomCache.setFiletype(StructureFiletype.CIF); + StructureIO.setAtomCache(atomCache); Structure bioAssembly = StructureIO.getBiologicalAssembly(pdbId,biolAssemblyNr); if ( bioAssembly == null){ From 069126ced7e1a85ea188ada0df77181de4d90c2b Mon Sep 17 00:00:00 2001 From: Michael L Heuer Date: Mon, 22 Feb 2021 09:26:59 -0600 Subject: [PATCH 046/599] Update guava dependency version to 29.0-jre. --- biojava-genome/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/biojava-genome/pom.xml b/biojava-genome/pom.xml index e219872582..c4d667cf50 100644 --- a/biojava-genome/pom.xml +++ b/biojava-genome/pom.xml @@ -75,7 +75,7 @@ com.google.guava guava compile - 28.1-jre + 29.0-jre junit From 1e59bb59883c3d2afe88671d60f48924fc3ece73 Mon Sep 17 00:00:00 2001 From: Michael L Heuer Date: Mon, 22 Feb 2021 09:27:35 -0600 Subject: [PATCH 047/599] Collect to ArrayList rather than LinkedList. --- .../org/biojava/nbio/genome/io/fastq/AbstractFastqReader.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/biojava-genome/src/main/java/org/biojava/nbio/genome/io/fastq/AbstractFastqReader.java b/biojava-genome/src/main/java/org/biojava/nbio/genome/io/fastq/AbstractFastqReader.java index 17ca61205c..b10a005fc7 100755 --- a/biojava-genome/src/main/java/org/biojava/nbio/genome/io/fastq/AbstractFastqReader.java +++ b/biojava-genome/src/main/java/org/biojava/nbio/genome/io/fastq/AbstractFastqReader.java @@ -152,7 +152,7 @@ public final Iterable read(final InputStream inputStream) throws IOExcept private static final class Collect implements StreamListener { /** List of FASTQ formatted sequences. */ - private final List result = Lists.newLinkedList(); + private final List result = Lists.newArrayList(); @Override public void fastq(final Fastq fastq) From 02b0ece17db3dc6ace817c231ea0ae7998cfcc1b Mon Sep 17 00:00:00 2001 From: Michael L Heuer Date: Mon, 22 Feb 2021 09:48:37 -0600 Subject: [PATCH 048/599] Add copy constructor to FastqBuilder. --- .../biojava/nbio/genome/io/fastq/Fastq.java | 15 ++++++++ .../nbio/genome/io/fastq/FastqBuilder.java | 19 ++++++++++ .../genome/io/fastq/FastqBuilderTest.java | 35 +++++++++++++++++++ .../nbio/genome/io/fastq/FastqTest.java | 14 ++++++++ 4 files changed, 83 insertions(+) diff --git a/biojava-genome/src/main/java/org/biojava/nbio/genome/io/fastq/Fastq.java b/biojava-genome/src/main/java/org/biojava/nbio/genome/io/fastq/Fastq.java index 2de9e05713..11e1d959f8 100755 --- a/biojava-genome/src/main/java/org/biojava/nbio/genome/io/fastq/Fastq.java +++ b/biojava-genome/src/main/java/org/biojava/nbio/genome/io/fastq/Fastq.java @@ -145,4 +145,19 @@ public static final FastqBuilder builder() { return new FastqBuilder(); } + + /** + * Create and return a new FastqBuilder configured from the + * specified FASTQ formatted sequence. + * The FastqBuilder will not be null. + * + * @since 6.0.0 + * @param fastq FASTQ formatted sequence, must not be null + * @return a new FastqBuilder configured from the specified FASTQ + * formatted sequence + */ + public static final FastqBuilder builder(final Fastq fastq) + { + return new FastqBuilder(fastq); + } } diff --git a/biojava-genome/src/main/java/org/biojava/nbio/genome/io/fastq/FastqBuilder.java b/biojava-genome/src/main/java/org/biojava/nbio/genome/io/fastq/FastqBuilder.java index 4067e90b9c..8b2ced15f2 100755 --- a/biojava-genome/src/main/java/org/biojava/nbio/genome/io/fastq/FastqBuilder.java +++ b/biojava-genome/src/main/java/org/biojava/nbio/genome/io/fastq/FastqBuilder.java @@ -51,6 +51,25 @@ public FastqBuilder() // empty } + /** + * Create a new FASTQ formatted sequence builder configured + * from the specified FASTQ formatted sequence. + * + * @since 6.0.0 + * @param fastq FASTQ formatted sequence, must not be null + */ + public FastqBuilder(final Fastq fastq) + { + if (fastq == null) + { + throw new IllegalArgumentException("fastq must not be null"); + } + withDescription(fastq.getDescription()); + withSequence(fastq.getSequence()); + withQuality(fastq.getQuality()); + withVariant(fastq.getVariant()); + } + /** * Return the description for this FASTQ formatted sequence builder. diff --git a/biojava-genome/src/test/java/org/biojava/nbio/genome/io/fastq/FastqBuilderTest.java b/biojava-genome/src/test/java/org/biojava/nbio/genome/io/fastq/FastqBuilderTest.java index b013e996d2..8d68673989 100755 --- a/biojava-genome/src/test/java/org/biojava/nbio/genome/io/fastq/FastqBuilderTest.java +++ b/biojava-genome/src/test/java/org/biojava/nbio/genome/io/fastq/FastqBuilderTest.java @@ -36,6 +36,41 @@ public void testConstructor() Assert.assertNotNull(fastqBuilder); } + @Test + public void testConstructorFastq() + { + FastqBuilder fastqBuilder = new FastqBuilder() + .withDescription("description") + .withSequence("sequence") + .withQuality("quality_") + .withVariant(FastqVariant.FASTQ_SOLEXA); + + Fastq fastq = fastqBuilder.build(); + + FastqBuilder fastqBuilder2 = new FastqBuilder(fastq); + Assert.assertNotNull(fastqBuilder2); + + Fastq fastq2 = fastqBuilder2.build(); + Assert.assertEquals("description", fastq2.getDescription()); + Assert.assertEquals("sequence", fastq2.getSequence()); + Assert.assertEquals("quality_", fastq2.getQuality()); + Assert.assertEquals(FastqVariant.FASTQ_SOLEXA, fastq2.getVariant()); + } + + @Test + public void testConstructorNullFastq() + { + try + { + new FastqBuilder(null); + Assert.fail("builder(null) expected IllegalArgumentException"); + } + catch (IllegalArgumentException e) + { + // expected + } + } + @Test public void testBuildDefault() { diff --git a/biojava-genome/src/test/java/org/biojava/nbio/genome/io/fastq/FastqTest.java b/biojava-genome/src/test/java/org/biojava/nbio/genome/io/fastq/FastqTest.java index b6fc3c98b0..564f8eed1c 100755 --- a/biojava-genome/src/test/java/org/biojava/nbio/genome/io/fastq/FastqTest.java +++ b/biojava-genome/src/test/java/org/biojava/nbio/genome/io/fastq/FastqTest.java @@ -111,6 +111,20 @@ public void testBuilder() Assert.assertNotNull(Fastq.builder()); } + @Test + public void testBuilderNullFastq() + { + try + { + Fastq.builder(null); + Assert.fail("builder(null) expected IllegalArgumentException"); + } + catch (IllegalArgumentException e) + { + // expected + } + } + @Test public void testEquals() { From 54f4c2b1797d55ff034ac27e897cfc0cb5e55e2f Mon Sep 17 00:00:00 2001 From: JonStargaryen Date: Wed, 24 Feb 2021 10:27:35 -0800 Subject: [PATCH 049/599] dedicated test for SuperPositionQCP issues (#914) --- .../geometry/TestSuperPositionQCP.java | 34 ++++++++++++++----- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/geometry/TestSuperPositionQCP.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/geometry/TestSuperPositionQCP.java index 8928c26cbd..f5080786fb 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/geometry/TestSuperPositionQCP.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/geometry/TestSuperPositionQCP.java @@ -20,20 +20,19 @@ */ package org.biojava.nbio.structure.geometry; -import static org.junit.Assert.*; - -import java.util.Random; +import org.junit.Ignore; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import javax.vecmath.AxisAngle4d; import javax.vecmath.Matrix4d; import javax.vecmath.Point3d; import javax.vecmath.Vector3d; +import java.util.Random; -import org.biojava.nbio.structure.geometry.SuperPositionQuat; -import org.biojava.nbio.structure.geometry.SuperPositionQCP; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; /** * Test the Quaternion-Based Characteristic Polynomial {@link SuperPositionQCP} @@ -166,4 +165,23 @@ public void testAlternativeUsageQCP() { } + @Ignore("test for https://github.com/biojava/biojava/issues/914") + @Test + public void shouldHandleTwoFoldSymmetry() { + Matrix4d operator = new Matrix4d(-1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, -1, 0, + 0, 0, 0, 1); + + // add some jitter - otherwise rotation matrix will contain NaN + Point3d[] original = new Point3d[] { new Point3d(0, 0, 0), new Point3d(1.001, 0, 0) }; + Point3d[] transformed = new Point3d[] { new Point3d(0, 0, 0), new Point3d(-1, 0, 0) }; + + SuperPosition sqcp = new SuperPositionQCP(false); + + // operator 2 is a 2-fold, trace should be == -1 + Matrix4d m = sqcp.superposeAndTransform(original, transformed); + assertEquals(-1.0, m.m00 + m.m11 + m.m22, 0.001); + assertEquals(0.0, CalcPoint.rmsd(original, transformed), 0.001); + } } From 288b18c88181b422ff9fafbc50ee5748350554f4 Mon Sep 17 00:00:00 2001 From: JonStargaryen Date: Wed, 24 Feb 2021 10:29:57 -0800 Subject: [PATCH 050/599] switch from QCP to SVD --- .../biojava/nbio/structure/io/TestHardBioUnits.java | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestHardBioUnits.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestHardBioUnits.java index b50b4524fc..41e2394cb5 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestHardBioUnits.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestHardBioUnits.java @@ -29,7 +29,7 @@ import org.biojava.nbio.structure.align.util.AtomCache; import org.biojava.nbio.structure.geometry.CalcPoint; import org.biojava.nbio.structure.geometry.SuperPosition; -import org.biojava.nbio.structure.geometry.SuperPositionQCP; +import org.biojava.nbio.structure.geometry.SuperPositionSVD; import org.junit.Test; import static org.junit.Assert.*; @@ -107,10 +107,6 @@ public void test4A1I() throws IOException, StructureException { String pdbId = "4A1I"; int biolAssemblyNr = 2; - AtomCache atomCache = new AtomCache(); - // TODO there seem to be numerical instabilities when parsing BCIF - atomCache.setFiletype(StructureFiletype.CIF); - StructureIO.setAtomCache(atomCache); Structure bioAssembly = StructureIO.getBiologicalAssembly(pdbId,biolAssemblyNr); if ( bioAssembly == null){ @@ -177,16 +173,16 @@ public void test4A1I() throws IOException, StructureException { Point3d[] atomsTransfChainG = Calc.atomsToPoints(StructureTools.getAtomCAArray(transfChainG)); Point3d[] atomsTransfChainB = Calc.atomsToPoints(StructureTools.getAtomCAArray(transfChainB)); - SuperPosition sqcp = new SuperPositionQCP(false); + SuperPosition superPosition = new SuperPositionSVD(false); // operator 1 is the identity, trace should be == 3 - Matrix4d m1 = sqcp.superposeAndTransform(atomsOrigChainG, atomsTransfChainG); + Matrix4d m1 = superPosition.superposeAndTransform(atomsOrigChainG, atomsTransfChainG); assertEquals(3.0, m1.m00 + m1.m11 + m1.m22, 0.00001); assertEquals(0.0, CalcPoint.rmsd(atomsOrigChainG, atomsTransfChainG), 0.00001); // operator 2 is a 2-fold, trace should be == -1 - Matrix4d m2 = sqcp.superposeAndTransform(atomsOrigChainB, atomsTransfChainB); + Matrix4d m2 = superPosition.superposeAndTransform(atomsOrigChainB, atomsTransfChainB); assertEquals(-1.0, m2.m00 + m2.m11 + m2.m22, 0.00001); assertEquals(0.0, CalcPoint.rmsd(atomsOrigChainB, atomsTransfChainB), 0.00001); From 71368bebfc9e3cd9113df9031978d5f7c8e2ebb5 Mon Sep 17 00:00:00 2001 From: Michael L Heuer Date: Fri, 26 Feb 2021 11:33:21 -0600 Subject: [PATCH 051/599] Address review comments. --- .../nbio/genome/io/fastq/FastqBuilderTest.java | 18 ++++++++---------- .../nbio/genome/io/fastq/FastqTest.java | 16 +++++++--------- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/biojava-genome/src/test/java/org/biojava/nbio/genome/io/fastq/FastqBuilderTest.java b/biojava-genome/src/test/java/org/biojava/nbio/genome/io/fastq/FastqBuilderTest.java index 8d68673989..5803068276 100755 --- a/biojava-genome/src/test/java/org/biojava/nbio/genome/io/fastq/FastqBuilderTest.java +++ b/biojava-genome/src/test/java/org/biojava/nbio/genome/io/fastq/FastqBuilderTest.java @@ -20,10 +20,11 @@ */ package org.biojava.nbio.genome.io.fastq; - import org.junit.Assert; import org.junit.Test; +import org.junit.function.ThrowingRunnable; + /** * Unit test for FastqBuilder. */ @@ -60,15 +61,12 @@ public void testConstructorFastq() @Test public void testConstructorNullFastq() { - try - { - new FastqBuilder(null); - Assert.fail("builder(null) expected IllegalArgumentException"); - } - catch (IllegalArgumentException e) - { - // expected - } + Assert.assertThrows(IllegalArgumentException.class, new ThrowingRunnable() { + @Override + public void run() { + new FastqBuilder(null); + } + }); } @Test diff --git a/biojava-genome/src/test/java/org/biojava/nbio/genome/io/fastq/FastqTest.java b/biojava-genome/src/test/java/org/biojava/nbio/genome/io/fastq/FastqTest.java index 564f8eed1c..62d7ee9368 100755 --- a/biojava-genome/src/test/java/org/biojava/nbio/genome/io/fastq/FastqTest.java +++ b/biojava-genome/src/test/java/org/biojava/nbio/genome/io/fastq/FastqTest.java @@ -23,6 +23,7 @@ import org.junit.Assert; import org.junit.Test; +import org.junit.function.ThrowingRunnable; /** * Unit test for Fastq. @@ -114,15 +115,12 @@ public void testBuilder() @Test public void testBuilderNullFastq() { - try - { - Fastq.builder(null); - Assert.fail("builder(null) expected IllegalArgumentException"); - } - catch (IllegalArgumentException e) - { - // expected - } + Assert.assertThrows(IllegalArgumentException.class, new ThrowingRunnable() { + @Override + public void run() { + Fastq.builder(null); + } + }); } @Test From 1f80b1976518a108e143db9e34104abe8aa68098 Mon Sep 17 00:00:00 2001 From: Michael L Heuer Date: Fri, 26 Feb 2021 16:25:38 -0600 Subject: [PATCH 052/599] Update junit dependency version to 4.13.2, log4j to 2.14.0. --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 66521c8b2f..368b6ab568 100644 --- a/pom.xml +++ b/pom.xml @@ -42,7 +42,7 @@ 512M 1.0.9 1.7.30 - 2.13.3 + 2.14.0 ciftools-java-jdk8 2.0.2 @@ -480,7 +480,7 @@ junit junit - 4.13.1 + 4.13.2 test From 20c72bfe109719a03f2dde3c497be3ec687aadd2 Mon Sep 17 00:00:00 2001 From: Michael L Heuer Date: Fri, 26 Feb 2021 17:03:13 -0600 Subject: [PATCH 053/599] Update maven plugin dependency versions. --- pom.xml | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/pom.xml b/pom.xml index 368b6ab568..afee698d7b 100644 --- a/pom.xml +++ b/pom.xml @@ -170,7 +170,7 @@ maven-compiler-plugin - 3.8.0 + 3.8.1 ${jdk.version} ${jdk.version} @@ -178,23 +178,23 @@ maven-dependency-plugin - 3.1.1 + 3.1.2 maven-jar-plugin - 3.1.2 + 3.2.0 maven-scm-plugin - 1.10.0 + 1.11.2 maven-source-plugin - 3.0.1 + 3.2.1 maven-failsafe-plugin - 3.0.0-M3 + 3.0.0-M5 net.sf @@ -209,7 +209,7 @@ org.apache.maven.plugins maven-release-plugin - 2.5.3 + 3.0.0-M1 true clean install @@ -227,7 +227,7 @@ org.apache.maven.plugins maven-javadoc-plugin - 3.1.0 + 3.2.0 -Xdoclint:none @@ -245,11 +245,11 @@ org.apache.maven.plugins maven-shade-plugin - 3.2.0 + 3.2.4 maven-assembly-plugin - 3.1.0 + 3.3.0 src/main/assembly/assembly.xml @@ -283,18 +283,18 @@ org.apache.maven.plugins maven-checkstyle-plugin - 3.0.0 + 3.1.1 org.apache.maven.plugins maven-resources-plugin - 3.1.0 + 3.2.0 maven-enforcer-plugin - 3.0.0-M2 + 3.0.0-M3 enforce-java @@ -319,12 +319,12 @@ org.apache.maven.plugins maven-surefire-plugin - 3.0.0-M3 + 3.0.0-M5 org.apache.maven.plugins maven-site-plugin - 3.7.1 + 3.9.1 @@ -343,7 +343,7 @@ org.sonatype.plugins nexus-staging-maven-plugin - 1.6.7 + 1.6.8 true ossrh From e40d0efdd0d1337741264d3e6389605bf822f440 Mon Sep 17 00:00:00 2001 From: Spencer Bliven Date: Mon, 1 Mar 2021 17:35:50 +0100 Subject: [PATCH 054/599] Fix #917: Symmetry doesn't display with non-US locales - Always use the US locale when printing jmol scripts - Update Jmol to 14.31.10 while we're at it. --- biojava-structure-gui/pom.xml | 2 +- .../symmetry/jmolScript/JmolSymmetryScriptGenerator.java | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/biojava-structure-gui/pom.xml b/biojava-structure-gui/pom.xml index a57bf73cdb..154f7c229d 100644 --- a/biojava-structure-gui/pom.xml +++ b/biojava-structure-gui/pom.xml @@ -42,7 +42,7 @@ net.sourceforge.jmol jmol - 14.29.17 + 14.31.10 diff --git a/biojava-structure-gui/src/main/java/org/biojava/nbio/structure/symmetry/jmolScript/JmolSymmetryScriptGenerator.java b/biojava-structure-gui/src/main/java/org/biojava/nbio/structure/symmetry/jmolScript/JmolSymmetryScriptGenerator.java index dd2401b2c8..8d3e89b4bf 100644 --- a/biojava-structure-gui/src/main/java/org/biojava/nbio/structure/symmetry/jmolScript/JmolSymmetryScriptGenerator.java +++ b/biojava-structure-gui/src/main/java/org/biojava/nbio/structure/symmetry/jmolScript/JmolSymmetryScriptGenerator.java @@ -29,6 +29,7 @@ import javax.vecmath.Tuple3d; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Map.Entry; @@ -226,11 +227,11 @@ protected static String getJmolPoint(Tuple3d point) { } protected static String f1Dot2(float number) { - return String.format("%1.2f", number); + return String.format(Locale.US, "%1.2f", number); } protected static String fDot2(double number) { - return String.format("%.2f", number); + return String.format(Locale.US, "%.2f", number); } /** From 802abb832c3295ff32b589f5190956dfb57515b6 Mon Sep 17 00:00:00 2001 From: Spencer Bliven Date: Mon, 1 Mar 2021 17:38:24 +0100 Subject: [PATCH 055/599] Test that Jmol polygons scripts generate correctly. This runs QuatSymmetryDetector. It would be better to mock the results, but this is nontrivial with the current implementation. --- .../TestJmolSymmetryScriptGenerator.java | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 biojava-structure-gui/src/test/java/org/biojava/nbio/structure/symmetry/TestJmolSymmetryScriptGenerator.java diff --git a/biojava-structure-gui/src/test/java/org/biojava/nbio/structure/symmetry/TestJmolSymmetryScriptGenerator.java b/biojava-structure-gui/src/test/java/org/biojava/nbio/structure/symmetry/TestJmolSymmetryScriptGenerator.java new file mode 100644 index 0000000000..164319e977 --- /dev/null +++ b/biojava-structure-gui/src/test/java/org/biojava/nbio/structure/symmetry/TestJmolSymmetryScriptGenerator.java @@ -0,0 +1,67 @@ +/* + * BioJava development code + * + * This code may be freely distributed and modified under the + * terms of the GNU Lesser General Public Licence. This should + * be distributed with the code. If you do not have a copy, + * see: + * + * http://www.gnu.org/copyleft/lesser.html + * + * Copyright for this code is held jointly by the individual + * authors. These should be listed in @author doc comments. + * + * For more information on the BioJava project and its aims, + * or to join the biojava-l mailing list, visit the home page + * at: + * + * http://www.biojava.org/ + * + */ +package org.biojava.nbio.structure.symmetry; + +import static org.junit.Assert.assertEquals; + +import java.io.IOException; +import java.util.List; + +import org.biojava.nbio.structure.Structure; +import org.biojava.nbio.structure.StructureException; +import org.biojava.nbio.structure.StructureIO; +import org.biojava.nbio.structure.cluster.SubunitCluster; +import org.biojava.nbio.structure.cluster.SubunitClustererParameters; +import org.biojava.nbio.structure.symmetry.axis.RotationAxisAligner; +import org.biojava.nbio.structure.symmetry.core.QuatSymmetryDetector; +import org.biojava.nbio.structure.symmetry.core.QuatSymmetryParameters; +import org.biojava.nbio.structure.symmetry.core.QuatSymmetryResults; +import org.biojava.nbio.structure.symmetry.core.RotationGroup; +import org.biojava.nbio.structure.symmetry.core.Stoichiometry; +import org.biojava.nbio.structure.symmetry.core.SymmetryPerceptionMethod; +import org.biojava.nbio.structure.symmetry.jmolScript.JmolSymmetryScriptGeneratorDn; +import org.junit.Before; +import org.junit.Test; + +/** + * + * @author Spencer Bliven + */ +public class TestJmolSymmetryScriptGenerator { + @Before + public void setUp() { + } + + @Test + public void testPolygon() throws IOException, StructureException { + Structure struc = StructureIO.getStructure("4hhb"); + QuatSymmetryParameters sp = new QuatSymmetryParameters(); + SubunitClustererParameters cp = new SubunitClustererParameters(); + + QuatSymmetryResults results = QuatSymmetryDetector.calcGlobalSymmetry(struc, sp, cp); + RotationAxisAligner axis = new RotationAxisAligner(results); + JmolSymmetryScriptGeneratorDn gen = new JmolSymmetryScriptGeneratorDn(axis, "D3"); + + String poly = gen.drawPolyhedron(); + String expected = "draw polyhedronD30 line{30.02,-39.95,0.59}{29.24,-0.53,40.00}{30.02,38.89,0.59}{30.80,-0.53,-38.82}{30.02,-39.95,0.59}{-30.00,-39.95,-0.60}{-30.79,-0.53,38.81}{-30.00,38.89,-0.60}{-29.22,-0.53,-40.01}{-30.00,-39.95,-0.60}width 0.45 color [x42ffd9] off;draw polyhedronD31 line{29.24,-0.53,40.00}{-30.79,-0.53,38.81}width 0.45 color [x42ffd9] off;draw polyhedronD32 line{30.02,38.89,0.59}{-30.00,38.89,-0.60}width 0.45 color [x42ffd9] off;draw polyhedronD33 line{30.80,-0.53,-38.82}{-29.22,-0.53,-40.01}width 0.45 color [x42ffd9] off;"; + assertEquals(expected, poly); + } +} \ No newline at end of file From 6a10ba505aadf845d0c7a9eec8fed85f81f783e3 Mon Sep 17 00:00:00 2001 From: Spencer Bliven Date: Mon, 1 Mar 2021 17:39:02 +0100 Subject: [PATCH 056/599] Test that fetching structures by SCOP domain works. --- .../java/org/biojava/nbio/structure/TestAtomCache.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/TestAtomCache.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/TestAtomCache.java index bb9ec5ba2a..ab7988ae3f 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/TestAtomCache.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/TestAtomCache.java @@ -221,6 +221,15 @@ public void testFetchObsolete() throws IOException, StructureException { } + @Test + public void testGetScopDomain() throws IOException, StructureException { + String name = "d2gs2a_"; + + Structure s = cache.getStructure(name); + assertNotNull("Failed to fetch structure from SCOP ID", s); + assertEquals("2gs2.A", s.getName()); + } + @Test public void testSettingFileParsingType(){ AtomCache cache = new AtomCache(); From 55b61461d3ddbc449c3ca5ecbbccc9ef97f2c393 Mon Sep 17 00:00:00 2001 From: Spencer Bliven Date: Mon, 1 Mar 2021 17:53:50 +0100 Subject: [PATCH 057/599] Fix compilation issues. These seem to be regularly deleted by IDEs running on different JDKs. If you see a warning, please find the correct syntax to silence it rather than deleting the cast. --- .../biojava/nbio/structure/chem/ZipChemCompProvider.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ZipChemCompProvider.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ZipChemCompProvider.java index 34d7eea4db..5888213c5b 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ZipChemCompProvider.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ZipChemCompProvider.java @@ -206,7 +206,8 @@ private synchronized ChemComp getFromZip(String recordName) { final String filename = "chemcomp/" + recordName + ".cif.gz"; // try with resources block to read from the filesystem. - try (FileSystem fs = FileSystems.newFileSystem(m_zipFile, null)) { + // Don't remove the (ClassLoader) cast! It is required for openjdk 11. + try (FileSystem fs = FileSystems.newFileSystem(m_zipFile, (ClassLoader)null)) { Path cif = fs.getPath(filename); if (Files.exists(cif)) { @@ -255,7 +256,8 @@ private synchronized boolean addToZipFileSystem(Path zipFile, File[] files, Path */ // Copy in each file. - try (FileSystem zipfs = FileSystems.newFileSystem(zipFile, null)) { + // Don't remove the (ClassLoader) cast! It is required for openjdk 11. + try (FileSystem zipfs = FileSystems.newFileSystem(zipFile, (ClassLoader)null)) { Files.createDirectories(pathWithinArchive); for (File f : files) { if (!f.isDirectory() && f.exists()) { From b8d7edd62a3b8ed5b366844da66f3f2d5865441b Mon Sep 17 00:00:00 2001 From: Jose Manuel Duarte Date: Tue, 2 Mar 2021 10:37:09 -0800 Subject: [PATCH 058/599] [maven-release-plugin] prepare release biojava-6.0.0-alpha1 --- biojava-aa-prop/pom.xml | 6 +++--- biojava-alignment/pom.xml | 4 ++-- biojava-core/pom.xml | 2 +- biojava-genome/pom.xml | 6 +++--- biojava-integrationtest/pom.xml | 4 ++-- biojava-modfinder/pom.xml | 4 ++-- biojava-ontology/pom.xml | 2 +- biojava-protein-disorder/pom.xml | 4 ++-- biojava-structure-gui/pom.xml | 6 +++--- biojava-structure/pom.xml | 6 +++--- biojava-survival/pom.xml | 2 +- biojava-ws/pom.xml | 4 ++-- pom.xml | 4 ++-- 13 files changed, 27 insertions(+), 27 deletions(-) diff --git a/biojava-aa-prop/pom.xml b/biojava-aa-prop/pom.xml index 78344622b1..7ad442f3b9 100644 --- a/biojava-aa-prop/pom.xml +++ b/biojava-aa-prop/pom.xml @@ -2,7 +2,7 @@ biojava org.biojava - 6.0.0-SNAPSHOT + 6.0.0-alpha1 4.0.0 biojava-aa-prop @@ -70,12 +70,12 @@ org.biojava biojava-core - 6.0.0-SNAPSHOT + 6.0.0-alpha1 org.biojava biojava-structure - 6.0.0-SNAPSHOT + 6.0.0-alpha1 diff --git a/biojava-alignment/pom.xml b/biojava-alignment/pom.xml index a22b560d19..5c45f050df 100644 --- a/biojava-alignment/pom.xml +++ b/biojava-alignment/pom.xml @@ -4,7 +4,7 @@ biojava org.biojava - 6.0.0-SNAPSHOT + 6.0.0-alpha1 biojava-alignment biojava-alignment @@ -47,7 +47,7 @@ org.biojava biojava-core - 6.0.0-SNAPSHOT + 6.0.0-alpha1 compile diff --git a/biojava-core/pom.xml b/biojava-core/pom.xml index 6cc9c6c9af..ee5b63903a 100644 --- a/biojava-core/pom.xml +++ b/biojava-core/pom.xml @@ -3,7 +3,7 @@ biojava org.biojava - 6.0.0-SNAPSHOT + 6.0.0-alpha1 4.0.0 biojava-core diff --git a/biojava-genome/pom.xml b/biojava-genome/pom.xml index c4d667cf50..84017f41f8 100644 --- a/biojava-genome/pom.xml +++ b/biojava-genome/pom.xml @@ -3,7 +3,7 @@ biojava org.biojava - 6.0.0-SNAPSHOT + 6.0.0-alpha1 4.0.0 biojava-genome @@ -85,13 +85,13 @@ org.biojava biojava-core - 6.0.0-SNAPSHOT + 6.0.0-alpha1 compile org.biojava biojava-alignment - 6.0.0-SNAPSHOT + 6.0.0-alpha1 compile diff --git a/biojava-integrationtest/pom.xml b/biojava-integrationtest/pom.xml index 0bd381f989..ad8bccc314 100644 --- a/biojava-integrationtest/pom.xml +++ b/biojava-integrationtest/pom.xml @@ -4,7 +4,7 @@ biojava org.biojava - 6.0.0-SNAPSHOT + 6.0.0-alpha1 biojava-integrationtest jar @@ -28,7 +28,7 @@ org.biojava biojava-structure - 6.0.0-SNAPSHOT + 6.0.0-alpha1 diff --git a/biojava-modfinder/pom.xml b/biojava-modfinder/pom.xml index 4df1148dee..130a9a8e8b 100644 --- a/biojava-modfinder/pom.xml +++ b/biojava-modfinder/pom.xml @@ -4,7 +4,7 @@ biojava org.biojava - 6.0.0-SNAPSHOT + 6.0.0-alpha1 biojava-modfinder biojava-modfinder @@ -31,7 +31,7 @@ org.biojava biojava-structure - 6.0.0-SNAPSHOT + 6.0.0-alpha1 jar compile diff --git a/biojava-ontology/pom.xml b/biojava-ontology/pom.xml index 03787e7d7a..92a8733da7 100644 --- a/biojava-ontology/pom.xml +++ b/biojava-ontology/pom.xml @@ -4,7 +4,7 @@ org.biojava biojava - 6.0.0-SNAPSHOT + 6.0.0-alpha1 biojava-ontology diff --git a/biojava-protein-disorder/pom.xml b/biojava-protein-disorder/pom.xml index 9153de3e05..103e19986c 100644 --- a/biojava-protein-disorder/pom.xml +++ b/biojava-protein-disorder/pom.xml @@ -3,7 +3,7 @@ biojava org.biojava - 6.0.0-SNAPSHOT + 6.0.0-alpha1 biojava-protein-disorder jar @@ -63,7 +63,7 @@ org.biojava biojava-core - 6.0.0-SNAPSHOT + 6.0.0-alpha1 diff --git a/biojava-structure-gui/pom.xml b/biojava-structure-gui/pom.xml index 154f7c229d..56087dedb3 100644 --- a/biojava-structure-gui/pom.xml +++ b/biojava-structure-gui/pom.xml @@ -3,7 +3,7 @@ biojava org.biojava - 6.0.0-SNAPSHOT + 6.0.0-alpha1 4.0.0 biojava-structure-gui @@ -27,13 +27,13 @@ org.biojava biojava-structure - 6.0.0-SNAPSHOT + 6.0.0-alpha1 compile org.biojava biojava-core - 6.0.0-SNAPSHOT + 6.0.0-alpha1 compile diff --git a/biojava-structure/pom.xml b/biojava-structure/pom.xml index 87b34d4dcb..8e7cfa717a 100644 --- a/biojava-structure/pom.xml +++ b/biojava-structure/pom.xml @@ -4,7 +4,7 @@ biojava org.biojava - 6.0.0-SNAPSHOT + 6.0.0-alpha1 biojava-structure biojava-structure @@ -44,13 +44,13 @@ org.biojava biojava-alignment - 6.0.0-SNAPSHOT + 6.0.0-alpha1 compile org.biojava biojava-core - 6.0.0-SNAPSHOT + 6.0.0-alpha1 compile diff --git a/biojava-survival/pom.xml b/biojava-survival/pom.xml index 8774d85478..f579e85eb5 100644 --- a/biojava-survival/pom.xml +++ b/biojava-survival/pom.xml @@ -4,7 +4,7 @@ org.biojava biojava - 6.0.0-SNAPSHOT + 6.0.0-alpha1 biojava-survival diff --git a/biojava-ws/pom.xml b/biojava-ws/pom.xml index 65b13c6730..628f4782e4 100644 --- a/biojava-ws/pom.xml +++ b/biojava-ws/pom.xml @@ -3,7 +3,7 @@ biojava org.biojava - 6.0.0-SNAPSHOT + 6.0.0-alpha1 biojava-ws biojava-ws @@ -19,7 +19,7 @@ org.biojava biojava-core - 6.0.0-SNAPSHOT + 6.0.0-alpha1 compile diff --git a/pom.xml b/pom.xml index afee698d7b..48009bd348 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ org.biojava biojava pom - 6.0.0-SNAPSHOT + 6.0.0-alpha1 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 @@ -51,7 +51,7 @@ scm:git:git@github.com:biojava/biojava.git https://github.com/biojava/biojava - HEAD + biojava-6.0.0-alpha1 diff --git a/biojava-alignment/pom.xml b/biojava-alignment/pom.xml index 5c45f050df..a22b560d19 100644 --- a/biojava-alignment/pom.xml +++ b/biojava-alignment/pom.xml @@ -4,7 +4,7 @@ biojava org.biojava - 6.0.0-alpha1 + 6.0.0-SNAPSHOT biojava-alignment biojava-alignment @@ -47,7 +47,7 @@ org.biojava biojava-core - 6.0.0-alpha1 + 6.0.0-SNAPSHOT compile diff --git a/biojava-core/pom.xml b/biojava-core/pom.xml index ee5b63903a..6cc9c6c9af 100644 --- a/biojava-core/pom.xml +++ b/biojava-core/pom.xml @@ -3,7 +3,7 @@ biojava org.biojava - 6.0.0-alpha1 + 6.0.0-SNAPSHOT 4.0.0 biojava-core diff --git a/biojava-genome/pom.xml b/biojava-genome/pom.xml index 84017f41f8..c4d667cf50 100644 --- a/biojava-genome/pom.xml +++ b/biojava-genome/pom.xml @@ -3,7 +3,7 @@ biojava org.biojava - 6.0.0-alpha1 + 6.0.0-SNAPSHOT 4.0.0 biojava-genome @@ -85,13 +85,13 @@ org.biojava biojava-core - 6.0.0-alpha1 + 6.0.0-SNAPSHOT compile org.biojava biojava-alignment - 6.0.0-alpha1 + 6.0.0-SNAPSHOT compile diff --git a/biojava-integrationtest/pom.xml b/biojava-integrationtest/pom.xml index ad8bccc314..0bd381f989 100644 --- a/biojava-integrationtest/pom.xml +++ b/biojava-integrationtest/pom.xml @@ -4,7 +4,7 @@ biojava org.biojava - 6.0.0-alpha1 + 6.0.0-SNAPSHOT biojava-integrationtest jar @@ -28,7 +28,7 @@ org.biojava biojava-structure - 6.0.0-alpha1 + 6.0.0-SNAPSHOT diff --git a/biojava-modfinder/pom.xml b/biojava-modfinder/pom.xml index 130a9a8e8b..4df1148dee 100644 --- a/biojava-modfinder/pom.xml +++ b/biojava-modfinder/pom.xml @@ -4,7 +4,7 @@ biojava org.biojava - 6.0.0-alpha1 + 6.0.0-SNAPSHOT biojava-modfinder biojava-modfinder @@ -31,7 +31,7 @@ org.biojava biojava-structure - 6.0.0-alpha1 + 6.0.0-SNAPSHOT jar compile diff --git a/biojava-ontology/pom.xml b/biojava-ontology/pom.xml index 92a8733da7..03787e7d7a 100644 --- a/biojava-ontology/pom.xml +++ b/biojava-ontology/pom.xml @@ -4,7 +4,7 @@ org.biojava biojava - 6.0.0-alpha1 + 6.0.0-SNAPSHOT biojava-ontology diff --git a/biojava-protein-disorder/pom.xml b/biojava-protein-disorder/pom.xml index 103e19986c..9153de3e05 100644 --- a/biojava-protein-disorder/pom.xml +++ b/biojava-protein-disorder/pom.xml @@ -3,7 +3,7 @@ biojava org.biojava - 6.0.0-alpha1 + 6.0.0-SNAPSHOT biojava-protein-disorder jar @@ -63,7 +63,7 @@ org.biojava biojava-core - 6.0.0-alpha1 + 6.0.0-SNAPSHOT diff --git a/biojava-structure-gui/pom.xml b/biojava-structure-gui/pom.xml index 56087dedb3..154f7c229d 100644 --- a/biojava-structure-gui/pom.xml +++ b/biojava-structure-gui/pom.xml @@ -3,7 +3,7 @@ biojava org.biojava - 6.0.0-alpha1 + 6.0.0-SNAPSHOT 4.0.0 biojava-structure-gui @@ -27,13 +27,13 @@ org.biojava biojava-structure - 6.0.0-alpha1 + 6.0.0-SNAPSHOT compile org.biojava biojava-core - 6.0.0-alpha1 + 6.0.0-SNAPSHOT compile diff --git a/biojava-structure/pom.xml b/biojava-structure/pom.xml index 8e7cfa717a..87b34d4dcb 100644 --- a/biojava-structure/pom.xml +++ b/biojava-structure/pom.xml @@ -4,7 +4,7 @@ biojava org.biojava - 6.0.0-alpha1 + 6.0.0-SNAPSHOT biojava-structure biojava-structure @@ -44,13 +44,13 @@ org.biojava biojava-alignment - 6.0.0-alpha1 + 6.0.0-SNAPSHOT compile org.biojava biojava-core - 6.0.0-alpha1 + 6.0.0-SNAPSHOT compile diff --git a/biojava-survival/pom.xml b/biojava-survival/pom.xml index f579e85eb5..8774d85478 100644 --- a/biojava-survival/pom.xml +++ b/biojava-survival/pom.xml @@ -4,7 +4,7 @@ org.biojava biojava - 6.0.0-alpha1 + 6.0.0-SNAPSHOT biojava-survival diff --git a/biojava-ws/pom.xml b/biojava-ws/pom.xml index 628f4782e4..65b13c6730 100644 --- a/biojava-ws/pom.xml +++ b/biojava-ws/pom.xml @@ -3,7 +3,7 @@ biojava org.biojava - 6.0.0-alpha1 + 6.0.0-SNAPSHOT biojava-ws biojava-ws @@ -19,7 +19,7 @@ org.biojava biojava-core - 6.0.0-alpha1 + 6.0.0-SNAPSHOT compile diff --git a/pom.xml b/pom.xml index 48009bd348..afee698d7b 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ org.biojava biojava pom - 6.0.0-alpha1 + 6.0.0-SNAPSHOT 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 @@ -51,7 +51,7 @@ scm:git:git@github.com:biojava/biojava.git https://github.com/biojava/biojava - biojava-6.0.0-alpha1 + HEAD forked-path - - true - -Pgpg-release + + false + @@ -339,35 +339,6 @@ - - - org.sonatype.plugins - nexus-staging-maven-plugin - 1.6.8 - true - - ossrh - https://oss.sonatype.org/ - true - - - - - - - - - - - - - - - - - - - org.apache.maven.plugins @@ -379,7 +350,6 @@ - org.apache.maven.plugins maven-jar-plugin @@ -403,7 +373,6 @@ - org.codehaus.mojo findbugs-maven-plugin @@ -418,49 +387,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -471,8 +397,6 @@ - - @@ -589,12 +513,96 @@ + + + + + ossrh + https://oss.sonatype.org/content/repositories/snapshots + + + ossrh + https://oss.sonatype.org/service/local/staging/deploy/maven2/ + + + + + release + + + + + + org.sonatype.plugins + nexus-staging-maven-plugin + 1.6.8 + true + + ossrh + https://oss.sonatype.org/ + true + + + + + + org.apache.maven.plugins + maven-gpg-plugin + 1.6 + + + sign-artifacts + verify + + sign + + + + + + + + org.apache.maven.plugins + maven-source-plugin + 3.2.0 + + + attach-sources + + jar-no-fork + + + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 3.2.0 + + + attach-javadocs + + jar + + + + + + + + + codesigning @@ -636,35 +644,6 @@ - - - - - - - release-sign-artifacts - - - performRelease - true - - - - - - org.apache.maven.plugins - maven-gpg-plugin - 1.6 - - - sign-artifacts - verify - - sign - - - - From 71b02ebc68a40c605fdd5b8d15ce1e65cce45e7e Mon Sep 17 00:00:00 2001 From: Jose Duarte Date: Wed, 3 Mar 2021 22:14:53 -0800 Subject: [PATCH 061/599] Adding some gpg config that works in other projects --- pom.xml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pom.xml b/pom.xml index 039670095e..d1940f9add 100644 --- a/pom.xml +++ b/pom.xml @@ -561,6 +561,13 @@ sign + + + + --pinentry-mode + loopback + + From fce9a51f295673968ae23cd2e9d21eb94f64d706 Mon Sep 17 00:00:00 2001 From: Jose Duarte Date: Wed, 3 Mar 2021 22:54:30 -0800 Subject: [PATCH 062/599] Can't test relase:perform without pushing --- pom.xml | 3 --- 1 file changed, 3 deletions(-) diff --git a/pom.xml b/pom.xml index d1940f9add..6d307acc49 100644 --- a/pom.xml +++ b/pom.xml @@ -218,9 +218,6 @@ forked-path - - false - From 58eb57015d303d980d07b4c66a8a79d80aea3b57 Mon Sep 17 00:00:00 2001 From: JonStargaryen Date: Thu, 4 Mar 2021 17:06:51 -0800 Subject: [PATCH 063/599] ChemComp#monNstdParentCompId now returns null instead of empty String (#921) --- .../src/main/java/org/biojava/nbio/structure/chem/ChemComp.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemComp.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemComp.java index 76043374fc..0323e82489 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemComp.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemComp.java @@ -149,7 +149,7 @@ public String getMonNstdParentCompId() { } public void setMonNstdParentCompId(String monNstdParentCompId) { - this.monNstdParentCompId = monNstdParentCompId; + this.monNstdParentCompId = monNstdParentCompId.isEmpty() ? null : monNstdParentCompId; setStandardFlag(); } From 4dcc024c9de0d6c85701186bf8557a47e408735a Mon Sep 17 00:00:00 2001 From: JonStargaryen Date: Thu, 4 Mar 2021 17:25:26 -0800 Subject: [PATCH 064/599] null check --- .../src/main/java/org/biojava/nbio/structure/chem/ChemComp.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemComp.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemComp.java index 0323e82489..cb33e369b3 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemComp.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/chem/ChemComp.java @@ -149,7 +149,7 @@ public String getMonNstdParentCompId() { } public void setMonNstdParentCompId(String monNstdParentCompId) { - this.monNstdParentCompId = monNstdParentCompId.isEmpty() ? null : monNstdParentCompId; + this.monNstdParentCompId = (monNstdParentCompId == null || monNstdParentCompId.isEmpty()) ? null : monNstdParentCompId; setStandardFlag(); } From c9f58cec9d661672c10b0c08aa2c618bc90caf44 Mon Sep 17 00:00:00 2001 From: Jose Manuel Duarte Date: Thu, 4 Mar 2021 22:01:44 -0800 Subject: [PATCH 065/599] [maven-release-plugin] prepare release biojava-6.0.0-alpha2 --- biojava-aa-prop/pom.xml | 6 +++--- biojava-alignment/pom.xml | 4 ++-- biojava-core/pom.xml | 2 +- biojava-genome/pom.xml | 6 +++--- biojava-integrationtest/pom.xml | 4 ++-- biojava-modfinder/pom.xml | 4 ++-- biojava-ontology/pom.xml | 2 +- biojava-protein-disorder/pom.xml | 4 ++-- biojava-structure-gui/pom.xml | 6 +++--- biojava-structure/pom.xml | 6 +++--- biojava-survival/pom.xml | 2 +- biojava-ws/pom.xml | 4 ++-- pom.xml | 4 ++-- 13 files changed, 27 insertions(+), 27 deletions(-) diff --git a/biojava-aa-prop/pom.xml b/biojava-aa-prop/pom.xml index 78344622b1..698b5ad850 100644 --- a/biojava-aa-prop/pom.xml +++ b/biojava-aa-prop/pom.xml @@ -2,7 +2,7 @@ biojava org.biojava - 6.0.0-SNAPSHOT + 6.0.0-alpha2 4.0.0 biojava-aa-prop @@ -70,12 +70,12 @@ org.biojava biojava-core - 6.0.0-SNAPSHOT + 6.0.0-alpha2 org.biojava biojava-structure - 6.0.0-SNAPSHOT + 6.0.0-alpha2 diff --git a/biojava-alignment/pom.xml b/biojava-alignment/pom.xml index a22b560d19..f6e899ebd5 100644 --- a/biojava-alignment/pom.xml +++ b/biojava-alignment/pom.xml @@ -4,7 +4,7 @@ biojava org.biojava - 6.0.0-SNAPSHOT + 6.0.0-alpha2 biojava-alignment biojava-alignment @@ -47,7 +47,7 @@ org.biojava biojava-core - 6.0.0-SNAPSHOT + 6.0.0-alpha2 compile diff --git a/biojava-core/pom.xml b/biojava-core/pom.xml index 6cc9c6c9af..f0c4a02483 100644 --- a/biojava-core/pom.xml +++ b/biojava-core/pom.xml @@ -3,7 +3,7 @@ biojava org.biojava - 6.0.0-SNAPSHOT + 6.0.0-alpha2 4.0.0 biojava-core diff --git a/biojava-genome/pom.xml b/biojava-genome/pom.xml index c4d667cf50..fbf64183da 100644 --- a/biojava-genome/pom.xml +++ b/biojava-genome/pom.xml @@ -3,7 +3,7 @@ biojava org.biojava - 6.0.0-SNAPSHOT + 6.0.0-alpha2 4.0.0 biojava-genome @@ -85,13 +85,13 @@ org.biojava biojava-core - 6.0.0-SNAPSHOT + 6.0.0-alpha2 compile org.biojava biojava-alignment - 6.0.0-SNAPSHOT + 6.0.0-alpha2 compile diff --git a/biojava-integrationtest/pom.xml b/biojava-integrationtest/pom.xml index 0bd381f989..9630da7a40 100644 --- a/biojava-integrationtest/pom.xml +++ b/biojava-integrationtest/pom.xml @@ -4,7 +4,7 @@ biojava org.biojava - 6.0.0-SNAPSHOT + 6.0.0-alpha2 biojava-integrationtest jar @@ -28,7 +28,7 @@ org.biojava biojava-structure - 6.0.0-SNAPSHOT + 6.0.0-alpha2 diff --git a/biojava-modfinder/pom.xml b/biojava-modfinder/pom.xml index 4df1148dee..a80d79fa8c 100644 --- a/biojava-modfinder/pom.xml +++ b/biojava-modfinder/pom.xml @@ -4,7 +4,7 @@ biojava org.biojava - 6.0.0-SNAPSHOT + 6.0.0-alpha2 biojava-modfinder biojava-modfinder @@ -31,7 +31,7 @@ org.biojava biojava-structure - 6.0.0-SNAPSHOT + 6.0.0-alpha2 jar compile diff --git a/biojava-ontology/pom.xml b/biojava-ontology/pom.xml index 03787e7d7a..ff59bfea06 100644 --- a/biojava-ontology/pom.xml +++ b/biojava-ontology/pom.xml @@ -4,7 +4,7 @@ org.biojava biojava - 6.0.0-SNAPSHOT + 6.0.0-alpha2 biojava-ontology diff --git a/biojava-protein-disorder/pom.xml b/biojava-protein-disorder/pom.xml index 9153de3e05..ac7c1cb0a4 100644 --- a/biojava-protein-disorder/pom.xml +++ b/biojava-protein-disorder/pom.xml @@ -3,7 +3,7 @@ biojava org.biojava - 6.0.0-SNAPSHOT + 6.0.0-alpha2 biojava-protein-disorder jar @@ -63,7 +63,7 @@ org.biojava biojava-core - 6.0.0-SNAPSHOT + 6.0.0-alpha2 diff --git a/biojava-structure-gui/pom.xml b/biojava-structure-gui/pom.xml index 154f7c229d..5f78ed2113 100644 --- a/biojava-structure-gui/pom.xml +++ b/biojava-structure-gui/pom.xml @@ -3,7 +3,7 @@ biojava org.biojava - 6.0.0-SNAPSHOT + 6.0.0-alpha2 4.0.0 biojava-structure-gui @@ -27,13 +27,13 @@ org.biojava biojava-structure - 6.0.0-SNAPSHOT + 6.0.0-alpha2 compile org.biojava biojava-core - 6.0.0-SNAPSHOT + 6.0.0-alpha2 compile diff --git a/biojava-structure/pom.xml b/biojava-structure/pom.xml index 87b34d4dcb..1642df61e4 100644 --- a/biojava-structure/pom.xml +++ b/biojava-structure/pom.xml @@ -4,7 +4,7 @@ biojava org.biojava - 6.0.0-SNAPSHOT + 6.0.0-alpha2 biojava-structure biojava-structure @@ -44,13 +44,13 @@ org.biojava biojava-alignment - 6.0.0-SNAPSHOT + 6.0.0-alpha2 compile org.biojava biojava-core - 6.0.0-SNAPSHOT + 6.0.0-alpha2 compile diff --git a/biojava-survival/pom.xml b/biojava-survival/pom.xml index 8774d85478..082f35dc01 100644 --- a/biojava-survival/pom.xml +++ b/biojava-survival/pom.xml @@ -4,7 +4,7 @@ org.biojava biojava - 6.0.0-SNAPSHOT + 6.0.0-alpha2 biojava-survival diff --git a/biojava-ws/pom.xml b/biojava-ws/pom.xml index 65b13c6730..05ea584fc4 100644 --- a/biojava-ws/pom.xml +++ b/biojava-ws/pom.xml @@ -3,7 +3,7 @@ biojava org.biojava - 6.0.0-SNAPSHOT + 6.0.0-alpha2 biojava-ws biojava-ws @@ -19,7 +19,7 @@ org.biojava biojava-core - 6.0.0-SNAPSHOT + 6.0.0-alpha2 compile diff --git a/pom.xml b/pom.xml index 6d307acc49..c8c3d67ebe 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ org.biojava biojava pom - 6.0.0-SNAPSHOT + 6.0.0-alpha2 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 @@ -51,7 +51,7 @@ scm:git:git@github.com:biojava/biojava.git https://github.com/biojava/biojava - HEAD + biojava-6.0.0-alpha2 diff --git a/biojava-alignment/pom.xml b/biojava-alignment/pom.xml index f6e899ebd5..a22b560d19 100644 --- a/biojava-alignment/pom.xml +++ b/biojava-alignment/pom.xml @@ -4,7 +4,7 @@ biojava org.biojava - 6.0.0-alpha2 + 6.0.0-SNAPSHOT biojava-alignment biojava-alignment @@ -47,7 +47,7 @@ org.biojava biojava-core - 6.0.0-alpha2 + 6.0.0-SNAPSHOT compile diff --git a/biojava-core/pom.xml b/biojava-core/pom.xml index f0c4a02483..6cc9c6c9af 100644 --- a/biojava-core/pom.xml +++ b/biojava-core/pom.xml @@ -3,7 +3,7 @@ biojava org.biojava - 6.0.0-alpha2 + 6.0.0-SNAPSHOT 4.0.0 biojava-core diff --git a/biojava-genome/pom.xml b/biojava-genome/pom.xml index fbf64183da..c4d667cf50 100644 --- a/biojava-genome/pom.xml +++ b/biojava-genome/pom.xml @@ -3,7 +3,7 @@ biojava org.biojava - 6.0.0-alpha2 + 6.0.0-SNAPSHOT 4.0.0 biojava-genome @@ -85,13 +85,13 @@ org.biojava biojava-core - 6.0.0-alpha2 + 6.0.0-SNAPSHOT compile org.biojava biojava-alignment - 6.0.0-alpha2 + 6.0.0-SNAPSHOT compile diff --git a/biojava-integrationtest/pom.xml b/biojava-integrationtest/pom.xml index 9630da7a40..0bd381f989 100644 --- a/biojava-integrationtest/pom.xml +++ b/biojava-integrationtest/pom.xml @@ -4,7 +4,7 @@ biojava org.biojava - 6.0.0-alpha2 + 6.0.0-SNAPSHOT biojava-integrationtest jar @@ -28,7 +28,7 @@ org.biojava biojava-structure - 6.0.0-alpha2 + 6.0.0-SNAPSHOT diff --git a/biojava-modfinder/pom.xml b/biojava-modfinder/pom.xml index a80d79fa8c..4df1148dee 100644 --- a/biojava-modfinder/pom.xml +++ b/biojava-modfinder/pom.xml @@ -4,7 +4,7 @@ biojava org.biojava - 6.0.0-alpha2 + 6.0.0-SNAPSHOT biojava-modfinder biojava-modfinder @@ -31,7 +31,7 @@ org.biojava biojava-structure - 6.0.0-alpha2 + 6.0.0-SNAPSHOT jar compile diff --git a/biojava-ontology/pom.xml b/biojava-ontology/pom.xml index ff59bfea06..03787e7d7a 100644 --- a/biojava-ontology/pom.xml +++ b/biojava-ontology/pom.xml @@ -4,7 +4,7 @@ org.biojava biojava - 6.0.0-alpha2 + 6.0.0-SNAPSHOT biojava-ontology diff --git a/biojava-protein-disorder/pom.xml b/biojava-protein-disorder/pom.xml index ac7c1cb0a4..9153de3e05 100644 --- a/biojava-protein-disorder/pom.xml +++ b/biojava-protein-disorder/pom.xml @@ -3,7 +3,7 @@ biojava org.biojava - 6.0.0-alpha2 + 6.0.0-SNAPSHOT biojava-protein-disorder jar @@ -63,7 +63,7 @@ org.biojava biojava-core - 6.0.0-alpha2 + 6.0.0-SNAPSHOT diff --git a/biojava-structure-gui/pom.xml b/biojava-structure-gui/pom.xml index 5f78ed2113..154f7c229d 100644 --- a/biojava-structure-gui/pom.xml +++ b/biojava-structure-gui/pom.xml @@ -3,7 +3,7 @@ biojava org.biojava - 6.0.0-alpha2 + 6.0.0-SNAPSHOT 4.0.0 biojava-structure-gui @@ -27,13 +27,13 @@ org.biojava biojava-structure - 6.0.0-alpha2 + 6.0.0-SNAPSHOT compile org.biojava biojava-core - 6.0.0-alpha2 + 6.0.0-SNAPSHOT compile diff --git a/biojava-structure/pom.xml b/biojava-structure/pom.xml index 1642df61e4..87b34d4dcb 100644 --- a/biojava-structure/pom.xml +++ b/biojava-structure/pom.xml @@ -4,7 +4,7 @@ biojava org.biojava - 6.0.0-alpha2 + 6.0.0-SNAPSHOT biojava-structure biojava-structure @@ -44,13 +44,13 @@ org.biojava biojava-alignment - 6.0.0-alpha2 + 6.0.0-SNAPSHOT compile org.biojava biojava-core - 6.0.0-alpha2 + 6.0.0-SNAPSHOT compile diff --git a/biojava-survival/pom.xml b/biojava-survival/pom.xml index 082f35dc01..8774d85478 100644 --- a/biojava-survival/pom.xml +++ b/biojava-survival/pom.xml @@ -4,7 +4,7 @@ org.biojava biojava - 6.0.0-alpha2 + 6.0.0-SNAPSHOT biojava-survival diff --git a/biojava-ws/pom.xml b/biojava-ws/pom.xml index 05ea584fc4..65b13c6730 100644 --- a/biojava-ws/pom.xml +++ b/biojava-ws/pom.xml @@ -3,7 +3,7 @@ biojava org.biojava - 6.0.0-alpha2 + 6.0.0-SNAPSHOT biojava-ws biojava-ws @@ -19,7 +19,7 @@ org.biojava biojava-core - 6.0.0-alpha2 + 6.0.0-SNAPSHOT compile diff --git a/pom.xml b/pom.xml index c8c3d67ebe..6d307acc49 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ org.biojava biojava pom - 6.0.0-alpha2 + 6.0.0-SNAPSHOT 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 @@ -51,7 +51,7 @@ scm:git:git@github.com:biojava/biojava.git https://github.com/biojava/biojava - biojava-6.0.0-alpha2 + HEAD diff --git a/biojava-alignment/pom.xml b/biojava-alignment/pom.xml index a22b560d19..108cdee778 100644 --- a/biojava-alignment/pom.xml +++ b/biojava-alignment/pom.xml @@ -4,7 +4,7 @@ biojava org.biojava - 6.0.0-SNAPSHOT + 6.0.0-alpha3 biojava-alignment biojava-alignment @@ -47,7 +47,7 @@ org.biojava biojava-core - 6.0.0-SNAPSHOT + 6.0.0-alpha3 compile diff --git a/biojava-core/pom.xml b/biojava-core/pom.xml index 6cc9c6c9af..7b38b5bddd 100644 --- a/biojava-core/pom.xml +++ b/biojava-core/pom.xml @@ -3,7 +3,7 @@ biojava org.biojava - 6.0.0-SNAPSHOT + 6.0.0-alpha3 4.0.0 biojava-core diff --git a/biojava-genome/pom.xml b/biojava-genome/pom.xml index c4d667cf50..f23c858b42 100644 --- a/biojava-genome/pom.xml +++ b/biojava-genome/pom.xml @@ -3,7 +3,7 @@ biojava org.biojava - 6.0.0-SNAPSHOT + 6.0.0-alpha3 4.0.0 biojava-genome @@ -85,13 +85,13 @@ org.biojava biojava-core - 6.0.0-SNAPSHOT + 6.0.0-alpha3 compile org.biojava biojava-alignment - 6.0.0-SNAPSHOT + 6.0.0-alpha3 compile diff --git a/biojava-integrationtest/pom.xml b/biojava-integrationtest/pom.xml index 0bd381f989..404c462ad6 100644 --- a/biojava-integrationtest/pom.xml +++ b/biojava-integrationtest/pom.xml @@ -4,7 +4,7 @@ biojava org.biojava - 6.0.0-SNAPSHOT + 6.0.0-alpha3 biojava-integrationtest jar @@ -28,7 +28,7 @@ org.biojava biojava-structure - 6.0.0-SNAPSHOT + 6.0.0-alpha3 diff --git a/biojava-modfinder/pom.xml b/biojava-modfinder/pom.xml index 4df1148dee..67f3440a0a 100644 --- a/biojava-modfinder/pom.xml +++ b/biojava-modfinder/pom.xml @@ -4,7 +4,7 @@ biojava org.biojava - 6.0.0-SNAPSHOT + 6.0.0-alpha3 biojava-modfinder biojava-modfinder @@ -31,7 +31,7 @@ org.biojava biojava-structure - 6.0.0-SNAPSHOT + 6.0.0-alpha3 jar compile diff --git a/biojava-ontology/pom.xml b/biojava-ontology/pom.xml index 03787e7d7a..414e38f0b0 100644 --- a/biojava-ontology/pom.xml +++ b/biojava-ontology/pom.xml @@ -4,7 +4,7 @@ org.biojava biojava - 6.0.0-SNAPSHOT + 6.0.0-alpha3 biojava-ontology diff --git a/biojava-protein-disorder/pom.xml b/biojava-protein-disorder/pom.xml index 9153de3e05..06d6ff0013 100644 --- a/biojava-protein-disorder/pom.xml +++ b/biojava-protein-disorder/pom.xml @@ -3,7 +3,7 @@ biojava org.biojava - 6.0.0-SNAPSHOT + 6.0.0-alpha3 biojava-protein-disorder jar @@ -63,7 +63,7 @@ org.biojava biojava-core - 6.0.0-SNAPSHOT + 6.0.0-alpha3 diff --git a/biojava-structure-gui/pom.xml b/biojava-structure-gui/pom.xml index 154f7c229d..f09fb9ae90 100644 --- a/biojava-structure-gui/pom.xml +++ b/biojava-structure-gui/pom.xml @@ -3,7 +3,7 @@ biojava org.biojava - 6.0.0-SNAPSHOT + 6.0.0-alpha3 4.0.0 biojava-structure-gui @@ -27,13 +27,13 @@ org.biojava biojava-structure - 6.0.0-SNAPSHOT + 6.0.0-alpha3 compile org.biojava biojava-core - 6.0.0-SNAPSHOT + 6.0.0-alpha3 compile diff --git a/biojava-structure/pom.xml b/biojava-structure/pom.xml index 87b34d4dcb..2307cd5f17 100644 --- a/biojava-structure/pom.xml +++ b/biojava-structure/pom.xml @@ -4,7 +4,7 @@ biojava org.biojava - 6.0.0-SNAPSHOT + 6.0.0-alpha3 biojava-structure biojava-structure @@ -44,13 +44,13 @@ org.biojava biojava-alignment - 6.0.0-SNAPSHOT + 6.0.0-alpha3 compile org.biojava biojava-core - 6.0.0-SNAPSHOT + 6.0.0-alpha3 compile diff --git a/biojava-survival/pom.xml b/biojava-survival/pom.xml index 8774d85478..d13042e8dc 100644 --- a/biojava-survival/pom.xml +++ b/biojava-survival/pom.xml @@ -4,7 +4,7 @@ org.biojava biojava - 6.0.0-SNAPSHOT + 6.0.0-alpha3 biojava-survival diff --git a/biojava-ws/pom.xml b/biojava-ws/pom.xml index 65b13c6730..e848c5e84f 100644 --- a/biojava-ws/pom.xml +++ b/biojava-ws/pom.xml @@ -3,7 +3,7 @@ biojava org.biojava - 6.0.0-SNAPSHOT + 6.0.0-alpha3 biojava-ws biojava-ws @@ -19,7 +19,7 @@ org.biojava biojava-core - 6.0.0-SNAPSHOT + 6.0.0-alpha3 compile diff --git a/pom.xml b/pom.xml index 6d307acc49..c6b236e951 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ org.biojava biojava pom - 6.0.0-SNAPSHOT + 6.0.0-alpha3 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 @@ -51,7 +51,7 @@ scm:git:git@github.com:biojava/biojava.git https://github.com/biojava/biojava - HEAD + biojava-6.0.0-alpha3 diff --git a/biojava-alignment/pom.xml b/biojava-alignment/pom.xml index 108cdee778..a22b560d19 100644 --- a/biojava-alignment/pom.xml +++ b/biojava-alignment/pom.xml @@ -4,7 +4,7 @@ biojava org.biojava - 6.0.0-alpha3 + 6.0.0-SNAPSHOT biojava-alignment biojava-alignment @@ -47,7 +47,7 @@ org.biojava biojava-core - 6.0.0-alpha3 + 6.0.0-SNAPSHOT compile diff --git a/biojava-core/pom.xml b/biojava-core/pom.xml index 7b38b5bddd..6cc9c6c9af 100644 --- a/biojava-core/pom.xml +++ b/biojava-core/pom.xml @@ -3,7 +3,7 @@ biojava org.biojava - 6.0.0-alpha3 + 6.0.0-SNAPSHOT 4.0.0 biojava-core diff --git a/biojava-genome/pom.xml b/biojava-genome/pom.xml index f23c858b42..c4d667cf50 100644 --- a/biojava-genome/pom.xml +++ b/biojava-genome/pom.xml @@ -3,7 +3,7 @@ biojava org.biojava - 6.0.0-alpha3 + 6.0.0-SNAPSHOT 4.0.0 biojava-genome @@ -85,13 +85,13 @@ org.biojava biojava-core - 6.0.0-alpha3 + 6.0.0-SNAPSHOT compile org.biojava biojava-alignment - 6.0.0-alpha3 + 6.0.0-SNAPSHOT compile diff --git a/biojava-integrationtest/pom.xml b/biojava-integrationtest/pom.xml index 404c462ad6..0bd381f989 100644 --- a/biojava-integrationtest/pom.xml +++ b/biojava-integrationtest/pom.xml @@ -4,7 +4,7 @@ biojava org.biojava - 6.0.0-alpha3 + 6.0.0-SNAPSHOT biojava-integrationtest jar @@ -28,7 +28,7 @@ org.biojava biojava-structure - 6.0.0-alpha3 + 6.0.0-SNAPSHOT diff --git a/biojava-modfinder/pom.xml b/biojava-modfinder/pom.xml index 67f3440a0a..4df1148dee 100644 --- a/biojava-modfinder/pom.xml +++ b/biojava-modfinder/pom.xml @@ -4,7 +4,7 @@ biojava org.biojava - 6.0.0-alpha3 + 6.0.0-SNAPSHOT biojava-modfinder biojava-modfinder @@ -31,7 +31,7 @@ org.biojava biojava-structure - 6.0.0-alpha3 + 6.0.0-SNAPSHOT jar compile diff --git a/biojava-ontology/pom.xml b/biojava-ontology/pom.xml index 414e38f0b0..03787e7d7a 100644 --- a/biojava-ontology/pom.xml +++ b/biojava-ontology/pom.xml @@ -4,7 +4,7 @@ org.biojava biojava - 6.0.0-alpha3 + 6.0.0-SNAPSHOT biojava-ontology diff --git a/biojava-protein-disorder/pom.xml b/biojava-protein-disorder/pom.xml index 06d6ff0013..9153de3e05 100644 --- a/biojava-protein-disorder/pom.xml +++ b/biojava-protein-disorder/pom.xml @@ -3,7 +3,7 @@ biojava org.biojava - 6.0.0-alpha3 + 6.0.0-SNAPSHOT biojava-protein-disorder jar @@ -63,7 +63,7 @@ org.biojava biojava-core - 6.0.0-alpha3 + 6.0.0-SNAPSHOT diff --git a/biojava-structure-gui/pom.xml b/biojava-structure-gui/pom.xml index f09fb9ae90..154f7c229d 100644 --- a/biojava-structure-gui/pom.xml +++ b/biojava-structure-gui/pom.xml @@ -3,7 +3,7 @@ biojava org.biojava - 6.0.0-alpha3 + 6.0.0-SNAPSHOT 4.0.0 biojava-structure-gui @@ -27,13 +27,13 @@ org.biojava biojava-structure - 6.0.0-alpha3 + 6.0.0-SNAPSHOT compile org.biojava biojava-core - 6.0.0-alpha3 + 6.0.0-SNAPSHOT compile diff --git a/biojava-structure/pom.xml b/biojava-structure/pom.xml index 2307cd5f17..87b34d4dcb 100644 --- a/biojava-structure/pom.xml +++ b/biojava-structure/pom.xml @@ -4,7 +4,7 @@ biojava org.biojava - 6.0.0-alpha3 + 6.0.0-SNAPSHOT biojava-structure biojava-structure @@ -44,13 +44,13 @@ org.biojava biojava-alignment - 6.0.0-alpha3 + 6.0.0-SNAPSHOT compile org.biojava biojava-core - 6.0.0-alpha3 + 6.0.0-SNAPSHOT compile diff --git a/biojava-survival/pom.xml b/biojava-survival/pom.xml index d13042e8dc..8774d85478 100644 --- a/biojava-survival/pom.xml +++ b/biojava-survival/pom.xml @@ -4,7 +4,7 @@ org.biojava biojava - 6.0.0-alpha3 + 6.0.0-SNAPSHOT biojava-survival diff --git a/biojava-ws/pom.xml b/biojava-ws/pom.xml index e848c5e84f..65b13c6730 100644 --- a/biojava-ws/pom.xml +++ b/biojava-ws/pom.xml @@ -3,7 +3,7 @@ biojava org.biojava - 6.0.0-alpha3 + 6.0.0-SNAPSHOT biojava-ws biojava-ws @@ -19,7 +19,7 @@ org.biojava biojava-core - 6.0.0-alpha3 + 6.0.0-SNAPSHOT compile diff --git a/pom.xml b/pom.xml index c6b236e951..6d307acc49 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ org.biojava biojava pom - 6.0.0-alpha3 + 6.0.0-SNAPSHOT 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 @@ -51,7 +51,7 @@ scm:git:git@github.com:biojava/biojava.git https://github.com/biojava/biojava - biojava-6.0.0-alpha3 + HEAD diff --git a/biojava-alignment/pom.xml b/biojava-alignment/pom.xml index a22b560d19..e23155c7ba 100644 --- a/biojava-alignment/pom.xml +++ b/biojava-alignment/pom.xml @@ -4,7 +4,7 @@ biojava org.biojava - 6.0.0-SNAPSHOT + 6.0.0-alpha4 biojava-alignment biojava-alignment @@ -47,7 +47,7 @@ org.biojava biojava-core - 6.0.0-SNAPSHOT + 6.0.0-alpha4 compile diff --git a/biojava-core/pom.xml b/biojava-core/pom.xml index 6cc9c6c9af..0413c71f63 100644 --- a/biojava-core/pom.xml +++ b/biojava-core/pom.xml @@ -3,7 +3,7 @@ biojava org.biojava - 6.0.0-SNAPSHOT + 6.0.0-alpha4 4.0.0 biojava-core diff --git a/biojava-genome/pom.xml b/biojava-genome/pom.xml index 2fb8e78426..311bb549c7 100644 --- a/biojava-genome/pom.xml +++ b/biojava-genome/pom.xml @@ -3,7 +3,7 @@ biojava org.biojava - 6.0.0-SNAPSHOT + 6.0.0-alpha4 4.0.0 biojava-genome @@ -85,13 +85,13 @@ org.biojava biojava-core - 6.0.0-SNAPSHOT + 6.0.0-alpha4 compile org.biojava biojava-alignment - 6.0.0-SNAPSHOT + 6.0.0-alpha4 compile diff --git a/biojava-integrationtest/pom.xml b/biojava-integrationtest/pom.xml index 0bd381f989..0070072c52 100644 --- a/biojava-integrationtest/pom.xml +++ b/biojava-integrationtest/pom.xml @@ -4,7 +4,7 @@ biojava org.biojava - 6.0.0-SNAPSHOT + 6.0.0-alpha4 biojava-integrationtest jar @@ -28,7 +28,7 @@ org.biojava biojava-structure - 6.0.0-SNAPSHOT + 6.0.0-alpha4 diff --git a/biojava-modfinder/pom.xml b/biojava-modfinder/pom.xml index 4df1148dee..11d57a9fce 100644 --- a/biojava-modfinder/pom.xml +++ b/biojava-modfinder/pom.xml @@ -4,7 +4,7 @@ biojava org.biojava - 6.0.0-SNAPSHOT + 6.0.0-alpha4 biojava-modfinder biojava-modfinder @@ -31,7 +31,7 @@ org.biojava biojava-structure - 6.0.0-SNAPSHOT + 6.0.0-alpha4 jar compile diff --git a/biojava-ontology/pom.xml b/biojava-ontology/pom.xml index 03787e7d7a..4542ede6e2 100644 --- a/biojava-ontology/pom.xml +++ b/biojava-ontology/pom.xml @@ -4,7 +4,7 @@ org.biojava biojava - 6.0.0-SNAPSHOT + 6.0.0-alpha4 biojava-ontology diff --git a/biojava-protein-disorder/pom.xml b/biojava-protein-disorder/pom.xml index 9153de3e05..dfe2fbd64e 100644 --- a/biojava-protein-disorder/pom.xml +++ b/biojava-protein-disorder/pom.xml @@ -3,7 +3,7 @@ biojava org.biojava - 6.0.0-SNAPSHOT + 6.0.0-alpha4 biojava-protein-disorder jar @@ -63,7 +63,7 @@ org.biojava biojava-core - 6.0.0-SNAPSHOT + 6.0.0-alpha4 diff --git a/biojava-structure-gui/pom.xml b/biojava-structure-gui/pom.xml index 154f7c229d..51efcc3262 100644 --- a/biojava-structure-gui/pom.xml +++ b/biojava-structure-gui/pom.xml @@ -3,7 +3,7 @@ biojava org.biojava - 6.0.0-SNAPSHOT + 6.0.0-alpha4 4.0.0 biojava-structure-gui @@ -27,13 +27,13 @@ org.biojava biojava-structure - 6.0.0-SNAPSHOT + 6.0.0-alpha4 compile org.biojava biojava-core - 6.0.0-SNAPSHOT + 6.0.0-alpha4 compile diff --git a/biojava-structure/pom.xml b/biojava-structure/pom.xml index 87b34d4dcb..fa75d6e5fa 100644 --- a/biojava-structure/pom.xml +++ b/biojava-structure/pom.xml @@ -4,7 +4,7 @@ biojava org.biojava - 6.0.0-SNAPSHOT + 6.0.0-alpha4 biojava-structure biojava-structure @@ -44,13 +44,13 @@ org.biojava biojava-alignment - 6.0.0-SNAPSHOT + 6.0.0-alpha4 compile org.biojava biojava-core - 6.0.0-SNAPSHOT + 6.0.0-alpha4 compile diff --git a/biojava-survival/pom.xml b/biojava-survival/pom.xml index 8774d85478..6f1e37a73e 100644 --- a/biojava-survival/pom.xml +++ b/biojava-survival/pom.xml @@ -4,7 +4,7 @@ org.biojava biojava - 6.0.0-SNAPSHOT + 6.0.0-alpha4 biojava-survival diff --git a/biojava-ws/pom.xml b/biojava-ws/pom.xml index 65b13c6730..1b3941438f 100644 --- a/biojava-ws/pom.xml +++ b/biojava-ws/pom.xml @@ -3,7 +3,7 @@ biojava org.biojava - 6.0.0-SNAPSHOT + 6.0.0-alpha4 biojava-ws biojava-ws @@ -19,7 +19,7 @@ org.biojava biojava-core - 6.0.0-SNAPSHOT + 6.0.0-alpha4 compile diff --git a/pom.xml b/pom.xml index 6d307acc49..90a22f63b7 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ org.biojava biojava pom - 6.0.0-SNAPSHOT + 6.0.0-alpha4 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 @@ -51,7 +51,7 @@ scm:git:git@github.com:biojava/biojava.git https://github.com/biojava/biojava - HEAD + biojava-6.0.0-alpha4 diff --git a/biojava-alignment/pom.xml b/biojava-alignment/pom.xml index e23155c7ba..a22b560d19 100644 --- a/biojava-alignment/pom.xml +++ b/biojava-alignment/pom.xml @@ -4,7 +4,7 @@ biojava org.biojava - 6.0.0-alpha4 + 6.0.0-SNAPSHOT biojava-alignment biojava-alignment @@ -47,7 +47,7 @@ org.biojava biojava-core - 6.0.0-alpha4 + 6.0.0-SNAPSHOT compile diff --git a/biojava-core/pom.xml b/biojava-core/pom.xml index 0413c71f63..6cc9c6c9af 100644 --- a/biojava-core/pom.xml +++ b/biojava-core/pom.xml @@ -3,7 +3,7 @@ biojava org.biojava - 6.0.0-alpha4 + 6.0.0-SNAPSHOT 4.0.0 biojava-core diff --git a/biojava-genome/pom.xml b/biojava-genome/pom.xml index 311bb549c7..2fb8e78426 100644 --- a/biojava-genome/pom.xml +++ b/biojava-genome/pom.xml @@ -3,7 +3,7 @@ biojava org.biojava - 6.0.0-alpha4 + 6.0.0-SNAPSHOT 4.0.0 biojava-genome @@ -85,13 +85,13 @@ org.biojava biojava-core - 6.0.0-alpha4 + 6.0.0-SNAPSHOT compile org.biojava biojava-alignment - 6.0.0-alpha4 + 6.0.0-SNAPSHOT compile diff --git a/biojava-integrationtest/pom.xml b/biojava-integrationtest/pom.xml index 0070072c52..0bd381f989 100644 --- a/biojava-integrationtest/pom.xml +++ b/biojava-integrationtest/pom.xml @@ -4,7 +4,7 @@ biojava org.biojava - 6.0.0-alpha4 + 6.0.0-SNAPSHOT biojava-integrationtest jar @@ -28,7 +28,7 @@ org.biojava biojava-structure - 6.0.0-alpha4 + 6.0.0-SNAPSHOT diff --git a/biojava-modfinder/pom.xml b/biojava-modfinder/pom.xml index 11d57a9fce..4df1148dee 100644 --- a/biojava-modfinder/pom.xml +++ b/biojava-modfinder/pom.xml @@ -4,7 +4,7 @@ biojava org.biojava - 6.0.0-alpha4 + 6.0.0-SNAPSHOT biojava-modfinder biojava-modfinder @@ -31,7 +31,7 @@ org.biojava biojava-structure - 6.0.0-alpha4 + 6.0.0-SNAPSHOT jar compile diff --git a/biojava-ontology/pom.xml b/biojava-ontology/pom.xml index 4542ede6e2..03787e7d7a 100644 --- a/biojava-ontology/pom.xml +++ b/biojava-ontology/pom.xml @@ -4,7 +4,7 @@ org.biojava biojava - 6.0.0-alpha4 + 6.0.0-SNAPSHOT biojava-ontology diff --git a/biojava-protein-disorder/pom.xml b/biojava-protein-disorder/pom.xml index dfe2fbd64e..9153de3e05 100644 --- a/biojava-protein-disorder/pom.xml +++ b/biojava-protein-disorder/pom.xml @@ -3,7 +3,7 @@ biojava org.biojava - 6.0.0-alpha4 + 6.0.0-SNAPSHOT biojava-protein-disorder jar @@ -63,7 +63,7 @@ org.biojava biojava-core - 6.0.0-alpha4 + 6.0.0-SNAPSHOT diff --git a/biojava-structure-gui/pom.xml b/biojava-structure-gui/pom.xml index 51efcc3262..154f7c229d 100644 --- a/biojava-structure-gui/pom.xml +++ b/biojava-structure-gui/pom.xml @@ -3,7 +3,7 @@ biojava org.biojava - 6.0.0-alpha4 + 6.0.0-SNAPSHOT 4.0.0 biojava-structure-gui @@ -27,13 +27,13 @@ org.biojava biojava-structure - 6.0.0-alpha4 + 6.0.0-SNAPSHOT compile org.biojava biojava-core - 6.0.0-alpha4 + 6.0.0-SNAPSHOT compile diff --git a/biojava-structure/pom.xml b/biojava-structure/pom.xml index fa75d6e5fa..87b34d4dcb 100644 --- a/biojava-structure/pom.xml +++ b/biojava-structure/pom.xml @@ -4,7 +4,7 @@ biojava org.biojava - 6.0.0-alpha4 + 6.0.0-SNAPSHOT biojava-structure biojava-structure @@ -44,13 +44,13 @@ org.biojava biojava-alignment - 6.0.0-alpha4 + 6.0.0-SNAPSHOT compile org.biojava biojava-core - 6.0.0-alpha4 + 6.0.0-SNAPSHOT compile diff --git a/biojava-survival/pom.xml b/biojava-survival/pom.xml index 6f1e37a73e..8774d85478 100644 --- a/biojava-survival/pom.xml +++ b/biojava-survival/pom.xml @@ -4,7 +4,7 @@ org.biojava biojava - 6.0.0-alpha4 + 6.0.0-SNAPSHOT biojava-survival diff --git a/biojava-ws/pom.xml b/biojava-ws/pom.xml index 1b3941438f..65b13c6730 100644 --- a/biojava-ws/pom.xml +++ b/biojava-ws/pom.xml @@ -3,7 +3,7 @@ biojava org.biojava - 6.0.0-alpha4 + 6.0.0-SNAPSHOT biojava-ws biojava-ws @@ -19,7 +19,7 @@ org.biojava biojava-core - 6.0.0-alpha4 + 6.0.0-SNAPSHOT compile diff --git a/pom.xml b/pom.xml index 90a22f63b7..6d307acc49 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ org.biojava biojava pom - 6.0.0-alpha4 + 6.0.0-SNAPSHOT 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 @@ -51,7 +51,7 @@ scm:git:git@github.com:biojava/biojava.git https://github.com/biojava/biojava - biojava-6.0.0-alpha4 + HEAD UTF-8 512M - 1.0.9 + 1.0.10 1.7.30 2.14.0 ciftools-java-jdk8 From eac22bc94bf684d92363dd0bff5ea705845af733 Mon Sep 17 00:00:00 2001 From: Richard Adams Date: Fri, 2 Jul 2021 17:05:20 +0100 Subject: [PATCH 103/599] test getTrace() to improve test coverage --- .../nbio/core/sequence/io/ABITracerTest.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/biojava-core/src/test/java/org/biojava/nbio/core/sequence/io/ABITracerTest.java b/biojava-core/src/test/java/org/biojava/nbio/core/sequence/io/ABITracerTest.java index 89aef23cbb..df77b7c00a 100644 --- a/biojava-core/src/test/java/org/biojava/nbio/core/sequence/io/ABITracerTest.java +++ b/biojava-core/src/test/java/org/biojava/nbio/core/sequence/io/ABITracerTest.java @@ -21,9 +21,14 @@ package org.biojava.nbio.core.sequence.io; +import static org.junit.Assert.assertEquals; + import java.awt.image.BufferedImage; import java.io.File; import java.net.URL; +import java.util.Arrays; + +import org.biojava.nbio.core.exceptions.CompoundNotFoundException; import org.junit.*; /** @@ -79,7 +84,8 @@ public void testLocal() throws Exception { Assert.assertNotNull(tracer); //Test length of tracer for file 3730.ab1 - Assert.assertEquals(16302, tracer.getTraceLength()); + final int EXPECTED_TRACE_LENGTH = 16302; + Assert.assertEquals(EXPECTED_TRACE_LENGTH, tracer.getTraceLength()); //Test length of sequence for file 3730.ab1 Assert.assertEquals(1165, tracer.getSequenceLength()); @@ -92,5 +98,10 @@ public void testLocal() throws Exception { //Test image of tracer for file 3730.ab1 BufferedImage image = tracer.getImage(100,100); Assert.assertNotNull(image); + + Assert.assertThrows(CompoundNotFoundException.class, ()->tracer.getTrace("D")); + for (String base: Arrays.asList(new String []{"A","T","C","G"})){ + assertEquals(EXPECTED_TRACE_LENGTH, tracer.getTrace(base).length); + } } } From d8d5a7b4519eef2807948733912c08fc159526ad Mon Sep 17 00:00:00 2001 From: Richard Adams Date: Fri, 2 Jul 2021 17:09:26 +0100 Subject: [PATCH 104/599] organise imports --- .../nbio/core/sequence/io/ABITracerTest.java | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/biojava-core/src/test/java/org/biojava/nbio/core/sequence/io/ABITracerTest.java b/biojava-core/src/test/java/org/biojava/nbio/core/sequence/io/ABITracerTest.java index df77b7c00a..6d42ba48fc 100644 --- a/biojava-core/src/test/java/org/biojava/nbio/core/sequence/io/ABITracerTest.java +++ b/biojava-core/src/test/java/org/biojava/nbio/core/sequence/io/ABITracerTest.java @@ -21,7 +21,10 @@ package org.biojava.nbio.core.sequence.io; +import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import java.awt.image.BufferedImage; import java.io.File; @@ -66,9 +69,9 @@ public void tearDown() { @Test public void testURL() throws Exception { URL resource = this.getClass().getResource("/3730.ab1"); - Assert.assertNotNull(resource); + assertNotNull(resource); ABITrace tracer = new ABITrace(resource); - Assert.assertNotNull(tracer); + assertNotNull(tracer); } /** @@ -77,27 +80,27 @@ public void testURL() throws Exception { @Test public void testLocal() throws Exception { URL resource = this.getClass().getResource("/3730.ab1"); - Assert.assertNotNull(resource); + assertNotNull(resource); File file = new File(resource.toURI()); - Assert.assertNotNull(file); + assertNotNull(file); ABITrace tracer = new ABITrace(file); - Assert.assertNotNull(tracer); + assertNotNull(tracer); //Test length of tracer for file 3730.ab1 final int EXPECTED_TRACE_LENGTH = 16302; - Assert.assertEquals(EXPECTED_TRACE_LENGTH, tracer.getTraceLength()); + assertEquals(EXPECTED_TRACE_LENGTH, tracer.getTraceLength()); //Test length of sequence for file 3730.ab1 - Assert.assertEquals(1165, tracer.getSequenceLength()); + assertEquals(1165, tracer.getSequenceLength()); //Test sequence of tracer for file 3730.ab1 - Assert.assertTrue(sequence.equals(tracer.getSequence().getSequenceAsString())); + assertTrue(sequence.equals(tracer.getSequence().getSequenceAsString())); //Test array that represents the quality of tracer for file 3730.ab1 - Assert.assertArrayEquals(qual, tracer.getQcalls()); + assertArrayEquals(qual, tracer.getQcalls()); //Test array that represents the baseline of tracer for file 3730.ab1 - Assert.assertArrayEquals(base, tracer.getBasecalls()); + assertArrayEquals(base, tracer.getBasecalls()); //Test image of tracer for file 3730.ab1 BufferedImage image = tracer.getImage(100,100); - Assert.assertNotNull(image); + assertNotNull(image); Assert.assertThrows(CompoundNotFoundException.class, ()->tracer.getTrace("D")); for (String base: Arrays.asList(new String []{"A","T","C","G"})){ From 281e915d59aa359fdc3cad36d49b2fe094d945b7 Mon Sep 17 00:00:00 2001 From: Richard Adams Date: Sun, 4 Jul 2021 00:19:25 +0100 Subject: [PATCH 105/599] initial addition of junit 5 --- biojava-core/pom.xml | 12 ++++++ .../nbio/core/TestAmbiguityCompoundSet.java | 14 ++++--- pom.xml | 42 ++++++++++++++++--- 3 files changed, 58 insertions(+), 10 deletions(-) diff --git a/biojava-core/pom.xml b/biojava-core/pom.xml index 6cc9c6c9af..4637ab6534 100644 --- a/biojava-core/pom.xml +++ b/biojava-core/pom.xml @@ -44,6 +44,18 @@ junit test + + org.junit.jupiter + junit-jupiter-api + + + org.junit.jupiter + junit-jupiter-engine + + + org.junit.vintage + junit-vintage-engine + org.slf4j diff --git a/biojava-core/src/test/java/org/biojava/nbio/core/TestAmbiguityCompoundSet.java b/biojava-core/src/test/java/org/biojava/nbio/core/TestAmbiguityCompoundSet.java index 56abb5d802..6951fbc4d4 100644 --- a/biojava-core/src/test/java/org/biojava/nbio/core/TestAmbiguityCompoundSet.java +++ b/biojava-core/src/test/java/org/biojava/nbio/core/TestAmbiguityCompoundSet.java @@ -30,8 +30,10 @@ import org.biojava.nbio.core.sequence.template.CompoundSet; import org.biojava.nbio.core.sequence.template.Sequence; import org.biojava.nbio.core.sequence.transcription.DNAToRNATranslator; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.DisplayName; + +import static org.junit.jupiter.api.Assertions.assertEquals; /** * A Test case for https://github.com/biojava/biojava/issues/344 @@ -39,9 +41,11 @@ * Created by andreas on 12/4/15. */ + public class TestAmbiguityCompoundSet { @Test + @DisplayName("Convert DNA to RNA") public void testCompountSet() throws Exception { CompoundSet dnaSet = AmbiguityDNACompoundSet.getDNACompoundSet(); @@ -49,13 +53,13 @@ public void testCompountSet() throws Exception { DNASequence dna = new DNASequence("AGTCS", dnaSet); - Assert.assertEquals("AGTCS", dna.toString()); + assertEquals("AGTCS", dna.toString()); RNASequence rna = dna.getRNASequence(); rna = new RNASequence(dna.getSequenceAsString().replaceAll("T", "U"), AmbiguityRNACompoundSet.getRNACompoundSet()); //fails with missing compound S - Assert.assertEquals("AGUCS", rna.toString()); + assertEquals("AGUCS", rna.toString()); /* now, do the translation also using the underlying API (should not be needed for a user) * @@ -65,7 +69,7 @@ public void testCompountSet() throws Exception { Sequence translated = translator.createSequence(dna); - Assert.assertEquals("AGUCS", translated.toString()); + assertEquals("AGUCS", translated.toString()); } diff --git a/pom.xml b/pom.xml index 6e55a71501..d5a7d30e65 100644 --- a/pom.xml +++ b/pom.xml @@ -239,6 +239,24 @@ + + org.apache.maven.plugins + maven-surefire-plugin + 3.0.0-M5 + + + true + true + true + true + + + true + true + true + + + org.apache.maven.plugins maven-shade-plugin @@ -313,11 +331,7 @@ maven-install-plugin 3.0.0-M1 - - org.apache.maven.plugins - maven-surefire-plugin - 3.0.0-M5 - + org.apache.maven.plugins maven-site-plugin @@ -404,6 +418,24 @@ 4.13.2 test + + org.junit.vintage + junit-vintage-engine + 5.7.2 + test + + + org.junit.jupiter + junit-jupiter-api + 5.7.2 + test + + + org.junit.jupiter + junit-jupiter-engine + 5.7.2 + test + org.slf4j slf4j-api From 30cd5ef614166827ce672fcac32a35ecdbc7f4ba Mon Sep 17 00:00:00 2001 From: Richard Adams Date: Sun, 4 Jul 2021 10:29:24 +0100 Subject: [PATCH 106/599] refactor 2 tests to use junit5 features --- biojava-core/pom.xml | 25 ++++---- .../nbio/core/TestAmbiguityCompoundSet.java | 3 +- .../nbio/core/sequence/io/ABITracerTest.java | 60 ++++++++++--------- pom.xml | 52 +++++++--------- 4 files changed, 64 insertions(+), 76 deletions(-) diff --git a/biojava-core/pom.xml b/biojava-core/pom.xml index 4637ab6534..b61e45194a 100644 --- a/biojava-core/pom.xml +++ b/biojava-core/pom.xml @@ -42,20 +42,19 @@ junit junit - test - - org.junit.jupiter - junit-jupiter-api - - - org.junit.jupiter - junit-jupiter-engine - - org.junit.vintage - junit-vintage-engine - + org.junit.jupiter + junit-jupiter-engine + + + org.junit.jupiter + junit-jupiter-params + + + org.junit.vintage + junit-vintage-engine + org.slf4j @@ -76,5 +75,3 @@ - - diff --git a/biojava-core/src/test/java/org/biojava/nbio/core/TestAmbiguityCompoundSet.java b/biojava-core/src/test/java/org/biojava/nbio/core/TestAmbiguityCompoundSet.java index 6951fbc4d4..9fad78d7b0 100644 --- a/biojava-core/src/test/java/org/biojava/nbio/core/TestAmbiguityCompoundSet.java +++ b/biojava-core/src/test/java/org/biojava/nbio/core/TestAmbiguityCompoundSet.java @@ -45,18 +45,17 @@ public class TestAmbiguityCompoundSet { @Test - @DisplayName("Convert DNA to RNA") public void testCompountSet() throws Exception { CompoundSet dnaSet = AmbiguityDNACompoundSet.getDNACompoundSet(); CompoundSet rnaSet = AmbiguityRNACompoundSet.getRNACompoundSet(); + DNASequence dna = new DNASequence("AGTCS", dnaSet); assertEquals("AGTCS", dna.toString()); RNASequence rna = dna.getRNASequence(); - rna = new RNASequence(dna.getSequenceAsString().replaceAll("T", "U"), AmbiguityRNACompoundSet.getRNACompoundSet()); //fails with missing compound S assertEquals("AGUCS", rna.toString()); diff --git a/biojava-core/src/test/java/org/biojava/nbio/core/sequence/io/ABITracerTest.java b/biojava-core/src/test/java/org/biojava/nbio/core/sequence/io/ABITracerTest.java index 6d42ba48fc..dce9cc7b58 100644 --- a/biojava-core/src/test/java/org/biojava/nbio/core/sequence/io/ABITracerTest.java +++ b/biojava-core/src/test/java/org/biojava/nbio/core/sequence/io/ABITracerTest.java @@ -21,10 +21,11 @@ package org.biojava.nbio.core.sequence.io; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; + +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.*; +import org.junit.jupiter.params.provider.ValueSource; +import org.junit.jupiter.params.ParameterizedTest; import java.awt.image.BufferedImage; import java.io.File; @@ -32,35 +33,31 @@ import java.util.Arrays; import org.biojava.nbio.core.exceptions.CompoundNotFoundException; -import org.junit.*; /** * Test file 3730.ab1 is from https://github.com/biopython/biopython/blob/master/Tests/Abi/3730.ab1 * The test data for comparing the results from ABITrace.java for file 3730.ab1 is from https://github.com/biopython/biopython/blob/master/Tests/Abi/test_data */ public class ABITracerTest { + private String sequence = "GGGCGAGCKYYAYATTTTGGCAAGAATTGAGCTCTATGGCCACAACCATGGTGAGCAAGGGCGAGGAGGATAACATGGCCATCATCAAGGAGTTCATGCGCTTCAAGGTGCACATGGAGGGCTCCGTGAACGGCCACGAGTTCGAGATCGAGGGCGAGGGCGAGGGCCGCCCCTACGAGGGCACCCAGACCGCCAAGCTGAAGGTGACCAAGGGTGGCCCCCTGCCCTTCGCCTGGGACATCCTGTCCCCTCAGTTCATGTACGGCTCCAAGGCCTACGTGAAGCACCCCGCCGACATCCCCGACTACTTGAAGCTGTCCTTCCCCGAGGGCTTCAAGTGGGAGCGCGTGATGAACTTCGAGGACGGCGGCGTGGTGACCGTGACCCAGGACTCCTCCCTGCAGGACGGCGAGTTCATCTACAAGGTGAAGCTGCGCGGCACCAACTTCCCCTCCGACGGCCCCGTAATGCAGAAGAAGACCATGGGCTGGGAGGCCTCCTCCGAGCGGATGTACCCCGAGGACGGCGCCCTGAAGGGCGAGATCAAGCAGAGGCTGAAGCTGAAGGACGGCGGCCACTACGACGCTGAGGTCAAGACCACCTACAAGGCCAAGAAGCCCGTGCAGCTGCCCGGCGCCTACAACGTCAACATCAAGTTGGACATCACCTCCCACAACGAGGACTACACCATCGTGGAACAGTACGAACGCGCCGAGGGCCGCCACTCCACCGGCGGCATGGACGAGCTGTACAAGGGCGGCAGCGGCATGGTGAGCAAGGGCGAGGAGCTGTTCACCGGGGTGGTGCCCATCCTGGTCGAGCTGGACGGCGACGTAAACGGCCACAAGTTCAGCGTGTCCGGCGAGGGCGAGGGCGATGCCACCTACGGCAAGCTGACCCTGAAGTTCATCTGCACCACCGGCAAGCTGCCCGTGCCCTGGCCCACCCTCGTGACCACCCTGACCTACGGCGTGCAGTGCTTCAGCCGCTACCCCGACCACATGAAGCAGCACGACTTCTTCAAGTCCGCCATGCCCGAAGGCTACGTCCAGGAGCGCACCATCTTCTTCAAGGACGACGGCAACTACAARACCCGCGCCGAGGTGAARTTCGAGGGCGACACCCTGGTGAACCGCATCGAGCTGAAAGGGGCAYCGCACCTTTC"; private int[] qual = {20, 3, 4, 4, 4, 6, 4, 4, 0, 0, 0, 6, 0, 10, 20, 26, 22, 17, 21, 31, 29, 32, 28, 18, 23, 17, 19, 35, 36, 50, 39, 50, 50, 50, 50, 50, 25, 35, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 35, 39, 33, 20, 35, 31, 50, 50, 50, 50, 50, 50, 50, 50, 50, 31, 50, 35, 31, 23, 28, 31, 21, 43, 39, 35, 24, 30, 26, 35, 31, 50, 50, 50, 50, 50, 50, 50, 50, 50, 39, 31, 24, 39, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 31, 31, 43, 43, 50, 50, 50, 50, 50, 31, 31, 31, 31, 50, 50, 50, 50, 50, 50, 50, 50, 31, 31, 35, 50, 50, 50, 50, 31, 36, 55, 55, 55, 55, 36, 55, 55, 55, 55, 55, 36, 55, 55, 55, 55, 55, 36, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 40, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 36, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 40, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 43, 43, 50, 43, 43, 50, 43, 43, 50, 43, 43, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 43, 43, 50, 43, 43, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 28, 28, 35, 28, 28, 35, 28, 28, 35, 28, 28, 35, 28, 28, 35, 28, 21, 28, 35, 28, 28, 35, 35, 35, 35, 35, 37, 38, 21, 28, 35, 28, 28, 35, 35, 35, 35, 35, 35, 35, 36, 36, 21, 39, 35, 35, 35, 39, 35, 37, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 28, 28, 35, 35, 28, 28, 35, 35, 35, 36, 36, 22, 39, 35, 35, 35, 35, 35, 35, 37, 38, 28, 35, 21, 36, 36, 37, 35, 35, 20, 39, 39, 35, 35, 35, 35, 37, 38, 28, 35, 37, 34, 35, 24, 24, 27, 25, 20, 24, 37, 35, 27, 21, 20, 21, 27, 17, 20, 24, 32, 26, 20, 12, 20, 10, 20, 24, 25, 23, 20, 32, 24, 24, 23, 20, 24, 23, 18, 34, 34, 34, 22, 26, 24, 24, 18, 22, 22, 23, 25, 20, 12, 20, 24, 23, 24, 23, 22, 20, 20, 0, 20, 24, 23, 20, 8, 10, 4, 20, 20, 3, 7, 19, 20, 4, 4, 7, 7, 0, 7, 11, 18, 8, 3, 23, 23, 20, 11, 4, 20, 18, 12, 20, 20, 20, 4, 20, 4, 2, 3, 21, 21, 21, 21, 10, 15, 14, 15, 19, 2, 4, 3, 6, 11, 3, 4, 6, 21, 16, 20, 11, 1, 4, 12, 0, 15, 8, 1, 3, 3, 12, 1, 11, 20, 4}; private int[] base = {2, 13, 38, 51, 67, 78, 92, 118, 138, 162, 181, 191, 210, 222, 239, 253, 266, 280, 288, 304, 317, 333, 347, 359, 375, 386, 394, 406, 418, 433, 444, 457, 472, 482, 496, 506, 519, 529, 544, 557, 569, 579, 590, 601, 614, 626, 638, 649, 663, 673, 686, 706, 715, 731, 740, 753, 765, 777, 787, 799, 813, 826, 838, 854, 863, 876, 892, 901, 913, 929, 937, 948, 960, 970, 981, 993, 1004, 1017, 1034, 1045, 1056, 1068, 1080, 1091, 1103, 1115, 1126, 1138, 1148, 1160, 1177, 1187, 1199, 1211, 1222, 1232, 1243, 1254, 1268, 1279, 1294, 1307, 1319, 1330, 1341, 1352, 1362, 1374, 1388, 1398, 1411, 1422, 1433, 1444, 1456, 1466, 1479, 1497, 1506, 1519, 1531, 1543, 1556, 1567, 1578, 1589, 1604, 1614, 1630, 1641, 1651, 1662, 1675, 1688, 1700, 1711, 1721, 1732, 1748, 1758, 1772, 1784, 1795, 1806, 1820, 1830, 1844, 1855, 1866, 1877, 1892, 1902, 1914, 1926, 1939, 1950, 1965, 1974, 1986, 1999, 2011, 2023, 2037, 2047, 2059, 2072, 2084, 2096, 2107, 2120, 2132, 2144, 2156, 2169, 2180, 2191, 2202, 2217, 2227, 2239, 2251, 2264, 2275, 2286, 2297, 2309, 2321, 2332, 2347, 2358, 2369, 2381, 2394, 2406, 2417, 2429, 2439, 2452, 2465, 2476, 2490, 2501, 2512, 2524, 2536, 2546, 2560, 2570, 2581, 2593, 2605, 2616, 2628, 2640, 2653, 2664, 2676, 2688, 2700, 2712, 2723, 2735, 2748, 2759, 2772, 2784, 2795, 2808, 2820, 2831, 2842, 2854, 2866, 2878, 2888, 2901, 2913, 2927, 2936, 2947, 2958, 2970, 2982, 2994, 3005, 3019, 3030, 3041, 3053, 3064, 3077, 3088, 3099, 3110, 3123, 3135, 3146, 3157, 3168, 3179, 3192, 3203, 3214, 3226, 3238, 3251, 3263, 3275, 3286, 3297, 3308, 3320, 3331, 3344, 3356, 3368, 3380, 3391, 3402, 3415, 3426, 3440, 3451, 3462, 3474, 3485, 3496, 3508, 3520, 3532, 3543, 3556, 3569, 3580, 3593, 3604, 3615, 3626, 3638, 3650, 3661, 3673, 3684, 3698, 3709, 3721, 3732, 3744, 3756, 3767, 3779, 3792, 3803, 3814, 3827, 3838, 3850, 3862, 3873, 3885, 3897, 3909, 3920, 3932, 3943, 3955, 3966, 3980, 3990, 4002, 4014, 4026, 4038, 4050, 4061, 4072, 4083, 4095, 4107, 4119, 4131, 4143, 4156, 4167, 4179, 4191, 4203, 4215, 4227, 4238, 4252, 4262, 4274, 4287, 4298, 4310, 4321, 4333, 4345, 4356, 4370, 4381, 4393, 4406, 4417, 4428, 4440, 4453, 4464, 4477, 4489, 4500, 4513, 4524, 4536, 4548, 4560, 4573, 4583, 4595, 4607, 4620, 4631, 4645, 4655, 4667, 4679, 4690, 4702, 4714, 4728, 4739, 4750, 4762, 4774, 4786, 4798, 4810, 4821, 4833, 4845, 4857, 4869, 4880, 4892, 4905, 4916, 4927, 4940, 4952, 4963, 4977, 4988, 5000, 5012, 5023, 5034, 5045, 5057, 5069, 5081, 5093, 5104, 5115, 5127, 5139, 5151, 5163, 5176, 5188, 5199, 5211, 5223, 5235, 5247, 5259, 5272, 5283, 5296, 5308, 5320, 5331, 5343, 5354, 5366, 5378, 5390, 5402, 5414, 5426, 5438, 5450, 5462, 5474, 5486, 5497, 5510, 5521, 5532, 5544, 5557, 5569, 5581, 5592, 5604, 5617, 5629, 5641, 5652, 5663, 5676, 5687, 5699, 5712, 5724, 5735, 5748, 5760, 5771, 5784, 5794, 5806, 5817, 5829, 5841, 5853, 5866, 5879, 5891, 5903, 5916, 5928, 5941, 5952, 5964, 5976, 5988, 6000, 6012, 6024, 6036, 6048, 6060, 6072, 6085, 6096, 6109, 6121, 6133, 6146, 6157, 6168, 6180, 6192, 6203, 6215, 6227, 6239, 6251, 6265, 6276, 6289, 6302, 6313, 6325, 6337, 6349, 6361, 6374, 6386, 6398, 6410, 6422, 6436, 6448, 6459, 6471, 6483, 6495, 6507, 6520, 6532, 6545, 6555, 6567, 6579, 6591, 6603, 6615, 6627, 6640, 6652, 6664, 6676, 6688, 6700, 6713, 6726, 6738, 6749, 6761, 6774, 6786, 6799, 6811, 6823, 6835, 6848, 6859, 6871, 6883, 6895, 6907, 6920, 6933, 6945, 6956, 6968, 6980, 6992, 7005, 7016, 7030, 7042, 7053, 7066, 7079, 7091, 7104, 7115, 7128, 7140, 7152, 7163, 7175, 7187, 7200, 7212, 7224, 7235, 7248, 7260, 7272, 7285, 7297, 7309, 7321, 7333, 7345, 7358, 7370, 7382, 7394, 7406, 7419, 7431, 7443, 7455, 7468, 7480, 7492, 7505, 7517, 7530, 7542, 7554, 7566, 7578, 7591, 7603, 7615, 7628, 7640, 7653, 7666, 7677, 7690, 7702, 7714, 7727, 7738, 7750, 7762, 7775, 7786, 7799, 7812, 7823, 7836, 7848, 7859, 7871, 7884, 7896, 7909, 7921, 7933, 7946, 7958, 7971, 7984, 7996, 8007, 8019, 8032, 8044, 8056, 8069, 8081, 8094, 8107, 8119, 8131, 8143, 8155, 8167, 8179, 8192, 8205, 8218, 8230, 8244, 8255, 8267, 8279, 8291, 8303, 8315, 8328, 8340, 8353, 8366, 8378, 8392, 8404, 8417, 8431, 8443, 8455, 8467, 8479, 8492, 8504, 8516, 8529, 8543, 8555, 8567, 8580, 8593, 8606, 8619, 8632, 8644, 8658, 8670, 8683, 8695, 8708, 8721, 8733, 8746, 8759, 8771, 8783, 8795, 8808, 8821, 8833, 8845, 8858, 8871, 8885, 8898, 8910, 8923, 8936, 8949, 8960, 8973, 8986, 9000, 9012, 9025, 9038, 9051, 9064, 9076, 9089, 9102, 9114, 9126, 9139, 9151, 9164, 9177, 9191, 9204, 9217, 9230, 9243, 9255, 9268, 9281, 9294, 9307, 9320, 9333, 9345, 9358, 9371, 9384, 9398, 9412, 9424, 9437, 9450, 9462, 9475, 9488, 9501, 9514, 9528, 9542, 9554, 9567, 9581, 9593, 9606, 9619, 9632, 9645, 9658, 9671, 9682, 9695, 9708, 9721, 9735, 9749, 9762, 9776, 9789, 9802, 9815, 9828, 9842, 9855, 9867, 9880, 9893, 9906, 9920, 9933, 9947, 9960, 9974, 9987, 10000, 10014, 10027, 10040, 10054, 10067, 10081, 10095, 10107, 10120, 10134, 10148, 10161, 10175, 10188, 10201, 10214, 10228, 10241, 10254, 10267, 10280, 10294, 10309, 10322, 10335, 10348, 10362, 10374, 10387, 10401, 10415, 10428, 10441, 10455, 10469, 10482, 10497, 10510, 10523, 10537, 10551, 10565, 10579, 10593, 10606, 10621, 10634, 10647, 10661, 10675, 10689, 10704, 10719, 10732, 10746, 10760, 10774, 10788, 10802, 10815, 10829, 10843, 10856, 10871, 10884, 10898, 10913, 10927, 10940, 10955, 10970, 10984, 10999, 11013, 11027, 11042, 11056, 11071, 11086, 11100, 11114, 11128, 11142, 11158, 11171, 11186, 11200, 11213, 11228, 11241, 11255, 11270, 11284, 11299, 11314, 11328, 11342, 11356, 11370, 11385, 11399, 11413, 11429, 11445, 11460, 11474, 11489, 11503, 11518, 11533, 11549, 11563, 11577, 11592, 11607, 11621, 11637, 11651, 11665, 11680, 11694, 11708, 11725, 11740, 11754, 11768, 11784, 11798, 11813, 11828, 11843, 11858, 11874, 11888, 11904, 11920, 11933, 11948, 11964, 11979, 11993, 12009, 12024, 12041, 12058, 12071, 12087, 12102, 12117, 12132, 12148, 12165, 12179, 12195, 12210, 12226, 12241, 12256, 12273, 12288, 12304, 12320, 12335, 12350, 12365, 12382, 12398, 12414, 12430, 12446, 12462, 12478, 12495, 12511, 12525, 12541, 12556, 12575, 12591, 12605, 12622, 12638, 12653, 12671, 12686, 12705, 12721, 12739, 12756, 12772, 12788, 12806, 12822, 12839, 12855, 12873, 12890, 12908, 12923, 12941, 12960, 12975, 12992, 13009, 13024, 13040, 13059, 13076, 13092, 13109, 13128, 13145, 13161, 13179, 13194, 13216, 13233, 13249, 13266, 13287, 13303, 13322, 13337, 13357, 13375, 13392, 13410, 13424, 13446, 13465, 13480, 13499, 13517, 13533, 13559, 13575, 13595, 13612, 13632, 13650, 13670, 13687, 13706, 13726, 13744, 13765, 13783, 13803, 13822, 13841, 13860, 13879, 13897, 13917, 13936, 13960, 13979, 13996, 14019, 14040, 14057, 14077, 14102, 14122, 14141, 14163, 14184, 14202, 14225, 14244, 14265, 14287, 14312, 14336, 14356, 14375, 14393, 14420, 14438, 14465, 14483, 14500, 14536, 14555, 14575, 14604, 14619, 14648, 14668, 14691, 14725, 14748, 14770, 14788, 14818, 14840, 14862, 14888, 14921, 14939, 14969, 14996, 15022, 15051, 15075, 15098, 15130, 15149, 15167, 15218, 15237, 15276, 15297, 15333, 15356, 15379, 15418, 15447, 15481, 15508, 15530, 15574, 15599, 15643, 15680, 15697, 15743, 15759, 15775, 15813, 15845, 15877, 15911, 15931, 15968, 16014, 16049, 16077, 16088, 16138, 16149, 16185, 16200, 16241, 16280, 16296}; - public ABITracerTest() { - } + private ABITrace tracer = null; + //Test length of tracer for file 3730.ab1 + static final int EXPECTED_TRACE_LENGTH = 16302; - @BeforeClass - public static void setUpClass() throws Exception { - } - - @AfterClass - public static void tearDownClass() throws Exception { - } - - @Before - public void setUp() { + @BeforeEach + void setUp() throws Exception { + URL resource = this.getClass().getResource("/3730.ab1"); + assertNotNull(resource); + tracer = new ABITrace(resource); } - @After - public void tearDown() { + @AfterEach + void tearDown() { } /** @@ -68,9 +65,6 @@ public void tearDown() { */ @Test public void testURL() throws Exception { - URL resource = this.getClass().getResource("/3730.ab1"); - assertNotNull(resource); - ABITrace tracer = new ABITrace(resource); assertNotNull(tracer); } @@ -78,7 +72,7 @@ public void testURL() throws Exception { * Test of Local file method, of class ABITracer. */ @Test - public void testLocal() throws Exception { + void testLocal() throws Exception { URL resource = this.getClass().getResource("/3730.ab1"); assertNotNull(resource); File file = new File(resource.toURI()); @@ -86,8 +80,7 @@ public void testLocal() throws Exception { ABITrace tracer = new ABITrace(file); assertNotNull(tracer); - //Test length of tracer for file 3730.ab1 - final int EXPECTED_TRACE_LENGTH = 16302; + assertEquals(EXPECTED_TRACE_LENGTH, tracer.getTraceLength()); //Test length of sequence for file 3730.ab1 assertEquals(1165, tracer.getSequenceLength()); @@ -102,9 +95,18 @@ public void testLocal() throws Exception { BufferedImage image = tracer.getImage(100,100); assertNotNull(image); - Assert.assertThrows(CompoundNotFoundException.class, ()->tracer.getTrace("D")); - for (String base: Arrays.asList(new String []{"A","T","C","G"})){ - assertEquals(EXPECTED_TRACE_LENGTH, tracer.getTrace(base).length); - } + + } + + @DisplayName("getTrace rejects invalid bases") + @Test + void testGetTraceThrowsCNFE() throws Exception { + assertThrows(CompoundNotFoundException.class, ()->tracer.getTrace("D")); + } + + @ParameterizedTest + @ValueSource(strings = {"A","T","C", "G" }) + void testGetTrace(String base) throws Exception {; + assertEquals(EXPECTED_TRACE_LENGTH, tracer.getTrace(base).length); } } diff --git a/pom.xml b/pom.xml index d5a7d30e65..3866c8753e 100644 --- a/pom.xml +++ b/pom.xml @@ -43,6 +43,7 @@ 1.0.10 1.7.30 2.14.0 + 5.7.2 ciftools-java-jdk8 2.0.2 @@ -243,20 +244,8 @@ org.apache.maven.plugins maven-surefire-plugin 3.0.0-M5 - - - true - true - true - true - - - true - true - true - - - + + org.apache.maven.plugins maven-shade-plugin @@ -419,23 +408,24 @@ test - org.junit.vintage - junit-vintage-engine - 5.7.2 - test - - - org.junit.jupiter - junit-jupiter-api - 5.7.2 - test - - - org.junit.jupiter - junit-jupiter-engine - 5.7.2 - test - + org.junit.vintage + junit-vintage-engine + ${junit-jupiter.version} + test + + + + org.junit.jupiter + junit-jupiter-engine + ${junit-jupiter.version} + test + + + org.junit.jupiter + junit-jupiter-params + ${junit-jupiter.version} + test + org.slf4j slf4j-api From 00bd3b2c610e60dded181e85a8781be588e7b991 Mon Sep 17 00:00:00 2001 From: Richard Adams Date: Sun, 4 Jul 2021 10:43:38 +0100 Subject: [PATCH 107/599] formatting --- .../nbio/core/sequence/io/ABITracerTest.java | 159 +++++++++++++++--- 1 file changed, 131 insertions(+), 28 deletions(-) diff --git a/biojava-core/src/test/java/org/biojava/nbio/core/sequence/io/ABITracerTest.java b/biojava-core/src/test/java/org/biojava/nbio/core/sequence/io/ABITracerTest.java index dce9cc7b58..3024940a07 100644 --- a/biojava-core/src/test/java/org/biojava/nbio/core/sequence/io/ABITracerTest.java +++ b/biojava-core/src/test/java/org/biojava/nbio/core/sequence/io/ABITracerTest.java @@ -21,9 +21,8 @@ package org.biojava.nbio.core.sequence.io; - import static org.junit.jupiter.api.Assertions.*; -import org.junit.jupiter.api.*; +import org.junit.jupiter.api.*; import org.junit.jupiter.params.provider.ValueSource; import org.junit.jupiter.params.ParameterizedTest; @@ -35,31 +34,138 @@ import org.biojava.nbio.core.exceptions.CompoundNotFoundException; /** - * Test file 3730.ab1 is from https://github.com/biopython/biopython/blob/master/Tests/Abi/3730.ab1 - * The test data for comparing the results from ABITrace.java for file 3730.ab1 is from https://github.com/biopython/biopython/blob/master/Tests/Abi/test_data + * Test file 3730.ab1 is from https://github.com/biopython/biopython/blob/master/Tests/Abi/3730.ab1 The test data for + * comparing the results from ABITrace.java for file 3730.ab1 is from + * https://github.com/biopython/biopython/blob/master/Tests/Abi/test_data */ public class ABITracerTest { - private String sequence = "GGGCGAGCKYYAYATTTTGGCAAGAATTGAGCTCTATGGCCACAACCATGGTGAGCAAGGGCGAGGAGGATAACATGGCCATCATCAAGGAGTTCATGCGCTTCAAGGTGCACATGGAGGGCTCCGTGAACGGCCACGAGTTCGAGATCGAGGGCGAGGGCGAGGGCCGCCCCTACGAGGGCACCCAGACCGCCAAGCTGAAGGTGACCAAGGGTGGCCCCCTGCCCTTCGCCTGGGACATCCTGTCCCCTCAGTTCATGTACGGCTCCAAGGCCTACGTGAAGCACCCCGCCGACATCCCCGACTACTTGAAGCTGTCCTTCCCCGAGGGCTTCAAGTGGGAGCGCGTGATGAACTTCGAGGACGGCGGCGTGGTGACCGTGACCCAGGACTCCTCCCTGCAGGACGGCGAGTTCATCTACAAGGTGAAGCTGCGCGGCACCAACTTCCCCTCCGACGGCCCCGTAATGCAGAAGAAGACCATGGGCTGGGAGGCCTCCTCCGAGCGGATGTACCCCGAGGACGGCGCCCTGAAGGGCGAGATCAAGCAGAGGCTGAAGCTGAAGGACGGCGGCCACTACGACGCTGAGGTCAAGACCACCTACAAGGCCAAGAAGCCCGTGCAGCTGCCCGGCGCCTACAACGTCAACATCAAGTTGGACATCACCTCCCACAACGAGGACTACACCATCGTGGAACAGTACGAACGCGCCGAGGGCCGCCACTCCACCGGCGGCATGGACGAGCTGTACAAGGGCGGCAGCGGCATGGTGAGCAAGGGCGAGGAGCTGTTCACCGGGGTGGTGCCCATCCTGGTCGAGCTGGACGGCGACGTAAACGGCCACAAGTTCAGCGTGTCCGGCGAGGGCGAGGGCGATGCCACCTACGGCAAGCTGACCCTGAAGTTCATCTGCACCACCGGCAAGCTGCCCGTGCCCTGGCCCACCCTCGTGACCACCCTGACCTACGGCGTGCAGTGCTTCAGCCGCTACCCCGACCACATGAAGCAGCACGACTTCTTCAAGTCCGCCATGCCCGAAGGCTACGTCCAGGAGCGCACCATCTTCTTCAAGGACGACGGCAACTACAARACCCGCGCCGAGGTGAARTTCGAGGGCGACACCCTGGTGAACCGCATCGAGCTGAAAGGGGCAYCGCACCTTTC"; - private int[] qual = {20, 3, 4, 4, 4, 6, 4, 4, 0, 0, 0, 6, 0, 10, 20, 26, 22, 17, 21, 31, 29, 32, 28, 18, 23, 17, 19, 35, 36, 50, 39, 50, 50, 50, 50, 50, 25, 35, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 35, 39, 33, 20, 35, 31, 50, 50, 50, 50, 50, 50, 50, 50, 50, 31, 50, 35, 31, 23, 28, 31, 21, 43, 39, 35, 24, 30, 26, 35, 31, 50, 50, 50, 50, 50, 50, 50, 50, 50, 39, 31, 24, 39, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 31, 31, 43, 43, 50, 50, 50, 50, 50, 31, 31, 31, 31, 50, 50, 50, 50, 50, 50, 50, 50, 31, 31, 35, 50, 50, 50, 50, 31, 36, 55, 55, 55, 55, 36, 55, 55, 55, 55, 55, 36, 55, 55, 55, 55, 55, 36, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 40, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 36, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 40, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 43, 43, 50, 43, 43, 50, 43, 43, 50, 43, 43, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 43, 43, 50, 43, 43, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 28, 28, 35, 28, 28, 35, 28, 28, 35, 28, 28, 35, 28, 28, 35, 28, 21, 28, 35, 28, 28, 35, 35, 35, 35, 35, 37, 38, 21, 28, 35, 28, 28, 35, 35, 35, 35, 35, 35, 35, 36, 36, 21, 39, 35, 35, 35, 39, 35, 37, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 28, 28, 35, 35, 28, 28, 35, 35, 35, 36, 36, 22, 39, 35, 35, 35, 35, 35, 35, 37, 38, 28, 35, 21, 36, 36, 37, 35, 35, 20, 39, 39, 35, 35, 35, 35, 37, 38, 28, 35, 37, 34, 35, 24, 24, 27, 25, 20, 24, 37, 35, 27, 21, 20, 21, 27, 17, 20, 24, 32, 26, 20, 12, 20, 10, 20, 24, 25, 23, 20, 32, 24, 24, 23, 20, 24, 23, 18, 34, 34, 34, 22, 26, 24, 24, 18, 22, 22, 23, 25, 20, 12, 20, 24, 23, 24, 23, 22, 20, 20, 0, 20, 24, 23, 20, 8, 10, 4, 20, 20, 3, 7, 19, 20, 4, 4, 7, 7, 0, 7, 11, 18, 8, 3, 23, 23, 20, 11, 4, 20, 18, 12, 20, 20, 20, 4, 20, 4, 2, 3, 21, 21, 21, 21, 10, 15, 14, 15, 19, 2, 4, 3, 6, 11, 3, 4, 6, 21, 16, 20, 11, 1, 4, 12, 0, 15, 8, 1, 3, 3, 12, 1, 11, 20, 4}; - private int[] base = {2, 13, 38, 51, 67, 78, 92, 118, 138, 162, 181, 191, 210, 222, 239, 253, 266, 280, 288, 304, 317, 333, 347, 359, 375, 386, 394, 406, 418, 433, 444, 457, 472, 482, 496, 506, 519, 529, 544, 557, 569, 579, 590, 601, 614, 626, 638, 649, 663, 673, 686, 706, 715, 731, 740, 753, 765, 777, 787, 799, 813, 826, 838, 854, 863, 876, 892, 901, 913, 929, 937, 948, 960, 970, 981, 993, 1004, 1017, 1034, 1045, 1056, 1068, 1080, 1091, 1103, 1115, 1126, 1138, 1148, 1160, 1177, 1187, 1199, 1211, 1222, 1232, 1243, 1254, 1268, 1279, 1294, 1307, 1319, 1330, 1341, 1352, 1362, 1374, 1388, 1398, 1411, 1422, 1433, 1444, 1456, 1466, 1479, 1497, 1506, 1519, 1531, 1543, 1556, 1567, 1578, 1589, 1604, 1614, 1630, 1641, 1651, 1662, 1675, 1688, 1700, 1711, 1721, 1732, 1748, 1758, 1772, 1784, 1795, 1806, 1820, 1830, 1844, 1855, 1866, 1877, 1892, 1902, 1914, 1926, 1939, 1950, 1965, 1974, 1986, 1999, 2011, 2023, 2037, 2047, 2059, 2072, 2084, 2096, 2107, 2120, 2132, 2144, 2156, 2169, 2180, 2191, 2202, 2217, 2227, 2239, 2251, 2264, 2275, 2286, 2297, 2309, 2321, 2332, 2347, 2358, 2369, 2381, 2394, 2406, 2417, 2429, 2439, 2452, 2465, 2476, 2490, 2501, 2512, 2524, 2536, 2546, 2560, 2570, 2581, 2593, 2605, 2616, 2628, 2640, 2653, 2664, 2676, 2688, 2700, 2712, 2723, 2735, 2748, 2759, 2772, 2784, 2795, 2808, 2820, 2831, 2842, 2854, 2866, 2878, 2888, 2901, 2913, 2927, 2936, 2947, 2958, 2970, 2982, 2994, 3005, 3019, 3030, 3041, 3053, 3064, 3077, 3088, 3099, 3110, 3123, 3135, 3146, 3157, 3168, 3179, 3192, 3203, 3214, 3226, 3238, 3251, 3263, 3275, 3286, 3297, 3308, 3320, 3331, 3344, 3356, 3368, 3380, 3391, 3402, 3415, 3426, 3440, 3451, 3462, 3474, 3485, 3496, 3508, 3520, 3532, 3543, 3556, 3569, 3580, 3593, 3604, 3615, 3626, 3638, 3650, 3661, 3673, 3684, 3698, 3709, 3721, 3732, 3744, 3756, 3767, 3779, 3792, 3803, 3814, 3827, 3838, 3850, 3862, 3873, 3885, 3897, 3909, 3920, 3932, 3943, 3955, 3966, 3980, 3990, 4002, 4014, 4026, 4038, 4050, 4061, 4072, 4083, 4095, 4107, 4119, 4131, 4143, 4156, 4167, 4179, 4191, 4203, 4215, 4227, 4238, 4252, 4262, 4274, 4287, 4298, 4310, 4321, 4333, 4345, 4356, 4370, 4381, 4393, 4406, 4417, 4428, 4440, 4453, 4464, 4477, 4489, 4500, 4513, 4524, 4536, 4548, 4560, 4573, 4583, 4595, 4607, 4620, 4631, 4645, 4655, 4667, 4679, 4690, 4702, 4714, 4728, 4739, 4750, 4762, 4774, 4786, 4798, 4810, 4821, 4833, 4845, 4857, 4869, 4880, 4892, 4905, 4916, 4927, 4940, 4952, 4963, 4977, 4988, 5000, 5012, 5023, 5034, 5045, 5057, 5069, 5081, 5093, 5104, 5115, 5127, 5139, 5151, 5163, 5176, 5188, 5199, 5211, 5223, 5235, 5247, 5259, 5272, 5283, 5296, 5308, 5320, 5331, 5343, 5354, 5366, 5378, 5390, 5402, 5414, 5426, 5438, 5450, 5462, 5474, 5486, 5497, 5510, 5521, 5532, 5544, 5557, 5569, 5581, 5592, 5604, 5617, 5629, 5641, 5652, 5663, 5676, 5687, 5699, 5712, 5724, 5735, 5748, 5760, 5771, 5784, 5794, 5806, 5817, 5829, 5841, 5853, 5866, 5879, 5891, 5903, 5916, 5928, 5941, 5952, 5964, 5976, 5988, 6000, 6012, 6024, 6036, 6048, 6060, 6072, 6085, 6096, 6109, 6121, 6133, 6146, 6157, 6168, 6180, 6192, 6203, 6215, 6227, 6239, 6251, 6265, 6276, 6289, 6302, 6313, 6325, 6337, 6349, 6361, 6374, 6386, 6398, 6410, 6422, 6436, 6448, 6459, 6471, 6483, 6495, 6507, 6520, 6532, 6545, 6555, 6567, 6579, 6591, 6603, 6615, 6627, 6640, 6652, 6664, 6676, 6688, 6700, 6713, 6726, 6738, 6749, 6761, 6774, 6786, 6799, 6811, 6823, 6835, 6848, 6859, 6871, 6883, 6895, 6907, 6920, 6933, 6945, 6956, 6968, 6980, 6992, 7005, 7016, 7030, 7042, 7053, 7066, 7079, 7091, 7104, 7115, 7128, 7140, 7152, 7163, 7175, 7187, 7200, 7212, 7224, 7235, 7248, 7260, 7272, 7285, 7297, 7309, 7321, 7333, 7345, 7358, 7370, 7382, 7394, 7406, 7419, 7431, 7443, 7455, 7468, 7480, 7492, 7505, 7517, 7530, 7542, 7554, 7566, 7578, 7591, 7603, 7615, 7628, 7640, 7653, 7666, 7677, 7690, 7702, 7714, 7727, 7738, 7750, 7762, 7775, 7786, 7799, 7812, 7823, 7836, 7848, 7859, 7871, 7884, 7896, 7909, 7921, 7933, 7946, 7958, 7971, 7984, 7996, 8007, 8019, 8032, 8044, 8056, 8069, 8081, 8094, 8107, 8119, 8131, 8143, 8155, 8167, 8179, 8192, 8205, 8218, 8230, 8244, 8255, 8267, 8279, 8291, 8303, 8315, 8328, 8340, 8353, 8366, 8378, 8392, 8404, 8417, 8431, 8443, 8455, 8467, 8479, 8492, 8504, 8516, 8529, 8543, 8555, 8567, 8580, 8593, 8606, 8619, 8632, 8644, 8658, 8670, 8683, 8695, 8708, 8721, 8733, 8746, 8759, 8771, 8783, 8795, 8808, 8821, 8833, 8845, 8858, 8871, 8885, 8898, 8910, 8923, 8936, 8949, 8960, 8973, 8986, 9000, 9012, 9025, 9038, 9051, 9064, 9076, 9089, 9102, 9114, 9126, 9139, 9151, 9164, 9177, 9191, 9204, 9217, 9230, 9243, 9255, 9268, 9281, 9294, 9307, 9320, 9333, 9345, 9358, 9371, 9384, 9398, 9412, 9424, 9437, 9450, 9462, 9475, 9488, 9501, 9514, 9528, 9542, 9554, 9567, 9581, 9593, 9606, 9619, 9632, 9645, 9658, 9671, 9682, 9695, 9708, 9721, 9735, 9749, 9762, 9776, 9789, 9802, 9815, 9828, 9842, 9855, 9867, 9880, 9893, 9906, 9920, 9933, 9947, 9960, 9974, 9987, 10000, 10014, 10027, 10040, 10054, 10067, 10081, 10095, 10107, 10120, 10134, 10148, 10161, 10175, 10188, 10201, 10214, 10228, 10241, 10254, 10267, 10280, 10294, 10309, 10322, 10335, 10348, 10362, 10374, 10387, 10401, 10415, 10428, 10441, 10455, 10469, 10482, 10497, 10510, 10523, 10537, 10551, 10565, 10579, 10593, 10606, 10621, 10634, 10647, 10661, 10675, 10689, 10704, 10719, 10732, 10746, 10760, 10774, 10788, 10802, 10815, 10829, 10843, 10856, 10871, 10884, 10898, 10913, 10927, 10940, 10955, 10970, 10984, 10999, 11013, 11027, 11042, 11056, 11071, 11086, 11100, 11114, 11128, 11142, 11158, 11171, 11186, 11200, 11213, 11228, 11241, 11255, 11270, 11284, 11299, 11314, 11328, 11342, 11356, 11370, 11385, 11399, 11413, 11429, 11445, 11460, 11474, 11489, 11503, 11518, 11533, 11549, 11563, 11577, 11592, 11607, 11621, 11637, 11651, 11665, 11680, 11694, 11708, 11725, 11740, 11754, 11768, 11784, 11798, 11813, 11828, 11843, 11858, 11874, 11888, 11904, 11920, 11933, 11948, 11964, 11979, 11993, 12009, 12024, 12041, 12058, 12071, 12087, 12102, 12117, 12132, 12148, 12165, 12179, 12195, 12210, 12226, 12241, 12256, 12273, 12288, 12304, 12320, 12335, 12350, 12365, 12382, 12398, 12414, 12430, 12446, 12462, 12478, 12495, 12511, 12525, 12541, 12556, 12575, 12591, 12605, 12622, 12638, 12653, 12671, 12686, 12705, 12721, 12739, 12756, 12772, 12788, 12806, 12822, 12839, 12855, 12873, 12890, 12908, 12923, 12941, 12960, 12975, 12992, 13009, 13024, 13040, 13059, 13076, 13092, 13109, 13128, 13145, 13161, 13179, 13194, 13216, 13233, 13249, 13266, 13287, 13303, 13322, 13337, 13357, 13375, 13392, 13410, 13424, 13446, 13465, 13480, 13499, 13517, 13533, 13559, 13575, 13595, 13612, 13632, 13650, 13670, 13687, 13706, 13726, 13744, 13765, 13783, 13803, 13822, 13841, 13860, 13879, 13897, 13917, 13936, 13960, 13979, 13996, 14019, 14040, 14057, 14077, 14102, 14122, 14141, 14163, 14184, 14202, 14225, 14244, 14265, 14287, 14312, 14336, 14356, 14375, 14393, 14420, 14438, 14465, 14483, 14500, 14536, 14555, 14575, 14604, 14619, 14648, 14668, 14691, 14725, 14748, 14770, 14788, 14818, 14840, 14862, 14888, 14921, 14939, 14969, 14996, 15022, 15051, 15075, 15098, 15130, 15149, 15167, 15218, 15237, 15276, 15297, 15333, 15356, 15379, 15418, 15447, 15481, 15508, 15530, 15574, 15599, 15643, 15680, 15697, 15743, 15759, 15775, 15813, 15845, 15877, 15911, 15931, 15968, 16014, 16049, 16077, 16088, 16138, 16149, 16185, 16200, 16241, 16280, 16296}; + private int[] qual = { 20, 3, 4, 4, 4, 6, 4, 4, 0, 0, 0, 6, 0, 10, 20, 26, 22, 17, 21, 31, 29, 32, 28, 18, 23, 17, + 19, 35, 36, 50, 39, 50, 50, 50, 50, 50, 25, 35, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 35, 39, 33, 20, 35, + 31, 50, 50, 50, 50, 50, 50, 50, 50, 50, 31, 50, 35, 31, 23, 28, 31, 21, 43, 39, 35, 24, 30, 26, 35, 31, 50, + 50, 50, 50, 50, 50, 50, 50, 50, 39, 31, 24, 39, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, + 50, 50, 50, 50, 50, 50, 50, 50, 50, 31, 31, 43, 43, 50, 50, 50, 50, 50, 31, 31, 31, 31, 50, 50, 50, 50, 50, + 50, 50, 50, 31, 31, 35, 50, 50, 50, 50, 31, 36, 55, 55, 55, 55, 36, 55, 55, 55, 55, 55, 36, 55, 55, 55, 55, + 55, 36, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 40, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 36, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 40, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 50, 50, + 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, + 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, + 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, + 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, + 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, + 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, + 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, + 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, + 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, + 50, 43, 43, 50, 43, 43, 50, 43, 43, 50, 43, 43, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, + 50, 50, 50, 50, 50, 50, 43, 43, 50, 43, 43, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 35, 35, 35, 35, 35, 35, + 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 28, 28, 35, 28, 28, 35, 28, 28, 35, 28, 28, 35, 28, 28, 35, 28, + 21, 28, 35, 28, 28, 35, 35, 35, 35, 35, 37, 38, 21, 28, 35, 28, 28, 35, 35, 35, 35, 35, 35, 35, 36, 36, 21, + 39, 35, 35, 35, 39, 35, 37, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 28, 28, 35, 35, 28, 28, 35, 35, + 35, 36, 36, 22, 39, 35, 35, 35, 35, 35, 35, 37, 38, 28, 35, 21, 36, 36, 37, 35, 35, 20, 39, 39, 35, 35, 35, + 35, 37, 38, 28, 35, 37, 34, 35, 24, 24, 27, 25, 20, 24, 37, 35, 27, 21, 20, 21, 27, 17, 20, 24, 32, 26, 20, + 12, 20, 10, 20, 24, 25, 23, 20, 32, 24, 24, 23, 20, 24, 23, 18, 34, 34, 34, 22, 26, 24, 24, 18, 22, 22, 23, + 25, 20, 12, 20, 24, 23, 24, 23, 22, 20, 20, 0, 20, 24, 23, 20, 8, 10, 4, 20, 20, 3, 7, 19, 20, 4, 4, 7, 7, + 0, 7, 11, 18, 8, 3, 23, 23, 20, 11, 4, 20, 18, 12, 20, 20, 20, 4, 20, 4, 2, 3, 21, 21, 21, 21, 10, 15, 14, + 15, 19, 2, 4, 3, 6, 11, 3, 4, 6, 21, 16, 20, 11, 1, 4, 12, 0, 15, 8, 1, 3, 3, 12, 1, 11, 20, 4 }; + private int[] base = { 2, 13, 38, 51, 67, 78, 92, 118, 138, 162, 181, 191, 210, 222, 239, 253, 266, 280, 288, 304, + 317, 333, 347, 359, 375, 386, 394, 406, 418, 433, 444, 457, 472, 482, 496, 506, 519, 529, 544, 557, 569, + 579, 590, 601, 614, 626, 638, 649, 663, 673, 686, 706, 715, 731, 740, 753, 765, 777, 787, 799, 813, 826, + 838, 854, 863, 876, 892, 901, 913, 929, 937, 948, 960, 970, 981, 993, 1004, 1017, 1034, 1045, 1056, 1068, + 1080, 1091, 1103, 1115, 1126, 1138, 1148, 1160, 1177, 1187, 1199, 1211, 1222, 1232, 1243, 1254, 1268, 1279, + 1294, 1307, 1319, 1330, 1341, 1352, 1362, 1374, 1388, 1398, 1411, 1422, 1433, 1444, 1456, 1466, 1479, 1497, + 1506, 1519, 1531, 1543, 1556, 1567, 1578, 1589, 1604, 1614, 1630, 1641, 1651, 1662, 1675, 1688, 1700, 1711, + 1721, 1732, 1748, 1758, 1772, 1784, 1795, 1806, 1820, 1830, 1844, 1855, 1866, 1877, 1892, 1902, 1914, 1926, + 1939, 1950, 1965, 1974, 1986, 1999, 2011, 2023, 2037, 2047, 2059, 2072, 2084, 2096, 2107, 2120, 2132, 2144, + 2156, 2169, 2180, 2191, 2202, 2217, 2227, 2239, 2251, 2264, 2275, 2286, 2297, 2309, 2321, 2332, 2347, 2358, + 2369, 2381, 2394, 2406, 2417, 2429, 2439, 2452, 2465, 2476, 2490, 2501, 2512, 2524, 2536, 2546, 2560, 2570, + 2581, 2593, 2605, 2616, 2628, 2640, 2653, 2664, 2676, 2688, 2700, 2712, 2723, 2735, 2748, 2759, 2772, 2784, + 2795, 2808, 2820, 2831, 2842, 2854, 2866, 2878, 2888, 2901, 2913, 2927, 2936, 2947, 2958, 2970, 2982, 2994, + 3005, 3019, 3030, 3041, 3053, 3064, 3077, 3088, 3099, 3110, 3123, 3135, 3146, 3157, 3168, 3179, 3192, 3203, + 3214, 3226, 3238, 3251, 3263, 3275, 3286, 3297, 3308, 3320, 3331, 3344, 3356, 3368, 3380, 3391, 3402, 3415, + 3426, 3440, 3451, 3462, 3474, 3485, 3496, 3508, 3520, 3532, 3543, 3556, 3569, 3580, 3593, 3604, 3615, 3626, + 3638, 3650, 3661, 3673, 3684, 3698, 3709, 3721, 3732, 3744, 3756, 3767, 3779, 3792, 3803, 3814, 3827, 3838, + 3850, 3862, 3873, 3885, 3897, 3909, 3920, 3932, 3943, 3955, 3966, 3980, 3990, 4002, 4014, 4026, 4038, 4050, + 4061, 4072, 4083, 4095, 4107, 4119, 4131, 4143, 4156, 4167, 4179, 4191, 4203, 4215, 4227, 4238, 4252, 4262, + 4274, 4287, 4298, 4310, 4321, 4333, 4345, 4356, 4370, 4381, 4393, 4406, 4417, 4428, 4440, 4453, 4464, 4477, + 4489, 4500, 4513, 4524, 4536, 4548, 4560, 4573, 4583, 4595, 4607, 4620, 4631, 4645, 4655, 4667, 4679, 4690, + 4702, 4714, 4728, 4739, 4750, 4762, 4774, 4786, 4798, 4810, 4821, 4833, 4845, 4857, 4869, 4880, 4892, 4905, + 4916, 4927, 4940, 4952, 4963, 4977, 4988, 5000, 5012, 5023, 5034, 5045, 5057, 5069, 5081, 5093, 5104, 5115, + 5127, 5139, 5151, 5163, 5176, 5188, 5199, 5211, 5223, 5235, 5247, 5259, 5272, 5283, 5296, 5308, 5320, 5331, + 5343, 5354, 5366, 5378, 5390, 5402, 5414, 5426, 5438, 5450, 5462, 5474, 5486, 5497, 5510, 5521, 5532, 5544, + 5557, 5569, 5581, 5592, 5604, 5617, 5629, 5641, 5652, 5663, 5676, 5687, 5699, 5712, 5724, 5735, 5748, 5760, + 5771, 5784, 5794, 5806, 5817, 5829, 5841, 5853, 5866, 5879, 5891, 5903, 5916, 5928, 5941, 5952, 5964, 5976, + 5988, 6000, 6012, 6024, 6036, 6048, 6060, 6072, 6085, 6096, 6109, 6121, 6133, 6146, 6157, 6168, 6180, 6192, + 6203, 6215, 6227, 6239, 6251, 6265, 6276, 6289, 6302, 6313, 6325, 6337, 6349, 6361, 6374, 6386, 6398, 6410, + 6422, 6436, 6448, 6459, 6471, 6483, 6495, 6507, 6520, 6532, 6545, 6555, 6567, 6579, 6591, 6603, 6615, 6627, + 6640, 6652, 6664, 6676, 6688, 6700, 6713, 6726, 6738, 6749, 6761, 6774, 6786, 6799, 6811, 6823, 6835, 6848, + 6859, 6871, 6883, 6895, 6907, 6920, 6933, 6945, 6956, 6968, 6980, 6992, 7005, 7016, 7030, 7042, 7053, 7066, + 7079, 7091, 7104, 7115, 7128, 7140, 7152, 7163, 7175, 7187, 7200, 7212, 7224, 7235, 7248, 7260, 7272, 7285, + 7297, 7309, 7321, 7333, 7345, 7358, 7370, 7382, 7394, 7406, 7419, 7431, 7443, 7455, 7468, 7480, 7492, 7505, + 7517, 7530, 7542, 7554, 7566, 7578, 7591, 7603, 7615, 7628, 7640, 7653, 7666, 7677, 7690, 7702, 7714, 7727, + 7738, 7750, 7762, 7775, 7786, 7799, 7812, 7823, 7836, 7848, 7859, 7871, 7884, 7896, 7909, 7921, 7933, 7946, + 7958, 7971, 7984, 7996, 8007, 8019, 8032, 8044, 8056, 8069, 8081, 8094, 8107, 8119, 8131, 8143, 8155, 8167, + 8179, 8192, 8205, 8218, 8230, 8244, 8255, 8267, 8279, 8291, 8303, 8315, 8328, 8340, 8353, 8366, 8378, 8392, + 8404, 8417, 8431, 8443, 8455, 8467, 8479, 8492, 8504, 8516, 8529, 8543, 8555, 8567, 8580, 8593, 8606, 8619, + 8632, 8644, 8658, 8670, 8683, 8695, 8708, 8721, 8733, 8746, 8759, 8771, 8783, 8795, 8808, 8821, 8833, 8845, + 8858, 8871, 8885, 8898, 8910, 8923, 8936, 8949, 8960, 8973, 8986, 9000, 9012, 9025, 9038, 9051, 9064, 9076, + 9089, 9102, 9114, 9126, 9139, 9151, 9164, 9177, 9191, 9204, 9217, 9230, 9243, 9255, 9268, 9281, 9294, 9307, + 9320, 9333, 9345, 9358, 9371, 9384, 9398, 9412, 9424, 9437, 9450, 9462, 9475, 9488, 9501, 9514, 9528, 9542, + 9554, 9567, 9581, 9593, 9606, 9619, 9632, 9645, 9658, 9671, 9682, 9695, 9708, 9721, 9735, 9749, 9762, 9776, + 9789, 9802, 9815, 9828, 9842, 9855, 9867, 9880, 9893, 9906, 9920, 9933, 9947, 9960, 9974, 9987, 10000, + 10014, 10027, 10040, 10054, 10067, 10081, 10095, 10107, 10120, 10134, 10148, 10161, 10175, 10188, 10201, + 10214, 10228, 10241, 10254, 10267, 10280, 10294, 10309, 10322, 10335, 10348, 10362, 10374, 10387, 10401, + 10415, 10428, 10441, 10455, 10469, 10482, 10497, 10510, 10523, 10537, 10551, 10565, 10579, 10593, 10606, + 10621, 10634, 10647, 10661, 10675, 10689, 10704, 10719, 10732, 10746, 10760, 10774, 10788, 10802, 10815, + 10829, 10843, 10856, 10871, 10884, 10898, 10913, 10927, 10940, 10955, 10970, 10984, 10999, 11013, 11027, + 11042, 11056, 11071, 11086, 11100, 11114, 11128, 11142, 11158, 11171, 11186, 11200, 11213, 11228, 11241, + 11255, 11270, 11284, 11299, 11314, 11328, 11342, 11356, 11370, 11385, 11399, 11413, 11429, 11445, 11460, + 11474, 11489, 11503, 11518, 11533, 11549, 11563, 11577, 11592, 11607, 11621, 11637, 11651, 11665, 11680, + 11694, 11708, 11725, 11740, 11754, 11768, 11784, 11798, 11813, 11828, 11843, 11858, 11874, 11888, 11904, + 11920, 11933, 11948, 11964, 11979, 11993, 12009, 12024, 12041, 12058, 12071, 12087, 12102, 12117, 12132, + 12148, 12165, 12179, 12195, 12210, 12226, 12241, 12256, 12273, 12288, 12304, 12320, 12335, 12350, 12365, + 12382, 12398, 12414, 12430, 12446, 12462, 12478, 12495, 12511, 12525, 12541, 12556, 12575, 12591, 12605, + 12622, 12638, 12653, 12671, 12686, 12705, 12721, 12739, 12756, 12772, 12788, 12806, 12822, 12839, 12855, + 12873, 12890, 12908, 12923, 12941, 12960, 12975, 12992, 13009, 13024, 13040, 13059, 13076, 13092, 13109, + 13128, 13145, 13161, 13179, 13194, 13216, 13233, 13249, 13266, 13287, 13303, 13322, 13337, 13357, 13375, + 13392, 13410, 13424, 13446, 13465, 13480, 13499, 13517, 13533, 13559, 13575, 13595, 13612, 13632, 13650, + 13670, 13687, 13706, 13726, 13744, 13765, 13783, 13803, 13822, 13841, 13860, 13879, 13897, 13917, 13936, + 13960, 13979, 13996, 14019, 14040, 14057, 14077, 14102, 14122, 14141, 14163, 14184, 14202, 14225, 14244, + 14265, 14287, 14312, 14336, 14356, 14375, 14393, 14420, 14438, 14465, 14483, 14500, 14536, 14555, 14575, + 14604, 14619, 14648, 14668, 14691, 14725, 14748, 14770, 14788, 14818, 14840, 14862, 14888, 14921, 14939, + 14969, 14996, 15022, 15051, 15075, 15098, 15130, 15149, 15167, 15218, 15237, 15276, 15297, 15333, 15356, + 15379, 15418, 15447, 15481, 15508, 15530, 15574, 15599, 15643, 15680, 15697, 15743, 15759, 15775, 15813, + 15845, 15877, 15911, 15931, 15968, 16014, 16049, 16077, 16088, 16138, 16149, 16185, 16200, 16241, 16280, + 16296 }; private ABITrace tracer = null; - //Test length of tracer for file 3730.ab1 + + // Test length of tracer for file 3730.ab1 static final int EXPECTED_TRACE_LENGTH = 16302; @BeforeEach - void setUp() throws Exception { + void setUp() throws Exception { URL resource = this.getClass().getResource("/3730.ab1"); assertNotNull(resource); tracer = new ABITrace(resource); } - @AfterEach - void tearDown() { - } - /** * Test of URL method, of class ABITracer. */ @@ -72,41 +178,38 @@ public void testURL() throws Exception { * Test of Local file method, of class ABITracer. */ @Test - void testLocal() throws Exception { + void testLocal() throws Exception { URL resource = this.getClass().getResource("/3730.ab1"); - assertNotNull(resource); File file = new File(resource.toURI()); assertNotNull(file); ABITrace tracer = new ABITrace(file); assertNotNull(tracer); - assertEquals(EXPECTED_TRACE_LENGTH, tracer.getTraceLength()); - //Test length of sequence for file 3730.ab1 + // Test length of sequence for file 3730.ab1 assertEquals(1165, tracer.getSequenceLength()); - //Test sequence of tracer for file 3730.ab1 + // Test sequence of tracer for file 3730.ab1 assertTrue(sequence.equals(tracer.getSequence().getSequenceAsString())); - //Test array that represents the quality of tracer for file 3730.ab1 + // Test array that represents the quality of tracer for file 3730.ab1 assertArrayEquals(qual, tracer.getQcalls()); - //Test array that represents the baseline of tracer for file 3730.ab1 + // Test array that represents the baseline of tracer for file 3730.ab1 assertArrayEquals(base, tracer.getBasecalls()); - //Test image of tracer for file 3730.ab1 - BufferedImage image = tracer.getImage(100,100); + // Test image of tracer for file 3730.ab1 + BufferedImage image = tracer.getImage(100, 100); assertNotNull(image); - - } @DisplayName("getTrace rejects invalid bases") @Test void testGetTraceThrowsCNFE() throws Exception { - assertThrows(CompoundNotFoundException.class, ()->tracer.getTrace("D")); + assertThrows(CompoundNotFoundException.class, () -> tracer.getTrace("D")); } - @ParameterizedTest - @ValueSource(strings = {"A","T","C", "G" }) - void testGetTrace(String base) throws Exception {; + @DisplayName("Traces are equal length for 4 nucleotides") + @ParameterizedTest(name="Base: {0}") + @ValueSource(strings = { "A", "T", "C", "G" }) + void testGetTrace(String base) throws Exception { assertEquals(EXPECTED_TRACE_LENGTH, tracer.getTrace(base).length); } } From 3669911f7f109833607be9b09691fa104e9197b2 Mon Sep 17 00:00:00 2001 From: Richard Adams Date: Sun, 4 Jul 2021 10:56:56 +0100 Subject: [PATCH 108/599] more formatting --- .../nbio/core/TestAmbiguityCompoundSet.java | 6 ++---- .../nbio/core/sequence/io/ABITracerTest.java | 15 ++++++++++----- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/biojava-core/src/test/java/org/biojava/nbio/core/TestAmbiguityCompoundSet.java b/biojava-core/src/test/java/org/biojava/nbio/core/TestAmbiguityCompoundSet.java index 9fad78d7b0..714f418280 100644 --- a/biojava-core/src/test/java/org/biojava/nbio/core/TestAmbiguityCompoundSet.java +++ b/biojava-core/src/test/java/org/biojava/nbio/core/TestAmbiguityCompoundSet.java @@ -20,7 +20,8 @@ */ package org.biojava.nbio.core; -import org.biojava.nbio.core.exceptions.CompoundNotFoundException; +import static org.junit.jupiter.api.Assertions.assertEquals; + import org.biojava.nbio.core.sequence.DNASequence; import org.biojava.nbio.core.sequence.RNASequence; import org.biojava.nbio.core.sequence.compound.AmbiguityDNACompoundSet; @@ -31,9 +32,6 @@ import org.biojava.nbio.core.sequence.template.Sequence; import org.biojava.nbio.core.sequence.transcription.DNAToRNATranslator; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.DisplayName; - -import static org.junit.jupiter.api.Assertions.assertEquals; /** * A Test case for https://github.com/biojava/biojava/issues/344 diff --git a/biojava-core/src/test/java/org/biojava/nbio/core/sequence/io/ABITracerTest.java b/biojava-core/src/test/java/org/biojava/nbio/core/sequence/io/ABITracerTest.java index 3024940a07..be87905e04 100644 --- a/biojava-core/src/test/java/org/biojava/nbio/core/sequence/io/ABITracerTest.java +++ b/biojava-core/src/test/java/org/biojava/nbio/core/sequence/io/ABITracerTest.java @@ -21,17 +21,22 @@ package org.biojava.nbio.core.sequence.io; -import static org.junit.jupiter.api.Assertions.*; -import org.junit.jupiter.api.*; -import org.junit.jupiter.params.provider.ValueSource; -import org.junit.jupiter.params.ParameterizedTest; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.awt.image.BufferedImage; import java.io.File; import java.net.URL; -import java.util.Arrays; import org.biojava.nbio.core.exceptions.CompoundNotFoundException; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; /** * Test file 3730.ab1 is from https://github.com/biopython/biopython/blob/master/Tests/Abi/3730.ab1 The test data for From 704bda6c582d049dab109586fe0949e7b8e63ab2 Mon Sep 17 00:00:00 2001 From: Richard Adams Date: Sun, 4 Jul 2021 11:32:26 +0100 Subject: [PATCH 109/599] update junit3->junit4 test, remove doc references to ju3 --- .../nbio/structure/test/TestSECalignment.java | 16 +++++++++++----- .../test/align/ce/OptimalCECPMainTest.java | 8 +------- .../org/biojava/nbio/structure/ElementTest.java | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/TestSECalignment.java b/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/TestSECalignment.java index 6a9516251b..b8ec8ed89c 100644 --- a/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/TestSECalignment.java +++ b/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/TestSECalignment.java @@ -22,7 +22,14 @@ */ package org.biojava.nbio.structure.test; -import junit.framework.TestCase; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.io.InputStream; + +import org.biojava.nbio.core.util.StringManipulationHelper; import org.biojava.nbio.structure.Atom; import org.biojava.nbio.structure.align.StructureAlignment; import org.biojava.nbio.structure.align.StructureAlignmentFactory; @@ -33,9 +40,7 @@ import org.biojava.nbio.structure.align.xml.AFPChainXMLParser; import org.biojava.nbio.structure.test.align.fatcat.FlipAFPChainTest; import org.biojava.nbio.structure.test.util.StringManipulationTestsHelper; -import org.biojava.nbio.core.util.StringManipulationHelper; - -import java.io.InputStream; +import org.junit.Test; /** This test makes sure that the new representation of selenocysteins as SEC amino acids does not * affect the structure alignment results. @@ -43,8 +48,9 @@ * @author andreas * */ -public class TestSECalignment extends TestCase { +public class TestSECalignment { + @Test public void testOldSecOutput() throws Exception { String fileName = "/ce_1fdo.A_2iv2.X.out"; diff --git a/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/align/ce/OptimalCECPMainTest.java b/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/align/ce/OptimalCECPMainTest.java index bf7ee56be4..81eb35c9b9 100644 --- a/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/align/ce/OptimalCECPMainTest.java +++ b/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/align/ce/OptimalCECPMainTest.java @@ -46,13 +46,7 @@ public class OptimalCECPMainTest { private AtomCache cache = new AtomCache(); - /* (non-Javadoc) - * @see junit.framework.TestCase#setUp() - */ - @Before - public void setUp() throws Exception { - } - + /** * Basic test that alignPermuted(..., 0) is equivalent to a normal CE alignment. * diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/ElementTest.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/ElementTest.java index 81ce22d087..7dd8cda993 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/ElementTest.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/ElementTest.java @@ -21,7 +21,7 @@ package org.biojava.nbio.structure; -import junit.framework.TestCase; + import org.junit.Assert; import org.junit.Test; From 3cc243e6660acc3d0ca98320d1863a58841c04ca Mon Sep 17 00:00:00 2001 From: Richard Adams Date: Fri, 9 Jul 2021 18:34:48 +0100 Subject: [PATCH 110/599] example of new nested test, with bug in SequenceTools#permuteCyclic detected and fixed --- .../biojava/nbio/core/util/SequenceTools.java | 15 ++++ .../nbio/core/util/SequenceToolsTest.java | 74 +++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 biojava-core/src/test/java/org/biojava/nbio/core/util/SequenceToolsTest.java diff --git a/biojava-core/src/main/java/org/biojava/nbio/core/util/SequenceTools.java b/biojava-core/src/main/java/org/biojava/nbio/core/util/SequenceTools.java index f23d4e7417..2dd32af6c9 100644 --- a/biojava-core/src/main/java/org/biojava/nbio/core/util/SequenceTools.java +++ b/biojava-core/src/main/java/org/biojava/nbio/core/util/SequenceTools.java @@ -50,6 +50,21 @@ public static String permuteCyclic(String string, int n) { return String.valueOf(p); } + /** + * Improved implementation that is generally 10-100x faster, and fixes some edge-case bugs. + * @param string The string to permute + * @param n The number of characters to permute by; can be positive or negative; values greater than the length of the array are acceptable + * @return + */ + public static String permuteCyclic2(String string, int n) { + String toMutate = string + string; + n = n % string.length(); + if (n < 0) { + n = string.length() + n; + } + return toMutate.substring(n, n + string.length()); + } + /** * Cyclically permute {@code array} forward by {@code n} elements. * @param array The original result; will not be changed diff --git a/biojava-core/src/test/java/org/biojava/nbio/core/util/SequenceToolsTest.java b/biojava-core/src/test/java/org/biojava/nbio/core/util/SequenceToolsTest.java new file mode 100644 index 0000000000..819c40e9b0 --- /dev/null +++ b/biojava-core/src/test/java/org/biojava/nbio/core/util/SequenceToolsTest.java @@ -0,0 +1,74 @@ +package org.biojava.nbio.core.util; + +import static org.junit.jupiter.api.Assertions.assertAll; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.Random; + +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; + +class SequenceToolsTest { + + String randomDNA(int n) { + String[] nucs = new String[] { "A", "T", "C", "G" }; + Random r = new Random(); + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < n; i++) { + sb.append(nucs[r.nextInt(4)]); + } + return sb.toString(); + } + + @Nested + class PermuteCyclic { + + @ParameterizedTest + @CsvSource(value = { "ATCGT,1,TCGTA", "ATCGT,-1,TATCG", "ATCGT,0,ATCGT", "ATCGT,25,ATCGT","12345,1,23451" }) + void permuteCyclicBasic(String original, int n, String expected) { + assertEquals(expected, SequenceTools.permuteCyclic(original, n)); + } + + @ParameterizedTest + @CsvSource(value = { "ATCGT,CGTAT", "ATCGT,CGTAT" }) + @Disabled("fails with current implementation") + void permuteCycleIntMaxMin(String original, String expected) { + assertAll( + ()->assertEquals(expected, SequenceTools.permuteCyclic(original, Integer.MAX_VALUE)), + ()->assertEquals(expected, SequenceTools.permuteCyclic(original, Integer.MIN_VALUE)) + ); + } + + @ParameterizedTest + @CsvSource(value = { "ATCGT,CGTAT", "ATCGT,CGTAT" }) + @DisplayName("Edge case fixed") + void permuteCycleIntMaxMin2(String original, String expected) { + assertAll( + ()->assertEquals(expected, SequenceTools.permuteCyclic2(original, Integer.MAX_VALUE)), + ()->assertEquals(expected, SequenceTools.permuteCyclic2(original, Integer.MIN_VALUE)) + ); + } + + @Test + void permuteCyclicPerformance() { + String dna = randomDNA(10_000_000); + long start = System.currentTimeMillis(); + String rotated = SequenceTools.permuteCyclic(dna, 5_000_000); + long end = System.currentTimeMillis(); + System.err.println(end-start); + + long start2 = System.currentTimeMillis(); + String rotated2 = SequenceTools.permuteCyclic2(dna, 5_000_000); + long end2 = System.currentTimeMillis(); + System.err.println(end2-start2); + assertTrue((end-start)/(end2-start2) > 5); + } + + } + +} From 43fafd0a40a523422c1f8d16d7a2a0b504881a01 Mon Sep 17 00:00:00 2001 From: Richard Adams Date: Sat, 10 Jul 2021 21:41:39 +0100 Subject: [PATCH 111/599] add tests for other SequenceToolsMethods --- .gitignore | 1 + .../biojava/nbio/core/util/SequenceTools.java | 18 ++++ .../nbio/core/util/SequenceToolsTest.java | 95 +++++++++++++++++++ 3 files changed, 114 insertions(+) diff --git a/.gitignore b/.gitignore index 4c968aac08..89345576ab 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ .profile .settings .classpath +.factorypath .DS_Store .idea *.iml diff --git a/biojava-core/src/main/java/org/biojava/nbio/core/util/SequenceTools.java b/biojava-core/src/main/java/org/biojava/nbio/core/util/SequenceTools.java index 2dd32af6c9..61f7e44135 100644 --- a/biojava-core/src/main/java/org/biojava/nbio/core/util/SequenceTools.java +++ b/biojava-core/src/main/java/org/biojava/nbio/core/util/SequenceTools.java @@ -119,6 +119,23 @@ public static boolean isNucleotideSequence(String sequence) return true; } + /** + * Attempts to parse String as a DNA sequence first.
+ * If this fails it tries to parse as a ProteinSequence. + *
+ * This method does not attempt to create an RNASequence. + *

+ * Also, a sequence such as 'ATCGTA' which is both a + * peptide sequence and a DNA sequence, will always be returned + * as a DNA sequence. + *

+ *

+ * An empty string argument returns a ProteinSequence of length 0. + * A null argument throws a {@link NullPointerException} + * @param sequence + * @return Either a DNASequence or a ProteinSequence + * @throws CompoundNotFoundException + */ public Sequence getSequenceFromString(String sequence) throws CompoundNotFoundException { @@ -126,6 +143,7 @@ public Sequence getSequenceFromString(String sequence) throws CompoundNotFoun return new DNASequence(sequence); } else { return new ProteinSequence(sequence); + } } diff --git a/biojava-core/src/test/java/org/biojava/nbio/core/util/SequenceToolsTest.java b/biojava-core/src/test/java/org/biojava/nbio/core/util/SequenceToolsTest.java index 819c40e9b0..420e574c28 100644 --- a/biojava-core/src/test/java/org/biojava/nbio/core/util/SequenceToolsTest.java +++ b/biojava-core/src/test/java/org/biojava/nbio/core/util/SequenceToolsTest.java @@ -1,17 +1,25 @@ package org.biojava.nbio.core.util; +import static org.junit.Assert.assertThrows; import static org.junit.jupiter.api.Assertions.assertAll; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.Random; +import org.biojava.nbio.core.exceptions.CompoundNotFoundException; +import org.biojava.nbio.core.sequence.ProteinSequence; +import org.biojava.nbio.core.sequence.template.Sequence; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; +import org.junit.jupiter.params.provider.EmptySource; +import org.junit.jupiter.params.provider.NullAndEmptySource; +import org.junit.jupiter.params.provider.NullSource; class SequenceToolsTest { @@ -68,7 +76,94 @@ void permuteCyclicPerformance() { System.err.println(end2-start2); assertTrue((end-start)/(end2-start2) > 5); } + } + + @Nested + class PercentNucleotideContent { + + @ParameterizedTest + @NullAndEmptySource + @DisplayName("percent nucleotide sequence returns 0 for null "+ + "or empty string") + void nucleotideContentInvalidValues(String empty){ + assertEquals(0, SequenceTools.percentNucleotideSequence(empty)); + } + + @Test + void nucleotideContentTest(){ + assertEquals(100, SequenceTools.percentNucleotideSequence("ATCGCAA")); + assertEquals(100, SequenceTools.percentNucleotideSequence("UUACG")); + assertEquals(100, SequenceTools.percentNucleotideSequence(randomDNA(1_000_000))); + assertEquals(50, SequenceTools.percentNucleotideSequence("123CCG")); + assertEquals(66, SequenceTools.percentNucleotideSequence("12TTAC")); assertEquals(0, SequenceTools.percentNucleotideSequence(" HH")); + assertEquals(0, SequenceTools.percentNucleotideSequence("actg")); + } + + @Test + void isNucleotideSequence () { + assertTrue(SequenceTools.isNucleotideSequence("AACGAA")); + assertFalse(SequenceTools.isNucleotideSequence("aacgaa")); + assertFalse(SequenceTools.isNucleotideSequence(" HH")); + } + @ParameterizedTest + @NullAndEmptySource + @DisplayName("isNucleotide is false for null "+ + "or empty string") + void isnucleotideInvalidValues(String empty){ + assertFalse(SequenceTools.isNucleotideSequence(empty)); + } } + @Nested + @DisplayName("SequenceFromString") + class SequenceFromString{ + SequenceTools tools = new SequenceTools(); + @Test + void acceptsUpperCaseDNA() throws CompoundNotFoundException { + Sequencenuc = tools.getSequenceFromString("ATCG"); + assertEquals(4, nuc.getLength()); + } + + @Test + void acceptsLowerCaseDNA() throws CompoundNotFoundException { + Sequencenuc = tools.getSequenceFromString("atcg"); + assertEquals(4, nuc.getLength()); + } + + @Test + void rejectsRNA()throws CompoundNotFoundException { + assertThrows(CompoundNotFoundException.class, + ()->tools.getSequenceFromString("AUCG")); + } + + @Test + void acceptsSingleLetterProtein()throws CompoundNotFoundException { + Sequence protein = tools.getSequenceFromString("HYDESS"); + assertEquals(6, protein.getLength()); + } + + @Test + void interpets3LetterAACodeAsSingleLetter()throws CompoundNotFoundException { + Sequence protein = tools.getSequenceFromString("AlaGlySer"); + assertEquals(9, protein.getLength()); + } + + @EmptySource + @ParameterizedTest + @DisplayName("empty string return 0-length protein sequence") + void emptyString(String empty) throws CompoundNotFoundException{ + Sequence protein = tools.getSequenceFromString(empty); + assertEquals(0, protein.getLength()); + assertTrue(protein instanceof ProteinSequence); + } + + @NullSource + @ParameterizedTest + @DisplayName("null string throws NPE") + void nullString(String nullStr) throws CompoundNotFoundException{ + assertThrows(NullPointerException.class, + ()-> tools.getSequenceFromString(nullStr)); + } + } } From 190b55fc016fe78a9d0d11295e2fbe03d5e146c9 Mon Sep 17 00:00:00 2001 From: Richard Adams Date: Wed, 21 Jul 2021 23:08:28 +0100 Subject: [PATCH 112/599] padleft/right tests --- .../core/util/StringManipulationHelper.java | 47 ++++++++++++++----- 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/biojava-core/src/main/java/org/biojava/nbio/core/util/StringManipulationHelper.java b/biojava-core/src/main/java/org/biojava/nbio/core/util/StringManipulationHelper.java index f8aef6b35e..ca7edcb3b2 100644 --- a/biojava-core/src/main/java/org/biojava/nbio/core/util/StringManipulationHelper.java +++ b/biojava-core/src/main/java/org/biojava/nbio/core/util/StringManipulationHelper.java @@ -23,6 +23,19 @@ */ package org.biojava.nbio.core.util; +import java.io.BufferedReader; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.AbstractCollection; +import java.util.Iterator; +import java.util.Scanner; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.w3c.dom.Document; @@ -31,14 +44,6 @@ import org.w3c.dom.Node; import org.xml.sax.SAXException; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; -import java.io.*; -import java.util.AbstractCollection; -import java.util.Iterator; -import java.util.Scanner; - /** * A utility class for common {@link String} manipulation tasks. @@ -62,10 +67,6 @@ private StringManipulationHelper() { // to prevent instantiation } - - - - /** * @author andreas * @param stream @@ -174,14 +175,36 @@ public static boolean equalsToXml(String expected, String actual) { throw new UnsupportedOperationException("not yet implemented"); } + /** + * Adds padding to left of supplied string + * @param s The String to pad + * @param n an integer >= 1 + * @return The left-padded string. + * @throws IllegalArgumentException if n <= 0 + */ public static String padLeft(String s, int n) { + validatePadding(n); return String.format("%1$" + n + "s", s); } + /** + * Adds padding to right of supplied string + * @param s The String to pad + * @param n an integer >= 1 + * @return The right-padded string. + * @throws IllegalArgumentException if n <= 0 + */ public static String padRight(String s, int n) { + validatePadding(n); return String.format("%1$-" + n + "s", s); } + private static void validatePadding(int n) { + if (n <=0 ) { + throw new IllegalArgumentException("padding must be >= 1"); + } + } + public static String join(AbstractCollection s, String delimiter) { if (s == null || s.isEmpty()) return ""; Iterator iter = s.iterator(); From fda5184389db3e05b9d825e03ab0049b958af60a Mon Sep 17 00:00:00 2001 From: Richard Adams Date: Thu, 22 Jul 2021 09:12:01 +0100 Subject: [PATCH 113/599] tests and docs for convertStreamToString --- .../core/util/StringManipulationHelper.java | 22 +++-- .../util/StringManipulationHelperTest.java | 83 +++++++++++++++++++ 2 files changed, 97 insertions(+), 8 deletions(-) create mode 100644 biojava-core/src/test/java/org/biojava/nbio/core/util/StringManipulationHelperTest.java diff --git a/biojava-core/src/main/java/org/biojava/nbio/core/util/StringManipulationHelper.java b/biojava-core/src/main/java/org/biojava/nbio/core/util/StringManipulationHelper.java index ca7edcb3b2..88f100b4d2 100644 --- a/biojava-core/src/main/java/org/biojava/nbio/core/util/StringManipulationHelper.java +++ b/biojava-core/src/main/java/org/biojava/nbio/core/util/StringManipulationHelper.java @@ -68,9 +68,18 @@ private StringManipulationHelper() { } /** + * Converts an InputStream of text to a String, closing the stream + * before returning. + *