/** * calculate distance between two atoms. * * @param a * an Atom object * @param b * an Atom object * @return a double */ public static final double getDistance(Atom a, Atom b) { double x = a.getX() - b.getX(); double y = a.getY() - b.getY(); double z = a.getZ() - b.getZ(); double s = x * x + y * y + z * z; return Math.sqrt(s); }
/** * Will calculate the square of distances between two atoms. This will be * faster as it will not perform the final square root to get the actual * distance. Use this if doing large numbers of distance comparisons - it is * marginally faster than getDistance(). * * @param a * an Atom object * @param b * an Atom object * @return a double */ public static double getDistanceFast(Atom a, Atom b) { double x = a.getX() - b.getX(); double y = a.getY() - b.getY(); double z = a.getZ() - b.getZ(); return x * x + y * y + z * z; }
/** * Returns the rotation axis and angle in a single javax.vecmath.AxisAngle4d object * @return */ public AxisAngle4d getAxisAngle4d() { return new AxisAngle4d(rotationAxis.getX(),rotationAxis.getY(),rotationAxis.getZ(),theta); }
/** * Get the rotation matrix corresponding to a rotation about this axis * @param theta The amount to rotate * @return A 3x3 rotation matrix */ public Matrix getRotationMatrix(double theta) { if( rotationAxis == null) { // special case for pure translational axes return Matrix.identity(3, 3); } double x = rotationAxis.getX(); double y = rotationAxis.getY(); double z = rotationAxis.getZ(); double cos = Math.cos(theta); double sin = Math.sin(theta); double com = 1 - cos; return new Matrix(new double[][] { {com*x*x + cos, com*x*y+sin*z, com*x*z+-sin*y}, {com*x*y-sin*z, com*y*y+cos, com*y*z+sin*x}, {com*x*z+sin*y, com*y*z-sin*x, com*z*z+cos}, }); }
public Vector3d getVector3dScrewTranslation() { return new Vector3d(screwTranslation.getX(),screwTranslation.getY(),screwTranslation.getZ()); }
/** * Vector product (cross product). * * @param a * an Atom object * @param b * an Atom object * @return an Atom object */ public static final Atom vectorProduct(Atom a , Atom b){ Atom c = new AtomImpl(); c.setX( a.getY() * b.getZ() - a.getZ() * b.getY() ) ; c.setY( a.getZ() * b.getX() - a.getX() * b.getZ() ) ; c.setZ( a.getX() * b.getY() - a.getY() * b.getX() ) ; return c ; }
try{ PDBFileReader read=new PDBFileReader(); Structure pdb=read.getStructure(filename); System.out.println("PDB code :"+pdb.getPDBCode()); List chains=Collections.synchronizedList(new ArrayList()); chains=pdb.getChains(); for(Iterator iter=chains.iterator();iter.hasNext();){ Chain c=(Chain)(iter.next()); System.out.println("Chain :"+c.getName()+"\n"+"Seq aa :"+c.getAtomSequence()); for(int j=0;j<c.getAtomLength();j++){ for (int k=0; k < c.getAtomGroup(j).size(); k++ ){ Atom a=c.getAtomGroup(j).getAtom(k); System.out.println("Name : "+a.getName()+" X : "+a.getX()+" Y : "+a.getY()+" Z : "+a.getZ()); } }
/** * subtract two atoms ( a - b). * * @param a * an Atom object * @param b * an Atom object * @return n new Atom object representing the difference */ public static final Atom subtract(Atom a, Atom b) { Atom c = new AtomImpl(); c.setX( a.getX() - b.getX() ); c.setY( a.getY() - b.getY() ); c.setZ( a.getZ() - b.getZ() ); return c ; }
/** * Perform linear transformation s*X+B, and store the result in b * * @param s * Amount to scale x * @param x * Input coordinate * @param b * Vector to translate (will be modified) * @return b, after modification */ public static Atom scaleAdd(double s, Atom x, Atom b){ double xc = s*x.getX() + b.getX(); double yc = s*x.getY() + b.getY(); double zc = s*x.getZ() + b.getZ(); //Atom a = new AtomImpl(); b.setX(xc); b.setY(yc); b.setZ(zc); return b; }
/** * Returns the unit vector of vector a . * * @param a * an Atom object * @return an Atom object */ public static final Atom unitVector(Atom a) { double amount = amount(a) ; double[] coords = new double[3]; coords[0] = a.getX() / amount ; coords[1] = a.getY() / amount ; coords[2] = a.getZ() / amount ; a.setCoords(coords); return a; }
/** * Translates an atom object, given a Vector3d (i.e. the vecmath library * double-precision 3-d vector) * * @param atom * @param v */ public static final void translate (Atom atom, Vector3d v) { atom.setX(atom.getX()+v.x); atom.setY(atom.getY()+v.y); atom.setZ(atom.getZ()+v.z); }
/** * Returns the Vector that needs to be applied to shift a set of atoms to * the Centroid, if the centroid is already known * * @param atomSet * array of Atoms * @return the vector needed to shift the set of atoms to its geometric * center */ public static final Atom getCenterVector(Atom[] atomSet, Atom centroid){ double[] coords = new double[3]; coords[0] = 0 - centroid.getX(); coords[1] = 0 - centroid.getY(); coords[2] = 0 - centroid.getZ(); Atom shiftVec = new AtomImpl(); shiftVec.setCoords(coords); return shiftVec; }
private static Atom calcSimple_H(Atom c, Atom o, Atom n) { Atom h = Calc.subtract(c,o); double dist = Calc.getDistance(o,c); //System.out.println(dist); double x = n.getX() + h.getX() / dist; double y = n.getY() + h.getY() / dist; double z = n.getZ() + h.getZ() / dist; h.setX(x); h.setY(y); h.setZ(z); h.setName("H"); return h; }
/** * Multiply elements of a by s (in place) * * @param a * @param s * @return the modified a */ public static Atom scaleEquals(Atom a, double s) { double x = a.getX(); double y = a.getY(); double z = a.getZ(); x *= s; y *= s; z *= s; //Atom b = new AtomImpl(); a.setX(x); a.setY(y); a.setZ(z); return a; }
/** * Shift a vector. * * @param a * vector a * @param b * vector b */ public static final void shift(Atom a, Atom b){ Atom natom = add(a,b); double x = natom.getX(); double y = natom.getY() ; double z = natom.getZ(); a.setX(x); a.setY(y); a.setZ(z); }
/** * Multiply elements of a by s * * @param a * @param s * @return A new Atom with s*a */ public static Atom scale(Atom a, double s) { double x = a.getX(); double y = a.getY(); double z = a.getZ(); Atom b = new AtomImpl(); b.setX(x*s); b.setY(y*s); b.setZ(z*s); return b; }
/** * Transforms an atom object, given a Matrix4d (i.e. the vecmath library * double-precision 4x4 rotation+translation matrix). The transformation * Matrix must be a post-multiplication Matrix. * * @param atom * @param m */ public static final void transform (Atom atom, Matrix4d m) { Point3d p = new Point3d(atom.getX(),atom.getY(),atom.getZ()); m.transform(p); atom.setX(p.x); atom.setY(p.y); atom.setZ(p.z); }
/** * Rotate an Atom around a Matrix object. The rotation Matrix must be a * pre-multiplication Matrix. * * @param atom * atom to be rotated * @param m * rotation matrix to be applied to the atom */ public static final void rotate(Atom atom, Matrix m){ double x = atom.getX(); double y = atom.getY(); double z = atom.getZ(); double[][] ad = new double[][]{{x,y,z}}; Matrix am = new Matrix(ad); Matrix na = am.times(m); atom.setX(na.get(0,0)); atom.setY(na.get(0,1)); atom.setZ(na.get(0,2)); }