Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: xyz file parsing - nAtoms & nLines to check formatting. Created… #52

Open
wants to merge 13 commits into
base: epic/SOF-5386
Choose a base branch
from

Conversation

adewyer
Copy link
Contributor

@adewyer adewyer commented Dec 30, 2021

… functions and tests

@@ -140,10 +141,25 @@ function fromMaterial(materialOrConfig, fractional = false) {
return fromBasis(basis, "%11.6f");
}

export function atomsCount(xyzFile) {
const xyzArray = xyzFile.split(/\r?\n/);
return Integer.parseInt(xyzArray[0]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Why do we even need this function, if all this does is just split on newlines? This is not specific to XYZ format, is it?
  2. No docstring, explanation of the expected behavior

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first line of an xyz file contains the number of atoms. So we split the string by new lines and then return the first new line to get the number of atoms in the file.

const content = xyzFile.split(/\r?\n/);
if (!content[-1]) {
content.pop();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what's happening above - no explanation either.

…nd converting to poscar to made instead of web-app
* @param {String} fileContent
* @returns {Number}
*/
export function getAtomsInFileByExtension(fileExtension, fileContent) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getNumberOfAtomsByFileExtension

src/parsers/parsers.js Outdated Show resolved Hide resolved
src/parsers/poscar.js Outdated Show resolved Hide resolved
import _ from "underscore";
import s from "underscore.string";

import { Basis } from "../basis/basis";
import { ConstrainedBasis } from "../basis/constrained_basis";
import { Lattice } from "../lattice/lattice";
// eslint-disable-next-line import/no-cycle
import { defaultMaterialConfig } from "../material";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand your comment above, but we should not be introducing circular dependencies with new code. It's usually a sign of not having a correct placement of the code

src/parsers/xyz.js Outdated Show resolved Hide resolved
const xyzBasis = xyzArrayBasisOnly.join("\n");
xyzConfig.basis = toBasisConfig(xyzBasis);
xyzConfig.basis.units = "cartesian";
return poscar.toPoscar(xyzConfig);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The placement of this function seems to be bad at the moment, hence the circular dependency. We should move this functionality to resolve the problem - maybe to top-level of parsers?

@@ -1,11 +1,47 @@
// eslint-disable-next-line import/no-cycle
import { defaultMaterialConfig } from "../material";
Copy link
Contributor Author

@adewyer adewyer Jan 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving the xyzToPoscar function from parsers/xyz.js to this file fixed the import xyz circular dependency, but created one for defaultMaterialConfig. Previously this circular dependency was noted inside parsers/xyz.js

@adewyer
Copy link
Contributor Author

adewyer commented Jan 13, 2022

Not sure why CICD tests are failing. Everything passes locally

Basis
Basis.constructor: units are not provided => set to crystal
Basis.constructor: units are not provided => set to crystal
✔ should return true if basises are equal
✔ should return true when basis is compared to its clone
✔ should return jsonified basis
Basis.constructor: units are not provided => set to crystal
Basis.constructor: units are not provided => set to crystal
✔ should return true if cells are equal
✔ should return Na4Cl4 as unitCellFormula
✔ should return NaCl as formula
✔ should return elements
✔ should return unique elements
✔ should return elements count
✔ should set elements
✔ should return coordinates
✔ should set coordinates
✔ should return true if basis is in crystal units
✔ should convert crystal to cartesian
✔ should add a new atom
✔ should remove an atom
✔ should return number of atoms
✔ should return the string
✔ should return standard representation
✔ should return minimum lattice size for a molecule
Basis.constructor: units are not provided => set to crystal
✔ should return minimum lattice size for an atom
✔ should return max distance
✔ should return center of coordinates
✔ should return the updated basis coordinates

Cell
✔ should return scaled cell

Primitive Cell
✔ should return primitive lattice

AtomicConstraints
✔ should return constraints as string
✔ should return constraints as string with given map function
✔ should return [true, true, true] as constraints for the line without any constraints

Lattice
✔ should return lattice cell volume
✔ should return lattice from vectors
✔ should return lattice type
✔ should return lattice hash string

Lattice Bravais
✔ should return lattice bravais from vectors
✔ should return a list of editable keys

Lattice Reciprocal
✔ should extract kpoint path
✔ should return cartesian coordinates of a point
✔ should return reciprocal vectors
✔ should extract symmetry points

Lattice Vectors
✔ should return lattice from bravais

Parsers:Espresso
Basis.constructor: units are not provided => set to crystal
✔ should return textual representation of a material according to QE pw.x input format
(node:19113) DeprecationWarning: sprintf() will be removed in the next major release, use the sprintf-js package instead.

Parsers:XYZ
✔ should return the xyz file content in poscar file format

Parsers.POSCAR
✔ should return a valid poscar
✔ should return poscar elements line according to id in basis, duplicate entries separate
✔ should return the number of atoms for a molecule in a poscar file

Parsers:XYZ
✔ should extract basis from XYZ text
✔ should return the number of atoms for a molecule in an xyz file

Parsers:CombinatorialBasis
Basis.constructor: units are not provided => set to crystal
✔ toBasisConfig
Basis.constructor: units are not provided => set to crystal
✔ Regular XYZ
Basis.constructor: units are not provided => set to crystal
Basis.constructor: units are not provided => set to crystal
Basis.constructor: units are not provided => set to crystal
✔ Permutation XYZ
✔ Combination XYZ
✔ Mixing combination and permutation should fail

Tools:Basis
Basis.constructor: units are not provided => set to crystal
✔ should return a repeated basis
✔ should return interpolated basises

Tools:Supercell
Basis.constructor: units are not provided => set to crystal
Basis.constructor: units are not provided => set to crystal
Basis.constructor: units are not provided => set to crystal
✔ should generate supercell

Tools:Surface
Basis.constructor: units are not provided => set to crystal
Basis.constructor: units are not provided => set to crystal
✔ should return slab

56 passing (105ms)

@@ -18,6 +18,8 @@ jobs:
steps:
Copy link
Contributor Author

@adewyer adewyer Jan 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes from @tjduigna to fix CICD test failures caused by git lfs not pulling test files.

},
lattice: {
// Primitive cell for Diamond FCC Silicon at ambient conditions
type: LATTICE_TYPE.FCC,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect the fact that we are using LATTICE_TYPE here and in the Lattice, and then import Lattice inside Material could lead to circular dependency which could lead to the problem with tests for https://github.com/Exabyte-io/exabyte-stack/pull/235/files#r805085142

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay i will look into this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We saw these same errors prior to me moving default materials out of material.

Previously we imported both LATTICE_TYPE & LATTICE into material.js. Wouldn't that lead to the same circular error?

* @returns {Object}
*/
export function getDefaultMaterialConfig() {
return defaultMaterialConfig;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return {...defaultMaterialConfig}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: utilize this function instead of defaultMaterialConfig in code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants