Skip to content

Commit

Permalink
fix(InpHelper): expose stripCoreZeros for simput
Browse files Browse the repository at this point in the history
also change choreShape return and add padding.
  • Loading branch information
aronhelser committed May 14, 2018
1 parent 5a9d905 commit d2d2a25
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
38 changes: 23 additions & 15 deletions src/utils/InpHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ function setSymmetry(rodmap, params) {
const labelCompare = (a, b) => a.label.localeCompare(b.label);

// anywhere the core map has zero, strip '-' from the text map.
function stripCoreZeros(textMap, coreMap) {
function stripCoreZeros(textMap, coreMap, pad = '') {
const coreRows = coreMap
.split('\n')
.map((line) => line.trim().split(/[,\s]+/));
Expand All @@ -187,12 +187,12 @@ function stripCoreZeros(textMap, coreMap) {
.join(' ');
// .trim();
});
return lines.join('\n');
return lines.join(`\n${pad}`);
}

function getCoreShape(coremaps, inShapeMap = null) {
let coreShapeMap = inShapeMap;
// set title, build a core_shape array.
// build a core_shape array.
// Set locations occupied in any map to 1, empty to 0
coremaps.forEach((cm, j) => {
if (!coreShapeMap) {
Expand All @@ -204,7 +204,14 @@ function getCoreShape(coremaps, inShapeMap = null) {
});
}
});
return coreShapeMap;
if (coreShapeMap) {
return {
type: 'coremaps',
symmetry: 'none',
cell_map: coreShapeMap,
};
}
return null;
}

// inverse of 'parseFile' - take a state, and write as much as
Expand All @@ -221,30 +228,29 @@ function writeToInp(state, GROUP_TYPES) {
result.push(` apitch ${state.params.assemblyPitch}`);

const groupTitles = {};
const coreShapeMap = getCoreShape(state.coremaps);
const coreShape = getCoreShape(state.coremaps);
// set title, build a core_shape array.
// Set locations occupied in any map to 1, empty to 0
state.coremaps.forEach((cm) => {
groupTitles[cm.group] = cm.label;
});
if (coreShapeMap) {
const coreShape = {
type: 'coremaps',
symmetry: 'none',
cell_map: coreShapeMap,
};
if (coreShape) {
const coreText = getTextMap(coreShape, state.params);
result.push('\n core_shape');
coreText.split('\n').forEach((line) => {
result.push(` ${line}`);
});

// get symmetry text maps for comparison with assemblies.
const coreMaps = {
const coreTextMaps = {
none: coreText,
oct: (coreShape.symmetry = 'oct') && getTextMap(coreShape, state.params),
quad:
(coreShape.symmetry = 'quad') && getTextMap(coreShape, state.params),
quad_rot:
(coreShape.symmetry = 'quad_rot') &&
getTextMap(coreShape, state.params),
quad_mir:
(coreShape.symmetry = 'quad_mir') &&
getTextMap(coreShape, state.params),
};
GROUP_TYPES.forEach((info) => {
const mapList = state.coremaps.filter((a) => a.group === info.group);
Expand All @@ -254,7 +260,7 @@ function writeToInp(state, GROUP_TYPES) {
setSymmetry(assemMap, state.params);
let textMap = getTextMap(assemMap, state.params);
// strips locations that are '0' in coreShape map.
textMap = stripCoreZeros(textMap, coreMaps[assemMap.symmetry]);
textMap = stripCoreZeros(textMap, coreTextMaps[assemMap.symmetry]);
textMap.split('\n').forEach((line) => {
result.push(` ${line}`);
});
Expand Down Expand Up @@ -350,5 +356,7 @@ export default {
getTextMap,
getFullMap,
setSymmetry,
stripCoreZeros,
writeToInp,
SymmetryModes,
};
4 changes: 3 additions & 1 deletion src/widgets/AssemblyLayoutEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,12 @@ export default class AssemblyLayoutEditor extends React.Component {
}
if (this.props.content.type === 'coremaps') {
// update the coreShape
this.props.content.coreShape = InpHelper.getCoreShape(
const coreShape = InpHelper.getCoreShape(
this.props.coremaps,
this.props.content.coreShape
);

this.props.content.coreShape = coreShape ? coreShape.cell_map : null;
}
updateLayoutImage(
this.props.content,
Expand Down

0 comments on commit d2d2a25

Please sign in to comment.