mirror of
https://github.com/LCPQ/QUESTDB_website.git
synced 2024-08-26 22:21:53 +02:00
36 lines
1.1 KiB
JavaScript
36 lines
1.1 KiB
JavaScript
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)
|
|
const maxAge= (DebugMode.Enabled,0,600)
|
|
var str = await getTextFromFileUrlAsync(file,{"Cache-Control":`max-age=${maxAge}`})
|
|
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
|
|
}
|
|
} |