diff --git a/app/Livewire/CollectionList.php b/app/Livewire/CollectionList.php new file mode 100644 index 00000000..45ddf4ec --- /dev/null +++ b/app/Livewire/CollectionList.php @@ -0,0 +1,47 @@ +resetPage(); + } + + public function render() + { + $search = $this->query; + $collections = Collection::query() + ->where(function ($query) use ($search) { + $query->whereRaw('LOWER(title) LIKE ?', ['%'.strtolower($search).'%']) + ->orWhereRaw('LOWER(description) LIKE ?', ['%'.strtolower($search).'%']); + }) + ->orderByRaw('title LIKE ? DESC', [$search.'%']) + ->orderByRaw('description LIKE ? DESC', [$search.'%']) + ->paginate($this->size); + + return view('livewire.collection-list', ['collections' => $collections]); + } +} diff --git a/app/Livewire/CompoundClasses.php b/app/Livewire/CompoundClasses.php index eb342e94..77c8a009 100644 --- a/app/Livewire/CompoundClasses.php +++ b/app/Livewire/CompoundClasses.php @@ -6,6 +6,32 @@ class CompoundClasses extends Component { + public $superClasses = [ + 'Acetylides', + 'Alkaloids and derivatives', + 'Allenes', + 'Benzenoids', + 'Hydrocarbon derivatives', + 'Hydrocarbons', + 'Lignans, neolignans and related compounds', + 'Lipids and lipid-like molecules', + 'Nucleosides, nucleotides, and analogues', + 'Organoheterocyclic compounds', + 'Organohalogen compounds', + 'Organometallic compounds', + 'Organophosphorus compounds', + 'Organosulfur compounds', + 'Organic 1,3-dipolar compounds', + 'Organic Polymers', + 'Organic acids and derivatives', + 'Organic anions', + 'Organic cations', + 'Organic nitrogen compounds', + 'Organic oxygen compounds', + 'Organic salts', + 'Phenylpropanoids and polyketides', + ]; + public $parentClasses = [ 'Acenaphthylenes', 'Acetals', @@ -985,7 +1011,8 @@ class CompoundClasses extends Component public function mount() { - $this->parentClasses = array_slice($this->parentClasses, 0, 50); + // $this->parentClasses = array_slice($this->parentClasses, 0, 50); + $this->superClasses = $this->superClasses; } public function render() diff --git a/app/Livewire/MoleculeDetails.php b/app/Livewire/MoleculeDetails.php index a201eff4..59f754e9 100644 --- a/app/Livewire/MoleculeDetails.php +++ b/app/Livewire/MoleculeDetails.php @@ -4,7 +4,6 @@ use App\Models\Molecule; use Cache; -use Livewire\Attributes\Layout; use Livewire\Component; class MoleculeDetails extends Component @@ -18,11 +17,20 @@ public function mount($id) }); } - #[Layout('layouts.guest')] public function render() { return view('livewire.molecule-details', [ 'molecule' => $this->molecule, - ]); + ])->layout('layouts.guest') + ->layoutData([ + 'title' => $this->molecule->name ? $this->molecule->name : $this->molecule->iupac_name, + 'description' => $this->molecule->description ?? 'Molecule details for '.($this->molecule->name ? $this->molecule->name : $this->molecule->iupac_name), + 'keywords' => 'natural products, '.$this->molecule->name.', '.$this->molecule->iupac_name.', '.implode(',', $this->molecule->synonyms ?? []), + 'author' => $this->molecule->author ?? 'COCONUT Team', + 'ogTitle' => $this->molecule->name ? $this->molecule->name : $this->molecule->iupac_name, + 'ogDescription' => $this->molecule->description ?? 'Molecule details for '.($this->molecule->name ? $this->molecule->name : $this->molecule->iupac_name), + 'ogImage' => env('CM_API').'depict/2D?smiles='.urlencode($this->molecule->canonical_smiles).'&height=200&width=200&toolkit=cdk' ?? asset('img/coconut-og-image.png'), + 'ogSiteName' => 'Coconut 2.0', + ]); } } diff --git a/app/Livewire/MoleculeEditor.php b/app/Livewire/MoleculeEditor.php deleted file mode 100644 index 4483f16c..00000000 --- a/app/Livewire/MoleculeEditor.php +++ /dev/null @@ -1,15 +0,0 @@ -page = $page; } - #[Layout('layouts.guest')] + protected $listeners = ['updateSmiles' => 'setSmiles']; + + public function setSmiles($smiles, $searchType) + { + $this->query = $smiles; + $this->type = $searchType; + } + public function render() { @@ -173,7 +183,31 @@ public function render() } elseif ($queryType == 'tags') { if ($this->tagType == 'dataSource') { $this->collection = Collection::where('title', $this->query)->first(); - $results = $this->collection->molecules()->orderBy('annotation_level', 'desc')->paginate($this->size); + if ($this->collection) { + $results = $this->collection->molecules()->orderBy('annotation_level', 'desc')->paginate($this->size); + } else { + $results = new LengthAwarePaginator( + [], + 0, + $this->size, + $this->page + ); + } + } elseif ($this->tagType == 'organisms') { + $this->organisms = array_map(function ($name) { + return strtolower(trim($name)); + }, explode(',', $this->query)); + + $organismIds = Organism::where(function ($query) { + foreach ($this->organisms as $name) { + $query->orWhereRaw('LOWER(name) = ?', [$name]); + } + })->pluck('id'); + + $results = Molecule::whereHas('organisms', function ($query) use ($organismIds) { + $query->whereIn('organism_id', $organismIds); + })->orderBy('annotation_level', 'DESC')->paginate($this->size); + } else { $results = Molecule::withAnyTags([$this->query], $this->tagType)->paginate($this->size); } @@ -235,11 +269,12 @@ public function render() } $statement = $statement. - '('.$filterMap[$_filter[0]].'::TEXT ILIKE \'%'.$_filter[1].'%\')'; + '(LOWER(REGEXP_REPLACE('.$filterMap[$_filter[0]].' , \'\s+\', \'-\', \'g\'))::TEXT ILIKE \'%'.$_filter[1].'%\')'; } } $statement = $statement.')'; } + // dd($statement); $statement = $statement.' LIMIT '.$this->size; } else { if ($this->query) { @@ -335,10 +370,5 @@ public function render() 500 ); } - // return view('livewire.search', [ - // 'molecules' => MoleculeResource::collection( - // Molecule::where('active', true)->orderByDesc('updated_at')->paginate($this->size) - // ), - // ]); } } diff --git a/app/Livewire/StructureEditor.php b/app/Livewire/StructureEditor.php new file mode 100644 index 00000000..928bb71f --- /dev/null +++ b/app/Livewire/StructureEditor.php @@ -0,0 +1,30 @@ +smiles = $smiles; + $this->isOpen = true; + } + + public function closeModal() + { + $this->isOpen = false; + } + + public function render() + { + return view('livewire.structure-editor'); + } +} diff --git a/package-lock.json b/package-lock.json index 3622b4e9..e53a6ec2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,11 +1,11 @@ { - "name": "html", + "name": "coconut", "lockfileVersion": 3, "requires": true, "packages": { "": { "dependencies": { - "openchemlib": "^8.9.0" + "openchemlib": "^8.13.0" }, "devDependencies": { "@tailwindcss/forms": "^0.5.7", @@ -2336,9 +2336,9 @@ } }, "node_modules/openchemlib": { - "version": "8.9.0", - "resolved": "https://registry.npmjs.org/openchemlib/-/openchemlib-8.9.0.tgz", - "integrity": "sha512-8Bb7batm6XvNHg9SWBJDYrkJj5bsq72D5dClpN5yO6BnxxNxtRP1+e6egHwoMwGhd4dyb+eBX7Kr/hdUqMN1Dw==" + "version": "8.13.0", + "resolved": "https://registry.npmjs.org/openchemlib/-/openchemlib-8.13.0.tgz", + "integrity": "sha512-CdE9mNFdiQaZbjThvpplKC2YObyg9w4cKbuZ8nn/dRuTvk35H7+LPl2xylm84OGW3062AanU61ms4HnNZOzoXA==" }, "node_modules/path-key": { "version": "3.1.1", diff --git a/package.json b/package.json index 01a873ec..7ad773be 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,6 @@ "vitepress": "^1.2.2" }, "dependencies": { - "openchemlib": "^8.9.0" + "openchemlib": "^8.13.0" } } diff --git a/public/img/coconut-og-image.png b/public/img/coconut-og-image.png new file mode 100644 index 00000000..4b4761db Binary files /dev/null and b/public/img/coconut-og-image.png differ diff --git a/resources/css/app.css b/resources/css/app.css index bde27f8c..fdbb0ecb 100644 --- a/resources/css/app.css +++ b/resources/css/app.css @@ -293,4 +293,12 @@ .tooltip:hover .tooltiptext { visibility: visible; opacity: 1; +} + +.organism::first-letter { + text-transform: capitalize !important; +} + +.organism { + font-style: italic; } \ No newline at end of file diff --git a/resources/js/app.js b/resources/js/app.js index 9062e98f..51383765 100644 --- a/resources/js/app.js +++ b/resources/js/app.js @@ -1,4 +1,4 @@ import "./bootstrap"; import OCL from "openchemlib/full"; -window.OCL = OCL; \ No newline at end of file +window.OCL = OCL; diff --git a/resources/views/layouts/guest.blade.php b/resources/views/layouts/guest.blade.php index b05fcc62..adff83a6 100644 --- a/resources/views/layouts/guest.blade.php +++ b/resources/views/layouts/guest.blade.php @@ -7,6 +7,19 @@
Explore our database of natural products to uncover their + unique properties. Search, filter, and discover the diverse realm of chemistry. +
+{{ $molecule->identifier }}
Created on · Last @@ -15,105 +15,123 @@ class="mb-2 text-2xl break-all font-bold leading-7 break-words text-gray-900 sm:
#COLLECTION
+#COLLECTION
{{ $collection->description }}
- @if($collection->license) -License: {{ $collection->license->title }}
+{{ $collection->description }}
+ @if ($collection->license) +License: {{ $collection->license->title }}
@endif#ORGANISMS
+ @foreach ($organisms as $index => $organism) + {{ ucfirst($organism) }} + @if (!$loop->last) + , + @endif + @endforeach +Explore our database of natural products to uncover their unique properties. Search, filter, and discover the diverse realm of chemistry. +
Explore our database of natural products to uncover their + unique properties. Search, filter, and discover the diverse realm of chemistry.