2020-09-28 15:39:46 +02:00
|
|
|
class Geometry {
|
|
|
|
constructor(molecule, comment) {
|
|
|
|
this.molecule = molecule
|
|
|
|
this.comment = comment
|
|
|
|
}
|
|
|
|
static async loadXYZAsync(file) {
|
|
|
|
switch (trueTypeOf(file)) {
|
|
|
|
case String.name:
|
2020-11-19 23:56:04 +01:00
|
|
|
file = getFullDataPath("structures"+file)
|
|
|
|
var str = getTextFromFileUrl(file)
|
2020-09-28 15:39:46 +02:00
|
|
|
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) => {
|
2020-11-02 15:18:46 +01:00
|
|
|
return line.match(/^\d+\s*$/)
|
2020-09-28 15:39:46 +02:00
|
|
|
})
|
|
|
|
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
|
|
|
|
}
|
2020-11-19 23:56:04 +01:00
|
|
|
}
|