hashmap to treemap

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shalini1988
    New Member
    • Aug 2010
    • 3

    hashmap to treemap

    I wrote a code called "x" to just extract some information... (content:x,y,z coordinates)

    There is already another class called "y" in that there is a method called "k"... i should call this method in the code "x"...

    I tried all the possible ways... but it didnot work... the problem is in "y" the coordinates are stored in the form of hashmap. and in "x" the coordinates are stored in the form of treemap.

    Now is it possible to do something and call that method in this or not... or should i rewrite the entire code??

    I am just a beginner in java (biologist) and I dont knw how to do it...
  • chaarmann
    Recognized Expert Contributor
    • Nov 2007
    • 785

    #2
    TreeMap and HashMap both implement interface Map, so what's the problem if you use a method from this interface to retrieve the desired values? If you want to get the stored coordinates using "get(Object key)", it works with both classes without a coding difference!

    Without showing the corresponding parts of your code, I can't help figuring out your error and only guess wildly. Without seeing your code, nobody is able to answer your question whether to rewrite it or not.

    Are you really sure you "tried all possible ways"? Maybe we Experts know some more ways that you didn't try, so please tell us the ways you already tried and we can tell you the ones you forgot to try. I am sure one of these additional ways will lead you to the solution of your problem.

    Comment

    • Dheeraj Joshi
      Recognized Expert Top Contributor
      • Jul 2009
      • 1129

      #3
      Rewriting the code may not be just restricted to hashmap to treemap. It may also have some other changes too. Please post the code and we can help you then.

      Regards
      Dheeraj Joshi

      Comment

      • shalini1988
        New Member
        • Aug 2010
        • 3

        #4
        Here is the code

        package gmbp;

        /**

        *
        */


        import java.io.Buffere dReader;

        import java.io.File;
        import java.io.FileNot FoundException;
        import java.io.FileRea der;
        import java.io.FileWri ter;
        import java.io.IOExcep tion;
        import java.io.PrintWr iter;
        import java.sql.SQLExc eption;
        import java.util.HashM ap;
        import java.util.TreeM ap;

        import javax.vecmath.P oint3d;
        import gmbp.RoTrans;

        import owl.core.*;
        import owl.core.struct ure.Pdb;
        import owl.core.struct ure.Template;
        import owl.core.struct ure.TemplateLis t;
        import owl.core.struct ure.PdbLoadErro r;
        import owl.core.struct ure.PdbasePdb;
        import owl.core.struct ure.Residue;
        import owl.core.util.F ileTypeGuesser;
        import gmbpModels.*;
        import gmbp.CMPdb_svox el_singleRes;
        import gmbp.RoTrans;

        /**
        * @author shalini
        *
        */
        public class InterChainConta cts {

        /**
        * @param args
        * @throws ModelConstructi onError
        * @throws IOException
        */
        public static void main(String[] args) throws IOException, ModelConstructi onError {
        // TODO Auto-generated method stub
        double cutOff=8.0;
        String pdbChainCode1=" A";
        String pdbChainCode2=" B";
        //String pdbChainCode3=" P";
        String contactType="SC ";


        int minSeqSep = 1;
        int maxSeqSep = 50;

        String inputFile = "/project/StruPPi/usha/shalusha/cullpdb1_20";
        String outputDir = "/project/StruPPi/usha/shalusha/shalini5_cb8p0_ alledcullpdb_20 _logfile.txtges ";

        BufferedReader in = new BufferedReader( new FileReader(inpu tFile));
        String proteinId;




        HashMap<String, TreeMap<Integer , Residue>> interChainConta cts= new HashMap<String, TreeMap<Integer , Residue>>();

        while ((proteinId = in.readLine()) != null)
        {
        System.out.prin tln(proteinId);

        // String inFile=inputDir +proteinId+".pd b";
        Model mod1=loadAFile (proteinId, contactType, cutOff, pdbChainCode1, minSeqSep, maxSeqSep, proteinId);
        Model mod2=loadAFile (proteinId, contactType, cutOff, pdbChainCode2, minSeqSep, maxSeqSep, proteinId);
        interChainConta cts = getAllInterChai nContacts(mod1, mod2);
        }

        PrintWriter InterchainConta ctsOut = new PrintWriter(new File(outputDir, "InterchainCont actsOut.txt"));// prints the inter chain contacts



        in.close();

        for (String key: interChainConta cts.keySet())
        {
        for (int key2: interChainConta cts.get(key).ke ySet())
        {
        System.out.prin tln(key+" "+key2+" "+interChainCon tacts.get(key). get(key2).getAt omsMap().get("C A").getCoords() .x+" "+interChainCon tacts.get(key). get(key2).getAt omsMap().get("C A").getCoords() .y+" "+interChainCon tacts.get(key). get(key2).getAt omsMap().get("C A").getCoords() .z);

        }
        }
        }


        // catch (PdbLoadError e) {
        // System.err.prin tln(e.getMessag e());
        // }
        //

        //
        // RoTrans roTransObject=n ew RoTrans(interCh ainContacts);
        //
        // HashMap<String, HashMap<String, Point3d>> transformedInte rChainContacts= roTransObject.r eturnAllTransfo rmedContacts(in terChainContact s);
        //


        // HashMap<String, TreeMap<Integer , Point3d>> InterChainConta cts= new HashMap<String, TreeMap<Integer , Point3d>>();
        // InterChainConta cts = getAllInterChai nContacts(mod1, mod2);







        public static Model loadAFile (String proteinId, String contactType, double cutOff, String pdbChainCode, int minSeqSep, int maxSeqSep, String pdbCode) throws FileNotFoundExc eption, IOException, ModelConstructi onError
        {

        // int fileType = FileTypeGuesser .guessFileType( new File(inFile));
        Model mod;
        //System.out.prin tln(proteinId);
        //System.out.prin tln("/home/akshinta/Desktop/"+proteinId+".c if");
        File cifFile = new File("/home/akshinta/Desktop/"+proteinId+".c if");
        mod = new PdbFtpModel(cif File, contactType, cutOff, minSeqSep, maxSeqSep);
        mod.load(pdbCha inCode, 1);
        System.out.prin tln(mod.getSequ ence());
        System.out.prin tln("Model Loaded Successfully");



        // mod = new PdbFtpModel(pdb Code, contactType, cutOff, minSeqSep, maxSeqSep);
        // mod.load("A", 1);
        // switch(fileType )
        // {
        // case FileTypeGuesser .PDB_FILE:
        // mod = new PdbFileModel(in File,contactTyp e,cutOff,minSeq Sep, minSeqSep);
        // mod.load(pdbCha inCode, 1);
        // System.out.prin tln(mod.getSequ ence());
        // System.out.prin tln("Model Loaded Successfully");
        // break;
        // case FileTypeGuesser .CASP_TS_FILE:
        // mod = new PdbFileModel(in File,contactTyp e,cutOff,-1, -1);
        // mod.load(pdbCha inCode, 1);
        // System.out.prin tln("Model Loaded Successfully");
        // break;
        // case FileTypeGuesser .OWL_CM_FILE:
        // mod = new ContactMapFileM odel(inFile);
        // System.out.prin tln("Model Loaded Successfully");
        // break;
        // case FileTypeGuesser .CASP_RR_FILE:
        // mod = new CaspRRFileModel (inFile);
        // System.out.prin tln("Model Loaded Successfully");
        // break;
        // case FileTypeGuesser .CIF_FILE:
        // mod = new PdbFtpModel(pdb Code, contactType, cutOff, minSeqSep, maxSeqSep);
        // mod.load("A", 1);
        // break;
        // default:
        // mod = new PdbFileModel(in File,contactTyp e,cutOff,minSeq Sep, maxSeqSep);
        // System.err.prin tln("Could not recognize file type of " + inFile);
        // return null;
        // }
        return mod;
        }

        // static HashMap<String, TreeMap<Integer , Point3d>> getAllInterChai nContacts(Model mod1, Model mod2)
        // {
        // HashMap<String, TreeMap<Integer , Point3d>> InterChainConta cts=new HashMap<String, TreeMap<Integer , Point3d>> ();
        // double x1, x2, y1, y2, z1, z2, dist;
        // for (int i=1; i<=mod1.get3DCo ordinates().get FullLength(); i++)
        // {
        // for (int j=1; j<=mod2.get3DCo ordinates().get FullLength(); j++)
        // {
        //// System.out.prin tln(x1+" "+x2+" "+y1+" "+y2+" "+z1+" "+z2);
        // x1=mod1.get3DCo ordinates().get Residue(i).getA tomsMap().get(" CA").getCoords( ).x;
        // y1=mod1.get3DCo ordinates().get Residue(i).getA tomsMap().get(" CA").getCoords( ).y;
        // z1=mod1.get3DCo ordinates().get Residue(i).getA tomsMap().get(" CA").getCoords( ).z;
        // x2=mod2.get3DCo ordinates().get Residue(j).getA tomsMap().get(" CA").getCoords( ).x;
        // y2=mod2.get3DCo ordinates().get Residue(j).getA tomsMap().get(" CA").getCoords( ).y;
        // z2=mod2.get3DCo ordinates().get Residue(j).getA tomsMap().get(" CA").getCoords( ).z;
        //
        // dist=Math.sqrt( Math.pow((x1-x2), 2)+Math.pow((y1-y2), 2)+Math.pow((z1-z2), 2));
        // if (dist<=8.0)
        // {
        // TreeMap<Integer , Point3d> oneInterChainCo ntact = new TreeMap<Integer , Point3d>();
        // oneInterChainCo ntact.put(i, mod1.get3DCoord inates().getRes idue(i).getAtom sMap().get("CA" ).getCoords());
        // oneInterChainCo ntact.put(j, mod1.get3DCoord inates().getRes idue(j).getAtom sMap().get("CA" ).getCoords());
        // String str= i+"_"+j;
        // InterChainConta cts.put(str, oneInterChainCo ntact);
        // }
        // }
        // }
        // return InterChainConta cts;
        // }

        static HashMap<String, TreeMap<Integer , Residue>> getAllInterChai nContacts(Model mod1, Model mod2)
        {
        HashMap<String, TreeMap<Integer , Residue>> InterChainConta cts=new HashMap<String, TreeMap<Integer , Residue>> ();
        double x1, x2, y1, y2, z1, z2, dist;
        for (int i=1; i<=mod1.get3DCo ordinates().get FullLength(); i++)
        {
        for (int j=1; j<=mod2.get3DCo ordinates().get FullLength(); j++)
        {
        // System.out.prin tln(x1+" "+x2+" "+y1+" "+y2+" "+z1+" "+z2);
        x1=mod1.get3DCo ordinates().get Residue(i).getA tomsMap().get(" CA").getCoords( ).x;
        y1=mod1.get3DCo ordinates().get Residue(i).getA tomsMap().get(" CA").getCoords( ).y;
        z1=mod1.get3DCo ordinates().get Residue(i).getA tomsMap().get(" CA").getCoords( ).z;
        x2=mod2.get3DCo ordinates().get Residue(j).getA tomsMap().get(" CA").getCoords( ).x;
        y2=mod2.get3DCo ordinates().get Residue(j).getA tomsMap().get(" CA").getCoords( ).y;
        z2=mod2.get3DCo ordinates().get Residue(j).getA tomsMap().get(" CA").getCoords( ).z;

        dist=Math.sqrt( Math.pow((x1-x2), 2)+Math.pow((y1-y2), 2)+Math.pow((z1-z2), 2));
        if (dist<=8.0)
        {
        TreeMap<Integer , Residue> oneInterChainCo ntact = new TreeMap<Integer , Residue>();
        oneInterChainCo ntact.put(i, mod1.get3DCoord inates().getRes idue(i));
        oneInterChainCo ntact.put(j, mod1.get3DCoord inates().getRes idue(j));
        String str= i+"_"+j;
        InterChainConta cts.put(str, oneInterChainCo ntact);
        }
        }
        }
        return InterChainConta cts;

        public static HashMap<String, Point3d> getTranslatedCo ordinates(Resid ue iRes, Residue jRes, Object centre)
        {
        HashMap<String, Point3d> translatedCoord inates=new HashMap<String, Point3d>();
        for (String key: jRes.getAtomsMa p().keySet())
        {
        Point3d tempTranslatedC oords=new Point3d();
        tempTranslatedC oords.x=jRes.ge tAtomsMap().get (key).getCoords ().x-iRes.getAtomsMa p().get(centre) .getCoords().x;
        tempTranslatedC oords.y=jRes.ge tAtomsMap().get (key).getCoords ().y-iRes.getAtomsMa p().get(centre) .getCoords().y;
        tempTranslatedC oords.z=jRes.ge tAtomsMap().get (key).getCoords ().z-iRes.getAtomsMa p().get(centre) .getCoords().z;
        translatedCoord inates.put(key, tempTranslatedC oords);

        }

        return translatedCoord inates;
        }


        }

        }

        ///////////////////////////////////////////////

        And I want to call the the function "get transformedcoor dinates from the following code...

        package gmbp;

        import java.util.HashM ap;
        import java.util.TreeM ap;

        import javax.vecmath.P oint3d;

        import owl.core.struct ure.Atom;
        import owl.core.struct ure.Pdb;
        import owl.core.struct ure.PdbLoadErro r;
        import owl.core.struct ure.PdbfilePdb;
        import owl.core.struct ure.Residue;

        public class RoTrans {

        /**
        * @param args
        * @throws PdbLoadError
        */
        public static void main(String[] args) throws PdbLoadError {
        // TODO Auto-generated method stub

        String str="A";
        Pdb proteinToLoad=n ew PdbfilePdb ("/home/akshinta/Desktop/1BSM.pdb");
        proteinToLoad.l oad(str, 1);
        TreeMap<Integer , Residue> protein=new TreeMap<Integer , Residue>(protei nToLoad.getResi dues());


        // Residue iRes=protein.ge t(23);
        // Residue jRes=protein.ge t(23);
        //

        String centre="CA";
        String right="C";
        String left="N";

        TreeMap<Integer , HashMap<String, Point3d>> allTransformedC oordinates=new TreeMap<Integer , HashMap<String, Point3d>>();


        // /*
        // * This method will call the rotation translation framework and return the rotated translated coordinates for the
        // * j residue with respect to the centre as the i residue. In case we want the coordinates for the i residue itself,
        // * send the same residue to both i residue and j residue.
        // */
        //
        //
        // HashMap<String, Point3d> transformedCoor dinates=getTran sformedCoordina tes(iRes, jRes, left, right, centre);
        //
        // /*
        // * These statements will print out some output for sanity check.
        // */
        //
        // System.out.prin tln(transformed Coordinates.get ("C").x+" "+transformedCo ordinates.get(" C").y+" "+transformedCo ordinates.get(" C").z);
        // System.out.prin tln(transformed Coordinates.get ("N").x+" "+transformedCo ordinates.get(" N").y+" "+transformedCo ordinates.get(" N").z);
        //
        //
        //
        // }
        for (int i=1; i<=proteinToLoa d.getSequence() .length(); i++)
        {
        Residue iRes=protein.ge t(i);
        Residue jRes=protein.ge t(i);
        HashMap<String, Point3d> transformedCoor dinates=getTran sformedCoordina tes(iRes, jRes, left, right, centre);
        System.out.prin tln(i+" "+"C"+" "+transformedCo ordinates.get(" C").x+" "+transformedCo ordinates.get(" C").y+" "+transformedCo ordinates.get(" C").z);
        System.out.prin tln(i+" "+"N"+" "+transformedCo ordinates.get(" N").x+" "+transformedCo ordinates.get(" N").y+" "+transformedCo ordinates.get(" N").z);
        System.out.prin tln(i+" "+"CA"+" "+transformedCo ordinates.get(" CA").x+" "+transformedCo ordinates.get(" CA").y+" "+transformedCo ordinates.get(" CA").z);
        allTransformedC oordinates.put( i, transformedCoor dinates);
        }
        }

        public static HashMap<String, Point3d> getTransformedC oordinates(Resi due iRes, Residue jRes, String left, String right, String centre)
        {

        int check=0;

        check=checkForC olinearity(iRes , left, right, centre);

        if (check==1)
        {
        HashMap<String, Point3d> translatedCoord inates=getTrans latedCoordinate s(iRes, jRes, centre);

        HashMap<String, Point3d> translatedSpher icalCoordinates =cartesianToSph erical(translat edCoordinates);

        double omega1= getAngleOfRotat ion1(iRes, centre, right);

        double omega2= getAngleOfRotat ion2(iRes, centre, right);

        double omega3= getAngleOfRotat ion3(iRes, centre, right, left, omega1, omega2);

        HashMap<String, Point3d> rotated1Spheric alCoordinates=g etRotated1Spher icalCoordinates (translatedSphe ricalCoordinate s, omega1, omega2);

        HashMap<String, Point3d> rotated1Cartesi anCoordinates= sphericalToCart esian(rotated1S phericalCoordin ates);

        HashMap<String, Point3d> rotated2Cartesi anCoordinates= getRotated2Cart esianCoordinate s(rotated1Carte sianCoordinates , omega3);

        HashMap<String, Point3d> rotated2Spheric alCoordinates= cartesianToSphe rical(rotated2C artesianCoordin ates);

        return rotated2Spheric alCoordinates;
        }

        else
        {
        System.out.prin tln("The left right and centre atoms are colinear and can hence not be used to generate a framework.");
        HashMap <String, Point3d> NullHashMap=new HashMap <String, Point3d> ();
        return NullHashMap;
        }

        }


        /*
        * This function will check if the three atoms chosen are colinear and will not go ahead with the further computation.
        */

        public static int checkForColinea rity(Residue iRes, String left, String right, String centre)
        {
        double det=0, x1=0, x2=0, x3=0, y1=0, y2=0, y3=0;
        x1=iRes.getAtom sMap().get(left ).getCoords().x ;
        y1=iRes.getAtom sMap().get(left ).getCoords().y ;
        x2=iRes.getAtom sMap().get(righ t).getCoords(). x;
        y2=iRes.getAtom sMap().get(righ t).getCoords(). y;
        x3=iRes.getAtom sMap().get(cent re).getCoords() .x;
        y3=iRes.getAtom sMap().get(cent re).getCoords() .z;
        det=x1*y2-x1*y3-y1*x2+y1*x3+x2* y3-x3*y2;
        if (det==0)
        {
        return 0;
        }
        else
        {
        return 1;
        }
        }







        /*
        * This function returns the translated coordinates with the centre atom in the iRes is taken as the centre of the new
        * framework.
        */




        public static HashMap<String, Point3d> getTranslatedCo ordinates(Resid ue iRes, Residue jRes, Object centre)
        {
        HashMap<String, Point3d> translatedCoord inates=new HashMap<String, Point3d>();
        for (String key: jRes.getAtomsMa p().keySet())
        {
        Point3d tempTranslatedC oords=new Point3d();
        tempTranslatedC oords.x=jRes.ge tAtomsMap().get (key).getCoords ().x-iRes.getAtomsMa p().get(centre) .getCoords().x;
        tempTranslatedC oords.y=jRes.ge tAtomsMap().get (key).getCoords ().y-iRes.getAtomsMa p().get(centre) .getCoords().y;
        tempTranslatedC oords.z=jRes.ge tAtomsMap().get (key).getCoords ().z-iRes.getAtomsMa p().get(centre) .getCoords().z;
        translatedCoord inates.put(key, tempTranslatedC oords);

        }

        return translatedCoord inates;

        }




        /*
        * This function converts Cartesian Coordinates to the Spherical Coordinates.
        */

        public static HashMap<String, Point3d> cartesianToSphe rical(HashMap<S tring, Point3d> cartesianCoordi nates)
        {
        HashMap<String, Point3d> sphericalCoordi nates=new HashMap<String, Point3d>();
        for (String key: cartesianCoordi nates.keySet())
        {
        Point3d tempSphericalCo ordinates=new Point3d();
        tempSphericalCo ordinates.x=Mat h.sqrt(Math.pow (cartesianCoord inates.get(key) .x, 2)+Math.pow(car tesianCoordinat es.get(key).y, 2)+Math.pow(car tesianCoordinat es.get(key).z, 2));
        tempSphericalCo ordinates.y=Mat h.acos(cartesia nCoordinates.ge t(key).z/tempSphericalCo ordinates.x);
        tempSphericalCo ordinates.z=Mat h.atan2(cartesi anCoordinates.g et(key).y, cartesianCoordi nates.get(key). x);
        sphericalCoordi nates.put(key, tempSphericalCo ordinates);
        }
        return sphericalCoordi nates;
        }




        /*
        * This function converts Spherical Coordinates to the Cartesian Coordinates.
        */

        public static HashMap<String, Point3d> sphericalToCart esian(HashMap<S tring, Point3d> sphericalCoordi nates)
        {
        HashMap<String, Point3d> cartesianCoordi nates=new HashMap<String, Point3d>();
        for (String key: sphericalCoordi nates.keySet())
        {
        Point3d tempRotated1Car tesianCoordinat es=new Point3d();
        tempRotated1Car tesianCoordinat es.x=sphericalC oordinates.get( key).x*Math.sin (sphericalCoord inates.get(key) .y)*Math.cos(sp hericalCoordina tes.get(key).z) ;
        tempRotated1Car tesianCoordinat es.y=sphericalC oordinates.get( key).x*Math.sin (sphericalCoord inates.get(key) .y)*Math.sin(sp hericalCoordina tes.get(key).z) ;
        tempRotated1Car tesianCoordinat es.z=sphericalC oordinates.get( key).x*Math.cos (sphericalCoord inates.get(key) .y);
        cartesianCoordi nates.put(key, tempRotated1Car tesianCoordinat es);
        }
        return cartesianCoordi nates;
        }



        /*
        * This function returns the first angle of rotation
        */

        public static double getAngleOfRotat ion1(Residue iRes, String centre, String right)
        {
        double omega1=0;
        HashMap<String, Point3d> translatedCoord inates=getTrans latedCoordinate s(iRes, iRes, centre);
        HashMap<String, Point3d> translatedSpher icalCoordinates =cartesianToSph erical(translat edCoordinates);
        omega1=Math.PI/2-translatedSpher icalCoordinates .get(right).y;
        return omega1;
        }



        /*
        * This function returns the second angle of rotation
        */

        public static double getAngleOfRotat ion2(Residue iRes, String centre, String right)
        {
        double omega2=0;
        HashMap<String, Point3d> translatedCoord inates=getTrans latedCoordinate s(iRes, iRes, centre);
        HashMap<String, Point3d> translatedSpher icalCoordinates =cartesianToSph erical(translat edCoordinates);
        omega2=translat edSphericalCoor dinates.get(rig ht).z;
        return omega2;
        }


        /*
        * This function returns the third angle of rotation
        */

        public static double getAngleOfRotat ion3(Residue iRes, String centre, String right, String left, double omega1, double omega2)
        {
        double omega3=0;
        HashMap<String, Point3d> translatedCoord inates=getTrans latedCoordinate s(iRes, iRes, centre);
        HashMap<String, Point3d> translatedSpher icalCoordinates =cartesianToSph erical(translat edCoordinates);
        HashMap<String, Point3d> rotated1Spheric alCoordinates=g etRotated1Spher icalCoordinates (translatedSphe ricalCoordinate s, omega1, omega2);
        HashMap<String, Point3d> rotated1Cartesi anCoordinates=s phericalToCarte sian(rotated1Sp hericalCoordina tes);
        omega3=Math.ata n(rotated1Carte sianCoordinates .get(left).y/rotated1Cartesi anCoordinates.g et(left).z);
        return omega3;
        }


        /*
        * This function rotates all the atoms through the first and second angle so as to get the C-zero along the X axis.
        */

        public static HashMap<String, Point3d> getRotated1Sphe ricalCoordinate s(HashMap<Strin g, Point3d> translatedSpher icalCoordinates , double omega1, double omega2)
        {
        HashMap<String, Point3d> rotated1Spheric alCoords=new HashMap<String, Point3d>();
        for (String key: translatedSpher icalCoordinates .keySet())
        {
        Point3d tempRotated1Sph ericalCoords=ne w Point3d();
        tempRotated1Sph ericalCoords.x= translatedSpher icalCoordinates .get(key).x;
        tempRotated1Sph ericalCoords.y= translatedSpher icalCoordinates .get(key).y+ome ga1;
        tempRotated1Sph ericalCoords.z= translatedSpher icalCoordinates .get(key).z-omega2;
        rotated1Spheric alCoords.put(ke y, tempRotated1Sph ericalCoords);
        }
        return rotated1Spheric alCoords;
        }




        /*
        * This function rotates all the atoms through the third angle so as to get the N into the XZ plane.
        */

        public static HashMap<String, Point3d> getRotated2Cart esianCoordinate s(HashMap<Strin g, Point3d> rotated1Cartesi anCoordinates, double omega3)
        {
        HashMap<String, Point3d> rotated2Cartesi anCoordinates=n ew HashMap<String, Point3d>();

        for (String key: rotated1Cartesi anCoordinates.k eySet())
        {
        Point3d tempRotated2Car tesianCoordinat es=new Point3d();
        tempRotated2Car tesianCoordinat es.x=rotated1Ca rtesianCoordina tes.get(key).x;
        tempRotated2Car tesianCoordinat es.y=rotated1Ca rtesianCoordina tes.get(key).y* Math.cos(omega3 )-rotated1Cartesi anCoordinates.g et(key).z*Math. sin(omega3);
        tempRotated2Car tesianCoordinat es.z=rotated1Ca rtesianCoordina tes.get(key).y* Math.sin(omega3 )+rotated1Carte sianCoordinates .get(key).z*Mat h.cos(omega3);
        rotated2Cartesi anCoordinates.p ut(key, tempRotated2Car tesianCoordinat es);
        }
        return rotated2Cartesi anCoordinates;
        }










        }

        Comment

        • chaarmann
          Recognized Expert Contributor
          • Nov 2007
          • 785

          #5
          Dear Shalini1988,

          Can you please wrap code tags around your code? (The #-button in the message-editor). It not only looks nicer and provides a better overview (indentation!), but also shows line numbers! And then tell us at which line number your program crashed, along with the error message. (Or where it puts out unexpected results, along with the current and expected output).

          I parsed through your huge code a long time, but couldn't find anything wrong so far. So please help me by pointing me to the location of your problem! It also would greatly help if you only post the parts of the code that really matters, so I don't need to waste time. Remember, I am not getting paid for helping you, so make it as easy as possible for me, please.

          Comment

          • shalini1988
            New Member
            • Aug 2010
            • 3

            #6
            static HashMap<String, TreeMap<Integer , Residue>> getAllInterChai nContacts(Model mod1, Model mod2)
            {
            HashMap<String, TreeMap<Integer , Residue>> InterChainConta cts=new HashMap<String, TreeMap<Integer , Residue>> ();
            double x1, x2, y1, y2, z1, z2, dist;
            for (int i=1; i<=mod1.get3DCo ordinates().get FullLength(); i++)
            {
            for (int j=1; j<=mod2.get3DCo ordinates().get FullLength(); j++)
            {
            // System.out.prin tln(x1+" "+x2+" "+y1+" "+y2+" "+z1+" "+z2);
            x1=mod1.get3DCo ordinates().get Residue(i).getA tomsMap().get(" CA").getCoords( ).x;
            y1=mod1.get3DCo ordinates().get Residue(i).getA tomsMap().get(" CA").getCoords( ).y;
            z1=mod1.get3DCo ordinates().get Residue(i).getA tomsMap().get(" CA").getCoords( ).z;
            x2=mod2.get3DCo ordinates().get Residue(j).getA tomsMap().get(" CA").getCoords( ).x;
            y2=mod2.get3DCo ordinates().get Residue(j).getA tomsMap().get(" CA").getCoords( ).y;
            z2=mod2.get3DCo ordinates().get Residue(j).getA tomsMap().get(" CA").getCoords( ).z;

            dist=Math.sqrt( Math.pow((x1-x2), 2)+Math.pow((y1-y2), 2)+Math.pow((z1-z2), 2));
            if (dist<=8.0)
            {
            TreeMap<Integer , Residue> oneInterChainCo ntact = new TreeMap<Integer , Residue>();
            oneInterChainCo ntact.put(i, mod1.get3DCoord inates().getRes idue(i));
            oneInterChainCo ntact.put(j, mod1.get3DCoord inates().getRes idue(j));
            String str= i+"_"+j;
            InterChainConta cts.put(str, oneInterChainCo ntact);
            }
            }
            }
            return InterChainConta cts;
            }
            }
            this is the code i am using...

            and now i need to call a function "getTransformed Coordinates"

            From the following code...


            public static HashMap<String, Point3d> getTransformedC oordinates(Resi due iRes, Residue jRes, String left, String right, String centre)
            {

            int check=0;

            check=checkForC olinearity(iRes , left, right, centre);

            if (check==1)
            {
            HashMap<String, Point3d> translatedCoord inates=getTrans latedCoordinate s(iRes, jRes, centre);

            HashMap<String, Point3d> translatedSpher icalCoordinates =cartesianToSph erical(translat edCoordinates);

            double omega1= getAngleOfRotat ion1(iRes, centre, right);

            double omega2= getAngleOfRotat ion2(iRes, centre, right);

            double omega3= getAngleOfRotat ion3(iRes, centre, right, left, omega1, omega2);

            HashMap<String, Point3d> rotated1Spheric alCoordinates=g etRotated1Spher icalCoordinates (translatedSphe ricalCoordinate s, omega1, omega2);

            HashMap<String, Point3d> rotated1Cartesi anCoordinates= sphericalToCart esian(rotated1S phericalCoordin ates);

            HashMap<String, Point3d> rotated2Cartesi anCoordinates= getRotated2Cart esianCoordinate s(rotated1Carte sianCoordinates , omega3);

            HashMap<String, Point3d> rotated2Spheric alCoordinates= cartesianToSphe rical(rotated2C artesianCoordin ates);

            return rotated2Spheric alCoordinates;
            }

            else
            {
            System.out.prin tln("The left right and centre atoms are colinear and can hence not be used to generate a framework.");
            HashMap <String, Point3d> NullHashMap=new HashMap <String, Point3d> ();
            return NullHashMap;
            }

            }

            this is a part of big code i have sent in previous message...

            Comment

            • chaarmann
              Recognized Expert Contributor
              • Nov 2007
              • 785

              #7
              It's already very hard to figure out your comments between the code, because you don't use code tags. (Again, please use them). But I can't guess what's your code (the code you wrote/modified and which may have error) and what's the code that was already there (the code that you never touched and which most likely is correct). Can you please tell me?
              Also, because you didn't use code tags, I can't reference to any line number, so it will be difficult for you to figure out the line I am referring to .

              Anyway, let's look into it: You wrote: "and now i need to call a function getTransformedC oordinates". Where do you want to call it? And with what parameters? You were talking of retrieving coordinates, which you already retrieved as x1,y1,z1,x2,y2, z2 as double values. Does this code crash? If not, you probably mean how to retrieve the coordinates returned from getTransformedC oordinates(), right? This function retrieves a HashMap<String, Point3d>. That means, strings are the keys, and Point3d-instances are the values. As what the name says, your coordinates are stored inside the Point3d-instances. I don't know the class Point3d, but from it's usage I can derive how to access these coordinates from a snippet of your source code here:
              Code:
              Point3d tempRotated2CartesianCoordinates=new Point3d();
              tempRotated2CartesianCoordinates.x=rotated1Cartesi anCoordinates.get(key).x;
              The solution:
              So if you combine the things together, you need following code to access the coordinates inside the returned hashmap:

              Code:
              HashMap<String, Point3d> transformedCoordinates = getTransformedCoordinates(iRes, jRes, left, right, centre);
              if (transformedCoordinates == null) System.out.println("Error, null returned. Please verify passed arguments");
              
              Point3d point = transformedCoordinates.get("myKey"); // exchange myKey with a key the hashmap has. You can get them all with transformedCoordinates.getKeys()
              if (point == null) System.out.println("Error, this key doesn't exist, choose another key");
              double x = point.x;
              System.out.println("the desired coordinate x=" + x);
              // retrieve y and z accordingly

              Comment

              Working...