public static double angle(Atom a, Atom b) { Vector3D va = new Vector3D(a.getX(), a.getY(), a.getZ()); Vector3D vb = new Vector3D(b.getX(), b.getY(), b.getZ()); return Vector3D.AngleBetween(va, vb); }
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; }
public static Atom add(Atom a, Atom b) { Atom c = new Atom(); c.setX(a.getX() + b.getX()); c.setY(a.getY() + b.getY()); c.setZ(a.getZ() + b.getZ()); return c; }
public static 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); }
public static double amount(Atom a) { return Math.Sqrt(scalarProduct(a, a)); }
public static Atom vectorProduct(Atom a, Atom b) { Atom c = new Atom(); 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; }
public static Atom unitVector(Atom a) { double amnt = amount(a); double[] coords = new double[3]; coords[0] = a.getX() / amnt; coords[1] = a.getY() / amnt; coords[2] = a.getZ() / amnt; a.setCoords(coords); return a; }
public static double torsionAngle(Atom a, Atom b, Atom c, Atom d) { Atom ab = subtract(a, b); Atom cb = subtract(c, b); Atom bc = subtract(b, c); Atom dc = subtract(d, c); Atom abc = vectorProduct(ab, cb); Atom bcd = vectorProduct(bc, dc); double angl = angle(abc, bcd); /* calc the sign: */ Atom vecprod = vectorProduct(abc, bcd); double val = scalarProduct(cb, vecprod); if (val < 0.0) angl = -angl; return angl; }
public static Atom subtract(Atom a, Atom b) { Atom c = new Atom(); c.setX(a.getX() - b.getX()); c.setY(a.getY() - b.getY()); c.setZ(a.getZ() - b.getZ()); return c; }
public void setC(Atom c) { C = c; }
public static Atom invert(Atom a) { double[] coords = new double[] { 0.0, 0.0, 0.0 }; Atom zero = new Atom(); zero.setCoords(coords); return subtract(zero, a); }
public void setO(Atom o) { O = o; }
public void setN(Atom n) { N = n; }
public void setCB(Atom cB) { CB = cB; }
public void setCA(Atom cA) { CA = cA; }
public static double scalarProduct(Atom a, Atom b) { return a.getX() * b.getX() + a.getY() * b.getY() + a.getZ() * b.getZ(); }
private Structure loadStructure(string fileName) { Structure structure = new Structure(); int l = fileName.Length; structure.PDBCode = fileName.Substring(l-8,4); bool flag = false; string line = ""; StreamReader file = new StreamReader(fileName); Group g = new Group(); AminoAcid aa = new AminoAcid(); while ((line = file.ReadLine()) != null) { if (line.StartsWith("ATOM")) { try{ if (flag) { g.groupID = (line.ElementAt(21) - 65); aa.aaID = Convert.ToInt16(line.Substring(22, 4).Trim()); flag = false; } if (aa.aaID != (Convert.ToInt16(line.Substring(22, 4).Trim()))) { g.AA.Add(aa); aa = new AminoAcid(); aa.aaID = Convert.ToInt16(line.Substring(22, 4).Trim()); } if (g.groupID != (line.ElementAt(21) - 65)) { structure.Groups.Add(g); g = new Group(); g.groupID = (line.ElementAt(21) - 65); } Atom ob = new Atom(); ob.setX(Convert.ToDouble(line.Substring(30, 8).Trim())); ob.setY(Convert.ToDouble(line.Substring(38, 8).Trim())); ob.setZ(Convert.ToDouble(line.Substring(46, 8).Trim())); ob.Name = line.Substring(12, 3).Trim(); if (ob.Name.Equals("N")) aa.setN(ob); else if (ob.Name.Equals("CA")) aa.setCA(ob); else if (ob.Name.Equals("CB")) aa.setCB(ob); else if (ob.Name.Equals("O")) aa.setO(ob); else if (ob.Name.Equals("C")) aa.setC(ob); } catch (Exception) { } } } g.AA.Add(aa); structure.Groups.Add(g); file.Close(); count++; return structure; }