473,421 Members | 1,695 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,421 software developers and data experts.

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...
Aug 2 '10 #1

✓ answered by chaarmann

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 getTransformedCoordinates". 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 getTransformedCoordinates(), 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:
Expand|Select|Wrap|Line Numbers
  1. Point3d tempRotated2CartesianCoordinates=new Point3d();
  2. 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:

Expand|Select|Wrap|Line Numbers
  1. HashMap<String, Point3d> transformedCoordinates = getTransformedCoordinates(iRes, jRes, left, right, centre);
  2. if (transformedCoordinates == null) System.out.println("Error, null returned. Please verify passed arguments");
  3.  
  4. Point3d point = transformedCoordinates.get("myKey"); // exchange myKey with a key the hashmap has. You can get them all with transformedCoordinates.getKeys()
  5. if (point == null) System.out.println("Error, this key doesn't exist, choose another key");
  6. double x = point.x;
  7. System.out.println("the desired coordinate x=" + x);
  8. // retrieve y and z accordingly
  9.  

6 2665
chaarmann
785 Expert 512MB
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.
Aug 3 '10 #2
Dheeraj Joshi
1,123 Expert 1GB
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
Aug 4 '10 #3
package gmbp;

/**

*
*/


import java.io.BufferedReader;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.TreeMap;

import javax.vecmath.Point3d;
import gmbp.RoTrans;

import owl.core.*;
import owl.core.structure.Pdb;
import owl.core.structure.Template;
import owl.core.structure.TemplateList;
import owl.core.structure.PdbLoadError;
import owl.core.structure.PdbasePdb;
import owl.core.structure.Residue;
import owl.core.util.FileTypeGuesser;
import gmbpModels.*;
import gmbp.CMPdb_svoxel_singleRes;
import gmbp.RoTrans;

/**
* @author shalini
*
*/
public class InterChainContacts {

/**
* @param args
* @throws ModelConstructionError
* @throws IOException
*/
public static void main(String[] args) throws IOException, ModelConstructionError {
// 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(inputFile));
String proteinId;




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

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

// String inFile=inputDir+proteinId+".pdb";
Model mod1=loadAFile (proteinId, contactType, cutOff, pdbChainCode1, minSeqSep, maxSeqSep, proteinId);
Model mod2=loadAFile (proteinId, contactType, cutOff, pdbChainCode2, minSeqSep, maxSeqSep, proteinId);
interChainContacts = getAllInterChainContacts(mod1, mod2);
}

PrintWriter InterchainContactsOut = new PrintWriter(new File(outputDir, "InterchainContactsOut.txt"));// prints the inter chain contacts



in.close();

for (String key: interChainContacts.keySet())
{
for (int key2: interChainContacts.get(key).keySet())
{
System.out.println(key+" "+key2+" "+interChainContacts.get(key).get(key2).getAtomsMa p().get("CA").getCoords().x+" "+interChainContacts.get(key).get(key2).getAtomsMa p().get("CA").getCoords().y+" "+interChainContacts.get(key).get(key2).getAtomsMa p().get("CA").getCoords().z);

}
}
}


// catch (PdbLoadError e) {
// System.err.println(e.getMessage());
// }
//

//
// RoTrans roTransObject=new RoTrans(interChainContacts);
//
// HashMap<String, HashMap<String, Point3d>> transformedInterChainContacts=roTransObject.return AllTransformedContacts(interChainContacts);
//


// HashMap<String, TreeMap<Integer, Point3d>> InterChainContacts= new HashMap<String, TreeMap<Integer, Point3d>>();
// InterChainContacts = getAllInterChainContacts(mod1, mod2);







public static Model loadAFile (String proteinId, String contactType, double cutOff, String pdbChainCode, int minSeqSep, int maxSeqSep, String pdbCode) throws FileNotFoundException, IOException, ModelConstructionError
{

// int fileType = FileTypeGuesser.guessFileType(new File(inFile));
Model mod;
//System.out.println(proteinId);
//System.out.println("/home/akshinta/Desktop/"+proteinId+".cif");
File cifFile = new File("/home/akshinta/Desktop/"+proteinId+".cif");
mod = new PdbFtpModel(cifFile, contactType, cutOff, minSeqSep, maxSeqSep);
mod.load(pdbChainCode, 1);
System.out.println(mod.getSequence());
System.out.println("Model Loaded Successfully");



// mod = new PdbFtpModel(pdbCode, contactType, cutOff, minSeqSep, maxSeqSep);
// mod.load("A", 1);
// switch(fileType)
// {
// case FileTypeGuesser.PDB_FILE:
// mod = new PdbFileModel(inFile,contactType,cutOff,minSeqSep, minSeqSep);
// mod.load(pdbChainCode, 1);
// System.out.println(mod.getSequence());
// System.out.println("Model Loaded Successfully");
// break;
// case FileTypeGuesser.CASP_TS_FILE:
// mod = new PdbFileModel(inFile,contactType,cutOff,-1, -1);
// mod.load(pdbChainCode, 1);
// System.out.println("Model Loaded Successfully");
// break;
// case FileTypeGuesser.OWL_CM_FILE:
// mod = new ContactMapFileModel(inFile);
// System.out.println("Model Loaded Successfully");
// break;
// case FileTypeGuesser.CASP_RR_FILE:
// mod = new CaspRRFileModel(inFile);
// System.out.println("Model Loaded Successfully");
// break;
// case FileTypeGuesser.CIF_FILE:
// mod = new PdbFtpModel(pdbCode, contactType, cutOff, minSeqSep, maxSeqSep);
// mod.load("A", 1);
// break;
// default:
// mod = new PdbFileModel(inFile,contactType,cutOff,minSeqSep, maxSeqSep);
// System.err.println("Could not recognize file type of " + inFile);
// return null;
// }
return mod;
}

// static HashMap<String, TreeMap<Integer, Point3d>> getAllInterChainContacts(Model mod1, Model mod2)
// {
// HashMap<String, TreeMap<Integer, Point3d>> InterChainContacts=new HashMap<String, TreeMap<Integer, Point3d>> ();
// double x1, x2, y1, y2, z1, z2, dist;
// for (int i=1; i<=mod1.get3DCoordinates().getFullLength(); i++)
// {
// for (int j=1; j<=mod2.get3DCoordinates().getFullLength(); j++)
// {
//// System.out.println(x1+" "+x2+" "+y1+" "+y2+" "+z1+" "+z2);
// x1=mod1.get3DCoordinates().getResidue(i).getAtomsM ap().get("CA").getCoords().x;
// y1=mod1.get3DCoordinates().getResidue(i).getAtomsM ap().get("CA").getCoords().y;
// z1=mod1.get3DCoordinates().getResidue(i).getAtomsM ap().get("CA").getCoords().z;
// x2=mod2.get3DCoordinates().getResidue(j).getAtomsM ap().get("CA").getCoords().x;
// y2=mod2.get3DCoordinates().getResidue(j).getAtomsM ap().get("CA").getCoords().y;
// z2=mod2.get3DCoordinates().getResidue(j).getAtomsM ap().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> oneInterChainContact = new TreeMap<Integer, Point3d>();
// oneInterChainContact.put(i, mod1.get3DCoordinates().getResidue(i).getAtomsMap( ).get("CA").getCoords());
// oneInterChainContact.put(j, mod1.get3DCoordinates().getResidue(j).getAtomsMap( ).get("CA").getCoords());
// String str= i+"_"+j;
// InterChainContacts.put(str, oneInterChainContact);
// }
// }
// }
// return InterChainContacts;
// }

static HashMap<String, TreeMap<Integer, Residue>> getAllInterChainContacts(Model mod1, Model mod2)
{
HashMap<String, TreeMap<Integer, Residue>> InterChainContacts=new HashMap<String, TreeMap<Integer, Residue>> ();
double x1, x2, y1, y2, z1, z2, dist;
for (int i=1; i<=mod1.get3DCoordinates().getFullLength(); i++)
{
for (int j=1; j<=mod2.get3DCoordinates().getFullLength(); j++)
{
// System.out.println(x1+" "+x2+" "+y1+" "+y2+" "+z1+" "+z2);
x1=mod1.get3DCoordinates().getResidue(i).getAtomsM ap().get("CA").getCoords().x;
y1=mod1.get3DCoordinates().getResidue(i).getAtomsM ap().get("CA").getCoords().y;
z1=mod1.get3DCoordinates().getResidue(i).getAtomsM ap().get("CA").getCoords().z;
x2=mod2.get3DCoordinates().getResidue(j).getAtomsM ap().get("CA").getCoords().x;
y2=mod2.get3DCoordinates().getResidue(j).getAtomsM ap().get("CA").getCoords().y;
z2=mod2.get3DCoordinates().getResidue(j).getAtomsM ap().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> oneInterChainContact = new TreeMap<Integer, Residue>();
oneInterChainContact.put(i, mod1.get3DCoordinates().getResidue(i));
oneInterChainContact.put(j, mod1.get3DCoordinates().getResidue(j));
String str= i+"_"+j;
InterChainContacts.put(str, oneInterChainContact);
}
}
}
return InterChainContacts;

public static HashMap<String, Point3d> getTranslatedCoordinates(Residue iRes, Residue jRes, Object centre)
{
HashMap<String, Point3d> translatedCoordinates=new HashMap<String, Point3d>();
for (String key: jRes.getAtomsMap().keySet())
{
Point3d tempTranslatedCoords=new Point3d();
tempTranslatedCoords.x=jRes.getAtomsMap().get(key) .getCoords().x-iRes.getAtomsMap().get(centre).getCoords().x;
tempTranslatedCoords.y=jRes.getAtomsMap().get(key) .getCoords().y-iRes.getAtomsMap().get(centre).getCoords().y;
tempTranslatedCoords.z=jRes.getAtomsMap().get(key) .getCoords().z-iRes.getAtomsMap().get(centre).getCoords().z;
translatedCoordinates.put(key, tempTranslatedCoords);

}

return translatedCoordinates;
}


}

}

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

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

package gmbp;

import java.util.HashMap;
import java.util.TreeMap;

import javax.vecmath.Point3d;

import owl.core.structure.Atom;
import owl.core.structure.Pdb;
import owl.core.structure.PdbLoadError;
import owl.core.structure.PdbfilePdb;
import owl.core.structure.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=new PdbfilePdb ("/home/akshinta/Desktop/1BSM.pdb");
proteinToLoad.load(str, 1);
TreeMap<Integer, Residue> protein=new TreeMap<Integer, Residue>(proteinToLoad.getResidues());


// Residue iRes=protein.get(23);
// Residue jRes=protein.get(23);
//

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

TreeMap<Integer, HashMap<String, Point3d>> allTransformedCoordinates=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> transformedCoordinates=getTransformedCoordinates(i Res, jRes, left, right, centre);
//
// /*
// * These statements will print out some output for sanity check.
// */
//
// System.out.println(transformedCoordinates.get("C") .x+" "+transformedCoordinates.get("C").y+" "+transformedCoordinates.get("C").z);
// System.out.println(transformedCoordinates.get("N") .x+" "+transformedCoordinates.get("N").y+" "+transformedCoordinates.get("N").z);
//
//
//
// }
for (int i=1; i<=proteinToLoad.getSequence().length(); i++)
{
Residue iRes=protein.get(i);
Residue jRes=protein.get(i);
HashMap<String, Point3d> transformedCoordinates=getTransformedCoordinates(i Res, jRes, left, right, centre);
System.out.println(i+" "+"C"+" "+transformedCoordinates.get("C").x+" "+transformedCoordinates.get("C").y+" "+transformedCoordinates.get("C").z);
System.out.println(i+" "+"N"+" "+transformedCoordinates.get("N").x+" "+transformedCoordinates.get("N").y+" "+transformedCoordinates.get("N").z);
System.out.println(i+" "+"CA"+" "+transformedCoordinates.get("CA").x+" "+transformedCoordinates.get("CA").y+" "+transformedCoordinates.get("CA").z);
allTransformedCoordinates.put(i, transformedCoordinates);
}
}

public static HashMap<String, Point3d> getTransformedCoordinates(Residue iRes, Residue jRes, String left, String right, String centre)
{

int check=0;

check=checkForColinearity(iRes, left, right, centre);

if (check==1)
{
HashMap<String, Point3d> translatedCoordinates=getTranslatedCoordinates(iRe s, jRes, centre);

HashMap<String, Point3d> translatedSphericalCoordinates=cartesianToSpherica l(translatedCoordinates);

double omega1= getAngleOfRotation1(iRes, centre, right);

double omega2= getAngleOfRotation2(iRes, centre, right);

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

HashMap<String, Point3d> rotated1SphericalCoordinates=getRotated1SphericalC oordinates(translatedSphericalCoordinates, omega1, omega2);

HashMap<String, Point3d> rotated1CartesianCoordinates= sphericalToCartesian(rotated1SphericalCoordinates) ;

HashMap<String, Point3d> rotated2CartesianCoordinates= getRotated2CartesianCoordinates(rotated1CartesianC oordinates, omega3);

HashMap<String, Point3d> rotated2SphericalCoordinates= cartesianToSpherical(rotated2CartesianCoordinates) ;

return rotated2SphericalCoordinates;
}

else
{
System.out.println("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 checkForColinearity(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.getAtomsMap().get(left).getCoords().x;
y1=iRes.getAtomsMap().get(left).getCoords().y;
x2=iRes.getAtomsMap().get(right).getCoords().x;
y2=iRes.getAtomsMap().get(right).getCoords().y;
x3=iRes.getAtomsMap().get(centre).getCoords().x;
y3=iRes.getAtomsMap().get(centre).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> getTranslatedCoordinates(Residue iRes, Residue jRes, Object centre)
{
HashMap<String, Point3d> translatedCoordinates=new HashMap<String, Point3d>();
for (String key: jRes.getAtomsMap().keySet())
{
Point3d tempTranslatedCoords=new Point3d();
tempTranslatedCoords.x=jRes.getAtomsMap().get(key) .getCoords().x-iRes.getAtomsMap().get(centre).getCoords().x;
tempTranslatedCoords.y=jRes.getAtomsMap().get(key) .getCoords().y-iRes.getAtomsMap().get(centre).getCoords().y;
tempTranslatedCoords.z=jRes.getAtomsMap().get(key) .getCoords().z-iRes.getAtomsMap().get(centre).getCoords().z;
translatedCoordinates.put(key, tempTranslatedCoords);

}

return translatedCoordinates;

}




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

public static HashMap<String, Point3d> cartesianToSpherical(HashMap<String, Point3d> cartesianCoordinates)
{
HashMap<String, Point3d> sphericalCoordinates=new HashMap<String, Point3d>();
for (String key: cartesianCoordinates.keySet())
{
Point3d tempSphericalCoordinates=new Point3d();
tempSphericalCoordinates.x=Math.sqrt(Math.pow(cart esianCoordinates.get(key).x, 2)+Math.pow(cartesianCoordinates.get(key).y, 2)+Math.pow(cartesianCoordinates.get(key).z, 2));
tempSphericalCoordinates.y=Math.acos(cartesianCoor dinates.get(key).z/tempSphericalCoordinates.x);
tempSphericalCoordinates.z=Math.atan2(cartesianCoo rdinates.get(key).y, cartesianCoordinates.get(key).x);
sphericalCoordinates.put(key, tempSphericalCoordinates);
}
return sphericalCoordinates;
}




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

public static HashMap<String, Point3d> sphericalToCartesian(HashMap<String, Point3d> sphericalCoordinates)
{
HashMap<String, Point3d> cartesianCoordinates=new HashMap<String, Point3d>();
for (String key: sphericalCoordinates.keySet())
{
Point3d tempRotated1CartesianCoordinates=new Point3d();
tempRotated1CartesianCoordinates.x=sphericalCoordi nates.get(key).x*Math.sin(sphericalCoordinates.get (key).y)*Math.cos(sphericalCoordinates.get(key).z) ;
tempRotated1CartesianCoordinates.y=sphericalCoordi nates.get(key).x*Math.sin(sphericalCoordinates.get (key).y)*Math.sin(sphericalCoordinates.get(key).z) ;
tempRotated1CartesianCoordinates.z=sphericalCoordi nates.get(key).x*Math.cos(sphericalCoordinates.get (key).y);
cartesianCoordinates.put(key, tempRotated1CartesianCoordinates);
}
return cartesianCoordinates;
}



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

public static double getAngleOfRotation1(Residue iRes, String centre, String right)
{
double omega1=0;
HashMap<String, Point3d> translatedCoordinates=getTranslatedCoordinates(iRe s, iRes, centre);
HashMap<String, Point3d> translatedSphericalCoordinates=cartesianToSpherica l(translatedCoordinates);
omega1=Math.PI/2-translatedSphericalCoordinates.get(right).y;
return omega1;
}



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

public static double getAngleOfRotation2(Residue iRes, String centre, String right)
{
double omega2=0;
HashMap<String, Point3d> translatedCoordinates=getTranslatedCoordinates(iRe s, iRes, centre);
HashMap<String, Point3d> translatedSphericalCoordinates=cartesianToSpherica l(translatedCoordinates);
omega2=translatedSphericalCoordinates.get(right).z ;
return omega2;
}


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

public static double getAngleOfRotation3(Residue iRes, String centre, String right, String left, double omega1, double omega2)
{
double omega3=0;
HashMap<String, Point3d> translatedCoordinates=getTranslatedCoordinates(iRe s, iRes, centre);
HashMap<String, Point3d> translatedSphericalCoordinates=cartesianToSpherica l(translatedCoordinates);
HashMap<String, Point3d> rotated1SphericalCoordinates=getRotated1SphericalC oordinates(translatedSphericalCoordinates, omega1, omega2);
HashMap<String, Point3d> rotated1CartesianCoordinates=sphericalToCartesian( rotated1SphericalCoordinates);
omega3=Math.atan(rotated1CartesianCoordinates.get( left).y/rotated1CartesianCoordinates.get(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> getRotated1SphericalCoordinates(HashMap<String, Point3d> translatedSphericalCoordinates, double omega1, double omega2)
{
HashMap<String, Point3d> rotated1SphericalCoords=new HashMap<String, Point3d>();
for (String key: translatedSphericalCoordinates.keySet())
{
Point3d tempRotated1SphericalCoords=new Point3d();
tempRotated1SphericalCoords.x=translatedSphericalC oordinates.get(key).x;
tempRotated1SphericalCoords.y=translatedSphericalC oordinates.get(key).y+omega1;
tempRotated1SphericalCoords.z=translatedSphericalC oordinates.get(key).z-omega2;
rotated1SphericalCoords.put(key, tempRotated1SphericalCoords);
}
return rotated1SphericalCoords;
}




/*
* 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> getRotated2CartesianCoordinates(HashMap<String, Point3d> rotated1CartesianCoordinates, double omega3)
{
HashMap<String, Point3d> rotated2CartesianCoordinates=new HashMap<String, Point3d>();

for (String key: rotated1CartesianCoordinates.keySet())
{
Point3d tempRotated2CartesianCoordinates=new Point3d();
tempRotated2CartesianCoordinates.x=rotated1Cartesi anCoordinates.get(key).x;
tempRotated2CartesianCoordinates.y=rotated1Cartesi anCoordinates.get(key).y*Math.cos(omega3)-rotated1CartesianCoordinates.get(key).z*Math.sin(o mega3);
tempRotated2CartesianCoordinates.z=rotated1Cartesi anCoordinates.get(key).y*Math.sin(omega3)+rotated1 CartesianCoordinates.get(key).z*Math.cos(omega3);
rotated2CartesianCoordinates.put(key, tempRotated2CartesianCoordinates);
}
return rotated2CartesianCoordinates;
}










}
Aug 4 '10 #4
chaarmann
785 Expert 512MB
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.
Aug 4 '10 #5
static HashMap<String, TreeMap<Integer, Residue>> getAllInterChainContacts(Model mod1, Model mod2)
{
HashMap<String, TreeMap<Integer, Residue>> InterChainContacts=new HashMap<String, TreeMap<Integer, Residue>> ();
double x1, x2, y1, y2, z1, z2, dist;
for (int i=1; i<=mod1.get3DCoordinates().getFullLength(); i++)
{
for (int j=1; j<=mod2.get3DCoordinates().getFullLength(); j++)
{
// System.out.println(x1+" "+x2+" "+y1+" "+y2+" "+z1+" "+z2);
x1=mod1.get3DCoordinates().getResidue(i).getAtomsM ap().get("CA").getCoords().x;
y1=mod1.get3DCoordinates().getResidue(i).getAtomsM ap().get("CA").getCoords().y;
z1=mod1.get3DCoordinates().getResidue(i).getAtomsM ap().get("CA").getCoords().z;
x2=mod2.get3DCoordinates().getResidue(j).getAtomsM ap().get("CA").getCoords().x;
y2=mod2.get3DCoordinates().getResidue(j).getAtomsM ap().get("CA").getCoords().y;
z2=mod2.get3DCoordinates().getResidue(j).getAtomsM ap().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> oneInterChainContact = new TreeMap<Integer, Residue>();
oneInterChainContact.put(i, mod1.get3DCoordinates().getResidue(i));
oneInterChainContact.put(j, mod1.get3DCoordinates().getResidue(j));
String str= i+"_"+j;
InterChainContacts.put(str, oneInterChainContact);
}
}
}
return InterChainContacts;
}
}
this is the code i am using...

and now i need to call a function "getTransformedCoordinates"

From the following code...


public static HashMap<String, Point3d> getTransformedCoordinates(Residue iRes, Residue jRes, String left, String right, String centre)
{

int check=0;

check=checkForColinearity(iRes, left, right, centre);

if (check==1)
{
HashMap<String, Point3d> translatedCoordinates=getTranslatedCoordinates(iRe s, jRes, centre);

HashMap<String, Point3d> translatedSphericalCoordinates=cartesianToSpherica l(translatedCoordinates);

double omega1= getAngleOfRotation1(iRes, centre, right);

double omega2= getAngleOfRotation2(iRes, centre, right);

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

HashMap<String, Point3d> rotated1SphericalCoordinates=getRotated1SphericalC oordinates(translatedSphericalCoordinates, omega1, omega2);

HashMap<String, Point3d> rotated1CartesianCoordinates= sphericalToCartesian(rotated1SphericalCoordinates) ;

HashMap<String, Point3d> rotated2CartesianCoordinates= getRotated2CartesianCoordinates(rotated1CartesianC oordinates, omega3);

HashMap<String, Point3d> rotated2SphericalCoordinates= cartesianToSpherical(rotated2CartesianCoordinates) ;

return rotated2SphericalCoordinates;
}

else
{
System.out.println("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...
Aug 4 '10 #6
chaarmann
785 Expert 512MB
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 getTransformedCoordinates". 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 getTransformedCoordinates(), 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:
Expand|Select|Wrap|Line Numbers
  1. Point3d tempRotated2CartesianCoordinates=new Point3d();
  2. 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:

Expand|Select|Wrap|Line Numbers
  1. HashMap<String, Point3d> transformedCoordinates = getTransformedCoordinates(iRes, jRes, left, right, centre);
  2. if (transformedCoordinates == null) System.out.println("Error, null returned. Please verify passed arguments");
  3.  
  4. Point3d point = transformedCoordinates.get("myKey"); // exchange myKey with a key the hashmap has. You can get them all with transformedCoordinates.getKeys()
  5. if (point == null) System.out.println("Error, this key doesn't exist, choose another key");
  6. double x = point.x;
  7. System.out.println("the desired coordinate x=" + x);
  8. // retrieve y and z accordingly
  9.  
Aug 5 '10 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: dougjrs | last post by:
I have a HashMap that is storing form data that will later be inserted into a database. I have been able to create the HashMap just fine, but I wanted to be able to take my HashMap and just "dump"...
1
by: Christian Gollwitzer | last post by:
Hi, I'm trying to loop over the elements in a hashmap of the STL-implementation by SGI. The point is, that because the key/value pair is stored as std::pair in the COntainer, the code becomes...
1
by: Mark Wayne | last post by:
Is is possible to use TreeMap in the javascript <SCRIPT> portion of HTML? If so, how? Thanks, mark
4
by: David | last post by:
Hi, I have created the following HashMap class. class HashMap: public hash_map<string, string, HashString, HashStringCompare> { public: HashMap(): hash_map<string, string, HashString,...
2
by: xor | last post by:
I'm doing up a school project using java, and am a little new to it (I've worked with other languages for years though). I've seen code posted by the instructor using HashMap like this... ...
1
by: treeman | last post by:
I copied the example Compile is successful .net 2003 but i press button , nothing to show but the example has box show up, why ? where 's wrong?
0
by: Treeman | last post by:
I copied the example Compile is successful .net 2003 but i press button , nothing to show but the example has box show up, why ? where 's wrong?
0
by: Thiero | last post by:
I am a studend in programming and I find it difficult to use treemap, can any one help me on how to use treemap. Specially the purpose is to use treemap and give a list of students firstname...
3
by: millz | last post by:
I am trying to create a tree map within a TreeMap. Any help would be great. goes a bit like this: public class ChessImpl implements CHESS { private Map<String, Integer> name; ...
1
by: evelina | last post by:
Hello, I need help. I have the following hashmap: HashMap<HashMap<Dimension, Integer>, String> mapList = new HashMap<HashMap<Dimension, Integer>, String>(); I want to extract Dimesion from the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.