File: fprime.cpp

package info (click to toggle)
gemmi 0.6.5%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 5,836 kB
  • sloc: cpp: 54,719; python: 4,743; ansic: 3,972; sh: 384; makefile: 73; f90: 42; javascript: 12
file content (65 lines) | stat: -rw-r--r-- 2,257 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright 2019 Global Phasing Ltd.

#include "gemmi/elem.hpp"    // for Element, find_element
#include "gemmi/fprime.hpp"  // for cromer_liberman_for_array
#include "gemmi/math.hpp"    // for hc
#include <cstdlib>           // for atof
#include <stdio.h>

#define GEMMI_PROG fprime
#include "options.h"

namespace {

enum OptionIndex { Energy=4, Wavelen };

const option::Descriptor Usage[] = {
  { NoOp, 0, "", "", Arg::None,
    "Usage:\n " EXE_NAME " [options] ELEMENT[...]"
    "\nPrints anomalous scattering factors f' and f\"."
    "\n\nOptions:" },
  CommonUsage[Help],
  CommonUsage[Version],
  //CommonUsage[Verbose],
  { Energy, 0, "e", "energy", Arg::Float,
    "  -e, --energy=ENERGY  \tEnergy [eV]" },
  { Wavelen, 0, "w", "wavelength", Arg::Float,
    "  -w, --wavelength=LAMBDA  \tWavelength [A]" },
  { 0, 0, 0, 0, 0, 0 }
};

} // anonymous namespace

int GEMMI_MAIN(int argc, char **argv) {
  OptParser p(EXE_NAME);
  p.simple_parse(argc, argv, Usage);
  if (!p.options[Energy] && !p.options[Wavelen]) {
    fprintf(stderr, "Neither energy nor wavelength was specified.\n");
    return -1;
  }
  for (int i = 0; i < p.nonOptionsCount(); ++i) {
    const char* name = p.nonOption(i);
    gemmi::Element elem = gemmi::find_element(name);
    if (elem == gemmi::El::X) {
      fprintf(stderr, "Error: element name not recognized: '%s'\n", name);
      return -1;
    }
    std::vector<double> energies;
    for (const option::Option* opt = p.options[Energy]; opt; opt = opt->next())
      energies.push_back(std::atof(opt->arg));
    double hc = gemmi::hc();
    for (const option::Option* opt = p.options[Wavelen]; opt; opt = opt->next())
      energies.push_back(hc / std::atof(opt->arg));
    std::vector<double> fp(energies.size(), 0);
    std::vector<double> fpp(energies.size(), 0);
    printf("Element\t E[eV]\tWavelength[A]\t   f'   \t  f\"\n");
    gemmi::cromer_liberman_for_array(elem.atomic_number(),
                                     (int) energies.size(), energies.data(),
                                     &fp[0], &fpp[0]);
    for (size_t j = 0; j != energies.size(); ++j) {
      printf("%s\t%#g\t% -8g\t%8.5g\t%.5g\n",
             elem.name(), energies[j], hc / energies[j], fp[j], fpp[j]);
    }
  }
  return 0;
}