UnityMol  0.9.6-875
UnityMol viewer / In developement
SocketPDB.cs
Go to the documentation of this file.
1 
66 
67 
68  using UnityEngine;
69  using System.Collections;
70  using System.Collections.Generic;
71  using System.IO;
72  using System.Net;
73  using System;
74  //using System.Net.Sockets;
75 
77  using Cmd;
78  using Molecule.Control;
79  using Molecule.Model;
80 namespace ParseData.ParsePDB
81 {
82 
83  public class SocketPDB
84  {
85 
86  public List<float[]> alist=new List<float[]>();
87 
88  private List<AtomModel> typelist=new List<AtomModel>();
89 
90  public ArrayList clubLocationalist=new ArrayList();
91  private ArrayList clubRotationList =new ArrayList();
92  private string Atoms="";
93  private string Clubs="";
94  public float progress;
95  //private string id="";
96  public SocketPDB(string id)
97  {
98  loadPDB(id);
99  }
100 
101 
102 
103  public void loadPDB(string id)
104  {
105 
107  UnitySocket.Send(0);
108  UnitySocket.Send(id);
109  int num0=UnitySocket.ReceiveInt();
110  int num1=UnitySocket.ReceiveInt();
111  //print(num);
112 
113  Debug.Log(num0+"|"+num1);
114 
115  for(int k=0;k<num0+num1;k++)
116  {
117 
119  UnitySocket.Send(k+1);
120  if(k<num0)
121  {
122  string sonAtoms=UnitySocket.ReceiveString(60000);
123 
124  Atoms+=sonAtoms.Trim();
125 // Debug.Log("sonAtoms is: "+sonAtoms);
126 
127 
128  }
129 
130  else
131  {
132  string sonClubs=UnitySocket.ReceiveString(68000);
133  Clubs+=sonClubs.Trim();
134  }
135 
136  }
137  string [] sArray=Atoms.Split('$');
138  Debug.Log("length:"+sArray.Length);
139  for(int i=0;i<sArray.Length-1;i++)
140  {
141  if(sArray[i]=="")continue;
142  string [] ssArray=sArray[i].Split('#');
143 
144 // Debug.Log(i+"|"+sArray[i]+"////");
145 
146  float[] vect=new float[3];
147 
148  float.TryParse(ssArray[0],out vect[0]);
149  float.TryParse(ssArray[1],out vect[1]);
150  float.TryParse(ssArray[2],out vect[2]);
151 // for(int kk=0;kk<vect.Length;kk++)
152 // {
153 // Debug.Log(i+"|"+vect[kk]+"////");
154 // }
155  typelist.Add(AtomModel.GetModel(ssArray[3]));
156  alist.Add(vect);
157 
158  }
159 
160  Debug.Log(Clubs);
161  Vector3 minPoint=Vector3.zero;
162  Vector3 maxPoint=Vector3.zero;
163 
165  MoleculeModel.atomsTypelist=typelist;
166  //MoleculeModel.bondList=ControlMolecule.CreateBondsList(alist,typelist);
167  //Debug.Log("======================= Bond List" + MoleculeModel.bondList.ToString());
170 
171 // float [] a0=alist[0] as float[];
172 // MoleculeModel.cameraLocation.x=MoleculeModel.target.x=a0[0];
173 // MoleculeModel.cameraLocation.y=MoleculeModel.target.y=a0[1];
174 // MoleculeModel.target.z=a0[2];
175 // MoleculeModel.cameraLocation.z=a0[2]-150;
176 //
177 
178  for(int i=0; i<alist.Count; i++)
179  {
180  float[] position= alist[i] as float[];
181  minPoint = Vector3.Min(minPoint, new Vector3(position[0],position[1],position[2]));
182  maxPoint = Vector3.Max(maxPoint, new Vector3(position[0],position[1],position[2]));
183  }
184  Vector3 centerPoint = minPoint + ((maxPoint - minPoint) / 2);
185  //MoleculeModel.target = centerPoint;
186 
187  MoleculeModel.Offset = -centerPoint;
188 
189 
190  for(int i=0; i<alist.Count; i++)
191  {
192  float[] position= alist[i] as float[];
193  float[] vect=new float[3];
194  vect[0]=position[0]+MoleculeModel.Offset.x;
195  vect[1]=position[1]+MoleculeModel.Offset.y;
196  vect[2]=position[2]+MoleculeModel.Offset.z;
197 
198  alist[i]=vect;
199  }
200 
201 
202 // Debug.Log("MoleculeModel.target "+MoleculeModel.target);
205 // MoleculeModel.cameraLocation.z=MoleculeModel.target.z-((maxPoint - minPoint) ).z;
206  MoleculeModel.cameraLocation.z=MoleculeModel.target.z-((maxPoint - minPoint) ).z;
207 
208 
209 
210  //MoleculeModel.bondList=ControlMolecule.CreateBondsList(alist,typelist);
213 
214 
215 
216 
217  MoleculeModel.atomsnumber = alist.Count;
219 
220 
221  string [] sClubArray=Clubs.Split('$');
222  for(int i=0;i<sClubArray.Length-1;i++)
223  {
224  string [] ssClubArray=sClubArray[i].Split('#');
225  float[] vect=new float[3];
226  vect[0]=float.Parse(ssClubArray[0]);
227  vect[1]=float.Parse(ssClubArray[1]);
228  vect[2]=float.Parse(ssClubArray[2]);
229  clubLocationalist.Add(vect);
230 
231 
232  float[] vectRotation=new float[3];
233  vectRotation[0]=float.Parse(ssClubArray[3]);
234  vectRotation[1]=float.Parse(ssClubArray[4]);
235  vectRotation[2]=0f;
236 
237  clubRotationList.Add(vectRotation);
238  }
239 
240  Debug.Log(clubRotationList.Count);
241 
242  }
243 
244  public List<float[]> getAtoms()
245  {
246 
247  return alist;
248 
249  }
250 
251 
252  public List<AtomModel> getTypes()
253  {
254  return typelist;
255  }
256 
257  public ArrayList getClubLocation()
258  {
259  return clubLocationalist;
260  }
261 
262 
263  public ArrayList getClubRotation()
264  {
265  return clubRotationList;
266  }
267  }
268 
269 }
static AtomModel GetModel(string type)
Definition: AtomModel.cs:257
Definition: CommandID.cs:66
static void Send(short data)
Definition: UnitySocket.cs:154
List< AtomModel > getTypes()
Definition: SocketPDB.cs:252
static Vector3 Offset
The offset for the molecule.
static List< int[]> CreateBondsEPList(List< float[]> atomsLocationlist, List< AtomModel > atomsTypelist)
List< float[]> getAtoms()
Definition: SocketPDB.cs:244
static List< AtomModel > atomsTypelist
The type of each atom.
static List< float[]> atomsSugarLocationlist
static List< AtomModel > atomsSugarTypelist
static List< int[]> bondEPSugarList
static List< int[]> bondEPList
The bonds between atoms.
void loadPDB(string id)
Definition: SocketPDB.cs:103
static string ReceiveString(int length)
Definition: UnitySocket.cs:206
static int GETPDB
Definition: CommandID.cs:76
static List< float[]> atomsLocationlist
The coordinates of each atom.