3 using System.Collections.Generic;
11 public class ParsePDB {
13 public static void FetchPDB2(
string url,
string id,
string proxyserver =
"",
int proxyport = 0) {
15 Stream dataStream=null;
16 HttpWebResponse response=null;
28 HttpWebRequest request =(HttpWebRequest) WebRequest.Create (url+
id+
".pdb");
31 request.Credentials = CredentialCache.DefaultCredentials;
36 request.Proxy =
new WebProxy(proxyserver,proxyport);
39 response = (HttpWebResponse)request.GetResponse ();
41 Debug.Log(
"LoadPDB Status :: " + response.StatusDescription);
44 dataStream = response.GetResponseStream ();
46 sr =
new StreamReader (dataStream);
51 if(dataStream!=null&& response!=null) {
60 sr=
new StreamReader(file_base_name+
".pdb");
75 FileInfo fieldlinefile=
new FileInfo(file_base_name+
".json");
76 FileInfo apffile=
new FileInfo(file_base_name+
".apf");
77 if(fieldlinefile.Exists) {
80 }
else if(apffile.Exists) {
88 FileInfo Surfacefile=
new FileInfo(file_base_name+
".obj");
89 FileInfo Surfacefile0=
new FileInfo(file_base_name+
"0.obj");
91 if(Surfacefile.Exists || Surfacefile0.Exists) {
99 FileInfo dxfile=
new FileInfo(file_base_name+
".dx");
112 List<float[]> alist =
new List<float[]>();
113 List<float[]> calist =
new List<float[]>();
115 List<float> BFactorList =
new List<float>();
117 List<string> resnamelist =
new List<string>();
118 List<string> atomsNameList =
new List<string>();
119 List<string> caChainlist =
new List<string>();
121 List<AtomModel> typelist =
new List<AtomModel>();
122 List<string> chainList =
new List<string>();
124 List<Color> colorList =
new List<Color>();
126 List<float[]> sshelixlist =
new List<float[]> ();
127 List<float[]> sssheetlist =
new List<float[]> ();
130 string[] dnaBackboneAtoms =
new string[] {
"C5'"};
131 List<int> residueIds =
new List<int>();
132 List<int> splits =
new List<int>();
133 List<int> atomsNumberList =
new List<int>();
136 int prevRes =
int.MinValue;
137 int currentRes =
int.MinValue+1;
144 string[] lines = sr.ReadToEnd().Split(
new [] {
'\r',
'\n' });
149 while(idl < lines.Length){
152 if(s.StartsWith(
"ENDMDL"))
156 bool isAtomLine = s.StartsWith(
"ATOM");
158 bool isHelixLine = s.StartsWith (
"HELIX");
159 bool isSheetLine = s.StartsWith(
"SHEET");
160 bool isConnectLine = s.StartsWith(
"CONECT");
161 if(s.StartsWith(
"TER")) {
167 string chainh = s.Substring (19,2).Trim ();
168 string initr = s.Substring(22,4);
169 string termr = s.Substring (34,4);
170 string classH = s.Substring(39,2);
172 string len = s.Substring(72,5);
173 float[] vect =
new float[4];
174 float initres =
float.Parse (initr);
175 float termres =
float.Parse (termr);
176 float length =
float.Parse (len);
177 float classhelix = 1f;
179 classhelix =
float.Parse (classH);
181 classhelix =
float.Parse (s.Substring(38,2));
186 vect[3] = classhelix;
187 sshelixlist.Add (vect);
192 string chainS = s.Substring (21, 2).Trim ();
193 string initr = s.Substring (23, 4);
194 string termr = s.Substring (34, 4);
195 float[] vect =
new float[2];
196 vect[0] =
float.Parse (initr);
197 vect[1] =
float.Parse (termr);
198 sssheetlist.Add (vect);
203 isAtomLine = isAtomLine || s.StartsWith(
"HETATM");
207 if ((
string) s.Substring(17,3).Trim() ==
"HOH")
215 float[] vect=
new float[4];
217 string sind = s.Substring(7,5);
219 string sx=s.Substring(30,8);
220 string sy=s.Substring(38,8);
221 string sz=s.Substring(46,8);
222 string sbfactor = null;
223 bool parseBFactor =
false;
225 sbfactor = s.Substring(60,6);
228 string atomsNumber = s.Substring(6,5);
229 string typestring=s.Substring(12,4).Trim();
230 atomsNameList.Add(typestring);
232 bool b =
int.TryParse(typestring[0].ToString(), out bout);
235 type=typestring[1].ToString();
237 type=typestring[0].ToString();
239 string resname=s.Substring(17,3).Trim();
240 int resid =
int.Parse(s.Substring(22,4));
241 residueIds.Add(resid);
243 atomsNumberList.Add (
int.Parse(atomsNumber));
248 float x=-
float.Parse(sx);
249 float y=
float.Parse(sy);
250 float z=
float.Parse(sz);
252 float ind =
float.Parse(sind);
253 float bfactor = 0.0f;
254 if (parseBFactor ==
true)
256 bfactor=
float.Parse(sbfactor);
265 if(typestring[0].ToString()==
"C" && typestring.Length>1) {
266 if(typestring[1].ToString()==
"A") {
267 string chaintype = s.Substring(21,1);
269 caChainlist.Add(chaintype);
275 if(dnaBackboneAtoms.Contains(typestring)) {
276 string chaintype = s.Substring(21,1);
278 caChainlist.Add(chaintype);
281 if(s.Substring(21,1) !=
" "){
282 string chain = s.Substring(21,1);
283 chainList.Add(chain);
287 if (parseBFactor ==
true)
289 BFactorList.Add(bfactor);
303 typelist.Add(aModel);
319 resnamelist.Add(resname);
330 int curresnb =
int.Parse (s.Substring(22,4));
331 if(prevresnb == 0 && curresnb != 0)
333 if(curresnb != prevresnb){
335 prevresnb = curresnb;
340 if(prevRes != currentRes)
343 prevRes = currentRes;
358 string[] splitedStringTemp = s.Split(
' ');
359 List<string> splitedString =
new List<string>();
360 for (
int j=0; j<splitedStringTemp.Length; j++){
361 if (splitedStringTemp[j]!=
"")
362 splitedString.Add(splitedStringTemp[j]);
364 for (
int j=2; j<splitedString.Count; j++){
376 for(
int i = 0; i < typelist.Count; i++)
379 foreach(
string name
in atomsNameList)
385 foreach(
string chain
in chainList)
400 if(resnamelist.Count == typelist.Count)
402 if(chainList.Count == typelist.Count)
430 StreamReader sr =
new StreamReader(file_name);
434 text = sr.ReadToEnd();
469 Debug.Log(
"name:"+file_base_name+
".obj");
472 string path = file_base_name+
".obj";
478 FileInfo file=
new FileInfo(file_base_name+
".obj");
488 Debug.Log(
"Generate new OBJ from "+path);
493 for (
int i =0;i< 6;i++){
494 file=
new FileInfo(file_base_name+i+
".obj");
496 path = file_base_name+i+
".obj";
498 Debug.Log(
"new OBJ");
static void LoadDxRequest(string file_name, Vector3 Offset)
static void InitHiRERNA()
static List< string > resChainList2
The chain of each residue.
static List< int[]> BondListFromPDB
static List< string > existingName
List of the names existing in the molecule.
static List< string > atomHetTypeList
static void ReadPDB2(TextReader sr)
static AtomModel GetModel(string type)
static List< string > atomsSugarNamelist
static Vector3 Offset
The offset for the molecule.
static void LoadPDBRequest2(string file_base_name, bool withData=true)
static List< string > atomsNamelist
The name of each atom.
static List< string > atomsChainList
The chain of each atom.
static bool fieldLineFileExists
static List< AtomModel > atomsTypelist
The type of each atom.
static List< string > helixChainList
The helix chain list (extract from the pdb).
static List< float[]> atomsSugarLocationlist
static List< int > residueIds
The residue identifiers.
static List< float[]> CatomsLocationlist
The coordinates of each Carbon alpha.
static List< float > BFactorList
Bfactor of each atom.
static List< int > splits
Terminal residue number of each subunits.
static Color GetAtomColor(string atomType)
static bool mustSplitDictList
static List< float[]> ssStrandList
First and last residue of each strand (extract from the pdb) float[0] is the first residue of each st...
static void LoadJsonRequest(string file_name, Vector3 Offset)
static List< AtomModel > atomsSugarTypelist
static List< float[]> ssHelixList
List of informations about each helix (extract from the pdb) float[0] is the first residue of each he...
!WiP Includes FLAGS of GUI.
static List< string > CaSplineChainList
The chain of each carbon alpha in the CA-Spline.
static List< Color > atomsColorList
The color of each atom.
static Dictionary< int, ArrayList > residues
The residues.
static List< List< Vector3 > > FieldLineList
static List< string > existingChain
List of the chains existing in the molecule.
static void InitAtomic()
Inits the atomic and chains scales.
static List< int > atomsNumberList
The number of each atoms (in the PDB file)
static List< string > resSugarChainList
static List< string > atomsResnamelist
The name of the residue to which each atom belongs.
static List< string > resChainList
The chain of each residue (only work if residues are numbered by chain).
static int firstresnb
First residue number in pdb.
static List< string > strandChainList
The strand chain list (extract from the pdb).
static List< string > sugarResname
static void LoadOBJRequest(string file_base_name)
static bool surfaceFileExists
static bool showFieldLines
static void FetchPDB2(string url, string id, string proxyserver="", int proxyport=0)
static bool connectivity_PDB
static List< float > atomsLocalScaleList
static List< string > atomsSugarResnamelist
static List< float[]> atomsLocationlist
The coordinates of each atom.