mirror of
https://github.com/LCPQ/QUESTDB_website.git
synced 2024-12-25 13:53:48 +01:00
Change geometries handling
This commit is contained in:
parent
a65fe57d35
commit
85ab5b9968
16
static/js/GeometriesLoader.js
Normal file
16
static/js/GeometriesLoader.js
Normal file
@ -0,0 +1,16 @@
|
||||
class GeometriesLoader{
|
||||
static async loadForAsync(array){
|
||||
var xyzs=[]
|
||||
for (const item of array) {
|
||||
const mymol=mhchemCE.extract(item.molecule).toLowerCase().replace(" ","_")
|
||||
const myset=item.set.split("#").join("")
|
||||
try {
|
||||
const mol=await Geometry.loadXYZAsync(`/${myset}/${mymol}.xyz`)
|
||||
xyzs.push(mol)
|
||||
} catch (error) {
|
||||
console.error("Geometry not found",item)
|
||||
}
|
||||
}
|
||||
return xyzs.flat()
|
||||
}
|
||||
}
|
35
static/js/Geometry.js
Normal file
35
static/js/Geometry.js
Normal file
@ -0,0 +1,35 @@
|
||||
class Geometry {
|
||||
constructor(molecule, comment) {
|
||||
this.molecule = molecule
|
||||
this.comment = comment
|
||||
}
|
||||
static async loadXYZAsync(file) {
|
||||
switch (trueTypeOf(file)) {
|
||||
case String.name:
|
||||
file = getFullDataPath("/structures/"+file)
|
||||
var str = await getTextFromFileUrlAsync(file)
|
||||
break;
|
||||
case File.name:
|
||||
var str = await getTextFromUploadedFileAsync(file)
|
||||
break
|
||||
}
|
||||
var xyz = this.loadXYZString(str);
|
||||
xyz.sourceFile = new websiteFile(file)
|
||||
return xyz
|
||||
}
|
||||
static loadXYZString(text) {
|
||||
var lines = text.split("\n")
|
||||
var indexes = lines.findAllIndexes((line) => {
|
||||
return line.match(/^\d+$/)
|
||||
})
|
||||
indexes.push(lines.length)
|
||||
var geoms = []
|
||||
for (let i = 0; i < indexes.length - 1; i++) {
|
||||
const mollines = lines.slice(indexes[i], indexes[i + 1])
|
||||
const comment = mollines[1]
|
||||
const molecule = ChemDoodle.readXYZ(mollines.join("\n"))
|
||||
geoms.push(new Geometry(molecule, comment))
|
||||
}
|
||||
return geoms
|
||||
}
|
||||
}
|
20
static/js/GeometryParseMetadataExtension.js
Normal file
20
static/js/GeometryParseMetadataExtension.js
Normal file
@ -0,0 +1,20 @@
|
||||
if (!Geometry.prototype.parseMetadata) {
|
||||
Geometry.prototype.parseMetadata = function () {
|
||||
const Ametadata = this.comment.split(",")
|
||||
const molecule = Ametadata[0]
|
||||
const stateRegExp = /^\^(\d+)(.+)$/
|
||||
const m = Ametadata[1].match(stateRegExp)
|
||||
const mul = m[1]
|
||||
const sym = m[2]
|
||||
var meth = null
|
||||
if (Ametadata.length>2) {
|
||||
meth = new method(Ametadata[2],Ametadata[3])
|
||||
}
|
||||
return {
|
||||
molecule:molecule,
|
||||
multiplicity:mul,
|
||||
symmetry:sym,
|
||||
method:meth
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user