-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathorigins.com
executable file
·1710 lines (1483 loc) · 57.6 KB
/
origins.com
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
#! /bin/tcsh -f
#
# origins.com - James Holton 9-18-19
#
# script for translating one PDB to a number of alternative origins
# and indexing conventions
# and checking if the symmetry-expanded atoms are close to those of
# another PDB.
#
# Atoms with the same name and resiude number are compared
#
set awk = awk
$awk 'BEGIN{print}' >& /dev/null
if($status) set awk = gawk
alias awk $awk
set SG = ""
set right_pdb = ""
set wrong_pdb = ""
set outfile = neworigin.pdb
set max_opeaks = 30
set min_opeak = 2.5
set skip_noid = 1
mkdir -p ${CCP4_SCR} >&! /dev/null
set tempfile = ${CCP4_SCR}/origins_temp$$
if($?debug) set tempfile = ./origins_temp
################################################################################
goto Setup
Help:
cat << EOF
usage: $0 right_origin.pdb wrong_origin.pdb $SG [correlate] [nochains]
where: right_origin.pdb is relative to your "desired" origin
wrong_origin.pdb is relative to another origin
$SG is your space group
wrong_origin.pdb will be moved to every possible origin in ${SG}
and then checked to see if the moved, and symmetry-expanded atoms
line up with the ones in right_origin.pdb.
The results of the origin choice that give the best agreement
to the reference pdb will be copied to $outfile
Using the word "correlate" on the command line signals the program
to ignore atom names in the comparision and instead use the correlation
coefficient of calculated electron density maps as the "similarity score"
By default, the program breaks up the input PDB files into any "chains"
specified therein. You can turn this off by using the word "nochains" on
the command line.
Using the word "otherhand" will also check for hand-inversion.
Using the word "altindex" will check for alternative indexing conventions.
Using the word "noorigins" will turn off the origin shift and just search
for symmetry-allowed alignments.
Using the word "fast" will skip atom-by-atom label re-assignments and stop
if a match is better than rmsd=1 or CC=0.8.
EOF
exit 9
Return_from_Setup:
################################################################################
set SCORE = "rmsd"
if($?CORRELATE) set SCORE = " CC "
# get unit cell from either pdb
set CELL = `awk '/^CRYST/{print $2,$3,$4,$5,$6,$7}' $right_pdb $wrong_pdb | head -1`
if("$CELL" == "") then
echo "ERROR: no CRYST card in $right_pdb"
goto Help
endif
# just in case these are different?
set right_cell = `awk '/^CRYST/{print $2,$3,$4,$5,$6,$7}' $right_pdb | head -1`
set wrong_cell = `awk '/^CRYST/{print $2,$3,$4,$5,$6,$7}' $wrong_pdb | head -1`
if("$right_cell" == "") set right_cell = "$CELL"
if("$wrong_cell" == "") set wrong_cell = "$right_cell"
# make the wrong_cell the default, so we are moving in allowed space
set CELL = ( $wrong_cell )
# try to get space group?
if("$SG" == "") then
set pdbSG = `awk '/^CRYST/{print substr($0,56,12)}' $right_pdb $wrong_pdb | head -1`
set SG = `awk -v pdbSG="$pdbSG" -F "[\047]" 'pdbSG==$2{print;exit}' ${CLIBD}/symop.lib | awk '{print $4}'`
endif
if("$SG" == "") then
# hmm, throw an error or go on? ...
set SG = P1
endif
set right_latt = `echo $SG | awk '{print substr($0,1,1)}'`
# check for H3/R3 weirdness
set test = `echo $CELL | awk '{print ( $4+0==90 && $5+0==90 && $6+0==120 )}'`
if("$right_latt" == "R" && "$test" == "1" ) then
# probably should use hexagonal system
set SG = `echo $SG | awk '{gsub("R","H");print}'`
endif
if("$right_latt" == "H" && "$test" == "0" ) then
# probably should use rhombohedral system
set SG = `echo $SG | awk '{gsub("H","R");print}'`
endif
# check if wrong pdb has different info
set wrong_pdbSG = `awk '/^CRYST/{print substr($0,56,12)}' $right_pdb $wrong_pdb | head -1`
set wrong_SG = `awk -v pdbSG="$wrong_pdbSG" -F "[\047]" 'pdbSG==$2{print;exit}' ${CLIBD}/symop.lib | awk '{print $4}'`
if("$wrong_SG" == "") set wrong_SG = $SG
set wrong_latt = `echo $wrong_SG | awk '{print substr($0,1,1)}'`
set test = `echo $wrong_cell | awk '{print ( $4+0==90 && $5+0==90 && $6+0==120 )}'`
if("$wrong_latt" == "R" && "$test" == "1" ) then
# probably should use hexagonal system
set wrong_SG = `echo $wrong_SG | awk '{gsub("R","H");print}'`
endif
if("$wrong_latt" == "H" && "$test" == "0" ) then
# probably should use rhombohedral system
set wrong_SG = `echo $wrong_SG | awk '{gsub("H","R");print}'`
endif
set wrong_latt = `echo $wrong_SG | awk '{print substr($0,1,1)}'`
# space group for correlation calculations
set CCSG = $SG
# preemtive cleanup
rm -f ${tempfile}_right[0-9][0-9][0-9].pdb >& /dev/null
rm -f ${tempfile}_wrong[0-9][0-9][0-9].pdb >& /dev/null
set reindexings = +X,+Y,+Z
# need to use the "lattice cell" for re-indexing pdb file
set lattCELL = ( $wrong_cell )
echo "CELL $wrong_cell" | pdbset xyzin $wrong_pdb xyzout ${tempfile}.pdb > /dev/null
cat ${tempfile}.pdb |\
awk '/^ATOM|^HETAT/{$0="ATOM 1 CA ALA 1 "substr($0,31,25)" 1.00 80.00"} \
/^ANIS/{next} {print}' |\
cat >! ${tempfile}reindexme.pdb
if(! $?ALTINDEX) goto otherhand
echo "finding all possible re-indexing operators..."
echo "within $wrong_cell on latt= $wrong_latt"
# find all possible reindexing operations
othercell << EOF | tee ${tempfile}othercell.log > /dev/null
$wrong_cell $wrong_latt
EOF
#set reciprocal_symops = `awk '/close to target:/{getline;while(/]$/){gsub("[][]","");print $NF;getline}}' ${tempfile}othercell.log | sort -u`
set lattCELL = `awk '/Lattice unit cell after reindexing/{print $6,$7,$8,$9,$10,$11}' ${tempfile}othercell.log`
echo "lattice cell for re-indexing coordinates: $lattCELL"
# need to use the "lattice cell" for re-indexing pdb file
# dont forget to change it back
echo "CELL $lattCELL" | pdbset xyzin $wrong_pdb xyzout ${tempfile}lattcell.pdb > /dev/null
cat ${tempfile}lattcell.pdb |\
awk '/^ATOM|^HETAT/{$0="ATOM 1 CA ALA 1 "substr($0,31,25)" 1.00 80.00"} \
/^ANIS/{next} {print}' |\
cat >! ${tempfile}reindexme.pdb
# get unit cell shifts associated with each re-indexing?
# gather all symmetry operators from all possible space groups for this cell
cat ${tempfile}othercell.log |\
awk '$1~/^</ && $NF~/>$/' | sort -u |\
awk '{split($0,w,"[<>]");print "SPACEGROUP",w[2]}' |\
cat - ${CLIBD}/symop.lib |\
awk '/^SPACEGROUP/{pdbSG=substr($0,12);\
#print "SG:",pdbSG;\
++seen[pdbSG];next}\
/[XYZ]/ && ! /[PCIFRH]/ && p==1 {print $1 $2 $3 $4}\
$5 ~ /^PG/{p=0} {split($0,w,"\047");pdbSG=w[2];if(seen[pdbSG])p=1}' |\
sort -u >! ${tempfile}all_symops
# and eliminate ones that are already in the space group to be used
cat ${CLIBD}/symop.lib |\
awk -v SG=$CCSG '/[XYZ]/ && ! /[PCIFRH]/ && p==1 {print $1 $2 $3 $4}\
$5 ~ /^PG/{p=0} $4 == SG{p=1}' |\
awk '{print "GOT",$0}' >! ${tempfile}SG_symops
echo "+X,+Y,+Z" >! ${tempfile}reindexings.txt
cat ${tempfile}SG_symops ${tempfile}all_symops |\
awk '/^GOT/{++got[substr($0,4)];next}\
! got[$0]{print}' |\
awk '{gsub(" ","");print}' |\
awk -F "," '{for(i=1;i<=NF;++i){print $i};print ""}' |\
awk '/^[^-]/{$0="+"$0} {print}' |\
awk 'NF==0{print substr(op,2);op=""} NF>0{op=op"," $0}' |\
cat >> ${tempfile}reindexings.txt
# get list of all alternative indexings to try
set reindexings = `cat ${tempfile}reindexings.txt`
echo "$#reindexings alternative indexing operators."
if(! $?debug) then
rm -f ${tempfile}symops
rm -f ${tempfile}all_symops
rm -f ${tempfile}SG_symops
rm -f ${tempfile}othercell.log
endif
# filter out equivalent operators?
echo "filtering out redundant re-indexing operators"
# do a coarser map grid sampling than normal (~ 3A resolution)
if(! $?reso) set reso = 3
set fakeCELL = `echo $lattCELL $reso | awk '{print $1/$NF/2,$2/$NF/2,$3/$NF/2,$4,$5,$6}'`
set BADD = `echo $reso | awk '{printf "%d", 79*($1/3)^2}'`
echo "CELL $fakeCELL" | pdbset xyzin $wrong_pdb xyzout ${tempfile}.pdb > /dev/null
# make an all-carbon version of this model
cat ${tempfile}.pdb |\
awk '/^ATOM|^HETAT/{$0="ATOM 1 CA ALA 1 "substr($0,31,25)" 1.00 5.00"}\
/^ANIS/{next} {print}' |\
cat >! ${tempfile}mapme.pdb
sfall xyzin ${tempfile}mapme.pdb mapout ${tempfile}right.map << EOF-sfall > /dev/null
MODE ATMMAP
CELL $fakeCELL
SYMM $CCSG
BADD $BADD
EOF-sfall
# recover coarse grid spacing
set coarseGRID = `echo "GO" | mapdump MAPIN ${tempfile}right.map | awk '/Grid sampling/{print $(NF-2), $(NF-1), $NF; exit}'`
rm -f ${tempfile}.pdb >& /dev/null
# now that we have a grid, make a safe version of whole file
set n = 0
foreach reindexing ( $reindexings )
@ n = ( $n + 1 )
#echo "applying $reindexing to $wrong_pdb"
pdbset xyzin ${tempfile}reindexme.pdb xyzout ${tempfile}reindexed.pdb << EOF > /dev/null
symgen $reindexing
BFACTOR 80
EOF
sfall xyzin ${tempfile}reindexed.pdb mapout ${tempfile}test_${n}.map << EOF > /dev/null
mode atmmap
resolution 3
GRID $coarseGRID
symm $SG
EOF
end
echo "maps done"
# now look for maps that are prefectly correlated, these indicate one of the ops is redundant
set redundant = ""
rm -f CC_vs_ij.log
foreach i ( `seq 1 $n` )
@ k = ( $i + 1 )
foreach j ( `seq $k $n` )
set test = `echo $i $j $redundant | awk '{for(k=3;k<=NF;++k){if($1==$k || $2==$k){print 1;exit}}}'`
if("$test" == "1") continue
echo "correlate section" |\
overlapmap mapin1 ${tempfile}test_${i}.map \
mapin2 ${tempfile}test_${j}.map mapout /dev/null |\
awk '/Total correlation/{print $NF}' >! ${tempfile}correlation
set CC = `awk '{print $1}' ${tempfile}correlation`
#echo "$CC $i $j" | tee -a CC_vs_ij.log
set test = `echo $CC | awk '{print ( $1 > 0.95 )}'`
if($test) then
# the jth operator is redundant with teh ith operator
set redundant = ( $redundant $j )
endif
end
end
foreach dupe ( $redundant )
set reindexings[$dupe] = ""
end
set reindexings = ( $reindexings )
echo "$#reindexings re-indexing operators remain:"
if(! $?debug) rm -f ${tempfile}correlation >& /dev/null
if(! $?debug) rm -f ${tempfile}test_*.map >& /dev/null
if(! $?debug) rm -f CC_vs_ij.log >& /dev/null
otherhand:
if($?OTHERHAND) then
echo "adding other hand..."
echo " $reindexings " |\
awk '{for(i=1;i<=NF;++i)print $i}' |\
awk '{print;\
gsub("+","q");gsub("-","+");gsub("q","-");\
print}' |\
cat >! ${tempfile}newops.txt
set reindexings = `sort -u ${tempfile}newops.txt`
echo "$#reindexings re-indexing operators remain:"
rm -f ${tempfile}newops.txt
endif
# now re-discover direct and reciprocal space operations
# first, make a reference mtz file for wrong_pdb expanded to P1
echo CELL $wrong_cell |\
pdbset xyzin ${tempfile}reindexme.pdb xyzout ${tempfile}ref.pdb > /dev/null
sfall xyzin ${tempfile}ref.pdb hklout ${tempfile}sfalled.mtz << EOF > /dev/null
mode sfcalc xyzin
resolution 3
symm $SG
EOF
cad hklin1 ${tempfile}sfalled.mtz hklout ${tempfile}P1.mtz << EOF > /dev/null
labin file 1 all
outlim P1
EOF
cad hklin1 ${tempfile}P1.mtz hklout ${tempfile}reindexme.mtz << EOF > /dev/null
labin file 1 all
symm 1
EOF
cp -p ${tempfile}sfalled.mtz ${tempfile}reindexme.mtz
# now loop over all real-space reindexing operators and see what they do in reciprocal space
rm -f ${tempfile}xyz_hkl_cell.log
foreach reindexing ( $reindexings )
pdbset xyzin ${tempfile}reindexme.pdb xyzout ${tempfile}.pdb << EOF > /dev/null
symgen $reindexing
BFACTOR 80
SPACE $SG
EOF
echo CELL $wrong_cell |\
pdbset xyzin ${tempfile}.pdb xyzout ${tempfile}reindexed.pdb > /dev/null
echo "tolerance 10" |\
pointless xyzin ${tempfile}reindexed.pdb \
hklin ${tempfile}reindexme.mtz \
hklout ${tempfile}reindexed.mtz |\
tee ${tempfile}pointless.log |\
awk '/Alternative /,NF==0' |\
awk '{print $4+0,$2}' | sort -gr |\
awk '{gsub(/[\]\[]/,"");print $2;exit}' |\
sort -u >! ${tempfile}reindexing.txt
set hkl = `cat ${tempfile}reindexing.txt`
set cell = `echo head | mtzdump hklin ${tempfile}reindexed.mtz | awk '/Cell Dimensions/{getline;getline;print}'`
echo "$reindexing $hkl $cell" |\
awk '{printf("%-20s %-10s %s %s %s %s %s %s\n",$1,$2,$3,$4,$5,$6,$7,$8)}' |\
tee -a ${tempfile}xyz_hkl_cell.log
end
if (! $?BYFILE) then
# break up "right" file into its respective chains
cat $right_pdb |\
awk '/^ATOM|^HETAT/{resnum=substr($0, 23, 4)+0;segid = substr($0, 22, 1); \
if(last_segid=="")last_segid=segid;\
if(resnum<last_resnum || (segid!=last_segid)) print "BREAK";\
last_resnum=resnum;last_segid=segid} {print}' |\
awk -v tempfile=${tempfile}_right 'BEGIN{chain="001"} /^ATOM|^HETAT/{segid = substr($0, 22, 1)}\
/^BREAK/{print "REMARK chain", segid > tempfile chain ".pdb";\
chain=sprintf("%03d", chain+1)}\
/^ATOM|^HETATM/{print "ATOM "substr($0,7,66) > tempfile chain ".pdb"}\
END{print "REMARK chain", segid > tempfile chain ".pdb"}'
# chains are now separated into files
# ${tempfile}_right###.pdb
# break up "wrong" file into its respective chains
cat $wrong_pdb |\
awk '/^ATOM|^HETAT/{resnum=substr($0, 23, 4)+0;segid = substr($0, 22, 1); \
if(last_segid=="")last_segid=segid;\
if(resnum<last_resnum || (segid!=last_segid)) print "BREAK";\
last_resnum=resnum;last_segid=segid} {print}' |\
awk -v tempfile=${tempfile}_wrong 'BEGIN{chain="001"} /^ATOM|^HETAT/{segid = substr($0, 22, 1)}\
/^BREAK/{print "REMARK chain", segid > tempfile chain ".pdb";\
chain=sprintf("%03d", chain+1)}\
/^ATOM|^HETAT/{print "ATOM "substr($0,7,66) > tempfile chain ".pdb"}\
END{print "REMARK chain", segid > tempfile chain ".pdb"}'
# chains are now separated into files
# ${tempfile}_wrong###.pdb
endif
# automatically switch to "nochains" mode if there is only one chain per PDB?
set test = `ls -1 ${tempfile}_right???.pdb ${tempfile}_wrong???.pdb | wc -l`
if("$test" == "2") set BYFILE
if($?BYFILE) then
echo "REMARK CHAIN _" >! ${tempfile}_right001.pdb
cat $right_pdb |\
awk '/^ATOM|^HETAT/{print "ATOM "substr($0,7,66)}' |\
cat >> ${tempfile}_right001.pdb
echo "REMARK CHAIN _" >> ${tempfile}_right001.pdb
echo "REMARK CHAIN _" >! ${tempfile}_wrong001.pdb
cat $wrong_pdb |\
awk '/^ATOM|^HETAT/{print "ATOM "substr($0,7,66)}' |\
cat >> ${tempfile}_wrong001.pdb
echo "REMARK CHAIN _" >> ${tempfile}_wrong001.pdb
endif
# add the proper headers
foreach file ( ${tempfile}_right[0-9][0-9][0-9].pdb ${tempfile}_wrong[0-9][0-9][0-9].pdb )
echo "END" >> $file
# make sure the cell gets encoded
set CELL = "$right_cell"
if("$file" =~ "*_wrong*") set CELL = "$wrong_cell"
# calculate the center of mass
pdbset xyzin $file xyzout ${tempfile}.pdb << EOF >! ${tempfile}.log
CELL $CELL
CHAIN " "
COM
EOF
egrep "^REMARK" $file >! ${tempfile}new.pdb
egrep -v "REMARK" ${tempfile}.pdb >> ${tempfile}new.pdb
mv ${tempfile}new.pdb ${tempfile}.pdb
# make a pdb file of an atom at the COM of this file
awk '/^CRYST/ || /^SCALE/' ${tempfile}.pdb >! ${tempfile}COM.pdb
cat ${tempfile}.log |\
awk '$1=="Center"{printf "ATOM 1 CA GLY 1 %8.3f%8.3f%8.3f 1.00 80.00\n", $4, $5, $6;exit}' |\
cat >> ${tempfile}COM.pdb
echo "END" >> ${tempfile}COM.pdb
# get fractional version of the COM too
coordconv XYZIN ${tempfile}COM.pdb XYZOUT ${tempfile}.xyz << EOF >& /dev/null
CELL $CELL
INPUT PDB
OUTPUT FRAC
EOF
# put this center as a remark in the PDB file
cat ${tempfile}.log |\
awk '$1=="Center"{print "COM", $4, $5, $6}' |\
cat - ${tempfile}.xyz |\
awk '{printf "REMARK " $0; getline; print " ", $2, $3, $4}' |\
cat >! $file
cat ${tempfile}.pdb |\
awk '/^REMARK/ && $NF=="chain"{print "REMARK chain _";next}\
/^REMARK/{print}' >> $file
cat ${tempfile}.pdb |\
awk '! /REMARK/{print substr($0,1,66)}' >> $file
rm -f ${tempfile}.pdb ${tempfile}COM.pdb ${tempfile}.xyz ${tempfile}.log >& /dev/null
# now "$file" has its center of mass in its header
end
# display stats
echo -n "reference chains: "
foreach file ( ${tempfile}_right[0-9][0-9][0-9].pdb )
awk '/^REMARK chain/{printf "%s ", $3;exit}' $file
end
echo " ( "`basename $right_pdb`" )"
echo -n " subject chains: "
foreach file ( ${tempfile}_wrong[0-9][0-9][0-9].pdb )
awk '/^REMARK chain/{printf "%s ", $3;exit}' $file
end
echo " ( "`basename $wrong_pdb`" )"
echo "CELL $CELL"
echo "SG $SG"
echo ""
################################
# get tranformations from a space group
# get symmetry operations from space group
cat ${CLIBD}/symop.lib |\
awk -v SG=$SG '/[XYZ]/ && ! /[PCIFRH]/ && p==1 {print $1 $2 $3 $4}\
$5 ~ /^PG/{p=0} $4 == SG{p=1}' |\
cat >! ${tempfile}symops
set symops = `cat ${tempfile}symops`
# get origin-shift operators from a space group (at the bottom of this script)
set table = $0
cat $table |\
awk '/TABLE OF ALLOWED ORIGIN SHIFTS/,/END OF THE TABLE/' |\
awk -v SG=$SG '/^[PCIFRH]/ && $0 ~ SG" "{getline; while(NF>0){\
print $1 "," $2 "," $3;getline};exit}' |\
cat >! ${tempfile}origins
# format: dX,dY,dZ
set origins = `cat ${tempfile}origins`
#set origins = `awk 'BEGIN{for(y=0;y<1;y+=0.01){print "0,"y",0";print "1/2,"y",0";print "0,"y",1/2";print "1/2,"y",1/2"}}'`
if($?NO_ORIGINS || "$origins" == "") then
set origins = "0,0,0"
set best_reindexing_origin = "+X,+Y,+Z_0,0,0"
set CCSG = 1
endif
rm -f ${tempfile}origins
rm -f ${tempfile}symops
if( $?NO_DECONV ) then
echo "skipping deconvolution step, using origins: $origins"
set reindexings = +X,+Y,+Z
set best_reindexing_origin = "+X,+Y,+Z_0,0,0"
set reindexing_origins = `echo $origins | awk '{for(i=1;i<=NF;++i){print "+X,+Y,+Z_"$i}}'`
echo "$reindexings h,k,l $CELL" |\
awk '{printf("%-20s %-10s %s %s %s %s %s %s\n",$1,$2,$3,$4,$5,$6,$7,$8)}' |\
cat >! ${tempfile}xyz_hkl_cell.log
goto skip_deconv
endif
deconvolute:
# preemtive:
rm -f ${tempfile}all_reindexing_origins.txt
# use deconvolution to find optimal shift
foreach reindexing ( $reindexings )
echo "applying $reindexing to $wrong_pdb"
set CELL = `awk -v key="$reindexing" '$1==key{print $3,$4,$5,$6,$7,$8;exit}' ${tempfile}xyz_hkl_cell.log`
set reindexing_hkl = `awk -v key="$reindexing" '$1==key{print $2;exit}' ${tempfile}xyz_hkl_cell.log`
echo "new cell: $CELL"
# apply the re-indexing operation, which is done in lattice cell
pdbset xyzin ${wrong_pdb} xyzout ${tempfile}lattcell.pdb << EOF > /dev/null
CELL $lattCELL
EOF
pdbset xyzin ${tempfile}lattcell.pdb xyzout ${tempfile}symmed.pdb << EOF > /dev/null
symgen $reindexing
EOF
# and then put back the relevant cell and SG in the header
pdbset xyzin ${tempfile}symmed.pdb xyzout ${tempfile}reindexed.pdb << EOF > /dev/null
CELL $CELL
space $SG
EOF
echo "deconvoluting maps..."
# do a coarser map grid sampling than normal, ~ 2A resolution
set reso = 2
# make a "mask" of all possible origin shifts
echo -n "" >! ${tempfile}xyz.txt
if("$SG" == "P1") then
echo "0 0 0" >> ${tempfile}xyz.txt
else
foreach origin ( $origins )
# break up the origin string
set Xf = `echo "$origin" | awk -F "," '{print $1}'`
set Yf = `echo "$origin" | awk -F "," '{print $2}'`
set Zf = `echo "$origin" | awk -F "," '{print $3}'`
set X = `echo "$Xf" | awk -F "/" 'NF==2{$1/=$2} {printf "%.10f",$1}'`
set Y = `echo "$Yf" | awk -F "/" 'NF==2{$1/=$2} {printf "%.10f",$1}'`
set Z = `echo "$Zf" | awk -F "/" 'NF==2{$1/=$2} {printf "%.10f",$1}'`
echo "$X $Y $Z $Xf $Yf $Zf" |\
awk '{print $1+0,$2+0,$3+0}\
$4=="x"{for(x=0;x<1;x+=0.001)print x,$2+0,$3+0}\
$5=="y"{for(y=0;y<1;y+=0.001)print $1+0,y,$3+0}\
$6=="z"{for(z=0;z<1;z+=0.001)print $1+0,$2+0,z}\
$4=="x=y=z"{for(x=0;x<2;x+=0.001)print x,x,x}' |\
cat >> ${tempfile}xyz.txt
end
endif
# make a frac coord file from all possible origin positions
cat ${tempfile}xyz.txt |\
awk 'NF>2{++n; printf "%5d%10.5f%10.5f%10.5f%10.5f%5.2f%5d%10d%2s%3s%3s %1s\n", \
n, $1, $2, $3, 80, 1, "38", n, "H", "", "IUM", " "}' |\
cat >! ${tempfile}.frac
coordconv XYZIN ${tempfile}.frac \
XYZOUT ${tempfile}originmask.pdb << EOF-conv >& /dev/null
CELL $CELL
INPUT FRAC
OUTPUT PDB ORTH 1
END
EOF-conv
sfall xyzin ${tempfile}originmask.pdb hklout ${tempfile}originmask.mtz << EOF-sfall > /dev/null
MODE sfcalc xyzin
CELL $CELL
SYMM 1
RESO $reso
EOF-sfall
fft hklin ${tempfile}originmask.mtz mapout ${tempfile}originmask.map << EOF >! ${tempfile}.log
labin F1=FC PHI=PHIC
scale F1 1 80
reso $reso
symm P1
EOF
# turn it into a binary mask
set scale = `awk '/Maximum density/ && $NF>0{print 1/$NF}' ${tempfile}.log`
rm -f ${tempfile}.log
if("$scale" == "") set scale = 1
echo "scale factor $scale 0" |\
mapmask mapin ${tempfile}originmask.map mapout ${tempfile}new.map > /dev/null
mv ${tempfile}new.map ${tempfile}originmask.map
echo "scale factor 0 1" |\
mapmask mapin ${tempfile}originmask.map mapout ${tempfile}one.map > /dev/null
# echo "mask cut 0" |\
# mapmask mapin ${tempfile}originmask.map mskout ${tempfile}originmask.msk > /dev/null
# echo "maps mult" |\
# mapmask mapin ${tempfile}one.map mskin ${tempfile}originmask.msk \
# mapout ${tempfile}originmask.map > /dev/null
if("$SG" == "P1") then
# P1 origin is good everywhere, so no mask
cp ${tempfile}one.map ${tempfile}originmask.map > /dev/null
endif
rm -f ${tempfile}one.map ${tempfile}originmask.mtz
rm -f ${tempfile}originmask.pdb ${tempfile}.frac ${tempfile}xyz.txt
# make an all-carbon version of right model
echo "CELL $right_cell" |\
pdbset xyzin $right_pdb xyzout ${tempfile}.pdb >! ${tempfile}.log
if($status) then
set BAD = "cannot set unit cell of right_pdb"
goto exit
endif
egrep "^CRYST1|^ATOM|^HETAT" ${tempfile}.pdb |\
awk '/^ATOM|^HETAT/{$0="ATOM 1 CA ALA 1 "substr($0,31,25)" 1.00 80.00"} {print}' |\
cat >! ${tempfile}mapme.pdb
sfall xyzin ${tempfile}mapme.pdb hklout ${tempfile}right.mtz << EOF-sfall >! ${tempfile}.log
MODE sfcalc xyzin
CELL $right_cell
SYMM $SG
RESO $reso
EOF-sfall
if($status) then
set BAD = "cannot sfall on right_pdb"
goto exit
endif
# make an all-carbon version of wrong, re-indexed model
echo "CELL $CELL" |\
pdbset xyzin ${tempfile}reindexed.pdb xyzout ${tempfile}.pdb > /dev/null
egrep "^CRYST1|^ATOM|^HETAT" ${tempfile}.pdb |\
awk '/^ATOM|^HETAT/{$0="ATOM 1 CA ALA 1 "substr($0,31,25)" 1.00 80.00"} {print}' |\
cat >! ${tempfile}mapme.pdb
sfall xyzin ${tempfile}mapme.pdb hklout ${tempfile}wrong.mtz << EOF-sfall >! ${tempfile}.log
MODE sfcalc xyzin
CELL $CELL
SYMM $SG
RESO $reso
EOF-sfall
if($status) then
set BAD = "cannot sfall on wrong_pdb"
goto exit
endif
rm -f ${tempfile}del.mtz
sftools << EOF > /dev/null
read ${tempfile}right.mtz
read ${tempfile}wrong.mtz
set labels
Fright
PHIright
Fwrong
PHIwrong
calc ( COL Fq PHIdel ) = ( COL Fright PHIright ) ( COL Fwrong PHIwrong ) /
calc COL W = COL Fq
select COL Fq > 1
calc COL W = 1 COL Fq /
select all
calc F COL Fdel = COL W 0.5 **
write ${tempfile}del.mtz col Fdel PHIdel
y
stop
EOF
fft hklin ${tempfile}del.mtz mapout ${tempfile}del.map << EOF >! ${tempfile}.log
labin F1=Fdel PHI=PHIdel
reso $reso
symm P1
EOF
# make sure that we define "sigma" for the unmasked map
echo "scale sigma 1 0" |\
mapmask mapin ${tempfile}del.map mapout ${tempfile}zscore.map > /dev/null
mapmask mapin1 ${tempfile}zscore.map mapin2 ${tempfile}originmask.map \
mapout ${tempfile}pickme.map << EOF >! ${tempfile}.log
mode mapin1 mapin2
maps mult
EOF
peakmax mapin ${tempfile}pickme.map xyzfrc ${tempfile}peak.txt << EOF >! ${tempfile}.log
output frac
# threshold 3
# numpeaks $max_opeaks
EOF
# this scale compensates for the mask, restoring "sigma" units
set scale = `awk '/peaks higher than the threshold/{print $(NF-1)/$9}' ${tempfile}.log`
# set scale = `awk '/Rms deviation from mean density/{print $NF}' ${tempfile}.log`
# echo | mapdump mapin ${tempfile}zscore.map | grep density
# echo | mapdump mapin ${tempfile}pickme.map | grep density
# head ${tempfile}peak.txt
# set scale = 1
echo "fractional origin shift Z-score"
cat ${tempfile}peak.txt |\
awk -v scale=$scale '/ATOM|^HETAT/{printf "%7.4f %7.4f %7.4f %s\n", $3,$4,$5,$6/scale}' |\
awk -v min_opeak=$min_opeak '$4>min_opeak' |\
awk 'NR==1{max=$4;print;next} \
max>=9 && $4>max/3 || max<9' |\
head -n $max_opeaks |\
tee ${tempfile}likely_origins.txt
wc -l ${tempfile}likely_origins.txt | awk '{print $1,"origins added."}'
# gather stats in case we need them
if(! $?maxpeak) set maxpeak = 0
set thismax = `awk -v scale=$scale '{print $6/scale}' ${tempfile}peak.txt |& sort -gr |& head -n 1`
set maxpeak = `echo $thismax $maxpeak | awk '$2>$1{$1=$2} {print $1}'`
# clean up a bit
rm -f ${tempfile}right.mtz ${tempfile}wrong.mtz
rm -f ${tempfile}del.mtz ${tempfile}del.map
rm -f ${tempfile}originmask.map ${tempfile}pickme.map ${tempfile}zscore.map
rm -f ${tempfile}peak.txt ${tempfile}.log
# now integrate these shifts with the "official" origin list
echo "ORIGINS $origins" |\
cat - ${tempfile}likely_origins.txt |\
awk '/^ORIGINS/{\
for(i=2;i<=NF;++i){\
++n;\
split($i,xyz,",");\
for(k in xyz){\
if(xyz[k]~/\//){\
split(xyz[k],w,"/");\
xyz[k]=w[1]/w[2];\
}\
}\
x0[n]=xyz[1];y0[n]=xyz[2];z0[n]=xyz[3];\
}\
}\
NF==4{x=$1;y=$2;z=$3;score=$4;\
minfd=999;\
for(i in x0){\
xp=x0[i];yp=y0[i];zp=z0[i];\
if(xp=="x")xp=x;\
if(yp=="y")yp=y;\
if(zp=="z")zp=z;\
if(xp=="x=y=z")xp=yp=zp=x;\
origin[i]= xp","yp","zp;\
fdx=sqrt((x-xp)^2);if(fdx>0.9)fdx-=1;\
fdy=sqrt((y-yp)^2);if(fdy>0.9)fdy-=1;\
fdz=sqrt((z-zp)^2);if(fdz>0.9)fdz-=1;\
fd=sqrt(fdx^2+fdy^2+fdz^2);\
if(fd<minfd){minfd=fd;best=i};\
};\
print score,1-minfd,origin[best], x,y,z;\
}' |\
awk -v op="$reindexing" '{print $0,op}' |\
tee -a ${tempfile}all_reindexing_origins.txt > /dev/null
# format: score rel_height x,y,z x y z reindexing
rm -f ${tempfile}likely_origins.txt
set goodenough = `awk '$1>50' ${tempfile}all_reindexing_origins.txt | wc -l`
if(("$goodenough" == "1") && ($?SPEEDUP)) then
echo "thats good enough..."
break
endif
end
set test = `cat ${tempfile}all_reindexing_origins.txt | wc -l`
echo "$test possible origins to explore."
if("$test" == "" || "$test" == "0") then
set test = `echo $min_opeak $maxpeak | awk '{print ($1>$2)}'`
if($test) then
set min_opeak = `echo $maxpeak | awk '{print $1*0.9}'`
echo "re-setting min_opeak to $min_opeak "
goto deconvolute
endif
set test = `echo $min_opeak 1 | awk '{print ($1>$2)}'`
if($test) then
echo "re-setting min_opeak to 1 "
set min_opeak = 1
goto deconvolute
endif
set BAD = "no significant origin peaks"
goto exit
endif
sort -gr ${tempfile}all_reindexing_origins.txt >! ${tempfile}neworigins.txt
set reindexing_origins = `awk '{ro=$7"_"$3} ! seen[ro]{print ro} {++seen[ro]}' ${tempfile}neworigins.txt`
set best_reindexing = `awk '{print $7;exit}' ${tempfile}neworigins.txt`
set CELL = `awk -v key="$best_reindexing" '$1==key{print $3,$4,$5,$6,$7,$8;exit}' ${tempfile}xyz_hkl_cell.log`
set reindexing_hkl = `awk -v key="$best_reindexing" '$1==key{print $2;exit}' ${tempfile}xyz_hkl_cell.log`
#rm -f ${tempfile}all_reindexing_origins.txt ${tempfile}neworigins.txt
#set reindexing_origins = `seq -1 0.05 2 | awk '{print "+X,+Y,+Z_0,"$1",0"}'`
#echo "GOTHERE: $reindexing_origins"
skip_deconv:
########################################
# now run through all origins, and chain pairings
echo "chain origin "
echo "r s reindexing dX dY dZ symop $SCORE"
again:
echo -n "" >! ${tempfile}scores
foreach right_chain ( ${tempfile}_right[0-9][0-9][0-9].pdb )
# get fractional coordinate limits that cover the "right" chain
coordconv xyzin $right_chain xyzout ${tempfile}.xyz << EOF >> /dev/null
INPUT PDB
OUTPUT FRAC
END
EOF
cat ${tempfile}.xyz |\
awk -v del=0.5 'BEGIN{xmin=ymin=zmin=99999999} \
$2<xmin{xmin=$2} $2>xmax{xmax=$2}\
$3<ymin{ymin=$3} $3>ymax{ymax=$3}\
$4<zmin{zmin=$4} $4>zmax{zmax=$4}\
END{print xmin-del, xmax+del, ymin-del, ymax+del, zmin-del, zmax+del}' |\
cat >! ${tempfile}.xyzlim
set xyzlim = `cat ${tempfile}.xyzlim`
rm -f ${tempfile}.xyzlim
rm -f ${tempfile}.xyz
if($?CORRELATE) then
# we want to do comparison with maps, not atoms
if(! $?coarseGRID) then
# do a coarser map grid sampling than normal (~ 3A resolution)
if(! $?reso) set reso = 3
set fakeCELL = `echo $CELL $reso | awk '{print $1/$NF/2,$2/$NF/2,$3/$NF/2,$4,$5,$6}'`
set BADD = `echo $reso | awk '{printf "%d", 79*($1/3)^2}'`
echo "CELL $fakeCELL" | pdbset xyzin $right_chain xyzout ${tempfile}.pdb > /dev/null
# make an all-carbon version of this model
cat ${tempfile}.pdb |\
awk '/^ATOM|^HETAT/{$0="ATOM 1 CA ALA 1 "substr($0,31,25)" 1.00 5.00"} {print}' |\
cat >! ${tempfile}mapme.pdb
sfall xyzin ${tempfile}mapme.pdb mapout ${tempfile}right.map << EOF-sfall > /dev/null
MODE ATMMAP
CELL $fakeCELL
SYMM $CCSG
BADD $BADD
EOF-sfall
# recover coarse grid spacing
set coarseGRID = `echo "GO" | mapdump MAPIN ${tempfile}right.map | awk '/Grid sampling/{print $(NF-2), $(NF-1), $NF; exit}'`
rm -f ${tempfile}.pdb >& /dev/null
endif
set GRID = "$coarseGRID"
# re-calculate the "right" map with reduced grid
cat $right_chain |\
awk '/^ATOM|^HETAT/{++n;$0="ATOM 1 CA ALA 1 "substr($0,31,25)" 1.00 5.00"} {print}' |\
awk '/^ATOM|^HETAT/{++n;}\
n==1{++n;\
print "ATOM 0 CA SHT 0 0.000 0.000 0.000 0.01 99.00";\
print "ATOM 0 CA SHT 0 0.000 0.000 0.000 -0.01 99.00";}\
{print}' |\
cat >! ${tempfile}mapme.pdb
sfall xyzin ${tempfile}mapme.pdb mapout ${tempfile}right.map << EOF-sfall > /dev/null
MODE ATMMAP
CELL $right_cell
SYMM $CCSG
GRID $GRID
BADD $BADD
EOF-sfall
rm -f ${tempfile}mapme.pdb >& /dev/null
# determine grid spacing to use for "wrong" map
set GRID = `echo "GO" | mapdump MAPIN ${tempfile}right.map | awk '/Grid sampling/{print $(NF-2), $(NF-1), $NF; exit}'`
# set xyzlim = "0 1 0 1 0 1"
endif
unset SKIP_CHAINPAIR
# now loop over the wrong chains
foreach wrong_chain ( ${tempfile}_wrong[0-9][0-9][0-9].pdb )
# no need to continue if there are no identities
if($?SKIP_CHAINPAIR) then
set test = `echo $SKIP_CHAINPAIR $right_chain $wrong_chain | awk '{print ( $1==$3 && $2==$4 )}'`
unset SKIP_CHAINPAIR
if($test && $skip_noid) continue
endif
# try every possible origin choice
foreach reindexing_origin ( $reindexing_origins )
if($?SKIP_CHAINPAIR) then
set test = `echo $SKIP_CHAINPAIR $right_chain $wrong_chain | awk '{print ( $1==$3 && $2==$4 )}'`
if($test && $skip_noid) break
endif
# break up the origin string
set reindexing = `echo $reindexing_origin | awk -F "_" '{print $1}'`
set CELL = `awk -v key="$reindexing" '$1==key{print $3,$4,$5,$6,$7,$8;exit}' ${tempfile}xyz_hkl_cell.log`
set reindexing_hkl = `awk -v key="$reindexing" '$1==key{print $2;exit}' ${tempfile}xyz_hkl_cell.log`
set origin = `echo $reindexing_origin | awk -F "_" '{print $2}'`
set Xf = `echo "$origin" | awk -F "," '{print $1}'`
set Yf = `echo "$origin" | awk -F "," '{print $2}'`
set Zf = `echo "$origin" | awk -F "," '{print $3}'`
set X = `echo "$Xf" | awk -F "/" 'NF==2{$1/=$2} {printf "%.10f",$1}'`
set Y = `echo "$Yf" | awk -F "/" 'NF==2{$1/=$2} {printf "%.10f",$1}'`
set Z = `echo "$Zf" | awk -F "/" 'NF==2{$1/=$2} {printf "%.10f",$1}'`
# apply this re-indexing to the "wrong" pdb
pdbset xyzin ${wrong_chain} xyzout ${tempfile}lattcell.pdb << EOF > /dev/null
CELL $lattCELL
EOF
# re-index the PDB in the lattice cell
pdbset xyzin ${tempfile}lattcell.pdb xyzout ${tempfile}symmed.pdb << EOF > /dev/null
symgen $reindexing
EOF
# and then put back the relevant cell and SG in the header
pdbset xyzin ${tempfile}symmed.pdb xyzout ${tempfile}wrong_reindexed.pdb << EOF > /dev/null
CELL $CELL
space $SG
EOF
# get the center of mass in orthogonal coordinates
pdbset xyzin ${tempfile}wrong_reindexed.pdb xyzout ${tempfile}.pdb << EOF >! ${tempfile}.log
COM
EOF
set wrong_COM = `awk '$1=="Center"{print $4,$5,$6}' ${tempfile}.log`
# make a pdb file of an atom at the COM of this file
awk '/^CRYST/ || /^SCALE/' ${tempfile}.pdb >! ${tempfile}COM.pdb
echo $wrong_COM |\
awk '{printf "ATOM 1 CA GLY 1 %8.3f%8.3f%8.3f 1.00 80.00\n", $1, $2, $3;exit}' |\
cat >> ${tempfile}COM.pdb
echo "END" >> ${tempfile}COM.pdb
# get fractional version of the COM too
coordconv XYZIN ${tempfile}COM.pdb XYZOUT ${tempfile}.xyz << EOF >& /dev/null
CELL $CELL
INPUT PDB
OUTPUT FRAC
EOF
set wrong_COM_frac = `awk '{print $2,$3,$4}' ${tempfile}.xyz`
# retrieve info from file headers
set right_COM = `awk '/^REMARK COM/{print $3, $4, $5;exit}' $right_chain`
#set wrong_COM = `awk '/^REMARK COM/{print $3, $4, $5;exit}' $wrong_chain`
set shift_COM = `echo "$wrong_COM $right_COM" | awk '{print $4-$1,$5-$2,$6-$3}'`
set right_COM_frac = `awk '/^REMARK COM/{print $6, $7, $8;exit}' $right_chain`
#set wrong_COM_frac = `awk '/^REMARK COM/{print $6, $7, $8;exit}' $wrong_chain`
set shift_COM_frac = `echo "$wrong_COM_frac $right_COM_frac" | awk '{print $4-$1,$5-$2,$6-$3}'`
set right_chain_ID = `awk '/^REMARK chain/{print $3}' $right_chain`
set wrong_chain_ID = `awk '/^REMARK chain/{print $3}' $wrong_chain`
if("$right_chain_ID" == "") set right_chain_ID = "_"
if("$wrong_chain_ID" == "") set wrong_chain_ID = "_"
# add translation along any polar axes
#set X = `echo "$opt_frac_shift $Xf $X" | awk '/x/{$NF=$1} {print $NF}'`
#set Y = `echo "$opt_frac_shift $Yf $Y" | awk '/y/{$NF=$2} {print $NF}'`
#set Z = `echo "$opt_frac_shift $Zf $Z" | awk '/z/{$NF=$3} {print $NF}'`
# calculate how to "level" the centers of the atom constellations
# NOTE: this is not a good idea if the chains are not rigid-body related
#set polar_slip = `echo "$opt_frac_shift $Xf $Yf $Zf" | awk '! /x/{$1=0} ! /y/{$2=0} ! /z/{$3=0} {print $1,$2,$3}'`
# now see which (if any) symops/cell translations will bring the
# shifted COM of "wrong_chain" anywhere near the COM of the "right" chain
# apply current origin shift to "wrong" COM
set new_COM = `echo "$wrong_COM_frac $X $Y $Z" | awk '{print $1+$4, $2+$5, $3+$6}'`
gensym << EOF >! ${tempfile}.log
CELL $CELL
SYMM $SG
atom X $new_COM
XYZLIM $xyzlim
EOF
# only use symops that showed up in the gensym result
cat ${tempfile}.log |\
awk '/List of sites/,/atoms generated from/' |\
awk 'NF>10{print $NF, $2, $3, $4, $5, $6, $7}' |\
sort -u -k1,1 >! ${tempfile}symop_center
# format: symop xf yf zf X Y Z
if($?CORRELATE && ! $?best_reindexing_origin) then
echo "1 $right_COM_frac $new_COM" >! ${tempfile}symop_center
endif
# loop over the symmetry operations
foreach line ( `awk '{print NR}' ${tempfile}symop_center` )
# skip all other origins if a good one has been found
if(("$good_origin" != "")&&("$good_origin" != "$X $Y $Z") && "$CCSG" != "1") then
# echo "skipping: $good_origin $X $Y $Z"
continue
endif
# skip rest of "right_chain" if we have already found a match
if("$good_right" == "$right_chain") then
# echo "skipping: $good_right == $right_chain"
continue
endif
if("$good_wrong" == "$wrong_chain") then
# echo "skipping: $good_wrong == $wrong_chain"
continue
endif
# retrieve symmetry operation
set symop = `awk -v line=$line 'NR==line{print $1}' ${tempfile}symop_center`
set symop = $symops[$symop]
# progress meter
echo "$right_chain_ID $wrong_chain_ID $reindexing $Xf $Yf $Zf $symop" |\
awk '{printf "%s vs %s by %-20s @ %3s %3s %3s %-20s", $1, $2, $3, $4,$5,$6, $7}'
# move the reindexed wrong PDB to the new position
pdbset xyzin ${tempfile}wrong_reindexed.pdb \