public Residue(Residue r,Chain c) : base(r) { number = r.number; atoms = new List<Atom>(); resName =r.resName; resID = r.resID; resChain = c; }
public static Molecule ReadPDB(TextReader sr) { Molecule mol = new Molecule (); bool mul_pos =false; Chain c = new Chain(); Residue r = new Residue(); lastresID =-1; lastchainID = "NONE"; nowresidue = -1; nowchain = -1; nbatom = 0; nbresidue=0; while((s=sr.ReadLine())!=null) { if(s.StartsWith("ENDMDL") && !mul_pos){ break; } if(s.StartsWith("MODEL")){ mul_pos =true; nbatom =0; int frame = int.Parse(s.Substring(10,4)); if(frame > 1) { Main.total_frames++; } } if(s.Length>4) { if(s.StartsWith("ATOM") || s.StartsWith("HETATM")) { if(Main.total_frames < 2){ chainID = s.Substring(21,1).Trim(); if(String.Compare(lastchainID,chainID) !=0){ if(s.StartsWith("ATOM")) c=new Chain("ATOM",chainID); else c=new Chain("HETATM",chainID); mol.Chains.Add(c); nowchain++; nowresidue =-1; lastchainID = chainID; } resID = int.Parse(s.Substring(22,4)); if((lastresID != resID)){ resname=s.Substring(17,3).Trim(); r = new Residue(resname,nbresidue,resID,c); mol.Chains[nowchain].Residues.Add(r); mol.Residues.Add(r); nowresidue++; nbresidue++; lastresID = resID; } atomname=s.Substring(12,4).Trim(); Atom at = new Atom(atomname,0.0f,nbatom,r,c); mol.Chains[nowchain].Residues[nowresidue].Atoms.Add(at); mol.Chains[nowchain].Atoms.Add(at); mol.Atoms.Add(at); } //Unity has a left-handed coordinates system while PDBs are right-handed //So we have to reverse the X coordinates //InvariantCulture necessary form cross-platform x=-float.Parse(s.Substring(30,8),System.Globalization.CultureInfo.InvariantCulture); y=float.Parse(s.Substring(38,8),System.Globalization.CultureInfo.InvariantCulture); z=float.Parse(s.Substring(46,8),System.Globalization.CultureInfo.InvariantCulture); vect = new Vector3(x,y,z); mol.Atoms[nbatom].Location[Main.total_frames-1] = vect; nbatom++; } } } sr.Close (); Debug.Log ("atoms:" + mol.Atoms.Count); return mol; }
public Residue(string resname,int num,int resid,Chain c) : base() { number = num; resName = resname; resID = resid; atoms = new List<Atom> (); resChain = c; }
public Molecule(Molecule m) : base(m) { chains = new List<Chain> (); residues = new List<Residue> (); atoms = new List<Atom> (); for (int i = 0; i<m.Chains.Count; i++) { Chain c= new Chain(m.Chains[i]); this.Chains.Add(c); for (int j = 0; j<m.Chains[i].Residues.Count; j++) { Residue r = new Residue(m.Chains[i].Residues[j],c); this.Chains[i].Residues.Add(r); this.Residues.Add(r); for (int k =0; k<m.Chains[i].Residues[j].Atoms.Count; k++) { Atom a = new Atom(m.Chains[i].Residues[j].Atoms[k],r,c); this.Chains[i].Residues[j].Atoms.Add(a); this.Chains[i].Atoms.Add(a); this.Atoms.Add(a); } } } bonds = new List<int[]> (m.Bonds); chainsBonds = new List<List<int>> (m.chainsBonds); color = m.color; type = m.type; render = m.render; select = m.select; energies = m.energies; }
public Chain(Chain c) : base(c) { chainID = c.chainID; type = c.type; residues = new List<Residue> (); atoms = new List<Atom> (); }
public Atom(Atom a,Residue r,Chain c) : base(a) { number = a.number; atomFullName = a.atomFullName; atomName = a.atomName; atomCharge = a.atomCharge; bonds = new List<int>(a.bonds); atomMass = a.atomMass; atomRadius = a.atomRadius; atomResidue = r; atomChain = c; }
public Atom(string name,float charge,int num,Residue r,Chain c) : base() { number = num; atomFullName = name; atomName = name [0].ToString(); atomCharge = charge; bonds = new List<int> (); int i =0; while((atomName != tableName[i]) && (i < tableName.Length)){ i++; } atomMass = tableMass [i]; atomRadius = tableRadius [i]; atomResidue = r; atomChain = c; }