-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSharedFunctions.cs
More file actions
3376 lines (2977 loc) · 184 KB
/
SharedFunctions.cs
File metadata and controls
3376 lines (2977 loc) · 184 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
** File: SharedFunctions.cs
** Started:
** Contributors: Meghan Franklin, Ryan Feehan et al.
** Overview:
**
** About:
**
** Last Edited:
*/
using System;
using System.Collections.Generic;
using System.Linq;
using betaBarrelProgram.BarrelStructures;
using betaBarrelProgram.Mono;
using System.IO;
using System.Numerics;
using MathNet.Numerics.LinearAlgebra;
using MathNet.Numerics.LinearAlgebra.Double;
using MathNet.Numerics.LinearAlgebra.Factorization;
namespace betaBarrelProgram
{
public class SharedFunctions
{
public static void create_dir(string outputDirectory)
{
if (!System.IO.Directory.Exists(outputDirectory))
{
System.IO.Directory.CreateDirectory(outputDirectory);
}
}
public static double AngleBetween(Vector3 v1, Vector3 v2)
{
float cos_angle = (Vector3.Dot(v1, v2) / (v1.Length()*v2.Length()));
double angle = Math.Acos(cos_angle);
angle = angle * (180.0 / Math.PI);
return (angle);
}
public static Vector3 sete1(Atom atomB, Vector3 atomC, Vector3 atomD, double angle, double dihedral)
{
Vector3 uCB = -(atomB.Coords - atomC);
uCB = Vector3.Normalize(uCB);
Vector3 dDC = -(atomC - atomD);
double angle2 = 180 - angle;
double dihe2 = 180 + dihedral;
double rsin = Math.Sin(angle2);
double rcos = Math.Cos(angle2);
double rsinsin = rsin * Math.Sin(dihe2);
double rsincos = rsin * Math.Cos(dihe2);
Vector3 dp2 = dDC - (uCB * Vector3.Dot(dDC, uCB));
dp2 = Vector3.Normalize(dp2);
Vector3 cp1 = Vector3.Cross(uCB, dDC);
cp1= Vector3.Normalize(cp1);
return ((uCB * (float)rcos) + (dp2 * (float)rsincos) + (cp1 * (float)rsinsin) + atomB.Coords);
}
public static double calculateEvdw(HAcceptor acceptor, HDonor hAtom, double d)
{
double Evdw;
double DsigmaIJ = d / (acceptor.vDWrad + hAtom.vDWrad);
double Eij = Math.Sqrt(acceptor.EpsMin * hAtom.EpsMin);
if (DsigmaIJ <= 0.8254) Evdw = 10;
else if (DsigmaIJ <= 1) Evdw = 57.273 * (1 - DsigmaIJ);
else if (DsigmaIJ < 10 / 9) Evdw = Eij * Math.Pow((10 - 9 * DsigmaIJ), 57.273 / (9 * Eij)) - Eij;
else if (DsigmaIJ < 4 / 3) Evdw = (Eij / 4) * Math.Pow((9 * DsigmaIJ - 10), 2) - Eij;
else Evdw = 0;
return Evdw;
}
public static double CalculateTorsion(Vector3 _atom1Coords, Vector3 _atom2Coords, Vector3 _atom3Coords, Vector3 _atom4Coords)
{
Vector3 vec1 = new Vector3();
vec1 = _atom2Coords - _atom1Coords;
Vector3 vec2 = new Vector3();
vec2 = _atom3Coords - _atom2Coords;
Vector3 vec3 = new Vector3();
vec3 = _atom4Coords - _atom3Coords;
Vector3 projVec = new Vector3((float)(Math.Sqrt(Vector3.Dot(vec2, vec2)) * vec1.X), (float)(Math.Sqrt(Vector3.Dot(vec2, vec2)) * vec1.Y),
(float)(Math.Sqrt(Vector3.Dot(vec2, vec2)) * vec1.Z));
return (Math.Atan2((Vector3.Dot(projVec, Vector3.Cross(vec2, vec3))),
Vector3.Dot(Vector3.Cross(vec1, vec2), Vector3.Cross(vec2, vec3)))) * 180 / Math.PI;
}
public static double calculateHydrogenBond(Atom N, Atom O, double d)
{
double aMax = 37;
double BMax = 49;
double sigmaD = .67;
double sigmaDSQ = .449;
double cosAmax = .7986;
double cosBmax = .561;
double d0 = 2.08;
double a = (Math.PI * AngleBetween(O.Coords - N.Hydrogen, N.Hydrogen - N.Coords)) / 180;
double B = (Math.PI * AngleBetween(O.e1, N.Hydrogen - O.Coords)) / 180;
if (O.e2!=null)
{
double B2 = (Math.PI * AngleBetween(O.e2, N.Hydrogen - O.Coords)) / 180;
if (B2 < B) B = B2;
}
if (B > BMax || a > aMax)
{
return 999;
}
double denominator = .176;
double w = Math.Sqrt((sigmaDSQ - Math.Pow(d - d0, 2)) * (Math.Cos(a) - cosAmax) * (Math.Cos(B) - cosBmax)) / denominator;
return w;
}
public static void writePymolScriptForStrands(List<Strand> strandlist, string outputDirectory, string DBdirectory, string pdbName)
{
create_dir(outputDirectory + "PyMOL/ColorStrands/");
List<string> chain_names = new List<string>();
string fileLocation = outputDirectory + "PyMOL/ColorStrands/strands_" + pdbName + ".py";
using (System.IO.StreamWriter file = new System.IO.StreamWriter(fileLocation))
{
//If you do NOT use MacPymol, uncomment several lines below
//file.WriteLine("import pymol"); //For PC
//file.WriteLine("import cmd"); //For PC
//file.WriteLine("from pymol import stored"); //For PC
file.WriteLine("from pymol import cmd, stored"); //For MacPyMOL
//string[] colors = { "white", "red", "orange", "purple", "yellow", "green", "cyan", "blue", "purple", "red", "orange", "yellow", "green", "cyan", "blue", "purple", "red", "orange", "yellow", "green", "cyan", "blue", "purple", "red", "orange", "yellow", "green", "cyan", "blue", "purple", "red", "orange", "yellow", "green", "cyan", "blue", "purple", "red", "orange", "yellow", "green", "cyan", "blue", "purple", "red", "orange", "yellow", "green", "cyan", "blue", "purple", "red", "orange", "yellow", "green", "cyan", "blue", "purple", "red", "orange", "yellow", "green", "cyan", "blue", "purple" };
string[] colors = { "red", "yellow", "green", "cyan", "blue", "magenta" };//, "red", "yellow", "green", "cyan", "blue", "magenta", "red", "yellow", "green", "cyan", "blue", "magenta", "red", "yellow", "green", "cyan", "blue", "magenta", "red", "yellow", "green", "cyan", "blue", "magenta", "red", "yellow", "green", "cyan", "blue", "magenta", "red", "yellow", "green", "cyan", "blue", "magenta", "red", "yellow", "green", "cyan", "blue", "magenta", "red", "yellow", "green", "cyan", "blue", "magenta", "red", "yellow", "green", "cyan", "blue", "magenta", "red", "yellow", "green", "cyan", "blue", "magenta" };
string pdb_file = DBdirectory + pdbName + ".pdb";
file.WriteLine("cmd.load(r\"{0}\")", pdb_file);
file.WriteLine("cmd.hide(\"everything\", \"all\")");
file.WriteLine("cmd.color(\"grey50\",\"all\")");
foreach (Strand strand in strandlist)
{
file.WriteLine("cmd.select(\"{0}_{1}_S{2}\", \"resi {3}-{4} & chain {1} & {0} \")", pdbName, strand.ChainName, strand.StrandNum, strand.Residues[0].SeqID, strand.Residues.Last().SeqID);
file.WriteLine("cmd.color (\"{3}\", \"{0}_{1}_S{2}\")", pdbName, strand.ChainName, strand.StrandNum, colors[(strand.StrandNum % 6)]);
if (chain_names.Contains(strand.ChainName) == false) chain_names.Add(strand.ChainName);
file.WriteLine("\n");
}
file.Write("cmd.select(\"{0}_barrel\", \"", pdbName);
for (int i = 0; i < chain_names.Count; i++)
{
if (i < chain_names.Count - 1) file.Write("{0}_{1}_S* or ", pdbName, chain_names[i]);
else file.WriteLine("{0}_{1}_S*\")", pdbName, chain_names[i]);
}
file.WriteLine("cmd.show(\"cartoon\", \"{0}_barrel\")", pdbName);
file.WriteLine("cmd.zoom(\"{0}_barrel\")", pdbName);
}
}
public static void writePymolScriptForLoops(Dictionary<string,string> looplist, string outputDirectory, string DBdirectory, ref Chain myChain, string pdbName)
{
create_dir(outputDirectory + "PyMOL/ColorLoops");
List<string> chain_names = new List<string>();
string fileLocation = outputDirectory + "PyMOL/ColorLoops/Loops_" + pdbName + ".py";
using (System.IO.StreamWriter file = new System.IO.StreamWriter(fileLocation, true))
{
//If you do NOT use MacPymol, uncomment several lines below
//file.WriteLine("import pymol"); //For PC
//file.WriteLine("import cmd"); //For PC
//file.WriteLine("from pymol import stored"); //For PC
file.WriteLine("from pymol import cmd, stored"); //For MacPyMOL
string[] colors = { "white", "red", "orange", "yellow", "forest", "cyan", "blue", "purple", "red", "orange", "yellow", "forest", "cyan", "blue", "purple", "red", "orange", "yellow", "forest", "cyan", "blue", "purple", "red", "orange", "yellow", "forest", "cyan", "blue", "purple", "red", "orange", "yellow", "forest", "cyan", "blue", "purple"};
string pdb_file = DBdirectory + pdbName + ".pdb";
file.WriteLine("cmd.load(\"{0}\")", pdb_file);
file.WriteLine("cmd.hide(\"everything\", \"all\")");
file.WriteLine("cmd.color(\"grey50\",\"all\")");
file.WriteLine("cmd.show(\"cartoon\", \"chain {0}\")", myChain.ChainName);
foreach (KeyValuePair<string,string> loop in looplist)
{
file.WriteLine("cmd.select(\"{0}{1}\", \"resi {2} & chain {0} \")", myChain.ChainName, loop.Key, loop.Value);
int loopNum = Convert.ToInt16(loop.Key.Substring(1, loop.Key.Length - 1));
file.WriteLine("cmd.color (\"{0}\", \"{2}{1}\")", colors[loopNum], loop.Key, myChain.ChainName);
//file.WriteLine("\n");
}
file.WriteLine("cmd.center (\"chain {0}\")", myChain.ChainName);
}
}
public static Vector3 getNormal(List<Vector3> myEllipse, Vector3 myCentroid)
{
List<Vector3> rawPoints = myEllipse;
//average points to find centroid
Vector3 centroid = new Vector3();
for (int cur = 0; cur < rawPoints.Count; cur++)
{
centroid += myEllipse[cur];
}
centroid /= rawPoints.Count;
//move points to around orgin
for (int cur = 0; cur < rawPoints.Count; cur++) myEllipse[cur] -= centroid;
Matrix<double> A = DenseMatrix.Build.Random(3, 3);
double X = myEllipse[0].X;
double Y = myEllipse[0].Y;
double Z = myEllipse[0].Z;
A[0, 0] = (X * X);
A[0, 1] = (X * Y);
A[0, 2] = (X * Z);
A[1, 0] = (Y * X);
A[1, 1] = (Y * Y);
A[1, 2] = (Y * Z);
A[2, 0] = (Z * X);
A[2, 1] = (Z * Y);
A[2, 2] = (Z * Z);
for (int cur = 1; cur < rawPoints.Count; cur++)
{
X = myEllipse[cur].X;
Y = myEllipse[cur].Y;
Z = myEllipse[cur].Z;
A[0, 0] = A[0, 0] + (X * X);
A[0, 1] = A[0, 1] + (X * Y);
A[0, 2] = A[0, 2] + (X * Z);
A[1, 0] = A[1, 0] + (Y * X);
A[1, 1] = A[1, 1] + (Y * Y);
A[1, 2] = A[1, 2] + (Y * Z);
A[2, 0] = A[2, 0] + (Z * X);
A[2, 1] = A[2, 1] + (Z * Y);
A[2, 2] = A[2, 2] + (Z * Z);
}
SortedList<double, Vector3> myEigenSolution = new SortedList<double, Vector3>();
Evd<double> eigen = A.Evd();
for (int vecCtr = 0; vecCtr < A.RowCount; vecCtr++)
{
double lambda = eigen.EigenValues.At(vecCtr).Real;
Vector3 vec3d = new Vector3();
vec3d.X = (float)eigen.EigenVectors.At(0, vecCtr);
vec3d.Y = (float)eigen.EigenVectors.At(1, vecCtr);
vec3d.Z = (float)eigen.EigenVectors.At(2, vecCtr);
myEigenSolution.Add(lambda, vec3d);
}
//Vector3 EigenvectorA = new Vector3();
//Vector3 EigenvectorB = new Vector3();
Vector3 EigenvectorN = new Vector3();
double eigenValN = myEigenSolution.Keys.Min();
EigenvectorN = myEigenSolution[eigenValN];
return EigenvectorN;
//Matrix3D covariance = new Matrix3D(sumX2,sumxy,sumxz,0,sumxy,sumY2,sumyz,0, sumxz,sumyz,sumZ2,0,0,0,0,0);
}
public static double setRadius(List<Strand> strandlist, Vector3 axis, Vector3 CCentroid, Vector3 NCentroid)
{
double AvgRad = 0;
double totalRes = 0;
foreach (Strand strand in strandlist)
{
foreach (Res myRes in strand)
{
myRes.Radius = (Vector3.Cross(myRes.BackboneCoords["CA"] - NCentroid, myRes.BackboneCoords["CA"] - CCentroid)).Length() / axis.Length();
AvgRad += myRes.Radius;
totalRes++;
}
}
return AvgRad / totalRes;
}
public static void setInOut(List<Strand> strandlist, string outputDirectory, string pdbName, Vector3 axis, Vector3 CCentroid, Vector3 NCentroid)
{
double direction; double angleUncertainty; double angle;
foreach (Strand strand in strandlist)
{
direction = AngleBetween(strand.Residues[0].BackboneCoords["CA"] - strand.Residues[strand.Residues.Count - 1].BackboneCoords["CA"], axis);
foreach (Res myRes in strand)
{
angleUncertainty = 10;
angle = AngleBetween(myRes.BackboneCoords["CA"] - ((myRes.BackboneCoords["N"] + myRes.BackboneCoords["C"]) / 2), axis);
if ((angle < 90 + angleUncertainty && angle > 90 - angleUncertainty || myRes.ResNum == 0 || myRes.ResNum == strand.Residues.Count - 1) && myRes.ThreeLetCode != "GLY")
{
//This combines the double-check in/out function
bool inward = false;
Vector3 myCentroid = new Vector3();
if ((myRes.BackboneCoords["CA"] - NCentroid).Length() < (myRes.BackboneCoords["CA"] - CCentroid).Length()) myCentroid = NCentroid;
else myCentroid = CCentroid;
if ((myRes.BackboneCoords["CA"] - myCentroid).Length() > (myRes.Atoms[4].Coords - myCentroid).Length()) inward = true;
if (inward == true)
{
myRes.Inward = true;
}
else myRes.Inward = false;
}
else
{
if (direction > 90)
{
if (angle > 90) myRes.Inward = true;
else myRes.Inward = false;
}
else
{
if (angle < 90) myRes.Inward = true;
else myRes.Inward = false;
}
}
}
}
}
public static void setInOutMin(List<Strand> strandlist, string outputDirectory, string pdbName, Vector3 CCentroid, Vector3 NCentroid) //10-07-20 - RD - Use the reference point on axis
{
string fileLocation3 = outputDirectory + "InOut/InOut_" + pdbName + ".txt";
create_dir(outputDirectory + "InOut");
Dictionary <Vector3, Vector3> nearestPoint = new Dictionary<Vector3, Vector3>();
using (System.IO.StreamWriter file = new System.IO.StreamWriter(fileLocation3))
{
file.Write("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\n", "Res", "ResNum", "SeqID", "Strand", "Chain", "Inward", "ZCoord");
foreach (Strand strand in strandlist)
{
foreach (Res myRes in strand)
{
var reference = ReferenceVector(myRes.BackboneCoords["CA"]);
var axisDirection = myRes.BackboneCoords["CA"] - reference;
var angle = 0.0;
nearestPoint.Add(myRes.BackboneCoords["CA"], reference); //For pymol output
if (myRes.ThreeLetCode != "GLY")
{
angle = AngleBetween(myRes.BackboneCoords["CA"] - myRes.Atoms.First(Atom => Atom.AtomName == "CB").Coords, axisDirection);
}
else
{
angle = AngleBetween(((myRes.BackboneCoords["N"] + myRes.BackboneCoords["C"]) / 2) - myRes.BackboneCoords["CA"], axisDirection);
}
//Console.WriteLine($"{myRes.SeqID}, {myRes.ThreeLetCode} - {angle}");
if (angle < 90)
{
myRes.Inward = true;
}
else
{
myRes.Inward = false;
}
file.Write("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\n", myRes.ThreeLetCode, myRes.ResNum + 1, myRes.SeqID, myRes.StrandNum, myRes.ChainName, myRes.Inward, myRes.BackboneCoords["CA"].Z);
}
}
}
//Calculate vector from CA to the nearest reference point on the axis
Vector3 ReferenceVector(Vector3 CAAtom)
{
Vector3 p1 = NCentroid;
Vector3 p2 = CCentroid;
Vector3 q = CAAtom;
Vector3 u = p2 - p1;
Vector3 pq = q - p1;
Vector3 w2 = pq - Vector3.Multiply(u, Vector3.Dot(pq, u) / u.LengthSquared()); //point on axis
Vector3 reference = q - w2;
return reference;
}
}
public static void getInOut(List<Strand> strandlist, string outputDirectory, string pdbName, Vector3 axis, Vector3 CCentroid, Vector3 NCentroid)
{
create_dir(outputDirectory + "InOut");
string fileLocation3 = outputDirectory + "InOut/InOut_" + pdbName + ".txt";
double direction; double angleUncertainty; double angle;
using (System.IO.StreamWriter file = new System.IO.StreamWriter(fileLocation3))
{
file.Write("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\n", "Res", "SeqID", "Strand", "Chain", "Inward", "ZCoord");
foreach (Strand strand in strandlist)
{
direction = AngleBetween(strand.Residues[0].BackboneCoords["CA"] - strand.Residues[strand.Residues.Count - 1].BackboneCoords["CA"], axis);
foreach (Res myRes in strand)
{
angleUncertainty = 10;
angle = AngleBetween(myRes.BackboneCoords["CA"] - ((myRes.BackboneCoords["N"] + myRes.BackboneCoords["C"]) / 2), axis);
if ((angle < 90 + angleUncertainty && angle > 90 - angleUncertainty || myRes.ResNum == 0 || myRes.ResNum == strand.Residues.Count - 1) && myRes.ThreeLetCode != "GLY")
{
//This combines the double-check in/out function
bool inward = false;
Vector3 myCentroid = new Vector3();
if ((myRes.BackboneCoords["CA"] - NCentroid).Length() < (myRes.BackboneCoords["CA"] - CCentroid).Length()) myCentroid = NCentroid;
else myCentroid = CCentroid;
if ((myRes.BackboneCoords["CA"] - myCentroid).Length() > (myRes.Atoms[4].Coords - myCentroid).Length()) inward = true;
if (inward == true)
{
myRes.Inward = true;
}
else myRes.Inward = false;
}
else
{
if (direction > 90)
{
if (angle > 90) myRes.Inward = true;
else myRes.Inward = false;
}
else
{
if (angle < 90) myRes.Inward = true;
else myRes.Inward = false;
}
}
file.Write("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\n", myRes.ThreeLetCode, myRes.SeqID, myRes.StrandNum, myRes.ChainName, myRes.Inward, myRes.BackboneCoords["CA"].Z);
//file.Write("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\n", myRes.ThreeLetCode, myRes.ResNum + 1, myRes.StrandNum, myRes.ChainName, myRes.Inward, myRes.BackboneCoords["CA"].Z);
}
}
}
}
public static List<double> getStrandLengths(List<Strand> strandlist, string outputDirectory, string pdbName)
{
create_dir(outputDirectory + "Tilts");
string fileLocation3 = outputDirectory + "Tilts/StrandLengths_" + pdbName + ".txt";
double height; List<double> all_lengths = new List<double>();
string fileOfPDBs = Global.MONO_DB_file;
using (System.IO.StreamWriter file = new System.IO.StreamWriter(fileLocation3))
{
file.Write("{0}\t{1}\t{2}\n", "Chain", "Strand #", "Length()");
foreach (Strand strand in strandlist)
{
Res res1 = strand.Residues[0];
Res res2 = strand.Residues.Last();
height = Math.Abs(res1.BackboneCoords["CA"].Z - res2.BackboneCoords["CA"].Z);
all_lengths.Add(height);
file.Write("{0}\t{1}\t{2}\n", strand.ChainName, strand.StrandNum, height);
}
}
return all_lengths;
}
public static void LogBarrel(ref Barrel myBarrel, string method)
{
var numberOfStrands = 0;
if (myBarrel.Success) numberOfStrands = myBarrel.Strands.Count;
var chainID = myBarrel.Strands[0].ChainName;
string logFileLoc = Global.OUTPUT_DIR + "Log.txt";
using (StreamWriter log = File.AppendText(logFileLoc))
{
log.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}", myBarrel.PdbName, myBarrel.Success, method, chainID, numberOfStrands);
}
}
public static Dictionary<string, string> getLoopTurns(List<Strand> strandlist, ref Chain myChain, string outputDirectory, string pdbName)
{
create_dir(outputDirectory + "LoopData");
create_dir(outputDirectory + "LoopData/v4Loops");
create_dir(outputDirectory + "TurnData");
create_dir(outputDirectory + "TurnData/v4Turns");
//string fileLocation = outputDirectory + "RosettaLoops/Loops/" + pdbName + "_Loops_Test.txt";
//string fileLocation2 = outputDirectory + "RosettaLoops/Turns/" + pdbName + "_Turns_Test.txt";
string fileLocation = outputDirectory + "LoopData/v4Loops/" + pdbName + "_Loops_Hairpin.txt";
string fileLocation2 = outputDirectory + "TurnData/v4Turns/" + pdbName + "_Turns_Hairpin.txt";
//string fileLocation = outputDirectory + "Loops/" + pdbName + "_Loops.txt";
//string fileLocation2 = outputDirectory + "Turns/" + pdbName + "_Turns.txt";
int turn_count = 0; int loop_count = 0; bool is_turn; string loop_seq = ""; List<Tuple<double, double>> phipsi = new List<Tuple<double, double>>();
string newline;
Dictionary<string, string> all_loops = new Dictionary<string, string>();
using (System.IO.StreamWriter file = new System.IO.StreamWriter(fileLocation, true))
{
file.Write("PDB\tID\tLength()\tSequence\tRes\tDist\tStrand1\tStrand2\n");
using (System.IO.StreamWriter file2 = new System.IO.StreamWriter(fileLocation2, true))
{
file2.Write("PDB\tID\tLength()\tSequence\tRes\tDist\tStrand1\tStrand2\n");
foreach (Strand strand in strandlist)
{
if (strand.ChainName == myChain.ChainName && strand.StrandNum != strandlist.Count - 1 && strandlist.IndexOf(strand) + 1 < strandlist.Count && strandlist[strandlist.IndexOf(strand) + 1].ChainName == myChain.ChainName)
{
int strand_id = strandlist.IndexOf(strand);
Res first_res = strand.Residues.Last();
Res last_res = strandlist[strand_id + 1].Residues[0];
//Determine if loop/turn; turns are on inside so Z-coords will be negative
if (first_res.BackboneCoords["CA"].Z - strand.Residues[0].BackboneCoords["CA"].Z < 0) { turn_count += 1; is_turn = true; }
else { loop_count += 1; is_turn = false; }
loop_seq = "";
phipsi.Clear();
List<double> avgBFac = new List<double>();
double distance = (first_res.Atoms[1].Coords - last_res.Atoms[1].Coords).Length();
//Check to see if loop is contiguous between strands
if (last_res.ResNum - first_res.ResNum == last_res.SeqID - first_res.SeqID)
{
for (int loop_res = first_res.ResNum; loop_res < last_res.ResNum + 1; loop_res++)
{
loop_seq += myChain.Residues[loop_res].OneLetCode;
phipsi.Add(Tuple.Create(myChain.Residues[loop_res].Phi, myChain.Residues[loop_res].Psi));
avgBFac.Add(myChain.Residues[loop_res].RelBFac);
}
//Console.WriteLine(loop_seq);
//Console.WriteLine(phipsi);
newline = loop_seq.Length.ToString() + "\t" + loop_seq + "\t" + first_res.SeqID.ToString() + "-" + last_res.SeqID.ToString() + "\t" + distance.ToString() + "\t" + strand_id.ToString() + "\t" + (strand_id + 1).ToString() + "\t";
//newline = loop_seq.Length().ToString() + "\t" + loop_seq + "\t" + (first_res.ResNum + 1).ToString() + "-" + (last_res.ResNum + 1).ToString() + "\t";
//if (loop_seq.Length() > 0) { newline += avgBFac.Average().ToString("F4") + "\t"; }
//Only print the phi/psi angles if less than 16 residues
/*if (loop_seq.Length() < 16 && loop_seq.Length() > 0)
{
foreach (Tuple<double, double> x in phipsi) { newline += "(" + x.Item1.ToString("F3") + "," + x.Item2.ToString("F3") +"), " ; }
}*/
}
else
{
if (last_res.ResNum < first_res.ResNum)
{
Console.WriteLine("INCORRECT LOOP DEFINITION");
if (is_turn == true) { turn_count -= 1; is_turn = false; loop_count += 1; }
else { loop_count -= 1; is_turn = true; turn_count += 1; }
}
//incomplete loop
//newline = "INCOMPLETE\t" + first_res.SeqID.ToString() + "-" + last_res.SeqID.ToString();
newline = "INCOMPLETE\t" + (first_res.ResNum + 1).ToString() + "-" + (last_res.ResNum + 1).ToString() + "\t" + distance.ToString() + "\t" + strand_id.ToString() + "\t" + (strand_id + 1).ToString();
}
//Write data to file and to dictionary
if (is_turn == true)
{
file2.WriteLine("{2}\tT{0}\t{1}", turn_count, newline, pdbName);
string key = "T" + turn_count.ToString();
string value = first_res.SeqID.ToString() + "-" + last_res.SeqID.ToString();
all_loops.Add(key, value);
}
else
{
file.WriteLine("{2}\tL{0}\t{1}", loop_count, newline, pdbName);
string key = "L" + loop_count.ToString();
string value = first_res.SeqID.ToString() + "-" + last_res.SeqID.ToString();
all_loops.Add(key, value);
}
}
}
}
}
return all_loops;
}
public static void findLoopsHBondingPartnersGeomOnly(Dictionary<string, string> looplist, string outputDirectory, ref Chain myChain, string pdbName, bool polybarrel)
{
string newLine;
bool inLoop;
string fileLocation = outputDirectory + "HBonding/GeomSC" + pdbName + ".txt";
string fileLocation2 = outputDirectory + "HBonding/GeomBBone" + pdbName + ".txt";
string fileLocation3 = outputDirectory + "HBonding/GeomBBSC" + pdbName + ".txt";
Char delimiter = '-';
create_dir(outputDirectory + "HBonding");
using (System.IO.StreamWriter test_file = new System.IO.StreamWriter(outputDirectory + "HBonding/TestFile"+pdbName + ".txt"))
{
using (System.IO.StreamWriter SCfile = new System.IO.StreamWriter(fileLocation))
{
newLine = "Atom\tNum\tRes\tChain\tAtom2\tNum\tRes2\tChain\tDist\tLoopID\tPartInLoop\tLoopPos";
SCfile.WriteLine(newLine);
using (System.IO.StreamWriter backbone = new System.IO.StreamWriter(fileLocation2))
{
backbone.WriteLine(newLine);
using (System.IO.StreamWriter bboneSC = new System.IO.StreamWriter(fileLocation3))
{
bboneSC.WriteLine(newLine);
foreach (KeyValuePair<string, string> loop in looplist)
{
var loop_ID = loop.Key;
int loop_start = Convert.ToInt16(loop.Value.Split(delimiter)[0]);
int loop_end = Convert.ToInt16(loop.Value.Split(delimiter)[1]);
//Console.WriteLine("{0},{1},{2}", loop_ID, loop_start, loop_end);
loop_start = myChain.Residues.FindIndex(a => a.SeqID == loop_start);
loop_end = myChain.Residues.FindIndex(a => a.SeqID == loop_end);
//Console.WriteLine("{0},{1},{2}", loop_ID, loop_start, loop_end);
int loop_pos = -1;
for (int i = loop_start; i < loop_end + 1; i++)
{
Res Residue1 = myChain.Residues[i];
loop_pos++;
for (int j = loop_start - 3; j < loop_end + 4; j++)
{
Res Residue2 = myChain.Residues[j];
if (j >= loop_start && j <= loop_end) inLoop = true;
else inLoop = false;
foreach (Atom atom1 in Residue1)
{
if ((atom1.AtomName == "N" && Residue1.ThreeLetCode != "PRO") || (atom1.AtomName == "CA" && Residue1.ThreeLetCode != "GLY") || atom1.AtomName == "C" || atom1.AtomType == "H") continue;
else if (atom1.AtomType == "C" && atom1.AtomName != "CA") continue; //skip any carbon atoms that aren't CA of gly
else //Compare to chains on either side
{
checkLoopsGeom(Residue1, atom1, Residue2, loop_ID.ToString(), inLoop, loop_pos, backbone, bboneSC, SCfile, test_file);
}
}
}
}
}
}
}
}
}
}
public static void checkLoopsGeom(Res Residue1, Atom atom1, Res Residue2, String LoopID, bool InLoop, int loop_position, StreamWriter backbone, StreamWriter bboneSC, StreamWriter SCfile, StreamWriter test_file)
{
double dist; double angle1; double angle2;
Atom prevatom1 = atom1; Vector3 prevatom1_coords;
Atom prevatom2; Vector3 prevatom2_coords;
string newLine;
List<string> bbatoms = new List<string> { "O", "C", "N", "CA", "OXT" };
foreach (Atom atom2 in Residue2)
{
if (atom2.AtomType == "H" || atom2.AtomName == "C") continue; //Skip all hydrogen; C can't h-bond
else if (atom2.AtomName == atom1.AtomName && Residue1.ResNum == Residue2.ResNum || atom2.AtomName == "CA" && Residue1.ResNum == Residue2.ResNum) continue; //skip self-atom in loop and self-CA bonds as impossible
else if (bbatoms.Contains(atom2.AtomName) && atom1.AtomName == "O") //O to bbatom
{
if (Residue1.ResNum == Residue2.ResNum || atom2.AtomName == "N" && Residue2.ResNum == Residue1.ResNum + 1 ) continue; //can't self-bb-bond or O-next N
dist = (atom1.Coords - atom2.Coords).Length();
if (dist < 6)
{
prevatom1 = Residue1.Atoms[Residue1.Atoms.FindIndex(a => a.AtomName == "C")];
prevatom1_coords = prevatom1.Coords;
prevatom2 = Residue2.Atoms[Residue2.Atoms.FindIndex(a => a.AtomName == "CA")]; //N-CA, CA-N, O-C
if (atom2.AtomName == "CA") prevatom2 = Residue2.Atoms[Residue2.Atoms.FindIndex(a => a.AtomName == "N")];
if (atom2.AtomName == "O") prevatom2 = Residue2.Atoms[Residue2.Atoms.FindIndex(a => a.AtomName == "C")];
prevatom2_coords = prevatom2.Coords;
Vector3 interatom = (atom1.Coords) - prevatom1_coords;
Vector3 intraatom = atom1.Coords - atom2.Coords;
angle1 = AngleBetween(interatom, intraatom);
interatom = (atom2.Coords) - prevatom2_coords;
angle2 = 180- AngleBetween(interatom, intraatom);
test_file.WriteLine("{0}_{1} {2} {3}_{4} {5} {6} {7}", atom1.AtomName, atom1.ResSeqID, prevatom1.AtomName, atom2.AtomName, atom2.ResSeqID, prevatom2.AtomName, angle1, angle2);
if (angle1 > 90 && angle2 > 90)
{
if (atom1.BBNeighAtoms.Contains(atom2) == false)
{
atom1.BBNeighAtoms.Add(atom2);
newLine = string.Format("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}\t{9}\t{10}\t{11}", atom1.AtomName, Residue1.SeqID, Residue1.ThreeLetCode, Residue1.ChainName, atom2.AtomName, Residue2.SeqID, Residue2.ThreeLetCode, Residue2.ChainName, dist, LoopID, InLoop, loop_position);
backbone.WriteLine(newLine);
}
if (atom2.BBNeighAtoms.Contains(atom1) == false) atom2.BBNeighAtoms.Add(atom2);
}
}
}
else if ((atom1.AtomName == "N" && Residue1.ThreeLetCode == "PRO" && atom2.AtomName == "N" && Residue2.ThreeLetCode == "PRO") || (atom1.AtomName == "CA" && Residue1.ThreeLetCode == "GLY" && atom2.AtomName == "CA" && Residue2.ThreeLetCode == "GLY")) //check Gly-Gly or Pro-Pro
{
dist = (atom1.Coords - atom2.Coords).Length();
if (dist < 6)
{
prevatom1 = Residue1.Atoms[Residue1.Atoms.FindIndex(a => a.AtomName == "C")];
prevatom1_coords = prevatom1.Coords;
prevatom2 = Residue2.Atoms[Residue2.Atoms.FindIndex(a => a.AtomName == "C")];
prevatom2_coords = prevatom2.Coords;
for (var i = Residue1.Atoms.FindIndex(a => a.AtomName == atom1.AtomName) - 1; i > 0; i--)
{
if (Residue1.Atoms[i].AtomType == "C")
{
prevatom1 = Residue1.Atoms[i];
prevatom1_coords = Residue1.Atoms[i].Coords; i = 0;
}
else continue;
}
for (var i = Residue2.Atoms.FindIndex(a => a.AtomName == atom2.AtomName) - 1; i > 0; i--)
{
if (Residue2.Atoms[i].AtomType == "C")
{
prevatom2 = Residue2.Atoms[i];
prevatom2_coords = Residue2.Atoms[i].Coords; i = 0;
}
else continue;
}
Vector3 interatom = (atom1.Coords) - prevatom1_coords;
Vector3 intraatom = atom1.Coords - atom2.Coords;
angle1 = AngleBetween(interatom, intraatom);
interatom = (atom2.Coords) - prevatom2_coords;
angle2 = 180 - AngleBetween(interatom, intraatom);
if (angle1 > 90 && angle2 > 90)
{
if (atom1.SCSCNeighAtoms.Contains(atom2) == false)
{
atom1.SCSCNeighAtoms.Add(atom2);
newLine = string.Format("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}\t{9}\t{10}\t{11}", atom1.AtomName, Residue1.SeqID, Residue1.ThreeLetCode, Residue1.ChainName, atom2.AtomName, Residue2.SeqID, Residue2.ThreeLetCode, Residue2.ChainName, dist, LoopID, InLoop, loop_position);
SCfile.WriteLine(newLine);
}
if (atom2.SCSCNeighAtoms.Contains(atom1) == false) atom2.SCSCNeighAtoms.Add(atom1);
}
}
}
else if (bbatoms.Contains(atom2.AtomName) && bbatoms.Contains(atom1.AtomName) == false) //SC atom to bb atom
{
dist = (atom1.Coords - atom2.Coords).Length();
if (dist < 6)
{
//These lines set up in case can't find a prev atom, ie CA
prevatom1 = Residue1.Atoms[Residue1.Atoms.FindIndex(a => a.AtomName == "C")];
prevatom1_coords = prevatom1.Coords;
//Work backwards from atom1/atom2 to find closest C as this is the atom to which it is bonded previously in the residue
//ALso need to ID the atom before this
for (var i = Residue1.Atoms.FindIndex(a => a.AtomName == atom1.AtomName) - 1; i > 0; i--)
{
if (Residue1.Atoms[i].AtomType == "C")
{
prevatom1 = Residue1.Atoms[i];
prevatom1_coords = Residue1.Atoms[i].Coords; i = 0;
}
else continue;
}
//Bbatoms have specific geometries
prevatom2 = Residue2.Atoms[Residue2.Atoms.FindIndex(a => a.AtomName == "CA")]; //N-CA, CA-N, O-C
if (atom2.AtomName == "CA") prevatom2 = Residue2.Atoms[Residue2.Atoms.FindIndex(a => a.AtomName == "N")];
if (atom2.AtomName == "O") prevatom2 = Residue2.Atoms[Residue2.Atoms.FindIndex(a => a.AtomName == "C")];
prevatom2_coords = prevatom2.Coords;
Vector3 interatom = (atom1.Coords) - prevatom1_coords;
Vector3 intraatom = atom1.Coords - atom2.Coords;
angle1 = AngleBetween(interatom, intraatom);
interatom = (atom2.Coords) - prevatom2_coords;
angle2 = 180 - AngleBetween(interatom, intraatom); //180 is because intraatom points towards towards atom2 instead of away from it
//test_file.WriteLine("{0}_{1} {2} {3}_{4} {5} {6} {7}", atom1.AtomName, atom1.ResSeqID, prevatom1.AtomName, atom2.AtomName, atom2.ResSeqID, prevatom2.AtomName, angle1, angle2);
if (angle1 > 90 && angle2 > 90) //changed to && from || 2/22/18
{
if (atom1.SCBBNeighAtoms.Contains(atom2) == false)
{
atom1.SCBBNeighAtoms.Add(atom2);
newLine = string.Format("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}\t{9}\t{10}\t{11}", atom1.AtomName, Residue1.SeqID, Residue1.ThreeLetCode, Residue1.ChainName, atom2.AtomName, Residue2.SeqID, Residue2.ThreeLetCode, Residue2.ChainName, dist, LoopID, InLoop, loop_position);
bboneSC.WriteLine(newLine);
}
if (atom2.SCBBNeighAtoms.Contains(atom1) == false) atom2.SCBBNeighAtoms.Add(atom1);
}
}
}
else if (bbatoms.Contains(atom1.AtomName) || bbatoms.Contains(atom1.AtomName)) continue;
else
{
dist = (atom1.Coords - atom2.Coords).Length();
if (dist < 6)
{
prevatom1 = Residue1.Atoms[Residue1.Atoms.FindIndex(a => a.AtomName == "C")];
prevatom1_coords = prevatom1.Coords;
prevatom2 = Residue2.Atoms[Residue2.Atoms.FindIndex(a => a.AtomName == "C")];
prevatom2_coords = prevatom2.Coords;
for (var i = Residue1.Atoms.FindIndex(a => a.AtomName == atom1.AtomName) - 1; i > 0; i--)
{
if (Residue1.Atoms[i].AtomType == "C")
{
prevatom1 = Residue1.Atoms[i];
prevatom1_coords = Residue1.Atoms[i].Coords; i = 0;
}
else continue;
}
for (var i = Residue2.Atoms.FindIndex(a => a.AtomName == atom2.AtomName) - 1; i > 0; i--)
{
if (Residue2.Atoms[i].AtomType == "C")
{
prevatom2 = Residue2.Atoms[i];
prevatom2_coords = Residue2.Atoms[i].Coords; i = 0;
}
else continue;
}
Vector3 interatom = (atom1.Coords) - prevatom1_coords;
Vector3 intraatom = atom1.Coords - atom2.Coords;
angle1 = AngleBetween(interatom, intraatom);
interatom = (atom2.Coords) - prevatom2_coords;
angle2 = 180 - AngleBetween(interatom, intraatom);
if (angle1 > 90 && angle2 > 90)
{
if (atom1.SCSCNeighAtoms.Contains(atom2) == false)
{
atom1.SCSCNeighAtoms.Add(atom2);
newLine = string.Format("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}\t{9}\t{10}\t{11}", atom1.AtomName, Residue1.SeqID, Residue1.ThreeLetCode, Residue1.ChainName, atom2.AtomName, Residue2.SeqID, Residue2.ThreeLetCode, Residue2.ChainName, dist, LoopID, InLoop, loop_position);
SCfile.WriteLine(newLine);
}
if (atom2.SCSCNeighAtoms.Contains(atom1) == false) atom2.SCSCNeighAtoms.Add(atom1);
}
}
}
}
}
public static void findNearestNeighbors(List<Strand> strandlist, string outputDirectory, string pdbName)
{
int next_strand; Res neighbor; double dist; double neighDist;
create_dir(outputDirectory + "NearestNeighMono/CANeighbors");
string fileLocation = outputDirectory + "/NearestNeighMono/CANeighbors/NearestNeigh" + pdbName + ".txt";
using (System.IO.StreamWriter file = new System.IO.StreamWriter(fileLocation))
{
file.WriteLine("Res\tResNum\tStrand\tNearNeigh\tResNum\tStrand\tDistance Between\tZCoord");
foreach (Strand strand in strandlist)
{
int strandIndex = strandlist.IndexOf(strand);
if (strandIndex == strandlist.Count - 1) next_strand = 0;
else next_strand = strandIndex + 1;
foreach (Res Residue1 in strand)
{
neighbor = strandlist[next_strand].Residues[0]; //obviously, this is the neighbor furthest away b/c strands are antiparallel
foreach (Res Residue2 in strandlist[next_strand]) //potential neighbors are only sought out on next strand because barrels are circular and this prevents duplicates in reversed order in the output file
{
dist = (Residue1.BackboneCoords["CA"] - Residue2.BackboneCoords["CA"]).Length();
neighDist = (Residue1.BackboneCoords["CA"] - neighbor.BackboneCoords["CA"]).Length();
if (dist < neighDist)
{
neighbor = Residue2;
}
}
file.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t\t{7}", Residue1.ThreeLetCode, Residue1.SeqID, strand.StrandNum, neighbor.ThreeLetCode, neighbor.SeqID, strandlist[next_strand].StrandNum, (Residue1.BackboneCoords["CA"] - neighbor.BackboneCoords["CA"]).Length(), Residue1.BackboneCoords["CA"].Z);
if ((Residue1.BackboneCoords["CA"] - neighbor.BackboneCoords["CA"]).Length() < 6) Residue1.ShearNumNeigh = neighbor;
}
}
}
}
//This is the current implementation for partners
public static void findHBondingPartnersGeomOnly(List<Strand> strandlist, string outputDirectory, string pdbName)
{
create_dir(outputDirectory + "HBonding");
string newLine; bool IFstatus;
string fileLocation = outputDirectory + "HBonding/GeomSC" + pdbName + ".txt";
string fileLocation2 = outputDirectory + "HBonding/GeomBBone" + pdbName + ".txt";
string fileLocation3 = outputDirectory + "HBonding/GeomBBSC" + pdbName + ".txt";
using (System.IO.StreamWriter SCfile = new System.IO.StreamWriter(fileLocation))
{
newLine = "Atom" + "\t" + "Num" + "\t" + "Res" + "\t" + "Strand" + "\t" + "Chain" + "\t" + "Atom2" + "\t" + "Num" + "\t" + "Res2" + "\t" + "Strand" + "\t" + "Chain" + "\t" + "Dist";
SCfile.WriteLine(newLine);
using (System.IO.StreamWriter backbone = new System.IO.StreamWriter(fileLocation2))
{
backbone.WriteLine(newLine);
using (System.IO.StreamWriter bboneSC = new System.IO.StreamWriter(fileLocation3))
{
bboneSC.WriteLine(newLine);
foreach (Strand strand in strandlist)
{
int strandIndex = strandlist.IndexOf(strand);
foreach (Res Residue1 in strand)
{
foreach (Atom atom1 in Residue1)
{
if ((atom1.AtomName == "N" && Residue1.ThreeLetCode != "PRO") || (atom1.AtomName == "CA" && Residue1.ThreeLetCode != "GLY") || atom1.AtomName == "C" || atom1.AtomType == "H") continue;
else //Compare to chains on either side
{
int strand_check = 0;
while (strand_check < strandlist.Count())
{
////Console.WriteLine(strand_check);
if (strand_check != strandIndex)
{
foreach (Res Residue2 in strandlist[strand_check])
{
if ((strandIndex == 0 && (strand_check == strandlist.Count() - 1 || strand_check == strandlist.Count() - 2)) || (strandIndex == 1 && strand_check == strandlist.Count() - 1)) IFstatus = true;
else if ((strandIndex == strandlist.Count() - 1 && (strand_check == 0 || strand_check == 1)) || (strandIndex == strandlist.Count() - 2 && strand_check == 0)) IFstatus = true;
else IFstatus = false;
checkStrandsGeom(Residue1, atom1, Residue2, strand, strandlist, strand_check, IFstatus, backbone, bboneSC, SCfile);
}
}
strand_check += 1;
}
}
}
}
}
}
}
}
}
public static void checkStrandsGeom(Res Residue1, Atom atom1, Res Residue2, Strand strand, List<Strand> strandlist, int strand_num_compare, bool IFstatus, StreamWriter backbone, StreamWriter bboneSC, StreamWriter SCfile)
{
double dist; double angle1; double angle2;
Atom prevatom1 = atom1; Vector3 prevatom1_coords;
Atom prevatom2; Vector3 prevatom2_coords;
string newLine;
List<string> bbatoms = new List<string> { "O", "C", "N", "CA", "OXT" };
foreach (Atom atom2 in Residue2)
{
if (atom2.AtomType == "H") continue; //Skip all hydrogen
else if (bbatoms.Contains(atom2.AtomName) && atom1.AtomName == "O")
{
dist = (atom1.Coords - atom2.Coords).Length();
if (dist < 6)
{
if (atom1.BBNeighAtoms.Contains(atom2) == false)
{
atom1.BBNeighAtoms.Add(atom2);
newLine = string.Format("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}\t{9}\t{10}\t{11}\t{12}\t{13}", atom1.AtomName, Residue1.SeqID, Residue1.ThreeLetCode, strand.StrandNum, Residue1.ChainName, atom2.AtomName, Residue2.SeqID, Residue2.ThreeLetCode, strandlist[strand_num_compare].StrandNum, Residue2.ChainName, dist, IFstatus, Residue1.Inward, Residue2.Inward);
backbone.WriteLine(newLine);
}
if (atom2.BBNeighAtoms.Contains(atom1) == false) atom2.BBNeighAtoms.Add(atom2);
}
}
else if ((atom1.AtomName == "N" && Residue1.ThreeLetCode == "PRO" && atom2.AtomName == "N" && Residue2.ThreeLetCode == "PRO") || (atom1.AtomName == "CA" && Residue1.ThreeLetCode == "GLY" && atom2.AtomName == "CA" && Residue2.ThreeLetCode == "GLY")) //bbatoms.Contains(atom2.AtomName) = false
{
dist = (atom1.Coords - atom2.Coords).Length();
if (dist < 6)
{
prevatom1 = Residue1.Atoms[Residue1.Atoms.FindIndex(a => a.AtomName == "C")];
prevatom1_coords = prevatom1.Coords;
prevatom2 = Residue2.Atoms[Residue2.Atoms.FindIndex(a => a.AtomName == "C")];
prevatom2_coords = prevatom2.Coords;
for (var i = Residue1.Atoms.FindIndex(a => a.AtomName == atom1.AtomName) - 1; i > 0; i--)
{
if (Residue1.Atoms[i].AtomType == "C")
{
prevatom1 = Residue1.Atoms[i];
prevatom1_coords = Residue1.Atoms[i].Coords; i = 0;
}
else continue;
}
for (var i = Residue2.Atoms.FindIndex(a => a.AtomName == atom2.AtomName) - 1; i > 0; i--)
{
if (Residue2.Atoms[i].AtomType == "C")
{
prevatom2 = Residue2.Atoms[i];
prevatom2_coords = Residue2.Atoms[i].Coords; i = 0;
}
else continue;
}
Vector3 interatom = (atom1.Coords) - prevatom1_coords;
Vector3 intraatom = atom1.Coords - atom2.Coords;
angle1 = AngleBetween(interatom, intraatom);
interatom = atom2.Coords - prevatom2_coords;
angle2 = AngleBetween(interatom, intraatom);
if (angle1 > 90 || angle2 > 90)
{
if (atom1.SCSCNeighAtoms.Contains(atom2) == false)
{
atom1.SCSCNeighAtoms.Add(atom2);
newLine = string.Format("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}\t{9}\t{10}\t{11}\t{12}\t{13}", atom1.AtomName, Residue1.SeqID, Residue1.ThreeLetCode, strand.StrandNum, Residue1.ChainName, atom2.AtomName, Residue2.SeqID, Residue2.ThreeLetCode, strandlist[strand_num_compare].StrandNum, Residue2.ChainName, dist, IFstatus, Residue1.Inward, Residue2.Inward);
SCfile.WriteLine(newLine);
}
if (atom2.SCSCNeighAtoms.Contains(atom1) == false) atom2.SCSCNeighAtoms.Add(atom1);
}
}
}
else if (bbatoms.Contains(atom2.AtomName) && bbatoms.Contains(atom1.AtomName) == false) //(atom1.AtomName == "N" && Residue1.ThreeLetCode == "PRO") || (atom1.AtomName == "CA" && Residue1.ThreeLetCode == "GLY") ||
{
dist = (atom1.Coords - atom2.Coords).Length();
if (dist < 6)
{