Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions src/include/meta_properties/pseudopotential.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,26 @@ export class Pseudopotential extends Property {
}

/**
* @summary Exclusive filter of raw data by all fields of the passed object
* @param {Array} rawData
* @summary Exclusive filter of raw pseudopotential array by approximation and functional
* @param {Pseudopotential[]} pseudos
* @param {Object} exchangeCorrelation
* @param {String} exchangeCorrelation.approximation
* @param {String} exchangeCorrelation.functional
*/
static filterRawDataByExchangeCorrelation(rawData, exchangeCorrelation) {
const { functional } = exchangeCorrelation;
static filterRawDataByExchangeCorrelation(pseudos, exchangeCorrelation) {
const { approximation, functional } = exchangeCorrelation;
if (!functional && !approximation) return pseudos;

if (!functional) {
return pseudos.filter(
(item) => item.exchangeCorrelation?.approximation === approximation,
);
}

const isCompatibleWithOther = Object.keys(this.compatibleExchangeCorrelation).includes(
functional,
);
return rawData.filter((item) => {
return pseudos.filter((item) => {
return isCompatibleWithOther
? this.compatibleExchangeCorrelation[functional].includes(
item.exchangeCorrelation?.functional,
Expand All @@ -95,16 +103,19 @@ export class Pseudopotential extends Property {
return Pseudopotential.filterUnique(this.filterByAppName(array, appName));
}

static filterRawDataByPath(rawData, pseudoPath = "") {
static filterRawDataByPath(pseudos, pseudoPath = "") {
if (!pseudoPath) return pseudos;
const regexp = new RegExp(pseudoPath);
return rawData.filter((el) => el.path.match(regexp));
return pseudos.filter((el) => el.path.match(regexp));
}

static filterByAppName(pseudos, appName) {
if (!appName) return pseudos;
return pseudos.filter((pseudo) => pseudo.apps.includes(appName));
}

static filterByElements(pseudos, elements) {
if (!elements || elements.length === 0) return pseudos;
return pseudos.filter((pseudo) => elements.includes(pseudo.element));
}

Expand Down
17 changes: 17 additions & 0 deletions tests/pseudopotential.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,23 @@ describe("Pseudopotentials", () => {
expect(sortedPseudos).to.have.length(3); // there are 3 PBE pseudos above
expect(sortedPseudos.map((p) => p.exchangeCorrelation.functional)).to.include("pbe");
});
it("can be filtered by exchange-correlation approximation only", () => {
const exchangeCorrelation = { approximation: "lda", functional: "" };
const sortedPseudos = Pseudopotential.filterRawDataByExchangeCorrelation(
pseudos,
exchangeCorrelation,
);
expect(sortedPseudos).to.have.length(1); // there is 1 LDA pseudo above
expect(sortedPseudos.map((p) => p.exchangeCorrelation.functional)).to.include("pz");
});
it("should return original array if approximation and functional are falsy", () => {
const exchangeCorrelation = { approximation: "", functional: "" };
const sortedPseudos = Pseudopotential.filterRawDataByExchangeCorrelation(
pseudos,
exchangeCorrelation,
);
expect(sortedPseudos).to.have.length(PSEUDO_CONFIGS.length); // there is 1 LDA pseudo above
});
it("can be filtered by pseudopotential type", () => {
const filtered = Pseudopotential.filterByType(pseudos, "paw");
const filteredWithObject = Pseudopotential.applyPseudoFilters(pseudos, { type: "paw" });
Expand Down