File size: 32,688 Bytes
b61753c
 
 
 
 
 
 
7860afc
 
b61753c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15f88a7
 
 
 
 
 
 
 
b61753c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7860afc
b61753c
 
 
 
 
 
 
 
 
 
7860afc
b61753c
 
 
 
3a8f9fb
b61753c
 
 
 
 
 
 
7860afc
b61753c
 
 
 
 
 
 
3a8f9fb
7860afc
 
 
3a8f9fb
7860afc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b61753c
 
7860afc
b61753c
7860afc
 
b61753c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3a8f9fb
b61753c
 
 
 
3a8f9fb
7860afc
b61753c
 
7860afc
 
 
 
 
 
 
 
 
 
 
 
b61753c
 
7860afc
 
 
 
 
 
 
 
 
 
 
 
 
 
3a8f9fb
7860afc
 
 
 
3a8f9fb
7860afc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b61753c
7860afc
 
3a8f9fb
7860afc
b61753c
 
3a8f9fb
7860afc
b61753c
 
7860afc
 
 
 
 
 
 
 
 
 
 
 
 
b61753c
 
3a8f9fb
 
 
7860afc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b61753c
 
 
7860afc
 
 
 
 
 
 
 
 
 
 
3a8f9fb
7860afc
 
 
 
 
3a8f9fb
7860afc
 
 
 
 
 
 
 
3a8f9fb
7860afc
 
 
 
 
 
 
 
 
 
 
 
3a8f9fb
7860afc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b61753c
 
3a8f9fb
7860afc
 
b61753c
 
3a8f9fb
7860afc
b61753c
 
7860afc
 
 
 
 
 
 
 
 
 
 
 
 
b61753c
 
3a8f9fb
 
 
7860afc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b61753c
 
 
3a8f9fb
 
 
b61753c
 
 
 
 
 
3a8f9fb
b61753c
 
3a8f9fb
 
b61753c
 
 
3a8f9fb
b61753c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3a8f9fb
b61753c
 
 
 
 
 
 
 
 
 
3a8f9fb
b61753c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3a8f9fb
b61753c
 
 
 
15f88a7
b61753c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15f88a7
 
 
 
 
 
 
 
 
 
 
b61753c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<script>
  import { createEventDispatcher } from "svelte";

  import Sequence from "./Sequence.svelte";
  import SearchInput from "./SearchInput.svelte";
  import Molecule from "./Molecule.svelte";

  // import "../style.css";

  const dispatch = createEventDispatcher();

  export let vals = [];

  export let covMods = [];

  let showCovModVals = [];
  $: {
    if (covMods) {
      // iterate over each val
      showCovModVals = vals.map((val) => {
        // check if val is in covMods and return index in CovMods or null
        return covMods.findIndex((covMod) => covMod.ligand === val.chain);
        // if index is not -1 return true else false

        // return covMods.some((covMod) => covMod.ligand === val.chain);
      });

      // dispatch("updateCovMod", covMods);
    }
  }

  let labels = {
    DNA: "NA sequence",
    RNA: "NA sequence",
    protein: "Protein sequence",
    ligand: "Small molecule",
  };

  let colorCode = {
    DNA: "bg-green-200 text-blue-800",
    RNA: "bg-green-200 text-blue-800",
    protein: "bg-blue-200 text-blue-800",
    ligand: "bg-orange-200 text-blue-800",
  };

  let metals = [
    "ZN",
    "MG",
    "CA",
    "FE",
    "NA",
    "K",
    "CL",
    "CU",
    "MN",
    "CO",
    "NI",
  ];

  let proteinChains = [];

  $: proteinChains = vals
    .filter((val) => val.class === "protein")
    .map((val) => val.chain);

  let ligandChains = [];

  $: ligandChains = vals
    .filter((val) => val.class === "ligand")
    .map((val) => val.chain);

  let residue_atoms = {
    A: ["C", "CA", "CB", "N", "O"],
    R: ["C", "CA", "CB", "CG", "CD", "CZ", "N", "NE", "O", "NH1", "NH2"],
    D: ["C", "CA", "CB", "CG", "N", "O", "OD1", "OD2"],
    N: ["C", "CA", "CB", "CG", "N", "ND2", "O", "OD1"],
    C: ["C", "CA", "CB", "N", "O", "SG"],
    E: ["C", "CA", "CB", "CG", "CD", "N", "O", "OE1", "OE2"],
    N: ["C", "CA", "CB", "CG", "CD", "N", "NE2", "O", "OE1"],
    G: ["C", "CA", "N", "O"],
    H: ["C", "CA", "CB", "CG", "CD2", "CE1", "N", "ND1", "NE2", "O"],
    I: ["C", "CA", "CB", "CG1", "CG2", "CD1", "N", "O"],
    L: ["C", "CA", "CB", "CG", "CD1", "CD2", "N", "O"],
    K: ["C", "CA", "CB", "CG", "CD", "CE", "N", "NZ", "O"],
    M: ["C", "CA", "CB", "CG", "CE", "N", "O", "SD"],
    F: ["C", "CA", "CB", "CG", "CD1", "CD2", "CE1", "CE2", "CZ", "N", "O"],
    P: ["C", "CA", "CB", "CG", "CD", "N", "O"],
    S: ["C", "CA", "CB", "N", "O", "OG"],
    T: ["C", "CA", "CB", "CG2", "N", "O", "OG1"],
    W: [
      "C",
      "CA",
      "CB",
      "CG",
      "CD1",
      "CD2",
      "CE2",
      "CE3",
      "CZ2",
      "CZ3",
      "CH2",
      "N",
      "NE1",
      "O",
    ],
    Y: [
      "C",
      "CA",
      "CB",
      "CG",
      "CD1",
      "CD2",
      "CE1",
      "CE2",
      "CZ",
      "N",
      "O",
      "OH",
    ],
    V: ["C", "CA", "CB", "CG1", "CG2", "N", "O"],
  };

  let resmap = {
    H: "HIS",
    A: "ALA",
    R: "ARG",
    N: "ASN",
    D: "ASP",
    C: "CYS",
    E: "GLU",
    Q: "GLN",
    G: "GLY",
    H: "HIS",
    I: "ILE",
    L: "LEU",
    K: "LYS",
    M: "MET",
    F: "PHE",
    P: "PRO",
    S: "SER",
    T: "THR",
    W: "TRP",
    Y: "TYR",
    V: "VAL",
  };

  function getResAtoms(covMod) {
    // get sequence of matching protein chain
    let seq = vals.find((val) => val.chain === covMod.protein).sequence;

    //do something if sequence is too short
    if (seq.length < covMod.residue) {
      alert("Residue number is too high");
      return [];
    }
    // get residue
    let residue = seq[covMod.residue - 1];
    // get atoms
    return residue_atoms[residue];
  }

  function getResidues(covMod) {
    // get sequence of matching protein chain
    let seq = vals.find((val) => val.chain === covMod.protein).sequence;

    // map single letters to three letter residues
    return Array.from(seq).map((residue) => resmap[residue]);
  }

  function getResname(covMod) {
    // get sequence of matching protein chain
    let seq = vals.find((val) => val.chain === covMod.protein).sequence;
    // get residue
    let residue = seq[covMod.residue - 1];
    // get atoms
    return resmap[residue];
  }

  function updateMol(event) {
    let index = event.detail.index;
    covMods[index].mol = event.detail.mol;
    covMods[index].attachmentIndex = event.detail.attachmentIndex;
    covMods[index].deleteIndexes = event.detail.deleteIndexes;

    dispatch("updateCovMod", covMods);
  }

  function handleMessage(event) {
    // fetch sdf content from https://files.rcsb.org/ligands/download/{name}_ideal.sdf
    // alert(event.detail.text);

    fetch(
      `https://files.rcsb.org/ligands/download/${event.detail.text}_ideal.sdf`
    )
      .then((response) => {
        if (!response.ok) {
          // Check if the status code is 200
          throw new Error("Network response was not ok");
        }
        return response.text();
      })
      .then((data) => {
        dispatch("updateVals", {
          sdf: data,
          name: event.detail.text,
          index: event.detail.index,
          close: true,
        });
      })
      .catch((error) => {
        alert("Error fetching sdf file");
      });
  }
</script>

<div data-accordion="collapse">
  {#each vals as item, i}
    <h2 id={`accordion-collapse-heading-${i}`}>
      <button
        type="button"
        class="flex items-center justify-between w-full p-5 font-medium rtl:text-right text-gray-500 border border-gray-200 gap-3"
        data-accordion-target={`#accordion-collapse-body-${i}`}
        class:rounded-t-xl={i === 0}
        class:border-b-0={i != vals.length - 1}
        aria-expanded={item.open}
        aria-controls={`accordion-collapse-body-${i}`}
        on:click={() => (item.open = !item.open)}
      >
        <div class="flex items-center justify-start">
          <span
            class="inline-flex items-center justify-center p-1 px-2 text-xs font-semibold rounded-full {colorCode[
              item.class
            ]}"
          >
            {item.chain}
          </span>
          <span class="p-1 dark:text-white">{labels[item.class]}</span>
          {#if ["DNA", "RNA", "protein"].includes(item.class)}
            {#if item.msa}
              <span
                class=" ml-4 inline-flex items-center justify-center p-1 px-2 text-xs font-semibold rounded-full border border-gray-300 dark:text-white"
              >
                <svg
                  xmlns="http://www.w3.org/2000/svg"
                  fill="none"
                  viewBox="0 0 24 24"
                  stroke-width="1.5"
                  stroke="currentColor"
                  class="size-3 mr-1"
                >
                  <path
                    stroke-linecap="round"
                    stroke-linejoin="round"
                    d="M3.75 6.75h16.5M3.75 12H12m-8.25 5.25h16.5"
                  />
                </svg>

                MSA
              </span>
            {:else}
              <span
                class="inline-flex items-center justify-center p-1 px-2 text-xs font-semibold rounded-full border border-gray-300"
              >
                <svg
                  xmlns="http://www.w3.org/2000/svg"
                  fill="none"
                  viewBox="0 0 24 24"
                  stroke-width="1.5"
                  stroke="currentColor"
                  class="size-3 mr-1"
                >
                  <path
                    stroke-linecap="round"
                    stroke-linejoin="round"
                    d="M5 12h14"
                  />
                </svg>

                single sequence
              </span>
            {/if}
          {/if}

          <span class="px-2 text-gray-800 font-bold">
            {#if !item.open && item.class === "ligand"}
              {#if item.name !== undefined}
                {item.name}
              {:else if item.sdf !== ""}
                SDF file
              {:else}
                {item.smiles}
              {/if}
            {/if}
          </span>
        </div>

        <div class="flex items-center space-x-2">
          <svg
            data-slot="icon"
            fill="none"
            stroke-width="3"
            stroke="currentColor"
            viewBox="0 0 24 24"
            xmlns="http://www.w3.org/2000/svg"
            aria-hidden="true"
            class="w-4 h-4 text-red-800"
            on:click={(e) => {
              dispatch("removeVal", i);
            }}
          >
            <path
              stroke-linecap="round"
              stroke-linejoin="round"
              d="M6 18 18 6M6 6l12 12"
            ></path>
          </svg>

          <svg
            data-accordion-icon
            class="w-3 h-3 shrink-0"
            class:rotate-180={item.open}
            class:-rotate-90={!item.open}
            aria-hidden="true"
            xmlns="http://www.w3.org/2000/svg"
            fill="none"
            viewBox="0 0 10 6"
          >
            <path
              stroke="currentColor"
              stroke-linecap="round"
              stroke-linejoin="round"
              stroke-width="2"
              d="M9 5 5 1 1 5"
            />
          </svg>
        </div>
      </button>
    </h2>

    {#if item.open}
      <div
        id={`accordion-collapse-body-${i}`}
        aria-labelledby={`accordion-collapse-heading-${i}`}
      >
        <div class="p-5 border border-t-0 border-gray-200">
          {#if ["DNA", "RNA", "protein"].includes(item.class)}
            <textarea
              id="message"
              rows="4"
              class="p-2.5 w-full text-sm text-gray-900 bg-gray-50 rounded-lg border-1 border-grey-200 focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:focus:ring-slate-900 dark:text-white dark:focus:border-slate-900"
              style="display:block"
              placeholder="MSAVGH..."
              value={item.sequence}
              on:keypress={(e) => {
                if (e.key === "Enter") {
                  if (e.target.value.length != 0) {
                    dispatch("updateVals", {
                      sequence: e.target.value,
                      close: true,
                      index: i,
                    });
                  } else {
                    alert("Sequence is empty");
                  }
                }
              }}
            ></textarea>
            <div class="flex items-center justify-between mt-1">
              <div class="flex items-center space-x-2 text-sm">
                <span>Single sequence</span>

                <label class="relative inline-flex cursor-pointer items-center">
                  <input
                    id="switch"
                    type="checkbox"
                    class="peer sr-only"
                    name={"msa" + i}
                    bind:checked={item.msa}
                  />
                  <label for="switch" class="hidden"></label>
                  <div
                    class="peer h-5 w-9 rounded-full border bg-slate-200 dark:bg-slate-600 after:absolute after:left-[2px] after:top-0.5 after:h-4 after:w-4 after:rounded-full after:border after:border-gray-300 after:bg-white after:transition-all after:content-[''] peer-checked:bg-slate-800 peer-checked:after:translate-x-full peer-checked:after:border-white peer-focus:ring-green-300"
                  ></div>
                </label>
                <span>Use MSA</span>
              </div>
              <div class="text-gray-700 dark:text-white">
                Press Enter or <button
                  on:click={() => {
                    if (item.sequence.length != 0) {
                      dispatch("updateVals", {
                        sequence: item.sequence,
                        close: true,
                        index: i,
                      });
                    } else {
                      alert("Sequence is empty");
                    }
                  }}
                  class="hover:bg-gray-100 hover:text-gray-900 underline p-1 rounded"
                  >click to add sequence.</button
                >
              </div>
            </div>
          {:else if item.class === "ligand"}
            <label
              for={"smiles" + i}
              class="block text-sm font-bold mb-1 px-2.5">SMILES</label
            >
            <textarea
              rows="1"
              class=" p-2.5 w-full text-sm text-gray-900 bg-gray-50 rounded-lg border border-gray-300 focus:ring-blue-500 focus:border-blue-500 dark:border-slate-800 dark:focus:ring-slate-900 dark:focus:border-blue-600 dark:text-white dark:bg-gray-700"
              style="display:block"
              placeholder="SMILES like CCC ..."
              value={item.smiles}
              name={"smiles" + i}
              on:keypress={(e) => {
                if (e.key === "Enter") {
                  if (e.target.value.length != 0) {
                    dispatch("updateVals", {
                      smiles: e.target.value,
                      close: true,
                      index: i,
                    });
                  } else {
                    alert("Sequence is empty");
                  }
                }
              }}
            ></textarea>
            <div
              class="text-gray-700 mt-0.5 px-2.5 text-right text-sm dark:text-white"
            >
              Press Enter or <button
                on:click={() => {
                  if (item.smiles != "") {
                    dispatch("updateVals", {
                      smiles: item.smiles,
                      close: true,
                      index: i,
                    });
                  } else {
                    alert("SMILES is empty");
                  }
                }}
                class="hover:bg-gray-100 hover:text-gray-900 underline p-1 rounded"
                >click to add SMILES.</button
              >
            </div>

            <div class="text-center text-gray-400 w-full my-2">- or -</div>

            {#if item.name === "" || item.name == undefined}
              <SearchInput
                database="rcsb-3ligand"
                index={i}
                on:triggerFetch={handleMessage}
              />
            {:else}
              <div class="max-w-lg mx-auto mb-2 my-2">
                <div class="flex">
                  <label
                    for="search-dropdown"
                    class="mb-2 text-sm font-medium text-gray-900 sr-only"
                    >Current ligand</label
                  >
                  <button
                    id="dropdown-button"
                    data-dropdown-toggle="dropdown"
                    class="flex-shrink-0 z-10 inline-flex items-center py-2.5 px-4 text-sm font-medium text-center text-gray-900 bg-gray-100 border border-gray-300 rounded-s-lg focus:ring-0 focus:outline-none dark:bg-slate-700 dark:text-white dark:border-slate-700"
                    type="button"
                    >CCD
                  </button>

                  <div class="relative w-full">
                    <input
                      type="search"
                      id="search-dropdown"
                      class=" p-2.5 w-full h-full z-20 text-sm text-gray-900 bg-gray-50 rounded-e-lg border-s-gray-50 border-s-2 border border-gray-300 focus:ring-blue-500 focus:border-blue-500 dark:focus:border-slate-900 dark:focus:ring-blue-900 dark:bg-slate-700 dark:text-white dark:border-l dark:border-slate-400 dark:border-t-0 dark:border-b-0 dark:border-r-0"
                      style="display:block"
                      value={item.name}
                    />
                    <button
                      on:click={() => {
                        dispatch("updateVals", {
                          name: "",
                          sdf: "",
                          open: true,
                          index: i,
                        });
                      }}
                      class="absolute top-0 end-0 p-2.5 text-sm font-medium h-full text-white bg-red-700 rounded-e-lg border border-red-700 hover:bg-red-800 focus:ring-4 focus:outline-none focus:ring-red-300"
                    >
                      <svg
                        xmlns="http://www.w3.org/2000/svg"
                        fill="none"
                        viewBox="0 0 24 24"
                        stroke-width="1.5"
                        stroke="currentColor"
                        class="w-4 h-4"
                      >
                        <path
                          stroke-linecap="round"
                          stroke-linejoin="round"
                          d="m14.74 9-.346 9m-4.788 0L9.26 9m9.968-3.21c.342.052.682.107 1.022.166m-1.022-.165L18.16 19.673a2.25 2.25 0 0 1-2.244 2.077H8.084a2.25 2.25 0 0 1-2.244-2.077L4.772 5.79m14.456 0a48.108 48.108 0 0 0-3.478-.397m-12 .562c.34-.059.68-.114 1.022-.165m0 0a48.11 48.11 0 0 1 3.478-.397m7.5 0v-.916c0-1.18-.91-2.164-2.09-2.201a51.964 51.964 0 0 0-3.32 0c-1.18.037-2.09 1.022-2.09 2.201v.916m7.5 0a48.667 48.667 0 0 0-7.5 0"
                        />
                      </svg>

                      <span class="sr-only">Delete</span>
                    </button>
                  </div>
                </div>
              </div>
            {/if}

            <div class="text-center text-gray-400 w-full my-2">- or -</div>
            <label for={"sdf" + i} class="block text-sm font-bold mb-1 px-2.5"
              >SDF file</label
            >
            <textarea
              rows="3"
              class="p-2.5 w-full text-sm text-gray-900 bg-gray-50 rounded-lg border border-gray-300 focus:ring-blue-500 focus:border-blue-500 dark:border-slate-800 dark:focus:ring-slate-900 dark:focus:border-blue-600 dark:text-white dark:bg-gray-700"
              style="display:block"
              placeholder="SDF format 3D molecule ..."
              value={item.sdf}
              name={"sdf" + i}
              on:keypress={(e) => {
                if (e.key === "Enter") {
                  if (e.target.value != "") {
                    dispatch("updateVals", {
                      sdf: e.target.value,
                      close: true,
                      index: i,
                    });
                  } else {
                    alert("SDF is empty");
                  }
                }
              }}
            ></textarea>
            <div
              class="text-gray-700 mt-0.5 px-2.5 text-right text-sm dark:text-white"
            >
              Press Enter or <button
                on:click={() => {
                  if (item.sdf != "") {
                    dispatch("updateVals", {
                      sdf: item.sdf,
                      close: true,
                      index: i,
                    });
                  } else {
                    alert("SDF file is empty");
                  }
                }}
                class="hover:bg-gray-100 hover:text-gray-900 underline p-1 rounded"
                >click to add SDF file.</button
              >
            </div>

            <div class="text-center text-gray-400 w-full my-2">- or -</div>

            <div
              class="text-center text-gray-600 font-bold mb-2 dark:text-white"
            >
              Metal ion
            </div>

            <div class="flex justify-center space-x-2">
              {#each metals as metal}
                <button
                  class="relative inline-flex items-center justify-center w-10 h-10 overflow-hidden rounded-full dark:text-white"
                  class:bg-blue-200={item.name === metal}
                  class:bg-violet-100={item.name !== metal}
                  class:dark:bg-slate-900={item.name === metal}
                  class:dark:bg-slate-700={item.name !== metal}
                  on:click={() =>
                    dispatch("updateVals", { name: metal, index: i })}
                >
                  <span class="font-medium text-gray-600 dark:text-white"
                    >{metal}</span
                  >
                </button>
              {/each}
            </div>
          {/if}

          <!-- <div class="text-center text-gray-400 w-full my-2">- or -</div>

          <label
            class="block mb-2 text-sm font-medium text-gray-900 dark:text-white hidden"
            for="file_input">Upload file</label
          >
          <input
            class="block w-full text-sm text-gray-900 border border-gray-300 rounded-lg cursor-pointer bg-gray-50 dark:text-gray-400 focus:outline-none dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400"
            aria-describedby="file_input_help"
            id="file_input"
            type="file"
          />
          <p
            class="mt-1 text-sm text-gray-500 dark:text-gray-300"
            id="file_input_help"
          >
            .fasta files
          </p> -->
        </div>
      </div>
    {/if}
    {#if !item.open}
      {#if ["DNA", "RNA", "protein"].includes(item.class)}
        <div
          id={`accordion-collapse-body-${i}`}
          aria-labelledby={`accordion-collapse-heading-${i}`}
        >
          <div
            class="p-5 border border-t-0 border-gray-200"
            class:border-b-0={i != vals.length - 1}
          >
            {#if item.sequence !== ""}
              <Sequence seq={item.sequence} />
            {/if}
          </div>
        </div>
      {:else if item.class === "ligand"}
        {#if item.sdf !== ""}
          <div
            class="p-5 border border-t-0 border-gray-200"
            class:border-b-0={i != vals.length - 1}
          >
            <div class="relative">
              <Molecule
                molvalue={item.sdf}
                showCovMod={showCovModVals[i]}
                on:updateMol={updateMol}
              />
            </div>
          </div>
          <!-- {:else if metals.includes(item.name)}
          {item.name}
        {:else}
          {item.smiles} -->
        {/if}
      {/if}
    {/if}
  {/each}

  <div class="p-5 border border-t-0 border-gray-200 w-full">
    {#if covMods.length > 0}
      <h4 class="text-center font-bold text-xl">Covalent Modification</h4>
      {#each covMods as covMod, i}
        <div class="flex p-10">
          <div class="flex divide-x rounded border p-1 w-full">
            <div class="w-3/5 flex-col px-2">
              <div class="flex justify-center">
                <span class="text-base font-medium text-gray-900">Protein</span>
              </div>
              <div class="grid grid-cols-4 font-bold">
                <span>Chain</span>
                <span>Residue</span>
                <span>Atom</span>
                <span>Chirality</span>
              </div>
              <div class="grid grid-cols-4">
                <select
                  name=""
                  id=""
                  bind:value={covMods[i].protein}
                  on:change={() => dispatch("updateCovMod", covMods)}
                >
                  {#each proteinChains as chain}
                    <option value={chain}>{chain}</option>
                  {/each}
                </select>

                <select
                  name=""
                  id=""
                  bind:value={covMods[i].residue}
                  on:change={() => dispatch("updateCovMod", covMods)}
                >
                  {#each getResidues(covMod) as resi, i}
                    <option value={i + 1}>{i + 1} {resi}</option>
                  {/each}
                </select>

                <select
                  name=""
                  id=""
                  bind:value={covMods[i].atom}
                  on:change={() => dispatch("updateCovMod", covMods)}
                >
                  {#if covMod.residue != ""}
                    {#each getResAtoms(covMod) as atom}}
                      <option value={atom}>{getResname(covMod)}:{atom}</option>
                    {/each}
                  {:else}
                    <option disabled></option>
                  {/if}
                </select>

                <select
                  name=""
                  id=""
                  bind:value={covMods[i].protein_symmetry}
                  on:change={() => dispatch("updateCovMod", covMods)}
                >
                  <option value="">no chirality defined</option>
                  <option value="CW">CW</option>
                  <option value="CCW">CCW</option>
                </select>
              </div>
            </div>

            <div class="w-2/5 px-2">
              <div class="flex-col p-1">
                <div class="flex justify-center">
                  <span
                    class="w-full whitespace-nowrap text-center text-base font-medium text-gray-900"
                    >Small molecule</span
                  >
                </div>
                <div class="grid grid-cols-3 font-bold">
                  <span>Chain</span>
                  <span title="click on atom in structure">Atom index </span>

                  <span>Chirality</span>
                </div>
                <div class="grid grid-cols-3">
                  <select
                    name=""
                    id=""
                    title="click on atom in structure"
                    bind:value={covMods[i].ligand}
                    on:change={() => dispatch("updateCovMod", covMods)}
                  >
                    {#each ligandChains as chain}
                      <option value={chain} selected={chain === covMod.ligand}
                        >{chain}</option
                      >
                    {/each}
                  </select>
                  <div>
                    {#if covMod.attachmentIndex}
                      <p class="font-mono">index {covMod.attachmentIndex}</p>
                    {:else}
                      <p class="font-mono">click on atom</p>
                    {/if}
                  </div>

                  <select
                    name=""
                    id=""
                    bind:value={covMods[i].ligand_symmetry}
                    on:change={() => dispatch("updateCovMod", covMods)}
                  >
                    <option value="">no chirality defined</option>
                    <option value="CW">CW</option>
                    <option value="CCW">CCW</option>
                  </select>
                </div>
              </div>
            </div>
          </div>

          <div class="flex items-center p-2">
            <svg
              data-slot="icon"
              fill="none"
              stroke-width="2"
              stroke="currentColor"
              viewBox="0 0 24 24"
              xmlns="http://www.w3.org/2000/svg"
              aria-hidden="true"
              class="w-8 h-8 text-red-800 cursor-pointer"
              on:click={(e) => {
                dispatch("removeCovMod", i);
              }}
            >
              <path
                stroke-linecap="round"
                stroke-linejoin="round"
                d="M6 18 18 6M6 6l12 12"
              ></path>
            </svg>
          </div>
        </div>
      {/each}
    {/if}
  </div>
  <!-- 
  <h2 id="accordion-collapse-heading-2">
    <button
      type="button"
      class="flex items-center justify-between w-full p-5 font-medium rtl:text-right text-gray-500 border border-b-0 border-gray-200 focus:ring-4 focus:ring-gray-200 dark:focus:ring-gray-800 dark:border-gray-700 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-800 gap-3"
      data-accordion-target="#accordion-collapse-body-2"
      aria-expanded="false"
      aria-controls="accordion-collapse-body-2"
    >
      <div>
        <span
          class="inline-flex items-center justify-center p-1 px-2 text-xs font-semibold text-blue-800 bg-blue-200 rounded-full"
        >
          A
        </span>
        <span>NA sequence</span>
      </div>
      <svg
        data-accordion-icon
        class="w-3 h-3 -rotate-90 shrink-0"
        aria-hidden="true"
        xmlns="http://www.w3.org/2000/svg"
        fill="none"
        viewBox="0 0 10 6"
      >
        <path
          stroke="currentColor"
          stroke-linecap="round"
          stroke-linejoin="round"
          stroke-width="2"
          d="M9 5 5 1 1 5"
        />
      </svg>
    </button>
    <div class="px-2">
      <Sequence />
    </div>
  </h2>

  <div
    id="accordion-collapse-body-2"
    class="hidden"
    aria-labelledby="accordion-collapse-heading-2"
  >
    <div
      class="p-5 border border-b-0 border-gray-200 dark:border-gray-700"
    ></div>
  </div>
  <h2 id="accordion-collapse-heading-3">
    <button
      type="button"
      class="flex items-center justify-between w-full p-5 font-medium rtl:text-right text-gray-500 border border-gray-200 focus:ring-4 focus:ring-gray-200 dark:focus:ring-gray-800 dark:border-gray-700 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-800 gap-3"
      data-accordion-target="#accordion-collapse-body-3"
      aria-expanded="false"
      aria-controls="accordion-collapse-body-3"
    >
      <div>
        <span
          class="inline-flex items-center justify-center p-1 px-2 text-xs font-semibold text-blue-800 bg-orange-200 rounded-full"
        >
          C
        </span>
        <span>Small molecule</span>
      </div>
      <svg
        data-accordion-icon
        class="w-3 h-3 rotate-180 shrink-0"
        aria-hidden="true"
        xmlns="http://www.w3.org/2000/svg"
        fill="none"
        viewBox="0 0 10 6"
      >
        <path
          stroke="currentColor"
          stroke-linecap="round"
          stroke-linejoin="round"
          stroke-width="2"
          d="M9 5 5 1 1 5"
        />
      </svg>
    </button>
  </h2>
  <div
    id="accordion-collapse-body-3"
    aria-labelledby="accordion-collapse-heading-3"
  >
    <div class="p-5 border border-t-0 border-gray-200 dark:border-gray-700">
      <label
        class="block mb-2 text-sm font-medium text-gray-900 dark:text-white"
        for="file_input">Upload file</label
      >
      <input
        class="block w-full text-sm text-gray-900 border border-gray-300 rounded-lg cursor-pointer bg-gray-50 dark:text-gray-400 focus:outline-none dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400"
        aria-describedby="file_input_help"
        id="file_input"
        type="file"
      />
      <p
        class="mt-1 text-sm text-gray-500 dark:text-gray-300"
        id="file_input_help"
      >
        SVG, PNG, JPG or GIF (MAX. 800x400px).
      </p>
      <div class="text-center text-gray-400 w-full my-2">- or -</div>

      <textarea
        id="message"
        rows="4"
        class="block p-2.5 w-full text-sm text-gray-900 bg-gray-50 rounded-lg border border-gray-300 focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"
        placeholder="SMILES like CCC ..."
      ></textarea>

      <div class="text-center text-gray-400 w-full my-2">- or -</div>

      <SearchInput database="rcsb-3ligand" />

      <div class="text-center text-gray-400 w-full my-2">- or -</div>

      <div class="text-center text-gray-600 font-bold mb-2">Metal ion</div>
      <div class="flex justify-center space-x-2">
        <div
          class="relative inline-flex items-center justify-center w-10 h-10 overflow-hidden bg-violet-100 rounded-full dark:bg-gray-600"
        >
          <span class="font-medium text-gray-600 dark:text-gray-300">ZN</span>
        </div>

        <div
          class="relative inline-flex items-center justify-center w-10 h-10 overflow-hidden bg-green-100 rounded-full dark:bg-gray-600"
        >
          <span class="font-medium text-gray-600 dark:text-gray-300">MG</span>
        </div>

        <div
          class="relative inline-flex items-center justify-center w-10 h-10 overflow-hidden bg-green-100 rounded-full dark:bg-gray-600"
        >
          <span class="font-medium text-gray-600 dark:text-gray-300">CA</span>
        </div>

        <div
          class="relative inline-flex items-center justify-center w-10 h-10 overflow-hidden bg-violet-100 rounded-full dark:bg-gray-600"
        >
          <span class="font-medium text-gray-600 dark:text-gray-300">FE</span>
        </div>

        <div
          class="relative inline-flex items-center justify-center w-10 h-10 overflow-hidden bg-yellow-100 rounded-full dark:bg-gray-600"
        >
          <span class="font-medium text-gray-600 dark:text-gray-300">NA</span>
        </div>
      </div>
    </div>
  </div> 

   -->
</div>