Skip to content

Commit

Permalink
Files output major changes
Browse files Browse the repository at this point in the history
- consolidated options in sidebar
- option to merge by CIF labels if present
- csv or fixed width option
- precision control

Partially addressed issue:
CCP-NC#15
  • Loading branch information
jkshenton committed Mar 16, 2023
1 parent c1439e7 commit 11d04d1
Show file tree
Hide file tree
Showing 3 changed files with 397 additions and 91 deletions.
125 changes: 112 additions & 13 deletions src/core/sidebars/MVSidebarFiles.js
Expand Up @@ -20,14 +20,41 @@ import MVButton from '../../controls/MVButton';
import MVCustomSelect, { MVCustomSelectOption } from '../../controls/MVCustomSelect';
import MVIcon from '../../icons/MVIcon';
import { GiSpinningTop } from 'react-icons/gi';

import MVCheckBox from '../../controls/MVCheckBox';
import MVRange from '../../controls/MVRange';
import MVTooltip from '../../controls/MVTooltip';
import { tooltip_files_merge, tooltip_files_precision} from './tooltip_messages';

import { useFilesInterface } from '../store';
import { saveContents } from '../../utils';

const saveFile = (c, fn) => { saveContents(c, fn); }

const mergeOption = (fileint) => {
if (fileint.hasCIFLabels) {
return (<MVCheckBox checked={fileint.mergeByLabel} onCheck={(v) => { fileint.mergeByLabel = v; }}>
Merge by label &nbsp;
<MVTooltip tooltipText={tooltip_files_merge} />
</MVCheckBox>);
} else {
// blank return
return (<></>);
}
}
const eulerOption = (fileint) => {
return (<MVCheckBox checked={fileint.includeEuler} onCheck={(v) => { fileint.includeEuler = v; }}>Include Euler angles</MVCheckBox>);
}

function selectFileFormat(fileint) {
return (<div className='.mv-sidebar-grid'>
<h3> File format:</h3>
<MVCustomSelect title={'File type'} zorder={3} selected={fileint.fileFormat} onSelect={(v) => { fileint.fileFormat = v; }}>
<MVCustomSelectOption value={'fixed'}>Fixed width</MVCustomSelectOption>
<MVCustomSelectOption value={'csv'}>CSV</MVCustomSelectOption>
</MVCustomSelect>
</div>);
}

function selectquadorder(fileint) {
return (<div className='.mv-sidebar-grid'>
<h4>Quadrupole order:</h4>
Expand All @@ -40,36 +67,108 @@ function selectquadorder(fileint) {

}

function setPrecision(fileint) {
return (<MVRange
min={0}
max={8}
step={1}
value={fileint.precision}
tooltip={tooltip_files_precision}
onChange={(p) => { fileint.precision = p; }}>
Precision
</MVRange>
);
}


// eslint-disable-next-line
function spinSysOptions(fileint) {
return (<div className='.mv-sidebar-grid'>
<h3>Include:</h3>
<MVCheckBox checked={fileint.spinSysIncludeMS} onCheck={(v) => { fileint.spinSysIncludeMS = v; }}>MS tensors</MVCheckBox>
<MVCheckBox checked={fileint.spinSysIncludeEFG} onCheck={(v) => { fileint.spinSysIncludeEFG = v; }}>EFG tensors</MVCheckBox>
{/* <MVCheckBox checked={fileint.spinSysIncludeJ} onCheck={(v) => { fileint.spinSysIncludeJ = v; }}>J couplings</MVCheckBox> */}
<MVCheckBox checked={fileint.spinSysIncludeD} onCheck={(v) => { fileint.spinSysIncludeD = v; }}>Dipolar couplings</MVCheckBox>
<h3>Options:</h3>
<MVCheckBox checked={fileint.includeMS} onCheck={(v) => { fileint.includeMS = v; }}>MS tensors</MVCheckBox>
<MVCheckBox checked={fileint.includeEFG} onCheck={(v) => { fileint.includeEFG = v; }}>EFG tensors</MVCheckBox>
{/* <MVCheckBox checked={fileint.includeJ} onCheck={(v) => { fileint.includeJ = v; }}>J couplings</MVCheckBox> */}
<MVCheckBox checked={fileint.includeD} onCheck={(v) => { fileint.includeD = v; }}>Dipolar couplings</MVCheckBox>
{/* if EFG is selected, show quadrupole selector */}
{fileint.spinSysIncludeEFG ? selectquadorder(fileint) : null}
{mergeOption(fileint)}

</div>);
}


function msTableOptions(fileint) {
return (<div className='.mv-sidebar-grid'>
<h3>Options:</h3>
{/* <MVCheckBox checked={fileint.includeMS} onCheck={(v) => { fileint.includeMS = v; }}>MS tensors</MVCheckBox> */}
{eulerOption(fileint)}
{mergeOption(fileint)}
{setPrecision(fileint)}
</div>);

}

function efgTableOptions(fileint) {
return (<div className='.mv-sidebar-grid'>
<h3>Options:</h3>
{/* <MVCheckBox checked={fileint.includeEFG} onCheck={(v) => { fileint.includeEFG = v; }}>EFG tensors</MVCheckBox> */}
{eulerOption(fileint)}
{/* <MVCheckBox checked={fileint.includeQuadrupole} onCheck={(v) => { fileint.includeQuadrupole = v; }}>Quadrupole moments</MVCheckBox> */}
{mergeOption(fileint)}
{setPrecision(fileint)}
</div>);
}

// eslint-disable-next-line
function dipTableOptions(fileint) {
return (<div className='.mv-sidebar-grid'>
<h3>Options:</h3>
{/* <MVCheckBox checked={fileint.includeD} onCheck={(v) => { fileint.includeD = v; }}>Dipolar couplings</MVCheckBox> */}
{eulerOption(fileint)}
{mergeOption(fileint)}
{setPrecision(fileint)}
</div>);
}
// eslint-disable-next-line
function iscTableOptions(fileint) {
return (<div className='.mv-sidebar-grid'>
<h3>Options:</h3>
{/* <MVCheckBox checked={fileint.includeJ} onCheck={(v) => { fileint.includeJ = v; }}>J couplings</MVCheckBox> */}
{eulerOption(fileint)}
{mergeOption(fileint)}
{setPrecision(fileint)}
</div>);
}


function MVSidebarFiles(props) {

const fileint = useFilesInterface();

return (<MagresViewSidebar title='Report files' show={props.show}>
<div className='mv-sidebar-block'>
<h3>File type:</h3>
<p>
Export the chosen data for the currently selected atoms. If no atoms are selected, the whole system will be exported.
</p>
<p>
The isotopes are set in the Select and display tab.
</p>
<h3>Output:</h3>
<MVCustomSelect selected={fileint.fileType} onSelect={(v) => { fileint.fileType = v; }}>
<MVCustomSelectOption value='ms' icon={<MVIcon icon='ms' color='var(--ms-color-3)' />}>MS table</MVCustomSelectOption>
<MVCustomSelectOption value='efg' icon={<MVIcon icon='efg' color='var(--efg-color-3)' />}>EFG table</MVCustomSelectOption>
<MVCustomSelectOption value='dip' icon={<MVIcon icon='dip' color='var(--dip-color-3)' />}>Dipolar coupling table</MVCustomSelectOption>
<MVCustomSelectOption value='isc' icon={<MVIcon icon='jcoup' color='var(--jcoup-color-3)' />}>J coupling table</MVCustomSelectOption>
<MVCustomSelectOption value='spinsys' icon={<GiSpinningTop style={{color: 'var(--spinsys-color-3)'}}/>}>SpinSys</MVCustomSelectOption>
<MVCustomSelectOption value='ms' icon={<MVIcon icon='ms' color='var(--ms-color-3)' />}>MS</MVCustomSelectOption>
<MVCustomSelectOption value='efg' icon={<MVIcon icon='efg' color='var(--efg-color-3)' />}>EFG</MVCustomSelectOption>
<MVCustomSelectOption value='dip' icon={<MVIcon icon='dip' color='var(--dip-color-3)' />}>Dipolar coupling</MVCustomSelectOption>
<MVCustomSelectOption value='isc' icon={<MVIcon icon='jcoup' color='var(--jcoup-color-3)' />}>J coupling</MVCustomSelectOption>
{/* <MVCustomSelectOption value='spinsys' icon={<GiSpinningTop style={{color: 'var(--spinsys-color-3)'}}/>}>SpinSys</MVCustomSelectOption> */}
</MVCustomSelect>
{/* check-boxes for what to include in spinsys output. Only show if fileint.fileType === 'spinsys' */}
{fileint.fileType === 'spinsys' ? spinSysOptions(fileint) : null}
{fileint.fileType === 'ms' ? msTableOptions(fileint) : null}
{fileint.fileType === 'efg' ? efgTableOptions(fileint) : null}
{fileint.fileType === 'dip' ? dipTableOptions(fileint) : null}
{fileint.fileType === 'isc' ? iscTableOptions(fileint) : null}
{/* {fileint.fileType === 'spinsys' ? spinSysOptions(fileint) : null} */}
{/* file type options */}
{selectFileFormat(fileint)}
<MVButton onClick={() => { saveFile(fileint.generateFile(), fileint.fileName); }} disabled={!fileint.fileValid}>Save file</MVButton>
</div>
</MagresViewSidebar>);
Expand Down
26 changes: 25 additions & 1 deletion src/core/sidebars/tooltip_messages.js
Expand Up @@ -90,7 +90,31 @@ export const tooltip_plots_shifts = <div>

export const tooltip_plots_elements = <div>
<p>
Choose which speicies to plot from the set of <i> currently selected </i> elements. <br />
Choose which species to plot from the set of <i> currently selected </i> elements. <br />
To change the selection, use the <b>Select and display</b> tab. <br />
</p>
</div>


// --- Report files sidebar ---
export const tooltip_files_merge = <div>
<p>
If checked, sites with the same crystallographic label will
be merged into one entry in the output file.
</p>
{/* <p>
If no crystallographic labels were present in the loaded file,
then they will have been generated automatically based on the site index,
so this option won't do anything.
</p> */}
<p>
The multiplicity of each label is given in the output file.
Note: This checks for multiplicity within the current selection only.
</p>
</div>

export const tooltip_files_precision = <div>
<p>
The number of decimal places to use in the output file.
</p>
</div>

0 comments on commit 11d04d1

Please sign in to comment.