-
Notifications
You must be signed in to change notification settings - Fork 0
/
parseNuclei.m
1622 lines (1310 loc) · 49.7 KB
/
parseNuclei.m
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
% Load pdb file into structure
%
% Nuclei = parseNuclei(System,Method,datafile)
%
% Input:
% System structure with fields for the spin system
% Method structure with fields for the method
% pdbFileName name of PDB file
function [Nuclei, System]= parseNuclei(System,Method,Data,pdbFile)
if Method.useCentralSpinSystem
[Nuclei, System] = centralSpinSystem(System,Method,Data,System.pdb);
else
[Nuclei, System] = parseNuclei_defualt(System,Method,Data,pdbFile);
end
if System.Methyl.max_radius < inf
n_methyl = max(Nuclei.MethylID);
for id = 1:n_methyl
methyl_select = Nuclei.MethylID==id;
assert(sum(methyl_select)==3);
r_center = vecnorm(mean( Nuclei.Coordinates(methyl_select,:),1));
if r_center > System.Methyl.max_radius
Nuclei.methylTunnelingSplitting(methyl_select,methyl_select) = 0;
end
end
end
end
%<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
function [Nuclei, System]= parseNuclei_defualt(System,Method,Data,pdbFile)
% set values to unspecified fields
System = setIsotopeDefaults(System,Method);
spinCenter = System.spinCenter;
Nuclei.nStates = System.nStates;
Nuclei.number = 0;
nuT = System.Methyl.tunnel_splitting;
% Define spin operators.
%Nuclei =
defineSpinOperators(); %Nuclei,System, Method);
% Copy graphCriterion to Nuclei.
Nuclei.graphCriterion = Method.graphCriterion;
% scale volume
scaleFactor = System.scale;
if ischar(pdbFile)
Nuclei.dataSource = pdbFile;
% open data file
if ~strcmp(pdbFile,'System.RandomEnsemble.include')
% [pdbCoordinates,Type,UnitCell,Connected,Indices_nonSolvent,pdbID,MoleculeID,...
% numberH,isSolvent,isWater,Exchangeable,VanDerWaalsRadii] ...
pdbFile = parsePDB(pdbFile,System);
else
pdbCoordinates = [];
isSolvent = [];
Type = {};
UnitCell.isUnitCell = false;
numberH = [0,0,0];
end
end
pdbCoordinates = pdbFile.Coordinates;
Type = pdbFile.Type;
UnitCell = pdbFile.UnitCell;
Connected = pdbFile.Connected;
Indices_nonSolvent = pdbFile.Indices_nonSolvent;
pdbID = pdbFile.pdbID;
MoleculeID = pdbFile.MoleculeID;
numberH = pdbFile.numberH;
isSolvent = pdbFile.isSolvent;
isWater = pdbFile.isWater;
Exchangeable = pdbFile.Exchangeable;
VanDerWaalsRadii = pdbFile.VanDerWaalsRadii;
pdbFile = [];
Nuclei.isSolvent = isSolvent;
% Set electron coordinates in the pdb frame.
Nuclei.Electron_pdbCoordinates = getElectronCoordinates(System,pdbCoordinates,pdbID);
% number of PDB entries used
Npdb = length(Type);
if System.Methyl.include
[Methyl_Data,pdbCoordinates,Type,UnitCell,Connected,Indices_nonSolvent] = ...
findMethyls(System, pdbCoordinates,Type,UnitCell,Connected,...
Indices_nonSolvent);
Nuclei.Methyl_Data = Methyl_Data;
else
Nuclei.Methyl_Data = [];
end
% Get nuclear quadrupole parameters.
if System.nuclear_quadrupole
Nuclei.warnings.setQuadrupoleTensor = false;
% Water Quadrupole Values
% Edmonds, D. T.; Mackay, A. L.
% The Pure Quadrupole Resonance of the Deuteron in Ice.
% Journal of Magnetic Resonance (1969) 1975, 20 (3), 515–519.
% https://doi.org/10.1016/0022-2364(75)90008-6.
% eta = 0.112*ones(1,Npdb*numberUnitCells);
% e2qQh = 213.4e3*ones(1,Npdb*numberUnitCells); % Hz
end
% Decide whether or not to add randomly distributed hard spheres.
if System.RandomEnsemble.include
[pdbCoordinates,Type,Connected,Indices_nonSolvent,pdbID,MoleculeID,...
numberH,isSolvent,isWater,Exchangeable,VanDerWaalsRadii] = ...
addRandomSpins(System, Nuclei.Electron_pdbCoordinates, ...
pdbCoordinates,Type,Connected,Indices_nonSolvent,pdbID,...
MoleculeID,numberH,isSolvent,isWater,Exchangeable,VanDerWaalsRadii);
% number of PDB entries used
Npdb = length(Type);
if length(pdbID) ~= npdb || length(Indices_nonSolvent) ~= npdb ...
|| length(VanDerWaalsRadii) ~= npdb
error('Inconsistent output from addRandomSpins().')
end
end
System.UnitCell = UnitCell;
cellshifts = getCellShifts(pdbCoordinates, Nuclei.Electron_pdbCoordinates,...
System);
numberUnitCells = size(cellshifts,1);
if ~System.limitToSpinHalf
Nuclei.quadrupole2lab = zeros(3,3,numberH(2)*numberUnitCells);
Nuclei.Qtensor = zeros(3,3,Npdb*numberUnitCells);
Nuclei.quadrupoleXaxis = zeros(numberH(2)*numberUnitCells,3);
Nuclei.quadrupoleYaxis = zeros(numberH(2)*numberUnitCells,3);
Nuclei.quadrupoleZaxis = zeros(numberH(2)*numberUnitCells,3);
end
num_ = Npdb*numberUnitCells;
% Nuclei.hyperfine2lab = sparse(3*3,num_);
Nuclei.Atensor = sparse(num_,9);
Nuclei.FermiContact = sparse(num_,1);
Nuclei.hf_Tzz = sparse(num_,1);
Nuclei.number_1H_exchangeable = 0;
Nuclei.number_1H_nonExchangeable = 0;
Nuclei.number_2H_exchangeable = 0;
Nuclei.number_2H_nonExchangeable = 0;
Nuclei.pdbNumber = size(Type,2);
% loop over x unit cell spacings
iNuc = uint32(0);
for uc = 1:numberUnitCells
% 3-vector offset to put each nucleus in the correct unit cell
Delta_R = cellshifts(uc,:);
ElectronCenteredCoordinates = ...
scaleFactor*(pdbCoordinates + Delta_R - Nuclei.Electron_pdbCoordinates);
% loop over all nuclei
for inucleus = 1:Nuclei.pdbNumber
type = Type{inucleus};
% get nuclear connection data
try
Conect = Connected{inucleus};
catch
Conect = {};
end
% set nuclear coordinates relative to the electron
NuclearCoordinates = ElectronCenteredCoordinates(inucleus,:);
% skip if the electron-nuclear separation is over the set cutoff
if norm(NuclearCoordinates)>System.load_radius*scaleFactor
continue
end
if norm(NuclearCoordinates)<System.inner_radius*scaleFactor
continue
end
%[Nuclei,iNuc] =
setNucleus(); %Nuclei,type, inucleus,iNuc, Delta_R,...
% System,Method,isSolvent,Exchangeable,Type,ElectronCenteredCoordinates, ...
% NuclearCoordinates,pdbCoordinates,Conect,MoleculeID,isWater,spinCenter);
end
end
Nuclei.ucpdbID = (Nuclei.ucpdbID-1)*Nuclei.pdbNumber + Nuclei.pdbID;
% get number of nuclei
try
Nuclei.number = uint32(size(Nuclei.Index,2));
catch
warning('No nuclear spins found.')
return
end
% Define methyl tunneling for APAYDIN CLOUGH methyl coupling.
% J . PHYS. c (PROC. PHYS. SOC.), 1968, SER. 2, VOL. 1. PRINTED IN GREAT BRITAIN
% Nuclear magnetic resonance line shapes of methyl groups
% undergoing tunnelling rotation
Nuclei.methylTunnelingSplitting = sparse( ...
double(Nuclei.number),double(Nuclei.number));
for iNuc = 1:Nuclei.number
if strcmp(Nuclei.Type{iNuc}, 'CH3')
Nuclei.methylTunnelingSplitting(iNuc+1,iNuc+2) = nuT;
Nuclei.methylTunnelingSplitting(iNuc+1,iNuc+3) = nuT;
Nuclei.methylTunnelingSplitting(iNuc+2,iNuc+3) = nuT;
Nuclei.methylTunnelingSplitting(iNuc+2,iNuc+1) = nuT;
Nuclei.methylTunnelingSplitting(iNuc+3,iNuc+1) = nuT;
Nuclei.methylTunnelingSplitting(iNuc+3,iNuc+2) = nuT;
end
end
% Rotate coordinates if requested by user via System.X/Y/Z
% [Nuclei,System] =
setOrientation(); %Nuclei,System, pdbCoordinates);
% Clear excess entries.
% Nuclei =
cleanUpNuclei(); %Nuclei,System,Method,Npdb);
% Get coupling statistics.
% Nuclei =
computeNuclearInteractions(); %Nuclei,System, Method,scaleFactor);
if Data.writeSpinPDB
try
writeSpinPDB(Nuclei,ones(1,Nuclei.number),...
[Data.OutputData, '_spinSystem.pdb']);
end
end
% Clean
Nuclei.State = [];
if ~Method.getNuclearStatistics
Nuclei.Statistics = [];
Nuclei.DistanceMatrix = [];
end
if ~Method.getNuclearContributions
Nuclei.PDBCoordinates = [];
Nuclei.Element = [];
end
% if System.newIsotopologuePerOrientation
Nuclei.MoleculeIDunique = unique(Nuclei.MoleculeID);
% else
% Nuclei.MoleculeID = [];
% Nuclei.Connected = [];
% Nuclei.isWater = [];
% end
checkNuclei(Nuclei);
% end
%<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
function ... % Nuclei =
cleanUpNuclei()%Nuclei,System,Method,Npdb)
if ~System.limitToSpinHalf
Nuclei.quadrupole2lab(:,:,Nuclei.number+1:end) = [];
Nuclei.Qtensor(:,:,Nuclei.number+1:end) = [];
Nuclei.quadrupoleXaxis(Nuclei.number+1:end,:) = [];
Nuclei.quadrupoleYaxis(Nuclei.number+1:end,:) = [];
Nuclei.quadrupoleZaxis(Nuclei.number+1:end,:) = [];
end
Nuclei.isSolvent(Nuclei.number+1:end) = [];
% Nuclei.hyperfine2lab(:,Nuclei.number+1:end) = [];
Nuclei.Atensor(Nuclei.number+1:end,:) = [];
Nuclei.FermiContact(Nuclei.number+1:end) = [];
Nuclei.hf_Tzz(Nuclei.number+1:end) = [];
if System.doPruneNuclei
if System.newIsotopologuePerOrientation && ~Method.reparseNuclei
Nuclei = newHydronIsotopologue(Nuclei,System);
System.newIsotopologuePerOrientation = false;
end
keep = Nuclei.Spin == 1/2 | ...
vecnorm(Nuclei.Coordinates') <= Method.vertexCutoff.radius_nonSpinHalf(1);
oldIndex = Nuclei.Index;
newIndex = oldIndex;
cumsum_keep = cumsum(keep);
newIndex(keep) = cumsum_keep(keep);
newIndex(~keep) = 0;
newIndex(end:Npdb)=0;
Nuclei.Index = 1:sum(keep);
Nuclei.Type = Nuclei.Type(keep);
Nuclei.Element = Nuclei.Element(keep);
for iNuc = 1:Nuclei.number
Nuclei.Connected{iNuc} = newIndex(Nuclei.Connected{iNuc});
end
Nuclei.Connected = Nuclei.Connected(keep);
Nuclei.Spin = Nuclei.Spin(keep); % hbar
Nuclei.StateMultiplicity = Nuclei.StateMultiplicity(keep);
Nuclei.Nuclear_g = Nuclei.Nuclear_g(keep);
Nuclei.Coordinates = Nuclei.Coordinates(keep,:);
Nuclei.PDBCoordinates = Nuclei.PDBCoordinates(keep,:);
Nuclei.MoleculeID = Nuclei.MoleculeID(keep);
Nuclei.Exchangeable = Nuclei.Exchangeable(keep);
Nuclei.NumberStates = Nuclei.NumberStates(keep);
Nuclei.valid = Nuclei.valid(keep);
Nuclei.isWater = Nuclei.isWater(keep);
Nuclei.Abundance = Nuclei.Abundance(keep);
Nuclei.isSolvent = Nuclei.isSolvent(keep);
if ~System.limitToSpinHalf
Nuclei.quadrupole2lab = Nuclei.quadrupole2lab(:,:,keep);
Nuclei.Qtensor = Nuclei.Qtensor(:,:,keep);
Nuclei.quadrupoleXaxis = Nuclei.quadrupoleXaxis(keep,:);
Nuclei.quadrupoleYaxis = Nuclei.quadrupoleYaxis(keep,:);
Nuclei.quadrupoleZaxis = Nuclei.quadrupoleZaxis(keep,:);
end
% Nuclei.hyperfine2lab = Nuclei.hyperfine2lab(:,keep);
Nuclei.Atensor = Nuclei.Atensor(keep,:);
Nuclei.FermiContact = Nuclei.FermiContact(keep);
Nuclei.hf_Tzz = Nuclei.hf_Tzz(keep);
% get number of nuclei
try
Nuclei.number = uint32(size(Nuclei.Index,2));
catch
warning('No nuclear spins remaining after pruning.')
return
end
end
end
%>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
%<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
% Rotate coordinates if requested by user via System.X/Y/Z
%-------------------------------------------------------------------------------
function ... %[Nuclei,System] =
setOrientation()%Nuclei,System, pdbCoordinates)
containsXYZ = [isfield(System,'X') isfield(System,'Y') isfield(System,'Z')];
if sum(containsXYZ)>=2
% if nucleus index is given in X/Y/Z, calculate vector from electron to that
% nucleus
if containsXYZ(3)
if iscell(System.Z) && numel(System.Z)==2
z1_ = System.Z{1};
z2_ = System.Z{2};
System.Z = pdbCoordinates(z2_,:) - pdbCoordinates(z1_,:);
elseif length(System.Z)==1
System.Z = pdbCoordinates(System.Z,:) - Electron_pdbCoordinates;
end
end
if containsXYZ(2)
if iscell(System.Y) && numel(System.Y)==2
y1_ = System.Y{1};
y2_ = System.Y{2};
System.Y = pdbCoordinates(y2_,:) - pdbCoordinates(y1_,:);
elseif length(System.Y)==1
System.Y = pdbCoordinates(System.Y,:) - Electron_pdbCoordinates;
end
end
if containsXYZ(1)
if iscell(System.X) && numel(System.X)==2
x1_ = System.X{1};
x2_ = System.X{2};
System.X = pdbCoordinates(x2_,:) - pdbCoordinates(x1_,:);
elseif length(System.X)==1
System.X = pdbCoordinates(System.X,:) - Electron_pdbCoordinates;
end
end
% find the x and z unit vectors if one was not specified
if ~containsXYZ(1)
System.X = cross(System.Y,System.Z);
elseif ~containsXYZ(3)
System.Z = cross(System.X,System.Y);
end
% rotate system
Rotation = alignCoordinates(System.X,System.Z);
Nuclei.Coordinates = Nuclei.Coordinates*Rotation';
Rotation = rotateZYZ(System.RotateAlpha,System.RotateBeta,0);
Nuclei.Coordinates = Nuclei.Coordinates*Rotation';
end
if System.randomOrientation
% Generate random Euler angles.
alpha_ = rand()*2*pi;
beta_ = acos( 2*rand(1) - 1);
gamma_ = rand()*2*pi;
% Get rotation matrix.
Rotation = rotateZYZ(alpha_,beta_,gamma_);
% Rotate coordinates.
Nuclei.Coordinates = Nuclei.Coordinates*Rotation';
% Save rotation matrix.
Nuclei.RandomRotationMatrix = Rotation;
end
end
%>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
%<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
function ... % Nuclei =
defineSpinOperators()%Nuclei,System, Method)
nuT = System.Methyl.tunnel_splitting;
maxSize = 10;
maxClusterSize = [0,6,6];
if System.Methyl.methylMethylCoupling
methylFactor = 2*System.Methyl.include + 1;
maxClusterSize(2) = min(maxSize,methylFactor*Method.order);
else
maxClusterSize(2)= min(maxSize,Method.order + 3);
end
Nuclei.maxClusterSize = maxClusterSize;
Nuclei.SpinOperators = cell(1,4);
multiplicity = 1;
Nuclei.SpinOperators{multiplicity} = 1;
for multiplicity = 2:3
S = (multiplicity-1)/2;
Nuclei.SpinOperators{multiplicity} = ...
generateSpinOperators(S,maxClusterSize(multiplicity));
% rot = generateRotationMatrices(spinDim,numberMethyl)
end
if Method.allowHDcoupling % allowMixedSpins
[Nuclei.SpinOperators_HD,Nuclei.SpinXiXjOperators_HD,...
Nuclei.SpinXiXjOperators_DH] ...
= assembleMixedSpinOperator(...
Nuclei.SpinOperators{2}{1},Nuclei.SpinOperators{3}{1},true);
Nuclei.SpinOperators_DH = assembleMixedSpinOperator(...
Nuclei.SpinOperators{3}{1},Nuclei.SpinOperators{2}{1}, false);
end
if System.Methyl.method==0
% Nuclei.rotationalMatrix{clusterSize,numberOfMethyls}
% generateRotationMatrices(spinMultiplicity,numberOfMethyls)
Nuclei.rotationalMatrix{1,1} = -nuT/3*generateRotationMatrices(2^3,1);
Nuclei.rotationalMatrix{2,1} = -nuT/3*generateRotationMatrices(2*2^3,1);
if System.Methyl.methylMethylCoupling
Nuclei.rotationalMatrix{2,2} = -nuT/3*generateRotationMatrices(2^3*2^3,2);
end
%
% Nuclei.rotationalMatrix{2,1} = -nuT/3*generateRotationMatrices(2,1);
% Nuclei.rotationalMatrix{4,1} = -nuT/3*generateRotationMatrices(4,1);
% Nuclei.rotationalMatrix{4,2} = -nuT/3*generateRotationMatrices(4,2);
% Nuclei.rotationalMatrix{3,1} = -nuT/3*generateRotationMatrices(3,1);
% Nuclei.rotationalMatrix{9,1} = -nuT/3*generateRotationMatrices(9,1);
% Nuclei.rotationalMatrix{9,1} = -nuT/3*generateRotationMatrices(9,2);
else
Nuclei.rotationalMatrix = [];
end
Nuclei.SpinXiXjOperators = generateXiXjSpinOperators(1,maxClusterSize(3));
end
%>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
%<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
function ... %[Nuclei,iNuc] =
setNucleus()%Nuclei,type, inucleus,iNuc, Delta_R,...
% System,Method,isSolvent,Exchangeable,Type,ElectronCenteredCoordinates, ...
% NuclearCoordinates,pdbCoordinates,Conect,MoleculeID,isWater,spinCenter)
% H =============================================================
isProtium_ = (strcmp(type,'H') && System.protium);
if System.newIsotopologuePerOrientation && ~Method.reparseNuclei
doParseAs1H_ = isProtium_ && ~isSolvent(inucleus);
else
isDeuteriumTurnedProtium_ = ( strcmp(type,'D') && isSolvent(inucleus) ...
&& (rand() > System.deuteriumFraction) );
doParseAs1H_ = ...
(isProtium_ || isDeuteriumTurnedProtium_);
end
if doParseAs1H_
iNuc = iNuc +1;
Nuclei.Index(iNuc) = iNuc;
Nuclei.Type{iNuc} = '1H';
Nuclei.Element{iNuc} = type;
Nuclei.Connected{iNuc} = Conect;
Nuclei.Spin(iNuc) = 0.5; % hbar
Nuclei.StateMultiplicity(iNuc) = 2*Nuclei.Spin(iNuc) +1;
Nuclei.Nuclear_g(iNuc) = 5.58569;
Nuclei.Coordinates((iNuc),:) = NuclearCoordinates;
Nuclei.PDBCoordinates((iNuc),:)= pdbCoordinates(inucleus,:) + Delta_R;
Nuclei.pdbID(iNuc) = pdbID(inucleus);
Nuclei.ucpdbID(iNuc) = uc;
Nuclei.MoleculeID(iNuc) = MoleculeID(inucleus);
Nuclei.Exchangeable(iNuc) = Exchangeable(inucleus);
Nuclei.NumberStates(iNuc) = int8(2);
Nuclei.MethylID(iNuc) = 0;
Nuclei.valid(iNuc)= true;
Nuclei.Abundance(iNuc) = 1;
Nuclei.isSolvent(iNuc) = isSolvent(inucleus);
Nuclei.isWater(iNuc) = isWater(inucleus);
if Nuclei.Exchangeable(iNuc)
Nuclei.number_1H_exchangeable = Nuclei.number_1H_exchangeable + 1;
else
Nuclei.number_1H_nonExchangeable = Nuclei.number_1H_nonExchangeable + 1;
end
% CH3_A =========================================================
elseif strcmp(type,'CH3')
iNuc = iNuc +1;
Nuclei.Index(iNuc) = iNuc;
Nuclei.Type{iNuc} = 'CH3';
Nuclei.Element{iNuc} = type;
Nuclei.Connected{iNuc} = Conect;
Nuclei.Spin(iNuc) = 1/2; % hbar
Nuclei.StateMultiplicity(iNuc) = 2*Nuclei.Spin(iNuc) +1;
Nuclei.Nuclear_g(iNuc) = 5.58569;
Nuclei.Coordinates((iNuc),:) = NuclearCoordinates;
Nuclei.PDBCoordinates((iNuc),:)= pdbCoordinates(inucleus,:) + Delta_R;
Nuclei.pdbID(iNuc) = -1; % pdbID(inucleus);
Nuclei.ucpdbID(iNuc) = uc;
Nuclei.MoleculeID(iNuc) = MoleculeID(inucleus);
Nuclei.Exchangeable(iNuc) = false;
Nuclei.NumberStates(iNuc) = int8(8);
Nuclei.valid(iNuc)= System.Methyl.method~=2; %
ID_ref_ = find(Methyl_Data.ID(:,1)==inucleus);
methylID_ = Methyl_Data.ID(ID_ref_,2) + max(Methyl_Data.ID(:,2))*(uc - 1);
Nuclei.Group_ID{iNuc} = methylID_;
Nuclei.MethylID(iNuc) = -methylID_;
Nuclei.Auxiliary_ID(iNuc,:) = Methyl_Data.Hydron_ID{inucleus};
[Nuclei.State{iNuc}, Nuclei.Abundance(iNuc)] = getMethylState(System);
iNuc = iNuc +1;
Nuclei.number_1H_nonExchangeable = Nuclei.number_1H_nonExchangeable + 1;
Nuclei.Index(iNuc) = iNuc;
Nuclei.Type{iNuc} = 'CH3_1H';
Nuclei.Element{iNuc} = type;
Nuclei.Connected{iNuc} = Conect;
Nuclei.Spin(iNuc) = 0.5; % hbar
Nuclei.StateMultiplicity(iNuc) = 2*Nuclei.Spin(iNuc) +1;
Nuclei.Nuclear_g(iNuc) = 5.58569;
Nuclei.Coordinates((iNuc),:) = ...
scaleFactor*(...
Methyl_Data.Hydron_Coordinates{inucleus}(1,:) ...
+ Delta_R - Nuclei.Electron_pdbCoordinates);
Nuclei.PDBCoordinates((iNuc),:) = ...
Methyl_Data.Hydron_Coordinates{inucleus}(1,:) + Delta_R;
Nuclei.NumberStates(iNuc) = int8(2);
Nuclei.MethylID(iNuc) = methylID_;
Nuclei.valid(iNuc) = System.Methyl.method==2;
Nuclei.Abundance(iNuc) = 1;
iNuc = iNuc +1;
Nuclei.number_1H_nonExchangeable = Nuclei.number_1H_nonExchangeable + 1;
Nuclei.Index(iNuc) = iNuc;
Nuclei.Type{iNuc} = 'CH3_1H';
Nuclei.Element{iNuc} = type;
Nuclei.Connected{iNuc} = Conect;
Nuclei.Spin(iNuc) = 0.5; % hbar
Nuclei.StateMultiplicity(iNuc) = 2*Nuclei.Spin(iNuc) +1;
Nuclei.Nuclear_g(iNuc) = 5.58569;
Nuclei.Coordinates((iNuc),:) = ...
scaleFactor*(...
Methyl_Data.Hydron_Coordinates{inucleus}(2,:) ...
+ Delta_R - Nuclei.Electron_pdbCoordinates);
Nuclei.PDBCoordinates((iNuc),:) = ...
Methyl_Data.Hydron_Coordinates{inucleus}(2,:) + Delta_R;
Nuclei.NumberStates(iNuc) = int8(2);
Nuclei.MethylID(iNuc) = methylID_;
Nuclei.valid(iNuc)= System.Methyl.method==2;
Nuclei.Abundance(iNuc) = 1;
iNuc = iNuc +1;
Nuclei.number_1H_nonExchangeable = Nuclei.number_1H_nonExchangeable + 1;
Nuclei.Index(iNuc) = iNuc;
Nuclei.Type{iNuc} = 'CH3_1H';
Nuclei.Element{iNuc} = type;
Nuclei.Connected{iNuc} = Conect;
Nuclei.Spin(iNuc) = 0.5; % hbar
Nuclei.StateMultiplicity(iNuc) = 2*Nuclei.Spin(iNuc) +1;
Nuclei.Nuclear_g(iNuc) = 5.58569;
Nuclei.Coordinates((iNuc),:) = ...
scaleFactor*(...
Methyl_Data.Hydron_Coordinates{inucleus}(3,:) ...
+ Delta_R - Nuclei.Electron_pdbCoordinates);
Nuclei.PDBCoordinates((iNuc),:) = ...
Methyl_Data.Hydron_Coordinates{inucleus}(3,:) + Delta_R;
Nuclei.NumberStates(iNuc) = int8(2);
Nuclei.MethylID(iNuc) = methylID_;
Nuclei.valid(iNuc)= System.Methyl.method==2;
Nuclei.isWater(iNuc) = false;
Nuclei.Abundance(iNuc) = 1;
% D =============================================================
elseif strcmp(type,'D') && System.deuterium
if Exchangeable(inucleus)
Nuclei.number_2H_exchangeable = Nuclei.number_2H_exchangeable + 1;
else
Nuclei.number_2H_nonExchangeable = Nuclei.number_2H_nonExchangeable + 1;
end
if System.limitToSpinHalf
return;
end
iNuc = iNuc +1;
Nuclei.Index(iNuc) = iNuc;
Nuclei.Type{iNuc} = '2H';
Nuclei.Element{iNuc} = type;
Nuclei.Connected{iNuc} = Conect;
Nuclei.Spin(iNuc) = 1; % hbar
Nuclei.StateMultiplicity(iNuc) = 2*Nuclei.Spin(iNuc) +1;
Nuclei.Nuclear_g(iNuc) = 0.857438;
Nuclei.Coordinates((iNuc),:) = NuclearCoordinates;
Nuclei.PDBCoordinates((iNuc),:)= pdbCoordinates(inucleus,:) + Delta_R;
Nuclei.pdbID(iNuc) = pdbID(inucleus);
Nuclei.ucpdbID(iNuc) = uc;
Nuclei.MoleculeID(iNuc) = MoleculeID(inucleus);
Nuclei.Exchangeable(iNuc) = Exchangeable(inucleus);
Nuclei.NumberStates(iNuc) = int8(3);
Nuclei.MethylID(iNuc) = 0;
Nuclei.valid(iNuc)= true;
Nuclei.isWater(iNuc) = isWater(inucleus);
Nuclei.Abundance(iNuc) = 1;
Nuclei.isSolvent(iNuc) = isSolvent(inucleus);
% Set up quadrupole tensors for water deuterons
if System.nuclear_quadrupole && ~System.spinHalfOnly
if isempty(Conect)
error(['Nucleus %d is not connected to anything - ',...
'cannot build NQ tensor.'],inucleus);
end
for iconnect = Conect
switch Type{iconnect}
case {'O','C'}
zQ = ElectronCenteredCoordinates(iconnect,:) - NuclearCoordinates;
case {'M','D'}
xQ = ElectronCenteredCoordinates(iconnect,:) - NuclearCoordinates;
end
end
if isWater(inucleus)
% Water Quadrupole Values
% Edmonds, D. T.; Mackay, A. L.
% The Pure Quadrupole Resonance of the Deuteron in Ice.
% Journal of Magnetic Resonance (1969) 1975, 20 (3), 515–519.
% https://doi.org/10.1016/0022-2364(75)90008-6.
eta_ = 0.112;
e2qQh_ = 213.4e3; % Hz
else
% ORCA
eta_ = 0; % from eta_ = 0.0161;
e2qQh_ = 0.1945e6; % Hz
xQ = [0,0,0];
end
Nuclei = setQuadrupoleTensor(e2qQh_,eta_,zQ,xQ,iNuc,Nuclei,System);
end
% C ============================================================
elseif strcmp(type,'C') && System.carbon
iNuc = iNuc +1;
Nuclei.Index(iNuc) = iNuc;
Nuclei.Type{iNuc} = '13C';
Nuclei.Element{iNuc} = type;
Nuclei.Connected{iNuc} = Conect;
Nuclei.Spin(iNuc) = 0.5; % hbar
Nuclei.StateMultiplicity(iNuc) = 2*Nuclei.Spin(iNuc) +1;
Nuclei.Nuclear_g(iNuc) = 1.4048;
Nuclei.Coordinates((iNuc),:) = NuclearCoordinates;
Nuclei.PDBCoordinates((iNuc),:)= pdbCoordinates(inucleus,:);
Nuclei.pdbID(iNuc) = pdbID(inucleus);
Nuclei.ucpdbID(iNuc) = uc;
Nuclei.MoleculeID(iNuc) = MoleculeID(inucleus);
Nuclei.Exchangeable(iNuc) = Exchangeable(inucleus);
Nuclei.NumberStates(iNuc) = int8(2);
Nuclei.MethylID(iNuc) = 0;
Nuclei.valid(iNuc)= true;
Nuclei.isWater(iNuc) = isWater(inucleus);
Nuclei.isSolvent(iNuc) = isSolvent(inucleus);
Nuclei.Abundance(iNuc) = 0.0107;
% N =============================================================
elseif strcmp(type,'N') && System.nitrogen && ~System.limitToSpinHalf
iNuc = iNuc +1;
Nuclei.Index(iNuc) = iNuc;
Nuclei.Type{iNuc} = '14N';
Nuclei.Element{iNuc} = type;
Nuclei.Connected{iNuc} = Conect;
Nuclei.Spin(iNuc) = 1; % hbar
Nuclei.StateMultiplicity(iNuc) = 2*Nuclei.Spin(iNuc) +1;
Nuclei.Nuclear_g(iNuc) = 0.403761;
Nuclei.Coordinates((iNuc),:) = NuclearCoordinates;
Nuclei.PDBCoordinates((iNuc),:)= pdbCoordinates(inucleus,:);
Nuclei.pdbID(iNuc) = pdbID(inucleus);
Nuclei.ucpdbID(iNuc) = uc;
Nuclei.MoleculeID(iNuc) = MoleculeID(inucleus);
Nuclei.Exchangeable(iNuc) = Exchangeable(inucleus);
Nuclei.NumberStates(iNuc) = int8(3);
Nuclei.MethylID(iNuc) = 0;
Nuclei.valid(iNuc)= true;
Nuclei.isWater(iNuc) = isWater(inucleus);
Nuclei.isSolvent(iNuc) = isSolvent(inucleus);
Nuclei.Abundance(iNuc) = 0.99632;
switch spinCenter
case 'TEMPO'
if norm(NuclearCoordinates) < System.angstrom
Nuclei.FermiContact(iNuc) = 46.666666666666664*1e6; %Hz
Nuclei.hf_Tzz(iNuc) = 53.333333333333336*1e6; % Hz
if isempty(Conect)
error(['Nucleus %d is not connected to anything',...
'- cannot build NQ tensor.'],inucleus);
end
for iconnect = Conect
% Marsh, D.
% Bonding in Nitroxide Spin Labels from 14 N
% Electric–Quadrupole Interactions.
% J. Phys. Chem. A 2015, 119 (5), 919–921.
% https://doi.org/10.1021/jp512764w.
switch Type{iconnect}
case 'O'
xQ = ElectronCenteredCoordinates(iconnect,:) ...
- NuclearCoordinates;
case 'C'
yQ = ElectronCenteredCoordinates(iconnect,:) ...
- NuclearCoordinates;
end
end
zQ = cross(xQ,yQ);
Atensor_L = setHyperfineTensor( Nuclei.hf_Tzz(iNuc),...
Nuclei.FermiContact(iNuc),zQ,xQ,iNuc,Nuclei);
Nuclei.Atensor(iNuc,:) = Atensor_L(:)';
% Jeong, J.; Briere, T.; Sahoo, N.; Das, T. P.;
% Ohira, S.; Nishiyama, O.
% Theory of Nuclear Quadrupole Interactions of 14 N, 17O,
% and 35 CI Nuclei in p-Cl-Ph-CH-N=TEMPO.
% Z. Naturforsch 2002.
if System.nuclear_quadrupole
% e2qQh_ = 4.807*1e6; % Hz
% eta_ = 0.408;
% de Oliveira, M.; Knitsch, R.; Sajid, M.; Stute, A.;
% Elmer, L.-M.; Kehr, G.; Erker, G.; Magon, C. J.;
% Jeschke, G.; Eckert, H.
% Aminoxyl Radicals of B/P Frustrated Lewis Pairs:
% Refinement of the Spin-Hamiltonian Parameters by Field- and
% Temperature-Dependent Pulsed EPR Spectroscopy.
% PLoS ONE 2016, 11 (6), e0157944.
% https://doi.org/10.1371/journal.pone.0157944.
e2qQh_ = 3.5*1e6; % Hz
eta_ = 0.68;
Nuclei = setQuadrupoleTensor(...
e2qQh_,eta_,zQ,xQ,iNuc,Nuclei,System);
end
end
otherwise
Nuclei.FermiContact(iNuc) = 0;
end
% Si ============================================================
elseif strcmp(type,'Si') && System.silicon
iNuc = iNuc +1;
Nuclei.Index(iNuc) = iNuc;
Nuclei.Type{iNuc} = '29Si';
Nuclei.Element{iNuc} = type;
Nuclei.Connected{iNuc} = Conect;
Nuclei.Spin(iNuc) = 0.5; % hbar
Nuclei.StateMultiplicity(iNuc) = 2*Nuclei.Spin(iNuc) +1;
Nuclei.Nuclear_g(iNuc) = -1.11058;
Nuclei.Coordinates((iNuc),:) = NuclearCoordinates;
Nuclei.PDBCoordinates((iNuc),:)= pdbCoordinates(inucleus,:);
%Nuclei.pdbID(iNuc) = pdbID(inucleus);
Nuclei.MoleculeID(iNuc) = MoleculeID(inucleus);
Nuclei.Exchangeable(iNuc) = Exchangeable(inucleus);
Nuclei.NumberStates(iNuc) = int8(2);
Nuclei.MethylID(iNuc) = 0;
Nuclei.valid(iNuc)= true;
Nuclei.isWater(iNuc) = isWater(inucleus);
Nuclei.isSolvent(iNuc) = isSolvent(inucleus);
Nuclei.Abundance(iNuc) = 0.046832;
% electron ======================================================
elseif strcmp(type,'e')
% electron, not a nucleus
iNuc = iNuc +1;
Nuclei.Index(iNuc) = iNuc;
Nuclei.Type{iNuc} = 'e';
Nuclei.Element{iNuc} = type;
Nuclei.Connected{iNuc} = Conect;
Nuclei.Spin(iNuc) = 0.5; % hbar
Nuclei.StateMultiplicity(iNuc) = 2*Nuclei.Spin(iNuc) +1;
Nuclei.Nuclear_g(iNuc) = 2.0023;
Nuclei.Coordinates((iNuc),:) = NuclearCoordinates;
Nuclei.PDBCoordinates((iNuc),:)= pdbCoordinates(inucleus,:);
%Nuclei.pdbID(iNuc) = pdbID(inucleus);
Nuclei.MoleculeID(iNuc) = MoleculeID(inucleus);
Nuclei.Exchangeable(iNuc) = Exchangeable(inucleus);
Nuclei.NumberStates(iNuc) = int8(2);
Nuclei.MethylID(iNuc) = 0;
Nuclei.valid(iNuc)= true;
Nuclei.isWater(iNuc) = isWater(inucleus);
Nuclei.isSolvent(iNuc) = isSolvent(inucleus);
Nuclei.Abundance(iNuc) = 1;
elseif System.allAtoms
iNuc = iNuc +1;
Nuclei.Index(iNuc) = iNuc;
Nuclei.Type{iNuc} = type;
Nuclei.Element{iNuc} = type;
Nuclei.Connected{iNuc} = Conect;
Nuclei.Spin(iNuc) = 0; % hbar
Nuclei.StateMultiplicity(iNuc) = 2*Nuclei.Spin(iNuc) +1;
Nuclei.Nuclear_g(iNuc) = 0;
Nuclei.Coordinates((iNuc),:) = NuclearCoordinates;
Nuclei.PDBCoordinates((iNuc),:)= pdbCoordinates(inucleus,:);
Nuclei.MoleculeID(iNuc) = MoleculeID(inucleus);
Nuclei.Exchangeable(iNuc) = Exchangeable(inucleus);
Nuclei.NumberStates(iNuc) = int8(2);
Nuclei.valid(iNuc)= true;
Nuclei.isWater(iNuc) = isWater(inucleus);
Nuclei.isSolvent(iNuc) = isSolvent(inucleus);
Nuclei.Abundance(iNuc) = 1;
end
end
%>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
%<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
function ... %Nuclei =
computeNuclearInteractions()%Nuclei,System, Method,scaleFactor)
Nuclei.Statistics = getPairwiseStatistics(System, Method, Nuclei);
Nuclei.DistanceMatrix = Nuclei.Statistics.DistanceMatrix;
if System.Methyl.include
% TO DO: ADD CHECK.
elseif any(vecnorm(Nuclei.Coordinates,2,2) > System.radius*scaleFactor)
error(['Error in parseNuclei(): ','Nuclei beyond the distance cutoff ', ...
'remain in the system.'])
end
% Get the highest spin value.
Nuclei.maxSpin = max(Nuclei.Spin);
Nuclei.Adjacency = getAdjacencyMatrix(System,Nuclei, Method);
Nuclei.AntiAdjacency = getAntiAdjacencyMatrix(System, Nuclei, Method);
% Set the starting spin index and ending spin index.
Nuclei.startSpin = max(1, floor(Method.startSpin));
Nuclei.endSpin = min(Nuclei.number, floor(Method.endSpin));
% Check for consistancy.
if Nuclei.startSpin > Nuclei.endSpin
disp(['Starting cluster spin cannot be greater than ending spin. ', ...
'Swapping assignment.']);
Nuclei.startSpin = max(0, floor(Method.endSpin));
Nuclei.endSpin = min(Nuclei.number, floor(Method.startSpin));
end
Nuclei.numberStartSpins = ...
min(Nuclei.number, Nuclei.endSpin - Nuclei.startSpin + 1);
% set thermal energy
Nuclei.kT = System.kT;
% set thermal equilibrium state
[Nuclei.State, ~]= setThermalEnsembleState(System,Nuclei);
Nuclei.ZeemanStates = setRandomZeemanState(Nuclei);
[Nuclei.RandomDenityMatrices,Nuclei.RandomSpinVector] = ...
setRandomDensityMatrix(Nuclei);
end
%>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
end
%<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
function [Coordinates,Type,Connected,Indices_nonSolvent,pdbID,MoleculeID,...
numberH,isSolvent,isWater,Exchangeable,VanDerWaalsRadii] ...
= addRandomSpins(System, Electron_pdbCoordinates, ...
Coordinates,Type,Connected,Indices_nonSolvent,pdbID,...
MoleculeID,numberH,isSolvent,isWater,Exchangeable,VanDerWaalsRadii)
% radius to add spheres within
R_ = System.RandomEnsemble.radius;
% radius within which to avoid adding spheres
R0_ = System.RandomEnsemble.innerRadius;
% hard sphere radius
r0_ = System.RandomEnsemble.sphereRadius;
% Get random packing of hard spheres, centered on the origin.
[inCoor, N_] = generateRandomConcentrationEnsemble(...
System.RandomEnsemble.concentration,R_,R0_,2*r0_);
% Translate random ensemble to be centered on the elecron spin.
inCoor = inCoor + Electron_pdbCoordinates;
% Remove spheres that overlap with pdb input.
if ~isempty(Coordinates)
[outCoor, N_] = removeOverlap(inCoor,Coordinates,VanDerWaalsRadii);
else
outCoor = inCoor;
end
% number of pdb coordinates
M_ = size(Coordinates,2);
% Add random spins to pdb spin.
Coordinates = [Coordinates; outCoor];
% Loop through the new spins.
for ii = M_+N_:-1: M_+1
% Update spin info.
Type{ii} = System.RandomEnsemble.Type;
if strcmp(Type{ii},'H')
numberH(1) = numberH(1) + 1;
elseif strcmp(Type{ii},'D')
numberH(2) = numberH(2) + 1;
end
Exchangeable(ii) = System.RandomEnsemble.Exchangeable;
isSolvent(ii) = System.RandomEnsemble.isSolvent;
isWater(ii) = System.RandomEnsemble.isWater;
MoleculeID(ii) = ii;
pdbID(ii) = - ii + M_;
Indices_nonSolvent(ii) = ~isSolvent(ii);
Connected{ii} = [];
end
numberH(3) = numberH(1) + numberH(3);
end
%>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
%<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
% Sets the initial bath state with a Boltzmann distribution.
% Both output variables contain the same information, but are formated
% differently.
function [State,ZeemanStates] = setThermalEnsembleState(System,Nuclei)
ZeemanStates = zeros(Nuclei.number, 2*Nuclei.maxSpin+1);