From 831cade17392da583e4a61a2cd07124074166b06 Mon Sep 17 00:00:00 2001 From: Venkata Chandra Sekhar Nainala Date: Fri, 7 Feb 2025 16:53:09 +0530 Subject: [PATCH] fix: missing root tag bug fix --- resources/scripts/python/3d/extract_3d.py | 51 +++ .../molecule-history-timeline.blade.php | 402 +++++++++--------- 2 files changed, 263 insertions(+), 190 deletions(-) create mode 100644 resources/scripts/python/3d/extract_3d.py diff --git a/resources/scripts/python/3d/extract_3d.py b/resources/scripts/python/3d/extract_3d.py new file mode 100644 index 0000000..a3b8979 --- /dev/null +++ b/resources/scripts/python/3d/extract_3d.py @@ -0,0 +1,51 @@ +import os +import json +import pandas as pd +from rdkit import Chem +from rdkit.Chem import SDWriter +from tqdm import tqdm # For progress bar + +# === CONFIGURATION === +csv_file = "/Users/chandu-jena/Development/nfdi4chem/coconut/resources/scripts/python/3d/coconut_30_01_2025.csv" +input_folder = "/Users/chandu-jena/Development/nfdi4chem/coconut/resources/scripts/python/3d/molecules_3d" +output_sdf = "coconut_30_01_2025_3D.sdf" + +# === STEP 1: READ CSV & GET IDENTIFIERS === +df = pd.read_csv(csv_file, usecols=["identifier"]) # Load only necessary column +identifiers = set(df["identifier"].astype(str)) # Convert to string & store as a set for fast lookup +print(f"✅ Loaded {len(identifiers)} unique identifiers from CSV") + +# === STEP 2: PROCESS JSON FILES === +json_files = [os.path.join(input_folder, f) for f in os.listdir(input_folder) if f.endswith(".json")] +writer = SDWriter(output_sdf) + +matched_count = 0 +failed_count = 0 + +for json_path in tqdm(json_files, desc="Processing JSON Files", unit="file"): + try: + with open(json_path, "r", encoding="utf-8") as file: + data = json.load(file) + except (json.JSONDecodeError, FileNotFoundError) as e: + print(f"⚠️ Skipping {json_path}: {e}") + continue + + # Filter JSON keys to only those present in CSV + matched_keys = identifiers.intersection(data.keys()) + + for key in matched_keys: + mol_block = data[key] + mol = Chem.MolFromMolBlock(mol_block, sanitize=False, removeHs=False) + + if mol: + mol.SetProp("coconut_id", key) # Store key as a property + writer.write(mol) + matched_count += 1 + else: + failed_count += 1 + +# === STEP 3: CLOSE WRITER & SUMMARY === +writer.close() +print(f"\n✅ Exported {matched_count} molecules to {output_sdf}") +if failed_count: + print(f"⚠️ {failed_count} molecules failed to parse.") diff --git a/resources/views/livewire/molecule-history-timeline.blade.php b/resources/views/livewire/molecule-history-timeline.blade.php index 9e4efae..df468c5 100644 --- a/resources/views/livewire/molecule-history-timeline.blade.php +++ b/resources/views/livewire/molecule-history-timeline.blade.php @@ -1,201 +1,223 @@ -
- - -
-
- -
    - @foreach ($audit_data as $audit) - @if (array_key_exists('affected_columns', $audit)) -
  • -
    -
    -
    -
    -
    -
    -
    -

    - {{ $audit['user_name'] ?? 'COCONUT Curator' }} - - {{ $audit['event'] ?? '' }}  - {{ \Carbon\Carbon::parse($audit['created_at'])->diffForHumans() }} - -

    - - @foreach ($audit['affected_columns'] as $column_name => $column_values) -
    -
    -
    - {{ Str::of($column_name)->camel()->replace('_', ' ')->replaceMatches('/[A-Z]/', ' $0')->title() }} +
    +
    + + +
    +
    + +
      + @foreach ($audit_data as $audit) + @if (array_key_exists('affected_columns', $audit)) +
    • +
      +
      - {{--
      - - - - - @switch(explode('.',$column_name)[0]) - @case('comment') - {{$column_values['new_value'][0]['comment'] ?? 'N/A'}} - @break - @case('active') - @if ($column_values['new_value']) - Activated - @else - Deactivated - @endif - @break - @case('created') - Initial creation of the compound on COCONUT - @break - @case('organisms') - @case('sampleLocations') - @if ($column_values['old_value']) - Detached from:
      {{$column_values['old_value']?:'N/A'}}
      - @endif - @if ($column_values['new_value']) - Attached to:
      {{$column_values['new_value']?:'N/A'}}
      - @endif - @break - @case('synonyms') - @if (array_diff($column_values['old_value'], $column_values['new_value'])) - Removed:
      {{implode(', ',array_diff($column_values['old_value'], $column_values['new_value']))}}
      - @endif - @if (array_diff($column_values['new_value'], $column_values['old_value'])) - Added:
      {{implode(', ',array_diff($column_values['new_value'], $column_values['old_value']))}}
      - @endif - @break - @case('cas') - @if (array_diff($column_values['old_value'], $column_values['new_value'])) - Removed:
      {{implode(', ',array_diff($column_values['old_value'], $column_values['new_value']))}}
      - @endif - @if (array_diff($column_values['new_value'], $column_values['old_value'])) - Added:
      {{implode(', ',array_diff($column_values['new_value'], $column_values['old_value']))}}
      - @endif - @break - @case('citations') - @if ($column_values['old_value']) - Detached from:
      {{$column_values['old_value']?:'N/A'}}
      - @endif - @if ($column_values['new_value']) - Attached to:
      {{$column_values['new_value']?:'N/A'}}
      - @endif - @break - @default - Old Value:
      {{$column_values['old_value']??'N/A'}}
      - New Value:
      {{$column_values['new_value']??'N/A'}} - @endswitch -
      -
      --}} -
    -
    +
    +
    +
    +
    +

    + {{ $audit['user_name'] ?? 'COCONUT Curator' }} + + {{ $audit['event'] ?? '' }}  + {{ \Carbon\Carbon::parse($audit['created_at'])->diffForHumans() }} + +

    + + @foreach ($audit['affected_columns'] as $column_name => $column_values) +
    +
    +
    + {{ Str::of($column_name)->camel()->replace('_', ' ')->replaceMatches('/[A-Z]/', ' $0')->title() }} +
    + {{--
    + + + + + @switch(explode('.',$column_name)[0]) + @case('comment') + {{$column_values['new_value'][0]['comment'] ?? 'N/A'}} + @break + @case('active') + @if ($column_values['new_value']) + Activated + @else + Deactivated + @endif + @break + @case('created') + Initial creation of the compound on COCONUT + @break + @case('organisms') + @case('sampleLocations') + @if ($column_values['old_value']) + Detached from:
    {{$column_values['old_value']?:'N/A'}}
    + @endif + @if ($column_values['new_value']) + Attached to:
    {{$column_values['new_value']?:'N/A'}}
    + @endif + @break + @case('synonyms') + @if (array_diff($column_values['old_value'], $column_values['new_value'])) + Removed:
    {{implode(', ',array_diff($column_values['old_value'], $column_values['new_value']))}}
    + @endif + @if (array_diff($column_values['new_value'], $column_values['old_value'])) + Added:
    {{implode(', ',array_diff($column_values['new_value'], $column_values['old_value']))}}
    + @endif + @break + @case('cas') + @if (array_diff($column_values['old_value'], $column_values['new_value'])) + Removed:
    {{implode(', ',array_diff($column_values['old_value'], $column_values['new_value']))}}
    + @endif + @if (array_diff($column_values['new_value'], $column_values['old_value'])) + Added:
    {{implode(', ',array_diff($column_values['new_value'], $column_values['old_value']))}}
    + @endif + @break + @case('citations') + @if ($column_values['old_value']) + Detached from:
    {{$column_values['old_value']?:'N/A'}}
    + @endif + @if ($column_values['new_value']) + Attached to:
    {{$column_values['new_value']?:'N/A'}}
    + @endif + @break + @default + Old Value:
    {{$column_values['old_value']??'N/A'}}
    + New Value:
    {{$column_values['new_value']??'N/A'}} + @endswitch +
    +
    --}} +
    +
    + @endforeach +
    +
  • + @endif @endforeach +
+
- - @endif - @endforeach - -
- -
- -
- -
-
-

- -
-
-