-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathassignmentReport.qs
More file actions
1976 lines (1661 loc) · 105 KB
/
assignmentReport.qs
File metadata and controls
1976 lines (1661 loc) · 105 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
/*
-also check in peaklist for 13C assignment... and do not list if not found in peaklist or multiplet
*/
/******************************************************************************************************
Modified by Christophe Fares (from assignmentReport.qs by Damien Jeannerat) June 13th, 2018.
-added the function AssignmentReporter.JReport (which converts the J-couplings from the assignment table
in MNova to the <NMREDATA_J> tag
-added one line to chose the location and name of export file.
-changed name to NMReDATAExport and added the shortcut key CTRL+3 (with icon) for easy menu launch
*****************************************************************************************************/
/******************************************************************************************************
Generate .nmredata.sdf from Mnova 11
by Damien Jeannerat, University of Geneva
http://nmredata.org
Starting program: assignmenetReport.qs for Mnova V11.0.1-17801
*****************************************************************************************************/
/*globals Str, Molecule, Application, NMRAssignments, NMRSpectrum, settings, print, MessageBox, MnUi, FileDialog, Dir, File, TextStream, AssignmentReporter*/
/*jslint plusplus: true, indent: 4*/
function assignmentReport() {
'use strict';
var mol, assign, spectra, foundMulti, specIndex, spectrum, multi, standardReporter, correlationsReporter,
diag, drawnItems, tableText, pageItem, i, standardTable, Jtable, correlationsTable, table, cols, j, width,
addNumberOfNuclides, addMultiplicity, parameters, correlationsTableStart, assignmentsArray, format,
lines = 25,
dw = Application.mainWindow.activeDocument,
///////////////
version_nmredata=1.1,//
///////////////
end_of_line,
clipBoardKey = "Correlation Reporter/ClipBoard",
correlations2DKey = "Correlation Reporter/2D Correlations",
orderKey = "Correlation Reporter/Order by shift",
decimalsForProtonKey = "Correlation Reporter/Number of decimals for proton",
decimalsForCarbonKey = "Correlation Reporter/Number of decimals for carbon and x-nuclei",
decimalsForJcouplings = "Correlation Reporter/Number of decimals for carbon and x-nuclei",
showShiftKey = "Correlation Reporter/Show Shift",
includeMultiplicityKey = "Correlation Reporter/Include Multiplicity",
addNumberOfNuclidesKey = "Correlation Reporter/Add number of nuclides",
exportToFileKey = "Correlation Reporter/Export to File",
exportingFormatKey = "Correlation Reporter/Exporting Format",
dropLinesWithoutCorrelationKey = "Correlation Reporter/Drop Lines Without Correlation",
formatKey = "Correlation Reporter/Format",
showDeltaForCarbonKey = "Correlation Reporter/Show Delta for carbon",
reportTxtFileKey = "Correlation Reporter/Report Txt File",
compound_number = 0,found_it,full_path,seppath,//dja dd
path_elements,//add dj
nmredata_level = 0, //add dj
table_of_moleculeId=[],// add dj
// FileNameNmredata = "out_export_nmredata.sdf.txt",
file, stream, dataFile, outmol, //DJ add
assignedMolecules,pageItem,spec,doc,page,jii,ipa,pageCount,itemCount,cn,nb_mol_id,known_mol,lop_id,shiftav,debug=0,//add dj
reportHTMLFileKey = "Correlation Reporter/Report HTML File";
function getActiveMolecule(aDocWin, aMolPlugin) {
var mol = aMolPlugin.activeMolecule();
if (mol.isValid()) {
return mol;
}
if (aDocWin.itemCount("Molecule") === 1) {
mol = new Molecule(aDocWin.item(0, "Molecule"));
return mol;
}
return undefined;
}
function exportToFile(aFormat) {
// function exportToFile(parameters) {
function formatHeader(aHeader) {
var re, header = aHeader.toString();
re = new RegExp("<(.*?)>|[&;]", 'g');
header = header.replace(re, '');
return header;
}
}
function getCorrelationsArray() {
return ["HSQC", "HMBC", "H2BC", "COSY", "NOESY", "TOCSY", "ROESY"];
}
function getCorrelationsDescriptions() {
return [assign.realAssignedExp("HSQC"), "HMBC", "H2BC", assign.realAssignedExp("COSY"), assign.realAssignedExp("NOESY"), assign.realAssignedExp("TOCSY"), "ROESY"];
}
function getAssignmentsArray() {
var headerArray = [];
headerArray.push("No");
if (!addNumberOfNuclides && !addMultiplicity) {
headerArray.push("δ <sub>H</sub>");
} else if (addNumberOfNuclides && !addMultiplicity) {
headerArray.push("δ <sub>H</sub> (nH)");
} else if (!addNumberOfNuclides && addMultiplicity) {
headerArray.push("δ <sub>H</sub> (Mul, <i>J</i>)");
} else if (addNumberOfNuclides && addMultiplicity) {
headerArray.push("δ <sub>H</sub> (Mul, <i>J</i>, nH)");
}
return headerArray;
}
function getAssignmentsDescriptions() {
var headerArray = [];
headerArray.push("No");
if (!addNumberOfNuclides && !addMultiplicity) {
headerArray.push("δ <sub>H</sub>");
} else if (addNumberOfNuclides && !addMultiplicity) {
headerArray.push("δ <sub>H</sub> (nH)");
} else if (!addNumberOfNuclides && addMultiplicity) {
headerArray.push("δ <sub>H</sub> (Multiplicity, <i>J</i>)");
} else if (addNumberOfNuclides && addMultiplicity) {
headerArray.push("δ <sub>H</sub> (Multiplicity, <i>J</i>, nH)");
}
return headerArray;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (version_nmredata>1.0) {
end_of_line = "\\\n";
} else {
end_of_line = "\n";
}
if (dw === undefined || Application.molecule === undefined) {
return;
}
// dw.update();// does not work
//Application.mainWindow.activeDocument.update();// does not work
//%/%/%
// assignedMolecules = spectrum.getNMRAssignedMolecules();
// nmredata[looop_over_spectra] += " multi ID " + multi.id + " \n";
// for (iii = 0; iii < assignedMolecules.length; ++iii) {
// pageItem = assignedMolecules[iii];
// mol = new Molecule(pageItem);
// could loop over molecules issue
//%/%/%
//////////
/// assignedMolecules,pageItem,spec,doc,page,jii,ipa,pageCount,itemCount,//add dj
compound_number=-1;
nb_mol_id=0;
doc = Application.mainWindow.activeDocument;
for (ipa = 0, pageCount = doc.pageCount(); ipa < pageCount; ipa++) {
page = doc.page(ipa);
for (jii = 0, itemCount = page.itemCount(); jii < itemCount; jii++) {
spec = new NMRSpectrum(page.item(jii));
if (spec.isValid()){
//////////
// compound_number = 0;
assignedMolecules = spec.getNMRAssignedMolecules();
for (cn = 0; cn < assignedMolecules.length; ++cn) {
pageItem = assignedMolecules[cn];
mol = new Molecule(pageItem);
if (mol.isValid() && (mol !== undefined)){
known_mol=0;//false
for (lop_id = 0 ; lop_id < nb_mol_id; lop_id++){
if (mol.moleculeId === table_of_moleculeId[lop_id]){
known_mol=1;
}
}
if( known_mol === 0){
table_of_moleculeId[nb_mol_id]=mol.moleculeId;
nb_mol_id++;
compound_number++;
// before...
/* compound_number = 1;
mol = getActiveMolecule(dw, Application.molecule);
if (mol === undefined || !mol.isValid()) {
MessageBox.critical("Invalid Molecule");
return;
}*/
/// dj add to dump in file
// dataFile = "/Volumes/san256/users_for_mac_system_macPro/jeannerat/Dropbox/mrc_working_group/work_on_NMR_record_generation/dj_mnova_generate_nmredata_sdf_file/toto.txt";
// dataFile = "/Users/djeanner/Dropbox/mrc_working_group/work_on_NMR_record_generation/dj_mnova_generate_nmredata_sdf_file/toto.txt";
// dataFile = FileDialog.getSaveFileName("*.txt", "Save report in .sdf", settings.value(reportTxtFileKey, Dir.home()));
parameters = {};
parameters.name_compound = "compound" + (compound_number+1);
parameters.version_nmredata=version_nmredata;
// removed because not good if more than one mnova file for the same dataset
/* spectra = dw.itemCount("NMR Spectrum");
found_it = 1;
specIndex=0;
while ( specIndex < spectra && found_it) {//to list all
spectrum = new NMRSpectrum(dw.item(specIndex, "NMR Spectrum"));
full_path=spectrum.getParam("Data File Name");
path_elements = full_path.split("/");
seppath="/";
if (path_elements.length < 3) {
path_elements = full_path.split("\\");
seppath="\\";
}
// in case points to fid
if (path_elements[path_elements.length-1]==="fid" || path_elements[path_elements.length-1]==="ser"){
full_path="";
for (lo=0 ; lo <=path_elements.length-2 ; lo ++) {
full_path += path_elements[lo] + seppath;
}
full_path += "pdata/1/2rr" ;
path_elements = full_path.split("/");seppath="/";
if (path_elements.length < 3) {
path_elements = full_path.split("\\");seppath="\\";
}
}
parameters.name_compound= "/" + path_elements[path_elements.length-5] ;
found_it=0;
specIndex++;
}*/
dataFile = Dir.home() + "/" + parameters.name_compound + ".nmredata.sdf";//HERE MAIN FILENAME
// var filename = FileDialog.getSaveFileName("*.nmredata.sdf","Choose file",dataFile,4);
// dataFile = filename;
if (dataFile !== "") {
file = new File(dataFile);
//settings.setValue(reportTxtFileKey, dataFile);
file.open(File.WriteOnly);
stream = new TextStream(file);
//stream.writeln(Dir.home());
parameters.dataFile=dataFile;
parameters.stream=stream;
}
assign = new NMRAssignments(mol);
spectra = dw.itemCount("NMR Spectrum");
foundMulti = false;
specIndex = 0;
while (!foundMulti && specIndex < spectra) {
spectrum = new NMRSpectrum(dw.item(specIndex, "NMR Spectrum"));
if ((spectrum.nucleus() === "1H") && (spectrum.dimCount === 1)) {
foundMulti = true;
multi = spectrum.multiplets();
} else {
specIndex++;
}
}
if (!foundMulti) {
MessageBox.critical("Invalid Spectrum");// issue. not sure this is critical here..
return;
}
out_mol = mol.getMolfile();
stream.write(out_mol);// bug reported by JMN Nov 9 replaced writeln with write to have one less end-of-line char in the file
// output some comments
// output some comments
stream.writeln("> <NMREDATA_VERSION>\n" + version_nmredata + end_of_line );
stream.writeln("> <NMREDATA_LEVEL>\n" + nmredata_level + end_of_line);
stream.writeln("> <NMREDATA_ID>");
stream.writeln("Record=https://www.dropbox.com/sh/ma8v25g15wylfj4/AAA4xWi5w9yQv5RBLr6oDHila?dl=0\\");
stream.writeln("Path=compound1.nmredata.sdf\\");
stream.writeln("");
if (debug){
stream.writeln("> <COMMENT_TO_DEL> ");
//stream.writeln(path_elements[path_elements.length-5]);
stream.write(";comments on the mol... " + end_of_line);
stream.write(";comments on the mol... " + end_of_line);
stream.write(";molName :" + mol.molName + end_of_line);
stream.write(";label :" + mol.label + end_of_line);
stream.write(";Description :" + mol.Description + end_of_line);
stream.write(";molecularFormula :" + mol.molecularFormula() + end_of_line);
stream.writeln("");
}
////////////////////////////////////////////////////
////////////////////////////////////////////////////
////////////////////////////////////////////////////
////////////////////////////////////////////////////
////////////////////////////////////////////////////
////////////////////////////////////////////////////
///
/// / just for solvent
spectra = dw.itemCount("NMR Spectrum");
found_it = 1;
while ( specIndex < spectra && found_it) {//to list all
spectrum = new NMRSpectrum(dw.item(specIndex, "NMR Spectrum"));
stream.writeln("> <NMREDATA_SOLVENT>\n" + spectrum.solvent + end_of_line);
found_it=0;
specIndex++;
}
////////////////////////////////////////////////////
////////////////////////////////////////////////////
////////////////////////////////////////////////////
////////////////////////////////////////////////////
////////////////////////////////////////////////////
// output main molecule
// aCount = aMolecule.atomCount,
//assignmentReport.qs: atomLabel = aMolecule.atom(at).number;
//assignmentReport.qs: element = aMolecule.atom(at).elementSymbol;
// DBPlugin.qs: dbItem.addField("Bonds", aMolecule.bondCount);
stream.writeln("> <NMREDATA_ASSIGNMENT>");
stream.flush();
drawnItems = [];
// if (diag.exec()) {
settings.setValue(correlations2DKey, true);// diag.widgets.gb2DCorrelations.checked);
settings.setValue(decimalsForProtonKey, 4);//diag.widgets.sbDecimalsForProton.value);
settings.setValue(decimalsForCarbonKey, 4);//diag.widgets.sbDecimalsForCarbon.value);
settings.setValue(decimalsForJcouplings, 1);//diag.widgets.sbDecimalsForCarbon.value);
settings.setValue(orderKey, true);//diag.widgets.ckOrder.checked);
settings.setValue(showShiftKey, true);//diag.widgets.gbShowDeltaForCarbon.checked);
settings.setValue(exportToFileKey, true);//diag.widgets.gbExportToFile.checked);
settings.setValue(exportingFormatKey, true);//diag.widgets.rbText.checked);
settings.setValue(clipBoardKey, true);//diag.widgets.ckClipBoard.checked);
settings.setValue(includeMultiplicityKey, true);//diag.widgets.ckIncludeMultiplicity.checked);
settings.setValue(addNumberOfNuclidesKey, true);//diag.widgets.ckAddNumberOfNuclides.checked);
settings.setValue(dropLinesWithoutCorrelationKey, true);//diag.widgets.ckDropLinesWithoutCorrelation.checked);
settings.setValue(showDeltaForCarbonKey, true);//diag.widgets.ckShowDeltaForCarbon.checked);
settings.setValue(formatKey, 0);
addNumberOfNuclides = true;//diag.widgets.ckAddNumberOfNuclides.checked;
addMultiplicity = true;//diag.widgets.ckIncludeMultiplicity.checked;
assignmentsArray = getAssignmentsArray();
correlationsTableStart = assignmentsArray.length;
standardReporter = new AssignmentReporter(assignmentsArray, "Main", getAssignmentsDescriptions(), "Correlation Reporter/H&C");
correlationsReporter = new AssignmentReporter(getCorrelationsArray(), "2D Correlations", getCorrelationsDescriptions(), "Correlation Reporter/2D");
parameters.protonDecimals = 4;//diag.widgets.sbDecimalsForProton.value;
parameters.carbonDecimals = 4;//diag.widgets.sbDecimalsForCarbon.value;
parameters.jcouplingsDecimals = 1;//diag.widgets.sbDecimalsForJcouplings.value;
parameters.assignmentObject = assign;
parameters.molecule = mol;
parameters.reporter = standardReporter;
parameters.multi = multi;
parameters.addNumberOfNuclides = addNumberOfNuclides;
parameters.addMultiplicity = addMultiplicity;
parameters.showDeltaForCarbon = true;//diag.widgets.ckShowDeltaForCarbon.checked;
// parameters.FileNameNmredata = FileNameNmredata;
standardTable = AssignmentReporter.assignmentReport(parameters);
JTable = AssignmentReporter.jReport(parameters);
// if (diag.widgets.gb2DCorrelations.checked) {
parameters.reporter = correlationsReporter;
// if (diag.widgets.rbN.checked) {
// parameters.format = 0;
// } else if (diag.widgets.rbDeltaN.checked) {
// parameters.format = 1;
// } else if (diag.widgets.rbCnDelta.checked) {
parameters.format = 2;
// }
correlationsTable = AssignmentReporter.assignmentReportWithCorrelations(parameters);
// if (diag.widgets.gbExportToFile.checked) {
exportToFile(true);//exportToFile(diag.widgets.rbText.checked);
// }
// }
if (dataFile !== "") {
stream.writeln("$$$$");
stream.flush();
file.close();
}
}
}
}
}
}
}
dataFile = Dir.home() + "/mnova_process_done.txt";//HERE MAIN FILENAME
if (dataFile !== "") {
file = new File(dataFile);
//settings.setValue(reportTxtFileKey, dataFile);
file.open(File.WriteOnly);
stream = new TextStream(file);
stream.writeln("done");
stream.flush();
file.close();
}
dw.close();// close the document needed when running automatic scripts
// write file flagging end of process
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function AssignmentReporter(aArray, aDescription, aCorrelationDesc) {
'use strict';
this.fCorrelations = aArray;
this.fDescription = aDescription;
this.fCorrelationsDescription = aCorrelationDesc;
this.xNuclides = {"C": 2};
this.xNuclidesIndex = 2;
this.nucleids = {};
}
AssignmentReporter.prototype = {};
AssignmentReporter.getXNucleus = function (aElement, aAssignmentReporter) {
'use strict';
if (aAssignmentReporter.xNuclides[aElement] === undefined && aElement !== "H") {
aAssignmentReporter.xNuclidesIndex++;
aAssignmentReporter.xNuclides[aElement] = aAssignmentReporter.xNuclidesIndex;
}
return aAssignmentReporter.xNuclides[aElement];
};
AssignmentReporter.assignmentReport = function (parameters) {
'use strict';
var i, j, at, noEqHs, hIndex, atomLabel, atomRow, h, shift, hIsHeavyIndex, skip, shiftH, shiftH0, shiftH1, element, shifts, atomNH,
end_of_line,
aAssignmentObject = parameters.assignmentObject,
aMolecule = parameters.molecule,
aAssignmentReporter = parameters.reporter,
aMultiplets = parameters.multi,
aAddNumberOfNuclides = parameters.addNumberOfNuclides,
aAddMultiplicity = parameters.addMultiplicity,
aDecimals = parameters.protonDecimals,
aDecimalsForCarbon = parameters.carbonDecimals,
aCarbonAssignments = parameters.showDeltaForCarbon,
mol=parameters.molecule,
aCount = aMolecule.atomCount,
tableRows = {},
implicitH,//DJ add
tagc = "", tagh = "",//DJ add
lich = [], licc = [],//chemical shifts H and C
lith = [], litc = [],//text associated to shifts H and C
// FileNameNmredata = parameters.FileNameNmredata,
value_c_shift,//add DJ
label = "",//add DJ
counth = 0, countc = 0,//add dj
stream = parameters.stream,//add dj
dataFile = parameters.dataFile,//add dj
ii , //add dj
separ = ", ", nmredataLine,debug_assignment_tag = 0,//DJ add
debug=0,
headerRow = [];
/// here was ...
if (parameters.version_nmredata>1.0) {
end_of_line = "\\\n";
} else {
end_of_line = "\n";
}
if (aAssignmentReporter !== undefined) {
for (i = 0; i < aAssignmentReporter.fCorrelations.length; i++) {
headerRow.push(aAssignmentReporter.fCorrelationsDescription[i]);
}
}
for (at = 1; at <= aCount; at++) { // loop over atoms…
noEqHs = aAssignmentObject.notEqHs(at);
skip = true;
hIsHeavyIndex = false;
atomLabel = aMolecule.atom(at).number;
element = aMolecule.atom(at).elementSymbol;
atomNH = aMolecule.atom(at).nHAll;
//print(at,atomLabel,noEqHs);
if (noEqHs.length === 0 && element !== "H") { // if atom has no attached H and is not an explicit H itself...
atomRow = [];
atomRow[0] = AssignmentReporter.atomIndexToString(atomLabel, at);
shifts = [];
atomRow[1] = "";
nmredataLine="";
if (aCarbonAssignments) {// parameters.showDeltaForCarbon flag
shift = aAssignmentObject.chemShiftArr(at);
if (shift) {
if (shift[1]) {
shiftH0 = Number((shift[0].max + shift[0].min) / 2).toFixed(aDecimalsForCarbon);
shiftH1 = Number((shift[1].max + shift[1].min) / 2).toFixed(aDecimalsForCarbon);
atomRow[AssignmentReporter.getXNucleus(element, aAssignmentReporter)] = shiftH0 + "," + shiftH1;
nmredataLine= AssignmentReporter.atomIndexToString(atomLabel, at) + separ + Number((shift[0].max + shift[0].min) / 2).toFixed(aDecimalsForCarbon) + separ +at;// could add element
if (debug_assignment_tag){
nmredataLine += " ;K1";
}
}
else {
atomRow[AssignmentReporter.getXNucleus(element, aAssignmentReporter)] = Number((shift[0].max + shift[0].min) / 2).toFixed(aDecimalsForCarbon);
nmredataLine= AssignmentReporter.atomIndexToString(atomLabel, at) + separ + Number((shift[0].max + shift[0].min) / 2).toFixed(aDecimalsForCarbon) + separ + at ;// could add element
if (debug_assignment_tag){
nmredataLine += " ;K2";
}
}
}
else {
if (debug_assignment_tag){
nmredataLine=";" + AssignmentReporter.atomIndexToString(atomLabel, at) + separ + at + "delete this line atom type : " + element + "; K3 ";
}
if (element !== "C") {
atomRow[AssignmentReporter.getXNucleus(element, aAssignmentReporter)] = "";
} else {
atomRow[AssignmentReporter.getXNucleus(element, aAssignmentReporter)] = "-";
}
}
}
tableRows[atomRow[0]] = atomRow;
/// dj add to dump in file
if (dataFile !== "") {
if (debug_assignment_tag){
stream.write("; a:");
stream.write(atomRow + end_of_line);
}
if ( nmredataLine !== ""){
stream.write(nmredataLine + end_of_line);
}
stream.flush();
}
//
}
else { //if atom has attached 1Hs... or is an explicit H itself
for (hIndex = 0; hIndex < noEqHs.length; hIndex++) { //...loop over all atoms at that position (0:heavy, 1:first 1H, 2:second 1H...)
atomRow = [];
atomRow[0] = AssignmentReporter.atomIndexToString(atomLabel, at);
atomRow[1] = "";
shifts = [];
h = noEqHs[hIndex];
if (h === 0) {
hIsHeavyIndex = true; //flag for explicit 1H
}
shift = aAssignmentObject.chemShiftArr(at, h);
nmredataLine= "";
if (aMolecule.atom(at).elementSymbol !== "H") {
implicitH="H";
}
else{
implicitH="";
}
if (shift) {
if (noEqHs.length > 1) { //2 (or more?) 1H attached
atomRow[0] = AssignmentReporter.atomIndexToString(atomLabel, at, h, true);
label="H" + AssignmentReporter.atomIndexToString(atomLabel, at)
if (h==1){
label+="a";
}
else{
label+="b";
}
nmredataLine = label + separ + Number((shift[0].max + shift[0].min) / 2).toFixed(aDecimalsForCarbon) + separ + implicitH + at ;
if (debug_assignment_tag){
nmredataLine += " ;check explicit H2 is OK ; L3";
}
}
else{
if (noEqHs.length > 0) { //if 1 attached implicit 1H
atomRow[0] = AssignmentReporter.atomIndexToString(atomLabel, at, h, false);
label="H" + AssignmentReporter.atomIndexToString(atomLabel, at) ;
nmredataLine = label + separ + Number((shift[0].max + shift[0].min) / 2).toFixed(aDecimalsForCarbon) + separ + implicitH + at ;
if (debug_assignment_tag){
nmredataLine += " ;check explicit H is OK ; L2 element:" + aMolecule.atom(at).elementSymbol + " expli: " + implicitH;
}
}
}
skip = false;
if (shift[1]) {
shiftH0 = Number((shift[0].max + shift[0].min) / 2).toFixed(aDecimals);
shiftH1 = Number((shift[1].max + shift[1].min) / 2).toFixed(aDecimals);
shifts.push(shiftH0);
shifts.push(shiftH1);
}
else {
shiftH = Number((shift[0].max + shift[0].min) / 2).toFixed(aDecimals);
shifts.push(shiftH);
}
if (aAssignmentReporter.nucleids[atomRow[0] + "_" + shift]) {
aAssignmentReporter.nucleids[atomRow[0] + "_" + shift]++;
}
else {
if (noEqHs.length > 1) {
aAssignmentReporter.nucleids[atomRow[0] + "_" + shift] = 1;
} else {
if (shift.length > 1 || hIsHeavyIndex) {
aAssignmentReporter.nucleids[atomRow[0] + "_" + shift] = 1;
} else {
aAssignmentReporter.nucleids[atomRow[0] + "_" + shift] = atomNH;
}
}
}
atomNH = aAssignmentReporter.nucleids[atomRow[0] + "_" + shift];
atomRow[1] = AssignmentReporter.findInformation(aDecimals, aMultiplets, shifts, atomNH, aAddNumberOfNuclides, aAddMultiplicity, label);
lith[counth]= AssignmentReporter.findInformation(aDecimals, aMultiplets, shifts, atomNH, aAddNumberOfNuclides, aAddMultiplicity, label);
lich[counth]= shift;
counth++;
} else {
atomRow[1] = "-";
}
/// dj add to dump in file
if (dataFile !== "") {
if (debug_assignment_tag){
stream.write("; b:");
stream.write(atomRow + end_of_line);
}
if ( nmredataLine !== ""){
stream.write(nmredataLine + end_of_line);
}
stream.flush();
}
//
if (aCarbonAssignments) {// parameters.showDeltaForCarbon
nmredataLine ="";
shift = aAssignmentObject.chemShiftArr(at);
if (!hIsHeavyIndex && shift && element !== "H") {
skip = false;
if (shift[1]) {
shiftH0 = Number((shift[0].max + shift[0].min) / 2).toFixed(aDecimalsForCarbon);
shiftH1 = Number((shift[1].max + shift[1].min) / 2).toFixed(aDecimalsForCarbon);
atomRow[AssignmentReporter.getXNucleus(element, aAssignmentReporter)] = shiftH0 + "," + shiftH1;
nmredataLine = + AssignmentReporter.atomIndexToString(atomLabel, at) + separ + shiftH0 + separ + at ;
if (debug_assignment_tag){
nmredataLine += "; LC1";
}
nmredataLine = nmredataLine + "\n" + AssignmentReporter.atomIndexToString(atomLabel, at) + separ + shiftH1 + separ + at ;
if (debug_assignment_tag){
nmredataLine += "; LC2";
}
} else {
atomRow[AssignmentReporter.getXNucleus(element, aAssignmentReporter)] = Number((shift[0].max + shift[0].min) / 2).toFixed(aDecimalsForCarbon);
value_c_shift=Number((shift[0].max + shift[0].min) / 2).toFixed(aDecimalsForCarbon);
nmredataLine = AssignmentReporter.atomIndexToString(atomLabel, at) + separ + value_c_shift + separ + at;
if (debug_assignment_tag){
nmredataLine += " ; LC min/max:" + shift[0].max + " " + shift[0].min;
}
litc[countc]= value_c_shift;
licc[countc]= (shift[0].max + shift[0].min) / 2;
countc++;
}
/// dj add to dump in file
if ( hIndex === 0 ) {// only write c with the first proton bound to it
if (dataFile !== "") {
if (debug_assignment_tag){
stream.write("; c:");
stream.write(atomRow + end_of_line);
}
stream.write(nmredataLine + end_of_line);
stream.flush();
}
}
//
} else {
atomRow[AssignmentReporter.getXNucleus(element, aAssignmentReporter)] = "-";
}
}
tableRows[atomRow[0]] = atomRow;
}
}
}
stream.writeln("");// end of assignment tag DJ put back Nov 23
//Step 1: get the active atom A (can be any explicit atom (CHcount=0) in the structure or its implicit attached Hs (CHcount>0))
/// dj add to dump in file
if (dataFile !== "") {
if (debug){
stream.writeln("");
// stream.writeln("");
stream.writeln("> <DEBUG_1D_1H_NOTOK>");
stream.write(";not satisfactory..." + end_of_line);
// stream.write(lich[ii]); could be used to sort....
for (ii = 0; ii < counth; ii++) {
stream.writeln(lith[ii]);
}
counth=0;
stream.writeln("");
// stream.writeln("");
stream.writeln("> <DEBUG_1D_13C_NOTOK>");
stream.write(";not satisfactory..." + end_of_line);
// stream.write(licc[ii]); could be used to sort....
for (ii = 0; ii < countc; ii++) {
stream.writeln(litc[ii]);
}
counth=0;
stream.writeln("");
// stream.writeln("");
stream.flush();
}
// file.close();
}
//////
for (j in aAssignmentReporter.xNuclides) {
if (aAssignmentReporter.xNuclides.hasOwnProperty(j)) {
headerRow.push("δ <sub>" + j + "</sub>");
}
}
tableRows.header = headerRow;
return tableRows;
};
AssignmentReporter.jReport = function (parameters) {
'use strict';
var i, j, at, jc0, jat, jatomNH, jCH, jh, jvalue,
CHcount,
atomLabel,
atomNH,
end_of_line,
aAssignmentObject = parameters.assignmentObject,
aDecimals = parameters.jcouplingsDecimals,
aMolecule = parameters.molecule,
mol=parameters.molecule,
aCount = aMolecule.atomCount;
stream = parameters.stream,//add dj
/// here was ...
if (parameters.version_nmredata>1.0) {
end_of_line = "\\\n";
} else {
end_of_line = "\n";
}
EDATAJstream="";
for (at = 1; at <= aCount; at++) { // loop over atoms…
//print(aMolecule.atom(at));
atomLabel = aMolecule.atom(at).number; // atomnumber
atomNH = aMolecule.atom(at).nHAll; //get number of attached Hs
if(atomNH==2){ //for CH2: expect up to two H-shifts
CHcount=2; //
}
if(atomNH==0){ //for Cquat: expect no H-shift
CHcount=0;
}
if(atomNH==1 ||atomNH==3 ){ //for CH or CH3: expect up to one H-shift (might not work for heteroatoms??)
CHcount=1;
}
for (i = 0; i <= CHcount; i++) { // i is the aIndex i.e.-0 for heavy index. Bigger values to specify a proton number.
jc0 = aAssignmentObject.jConsts(at,i);
//print(jc0);
if (jc0) {
print(jc0);
if(i==0) {
element = "(" + aMolecule.atom(at).elementSymbol + ")";
atomLabel2 = /**/ "H" + atomLabel;// dj added H for explicit... (could remove it here AND at line 605)
}
if(i>0 && CHcount == 1) {
element = "(H)";
atomLabel2 = "H" + atomLabel;
}
if(i>0 && CHcount == 2) {
element ="(H)<" + aMolecule.atom(at).protonLabel(i) +">";
atomLabel2 = "H" + atomLabel + aMolecule.atom(at).protonLabel(i);
}
//Step2 : get passive atom B
for (j = 0; j < jc0.length; j++) { //cycle through all j-couplings for atom at
jat = jc0[j].atom.index; //jat is the passive atom number
jatomNH = aMolecule.atom(jat).nHAll;
jh = jc0[j].atom.h; //jh is the "atom index" of the passive atom (no value:explicit nucleus or a,b,c: one of the implicit attached Hs)
print(jat);
jatomLabel = aMolecule.atom(jat).number;
jCH = 0;
if (jh == "a"){
jCH=1;
}
if (jh == "b"){
jCH=2;
}
if (jh == "c"){
jCH=3;
}
//case 2.1: one of a methylene (CH2) proton: need to add a protonLabel: eg ' or ''
if((jCH == 2 || jCH == 1) && jatomNH == 2) {
jatomLabel2 = "H" + aMolecule.atom(jat).number + aMolecule.atom(jat).protonLabel(jCH);
}
//case 2.2: methyne or methyl (CH or CH3) proton: no need to add a protonLabel: eg ' or ''
if(jCH == 1 && (jatomNH == 1 ||jatomNH == 3)) {
jatomLabel2 = "H" + aMolecule.atom(jat).number;
}
//case 2.3: not an implicit H (this will work for explicit Hs)
if(jCH == 0) {
jatomLabel2 = /**/ "H" + aMolecule.atom(jat).number;// dj added H for explicit... (could remove it here AND at line 605)
}
jvalue =jc0[j].value.toFixed(aDecimals); //this is the J-coupling value
//Step 3: write entry as stream
if (jatomNH < 3 || (jatomNH == 3 && jCH == 1)){
//Case 3.1: coupling between different positions (eg 2J_CC, 3J_HH, 3_JCH)
//setting A<B insures that each coupling is entered only once (e.g. J_AB and not J_BA again later)
if (at < jat) {
//print(jc0);
EDATAJstream = EDATAJstream + atomLabel2 + ", " + jatomLabel2 + ", " + jvalue + end_of_line;
}
//Case 3.2: coupling within the same position number (eg 1J_CH, or 2J_HH)
//setting i<jCH ensures no replication of couplings (2JH'H'' but not 2JH''H')
//setting jCH < 3 ensures that methyl group J_CH don't get entered 3 times)
if (at == jat && i < jCH && jCH < 3 ) {
EDATAJstream = EDATAJstream + atomLabel2 + ", " + jatomLabel2 + ", " + jvalue + end_of_line;
}
}
}
}
}
}
stream.writeln("> <NMREDATA_J>");
stream.writeln(EDATAJstream);// end of jcoup tag
return EDATAJstream;
};
AssignmentReporter.assignmentReportWithCorrelations = function (parameters) {
'use strict';
var i, at, noEqHs, hIndex, atomRow, h, c, shift, atomLabel, element, correlations,
end_of_line ,
aAssignmentObject = parameters.assignmentObject,
aMolecule = parameters.molecule,
aAssignmentReporter = parameters.reporter,
aFormat = parameters.format,
aProtonDecimals = parameters.protonDecimals,
aCarbonDecimals = parameters.carbonDecimals,
correlationsArray = [],
aCount = aMolecule.atomCount,j,
tableRows = {},
iii,pageItem, mol,
assignString = "",
nmrAssignObject,
assignedMolecules,lll,//add dj
tmpString = "",
file,dataFile,stream,
// FileNameNmredata = parameters.FileNameNmredata,
headerRow = [],
dw = Application.mainWindow.activeDocument,lo,seppath,item_position=[],//dj add
type,//add dj
dataFile=parameters.dataFile,looop_over_spectra,//add dj
stream=parameters.stream,root_path,rel_path,//add dj
// spectrum,//add dj
test_type,path_elements,full_path,multi,lab,//add dj
spectra,spectrum,specIndex,found_it,found_sih,ii,ma,j,ama,apa,noEqHs,keep_type,full_path_orig,cur_spec_atom,found_one,tmpll,labArray = [],peaklist,//add dj
separ = ", ",smallest_cs,
position_of_smallest_diff,debug=0,max_delta_chemshift_for_peak_to_be_assigned_to_chemical_shift = 0.05,conn,tmpi,tmparr = [],chem_shift,
// emptynmr = [],
nmredata = [];
nmredata_header = [];
function sortFunctionForFloats(a, b) {
return parseFloat(a) - parseFloat(b);
}
tableRows.header = headerRow;
if (parameters.version_nmredata>1.0) {
end_of_line = "\\\n";
} else {
end_of_line = "\n";
}
if (aAssignmentReporter !== undefined) {
stream.flush();
//initialize output
spectra = dw.itemCount("NMR Spectrum");
specIndex=0;
while ( specIndex < spectra ) {//to list all
nmredata[specIndex+1] = "";
nmredata_header[specIndex+1] = "";
looop_over_spectra=specIndex+1;
spectrum = new NMRSpectrum(dw.item(specIndex, "NMR Spectrum"));
keep_type="na;Type was not identified" + spectrum.experimentType;
for (i = 0; i < aAssignmentReporter.fCorrelations.length; i++) {
headerRow.push(aAssignmentReporter.fCorrelationsDescription[i]);
// emptynmr[i] = true;
type= aAssignmentReporter.fCorrelationsDescription[i];
// specIndex=0;
test_type= "2D-" + type;
// loop over all spectra
// spectra = dw.itemCount("NMR Spectrum");
// found_it = 1;
// while ( specIndex < spectra && found_it) {//to list all
// while ( specIndex < spectra ) {//to list all
// spectrum = new NMRSpectrum(dw.item(specIndex, "NMR Spectrum"));
if ((spectrum.experimentType === test_type)) {
item_position[i]=specIndex+1;
keep_type=type;
}
// specIndex++;
// }
}
//
cur_spec_atom="";
label="";
if (spectrum.dimCount === 1) {
label = "> <NMREDATA_1D_" + spectrum.nucleus(1) + "";
cur_spec_atom=spectrum.nucleus(1);
cur_spec_atom=cur_spec_atom.replace(/[0-9]/g,"");// reploaces "13C" in to "C" - removed the numbers... convert isotope into element name
}
// the following lines apear at two places in the program... if change... change both...
if (keep_type === "HSQC") { label = "> <NMREDATA_2D_" + spectrum.nucleus(1) + "_1J_" + spectrum.nucleus(2) + ""; }
if (keep_type === "HMBC") { label = "> <NMREDATA_2D_13C_NJ_1H"; }
if (keep_type === "H2BC") { label = "> <NMREDATA_2D_13C_2J_1H"; }
if (keep_type === "COSY") { label = "> <NMREDATA_2D_" + spectrum.nucleus(1) + "_NJ_" + spectrum.nucleus(1) + ""; }
if (keep_type === "NOESY") { label= "> <NMREDATA_2D_" + spectrum.nucleus(1) + "_D_" + spectrum.nucleus(1) + ""; }
if (keep_type === "TOCSY") { label= "> <NMREDATA_2D_" + spectrum.nucleus(1) + "_TJ_" + spectrum.nucleus(1) + ""; }
if (spectrum.dimCount === 2){
if (label === ""){
// try to determine the type of experiment when not in the list of "official" Mnova type
if (spectrum.nucleus(2)===""){
lab= "_unidentified_homonuclear_2d_spectrum_" ;
}else{
lab = "_unidentified_heteronuclear_2d_spectrum_" ;
if ( spectrum.getParam("Pulse Sequence").find("hoesy",0) > -1){ lab="_D_";}// this is for hoesy see http://nmredata.org/wiki/NMReDATA_tag_format#Naming_tags_for_nD
}
if (spectrum.nucleus(2)===""){
label += "> <NMREDATA_2D_" + spectrum.nucleus(1) + lab + spectrum.nucleus(1) + "";
}else{
label += "> <NMREDATA_2D_" + spectrum.nucleus(1) + lab + spectrum.nucleus(2) + "";
}
}
}
// add number to tag name when name already exist example : <NMREDATA_1D_1H> <NMREDATA_1D_1H.2> <NMREDATA_1D_1H.3>
// count number of occurances of the current label in the alread existing tags.
iii=1;
for (at = 1; at < looop_over_spectra+1; at++) {// loop over spectra spectra
lab=nmredata_header[at];
if (lab !== ""){
if (lab.find(label,0) > -1){
iii++
}
}
}
if (iii>1){
label += "#" + iii ;// add number when more than one with the same name. The period is not allowed in sdf names. We replaced it with "#"
}