Xmipp  v3.23.11-Nereus
Namespaces | Classes | Enumerations | Functions | Variables
cif Namespace Reference

Namespaces

 data
 
 detail
 
 mm
 
 pdb
 

Classes

class  category_index
 
class  CCD_compound_factory_impl
 
class  CCP4_compound_factory_impl
 
struct  compound_atom_less
 
struct  compound_bond_less
 
class  compound_factory_impl
 
class  dictionary_parser
 
class  IdentityMatrix
 
class  Matrix
 
class  MatrixExpression
 
class  MatrixMultiplication
 
class  MatrixSubtraction
 
struct  my_from_chars
 
struct  ProgressImpl
 
struct  regex_impl
 
class  ResourcePool
 
class  row_comparator
 
class  save_value
 
struct  std_from_chars
 
class  SymmetricMatrix
 
struct  tls_residue
 
struct  tls_selection_all
 
struct  tls_selection_by_element
 
struct  tls_selection_by_name
 
struct  tls_selection_chain
 
struct  tls_selection_intersection
 
struct  tls_selection_not
 
class  tls_selection_parser_impl
 
struct  tls_selection_range_id
 
struct  tls_selection_range_seq
 
struct  tls_selection_res_id
 
struct  tls_selection_union
 
class  TLSSelectionParser
 
class  TLSSelectionParserBase
 
class  TLSSelectionParserImplBuster
 
class  TLSSelectionParserImplBusterOld
 
class  TLSSelectionParserImplPhenix
 

Enumerations

enum  LineBreakClass {
  kLBC_OpenPunctuation, kLBC_ClosePunctuation, kLBC_CloseParenthesis, kLBC_Quotation,
  kLBC_NonBreaking, kLBC_Nonstarter, kLBC_Exlamation, kLBC_SymbolAllowingBreakAfter,
  kLBC_InfixNumericSeparator, kLBC_PrefixNumeric, kLBC_PostfixNumeric, kLBC_Numeric,
  kLBC_Alphabetic, kLBC_Ideographic, kLBC_Inseperable, kLBC_Hyphen,
  kLBC_BreakAfter, kLBC_BreakBefor, kLBC_BreakOpportunityBeforeAndAfter, kLBC_ZeroWidthSpace,
  kLBC_CombiningMark, kLBC_WordJoiner, kLBC_HangulLVSyllable, kLBC_HangulLVTSyllable,
  kLBC_HangulLJamo, kLBC_HangulVJamo, kLBC_HangulTJamo, kLBC_MandatoryBreak,
  kLBC_CarriageReturn, kLBC_LineFeed, kLBC_NextLine, kLBC_Surrogate,
  kLBC_Space, kLBC_ContigentBreakOpportunity, kLBC_Ambiguous, kLBC_ComplexContext,
  kLBC_Unknown
}
 

Functions

std::string to_string (bond_type bondType)
 
bond_type from_string (const std::string &bondType)
 
iset get_category_fields (const category &cat)
 
uint16_t get_column_ix (const category &cat, std::string_view col)
 
bool is_column_type_uchar (const category &cat, std::string_view col)
 
validator parse_dictionary (std::string_view name, std::istream &is)
 
void dump_selection (const std::vector< tls_residue > &selected, size_t indentLevel)
 
std::unique_ptr< tls_selection > parse_tls_selection_details (const std::string &program, const std::string &selection)
 
template<typename M1 , typename M2 >
MatrixSubtraction< M1, M2operator- (const MatrixExpression< M1 > &m1, const MatrixExpression< M2 > &m2)
 
template<typename M >
MatrixMultiplication< M > operator* (const MatrixExpression< M > &m, double v)
 
template<class M1 >
Matrix Cofactors (const M1 &m)
 
template<typename T >
quaternion_type< T > normalize (quaternion_type< T > q)
 
quaternion construct_from_angle_axis (float angle, point axis)
 
std::tuple< double, pointquaternion_to_angle_axis (quaternion q)
 
point center_points (std::vector< point > &Points)
 
quaternion construct_for_dihedral_angle (point p1, point p2, point p3, point p4, float angle, float esd)
 
point centroid (const std::vector< point > &pts)
 
double RMSd (const std::vector< point > &a, const std::vector< point > &b)
 
double LargestDepressedQuarticSolution (double a, double b, double c)
 
quaternion align_points (const std::vector< point > &pa, const std::vector< point > &pb)
 
point nudge (point p, float offset)
 
int get_space_group_number (std::string spacegroup)
 
int get_space_group_number (std::string spacegroup, space_group_name type)
 
bool iequals (std::string_view a, std::string_view b)
 
bool iequals (const char *a, const char *b)
 
int icompare (std::string_view a, std::string_view b)
 
int icompare (const char *a, const char *b)
 
void to_lower (std::string &s)
 
std::string to_lower_copy (std::string_view s)
 
void to_upper (std::string &s)
 
void replace_all (std::string &s, std::string_view what, std::string_view with)
 
bool icontains (std::string_view s, std::string_view q)
 
void trim_right (std::string &s)
 
std::string trim_right_copy (std::string_view s)
 
std::string trim_left_copy (std::string_view s)
 
void trim_left (std::string &s)
 
void trim (std::string &s)
 
std::string trim_copy (std::string_view s)
 
std::tuple< std::string, std::string > split_tag_name (std::string_view tag)
 
std::string cif_id_for_number (int number)
 
std::string::const_iterator nextLineBreak (std::string::const_iterator text, std::string::const_iterator end)
 
std::vector< std::string > wrapLine (const std::string &text, size_t width)
 
std::vector< std::string > word_wrap (const std::string &text, size_t width)
 
std::string get_version_nr ()
 
uint32_t get_terminal_width ()
 
std::string get_executable_path ()
 
void add_data_directory (std::filesystem::path dataDir)
 
void add_file_resource (const std::string &name, std::filesystem::path dataFile)
 
std::unique_ptr< std::istream > load_resource (std::filesystem::path name)
 
DDL_PrimitiveType map_to_primitive_type (std::string_view s)
 

Variables

const uint32_t kMaxLineLength = 132
 
row_handle s_null_row_handle
 
const int kResidueNrWildcard = std::numeric_limits<int>::min()
 
const int kNoSeqNum = std::numeric_limits<int>::max() - 1
 
const uint8_t kCharToLowerMap [256]
 
const LineBreakClass kASCII_LBTable [128]
 
int VERBOSE = 0
 

Enumeration Type Documentation

◆ LineBreakClass

Enumerator
kLBC_OpenPunctuation 
kLBC_ClosePunctuation 
kLBC_CloseParenthesis 
kLBC_Quotation 
kLBC_NonBreaking 
kLBC_Nonstarter 
kLBC_Exlamation 
kLBC_SymbolAllowingBreakAfter 
kLBC_InfixNumericSeparator 
kLBC_PrefixNumeric 
kLBC_PostfixNumeric 
kLBC_Numeric 
kLBC_Alphabetic 
kLBC_Ideographic 
kLBC_Inseperable 
kLBC_Hyphen 
kLBC_BreakAfter 
kLBC_BreakBefor 
kLBC_BreakOpportunityBeforeAndAfter 
kLBC_ZeroWidthSpace 
kLBC_CombiningMark 
kLBC_WordJoiner 
kLBC_HangulLVSyllable 
kLBC_HangulLVTSyllable 
kLBC_HangulLJamo 
kLBC_HangulVJamo 
kLBC_HangulTJamo 
kLBC_MandatoryBreak 
kLBC_CarriageReturn 
kLBC_LineFeed 
kLBC_NextLine 
kLBC_Surrogate 
kLBC_Space 
kLBC_ContigentBreakOpportunity 
kLBC_Ambiguous 
kLBC_ComplexContext 
kLBC_Unknown 

Definition at line 268 of file text.cpp.

269 {
281  kLBC_Numeric,
285  kLBC_Hyphen,
297 
303  kLBC_Space,
308 };

Function Documentation

◆ add_data_directory()

void cif::add_data_directory ( std::filesystem::path  dataDir)

Definition at line 933 of file utilities.cpp.

934 {
935  ResourcePool::instance().pushDir(dataDir);
936 }

◆ add_file_resource()

void cif::add_file_resource ( const std::string &  name,
std::filesystem::path  dataFile 
)

Definition at line 938 of file utilities.cpp.

939 {
940  ResourcePool::instance().pushAlias(name, dataFile);
941 }

◆ align_points()

quaternion cif::align_points ( const std::vector< point > &  pa,
const std::vector< point > &  pb 
)

Definition at line 467 of file point.cpp.

468 {
469  // First calculate M, a 3x3 Matrix containing the sums of products of the coordinates of A and B
470  Matrix M(3, 3, 0);
471 
472  for (uint32_t i = 0; i < pa.size(); ++i)
473  {
474  const point &a = pa[i];
475  const point &b = pb[i];
476 
477  M(0, 0) += a.m_x * b.m_x;
478  M(0, 1) += a.m_x * b.m_y;
479  M(0, 2) += a.m_x * b.m_z;
480  M(1, 0) += a.m_y * b.m_x;
481  M(1, 1) += a.m_y * b.m_y;
482  M(1, 2) += a.m_y * b.m_z;
483  M(2, 0) += a.m_z * b.m_x;
484  M(2, 1) += a.m_z * b.m_y;
485  M(2, 2) += a.m_z * b.m_z;
486  }
487 
488  // Now calculate N, a symmetric 4x4 Matrix
489  SymmetricMatrix N(4);
490 
491  N(0, 0) = M(0, 0) + M(1, 1) + M(2, 2);
492  N(0, 1) = M(1, 2) - M(2, 1);
493  N(0, 2) = M(2, 0) - M(0, 2);
494  N(0, 3) = M(0, 1) - M(1, 0);
495 
496  N(1, 1) = M(0, 0) - M(1, 1) - M(2, 2);
497  N(1, 2) = M(0, 1) + M(1, 0);
498  N(1, 3) = M(0, 2) + M(2, 0);
499 
500  N(2, 2) = -M(0, 0) + M(1, 1) - M(2, 2);
501  N(2, 3) = M(1, 2) + M(2, 1);
502 
503  N(3, 3) = -M(0, 0) - M(1, 1) + M(2, 2);
504 
505  // det(N - λI) = 0
506  // find the largest λ (λm)
507  //
508  // Aλ4 + Bλ3 + Cλ2 + Dλ + E = 0
509  // A = 1
510  // B = 0
511  // and so this is a so-called depressed quartic
512  // solve it using Ferrari's algorithm
513 
514  double C = -2 * (M(0, 0) * M(0, 0) + M(0, 1) * M(0, 1) + M(0, 2) * M(0, 2) +
515  M(1, 0) * M(1, 0) + M(1, 1) * M(1, 1) + M(1, 2) * M(1, 2) +
516  M(2, 0) * M(2, 0) + M(2, 1) * M(2, 1) + M(2, 2) * M(2, 2));
517 
518  double D = 8 * (M(0, 0) * M(1, 2) * M(2, 1) +
519  M(1, 1) * M(2, 0) * M(0, 2) +
520  M(2, 2) * M(0, 1) * M(1, 0)) -
521  8 * (M(0, 0) * M(1, 1) * M(2, 2) +
522  M(1, 2) * M(2, 0) * M(0, 1) +
523  M(2, 1) * M(1, 0) * M(0, 2));
524 
525  // E is the determinant of N:
526  double E =
527  (N(0, 0) * N(1, 1) - N(0, 1) * N(0, 1)) * (N(2, 2) * N(3, 3) - N(2, 3) * N(2, 3)) +
528  (N(0, 1) * N(0, 2) - N(0, 0) * N(2, 1)) * (N(2, 1) * N(3, 3) - N(2, 3) * N(1, 3)) +
529  (N(0, 0) * N(1, 3) - N(0, 1) * N(0, 3)) * (N(2, 1) * N(2, 3) - N(2, 2) * N(1, 3)) +
530  (N(0, 1) * N(2, 1) - N(1, 1) * N(0, 2)) * (N(0, 2) * N(3, 3) - N(2, 3) * N(0, 3)) +
531  (N(1, 1) * N(0, 3) - N(0, 1) * N(1, 3)) * (N(0, 2) * N(2, 3) - N(2, 2) * N(0, 3)) +
532  (N(0, 2) * N(1, 3) - N(2, 1) * N(0, 3)) * (N(0, 2) * N(1, 3) - N(2, 1) * N(0, 3));
533 
534  // solve quartic
535  double lambda = LargestDepressedQuarticSolution(C, D, E);
536 
537  // calculate t = (N - λI)
538  Matrix t = N - IdentityMatrix(4) * lambda;
539 
540  // calculate a Matrix of cofactors for t
541  Matrix cf = Cofactors(t);
542 
543  int maxR = 0;
544  for (int r = 1; r < 4; ++r)
545  {
546  if (std::abs(cf(r, 0)) > std::abs(cf(maxR, 0)))
547  maxR = r;
548  }
549 
550  quaternion q(
551  static_cast<float>(cf(maxR, 0)),
552  static_cast<float>(cf(maxR, 1)),
553  static_cast<float>(cf(maxR, 2)),
554  static_cast<float>(cf(maxR, 3)));
555  q = normalize(q);
556 
557  return q;
558 }
Matrix Cofactors(const M1 &m)
Definition: point.cpp:240
void abs(Image< double > &op)
#define i
doublereal * b
double * lambda
quaternion_type< T > normalize(quaternion_type< T > q)
Definition: point.cpp:278
Definition: Matrix.h:38
double LargestDepressedQuarticSolution(double a, double b, double c)
Definition: point.cpp:437
doublereal * a

◆ center_points()

point cif::center_points ( std::vector< point > &  Points)

Definition at line 334 of file point.cpp.

335 {
336  point t;
337 
338  for (point &pt : Points)
339  {
340  t.m_x += pt.m_x;
341  t.m_y += pt.m_y;
342  t.m_z += pt.m_z;
343  }
344 
345  t.m_x /= Points.size();
346  t.m_y /= Points.size();
347  t.m_z /= Points.size();
348 
349  for (point &pt : Points)
350  {
351  pt.m_x -= t.m_x;
352  pt.m_y -= t.m_y;
353  pt.m_z -= t.m_z;
354  }
355 
356  return t;
357 }

◆ centroid()

point cif::centroid ( const std::vector< point > &  pts)

Definition at line 397 of file point.cpp.

398 {
399  point result;
400 
401  for (auto &pt : pts)
402  result += pt;
403 
404  result /= static_cast<float>(pts.size());
405 
406  return result;
407 }

◆ cif_id_for_number()

std::string cif::cif_id_for_number ( int  number)

Definition at line 235 of file text.cpp.

236 {
237  std::string result;
238 
239  if (number >= 26 * 26 * 26)
240  result = 'L' + std::to_string(number);
241  else
242  {
243  if (number >= 26 * 26)
244  {
245  int v = number / (26 * 26);
246  result += char('A' - 1 + v);
247  number %= (26 * 26);
248  }
249 
250  if (number >= 26)
251  {
252  int v = number / 26;
253  result += char('A' - 1 + v);
254  number %= 26;
255  }
256 
257  result += char('A' + number);
258  }
259 
260  assert(not result.empty());
261  return result;
262 }
std::string to_string(bond_type bondType)
Definition: compound.cpp:43

◆ Cofactors()

template<class M1 >
Matrix cif::Cofactors ( const M1 m)

Definition at line 240 of file point.cpp.

241 {
242  Matrix cf(m.dim_m(), m.dim_m());
243 
244  const size_t ixs[4][3] = {
245  { 1, 2, 3 },
246  { 0, 2, 3 },
247  { 0, 1, 3 },
248  { 0, 1, 2 }
249  };
250 
251  for (size_t x = 0; x < 4; ++x)
252  {
253  const size_t *ix = ixs[x];
254 
255  for (size_t y = 0; y < 4; ++y)
256  {
257  const size_t *iy = ixs[y];
258 
259  cf(x, y) =
260  m(ix[0], iy[0]) * m(ix[1], iy[1]) * m(ix[2], iy[2]) +
261  m(ix[0], iy[1]) * m(ix[1], iy[2]) * m(ix[2], iy[0]) +
262  m(ix[0], iy[2]) * m(ix[1], iy[0]) * m(ix[2], iy[1]) -
263  m(ix[0], iy[2]) * m(ix[1], iy[1]) * m(ix[2], iy[0]) -
264  m(ix[0], iy[1]) * m(ix[1], iy[0]) * m(ix[2], iy[2]) -
265  m(ix[0], iy[0]) * m(ix[1], iy[2]) * m(ix[2], iy[1]);
266 
267  if ((x + y) % 2 == 1)
268  cf(x, y) *= -1;
269  }
270  }
271 
272  return cf;
273 }
static double * y
doublereal * x
Definition: Matrix.h:38
int m

◆ construct_for_dihedral_angle()

quaternion cif::construct_for_dihedral_angle ( point  p1,
point  p2,
point  p3,
point  p4,
float  angle,
float  esd 
)

Definition at line 359 of file point.cpp.

361 {
362  p1 -= p3;
363  p2 -= p3;
364  p4 -= p3;
365  p3 -= p3;
366 
367  quaternion q;
368  auto axis = p2;
369 
370  float dh = dihedral_angle(p1, p2, p3, p4);
371  for (int iteration = 0; iteration < 100; ++iteration)
372  {
373  float delta = std::fmod(angle - dh, 360.0f);
374 
375  if (delta < -180)
376  delta += 360;
377  if (delta > 180)
378  delta -= 360;
379 
380  if (std::abs(delta) < esd)
381  break;
382 
383  // if (iteration > 0)
384  // std::cout << cif::coloured(("iteration " + std::to_string(iteration)).c_str(), cif::scBLUE, cif::scBLACK) << " delta: " << delta << std::endl;
385 
386  auto q2 = construct_from_angle_axis(delta, axis);
387  q = iteration == 0 ? q2 : q * q2;
388 
389  p4.rotate(q2);
390 
391  dh = dihedral_angle(p1, p2, p3, p4);
392  }
393 
394  return q;
395 }
n The following was calculated during iteration
void abs(Image< double > &op)
char axis
double * f
quaternion construct_from_angle_axis(float angle, point axis)
Definition: point.cpp:301
#define q2
double * delta

◆ construct_from_angle_axis()

quaternion cif::construct_from_angle_axis ( float  angle,
point  axis 
)

Definition at line 301 of file point.cpp.

302 {
303  auto q = std::cos((angle * kPI / 180) / 2);
304  auto s = std::sqrt(1 - q * q);
305 
306  axis.normalize();
307 
308  return normalize(quaternion{
309  static_cast<float>(q),
310  static_cast<float>(s * axis.m_x),
311  static_cast<float>(s * axis.m_y),
312  static_cast<float>(s * axis.m_z) });
313 }
void sqrt(Image< double > &op)
quaternion_type< T > normalize(quaternion_type< T > q)
Definition: point.cpp:278

◆ dump_selection()

void cif::dump_selection ( const std::vector< tls_residue > &  selected,
size_t  indentLevel 
)

Definition at line 69 of file tls.cpp.

70 {
71  std::string indent(indentLevel * 2, ' ');
72 
73  auto i = selected.begin();
74  bool first = true;
75 
76  // First print in PDB space
77  while (i != selected.end())
78  {
79  auto b = find_if(i, selected.end(), [](auto s) -> bool
80  { return s.selected; });
81  if (b == selected.end())
82  break;
83 
84  if (first)
85  std::cout << indent << "PDB:" << std::endl;
86  first = false;
87 
88  auto e = find_if(b, selected.end(), [b](auto s) -> bool
89  { return s.chainID != b->chainID or not s.selected; });
90 
91  std::cout << indent << " >> " << b->chainID << ' ' << b->seqNr << ':' << (e - 1)->seqNr << std::endl;
92  i = e;
93  }
94 
95  // Then in mmCIF space
96 
97  if (not first)
98  std::cout << indent << "mmCIF:" << std::endl;
99 
100  i = selected.begin();
101  while (i != selected.end())
102  {
103  auto b = find_if(i, selected.end(), [](auto s) -> bool
104  { return s.selected; });
105  if (b == selected.end())
106  break;
107 
108  auto e = find_if(b, selected.end(), [b](auto s) -> bool
109  { return s.asymID != b->asymID or not s.selected; });
110 
111  std::string asymID = b->asymID;
112  int from = b->seqID, to = from;
113 
114  for (auto j = b + 1; j != e; ++j)
115  {
116  if (j->seqID == to + 1)
117  to = j->seqID;
118  else if (j->seqID != to) // probably an insertion code
119  {
120  if (from == kNoSeqNum or to == kNoSeqNum)
121  std::cout << indent << " >> " << asymID << std::endl;
122  else
123  std::cout << indent << " >> " << asymID << ' ' << from << ':' << to << std::endl;
124  asymID = b->asymID;
125  from = to = b->seqID;
126  }
127  }
128 
129  if (from == kNoSeqNum or to == kNoSeqNum)
130  std::cout << indent << " >> " << asymID << std::endl;
131  else
132  std::cout << indent << " >> " << asymID << ' ' << from << ':' << to << std::endl;
133 
134  i = e;
135  }
136 
137  if (first)
138  {
139  if (isatty(STDOUT_FILENO))
140  std::cout << indent << cif::coloured("Empty selection") << std::endl;
141  else
142  std::cout << indent << "Empty selection" << std::endl;
143  }
144 }
const int kNoSeqNum
Definition: tls.cpp:41
#define i
glob_log first
doublereal * b
#define j

◆ from_string()

bond_type cif::from_string ( const std::string &  bondType)

Definition at line 59 of file compound.cpp.

60 {
61  if (cif::iequals(bondType, "sing"))
62  return bond_type::sing;
63  if (cif::iequals(bondType, "doub"))
64  return bond_type::doub;
65  if (cif::iequals(bondType, "trip"))
66  return bond_type::trip;
67  if (cif::iequals(bondType, "quad"))
68  return bond_type::quad;
69  if (cif::iequals(bondType, "arom"))
70  return bond_type::arom;
71  if (cif::iequals(bondType, "poly"))
72  return bond_type::poly;
73  if (cif::iequals(bondType, "delo"))
74  return bond_type::delo;
75  if (cif::iequals(bondType, "pi"))
76  return bond_type::pi;
77  throw std::invalid_argument("Invalid bondType: " + bondType);
78 }
bool iequals(std::string_view a, std::string_view b)
Definition: text.cpp:59
#define pi

◆ get_category_fields()

iset cif::get_category_fields ( const category &  cat)

Definition at line 34 of file condition.cpp.

35 {
36  return cat.key_fields();
37 }

◆ get_column_ix()

uint16_t cif::get_column_ix ( const category &  cat,
std::string_view  col 
)

Definition at line 39 of file condition.cpp.

40 {
41  return cat.get_column_ix(col);
42 }

◆ get_executable_path()

std::string cif::get_executable_path ( )

Definition at line 123 of file utilities.cpp.

124 {
125  using namespace std::literals;
126 
127  // This used to be PATH_MAX, but lets simply assume 1024 is enough...
128  char path[1024] = "";
129  if (readlink("/proc/self/exe", path, sizeof(path)) == -1)
130  throw std::runtime_error("could not get exe path "s + strerror(errno));
131  return {path};
132 }

◆ get_space_group_number() [1/2]

int cif::get_space_group_number ( std::string  spacegroup)

Definition at line 43 of file symmetry.cpp.

44 {
45  if (spacegroup == "P 21 21 2 A")
46  spacegroup = "P 21 21 2 (a)";
47  else if (spacegroup.empty())
48  throw std::runtime_error("No spacegroup, cannot continue");
49 
50  int result = 0;
51 
52  const size_t N = kNrOfSpaceGroups;
53  int32_t L = 0, R = static_cast<int32_t>(N - 1);
54  while (L <= R)
55  {
56  int32_t i = (L + R) / 2;
57 
58  int d = spacegroup.compare(kSpaceGroups[i].name);
59 
60  if (d > 0)
61  L = i + 1;
62  else if (d < 0)
63  R = i - 1;
64  else
65  {
66  result = kSpaceGroups[i].nr;
67  break;
68  }
69  }
70 
71  // not found, see if we can find a match based on xHM name
72  if (result == 0)
73  {
74  for (size_t i = 0; i < kNrOfSpaceGroups; ++i)
75  {
76  auto& sp = kSpaceGroups[i];
77  if (sp.xHM == spacegroup)
78  {
79  result = sp.nr;
80  break;
81  }
82  }
83  }
84 
85  if (result == 0)
86  throw std::runtime_error("Spacegroup name " + spacegroup + " was not found in table");
87 
88  return result;
89 }
#define i
doublereal * d

◆ get_space_group_number() [2/2]

int cif::get_space_group_number ( std::string  spacegroup,
space_group_name  type 
)

Definition at line 93 of file symmetry.cpp.

94 {
95  if (spacegroup == "P 21 21 2 A")
96  spacegroup = "P 21 21 2 (a)";
97  else if (spacegroup.empty())
98  throw std::runtime_error("No spacegroup, cannot continue");
99 
100  int result = 0;
101 
102  if (type == space_group_name::full)
103  {
104  const size_t N = kNrOfSpaceGroups;
105  int32_t L = 0, R = static_cast<int32_t>(N - 1);
106  while (L <= R)
107  {
108  int32_t i = (L + R) / 2;
109 
110  int d = spacegroup.compare(kSpaceGroups[i].name);
111 
112  if (d > 0)
113  L = i + 1;
114  else if (d < 0)
115  R = i - 1;
116  else
117  {
118  result = kSpaceGroups[i].nr;
119  break;
120  }
121  }
122  }
123  else if (type == space_group_name::xHM)
124  {
125  for (auto &sg : kSpaceGroups)
126  {
127  if (sg.xHM == spacegroup)
128  {
129  result = sg.nr;
130  break;
131  }
132  }
133  }
134  else
135  {
136  for (auto &sg : kSpaceGroups)
137  {
138  if (sg.Hall == spacegroup)
139  {
140  result = sg.nr;
141  break;
142  }
143  }
144  }
145 
146  // not found, see if we can find a match based on xHM name
147  if (result == 0)
148  throw std::runtime_error("Spacegroup name " + spacegroup + " was not found in table");
149 
150  return result;
151 }
#define i
doublereal * d
viol type

◆ get_terminal_width()

uint32_t cif::get_terminal_width ( )

Definition at line 110 of file utilities.cpp.

111 {
112  uint32_t result = 80;
113 
114  if (isatty(STDOUT_FILENO))
115  {
116  struct winsize w;
117  ioctl(0, TIOCGWINSZ, &w);
118  result = w.ws_col;
119  }
120  return result;
121 }
doublereal * w

◆ get_version_nr()

std::string cif::get_version_nr ( )

Definition at line 62 of file utilities.cpp.

63 {
64  std::ostringstream s;
65  write_version_string(s, false);
66  return s.str();
67 }

◆ icompare() [1/2]

int cif::icompare ( std::string_view  a,
std::string_view  b 
)

Definition at line 77 of file text.cpp.

78 {
79  int d = 0;
80  auto ai = a.begin(), bi = b.begin();
81 
82  for (; d == 0 and ai != a.end() and bi != b.end(); ++ai, ++bi)
83  d = tolower(*ai) - tolower(*bi);
84 
85  if (d == 0)
86  {
87  if (ai != a.end())
88  d = 1;
89  else if (bi != b.end())
90  d = -1;
91  }
92 
93  return d;
94 }
doublereal * d
doublereal * b
doublereal * a

◆ icompare() [2/2]

int cif::icompare ( const char *  a,
const char *  b 
)

Definition at line 96 of file text.cpp.

97 {
98  int d = 0;
99 
100  for (; d == 0 and *a != 0 and *b != 0; ++a, ++b)
101  d = tolower(*a) - tolower(*b);
102 
103  if (d == 0)
104  {
105  if (*a != 0)
106  d = 1;
107  else if (*b != 0)
108  d = -1;
109  }
110 
111  return d;
112 }
doublereal * d
doublereal * b
doublereal * a

◆ icontains()

bool cif::icontains ( std::string_view  s,
std::string_view  q 
)

Definition at line 143 of file text.cpp.

144 {
145  return contains(to_lower_copy(s), to_lower_copy(q));
146 }
std::string to_lower_copy(std::string_view s)
Definition: text.cpp:120

◆ iequals() [1/2]

bool cif::iequals ( std::string_view  a,
std::string_view  b 
)

Definition at line 59 of file text.cpp.

60 {
61  bool result = a.length() == b.length();
62  for (auto ai = a.begin(), bi = b.begin(); result and ai != a.end(); ++ai, ++bi)
63  result = kCharToLowerMap[uint8_t(*ai)] == kCharToLowerMap[uint8_t(*bi)];
64  // result = tolower(*ai) == tolower(*bi);
65  return result;
66 }
doublereal * b
const uint8_t kCharToLowerMap[256]
Definition: text.cpp:38
doublereal * a

◆ iequals() [2/2]

bool cif::iequals ( const char *  a,
const char *  b 
)

Definition at line 68 of file text.cpp.

69 {
70  bool result = true;
71  for (; result and *a and *b; ++a, ++b)
72  result = tolower(*a) == tolower(*b);
73 
74  return result and *a == *b;
75 }
doublereal * b
doublereal * a

◆ is_column_type_uchar()

bool cif::is_column_type_uchar ( const category &  cat,
std::string_view  col 
)

Definition at line 44 of file condition.cpp.

45 {
46  bool result = false;
47 
48  auto cv = cat.get_cat_validator();
49  if (cv)
50  {
51  auto iv = cv->get_validator_for_item(col);
52  if (iv != nullptr and iv->m_type != nullptr)
53  {
54  auto type = iv->m_type;
55  result = type->m_primitive_type == DDL_PrimitiveType::UChar;
56  }
57  }
58 
59  return result;
60 }
viol type

◆ LargestDepressedQuarticSolution()

double cif::LargestDepressedQuarticSolution ( double  a,
double  b,
double  c 
)

Definition at line 437 of file point.cpp.

438 {
439  std::complex<double> P = -(a * a) / 12 - c;
440  std::complex<double> Q = -(a * a * a) / 108 + (a * c) / 3 - (b * b) / 8;
441  std::complex<double> R = -Q / 2.0 + std::sqrt((Q * Q) / 4.0 + (P * P * P) / 27.0);
442 
443  std::complex<double> U = std::pow(R, 1 / 3.0);
444 
445  std::complex<double> y;
446  if (U == 0.0)
447  y = -5.0 * a / 6.0 + U - std::pow(Q, 1.0 / 3.0);
448  else
449  y = -5.0 * a / 6.0 + U - P / (3.0 * U);
450 
451  std::complex<double> W = std::sqrt(a + 2.0 * y);
452 
453  // And to get the final result:
454  // result = (±W + std::sqrt(-(3 * alpha + 2 * y ± 2 * beta / W))) / 2;
455  // We want the largest result, so:
456 
457  std::valarray<double> t(4);
458 
459  t[0] = ((W + std::sqrt(-(3.0 * a + 2.0 * y + 2.0 * b / W))) / 2.0).real();
460  t[1] = ((W + std::sqrt(-(3.0 * a + 2.0 * y - 2.0 * b / W))) / 2.0).real();
461  t[2] = ((-W + std::sqrt(-(3.0 * a + 2.0 * y + 2.0 * b / W))) / 2.0).real();
462  t[3] = ((-W + std::sqrt(-(3.0 * a + 2.0 * y - 2.0 * b / W))) / 2.0).real();
463 
464  return t.max();
465 }
doublereal * c
void sqrt(Image< double > &op)
static double * y
doublereal * b
doublereal * a

◆ load_resource()

std::unique_ptr<std::istream> cif::load_resource ( std::filesystem::path  name)

Definition at line 943 of file utilities.cpp.

944 {
945  return ResourcePool::instance().load(name);
946 }

◆ map_to_primitive_type()

DDL_PrimitiveType cif::map_to_primitive_type ( std::string_view  s)

Definition at line 72 of file validate.cpp.

73 {
74  DDL_PrimitiveType result;
75  if (iequals(s, "char"))
76  result = DDL_PrimitiveType::Char;
77  else if (iequals(s, "uchar"))
78  result = DDL_PrimitiveType::UChar;
79  else if (iequals(s, "numb"))
80  result = DDL_PrimitiveType::Numb;
81  else
82  throw validation_error("Not a known primitive type");
83  return result;
84 }
bool iequals(std::string_view a, std::string_view b)
Definition: text.cpp:59

◆ nextLineBreak()

std::string::const_iterator cif::nextLineBreak ( std::string::const_iterator  text,
std::string::const_iterator  end 
)

Definition at line 334 of file text.cpp.

335 {
336  if (text == end)
337  return text;
338 
339  enum breakAction
340  {
341  DBK = 0, // direct break (blank in table)
342  IBK, // indirect break (% in table)
343  PBK, // prohibited break (^ in table)
344  CIB, // combining indirect break
345  CPB // combining prohibited break
346  };
347 
348  const breakAction brkTable[27][27] = {
349  // OP CL CP QU GL NS EX SY IS PR PO NU AL ID IN HY BA BB B2 ZW CM WJ H2 H3 JL JV JT
350  /* OP */ {PBK, PBK, PBK, PBK, PBK, PBK, PBK, PBK, PBK, PBK, PBK, PBK, PBK, PBK, PBK, PBK, PBK, PBK, PBK, PBK, CPB, PBK, PBK, PBK, PBK, PBK, PBK},
351  /* CL */ {DBK, PBK, PBK, IBK, IBK, PBK, PBK, PBK, PBK, IBK, IBK, DBK, DBK, DBK, DBK, IBK, IBK, DBK, DBK, PBK, CIB, PBK, DBK, DBK, DBK, DBK, DBK},
352  /* CP */ {DBK, PBK, PBK, IBK, IBK, PBK, PBK, PBK, PBK, IBK, IBK, IBK, IBK, DBK, DBK, IBK, IBK, DBK, DBK, PBK, CIB, PBK, DBK, DBK, DBK, DBK, DBK},
353  /* QU */ {PBK, PBK, PBK, IBK, IBK, IBK, PBK, PBK, PBK, IBK, IBK, IBK, IBK, IBK, IBK, IBK, IBK, IBK, IBK, PBK, CIB, PBK, IBK, IBK, IBK, IBK, IBK},
354  /* GL */ {IBK, PBK, PBK, IBK, IBK, IBK, PBK, PBK, PBK, IBK, IBK, IBK, IBK, IBK, IBK, IBK, IBK, IBK, IBK, PBK, CIB, PBK, IBK, IBK, IBK, IBK, IBK},
355  /* NS */ {DBK, PBK, PBK, IBK, IBK, IBK, PBK, PBK, PBK, DBK, DBK, DBK, DBK, DBK, DBK, IBK, IBK, DBK, DBK, PBK, CIB, PBK, DBK, DBK, DBK, DBK, DBK},
356  /* EX */ {DBK, PBK, PBK, IBK, IBK, IBK, PBK, PBK, PBK, DBK, DBK, DBK, DBK, DBK, DBK, IBK, IBK, DBK, DBK, PBK, CIB, PBK, DBK, DBK, DBK, DBK, DBK},
357  /* SY */ {DBK, PBK, PBK, IBK, IBK, IBK, PBK, PBK, PBK, DBK, DBK, IBK, DBK, DBK, DBK, IBK, IBK, DBK, DBK, PBK, CIB, PBK, DBK, DBK, DBK, DBK, DBK},
358  /* IS */ {DBK, PBK, PBK, IBK, IBK, IBK, PBK, PBK, PBK, DBK, DBK, IBK, IBK, DBK, DBK, IBK, IBK, DBK, DBK, PBK, CIB, PBK, DBK, DBK, DBK, DBK, DBK},
359  /* PR */ {IBK, PBK, PBK, IBK, IBK, IBK, PBK, PBK, PBK, DBK, DBK, IBK, IBK, IBK, DBK, IBK, IBK, DBK, DBK, PBK, CIB, PBK, IBK, IBK, IBK, IBK, IBK},
360  /* PO */ {IBK, PBK, PBK, IBK, IBK, IBK, PBK, PBK, PBK, DBK, DBK, IBK, IBK, DBK, DBK, IBK, IBK, DBK, DBK, PBK, CIB, PBK, DBK, DBK, DBK, DBK, DBK},
361  /* NU */ {DBK, PBK, PBK, IBK, IBK, IBK, PBK, PBK, PBK, IBK, IBK, IBK, IBK, DBK, IBK, IBK, IBK, DBK, DBK, PBK, CIB, PBK, DBK, DBK, DBK, DBK, DBK},
362  /* AL */ {DBK, PBK, PBK, IBK, IBK, IBK, PBK, PBK, PBK, DBK, DBK, IBK, IBK, DBK, IBK, IBK, IBK, DBK, DBK, PBK, CIB, PBK, DBK, DBK, DBK, DBK, DBK},
363  /* ID */ {DBK, PBK, PBK, IBK, IBK, IBK, PBK, PBK, PBK, DBK, IBK, DBK, DBK, DBK, IBK, IBK, IBK, DBK, DBK, PBK, CIB, PBK, DBK, DBK, DBK, DBK, DBK},
364  /* IN */ {DBK, PBK, PBK, IBK, IBK, IBK, PBK, PBK, PBK, DBK, DBK, DBK, DBK, DBK, IBK, IBK, IBK, DBK, DBK, PBK, CIB, PBK, DBK, DBK, DBK, DBK, DBK},
365  /* HY */ {DBK, PBK, PBK, IBK, DBK, IBK, PBK, PBK, PBK, DBK, DBK, IBK, DBK, DBK, DBK, IBK, IBK, DBK, DBK, PBK, CIB, PBK, DBK, DBK, DBK, DBK, DBK},
366  /* BA */ {DBK, PBK, PBK, IBK, DBK, IBK, PBK, PBK, PBK, DBK, DBK, DBK, DBK, DBK, DBK, IBK, IBK, DBK, DBK, PBK, CIB, PBK, DBK, DBK, DBK, DBK, DBK},
367  /* BB */ {IBK, PBK, PBK, IBK, IBK, IBK, PBK, PBK, PBK, IBK, IBK, IBK, IBK, IBK, IBK, IBK, IBK, IBK, IBK, PBK, CIB, PBK, IBK, IBK, IBK, IBK, IBK},
368  /* B2 */ {DBK, PBK, PBK, IBK, IBK, IBK, PBK, PBK, PBK, DBK, DBK, DBK, DBK, DBK, DBK, IBK, IBK, DBK, PBK, PBK, CIB, PBK, DBK, DBK, DBK, DBK, DBK},
369  /* ZW */ {DBK, DBK, DBK, DBK, DBK, DBK, DBK, DBK, DBK, DBK, DBK, DBK, DBK, DBK, DBK, DBK, DBK, DBK, DBK, PBK, DBK, DBK, DBK, DBK, DBK, DBK, DBK},
370  /* CM */ {DBK, PBK, PBK, IBK, IBK, IBK, PBK, PBK, PBK, DBK, DBK, IBK, IBK, DBK, IBK, IBK, IBK, DBK, DBK, PBK, CIB, PBK, DBK, DBK, DBK, DBK, DBK},
371  /* WJ */ {IBK, PBK, PBK, IBK, IBK, IBK, PBK, PBK, PBK, IBK, IBK, IBK, IBK, IBK, IBK, IBK, IBK, IBK, IBK, PBK, CIB, PBK, IBK, IBK, IBK, IBK, IBK},
372  /* H2 */ {DBK, PBK, PBK, IBK, IBK, IBK, PBK, PBK, PBK, DBK, IBK, DBK, DBK, DBK, IBK, IBK, IBK, DBK, DBK, PBK, CIB, PBK, DBK, DBK, DBK, IBK, IBK},
373  /* H3 */ {DBK, PBK, PBK, IBK, IBK, IBK, PBK, PBK, PBK, DBK, IBK, DBK, DBK, DBK, IBK, IBK, IBK, DBK, DBK, PBK, CIB, PBK, DBK, DBK, DBK, DBK, IBK},
374  /* JL */ {DBK, PBK, PBK, IBK, IBK, IBK, PBK, PBK, PBK, DBK, IBK, DBK, DBK, DBK, IBK, IBK, IBK, DBK, DBK, PBK, CIB, PBK, IBK, IBK, IBK, IBK, DBK},
375  /* JV */ {DBK, PBK, PBK, IBK, IBK, IBK, PBK, PBK, PBK, DBK, IBK, DBK, DBK, DBK, IBK, IBK, IBK, DBK, DBK, PBK, CIB, PBK, DBK, DBK, DBK, IBK, IBK},
376  /* JT */ {DBK, PBK, PBK, IBK, IBK, IBK, PBK, PBK, PBK, DBK, IBK, DBK, DBK, DBK, IBK, IBK, IBK, DBK, DBK, PBK, CIB, PBK, DBK, DBK, DBK, DBK, IBK},
377  };
378 
379  uint8_t ch = static_cast<uint8_t>(*text);
380 
381  LineBreakClass cls;
382 
383  if (ch == '\n')
384  cls = kLBC_MandatoryBreak;
385  else if (ch < 128)
386  {
387  cls = kASCII_LBTable[ch];
388  if (cls > kLBC_MandatoryBreak and cls != kLBC_Space) // duh...
389  cls = kLBC_Alphabetic;
390  }
391  else
392  cls = kLBC_Unknown;
393 
394  if (cls == kLBC_Space)
395  cls = kLBC_WordJoiner;
396 
397  LineBreakClass ncls = cls;
398 
399  while (++text != end and cls != kLBC_MandatoryBreak)
400  {
401  ch = *text;
402 
403  LineBreakClass lcls = ncls;
404 
405  if (ch == '\n')
406  {
407  ++text;
408  break;
409  }
410 
411  ncls = kASCII_LBTable[ch];
412 
413  if (ncls == kLBC_Space)
414  continue;
415 
416  breakAction brk = brkTable[cls][ncls];
417 
418  if (brk == DBK or (brk == IBK and lcls == kLBC_Space))
419  break;
420 
421  cls = ncls;
422  }
423 
424  return text;
425 }
const LineBreakClass kASCII_LBTable[128]
Definition: text.cpp:310
LineBreakClass
Definition: text.cpp:268

◆ normalize()

template<typename T >
quaternion_type<T> cif::normalize ( quaternion_type< T >  q)

Definition at line 278 of file point.cpp.

279 {
280  std::valarray<double> t(4);
281 
282  t[0] = q.get_a();
283  t[1] = q.get_b();
284  t[2] = q.get_c();
285  t[3] = q.get_d();
286 
287  t *= t;
288 
289  double length = std::sqrt(t.sum());
290 
291  if (length > 0.001)
292  q /= static_cast<quaternion::value_type>(length);
293  else
294  q = quaternion(1, 0, 0, 0);
295 
296  return q;
297 }
void sqrt(Image< double > &op)
__host__ __device__ float length(float2 v)

◆ nudge()

point cif::nudge ( point  p,
float  offset 
)

Definition at line 562 of file point.cpp.

563 {
564  static const float kPI_f = static_cast<float>(kPI);
565 
566  static std::random_device rd;
567  static std::mt19937_64 rng(rd());
568 
569  std::uniform_real_distribution<float> randomAngle(0, 2 * kPI_f);
570  std::normal_distribution<float> randomOffset(0, offset);
571 
572  float theta = randomAngle(rng);
573  float phi1 = randomAngle(rng) - kPI_f;
574  float phi2 = randomAngle(rng) - kPI_f;
575 
576  quaternion q = spherical(1.0f, theta, phi1, phi2);
577 
578  point r{ 0, 0, 1 };
579  r.rotate(q);
580  r *= randomOffset(rng);
581 
582  return p + r;
583 }
double theta
double * f

◆ operator*()

template<typename M >
MatrixMultiplication<M> cif::operator* ( const MatrixExpression< M > &  m,
double  v 
)

Definition at line 232 of file point.cpp.

233 {
234  return MatrixMultiplication(*static_cast<const M *>(&m), v);
235 }
int m

◆ operator-()

template<typename M1 , typename M2 >
MatrixSubtraction<M1, M2> cif::operator- ( const MatrixExpression< M1 > &  m1,
const MatrixExpression< M2 > &  m2 
)

Definition at line 203 of file point.cpp.

204 {
205  return MatrixSubtraction(*static_cast<const M1 *>(&m1), *static_cast<const M2 *>(&m2));
206 }

◆ parse_dictionary()

validator cif::parse_dictionary ( std::string_view  name,
std::istream &  is 
)

Definition at line 473 of file dictionary_parser.cpp.

474 {
475  validator result(name);
476 
477  file f;
478  dictionary_parser p(result, is, f);
479  p.load_dictionary();
480 
481  return result;
482 }
double * f

◆ parse_tls_selection_details()

std::unique_ptr<tls_selection> cif::parse_tls_selection_details ( const std::string &  program,
const std::string &  selection 
)

Definition at line 1947 of file tls.cpp.

1948 {
1949  TLSSelectionParser<TLSSelectionParserImplPhenix> phenix;
1950  TLSSelectionParser<TLSSelectionParserImplBuster> buster;
1951  TLSSelectionParser<TLSSelectionParserImplBusterOld> busterOld;
1952 
1953  std::unique_ptr<tls_selection> result;
1954 
1955  if (cif::icontains(program, "buster"))
1956  {
1957  result = buster.Parse(selection);
1958 
1959  if (not result)
1960  {
1961  if (cif::VERBOSE > 0)
1962  std::cerr << "Falling back to old BUSTER" << std::endl;
1963  result = busterOld.Parse(selection);
1964  }
1965 
1966  if (not result)
1967  {
1968  if (cif::VERBOSE > 0)
1969  std::cerr << "Falling back to PHENIX" << std::endl;
1970  result = phenix.Parse(selection);
1971  }
1972  }
1973  else if (cif::icontains(program, "phenix"))
1974  {
1975  result = phenix.Parse(selection);
1976 
1977  if (not result)
1978  {
1979  if (cif::VERBOSE > 0)
1980  std::cerr << "Falling back to BUSTER" << std::endl;
1981  result = buster.Parse(selection);
1982  }
1983 
1984  if (not result)
1985  {
1986  if (cif::VERBOSE > 0)
1987  std::cerr << "Falling back to old BUSTER" << std::endl;
1988  result = busterOld.Parse(selection);
1989  }
1990  }
1991  else
1992  {
1993  if (cif::VERBOSE > 0)
1994  std::cerr << "No known program specified, trying PHENIX" << std::endl;
1995 
1996  result = phenix.Parse(selection);
1997 
1998  if (not result)
1999  {
2000  if (cif::VERBOSE > 0)
2001  std::cerr << "Falling back to BUSTER" << std::endl;
2002  result = buster.Parse(selection);
2003  }
2004 
2005  if (not result)
2006  {
2007  if (cif::VERBOSE > 0)
2008  std::cerr << "Falling back to old BUSTER" << std::endl;
2009  result = busterOld.Parse(selection);
2010  }
2011  }
2012 
2013  return result;
2014 }
bool icontains(std::string_view s, std::string_view q)
Definition: text.cpp:143
int VERBOSE
Definition: utilities.cpp:58

◆ quaternion_to_angle_axis()

std::tuple<double, point> cif::quaternion_to_angle_axis ( quaternion  q)

Definition at line 315 of file point.cpp.

316 {
317  if (q.get_a() > 1)
318  q = normalize(q);
319 
320  // angle:
321  double angle = 2 * std::acos(q.get_a());
322  angle = angle * 180 / kPI;
323 
324  // axis:
325  float s = std::sqrt(1 - q.get_a() * q.get_a());
326  if (s < 0.001)
327  s = 1;
328 
329  point axis(q.get_b() / s, q.get_c() / s, q.get_d() / s);
330 
331  return { angle, axis };
332 }
void sqrt(Image< double > &op)
char axis
quaternion_type< T > normalize(quaternion_type< T > q)
Definition: point.cpp:278

◆ replace_all()

void cif::replace_all ( std::string &  s,
std::string_view  what,
std::string_view  with 
)

Definition at line 134 of file text.cpp.

135 {
136  for (std::string::size_type p = s.find(what); p != std::string::npos; p = s.find(what, p))
137  {
138  s.replace(p, what.length(), with);
139  p += with.length();
140  }
141 }

◆ RMSd()

double cif::RMSd ( const std::vector< point > &  a,
const std::vector< point > &  b 
)

Definition at line 409 of file point.cpp.

410 {
411  double sum = 0;
412  for (uint32_t i = 0; i < a.size(); ++i)
413  {
414  std::valarray<double> d(3);
415 
416  d[0] = b[i].m_x - a[i].m_x;
417  d[1] = b[i].m_y - a[i].m_y;
418  d[2] = b[i].m_z - a[i].m_z;
419 
420  d *= d;
421 
422  sum += d.sum();
423  }
424 
425  return std::sqrt(sum / a.size());
426 }
void sqrt(Image< double > &op)
#define i
doublereal * d
doublereal * b
doublereal * a

◆ split_tag_name()

std::tuple<std::string, std::string> cif::split_tag_name ( std::string_view  tag)

Definition at line 218 of file text.cpp.

219 {
220  if (tag.empty())
221  throw std::runtime_error("empty tag");
222  if (tag[0] != '_')
223  throw std::runtime_error("tag '" + std::string { tag } + "' does not start with underscore");
224 
225  auto s = tag.find('.');
226  if (s == std::string::npos)
227  // throw std::runtime_error("tag does not contain dot (" + std::string{ tag } + ')');
228  return std::tuple<std::string, std::string>{ "", tag.substr(1) };
229  else
230  return std::tuple<std::string, std::string>{tag.substr(1, s - 1), tag.substr(s + 1)};
231 }

◆ to_lower()

void cif::to_lower ( std::string &  s)

Definition at line 114 of file text.cpp.

115 {
116  for (auto &c : s)
117  c = tolower(c);
118 }
doublereal * c

◆ to_lower_copy()

std::string cif::to_lower_copy ( std::string_view  s)

Definition at line 120 of file text.cpp.

121 {
122  std::string result(s);
123  for (auto &c : result)
124  c = tolower(c);
125  return result;
126 }
doublereal * c

◆ to_string()

std::string cif::to_string ( bond_type  bondType)

Definition at line 43 of file compound.cpp.

44 {
45  switch (bondType)
46  {
47  case bond_type::sing: return "sing";
48  case bond_type::doub: return "doub";
49  case bond_type::trip: return "trip";
50  case bond_type::quad: return "quad";
51  case bond_type::arom: return "arom";
52  case bond_type::poly: return "poly";
53  case bond_type::delo: return "delo";
54  case bond_type::pi: return "pi";
55  }
56  throw std::invalid_argument("Invalid bondType");
57 }
#define pi

◆ to_upper()

void cif::to_upper ( std::string &  s)

Definition at line 128 of file text.cpp.

129 {
130  for (auto &c : s)
131  c = static_cast<char>(toupper(c));
132 }
doublereal * c

◆ trim()

void cif::trim ( std::string &  s)

Definition at line 205 of file text.cpp.

206 {
207  trim_right(s);
208  trim_left(s);
209 }
void trim_left(std::string &s)
Definition: text.cpp:191
void trim_right(std::string &s)
Definition: text.cpp:148

◆ trim_copy()

std::string cif::trim_copy ( std::string_view  s)

Definition at line 211 of file text.cpp.

212 {
213  return trim_left_copy(trim_right_copy(s));
214 }
std::string trim_left_copy(std::string_view s)
Definition: text.cpp:177
std::string trim_right_copy(std::string_view s)
Definition: text.cpp:163

◆ trim_left()

void cif::trim_left ( std::string &  s)

Definition at line 191 of file text.cpp.

192 {
193  auto b = s.begin();
194  while (b != s.end())
195  {
196  if (not std::isspace(*b))
197  break;
198 
199  b = std::next(b);
200  }
201 
202  s.erase(s.begin(), b);
203 }
doublereal * b

◆ trim_left_copy()

std::string cif::trim_left_copy ( std::string_view  s)

Definition at line 177 of file text.cpp.

178 {
179  auto b = s.begin();
180  while (b != s.end())
181  {
182  if (not std::isspace(*b))
183  break;
184 
185  b = std::next(b);
186  }
187 
188  return {b, s.end()};
189 }
doublereal * b

◆ trim_right()

void cif::trim_right ( std::string &  s)

Definition at line 148 of file text.cpp.

149 {
150  auto e = s.end();
151  while (e != s.begin())
152  {
153  auto pe = std::prev(e);
154  if (not std::isspace(*pe))
155  break;
156  e = pe;
157  }
158 
159  if (e != s.end())
160  s.erase(e, s.end());
161 }

◆ trim_right_copy()

std::string cif::trim_right_copy ( std::string_view  s)

Definition at line 163 of file text.cpp.

164 {
165  auto e = s.end();
166  while (e != s.begin())
167  {
168  auto pe = std::prev(e);
169  if (not std::isspace(*pe))
170  break;
171  e = pe;
172  }
173 
174  return {s.begin(), e};
175 }

◆ word_wrap()

std::vector<std::string> cif::word_wrap ( const std::string &  text,
size_t  width 
)

Definition at line 488 of file text.cpp.

489 {
490  std::vector<std::string> result;
491  for (auto p : cif::split<std::string>(text, "\n"))
492  {
493  if (p.empty())
494  {
495  result.push_back("");
496  continue;
497  }
498 
499  auto lines = wrapLine(p, width);
500  result.insert(result.end(), lines.begin(), lines.end());
501  }
502 
503  return result;
504 }
std::vector< std::string > wrapLine(const std::string &text, size_t width)
Definition: text.cpp:427

◆ wrapLine()

std::vector<std::string> cif::wrapLine ( const std::string &  text,
size_t  width 
)

Definition at line 427 of file text.cpp.

428 {
429  std::vector<std::string> result;
430  std::vector<size_t> offsets = {0};
431 
432  auto b = text.begin();
433  while (b != text.end())
434  {
435  auto e = nextLineBreak(b, text.end());
436 
437  offsets.push_back(e - text.begin());
438 
439  b = e;
440  }
441 
442  size_t count = offsets.size() - 1;
443 
444  std::vector<size_t> minima(count + 1, 1000000);
445  minima[0] = 0;
446  std::vector<size_t> breaks(count + 1, 0);
447 
448  for (size_t i = 0; i < count; ++i)
449  {
450  size_t j = i + 1;
451  while (j <= count)
452  {
453  size_t w = offsets[j] - offsets[i];
454 
455  if (w > width)
456  break;
457 
458  while (w > 0 and isspace(text[offsets[i] + w - 1]))
459  --w;
460 
461  size_t cost = minima[i];
462  if (j < count) // last line may be shorter
463  cost += (width - w) * (width - w);
464 
465  if (cost < minima[j])
466  {
467  minima[j] = cost;
468  breaks[j] = i;
469  }
470 
471  ++j;
472  }
473  }
474 
475  size_t j = count;
476  while (j > 0)
477  {
478  size_t i = breaks[j];
479  result.push_back(text.substr(offsets[i], offsets[j] - offsets[i]));
480  j = i;
481  }
482 
483  reverse(result.begin(), result.end());
484 
485  return result;
486 }
doublereal * w
#define i
doublereal * b
#define j
std::string::const_iterator nextLineBreak(std::string::const_iterator text, std::string::const_iterator end)
Definition: text.cpp:334

Variable Documentation

◆ kASCII_LBTable

const LineBreakClass cif::kASCII_LBTable[128]
Initial value:
=
{

Definition at line 310 of file text.cpp.

◆ kCharToLowerMap

const uint8_t cif::kCharToLowerMap[256]
Initial value:
=
{
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
0x40, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff}

Definition at line 38 of file text.cpp.

◆ kMaxLineLength

const uint32_t cif::kMaxLineLength = 132

Definition at line 42 of file category.cpp.

◆ kNoSeqNum

const int cif::kNoSeqNum = std::numeric_limits<int>::max() - 1

Definition at line 41 of file tls.cpp.

◆ kResidueNrWildcard

const int cif::kResidueNrWildcard = std::numeric_limits<int>::min()

Definition at line 40 of file tls.cpp.

◆ s_null_row_handle

row_handle cif::s_null_row_handle

Definition at line 35 of file item.cpp.

◆ VERBOSE

int cif::VERBOSE = 0

Definition at line 58 of file utilities.cpp.