-
Notifications
You must be signed in to change notification settings - Fork 4
Feat: xyz file parsing - nAtoms & nLines to check formatting. Created… #52
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
base: epic/SOF-5386
Are you sure you want to change the base?
Changes from 5 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 |
|---|---|---|
| @@ -1,11 +1,31 @@ | ||
| import cif from "./cif"; | ||
| // eslint-disable-next-line import/no-cycle | ||
| import espresso from "./espresso"; | ||
| import poscar from "./poscar"; | ||
| // eslint-disable-next-line import/no-cycle | ||
| 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.poscarFileAtomsCount(fileContent); | ||
| } | ||
| if (fileExtension === "xyz") { | ||
| numberOfAtoms = xyz.xyzFileAtomsCount(fileContent); | ||
| } | ||
| return numberOfAtoms; | ||
| } | ||
|
|
||
| export default { | ||
| xyz, | ||
| poscar, | ||
| cif, | ||
| espresso, | ||
| getNumberOfAtomsInFileByExtension, | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,15 @@ | ||
| import Integer from "lodash/string"; | ||
| 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"; | ||
|
||
| import math from "../math"; | ||
| import { InvalidLineError } from "./errors"; | ||
| import poscar from "./poscar"; | ||
| import { CombinatorialBasis } from "./xyz_combinatorial_basis"; | ||
|
|
||
| // Regular expression for an XYZ line with atomic constraints, eg. Si 0.000000 0.500000 0.446678 1 1 1` | ||
|
|
@@ -140,10 +144,37 @@ function fromMaterial(materialOrConfig, fractional = false) { | |
| return fromBasis(basis, "%11.6f"); | ||
| } | ||
|
|
||
| /** | ||
| * Function splits the xyzFile string at new lines and then returns the first element of the array. | ||
| * The first line of the XYZ file should contain the number of atoms in the structure. | ||
| * @param {String} xyzFile | ||
| * @returns {Number} | ||
| */ | ||
| export function xyzFileAtomsCount(xyzFile) { | ||
| return Integer.parseInt(xyzFile.split(/\r?\n/)[0]); | ||
adewyer marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| /** | ||
| * 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 = toBasisConfig(xyzBasis); | ||
| xyzConfig.basis.units = "cartesian"; | ||
| return poscar.toPoscar(xyzConfig); | ||
|
||
| } | ||
|
|
||
| export default { | ||
| validate, | ||
| fromMaterial, | ||
| toBasisConfig, | ||
| fromBasis, | ||
| CombinatorialBasis, | ||
| xyzFileAtomsCount, | ||
| xyzToPoscar, | ||
| }; | ||
Uh oh!
There was an error while loading. Please reload this page.