Problem To Convert Pdb Text File To Jmol Jar File
3
4
Entering edit mode
13.8 years ago
Hazelin ▴ 100

I have to read the co-ordinates of a 3D object from the text file that's from PDB and store it in an array and after storing the co-ordinates in the array, I need it to undergo some processes such as rotation & translation and finally, the final product would be a JAR file.

The trick here is that I need to store it in a JAR file so that I can view the final product in my visualizer (Jmol). How do I get about in doing that?

The following code here is the compression of a JAR file.

Is this of use?

import java.io.*;
import java.util.zip.*;

public class compress {
    public static void doit(String filein, String fileout)
    {
        FileInputStream fis = null;
        FileOutputStream fos = null;
        try {
            fis = new FileInputStream(filein);
            fos = new FileOutputStream(fileout);
            ZipOutputStream zos = new ZipOutputStream(fos);
            ZipEntry ze = new ZipEntry(filein);
            zos.putNextEntry(ze);
            final int BUFSIZ = 4096;
            byte inbuf[] = new byte[BUFSIZ];
            int n;
            while ((n = fis.read(inbuf)) != -1)
                zos.write(inbuf, 0, n);
            fis.close();
            fis = null;
            zos.close();
            fos = null;
        }
        catch (IOException e) {
            System.err.println(e);
        }
        finally {
            try {
                if (fis != null)
                    fis.close();
                if (fos != null)
                    fos.close();
                }
            catch (IOException e) { }
        }
    }

    public static void main(String args[])
    {
        if (args.length != 2)
        {
            System.err.println("missing filenames");
            System.exit(1);
        }
        if (args[0].equals(args[1]))
        {
            System.err.println("filenames are identical");
            System.exit(1);
        }

        doit(args[0], args[1]);
    }
}

Your help is greatly appreciated! :D I need to do this program in JAVA.

pdb java • 3.7k views
ADD COMMENT
0
Entering edit mode

I am sorry, but the question is not entirely clear to me... do I understand correctly that you like to rebuild the Jmol jar, to include one particular PDB entry?

ADD REPLY
0
Entering edit mode

Sorry for the lack of clarity. Actually, no. It's 2 PDB entries because I'm doing a superposition algorithm using JAVA. So the target will remain in array1 but the query in array2 will undergo transformation and so on, thus I need the final product/output to be shown in Jmol. Thank you!!

ADD REPLY
0
Entering edit mode

JAR files are used to package and distribute multiple java files as a single file. In fact they are nothing more than a zip archive with an extra directory in it. Therefore you would need to be a little more specific in just what type of JAR file you need.

ADD REPLY
2
Entering edit mode
13.8 years ago
Jussi ▴ 180

I'm not sure did I understand your requirements properly, but I would use some build tool (Ant, for example). You can create the files in Java and add them to the jar using build tool you your choise. Ant has a "Jar" task that can create or update the jar file for you:

<jar destfile="${dist}/lib/app.jar" update="true">
    <fileset dir="${build}/classes"
         excludes="**/Test.class"
    />
<fileset dir="${src}/resources"/>

[?]

It is better to use existing implementation rather than creating your own. For example, you have lots of code handling exceptions and closing streams safely, but still your fos stream is never closed.

ADD COMMENT
1
Entering edit mode
13.8 years ago

Not sure I understand what you want to be packaged.

However, see CreateJarfile here and the other samples about 'jar' here.

ADD COMMENT
1
Entering edit mode
13.8 years ago

I think it will good to add PDB files as such to 'resources' than converting PDB file to an object. I am afraid, if you convert PDB file to objects you again need to convert it back to native format before loading to JMol. And regarding the superposition part, as I explained in your earlier questions (1 and 2), you may perform the superposition part prior to load the PDB files to JMol.

ADD COMMENT

Login before adding your answer.

Traffic: 1514 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6