10
0
mirror of https://github.com/LCPQ/QUESTDB_website.git synced 2024-12-25 05:43:46 +01:00

Allow to export geometries (#6)

* Fix broken link

* Fix bug in indexDB

* Fix sourceFile  for each geometry

* Add function to export geometry as xyz

* Fix bug when printing z

* Fix align with website structures

* Add Export geometries fonctionality

* Better class name for select buttons

* Fix after =

* Enable export button only when it makes sense

Co-authored-by: Mickaël Véril <mveril@irsamc.ups-tlse.fr>
This commit is contained in:
mveril 2020-12-07 11:15:26 +01:00 committed by GitHub
parent f37f7b47d9
commit 4baaaa0fc2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 61 additions and 8 deletions

View File

@ -204,6 +204,7 @@ draft: false
processingIndicator.isActive = false processingIndicator.isActive = false
reloadSizeSelector() reloadSizeSelector()
reloadSelect("sets") reloadSelect("sets")
refreshExportGeoms()
} }
async function clearSelect(BeforeName = null) { async function clearSelect(BeforeName = null) {
var selects = ((BeforeName == null) ? getAllSelect() : getAllSelectAfter(BeforeName, true)) var selects = ((BeforeName == null) ? getAllSelect() : getAllSelectAfter(BeforeName, true))
@ -691,6 +692,41 @@ draft: false
} }
await reloadContent(); await reloadContent();
} }
function refreshExportGeoms() {
const vals=$("#mol_select").val()
const disable = vals === null || vals.length===0
$("#btn_export_geoms").prop("disabled",disable)
}
async function moleculeSelectionChanged(event) {
refreshExportGeoms()
await reloadNextSelect(event)
}
async function exportGeoms() {
var mols = new Set($("#mol_select").val())
if (mols.size!==0) {
const zip = JSZip();
const geomDic=new Map()
for (const geom of window.geoms) {
const molecule =geom.parseMetadata().molecule
if (mols.has(molecule)) {
if (!geomDic.has(molecule)) {
geomDic.set(molecule,[])
}
geomDic.get(molecule).push(geom.toXYZ())
}
}
for (const [molecule,geometries] of geomDic) {
const xyz=geometries.join("\n\n")
var blob=new Blob([xyz],{type: 'chemical/x-xyz'})
zip.file(`${mhchemCE.extract(molecule).toLowerCase().replace(" ","_")}.xyz`,blob)
}
const zipFile = await zip.generateAsync({type: 'blob'})
saveAs(zipFile, "molecules.zip")
}
}
</script> </script>
{{< getDataFilesName >}} {{< getDataFilesName >}}
<noscript> <noscript>
@ -732,23 +768,24 @@ draft: false
</p> </p>
<div style="display: inline-block;"> <div style="display: inline-block;">
<label for="DOI_select" class="required">Set</label> <label for="DOI_select" class="required">Set</label>
<button class="SelectAll" type="button" onclick="selectSelectAll_click(event)">Select all</button> <button class="selectButton" type="button" onclick="selectSelectAll_click(event)">Select all</button>
<select multiple id="DOI_select" required name="sets" onchange="reloadNextSelect(event)"></select> <select multiple id="DOI_select" required name="sets" onchange="reloadNextSelect(event)"></select>
</div> </div>
<div style="display:inline-block"> <div style="display:inline-block">
<label for="mol_select" class="required">Molecule</label> <label for="mol_select" class="required">Molecule</label>
<button class="SelectAll" type="button" onclick="selectSelectAll_click(event)">Select all</button> <button class="selectButton" type="button" onclick="selectSelectAll_click(event)">Select all</button>
<select multiple id="mol_select" required name="molecule" onchange="reloadNextSelect(event)"></select> <select multiple id="mol_select" required name="molecule" onchange="moleculeSelectionChanged(event)"></select>
<button id="btn_export_geoms" class="selectButton" type="button" disabled onclick="exportGeoms()">Export geometries</button>
</div> </div>
<br /> <br />
<div style="display: inline-block;"> <div style="display: inline-block;">
<label for="method_select" class="required">Method</label> <label for="method_select" class="required">Method</label>
<button class="SelectAll" type="button" onclick="selectSelectAll_click(event)">Select all</button> <button class="selectButton" type="button" onclick="selectSelectAll_click(event)">Select all</button>
<select multiple id="method_select" required name="method" onchange="reloadNextSelect(event)"></select> <select multiple id="method_select" required name="method" onchange="reloadNextSelect(event)"></select>
</div> </div>
<div style="display: inline-block;"> <div style="display: inline-block;">
<label for="basis_select" class="required">Basis set</label> <label for="basis_select" class="required">Basis set</label>
<button class="SelectAll" type="button" onclick="selectSelectAll_click(event)">Select all</button> <button class="selectButton" type="button" onclick="selectSelectAll_click(event)">Select all</button>
<select multiple id="basis_select" required name="basis" onchange="reloadNextSelect(event)"></select> <select multiple id="basis_select" required name="basis" onchange="reloadNextSelect(event)"></select>
</div> </div>
</fieldset> </fieldset>

View File

@ -5,7 +5,6 @@ draft: false
--- ---
<script src="/js/getFullDataPath.js" type="text/javascript"></script> <script src="/js/getFullDataPath.js" type="text/javascript"></script>
<script src="/js/getTextFromFile.js" type="text/javascript"></script> <script src="/js/getTextFromFile.js" type="text/javascript"></script>
<script src="https://cdn.jsdelivr.net/npm/file-saver@2.0.2/dist/FileSaver.min.js"></script>
<script src="/js/Base64ToBlob.js" type="text/javascript"></script> <script src="/js/Base64ToBlob.js" type="text/javascript"></script>
<script> <script>

View File

@ -21,4 +21,6 @@ MathJax.Hub.Config({
<script src="/js/pubUtils.js"></script> <script src="/js/pubUtils.js"></script>
<script src="https://unpkg.com/simple-statistics@7.0.2/dist/simple-statistics.min.js"></script> <script src="https://unpkg.com/simple-statistics@7.0.2/dist/simple-statistics.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bowser@2.5.3/es5.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/bowser@2.5.3/es5.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-yaml/3.13.1/js-yaml.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/js-yaml/3.13.1/js-yaml.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jszip@3.5.0/dist/jszip.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/file-saver@2.0.2/dist/FileSaver.min.js"></script>

View File

@ -8,7 +8,7 @@ ul.nestedCbList {
list-style-type: none; list-style-type: none;
padding-left: 1em; padding-left: 1em;
} }
form button.SelectAll { form button.selectButton {
display: block; display: block;
} }
form fieldset.main { form fieldset.main {

View File

@ -3,6 +3,21 @@ class Geometry {
this.molecule = molecule this.molecule = molecule
this.comment = comment this.comment = comment
} }
toXYZ() {
var lines =[]
lines.push(this.molecule.atoms.length)
lines.push(this.comment)
for (const a of this.molecule.atoms) {
var line = a.label.padEnd(4, ' ')
line += a.x.toFixed(8).padStart(11,' ')
line += a.y.toFixed(8).padStart(22,` `)
line += a.z.toFixed(8).padStart(22,` `)
lines.push(line)
}
return lines.join("\n")
}
static async loadXYZAsync(file) { static async loadXYZAsync(file) {
switch (trueTypeOf(file)) { switch (trueTypeOf(file)) {
case String.name: case String.name: