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
20 changes: 10 additions & 10 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ jobs:

steps:
- name: Checkout this repository
uses: actions/checkout@v4
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
lfs: true

- name: Checkout actions repository
uses: actions/checkout@v4
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
repository: Exabyte-io/actions
token: ${{ secrets.BOT_GITHUB_TOKEN }}
Expand All @@ -43,12 +43,12 @@ jobs:

steps:
- name: Checkout this repository
uses: actions/checkout@v4
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
lfs: true

- name: Checkout actions repository
uses: actions/checkout@v4
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
repository: Exabyte-io/actions
token: ${{ secrets.BOT_GITHUB_TOKEN }}
Expand All @@ -70,12 +70,12 @@ jobs:

steps:
- name: Checkout this repository
uses: actions/checkout@v4
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
lfs: true

- name: Checkout actions repository
uses: actions/checkout@v4
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
repository: Exabyte-io/actions
token: ${{ secrets.BOT_GITHUB_TOKEN }}
Expand All @@ -102,10 +102,10 @@ jobs:

steps:
- name: Checkout this repository
uses: actions/checkout@v4
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0

- name: Checkout actions repository
uses: actions/checkout@v4
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
repository: Exabyte-io/actions
token: ${{ secrets.BOT_GITHUB_TOKEN }}
Expand All @@ -128,12 +128,12 @@ jobs:

steps:
- name: Checkout this repository
uses: actions/checkout@v4
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
lfs: true

- name: Checkout actions repository
uses: actions/checkout@v4
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
repository: Exabyte-io/actions
token: ${{ secrets.BOT_GITHUB_TOKEN }}
Expand Down
20 changes: 11 additions & 9 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

#### Below is an example of how to rebuild JS and PY assets if JSON assets have changed.
# SRC_PATTERN="\.json$"
# if git diff --cached --name-only | grep --quiet -E "$SRC_PATTERN"
# then
# echo "JSON assets changed. Running build scripts."
# echo "Re-building JS and PY assets using JS script."
# npm run build:js-and-python-modules
# fi
SRC_PATTERN="constants\.json$"
if git diff --cached --name-only | grep --quiet -E "$SRC_PATTERN"
then
echo "JSON assets changed. Running build scripts."
# Run your custom script to generate constants.py and constants.js
npm run build:constants

# Stage the newly generated files
git add src/py/mat3ra/utils/constants.py
git add src/js/shared/constants.js
fi

# Automatically lint staged files in pre-commit hook
npm run transpile
npx lint-staged
git add dist/js
1 change: 1 addition & 0 deletions dist/js/shared/constants.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ declare namespace _default {
export { tolerance };
export { units };
export { ATOMIC_COORD_UNITS };
export { HASH_TOLERANCE };
}
export default _default;
36 changes: 17 additions & 19 deletions dist/js/shared/constants.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,35 @@
"use strict";
// This file is autogenerated from src/shared/constants.yaml
// DO NOT EDIT DIRECTLY! Edit above YAML file and run 'npm run build:constants'.
Object.defineProperty(exports, "__esModule", { value: true });
exports.HASH_TOLERANCE = exports.ATOMIC_COORD_UNITS = exports.units = exports.tolerance = exports.coefficients = void 0;
exports.coefficients = {
EV_TO_RY: 0.0734986176,
BOHR_TO_ANGSTROM: 0.52917721092,
ANGSTROM_TO_BOHR: 1 / 0.52917721092,
EV_A_TO_RY_BOHR: 1 / 25.71104309541616,
"EV_TO_RY": 0.0734986444,
"BOHR_TO_ANGSTROM": 0.529177210544,
"ANGSTROM_TO_BOHR": 1.8897261259077822,
"EV_A_TO_RY_BOHR": 0.0388938075966032
};
exports.tolerance = {
// in crystal coordinates
length: 0.01,
lengthAngstrom: 0.001,
pointsDistance: 0.001,
"length": 0.01,
"lengthAngstrom": 0.001,
"pointsDistance": 0.001
};
exports.units = {
bohr: "bohr",
angstrom: "angstrom",
degree: "degree",
radian: "radian",
alat: "alat",
"bohr": "bohr",
"angstrom": "angstrom",
"degree": "degree",
"radian": "radian",
"alat": "alat"
};
/**
* @summary Coordinates units for a material's basis.
*/
exports.ATOMIC_COORD_UNITS = {
crystal: "crystal",
cartesian: "cartesian",
"crystal": "crystal",
"cartesian": "cartesian"
};
// Only 3 digits will be considered for lattice and basis params for hashing
exports.HASH_TOLERANCE = 3;
exports.default = {
coefficients: exports.coefficients,
tolerance: exports.tolerance,
units: exports.units,
ATOMIC_COORD_UNITS: exports.ATOMIC_COORD_UNITS,
HASH_TOLERANCE: exports.HASH_TOLERANCE,
};
3 changes: 2 additions & 1 deletion dist/js/shared/str.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ exports.toFixedLocale = toFixedLocale;
function removeCommentsFromSourceCode(text, language = "shell") {
var _a;
const regexList = {
shell: /#(?!!).*$/gm,
espresso: /[!#].*$/gm,
fortran: /!.*$/gm,
python: /#.*$/gm,
shell: /#(?!!).*$/gm,
};
return text.replace((_a = regexList[language]) !== null && _a !== void 0 ? _a : regexList.shell, "");
}
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"prepare": "husky install || exit 0",
"prettier": "prettier --check src/js tests/js",
"test": "nyc --reporter=text mocha --recursive --bail tests/js",
"transpile": "tsc -p tsconfig-transpile.json"
"transpile": "tsc -p tsconfig-transpile.json",
"build:constants": "node scripts/build_constants.js"
},
"author": "Exabyte Inc.",
"license": "ISC",
Expand Down
62 changes: 62 additions & 0 deletions scripts/build_constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
const fs = require('fs');
const path = require('path');
const yaml = require('js-yaml');

// Define paths relative to the project root
const yamlPath = path.join(process.cwd(), 'src/shared/constants.yaml');
const jsPath = path.join(process.cwd(), 'src/js/shared/constants.js');
const pyPath = path.join(process.cwd(), 'src/py/mat3ra/utils/constants.py');

try {
// Read and parse the YAML file
const rawData = fs.readFileSync(yamlPath, 'utf-8');
const constants = yaml.load(rawData);

// Build JS content
let jsContent = `// This file is autogenerated from src/shared/constants.yaml\n` +
`// DO NOT EDIT DIRECTLY! Edit above YAML file and run ` +
`'npm run build:constants'.\n\n`;

// Dynamically generate individual exports for every top-level key
const keys = Object.keys(constants);
for (const key of keys) {
jsContent += `export const ${key} = ${JSON.stringify(constants[key], null, 4)};\n\n`;
}

// Dynamically generate the default export block
jsContent += `export default {\n`;
for (const key of keys) {
jsContent += ` ${key},\n`;
}
jsContent += `};\n`;

fs.mkdirSync(path.dirname(jsPath), { recursive: true });
fs.writeFileSync(jsPath, jsContent, 'utf-8');

console.log(`✅ Successfully generated JS constants at: ${jsPath}`);

// Build Python content
let pyContent = `# This file is autogenerated from src/shared/constants.yaml\n` +
`# DO NOT EDIT DIRECTLY! Edit above YAML file and run` +
`'npm run build:constants'.\n`;

for (const key of Object.keys(constants)) {
// In Python, standard practice is to use UPPERCASE for constants
const pyKey = key.toUpperCase();

// Stringify the object, but replace JS native types with Python native types
let pyValue = JSON.stringify(constants[key], null, 4)
.replace(/: true/g, ': True')
.replace(/: false/g, ': False')
.replace(/: null/g, ': None');

pyContent += `\n${pyKey} = ${pyValue}\n`;
}

fs.mkdirSync(path.dirname(pyPath), { recursive: true });
fs.writeFileSync(pyPath, pyContent, 'utf-8');
console.log(`✅ Successfully generated Python constants at: ${pyPath}`);
} catch (error) {
console.error("❌ Failed to build constants.js:", error.message);
process.exit(1);
}
37 changes: 18 additions & 19 deletions src/js/shared/constants.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,38 @@
// This file is autogenerated from src/shared/constants.yaml
// DO NOT EDIT DIRECTLY! Edit above YAML file and run 'npm run build:constants'.

export const coefficients = {
EV_TO_RY: 0.0734986176,
BOHR_TO_ANGSTROM: 0.52917721092,
ANGSTROM_TO_BOHR: 1 / 0.52917721092,
EV_A_TO_RY_BOHR: 1 / 25.71104309541616,
"EV_TO_RY": 0.0734986444,
"BOHR_TO_ANGSTROM": 0.529177210544,
"ANGSTROM_TO_BOHR": 1.8897261259077822,
"EV_A_TO_RY_BOHR": 0.0388938075966032
};

export const tolerance = {
// in crystal coordinates
length: 0.01,
lengthAngstrom: 0.001,
pointsDistance: 0.001,
"length": 0.01,
"lengthAngstrom": 0.001,
"pointsDistance": 0.001
};

export const units = {
bohr: "bohr",
angstrom: "angstrom",
degree: "degree",
radian: "radian",
alat: "alat",
"bohr": "bohr",
"angstrom": "angstrom",
"degree": "degree",
"radian": "radian",
"alat": "alat"
};

/**
* @summary Coordinates units for a material's basis.
*/
export const ATOMIC_COORD_UNITS = {
crystal: "crystal",
cartesian: "cartesian",
"crystal": "crystal",
"cartesian": "cartesian"
};

// Only 3 digits will be considered for lattice and basis params for hashing
export const HASH_TOLERANCE = 3;

export default {
coefficients,
tolerance,
units,
ATOMIC_COORD_UNITS,
HASH_TOLERANCE,
};
3 changes: 2 additions & 1 deletion src/js/shared/str.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ export function toFixedLocale(number, precision) {
*/
export function removeCommentsFromSourceCode(text, language = "shell") {
const regexList = {
shell: /#(?!!).*$/gm,
espresso: /[!#].*$/gm,
fortran: /!.*$/gm,
python: /#.*$/gm,
shell: /#(?!!).*$/gm,
};
return text.replace(regexList[language] ?? regexList.shell, "");
}
Expand Down
30 changes: 30 additions & 0 deletions src/py/mat3ra/utils/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# This file is autogenerated from src/shared/constants.yaml
# DO NOT EDIT DIRECTLY! Edit above YAML file and run'npm run build:constants'.

COEFFICIENTS = {
"EV_TO_RY": 0.0734986444,
"BOHR_TO_ANGSTROM": 0.529177210544,
"ANGSTROM_TO_BOHR": 1.8897261259077822,
"EV_A_TO_RY_BOHR": 0.0388938075966032
}

TOLERANCE = {
"length": 0.01,
"lengthAngstrom": 0.001,
"pointsDistance": 0.001
}

UNITS = {
"bohr": "bohr",
"angstrom": "angstrom",
"degree": "degree",
"radian": "radian",
"alat": "alat"
}

ATOMIC_COORD_UNITS = {
"crystal": "crystal",
"cartesian": "cartesian"
}

HASH_TOLERANCE = 3
Loading
Loading