Skip to content

Commit

Permalink
Merge pull request #13 from Exabyte-io/epic/SOF-6265
Browse files Browse the repository at this point in the history
Epic/sof 6265
  • Loading branch information
timurbazhirov authored Nov 11, 2022
2 parents c1615d9 + f478de0 commit a9bf80e
Show file tree
Hide file tree
Showing 6 changed files with 248 additions and 246 deletions.
269 changes: 104 additions & 165 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"@babel/preset-react": "7.16.7",
"@babel/register": "^7.16.0",
"@babel/runtime-corejs3": "7.16.8",
"@exabyte-io/application-flavors.js": "2022.7.24-0",
"@exabyte-io/application-flavors.js": "2022.11.10-0",
"@exabyte-io/periodic-table.js": "2022.6.8-0",
"lodash": "^4.17.21",
"mixwith": "^0.1.1",
Expand All @@ -45,7 +45,7 @@
"underscore.string": "^3.3.4"
},
"devDependencies": {
"@exabyte-io/code.js": "2022.9.2-0",
"@exabyte-io/code.js": "2022.11.11-0",
"@exabyte-io/made.js": "2022.6.15-0",
"chai": "^4.3.4",
"eslint": "7.32.0",
Expand Down
89 changes: 63 additions & 26 deletions src/context/providers/espresso/providers.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,62 @@ import { Made } from "@exabyte-io/made.js";
import { PERIODIC_TABLE } from "@exabyte-io/periodic-table.js";
import lodash from "lodash";
import { mix } from "mixwith";
import _ from "underscore";
import s from "underscore.string";

import { ExecutableContextProvider } from "../../providers";

export class QEPWXContextProvider extends mix(ExecutableContextProvider).with(
MaterialContextMixin,
MaterialsContextMixin,
MethodDataContextMixin,
WorkflowContextMixin,
JobContextMixin,
) {
static Material = Made.Material;

get atomSymbols() {
return this.material.Basis.uniqueElements;
static atomSymbols(material) {
return material.Basis.uniqueElements;
}

/** Returns the input text block for atomic positions WITH constraints.
*/
static atomicPositionsWithConstraints(material) {
return material.Basis.atomicPositionsWithConstraints.join("\n");
}

/** Returns the input text block for atomic positions
* Note: does NOT include constraints
*/
static atomicPositions(material) {
return material.Basis.atomicPositions.join("\n");
}

static NAT(material) {
return material.Basis.atomicPositions.length;
}

static NTYP(material) {
return material.Basis.uniqueElements.length;
}

get atomicPositionsWithoutConstraints() {
return this.material.Basis.atomicPositions;
buildQEPWXContext(material) {
const IBRAV = 0; // use CELL_PARAMETERS to define Bravais lattice

return {
IBRAV,
RESTART_MODE: this.RESTART_MODE,
ATOMIC_SPECIES: this.ATOMIC_SPECIES(material),
NAT: QEPWXContextProvider.NAT(material),
NTYP: QEPWXContextProvider.NTYP(material),
ATOMIC_POSITIONS: QEPWXContextProvider.atomicPositionsWithConstraints(material),
ATOMIC_POSITIONS_WITHOUT_CONSTRAINTS: QEPWXContextProvider.atomicPositions(material),
CELL_PARAMETERS: QEPWXContextProvider.CELL_PARAMETERS(material),
};
}

get atomicPositions() {
return this.material.Basis.atomicPositionsWithConstraints;
getDataPerMaterial() {
if (!this.materials || this.materials.length <= 1) return {};
return { perMaterial: this.materials.map((material) => this.buildQEPWXContext(material)) };
}

/*
Expand All @@ -44,17 +77,9 @@ export class QEPWXContextProvider extends mix(ExecutableContextProvider).with(
// ECUTWFC = 40;
// ECUTRHO = 200;

const IBRAV = 0;

return {
IBRAV,
RESTART_MODE: this.RESTART_MODE,
NAT: this.atomicPositions.length,
NTYP: this.atomSymbols.length,
ATOMIC_POSITIONS: this.atomicPositions.join("\n"),
ATOMIC_POSITIONS_WITHOUT_CONSTRAINTS: this.atomicPositionsWithoutConstraints.join("\n"),
CELL_PARAMETERS: this.CELL_PARAMETERS,
ATOMIC_SPECIES: this.ATOMIC_SPECIES,
...this.buildQEPWXContext(this.material),
...this.getDataPerMaterial(),
};
}

Expand All @@ -66,16 +91,25 @@ export class QEPWXContextProvider extends mix(ExecutableContextProvider).with(
return (this.methodData.pseudo || []).find((p) => p.element === symbol);
}

get ATOMIC_SPECIES() {
// atomic species with pseudopotentials
return _.map(this.atomSymbols, (symbol) => {
const pseudo = this.getPseudoBySymbol(symbol);
return QEPWXContextProvider.symbolToAtomicSpecie(symbol, pseudo);
}).join("\n");
/** Builds ATOMIC SPECIES block of pw.x input in the format
* X Mass_X PseudoPot_X
* where X is the atom label
* Mass_X is the mass of element X [amu]
* PseudoPot_X is the pseudopotential filename associated with element X
*
* Note: assumes this.methodData is defined
*/
ATOMIC_SPECIES(material) {
return QEPWXContextProvider.atomSymbols(material)
.map((symbol) => {
const pseudo = this.getPseudoBySymbol(symbol);
return QEPWXContextProvider.symbolToAtomicSpecie(symbol, pseudo);
})
.join("\n");
}

get CELL_PARAMETERS() {
return this.material.Lattice.vectorArrays
static CELL_PARAMETERS(material) {
return material.Lattice.vectorArrays
.map((x) => {
return x
.map((y) => {
Expand Down Expand Up @@ -114,7 +148,10 @@ export class QENEBContextProvider extends mix(ExecutableContextProvider).with(
});

return {
..._.omit(PWXContexts[0], ["ATOMIC_POSITIONS", "ATOMIC_POSITIONS_WITHOUT_CONSTRAINTS"]),
...lodash.omit(PWXContexts[0], [
"ATOMIC_POSITIONS",
"ATOMIC_POSITIONS_WITHOUT_CONSTRAINTS",
]),
FIRST_IMAGE: PWXContexts[0].ATOMIC_POSITIONS,
LAST_IMAGE: PWXContexts[PWXContexts.length - 1].ATOMIC_POSITIONS,
INTERMEDIATE_IMAGES: PWXContexts.slice(1, PWXContexts.length - 1).map(
Expand Down
20 changes: 17 additions & 3 deletions src/context/providers/vasp/providers.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,27 @@ import { ExecutableContextProvider } from "../../providers";

export class VASPContextProvider extends mix(ExecutableContextProvider).with(
MaterialContextMixin,
MaterialsContextMixin,
MethodDataContextMixin,
WorkflowContextMixin,
JobContextMixin,
) {
static Material = Made.Material;

// eslint-disable-next-line class-methods-use-this
buildVASPContext(material) {
return {
// TODO: figure out whether we need two separate POSCARS, maybe one is enough
POSCAR: material.getAsPOSCAR(true, true),
POSCAR_WITH_CONSTRAINTS: material.getAsPOSCAR(true),
};
}

getDataPerMaterial() {
if (!this.materials || this.materials.length <= 1) return {};
return { perMaterial: this.materials.map((material) => this.buildVASPContext(material)) };
}

/*
* @NOTE: Overriding getData makes this provider "stateless", ie. delivering data from scratch each time and not
* considering the content of `this.data`, and `this.isEdited` field(s).
Expand All @@ -29,9 +44,8 @@ export class VASPContextProvider extends mix(ExecutableContextProvider).with(
// ECUTRHO;

return {
// TODO: figure out whether we need two separate POSCARS, maybe one is enough
POSCAR: this.material.getAsPOSCAR(true, true),
POSCAR_WITH_CONSTRAINTS: this.material.getAsPOSCAR(true),
...this.buildVASPContext(this.material),
...this.getDataPerMaterial(),
};
}
}
Expand Down
24 changes: 10 additions & 14 deletions src/executable.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import { mix } from "mixwith";
import { NamedDefaultableInMemoryEntity, RuntimeItemsMixin } from "@exabyte-io/code.js/dist/entity";
import { mix } from "mixwith";

import { Flavor } from "./flavor";

export class Executable extends mix(NamedDefaultableInMemoryEntity).with(RuntimeItemsMixin) {
static Flavor = Flavor;

constructor(config) {
super(config);
}

toJSON(exclude) {
return super.toJSON(["flavors"].concat(exclude));
}
Expand All @@ -18,18 +15,18 @@ export class Executable extends mix(NamedDefaultableInMemoryEntity).with(Runtime
}

get flavors() {
return Object.keys(this.flavorsTree).map(key => {
return this.constructor.Flavor.create(
Object.assign({}, this.flavorsTree[key], {name: key, executable: this})
);
return Object.keys(this.flavorsTree).map((key) => {
return this.constructor.Flavor.create({
...this.flavorsTree[key],
name: key,
executable: this,
});
});
}

get flavorsFromTree() {
return Object.keys(this.flavorsTree).map(key => {
return new this.constructor.Flavor(
Object.assign({}, this.flavorsTree[key], {name: key})
);
return Object.keys(this.flavorsTree).map((key) => {
return new this.constructor.Flavor({ ...this.flavorsTree[key], name: key });
});
}

Expand All @@ -44,5 +41,4 @@ export class Executable extends mix(NamedDefaultableInMemoryEntity).with(Runtime
getFlavorByConfig(config) {
return config ? this.getFlavorByName(config.name) : this.defaultFlavor;
}

}
Loading

0 comments on commit a9bf80e

Please sign in to comment.