Package org.rcsb.cif

Class CifIO


  • public class CifIO
    extends Object
    Collection of IO operations to retrieve, process, and write CIF files. All read and write operations are thread-safe. The data model (i.e. CifFile, Block, Category, and Column) is immutable to the user but maintains some internal state to improve performance. Therefore, multi-threaded access to data of one CifFile is not safe and should be avoided.
    • Constructor Detail

      • CifIO

        public CifIO()
    • Method Detail

      • readById

        public static CifFile readById​(String pdbId)
                                throws IOException
        Read a CifFile from web. Refine the address via CifOptions.CifOptionsBuilder.fetchUrl(String). Otherwise binaryCIF will be loaded.
        Parameters:
        pdbId - the pdbId which should be fetched from the web - the library will determine whether the file is gzipped or plain information and whether it is in binary format (after resolving GZIP if needed) or text the appropriate reader will be chosen automatically
        Returns:
        a CifFile instance
        Throws:
        IOException - thrown when reading fails
      • readById

        public static CifFile readById​(String pdbId,
                                       CifOptions options)
                                throws IOException
        Read a CifFile from web. Refine the address via CifOptions.CifOptionsBuilder.fetchUrl(String). Otherwise binaryCIF will be loaded.
        Parameters:
        pdbId - the pdbId which should be fetched from the web - the library will determine whether the file is gzipped or plain information and whether it is in binary format (after resolving GZIP if needed) or text the appropriate reader will be chosen automatically
        options - CifOptions for the reading process
        Returns:
        a CifFile instance
        Throws:
        IOException - thrown when reading fails
      • readFromURL

        public static CifFile readFromURL​(URL url)
                                   throws IOException
        Read a CifFile from a given URL.
        Parameters:
        url - the URL from which to read - the library will determine whether the file is gzipped or plain information and whether it is in binary format (after resolving GZIP if needed) or text the appropriate reader will be chosen automatically
        Returns:
        a CifFile instance
        Throws:
        IOException - thrown when reading fails
      • readFromURL

        public static CifFile readFromURL​(URL url,
                                          CifOptions options)
                                   throws IOException
        Read a CifFile from a given URL.
        Parameters:
        url - the URL from which to read - the library will determine whether the file is gzipped or plain information and whether it is in binary format (after resolving GZIP if needed) or text the appropriate reader will be chosen automatically
        options - CifOptions for the reading process
        Returns:
        a CifFile instance
        Throws:
        IOException - thrown when reading fails
      • readFromPath

        public static CifFile readFromPath​(Path path)
                                    throws IOException
        Read a CifFile from a given Path.
        Parameters:
        path - the Path from which to read - the library will determine whether the file is gzipped or plain information and whether it is in binary format (after resolving GZIP if needed) or text the appropriate reader will be chosen automatically
        Returns:
        a CifFile instance
        Throws:
        IOException - thrown when reading fails
      • readFromPath

        public static CifFile readFromPath​(Path path,
                                           CifOptions options)
                                    throws IOException
        Read a CifFile from a given Path.
        Parameters:
        path - the Path from which to read - the library will determine whether the file is gzipped or plain information and whether it is in binary format (after resolving GZIP if needed) or text the appropriate reader will be chosen automatically
        options - CifOptions for the reading process
        Returns:
        a CifFile instance
        Throws:
        IOException - thrown when reading fails
      • readFromInputStream

        public static CifFile readFromInputStream​(InputStream inputStream)
                                           throws IOException
        Read a CifFile from a given InputStream.
        Parameters:
        inputStream - the InputStream to process - the library will determine whether the file is gzipped or plain information and whether it is in binary format (after resolving GZIP if needed) or text - the appropriate reader will be chosen automatically
        Returns:
        a CifFile instance
        Throws:
        IOException - thrown when reading fails
      • readFromInputStream

        public static CifFile readFromInputStream​(InputStream inputStream,
                                                  CifOptions options)
                                           throws IOException
        Read a CifFile from a given InputStream.
        Parameters:
        inputStream - the InputStream to process - the library will determine whether the file is gzipped or plain information and whether it is in binary format (after resolving GZIP if needed) or text - the appropriate reader will be chosen automatically
        options - CifOptions for the reading process
        Returns:
        a CifFile instance
        Throws:
        IOException - thrown when reading fails
      • writeBinary

        public static void writeBinary​(CifFile cifFile,
                                       Path outputFile)
                                throws IOException
        Write a binary CifFile to a given Path.
        Parameters:
        cifFile - the CifFile to process
        outputFile - the Path where the content should be written
        Throws:
        IOException - thrown when writing fails
      • writeBinary

        public static byte[] writeBinary​(CifFile cifFile)
                                  throws IOException
        Convert a CifFile to its binary byte[] representation.
        Parameters:
        cifFile - the CifFile to process
        Returns:
        a byte[] representing the information to write
        Throws:
        IOException - thrown when writing fails
      • writeBinary

        public static byte[] writeBinary​(CifFile cifFile,
                                         CifOptions options)
                                  throws IOException
        Convert a CifFile to its binary byte[] representation.
        Parameters:
        cifFile - the CifFile to process
        options - CifOptions for the writing process
        Returns:
        a byte[] representing the information to write
        Throws:
        IOException - thrown when writing fails
      • writeText

        public static void writeText​(CifFile cifFile,
                                     Path outputFile)
                              throws IOException
        Write a text CifFile to a given Path.
        Parameters:
        cifFile - the CifFile to process
        outputFile - the Path where the content should be written
        Throws:
        IOException - thrown when writing fails
      • writeText

        public static byte[] writeText​(CifFile cifFile)
                                throws IOException
        Convert a CifFile to its text byte[] representation.
        Parameters:
        cifFile - the CifFile to process
        Returns:
        a byte[] representing the information to write
        Throws:
        IOException - thrown when conversion fails
      • writeText

        public static byte[] writeText​(CifFile cifFile,
                                       CifOptions options)
                                throws IOException
        Convert a CifFile to its text byte[] representation.
        Parameters:
        cifFile - the CifFile to process
        options - CifOptions for the writing process
        Returns:
        a byte[] representing the information to write
        Throws:
        IOException - thrown when conversion fails