-
Notifications
You must be signed in to change notification settings - Fork 3
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
base: epic/SOF-5386
Are you sure you want to change the base?
Changes from 8 commits
ac672c8
c06358a
e5e38b6
aef4e7b
65c6528
6ef320c
78572e9
df31214
bce5e1b
2877ebc
d859afc
8750dae
431a269
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { ATOMIC_COORD_UNITS, units } from "./constants"; | ||
import { LATTICE_TYPE } from "./lattice/types"; | ||
|
||
export const defaultMaterialConfig = { | ||
name: "Silicon FCC", | ||
basis: { | ||
elements: [ | ||
{ | ||
id: 1, | ||
value: "Si", | ||
}, | ||
{ | ||
id: 2, | ||
value: "Si", | ||
}, | ||
], | ||
coordinates: [ | ||
{ | ||
id: 1, | ||
value: [0.0, 0.0, 0.0], | ||
}, | ||
{ | ||
id: 2, | ||
value: [0.25, 0.25, 0.25], | ||
}, | ||
], | ||
units: ATOMIC_COORD_UNITS.crystal, | ||
}, | ||
lattice: { | ||
// Primitive cell for Diamond FCC Silicon at ambient conditions | ||
type: LATTICE_TYPE.FCC, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. okay i will look into this. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? |
||
a: 3.867, | ||
b: 3.867, | ||
c: 3.867, | ||
alpha: 60, | ||
beta: 60, | ||
gamma: 60, | ||
units: { | ||
length: units.angstrom, | ||
angle: units.degree, | ||
}, | ||
}, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,47 @@ | ||
// eslint-disable-next-line import/no-cycle | ||
import { defaultMaterialConfig } from "../default_material"; | ||
import cif from "./cif"; | ||
import espresso from "./espresso"; | ||
import poscar from "./poscar"; | ||
import xyz from "./xyz"; | ||
|
||
/** | ||
* Function returns the number of atoms in a file using the proper parser function based on the file extension. | ||
* @param {String} fileExtension | ||
* @param {String} fileContent | ||
* @returns {Number} | ||
*/ | ||
export function getNumberOfAtomsInFileByExtension(fileExtension, fileContent) { | ||
let numberOfAtoms = 0; | ||
if (fileExtension === "poscar") { | ||
numberOfAtoms = poscar.getAtomsCount(fileContent); | ||
} | ||
if (fileExtension === "xyz") { | ||
numberOfAtoms = xyz.getAtomsCount(fileContent); | ||
} | ||
return numberOfAtoms; | ||
} | ||
|
||
/** | ||
* Function converts an XYZ formatted structure as a POSCAR formatted structure | ||
* @param {String} xyzContent | ||
* @returns {String} | ||
*/ | ||
export function xyzToPoscar(xyzContent) { | ||
const xyzConfig = defaultMaterialConfig; | ||
const xyzArray = xyzContent.split(/\r?\n/); | ||
const xyzArrayBasisOnly = xyzArray.slice(2, -1); | ||
const xyzBasis = xyzArrayBasisOnly.join("\n"); | ||
xyzConfig.basis = xyz.toBasisConfig(xyzBasis); | ||
xyzConfig.basis.units = "cartesian"; | ||
return poscar.toPoscar(xyzConfig); | ||
} | ||
|
||
export default { | ||
xyz, | ||
poscar, | ||
cif, | ||
espresso, | ||
getNumberOfAtomsInFileByExtension, | ||
xyzToPoscar, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { xyzToPoscar } from "../../src/parsers/parsers"; | ||
import { CH4, CH4POSCAR } from "../enums"; | ||
import { assertDeepAlmostEqual } from "../utils"; | ||
|
||
describe("Parsers:XYZ", () => { | ||
it("should return the xyz file content in poscar file format", () => { | ||
assertDeepAlmostEqual(xyzToPoscar(CH4), CH4POSCAR); | ||
}); | ||
}); |
There was a problem hiding this comment.
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.