/** Validate unnamed group of type NXsample. */
  private void validateGroup_entry_NXsample(final NXsample group) throws NexusValidationException {
    // validate that the group is not null
    validateGroupNotNull(null, NXsample.class, group);
    clearLocalGroupDimensionPlaceholderValues();

    // validate field 'name' of unknown type.
    final IDataset name = group.getName();
    validateFieldNotNull("name", name);

    // validate field 'nature' of type NX_CHAR. Note: field not defined in base class.
    final IDataset nature = group.getDataset("nature");
    validateFieldNotNull("nature", nature);
    validateFieldType("nature", nature, NX_CHAR);
    validateFieldEnumeration("nature", nature, "powder", "liquid", "single crystal");
  }
  /** Validate group 'sample' of type NXsample. */
  private void validateGroup_NXentry_sample(final NXsample group) throws NexusValidationException {
    // validate that the group is not null
    validateGroupNotNull("sample", NXsample.class, group);
    clearLocalGroupDimensionPlaceholderValues();

    // validate field 'name' of unknown type.
    final IDataset name = group.getName();
    validateFieldNotNull("name", name);

    // validate field 'aequatorial_angle' of type NX_FLOAT. Note: field not defined in base class.
    final IDataset aequatorial_angle = group.getDataset("aequatorial_angle");
    validateFieldNotNull("aequatorial_angle", aequatorial_angle);
    validateFieldType("aequatorial_angle", aequatorial_angle, NX_FLOAT);
    validateFieldUnits("aequatorial_angle", aequatorial_angle, NX_ANGLE);
  }
Beispiel #3
0
  /** Validate unnamed group of type NXsample. */
  private void validateGroup_NXentry_NXsample(final NXsample group)
      throws NexusValidationException {
    // validate that the group is not null
    validateGroupNotNull(null, NXsample.class, group);
    clearLocalGroupDimensionPlaceholderValues();

    // validate field 'rotation_angle' of type NX_NUMBER.
    final IDataset rotation_angle = group.getRotation_angle();
    validateFieldNotNull("rotation_angle", rotation_angle);
    validateFieldType("rotation_angle", rotation_angle, NX_NUMBER);
    validateFieldUnits("rotation_angle", rotation_angle, NX_ANGLE);

    // validate field 'seblock' of type NX_CHAR. Note: field not defined in base class.
    final IDataset seblock = group.getDataset("seblock");
    validateFieldNotNull("seblock", seblock);
    validateFieldType("seblock", seblock, NX_CHAR);

    // validate field 'temperature' of type NX_NUMBER.
    final IDataset temperature = group.getTemperature();
    validateFieldNotNull("temperature", temperature);
    validateFieldType("temperature", temperature, NX_NUMBER);
    validateFieldUnits("temperature", temperature, NX_TEMPERATURE);
    validateFieldDimensions("temperature", temperature, "NXsample", "n_Temp");
  }
  @Test
  public void testWriteNX() {

    String filename = "/tmp/sample.nxs";
    NexusFileBuilder builder = new DefaultNexusFileBuilder(filename);
    NXsample nxample = sample.getNXsample(builder);

    int nCompo = sample.getPhases().size();

    assertEquals("NX name incorrect", sample.getName(), nxample.getNameScalar());
    assertEquals(
        "NX description incorrect",
        sample.getName() + ", " + sample.getComposition() + ", " + sample.getShapeName(),
        nxample.getDescriptionScalar());
    assertEquals(
        "NX component names incorrect",
        DatasetFactory.createFromList(
            sample.getPhases().stream().map(a -> a.getName()).collect(Collectors.toList())),
        nxample.getComponent());
    assertEquals(
        "NX component formulae incorrect",
        DatasetFactory.createFromObject(
            sample
                .getPhases()
                .stream()
                .map(a -> a.getComposition().getHallNotation(false))
                .collect(Collectors.toList()),
            nCompo,
            1),
        nxample.getChemical_formula());
    assertEquals(
        "NX formula weight incorrect",
        DatasetFactory.createFromList(
            sample
                .getPhases()
                .stream()
                .map(a -> a.getComposition().getFormulaMass())
                .collect(Collectors.toList())),
        nxample.getDataset("chemical_formula_weight"));
    // unit cell parameters...
    assertEquals(
        "NX unit cell volume incorrect",
        DatasetFactory.createFromList(
            sample
                .getPhases()
                .stream()
                .map(a -> a.getUnitCellVolume())
                .collect(Collectors.toList())),
        nxample.getUnit_cell_volume());
    assertEquals(
        "NX unit cell class incorrect",
        DatasetFactory.createFromList(
            sample
                .getPhases()
                .stream()
                .map(a -> a.getCrystalSystem().getName())
                .collect(Collectors.toList())),
        nxample.getUnit_cell_class());
    assertEquals(
        "NX unit cell space group incorrect",
        DatasetFactory.createFromList(
            sample
                .getPhases()
                .stream()
                .map(a -> a.getSpaceGroup().getNumber() + ": " + a.getSpaceGroup().getName())
                .collect(Collectors.toList())),
        nxample.getUnit_cell_group());
    assertEquals(
        "NX theoretical densities incorrect",
        DatasetFactory.createFromList(
            sample.getPhases().stream().map(a -> a.getDensity()).collect(Collectors.toList())),
        nxample.getDataset("theoretical_density"));
  }