Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
libcifpp
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open
libcifpp
Commits
4b4757ee
Commit
4b4757ee
authored
Sep 22, 2020
by
Maarten L. Hekkelman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
removed using namespace std;
parent
ac088dd0
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
868 additions
and
995 deletions
+868
-995
GNUmakefile.in
+0
-1
src/AtomType.cpp
+7
-9
src/Cif++.cpp
+188
-189
src/CifParser.cpp
+68
-69
src/CifUtils.cpp
+36
-35
src/CifValidator.cpp
+33
-34
src/Compound.cpp
+104
-110
src/FixDMC.cpp
+0
-88
src/PDB2Cif.cpp
+0
-0
src/PDB2CifRemark3.cpp
+78
-80
src/Point.cpp
+23
-25
src/Structure.cpp
+196
-204
src/Symmetry.cpp
+2
-4
src/TlsParser.cpp
+133
-147
No files found.
GNUmakefile.in
View file @
4b4757ee
...
@@ -97,7 +97,6 @@ LIBCIF_SRC = AtomType.cpp \
...
@@ -97,7 +97,6 @@ LIBCIF_SRC = AtomType.cpp \
CifUtils.cpp
\
CifUtils.cpp
\
CifValidator.cpp
\
CifValidator.cpp
\
Compound.cpp
\
Compound.cpp
\
FixDMC.cpp
\
PDB2Cif.cpp
\
PDB2Cif.cpp
\
PDB2CifRemark3.cpp
\
PDB2CifRemark3.cpp
\
Point.cpp
\
Point.cpp
\
...
...
src/AtomType.cpp
View file @
4b4757ee
...
@@ -29,8 +29,6 @@
...
@@ -29,8 +29,6 @@
#include "cif++/AtomType.hpp"
#include "cif++/AtomType.hpp"
#include "cif++/Cif++.hpp"
#include "cif++/Cif++.hpp"
using
namespace
std
;
namespace
mmcif
namespace
mmcif
{
{
...
@@ -1237,7 +1235,7 @@ SFDataArrayElement kELSFData[] = {
...
@@ -1237,7 +1235,7 @@ SFDataArrayElement kELSFData[] = {
// --------------------------------------------------------------------
// --------------------------------------------------------------------
// AtomTypeTraits
// AtomTypeTraits
AtomTypeTraits
::
AtomTypeTraits
(
const
string
&
symbol
)
AtomTypeTraits
::
AtomTypeTraits
(
const
st
d
::
st
ring
&
symbol
)
:
mInfo
(
nullptr
)
:
mInfo
(
nullptr
)
{
{
for
(
auto
&
i
:
data
::
kKnownAtoms
)
for
(
auto
&
i
:
data
::
kKnownAtoms
)
...
@@ -1250,20 +1248,20 @@ AtomTypeTraits::AtomTypeTraits(const string& symbol)
...
@@ -1250,20 +1248,20 @@ AtomTypeTraits::AtomTypeTraits(const string& symbol)
}
}
if
(
mInfo
==
nullptr
)
if
(
mInfo
==
nullptr
)
throw
invalid_argument
(
"Not a known element: "
+
symbol
);
throw
std
::
invalid_argument
(
"Not a known element: "
+
symbol
);
}
}
AtomTypeTraits
::
AtomTypeTraits
(
AtomType
t
)
AtomTypeTraits
::
AtomTypeTraits
(
AtomType
t
)
{
{
if
(
t
<
H
or
t
>=
data
::
kKnownAtomsCount
)
if
(
t
<
H
or
t
>=
data
::
kKnownAtomsCount
)
throw
invalid_argument
(
"atomType out of range"
);
throw
std
::
invalid_argument
(
"atomType out of range"
);
mInfo
=
&
data
::
kKnownAtoms
[
t
];
mInfo
=
&
data
::
kKnownAtoms
[
t
];
assert
(
mInfo
->
type
==
t
);
assert
(
mInfo
->
type
==
t
);
}
}
bool
AtomTypeTraits
::
isElement
(
const
string
&
symbol
)
bool
AtomTypeTraits
::
isElement
(
const
st
d
::
st
ring
&
symbol
)
{
{
bool
result
=
false
;
bool
result
=
false
;
...
@@ -1279,7 +1277,7 @@ bool AtomTypeTraits::isElement(const string& symbol)
...
@@ -1279,7 +1277,7 @@ bool AtomTypeTraits::isElement(const string& symbol)
return
result
;
return
result
;
}
}
bool
AtomTypeTraits
::
isMetal
(
const
string
&
symbol
)
bool
AtomTypeTraits
::
isMetal
(
const
st
d
::
st
ring
&
symbol
)
{
{
bool
result
=
false
;
bool
result
=
false
;
...
@@ -1303,7 +1301,7 @@ auto AtomTypeTraits::wksf(int charge) const -> const SFData&
...
@@ -1303,7 +1301,7 @@ auto AtomTypeTraits::wksf(int charge) const -> const SFData&
return
sf
.
sf
;
return
sf
.
sf
;
}
}
throw
runtime_error
(
"No scattering factor found for "
+
name
()
+
to_string
(
charge
));
throw
std
::
runtime_error
(
"No scattering factor found for "
+
name
()
+
std
::
to_string
(
charge
));
}
}
auto
AtomTypeTraits
::
elsf
()
const
->
const
SFData
&
auto
AtomTypeTraits
::
elsf
()
const
->
const
SFData
&
...
@@ -1314,7 +1312,7 @@ auto AtomTypeTraits::elsf() const -> const SFData&
...
@@ -1314,7 +1312,7 @@ auto AtomTypeTraits::elsf() const -> const SFData&
return
sf
.
sf
;
return
sf
.
sf
;
}
}
throw
runtime_error
(
"No scattering factor found for "
+
name
());
throw
std
::
runtime_error
(
"No scattering factor found for "
+
name
());
}
}
}
}
src/Cif++.cpp
View file @
4b4757ee
...
@@ -47,7 +47,6 @@
...
@@ -47,7 +47,6 @@
#include "cif++/CifValidator.hpp"
#include "cif++/CifValidator.hpp"
#include "cif++/CifUtils.hpp"
#include "cif++/CifUtils.hpp"
using
namespace
std
;
namespace
ba
=
boost
::
algorithm
;
namespace
ba
=
boost
::
algorithm
;
namespace
io
=
boost
::
iostreams
;
namespace
io
=
boost
::
iostreams
;
namespace
fs
=
std
::
filesystem
;
namespace
fs
=
std
::
filesystem
;
...
@@ -115,7 +114,7 @@ void ItemValue::operator delete(void* p)
...
@@ -115,7 +114,7 @@ void ItemValue::operator delete(void* p)
struct
ItemColumn
struct
ItemColumn
{
{
string
mName
;
// store lower-case, for optimization
st
d
::
st
ring
mName
;
// store lower-case, for optimization
const
ValidateItem
*
mValidator
;
const
ValidateItem
*
mValidator
;
};
};
...
@@ -128,9 +127,9 @@ struct ItemRow
...
@@ -128,9 +127,9 @@ struct ItemRow
void
drop
(
uint32_t
columnIx
);
void
drop
(
uint32_t
columnIx
);
const
char
*
c_str
(
uint32_t
columnIx
)
const
;
const
char
*
c_str
(
uint32_t
columnIx
)
const
;
string
str
()
const
st
d
::
st
ring
str
()
const
{
{
stringstream
s
;
st
d
::
st
ringstream
s
;
s
<<
'{'
;
s
<<
'{'
;
for
(
auto
v
=
mValues
;
v
!=
nullptr
;
v
=
v
->
mNext
)
for
(
auto
v
=
mValues
;
v
!=
nullptr
;
v
=
v
->
mNext
)
...
@@ -152,7 +151,7 @@ struct ItemRow
...
@@ -152,7 +151,7 @@ struct ItemRow
uint32_t
mLineNr
=
0
;
uint32_t
mLineNr
=
0
;
};
};
ostream
&
operator
<<
(
ostream
&
os
,
const
ItemRow
&
r
)
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
ItemRow
&
r
)
{
{
os
<<
r
.
mCategory
->
name
()
<<
'['
;
os
<<
r
.
mCategory
->
name
()
<<
'['
;
for
(
auto
iv
=
r
.
mValues
;
iv
!=
nullptr
;
iv
=
iv
->
mNext
)
for
(
auto
iv
=
r
.
mValues
;
iv
!=
nullptr
;
iv
=
iv
->
mNext
)
...
@@ -234,10 +233,10 @@ const char* ItemRow::c_str(uint32_t columnIx) const
...
@@ -234,10 +233,10 @@ const char* ItemRow::c_str(uint32_t columnIx) const
namespace
detail
namespace
detail
{
{
ItemReference
&
ItemReference
::
operator
=
(
const
string
&
value
)
ItemReference
&
ItemReference
::
operator
=
(
const
st
d
::
st
ring
&
value
)
{
{
if
(
mConst
)
if
(
mConst
)
throw
logic_error
(
"Attempt to write to a constant row"
);
throw
std
::
logic_error
(
"Attempt to write to a constant row"
);
mRow
.
assign
(
mName
,
value
,
false
);
mRow
.
assign
(
mName
,
value
,
false
);
return
*
this
;
return
*
this
;
...
@@ -342,7 +341,7 @@ std::ostream& operator<<(std::ostream& os, ItemReference& item)
...
@@ -342,7 +341,7 @@ std::ostream& operator<<(std::ostream& os, ItemReference& item)
// --------------------------------------------------------------------
// --------------------------------------------------------------------
// Datablock implementation
// Datablock implementation
Datablock
::
Datablock
(
const
string
&
name
)
Datablock
::
Datablock
(
const
st
d
::
st
ring
&
name
)
:
mName
(
name
),
mValidator
(
nullptr
),
mNext
(
nullptr
)
:
mName
(
name
),
mValidator
(
nullptr
),
mNext
(
nullptr
)
{
{
}
}
...
@@ -352,11 +351,11 @@ Datablock::~Datablock()
...
@@ -352,11 +351,11 @@ Datablock::~Datablock()
delete
mNext
;
delete
mNext
;
}
}
st
ring
Datablock
::
firstItem
(
const
string
&
tag
)
const
st
d
::
string
Datablock
::
firstItem
(
const
std
::
string
&
tag
)
const
{
{
string
result
;
st
d
::
st
ring
result
;
string
catName
,
itemName
;
st
d
::
st
ring
catName
,
itemName
;
std
::
tie
(
catName
,
itemName
)
=
splitTagName
(
tag
);
std
::
tie
(
catName
,
itemName
)
=
splitTagName
(
tag
);
for
(
auto
&
cat
:
mCategories
)
for
(
auto
&
cat
:
mCategories
)
...
@@ -365,7 +364,7 @@ string Datablock::firstItem(const string& tag) const
...
@@ -365,7 +364,7 @@ string Datablock::firstItem(const string& tag) const
{
{
for
(
auto
row
:
cat
)
for
(
auto
row
:
cat
)
{
{
result
=
row
[
itemName
].
as
<
string
>
();
result
=
row
[
itemName
].
as
<
st
d
::
st
ring
>
();
break
;
break
;
}
}
...
@@ -376,7 +375,7 @@ string Datablock::firstItem(const string& tag) const
...
@@ -376,7 +375,7 @@ string Datablock::firstItem(const string& tag) const
return
result
;
return
result
;
}
}
auto
Datablock
::
emplace
(
const
st
ring
&
name
)
->
tuple
<
iterator
,
bool
>
auto
Datablock
::
emplace
(
const
st
d
::
string
&
name
)
->
std
::
tuple
<
iterator
,
bool
>
{
{
bool
isNew
=
false
;
bool
isNew
=
false
;
iterator
i
=
find_if
(
begin
(),
end
(),
[
name
](
const
Category
&
cat
)
->
bool
iterator
i
=
find_if
(
begin
(),
end
(),
[
name
](
const
Category
&
cat
)
->
bool
...
@@ -388,17 +387,17 @@ auto Datablock::emplace(const string& name) -> tuple<iterator,bool>
...
@@ -388,17 +387,17 @@ auto Datablock::emplace(const string& name) -> tuple<iterator,bool>
i
=
mCategories
.
emplace
(
end
(),
*
this
,
name
,
mValidator
);
i
=
mCategories
.
emplace
(
end
(),
*
this
,
name
,
mValidator
);
}
}
return
make_tuple
(
i
,
isNew
);
return
std
::
make_tuple
(
i
,
isNew
);
}
}
Category
&
Datablock
::
operator
[](
const
string
&
name
)
Category
&
Datablock
::
operator
[](
const
st
d
::
st
ring
&
name
)
{
{
iterator
i
;
iterator
i
;
std
::
tie
(
i
,
ignore
)
=
emplace
(
name
);
std
::
tie
(
i
,
std
::
ignore
)
=
emplace
(
name
);
return
*
i
;
return
*
i
;
}
}
Category
*
Datablock
::
get
(
const
string
&
name
)
Category
*
Datablock
::
get
(
const
st
d
::
st
ring
&
name
)
{
{
auto
i
=
find_if
(
begin
(),
end
(),
[
name
](
const
Category
&
cat
)
->
bool
auto
i
=
find_if
(
begin
(),
end
(),
[
name
](
const
Category
&
cat
)
->
bool
{
return
iequals
(
cat
.
name
(),
name
);
});
{
return
iequals
(
cat
.
name
(),
name
);
});
...
@@ -409,7 +408,7 @@ Category* Datablock::get(const string& name)
...
@@ -409,7 +408,7 @@ Category* Datablock::get(const string& name)
bool
Datablock
::
isValid
()
bool
Datablock
::
isValid
()
{
{
if
(
mValidator
==
nullptr
)
if
(
mValidator
==
nullptr
)
throw
runtime_error
(
"Validator not specified"
);
throw
std
::
runtime_error
(
"Validator not specified"
);
bool
result
=
true
;
bool
result
=
true
;
for
(
auto
&
cat
:
*
this
)
for
(
auto
&
cat
:
*
this
)
...
@@ -431,7 +430,7 @@ void Datablock::setValidator(Validator* v)
...
@@ -431,7 +430,7 @@ void Datablock::setValidator(Validator* v)
cat
.
setValidator
(
v
);
cat
.
setValidator
(
v
);
}
}
void
Datablock
::
add_software
(
const
st
ring
&
name
,
const
string
&
classification
,
const
string
&
versionNr
,
const
string
&
versionDate
)
void
Datablock
::
add_software
(
const
st
d
::
string
&
name
,
const
std
::
string
&
classification
,
const
std
::
string
&
versionNr
,
const
std
::
string
&
versionDate
)
{
{
Category
&
cat
=
operator
[](
"software"
);
Category
&
cat
=
operator
[](
"software"
);
int
ordNr
=
cat
.
size
()
+
1
;
int
ordNr
=
cat
.
size
()
+
1
;
...
@@ -446,16 +445,16 @@ void Datablock::add_software(const string& name, const string& classification, c
...
@@ -446,16 +445,16 @@ void Datablock::add_software(const string& name, const string& classification, c
});
});
}
}
void
Datablock
::
getTagOrder
(
vector
<
string
>&
tags
)
const
void
Datablock
::
getTagOrder
(
std
::
vector
<
std
::
string
>&
tags
)
const
{
{
for
(
auto
&
cat
:
*
this
)
for
(
auto
&
cat
:
*
this
)
cat
.
getTagOrder
(
tags
);
cat
.
getTagOrder
(
tags
);
}
}
void
Datablock
::
write
(
ostream
&
os
)
void
Datablock
::
write
(
std
::
ostream
&
os
)
{
{
os
<<
"data_"
<<
mName
<<
endl
os
<<
"data_"
<<
mName
<<
std
::
endl
<<
"# "
<<
endl
;
<<
"# "
<<
std
::
endl
;
// mmcif support, sort of. First write the 'entry' Category
// mmcif support, sort of. First write the 'entry' Category
// and if it exists, _AND_ we have a Validator, write out the
// and if it exists, _AND_ we have a Validator, write out the
...
@@ -488,17 +487,17 @@ void Datablock::write(ostream& os)
...
@@ -488,17 +487,17 @@ void Datablock::write(ostream& os)
}
}
}
}
void
Datablock
::
write
(
ostream
&
os
,
const
vector
<
string
>&
order
)
void
Datablock
::
write
(
std
::
ostream
&
os
,
const
std
::
vector
<
std
::
string
>&
order
)
{
{
os
<<
"data_"
<<
mName
<<
endl
os
<<
"data_"
<<
mName
<<
std
::
endl
<<
"# "
<<
endl
;
<<
"# "
<<
std
::
endl
;
vector
<
string
>
catOrder
;
std
::
vector
<
std
::
string
>
catOrder
;
for
(
auto
&
o
:
order
)
for
(
auto
&
o
:
order
)
{
{
string
cat
,
Item
;
st
d
::
st
ring
cat
,
Item
;
std
::
tie
(
cat
,
Item
)
=
splitTagName
(
o
);
std
::
tie
(
cat
,
Item
)
=
splitTagName
(
o
);
if
(
find_if
(
catOrder
.
rbegin
(),
catOrder
.
rend
(),
[
cat
](
const
string
&
s
)
->
bool
{
return
iequals
(
cat
,
s
);
})
==
catOrder
.
rend
())
if
(
find_if
(
catOrder
.
rbegin
(),
catOrder
.
rend
(),
[
cat
](
const
st
d
::
st
ring
&
s
)
->
bool
{
return
iequals
(
cat
,
s
);
})
==
catOrder
.
rend
())
catOrder
.
push_back
(
cat
);
catOrder
.
push_back
(
cat
);
}
}
...
@@ -508,10 +507,10 @@ void Datablock::write(ostream& os, const vector<string>& order)
...
@@ -508,10 +507,10 @@ void Datablock::write(ostream& os, const vector<string>& order)
if
(
cat
==
nullptr
)
if
(
cat
==
nullptr
)
continue
;
continue
;
vector
<
string
>
items
;
std
::
vector
<
std
::
string
>
items
;
for
(
auto
&
o
:
order
)
for
(
auto
&
o
:
order
)
{
{
string
catName
,
Item
;
st
d
::
st
ring
catName
,
Item
;
std
::
tie
(
catName
,
Item
)
=
splitTagName
(
o
);
std
::
tie
(
catName
,
Item
)
=
splitTagName
(
o
);
if
(
catName
==
c
)
if
(
catName
==
c
)
...
@@ -524,7 +523,7 @@ void Datablock::write(ostream& os, const vector<string>& order)
...
@@ -524,7 +523,7 @@ void Datablock::write(ostream& os, const vector<string>& order)
// for any Category we missed in the catOrder
// for any Category we missed in the catOrder
for
(
auto
&
cat
:
mCategories
)
for
(
auto
&
cat
:
mCategories
)
{
{
if
(
find_if
(
catOrder
.
begin
(),
catOrder
.
end
(),
[
&
](
const
string
&
s
)
->
bool
{
return
iequals
(
cat
.
name
(),
s
);
})
!=
catOrder
.
end
())
if
(
find_if
(
catOrder
.
begin
(),
catOrder
.
end
(),
[
&
](
const
st
d
::
st
ring
&
s
)
->
bool
{
return
iequals
(
cat
.
name
(),
s
);
})
!=
catOrder
.
end
())
continue
;
continue
;
cat
.
write
(
os
);
cat
.
write
(
os
);
...
@@ -603,11 +602,11 @@ class RowComparator
...
@@ -603,11 +602,11 @@ class RowComparator
}
}
private
:
private
:
typedef
function
<
int
(
const
char
*
,
const
char
*
)
>
compareFunc
;
typedef
std
::
function
<
int
(
const
char
*
,
const
char
*
)
>
compareFunc
;
typedef
tuple
<
size_t
,
compareFunc
>
keyComp
;
typedef
std
::
tuple
<
size_t
,
compareFunc
>
keyComp
;
vector
<
keyComp
>
mComp
;
std
::
vector
<
keyComp
>
mComp
;
};
};
template
<
typename
KeyIter
>
template
<
typename
KeyIter
>
...
@@ -617,19 +616,19 @@ RowComparator::RowComparator(Category* cat, KeyIter b, KeyIter e)
...
@@ -617,19 +616,19 @@ RowComparator::RowComparator(Category* cat, KeyIter b, KeyIter e)
for
(
auto
ki
=
b
;
ki
!=
e
;
++
ki
)
for
(
auto
ki
=
b
;
ki
!=
e
;
++
ki
)
{
{
string
k
=
*
ki
;
st
d
::
st
ring
k
=
*
ki
;
size_t
ix
=
cat
->
getColumnIndex
(
k
);
size_t
ix
=
cat
->
getColumnIndex
(
k
);
auto
iv
=
cv
->
getValidatorForItem
(
k
);
auto
iv
=
cv
->
getValidatorForItem
(
k
);
if
(
iv
==
nullptr
)
if
(
iv
==
nullptr
)
throw
runtime_error
(
"Incomplete dictionary, no Item Validator for Key "
+
k
);
throw
std
::
runtime_error
(
"Incomplete dictionary, no Item Validator for Key "
+
k
);
auto
tv
=
iv
->
mType
;
auto
tv
=
iv
->
mType
;
if
(
tv
==
nullptr
)
if
(
tv
==
nullptr
)
throw
runtime_error
(
"Incomplete dictionary, no type Validator for Item "
+
k
);
throw
std
::
runtime_error
(
"Incomplete dictionary, no type Validator for Item "
+
k
);
using
namespace
placeholders
;
using
namespace
std
::
placeholders
;
mComp
.
emplace_back
(
ix
,
bind
(
&
ValidateType
::
compare
,
tv
,
_1
,
_2
));
mComp
.
emplace_back
(
ix
,
bind
(
&
ValidateType
::
compare
,
tv
,
_1
,
_2
));
}
}
...
@@ -680,9 +679,9 @@ class CatIndex
...
@@ -680,9 +679,9 @@ class CatIndex
void
reconstruct
();
void
reconstruct
();
// reorder the ItemRow's and returns new head and tail
// reorder the ItemRow's and returns new head and tail
tuple
<
ItemRow
*
,
ItemRow
*>
reorder
()
std
::
tuple
<
ItemRow
*
,
ItemRow
*>
reorder
()
{
{
tuple
<
ItemRow
*
,
ItemRow
*>
result
=
make_tuple
(
nullptr
,
nullptr
);
std
::
tuple
<
ItemRow
*
,
ItemRow
*>
result
=
std
::
make_tuple
(
nullptr
,
nullptr
);
if
(
mRoot
!=
nullptr
)
if
(
mRoot
!=
nullptr
)
{
{
...
@@ -691,7 +690,7 @@ class CatIndex
...
@@ -691,7 +690,7 @@ class CatIndex
tail
->
mRow
->
mNext
=
nullptr
;
tail
->
mRow
->
mNext
=
nullptr
;
result
=
make_tuple
(
head
->
mRow
,
tail
->
mRow
);
result
=
std
::
make_tuple
(
head
->
mRow
,
tail
->
mRow
);
}
}
return
result
;
return
result
;
...
@@ -898,7 +897,7 @@ CatIndex::entry* CatIndex::insert(entry* h, ItemRow* v)
...
@@ -898,7 +897,7 @@ CatIndex::entry* CatIndex::insert(entry* h, ItemRow* v)
if
(
d
<
0
)
h
->
mLeft
=
insert
(
h
->
mLeft
,
v
);
if
(
d
<
0
)
h
->
mLeft
=
insert
(
h
->
mLeft
,
v
);
else
if
(
d
>
0
)
h
->
mRight
=
insert
(
h
->
mRight
,
v
);
else
if
(
d
>
0
)
h
->
mRight
=
insert
(
h
->
mRight
,
v
);
else
else
throw
runtime_error
(
"Duplicate Key violation, cat: "
+
mCat
.
name
()
+
" values: "
+
v
->
str
());
throw
std
::
runtime_error
(
"Duplicate Key violation, cat: "
+
mCat
.
name
()
+
" values: "
+
v
->
str
());
if
(
isRed
(
h
->
mRight
)
and
not
isRed
(
h
->
mLeft
))
if
(
isRed
(
h
->
mRight
)
and
not
isRed
(
h
->
mLeft
))
h
=
rotateLeft
(
h
);
h
=
rotateLeft
(
h
);
...
@@ -969,9 +968,9 @@ void CatIndex::reconstruct()
...
@@ -969,9 +968,9 @@ void CatIndex::reconstruct()
insert
(
r
.
mData
);
insert
(
r
.
mData
);
// maybe reconstruction can be done quicker by using the following commented code.
// maybe reconstruction can be done quicker by using the following commented code.
// however, I've not had the time to think of a way to set the red/black flag correctly in that case.
// however, I've not had the time to think of a way to s
td::s
et the red/black flag correctly in that case.
// vector<ItemRow*> rows;
//
std::
vector<ItemRow*> rows;
// transform(mCat.begin(), mCat.end(), backInserter(rows),
// transform(mCat.begin(), mCat.end(), backInserter(rows),
// [](Row r) -> ItemRow* { assert(r.mData); return r.mData; });
// [](Row r) -> ItemRow* { assert(r.mData); return r.mData; });
//
//
...
@@ -1039,7 +1038,7 @@ void CatIndex::reconstruct()
...
@@ -1039,7 +1038,7 @@ void CatIndex::reconstruct()
size_t
CatIndex
::
size
()
const
size_t
CatIndex
::
size
()
const
{
{
stack
<
entry
*>
s
;
st
d
::
st
ack
<
entry
*>
s
;
s
.
push
(
mRoot
);
s
.
push
(
mRoot
);
size_t
result
=
0
;
size_t
result
=
0
;
...
@@ -1189,7 +1188,7 @@ RowSet& RowSet::operator=(RowSet&& rhs)
...
@@ -1189,7 +1188,7 @@ RowSet& RowSet::operator=(RowSet&& rhs)
return
*
this
;
return
*
this
;
}
}
RowSet
&
RowSet
::
orderBy
(
initializer_list
<
string
>
items
)
RowSet
&
RowSet
::
orderBy
(
std
::
initializer_list
<
std
::
string
>
items
)
{
{
RowComparator
c
(
mCat
,
items
.
begin
(),
items
.
end
());
RowComparator
c
(
mCat
,
items
.
begin
(),
items
.
end
());
...
@@ -1200,7 +1199,7 @@ RowSet& RowSet::orderBy(initializer_list<string> items)
...
@@ -1200,7 +1199,7 @@ RowSet& RowSet::orderBy(initializer_list<string> items)
// --------------------------------------------------------------------
// --------------------------------------------------------------------
Category
::
Category
(
Datablock
&
db
,
const
string
&
name
,
Validator
*
Validator
)
Category
::
Category
(
Datablock
&
db
,
const
st
d
::
st
ring
&
name
,
Validator
*
Validator
)
:
mDb
(
db
),
mName
(
name
),
mValidator
(
Validator
)
:
mDb
(
db
),
mName
(
name
),
mValidator
(
Validator
)
,
mHead
(
nullptr
),
mTail
(
nullptr
),
mIndex
(
nullptr
)
,
mHead
(
nullptr
),
mTail
(
nullptr
),
mIndex
(
nullptr
)
{
{
...
@@ -1258,12 +1257,12 @@ void Category::setValidator(Validator* v)
...
@@ -1258,12 +1257,12 @@ void Category::setValidator(Validator* v)
mCatValidator
=
nullptr
;
mCatValidator
=
nullptr
;
}
}
bool
Category
::
hasColumn
(
const
string
&
name
)
const
bool
Category
::
hasColumn
(
const
st
d
::
st
ring
&
name
)
const
{
{
return
getColumnIndex
(
name
)
<
mColumns
.
size
();
return
getColumnIndex
(
name
)
<
mColumns
.
size
();
}
}
size_t
Category
::
getColumnIndex
(
const
string
&
name
)
const
size_t
Category
::
getColumnIndex
(
const
st
d
::
st
ring
&
name
)
const
{
{
size_t
result
;
size_t
result
;
...
@@ -1277,26 +1276,26 @@ size_t Category::getColumnIndex(const string& name) const
...
@@ -1277,26 +1276,26 @@ size_t Category::getColumnIndex(const string& name) const
{
{
auto
iv
=
mCatValidator
->
getValidatorForItem
(
name
);
auto
iv
=
mCatValidator
->
getValidatorForItem
(
name
);
if
(
iv
==
nullptr
)
if
(
iv
==
nullptr
)
cerr
<<
"Invalid name used '"
+
name
+
"' is not a known column in "
+
mName
<<
endl
;
std
::
cerr
<<
"Invalid name used '"
+
name
+
"' is not a known column in "
+
mName
<<
std
::
endl
;
}
}
return
result
;
return
result
;
}
}
const
string
&
Category
::
getColumnName
(
size_t
columnIx
)
const
const
st
d
::
st
ring
&
Category
::
getColumnName
(
size_t
columnIx
)
const
{
{
return
mColumns
.
at
(
columnIx
).
mName
;
return
mColumns
.
at
(
columnIx
).
mName
;
}
}
vector
<
string
>
Category
::
getColumnNames
()
const
std
::
vector
<
std
::
string
>
Category
::
getColumnNames
()
const
{
{
vector
<
string
>
result
;
std
::
vector
<
std
::
string
>
result
;
for
(
auto
&
c
:
mColumns
)
for
(
auto
&
c
:
mColumns
)
result
.
push_back
(
c
.
mName
);
result
.
push_back
(
c
.
mName
);
return
result
;
return
result
;
}
}
size_t
Category
::
addColumn
(
const
string
&
name
)
size_t
Category
::
addColumn
(
const
st
d
::
st
ring
&
name
)
{
{
size_t
result
=
getColumnIndex
(
name
);
size_t
result
=
getColumnIndex
(
name
);
...
@@ -1343,7 +1342,7 @@ void Category::sort(std::function<int(const Row&, const Row&)> comparator)
...
@@ -1343,7 +1342,7 @@ void Category::sort(std::function<int(const Row&, const Row&)> comparator)
if
(
mHead
==
nullptr
)
if
(
mHead
==
nullptr
)
return
;
return
;
vector
<
ItemRow
*>
rows
;
std
::
vector
<
ItemRow
*>
rows
;
for
(
auto
itemRow
=
mHead
;
itemRow
!=
nullptr
;
itemRow
=
itemRow
->
mNext
)
for
(
auto
itemRow
=
mHead
;
itemRow
!=
nullptr
;
itemRow
=
itemRow
->
mNext
)
rows
.
push_back
(
itemRow
);
rows
.
push_back
(
itemRow
);
...
@@ -1382,9 +1381,9 @@ bool Category::empty() const
...
@@ -1382,9 +1381,9 @@ bool Category::empty() const
return
mHead
==
nullptr
or
mHead
->
mValues
==
nullptr
;
return
mHead
==
nullptr
or
mHead
->
mValues
==
nullptr
;
}
}
void
Category
::
drop
(
const
string
&
field
)
void
Category
::
drop
(
const
st
d
::
st
ring
&
field
)
{
{
using
namespace
placeholders
;
using
namespace
std
::
placeholders
;
auto
ci
=
find_if
(
mColumns
.
begin
(),
mColumns
.
end
(),
auto
ci
=
find_if
(
mColumns
.
begin
(),
mColumns
.
end
(),
[
field
](
ItemColumn
&
c
)
->
bool
{
return
iequals
(
c
.
mName
,
field
);
});
[
field
](
ItemColumn
&
c
)
->
bool
{
return
iequals
(
c
.
mName
,
field
);
});
...
@@ -1450,7 +1449,7 @@ bool Category::exists(Condition&& cond) const
...
@@ -1450,7 +1449,7 @@ bool Category::exists(Condition&& cond) const
return
result
;
return
result
;
}
}
RowSet
Category
::
orderBy
(
std
::
initializer_list
<
string
>
items
)
RowSet
Category
::
orderBy
(
std
::
initializer_list
<
st
d
::
st
ring
>
items
)
{
{
RowSet
result
(
*
this
);
RowSet
result
(
*
this
);
result
.
insert
(
result
.
begin
(),
begin
(),
end
());
result
.
insert
(
result
.
begin
(),
begin
(),
end
());
...
@@ -1471,10 +1470,10 @@ void Category::clear()
...
@@ -1471,10 +1470,10 @@ void Category::clear()
}
}
template
<
class
Iter
>
template
<
class
Iter
>
tuple
<
Row
,
bool
>
Category
::
emplace
(
Iter
b
,
Iter
e
)
std
::
tuple
<
Row
,
bool
>
Category
::
emplace
(
Iter
b
,
Iter
e
)
{
{
// First, make sure all mandatory fields are supplied
// First, make sure all mandatory fields are supplied
tuple
<
Row
,
bool
>
result
=
make_tuple
(
Row
(),
true
);
std
::
tuple
<
Row
,
bool
>
result
=
std
::
make_tuple
(
Row
(),
true
);
if
(
mCatValidator
!=
nullptr
and
b
!=
e
)
if
(
mCatValidator
!=
nullptr
and
b
!=
e
)
{
{
...
@@ -1497,12 +1496,12 @@ tuple<Row,bool> Category::emplace(Iter b, Iter e)
...
@@ -1497,12 +1496,12 @@ tuple<Row,bool> Category::emplace(Iter b, Iter e)
}
}
if
(
not
seen
and
iv
->
mMandatory
)
if
(
not
seen
and
iv
->
mMandatory
)
throw
runtime_error
(
"missing mandatory field "
+
col
.
mName
+
" for Category "
+
mName
);
throw
std
::
runtime_error
(
"missing mandatory field "
+
col
.
mName
+
" for Category "
+
mName
);
}
}
if
(
mIndex
!=
nullptr
)
if
(
mIndex
!=
nullptr
)
{
{
unique_ptr
<
ItemRow
>
nr
(
new
ItemRow
{
nullptr
,
this
,
nullptr
});
std
::
unique_ptr
<
ItemRow
>
nr
(
new
ItemRow
{
nullptr
,
this
,
nullptr
});
Row
r
(
nr
.
get
());
Row
r
(
nr
.
get
());
auto
keys
=
keyFields
();
auto
keys
=
keyFields
();
...
@@ -1516,13 +1515,13 @@ tuple<Row,bool> Category::emplace(Iter b, Iter e)
...
@@ -1516,13 +1515,13 @@ tuple<Row,bool> Category::emplace(Iter b, Iter e)
if
(
test
!=
nullptr
)
if
(
test
!=
nullptr
)
{
{
if
(
VERBOSE
>
1
)
if
(
VERBOSE
>
1
)
cerr
<<
"Not inserting new record in "
<<
mName
<<
" (duplicate Key)"
<<
endl
;
std
::
cerr
<<
"Not inserting new record in "
<<
mName
<<
" (duplicate Key)"
<<
std
::
endl
;
result
=
make_tuple
(
Row
(
test
),
false
);
result
=
std
::
make_tuple
(
Row
(
test
),
false
);
}
}
}
}
}
}
if
(
get
<
1
>
(
result
))
if
(
std
::
get
<
1
>
(
result
))
{
{
auto
nr
=
new
ItemRow
{
nullptr
,
this
,
nullptr
};
auto
nr
=
new
ItemRow
{
nullptr
,
this
,
nullptr
};
...
@@ -1544,7 +1543,7 @@ tuple<Row,bool> Category::emplace(Iter b, Iter e)
...
@@ -1544,7 +1543,7 @@ tuple<Row,bool> Category::emplace(Iter b, Iter e)
for
(
auto
v
=
b
;
v
!=
e
;
++
v
)
for
(
auto
v
=
b
;
v
!=
e
;
++
v
)
r
.
assign
(
*
v
,
true
);
r
.
assign
(
*
v
,
true
);
get
<
0
>
(
result
)
=
r
;
std
::
get
<
0
>
(
result
)
=
r
;
if
(
mIndex
!=
nullptr
)
if
(
mIndex
!=
nullptr
)
mIndex
->
insert
(
nr
);
mIndex
->
insert
(
nr
);
...
@@ -1553,7 +1552,7 @@ tuple<Row,bool> Category::emplace(Iter b, Iter e)
...
@@ -1553,7 +1552,7 @@ tuple<Row,bool> Category::emplace(Iter b, Iter e)
return
result
;
return
result
;
}
}
tuple
<
Row
,
bool
>
Category
::
emplace
(
Row
r
)
std
::
tuple
<
Row
,
bool
>
Category
::
emplace
(
Row
r
)
{
{
return
emplace
(
r
.
begin
(),
r
.
end
());
return
emplace
(
r
.
begin
(),
r
.
end
());
}
}
...
@@ -1603,7 +1602,7 @@ size_t Category::erase(Condition&& cond, std::function<void(const Row&)>&& verbo
...
@@ -1603,7 +1602,7 @@ size_t Category::erase(Condition&& cond, std::function<void(const Row&)>&& verbo
void
Category
::
eraseOrphans
(
Condition
&&
cond
)
void
Category
::
eraseOrphans
(
Condition
&&
cond
)
{
{
vector
<
ItemRow
*>
remove
;
std
::
vector
<
ItemRow
*>
remove
;
cond
.
prepare
(
*
this
);
cond
.
prepare
(
*
this
);
...
@@ -1612,9 +1611,9 @@ void Category::eraseOrphans(Condition&& cond)
...
@@ -1612,9 +1611,9 @@ void Category::eraseOrphans(Condition&& cond)
if
(
cond
(
*
this
,
r
)
and
isOrphan
(
r
))
if
(
cond
(
*
this
,
r
)
and
isOrphan
(
r
))
{
{
if
(
VERBOSE
>
1
)
if
(
VERBOSE
>
1
)
cerr
<<
"Removing orphaned record: "
<<
endl
std
::
cerr
<<
"Removing orphaned record: "
<<
std
::
endl
<<
r
<<
endl
<<
r
<<
std
::
endl
<<
endl
;
<<
std
::
endl
;
remove
.
push_back
(
r
.
mData
);
remove
.
push_back
(
r
.
mData
);
}
}
...
@@ -1639,7 +1638,7 @@ auto Category::erase(iterator pos) -> iterator
...
@@ -1639,7 +1638,7 @@ auto Category::erase(iterator pos) -> iterator
keys
=
iset
(
mCatValidator
->
mKeys
.
begin
(),
mCatValidator
->
mKeys
.
end
());
keys
=
iset
(
mCatValidator
->
mKeys
.
begin
(),
mCatValidator
->
mKeys
.
end
());
if
(
mHead
==
nullptr
)
if
(
mHead
==
nullptr
)
throw
runtime_error
(
"erase"
);
throw
std
::
runtime_error
(
"erase"
);
if
(
mIndex
!=
nullptr
)
if
(
mIndex
!=
nullptr
)
mIndex
->
erase
(
r
.
mData
);
mIndex
->
erase
(
r
.
mData
);
...
@@ -1666,7 +1665,7 @@ auto Category::erase(iterator pos) -> iterator
...
@@ -1666,7 +1665,7 @@ auto Category::erase(iterator pos) -> iterator
// in mmcif_pdbx.dic dictionary.
// in mmcif_pdbx.dic dictionary.
//
//
// For each link group in _pdbx_item_linked_group_list
// For each link group in _pdbx_item_linked_group_list
// a set of keys from one category is mapped to another.
// a s
td::s
et of keys from one category is mapped to another.
// If all values in a child are the same as the specified parent ones
// If all values in a child are the same as the specified parent ones
// the child is removed as well, recursively of course.
// the child is removed as well, recursively of course.
...
@@ -1684,10 +1683,10 @@ auto Category::erase(iterator pos) -> iterator
...
@@ -1684,10 +1683,10 @@ auto Category::erase(iterator pos) -> iterator
{
{
const
char
*
value
=
r
[
link
->
mParentKeys
[
ix
]].
c_str
();
const
char
*
value
=
r
[
link
->
mParentKeys
[
ix
]].
c_str
();
cond
=
move
(
cond
)
&&
(
Key
(
link
->
mChildKeys
[
ix
])
==
value
);
cond
=
std
::
move
(
cond
)
&&
(
Key
(
link
->
mChildKeys
[
ix
])
==
value
);
}
}
childCat
->
eraseOrphans
(
move
(
cond
));
childCat
->
eraseOrphans
(
std
::
move
(
cond
));
}
}
}
}
...
@@ -1705,7 +1704,7 @@ auto Category::erase(iterator pos) -> iterator
...
@@ -1705,7 +1704,7 @@ auto Category::erase(iterator pos) -> iterator
return
result
;
return
result
;
}
}
void
Category
::
getTagOrder
(
vector
<
string
>&
tags
)
const
void
Category
::
getTagOrder
(
std
::
vector
<
std
::
string
>&
tags
)
const
{
{
for
(
auto
&
c
:
mColumns
)
for
(
auto
&
c
:
mColumns
)
tags
.
push_back
(
"_"
+
mName
+
"."
+
c
.
mName
);
tags
.
push_back
(
"_"
+
mName
+
"."
+
c
.
mName
);
...
@@ -1746,12 +1745,12 @@ bool Category::hasParent(Row r, const Category& parentCat, const ValidateLink& l
...
@@ -1746,12 +1745,12 @@ bool Category::hasParent(Row r, const Category& parentCat, const ValidateLink& l
if
(
field
.
empty
())
if
(
field
.
empty
())
{
{
if
(
mCatValidator
->
mMandatoryFields
.
count
(
name
)
and
field
.
is_null
())
if
(
mCatValidator
->
mMandatoryFields
.
count
(
name
)
and
field
.
is_null
())
cond
=
move
(
cond
)
and
(
Key
(
link
.
mParentKeys
[
ix
])
==
Empty
());
cond
=
std
::
move
(
cond
)
and
(
Key
(
link
.
mParentKeys
[
ix
])
==
Empty
());
}
}
else
else
{
{
const
char
*
value
=
field
.
c_str
();
const
char
*
value
=
field
.
c_str
();
cond
=
move
(
cond
)
and
(
Key
(
link
.
mParentKeys
[
ix
])
==
value
);
cond
=
std
::
move
(
cond
)
and
(
Key
(
link
.
mParentKeys
[
ix
])
==
value
);
}
}
}
}
...
@@ -1760,10 +1759,10 @@ bool Category::hasParent(Row r, const Category& parentCat, const ValidateLink& l
...
@@ -1760,10 +1759,10 @@ bool Category::hasParent(Row r, const Category& parentCat, const ValidateLink& l
result
=
parentCat
.
exists
(
std
::
move
(
cond
));
result
=
parentCat
.
exists
(
std
::
move
(
cond
));
if
(
VERBOSE
>
3
or
(
result
==
false
and
VERBOSE
>
2
))
if
(
VERBOSE
>
3
or
(
result
==
false
and
VERBOSE
>
2
))
cerr
<<
"result = "
<<
boolalpha
<<
result
<<
" for: '"
<<
cond
<<
"' in parent category "
<<
link
.
mParentCategory
<<
" for child cat "
<<
mName
<<
endl
;
std
::
cerr
<<
"result = "
<<
std
::
boolalpha
<<
result
<<
" for: '"
<<
cond
<<
"' in parent category "
<<
link
.
mParentCategory
<<
" for child cat "
<<
mName
<<
std
::
endl
;
}
}
else
if
(
VERBOSE
>
3
and
cond
.
empty
())
else
if
(
VERBOSE
>
3
and
cond
.
empty
())
cerr
<<
"Condition is empty due to missing data in parent category "
<<
link
.
mParentCategory
<<
" for child cat "
<<
mName
<<
endl
;
std
::
cerr
<<
"Condition is empty due to missing data in parent category "
<<
link
.
mParentCategory
<<
" for child cat "
<<
mName
<<
std
::
endl
;
return
result
;
return
result
;
}
}
...
@@ -1785,16 +1784,16 @@ bool Category::isOrphan(Row r)
...
@@ -1785,16 +1784,16 @@ bool Category::isOrphan(Row r)
for
(
size_t
ix
=
0
;
ix
<
link
->
mChildKeys
.
size
();
++
ix
)
for
(
size_t
ix
=
0
;
ix
<
link
->
mChildKeys
.
size
();
++
ix
)
{
{
const
char
*
value
=
r
[
link
->
mChildKeys
[
ix
]].
c_str
();
const
char
*
value
=
r
[
link
->
mChildKeys
[
ix
]].
c_str
();
cond
=
move
(
cond
)
&&
(
Key
(
link
->
mParentKeys
[
ix
])
==
value
);
cond
=
std
::
move
(
cond
)
&&
(
Key
(
link
->
mParentKeys
[
ix
])
==
value
);
}
}
if
(
VERBOSE
>
2
)
if
(
VERBOSE
>
2
)
cerr
<<
"Check condition '"
<<
cond
<<
"' in parent category "
<<
link
->
mParentCategory
<<
" for child cat "
<<
mName
<<
endl
;
std
::
cerr
<<
"Check condition '"
<<
cond
<<
"' in parent category "
<<
link
->
mParentCategory
<<
" for child cat "
<<
mName
<<
std
::
endl
;
if
(
parentCat
->
exists
(
std
::
move
(
cond
)))
if
(
parentCat
->
exists
(
std
::
move
(
cond
)))
{
{
if
(
VERBOSE
>
2
)
if
(
VERBOSE
>
2
)
cerr
<<
"Not removing because row has a parent in category "
<<
link
->
mParentCategory
<<
endl
;
std
::
cerr
<<
"Not removing because row has a parent in category "
<<
link
->
mParentCategory
<<
std
::
endl
;
isOrphan
=
false
;
isOrphan
=
false
;
break
;
break
;
...
@@ -1823,7 +1822,7 @@ bool Category::hasChildren(Row r) const
...
@@ -1823,7 +1822,7 @@ bool Category::hasChildren(Row r) const
{
{
const
char
*
value
=
r
[
link
->
mParentKeys
[
ix
]].
c_str
();
const
char
*
value
=
r
[
link
->
mParentKeys
[
ix
]].
c_str
();
cond
=
move
(
cond
)
&&
(
Key
(
link
->
mChildKeys
[
ix
])
==
value
);
cond
=
std
::
move
(
cond
)
&&
(
Key
(
link
->
mChildKeys
[
ix
])
==
value
);
}
}
result
=
not
childCat
->
find
(
std
::
move
(
cond
)).
empty
();
result
=
not
childCat
->
find
(
std
::
move
(
cond
)).
empty
();
...
@@ -1840,12 +1839,12 @@ bool Category::isValid()
...
@@ -1840,12 +1839,12 @@ bool Category::isValid()
bool
result
=
true
;
bool
result
=
true
;
if
(
mValidator
==
nullptr
)
if
(
mValidator
==
nullptr
)
throw
runtime_error
(
"no Validator specified"
);
throw
std
::
runtime_error
(
"no Validator specified"
);
if
(
empty
())
if
(
empty
())
{
{
if
(
VERBOSE
>
2
)
if
(
VERBOSE
>
2
)
cerr
<<
"Skipping validation of empty Category "
<<
mName
<<
endl
;
std
::
cerr
<<
"Skipping validation of empty Category "
<<
mName
<<
std
::
endl
;
return
true
;
return
true
;
}
}
...
@@ -1947,8 +1946,8 @@ void Category::validateLinks() const
...
@@ -1947,8 +1946,8 @@ void Category::validateLinks() const
if
(
missing
)
if
(
missing
)
{
{
cerr
<<
"Links for "
<<
linkValidator
->
mLinkGroupLabel
<<
" are incomplete"
<<
endl
std
::
cerr
<<
"Links for "
<<
linkValidator
->
mLinkGroupLabel
<<
" are incomplete"
<<
std
::
endl
<<
" There are "
<<
missing
<<
" items in "
<<
mName
<<
" that don't have matching parent items in "
<<
parent
->
mName
<<
endl
;
<<
" There are "
<<
missing
<<
" items in "
<<
mName
<<
" that don't have matching parent items in "
<<
parent
->
mName
<<
std
::
endl
;
}
}
}
}
}
}
...
@@ -1956,14 +1955,14 @@ void Category::validateLinks() const
...
@@ -1956,14 +1955,14 @@ void Category::validateLinks() const
const
Validator
&
Category
::
getValidator
()
const
const
Validator
&
Category
::
getValidator
()
const
{
{
if
(
mValidator
==
nullptr
)
if
(
mValidator
==
nullptr
)
throw
runtime_error
(
"no Validator defined yet"
);
throw
std
::
runtime_error
(
"no Validator defined yet"
);
return
*
mValidator
;
return
*
mValidator
;
}
}
iset
Category
::
fields
()
const
iset
Category
::
fields
()
const
{
{
if
(
mValidator
==
nullptr
)
if
(
mValidator
==
nullptr
)
throw
runtime_error
(
"No Validator specified"
);
throw
std
::
runtime_error
(
"No Validator specified"
);
if
(
mCatValidator
==
nullptr
)
if
(
mCatValidator
==
nullptr
)
mValidator
->
reportError
(
"undefined Category"
,
true
);
mValidator
->
reportError
(
"undefined Category"
,
true
);
...
@@ -1977,7 +1976,7 @@ iset Category::fields() const
...
@@ -1977,7 +1976,7 @@ iset Category::fields() const
iset
Category
::
mandatoryFields
()
const
iset
Category
::
mandatoryFields
()
const
{
{
if
(
mValidator
==
nullptr
)
if
(
mValidator
==
nullptr
)
throw
runtime_error
(
"No Validator specified"
);
throw
std
::
runtime_error
(
"No Validator specified"
);
if
(
mCatValidator
==
nullptr
)
if
(
mCatValidator
==
nullptr
)
mValidator
->
reportError
(
"undefined Category"
,
true
);
mValidator
->
reportError
(
"undefined Category"
,
true
);
...
@@ -1988,7 +1987,7 @@ iset Category::mandatoryFields() const
...
@@ -1988,7 +1987,7 @@ iset Category::mandatoryFields() const
iset
Category
::
keyFields
()
const
iset
Category
::
keyFields
()
const
{
{
if
(
mValidator
==
nullptr
)
if
(
mValidator
==
nullptr
)
throw
runtime_error
(
"No Validator specified"
);
throw
std
::
runtime_error
(
"No Validator specified"
);
if
(
mCatValidator
==
nullptr
)
if
(
mCatValidator
==
nullptr
)
mValidator
->
reportError
(
"undefined Category"
,
true
);
mValidator
->
reportError
(
"undefined Category"
,
true
);
...
@@ -1996,15 +1995,15 @@ iset Category::keyFields() const
...
@@ -1996,15 +1995,15 @@ iset Category::keyFields() const
return
iset
{
mCatValidator
->
mKeys
.
begin
(),
mCatValidator
->
mKeys
.
end
()
};
return
iset
{
mCatValidator
->
mKeys
.
begin
(),
mCatValidator
->
mKeys
.
end
()
};
}
}
set
<
size_t
>
Category
::
keyFieldsByIndex
()
const
s
td
::
s
et
<
size_t
>
Category
::
keyFieldsByIndex
()
const
{
{
if
(
mValidator
==
nullptr
)
if
(
mValidator
==
nullptr
)
throw
runtime_error
(
"No Validator specified"
);
throw
std
::
runtime_error
(
"No Validator specified"
);
if
(
mCatValidator
==
nullptr
)
if
(
mCatValidator
==
nullptr
)
mValidator
->
reportError
(
"undefined Category"
,
true
);
mValidator
->
reportError
(
"undefined Category"
,
true
);
set
<
size_t
>
result
;
s
td
::
s
et
<
size_t
>
result
;
for
(
auto
&
k
:
mCatValidator
->
mKeys
)
for
(
auto
&
k
:
mCatValidator
->
mKeys
)
result
.
insert
(
getColumnIndex
(
k
));
result
.
insert
(
getColumnIndex
(
k
));
...
@@ -2026,18 +2025,18 @@ set<size_t> Category::keyFieldsByIndex() const
...
@@ -2026,18 +2025,18 @@ set<size_t> Category::keyFieldsByIndex() const
namespace
detail
namespace
detail
{
{
size_t
writeValue
(
ostream
&
os
,
string
value
,
size_t
offset
,
size_t
width
)
size_t
writeValue
(
std
::
ostream
&
os
,
std
::
string
value
,
size_t
offset
,
size_t
width
)
{
{
if
(
value
.
find
(
'\n'
)
!=
string
::
npos
or
width
==
0
or
value
.
length
()
>=
132
)
// write as text field
if
(
value
.
find
(
'\n'
)
!=
st
d
::
st
ring
::
npos
or
width
==
0
or
value
.
length
()
>=
132
)
// write as text field
{
{
ba
::
replace_all
(
value
,
"
\n
;"
,
"
\n\\
;"
);
ba
::
replace_all
(
value
,
"
\n
;"
,
"
\n\\
;"
);
if
(
offset
>
0
)
if
(
offset
>
0
)
os
<<
endl
;
os
<<
std
::
endl
;
os
<<
';'
<<
value
;
os
<<
';'
<<
value
;
if
(
not
ba
::
ends_with
(
value
,
"
\n
"
))
if
(
not
ba
::
ends_with
(
value
,
"
\n
"
))
os
<<
endl
;
os
<<
std
::
endl
;
os
<<
';'
<<
endl
;
os
<<
';'
<<
std
::
endl
;
offset
=
0
;
offset
=
0
;
}
}
else
if
(
isUnquotedString
(
value
.
c_str
()))
else
if
(
isUnquotedString
(
value
.
c_str
()))
...
@@ -2046,7 +2045,7 @@ size_t writeValue(ostream& os, string value, size_t offset, size_t width)
...
@@ -2046,7 +2045,7 @@ size_t writeValue(ostream& os, string value, size_t offset, size_t width)
if
(
value
.
length
()
<
width
)
if
(
value
.
length
()
<
width
)
{
{
os
<<
string
(
width
-
value
.
length
(),
' '
);
os
<<
st
d
::
st
ring
(
width
-
value
.
length
(),
' '
);
offset
+=
width
;
offset
+=
width
;
}
}
else
else
...
@@ -2061,17 +2060,17 @@ size_t writeValue(ostream& os, string value, size_t offset, size_t width)
...
@@ -2061,17 +2060,17 @@ size_t writeValue(ostream& os, string value, size_t offset, size_t width)
for
(
char
q
:
{
'\''
,
'"'
})
for
(
char
q
:
{
'\''
,
'"'
})
{
{
auto
p
=
value
.
find
(
q
);
// see if we can use the quote character
auto
p
=
value
.
find
(
q
);
// see if we can use the quote character
while
(
p
!=
string
::
npos
and
isNonBlank
(
value
[
p
+
1
])
and
value
[
p
+
1
]
!=
q
)
while
(
p
!=
st
d
::
st
ring
::
npos
and
isNonBlank
(
value
[
p
+
1
])
and
value
[
p
+
1
]
!=
q
)
p
=
value
.
find
(
q
,
p
+
1
);
p
=
value
.
find
(
q
,
p
+
1
);
if
(
p
!=
string
::
npos
)
if
(
p
!=
st
d
::
st
ring
::
npos
)
continue
;
continue
;
os
<<
q
<<
value
<<
q
;
os
<<
q
<<
value
<<
q
;
if
(
value
.
length
()
+
2
<
width
)
if
(
value
.
length
()
+
2
<
width
)
{
{
os
<<
string
(
width
-
value
.
length
()
-
2
,
' '
);
os
<<
st
d
::
st
ring
(
width
-
value
.
length
()
-
2
,
' '
);
offset
+=
width
;
offset
+=
width
;
}
}
else
else
...
@@ -2087,9 +2086,9 @@ size_t writeValue(ostream& os, string value, size_t offset, size_t width)
...
@@ -2087,9 +2086,9 @@ size_t writeValue(ostream& os, string value, size_t offset, size_t width)
if
(
not
done
)
if
(
not
done
)
{
{
if
(
offset
>
0
)
if
(
offset
>
0
)
os
<<
endl
;
os
<<
std
::
endl
;
os
<<
';'
<<
value
<<
endl
os
<<
';'
<<
value
<<
std
::
endl
<<
';'
<<
endl
;
<<
';'
<<
std
::
endl
;
offset
=
0
;
offset
=
0
;
}
}
}
}
...
@@ -2099,7 +2098,7 @@ size_t writeValue(ostream& os, string value, size_t offset, size_t width)
...
@@ -2099,7 +2098,7 @@ size_t writeValue(ostream& os, string value, size_t offset, size_t width)
}
}
void
Category
::
write
(
ostream
&
os
,
const
vector
<
int
>&
order
,
bool
includeEmptyColumns
)
void
Category
::
write
(
std
::
ostream
&
os
,
const
std
::
vector
<
int
>&
order
,
bool
includeEmptyColumns
)
{
{
if
(
empty
())
if
(
empty
())
return
;
return
;
...
@@ -2109,14 +2108,14 @@ void Category::write(ostream& os, const vector<int>& order, bool includeEmptyCol
...
@@ -2109,14 +2108,14 @@ void Category::write(ostream& os, const vector<int>& order, bool includeEmptyCol
if
(
needLoop
)
if
(
needLoop
)
{
{
os
<<
"loop_"
<<
endl
;
os
<<
"loop_"
<<
std
::
endl
;
vector
<
size_t
>
columnWidths
;
std
::
vector
<
size_t
>
columnWidths
;
for
(
auto
cix
:
order
)
for
(
auto
cix
:
order
)
{
{
auto
&
col
=
mColumns
[
cix
];
auto
&
col
=
mColumns
[
cix
];
os
<<
'_'
<<
mName
<<
'.'
<<
col
.
mName
<<
' '
<<
endl
;
os
<<
'_'
<<
mName
<<
'.'
<<
col
.
mName
<<
' '
<<
std
::
endl
;
columnWidths
.
push_back
(
2
);
columnWidths
.
push_back
(
2
);
}
}
...
@@ -2148,7 +2147,7 @@ void Category::write(ostream& os, const vector<int>& order, bool includeEmptyCol
...
@@ -2148,7 +2147,7 @@ void Category::write(ostream& os, const vector<int>& order, bool includeEmptyCol
{
{
size_t
w
=
columnWidths
[
cix
];
size_t
w
=
columnWidths
[
cix
];
string
s
;
st
d
::
st
ring
s
;
for
(
auto
iv
=
Row
->
mValues
;
iv
!=
nullptr
;
iv
=
iv
->
mNext
)
for
(
auto
iv
=
Row
->
mValues
;
iv
!=
nullptr
;
iv
=
iv
->
mNext
)
{
{
if
(
iv
->
mColumnIndex
==
cix
)
if
(
iv
->
mColumnIndex
==
cix
)
...
@@ -2169,7 +2168,7 @@ void Category::write(ostream& os, const vector<int>& order, bool includeEmptyCol
...
@@ -2169,7 +2168,7 @@ void Category::write(ostream& os, const vector<int>& order, bool includeEmptyCol
if
(
offset
+
l
>=
132
and
offset
>
0
)
if
(
offset
+
l
>=
132
and
offset
>
0
)
{
{
os
<<
endl
;
os
<<
std
::
endl
;
offset
=
0
;
offset
=
0
;
}
}
...
@@ -2177,13 +2176,13 @@ void Category::write(ostream& os, const vector<int>& order, bool includeEmptyCol
...
@@ -2177,13 +2176,13 @@ void Category::write(ostream& os, const vector<int>& order, bool includeEmptyCol
if
(
offset
>=
132
)
if
(
offset
>=
132
)
{
{
os
<<
endl
;
os
<<
std
::
endl
;
offset
=
0
;
offset
=
0
;
}
}
}
}
if
(
offset
>
0
)
if
(
offset
>
0
)
os
<<
endl
;
os
<<
std
::
endl
;
}
}
}
}
else
else
...
@@ -2193,7 +2192,7 @@ void Category::write(ostream& os, const vector<int>& order, bool includeEmptyCol
...
@@ -2193,7 +2192,7 @@ void Category::write(ostream& os, const vector<int>& order, bool includeEmptyCol
for
(
auto
&
col
:
mColumns
)
for
(
auto
&
col
:
mColumns
)
{
{
string
tag
=
'_'
+
mName
+
'.'
+
col
.
mName
;
st
d
::
st
ring
tag
=
'_'
+
mName
+
'.'
+
col
.
mName
;
if
(
l
<
tag
.
length
())
if
(
l
<
tag
.
length
())
l
=
tag
.
length
();
l
=
tag
.
length
();
...
@@ -2205,9 +2204,9 @@ void Category::write(ostream& os, const vector<int>& order, bool includeEmptyCol
...
@@ -2205,9 +2204,9 @@ void Category::write(ostream& os, const vector<int>& order, bool includeEmptyCol
{
{
auto
&
col
=
mColumns
[
cix
];
auto
&
col
=
mColumns
[
cix
];
os
<<
'_'
<<
mName
<<
'.'
<<
col
.
mName
<<
string
(
l
-
col
.
mName
.
length
()
-
mName
.
length
()
-
2
,
' '
);
os
<<
'_'
<<
mName
<<
'.'
<<
col
.
mName
<<
st
d
::
st
ring
(
l
-
col
.
mName
.
length
()
-
mName
.
length
()
-
2
,
' '
);
string
s
;
st
d
::
st
ring
s
;
for
(
auto
iv
=
mHead
->
mValues
;
iv
!=
nullptr
;
iv
=
iv
->
mNext
)
for
(
auto
iv
=
mHead
->
mValues
;
iv
!=
nullptr
;
iv
=
iv
->
mNext
)
{
{
if
(
iv
->
mColumnIndex
==
cix
)
if
(
iv
->
mColumnIndex
==
cix
)
...
@@ -2223,32 +2222,32 @@ void Category::write(ostream& os, const vector<int>& order, bool includeEmptyCol
...
@@ -2223,32 +2222,32 @@ void Category::write(ostream& os, const vector<int>& order, bool includeEmptyCol
size_t
offset
=
l
;
size_t
offset
=
l
;
if
(
s
.
length
()
+
l
>=
kMaxLineLength
)
if
(
s
.
length
()
+
l
>=
kMaxLineLength
)
{
{
os
<<
endl
;
os
<<
std
::
endl
;
offset
=
0
;
offset
=
0
;
}
}
if
(
detail
::
writeValue
(
os
,
s
,
offset
,
1
)
!=
0
)
if
(
detail
::
writeValue
(
os
,
s
,
offset
,
1
)
!=
0
)
os
<<
endl
;
os
<<
std
::
endl
;
}
}
}
}
os
<<
"# "
<<
endl
;
os
<<
"# "
<<
std
::
endl
;
}
}
void
Category
::
write
(
ostream
&
os
)
void
Category
::
write
(
std
::
ostream
&
os
)
{
{
vector
<
int
>
order
(
mColumns
.
size
());
std
::
vector
<
int
>
order
(
mColumns
.
size
());
iota
(
order
.
begin
(),
order
.
end
(),
0
);
iota
(
order
.
begin
(),
order
.
end
(),
0
);
write
(
os
,
order
,
false
);
write
(
os
,
order
,
false
);
}
}
void
Category
::
write
(
ostream
&
os
,
const
vector
<
string
>&
columns
)
void
Category
::
write
(
std
::
ostream
&
os
,
const
std
::
vector
<
std
::
string
>&
columns
)
{
{
// make sure all columns are present
// make sure all columns are present
for
(
auto
&
c
:
columns
)
for
(
auto
&
c
:
columns
)
addColumn
(
c
);
addColumn
(
c
);
vector
<
int
>
order
;
std
::
vector
<
int
>
order
;
order
.
reserve
(
mColumns
.
size
());
order
.
reserve
(
mColumns
.
size
());
for
(
auto
&
c
:
columns
)
for
(
auto
&
c
:
columns
)
...
@@ -2307,15 +2306,15 @@ void Row::assign(const std::vector<Item>& values)
...
@@ -2307,15 +2306,15 @@ void Row::assign(const std::vector<Item>& values)
{
{
auto
cat
=
mData
->
mCategory
;
auto
cat
=
mData
->
mCategory
;
map
<
string
,
tuple
<
int
,
string
,
string
>>
changed
;
std
::
map
<
std
::
string
,
std
::
tuple
<
int
,
std
::
string
,
std
::
string
>>
changed
;
for
(
auto
&
value
:
values
)
for
(
auto
&
value
:
values
)
{
{
auto
columnIx
=
cat
->
addColumn
(
value
.
name
());
auto
columnIx
=
cat
->
addColumn
(
value
.
name
());
auto
&
col
=
cat
->
mColumns
[
columnIx
];
auto
&
col
=
cat
->
mColumns
[
columnIx
];
st
ring
tag
=
col
.
mValidator
?
col
.
mValidator
->
mTag
:
to_string
(
columnIx
);
st
d
::
string
tag
=
col
.
mValidator
?
col
.
mValidator
->
mTag
:
std
::
to_string
(
columnIx
);
changed
[
tag
]
=
make_tuple
(
columnIx
,
operator
[](
columnIx
).
c_str
(),
value
.
value
());
changed
[
tag
]
=
std
::
make_tuple
(
columnIx
,
operator
[](
columnIx
).
c_str
(),
value
.
value
());
assign
(
columnIx
,
value
.
value
(),
true
);
assign
(
columnIx
,
value
.
value
(),
true
);
}
}
...
@@ -2337,29 +2336,29 @@ void Row::assign(const std::vector<Item>& values)
...
@@ -2337,29 +2336,29 @@ void Row::assign(const std::vector<Item>& values)
// continue;
// continue;
Condition
cond
;
Condition
cond
;
string
childTag
;
st
d
::
st
ring
childTag
;
vector
<
Item
>
newValues
;
std
::
vector
<
Item
>
newValues
;
for
(
size_t
ix
=
0
;
ix
<
linked
->
mParentKeys
.
size
();
++
ix
)
for
(
size_t
ix
=
0
;
ix
<
linked
->
mParentKeys
.
size
();
++
ix
)
{
{
string
pk
=
linked
->
mParentKeys
[
ix
];
st
d
::
st
ring
pk
=
linked
->
mParentKeys
[
ix
];
string
ck
=
linked
->
mChildKeys
[
ix
];
st
d
::
st
ring
ck
=
linked
->
mChildKeys
[
ix
];
if
(
changed
.
count
(
pk
)
>
0
)
if
(
changed
.
count
(
pk
)
>
0
)
{
{
childTag
=
ck
;
childTag
=
ck
;
cond
=
move
(
cond
)
&&
(
Key
(
ck
)
==
std
::
get
<
1
>
(
changed
[
pk
]));
cond
=
std
::
move
(
cond
)
&&
(
Key
(
ck
)
==
std
::
get
<
1
>
(
changed
[
pk
]));
newValues
.
emplace_back
(
ck
,
std
::
get
<
2
>
(
changed
[
pk
]));
newValues
.
emplace_back
(
ck
,
std
::
get
<
2
>
(
changed
[
pk
]));
}
}
else
else
{
{
const
char
*
value
=
(
*
this
)[
pk
].
c_str
();
const
char
*
value
=
(
*
this
)[
pk
].
c_str
();
cond
=
move
(
cond
)
&&
(
Key
(
ck
)
==
value
);
cond
=
std
::
move
(
cond
)
&&
(
Key
(
ck
)
==
value
);
}
}
}
}
auto
rows
=
childCat
->
find
(
move
(
cond
));
auto
rows
=
childCat
->
find
(
std
::
move
(
cond
));
for
(
auto
&
cr
:
rows
)
for
(
auto
&
cr
:
rows
)
cr
.
assign
(
newValues
);
cr
.
assign
(
newValues
);
}
}
...
@@ -2371,24 +2370,24 @@ void Row::assign(const Item& value, bool skipUpdateLinked)
...
@@ -2371,24 +2370,24 @@ void Row::assign(const Item& value, bool skipUpdateLinked)
assign
(
value
.
name
(),
value
.
value
(),
skipUpdateLinked
);
assign
(
value
.
name
(),
value
.
value
(),
skipUpdateLinked
);
}
}
void
Row
::
assign
(
const
st
ring
&
name
,
const
string
&
value
,
bool
skipUpdateLinked
)
void
Row
::
assign
(
const
st
d
::
string
&
name
,
const
std
::
string
&
value
,
bool
skipUpdateLinked
)
{
{
try
try
{
{
auto
cat
=
mData
->
mCategory
;
auto
cat
=
mData
->
mCategory
;
assign
(
cat
->
addColumn
(
name
),
value
,
skipUpdateLinked
);
assign
(
cat
->
addColumn
(
name
),
value
,
skipUpdateLinked
);
}
}
catch
(
const
exception
&
ex
)
catch
(
const
std
::
exception
&
ex
)
{
{
cerr
<<
"Could not assign value '"
<<
value
<<
"' to column _"
<<
mData
->
mCategory
->
name
()
<<
'.'
<<
name
<<
endl
;
std
::
cerr
<<
"Could not assign value '"
<<
value
<<
"' to column _"
<<
mData
->
mCategory
->
name
()
<<
'.'
<<
name
<<
std
::
endl
;
throw
;
throw
;
}
}
}
}
void
Row
::
assign
(
size_t
column
,
const
string
&
value
,
bool
skipUpdateLinked
)
void
Row
::
assign
(
size_t
column
,
const
st
d
::
st
ring
&
value
,
bool
skipUpdateLinked
)
{
{
if
(
mData
==
nullptr
)
if
(
mData
==
nullptr
)
throw
logic_error
(
"invalid Row, no data assigning value '"
+
value
+
"' to column with index "
+
to_string
(
column
));
throw
std
::
logic_error
(
"invalid Row, no data assigning value '"
+
value
+
"' to column with index "
+
std
::
to_string
(
column
));
auto
cat
=
mData
->
mCategory
;
auto
cat
=
mData
->
mCategory
;
auto
&
col
=
cat
->
mColumns
[
column
];
auto
&
col
=
cat
->
mColumns
[
column
];
...
@@ -2408,7 +2407,7 @@ void Row::assign(size_t column, const string& value, bool skipUpdateLinked)
...
@@ -2408,7 +2407,7 @@ void Row::assign(size_t column, const string& value, bool skipUpdateLinked)
if
(
oldValue
!=
nullptr
and
value
==
oldValue
)
// no need to update
if
(
oldValue
!=
nullptr
and
value
==
oldValue
)
// no need to update
return
;
return
;
string
oldStrValue
=
oldValue
?
oldValue
:
""
;
st
d
::
st
ring
oldStrValue
=
oldValue
?
oldValue
:
""
;
// check the value
// check the value
if
(
col
.
mValidator
)
if
(
col
.
mValidator
)
...
@@ -2489,35 +2488,35 @@ void Row::assign(size_t column, const string& value, bool skipUpdateLinked)
...
@@ -2489,35 +2488,35 @@ void Row::assign(size_t column, const string& value, bool skipUpdateLinked)
continue
;
continue
;
Condition
cond
;
Condition
cond
;
string
childTag
;
st
d
::
st
ring
childTag
;
for
(
size_t
ix
=
0
;
ix
<
linked
->
mParentKeys
.
size
();
++
ix
)
for
(
size_t
ix
=
0
;
ix
<
linked
->
mParentKeys
.
size
();
++
ix
)
{
{
string
pk
=
linked
->
mParentKeys
[
ix
];
st
d
::
st
ring
pk
=
linked
->
mParentKeys
[
ix
];
string
ck
=
linked
->
mChildKeys
[
ix
];
st
d
::
st
ring
ck
=
linked
->
mChildKeys
[
ix
];
// TODO add code to *NOT* test mandatory fiels for Empty
// TODO add code to *NOT* test mandatory fiels for Empty
if
(
pk
==
iv
->
mTag
)
if
(
pk
==
iv
->
mTag
)
{
{
childTag
=
ck
;
childTag
=
ck
;
cond
=
move
(
cond
)
&&
((
Key
(
ck
)
==
oldStrValue
)
or
Key
(
ck
)
==
Empty
());
cond
=
std
::
move
(
cond
)
&&
((
Key
(
ck
)
==
oldStrValue
)
or
Key
(
ck
)
==
Empty
());
}
}
else
else
{
{
const
char
*
value
=
(
*
this
)[
pk
].
c_str
();
const
char
*
value
=
(
*
this
)[
pk
].
c_str
();
cond
=
move
(
cond
)
&&
((
Key
(
ck
)
==
value
)
or
Key
(
ck
)
==
Empty
());
cond
=
std
::
move
(
cond
)
&&
((
Key
(
ck
)
==
value
)
or
Key
(
ck
)
==
Empty
());
}
}
}
}
// if (cif::VERBOSE > 2)
// if (cif::VERBOSE > 2)
// {
// {
// std::
cerr << "Parent: " << linked->mParentCategory << " Child: " << linked->mChildCategory <<
std::endl
// std::
std::cerr << "Parent: " << linked->mParentCategory << " Child: " << linked->mChildCategory << std::
std::endl
// << cond << std::endl;
// << cond << std::
std::
endl;
// }
// }
auto
rows
=
childCat
->
find
(
move
(
cond
));
auto
rows
=
childCat
->
find
(
std
::
move
(
cond
));
for
(
auto
&
cr
:
rows
)
for
(
auto
&
cr
:
rows
)
cr
.
assign
(
childTag
,
value
,
false
);
cr
.
assign
(
childTag
,
value
,
false
);
}
}
...
@@ -2527,11 +2526,11 @@ void Row::assign(size_t column, const string& value, bool skipUpdateLinked)
...
@@ -2527,11 +2526,11 @@ void Row::assign(size_t column, const string& value, bool skipUpdateLinked)
void
Row
::
swap
(
size_t
cix
,
ItemRow
*
a
,
ItemRow
*
b
)
void
Row
::
swap
(
size_t
cix
,
ItemRow
*
a
,
ItemRow
*
b
)
{
{
if
(
a
==
nullptr
or
b
==
nullptr
)
if
(
a
==
nullptr
or
b
==
nullptr
)
throw
logic_error
(
"invalid Rows in swap"
);
throw
std
::
logic_error
(
"invalid Rows in swap"
);
assert
(
a
->
mCategory
==
b
->
mCategory
);
assert
(
a
->
mCategory
==
b
->
mCategory
);
if
(
a
->
mCategory
!=
b
->
mCategory
)
if
(
a
->
mCategory
!=
b
->
mCategory
)
throw
logic_error
(
"Categories not same in swap"
);
throw
std
::
logic_error
(
"Categories not same in swap"
);
auto
cat
=
a
->
mCategory
;
auto
cat
=
a
->
mCategory
;
...
@@ -2642,7 +2641,7 @@ void Row::swap(size_t cix, ItemRow* a, ItemRow* b)
...
@@ -2642,7 +2641,7 @@ void Row::swap(size_t cix, ItemRow* a, ItemRow* b)
if
(
childCatValidator
==
nullptr
)
if
(
childCatValidator
==
nullptr
)
continue
;
continue
;
string
linkChildColName
;
st
d
::
st
ring
linkChildColName
;
Condition
cond
[
2
];
Condition
cond
[
2
];
for
(
size_t
ab
=
0
;
ab
<
2
;
++
ab
)
for
(
size_t
ab
=
0
;
ab
<
2
;
++
ab
)
...
@@ -2660,7 +2659,7 @@ void Row::swap(size_t cix, ItemRow* a, ItemRow* b)
...
@@ -2660,7 +2659,7 @@ void Row::swap(size_t cix, ItemRow* a, ItemRow* b)
find
(
childCatValidator
->
mMandatoryFields
.
begin
(),
childCatValidator
->
mMandatoryFields
.
end
(),
childColName
)
!=
childCatValidator
->
mMandatoryFields
.
end
()
or
find
(
childCatValidator
->
mMandatoryFields
.
begin
(),
childCatValidator
->
mMandatoryFields
.
end
(),
childColName
)
!=
childCatValidator
->
mMandatoryFields
.
end
()
or
find
(
parentCatValidator
->
mMandatoryFields
.
begin
(),
parentCatValidator
->
mMandatoryFields
.
end
(),
link
->
mParentKeys
[
ix
])
!=
parentCatValidator
->
mMandatoryFields
.
end
();
find
(
parentCatValidator
->
mMandatoryFields
.
begin
(),
parentCatValidator
->
mMandatoryFields
.
end
(),
link
->
mParentKeys
[
ix
])
!=
parentCatValidator
->
mMandatoryFields
.
end
();
string
childValue
;
st
d
::
st
ring
childValue
;
if
(
pcix
==
cix
)
if
(
pcix
==
cix
)
{
{
...
@@ -2670,7 +2669,7 @@ void Row::swap(size_t cix, ItemRow* a, ItemRow* b)
...
@@ -2670,7 +2669,7 @@ void Row::swap(size_t cix, ItemRow* a, ItemRow* b)
}
}
else
else
{
{
string
ps
=
r
->
c_str
(
pcix
);
st
d
::
st
ring
ps
=
r
->
c_str
(
pcix
);
if
(
not
(
ps
.
empty
()
or
ps
==
"."
or
ps
==
"?"
))
if
(
not
(
ps
.
empty
()
or
ps
==
"."
or
ps
==
"?"
))
childValue
=
ps
;
childValue
=
ps
;
}
}
...
@@ -2678,12 +2677,12 @@ void Row::swap(size_t cix, ItemRow* a, ItemRow* b)
...
@@ -2678,12 +2677,12 @@ void Row::swap(size_t cix, ItemRow* a, ItemRow* b)
if
(
not
childValue
.
empty
())
if
(
not
childValue
.
empty
())
{
{
if
(
mandatory
or
pcix
==
cix
)
if
(
mandatory
or
pcix
==
cix
)
cond
[
ab
]
=
move
(
cond
[
ab
])
and
Key
(
childColName
)
==
childValue
;
cond
[
ab
]
=
std
::
move
(
cond
[
ab
])
and
Key
(
childColName
)
==
childValue
;
else
else
cond
[
ab
]
=
move
(
cond
[
ab
])
and
(
Key
(
childColName
)
==
childValue
or
Key
(
childColName
)
==
Empty
());
cond
[
ab
]
=
std
::
move
(
cond
[
ab
])
and
(
Key
(
childColName
)
==
childValue
or
Key
(
childColName
)
==
Empty
());
}
}
else
else
cond
[
ab
]
=
move
(
cond
[
ab
])
and
Key
(
childColName
)
==
Empty
();
cond
[
ab
]
=
std
::
move
(
cond
[
ab
])
and
Key
(
childColName
)
==
Empty
();
}
}
}
}
...
@@ -2696,10 +2695,10 @@ void Row::swap(size_t cix, ItemRow* a, ItemRow* b)
...
@@ -2696,10 +2695,10 @@ void Row::swap(size_t cix, ItemRow* a, ItemRow* b)
continue
;
continue
;
if
(
VERBOSE
>
1
)
if
(
VERBOSE
>
1
)
cerr
<<
"Fixing link from "
<<
cat
->
mName
<<
" to "
<<
childCat
->
mName
<<
" with "
<<
endl
std
::
cerr
<<
"Fixing link from "
<<
cat
->
mName
<<
" to "
<<
childCat
->
mName
<<
" with "
<<
std
::
endl
<<
cond
[
ab
]
<<
endl
;
<<
cond
[
ab
]
<<
std
::
endl
;
rs
.
push_back
(
childCat
->
find
(
move
(
cond
[
ab
])));
rs
.
push_back
(
childCat
->
find
(
std
::
move
(
cond
[
ab
])));
}
}
for
(
size_t
ab
=
0
;
ab
<
2
;
++
ab
)
for
(
size_t
ab
=
0
;
ab
<
2
;
++
ab
)
...
@@ -2720,12 +2719,12 @@ void Row::swap(size_t cix, ItemRow* a, ItemRow* b)
...
@@ -2720,12 +2719,12 @@ void Row::swap(size_t cix, ItemRow* a, ItemRow* b)
if
(
n
==
link
->
mChildKeys
.
size
())
if
(
n
==
link
->
mChildKeys
.
size
())
{
{
if
(
VERBOSE
>
1
)
if
(
VERBOSE
>
1
)
cerr
<<
"All empty columns, skipping"
<<
endl
;
std
::
cerr
<<
"All empty columns, skipping"
<<
std
::
endl
;
}
}
else
else
{
{
if
(
VERBOSE
)
if
(
VERBOSE
)
cerr
<<
"In "
<<
childCat
->
mName
<<
" changing "
<<
linkChildColName
<<
": "
<<
r
[
linkChildColName
]
<<
" => "
<<
(
i
?
i
->
mText
:
""
)
<<
endl
;
std
::
cerr
<<
"In "
<<
childCat
->
mName
<<
" changing "
<<
linkChildColName
<<
": "
<<
r
[
linkChildColName
]
<<
" => "
<<
(
i
?
i
->
mText
:
""
)
<<
std
::
endl
;
r
[
linkChildColName
]
=
i
?
i
->
mText
:
""
;
r
[
linkChildColName
]
=
i
?
i
->
mText
:
""
;
}
}
}
}
...
@@ -2800,11 +2799,11 @@ void Row::const_iterator::fetch()
...
@@ -2800,11 +2799,11 @@ void Row::const_iterator::fetch()
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
Row
&
row
)
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
Row
&
row
)
{
{
auto
category
=
row
.
mData
->
mCategory
;
auto
category
=
row
.
mData
->
mCategory
;
string
catName
=
category
->
name
();
st
d
::
st
ring
catName
=
category
->
name
();
for
(
auto
item
=
row
.
mData
->
mValues
;
item
!=
nullptr
;
item
=
item
->
mNext
)
for
(
auto
item
=
row
.
mData
->
mValues
;
item
!=
nullptr
;
item
=
item
->
mNext
)
{
{
string
tagName
=
category
->
getColumnName
(
item
->
mColumnIndex
);
st
d
::
st
ring
tagName
=
category
->
getColumnName
(
item
->
mColumnIndex
);
os
<<
'_'
<<
catName
<<
'.'
<<
tagName
<<
' '
<<
item
->
mText
<<
endl
;
os
<<
'_'
<<
catName
<<
'.'
<<
tagName
<<
' '
<<
item
->
mText
<<
std
::
endl
;
}
}
return
os
;
return
os
;
...
@@ -2818,7 +2817,7 @@ File::File()
...
@@ -2818,7 +2817,7 @@ File::File()
{
{
}
}
File
::
File
(
istream
&
is
,
bool
validate
)
File
::
File
(
std
::
istream
&
is
,
bool
validate
)
:
File
()
:
File
()
{
{
load
(
is
);
load
(
is
);
...
@@ -2831,9 +2830,9 @@ File::File(const std::string& path, bool validate)
...
@@ -2831,9 +2830,9 @@ File::File(const std::string& path, bool validate)
{
{
load
(
path
);
load
(
path
);
}
}
catch
(
const
exception
&
ex
)
catch
(
const
std
::
exception
&
ex
)
{
{
cerr
<<
"Error while loading file "
<<
path
<<
endl
;
std
::
cerr
<<
"Error while loading file "
<<
path
<<
std
::
endl
;
throw
;
throw
;
}
}
}
}
...
@@ -2880,9 +2879,9 @@ void File::load(const std::string& p)
...
@@ -2880,9 +2879,9 @@ void File::load(const std::string& p)
{
{
fs
::
path
path
(
p
);
fs
::
path
path
(
p
);
std
::
ifstream
inFile
(
p
,
ios_base
::
in
|
ios_base
::
binary
);
std
::
ifstream
inFile
(
p
,
std
::
ios_base
::
in
|
std
::
ios_base
::
binary
);
if
(
not
inFile
.
is_open
())
if
(
not
inFile
.
is_open
())
throw
runtime_error
(
"Could not open file: "
+
path
.
string
());
throw
std
::
runtime_error
(
"Could not open file: "
+
path
.
string
());
io
::
filtering_stream
<
io
::
input
>
in
;
io
::
filtering_stream
<
io
::
input
>
in
;
std
::
string
ext
;
std
::
string
ext
;
...
@@ -2904,9 +2903,9 @@ void File::load(const std::string& p)
...
@@ -2904,9 +2903,9 @@ void File::load(const std::string& p)
{
{
load
(
in
);
load
(
in
);
}
}
catch
(
const
exception
&
ex
)
catch
(
const
std
::
exception
&
ex
)
{
{
cerr
<<
"Error loading file "
<<
path
<<
endl
;
std
::
cerr
<<
"Error loading file "
<<
path
<<
std
::
endl
;
throw
;
throw
;
}
}
}
}
...
@@ -2915,7 +2914,7 @@ void File::save(const std::string& p)
...
@@ -2915,7 +2914,7 @@ void File::save(const std::string& p)
{
{
fs
::
path
path
(
p
);
fs
::
path
path
(
p
);
std
::
ofstream
outFile
(
p
,
ios_base
::
out
|
ios_base
::
binary
);
std
::
ofstream
outFile
(
p
,
std
::
ios_base
::
out
|
std
::
ios_base
::
binary
);
io
::
filtering_stream
<
io
::
output
>
out
;
io
::
filtering_stream
<
io
::
output
>
out
;
if
(
path
.
extension
()
==
".gz"
)
if
(
path
.
extension
()
==
".gz"
)
...
@@ -2933,7 +2932,7 @@ void File::save(const std::string& p)
...
@@ -2933,7 +2932,7 @@ void File::save(const std::string& p)
save
(
out
);
save
(
out
);
}
}
void
File
::
load
(
istream
&
is
)
void
File
::
load
(
std
::
istream
&
is
)
{
{
Validator
*
saved
=
mValidator
;
Validator
*
saved
=
mValidator
;
setValidator
(
nullptr
);
setValidator
(
nullptr
);
...
@@ -2948,7 +2947,7 @@ void File::load(istream& is)
...
@@ -2948,7 +2947,7 @@ void File::load(istream& is)
}
}
}
}
void
File
::
save
(
ostream
&
os
)
void
File
::
save
(
std
::
ostream
&
os
)
{
{
Datablock
*
e
=
mHead
;
Datablock
*
e
=
mHead
;
while
(
e
!=
nullptr
)
while
(
e
!=
nullptr
)
...
@@ -2958,7 +2957,7 @@ void File::save(ostream& os)
...
@@ -2958,7 +2957,7 @@ void File::save(ostream& os)
}
}
}
}
void
File
::
write
(
ostream
&
os
,
const
vector
<
string
>&
order
)
void
File
::
write
(
std
::
ostream
&
os
,
const
std
::
vector
<
std
::
string
>&
order
)
{
{
Datablock
*
e
=
mHead
;
Datablock
*
e
=
mHead
;
while
(
e
!=
nullptr
)
while
(
e
!=
nullptr
)
...
@@ -2968,7 +2967,7 @@ void File::write(ostream& os, const vector<string>& order)
...
@@ -2968,7 +2967,7 @@ void File::write(ostream& os, const vector<string>& order)
}
}
}
}
Datablock
*
File
::
get
(
const
string
&
name
)
const
Datablock
*
File
::
get
(
const
st
d
::
st
ring
&
name
)
const
{
{
const
Datablock
*
result
=
mHead
;
const
Datablock
*
result
=
mHead
;
while
(
result
!=
nullptr
and
not
iequals
(
result
->
mName
,
name
))
while
(
result
!=
nullptr
and
not
iequals
(
result
->
mName
,
name
))
...
@@ -2976,13 +2975,13 @@ Datablock* File::get(const string& name) const
...
@@ -2976,13 +2975,13 @@ Datablock* File::get(const string& name) const
return
const_cast
<
Datablock
*>
(
result
);
return
const_cast
<
Datablock
*>
(
result
);
}
}
Datablock
&
File
::
operator
[](
const
string
&
name
)
Datablock
&
File
::
operator
[](
const
st
d
::
st
ring
&
name
)
{
{
Datablock
*
result
=
mHead
;
Datablock
*
result
=
mHead
;
while
(
result
!=
nullptr
and
not
iequals
(
result
->
mName
,
name
))
while
(
result
!=
nullptr
and
not
iequals
(
result
->
mName
,
name
))
result
=
result
->
mNext
;
result
=
result
->
mNext
;
if
(
result
==
nullptr
)
if
(
result
==
nullptr
)
throw
runtime_error
(
"Datablock "
+
name
+
" does not exist"
);
throw
std
::
runtime_error
(
"Datablock "
+
name
+
" does not exist"
);
return
*
result
;
return
*
result
;
}
}
...
@@ -2991,7 +2990,7 @@ bool File::isValid()
...
@@ -2991,7 +2990,7 @@ bool File::isValid()
if
(
mValidator
==
nullptr
)
if
(
mValidator
==
nullptr
)
{
{
if
(
VERBOSE
)
if
(
VERBOSE
)
cerr
<<
"No dictionary loaded explicitly, loading default"
<<
endl
;
std
::
cerr
<<
"No dictionary loaded explicitly, loading default"
<<
std
::
endl
;
loadDictionary
();
loadDictionary
();
}
}
...
@@ -3011,7 +3010,7 @@ void File::validateLinks() const
...
@@ -3011,7 +3010,7 @@ void File::validateLinks() const
const
Validator
&
File
::
getValidator
()
const
const
Validator
&
File
::
getValidator
()
const
{
{
if
(
mValidator
==
nullptr
)
if
(
mValidator
==
nullptr
)
throw
runtime_error
(
"no Validator defined yet"
);
throw
std
::
runtime_error
(
"no Validator defined yet"
);
return
*
mValidator
;
return
*
mValidator
;
}
}
...
@@ -3037,7 +3036,7 @@ void File::loadDictionary(const char* dict)
...
@@ -3037,7 +3036,7 @@ void File::loadDictionary(const char* dict)
}
}
catch
(...)
{}
catch
(...)
{}
fs
::
path
dictFile
=
string
(
"dictionaries/"
)
+
dict
+
".dic"
;
fs
::
path
dictFile
=
st
d
::
st
ring
(
"dictionaries/"
)
+
dict
+
".dic"
;
try
try
{
{
...
@@ -3054,7 +3053,7 @@ void File::loadDictionary(const char* dict)
...
@@ -3054,7 +3053,7 @@ void File::loadDictionary(const char* dict)
if
(
dictData
)
if
(
dictData
)
{
{
struct
membuf
:
public
streambuf
struct
membuf
:
public
st
d
::
st
reambuf
{
{
membuf
(
char
*
dict
,
size_t
length
)
membuf
(
char
*
dict
,
size_t
length
)
{
{
...
@@ -3062,19 +3061,19 @@ void File::loadDictionary(const char* dict)
...
@@ -3062,19 +3061,19 @@ void File::loadDictionary(const char* dict)
}
}
}
buffer
(
const_cast
<
char
*>
(
dictData
.
data
()),
dictData
.
size
());
}
buffer
(
const_cast
<
char
*>
(
dictData
.
data
()),
dictData
.
size
());
istream
is
(
&
buffer
);
std
::
istream
is
(
&
buffer
);
loadDictionary
(
is
);
loadDictionary
(
is
);
break
;
break
;
}
}
throw
runtime_error
(
"Dictionary not found or defined ("
+
name
.
string
()
+
")"
);
throw
std
::
runtime_error
(
"Dictionary not found or defined ("
+
name
.
string
()
+
")"
);
}
}
}
}
void
File
::
loadDictionary
(
istream
&
is
)
void
File
::
loadDictionary
(
std
::
istream
&
is
)
{
{
unique_ptr
<
Validator
>
v
(
new
Validator
());
std
::
unique_ptr
<
Validator
>
v
(
new
Validator
());
DictParser
p
(
*
v
,
is
);
DictParser
p
(
*
v
,
is
);
p
.
loadDictionary
();
p
.
loadDictionary
();
...
@@ -3090,7 +3089,7 @@ void File::setValidator(Validator* v)
...
@@ -3090,7 +3089,7 @@ void File::setValidator(Validator* v)
d
->
setValidator
(
mValidator
);
d
->
setValidator
(
mValidator
);
}
}
void
File
::
getTagOrder
(
vector
<
string
>&
tags
)
const
void
File
::
getTagOrder
(
std
::
vector
<
std
::
string
>&
tags
)
const
{
{
for
(
auto
d
=
mHead
;
d
!=
nullptr
;
d
=
d
->
mNext
)
for
(
auto
d
=
mHead
;
d
!=
nullptr
;
d
=
d
->
mNext
)
d
->
getTagOrder
(
tags
);
d
->
getTagOrder
(
tags
);
...
...
src/CifParser.cpp
View file @
4b4757ee
...
@@ -32,7 +32,6 @@
...
@@ -32,7 +32,6 @@
#include "cif++/CifParser.hpp"
#include "cif++/CifParser.hpp"
#include "cif++/CifValidator.hpp"
#include "cif++/CifValidator.hpp"
using
namespace
std
;
namespace
ba
=
boost
::
algorithm
;
namespace
ba
=
boost
::
algorithm
;
extern
int
VERBOSE
;
extern
int
VERBOSE
;
...
@@ -54,8 +53,8 @@ const uint8_t kCharTraitsTable[128] = {
...
@@ -54,8 +53,8 @@ const uint8_t kCharTraitsTable[128] = {
// --------------------------------------------------------------------
// --------------------------------------------------------------------
CifParserError
::
CifParserError
(
uint32_t
lineNr
,
const
string
&
message
)
CifParserError
::
CifParserError
(
uint32_t
lineNr
,
const
st
d
::
st
ring
&
message
)
:
runtime_error
(
"parse error at line "
+
to_string
(
lineNr
)
+
": "
+
message
)
:
std
::
runtime_error
(
"parse error at line "
+
std
::
to_string
(
lineNr
)
+
": "
+
message
)
{
{
}
}
...
@@ -94,7 +93,7 @@ SacParser::SacParser(std::istream& is)
...
@@ -94,7 +93,7 @@ SacParser::SacParser(std::istream& is)
mLookahead
=
getNextToken
();
mLookahead
=
getNextToken
();
}
}
void
SacParser
::
error
(
const
string
&
msg
)
void
SacParser
::
error
(
const
st
d
::
st
ring
&
msg
)
{
{
throw
CifParserError
(
mLineNr
,
msg
);
throw
CifParserError
(
mLineNr
,
msg
);
}
}
...
@@ -130,11 +129,11 @@ int SacParser::getNextChar()
...
@@ -130,11 +129,11 @@ int SacParser::getNextChar()
if
(
VERBOSE
>=
6
)
if
(
VERBOSE
>=
6
)
{
{
cerr
<<
"getNextChar => "
;
std
::
cerr
<<
"getNextChar => "
;
if
(
iscntrl
(
result
)
or
not
isprint
(
result
))
if
(
iscntrl
(
result
)
or
not
isprint
(
result
))
cerr
<<
int
(
result
)
<<
endl
;
std
::
cerr
<<
int
(
result
)
<<
std
::
endl
;
else
else
cerr
<<
char
(
result
)
<<
endl
;
std
::
cerr
<<
char
(
result
)
<<
std
::
endl
;
}
}
return
result
;
return
result
;
...
@@ -181,14 +180,14 @@ void SacParser::restart()
...
@@ -181,14 +180,14 @@ void SacParser::restart()
void
SacParser
::
match
(
SacParser
::
CIFToken
t
)
void
SacParser
::
match
(
SacParser
::
CIFToken
t
)
{
{
if
(
mLookahead
!=
t
)
if
(
mLookahead
!=
t
)
error
(
string
(
"Unexpected token, expected "
)
+
kTokenName
[
t
]
+
" but found "
+
kTokenName
[
mLookahead
]);
error
(
st
d
::
st
ring
(
"Unexpected token, expected "
)
+
kTokenName
[
t
]
+
" but found "
+
kTokenName
[
mLookahead
]);
mLookahead
=
getNextToken
();
mLookahead
=
getNextToken
();
}
}
SacParser
::
CIFToken
SacParser
::
getNextToken
()
SacParser
::
CIFToken
SacParser
::
getNextToken
()
{
{
const
auto
kEOF
=
char_traits
<
char
>::
eof
();
const
auto
kEOF
=
std
::
char_traits
<
char
>::
eof
();
CIFToken
result
=
eCIFTokenUnknown
;
CIFToken
result
=
eCIFTokenUnknown
;
int
quoteChar
=
0
;
int
quoteChar
=
0
;
...
@@ -291,7 +290,7 @@ SacParser::CIFToken SacParser::getNextToken()
...
@@ -291,7 +290,7 @@ SacParser::CIFToken SacParser::getNextToken()
error
(
"unterminated textfield"
);
error
(
"unterminated textfield"
);
else
if
(
not
isAnyPrint
(
ch
))
else
if
(
not
isAnyPrint
(
ch
))
// error("invalid character in text field '" + string({ static_cast<char>(ch) }) + "' (" + to_string((int)ch) + ")");
// error("invalid character in text field '" + string({ static_cast<char>(ch) }) + "' (" + to_string((int)ch) + ")");
cerr
<<
"invalid character in text field '"
<<
string
({
static_cast
<
char
>
(
ch
)
})
<<
"' ("
<<
ch
<<
") line: "
<<
mLineNr
<<
endl
;
std
::
cerr
<<
"invalid character in text field '"
<<
std
::
string
({
static_cast
<
char
>
(
ch
)
})
<<
"' ("
<<
ch
<<
") line: "
<<
mLineNr
<<
std
::
endl
;
break
;
break
;
case
eStateTextField
+
1
:
case
eStateTextField
+
1
:
...
@@ -469,7 +468,7 @@ SacParser::CIFToken SacParser::getNextToken()
...
@@ -469,7 +468,7 @@ SacParser::CIFToken SacParser::getNextToken()
case
eStateValue
+
1
:
case
eStateValue
+
1
:
if
(
ch
==
'_'
)
// first _, check for keywords
if
(
ch
==
'_'
)
// first _, check for keywords
{
{
string
s
=
toLowerCopy
(
mTokenValue
);
st
d
::
st
ring
s
=
toLowerCopy
(
mTokenValue
);
if
(
s
==
"global_"
)
if
(
s
==
"global_"
)
result
=
eCIFTokenGLOBAL
;
result
=
eCIFTokenGLOBAL
;
...
@@ -511,12 +510,12 @@ SacParser::CIFToken SacParser::getNextToken()
...
@@ -511,12 +510,12 @@ SacParser::CIFToken SacParser::getNextToken()
if
(
VERBOSE
>=
5
)
if
(
VERBOSE
>=
5
)
{
{
cerr
<<
kTokenName
[
result
];
std
::
cerr
<<
kTokenName
[
result
];
if
(
mTokenType
!=
eCIFValueUnknown
)
if
(
mTokenType
!=
eCIFValueUnknown
)
cerr
<<
' '
<<
kValueName
[
mTokenType
];
std
::
cerr
<<
' '
<<
kValueName
[
mTokenType
];
if
(
result
!=
eCIFTokenEOF
)
if
(
result
!=
eCIFTokenEOF
)
cerr
<<
" '"
<<
mTokenValue
<<
'\''
;
std
::
cerr
<<
" '"
<<
mTokenValue
<<
'\''
;
cerr
<<
endl
;
std
::
cerr
<<
std
::
endl
;
}
}
return
result
;
return
result
;
...
@@ -558,7 +557,7 @@ void SacParser::parseGlobal()
...
@@ -558,7 +557,7 @@ void SacParser::parseGlobal()
void
SacParser
::
parseDataBlock
()
void
SacParser
::
parseDataBlock
()
{
{
string
cat
;
st
d
::
st
ring
cat
;
while
(
mLookahead
==
eCIFTokenLOOP
or
mLookahead
==
eCIFTokenTag
or
mLookahead
==
eCIFTokenSAVE
)
while
(
mLookahead
==
eCIFTokenLOOP
or
mLookahead
==
eCIFTokenTag
or
mLookahead
==
eCIFTokenSAVE
)
{
{
...
@@ -570,11 +569,11 @@ void SacParser::parseDataBlock()
...
@@ -570,11 +569,11 @@ void SacParser::parseDataBlock()
match
(
eCIFTokenLOOP
);
match
(
eCIFTokenLOOP
);
vector
<
string
>
tags
;
std
::
vector
<
std
::
string
>
tags
;
while
(
mLookahead
==
eCIFTokenTag
)
while
(
mLookahead
==
eCIFTokenTag
)
{
{
string
catName
,
itemName
;
st
d
::
st
ring
catName
,
itemName
;
std
::
tie
(
catName
,
itemName
)
=
splitTagName
(
mTokenValue
);
std
::
tie
(
catName
,
itemName
)
=
splitTagName
(
mTokenValue
);
if
(
cat
.
empty
())
if
(
cat
.
empty
())
...
@@ -607,7 +606,7 @@ void SacParser::parseDataBlock()
...
@@ -607,7 +606,7 @@ void SacParser::parseDataBlock()
case
eCIFTokenTag
:
case
eCIFTokenTag
:
{
{
string
catName
,
itemName
;
st
d
::
st
ring
catName
,
itemName
;
std
::
tie
(
catName
,
itemName
)
=
splitTagName
(
mTokenValue
);
std
::
tie
(
catName
,
itemName
)
=
splitTagName
(
mTokenValue
);
if
(
not
iequals
(
cat
,
catName
))
if
(
not
iequals
(
cat
,
catName
))
...
@@ -648,34 +647,34 @@ Parser::Parser(std::istream& is, File& f)
...
@@ -648,34 +647,34 @@ Parser::Parser(std::istream& is, File& f)
{
{
}
}
void
Parser
::
produceDatablock
(
const
string
&
name
)
void
Parser
::
produceDatablock
(
const
st
d
::
st
ring
&
name
)
{
{
mDataBlock
=
new
Datablock
(
name
);
mDataBlock
=
new
Datablock
(
name
);
mFile
.
append
(
mDataBlock
);
mFile
.
append
(
mDataBlock
);
}
}
void
Parser
::
produceCategory
(
const
string
&
name
)
void
Parser
::
produceCategory
(
const
st
d
::
st
ring
&
name
)
{
{
if
(
VERBOSE
>=
4
)
if
(
VERBOSE
>=
4
)
cerr
<<
"producing category "
<<
name
<<
endl
;
std
::
cerr
<<
"producing category "
<<
name
<<
std
::
endl
;
std
::
tie
(
mCat
,
ignore
)
=
mDataBlock
->
emplace
(
name
);
std
::
tie
(
mCat
,
std
::
ignore
)
=
mDataBlock
->
emplace
(
name
);
}
}
void
Parser
::
produceRow
()
void
Parser
::
produceRow
()
{
{
if
(
VERBOSE
>=
4
)
if
(
VERBOSE
>=
4
)
cerr
<<
"producing row for category "
<<
mCat
->
name
()
<<
endl
;
std
::
cerr
<<
"producing row for category "
<<
mCat
->
name
()
<<
std
::
endl
;
mCat
->
emplace
({});
mCat
->
emplace
({});
mRow
=
mCat
->
back
();
mRow
=
mCat
->
back
();
mRow
.
lineNr
(
mLineNr
);
mRow
.
lineNr
(
mLineNr
);
}
}
void
Parser
::
produceItem
(
const
st
ring
&
category
,
const
string
&
item
,
const
string
&
value
)
void
Parser
::
produceItem
(
const
st
d
::
string
&
category
,
const
std
::
string
&
item
,
const
std
::
string
&
value
)
{
{
if
(
VERBOSE
>=
4
)
if
(
VERBOSE
>=
4
)
cerr
<<
"producing _"
<<
category
<<
'.'
<<
item
<<
" -> "
<<
value
<<
endl
;
std
::
cerr
<<
"producing _"
<<
category
<<
'.'
<<
item
<<
" -> "
<<
value
<<
std
::
endl
;
if
(
not
iequals
(
category
,
mCat
->
name
()))
if
(
not
iequals
(
category
,
mCat
->
name
()))
error
(
"inconsistent categories in loop_"
);
error
(
"inconsistent categories in loop_"
);
...
@@ -688,9 +687,9 @@ void Parser::produceItem(const string& category, const string& item, const strin
...
@@ -688,9 +687,9 @@ void Parser::produceItem(const string& category, const string& item, const strin
struct
DictParserDataImpl
struct
DictParserDataImpl
{
{
// temporary values for constructing dictionaries
// temporary values for constructing dictionaries
vector
<
ValidateCategory
>
mCategoryValidators
;
std
::
vector
<
ValidateCategory
>
mCategoryValidators
;
map
<
string
,
vector
<
ValidateItem
>>
mItemValidators
;
std
::
map
<
std
::
string
,
std
::
vector
<
ValidateItem
>>
mItemValidators
;
s
et
<
tuple
<
string
,
string
>>
mLinkedItems
;
s
td
::
set
<
std
::
tuple
<
std
::
string
,
std
::
string
>>
mLinkedItems
;
};
};
DictParser
::
DictParser
(
Validator
&
validator
,
std
::
istream
&
is
)
DictParser
::
DictParser
(
Validator
&
validator
,
std
::
istream
&
is
)
...
@@ -708,7 +707,7 @@ void DictParser::parseSaveFrame()
...
@@ -708,7 +707,7 @@ void DictParser::parseSaveFrame()
if
(
not
mCollectedItemTypes
)
if
(
not
mCollectedItemTypes
)
mCollectedItemTypes
=
collectItemTypes
();
mCollectedItemTypes
=
collectItemTypes
();
string
saveFrameName
=
mTokenValue
;
st
d
::
st
ring
saveFrameName
=
mTokenValue
;
if
(
saveFrameName
.
empty
())
if
(
saveFrameName
.
empty
())
error
(
"Invalid save frame, should contain more than just 'save_' here"
);
error
(
"Invalid save frame, should contain more than just 'save_' here"
);
...
@@ -727,14 +726,14 @@ void DictParser::parseSaveFrame()
...
@@ -727,14 +726,14 @@ void DictParser::parseSaveFrame()
match
(
eCIFTokenLOOP
);
match
(
eCIFTokenLOOP
);
vector
<
string
>
tags
;
std
::
vector
<
std
::
string
>
tags
;
while
(
mLookahead
==
eCIFTokenTag
)
while
(
mLookahead
==
eCIFTokenTag
)
{
{
string
catName
,
itemName
;
st
d
::
st
ring
catName
,
itemName
;
std
::
tie
(
catName
,
itemName
)
=
splitTagName
(
mTokenValue
);
std
::
tie
(
catName
,
itemName
)
=
splitTagName
(
mTokenValue
);
if
(
cat
==
dict
.
end
())
if
(
cat
==
dict
.
end
())
std
::
tie
(
cat
,
ignore
)
=
dict
.
emplace
(
catName
);
std
::
tie
(
cat
,
std
::
ignore
)
=
dict
.
emplace
(
catName
);
else
if
(
not
iequals
(
cat
->
name
(),
catName
))
else
if
(
not
iequals
(
cat
->
name
(),
catName
))
error
(
"inconsistent categories in loop_"
);
error
(
"inconsistent categories in loop_"
);
...
@@ -758,11 +757,11 @@ void DictParser::parseSaveFrame()
...
@@ -758,11 +757,11 @@ void DictParser::parseSaveFrame()
}
}
else
else
{
{
string
catName
,
itemName
;
st
d
::
st
ring
catName
,
itemName
;
std
::
tie
(
catName
,
itemName
)
=
splitTagName
(
mTokenValue
);
std
::
tie
(
catName
,
itemName
)
=
splitTagName
(
mTokenValue
);
if
(
cat
==
dict
.
end
()
or
not
iequals
(
cat
->
name
(),
catName
))
if
(
cat
==
dict
.
end
()
or
not
iequals
(
cat
->
name
(),
catName
))
std
::
tie
(
cat
,
ignore
)
=
dict
.
emplace
(
catName
);
std
::
tie
(
cat
,
std
::
ignore
)
=
dict
.
emplace
(
catName
);
match
(
eCIFTokenTag
);
match
(
eCIFTokenTag
);
...
@@ -778,22 +777,22 @@ void DictParser::parseSaveFrame()
...
@@ -778,22 +777,22 @@ void DictParser::parseSaveFrame()
if
(
isCategorySaveFrame
)
if
(
isCategorySaveFrame
)
{
{
string
category
=
dict
.
firstItem
(
"_category.id"
);
st
d
::
st
ring
category
=
dict
.
firstItem
(
"_category.id"
);
vector
<
string
>
keys
;
std
::
vector
<
std
::
string
>
keys
;
for
(
auto
k
:
dict
[
"category_key"
])
for
(
auto
k
:
dict
[
"category_key"
])
keys
.
push_back
(
get
<
1
>
(
splitTagName
(
k
[
"name"
].
as
<
string
>
())));
keys
.
push_back
(
std
::
get
<
1
>
(
splitTagName
(
k
[
"name"
].
as
<
std
::
string
>
())));
iset
groups
;
iset
groups
;
for
(
auto
g
:
dict
[
"category_group"
])
for
(
auto
g
:
dict
[
"category_group"
])
groups
.
insert
(
g
[
"id"
].
as
<
string
>
());
groups
.
insert
(
g
[
"id"
].
as
<
st
d
::
st
ring
>
());
mImpl
->
mCategoryValidators
.
push_back
(
ValidateCategory
{
category
,
keys
,
groups
});
mImpl
->
mCategoryValidators
.
push_back
(
ValidateCategory
{
category
,
keys
,
groups
});
}
}
else
else
{
{
// if the type code is missing, this must be a pointer, just skip it
// if the type code is missing, this must be a pointer, just skip it
string
typeCode
=
dict
.
firstItem
(
"_item_type.code"
);
st
d
::
st
ring
typeCode
=
dict
.
firstItem
(
"_item_type.code"
);
const
ValidateType
*
tv
=
nullptr
;
const
ValidateType
*
tv
=
nullptr
;
if
(
not
(
typeCode
.
empty
()
or
typeCode
==
"?"
))
if
(
not
(
typeCode
.
empty
()
or
typeCode
==
"?"
))
...
@@ -801,9 +800,9 @@ void DictParser::parseSaveFrame()
...
@@ -801,9 +800,9 @@ void DictParser::parseSaveFrame()
iset
ess
;
iset
ess
;
for
(
auto
e
:
dict
[
"item_enumeration"
])
for
(
auto
e
:
dict
[
"item_enumeration"
])
ess
.
insert
(
e
[
"value"
].
as
<
string
>
());
ess
.
insert
(
e
[
"value"
].
as
<
st
d
::
st
ring
>
());
string
defaultValue
=
dict
.
firstItem
(
"_item_default.value"
);
st
d
::
st
ring
defaultValue
=
dict
.
firstItem
(
"_item_default.value"
);
bool
defaultIsNull
=
false
;
bool
defaultIsNull
=
false
;
if
(
defaultValue
.
empty
())
if
(
defaultValue
.
empty
())
{
{
...
@@ -817,11 +816,11 @@ void DictParser::parseSaveFrame()
...
@@ -817,11 +816,11 @@ void DictParser::parseSaveFrame()
// collect the dict from our dataBlock and construct validators
// collect the dict from our dataBlock and construct validators
for
(
auto
i
:
dict
[
"item"
])
for
(
auto
i
:
dict
[
"item"
])
{
{
string
tagName
,
category
,
mandatory
;
st
d
::
st
ring
tagName
,
category
,
mandatory
;
cif
::
tie
(
tagName
,
category
,
mandatory
)
=
i
.
get
(
"name"
,
"category_id"
,
"mandatory_code"
);
cif
::
tie
(
tagName
,
category
,
mandatory
)
=
i
.
get
(
"name"
,
"category_id"
,
"mandatory_code"
);
string
catName
,
itemName
;
st
d
::
st
ring
catName
,
itemName
;
std
::
tie
(
catName
,
itemName
)
=
splitTagName
(
tagName
);
std
::
tie
(
catName
,
itemName
)
=
splitTagName
(
tagName
);
if
(
catName
.
empty
()
or
itemName
.
empty
())
if
(
catName
.
empty
()
or
itemName
.
empty
())
...
@@ -844,12 +843,12 @@ void DictParser::parseSaveFrame()
...
@@ -844,12 +843,12 @@ void DictParser::parseSaveFrame()
{
{
if
(
VERBOSE
>
2
)
if
(
VERBOSE
>
2
)
{
{
cerr
<<
"inconsistent mandatory value for "
<<
tagName
<<
" in dictionary"
<<
endl
;
std
::
cerr
<<
"inconsistent mandatory value for "
<<
tagName
<<
" in dictionary"
<<
std
::
endl
;
if
(
iequals
(
tagName
,
saveFrameName
))
if
(
iequals
(
tagName
,
saveFrameName
))
cerr
<<
"choosing "
<<
mandatory
<<
endl
;
std
::
cerr
<<
"choosing "
<<
mandatory
<<
std
::
endl
;
else
else
cerr
<<
"choosing "
<<
(
vi
->
mMandatory
?
"Y"
:
"N"
)
<<
endl
;
std
::
cerr
<<
"choosing "
<<
(
vi
->
mMandatory
?
"Y"
:
"N"
)
<<
std
::
endl
;
}
}
if
(
iequals
(
tagName
,
saveFrameName
))
if
(
iequals
(
tagName
,
saveFrameName
))
...
@@ -859,7 +858,7 @@ void DictParser::parseSaveFrame()
...
@@ -859,7 +858,7 @@ void DictParser::parseSaveFrame()
if
(
vi
->
mType
!=
nullptr
and
tv
!=
nullptr
and
vi
->
mType
!=
tv
)
if
(
vi
->
mType
!=
nullptr
and
tv
!=
nullptr
and
vi
->
mType
!=
tv
)
{
{
if
(
VERBOSE
>
1
)
if
(
VERBOSE
>
1
)
cerr
<<
"inconsistent type for "
<<
tagName
<<
" in dictionary"
<<
endl
;
std
::
cerr
<<
"inconsistent type for "
<<
tagName
<<
" in dictionary"
<<
std
::
endl
;
}
}
// vi->mMandatory = (iequals(mandatory, "yes"));
// vi->mMandatory = (iequals(mandatory, "yes"));
...
@@ -876,7 +875,7 @@ void DictParser::parseSaveFrame()
...
@@ -876,7 +875,7 @@ void DictParser::parseSaveFrame()
// collect the dict from our dataBlock and construct validators
// collect the dict from our dataBlock and construct validators
for
(
auto
i
:
dict
[
"item_linked"
])
for
(
auto
i
:
dict
[
"item_linked"
])
{
{
string
childTagName
,
parentTagName
;
st
d
::
st
ring
childTagName
,
parentTagName
;
cif
::
tie
(
childTagName
,
parentTagName
)
=
i
.
get
(
"child_name"
,
"parent_name"
);
cif
::
tie
(
childTagName
,
parentTagName
)
=
i
.
get
(
"child_name"
,
"parent_name"
);
...
@@ -892,12 +891,12 @@ void DictParser::linkItems()
...
@@ -892,12 +891,12 @@ void DictParser::linkItems()
auto
&
dict
=
*
mDataBlock
;
auto
&
dict
=
*
mDataBlock
;
map
<
tuple
<
string
,
string
,
int
>
,
size_t
>
linkIndex
;
std
::
map
<
std
::
tuple
<
std
::
string
,
std
::
string
,
int
>
,
size_t
>
linkIndex
;
vector
<
tuple
<
vector
<
string
>
,
vector
<
string
>>>
linkKeys
;
std
::
vector
<
std
::
tuple
<
std
::
vector
<
std
::
string
>
,
std
::
vector
<
std
::
string
>>>
linkKeys
;
for
(
auto
gl
:
dict
[
"pdbx_item_linked_group_list"
])
for
(
auto
gl
:
dict
[
"pdbx_item_linked_group_list"
])
{
{
string
child
,
parent
;
st
d
::
st
ring
child
,
parent
;
int
link_group_id
;
int
link_group_id
;
cif
::
tie
(
child
,
parent
,
link_group_id
)
=
gl
.
get
(
"child_name"
,
"parent_name"
,
"link_group_id"
);
cif
::
tie
(
child
,
parent
,
link_group_id
)
=
gl
.
get
(
"child_name"
,
"parent_name"
,
"link_group_id"
);
...
@@ -918,13 +917,13 @@ void DictParser::linkItems()
...
@@ -918,13 +917,13 @@ void DictParser::linkItems()
size_t
ix
=
linkIndex
.
at
(
key
);
size_t
ix
=
linkIndex
.
at
(
key
);
get
<
0
>
(
linkKeys
.
at
(
ix
)).
push_back
(
piv
->
mTag
);
std
::
get
<
0
>
(
linkKeys
.
at
(
ix
)).
push_back
(
piv
->
mTag
);
get
<
1
>
(
linkKeys
.
at
(
ix
)).
push_back
(
civ
->
mTag
);
std
::
get
<
1
>
(
linkKeys
.
at
(
ix
)).
push_back
(
civ
->
mTag
);
}
}
// for (auto li: mImpl->mLinkedItems)
// for (auto li: mImpl->mLinkedItems)
// {
// {
// string child, parent;
// st
d::st
ring child, parent;
// std::tie(child, parent) = li;
// std::tie(child, parent) = li;
//
//
// auto civ = mValidator.getValidatorForItem(child);
// auto civ = mValidator.getValidatorForItem(child);
...
@@ -961,11 +960,11 @@ void DictParser::linkItems()
...
@@ -961,11 +960,11 @@ void DictParser::linkItems()
// look up the label
// look up the label
for
(
auto
r
:
linkedGroup
.
find
(
cif
::
Key
(
"category_id"
)
==
link
.
mChildCategory
and
cif
::
Key
(
"link_group_id"
)
==
link
.
mLinkGroupID
))
for
(
auto
r
:
linkedGroup
.
find
(
cif
::
Key
(
"category_id"
)
==
link
.
mChildCategory
and
cif
::
Key
(
"link_group_id"
)
==
link
.
mLinkGroupID
))
{
{
link
.
mLinkGroupLabel
=
r
[
"label"
].
as
<
string
>
();
link
.
mLinkGroupLabel
=
r
[
"label"
].
as
<
st
d
::
st
ring
>
();
break
;
break
;
}
}
mValidator
.
addLinkValidator
(
move
(
link
));
mValidator
.
addLinkValidator
(
std
::
move
(
link
));
}
}
// now make sure the itemType is specified for all itemValidators
// now make sure the itemType is specified for all itemValidators
...
@@ -975,14 +974,14 @@ void DictParser::linkItems()
...
@@ -975,14 +974,14 @@ void DictParser::linkItems()
for
(
auto
&
iv
:
cv
.
mItemValidators
)
for
(
auto
&
iv
:
cv
.
mItemValidators
)
{
{
if
(
iv
.
mType
==
nullptr
)
if
(
iv
.
mType
==
nullptr
)
cerr
<<
"Missing item_type for "
<<
iv
.
mTag
<<
endl
;
std
::
cerr
<<
"Missing item_type for "
<<
iv
.
mTag
<<
std
::
endl
;
}
}
}
}
}
}
void
DictParser
::
loadDictionary
()
void
DictParser
::
loadDictionary
()
{
{
unique_ptr
<
Datablock
>
dict
;
std
::
unique_ptr
<
Datablock
>
dict
;
Datablock
*
savedDatablock
=
mDataBlock
;
Datablock
*
savedDatablock
=
mDataBlock
;
try
try
...
@@ -1007,15 +1006,15 @@ void DictParser::loadDictionary()
...
@@ -1007,15 +1006,15 @@ void DictParser::loadDictionary()
}
}
}
}
}
}
catch
(
const
exception
&
ex
)
catch
(
const
std
::
exception
&
ex
)
{
{
cerr
<<
"Error parsing dictionary"
<<
endl
;
std
::
cerr
<<
"Error parsing dictionary"
<<
std
::
endl
;
throw
;
throw
;
}
}
// store all validators
// store all validators
for
(
auto
&
ic
:
mImpl
->
mCategoryValidators
)
for
(
auto
&
ic
:
mImpl
->
mCategoryValidators
)
mValidator
.
addCategoryValidator
(
move
(
ic
));
mValidator
.
addCategoryValidator
(
std
::
move
(
ic
));
mImpl
->
mCategoryValidators
.
clear
();
mImpl
->
mCategoryValidators
.
clear
();
for
(
auto
&
iv
:
mImpl
->
mItemValidators
)
for
(
auto
&
iv
:
mImpl
->
mItemValidators
)
...
@@ -1025,7 +1024,7 @@ void DictParser::loadDictionary()
...
@@ -1025,7 +1024,7 @@ void DictParser::loadDictionary()
error
(
"Undefined category '"
+
iv
.
first
);
error
(
"Undefined category '"
+
iv
.
first
);
for
(
auto
&
v
:
iv
.
second
)
for
(
auto
&
v
:
iv
.
second
)
const_cast
<
ValidateCategory
*>
(
cv
)
->
addItemValidator
(
move
(
v
));
const_cast
<
ValidateCategory
*>
(
cv
)
->
addItemValidator
(
std
::
move
(
v
));
}
}
// check all item validators for having a typeValidator
// check all item validators for having a typeValidator
...
@@ -1040,8 +1039,8 @@ void DictParser::loadDictionary()
...
@@ -1040,8 +1039,8 @@ void DictParser::loadDictionary()
if
(
n
)
if
(
n
)
{
{
auto
r
=
info
->
front
();
auto
r
=
info
->
front
();
mValidator
.
dictName
(
r
[
"title"
].
as
<
string
>
());
mValidator
.
dictName
(
r
[
"title"
].
as
<
st
d
::
st
ring
>
());
mValidator
.
dictVersion
(
r
[
"version"
].
as
<
string
>
());
mValidator
.
dictVersion
(
r
[
"version"
].
as
<
st
d
::
st
ring
>
());
}
}
mDataBlock
=
savedDatablock
;
mDataBlock
=
savedDatablock
;
...
@@ -1060,7 +1059,7 @@ bool DictParser::collectItemTypes()
...
@@ -1060,7 +1059,7 @@ bool DictParser::collectItemTypes()
for
(
auto
&
t
:
dict
[
"item_type_list"
])
for
(
auto
&
t
:
dict
[
"item_type_list"
])
{
{
string
code
,
primitiveCode
,
construct
;
st
d
::
st
ring
code
,
primitiveCode
,
construct
;
cif
::
tie
(
code
,
primitiveCode
,
construct
)
=
t
.
get
(
"code"
,
"primitive_code"
,
"construct"
);
cif
::
tie
(
code
,
primitiveCode
,
construct
)
=
t
.
get
(
"code"
,
"primitive_code"
,
"construct"
);
ba
::
replace_all
(
construct
,
"
\\
n"
,
"
\n
"
);
ba
::
replace_all
(
construct
,
"
\\
n"
,
"
\n
"
);
...
@@ -1073,9 +1072,9 @@ bool DictParser::collectItemTypes()
...
@@ -1073,9 +1072,9 @@ bool DictParser::collectItemTypes()
code
,
mapToPrimitiveType
(
primitiveCode
),
std
::
regex
(
construct
,
std
::
regex
::
extended
|
std
::
regex
::
optimize
)
code
,
mapToPrimitiveType
(
primitiveCode
),
std
::
regex
(
construct
,
std
::
regex
::
extended
|
std
::
regex
::
optimize
)
};
};
mValidator
.
addTypeValidator
(
move
(
v
));
mValidator
.
addTypeValidator
(
std
::
move
(
v
));
}
}
catch
(
const
exception
&
ex
)
catch
(
const
std
::
exception
&
ex
)
{
{
throw_with_nested
(
CifParserError
(
t
.
lineNr
(),
"error in regular expression"
));
throw_with_nested
(
CifParserError
(
t
.
lineNr
(),
"error in regular expression"
));
}
}
...
@@ -1086,7 +1085,7 @@ bool DictParser::collectItemTypes()
...
@@ -1086,7 +1085,7 @@ bool DictParser::collectItemTypes()
// mFileImpl.mTypeValidators.erase(v);
// mFileImpl.mTypeValidators.erase(v);
if
(
VERBOSE
>=
5
)
if
(
VERBOSE
>=
5
)
cerr
<<
"Added type "
<<
code
<<
" ("
<<
primitiveCode
<<
") => "
<<
construct
<<
endl
;
std
::
cerr
<<
"Added type "
<<
code
<<
" ("
<<
primitiveCode
<<
") => "
<<
construct
<<
std
::
endl
;
result
=
true
;
result
=
true
;
}
}
...
...
src/CifUtils.cpp
View file @
4b4757ee
...
@@ -47,7 +47,6 @@
...
@@ -47,7 +47,6 @@
#include "cif++/CifUtils.hpp"
#include "cif++/CifUtils.hpp"
using
namespace
std
;
namespace
ba
=
boost
::
algorithm
;
namespace
ba
=
boost
::
algorithm
;
namespace
cif
namespace
cif
...
@@ -80,7 +79,7 @@ const uint8_t kCharToLowerMap[256] =
...
@@ -80,7 +79,7 @@ const uint8_t kCharToLowerMap[256] =
// --------------------------------------------------------------------
// --------------------------------------------------------------------
bool
iequals
(
const
st
ring
&
a
,
const
string
&
b
)
bool
iequals
(
const
st
d
::
string
&
a
,
const
std
::
string
&
b
)
{
{
bool
result
=
a
.
length
()
==
b
.
length
();
bool
result
=
a
.
length
()
==
b
.
length
();
for
(
auto
ai
=
a
.
begin
(),
bi
=
b
.
begin
();
result
and
ai
!=
a
.
end
()
and
bi
!=
b
.
end
();
++
ai
,
++
bi
)
for
(
auto
ai
=
a
.
begin
(),
bi
=
b
.
begin
();
result
and
ai
!=
a
.
end
()
and
bi
!=
b
.
end
();
++
ai
,
++
bi
)
...
@@ -97,7 +96,7 @@ bool iequals(const char* a, const char* b)
...
@@ -97,7 +96,7 @@ bool iequals(const char* a, const char* b)
return
result
and
*
a
==
*
b
;
return
result
and
*
a
==
*
b
;
}
}
int
icompare
(
const
st
ring
&
a
,
const
string
&
b
)
int
icompare
(
const
st
d
::
string
&
a
,
const
std
::
string
&
b
)
{
{
int
d
=
0
;
int
d
=
0
;
auto
ai
=
a
.
begin
(),
bi
=
b
.
begin
();
auto
ai
=
a
.
begin
(),
bi
=
b
.
begin
();
...
@@ -134,15 +133,15 @@ int icompare(const char* a, const char* b)
...
@@ -134,15 +133,15 @@ int icompare(const char* a, const char* b)
return
d
;
return
d
;
}
}
void
toLower
(
string
&
s
)
void
toLower
(
st
d
::
st
ring
&
s
)
{
{
for
(
auto
&
c
:
s
)
for
(
auto
&
c
:
s
)
c
=
tolower
(
c
);
c
=
tolower
(
c
);
}
}
st
ring
toLowerCopy
(
const
string
&
s
)
st
d
::
string
toLowerCopy
(
const
std
::
string
&
s
)
{
{
string
result
(
s
);
st
d
::
st
ring
result
(
s
);
for
(
auto
&
c
:
result
)
for
(
auto
&
c
:
result
)
c
=
tolower
(
c
);
c
=
tolower
(
c
);
return
result
;
return
result
;
...
@@ -150,17 +149,17 @@ string toLowerCopy(const string& s)
...
@@ -150,17 +149,17 @@ string toLowerCopy(const string& s)
// --------------------------------------------------------------------
// --------------------------------------------------------------------
tuple
<
string
,
string
>
splitTagName
(
const
string
&
tag
)
std
::
tuple
<
std
::
string
,
std
::
string
>
splitTagName
(
const
std
::
string
&
tag
)
{
{
if
(
tag
.
empty
())
if
(
tag
.
empty
())
throw
runtime_error
(
"empty tag"
);
throw
std
::
runtime_error
(
"empty tag"
);
if
(
tag
[
0
]
!=
'_'
)
if
(
tag
[
0
]
!=
'_'
)
throw
runtime_error
(
"tag does not start with underscore"
);
throw
std
::
runtime_error
(
"tag does not start with underscore"
);
auto
s
=
tag
.
find
(
'.'
);
auto
s
=
tag
.
find
(
'.'
);
if
(
s
==
string
::
npos
)
if
(
s
==
st
d
::
st
ring
::
npos
)
throw
runtime_error
(
"tag does not contain dot"
);
throw
std
::
runtime_error
(
"tag does not contain dot"
);
return
tuple
<
string
,
string
>
{
return
std
::
tuple
<
std
::
string
,
std
::
string
>
{
tag
.
substr
(
1
,
s
-
1
),
tag
.
substr
(
s
+
1
)
tag
.
substr
(
1
,
s
-
1
),
tag
.
substr
(
s
+
1
)
};
};
}
}
...
@@ -236,7 +235,7 @@ const LineBreakClass kASCII_LBTable[128] =
...
@@ -236,7 +235,7 @@ const LineBreakClass kASCII_LBTable[128] =
kLBC_Alphabetic
,
kLBC_Alphabetic
,
kLBC_Alphabetic
,
kLBC_OpenPunctuation
,
kLBC_BreakAfter
,
kLBC_ClosePunctuation
,
kLBC_Alphabetic
,
kLBC_CombiningMark
kLBC_Alphabetic
,
kLBC_Alphabetic
,
kLBC_Alphabetic
,
kLBC_OpenPunctuation
,
kLBC_BreakAfter
,
kLBC_ClosePunctuation
,
kLBC_Alphabetic
,
kLBC_CombiningMark
};
};
st
ring
::
const_iterator
nextLineBreak
(
string
::
const_iterator
text
,
string
::
const_iterator
end
)
st
d
::
string
::
const_iterator
nextLineBreak
(
std
::
string
::
const_iterator
text
,
std
::
string
::
const_iterator
end
)
{
{
if
(
text
==
end
)
if
(
text
==
end
)
return
text
;
return
text
;
...
@@ -329,10 +328,10 @@ string::const_iterator nextLineBreak(string::const_iterator text, string::const_
...
@@ -329,10 +328,10 @@ string::const_iterator nextLineBreak(string::const_iterator text, string::const_
return
text
;
return
text
;
}
}
vector
<
string
>
wrapLine
(
const
string
&
text
,
unsigned
int
width
)
std
::
vector
<
std
::
string
>
wrapLine
(
const
std
::
string
&
text
,
unsigned
int
width
)
{
{
vector
<
string
>
result
;
std
::
vector
<
std
::
string
>
result
;
vector
<
size_t
>
offsets
=
{
0
};
std
::
vector
<
size_t
>
offsets
=
{
0
};
auto
b
=
text
.
begin
();
auto
b
=
text
.
begin
();
while
(
b
!=
text
.
end
())
while
(
b
!=
text
.
end
())
...
@@ -346,9 +345,9 @@ vector<string> wrapLine(const string& text, unsigned int width)
...
@@ -346,9 +345,9 @@ vector<string> wrapLine(const string& text, unsigned int width)
size_t
count
=
offsets
.
size
()
-
1
;
size_t
count
=
offsets
.
size
()
-
1
;
vector
<
size_t
>
minima
(
count
+
1
,
1000000
);
std
::
vector
<
size_t
>
minima
(
count
+
1
,
1000000
);
minima
[
0
]
=
0
;
minima
[
0
]
=
0
;
vector
<
size_t
>
breaks
(
count
+
1
,
0
);
std
::
vector
<
size_t
>
breaks
(
count
+
1
,
0
);
for
(
size_t
i
=
0
;
i
<
count
;
++
i
)
for
(
size_t
i
=
0
;
i
<
count
;
++
i
)
{
{
...
@@ -390,12 +389,12 @@ vector<string> wrapLine(const string& text, unsigned int width)
...
@@ -390,12 +389,12 @@ vector<string> wrapLine(const string& text, unsigned int width)
return
result
;
return
result
;
}
}
vector
<
string
>
wordWrap
(
const
string
&
text
,
unsigned
int
width
)
std
::
vector
<
std
::
string
>
wordWrap
(
const
std
::
string
&
text
,
unsigned
int
width
)
{
{
vector
<
string
>
paragraphs
;
std
::
vector
<
std
::
string
>
paragraphs
;
ba
::
split
(
paragraphs
,
text
,
ba
::
is_any_of
(
"
\n
"
));
ba
::
split
(
paragraphs
,
text
,
ba
::
is_any_of
(
"
\n
"
));
vector
<
string
>
result
;
std
::
vector
<
std
::
string
>
result
;
for
(
auto
&
p
:
paragraphs
)
for
(
auto
&
p
:
paragraphs
)
{
{
if
(
p
.
empty
())
if
(
p
.
empty
())
...
@@ -420,7 +419,7 @@ uint32_t get_terminal_width()
...
@@ -420,7 +419,7 @@ uint32_t get_terminal_width()
}
}
// I don't have a windows machine to test the following code, please accept my apologies in case it fails...
// I don't have a windows machine to test the following code, please accept my apologies in case it fails...
string
GetExecutablePath
()
st
d
::
st
ring
GetExecutablePath
()
{
{
WCHAR
buffer
[
4096
];
WCHAR
buffer
[
4096
];
...
@@ -430,7 +429,7 @@ string GetExecutablePath()
...
@@ -430,7 +429,7 @@ string GetExecutablePath()
wstring
ws
(
buffer
);
wstring
ws
(
buffer
);
return
string
(
ws
.
begin
(),
ws
.
end
());
return
st
d
::
st
ring
(
ws
.
begin
(),
ws
.
end
());
}
}
#else
#else
...
@@ -447,11 +446,13 @@ uint32_t get_terminal_width()
...
@@ -447,11 +446,13 @@ uint32_t get_terminal_width()
return
result
;
return
result
;
}
}
string
get_executable_path
()
st
d
::
st
ring
get_executable_path
()
{
{
using
namespace
std
::
literals
;
char
path
[
PATH_MAX
]
=
""
;
char
path
[
PATH_MAX
]
=
""
;
if
(
readlink
(
"/proc/self/exe"
,
path
,
sizeof
(
path
))
==
-
1
)
if
(
readlink
(
"/proc/self/exe"
,
path
,
sizeof
(
path
))
==
-
1
)
throw
runtime_error
(
"could not get exe path "
s
+
strerror
(
errno
));
throw
std
::
runtime_error
(
"could not get exe path "
s
+
strerror
(
errno
));
return
{
path
};
return
{
path
};
}
}
...
@@ -461,7 +462,7 @@ string get_executable_path()
...
@@ -461,7 +462,7 @@ string get_executable_path()
struct
ProgressImpl
struct
ProgressImpl
{
{
ProgressImpl
(
int64_t
inMax
,
const
string
&
inAction
)
ProgressImpl
(
int64_t
inMax
,
const
st
d
::
st
ring
&
inAction
)
:
mMax
(
inMax
),
mConsumed
(
0
),
mAction
(
inAction
),
mMessage
(
inAction
)
:
mMax
(
inMax
),
mConsumed
(
0
),
mAction
(
inAction
),
mMessage
(
inAction
)
,
mThread
(
std
::
bind
(
&
ProgressImpl
::
Run
,
this
))
,
mThread
(
std
::
bind
(
&
ProgressImpl
::
Run
,
this
))
,
mStart
(
boost
::
posix_time
::
second_clock
::
local_time
())
{}
,
mStart
(
boost
::
posix_time
::
second_clock
::
local_time
())
{}
...
@@ -478,10 +479,10 @@ struct ProgressImpl
...
@@ -478,10 +479,10 @@ struct ProgressImpl
void
PrintDone
();
void
PrintDone
();
int64_t
mMax
;
int64_t
mMax
;
atomic
<
int64_t
>
mConsumed
;
std
::
atomic
<
int64_t
>
mConsumed
;
int64_t
mLastConsumed
=
0
;
int64_t
mLastConsumed
=
0
;
int
mSpinnerIndex
=
0
;
int
mSpinnerIndex
=
0
;
string
mAction
,
mMessage
;
st
d
::
st
ring
mAction
,
mMessage
;
std
::
mutex
mMutex
;
std
::
mutex
mMutex
;
std
::
thread
mThread
;
std
::
thread
mThread
;
boost
::
timer
::
cpu_timer
mTimer
;
boost
::
timer
::
cpu_timer
mTimer
;
...
@@ -549,7 +550,7 @@ void ProgressImpl::PrintProgress()
...
@@ -549,7 +550,7 @@ void ProgressImpl::PrintProgress()
uint32_t
width
=
get_terminal_width
();
uint32_t
width
=
get_terminal_width
();
string
msg
;
st
d
::
st
ring
msg
;
msg
.
reserve
(
width
+
1
);
msg
.
reserve
(
width
+
1
);
if
(
mMessage
.
length
()
<=
20
)
if
(
mMessage
.
length
()
<=
20
)
{
{
...
@@ -604,23 +605,23 @@ void ProgressImpl::PrintProgress()
...
@@ -604,23 +605,23 @@ void ProgressImpl::PrintProgress()
// msg += to_string(perc);
// msg += to_string(perc);
// msg += '%';
// msg += '%';
cout
<<
'\r'
<<
msg
;
std
::
cout
<<
'\r'
<<
msg
;
cout
.
flush
();
std
::
cout
.
flush
();
}
}
void
ProgressImpl
::
PrintDone
()
void
ProgressImpl
::
PrintDone
()
{
{
string
msg
=
mAction
+
" done in "
+
mTimer
.
format
(
0
,
"%ts cpu / %ws wall"
);
st
d
::
st
ring
msg
=
mAction
+
" done in "
+
mTimer
.
format
(
0
,
"%ts cpu / %ws wall"
);
uint32_t
width
=
get_terminal_width
();
uint32_t
width
=
get_terminal_width
();
if
(
msg
.
length
()
<
width
)
if
(
msg
.
length
()
<
width
)
msg
+=
string
(
width
-
msg
.
length
(),
' '
);
msg
+=
st
d
::
st
ring
(
width
-
msg
.
length
(),
' '
);
cout
<<
'\r'
<<
msg
<<
endl
;
std
::
cout
<<
'\r'
<<
msg
<<
std
::
endl
;
}
}
Progress
::
Progress
(
int64_t
inMax
,
const
string
&
inAction
)
Progress
::
Progress
(
int64_t
inMax
,
const
st
d
::
st
ring
&
inAction
)
:
mImpl
(
nullptr
)
:
mImpl
(
nullptr
)
{
{
if
(
isatty
(
STDOUT_FILENO
))
if
(
isatty
(
STDOUT_FILENO
))
...
...
src/CifValidator.cpp
View file @
4b4757ee
...
@@ -34,7 +34,6 @@
...
@@ -34,7 +34,6 @@
#include "cif++/CifParser.hpp"
#include "cif++/CifParser.hpp"
#include "cif++/CifValidator.hpp"
#include "cif++/CifValidator.hpp"
using
namespace
std
;
namespace
ba
=
boost
::
algorithm
;
namespace
ba
=
boost
::
algorithm
;
extern
int
VERBOSE
;
extern
int
VERBOSE
;
...
@@ -42,19 +41,19 @@ extern int VERBOSE;
...
@@ -42,19 +41,19 @@ extern int VERBOSE;
namespace
cif
namespace
cif
{
{
ValidationError
::
ValidationError
(
const
string
&
msg
)
ValidationError
::
ValidationError
(
const
st
d
::
st
ring
&
msg
)
:
mMsg
(
msg
)
:
mMsg
(
msg
)
{
{
}
}
ValidationError
::
ValidationError
(
const
st
ring
&
cat
,
const
string
&
item
,
const
string
&
msg
)
ValidationError
::
ValidationError
(
const
st
d
::
string
&
cat
,
const
std
::
string
&
item
,
const
std
::
string
&
msg
)
:
mMsg
(
"When validating _"
+
cat
+
'.'
+
item
+
": "
+
msg
)
:
mMsg
(
"When validating _"
+
cat
+
'.'
+
item
+
": "
+
msg
)
{
{
}
}
// --------------------------------------------------------------------
// --------------------------------------------------------------------
DDL_PrimitiveType
mapToPrimitiveType
(
const
string
&
s
)
DDL_PrimitiveType
mapToPrimitiveType
(
const
st
d
::
st
ring
&
s
)
{
{
DDL_PrimitiveType
result
;
DDL_PrimitiveType
result
;
if
(
iequals
(
s
,
"char"
))
if
(
iequals
(
s
,
"char"
))
...
@@ -90,7 +89,7 @@ int ValidateType::compare(const char* a, const char* b) const
...
@@ -90,7 +89,7 @@ int ValidateType::compare(const char* a, const char* b) const
double
db
=
strtod
(
b
,
nullptr
);
double
db
=
strtod
(
b
,
nullptr
);
auto
d
=
da
-
db
;
auto
d
=
da
-
db
;
if
(
abs
(
d
)
>
numeric_limits
<
double
>::
epsilon
())
if
(
std
::
abs
(
d
)
>
std
::
numeric_limits
<
double
>::
epsilon
())
{
{
if
(
d
>
0
)
if
(
d
>
0
)
result
=
1
;
result
=
1
;
...
@@ -177,12 +176,12 @@ int ValidateType::compare(const char* a, const char* b) const
...
@@ -177,12 +176,12 @@ int ValidateType::compare(const char* a, const char* b) const
//
//
// parent->mChildren.insert(this);
// parent->mChildren.insert(this);
////
////
//// if (mCategory->mKeys ==
vector<
string>{mTag})
//// if (mCategory->mKeys ==
std::vector<std::
string>{mTag})
//// parent->mForeignKeys.insert(this);
//// parent->mForeignKeys.insert(this);
// }
// }
//}
//}
void
ValidateItem
::
operator
()(
string
value
)
const
void
ValidateItem
::
operator
()(
st
d
::
st
ring
value
)
const
{
{
if
(
not
value
.
empty
()
and
value
!=
"?"
and
value
!=
"."
)
if
(
not
value
.
empty
()
and
value
!=
"?"
and
value
!=
"."
)
{
{
...
@@ -206,19 +205,19 @@ void ValidateCategory::addItemValidator(ValidateItem&& v)
...
@@ -206,19 +205,19 @@ void ValidateCategory::addItemValidator(ValidateItem&& v)
v
.
mCategory
=
this
;
v
.
mCategory
=
this
;
auto
r
=
mItemValidators
.
insert
(
move
(
v
));
auto
r
=
mItemValidators
.
insert
(
std
::
move
(
v
));
if
(
not
r
.
second
and
VERBOSE
>=
4
)
if
(
not
r
.
second
and
VERBOSE
>=
4
)
cout
<<
"Could not add validator for item "
<<
v
.
mTag
<<
" to category "
<<
mName
<<
endl
;
std
::
cout
<<
"Could not add validator for item "
<<
v
.
mTag
<<
" to category "
<<
mName
<<
std
::
endl
;
}
}
const
ValidateItem
*
ValidateCategory
::
getValidatorForItem
(
string
tag
)
const
const
ValidateItem
*
ValidateCategory
::
getValidatorForItem
(
st
d
::
st
ring
tag
)
const
{
{
const
ValidateItem
*
result
=
nullptr
;
const
ValidateItem
*
result
=
nullptr
;
auto
i
=
mItemValidators
.
find
(
ValidateItem
{
tag
});
auto
i
=
mItemValidators
.
find
(
ValidateItem
{
tag
});
if
(
i
!=
mItemValidators
.
end
())
if
(
i
!=
mItemValidators
.
end
())
result
=
&*
i
;
result
=
&*
i
;
else
if
(
VERBOSE
>
4
)
else
if
(
VERBOSE
>
4
)
cout
<<
"No validator for tag "
<<
tag
<<
endl
;
std
::
cout
<<
"No validator for tag "
<<
tag
<<
std
::
endl
;
return
result
;
return
result
;
}
}
...
@@ -234,12 +233,12 @@ Validator::~Validator()
...
@@ -234,12 +233,12 @@ Validator::~Validator()
void
Validator
::
addTypeValidator
(
ValidateType
&&
v
)
void
Validator
::
addTypeValidator
(
ValidateType
&&
v
)
{
{
auto
r
=
mTypeValidators
.
insert
(
move
(
v
));
auto
r
=
mTypeValidators
.
insert
(
std
::
move
(
v
));
if
(
not
r
.
second
and
VERBOSE
>
4
)
if
(
not
r
.
second
and
VERBOSE
>
4
)
cout
<<
"Could not add validator for type "
<<
v
.
mName
<<
endl
;
std
::
cout
<<
"Could not add validator for type "
<<
v
.
mName
<<
std
::
endl
;
}
}
const
ValidateType
*
Validator
::
getValidatorForType
(
string
typeCode
)
const
const
ValidateType
*
Validator
::
getValidatorForType
(
st
d
::
st
ring
typeCode
)
const
{
{
const
ValidateType
*
result
=
nullptr
;
const
ValidateType
*
result
=
nullptr
;
...
@@ -247,33 +246,33 @@ const ValidateType* Validator::getValidatorForType(string typeCode) const
...
@@ -247,33 +246,33 @@ const ValidateType* Validator::getValidatorForType(string typeCode) const
if
(
i
!=
mTypeValidators
.
end
())
if
(
i
!=
mTypeValidators
.
end
())
result
=
&*
i
;
result
=
&*
i
;
else
if
(
VERBOSE
>
4
)
else
if
(
VERBOSE
>
4
)
cout
<<
"No validator for type "
<<
typeCode
<<
endl
;
std
::
cout
<<
"No validator for type "
<<
typeCode
<<
std
::
endl
;
return
result
;
return
result
;
}
}
void
Validator
::
addCategoryValidator
(
ValidateCategory
&&
v
)
void
Validator
::
addCategoryValidator
(
ValidateCategory
&&
v
)
{
{
auto
r
=
mCategoryValidators
.
insert
(
move
(
v
));
auto
r
=
mCategoryValidators
.
insert
(
std
::
move
(
v
));
if
(
not
r
.
second
and
VERBOSE
>
4
)
if
(
not
r
.
second
and
VERBOSE
>
4
)
cout
<<
"Could not add validator for category "
<<
v
.
mName
<<
endl
;
std
::
cout
<<
"Could not add validator for category "
<<
v
.
mName
<<
std
::
endl
;
}
}
const
ValidateCategory
*
Validator
::
getValidatorForCategory
(
string
category
)
const
const
ValidateCategory
*
Validator
::
getValidatorForCategory
(
st
d
::
st
ring
category
)
const
{
{
const
ValidateCategory
*
result
=
nullptr
;
const
ValidateCategory
*
result
=
nullptr
;
auto
i
=
mCategoryValidators
.
find
(
ValidateCategory
{
category
});
auto
i
=
mCategoryValidators
.
find
(
ValidateCategory
{
category
});
if
(
i
!=
mCategoryValidators
.
end
())
if
(
i
!=
mCategoryValidators
.
end
())
result
=
&*
i
;
result
=
&*
i
;
else
if
(
VERBOSE
>
4
)
else
if
(
VERBOSE
>
4
)
cout
<<
"No validator for category "
<<
category
<<
endl
;
std
::
cout
<<
"No validator for category "
<<
category
<<
std
::
endl
;
return
result
;
return
result
;
}
}
ValidateItem
*
Validator
::
getValidatorForItem
(
string
tag
)
const
ValidateItem
*
Validator
::
getValidatorForItem
(
st
d
::
st
ring
tag
)
const
{
{
ValidateItem
*
result
=
nullptr
;
ValidateItem
*
result
=
nullptr
;
string
cat
,
item
;
st
d
::
st
ring
cat
,
item
;
std
::
tie
(
cat
,
item
)
=
splitTagName
(
tag
);
std
::
tie
(
cat
,
item
)
=
splitTagName
(
tag
);
auto
*
cv
=
getValidatorForCategory
(
cat
);
auto
*
cv
=
getValidatorForCategory
(
cat
);
...
@@ -281,7 +280,7 @@ ValidateItem* Validator::getValidatorForItem(string tag) const
...
@@ -281,7 +280,7 @@ ValidateItem* Validator::getValidatorForItem(string tag) const
result
=
const_cast
<
ValidateItem
*>
(
cv
->
getValidatorForItem
(
item
));
result
=
const_cast
<
ValidateItem
*>
(
cv
->
getValidatorForItem
(
item
));
if
(
result
==
nullptr
and
VERBOSE
>
4
)
if
(
result
==
nullptr
and
VERBOSE
>
4
)
cout
<<
"No validator for item "
<<
tag
<<
endl
;
std
::
cout
<<
"No validator for item "
<<
tag
<<
std
::
endl
;
return
result
;
return
result
;
}
}
...
@@ -290,38 +289,38 @@ void Validator::addLinkValidator(ValidateLink&& v)
...
@@ -290,38 +289,38 @@ void Validator::addLinkValidator(ValidateLink&& v)
{
{
assert
(
v
.
mParentKeys
.
size
()
==
v
.
mChildKeys
.
size
());
assert
(
v
.
mParentKeys
.
size
()
==
v
.
mChildKeys
.
size
());
if
(
v
.
mParentKeys
.
size
()
!=
v
.
mChildKeys
.
size
())
if
(
v
.
mParentKeys
.
size
()
!=
v
.
mChildKeys
.
size
())
throw
runtime_error
(
"unequal number of keys for parent and child in link"
);
throw
std
::
runtime_error
(
"unequal number of keys for parent and child in link"
);
auto
pcv
=
getValidatorForCategory
(
v
.
mParentCategory
);
auto
pcv
=
getValidatorForCategory
(
v
.
mParentCategory
);
auto
ccv
=
getValidatorForCategory
(
v
.
mChildCategory
);
auto
ccv
=
getValidatorForCategory
(
v
.
mChildCategory
);
if
(
pcv
==
nullptr
)
if
(
pcv
==
nullptr
)
throw
runtime_error
(
"unknown parent category "
+
v
.
mParentCategory
);
throw
std
::
runtime_error
(
"unknown parent category "
+
v
.
mParentCategory
);
if
(
ccv
==
nullptr
)
if
(
ccv
==
nullptr
)
throw
runtime_error
(
"unknown child category "
+
v
.
mChildCategory
);
throw
std
::
runtime_error
(
"unknown child category "
+
v
.
mChildCategory
);
for
(
size_t
i
=
0
;
i
<
v
.
mParentKeys
.
size
();
++
i
)
for
(
size_t
i
=
0
;
i
<
v
.
mParentKeys
.
size
();
++
i
)
{
{
auto
piv
=
pcv
->
getValidatorForItem
(
v
.
mParentKeys
[
i
]);
auto
piv
=
pcv
->
getValidatorForItem
(
v
.
mParentKeys
[
i
]);
if
(
piv
==
nullptr
)
if
(
piv
==
nullptr
)
throw
runtime_error
(
"unknown parent tag _"
+
v
.
mParentCategory
+
'.'
+
v
.
mParentKeys
[
i
]);
throw
std
::
runtime_error
(
"unknown parent tag _"
+
v
.
mParentCategory
+
'.'
+
v
.
mParentKeys
[
i
]);
auto
civ
=
ccv
->
getValidatorForItem
(
v
.
mChildKeys
[
i
]);
auto
civ
=
ccv
->
getValidatorForItem
(
v
.
mChildKeys
[
i
]);
if
(
civ
==
nullptr
)
if
(
civ
==
nullptr
)
throw
runtime_error
(
"unknown child tag _"
+
v
.
mChildCategory
+
'.'
+
v
.
mChildKeys
[
i
]);
throw
std
::
runtime_error
(
"unknown child tag _"
+
v
.
mChildCategory
+
'.'
+
v
.
mChildKeys
[
i
]);
if
(
civ
->
mType
==
nullptr
and
piv
->
mType
!=
nullptr
)
if
(
civ
->
mType
==
nullptr
and
piv
->
mType
!=
nullptr
)
const_cast
<
ValidateItem
*>
(
civ
)
->
mType
=
piv
->
mType
;
const_cast
<
ValidateItem
*>
(
civ
)
->
mType
=
piv
->
mType
;
}
}
mLinkValidators
.
emplace_back
(
move
(
v
));
mLinkValidators
.
emplace_back
(
std
::
move
(
v
));
}
}
vector
<
const
ValidateLink
*>
Validator
::
getLinksForParent
(
const
string
&
category
)
const
std
::
vector
<
const
ValidateLink
*>
Validator
::
getLinksForParent
(
const
std
::
string
&
category
)
const
{
{
vector
<
const
ValidateLink
*>
result
;
std
::
vector
<
const
ValidateLink
*>
result
;
for
(
auto
&
l
:
mLinkValidators
)
for
(
auto
&
l
:
mLinkValidators
)
{
{
...
@@ -332,9 +331,9 @@ vector<const ValidateLink*> Validator::getLinksForParent(const string& category)
...
@@ -332,9 +331,9 @@ vector<const ValidateLink*> Validator::getLinksForParent(const string& category)
return
result
;
return
result
;
}
}
vector
<
const
ValidateLink
*>
Validator
::
getLinksForChild
(
const
string
&
category
)
const
std
::
vector
<
const
ValidateLink
*>
Validator
::
getLinksForChild
(
const
std
::
string
&
category
)
const
{
{
vector
<
const
ValidateLink
*>
result
;
std
::
vector
<
const
ValidateLink
*>
result
;
for
(
auto
&
l
:
mLinkValidators
)
for
(
auto
&
l
:
mLinkValidators
)
{
{
...
@@ -345,12 +344,12 @@ vector<const ValidateLink*> Validator::getLinksForChild(const string& category)
...
@@ -345,12 +344,12 @@ vector<const ValidateLink*> Validator::getLinksForChild(const string& category)
return
result
;
return
result
;
}
}
void
Validator
::
reportError
(
const
string
&
msg
,
bool
fatal
)
void
Validator
::
reportError
(
const
st
d
::
st
ring
&
msg
,
bool
fatal
)
{
{
if
(
mStrict
or
fatal
)
if
(
mStrict
or
fatal
)
throw
ValidationError
(
msg
);
throw
ValidationError
(
msg
);
else
if
(
VERBOSE
)
else
if
(
VERBOSE
)
cerr
<<
msg
<<
endl
;
std
::
cerr
<<
msg
<<
std
::
endl
;
}
}
}
}
src/Compound.cpp
View file @
4b4757ee
...
@@ -32,21 +32,15 @@
...
@@ -32,21 +32,15 @@
#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string.hpp>
#if __has_include(<filesystem>)
#include <filesystem>
#include <filesystem>
namespace
fs
=
std
::
filesystem
;
#elif __has_include(<boost/filesystem.hpp>)
#include <boost/filesystem.hpp>
namespace
fs
=
boost
::
filesystem
;
#endif
#include "cif++/Cif++.hpp"
#include "cif++/Cif++.hpp"
#include "cif++/Point.hpp"
#include "cif++/Point.hpp"
#include "cif++/Compound.hpp"
#include "cif++/Compound.hpp"
#include "cif++/CifUtils.hpp"
#include "cif++/CifUtils.hpp"
using
namespace
std
;
namespace
ba
=
boost
::
algorithm
;
namespace
ba
=
boost
::
algorithm
;
namespace
fs
=
std
::
filesystem
;
namespace
mmcif
namespace
mmcif
{
{
...
@@ -83,12 +77,12 @@ struct CompoundBondLess
...
@@ -83,12 +77,12 @@ struct CompoundBondLess
struct
IsomerSet
struct
IsomerSet
{
{
vector
<
string
>
compounds
;
std
::
vector
<
std
::
string
>
compounds
;
};
};
struct
IsomerSets
struct
IsomerSets
{
{
vector
<
IsomerSet
>
isomers
;
std
::
vector
<
IsomerSet
>
isomers
;
};
};
class
IsomerDB
class
IsomerDB
...
@@ -97,8 +91,8 @@ class IsomerDB
...
@@ -97,8 +91,8 @@ class IsomerDB
static
IsomerDB
&
instance
();
static
IsomerDB
&
instance
();
size_t
count
(
const
string
&
compound
)
const
;
size_t
count
(
const
st
d
::
st
ring
&
compound
)
const
;
const
vector
<
string
>&
operator
[](
const
string
&
compound
)
const
;
const
std
::
vector
<
std
::
string
>&
operator
[](
const
std
::
string
&
compound
)
const
;
private
:
private
:
...
@@ -111,14 +105,14 @@ IsomerDB::IsomerDB()
...
@@ -111,14 +105,14 @@ IsomerDB::IsomerDB()
{
{
auto
isomers
=
cif
::
rsrc_loader
::
load
(
"isomers.txt"
);
auto
isomers
=
cif
::
rsrc_loader
::
load
(
"isomers.txt"
);
if
(
not
isomers
)
if
(
not
isomers
)
throw
runtime_error
(
"Missing isomers.txt resource"
);
throw
std
::
runtime_error
(
"Missing isomers.txt resource"
);
struct
membuf
:
public
streambuf
struct
membuf
:
public
st
d
::
st
reambuf
{
{
membuf
(
char
*
data
,
size_t
length
)
{
this
->
setg
(
data
,
data
,
data
+
length
);
}
membuf
(
char
*
data
,
size_t
length
)
{
this
->
setg
(
data
,
data
,
data
+
length
);
}
}
buffer
(
const_cast
<
char
*>
(
isomers
.
data
()),
isomers
.
size
());
}
buffer
(
const_cast
<
char
*>
(
isomers
.
data
()),
isomers
.
size
());
istream
is
(
&
buffer
);
std
::
istream
is
(
&
buffer
);
// #else
// #else
// cerr << "resource support was not compiled in, falling back to a local file" << endl;
// cerr << "resource support was not compiled in, falling back to a local file" << endl;
// fs::path isomersFile = "isomers.txt";
// fs::path isomersFile = "isomers.txt";
...
@@ -127,12 +121,12 @@ IsomerDB::IsomerDB()
...
@@ -127,12 +121,12 @@ IsomerDB::IsomerDB()
// fs::ifstream is(isomersFile);
// fs::ifstream is(isomersFile);
// if (not is.is_open())
// if (not is.is_open())
// throw runtime_error("Could not open the file isomers.txt");
// throw
std::
runtime_error("Could not open the file isomers.txt");
// #endif
// #endif
string
line
;
st
d
::
st
ring
line
;
while
(
getline
(
is
,
line
))
while
(
std
::
getline
(
is
,
line
))
{
{
IsomerSet
compounds
;
IsomerSet
compounds
;
ba
::
split
(
compounds
.
compounds
,
line
,
ba
::
is_any_of
(
":"
));
ba
::
split
(
compounds
.
compounds
,
line
,
ba
::
is_any_of
(
":"
));
...
@@ -148,7 +142,7 @@ IsomerDB& IsomerDB::instance()
...
@@ -148,7 +142,7 @@ IsomerDB& IsomerDB::instance()
return
sInstance
;
return
sInstance
;
}
}
size_t
IsomerDB
::
count
(
const
string
&
compound
)
const
size_t
IsomerDB
::
count
(
const
st
d
::
st
ring
&
compound
)
const
{
{
size_t
n
=
0
;
size_t
n
=
0
;
for
(
auto
&
d
:
mData
.
isomers
)
for
(
auto
&
d
:
mData
.
isomers
)
...
@@ -159,7 +153,7 @@ size_t IsomerDB::count(const string& compound) const
...
@@ -159,7 +153,7 @@ size_t IsomerDB::count(const string& compound) const
return
n
;
return
n
;
}
}
const
vector
<
string
>&
IsomerDB
::
operator
[](
const
string
&
compound
)
const
const
std
::
vector
<
std
::
string
>&
IsomerDB
::
operator
[](
const
std
::
string
&
compound
)
const
{
{
for
(
auto
&
d
:
mData
.
isomers
)
for
(
auto
&
d
:
mData
.
isomers
)
{
{
...
@@ -167,7 +161,7 @@ const vector<string>& IsomerDB::operator[](const string& compound) const
...
@@ -167,7 +161,7 @@ const vector<string>& IsomerDB::operator[](const string& compound) const
return
d
.
compounds
;
return
d
.
compounds
;
}
}
throw
runtime_error
(
"No isomer set found containing "
+
compound
);
throw
std
::
runtime_error
(
"No isomer set found containing "
+
compound
);
}
}
// --------------------------------------------------------------------
// --------------------------------------------------------------------
...
@@ -177,16 +171,16 @@ const vector<string>& IsomerDB::operator[](const string& compound) const
...
@@ -177,16 +171,16 @@ const vector<string>& IsomerDB::operator[](const string& compound) const
struct
Node
struct
Node
{
{
string
id
;
st
d
::
st
ring
id
;
AtomType
symbol
;
AtomType
symbol
;
vector
<
tuple
<
size_t
,
BondType
>>
links
;
std
::
vector
<
std
::
tuple
<
size_t
,
BondType
>>
links
;
size_t
hydrogens
=
0
;
size_t
hydrogens
=
0
;
};
};
// Check to see if the nodes a[iA] and b[iB] are the start of a similar sub structure
// Check to see if the nodes a[iA] and b[iB] are the start of a similar sub structure
bool
SubStructuresAreIsomeric
(
bool
SubStructuresAreIsomeric
(
const
vector
<
Node
>&
a
,
const
vector
<
Node
>&
b
,
size_t
iA
,
size_t
iB
,
const
std
::
vector
<
Node
>&
a
,
const
std
::
vector
<
Node
>&
b
,
size_t
iA
,
size_t
iB
,
vector
<
bool
>
visitedA
,
vector
<
bool
>
visitedB
,
vector
<
tuple
<
string
,
string
>>&
outMapping
)
std
::
vector
<
bool
>
visitedA
,
std
::
vector
<
bool
>
visitedB
,
std
::
vector
<
std
::
tuple
<
std
::
string
,
std
::
string
>>&
outMapping
)
{
{
auto
&
na
=
a
[
iA
];
auto
&
na
=
a
[
iA
];
auto
&
nb
=
b
[
iB
];
auto
&
nb
=
b
[
iB
];
...
@@ -204,21 +198,21 @@ bool SubStructuresAreIsomeric(
...
@@ -204,21 +198,21 @@ bool SubStructuresAreIsomeric(
// we now have two sets of links to compare.
// we now have two sets of links to compare.
// Compare each permutation of the second set of indices with the first
// Compare each permutation of the second set of indices with the first
vector
<
size_t
>
ilb
(
N
);
std
::
vector
<
size_t
>
ilb
(
N
);
iota
(
ilb
.
begin
(),
ilb
.
end
(),
0
);
iota
(
ilb
.
begin
(),
ilb
.
end
(),
0
);
for
(;;)
for
(;;)
{
{
result
=
true
;
result
=
true
;
vector
<
tuple
<
string
,
string
>>
m
;
std
::
vector
<
std
::
tuple
<
std
::
string
,
std
::
string
>>
m
;
for
(
size_t
i
=
0
;
result
and
i
<
N
;
++
i
)
for
(
size_t
i
=
0
;
result
and
i
<
N
;
++
i
)
{
{
size_t
lA
,
lB
;
size_t
lA
,
lB
;
BondType
typeA
,
typeB
;
BondType
typeA
,
typeB
;
tie
(
lA
,
typeA
)
=
na
.
links
[
i
];
assert
(
lA
<
a
.
size
());
std
::
tie
(
lA
,
typeA
)
=
na
.
links
[
i
];
assert
(
lA
<
a
.
size
());
tie
(
lB
,
typeB
)
=
nb
.
links
[
ilb
[
i
]];
assert
(
lB
<
b
.
size
());
std
::
tie
(
lB
,
typeB
)
=
nb
.
links
[
ilb
[
i
]];
assert
(
lB
<
b
.
size
());
if
(
typeA
!=
typeB
or
visitedA
[
lA
]
!=
visitedB
[
lB
])
if
(
typeA
!=
typeB
or
visitedA
[
lA
]
!=
visitedB
[
lB
])
{
{
...
@@ -255,15 +249,15 @@ bool SubStructuresAreIsomeric(
...
@@ -255,15 +249,15 @@ bool SubStructuresAreIsomeric(
return
result
;
return
result
;
}
}
bool
StructuresAreIsomeric
(
vector
<
CompoundAtom
>
atomsA
,
const
vector
<
CompoundBond
>&
bondsA
,
bool
StructuresAreIsomeric
(
std
::
vector
<
CompoundAtom
>
atomsA
,
const
std
::
vector
<
CompoundBond
>&
bondsA
,
vector
<
CompoundAtom
>
atomsB
,
const
vector
<
CompoundBond
>&
bondsB
,
std
::
vector
<
CompoundAtom
>
atomsB
,
const
std
::
vector
<
CompoundBond
>&
bondsB
,
vector
<
tuple
<
string
,
string
>>&
outMapping
)
std
::
vector
<
std
::
tuple
<
std
::
string
,
std
::
string
>>&
outMapping
)
{
{
assert
(
atomsA
.
size
()
==
atomsB
.
size
());
assert
(
atomsA
.
size
()
==
atomsB
.
size
());
assert
(
bondsA
.
size
()
==
bondsB
.
size
());
assert
(
bondsA
.
size
()
==
bondsB
.
size
());
vector
<
Node
>
a
,
b
;
std
::
vector
<
Node
>
a
,
b
;
map
<
string
,
size_t
>
ma
,
mb
;
std
::
map
<
std
::
string
,
size_t
>
ma
,
mb
;
for
(
auto
&
atomA
:
atomsA
)
for
(
auto
&
atomA
:
atomsA
)
{
{
...
@@ -320,7 +314,7 @@ bool StructuresAreIsomeric(vector<CompoundAtom> atomsA, const vector<CompoundBon
...
@@ -320,7 +314,7 @@ bool StructuresAreIsomeric(vector<CompoundAtom> atomsA, const vector<CompoundBon
if
(
b
[
ib
].
symbol
!=
a
[
ia
].
symbol
or
a
[
ia
].
hydrogens
!=
b
[
ib
].
hydrogens
or
a
[
ia
].
links
.
size
()
!=
b
[
ib
].
links
.
size
())
if
(
b
[
ib
].
symbol
!=
a
[
ia
].
symbol
or
a
[
ia
].
hydrogens
!=
b
[
ib
].
hydrogens
or
a
[
ia
].
links
.
size
()
!=
b
[
ib
].
links
.
size
())
continue
;
continue
;
vector
<
bool
>
va
(
N
,
false
),
vb
(
N
,
false
);
std
::
vector
<
bool
>
va
(
N
,
false
),
vb
(
N
,
false
);
if
(
SubStructuresAreIsomeric
(
a
,
b
,
ia
,
ib
,
va
,
vb
,
outMapping
))
if
(
SubStructuresAreIsomeric
(
a
,
b
,
ia
,
ib
,
va
,
vb
,
outMapping
))
{
{
...
@@ -350,7 +344,7 @@ Compound::Compound(const std::string& file, const std::string& id,
...
@@ -350,7 +344,7 @@ Compound::Compound(const std::string& file, const std::string& id,
for
(
auto
row
:
compoundAtoms
)
for
(
auto
row
:
compoundAtoms
)
{
{
string
id
,
symbol
,
energy
;
st
d
::
st
ring
id
,
symbol
,
energy
;
float
charge
;
float
charge
;
cif
::
tie
(
id
,
symbol
,
energy
,
charge
)
=
row
.
get
(
"atom_id"
,
"type_symbol"
,
"type_energy"
,
"partial_charge"
);
cif
::
tie
(
id
,
symbol
,
energy
,
charge
)
=
row
.
get
(
"atom_id"
,
"type_symbol"
,
"type_energy"
,
"partial_charge"
);
...
@@ -366,7 +360,7 @@ Compound::Compound(const std::string& file, const std::string& id,
...
@@ -366,7 +360,7 @@ Compound::Compound(const std::string& file, const std::string& id,
for
(
auto
row
:
compBonds
)
for
(
auto
row
:
compBonds
)
{
{
CompoundBond
b
;
CompoundBond
b
;
string
type
,
aromatic
;
st
d
::
st
ring
type
,
aromatic
;
cif
::
tie
(
b
.
atomID
[
0
],
b
.
atomID
[
1
],
type
,
b
.
distance
,
b
.
esd
)
=
cif
::
tie
(
b
.
atomID
[
0
],
b
.
atomID
[
1
],
type
,
b
.
distance
,
b
.
esd
)
=
row
.
get
(
"atom_id_1"
,
"atom_id_2"
,
"type"
,
"value_dist"
,
"value_dist_esd"
);
row
.
get
(
"atom_id_1"
,
"atom_id_2"
,
"type"
,
"value_dist"
,
"value_dist_esd"
);
...
@@ -381,7 +375,7 @@ Compound::Compound(const std::string& file, const std::string& id,
...
@@ -381,7 +375,7 @@ Compound::Compound(const std::string& file, const std::string& id,
else
else
{
{
if
(
cif
::
VERBOSE
)
if
(
cif
::
VERBOSE
)
cerr
<<
"Unimplemented chem_comp_bond.type "
<<
type
<<
" in "
<<
id
<<
endl
;
std
::
cerr
<<
"Unimplemented chem_comp_bond.type "
<<
type
<<
" in "
<<
id
<<
std
::
endl
;
b
.
type
=
singleBond
;
b
.
type
=
singleBond
;
}
}
...
@@ -415,7 +409,7 @@ Compound::Compound(const std::string& file, const std::string& id,
...
@@ -415,7 +409,7 @@ Compound::Compound(const std::string& file, const std::string& id,
for
(
auto
row
:
db
[
"chem_comp_chir"
])
for
(
auto
row
:
db
[
"chem_comp_chir"
])
{
{
CompoundChiralCentre
cc
;
CompoundChiralCentre
cc
;
string
volumeSign
;
st
d
::
st
ring
volumeSign
;
cif
::
tie
(
cc
.
id
,
cc
.
atomIDCentre
,
cc
.
atomID
[
0
],
cif
::
tie
(
cc
.
id
,
cc
.
atomIDCentre
,
cc
.
atomID
[
0
],
cc
.
atomID
[
1
],
cc
.
atomID
[
2
],
volumeSign
)
=
cc
.
atomID
[
1
],
cc
.
atomID
[
2
],
volumeSign
)
=
...
@@ -431,7 +425,7 @@ Compound::Compound(const std::string& file, const std::string& id,
...
@@ -431,7 +425,7 @@ Compound::Compound(const std::string& file, const std::string& id,
else
else
{
{
if
(
cif
::
VERBOSE
)
if
(
cif
::
VERBOSE
)
cerr
<<
"Unimplemented chem_comp_chir.volume_sign "
<<
volumeSign
<<
" in "
<<
id
<<
endl
;
std
::
cerr
<<
"Unimplemented chem_comp_chir.volume_sign "
<<
volumeSign
<<
" in "
<<
id
<<
std
::
endl
;
continue
;
continue
;
}
}
...
@@ -442,7 +436,7 @@ Compound::Compound(const std::string& file, const std::string& id,
...
@@ -442,7 +436,7 @@ Compound::Compound(const std::string& file, const std::string& id,
for
(
auto
row
:
compPlanes
)
for
(
auto
row
:
compPlanes
)
{
{
string
atom_id
,
plane_id
;
st
d
::
st
ring
atom_id
,
plane_id
;
float
esd
;
float
esd
;
cif
::
tie
(
atom_id
,
plane_id
,
esd
)
=
row
.
get
(
"atom_id"
,
"plane_id"
,
"dist_esd"
);
cif
::
tie
(
atom_id
,
plane_id
,
esd
)
=
row
.
get
(
"atom_id"
,
"plane_id"
,
"dist_esd"
);
...
@@ -454,18 +448,18 @@ Compound::Compound(const std::string& file, const std::string& id,
...
@@ -454,18 +448,18 @@ Compound::Compound(const std::string& file, const std::string& id,
i
->
atomID
.
push_back
(
atom_id
);
i
->
atomID
.
push_back
(
atom_id
);
}
}
}
}
catch
(
const
exception
&
ex
)
catch
(
const
std
::
exception
&
ex
)
{
{
cerr
<<
"Error loading ccp4 file for "
<<
id
<<
" from file "
<<
file
<<
endl
;
std
::
cerr
<<
"Error loading ccp4 file for "
<<
id
<<
" from file "
<<
file
<<
std
::
endl
;
throw
;
throw
;
}
}
}
}
string
Compound
::
formula
()
const
st
d
::
st
ring
Compound
::
formula
()
const
{
{
string
result
;
st
d
::
st
ring
result
;
map
<
string
,
uint32_t
>
atoms
;
std
::
map
<
std
::
string
,
uint32_t
>
atoms
;
float
chargeSum
=
0
;
float
chargeSum
=
0
;
for
(
auto
r
:
mAtoms
)
for
(
auto
r
:
mAtoms
)
...
@@ -480,7 +474,7 @@ string Compound::formula() const
...
@@ -480,7 +474,7 @@ string Compound::formula() const
result
=
"C"
;
result
=
"C"
;
if
(
c
->
second
>
1
)
if
(
c
->
second
>
1
)
result
+=
to_string
(
c
->
second
);
result
+=
std
::
to_string
(
c
->
second
);
atoms
.
erase
(
c
);
atoms
.
erase
(
c
);
...
@@ -489,7 +483,7 @@ string Compound::formula() const
...
@@ -489,7 +483,7 @@ string Compound::formula() const
{
{
result
+=
" H"
;
result
+=
" H"
;
if
(
h
->
second
>
1
)
if
(
h
->
second
>
1
)
result
+=
to_string
(
h
->
second
);
result
+=
std
::
to_string
(
h
->
second
);
atoms
.
erase
(
h
);
atoms
.
erase
(
h
);
}
}
...
@@ -502,12 +496,12 @@ string Compound::formula() const
...
@@ -502,12 +496,12 @@ string Compound::formula() const
result
+=
a
.
first
;
result
+=
a
.
first
;
if
(
a
.
second
>
1
)
if
(
a
.
second
>
1
)
result
+=
to_string
(
a
.
second
);
result
+=
std
::
to_string
(
a
.
second
);
}
}
int
charge
=
lrint
(
chargeSum
);
int
charge
=
lrint
(
chargeSum
);
if
(
charge
!=
0
)
if
(
charge
!=
0
)
result
+=
' '
+
to_string
(
charge
);
result
+=
' '
+
std
::
to_string
(
charge
);
return
result
;
return
result
;
}
}
...
@@ -532,9 +526,9 @@ int Compound::charge() const
...
@@ -532,9 +526,9 @@ int Compound::charge() const
return
lrint
(
result
);
return
lrint
(
result
);
}
}
string
Compound
::
type
()
const
st
d
::
st
ring
Compound
::
type
()
const
{
{
string
result
;
st
d
::
st
ring
result
;
// known groups are (counted from ccp4 monomer dictionary)
// known groups are (counted from ccp4 monomer dictionary)
...
@@ -579,7 +573,7 @@ bool Compound::isSugar() const
...
@@ -579,7 +573,7 @@ bool Compound::isSugar() const
return
cif
::
iequals
(
mGroup
,
"furanose"
)
or
cif
::
iequals
(
mGroup
,
"pyranose"
);
return
cif
::
iequals
(
mGroup
,
"furanose"
)
or
cif
::
iequals
(
mGroup
,
"pyranose"
);
}
}
CompoundAtom
Compound
::
getAtomByID
(
const
string
&
atomID
)
const
CompoundAtom
Compound
::
getAtomByID
(
const
st
d
::
st
ring
&
atomID
)
const
{
{
CompoundAtom
result
=
{};
CompoundAtom
result
=
{};
for
(
auto
&
a
:
mAtoms
)
for
(
auto
&
a
:
mAtoms
)
...
@@ -592,12 +586,12 @@ CompoundAtom Compound::getAtomByID(const string& atomID) const
...
@@ -592,12 +586,12 @@ CompoundAtom Compound::getAtomByID(const string& atomID) const
}
}
if
(
result
.
id
!=
atomID
)
if
(
result
.
id
!=
atomID
)
throw
out_of_range
(
"No atom "
+
atomID
+
" in Compound "
+
mID
);
throw
std
::
out_of_range
(
"No atom "
+
atomID
+
" in Compound "
+
mID
);
return
result
;
return
result
;
}
}
const
Compound
*
Compound
::
create
(
const
string
&
id
)
const
Compound
*
Compound
::
create
(
const
st
d
::
st
ring
&
id
)
{
{
auto
result
=
CompoundFactory
::
instance
().
get
(
id
);
auto
result
=
CompoundFactory
::
instance
().
get
(
id
);
if
(
result
==
nullptr
)
if
(
result
==
nullptr
)
...
@@ -605,7 +599,7 @@ const Compound* Compound::create(const string& id)
...
@@ -605,7 +599,7 @@ const Compound* Compound::create(const string& id)
return
result
;
return
result
;
}
}
bool
Compound
::
atomsBonded
(
const
st
ring
&
atomId_1
,
const
string
&
atomId_2
)
const
bool
Compound
::
atomsBonded
(
const
st
d
::
string
&
atomId_1
,
const
std
::
string
&
atomId_2
)
const
{
{
auto
i
=
find_if
(
mBonds
.
begin
(),
mBonds
.
end
(),
auto
i
=
find_if
(
mBonds
.
begin
(),
mBonds
.
end
(),
[
&
](
const
CompoundBond
&
b
)
[
&
](
const
CompoundBond
&
b
)
...
@@ -617,7 +611,7 @@ bool Compound::atomsBonded(const string& atomId_1, const string& atomId_2) const
...
@@ -617,7 +611,7 @@ bool Compound::atomsBonded(const string& atomId_1, const string& atomId_2) const
return
i
!=
mBonds
.
end
();
return
i
!=
mBonds
.
end
();
}
}
float
Compound
::
atomBondValue
(
const
st
ring
&
atomId_1
,
const
string
&
atomId_2
)
const
float
Compound
::
atomBondValue
(
const
st
d
::
string
&
atomId_1
,
const
std
::
string
&
atomId_2
)
const
{
{
auto
i
=
find_if
(
mBonds
.
begin
(),
mBonds
.
end
(),
auto
i
=
find_if
(
mBonds
.
begin
(),
mBonds
.
end
(),
[
&
](
const
CompoundBond
&
b
)
[
&
](
const
CompoundBond
&
b
)
...
@@ -652,7 +646,7 @@ bool Compound::isIsomerOf(const Compound& c) const
...
@@ -652,7 +646,7 @@ bool Compound::isIsomerOf(const Compound& c) const
break
;
break
;
// same number of atoms of each type?
// same number of atoms of each type?
map
<
AtomType
,
int
>
aTypeCount
,
bTypeCount
;
std
::
map
<
AtomType
,
int
>
aTypeCount
,
bTypeCount
;
bool
sameAtomNames
=
true
;
bool
sameAtomNames
=
true
;
for
(
size_t
i
=
0
;
i
<
mAtoms
.
size
();
++
i
)
for
(
size_t
i
=
0
;
i
<
mAtoms
.
size
();
++
i
)
...
@@ -687,13 +681,13 @@ bool Compound::isIsomerOf(const Compound& c) const
...
@@ -687,13 +681,13 @@ bool Compound::isIsomerOf(const Compound& c) const
// implement rest of tests
// implement rest of tests
vector
<
tuple
<
string
,
string
>>
mapping
;
std
::
vector
<
std
::
tuple
<
std
::
string
,
std
::
string
>>
mapping
;
result
=
StructuresAreIsomeric
(
mAtoms
,
mBonds
,
c
.
mAtoms
,
c
.
mBonds
,
mapping
);
result
=
StructuresAreIsomeric
(
mAtoms
,
mBonds
,
c
.
mAtoms
,
c
.
mBonds
,
mapping
);
if
(
cif
::
VERBOSE
and
result
)
if
(
cif
::
VERBOSE
and
result
)
{
{
for
(
auto
&
m
:
mapping
)
for
(
auto
&
m
:
mapping
)
cerr
<<
" "
<<
get
<
0
>
(
m
)
<<
" => "
<<
get
<
1
>
(
m
)
<<
endl
;
std
::
cerr
<<
" "
<<
std
::
get
<
0
>
(
m
)
<<
" => "
<<
std
::
get
<
1
>
(
m
)
<<
std
::
endl
;
}
}
break
;
break
;
...
@@ -702,20 +696,20 @@ bool Compound::isIsomerOf(const Compound& c) const
...
@@ -702,20 +696,20 @@ bool Compound::isIsomerOf(const Compound& c) const
return
result
;
return
result
;
}
}
vector
<
tuple
<
string
,
string
>>
Compound
::
mapToIsomer
(
const
Compound
&
c
)
const
std
::
vector
<
std
::
tuple
<
std
::
string
,
std
::
string
>>
Compound
::
mapToIsomer
(
const
Compound
&
c
)
const
{
{
vector
<
tuple
<
string
,
string
>>
result
;
std
::
vector
<
std
::
tuple
<
std
::
string
,
std
::
string
>>
result
;
bool
check
=
StructuresAreIsomeric
(
mAtoms
,
mBonds
,
c
.
mAtoms
,
c
.
mBonds
,
result
);
bool
check
=
StructuresAreIsomeric
(
mAtoms
,
mBonds
,
c
.
mAtoms
,
c
.
mBonds
,
result
);
if
(
not
check
)
if
(
not
check
)
throw
runtime_error
(
"Compounds "
+
id
()
+
" and "
+
c
.
id
()
+
" are not isomers in call to mapToIsomer"
);
throw
std
::
runtime_error
(
"Compounds "
+
id
()
+
" and "
+
c
.
id
()
+
" are not isomers in call to mapToIsomer"
);
return
result
;
return
result
;
}
}
vector
<
string
>
Compound
::
isomers
()
const
std
::
vector
<
std
::
string
>
Compound
::
isomers
()
const
{
{
vector
<
string
>
result
;
std
::
vector
<
std
::
string
>
result
;
auto
&
db
=
IsomerDB
::
instance
();
auto
&
db
=
IsomerDB
::
instance
();
if
(
db
.
count
(
mID
))
if
(
db
.
count
(
mID
))
...
@@ -731,7 +725,7 @@ vector<string> Compound::isomers() const
...
@@ -731,7 +725,7 @@ vector<string> Compound::isomers() const
return
result
;
return
result
;
}
}
float
Compound
::
bondAngle
(
const
st
ring
&
atomId_1
,
const
string
&
atomId_2
,
const
string
&
atomId_3
)
const
float
Compound
::
bondAngle
(
const
st
d
::
string
&
atomId_1
,
const
std
::
string
&
atomId_2
,
const
std
::
string
&
atomId_3
)
const
{
{
float
result
=
nanf
(
"1"
);
float
result
=
nanf
(
"1"
);
...
@@ -759,7 +753,7 @@ float Compound::bondAngle(const string& atomId_1, const string& atomId_2, const
...
@@ -759,7 +753,7 @@ float Compound::bondAngle(const string& atomId_1, const string& atomId_2, const
// return c;
// return c;
//}
//}
float
Compound
::
chiralVolume
(
const
string
&
centreID
)
const
float
Compound
::
chiralVolume
(
const
st
d
::
st
ring
&
centreID
)
const
{
{
float
result
=
0
;
float
result
=
0
;
...
@@ -808,7 +802,7 @@ Link::Link(cif::Datablock& db)
...
@@ -808,7 +802,7 @@ Link::Link(cif::Datablock& db)
for
(
auto
row
:
linkBonds
)
for
(
auto
row
:
linkBonds
)
{
{
LinkBond
b
;
LinkBond
b
;
string
type
,
aromatic
;
st
d
::
st
ring
type
,
aromatic
;
cif
::
tie
(
b
.
atom
[
0
].
compID
,
b
.
atom
[
0
].
atomID
,
cif
::
tie
(
b
.
atom
[
0
].
compID
,
b
.
atom
[
0
].
atomID
,
b
.
atom
[
1
].
compID
,
b
.
atom
[
1
].
atomID
,
type
,
b
.
distance
,
b
.
esd
)
=
b
.
atom
[
1
].
compID
,
b
.
atom
[
1
].
atomID
,
type
,
b
.
distance
,
b
.
esd
)
=
...
@@ -825,7 +819,7 @@ Link::Link(cif::Datablock& db)
...
@@ -825,7 +819,7 @@ Link::Link(cif::Datablock& db)
else
else
{
{
if
(
cif
::
VERBOSE
)
if
(
cif
::
VERBOSE
)
cerr
<<
"Unimplemented chem_link_bond.type "
<<
type
<<
" in "
<<
mID
<<
endl
;
std
::
cerr
<<
"Unimplemented chem_link_bond.type "
<<
type
<<
" in "
<<
mID
<<
std
::
endl
;
b
.
type
=
singleBond
;
b
.
type
=
singleBond
;
}
}
...
@@ -867,7 +861,7 @@ Link::Link(cif::Datablock& db)
...
@@ -867,7 +861,7 @@ Link::Link(cif::Datablock& db)
for
(
auto
row
:
linkChir
)
for
(
auto
row
:
linkChir
)
{
{
LinkChiralCentre
cc
;
LinkChiralCentre
cc
;
string
volumeSign
;
st
d
::
st
ring
volumeSign
;
cif
::
tie
(
cc
.
id
,
cc
.
atomCentre
.
compID
,
cc
.
atomCentre
.
atomID
,
cif
::
tie
(
cc
.
id
,
cc
.
atomCentre
.
compID
,
cc
.
atomCentre
.
atomID
,
cc
.
atom
[
0
].
compID
,
cc
.
atom
[
0
].
atomID
,
cc
.
atom
[
0
].
compID
,
cc
.
atom
[
0
].
atomID
,
...
@@ -887,7 +881,7 @@ Link::Link(cif::Datablock& db)
...
@@ -887,7 +881,7 @@ Link::Link(cif::Datablock& db)
else
else
{
{
if
(
cif
::
VERBOSE
)
if
(
cif
::
VERBOSE
)
cerr
<<
"Unimplemented chem_link_chir.volume_sign "
<<
volumeSign
<<
" in "
<<
mID
<<
endl
;
std
::
cerr
<<
"Unimplemented chem_link_chir.volume_sign "
<<
volumeSign
<<
" in "
<<
mID
<<
std
::
endl
;
continue
;
continue
;
}
}
...
@@ -898,7 +892,7 @@ Link::Link(cif::Datablock& db)
...
@@ -898,7 +892,7 @@ Link::Link(cif::Datablock& db)
for
(
auto
row
:
linkPlanes
)
for
(
auto
row
:
linkPlanes
)
{
{
int
compID
;
int
compID
;
string
atomID
,
planeID
;
st
d
::
st
ring
atomID
,
planeID
;
float
esd
;
float
esd
;
cif
::
tie
(
planeID
,
compID
,
atomID
,
esd
)
=
row
.
get
(
"plane_id"
,
"atom_comp_id"
,
"atom_id"
,
"dist_esd"
);
cif
::
tie
(
planeID
,
compID
,
atomID
,
esd
)
=
row
.
get
(
"plane_id"
,
"atom_comp_id"
,
"atom_id"
,
"dist_esd"
);
...
@@ -906,7 +900,7 @@ Link::Link(cif::Datablock& db)
...
@@ -906,7 +900,7 @@ Link::Link(cif::Datablock& db)
auto
i
=
find_if
(
mPlanes
.
begin
(),
mPlanes
.
end
(),
[
&
](
auto
&
p
)
{
return
p
.
id
==
planeID
;});
auto
i
=
find_if
(
mPlanes
.
begin
(),
mPlanes
.
end
(),
[
&
](
auto
&
p
)
{
return
p
.
id
==
planeID
;});
if
(
i
==
mPlanes
.
end
())
if
(
i
==
mPlanes
.
end
())
{
{
vector
<
LinkAtom
>
atoms
{
LinkAtom
{
compID
,
atomID
}};
std
::
vector
<
LinkAtom
>
atoms
{
LinkAtom
{
compID
,
atomID
}};
mPlanes
.
emplace_back
(
LinkPlane
{
planeID
,
move
(
atoms
),
esd
});
mPlanes
.
emplace_back
(
LinkPlane
{
planeID
,
move
(
atoms
),
esd
});
}
}
else
else
...
@@ -921,7 +915,7 @@ const Link& Link::create(const std::string& id)
...
@@ -921,7 +915,7 @@ const Link& Link::create(const std::string& id)
result
=
CompoundFactory
::
instance
().
createLink
(
id
);
result
=
CompoundFactory
::
instance
().
createLink
(
id
);
if
(
result
==
nullptr
)
if
(
result
==
nullptr
)
throw
runtime_error
(
"Link with id "
+
id
+
" not found"
);
throw
std
::
runtime_error
(
"Link with id "
+
id
+
" not found"
);
return
*
result
;
return
*
result
;
}
}
...
@@ -960,7 +954,7 @@ float Link::bondAngle(const LinkAtom& atom1, const LinkAtom& atom2, const LinkAt
...
@@ -960,7 +954,7 @@ float Link::bondAngle(const LinkAtom& atom1, const LinkAtom& atom2, const LinkAt
return
result
;
return
result
;
}
}
float
Link
::
chiralVolume
(
const
string
&
centreID
)
const
float
Link
::
chiralVolume
(
const
st
d
::
st
ring
&
centreID
)
const
{
{
float
result
=
0
;
float
result
=
0
;
...
@@ -1001,7 +995,7 @@ float Link::chiralVolume(const string& centreID) const
...
@@ -1001,7 +995,7 @@ float Link::chiralVolume(const string& centreID) const
// --------------------------------------------------------------------
// --------------------------------------------------------------------
// a factory class to generate compounds
// a factory class to generate compounds
const
map
<
string
,
char
>
kAAMap
{
const
std
::
map
<
std
::
string
,
char
>
kAAMap
{
{
"ALA"
,
'A'
},
{
"ALA"
,
'A'
},
{
"ARG"
,
'R'
},
{
"ARG"
,
'R'
},
{
"ASN"
,
'N'
},
{
"ASN"
,
'N'
},
...
@@ -1026,7 +1020,7 @@ const map<string,char> kAAMap{
...
@@ -1026,7 +1020,7 @@ const map<string,char> kAAMap{
{
"ASX"
,
'B'
}
{
"ASX"
,
'B'
}
};
};
const
map
<
string
,
char
>
kBaseMap
{
const
std
::
map
<
std
::
string
,
char
>
kBaseMap
{
{
"A"
,
'A'
},
{
"A"
,
'A'
},
{
"C"
,
'C'
},
{
"C"
,
'C'
},
{
"G"
,
'G'
},
{
"G"
,
'G'
},
...
@@ -1050,8 +1044,8 @@ class CompoundFactoryImpl
...
@@ -1050,8 +1044,8 @@ class CompoundFactoryImpl
delete
mNext
;
delete
mNext
;
}
}
Compound
*
get
(
string
id
);
Compound
*
get
(
st
d
::
st
ring
id
);
Compound
*
create
(
string
id
);
Compound
*
create
(
st
d
::
st
ring
id
);
const
Link
*
getLink
(
std
::
string
id
);
const
Link
*
getLink
(
std
::
string
id
);
const
Link
*
createLink
(
std
::
string
id
);
const
Link
*
createLink
(
std
::
string
id
);
...
@@ -1064,18 +1058,18 @@ class CompoundFactoryImpl
...
@@ -1064,18 +1058,18 @@ class CompoundFactoryImpl
return
result
;
return
result
;
}
}
st
ring
unalias
(
const
string
&
resName
)
const
st
d
::
string
unalias
(
const
std
::
string
&
resName
)
const
{
{
string
result
=
resName
;
st
d
::
st
ring
result
=
resName
;
auto
&
e
=
const_cast
<
cif
::
File
&>
(
mFile
)[
"comp_synonym_list"
];
auto
&
e
=
const_cast
<
cif
::
File
&>
(
mFile
)[
"comp_synonym_list"
];
for
(
auto
&
synonym
:
e
[
"chem_comp_synonyms"
])
for
(
auto
&
synonym
:
e
[
"chem_comp_synonyms"
])
{
{
if
(
ba
::
iequals
(
synonym
[
"comp_alternative_id"
].
as
<
string
>
(),
resName
)
==
false
)
if
(
ba
::
iequals
(
synonym
[
"comp_alternative_id"
].
as
<
st
d
::
st
ring
>
(),
resName
)
==
false
)
continue
;
continue
;
result
=
synonym
[
"comp_id"
].
as
<
string
>
();
result
=
synonym
[
"comp_id"
].
as
<
st
d
::
st
ring
>
();
ba
::
trim
(
result
);
ba
::
trim
(
result
);
break
;
break
;
}
}
...
@@ -1086,13 +1080,13 @@ class CompoundFactoryImpl
...
@@ -1086,13 +1080,13 @@ class CompoundFactoryImpl
return
result
;
return
result
;
}
}
bool
isKnownPeptide
(
const
string
&
resName
)
bool
isKnownPeptide
(
const
st
d
::
st
ring
&
resName
)
{
{
return
mKnownPeptides
.
count
(
resName
)
or
return
mKnownPeptides
.
count
(
resName
)
or
(
mNext
!=
nullptr
and
mNext
->
isKnownPeptide
(
resName
));
(
mNext
!=
nullptr
and
mNext
->
isKnownPeptide
(
resName
));
}
}
bool
isKnownBase
(
const
string
&
resName
)
bool
isKnownBase
(
const
st
d
::
st
ring
&
resName
)
{
{
return
mKnownBases
.
count
(
resName
)
or
return
mKnownBases
.
count
(
resName
)
or
(
mNext
!=
nullptr
and
mNext
->
isKnownBase
(
resName
));
(
mNext
!=
nullptr
and
mNext
->
isKnownBase
(
resName
));
...
@@ -1102,11 +1096,11 @@ class CompoundFactoryImpl
...
@@ -1102,11 +1096,11 @@ class CompoundFactoryImpl
std
::
shared_timed_mutex
mMutex
;
std
::
shared_timed_mutex
mMutex
;
std
::
string
mPath
;
std
::
string
mPath
;
vector
<
Compound
*>
mCompounds
;
std
::
vector
<
Compound
*>
mCompounds
;
vector
<
const
Link
*>
mLinks
;
std
::
vector
<
const
Link
*>
mLinks
;
/*unordered_*/
s
et
<
string
>
mKnownPeptides
;
/*unordered_*/
s
td
::
set
<
std
::
string
>
mKnownPeptides
;
s
et
<
string
>
mKnownBases
;
s
td
::
set
<
std
::
string
>
mKnownBases
;
s
et
<
string
>
mMissing
;
s
td
::
set
<
std
::
string
>
mMissing
;
cif
::
File
mFile
;
cif
::
File
mFile
;
cif
::
Category
&
mChemComp
;
cif
::
Category
&
mChemComp
;
CompoundFactoryImpl
*
mNext
;
CompoundFactoryImpl
*
mNext
;
...
@@ -1121,7 +1115,7 @@ CompoundFactoryImpl::CompoundFactoryImpl(const std::string& file, CompoundFactor
...
@@ -1121,7 +1115,7 @@ CompoundFactoryImpl::CompoundFactoryImpl(const std::string& file, CompoundFactor
for
(
auto
&
chemComp
:
mChemComp
)
for
(
auto
&
chemComp
:
mChemComp
)
{
{
string
group
,
threeLetterCode
;
st
d
::
st
ring
group
,
threeLetterCode
;
cif
::
tie
(
group
,
threeLetterCode
)
=
chemComp
.
get
(
"group"
,
"three_letter_code"
);
cif
::
tie
(
group
,
threeLetterCode
)
=
chemComp
.
get
(
"group"
,
"three_letter_code"
);
...
@@ -1136,17 +1130,17 @@ CompoundFactoryImpl::CompoundFactoryImpl(const std::string& file, CompoundFactor
...
@@ -1136,17 +1130,17 @@ CompoundFactoryImpl::CompoundFactoryImpl(const std::string& file, CompoundFactor
//{
//{
// CompoundFactoryImpl();
// CompoundFactoryImpl();
//
//
// Compound* get(string id);
// Compound* get(st
d::st
ring id);
// Compound* create(string id);
// Compound* create(st
d::st
ring id);
//
//
// void pushDictionary(const boost::filesystem::path& dictFile);
// void pushDictionary(const boost::filesystem::path& dictFile);
//
//
// // cif::File cf acts as owner of datablock
// // cif::File cf acts as owner of datablock
// cif::Datablock& getDatablock(const string& name, cif::File& cf);
// cif::Datablock& getDatablock(const st
d::st
ring& name, cif::File& cf);
//
//
// deque<cif::File> mDictionaries;
// deque<cif::File> mDictionaries;
// fs::path mClibdMon;
// fs::path mClibdMon;
// vector<Compound*> mCompounds;
//
std::
vector<Compound*> mCompounds;
// boost::shared_mutex mMutex;
// boost::shared_mutex mMutex;
//};
//};
//
//
...
@@ -1154,7 +1148,7 @@ CompoundFactoryImpl::CompoundFactoryImpl(const std::string& file, CompoundFactor
...
@@ -1154,7 +1148,7 @@ CompoundFactoryImpl::CompoundFactoryImpl(const std::string& file, CompoundFactor
//{
//{
// const char* clibdMon = getenv("CLIBD_MON");
// const char* clibdMon = getenv("CLIBD_MON");
// if (clibdMon == nullptr)
// if (clibdMon == nullptr)
// throw runtime_error("Cannot locate peptide list, please source the CCP4 environment");
// throw
std::
runtime_error("Cannot locate peptide list, please source the CCP4 environment");
// mClibdMon = clibdMon;
// mClibdMon = clibdMon;
//}
//}
//
//
...
@@ -1165,7 +1159,7 @@ CompoundFactoryImpl::CompoundFactoryImpl(const std::string& file, CompoundFactor
...
@@ -1165,7 +1159,7 @@ CompoundFactoryImpl::CompoundFactoryImpl(const std::string& file, CompoundFactor
// mDictionaries.emplace_back(dictFile);
// mDictionaries.emplace_back(dictFile);
//}
//}
//
//
//cif::Datablock& CompoundFactoryImpl::getDatablock(const string& name, cif::File& cf)
//cif::Datablock& CompoundFactoryImpl::getDatablock(const st
d::st
ring& name, cif::File& cf)
//{
//{
// cif::Datablock* result = nullptr;
// cif::Datablock* result = nullptr;
//
//
...
@@ -1195,7 +1189,7 @@ CompoundFactoryImpl::CompoundFactoryImpl(const std::string& file, CompoundFactor
...
@@ -1195,7 +1189,7 @@ CompoundFactoryImpl::CompoundFactoryImpl(const std::string& file, CompoundFactor
// }
// }
// catch (...)
// catch (...)
// {
// {
// throw_with_nested(runtime_error("Error while loading " + resFile));
// throw_with_nested(
std::
runtime_error("Error while loading " + resFile));
// }
// }
//
//
// result = cf.get(name);
// result = cf.get(name);
...
@@ -1203,12 +1197,12 @@ CompoundFactoryImpl::CompoundFactoryImpl(const std::string& file, CompoundFactor
...
@@ -1203,12 +1197,12 @@ CompoundFactoryImpl::CompoundFactoryImpl(const std::string& file, CompoundFactor
// }
// }
//
//
// if (result == nullptr)
// if (result == nullptr)
// throw runtime_error("Failed to load datablock " + name);
// throw
std::
runtime_error("Failed to load datablock " + name);
//
//
// return *result;
// return *result;
//}
//}
Compound
*
CompoundFactoryImpl
::
get
(
string
id
)
Compound
*
CompoundFactoryImpl
::
get
(
st
d
::
st
ring
id
)
{
{
std
::
shared_lock
lock
(
mMutex
);
std
::
shared_lock
lock
(
mMutex
);
...
@@ -1246,7 +1240,7 @@ Compound* CompoundFactoryImpl::create(std::string id)
...
@@ -1246,7 +1240,7 @@ Compound* CompoundFactoryImpl::create(std::string id)
{
{
auto
row
=
rs
.
front
();
auto
row
=
rs
.
front
();
string
name
,
group
;
st
d
::
st
ring
name
,
group
;
uint32_t
numberAtomsAll
,
numberAtomsNh
;
uint32_t
numberAtomsAll
,
numberAtomsNh
;
cif
::
tie
(
name
,
group
,
numberAtomsAll
,
numberAtomsNh
)
=
cif
::
tie
(
name
,
group
,
numberAtomsAll
,
numberAtomsNh
)
=
row
.
get
(
"name"
,
"group"
,
"number_atoms_all"
,
"number_atoms_nh"
);
row
.
get
(
"name"
,
"group"
,
"number_atoms_all"
,
"number_atoms_nh"
);
...
@@ -1285,7 +1279,7 @@ Compound* CompoundFactoryImpl::create(std::string id)
...
@@ -1285,7 +1279,7 @@ Compound* CompoundFactoryImpl::create(std::string id)
return
result
;
return
result
;
}
}
const
Link
*
CompoundFactoryImpl
::
getLink
(
string
id
)
const
Link
*
CompoundFactoryImpl
::
getLink
(
st
d
::
st
ring
id
)
{
{
std
::
shared_lock
lock
(
mMutex
);
std
::
shared_lock
lock
(
mMutex
);
...
@@ -1341,7 +1335,7 @@ CompoundFactory::CompoundFactory()
...
@@ -1341,7 +1335,7 @@ CompoundFactory::CompoundFactory()
{
{
const
char
*
clibdMon
=
getenv
(
"CLIBD_MON"
);
const
char
*
clibdMon
=
getenv
(
"CLIBD_MON"
);
if
(
clibdMon
==
nullptr
)
if
(
clibdMon
==
nullptr
)
throw
runtime_error
(
"Cannot locate peptide list, please source the CCP4 environment"
);
throw
std
::
runtime_error
(
"Cannot locate peptide list, please source the CCP4 environment"
);
fs
::
path
db
=
fs
::
path
(
clibdMon
)
/
"list"
/
"mon_lib_list.cif"
;
fs
::
path
db
=
fs
::
path
(
clibdMon
)
/
"list"
/
"mon_lib_list.cif"
;
...
@@ -1360,22 +1354,22 @@ CompoundFactory& CompoundFactory::instance()
...
@@ -1360,22 +1354,22 @@ CompoundFactory& CompoundFactory::instance()
return
*
sInstance
;
return
*
sInstance
;
}
}
void
CompoundFactory
::
pushDictionary
(
const
string
&
inDictFile
)
void
CompoundFactory
::
pushDictionary
(
const
st
d
::
st
ring
&
inDictFile
)
{
{
if
(
not
fs
::
exists
(
inDictFile
))
if
(
not
fs
::
exists
(
inDictFile
))
throw
runtime_error
(
"file not found: "
+
inDictFile
);
throw
std
::
runtime_error
(
"file not found: "
+
inDictFile
);
// ifstream file(inDictFile);
// ifstream file(inDictFile);
// if (not file.is_open())
// if (not file.is_open())
// throw runtime_error("Could not open peptide list " + inDictFile);
// throw
std::
runtime_error("Could not open peptide list " + inDictFile);
try
try
{
{
mImpl
=
new
CompoundFactoryImpl
(
inDictFile
,
mImpl
);
mImpl
=
new
CompoundFactoryImpl
(
inDictFile
,
mImpl
);
}
}
catch
(
const
exception
&
ex
)
catch
(
const
std
::
exception
&
ex
)
{
{
cerr
<<
"Error loading dictionary "
<<
inDictFile
<<
endl
;
std
::
cerr
<<
"Error loading dictionary "
<<
inDictFile
<<
std
::
endl
;
throw
;
throw
;
}
}
}
}
...
@@ -1407,17 +1401,17 @@ const Link* CompoundFactory::createLink(std::string id)
...
@@ -1407,17 +1401,17 @@ const Link* CompoundFactory::createLink(std::string id)
return
mImpl
->
createLink
(
id
);
return
mImpl
->
createLink
(
id
);
}
}
bool
CompoundFactory
::
isKnownPeptide
(
const
string
&
resName
)
const
bool
CompoundFactory
::
isKnownPeptide
(
const
st
d
::
st
ring
&
resName
)
const
{
{
return
mImpl
->
isKnownPeptide
(
resName
);
return
mImpl
->
isKnownPeptide
(
resName
);
}
}
bool
CompoundFactory
::
isKnownBase
(
const
string
&
resName
)
const
bool
CompoundFactory
::
isKnownBase
(
const
st
d
::
st
ring
&
resName
)
const
{
{
return
mImpl
->
isKnownBase
(
resName
);
return
mImpl
->
isKnownBase
(
resName
);
}
}
st
ring
CompoundFactory
::
unalias
(
const
string
&
resName
)
const
st
d
::
string
CompoundFactory
::
unalias
(
const
std
::
string
&
resName
)
const
{
{
return
mImpl
->
unalias
(
resName
);
return
mImpl
->
unalias
(
resName
);
}
}
...
...
src/FixDMC.cpp
deleted
100644 → 0
View file @
ac088dd0
/*-
* SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2020 NKI/AVL, Netherlands Cancer Institute
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <set>
#include <cif++/Structure.hpp>
namespace
mmcif
{
void
addC
(
Monomer
&
mon
)
{
}
void
addCA
(
Monomer
&
mon
)
{
}
void
addN
(
Monomer
&
mon
)
{
}
void
addO
(
Monomer
&
mon
)
{
}
void
CreateMissingBackboneAtoms
(
Structure
&
structure
,
bool
simplified
)
{
for
(
auto
&
poly
:
structure
.
polymers
())
{
for
(
auto
&
mon
:
poly
)
{
if
(
mon
.
isComplete
()
or
mon
.
hasAlternateBackboneAtoms
())
continue
;
auto
atomC
=
mon
.
atomByID
(
"C"
);
auto
atomCA
=
mon
.
atomByID
(
"CA"
);
auto
atomN
=
mon
.
atomByID
(
"N"
);
auto
atomO
=
mon
.
atomByID
(
"O"
);
int
missing
=
(
atomC
?
0
:
1
)
+
(
atomCA
?
0
:
1
)
+
(
atomN
?
0
:
1
)
+
(
atomO
?
0
:
1
);
switch
(
missing
)
{
case
1
:
if
(
not
atomO
)
addO
(
mon
);
else
if
(
not
atomN
)
addN
(
mon
);
else
if
(
not
atomCA
)
addCA
(
mon
);
else
if
(
not
atomC
)
addC
(
mon
);
break
;
}
}
}
}
}
\ No newline at end of file
src/PDB2Cif.cpp
View file @
4b4757ee
This source diff could not be displayed because it is too large. You can
view the blob
instead.
src/PDB2CifRemark3.cpp
View file @
4b4757ee
...
@@ -33,14 +33,12 @@
...
@@ -33,14 +33,12 @@
#include <boost/date_time/gregorian/gregorian.hpp>
#include <boost/date_time/gregorian/gregorian.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/format.hpp>
#include <boost/format.hpp>
// #include <boost/numeric/ublas/matrix.hpp>
#include "cif++/AtomType.hpp"
#include "cif++/AtomType.hpp"
#include "cif++/Compound.hpp"
#include "cif++/Compound.hpp"
#include "cif++/PDB2CifRemark3.hpp"
#include "cif++/PDB2CifRemark3.hpp"
#include "cif++/CifUtils.hpp"
#include "cif++/CifUtils.hpp"
using
namespace
std
;
namespace
ba
=
boost
::
algorithm
;
namespace
ba
=
boost
::
algorithm
;
using
cif
::
Datablock
;
using
cif
::
Datablock
;
...
@@ -53,12 +51,12 @@ using cif::iequals;
...
@@ -53,12 +51,12 @@ using cif::iequals;
struct
TemplateLine
struct
TemplateLine
{
{
const
char
*
rx
;
const
char
*
rx
;
int
nextStateOffset
;
int
nextStateOffset
;
const
char
*
category
;
const
char
*
category
;
initializer_list
<
const
char
*>
items
;
std
::
initializer_list
<
const
char
*>
items
;
const
char
*
lsRestrType
=
nullptr
;
const
char
*
lsRestrType
=
nullptr
;
bool
createNew
;
bool
createNew
;
};
};
// --------------------------------------------------------------------
// --------------------------------------------------------------------
...
@@ -168,10 +166,10 @@ const TemplateLine kBusterTNT_Template[] = {
...
@@ -168,10 +166,10 @@ const TemplateLine kBusterTNT_Template[] = {
class
BUSTER_TNT_Remark3Parser
:
public
Remark3Parser
class
BUSTER_TNT_Remark3Parser
:
public
Remark3Parser
{
{
public
:
public
:
BUSTER_TNT_Remark3Parser
(
const
st
ring
&
name
,
const
string
&
expMethod
,
PDBRecord
*
r
,
cif
::
Datablock
&
db
)
BUSTER_TNT_Remark3Parser
(
const
st
d
::
string
&
name
,
const
std
::
string
&
expMethod
,
PDBRecord
*
r
,
cif
::
Datablock
&
db
)
:
Remark3Parser
(
name
,
expMethod
,
r
,
db
,
:
Remark3Parser
(
name
,
expMethod
,
r
,
db
,
kBusterTNT_Template
,
sizeof
(
kBusterTNT_Template
)
/
sizeof
(
TemplateLine
),
kBusterTNT_Template
,
sizeof
(
kBusterTNT_Template
)
/
sizeof
(
TemplateLine
),
regex
(
R"((BUSTER(?:-TNT)?)(?: (\d+(?:\..+)?))?)"
))
{}
std
::
regex
(
R"((BUSTER(?:-TNT)?)(?: (\d+(?:\..+)?))?)"
))
{}
};
};
const
TemplateLine
kCNS_Template
[]
=
{
const
TemplateLine
kCNS_Template
[]
=
{
...
@@ -261,9 +259,9 @@ const TemplateLine kCNS_Template[] = {
...
@@ -261,9 +259,9 @@ const TemplateLine kCNS_Template[] = {
class
CNS_Remark3Parser
:
public
Remark3Parser
class
CNS_Remark3Parser
:
public
Remark3Parser
{
{
public
:
public
:
CNS_Remark3Parser
(
const
st
ring
&
name
,
const
string
&
expMethod
,
PDBRecord
*
r
,
cif
::
Datablock
&
db
)
CNS_Remark3Parser
(
const
st
d
::
string
&
name
,
const
std
::
string
&
expMethod
,
PDBRecord
*
r
,
cif
::
Datablock
&
db
)
:
Remark3Parser
(
name
,
expMethod
,
r
,
db
,
kCNS_Template
,
:
Remark3Parser
(
name
,
expMethod
,
r
,
db
,
kCNS_Template
,
sizeof
(
kCNS_Template
)
/
sizeof
(
TemplateLine
),
regex
(
R"((CN[SX])(?: (\d+(?:\.\d+)?))?)"
))
{}
sizeof
(
kCNS_Template
)
/
sizeof
(
TemplateLine
),
std
::
regex
(
R"((CN[SX])(?: (\d+(?:\.\d+)?))?)"
))
{}
};
};
const
TemplateLine
kPHENIX_Template
[]
=
{
const
TemplateLine
kPHENIX_Template
[]
=
{
...
@@ -339,9 +337,9 @@ const TemplateLine kPHENIX_Template[] = {
...
@@ -339,9 +337,9 @@ const TemplateLine kPHENIX_Template[] = {
class
PHENIX_Remark3Parser
:
public
Remark3Parser
class
PHENIX_Remark3Parser
:
public
Remark3Parser
{
{
public
:
public
:
PHENIX_Remark3Parser
(
const
st
ring
&
name
,
const
string
&
expMethod
,
PDBRecord
*
r
,
cif
::
Datablock
&
db
)
PHENIX_Remark3Parser
(
const
st
d
::
string
&
name
,
const
std
::
string
&
expMethod
,
PDBRecord
*
r
,
cif
::
Datablock
&
db
)
:
Remark3Parser
(
name
,
expMethod
,
r
,
db
,
kPHENIX_Template
,
sizeof
(
kPHENIX_Template
)
/
sizeof
(
TemplateLine
),
:
Remark3Parser
(
name
,
expMethod
,
r
,
db
,
kPHENIX_Template
,
sizeof
(
kPHENIX_Template
)
/
sizeof
(
TemplateLine
),
regex
(
R"((PHENIX)(?: \(PHENIX\.REFINE:) (\d+(?:\.[^)]+)?)\)?)"
))
{}
std
::
regex
(
R"((PHENIX)(?: \(PHENIX\.REFINE:) (\d+(?:\.[^)]+)?)\)?)"
))
{}
virtual
void
fixup
();
virtual
void
fixup
();
};
};
...
@@ -423,9 +421,9 @@ const TemplateLine kNUCLSQ_Template[] = {
...
@@ -423,9 +421,9 @@ const TemplateLine kNUCLSQ_Template[] = {
class
NUCLSQ_Remark3Parser
:
public
Remark3Parser
class
NUCLSQ_Remark3Parser
:
public
Remark3Parser
{
{
public
:
public
:
NUCLSQ_Remark3Parser
(
const
st
ring
&
name
,
const
string
&
expMethod
,
PDBRecord
*
r
,
cif
::
Datablock
&
db
)
NUCLSQ_Remark3Parser
(
const
st
d
::
string
&
name
,
const
std
::
string
&
expMethod
,
PDBRecord
*
r
,
cif
::
Datablock
&
db
)
:
Remark3Parser
(
name
,
expMethod
,
r
,
db
,
kNUCLSQ_Template
,
sizeof
(
kNUCLSQ_Template
)
/
sizeof
(
TemplateLine
),
:
Remark3Parser
(
name
,
expMethod
,
r
,
db
,
kNUCLSQ_Template
,
sizeof
(
kNUCLSQ_Template
)
/
sizeof
(
TemplateLine
),
regex
(
R"((NUCLSQ)(?: (\d+(?:\.\d+)?))?)"
))
{}
std
::
regex
(
R"((NUCLSQ)(?: (\d+(?:\.\d+)?))?)"
))
{}
virtual
void
fixup
()
virtual
void
fixup
()
{
{
...
@@ -512,9 +510,9 @@ const TemplateLine kPROLSQ_Template[] = {
...
@@ -512,9 +510,9 @@ const TemplateLine kPROLSQ_Template[] = {
class
PROLSQ_Remark3Parser
:
public
Remark3Parser
class
PROLSQ_Remark3Parser
:
public
Remark3Parser
{
{
public
:
public
:
PROLSQ_Remark3Parser
(
const
st
ring
&
name
,
const
string
&
expMethod
,
PDBRecord
*
r
,
cif
::
Datablock
&
db
)
PROLSQ_Remark3Parser
(
const
st
d
::
string
&
name
,
const
std
::
string
&
expMethod
,
PDBRecord
*
r
,
cif
::
Datablock
&
db
)
:
Remark3Parser
(
name
,
expMethod
,
r
,
db
,
kPROLSQ_Template
,
sizeof
(
kPROLSQ_Template
)
/
sizeof
(
TemplateLine
),
:
Remark3Parser
(
name
,
expMethod
,
r
,
db
,
kPROLSQ_Template
,
sizeof
(
kPROLSQ_Template
)
/
sizeof
(
TemplateLine
),
regex
(
R"((PROLSQ)(?: (\d+(?:\.\d+)?))?)"
))
{}
std
::
regex
(
R"((PROLSQ)(?: (\d+(?:\.\d+)?))?)"
))
{}
virtual
void
fixup
()
virtual
void
fixup
()
{
{
...
@@ -597,12 +595,12 @@ const TemplateLine kREFMAC_Template[] = {
...
@@ -597,12 +595,12 @@ const TemplateLine kREFMAC_Template[] = {
class
REFMAC_Remark3Parser
:
public
Remark3Parser
class
REFMAC_Remark3Parser
:
public
Remark3Parser
{
{
public
:
public
:
REFMAC_Remark3Parser
(
const
st
ring
&
name
,
const
string
&
expMethod
,
PDBRecord
*
r
,
cif
::
Datablock
&
db
)
REFMAC_Remark3Parser
(
const
st
d
::
string
&
name
,
const
std
::
string
&
expMethod
,
PDBRecord
*
r
,
cif
::
Datablock
&
db
)
:
Remark3Parser
(
name
,
expMethod
,
r
,
db
,
kREFMAC_Template
,
sizeof
(
kREFMAC_Template
)
/
sizeof
(
TemplateLine
),
:
Remark3Parser
(
name
,
expMethod
,
r
,
db
,
kREFMAC_Template
,
sizeof
(
kREFMAC_Template
)
/
sizeof
(
TemplateLine
),
regex
(
".+"
))
{}
std
::
regex
(
".+"
))
{}
virtual
string
program
()
{
return
"REFMAC"
;
}
virtual
st
d
::
st
ring
program
()
{
return
"REFMAC"
;
}
virtual
string
version
()
{
return
""
;
}
virtual
st
d
::
st
ring
version
()
{
return
""
;
}
};
};
const
TemplateLine
kREFMAC5_Template
[]
=
{
const
TemplateLine
kREFMAC5_Template
[]
=
{
...
@@ -749,9 +747,9 @@ const TemplateLine kREFMAC5_Template[] = {
...
@@ -749,9 +747,9 @@ const TemplateLine kREFMAC5_Template[] = {
class
REFMAC5_Remark3Parser
:
public
Remark3Parser
class
REFMAC5_Remark3Parser
:
public
Remark3Parser
{
{
public
:
public
:
REFMAC5_Remark3Parser
(
const
st
ring
&
name
,
const
string
&
expMethod
,
PDBRecord
*
r
,
cif
::
Datablock
&
db
)
REFMAC5_Remark3Parser
(
const
st
d
::
string
&
name
,
const
std
::
string
&
expMethod
,
PDBRecord
*
r
,
cif
::
Datablock
&
db
)
:
Remark3Parser
(
name
,
expMethod
,
r
,
db
,
kREFMAC5_Template
,
sizeof
(
kREFMAC5_Template
)
/
sizeof
(
TemplateLine
),
:
Remark3Parser
(
name
,
expMethod
,
r
,
db
,
kREFMAC5_Template
,
sizeof
(
kREFMAC5_Template
)
/
sizeof
(
TemplateLine
),
regex
(
R"((REFMAC)(?: (\d+(?:\..+)?))?)"
))
{}
std
::
regex
(
R"((REFMAC)(?: (\d+(?:\..+)?))?)"
))
{}
};
};
const
TemplateLine
kSHELXL_Template
[]
=
{
const
TemplateLine
kSHELXL_Template
[]
=
{
...
@@ -807,9 +805,9 @@ const TemplateLine kSHELXL_Template[] = {
...
@@ -807,9 +805,9 @@ const TemplateLine kSHELXL_Template[] = {
class
SHELXL_Remark3Parser
:
public
Remark3Parser
class
SHELXL_Remark3Parser
:
public
Remark3Parser
{
{
public
:
public
:
SHELXL_Remark3Parser
(
const
st
ring
&
name
,
const
string
&
expMethod
,
PDBRecord
*
r
,
cif
::
Datablock
&
db
)
SHELXL_Remark3Parser
(
const
st
d
::
string
&
name
,
const
std
::
string
&
expMethod
,
PDBRecord
*
r
,
cif
::
Datablock
&
db
)
:
Remark3Parser
(
name
,
expMethod
,
r
,
db
,
kSHELXL_Template
,
sizeof
(
kSHELXL_Template
)
/
sizeof
(
TemplateLine
),
:
Remark3Parser
(
name
,
expMethod
,
r
,
db
,
kSHELXL_Template
,
sizeof
(
kSHELXL_Template
)
/
sizeof
(
TemplateLine
),
regex
(
R"((SHELXL)(?:-(\d+(?:\..+)?)))"
))
{}
std
::
regex
(
R"((SHELXL)(?:-(\d+(?:\..+)?)))"
))
{}
};
};
const
TemplateLine
kTNT_Template
[]
=
{
const
TemplateLine
kTNT_Template
[]
=
{
...
@@ -862,9 +860,9 @@ const TemplateLine kTNT_Template[] = {
...
@@ -862,9 +860,9 @@ const TemplateLine kTNT_Template[] = {
class
TNT_Remark3Parser
:
public
Remark3Parser
class
TNT_Remark3Parser
:
public
Remark3Parser
{
{
public
:
public
:
TNT_Remark3Parser
(
const
st
ring
&
name
,
const
string
&
expMethod
,
PDBRecord
*
r
,
cif
::
Datablock
&
db
)
TNT_Remark3Parser
(
const
st
d
::
string
&
name
,
const
std
::
string
&
expMethod
,
PDBRecord
*
r
,
cif
::
Datablock
&
db
)
:
Remark3Parser
(
name
,
expMethod
,
r
,
db
,
kTNT_Template
,
sizeof
(
kTNT_Template
)
/
sizeof
(
TemplateLine
),
:
Remark3Parser
(
name
,
expMethod
,
r
,
db
,
kTNT_Template
,
sizeof
(
kTNT_Template
)
/
sizeof
(
TemplateLine
),
regex
(
R"((TNT)(?: V. (\d+.+)?)?)"
))
{}
std
::
regex
(
R"((TNT)(?: V. (\d+.+)?)?)"
))
{}
};
};
const
TemplateLine
kXPLOR_Template
[]
=
{
const
TemplateLine
kXPLOR_Template
[]
=
{
...
@@ -940,9 +938,9 @@ const TemplateLine kXPLOR_Template[] = {
...
@@ -940,9 +938,9 @@ const TemplateLine kXPLOR_Template[] = {
class
XPLOR_Remark3Parser
:
public
Remark3Parser
class
XPLOR_Remark3Parser
:
public
Remark3Parser
{
{
public
:
public
:
XPLOR_Remark3Parser
(
const
st
ring
&
name
,
const
string
&
expMethod
,
PDBRecord
*
r
,
cif
::
Datablock
&
db
)
XPLOR_Remark3Parser
(
const
st
d
::
string
&
name
,
const
std
::
string
&
expMethod
,
PDBRecord
*
r
,
cif
::
Datablock
&
db
)
:
Remark3Parser
(
name
,
expMethod
,
r
,
db
,
kXPLOR_Template
,
sizeof
(
kXPLOR_Template
)
/
sizeof
(
TemplateLine
),
:
Remark3Parser
(
name
,
expMethod
,
r
,
db
,
kXPLOR_Template
,
sizeof
(
kXPLOR_Template
)
/
sizeof
(
TemplateLine
),
regex
(
R"((X-PLOR)(?: (\d+(?:\.\d+)?))?)"
))
{}
std
::
regex
(
R"((X-PLOR)(?: (\d+(?:\.\d+)?))?)"
))
{}
};
};
// --------------------------------------------------------------------
// --------------------------------------------------------------------
...
@@ -954,7 +952,7 @@ Remark3Parser::Remark3Parser(const std::string& name, const std::string& expMeth
...
@@ -954,7 +952,7 @@ Remark3Parser::Remark3Parser(const std::string& name, const std::string& expMeth
{
{
}
}
string
Remark3Parser
::
nextLine
()
st
d
::
st
ring
Remark3Parser
::
nextLine
()
{
{
mLine
.
clear
();
mLine
.
clear
();
...
@@ -985,11 +983,11 @@ string Remark3Parser::nextLine()
...
@@ -985,11 +983,11 @@ string Remark3Parser::nextLine()
if
(
valueIndent
>
4
)
if
(
valueIndent
>
4
)
{
{
string
indent
(
valueIndent
-
4
,
' '
);
st
d
::
st
ring
indent
(
valueIndent
-
4
,
' '
);
while
(
mRec
->
is
(
"REMARK 3"
)
and
mRec
->
mVlen
>
valueIndent
)
while
(
mRec
->
is
(
"REMARK 3"
)
and
mRec
->
mVlen
>
valueIndent
)
{
{
string
v
(
mRec
->
mValue
+
4
,
mRec
->
mValue
+
mRec
->
mVlen
);
st
d
::
st
ring
v
(
mRec
->
mValue
+
4
,
mRec
->
mValue
+
mRec
->
mVlen
);
if
(
not
ba
::
starts_with
(
v
,
indent
))
if
(
not
ba
::
starts_with
(
v
,
indent
))
break
;
break
;
...
@@ -1024,21 +1022,21 @@ string Remark3Parser::nextLine()
...
@@ -1024,21 +1022,21 @@ string Remark3Parser::nextLine()
}
}
if
(
cif
::
VERBOSE
>=
2
)
if
(
cif
::
VERBOSE
>=
2
)
cerr
<<
"RM3: "
<<
mLine
<<
endl
;
std
::
cerr
<<
"RM3: "
<<
mLine
<<
std
::
endl
;
return
mLine
;
return
mLine
;
}
}
bool
Remark3Parser
::
match
(
const
char
*
expr
,
int
nextState
)
bool
Remark3Parser
::
match
(
const
char
*
expr
,
int
nextState
)
{
{
regex
rx
(
expr
);
std
::
regex
rx
(
expr
);
bool
result
=
regex_match
(
mLine
,
mM
,
rx
);
bool
result
=
regex_match
(
mLine
,
mM
,
rx
);
if
(
result
)
if
(
result
)
mState
=
nextState
;
mState
=
nextState
;
else
if
(
cif
::
VERBOSE
>=
3
)
else
if
(
cif
::
VERBOSE
>=
3
)
cerr
<<
cif
::
coloured
(
"No match:"
,
cif
::
scWHITE
,
cif
::
scRED
)
<<
" '"
<<
expr
<<
'\''
<<
endl
;
std
::
cerr
<<
cif
::
coloured
(
"No match:"
,
cif
::
scWHITE
,
cif
::
scRED
)
<<
" '"
<<
expr
<<
'\''
<<
std
::
endl
;
return
result
;
return
result
;
}
}
...
@@ -1046,7 +1044,7 @@ bool Remark3Parser::match(const char* expr, int nextState)
...
@@ -1046,7 +1044,7 @@ bool Remark3Parser::match(const char* expr, int nextState)
float
Remark3Parser
::
parse
()
float
Remark3Parser
::
parse
()
{
{
int
lineCount
=
0
,
dropped
=
0
;
int
lineCount
=
0
,
dropped
=
0
;
string
remarks
;
st
d
::
st
ring
remarks
;
mState
=
0
;
mState
=
0
;
while
(
mRec
!=
nullptr
)
while
(
mRec
!=
nullptr
)
...
@@ -1098,7 +1096,7 @@ float Remark3Parser::parse()
...
@@ -1098,7 +1096,7 @@ float Remark3Parser::parse()
}
}
if
(
cif
::
VERBOSE
>=
2
)
if
(
cif
::
VERBOSE
>=
2
)
cerr
<<
cif
::
coloured
(
"Dropping line:"
,
cif
::
scWHITE
,
cif
::
scRED
)
<<
" '"
<<
mLine
<<
'\''
<<
endl
;
std
::
cerr
<<
cif
::
coloured
(
"Dropping line:"
,
cif
::
scWHITE
,
cif
::
scRED
)
<<
" '"
<<
mLine
<<
'\''
<<
std
::
endl
;
++
dropped
;
++
dropped
;
}
}
...
@@ -1114,43 +1112,43 @@ float Remark3Parser::parse()
...
@@ -1114,43 +1112,43 @@ float Remark3Parser::parse()
return
score
;
return
score
;
}
}
string
Remark3Parser
::
program
()
st
d
::
st
ring
Remark3Parser
::
program
()
{
{
string
result
=
mName
;
st
d
::
st
ring
result
=
mName
;
smatch
m
;
s
td
::
s
match
m
;
if
(
regex_match
(
mName
,
m
,
mProgramVersion
))
if
(
regex_match
(
mName
,
m
,
mProgramVersion
))
result
=
m
[
1
].
str
();
result
=
m
[
1
].
str
();
return
result
;
return
result
;
}
}
string
Remark3Parser
::
version
()
st
d
::
st
ring
Remark3Parser
::
version
()
{
{
string
result
;
st
d
::
st
ring
result
;
smatch
m
;
s
td
::
s
match
m
;
if
(
regex_match
(
mName
,
m
,
mProgramVersion
))
if
(
regex_match
(
mName
,
m
,
mProgramVersion
))
result
=
m
[
2
].
str
();
result
=
m
[
2
].
str
();
return
result
;
return
result
;
}
}
void
Remark3Parser
::
storeCapture
(
const
char
*
category
,
initializer_list
<
const
char
*>
items
,
bool
createNew
)
void
Remark3Parser
::
storeCapture
(
const
char
*
category
,
std
::
initializer_list
<
const
char
*>
items
,
bool
createNew
)
{
{
int
capture
=
0
;
int
capture
=
0
;
for
(
auto
item
:
items
)
for
(
auto
item
:
items
)
{
{
++
capture
;
++
capture
;
string
value
=
mM
[
capture
].
str
();
st
d
::
st
ring
value
=
mM
[
capture
].
str
();
ba
::
trim
(
value
);
ba
::
trim
(
value
);
if
(
iequals
(
value
,
"NULL"
)
or
iequals
(
value
,
"NONE"
)
or
iequals
(
value
,
"Inf"
)
or
iequals
(
value
,
"+Inf"
)
or
iequals
(
value
,
string
(
value
.
length
(),
'*'
)))
if
(
iequals
(
value
,
"NULL"
)
or
iequals
(
value
,
"NONE"
)
or
iequals
(
value
,
"Inf"
)
or
iequals
(
value
,
"+Inf"
)
or
iequals
(
value
,
st
d
::
st
ring
(
value
.
length
(),
'*'
)))
continue
;
continue
;
if
(
cif
::
VERBOSE
>=
3
)
if
(
cif
::
VERBOSE
>=
3
)
cerr
<<
"storing: '"
<<
value
<<
"' in _"
<<
category
<<
'.'
<<
item
<<
endl
;
std
::
cerr
<<
"storing: '"
<<
value
<<
"' in _"
<<
category
<<
'.'
<<
item
<<
std
::
endl
;
auto
&
cat
=
mDb
[
category
];
auto
&
cat
=
mDb
[
category
];
if
(
cat
.
empty
()
or
createNew
)
if
(
cat
.
empty
()
or
createNew
)
...
@@ -1170,7 +1168,7 @@ void Remark3Parser::storeCapture(const char* category, initializer_list<const ch
...
@@ -1170,7 +1168,7 @@ void Remark3Parser::storeCapture(const char* category, initializer_list<const ch
});
});
else
if
(
iequals
(
category
,
"refine_hist"
))
else
if
(
iequals
(
category
,
"refine_hist"
))
{
{
string
dResHigh
,
dResLow
;
st
d
::
st
ring
dResHigh
,
dResLow
;
for
(
auto
r
:
mDb
[
"refine"
])
for
(
auto
r
:
mDb
[
"refine"
])
{
{
cif
::
tie
(
dResHigh
,
dResLow
)
=
r
.
get
(
"ls_d_res_high"
,
"ls_d_res_low"
);
cif
::
tie
(
dResHigh
,
dResLow
)
=
r
.
get
(
"ls_d_res_high"
,
"ls_d_res_low"
);
...
@@ -1192,9 +1190,9 @@ void Remark3Parser::storeCapture(const char* category, initializer_list<const ch
...
@@ -1192,9 +1190,9 @@ void Remark3Parser::storeCapture(const char* category, initializer_list<const ch
}
}
else
if
(
iequals
(
category
,
"pdbx_refine_tls_group"
))
else
if
(
iequals
(
category
,
"pdbx_refine_tls_group"
))
{
{
string
tlsGroupID
;
st
d
::
st
ring
tlsGroupID
;
if
(
not
mDb
[
"pdbx_refine_tls"
].
empty
())
if
(
not
mDb
[
"pdbx_refine_tls"
].
empty
())
tlsGroupID
=
mDb
[
"pdbx_refine_tls"
].
back
()[
"id"
].
as
<
string
>
();
tlsGroupID
=
mDb
[
"pdbx_refine_tls"
].
back
()[
"id"
].
as
<
st
d
::
st
ring
>
();
cat
.
emplace
({
cat
.
emplace
({
{
"pdbx_refine_id"
,
mExpMethod
},
{
"pdbx_refine_id"
,
mExpMethod
},
...
@@ -1241,7 +1239,7 @@ void Remark3Parser::storeCapture(const char* category, initializer_list<const ch
...
@@ -1241,7 +1239,7 @@ void Remark3Parser::storeCapture(const char* category, initializer_list<const ch
}
}
}
}
void
Remark3Parser
::
storeRefineLsRestr
(
const
char
*
type
,
initializer_list
<
const
char
*>
items
)
void
Remark3Parser
::
storeRefineLsRestr
(
const
char
*
type
,
std
::
initializer_list
<
const
char
*>
items
)
{
{
Row
r
;
Row
r
;
int
capture
=
0
;
int
capture
=
0
;
...
@@ -1250,9 +1248,9 @@ void Remark3Parser::storeRefineLsRestr(const char* type, initializer_list<const
...
@@ -1250,9 +1248,9 @@ void Remark3Parser::storeRefineLsRestr(const char* type, initializer_list<const
{
{
++
capture
;
++
capture
;
string
value
=
mM
[
capture
].
str
();
st
d
::
st
ring
value
=
mM
[
capture
].
str
();
ba
::
trim
(
value
);
ba
::
trim
(
value
);
if
(
value
.
empty
()
or
iequals
(
value
,
"NULL"
)
or
iequals
(
value
,
"Inf"
)
or
iequals
(
value
,
"+Inf"
)
or
iequals
(
value
,
string
(
value
.
length
(),
'*'
)))
if
(
value
.
empty
()
or
iequals
(
value
,
"NULL"
)
or
iequals
(
value
,
"Inf"
)
or
iequals
(
value
,
"+Inf"
)
or
iequals
(
value
,
st
d
::
st
ring
(
value
.
length
(),
'*'
)))
continue
;
continue
;
if
(
not
r
)
if
(
not
r
)
...
@@ -1267,7 +1265,7 @@ void Remark3Parser::storeRefineLsRestr(const char* type, initializer_list<const
...
@@ -1267,7 +1265,7 @@ void Remark3Parser::storeRefineLsRestr(const char* type, initializer_list<const
}
}
}
}
void
Remark3Parser
::
updateRefineLsRestr
(
const
char
*
type
,
initializer_list
<
const
char
*>
items
)
void
Remark3Parser
::
updateRefineLsRestr
(
const
char
*
type
,
std
::
initializer_list
<
const
char
*>
items
)
{
{
auto
rows
=
mDb
[
"refine_ls_restr"
].
find
(
cif
::
Key
(
"type"
)
==
type
and
cif
::
Key
(
"pdbx_refine_id"
)
==
mExpMethod
);
auto
rows
=
mDb
[
"refine_ls_restr"
].
find
(
cif
::
Key
(
"type"
)
==
type
and
cif
::
Key
(
"pdbx_refine_id"
)
==
mExpMethod
);
if
(
rows
.
empty
())
if
(
rows
.
empty
())
...
@@ -1281,9 +1279,9 @@ void Remark3Parser::updateRefineLsRestr(const char* type, initializer_list<const
...
@@ -1281,9 +1279,9 @@ void Remark3Parser::updateRefineLsRestr(const char* type, initializer_list<const
{
{
++
capture
;
++
capture
;
string
value
=
mM
[
capture
].
str
();
st
d
::
st
ring
value
=
mM
[
capture
].
str
();
ba
::
trim
(
value
);
ba
::
trim
(
value
);
if
(
iequals
(
value
,
"NULL"
)
or
iequals
(
value
,
string
(
value
.
length
(),
'*'
)))
if
(
iequals
(
value
,
"NULL"
)
or
iequals
(
value
,
st
d
::
st
ring
(
value
.
length
(),
'*'
)))
value
.
clear
();
value
.
clear
();
r
[
item
]
=
value
;
r
[
item
]
=
value
;
...
@@ -1296,12 +1294,12 @@ void Remark3Parser::updateRefineLsRestr(const char* type, initializer_list<const
...
@@ -1296,12 +1294,12 @@ void Remark3Parser::updateRefineLsRestr(const char* type, initializer_list<const
// --------------------------------------------------------------------
// --------------------------------------------------------------------
bool
Remark3Parser
::
parse
(
const
string
&
expMethod
,
PDBRecord
*
r
,
cif
::
Datablock
&
db
)
bool
Remark3Parser
::
parse
(
const
st
d
::
st
ring
&
expMethod
,
PDBRecord
*
r
,
cif
::
Datablock
&
db
)
{
{
// simple version, only for the first few lines
// simple version, only for the first few lines
auto
getNextLine
=
[
&
]()
auto
getNextLine
=
[
&
]()
{
{
string
result
;
st
d
::
st
ring
result
;
while
(
result
.
empty
()
and
r
!=
nullptr
and
r
->
is
(
"REMARK 3"
))
while
(
result
.
empty
()
and
r
!=
nullptr
and
r
->
is
(
"REMARK 3"
))
{
{
...
@@ -1314,24 +1312,24 @@ bool Remark3Parser::parse(const string& expMethod, PDBRecord* r, cif::Datablock&
...
@@ -1314,24 +1312,24 @@ bool Remark3Parser::parse(const string& expMethod, PDBRecord* r, cif::Datablock&
// All remark 3 records should start with the same data.
// All remark 3 records should start with the same data.
string
line
=
getNextLine
();
st
d
::
st
ring
line
=
getNextLine
();
if
(
line
!=
"REFINEMENT."
)
if
(
line
!=
"REFINEMENT."
)
{
{
if
(
cif
::
VERBOSE
)
if
(
cif
::
VERBOSE
)
cerr
<<
"Unexpected data in REMARK 3"
<<
endl
;
std
::
cerr
<<
"Unexpected data in REMARK 3"
<<
std
::
endl
;
return
false
;
return
false
;
}
}
line
=
getNextLine
();
line
=
getNextLine
();
regex
rxp
(
R"(^PROGRAM\s*:\s*(.+))"
);
std
::
regex
rxp
(
R"(^PROGRAM\s*:\s*(.+))"
);
smatch
m
;
s
td
::
s
match
m
;
if
(
not
regex_match
(
line
,
m
,
rxp
))
if
(
not
std
::
regex_match
(
line
,
m
,
rxp
))
{
{
if
(
cif
::
VERBOSE
)
if
(
cif
::
VERBOSE
)
cerr
<<
"Expected valid PROGRAM line in REMARK 3"
<<
endl
;
std
::
cerr
<<
"Expected valid PROGRAM line in REMARK 3"
<<
std
::
endl
;
return
false
;
return
false
;
}
}
...
@@ -1339,11 +1337,11 @@ bool Remark3Parser::parse(const string& expMethod, PDBRecord* r, cif::Datablock&
...
@@ -1339,11 +1337,11 @@ bool Remark3Parser::parse(const string& expMethod, PDBRecord* r, cif::Datablock&
struct
programScore
struct
programScore
{
{
programScore
(
const
string
&
program
,
Remark3Parser
*
parser
,
float
score
)
programScore
(
const
st
d
::
st
ring
&
program
,
Remark3Parser
*
parser
,
float
score
)
:
program
(
program
),
parser
(
parser
),
score
(
score
)
{}
:
program
(
program
),
parser
(
parser
),
score
(
score
)
{}
string
program
;
st
d
::
st
ring
program
;
unique_ptr
<
Remark3Parser
>
parser
;
std
::
unique_ptr
<
Remark3Parser
>
parser
;
float
score
;
float
score
;
bool
operator
<
(
const
programScore
&
rhs
)
const
bool
operator
<
(
const
programScore
&
rhs
)
const
...
@@ -1352,11 +1350,11 @@ bool Remark3Parser::parse(const string& expMethod, PDBRecord* r, cif::Datablock&
...
@@ -1352,11 +1350,11 @@ bool Remark3Parser::parse(const string& expMethod, PDBRecord* r, cif::Datablock&
}
}
};
};
vector
<
programScore
>
scores
;
std
::
vector
<
programScore
>
scores
;
auto
tryParser
=
[
&
](
Remark3Parser
*
p
)
auto
tryParser
=
[
&
](
Remark3Parser
*
p
)
{
{
unique_ptr
<
Remark3Parser
>
parser
(
p
);
std
::
unique_ptr
<
Remark3Parser
>
parser
(
p
);
float
score
;
float
score
;
try
try
...
@@ -1365,18 +1363,18 @@ bool Remark3Parser::parse(const string& expMethod, PDBRecord* r, cif::Datablock&
...
@@ -1365,18 +1363,18 @@ bool Remark3Parser::parse(const string& expMethod, PDBRecord* r, cif::Datablock&
}
}
catch
(
const
std
::
exception
&
e
)
catch
(
const
std
::
exception
&
e
)
{
{
std
::
cerr
<<
"Error parsing REMARK 3 with "
<<
parser
->
program
()
<<
endl
std
::
cerr
<<
"Error parsing REMARK 3 with "
<<
parser
->
program
()
<<
std
::
endl
<<
e
.
what
()
<<
'\n'
;
<<
e
.
what
()
<<
'\n'
;
score
=
0
;
score
=
0
;
}
}
if
(
cif
::
VERBOSE
>=
2
)
if
(
cif
::
VERBOSE
>=
2
)
cerr
<<
"Score for "
<<
parser
->
program
()
<<
": "
<<
score
<<
endl
;
std
::
cerr
<<
"Score for "
<<
parser
->
program
()
<<
": "
<<
score
<<
std
::
endl
;
if
(
score
>
0
)
if
(
score
>
0
)
{
{
string
program
=
parser
->
program
();
st
d
::
st
ring
program
=
parser
->
program
();
string
version
=
parser
->
version
();
st
d
::
st
ring
version
=
parser
->
version
();
scores
.
emplace_back
(
program
,
parser
.
release
(),
score
);
scores
.
emplace_back
(
program
,
parser
.
release
(),
score
);
}
}
...
@@ -1385,7 +1383,7 @@ bool Remark3Parser::parse(const string& expMethod, PDBRecord* r, cif::Datablock&
...
@@ -1385,7 +1383,7 @@ bool Remark3Parser::parse(const string& expMethod, PDBRecord* r, cif::Datablock&
for
(
auto
p
=
make_split_iterator
(
line
,
ba
::
first_finder
(
", "
));
for
(
auto
p
=
make_split_iterator
(
line
,
ba
::
first_finder
(
", "
));
not
p
.
eof
();
++
p
)
not
p
.
eof
();
++
p
)
{
{
string
program
(
p
->
begin
(),
p
->
end
());
st
d
::
st
ring
program
(
p
->
begin
(),
p
->
end
());
if
(
ba
::
starts_with
(
program
,
"BUSTER"
))
if
(
ba
::
starts_with
(
program
,
"BUSTER"
))
tryParser
(
new
BUSTER_TNT_Remark3Parser
(
program
,
expMethod
,
r
,
db
));
tryParser
(
new
BUSTER_TNT_Remark3Parser
(
program
,
expMethod
,
r
,
db
));
...
@@ -1410,7 +1408,7 @@ bool Remark3Parser::parse(const string& expMethod, PDBRecord* r, cif::Datablock&
...
@@ -1410,7 +1408,7 @@ bool Remark3Parser::parse(const string& expMethod, PDBRecord* r, cif::Datablock&
else
if
(
ba
::
starts_with
(
program
,
"X-PLOR"
))
else
if
(
ba
::
starts_with
(
program
,
"X-PLOR"
))
tryParser
(
new
XPLOR_Remark3Parser
(
program
,
expMethod
,
r
,
db
));
tryParser
(
new
XPLOR_Remark3Parser
(
program
,
expMethod
,
r
,
db
));
else
if
(
cif
::
VERBOSE
)
else
if
(
cif
::
VERBOSE
)
cerr
<<
"Skipping unknown program ("
<<
program
<<
") in REMARK 3"
<<
endl
;
std
::
cerr
<<
"Skipping unknown program ("
<<
program
<<
") in REMARK 3"
<<
std
::
endl
;
}
}
sort
(
scores
.
begin
(),
scores
.
end
());
sort
(
scores
.
begin
(),
scores
.
end
());
...
@@ -1418,7 +1416,7 @@ bool Remark3Parser::parse(const string& expMethod, PDBRecord* r, cif::Datablock&
...
@@ -1418,7 +1416,7 @@ bool Remark3Parser::parse(const string& expMethod, PDBRecord* r, cif::Datablock&
bool
guessProgram
=
scores
.
empty
()
or
scores
.
front
().
score
<
0.9
f
;;
bool
guessProgram
=
scores
.
empty
()
or
scores
.
front
().
score
<
0.9
f
;;
if
(
guessProgram
)
if
(
guessProgram
)
{
{
cerr
<<
"Unknown or untrusted program in REMARK 3, trying all parsers to see if there is a match"
<<
endl
;
std
::
cerr
<<
"Unknown or untrusted program in REMARK 3, trying all parsers to see if there is a match"
<<
std
::
endl
;
tryParser
(
new
BUSTER_TNT_Remark3Parser
(
"BUSTER-TNT"
,
expMethod
,
r
,
db
));
tryParser
(
new
BUSTER_TNT_Remark3Parser
(
"BUSTER-TNT"
,
expMethod
,
r
,
db
));
tryParser
(
new
CNS_Remark3Parser
(
"CNS"
,
expMethod
,
r
,
db
));
tryParser
(
new
CNS_Remark3Parser
(
"CNS"
,
expMethod
,
r
,
db
));
...
@@ -1443,11 +1441,11 @@ bool Remark3Parser::parse(const string& expMethod, PDBRecord* r, cif::Datablock&
...
@@ -1443,11 +1441,11 @@ bool Remark3Parser::parse(const string& expMethod, PDBRecord* r, cif::Datablock&
auto
&
best
=
scores
.
front
();
auto
&
best
=
scores
.
front
();
if
(
cif
::
VERBOSE
)
if
(
cif
::
VERBOSE
)
cerr
<<
"Choosing "
<<
best
.
parser
->
program
()
<<
" version '"
<<
best
.
parser
->
version
()
<<
"' as refinement program. Score = "
<<
best
.
score
<<
endl
;
std
::
cerr
<<
"Choosing "
<<
best
.
parser
->
program
()
<<
" version '"
<<
best
.
parser
->
version
()
<<
"' as refinement program. Score = "
<<
best
.
score
<<
std
::
endl
;
auto
&
software
=
db
[
"software"
];
auto
&
software
=
db
[
"software"
];
string
program
=
best
.
parser
->
program
();
st
d
::
st
ring
program
=
best
.
parser
->
program
();
string
version
=
best
.
parser
->
version
();
st
d
::
st
ring
version
=
best
.
parser
->
version
();
software
.
emplace
({
software
.
emplace
({
{
"name"
,
program
},
{
"name"
,
program
},
...
...
src/Point.cpp
View file @
4b4757ee
...
@@ -29,8 +29,6 @@
...
@@ -29,8 +29,6 @@
#include "cif++/Point.hpp"
#include "cif++/Point.hpp"
using
namespace
std
;
namespace
mmcif
namespace
mmcif
{
{
...
@@ -38,7 +36,7 @@ namespace mmcif
...
@@ -38,7 +36,7 @@ namespace mmcif
quaternion
Normalize
(
quaternion
q
)
quaternion
Normalize
(
quaternion
q
)
{
{
valarray
<
double
>
t
(
4
);
std
::
valarray
<
double
>
t
(
4
);
t
[
0
]
=
q
.
R_component_1
();
t
[
0
]
=
q
.
R_component_1
();
t
[
1
]
=
q
.
R_component_2
();
t
[
1
]
=
q
.
R_component_2
();
...
@@ -59,7 +57,7 @@ quaternion Normalize(quaternion q)
...
@@ -59,7 +57,7 @@ quaternion Normalize(quaternion q)
// --------------------------------------------------------------------
// --------------------------------------------------------------------
tuple
<
double
,
Point
>
QuaternionToAngleAxis
(
quaternion
q
)
std
::
tuple
<
double
,
Point
>
QuaternionToAngleAxis
(
quaternion
q
)
{
{
if
(
q
.
R_component_1
()
>
1
)
if
(
q
.
R_component_1
()
>
1
)
q
=
Normalize
(
q
);
q
=
Normalize
(
q
);
...
@@ -75,10 +73,10 @@ tuple<double,Point> QuaternionToAngleAxis(quaternion q)
...
@@ -75,10 +73,10 @@ tuple<double,Point> QuaternionToAngleAxis(quaternion q)
Point
axis
(
q
.
R_component_2
()
/
s
,
q
.
R_component_3
()
/
s
,
q
.
R_component_4
()
/
s
);
Point
axis
(
q
.
R_component_2
()
/
s
,
q
.
R_component_3
()
/
s
,
q
.
R_component_4
()
/
s
);
return
make_tuple
(
angle
,
axis
);
return
std
::
make_tuple
(
angle
,
axis
);
}
}
Point
CenterPoints
(
vector
<
Point
>&
Points
)
Point
CenterPoints
(
std
::
vector
<
Point
>&
Points
)
{
{
Point
t
;
Point
t
;
...
@@ -103,7 +101,7 @@ Point CenterPoints(vector<Point>& Points)
...
@@ -103,7 +101,7 @@ Point CenterPoints(vector<Point>& Points)
return
t
;
return
t
;
}
}
Point
Centroid
(
vector
<
Point
>&
Points
)
Point
Centroid
(
std
::
vector
<
Point
>&
Points
)
{
{
Point
result
;
Point
result
;
...
@@ -115,12 +113,12 @@ Point Centroid(vector<Point>& Points)
...
@@ -115,12 +113,12 @@ Point Centroid(vector<Point>& Points)
return
result
;
return
result
;
}
}
double
RMSd
(
const
vector
<
Point
>&
a
,
const
vector
<
Point
>&
b
)
double
RMSd
(
const
std
::
vector
<
Point
>&
a
,
const
std
::
vector
<
Point
>&
b
)
{
{
double
sum
=
0
;
double
sum
=
0
;
for
(
uint32_t
i
=
0
;
i
<
a
.
size
();
++
i
)
for
(
uint32_t
i
=
0
;
i
<
a
.
size
();
++
i
)
{
{
valarray
<
double
>
d
(
3
);
std
::
valarray
<
double
>
d
(
3
);
d
[
0
]
=
b
[
i
].
mX
-
a
[
i
].
mX
;
d
[
0
]
=
b
[
i
].
mX
-
a
[
i
].
mX
;
d
[
1
]
=
b
[
i
].
mY
-
a
[
i
].
mY
;
d
[
1
]
=
b
[
i
].
mY
-
a
[
i
].
mY
;
...
@@ -131,7 +129,7 @@ double RMSd(const vector<Point>& a, const vector<Point>& b)
...
@@ -131,7 +129,7 @@ double RMSd(const vector<Point>& a, const vector<Point>& b)
sum
+=
d
.
sum
();
sum
+=
d
.
sum
();
}
}
return
sqrt
(
sum
/
a
.
size
());
return
s
td
::
s
qrt
(
sum
/
a
.
size
());
}
}
// The next function returns the largest solution for a quartic equation
// The next function returns the largest solution for a quartic equation
...
@@ -145,30 +143,30 @@ double RMSd(const vector<Point>& a, const vector<Point>& b)
...
@@ -145,30 +143,30 @@ double RMSd(const vector<Point>& a, const vector<Point>& b)
// sqrt of a negative number)
// sqrt of a negative number)
double
LargestDepressedQuarticSolution
(
double
a
,
double
b
,
double
c
)
double
LargestDepressedQuarticSolution
(
double
a
,
double
b
,
double
c
)
{
{
complex
<
double
>
P
=
-
(
a
*
a
)
/
12
-
c
;
std
::
complex
<
double
>
P
=
-
(
a
*
a
)
/
12
-
c
;
complex
<
double
>
Q
=
-
(
a
*
a
*
a
)
/
108
+
(
a
*
c
)
/
3
-
(
b
*
b
)
/
8
;
std
::
complex
<
double
>
Q
=
-
(
a
*
a
*
a
)
/
108
+
(
a
*
c
)
/
3
-
(
b
*
b
)
/
8
;
complex
<
double
>
R
=
-
Q
/
2.0
+
sqrt
((
Q
*
Q
)
/
4.0
+
(
P
*
P
*
P
)
/
27.0
);
std
::
complex
<
double
>
R
=
-
Q
/
2.0
+
std
::
sqrt
((
Q
*
Q
)
/
4.0
+
(
P
*
P
*
P
)
/
27.0
);
complex
<
double
>
U
=
pow
(
R
,
1
/
3.0
);
std
::
complex
<
double
>
U
=
std
::
pow
(
R
,
1
/
3.0
);
complex
<
double
>
y
;
std
::
complex
<
double
>
y
;
if
(
U
==
0.0
)
if
(
U
==
0.0
)
y
=
-
5.0
*
a
/
6.0
+
U
-
pow
(
Q
,
1.0
/
3.0
);
y
=
-
5.0
*
a
/
6.0
+
U
-
std
::
pow
(
Q
,
1.0
/
3.0
);
else
else
y
=
-
5.0
*
a
/
6.0
+
U
-
P
/
(
3.0
*
U
);
y
=
-
5.0
*
a
/
6.0
+
U
-
P
/
(
3.0
*
U
);
complex
<
double
>
W
=
sqrt
(
a
+
2.0
*
y
);
std
::
complex
<
double
>
W
=
std
::
sqrt
(
a
+
2.0
*
y
);
// And to get the final result:
// And to get the final result:
// result = (±W + sqrt(-(3 * alpha + 2 * y ± 2 * beta / W))) / 2;
// result = (±W + sqrt(-(3 * alpha + 2 * y ± 2 * beta / W))) / 2;
// We want the largest result, so:
// We want the largest result, so:
valarray
<
double
>
t
(
4
);
std
::
valarray
<
double
>
t
(
4
);
t
[
0
]
=
((
W
+
sqrt
(
-
(
3.0
*
a
+
2.0
*
y
+
2.0
*
b
/
W
)))
/
2.0
).
real
();
t
[
0
]
=
((
W
+
s
td
::
s
qrt
(
-
(
3.0
*
a
+
2.0
*
y
+
2.0
*
b
/
W
)))
/
2.0
).
real
();
t
[
1
]
=
((
W
+
sqrt
(
-
(
3.0
*
a
+
2.0
*
y
-
2.0
*
b
/
W
)))
/
2.0
).
real
();
t
[
1
]
=
((
W
+
s
td
::
s
qrt
(
-
(
3.0
*
a
+
2.0
*
y
-
2.0
*
b
/
W
)))
/
2.0
).
real
();
t
[
2
]
=
((
-
W
+
sqrt
(
-
(
3.0
*
a
+
2.0
*
y
+
2.0
*
b
/
W
)))
/
2.0
).
real
();
t
[
2
]
=
((
-
W
+
s
td
::
s
qrt
(
-
(
3.0
*
a
+
2.0
*
y
+
2.0
*
b
/
W
)))
/
2.0
).
real
();
t
[
3
]
=
((
-
W
+
sqrt
(
-
(
3.0
*
a
+
2.0
*
y
-
2.0
*
b
/
W
)))
/
2.0
).
real
();
t
[
3
]
=
((
-
W
+
s
td
::
s
qrt
(
-
(
3.0
*
a
+
2.0
*
y
-
2.0
*
b
/
W
)))
/
2.0
).
real
();
return
t
.
max
();
return
t
.
max
();
}
}
...
@@ -286,10 +284,10 @@ double LargestDepressedQuarticSolution(double a, double b, double c)
...
@@ -286,10 +284,10 @@ double LargestDepressedQuarticSolution(double a, double b, double c)
Point
Nudge
(
Point
p
,
float
offset
)
Point
Nudge
(
Point
p
,
float
offset
)
{
{
static
std
::
random_device
rd
;
static
std
::
random_device
rd
;
static
mt19937_64
rng
(
rd
());
static
std
::
mt19937_64
rng
(
rd
());
uniform_real_distribution
<>
randomAngle
(
0
,
2
*
kPI
);
std
::
uniform_real_distribution
<>
randomAngle
(
0
,
2
*
kPI
);
normal_distribution
<>
randomOffset
(
0
,
offset
);
std
::
normal_distribution
<>
randomOffset
(
0
,
offset
);
float
theta
=
randomAngle
(
rng
);
float
theta
=
randomAngle
(
rng
);
float
phi1
=
randomAngle
(
rng
)
-
kPI
;
float
phi1
=
randomAngle
(
rng
)
-
kPI
;
...
...
src/Structure.cpp
View file @
4b4757ee
...
@@ -28,14 +28,7 @@
...
@@ -28,14 +28,7 @@
#include <numeric>
#include <numeric>
#include <fstream>
#include <fstream>
#if __has_include(<filesystem>)
#include <filesystem>
#include <filesystem>
namespace
fs
=
std
::
filesystem
;
#elif __has_include(<boost/filesystem.hpp>)
#include <boost/filesystem.hpp>
namespace
fs
=
boost
::
filesystem
;
#endif
#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/iostreams/filtering_stream.hpp>
#include <boost/iostreams/filtering_stream.hpp>
...
@@ -49,8 +42,7 @@ namespace fs = boost::filesystem;
...
@@ -49,8 +42,7 @@ namespace fs = boost::filesystem;
#include "cif++/Cif2PDB.hpp"
#include "cif++/Cif2PDB.hpp"
// #include "cif++/AtomShape.hpp"
// #include "cif++/AtomShape.hpp"
using
namespace
std
;
namespace
fs
=
std
::
filesystem
;
namespace
ba
=
boost
::
algorithm
;
namespace
ba
=
boost
::
algorithm
;
namespace
io
=
boost
::
iostreams
;
namespace
io
=
boost
::
iostreams
;
...
@@ -75,12 +67,12 @@ void FileImpl::load(const std::string& p)
...
@@ -75,12 +67,12 @@ void FileImpl::load(const std::string& p)
{
{
fs
::
path
path
(
p
);
fs
::
path
path
(
p
);
std
::
ifstream
inFile
(
path
,
ios_base
::
in
|
ios_base
::
binary
);
std
::
ifstream
inFile
(
path
,
std
::
ios_base
::
in
|
std
::
ios_base
::
binary
);
if
(
not
inFile
.
is_open
())
if
(
not
inFile
.
is_open
())
throw
runtime_error
(
"No such file: "
+
path
.
string
());
throw
std
::
runtime_error
(
"No such file: "
+
path
.
string
());
io
::
filtering_stream
<
io
::
input
>
in
;
io
::
filtering_stream
<
io
::
input
>
in
;
string
ext
=
path
.
extension
().
string
();
st
d
::
st
ring
ext
=
path
.
extension
().
string
();
if
(
path
.
extension
()
==
".bz2"
)
if
(
path
.
extension
()
==
".bz2"
)
{
{
...
@@ -107,14 +99,14 @@ void FileImpl::load(const std::string& p)
...
@@ -107,14 +99,14 @@ void FileImpl::load(const std::string& p)
try
try
{
{
if
(
cif
::
VERBOSE
)
if
(
cif
::
VERBOSE
)
cerr
<<
"unrecognized file extension, trying cif"
<<
endl
;
std
::
cerr
<<
"unrecognized file extension, trying cif"
<<
std
::
endl
;
mData
.
load
(
in
);
mData
.
load
(
in
);
}
}
catch
(
const
cif
::
CifParserError
&
e
)
catch
(
const
cif
::
CifParserError
&
e
)
{
{
if
(
cif
::
VERBOSE
)
if
(
cif
::
VERBOSE
)
cerr
<<
"Not cif, trying plain old PDB"
<<
endl
;
std
::
cerr
<<
"Not cif, trying plain old PDB"
<<
std
::
endl
;
// pffft...
// pffft...
in
.
reset
();
in
.
reset
();
...
@@ -122,7 +114,7 @@ void FileImpl::load(const std::string& p)
...
@@ -122,7 +114,7 @@ void FileImpl::load(const std::string& p)
if
(
inFile
.
is_open
())
if
(
inFile
.
is_open
())
inFile
.
seekg
(
0
);
inFile
.
seekg
(
0
);
else
else
inFile
.
open
(
path
,
ios_base
::
in
|
ios
::
binary
);
inFile
.
open
(
path
,
std
::
ios_base
::
in
|
std
::
ios
::
binary
);
if
(
path
.
extension
()
==
".bz2"
)
if
(
path
.
extension
()
==
".bz2"
)
in
.
push
(
io
::
bzip2_decompressor
());
in
.
push
(
io
::
bzip2_decompressor
());
...
@@ -135,9 +127,9 @@ void FileImpl::load(const std::string& p)
...
@@ -135,9 +127,9 @@ void FileImpl::load(const std::string& p)
}
}
}
}
}
}
catch
(
const
exception
&
ex
)
catch
(
const
std
::
exception
&
ex
)
{
{
cerr
<<
"Error trying to load file "
<<
path
<<
endl
;
std
::
cerr
<<
"Error trying to load file "
<<
path
<<
std
::
endl
;
throw
;
throw
;
}
}
...
@@ -148,14 +140,14 @@ void FileImpl::load(const std::string& p)
...
@@ -148,14 +140,14 @@ void FileImpl::load(const std::string& p)
// if (mData.getValidator() == nullptr)
// if (mData.getValidator() == nullptr)
mData
.
loadDictionary
(
"mmcif_pdbx"
);
mData
.
loadDictionary
(
"mmcif_pdbx"
);
if
(
not
mData
.
isValid
())
if
(
not
mData
.
isValid
())
cerr
<<
"Invalid mmCIF file"
<<
(
cif
::
VERBOSE
?
"."
:
" use --verbose option to see errors"
)
<<
endl
;
std
::
cerr
<<
"Invalid mmCIF file"
<<
(
cif
::
VERBOSE
?
"."
:
" use --verbose option to see errors"
)
<<
std
::
endl
;
}
}
void
FileImpl
::
save
(
const
std
::
string
&
p
)
void
FileImpl
::
save
(
const
std
::
string
&
p
)
{
{
fs
::
path
path
(
p
);
fs
::
path
path
(
p
);
std
::
ofstream
outFile
(
p
,
ios_base
::
out
|
ios_base
::
binary
);
std
::
ofstream
outFile
(
p
,
std
::
ios_base
::
out
|
std
::
ios_base
::
binary
);
io
::
filtering_stream
<
io
::
output
>
out
;
io
::
filtering_stream
<
io
::
output
>
out
;
if
(
path
.
extension
()
==
".gz"
)
if
(
path
.
extension
()
==
".gz"
)
...
@@ -194,7 +186,7 @@ struct AtomImpl
...
@@ -194,7 +186,7 @@ struct AtomImpl
{
{
}
}
AtomImpl
(
const
File
&
f
,
const
string
&
id
)
AtomImpl
(
const
File
&
f
,
const
st
d
::
st
ring
&
id
)
:
mFile
(
f
),
mID
(
id
),
mRefcount
(
1
),
mCompound
(
nullptr
)
:
mFile
(
f
),
mID
(
id
),
mRefcount
(
1
),
mCompound
(
nullptr
)
{
{
auto
&
db
=
*
mFile
.
impl
().
mDb
;
auto
&
db
=
*
mFile
.
impl
().
mDb
;
...
@@ -205,7 +197,7 @@ struct AtomImpl
...
@@ -205,7 +197,7 @@ struct AtomImpl
prefetch
();
prefetch
();
}
}
AtomImpl
(
const
File
&
f
,
const
string
&
id
,
cif
::
Row
row
)
AtomImpl
(
const
File
&
f
,
const
st
d
::
st
ring
&
id
,
cif
::
Row
row
)
:
mFile
(
f
),
mID
(
id
),
mRefcount
(
1
),
mRow
(
row
),
mCompound
(
nullptr
)
:
mFile
(
f
),
mID
(
id
),
mRefcount
(
1
),
mRow
(
row
),
mCompound
(
nullptr
)
{
{
prefetch
();
prefetch
();
...
@@ -227,7 +219,7 @@ struct AtomImpl
...
@@ -227,7 +219,7 @@ struct AtomImpl
void
prefetch
()
void
prefetch
()
{
{
// Prefetch some data
// Prefetch some data
string
symbol
;
st
d
::
st
ring
symbol
;
cif
::
tie
(
symbol
,
mAtomID
,
mCompID
,
mAsymID
,
mSeqID
,
mAltID
)
=
cif
::
tie
(
symbol
,
mAtomID
,
mCompID
,
mAsymID
,
mSeqID
,
mAltID
)
=
mRow
.
get
(
"type_symbol"
,
"label_atom_id"
,
"label_comp_id"
,
"label_asym_id"
,
"label_seq_id"
,
"label_alt_id"
);
mRow
.
get
(
"type_symbol"
,
"label_atom_id"
,
"label_comp_id"
,
"label_asym_id"
,
"label_seq_id"
,
"label_alt_id"
);
...
@@ -239,7 +231,7 @@ struct AtomImpl
...
@@ -239,7 +231,7 @@ struct AtomImpl
mLocation
=
Point
(
x
,
y
,
z
);
mLocation
=
Point
(
x
,
y
,
z
);
string
compID
;
st
d
::
st
ring
compID
;
cif
::
tie
(
compID
)
=
mRow
.
get
(
"label_comp_id"
);
cif
::
tie
(
compID
)
=
mRow
.
get
(
"label_comp_id"
);
mCompound
=
Compound
::
create
(
compID
);
mCompound
=
Compound
::
create
(
compID
);
...
@@ -255,12 +247,12 @@ struct AtomImpl
...
@@ -255,12 +247,12 @@ struct AtomImpl
// else
// else
// result.set_occupancy(mRow["occupancy"].as<float>());
// result.set_occupancy(mRow["occupancy"].as<float>());
// st
ring element = mRow["type_symbol"].as<
string>();
// st
d::string element = mRow["type_symbol"].as<std::
string>();
// if (not mRow["pdbx_formal_charge"].empty())
// if (not mRow["pdbx_formal_charge"].empty())
// {
// {
// int charge = mRow["pdbx_formal_charge"].as<int>();
// int charge = mRow["pdbx_formal_charge"].as<int>();
// if (abs(charge) > 1)
// if (abs(charge) > 1)
// element += to_string(charge);
// element +=
std::
to_string(charge);
// if (charge < 0)
// if (charge < 0)
// element += '-';
// element += '-';
// else
// else
...
@@ -273,7 +265,7 @@ struct AtomImpl
...
@@ -273,7 +265,7 @@ struct AtomImpl
// else if (not mRow["B_iso_or_equiv"].empty())
// else if (not mRow["B_iso_or_equiv"].empty())
// result.set_u_iso(mRow["B_iso_or_equiv"].as<float>() / (8 * kPI * kPI));
// result.set_u_iso(mRow["B_iso_or_equiv"].as<float>() / (8 * kPI * kPI));
// else
// else
// throw runtime_error("Missing B_iso or U_iso");
// throw
std::
runtime_error("Missing B_iso or U_iso");
// auto& db = *mFile.impl().mDb;
// auto& db = *mFile.impl().mDb;
// auto& cat = db["atom_site_anisotrop"];
// auto& cat = db["atom_site_anisotrop"];
...
@@ -324,7 +316,7 @@ struct AtomImpl
...
@@ -324,7 +316,7 @@ struct AtomImpl
{
{
assert
(
not
mSymmetryCopy
);
assert
(
not
mSymmetryCopy
);
if
(
mSymmetryCopy
)
if
(
mSymmetryCopy
)
throw
runtime_error
(
"Moving symmetry copy"
);
throw
std
::
runtime_error
(
"Moving symmetry copy"
);
if
(
not
mClone
)
if
(
not
mClone
)
{
{
...
@@ -346,17 +338,17 @@ struct AtomImpl
...
@@ -346,17 +338,17 @@ struct AtomImpl
{
{
if
(
mCompound
==
nullptr
)
if
(
mCompound
==
nullptr
)
{
{
string
compID
;
st
d
::
st
ring
compID
;
cif
::
tie
(
compID
)
=
mRow
.
get
(
"label_comp_id"
);
cif
::
tie
(
compID
)
=
mRow
.
get
(
"label_comp_id"
);
mCompound
=
Compound
::
create
(
compID
);
mCompound
=
Compound
::
create
(
compID
);
if
(
cif
::
VERBOSE
and
mCompound
==
nullptr
)
if
(
cif
::
VERBOSE
and
mCompound
==
nullptr
)
cerr
<<
"Compound not found: '"
<<
compID
<<
'\''
<<
endl
;
std
::
cerr
<<
"Compound not found: '"
<<
compID
<<
'\''
<<
std
::
endl
;
}
}
if
(
mCompound
==
nullptr
)
if
(
mCompound
==
nullptr
)
throw
runtime_error
(
"no compound"
);
throw
std
::
runtime_error
(
"no compound"
);
return
*
mCompound
;
return
*
mCompound
;
}
}
...
@@ -371,9 +363,9 @@ struct AtomImpl
...
@@ -371,9 +363,9 @@ struct AtomImpl
return
mRadius
;
return
mRadius
;
}
}
const
st
ring
&
property
(
const
string
&
name
)
const
const
st
d
::
string
&
property
(
const
std
::
string
&
name
)
const
{
{
static
string
kEmptyString
;
static
st
d
::
st
ring
kEmptyString
;
auto
i
=
mCachedProperties
.
find
(
name
);
auto
i
=
mCachedProperties
.
find
(
name
);
if
(
i
==
mCachedProperties
.
end
())
if
(
i
==
mCachedProperties
.
end
())
...
@@ -382,7 +374,7 @@ struct AtomImpl
...
@@ -382,7 +374,7 @@ struct AtomImpl
if
(
v
.
empty
())
if
(
v
.
empty
())
return
kEmptyString
;
return
kEmptyString
;
return
mCachedProperties
[
name
]
=
v
.
as
<
string
>
();
return
mCachedProperties
[
name
]
=
v
.
as
<
st
d
::
st
ring
>
();
}
}
else
else
return
i
->
second
;
return
i
->
second
;
...
@@ -404,21 +396,21 @@ struct AtomImpl
...
@@ -404,21 +396,21 @@ struct AtomImpl
}
}
const
File
&
mFile
;
const
File
&
mFile
;
string
mID
;
st
d
::
st
ring
mID
;
AtomType
mType
;
AtomType
mType
;
string
mAtomID
;
st
d
::
st
ring
mAtomID
;
string
mCompID
;
st
d
::
st
ring
mCompID
;
string
mAsymID
;
st
d
::
st
ring
mAsymID
;
int
mSeqID
;
int
mSeqID
;
string
mAltID
;
st
d
::
st
ring
mAltID
;
Point
mLocation
;
Point
mLocation
;
int
mRefcount
;
int
mRefcount
;
cif
::
Row
mRow
;
cif
::
Row
mRow
;
mutable
const
Compound
*
mCompound
;
mutable
const
Compound
*
mCompound
;
float
mRadius
=
nan
(
"4"
);
float
mRadius
=
nan
(
"4"
);
mutable
map
<
string
,
string
>
mCachedProperties
;
mutable
std
::
map
<
std
::
string
,
std
::
string
>
mCachedProperties
;
bool
mSymmetryCopy
=
false
;
bool
mSymmetryCopy
=
false
;
bool
mClone
=
false
;
bool
mClone
=
false
;
...
@@ -428,7 +420,7 @@ struct AtomImpl
...
@@ -428,7 +420,7 @@ struct AtomImpl
// int32_t mRTix;
// int32_t mRTix;
};
};
//Atom::Atom(const File& f, const string& id)
//Atom::Atom(const File& f, const st
d::st
ring& id)
// : mImpl(new AtomImpl(f, id))
// : mImpl(new AtomImpl(f, id))
//{
//{
//}
//}
...
@@ -491,25 +483,25 @@ Atom& Atom::operator=(const Atom& rhs)
...
@@ -491,25 +483,25 @@ Atom& Atom::operator=(const Atom& rhs)
}
}
template
<>
template
<>
st
ring
Atom
::
property
<
string
>
(
const
string
&
name
)
const
st
d
::
string
Atom
::
property
<
std
::
string
>
(
const
std
::
string
&
name
)
const
{
{
return
impl
()
->
property
(
name
);
return
impl
()
->
property
(
name
);
}
}
template
<>
template
<>
int
Atom
::
property
<
int
>
(
const
string
&
name
)
const
int
Atom
::
property
<
int
>
(
const
st
d
::
st
ring
&
name
)
const
{
{
auto
v
=
impl
()
->
property
(
name
);
auto
v
=
impl
()
->
property
(
name
);
return
v
.
empty
()
?
0
:
stoi
(
v
);
return
v
.
empty
()
?
0
:
stoi
(
v
);
}
}
template
<>
template
<>
float
Atom
::
property
<
float
>
(
const
string
&
name
)
const
float
Atom
::
property
<
float
>
(
const
st
d
::
st
ring
&
name
)
const
{
{
return
stof
(
impl
()
->
property
(
name
));
return
stof
(
impl
()
->
property
(
name
));
}
}
const
string
&
Atom
::
id
()
const
const
st
d
::
st
ring
&
Atom
::
id
()
const
{
{
return
impl
()
->
mID
;
return
impl
()
->
mID
;
}
}
...
@@ -524,9 +516,9 @@ int Atom::charge() const
...
@@ -524,9 +516,9 @@ int Atom::charge() const
return
property
<
int
>
(
"pdbx_formal_charge"
);
return
property
<
int
>
(
"pdbx_formal_charge"
);
}
}
string
Atom
::
energyType
()
const
st
d
::
st
ring
Atom
::
energyType
()
const
{
{
string
result
;
st
d
::
st
ring
result
;
if
(
impl
()
and
impl
()
->
mCompound
)
if
(
impl
()
and
impl
()
->
mCompound
)
result
=
impl
()
->
mCompound
->
getAtomByID
(
impl
()
->
mAtomID
).
typeEnergy
;
result
=
impl
()
->
mCompound
->
getAtomByID
(
impl
()
->
mAtomID
).
typeEnergy
;
...
@@ -538,12 +530,12 @@ float Atom::uIso() const
...
@@ -538,12 +530,12 @@ float Atom::uIso() const
{
{
float
result
;
float
result
;
if
(
not
property
<
string
>
(
"U_iso_or_equiv"
).
empty
())
if
(
not
property
<
st
d
::
st
ring
>
(
"U_iso_or_equiv"
).
empty
())
result
=
property
<
float
>
(
"U_iso_or_equiv"
);
result
=
property
<
float
>
(
"U_iso_or_equiv"
);
else
if
(
not
property
<
string
>
(
"B_iso_or_equiv"
).
empty
())
else
if
(
not
property
<
st
d
::
st
ring
>
(
"B_iso_or_equiv"
).
empty
())
result
=
property
<
float
>
(
"B_iso_or_equiv"
)
/
(
8
*
kPI
*
kPI
);
result
=
property
<
float
>
(
"B_iso_or_equiv"
)
/
(
8
*
kPI
*
kPI
);
else
else
throw
runtime_error
(
"Missing B_iso or U_iso"
);
throw
std
::
runtime_error
(
"Missing B_iso or U_iso"
);
return
result
;
return
result
;
}
}
...
@@ -558,22 +550,22 @@ float Atom::occupancy() const
...
@@ -558,22 +550,22 @@ float Atom::occupancy() const
return
property
<
float
>
(
"occupancy"
);
return
property
<
float
>
(
"occupancy"
);
}
}
string
Atom
::
labelAtomID
()
const
st
d
::
st
ring
Atom
::
labelAtomID
()
const
{
{
return
impl
()
->
mAtomID
;
return
impl
()
->
mAtomID
;
}
}
string
Atom
::
labelCompID
()
const
st
d
::
st
ring
Atom
::
labelCompID
()
const
{
{
return
impl
()
->
mCompID
;
return
impl
()
->
mCompID
;
}
}
string
Atom
::
labelAsymID
()
const
st
d
::
st
ring
Atom
::
labelAsymID
()
const
{
{
return
impl
()
->
mAsymID
;
return
impl
()
->
mAsymID
;
}
}
string
Atom
::
labelAltID
()
const
st
d
::
st
ring
Atom
::
labelAltID
()
const
{
{
return
impl
()
->
mAltID
;
return
impl
()
->
mAltID
;
}
}
...
@@ -588,48 +580,48 @@ int Atom::labelSeqID() const
...
@@ -588,48 +580,48 @@ int Atom::labelSeqID() const
return
impl
()
->
mSeqID
;
return
impl
()
->
mSeqID
;
}
}
string
Atom
::
authAsymID
()
const
st
d
::
st
ring
Atom
::
authAsymID
()
const
{
{
return
property
<
string
>
(
"auth_asym_id"
);
return
property
<
st
d
::
st
ring
>
(
"auth_asym_id"
);
}
}
string
Atom
::
authAtomID
()
const
st
d
::
st
ring
Atom
::
authAtomID
()
const
{
{
return
property
<
string
>
(
"auth_atom_id"
);
return
property
<
st
d
::
st
ring
>
(
"auth_atom_id"
);
}
}
string
Atom
::
pdbxAuthAltID
()
const
st
d
::
st
ring
Atom
::
pdbxAuthAltID
()
const
{
{
return
property
<
string
>
(
"pdbx_auth_alt_id"
);
return
property
<
st
d
::
st
ring
>
(
"pdbx_auth_alt_id"
);
}
}
string
Atom
::
pdbxAuthInsCode
()
const
st
d
::
st
ring
Atom
::
pdbxAuthInsCode
()
const
{
{
return
property
<
string
>
(
"pdbx_PDB_ins_code"
);
return
property
<
st
d
::
st
ring
>
(
"pdbx_PDB_ins_code"
);
}
}
string
Atom
::
authCompID
()
const
st
d
::
st
ring
Atom
::
authCompID
()
const
{
{
return
property
<
string
>
(
"auth_comp_id"
);
return
property
<
st
d
::
st
ring
>
(
"auth_comp_id"
);
}
}
string
Atom
::
authSeqID
()
const
st
d
::
st
ring
Atom
::
authSeqID
()
const
{
{
return
property
<
string
>
(
"auth_seq_id"
);
return
property
<
st
d
::
st
ring
>
(
"auth_seq_id"
);
}
}
string
Atom
::
labelID
()
const
st
d
::
st
ring
Atom
::
labelID
()
const
{
{
return
property
<
st
ring
>
(
"label_comp_id"
)
+
'_'
+
impl
()
->
mAsymID
+
'_'
+
to_string
(
impl
()
->
mSeqID
)
+
':'
+
impl
()
->
mAtomID
;
return
property
<
st
d
::
string
>
(
"label_comp_id"
)
+
'_'
+
impl
()
->
mAsymID
+
'_'
+
std
::
to_string
(
impl
()
->
mSeqID
)
+
':'
+
impl
()
->
mAtomID
;
}
}
string
Atom
::
pdbID
()
const
st
d
::
st
ring
Atom
::
pdbID
()
const
{
{
return
return
property
<
string
>
(
"auth_comp_id"
)
+
'_'
+
property
<
st
d
::
st
ring
>
(
"auth_comp_id"
)
+
'_'
+
property
<
string
>
(
"auth_asym_id"
)
+
'_'
+
property
<
st
d
::
st
ring
>
(
"auth_asym_id"
)
+
'_'
+
property
<
string
>
(
"auth_seq_id"
)
+
property
<
st
d
::
st
ring
>
(
"auth_seq_id"
)
+
property
<
string
>
(
"pdbx_PDB_ins_code"
);
property
<
st
d
::
st
ring
>
(
"pdbx_PDB_ins_code"
);
}
}
Point
Atom
::
location
()
const
Point
Atom
::
location
()
const
...
@@ -652,7 +644,7 @@ void Atom::location(Point p)
...
@@ -652,7 +644,7 @@ void Atom::location(Point p)
// return impl()->mSymmetryCopy;
// return impl()->mSymmetryCopy;
// }
// }
// string Atom::symmetry() const
// st
d::st
ring Atom::symmetry() const
// {
// {
// return clipper::Symop(impl()->mRTop).format() + "\n" + impl()->mRTop.format();
// return clipper::Symop(impl()->mRTop).format() + "\n" + impl()->mRTop.format();
// }
// }
...
@@ -690,7 +682,7 @@ bool Atom::operator==(const Atom& rhs) const
...
@@ -690,7 +682,7 @@ bool Atom::operator==(const Atom& rhs) const
// // verbose
// // verbose
// if (cif::VERBOSE > 1)
// if (cif::VERBOSE > 1)
// cout << "Calculated radius for " << AtomTypeTraits(impl()->mType).name() << " with charge " << charge() << " is " << impl()->mRadius << endl;
// cout << "Calculated radius for " << AtomTypeTraits(impl()->mType).name() << " with charge " << charge() << " is " << impl()->mRadius <<
std::
endl;
// }
// }
float
Atom
::
radius
()
const
float
Atom
::
radius
()
const
...
@@ -705,7 +697,7 @@ int Atom::compare(const Atom& b) const
...
@@ -705,7 +697,7 @@ int Atom::compare(const Atom& b) const
void
Atom
::
setID
(
int
id
)
void
Atom
::
setID
(
int
id
)
{
{
impl
()
->
mID
=
to_string
(
id
);
impl
()
->
mID
=
std
::
to_string
(
id
);
}
}
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
Atom
&
atom
)
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
Atom
&
atom
)
...
@@ -723,8 +715,8 @@ std::ostream& operator<<(std::ostream& os, const Atom& atom)
...
@@ -723,8 +715,8 @@ std::ostream& operator<<(std::ostream& os, const Atom& atom)
// --------------------------------------------------------------------
// --------------------------------------------------------------------
// residue
// residue
Residue
::
Residue
(
const
Structure
&
structure
,
const
string
&
compoundID
,
Residue
::
Residue
(
const
Structure
&
structure
,
const
st
d
::
st
ring
&
compoundID
,
const
st
ring
&
asymID
,
const
string
&
authSeqID
)
const
st
d
::
string
&
asymID
,
const
std
::
string
&
authSeqID
)
:
mStructure
(
&
structure
),
mCompoundID
(
compoundID
)
:
mStructure
(
&
structure
),
mCompoundID
(
compoundID
)
,
mAsymID
(
asymID
),
mAuthSeqID
(
authSeqID
)
,
mAsymID
(
asymID
),
mAuthSeqID
(
authSeqID
)
{
{
...
@@ -745,8 +737,8 @@ Residue::Residue(const Structure& structure, const string& compoundID,
...
@@ -745,8 +737,8 @@ Residue::Residue(const Structure& structure, const string& compoundID,
assert
(
not
mAtoms
.
empty
());
assert
(
not
mAtoms
.
empty
());
}
}
Residue
::
Residue
(
const
Structure
&
structure
,
const
string
&
compoundID
,
Residue
::
Residue
(
const
Structure
&
structure
,
const
st
d
::
st
ring
&
compoundID
,
const
string
&
asymID
,
int
seqID
)
const
st
d
::
st
ring
&
asymID
,
int
seqID
)
:
mStructure
(
&
structure
),
mCompoundID
(
compoundID
)
:
mStructure
(
&
structure
),
mCompoundID
(
compoundID
)
,
mAsymID
(
asymID
),
mSeqID
(
seqID
)
,
mAsymID
(
asymID
),
mSeqID
(
seqID
)
{
{
...
@@ -766,43 +758,43 @@ Residue::Residue(const Structure& structure, const string& compoundID,
...
@@ -766,43 +758,43 @@ Residue::Residue(const Structure& structure, const string& compoundID,
}
}
Residue
::
Residue
(
Residue
&&
rhs
)
Residue
::
Residue
(
Residue
&&
rhs
)
:
mStructure
(
rhs
.
mStructure
),
mCompoundID
(
move
(
rhs
.
mCompoundID
)),
mAsymID
(
move
(
rhs
.
mAsymID
))
:
mStructure
(
rhs
.
mStructure
),
mCompoundID
(
std
::
move
(
rhs
.
mCompoundID
)),
mAsymID
(
std
::
move
(
rhs
.
mAsymID
))
,
mSeqID
(
rhs
.
mSeqID
),
mAuthSeqID
(
rhs
.
mAuthSeqID
),
mAtoms
(
move
(
rhs
.
mAtoms
))
,
mSeqID
(
rhs
.
mSeqID
),
mAuthSeqID
(
rhs
.
mAuthSeqID
),
mAtoms
(
std
::
move
(
rhs
.
mAtoms
))
{
{
//
cerr << "move constructor residue" <<
endl;
//
std::cerr << "move constructor residue" << std::
endl;
rhs
.
mStructure
=
nullptr
;
rhs
.
mStructure
=
nullptr
;
}
}
Residue
&
Residue
::
operator
=
(
Residue
&&
rhs
)
Residue
&
Residue
::
operator
=
(
Residue
&&
rhs
)
{
{
//
cerr << "move assignment residue" <<
endl;
//
std::cerr << "move assignment residue" << std::
endl;
mStructure
=
rhs
.
mStructure
;
rhs
.
mStructure
=
nullptr
;
mStructure
=
rhs
.
mStructure
;
rhs
.
mStructure
=
nullptr
;
mCompoundID
=
move
(
rhs
.
mCompoundID
);
mCompoundID
=
std
::
move
(
rhs
.
mCompoundID
);
mAsymID
=
move
(
rhs
.
mAsymID
);
mAsymID
=
std
::
move
(
rhs
.
mAsymID
);
mSeqID
=
rhs
.
mSeqID
;
mSeqID
=
rhs
.
mSeqID
;
mAuthSeqID
=
rhs
.
mAuthSeqID
;
mAuthSeqID
=
rhs
.
mAuthSeqID
;
mAtoms
=
move
(
rhs
.
mAtoms
);
mAtoms
=
std
::
move
(
rhs
.
mAtoms
);
return
*
this
;
return
*
this
;
}
}
Residue
::~
Residue
()
Residue
::~
Residue
()
{
{
//
cerr << "~Residue" <<
endl;
//
std::cerr << "~Residue" << std::
endl;
}
}
string
Residue
::
authInsCode
()
const
st
d
::
st
ring
Residue
::
authInsCode
()
const
{
{
assert
(
mStructure
);
assert
(
mStructure
);
string
result
;
st
d
::
st
ring
result
;
try
try
{
{
char
iCode
;
char
iCode
;
tie
(
ignore
,
ignore
,
iCode
)
=
mStructure
->
MapLabelToAuth
(
mAsymID
,
mSeqID
);
tie
(
std
::
ignore
,
std
::
ignore
,
iCode
)
=
mStructure
->
MapLabelToAuth
(
mAsymID
,
mSeqID
);
result
=
string
{
iCode
};
result
=
st
d
::
st
ring
{
iCode
};
ba
::
trim
(
result
);
ba
::
trim
(
result
);
}
}
catch
(...)
catch
(...)
...
@@ -812,15 +804,15 @@ string Residue::authInsCode() const
...
@@ -812,15 +804,15 @@ string Residue::authInsCode() const
return
result
;
return
result
;
}
}
string
Residue
::
authAsymID
()
const
st
d
::
st
ring
Residue
::
authAsymID
()
const
{
{
assert
(
mStructure
);
assert
(
mStructure
);
string
result
;
st
d
::
st
ring
result
;
try
try
{
{
tie
(
result
,
ignore
,
ignore
)
=
mStructure
->
MapLabelToAuth
(
mAsymID
,
mSeqID
);
tie
(
result
,
std
::
ignore
,
std
::
ignore
)
=
mStructure
->
MapLabelToAuth
(
mAsymID
,
mSeqID
);
}
}
catch
(...)
catch
(...)
{
{
...
@@ -830,17 +822,17 @@ string Residue::authAsymID() const
...
@@ -830,17 +822,17 @@ string Residue::authAsymID() const
return
result
;
return
result
;
}
}
string
Residue
::
authSeqID
()
const
st
d
::
st
ring
Residue
::
authSeqID
()
const
{
{
assert
(
mStructure
);
assert
(
mStructure
);
string
result
;
st
d
::
st
ring
result
;
try
try
{
{
int
seqID
;
int
seqID
;
tie
(
ignore
,
seqID
,
ignore
)
=
mStructure
->
MapLabelToAuth
(
mAsymID
,
mSeqID
);
tie
(
std
::
ignore
,
seqID
,
std
::
ignore
)
=
mStructure
->
MapLabelToAuth
(
mAsymID
,
mSeqID
);
result
=
to_string
(
seqID
);
result
=
std
::
to_string
(
seqID
);
}
}
catch
(...)
catch
(...)
{
{
...
@@ -853,14 +845,14 @@ const Compound& Residue::compound() const
...
@@ -853,14 +845,14 @@ const Compound& Residue::compound() const
{
{
auto
result
=
Compound
::
create
(
mCompoundID
);
auto
result
=
Compound
::
create
(
mCompoundID
);
if
(
result
==
nullptr
)
if
(
result
==
nullptr
)
throw
runtime_error
(
"Failed to create compound "
+
mCompoundID
);
throw
std
::
runtime_error
(
"Failed to create compound "
+
mCompoundID
);
return
*
result
;
return
*
result
;
}
}
const
AtomView
&
Residue
::
atoms
()
const
const
AtomView
&
Residue
::
atoms
()
const
{
{
if
(
mStructure
==
nullptr
)
if
(
mStructure
==
nullptr
)
throw
runtime_error
(
"Invalid Residue object"
);
throw
std
::
runtime_error
(
"Invalid Residue object"
);
return
mAtoms
;
return
mAtoms
;
}
}
...
@@ -868,7 +860,7 @@ const AtomView& Residue::atoms() const
...
@@ -868,7 +860,7 @@ const AtomView& Residue::atoms() const
std
::
string
Residue
::
unique_alt_id
()
const
std
::
string
Residue
::
unique_alt_id
()
const
{
{
if
(
mStructure
==
nullptr
)
if
(
mStructure
==
nullptr
)
throw
runtime_error
(
"Invalid Residue object"
);
throw
std
::
runtime_error
(
"Invalid Residue object"
);
auto
firstAlt
=
std
::
find_if
(
mAtoms
.
begin
(),
mAtoms
.
end
(),
[](
auto
&
a
)
{
return
not
a
.
labelAltID
().
empty
();
});
auto
firstAlt
=
std
::
find_if
(
mAtoms
.
begin
(),
mAtoms
.
end
(),
[](
auto
&
a
)
{
return
not
a
.
labelAltID
().
empty
();
});
...
@@ -878,7 +870,7 @@ std::string Residue::unique_alt_id() const
...
@@ -878,7 +870,7 @@ std::string Residue::unique_alt_id() const
AtomView
Residue
::
unique_atoms
()
const
AtomView
Residue
::
unique_atoms
()
const
{
{
if
(
mStructure
==
nullptr
)
if
(
mStructure
==
nullptr
)
throw
runtime_error
(
"Invalid Residue object"
);
throw
std
::
runtime_error
(
"Invalid Residue object"
);
AtomView
result
;
AtomView
result
;
std
::
string
firstAlt
;
std
::
string
firstAlt
;
...
@@ -907,7 +899,7 @@ AtomView Residue::unique_atoms() const
...
@@ -907,7 +899,7 @@ AtomView Residue::unique_atoms() const
return
result
;
return
result
;
}
}
Atom
Residue
::
atomByID
(
const
string
&
atomID
)
const
Atom
Residue
::
atomByID
(
const
st
d
::
st
ring
&
atomID
)
const
{
{
Atom
result
;
Atom
result
;
...
@@ -939,40 +931,40 @@ bool Residue::isEntity() const
...
@@ -939,40 +931,40 @@ bool Residue::isEntity() const
return
a1
.
size
()
==
a2
.
size
();
return
a1
.
size
()
==
a2
.
size
();
}
}
string
Residue
::
authID
()
const
st
d
::
st
ring
Residue
::
authID
()
const
{
{
string
result
;
st
d
::
st
ring
result
;
try
try
{
{
char
chainID
,
iCode
;
char
chainID
,
iCode
;
int
seqNum
;
int
seqNum
;
tie
(
chainID
,
seqNum
,
iCode
)
=
mStructure
->
MapLabelToAuth
(
mAsymID
,
mSeqID
);
std
::
tie
(
chainID
,
seqNum
,
iCode
)
=
mStructure
->
MapLabelToAuth
(
mAsymID
,
mSeqID
);
result
=
chainID
+
to_string
(
seqNum
);
result
=
chainID
+
std
::
to_string
(
seqNum
);
if
(
iCode
!=
' '
and
iCode
!=
0
)
if
(
iCode
!=
' '
and
iCode
!=
0
)
result
+=
iCode
;
result
+=
iCode
;
}
}
catch
(...)
catch
(...)
{
{
result
=
mAsymID
+
to_string
(
mSeqID
);
result
=
mAsymID
+
std
::
to_string
(
mSeqID
);
}
}
return
result
;
return
result
;
}
}
string
Residue
::
labelID
()
const
st
d
::
st
ring
Residue
::
labelID
()
const
{
{
if
(
mCompoundID
==
"HOH"
)
if
(
mCompoundID
==
"HOH"
)
return
mAsymID
+
mAuthSeqID
;
return
mAsymID
+
mAuthSeqID
;
else
else
return
mAsymID
+
to_string
(
mSeqID
);
return
mAsymID
+
std
::
to_string
(
mSeqID
);
}
}
tuple
<
Point
,
float
>
Residue
::
centerAndRadius
()
const
std
::
tuple
<
Point
,
float
>
Residue
::
centerAndRadius
()
const
{
{
vector
<
Point
>
pts
;
std
::
vector
<
Point
>
pts
;
for
(
auto
&
a
:
mAtoms
)
for
(
auto
&
a
:
mAtoms
)
pts
.
push_back
(
a
.
location
());
pts
.
push_back
(
a
.
location
());
...
@@ -986,7 +978,7 @@ tuple<Point,float> Residue::centerAndRadius() const
...
@@ -986,7 +978,7 @@ tuple<Point,float> Residue::centerAndRadius() const
radius
=
d
;
radius
=
d
;
}
}
return
make_tuple
(
center
,
radius
);
return
std
::
make_tuple
(
center
,
radius
);
}
}
bool
Residue
::
hasAlternateAtoms
()
const
bool
Residue
::
hasAlternateAtoms
()
const
...
@@ -1008,11 +1000,11 @@ std::ostream& operator<<(std::ostream& os, const Residue& res)
...
@@ -1008,11 +1000,11 @@ std::ostream& operator<<(std::ostream& os, const Residue& res)
// monomer
// monomer
//Monomer::Monomer(Monomer&& rhs)
//Monomer::Monomer(Monomer&& rhs)
// : Residue(move(rhs)), mPolymer(rhs.mPolymer), mIndex(rhs.mIndex)
// : Residue(
std::
move(rhs)), mPolymer(rhs.mPolymer), mIndex(rhs.mIndex)
//{
//{
//}
//}
Monomer
::
Monomer
(
const
Polymer
&
polymer
,
uint32_t
index
,
int
seqID
,
const
string
&
compoundID
)
Monomer
::
Monomer
(
const
Polymer
&
polymer
,
uint32_t
index
,
int
seqID
,
const
st
d
::
st
ring
&
compoundID
)
:
Residue
(
*
polymer
.
structure
(),
compoundID
,
polymer
.
asymID
(),
seqID
)
:
Residue
(
*
polymer
.
structure
(),
compoundID
,
polymer
.
asymID
(),
seqID
)
,
mPolymer
(
&
polymer
)
,
mPolymer
(
&
polymer
)
,
mIndex
(
index
)
,
mIndex
(
index
)
...
@@ -1020,15 +1012,15 @@ Monomer::Monomer(const Polymer& polymer, uint32_t index, int seqID, const string
...
@@ -1020,15 +1012,15 @@ Monomer::Monomer(const Polymer& polymer, uint32_t index, int seqID, const string
}
}
Monomer
::
Monomer
(
Monomer
&&
rhs
)
Monomer
::
Monomer
(
Monomer
&&
rhs
)
:
Residue
(
move
(
rhs
)),
mPolymer
(
rhs
.
mPolymer
),
mIndex
(
rhs
.
mIndex
)
:
Residue
(
std
::
move
(
rhs
)),
mPolymer
(
rhs
.
mPolymer
),
mIndex
(
rhs
.
mIndex
)
{
{
cerr
<<
"move constructor monomer"
<<
endl
;
std
::
cerr
<<
"move constructor monomer"
<<
std
::
endl
;
// mStructure = rhs.mStructure; rhs.mStructure = nullptr;
// mStructure = rhs.mStructure; rhs.mStructure = nullptr;
// mCompoundID = move(rhs.mCompoundID);
// mCompoundID =
std::
move(rhs.mCompoundID);
// mAsymID = move(rhs.mAsymID);
// mAsymID =
std::
move(rhs.mAsymID);
// mSeqID = rhs.mSeqID;
// mSeqID = rhs.mSeqID;
// mAtoms = move(rhs.mAtoms);
// mAtoms =
std::
move(rhs.mAtoms);
//
//
// mPolymer = rhs.mPolymer; rhs.mPolymer = nullptr;
// mPolymer = rhs.mPolymer; rhs.mPolymer = nullptr;
// mIndex = rhs.mIndex;
// mIndex = rhs.mIndex;
...
@@ -1037,9 +1029,9 @@ cerr << "move constructor monomer" << endl;
...
@@ -1037,9 +1029,9 @@ cerr << "move constructor monomer" << endl;
Monomer
&
Monomer
::
operator
=
(
Monomer
&&
rhs
)
Monomer
&
Monomer
::
operator
=
(
Monomer
&&
rhs
)
{
{
cerr
<<
"move assignment monomer"
<<
endl
;
std
::
cerr
<<
"move assignment monomer"
<<
std
::
endl
;
Residue
::
operator
=
(
move
(
rhs
));
Residue
::
operator
=
(
std
::
move
(
rhs
));
mPolymer
=
rhs
.
mPolymer
;
rhs
.
mPolymer
=
nullptr
;
mPolymer
=
rhs
.
mPolymer
;
rhs
.
mPolymer
=
nullptr
;
mIndex
=
rhs
.
mIndex
;
mIndex
=
rhs
.
mIndex
;
...
@@ -1080,10 +1072,10 @@ float Monomer::phi() const
...
@@ -1080,10 +1072,10 @@ float Monomer::phi() const
result
=
DihedralAngle
(
prev
.
C
().
location
(),
N
().
location
(),
CAlpha
().
location
(),
C
().
location
());
result
=
DihedralAngle
(
prev
.
C
().
location
(),
N
().
location
(),
CAlpha
().
location
(),
C
().
location
());
}
}
}
}
catch
(
const
exception
&
ex
)
catch
(
const
std
::
exception
&
ex
)
{
{
if
(
cif
::
VERBOSE
)
if
(
cif
::
VERBOSE
)
cerr
<<
ex
.
what
()
<<
endl
;
std
::
cerr
<<
ex
.
what
()
<<
std
::
endl
;
}
}
return
result
;
return
result
;
...
@@ -1102,10 +1094,10 @@ float Monomer::psi() const
...
@@ -1102,10 +1094,10 @@ float Monomer::psi() const
result
=
DihedralAngle
(
N
().
location
(),
CAlpha
().
location
(),
C
().
location
(),
next
.
N
().
location
());
result
=
DihedralAngle
(
N
().
location
(),
CAlpha
().
location
(),
C
().
location
(),
next
.
N
().
location
());
}
}
}
}
catch
(
const
exception
&
ex
)
catch
(
const
std
::
exception
&
ex
)
{
{
if
(
cif
::
VERBOSE
)
if
(
cif
::
VERBOSE
)
cerr
<<
ex
.
what
()
<<
endl
;
std
::
cerr
<<
ex
.
what
()
<<
std
::
endl
;
}
}
return
result
;
return
result
;
...
@@ -1126,10 +1118,10 @@ float Monomer::alpha() const
...
@@ -1126,10 +1118,10 @@ float Monomer::alpha() const
result
=
DihedralAngle
(
prev
.
CAlpha
().
location
(),
CAlpha
().
location
(),
next
.
CAlpha
().
location
(),
nextNext
.
CAlpha
().
location
());
result
=
DihedralAngle
(
prev
.
CAlpha
().
location
(),
CAlpha
().
location
(),
next
.
CAlpha
().
location
(),
nextNext
.
CAlpha
().
location
());
}
}
}
}
catch
(
const
exception
&
ex
)
catch
(
const
std
::
exception
&
ex
)
{
{
if
(
cif
::
VERBOSE
)
if
(
cif
::
VERBOSE
)
cerr
<<
ex
.
what
()
<<
endl
;
std
::
cerr
<<
ex
.
what
()
<<
std
::
endl
;
}
}
return
result
;
return
result
;
...
@@ -1154,11 +1146,11 @@ float Monomer::kappa() const
...
@@ -1154,11 +1146,11 @@ float Monomer::kappa() const
}
}
}
}
}
}
catch
(
const
exception
&
ex
)
catch
(
const
std
::
exception
&
ex
)
{
{
if
(
cif
::
VERBOSE
)
if
(
cif
::
VERBOSE
)
cerr
<<
"When trying to calculate kappa for "
<<
asymID
()
<<
':'
<<
seqID
()
<<
": "
std
::
cerr
<<
"When trying to calculate kappa for "
<<
asymID
()
<<
':'
<<
seqID
()
<<
": "
<<
ex
.
what
()
<<
endl
;
<<
ex
.
what
()
<<
std
::
endl
;
}
}
return
result
;
return
result
;
...
@@ -1177,11 +1169,11 @@ float Monomer::tco() const
...
@@ -1177,11 +1169,11 @@ float Monomer::tco() const
result
=
CosinusAngle
(
C
().
location
(),
O
().
location
(),
prev
.
C
().
location
(),
prev
.
O
().
location
());
result
=
CosinusAngle
(
C
().
location
(),
O
().
location
(),
prev
.
C
().
location
(),
prev
.
O
().
location
());
}
}
}
}
catch
(
const
exception
&
ex
)
catch
(
const
std
::
exception
&
ex
)
{
{
if
(
cif
::
VERBOSE
)
if
(
cif
::
VERBOSE
)
cerr
<<
"When trying to calculate tco for "
<<
asymID
()
<<
':'
<<
seqID
()
<<
": "
std
::
cerr
<<
"When trying to calculate tco for "
<<
asymID
()
<<
':'
<<
seqID
()
<<
": "
<<
ex
.
what
()
<<
endl
;
<<
ex
.
what
()
<<
std
::
endl
;
}
}
return
result
;
return
result
;
...
@@ -1196,17 +1188,17 @@ float Monomer::omega() const
...
@@ -1196,17 +1188,17 @@ float Monomer::omega() const
if
(
not
is_last_in_chain
())
if
(
not
is_last_in_chain
())
result
=
omega
(
*
this
,
mPolymer
->
operator
[](
mIndex
+
1
));
result
=
omega
(
*
this
,
mPolymer
->
operator
[](
mIndex
+
1
));
}
}
catch
(
const
exception
&
ex
)
catch
(
const
std
::
exception
&
ex
)
{
{
if
(
cif
::
VERBOSE
)
if
(
cif
::
VERBOSE
)
cerr
<<
"When trying to calculate omega for "
<<
asymID
()
<<
':'
<<
seqID
()
<<
": "
std
::
cerr
<<
"When trying to calculate omega for "
<<
asymID
()
<<
':'
<<
seqID
()
<<
": "
<<
ex
.
what
()
<<
endl
;
<<
ex
.
what
()
<<
std
::
endl
;
}
}
return
result
;
return
result
;
}
}
const
map
<
string
,
vector
<
string
>>
kChiAtomsMap
=
{
const
std
::
map
<
std
::
string
,
std
::
vector
<
std
::
string
>>
kChiAtomsMap
=
{
{
"ASP"
,
{
"CG"
,
"OD1"
}
},
{
"ASP"
,
{
"CG"
,
"OD1"
}
},
{
"ASN"
,
{
"CG"
,
"OD1"
}
},
{
"ASN"
,
{
"CG"
,
"OD1"
}
},
{
"ARG"
,
{
"CG"
,
"CD"
,
"NE"
,
"CZ"
}
},
{
"ARG"
,
{
"CG"
,
"CD"
,
"NE"
,
"CZ"
}
},
...
@@ -1248,7 +1240,7 @@ float Monomer::chi(size_t nr) const
...
@@ -1248,7 +1240,7 @@ float Monomer::chi(size_t nr) const
auto
i
=
kChiAtomsMap
.
find
(
mCompoundID
);
auto
i
=
kChiAtomsMap
.
find
(
mCompoundID
);
if
(
i
!=
kChiAtomsMap
.
end
()
and
nr
<
i
->
second
.
size
())
if
(
i
!=
kChiAtomsMap
.
end
()
and
nr
<
i
->
second
.
size
())
{
{
vector
<
string
>
atoms
{
"N"
,
"CA"
,
"CB"
};
std
::
vector
<
std
::
string
>
atoms
{
"N"
,
"CA"
,
"CB"
};
atoms
.
insert
(
atoms
.
end
(),
i
->
second
.
begin
(),
i
->
second
.
end
());
atoms
.
insert
(
atoms
.
end
(),
i
->
second
.
begin
(),
i
->
second
.
end
());
...
@@ -1410,7 +1402,7 @@ bool Monomer::isCis(const mmcif::Monomer& a, const mmcif::Monomer& b)
...
@@ -1410,7 +1402,7 @@ bool Monomer::isCis(const mmcif::Monomer& a, const mmcif::Monomer& b)
// if (index < polySeq.size())
// if (index < polySeq.size())
// {
// {
// int seqID;
// int seqID;
// string asymID, monID;
// st
d::st
ring asymID, monID;
// cif::tie(asymID, seqID, monID) =
// cif::tie(asymID, seqID, monID) =
// polySeq[mIndex].get("asym_id", "seq_id", "mon_id");
// polySeq[mIndex].get("asym_id", "seq_id", "mon_id");
//
//
...
@@ -1423,7 +1415,7 @@ bool Monomer::isCis(const mmcif::Monomer& a, const mmcif::Monomer& b)
...
@@ -1423,7 +1415,7 @@ bool Monomer::isCis(const mmcif::Monomer& a, const mmcif::Monomer& b)
// if (index >= mPolySeq.size())
// if (index >= mPolySeq.size())
// throw out_of_range("Invalid index for residue in polymer");
// throw out_of_range("Invalid index for residue in polymer");
//
//
// string compoundID;
// st
d::st
ring compoundID;
// int seqID;
// int seqID;
//
//
// auto r = mPolySeq[index];
// auto r = mPolySeq[index];
...
@@ -1449,7 +1441,7 @@ bool Monomer::isCis(const mmcif::Monomer& a, const mmcif::Monomer& b)
...
@@ -1449,7 +1441,7 @@ bool Monomer::isCis(const mmcif::Monomer& a, const mmcif::Monomer& b)
// if (mIndex < polySeq.size())
// if (mIndex < polySeq.size())
// {
// {
// int seqID;
// int seqID;
// string asymID, monID;
// st
d::st
ring asymID, monID;
// cif::tie(asymID, seqID, monID) =
// cif::tie(asymID, seqID, monID) =
// polySeq[mIndex].get("asym_id", "seq_id", "mon_id");
// polySeq[mIndex].get("asym_id", "seq_id", "mon_id");
//
//
...
@@ -1459,11 +1451,11 @@ bool Monomer::isCis(const mmcif::Monomer& a, const mmcif::Monomer& b)
...
@@ -1459,11 +1451,11 @@ bool Monomer::isCis(const mmcif::Monomer& a, const mmcif::Monomer& b)
// return *this;
// return *this;
//}
//}
//Polymer::Polymer(const Structure& s, const string& asymID)
//Polymer::Polymer(const Structure& s, const st
d::st
ring& asymID)
// : mStructure(const_cast<Structure*>(&s)), mAsymID(asymID)
// : mStructure(const_cast<Structure*>(&s)), mAsymID(asymID)
// , mPolySeq(s.category("pdbx_poly_seq_scheme").find(cif::Key("asym_id") == mAsymID))
// , mPolySeq(s.category("pdbx_poly_seq_scheme").find(cif::Key("asym_id") == mAsymID))
//{
//{
// mEntityID = mPolySeq.front()["entity_id"].as<string>();
// mEntityID = mPolySeq.front()["entity_id"].as<st
d::st
ring>();
//
//
//#if DEBUG
//#if DEBUG
// for (auto r: mPolySeq)
// for (auto r: mPolySeq)
...
@@ -1473,35 +1465,35 @@ bool Monomer::isCis(const mmcif::Monomer& a, const mmcif::Monomer& b)
...
@@ -1473,35 +1465,35 @@ bool Monomer::isCis(const mmcif::Monomer& a, const mmcif::Monomer& b)
//}
//}
//Polymer::Polymer(Polymer&& rhs)
//Polymer::Polymer(Polymer&& rhs)
// :
vector<Monomer>(
move(rhs))
// :
std::vector<Monomer>(std::
move(rhs))
// , mStructure(rhs.mStructure)
// , mStructure(rhs.mStructure)
// , mEntityID(
move(rhs.mEntityID)), mAsymID(move(rhs.mAsymID)), mPolySeq(
move(rhs.mPolySeq))
// , mEntityID(
std::move(rhs.mEntityID)), mAsymID(std::move(rhs.mAsymID)), mPolySeq(std::
move(rhs.mPolySeq))
//{
//{
// rhs.mStructure = nullptr;
// rhs.mStructure = nullptr;
//}
//}
//
//
//Polymer& Polymer::operator=(Polymer&& rhs)
//Polymer& Polymer::operator=(Polymer&& rhs)
//{
//{
//
vector<Monomer>::operator=(
move(rhs));
//
std::vector<Monomer>::operator=(std::
move(rhs));
// mStructure = rhs.mStructure; rhs.mStructure = nullptr;
// mStructure = rhs.mStructure; rhs.mStructure = nullptr;
// mEntityID = move(rhs.mEntityID);
// mEntityID =
std::
move(rhs.mEntityID);
// mAsymID = move(rhs.mAsymID);
// mAsymID =
std::
move(rhs.mAsymID);
// mPolySeq = move(rhs.mPolySeq);
// mPolySeq =
std::
move(rhs.mPolySeq);
// return *this;
// return *this;
//}
//}
Polymer
::
Polymer
(
const
Structure
&
s
,
const
st
ring
&
entityID
,
const
string
&
asymID
)
Polymer
::
Polymer
(
const
Structure
&
s
,
const
st
d
::
string
&
entityID
,
const
std
::
string
&
asymID
)
:
mStructure
(
const_cast
<
Structure
*>
(
&
s
)),
mEntityID
(
entityID
),
mAsymID
(
asymID
)
:
mStructure
(
const_cast
<
Structure
*>
(
&
s
)),
mEntityID
(
entityID
),
mAsymID
(
asymID
)
,
mPolySeq
(
s
.
category
(
"pdbx_poly_seq_scheme"
),
cif
::
Key
(
"asym_id"
)
==
mAsymID
and
cif
::
Key
(
"entity_id"
)
==
mEntityID
)
,
mPolySeq
(
s
.
category
(
"pdbx_poly_seq_scheme"
),
cif
::
Key
(
"asym_id"
)
==
mAsymID
and
cif
::
Key
(
"entity_id"
)
==
mEntityID
)
{
{
map
<
uint32_t
,
uint32_t
>
ix
;
std
::
map
<
uint32_t
,
uint32_t
>
ix
;
reserve
(
mPolySeq
.
size
());
reserve
(
mPolySeq
.
size
());
for
(
auto
r
:
mPolySeq
)
for
(
auto
r
:
mPolySeq
)
{
{
int
seqID
;
int
seqID
;
string
compoundID
;
st
d
::
st
ring
compoundID
;
cif
::
tie
(
seqID
,
compoundID
)
=
r
.
get
(
"seq_id"
,
"mon_id"
);
cif
::
tie
(
seqID
,
compoundID
)
=
r
.
get
(
"seq_id"
,
"mon_id"
);
uint32_t
index
=
size
();
uint32_t
index
=
size
();
...
@@ -1520,9 +1512,9 @@ Polymer::Polymer(const Structure& s, const string& entityID, const string& asymI
...
@@ -1520,9 +1512,9 @@ Polymer::Polymer(const Structure& s, const string& entityID, const string& asymI
}
}
}
}
string
Polymer
::
chainID
()
const
st
d
::
st
ring
Polymer
::
chainID
()
const
{
{
return
mPolySeq
.
front
()[
"pdb_strand_id"
].
as
<
string
>
();
return
mPolySeq
.
front
()[
"pdb_strand_id"
].
as
<
st
d
::
st
ring
>
();
}
}
Monomer
&
Polymer
::
getBySeqID
(
int
seqID
)
Monomer
&
Polymer
::
getBySeqID
(
int
seqID
)
...
@@ -1531,7 +1523,7 @@ Monomer& Polymer::getBySeqID(int seqID)
...
@@ -1531,7 +1523,7 @@ Monomer& Polymer::getBySeqID(int seqID)
if
(
m
.
seqID
()
==
seqID
)
if
(
m
.
seqID
()
==
seqID
)
return
m
;
return
m
;
throw
runtime_error
(
"Monomer with seqID "
+
to_string
(
seqID
)
+
" not found in polymer "
+
mAsymID
);
throw
std
::
runtime_error
(
"Monomer with seqID "
+
std
::
to_string
(
seqID
)
+
" not found in polymer "
+
mAsymID
);
}
}
const
Monomer
&
Polymer
::
getBySeqID
(
int
seqID
)
const
const
Monomer
&
Polymer
::
getBySeqID
(
int
seqID
)
const
...
@@ -1540,16 +1532,16 @@ const Monomer& Polymer::getBySeqID(int seqID) const
...
@@ -1540,16 +1532,16 @@ const Monomer& Polymer::getBySeqID(int seqID) const
if
(
m
.
seqID
()
==
seqID
)
if
(
m
.
seqID
()
==
seqID
)
return
m
;
return
m
;
throw
runtime_error
(
"Monomer with seqID "
+
to_string
(
seqID
)
+
" not found in polymer "
+
mAsymID
);
throw
std
::
runtime_error
(
"Monomer with seqID "
+
std
::
to_string
(
seqID
)
+
" not found in polymer "
+
mAsymID
);
}
}
int
Polymer
::
Distance
(
const
Monomer
&
a
,
const
Monomer
&
b
)
const
int
Polymer
::
Distance
(
const
Monomer
&
a
,
const
Monomer
&
b
)
const
{
{
int
result
=
numeric_limits
<
int
>::
max
();
int
result
=
std
::
numeric_limits
<
int
>::
max
();
if
(
a
.
asymID
()
==
b
.
asymID
())
if
(
a
.
asymID
()
==
b
.
asymID
())
{
{
int
ixa
=
numeric_limits
<
int
>::
max
(),
ixb
=
numeric_limits
<
int
>::
max
();
int
ixa
=
std
::
numeric_limits
<
int
>::
max
(),
ixb
=
std
::
numeric_limits
<
int
>::
max
();
int
ix
=
0
,
f
=
0
;
int
ix
=
0
,
f
=
0
;
for
(
auto
&
m
:
*
this
)
for
(
auto
&
m
:
*
this
)
...
@@ -1600,14 +1592,14 @@ void File::load(const std::string& p)
...
@@ -1600,14 +1592,14 @@ void File::load(const std::string& p)
//
//
// struct entity
// struct entity
// {
// {
// string id;
// st
d::st
ring id;
// string type;
// st
d::st
ring type;
// };
// };
// vector<entity> entities;
//
std::
vector<entity> entities;
//
//
// for (auto& _e: db["entity"])
// for (auto& _e: db["entity"])
// {
// {
// string type = _e["type"];
// st
d::st
ring type = _e["type"];
// ba::to_lower(type);
// ba::to_lower(type);
// entities.push_back({ _e["id"], type });
// entities.push_back({ _e["id"], type });
// }
// }
...
@@ -1617,13 +1609,13 @@ void File::load(const std::string& p)
...
@@ -1617,13 +1609,13 @@ void File::load(const std::string& p)
// {
// {
// AtomPtr ap(new Atom(this, atom_site));
// AtomPtr ap(new Atom(this, atom_site));
//
//
// string entity_id = atom_site["entity_id"];
// st
d::st
ring entity_id = atom_site["entity_id"];
//
//
// auto e = find_if(entities.begin(), entities.end(), [=](entity& e) -> bool { return e.id == entity_id; });
// auto e = find_if(entities.begin(), entities.end(), [=](entity& e) -> bool { return e.id == entity_id; });
// if (e == entities.end())
// if (e == entities.end())
// throw runtime_error("Entity " + entity_id + " is not defined");
// throw
std::
runtime_error("Entity " + entity_id + " is not defined");
//
//
// string comp_id, asym_id, seq_id;
// st
d::st
ring comp_id, asym_id, seq_id;
// cif::tie(comp_id, seq_id) = atom_site.get("label_comp_id", "label_asym_id", "label_seq_id");
// cif::tie(comp_id, seq_id) = atom_site.get("label_comp_id", "label_asym_id", "label_seq_id");
//
//
// auto r = find_if(m_residues.begin(), m_residues.end(), [=](residue_ptr& res) -> bool
// auto r = find_if(m_residues.begin(), m_residues.end(), [=](residue_ptr& res) -> bool
...
@@ -1655,7 +1647,7 @@ cif::Datablock& File::data()
...
@@ -1655,7 +1647,7 @@ cif::Datablock& File::data()
assert
(
mImpl
->
mDb
);
assert
(
mImpl
->
mDb
);
if
(
mImpl
==
nullptr
or
mImpl
->
mDb
==
nullptr
)
if
(
mImpl
==
nullptr
or
mImpl
->
mDb
==
nullptr
)
throw
runtime_error
(
"No data loaded"
);
throw
std
::
runtime_error
(
"No data loaded"
);
return
*
mImpl
->
mDb
;
return
*
mImpl
->
mDb
;
}
}
...
@@ -1665,7 +1657,7 @@ cif::File& File::file()
...
@@ -1665,7 +1657,7 @@ cif::File& File::file()
assert
(
mImpl
);
assert
(
mImpl
);
if
(
mImpl
==
nullptr
)
if
(
mImpl
==
nullptr
)
throw
runtime_error
(
"No data loaded"
);
throw
std
::
runtime_error
(
"No data loaded"
);
return
mImpl
->
mData
;
return
mImpl
->
mData
;
}
}
...
@@ -1720,7 +1712,7 @@ void Structure::loadData()
...
@@ -1720,7 +1712,7 @@ void Structure::loadData()
for
(
auto
&
r
:
polySeqScheme
)
for
(
auto
&
r
:
polySeqScheme
)
{
{
string
asymID
,
entityID
,
seqID
,
monID
;
st
d
::
st
ring
asymID
,
entityID
,
seqID
,
monID
;
cif
::
tie
(
asymID
,
entityID
,
seqID
,
monID
)
=
cif
::
tie
(
asymID
,
entityID
,
seqID
,
monID
)
=
r
.
get
(
"asym_id"
,
"entity_id"
,
"seq_id"
,
"mon_id"
);
r
.
get
(
"asym_id"
,
"entity_id"
,
"seq_id"
,
"mon_id"
);
...
@@ -1732,7 +1724,7 @@ void Structure::loadData()
...
@@ -1732,7 +1724,7 @@ void Structure::loadData()
for
(
auto
&
r
:
nonPolyScheme
)
for
(
auto
&
r
:
nonPolyScheme
)
{
{
string
asymID
,
monID
,
pdbSeqNum
;
st
d
::
st
ring
asymID
,
monID
,
pdbSeqNum
;
cif
::
tie
(
asymID
,
monID
,
pdbSeqNum
)
=
cif
::
tie
(
asymID
,
monID
,
pdbSeqNum
)
=
r
.
get
(
"asym_id"
,
"mon_id"
,
"pdb_seq_num"
);
r
.
get
(
"asym_id"
,
"mon_id"
,
"pdb_seq_num"
);
...
@@ -1745,7 +1737,7 @@ void Structure::loadData()
...
@@ -1745,7 +1737,7 @@ void Structure::loadData()
void
Structure
::
updateAtomIndex
()
void
Structure
::
updateAtomIndex
()
{
{
mAtomIndex
=
vector
<
size_t
>
(
mAtoms
.
size
());
mAtomIndex
=
std
::
vector
<
size_t
>
(
mAtoms
.
size
());
iota
(
mAtomIndex
.
begin
(),
mAtomIndex
.
end
(),
0
);
iota
(
mAtomIndex
.
begin
(),
mAtomIndex
.
end
(),
0
);
...
@@ -1774,10 +1766,10 @@ AtomView Structure::waters() const
...
@@ -1774,10 +1766,10 @@ AtomView Structure::waters() const
// Get the entity id for water
// Get the entity id for water
auto
&
entityCat
=
db
[
"entity"
];
auto
&
entityCat
=
db
[
"entity"
];
string
waterEntityID
;
st
d
::
st
ring
waterEntityID
;
for
(
auto
&
e
:
entityCat
)
for
(
auto
&
e
:
entityCat
)
{
{
string
id
,
type
;
st
d
::
st
ring
id
,
type
;
cif
::
tie
(
id
,
type
)
=
e
.
get
(
"id"
,
"type"
);
cif
::
tie
(
id
,
type
)
=
e
.
get
(
"id"
,
"type"
);
if
(
ba
::
iequals
(
type
,
"water"
))
if
(
ba
::
iequals
(
type
,
"water"
))
{
{
...
@@ -1788,28 +1780,28 @@ AtomView Structure::waters() const
...
@@ -1788,28 +1780,28 @@ AtomView Structure::waters() const
for
(
auto
&
a
:
mAtoms
)
for
(
auto
&
a
:
mAtoms
)
{
{
if
(
a
.
property
<
string
>
(
"label_entity_id"
)
==
waterEntityID
)
if
(
a
.
property
<
st
d
::
st
ring
>
(
"label_entity_id"
)
==
waterEntityID
)
result
.
push_back
(
a
);
result
.
push_back
(
a
);
}
}
return
result
;
return
result
;
}
}
Atom
Structure
::
getAtomByID
(
string
id
)
const
Atom
Structure
::
getAtomByID
(
st
d
::
st
ring
id
)
const
{
{
auto
i
=
lower_bound
(
mAtomIndex
.
begin
(),
mAtomIndex
.
end
(),
auto
i
=
std
::
lower_bound
(
mAtomIndex
.
begin
(),
mAtomIndex
.
end
(),
id
,
[
this
](
auto
&
a
,
auto
&
b
)
{
return
mAtoms
[
a
].
id
()
<
b
;
});
id
,
[
this
](
auto
&
a
,
auto
&
b
)
{
return
mAtoms
[
a
].
id
()
<
b
;
});
// auto i = find_if(mAtoms.begin(), mAtoms.end(),
// auto i = find_if(mAtoms.begin(), mAtoms.end(),
// [&id](auto& a) { return a.id() == id; });
// [&id](auto& a) { return a.id() == id; });
if
(
i
==
mAtomIndex
.
end
()
or
mAtoms
[
*
i
].
id
()
!=
id
)
if
(
i
==
mAtomIndex
.
end
()
or
mAtoms
[
*
i
].
id
()
!=
id
)
throw
out_of_range
(
"Could not find atom with id "
+
id
);
throw
std
::
out_of_range
(
"Could not find atom with id "
+
id
);
return
mAtoms
[
*
i
];
return
mAtoms
[
*
i
];
}
}
Atom
Structure
::
getAtomByLabel
(
const
st
ring
&
atomID
,
const
string
&
asymID
,
const
string
&
compID
,
int
seqID
,
const
string
&
altID
)
Atom
Structure
::
getAtomByLabel
(
const
st
d
::
string
&
atomID
,
const
std
::
string
&
asymID
,
const
std
::
string
&
compID
,
int
seqID
,
const
std
::
string
&
altID
)
{
{
for
(
auto
&
a
:
mAtoms
)
for
(
auto
&
a
:
mAtoms
)
{
{
...
@@ -1823,7 +1815,7 @@ Atom Structure::getAtomByLabel(const string& atomID, const string& asymID, const
...
@@ -1823,7 +1815,7 @@ Atom Structure::getAtomByLabel(const string& atomID, const string& asymID, const
}
}
}
}
throw
out_of_range
(
"Could not find atom with specified label"
);
throw
std
::
out_of_range
(
"Could not find atom with specified label"
);
}
}
File
&
Structure
::
getFile
()
const
File
&
Structure
::
getFile
()
const
...
@@ -1837,25 +1829,25 @@ cif::Category& Structure::category(const char* name) const
...
@@ -1837,25 +1829,25 @@ cif::Category& Structure::category(const char* name) const
return
db
[
name
];
return
db
[
name
];
}
}
tuple
<
char
,
int
,
char
>
Structure
::
MapLabelToAuth
(
std
::
tuple
<
char
,
int
,
char
>
Structure
::
MapLabelToAuth
(
const
string
&
asymID
,
int
seqID
)
const
const
st
d
::
st
ring
&
asymID
,
int
seqID
)
const
{
{
auto
&
db
=
*
getFile
().
impl
().
mDb
;
auto
&
db
=
*
getFile
().
impl
().
mDb
;
tuple
<
char
,
int
,
char
>
result
;
std
::
tuple
<
char
,
int
,
char
>
result
;
bool
found
=
false
;
bool
found
=
false
;
for
(
auto
r
:
db
[
"pdbx_poly_seq_scheme"
].
find
(
for
(
auto
r
:
db
[
"pdbx_poly_seq_scheme"
].
find
(
cif
::
Key
(
"asym_id"
)
==
asymID
and
cif
::
Key
(
"asym_id"
)
==
asymID
and
cif
::
Key
(
"seq_id"
)
==
seqID
))
cif
::
Key
(
"seq_id"
)
==
seqID
))
{
{
string
auth_asym_id
,
pdb_ins_code
;
st
d
::
st
ring
auth_asym_id
,
pdb_ins_code
;
int
pdb_seq_num
;
int
pdb_seq_num
;
cif
::
tie
(
auth_asym_id
,
pdb_seq_num
,
pdb_ins_code
)
=
cif
::
tie
(
auth_asym_id
,
pdb_seq_num
,
pdb_ins_code
)
=
r
.
get
(
"pdb_strand_id"
,
"pdb_seq_num"
,
"pdb_ins_code"
);
r
.
get
(
"pdb_strand_id"
,
"pdb_seq_num"
,
"pdb_ins_code"
);
result
=
make_tuple
(
auth_asym_id
.
front
(),
pdb_seq_num
,
result
=
std
::
make_tuple
(
auth_asym_id
.
front
(),
pdb_seq_num
,
pdb_ins_code
.
empty
()
?
' '
:
pdb_ins_code
.
front
());
pdb_ins_code
.
empty
()
?
' '
:
pdb_ins_code
.
front
());
found
=
true
;
found
=
true
;
...
@@ -1868,13 +1860,13 @@ tuple<char,int,char> Structure::MapLabelToAuth(
...
@@ -1868,13 +1860,13 @@ tuple<char,int,char> Structure::MapLabelToAuth(
cif
::
Key
(
"asym_id"
)
==
asymID
and
cif
::
Key
(
"asym_id"
)
==
asymID
and
cif
::
Key
(
"seq_id"
)
==
seqID
))
cif
::
Key
(
"seq_id"
)
==
seqID
))
{
{
string
pdb_strand_id
,
pdb_ins_code
;
st
d
::
st
ring
pdb_strand_id
,
pdb_ins_code
;
int
pdb_seq_num
;
int
pdb_seq_num
;
cif
::
tie
(
pdb_strand_id
,
pdb_seq_num
,
pdb_ins_code
)
=
cif
::
tie
(
pdb_strand_id
,
pdb_seq_num
,
pdb_ins_code
)
=
r
.
get
(
"pdb_strand_id"
,
"pdb_seq_num"
,
"pdb_ins_code"
);
r
.
get
(
"pdb_strand_id"
,
"pdb_seq_num"
,
"pdb_ins_code"
);
result
=
make_tuple
(
pdb_strand_id
.
front
(),
pdb_seq_num
,
result
=
std
::
make_tuple
(
pdb_strand_id
.
front
(),
pdb_seq_num
,
pdb_ins_code
.
empty
()
?
' '
:
pdb_ins_code
.
front
());
pdb_ins_code
.
empty
()
?
' '
:
pdb_ins_code
.
front
());
found
=
true
;
found
=
true
;
...
@@ -1885,13 +1877,13 @@ tuple<char,int,char> Structure::MapLabelToAuth(
...
@@ -1885,13 +1877,13 @@ tuple<char,int,char> Structure::MapLabelToAuth(
return
result
;
return
result
;
}
}
tuple
<
string
,
int
,
string
,
string
>
Structure
::
MapLabelToPDB
(
std
::
tuple
<
std
::
string
,
int
,
std
::
string
,
std
::
string
>
Structure
::
MapLabelToPDB
(
const
st
ring
&
asymID
,
int
seqID
,
const
string
&
monID
,
const
st
d
::
string
&
asymID
,
int
seqID
,
const
std
::
string
&
monID
,
const
string
&
authSeqID
)
const
const
st
d
::
st
ring
&
authSeqID
)
const
{
{
auto
&
db
=
datablock
();
auto
&
db
=
datablock
();
tuple
<
string
,
int
,
string
,
string
>
result
;
std
::
tuple
<
std
::
string
,
int
,
std
::
string
,
std
::
string
>
result
;
if
(
monID
==
"HOH"
)
if
(
monID
==
"HOH"
)
{
{
...
@@ -1927,12 +1919,12 @@ tuple<string,int,string,string> Structure::MapLabelToPDB(
...
@@ -1927,12 +1919,12 @@ tuple<string,int,string,string> Structure::MapLabelToPDB(
return
result
;
return
result
;
}
}
tuple
<
string
,
int
,
string
>
Structure
::
MapPDBToLabel
(
const
string
&
asymID
,
int
seqID
,
std
::
tuple
<
std
::
string
,
int
,
std
::
string
>
Structure
::
MapPDBToLabel
(
const
std
::
string
&
asymID
,
int
seqID
,
const
st
ring
&
compID
,
const
string
&
iCode
)
const
const
st
d
::
string
&
compID
,
const
std
::
string
&
iCode
)
const
{
{
auto
&
db
=
datablock
();
auto
&
db
=
datablock
();
tuple
<
string
,
int
,
string
>
result
;
std
::
tuple
<
std
::
string
,
int
,
std
::
string
>
result
;
if
(
iCode
.
empty
())
if
(
iCode
.
empty
())
{
{
...
@@ -1988,11 +1980,11 @@ cif::Datablock& Structure::datablock() const
...
@@ -1988,11 +1980,11 @@ cif::Datablock& Structure::datablock() const
return
*
mFile
.
impl
().
mDb
;
return
*
mFile
.
impl
().
mDb
;
}
}
void
Structure
::
insertCompound
(
const
string
&
compoundID
,
bool
isEntity
)
void
Structure
::
insertCompound
(
const
st
d
::
st
ring
&
compoundID
,
bool
isEntity
)
{
{
auto
compound
=
Compound
::
create
(
compoundID
);
auto
compound
=
Compound
::
create
(
compoundID
);
if
(
compound
==
nullptr
)
if
(
compound
==
nullptr
)
throw
runtime_error
(
"Trying to insert unknown compound "
+
compoundID
+
" (not found in CCP4 monomers lib)"
);
throw
std
::
runtime_error
(
"Trying to insert unknown compound "
+
compoundID
+
" (not found in CCP4 monomers lib)"
);
cif
::
Datablock
&
db
=
*
mFile
.
impl
().
mDb
;
cif
::
Datablock
&
db
=
*
mFile
.
impl
().
mDb
;
...
@@ -2014,7 +2006,7 @@ void Structure::insertCompound(const string& compoundID, bool isEntity)
...
@@ -2014,7 +2006,7 @@ void Structure::insertCompound(const string& compoundID, bool isEntity)
if
(
pdbxEntityNonpoly
.
find
(
cif
::
Key
(
"comp_id"
)
==
compoundID
).
empty
())
if
(
pdbxEntityNonpoly
.
find
(
cif
::
Key
(
"comp_id"
)
==
compoundID
).
empty
())
{
{
auto
&
entity
=
db
[
"entity"
];
auto
&
entity
=
db
[
"entity"
];
st
ring
entityID
=
to_string
(
entity
.
size
()
+
1
);
st
d
::
string
entityID
=
std
::
to_string
(
entity
.
size
()
+
1
);
entity
.
emplace
({
entity
.
emplace
({
{
"id"
,
entityID
},
{
"id"
,
entityID
},
...
@@ -2101,7 +2093,7 @@ void Structure::removeAtom(Atom& a)
...
@@ -2101,7 +2093,7 @@ void Structure::removeAtom(Atom& a)
for
(
auto
i
=
atomSites
.
begin
();
i
!=
atomSites
.
end
();
++
i
)
for
(
auto
i
=
atomSites
.
begin
();
i
!=
atomSites
.
end
();
++
i
)
{
{
string
id
;
st
d
::
st
ring
id
;
cif
::
tie
(
id
)
=
i
->
get
(
"id"
);
cif
::
tie
(
id
)
=
i
->
get
(
"id"
);
if
(
id
==
a
.
id
())
if
(
id
==
a
.
id
())
...
@@ -2125,10 +2117,10 @@ void Structure::swapAtoms(Atom& a1, Atom& a2)
...
@@ -2125,10 +2117,10 @@ void Structure::swapAtoms(Atom& a1, Atom& a2)
auto
rs2
=
atomSites
.
find
(
cif
::
Key
(
"id"
)
==
a2
.
id
());
auto
rs2
=
atomSites
.
find
(
cif
::
Key
(
"id"
)
==
a2
.
id
());
if
(
rs1
.
size
()
!=
1
)
if
(
rs1
.
size
()
!=
1
)
throw
runtime_error
(
"Cannot swap atoms since the number of atoms with id "
+
a1
.
id
()
+
" is "
+
to_string
(
rs1
.
size
()));
throw
std
::
runtime_error
(
"Cannot swap atoms since the number of atoms with id "
+
a1
.
id
()
+
" is "
+
std
::
to_string
(
rs1
.
size
()));
if
(
rs2
.
size
()
!=
1
)
if
(
rs2
.
size
()
!=
1
)
throw
runtime_error
(
"Cannot swap atoms since the number of atoms with id "
+
a2
.
id
()
+
" is "
+
to_string
(
rs2
.
size
()));
throw
std
::
runtime_error
(
"Cannot swap atoms since the number of atoms with id "
+
a2
.
id
()
+
" is "
+
std
::
to_string
(
rs2
.
size
()));
auto
r1
=
rs1
.
front
();
auto
r1
=
rs1
.
front
();
auto
r2
=
rs2
.
front
();
auto
r2
=
rs2
.
front
();
...
@@ -2149,12 +2141,12 @@ void Structure::moveAtom(Atom& a, Point p)
...
@@ -2149,12 +2141,12 @@ void Structure::moveAtom(Atom& a, Point p)
a
.
location
(
p
);
a
.
location
(
p
);
}
}
void
Structure
::
changeResidue
(
const
Residue
&
res
,
const
string
&
newCompound
,
void
Structure
::
changeResidue
(
const
Residue
&
res
,
const
st
d
::
st
ring
&
newCompound
,
const
vector
<
tuple
<
string
,
string
>>&
remappedAtoms
)
const
std
::
vector
<
std
::
tuple
<
std
::
string
,
std
::
string
>>&
remappedAtoms
)
{
{
cif
::
Datablock
&
db
=
*
mFile
.
impl
().
mDb
;
cif
::
Datablock
&
db
=
*
mFile
.
impl
().
mDb
;
string
entityID
;
st
d
::
st
ring
entityID
;
// First make sure the compound is already known or insert it.
// First make sure the compound is already known or insert it.
// And if the residue is an entity, we must make sure it exists
// And if the residue is an entity, we must make sure it exists
...
@@ -2165,13 +2157,13 @@ void Structure::changeResidue(const Residue& res, const string& newCompound,
...
@@ -2165,13 +2157,13 @@ void Structure::changeResidue(const Residue& res, const string& newCompound,
for
(
auto
&
a
:
remappedAtoms
)
for
(
auto
&
a
:
remappedAtoms
)
{
{
string
a1
,
a2
;
st
d
::
st
ring
a1
,
a2
;
tie
(
a1
,
a2
)
=
a
;
tie
(
a1
,
a2
)
=
a
;
auto
i
=
find_if
(
atoms
.
begin
(),
atoms
.
end
(),
[
&
](
const
Atom
&
a
)
{
return
a
.
labelAtomID
()
==
a1
;
});
auto
i
=
find_if
(
atoms
.
begin
(),
atoms
.
end
(),
[
&
](
const
Atom
&
a
)
{
return
a
.
labelAtomID
()
==
a1
;
});
if
(
i
==
atoms
.
end
())
if
(
i
==
atoms
.
end
())
{
{
cerr
<<
"Missing atom for atom ID "
<<
a1
<<
endl
;
std
::
cerr
<<
"Missing atom for atom ID "
<<
a1
<<
std
::
endl
;
continue
;
continue
;
}
}
...
...
src/Symmetry.cpp
View file @
4b4757ee
...
@@ -32,8 +32,6 @@
...
@@ -32,8 +32,6 @@
#include "cif++/Symmetry.hpp"
#include "cif++/Symmetry.hpp"
#include "cif++/CifUtils.hpp"
#include "cif++/CifUtils.hpp"
using
namespace
std
;
namespace
mmcif
namespace
mmcif
{
{
...
@@ -51,7 +49,7 @@ int GetSpacegroupNumber(std::string spacegroup)
...
@@ -51,7 +49,7 @@ int GetSpacegroupNumber(std::string spacegroup)
if
(
spacegroup
==
"P 21 21 2 A"
)
if
(
spacegroup
==
"P 21 21 2 A"
)
spacegroup
=
"P 21 21 2 (a)"
;
spacegroup
=
"P 21 21 2 (a)"
;
else
if
(
spacegroup
.
empty
())
else
if
(
spacegroup
.
empty
())
throw
runtime_error
(
"No spacegroup, cannot continue"
);
throw
std
::
runtime_error
(
"No spacegroup, cannot continue"
);
int
result
=
0
;
int
result
=
0
;
...
@@ -88,7 +86,7 @@ int GetSpacegroupNumber(std::string spacegroup)
...
@@ -88,7 +86,7 @@ int GetSpacegroupNumber(std::string spacegroup)
}
}
if
(
result
==
0
)
if
(
result
==
0
)
throw
runtime_error
(
"Spacegroup name "
+
spacegroup
+
" was not found in table"
);
throw
std
::
runtime_error
(
"Spacegroup name "
+
spacegroup
+
" was not found in table"
);
return
result
;
return
result
;
}
}
...
...
src/TlsParser.cpp
View file @
4b4757ee
...
@@ -26,32 +26,18 @@
...
@@ -26,32 +26,18 @@
#include "cif++/Config.hpp"
#include "cif++/Config.hpp"
#include <termios.h>
#include <sys/ioctl.h>
#include <iostream>
#include <iomanip>
#include <boost/program_options.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string.hpp>
#include "cif++/CifUtils.hpp"
#include "cif++/Structure.hpp"
#include "cif++/TlsParser.hpp"
#include "cif++/TlsParser.hpp"
using
namespace
std
;
namespace
po
=
boost
::
program_options
;
namespace
ba
=
boost
::
algorithm
;
namespace
ba
=
boost
::
algorithm
;
namespace
c
=
mmcif
;
namespace
cif
namespace
cif
{
{
const
int
const
int
kResidueNrWildcard
=
numeric_limits
<
int
>::
min
(),
kResidueNrWildcard
=
std
::
numeric_limits
<
int
>::
min
(),
kNoSeqNum
=
numeric_limits
<
int
>::
max
()
-
1
;
kNoSeqNum
=
std
::
numeric_limits
<
int
>::
max
()
-
1
;
using
namespace
std
;
// --------------------------------------------------------------------
// --------------------------------------------------------------------
// We parse selection statements and create a selection expression tree
// We parse selection statements and create a selection expression tree
...
@@ -60,14 +46,14 @@ using namespace std;
...
@@ -60,14 +46,14 @@ using namespace std;
struct
TLSResidue
struct
TLSResidue
{
{
string
chainID
;
st
d
::
st
ring
chainID
;
int
seqNr
;
int
seqNr
;
char
iCode
;
char
iCode
;
string
name
;
st
d
::
st
ring
name
;
bool
selected
;
bool
selected
;
string
asymID
;
st
d
::
st
ring
asymID
;
int
seqID
;
int
seqID
;
bool
operator
==
(
const
TLSResidue
&
rhs
)
const
bool
operator
==
(
const
TLSResidue
&
rhs
)
const
{
{
...
@@ -79,9 +65,9 @@ struct TLSResidue
...
@@ -79,9 +65,9 @@ struct TLSResidue
}
}
};
};
void
DumpSelection
(
const
vector
<
TLSResidue
>&
selected
,
int
indentLevel
)
void
DumpSelection
(
const
std
::
vector
<
TLSResidue
>&
selected
,
int
indentLevel
)
{
{
string
indent
(
indentLevel
*
2
,
' '
);
st
d
::
st
ring
indent
(
indentLevel
*
2
,
' '
);
auto
i
=
selected
.
begin
();
auto
i
=
selected
.
begin
();
bool
first
=
true
;
bool
first
=
true
;
...
@@ -89,35 +75,35 @@ void DumpSelection(const vector<TLSResidue>& selected, int indentLevel)
...
@@ -89,35 +75,35 @@ void DumpSelection(const vector<TLSResidue>& selected, int indentLevel)
// First print in PDB space
// First print in PDB space
while
(
i
!=
selected
.
end
())
while
(
i
!=
selected
.
end
())
{
{
auto
b
=
find_if
(
i
,
selected
.
end
(),
[](
auto
s
)
->
bool
{
return
s
.
selected
;
});
auto
b
=
std
::
find_if
(
i
,
selected
.
end
(),
[](
auto
s
)
->
bool
{
return
s
.
selected
;
});
if
(
b
==
selected
.
end
())
if
(
b
==
selected
.
end
())
break
;
break
;
if
(
first
)
if
(
first
)
cout
<<
indent
<<
"PDB:"
<<
endl
;
std
::
cout
<<
indent
<<
"PDB:"
<<
std
::
endl
;
first
=
false
;
first
=
false
;
auto
e
=
find_if
(
b
,
selected
.
end
(),
[
b
](
auto
s
)
->
bool
{
return
s
.
chainID
!=
b
->
chainID
or
not
s
.
selected
;
});
auto
e
=
std
::
find_if
(
b
,
selected
.
end
(),
[
b
](
auto
s
)
->
bool
{
return
s
.
chainID
!=
b
->
chainID
or
not
s
.
selected
;
});
cout
<<
indent
<<
" >> "
<<
b
->
chainID
<<
' '
<<
b
->
seqNr
<<
':'
<<
(
e
-
1
)
->
seqNr
<<
endl
;
std
::
cout
<<
indent
<<
" >> "
<<
b
->
chainID
<<
' '
<<
b
->
seqNr
<<
':'
<<
(
e
-
1
)
->
seqNr
<<
std
::
endl
;
i
=
e
;
i
=
e
;
}
}
// Then in mmCIF space
// Then in mmCIF space
if
(
not
first
)
if
(
not
first
)
cout
<<
indent
<<
"mmCIF:"
<<
endl
;
std
::
cout
<<
indent
<<
"mmCIF:"
<<
std
::
endl
;
i
=
selected
.
begin
();
i
=
selected
.
begin
();
while
(
i
!=
selected
.
end
())
while
(
i
!=
selected
.
end
())
{
{
auto
b
=
find_if
(
i
,
selected
.
end
(),
[](
auto
s
)
->
bool
{
return
s
.
selected
;
});
auto
b
=
std
::
find_if
(
i
,
selected
.
end
(),
[](
auto
s
)
->
bool
{
return
s
.
selected
;
});
if
(
b
==
selected
.
end
())
if
(
b
==
selected
.
end
())
break
;
break
;
auto
e
=
find_if
(
b
,
selected
.
end
(),
[
b
](
auto
s
)
->
bool
{
return
s
.
asymID
!=
b
->
asymID
or
not
s
.
selected
;
});
auto
e
=
std
::
find_if
(
b
,
selected
.
end
(),
[
b
](
auto
s
)
->
bool
{
return
s
.
asymID
!=
b
->
asymID
or
not
s
.
selected
;
});
string
asymID
=
b
->
asymID
;
st
d
::
st
ring
asymID
=
b
->
asymID
;
int
from
=
b
->
seqID
,
to
=
from
;
int
from
=
b
->
seqID
,
to
=
from
;
for
(
auto
j
=
b
+
1
;
j
!=
e
;
++
j
)
for
(
auto
j
=
b
+
1
;
j
!=
e
;
++
j
)
...
@@ -127,18 +113,18 @@ void DumpSelection(const vector<TLSResidue>& selected, int indentLevel)
...
@@ -127,18 +113,18 @@ void DumpSelection(const vector<TLSResidue>& selected, int indentLevel)
else
if
(
j
->
seqID
!=
to
)
// probably an insertion code
else
if
(
j
->
seqID
!=
to
)
// probably an insertion code
{
{
if
(
from
==
kNoSeqNum
or
to
==
kNoSeqNum
)
if
(
from
==
kNoSeqNum
or
to
==
kNoSeqNum
)
cout
<<
indent
<<
" >> "
<<
asymID
<<
endl
;
std
::
cout
<<
indent
<<
" >> "
<<
asymID
<<
std
::
endl
;
else
else
cout
<<
indent
<<
" >> "
<<
asymID
<<
' '
<<
from
<<
':'
<<
to
<<
endl
;
std
::
cout
<<
indent
<<
" >> "
<<
asymID
<<
' '
<<
from
<<
':'
<<
to
<<
std
::
endl
;
asymID
=
b
->
asymID
;
asymID
=
b
->
asymID
;
from
=
to
=
b
->
seqID
;
from
=
to
=
b
->
seqID
;
}
}
}
}
if
(
from
==
kNoSeqNum
or
to
==
kNoSeqNum
)
if
(
from
==
kNoSeqNum
or
to
==
kNoSeqNum
)
cout
<<
indent
<<
" >> "
<<
asymID
<<
endl
;
std
::
cout
<<
indent
<<
" >> "
<<
asymID
<<
std
::
endl
;
else
else
cout
<<
indent
<<
" >> "
<<
asymID
<<
' '
<<
from
<<
':'
<<
to
<<
endl
;
std
::
cout
<<
indent
<<
" >> "
<<
asymID
<<
' '
<<
from
<<
':'
<<
to
<<
std
::
endl
;
i
=
e
;
i
=
e
;
}
}
...
@@ -146,22 +132,22 @@ void DumpSelection(const vector<TLSResidue>& selected, int indentLevel)
...
@@ -146,22 +132,22 @@ void DumpSelection(const vector<TLSResidue>& selected, int indentLevel)
if
(
first
)
if
(
first
)
{
{
if
(
isatty
(
STDOUT_FILENO
))
if
(
isatty
(
STDOUT_FILENO
))
cout
<<
indent
<<
cif
::
coloured
(
"Empty selection"
)
<<
endl
;
std
::
cout
<<
indent
<<
cif
::
coloured
(
"Empty selection"
)
<<
std
::
endl
;
else
else
cout
<<
indent
<<
cif
::
coloured
(
"Empty selection"
)
<<
endl
;
std
::
cout
<<
indent
<<
cif
::
coloured
(
"Empty selection"
)
<<
std
::
endl
;
}
}
}
}
vector
<
tuple
<
string
,
int
,
int
>>
TLSSelection
::
GetRanges
(
Datablock
&
db
,
bool
pdbNamespace
)
const
std
::
vector
<
std
::
tuple
<
std
::
string
,
int
,
int
>>
TLSSelection
::
GetRanges
(
Datablock
&
db
,
bool
pdbNamespace
)
const
{
{
vector
<
TLSResidue
>
selected
;
std
::
vector
<
TLSResidue
>
selected
;
// Collect the residues from poly seq scheme...
// Collect the residues from poly seq scheme...
for
(
auto
r
:
db
[
"pdbx_poly_seq_scheme"
])
for
(
auto
r
:
db
[
"pdbx_poly_seq_scheme"
])
{
{
string
chain
,
seqNr
,
iCode
,
name
;
st
d
::
st
ring
chain
,
seqNr
,
iCode
,
name
;
string
asymID
;
st
d
::
st
ring
asymID
;
int
seqID
;
int
seqID
;
if
(
pdbNamespace
)
if
(
pdbNamespace
)
...
@@ -177,7 +163,7 @@ vector<tuple<string,int,int>> TLSSelection::GetRanges(Datablock& db, bool pdbNam
...
@@ -177,7 +163,7 @@ vector<tuple<string,int,int>> TLSSelection::GetRanges(Datablock& db, bool pdbNam
continue
;
continue
;
if
(
iCode
.
length
()
>
1
)
if
(
iCode
.
length
()
>
1
)
throw
runtime_error
(
"invalid iCode"
);
throw
std
::
runtime_error
(
"invalid iCode"
);
selected
.
push_back
({
chain
,
stoi
(
seqNr
),
iCode
[
0
],
name
,
false
,
asymID
,
seqID
});
selected
.
push_back
({
chain
,
stoi
(
seqNr
),
iCode
[
0
],
name
,
false
,
asymID
,
seqID
});
}
}
...
@@ -185,7 +171,7 @@ vector<tuple<string,int,int>> TLSSelection::GetRanges(Datablock& db, bool pdbNam
...
@@ -185,7 +171,7 @@ vector<tuple<string,int,int>> TLSSelection::GetRanges(Datablock& db, bool pdbNam
// ... those from the nonpoly scheme
// ... those from the nonpoly scheme
for
(
auto
r
:
db
[
"pdbx_nonpoly_scheme"
])
for
(
auto
r
:
db
[
"pdbx_nonpoly_scheme"
])
{
{
string
chain
,
seqNr
,
iCode
,
name
,
asymID
;
st
d
::
st
ring
chain
,
seqNr
,
iCode
,
name
,
asymID
;
if
(
pdbNamespace
)
if
(
pdbNamespace
)
{
{
...
@@ -204,7 +190,7 @@ vector<tuple<string,int,int>> TLSSelection::GetRanges(Datablock& db, bool pdbNam
...
@@ -204,7 +190,7 @@ vector<tuple<string,int,int>> TLSSelection::GetRanges(Datablock& db, bool pdbNam
continue
;
continue
;
if
(
iCode
.
length
()
>
1
)
if
(
iCode
.
length
()
>
1
)
throw
runtime_error
(
"invalid iCode"
);
throw
std
::
runtime_error
(
"invalid iCode"
);
selected
.
push_back
({
chain
,
stoi
(
seqNr
),
iCode
[
0
],
name
,
false
,
asymID
,
kNoSeqNum
});
selected
.
push_back
({
chain
,
stoi
(
seqNr
),
iCode
[
0
],
name
,
false
,
asymID
,
kNoSeqNum
});
}
}
...
@@ -222,17 +208,17 @@ vector<tuple<string,int,int>> TLSSelection::GetRanges(Datablock& db, bool pdbNam
...
@@ -222,17 +208,17 @@ vector<tuple<string,int,int>> TLSSelection::GetRanges(Datablock& db, bool pdbNam
CollectResidues
(
db
,
selected
);
CollectResidues
(
db
,
selected
);
vector
<
tuple
<
string
,
int
,
int
>>
result
;
std
::
vector
<
std
::
tuple
<
std
::
string
,
int
,
int
>>
result
;
auto
i
=
selected
.
begin
();
auto
i
=
selected
.
begin
();
while
(
i
!=
selected
.
end
())
while
(
i
!=
selected
.
end
())
{
{
auto
b
=
find_if
(
i
,
selected
.
end
(),
[](
auto
s
)
->
bool
{
return
s
.
selected
;
});
auto
b
=
std
::
find_if
(
i
,
selected
.
end
(),
[](
auto
s
)
->
bool
{
return
s
.
selected
;
});
if
(
b
==
selected
.
end
())
if
(
b
==
selected
.
end
())
break
;
break
;
auto
e
=
find_if
(
b
,
selected
.
end
(),
[
b
](
auto
s
)
->
bool
{
return
s
.
asymID
!=
b
->
asymID
or
not
s
.
selected
;
});
auto
e
=
std
::
find_if
(
b
,
selected
.
end
(),
[
b
](
auto
s
)
->
bool
{
return
s
.
asymID
!=
b
->
asymID
or
not
s
.
selected
;
});
// return ranges with strict increasing sequence numbers.
// return ranges with strict increasing sequence numbers.
// So when there's a gap in the sequence we split the range.
// So when there's a gap in the sequence we split the range.
...
@@ -240,9 +226,9 @@ vector<tuple<string,int,int>> TLSSelection::GetRanges(Datablock& db, bool pdbNam
...
@@ -240,9 +226,9 @@ vector<tuple<string,int,int>> TLSSelection::GetRanges(Datablock& db, bool pdbNam
result
.
push_back
(
make_tuple
(
b
->
asymID
,
b
->
seqID
,
b
->
seqID
));
result
.
push_back
(
make_tuple
(
b
->
asymID
,
b
->
seqID
,
b
->
seqID
));
for
(
auto
j
=
b
+
1
;
j
!=
e
;
++
j
)
for
(
auto
j
=
b
+
1
;
j
!=
e
;
++
j
)
{
{
if
(
j
->
seqID
==
get
<
2
>
(
result
.
back
())
+
1
)
if
(
j
->
seqID
==
std
::
get
<
2
>
(
result
.
back
())
+
1
)
get
<
2
>
(
result
.
back
())
=
j
->
seqID
;
std
::
get
<
2
>
(
result
.
back
())
=
j
->
seqID
;
else
if
(
j
->
seqID
!=
get
<
2
>
(
result
.
back
()))
// probably an insertion code
else
if
(
j
->
seqID
!=
std
::
get
<
2
>
(
result
.
back
()))
// probably an insertion code
result
.
push_back
(
make_tuple
(
b
->
asymID
,
j
->
seqID
,
j
->
seqID
));
result
.
push_back
(
make_tuple
(
b
->
asymID
,
j
->
seqID
,
j
->
seqID
));
}
}
...
@@ -257,7 +243,7 @@ struct TLSSelectionNot : public TLSSelection
...
@@ -257,7 +243,7 @@ struct TLSSelectionNot : public TLSSelection
TLSSelectionNot
(
TLSSelectionPtr
selection
)
TLSSelectionNot
(
TLSSelectionPtr
selection
)
:
selection
(
selection
.
release
())
{}
:
selection
(
selection
.
release
())
{}
virtual
void
CollectResidues
(
Datablock
&
db
,
vector
<
TLSResidue
>&
residues
,
int
indentLevel
)
const
virtual
void
CollectResidues
(
Datablock
&
db
,
std
::
vector
<
TLSResidue
>&
residues
,
int
indentLevel
)
const
{
{
selection
->
CollectResidues
(
db
,
residues
,
indentLevel
+
1
);
selection
->
CollectResidues
(
db
,
residues
,
indentLevel
+
1
);
...
@@ -266,7 +252,7 @@ struct TLSSelectionNot : public TLSSelection
...
@@ -266,7 +252,7 @@ struct TLSSelectionNot : public TLSSelection
if
(
cif
::
VERBOSE
)
if
(
cif
::
VERBOSE
)
{
{
cout
<<
string
(
indentLevel
*
2
,
' '
)
<<
"NOT"
<<
endl
;
std
::
cout
<<
std
::
string
(
indentLevel
*
2
,
' '
)
<<
"NOT"
<<
std
::
endl
;
DumpSelection
(
residues
,
indentLevel
);
DumpSelection
(
residues
,
indentLevel
);
}
}
}
}
...
@@ -278,14 +264,14 @@ struct TLSSelectionAll : public TLSSelection
...
@@ -278,14 +264,14 @@ struct TLSSelectionAll : public TLSSelection
{
{
TLSSelectionAll
()
{}
TLSSelectionAll
()
{}
virtual
void
CollectResidues
(
Datablock
&
db
,
vector
<
TLSResidue
>&
residues
,
int
indentLevel
)
const
virtual
void
CollectResidues
(
Datablock
&
db
,
std
::
vector
<
TLSResidue
>&
residues
,
int
indentLevel
)
const
{
{
for
(
auto
&
r
:
residues
)
for
(
auto
&
r
:
residues
)
r
.
selected
=
true
;
r
.
selected
=
true
;
if
(
cif
::
VERBOSE
)
if
(
cif
::
VERBOSE
)
{
{
cout
<<
string
(
indentLevel
*
2
,
' '
)
<<
"ALL"
<<
endl
;
std
::
cout
<<
std
::
string
(
indentLevel
*
2
,
' '
)
<<
"ALL"
<<
std
::
endl
;
DumpSelection
(
residues
,
indentLevel
);
DumpSelection
(
residues
,
indentLevel
);
}
}
}
}
...
@@ -293,10 +279,10 @@ struct TLSSelectionAll : public TLSSelection
...
@@ -293,10 +279,10 @@ struct TLSSelectionAll : public TLSSelection
struct
TLSSelectionChain
:
public
TLSSelectionAll
struct
TLSSelectionChain
:
public
TLSSelectionAll
{
{
TLSSelectionChain
(
const
string
&
chainID
)
TLSSelectionChain
(
const
st
d
::
st
ring
&
chainID
)
:
m_chain
(
chainID
)
{}
:
m_chain
(
chainID
)
{}
virtual
void
CollectResidues
(
Datablock
&
db
,
vector
<
TLSResidue
>&
residues
,
int
indentLevel
)
const
virtual
void
CollectResidues
(
Datablock
&
db
,
std
::
vector
<
TLSResidue
>&
residues
,
int
indentLevel
)
const
{
{
bool
allChains
=
m_chain
==
"*"
;
bool
allChains
=
m_chain
==
"*"
;
...
@@ -305,12 +291,12 @@ struct TLSSelectionChain : public TLSSelectionAll
...
@@ -305,12 +291,12 @@ struct TLSSelectionChain : public TLSSelectionAll
if
(
cif
::
VERBOSE
)
if
(
cif
::
VERBOSE
)
{
{
cout
<<
string
(
indentLevel
*
2
,
' '
)
<<
"CHAIN "
<<
m_chain
<<
endl
;
std
::
cout
<<
std
::
string
(
indentLevel
*
2
,
' '
)
<<
"CHAIN "
<<
m_chain
<<
std
::
endl
;
DumpSelection
(
residues
,
indentLevel
);
DumpSelection
(
residues
,
indentLevel
);
}
}
}
}
string
m_chain
;
st
d
::
st
ring
m_chain
;
};
};
struct
TLSSelectionResID
:
public
TLSSelectionAll
struct
TLSSelectionResID
:
public
TLSSelectionAll
...
@@ -318,14 +304,14 @@ struct TLSSelectionResID : public TLSSelectionAll
...
@@ -318,14 +304,14 @@ struct TLSSelectionResID : public TLSSelectionAll
TLSSelectionResID
(
int
seqNr
,
char
iCode
)
TLSSelectionResID
(
int
seqNr
,
char
iCode
)
:
m_seq_nr
(
seqNr
),
m_icode
(
iCode
)
{}
:
m_seq_nr
(
seqNr
),
m_icode
(
iCode
)
{}
virtual
void
CollectResidues
(
Datablock
&
db
,
vector
<
TLSResidue
>&
residues
,
int
indentLevel
)
const
virtual
void
CollectResidues
(
Datablock
&
db
,
std
::
vector
<
TLSResidue
>&
residues
,
int
indentLevel
)
const
{
{
for
(
auto
&
r
:
residues
)
for
(
auto
&
r
:
residues
)
r
.
selected
=
r
.
seqNr
==
m_seq_nr
and
r
.
iCode
==
m_icode
;
r
.
selected
=
r
.
seqNr
==
m_seq_nr
and
r
.
iCode
==
m_icode
;
if
(
cif
::
VERBOSE
)
if
(
cif
::
VERBOSE
)
{
{
cout
<<
string
(
indentLevel
*
2
,
' '
)
<<
"ResID "
<<
m_seq_nr
<<
(
m_icode
?
string
{
m_icode
}
:
""
)
<<
endl
;
std
::
cout
<<
std
::
string
(
indentLevel
*
2
,
' '
)
<<
"ResID "
<<
m_seq_nr
<<
(
m_icode
?
std
::
string
{
m_icode
}
:
""
)
<<
std
::
endl
;
DumpSelection
(
residues
,
indentLevel
);
DumpSelection
(
residues
,
indentLevel
);
}
}
}
}
...
@@ -339,7 +325,7 @@ struct TLSSelectionRangeSeq : public TLSSelectionAll
...
@@ -339,7 +325,7 @@ struct TLSSelectionRangeSeq : public TLSSelectionAll
TLSSelectionRangeSeq
(
int
first
,
int
last
)
TLSSelectionRangeSeq
(
int
first
,
int
last
)
:
m_first
(
first
),
m_last
(
last
)
{}
:
m_first
(
first
),
m_last
(
last
)
{}
virtual
void
CollectResidues
(
Datablock
&
db
,
vector
<
TLSResidue
>&
residues
,
int
indentLevel
)
const
virtual
void
CollectResidues
(
Datablock
&
db
,
std
::
vector
<
TLSResidue
>&
residues
,
int
indentLevel
)
const
{
{
for
(
auto
&
r
:
residues
)
for
(
auto
&
r
:
residues
)
{
{
...
@@ -349,7 +335,7 @@ struct TLSSelectionRangeSeq : public TLSSelectionAll
...
@@ -349,7 +335,7 @@ struct TLSSelectionRangeSeq : public TLSSelectionAll
if
(
cif
::
VERBOSE
)
if
(
cif
::
VERBOSE
)
{
{
cout
<<
string
(
indentLevel
*
2
,
' '
)
<<
"Range "
<<
m_first
<<
':'
<<
m_last
<<
endl
;
std
::
cout
<<
std
::
string
(
indentLevel
*
2
,
' '
)
<<
"Range "
<<
m_first
<<
':'
<<
m_last
<<
std
::
endl
;
DumpSelection
(
residues
,
indentLevel
);
DumpSelection
(
residues
,
indentLevel
);
}
}
}
}
...
@@ -362,21 +348,21 @@ struct TLSSelectionRangeID : public TLSSelectionAll
...
@@ -362,21 +348,21 @@ struct TLSSelectionRangeID : public TLSSelectionAll
TLSSelectionRangeID
(
int
first
,
int
last
,
char
icodeFirst
=
0
,
char
icodeLast
=
0
)
TLSSelectionRangeID
(
int
first
,
int
last
,
char
icodeFirst
=
0
,
char
icodeLast
=
0
)
:
m_first
(
first
),
m_last
(
last
),
m_icode_first
(
icodeFirst
),
m_icode_last
(
icodeLast
)
{}
:
m_first
(
first
),
m_last
(
last
),
m_icode_first
(
icodeFirst
),
m_icode_last
(
icodeLast
)
{}
virtual
void
CollectResidues
(
Datablock
&
db
,
vector
<
TLSResidue
>&
residues
,
int
indentLevel
)
const
virtual
void
CollectResidues
(
Datablock
&
db
,
std
::
vector
<
TLSResidue
>&
residues
,
int
indentLevel
)
const
{
{
// need to do this per chain
// need to do this per chain
s
et
<
string
>
chains
;
s
td
::
set
<
std
::
string
>
chains
;
for
(
auto
&
r
:
residues
)
for
(
auto
&
r
:
residues
)
chains
.
insert
(
r
.
chainID
);
chains
.
insert
(
r
.
chainID
);
for
(
string
chain
:
chains
)
for
(
st
d
::
st
ring
chain
:
chains
)
{
{
auto
f
=
find_if
(
residues
.
begin
(),
residues
.
end
(),
auto
f
=
std
::
find_if
(
residues
.
begin
(),
residues
.
end
(),
[
=
](
auto
r
)
->
bool
{
[
=
](
auto
r
)
->
bool
{
return
r
.
chainID
==
chain
and
r
.
seqNr
==
m_first
and
r
.
iCode
==
m_icode_first
;
return
r
.
chainID
==
chain
and
r
.
seqNr
==
m_first
and
r
.
iCode
==
m_icode_first
;
});
});
auto
l
=
find_if
(
residues
.
begin
(),
residues
.
end
(),
auto
l
=
std
::
find_if
(
residues
.
begin
(),
residues
.
end
(),
[
=
](
auto
r
)
->
bool
{
[
=
](
auto
r
)
->
bool
{
return
r
.
chainID
==
chain
and
r
.
seqNr
==
m_last
and
r
.
iCode
==
m_icode_last
;
return
r
.
chainID
==
chain
and
r
.
seqNr
==
m_last
and
r
.
iCode
==
m_icode_last
;
});
});
...
@@ -392,7 +378,7 @@ struct TLSSelectionRangeID : public TLSSelectionAll
...
@@ -392,7 +378,7 @@ struct TLSSelectionRangeID : public TLSSelectionAll
if
(
cif
::
VERBOSE
)
if
(
cif
::
VERBOSE
)
{
{
cout
<<
string
(
indentLevel
*
2
,
' '
)
<<
"Through "
<<
m_first
<<
':'
<<
m_last
<<
endl
;
std
::
cout
<<
std
::
string
(
indentLevel
*
2
,
' '
)
<<
"Through "
<<
m_first
<<
':'
<<
m_last
<<
std
::
endl
;
DumpSelection
(
residues
,
indentLevel
);
DumpSelection
(
residues
,
indentLevel
);
}
}
}
}
...
@@ -409,7 +395,7 @@ struct TLSSelectionUnion : public TLSSelection
...
@@ -409,7 +395,7 @@ struct TLSSelectionUnion : public TLSSelection
TLSSelectionUnion
(
TLSSelectionPtr
&
lhs
,
TLSSelectionPtr
&&
rhs
)
TLSSelectionUnion
(
TLSSelectionPtr
&
lhs
,
TLSSelectionPtr
&&
rhs
)
:
lhs
(
lhs
.
release
()),
rhs
(
rhs
.
release
())
{}
:
lhs
(
lhs
.
release
()),
rhs
(
rhs
.
release
())
{}
virtual
void
CollectResidues
(
Datablock
&
db
,
vector
<
TLSResidue
>&
residues
,
int
indentLevel
)
const
virtual
void
CollectResidues
(
Datablock
&
db
,
std
::
vector
<
TLSResidue
>&
residues
,
int
indentLevel
)
const
{
{
auto
a
=
residues
;
auto
a
=
residues
;
for_each
(
a
.
begin
(),
a
.
end
(),
[](
auto
&
r
)
{
r
.
selected
=
false
;
});
for_each
(
a
.
begin
(),
a
.
end
(),
[](
auto
&
r
)
{
r
.
selected
=
false
;
});
...
@@ -425,7 +411,7 @@ struct TLSSelectionUnion : public TLSSelection
...
@@ -425,7 +411,7 @@ struct TLSSelectionUnion : public TLSSelection
if
(
cif
::
VERBOSE
)
if
(
cif
::
VERBOSE
)
{
{
cout
<<
string
(
indentLevel
*
2
,
' '
)
<<
"Union"
<<
endl
;
std
::
cout
<<
std
::
string
(
indentLevel
*
2
,
' '
)
<<
"Union"
<<
std
::
endl
;
DumpSelection
(
residues
,
indentLevel
);
DumpSelection
(
residues
,
indentLevel
);
}
}
}
}
...
@@ -442,7 +428,7 @@ struct TLSSelectionIntersection : public TLSSelection
...
@@ -442,7 +428,7 @@ struct TLSSelectionIntersection : public TLSSelection
TLSSelectionIntersection
(
TLSSelectionPtr
&
lhs
,
TLSSelectionPtr
&&
rhs
)
TLSSelectionIntersection
(
TLSSelectionPtr
&
lhs
,
TLSSelectionPtr
&&
rhs
)
:
lhs
(
lhs
.
release
()),
rhs
(
rhs
.
release
())
{}
:
lhs
(
lhs
.
release
()),
rhs
(
rhs
.
release
())
{}
virtual
void
CollectResidues
(
Datablock
&
db
,
vector
<
TLSResidue
>&
residues
,
int
indentLevel
)
const
virtual
void
CollectResidues
(
Datablock
&
db
,
std
::
vector
<
TLSResidue
>&
residues
,
int
indentLevel
)
const
{
{
auto
a
=
residues
;
auto
a
=
residues
;
for_each
(
a
.
begin
(),
a
.
end
(),
[](
auto
&
r
)
{
r
.
selected
=
false
;
});
for_each
(
a
.
begin
(),
a
.
end
(),
[](
auto
&
r
)
{
r
.
selected
=
false
;
});
...
@@ -458,7 +444,7 @@ struct TLSSelectionIntersection : public TLSSelection
...
@@ -458,7 +444,7 @@ struct TLSSelectionIntersection : public TLSSelection
if
(
cif
::
VERBOSE
)
if
(
cif
::
VERBOSE
)
{
{
cout
<<
string
(
indentLevel
*
2
,
' '
)
<<
"Intersection"
<<
endl
;
std
::
cout
<<
std
::
string
(
indentLevel
*
2
,
' '
)
<<
"Intersection"
<<
std
::
endl
;
DumpSelection
(
residues
,
indentLevel
);
DumpSelection
(
residues
,
indentLevel
);
}
}
}
}
...
@@ -470,31 +456,31 @@ struct TLSSelectionIntersection : public TLSSelection
...
@@ -470,31 +456,31 @@ struct TLSSelectionIntersection : public TLSSelection
struct
TLSSelectionByName
:
public
TLSSelectionAll
struct
TLSSelectionByName
:
public
TLSSelectionAll
{
{
public
:
public
:
TLSSelectionByName
(
const
string
&
resname
)
TLSSelectionByName
(
const
st
d
::
st
ring
&
resname
)
:
m_name
(
resname
)
{}
:
m_name
(
resname
)
{}
virtual
void
CollectResidues
(
Datablock
&
db
,
vector
<
TLSResidue
>&
residues
,
int
indentLevel
)
const
virtual
void
CollectResidues
(
Datablock
&
db
,
std
::
vector
<
TLSResidue
>&
residues
,
int
indentLevel
)
const
{
{
for
(
auto
&
r
:
residues
)
for
(
auto
&
r
:
residues
)
r
.
selected
=
r
.
name
==
m_name
;
r
.
selected
=
r
.
name
==
m_name
;
if
(
cif
::
VERBOSE
)
if
(
cif
::
VERBOSE
)
{
{
cout
<<
string
(
indentLevel
*
2
,
' '
)
<<
"Name "
<<
m_name
<<
endl
;
std
::
cout
<<
std
::
string
(
indentLevel
*
2
,
' '
)
<<
"Name "
<<
m_name
<<
std
::
endl
;
DumpSelection
(
residues
,
indentLevel
);
DumpSelection
(
residues
,
indentLevel
);
}
}
}
}
string
m_name
;
st
d
::
st
ring
m_name
;
};
};
struct
TLSSelectionByElement
:
public
TLSSelectionAll
struct
TLSSelectionByElement
:
public
TLSSelectionAll
{
{
public
:
public
:
TLSSelectionByElement
(
const
string
&
element
)
TLSSelectionByElement
(
const
st
d
::
st
ring
&
element
)
:
m_element
(
element
)
{}
:
m_element
(
element
)
{}
virtual
void
CollectResidues
(
Datablock
&
db
,
vector
<
TLSResidue
>&
residues
,
int
indentLevel
)
const
virtual
void
CollectResidues
(
Datablock
&
db
,
std
::
vector
<
TLSResidue
>&
residues
,
int
indentLevel
)
const
{
{
// rationale... We want to select residues only. So we select
// rationale... We want to select residues only. So we select
// residues that have just a single atom of type m_element.
// residues that have just a single atom of type m_element.
...
@@ -506,12 +492,12 @@ struct TLSSelectionByElement : public TLSSelectionAll
...
@@ -506,12 +492,12 @@ struct TLSSelectionByElement : public TLSSelectionAll
if
(
cif
::
VERBOSE
)
if
(
cif
::
VERBOSE
)
{
{
cout
<<
string
(
indentLevel
*
2
,
' '
)
<<
"Element "
<<
m_element
<<
endl
;
std
::
cout
<<
std
::
string
(
indentLevel
*
2
,
' '
)
<<
"Element "
<<
m_element
<<
std
::
endl
;
DumpSelection
(
residues
,
indentLevel
);
DumpSelection
(
residues
,
indentLevel
);
}
}
}
}
string
m_element
;
st
d
::
st
ring
m_element
;
};
};
// --------------------------------------------------------------------
// --------------------------------------------------------------------
...
@@ -519,7 +505,7 @@ struct TLSSelectionByElement : public TLSSelectionAll
...
@@ -519,7 +505,7 @@ struct TLSSelectionByElement : public TLSSelectionAll
class
TLSSelectionParserImpl
class
TLSSelectionParserImpl
{
{
public
:
public
:
TLSSelectionParserImpl
(
const
string
&
selection
)
TLSSelectionParserImpl
(
const
st
d
::
st
ring
&
selection
)
:
m_selection
(
selection
),
m_p
(
m_selection
.
begin
()),
m_end
(
m_selection
.
end
())
{}
:
m_selection
(
selection
),
m_p
(
m_selection
.
begin
()),
m_end
(
m_selection
.
end
())
{}
virtual
TLSSelectionPtr
Parse
()
=
0
;
virtual
TLSSelectionPtr
Parse
()
=
0
;
...
@@ -528,12 +514,12 @@ class TLSSelectionParserImpl
...
@@ -528,12 +514,12 @@ class TLSSelectionParserImpl
virtual
int
GetNextToken
()
=
0
;
virtual
int
GetNextToken
()
=
0
;
virtual
void
Match
(
int
token
);
virtual
void
Match
(
int
token
);
virtual
string
ToString
(
int
token
)
=
0
;
virtual
st
d
::
st
ring
ToString
(
int
token
)
=
0
;
string
m_selection
;
st
d
::
st
ring
m_selection
;
string
::
iterator
m_p
,
m_end
;
st
d
::
st
ring
::
iterator
m_p
,
m_end
;
int
m_lookahead
;
int
m_lookahead
;
string
m_token
;
st
d
::
st
ring
m_token
;
};
};
...
@@ -543,19 +529,19 @@ void TLSSelectionParserImpl::Match(int token)
...
@@ -543,19 +529,19 @@ void TLSSelectionParserImpl::Match(int token)
m_lookahead
=
GetNextToken
();
m_lookahead
=
GetNextToken
();
else
else
{
{
string
expected
;
st
d
::
st
ring
expected
;
if
(
token
>=
256
)
if
(
token
>=
256
)
expected
=
ToString
(
token
);
expected
=
ToString
(
token
);
else
else
expected
=
{
char
(
token
)
};
expected
=
{
char
(
token
)
};
string
found
;
st
d
::
st
ring
found
;
if
(
m_lookahead
>=
256
)
if
(
m_lookahead
>=
256
)
found
=
ToString
(
m_lookahead
)
+
" ("
+
m_token
+
')'
;
found
=
ToString
(
m_lookahead
)
+
" ("
+
m_token
+
')'
;
else
else
found
=
{
char
(
m_lookahead
)
};
found
=
{
char
(
m_lookahead
)
};
throw
runtime_error
(
"Expected "
+
expected
+
" but found "
+
found
);
throw
std
::
runtime_error
(
"Expected "
+
expected
+
" but found "
+
found
);
}
}
}
}
...
@@ -564,7 +550,7 @@ void TLSSelectionParserImpl::Match(int token)
...
@@ -564,7 +550,7 @@ void TLSSelectionParserImpl::Match(int token)
class
TLSSelectionParserImplPhenix
:
public
TLSSelectionParserImpl
class
TLSSelectionParserImplPhenix
:
public
TLSSelectionParserImpl
{
{
public
:
public
:
TLSSelectionParserImplPhenix
(
const
string
&
selection
)
TLSSelectionParserImplPhenix
(
const
st
d
::
st
ring
&
selection
)
:
TLSSelectionParserImpl
(
selection
)
:
TLSSelectionParserImpl
(
selection
)
{
{
m_lookahead
=
GetNextToken
();
m_lookahead
=
GetNextToken
();
...
@@ -601,10 +587,10 @@ class TLSSelectionParserImplPhenix : public TLSSelectionParserImpl
...
@@ -601,10 +587,10 @@ class TLSSelectionParserImplPhenix : public TLSSelectionParserImpl
};
};
virtual
int
GetNextToken
();
virtual
int
GetNextToken
();
virtual
string
ToString
(
int
token
);
virtual
st
d
::
st
ring
ToString
(
int
token
);
int
m_value_i
;
int
m_value_i
;
string
m_value_s
;
st
d
::
st
ring
m_value_s
;
char
m_icode
;
char
m_icode
;
};
};
...
@@ -793,7 +779,7 @@ int TLSSelectionParserImplPhenix::GetNextToken()
...
@@ -793,7 +779,7 @@ int TLSSelectionParserImplPhenix::GetNextToken()
if
(
ch
==
'\''
)
if
(
ch
==
'\''
)
result
=
pt_STRING
;
result
=
pt_STRING
;
else
if
(
ch
==
0
)
else
if
(
ch
==
0
)
throw
runtime_error
(
"Unexpected end of selection, missing quote character?"
);
throw
std
::
runtime_error
(
"Unexpected end of selection, missing quote character?"
);
else
else
m_value_s
+=
ch
;
m_value_s
+=
ch
;
break
;
break
;
...
@@ -814,7 +800,7 @@ int TLSSelectionParserImplPhenix::GetNextToken()
...
@@ -814,7 +800,7 @@ int TLSSelectionParserImplPhenix::GetNextToken()
if
(
ch
==
'\"'
)
if
(
ch
==
'\"'
)
result
=
pt_STRING
;
result
=
pt_STRING
;
else
if
(
ch
==
0
)
else
if
(
ch
==
0
)
throw
runtime_error
(
"Unexpected end of selection, missing quote character?"
);
throw
std
::
runtime_error
(
"Unexpected end of selection, missing quote character?"
);
else
else
m_value_s
+=
ch
;
m_value_s
+=
ch
;
break
;
break
;
...
@@ -857,7 +843,7 @@ int TLSSelectionParserImplPhenix::GetNextToken()
...
@@ -857,7 +843,7 @@ int TLSSelectionParserImplPhenix::GetNextToken()
return
result
;
return
result
;
}
}
string
TLSSelectionParserImplPhenix
::
ToString
(
int
token
)
st
d
::
st
ring
TLSSelectionParserImplPhenix
::
ToString
(
int
token
)
{
{
switch
(
token
)
switch
(
token
)
{
{
...
@@ -891,7 +877,7 @@ TLSSelectionPtr TLSSelectionParserImplPhenix::Parse()
...
@@ -891,7 +877,7 @@ TLSSelectionPtr TLSSelectionParserImplPhenix::Parse()
Match
(
pt_KW_PDB
);
Match
(
pt_KW_PDB
);
// Match(pt_KW_ENTRY);
// Match(pt_KW_ENTRY);
throw
runtime_error
(
"Unimplemented PDB ENTRY specification"
);
throw
std
::
runtime_error
(
"Unimplemented PDB ENTRY specification"
);
}
}
TLSSelectionPtr
result
=
ParseAtomSelection
();
TLSSelectionPtr
result
=
ParseAtomSelection
();
...
@@ -907,7 +893,7 @@ TLSSelectionPtr TLSSelectionParserImplPhenix::Parse()
...
@@ -907,7 +893,7 @@ TLSSelectionPtr TLSSelectionParserImplPhenix::Parse()
Match
(
pt_EOLN
);
Match
(
pt_EOLN
);
if
(
extraParenthesis
)
if
(
extraParenthesis
)
cerr
<<
"WARNING: too many closing parenthesis in TLS selection statement"
<<
endl
;
std
::
cerr
<<
"WARNING: too many closing parenthesis in TLS selection statement"
<<
std
::
endl
;
return
result
;
return
result
;
}
}
...
@@ -948,7 +934,7 @@ TLSSelectionPtr TLSSelectionParserImplPhenix::ParseFactor()
...
@@ -948,7 +934,7 @@ TLSSelectionPtr TLSSelectionParserImplPhenix::ParseFactor()
Match
(
'('
);
Match
(
'('
);
result
=
ParseAtomSelection
();
result
=
ParseAtomSelection
();
if
(
m_lookahead
==
pt_EOLN
)
if
(
m_lookahead
==
pt_EOLN
)
cerr
<<
"WARNING: missing closing parenthesis in TLS selection statement"
<<
endl
;
std
::
cerr
<<
"WARNING: missing closing parenthesis in TLS selection statement"
<<
std
::
endl
;
else
else
Match
(
')'
);
Match
(
')'
);
break
;
break
;
...
@@ -962,10 +948,10 @@ TLSSelectionPtr TLSSelectionParserImplPhenix::ParseFactor()
...
@@ -962,10 +948,10 @@ TLSSelectionPtr TLSSelectionParserImplPhenix::ParseFactor()
{
{
Match
(
pt_KW_CHAIN
);
Match
(
pt_KW_CHAIN
);
string
chainID
=
m_value_s
;
st
d
::
st
ring
chainID
=
m_value_s
;
if
(
m_lookahead
==
pt_NUMBER
)
// sigh
if
(
m_lookahead
==
pt_NUMBER
)
// sigh
{
{
chainID
=
to_string
(
m_value_i
);
chainID
=
std
::
to_string
(
m_value_i
);
Match
(
pt_NUMBER
);
Match
(
pt_NUMBER
);
}
}
else
else
...
@@ -978,7 +964,7 @@ TLSSelectionPtr TLSSelectionParserImplPhenix::ParseFactor()
...
@@ -978,7 +964,7 @@ TLSSelectionPtr TLSSelectionParserImplPhenix::ParseFactor()
case
pt_KW_RESNAME
:
case
pt_KW_RESNAME
:
{
{
Match
(
pt_KW_RESNAME
);
Match
(
pt_KW_RESNAME
);
string
name
=
m_value_s
;
st
d
::
st
ring
name
=
m_value_s
;
Match
(
pt_IDENT
);
Match
(
pt_IDENT
);
result
.
reset
(
new
TLSSelectionByName
(
name
));
result
.
reset
(
new
TLSSelectionByName
(
name
));
break
;
break
;
...
@@ -987,7 +973,7 @@ TLSSelectionPtr TLSSelectionParserImplPhenix::ParseFactor()
...
@@ -987,7 +973,7 @@ TLSSelectionPtr TLSSelectionParserImplPhenix::ParseFactor()
case
pt_KW_ELEMENT
:
case
pt_KW_ELEMENT
:
{
{
Match
(
pt_KW_ELEMENT
);
Match
(
pt_KW_ELEMENT
);
string
element
=
m_value_s
;
st
d
::
st
ring
element
=
m_value_s
;
Match
(
pt_IDENT
);
Match
(
pt_IDENT
);
result
.
reset
(
new
TLSSelectionByElement
(
element
));
result
.
reset
(
new
TLSSelectionByElement
(
element
));
break
;
break
;
...
@@ -1050,7 +1036,7 @@ TLSSelectionPtr TLSSelectionParserImplPhenix::ParseFactor()
...
@@ -1050,7 +1036,7 @@ TLSSelectionPtr TLSSelectionParserImplPhenix::ParseFactor()
else
else
{
{
if
(
cif
::
VERBOSE
and
(
icode_from
or
icode_to
))
if
(
cif
::
VERBOSE
and
(
icode_from
or
icode_to
))
cerr
<<
"Warning, ignoring insertion codes"
<<
endl
;
std
::
cerr
<<
"Warning, ignoring insertion codes"
<<
std
::
endl
;
result
.
reset
(
new
TLSSelectionRangeSeq
(
from
,
to
));
result
.
reset
(
new
TLSSelectionRangeSeq
(
from
,
to
));
}
}
...
@@ -1067,7 +1053,7 @@ TLSSelectionPtr TLSSelectionParserImplPhenix::ParseFactor()
...
@@ -1067,7 +1053,7 @@ TLSSelectionPtr TLSSelectionParserImplPhenix::ParseFactor()
break
;
break
;
default
:
default
:
throw
runtime_error
(
"Unexpected token "
+
ToString
(
m_lookahead
)
+
" ("
+
m_token
+
')'
);
throw
std
::
runtime_error
(
"Unexpected token "
+
ToString
(
m_lookahead
)
+
" ("
+
m_token
+
')'
);
}
}
return
result
;
return
result
;
...
@@ -1078,7 +1064,7 @@ TLSSelectionPtr TLSSelectionParserImplPhenix::ParseFactor()
...
@@ -1078,7 +1064,7 @@ TLSSelectionPtr TLSSelectionParserImplPhenix::ParseFactor()
class
TLSSelectionParserImplBuster
:
public
TLSSelectionParserImpl
class
TLSSelectionParserImplBuster
:
public
TLSSelectionParserImpl
{
{
public
:
public
:
TLSSelectionParserImplBuster
(
const
string
&
selection
);
TLSSelectionParserImplBuster
(
const
st
d
::
st
ring
&
selection
);
virtual
TLSSelectionPtr
Parse
();
virtual
TLSSelectionPtr
Parse
();
...
@@ -1092,19 +1078,19 @@ class TLSSelectionParserImplBuster : public TLSSelectionParserImpl
...
@@ -1092,19 +1078,19 @@ class TLSSelectionParserImplBuster : public TLSSelectionParserImpl
};
};
virtual
int
GetNextToken
();
virtual
int
GetNextToken
();
virtual
string
ToString
(
int
token
);
virtual
st
d
::
st
ring
ToString
(
int
token
);
TLSSelectionPtr
ParseGroup
();
TLSSelectionPtr
ParseGroup
();
tuple
<
string
,
int
>
ParseAtom
();
std
::
tuple
<
std
::
string
,
int
>
ParseAtom
();
TLSSelectionPtr
ParseOldGroup
();
TLSSelectionPtr
ParseOldGroup
();
int
m_value_i
;
int
m_value_i
;
string
m_value_s
;
st
d
::
st
ring
m_value_s
;
bool
m_parsing_old_style
=
false
;
bool
m_parsing_old_style
=
false
;
};
};
TLSSelectionParserImplBuster
::
TLSSelectionParserImplBuster
(
const
string
&
selection
)
TLSSelectionParserImplBuster
::
TLSSelectionParserImplBuster
(
const
st
d
::
st
ring
&
selection
)
:
TLSSelectionParserImpl
(
selection
)
:
TLSSelectionParserImpl
(
selection
)
{
{
m_lookahead
=
GetNextToken
();
m_lookahead
=
GetNextToken
();
...
@@ -1192,12 +1178,12 @@ int TLSSelectionParserImplBuster::GetNextToken()
...
@@ -1192,12 +1178,12 @@ int TLSSelectionParserImplBuster::GetNextToken()
return
result
;
return
result
;
}
}
string
TLSSelectionParserImplBuster
::
ToString
(
int
token
)
st
d
::
st
ring
TLSSelectionParserImplBuster
::
ToString
(
int
token
)
{
{
switch
(
token
)
switch
(
token
)
{
{
case
bt_IDENT
:
return
"identifier ("
+
m_value_s
+
')'
;
case
bt_IDENT
:
return
"identifier ("
+
m_value_s
+
')'
;
case
bt_NUMBER
:
return
"number ("
+
to_string
(
m_value_i
)
+
')'
;
case
bt_NUMBER
:
return
"number ("
+
std
::
to_string
(
m_value_i
)
+
')'
;
case
bt_EOLN
:
return
"end of line"
;
case
bt_EOLN
:
return
"end of line"
;
default
:
default
:
...
@@ -1210,7 +1196,7 @@ TLSSelectionPtr TLSSelectionParserImplBuster::ParseGroup()
...
@@ -1210,7 +1196,7 @@ TLSSelectionPtr TLSSelectionParserImplBuster::ParseGroup()
{
{
TLSSelectionPtr
result
;
TLSSelectionPtr
result
;
auto
add
=
[
&
result
](
const
string
&
chainID
,
int
from
,
int
to
)
auto
add
=
[
&
result
](
const
st
d
::
st
ring
&
chainID
,
int
from
,
int
to
)
{
{
TLSSelectionPtr
sc
(
new
TLSSelectionChain
(
chainID
));
TLSSelectionPtr
sc
(
new
TLSSelectionChain
(
chainID
));
TLSSelectionPtr
sr
(
new
TLSSelectionRangeSeq
(
from
,
to
));
TLSSelectionPtr
sr
(
new
TLSSelectionRangeSeq
(
from
,
to
));
...
@@ -1226,13 +1212,13 @@ TLSSelectionPtr TLSSelectionParserImplBuster::ParseGroup()
...
@@ -1226,13 +1212,13 @@ TLSSelectionPtr TLSSelectionParserImplBuster::ParseGroup()
do
do
{
{
string
chain1
;
st
d
::
st
ring
chain1
;
int
seqNr1
;
int
seqNr1
;
std
::
tie
(
chain1
,
seqNr1
)
=
ParseAtom
();
std
::
tie
(
chain1
,
seqNr1
)
=
ParseAtom
();
if
(
m_lookahead
==
'-'
)
if
(
m_lookahead
==
'-'
)
{
{
string
chain2
;
st
d
::
st
ring
chain2
;
int
seqNr2
=
seqNr1
;
int
seqNr2
=
seqNr1
;
Match
(
'-'
);
Match
(
'-'
);
...
@@ -1247,7 +1233,7 @@ TLSSelectionPtr TLSSelectionParserImplBuster::ParseGroup()
...
@@ -1247,7 +1233,7 @@ TLSSelectionPtr TLSSelectionParserImplBuster::ParseGroup()
std
::
tie
(
chain2
,
seqNr2
)
=
ParseAtom
();
std
::
tie
(
chain2
,
seqNr2
)
=
ParseAtom
();
if
(
chain1
!=
chain2
)
if
(
chain1
!=
chain2
)
{
{
cerr
<<
"Warning, ranges over multiple chains detected"
<<
endl
;
std
::
cerr
<<
"Warning, ranges over multiple chains detected"
<<
std
::
endl
;
TLSSelectionPtr
sc1
(
new
TLSSelectionChain
(
chain1
));
TLSSelectionPtr
sc1
(
new
TLSSelectionChain
(
chain1
));
TLSSelectionPtr
sr1
(
new
TLSSelectionRangeSeq
(
seqNr1
,
kResidueNrWildcard
));
TLSSelectionPtr
sr1
(
new
TLSSelectionRangeSeq
(
seqNr1
,
kResidueNrWildcard
));
...
@@ -1281,9 +1267,9 @@ TLSSelectionPtr TLSSelectionParserImplBuster::ParseGroup()
...
@@ -1281,9 +1267,9 @@ TLSSelectionPtr TLSSelectionParserImplBuster::ParseGroup()
return
result
;
return
result
;
}
}
tuple
<
string
,
int
>
TLSSelectionParserImplBuster
::
ParseAtom
()
std
::
tuple
<
std
::
string
,
int
>
TLSSelectionParserImplBuster
::
ParseAtom
()
{
{
string
chain
=
m_value_s
;
st
d
::
st
ring
chain
=
m_value_s
;
int
seqNr
=
kResidueNrWildcard
;
int
seqNr
=
kResidueNrWildcard
;
if
(
m_lookahead
==
'*'
)
if
(
m_lookahead
==
'*'
)
...
@@ -1303,10 +1289,10 @@ tuple<string,int> TLSSelectionParserImplBuster::ParseAtom()
...
@@ -1303,10 +1289,10 @@ tuple<string,int> TLSSelectionParserImplBuster::ParseAtom()
if
(
m_lookahead
==
':'
)
if
(
m_lookahead
==
':'
)
{
{
Match
(
':'
);
Match
(
':'
);
string
atom
=
m_value_s
;
st
d
::
st
ring
atom
=
m_value_s
;
if
(
cif
::
VERBOSE
)
if
(
cif
::
VERBOSE
)
cerr
<<
"Warning: ignoring atom ID '"
<<
atom
<<
"' in TLS selection"
<<
endl
;
std
::
cerr
<<
"Warning: ignoring atom ID '"
<<
atom
<<
"' in TLS selection"
<<
std
::
endl
;
Match
(
bt_IDENT
);
Match
(
bt_IDENT
);
}
}
...
@@ -1327,7 +1313,7 @@ TLSSelectionPtr TLSSelectionParserImplBuster::Parse()
...
@@ -1327,7 +1313,7 @@ TLSSelectionPtr TLSSelectionParserImplBuster::Parse()
class
TLSSelectionParserImplBusterOld
:
public
TLSSelectionParserImpl
class
TLSSelectionParserImplBusterOld
:
public
TLSSelectionParserImpl
{
{
public
:
public
:
TLSSelectionParserImplBusterOld
(
const
string
&
selection
)
TLSSelectionParserImplBusterOld
(
const
st
d
::
st
ring
&
selection
)
:
TLSSelectionParserImpl
(
selection
)
:
TLSSelectionParserImpl
(
selection
)
{
{
m_lookahead
=
GetNextToken
();
m_lookahead
=
GetNextToken
();
...
@@ -1368,10 +1354,10 @@ class TLSSelectionParserImplBusterOld : public TLSSelectionParserImpl
...
@@ -1368,10 +1354,10 @@ class TLSSelectionParserImplBusterOld : public TLSSelectionParserImpl
};
};
virtual
int
GetNextToken
();
virtual
int
GetNextToken
();
virtual
string
ToString
(
int
token
);
virtual
st
d
::
st
ring
ToString
(
int
token
);
int
m_value_i
;
int
m_value_i
;
string
m_value_s
;
st
d
::
st
ring
m_value_s
;
int
m_value_r
[
2
];
int
m_value_r
[
2
];
};
};
...
@@ -1493,7 +1479,7 @@ int TLSSelectionParserImplBusterOld::GetNextToken()
...
@@ -1493,7 +1479,7 @@ int TLSSelectionParserImplBusterOld::GetNextToken()
case
st_CHAINRESID
:
case
st_CHAINRESID
:
if
(
isalpha
(
ch
))
if
(
isalpha
(
ch
))
{
{
m_value_s
+=
to_string
(
m_value_i
);
m_value_s
+=
std
::
to_string
(
m_value_i
);
m_value_s
+=
ch
;
m_value_s
+=
ch
;
state
=
st_IDENT
;
state
=
st_IDENT
;
}
}
...
@@ -1533,7 +1519,7 @@ int TLSSelectionParserImplBusterOld::GetNextToken()
...
@@ -1533,7 +1519,7 @@ int TLSSelectionParserImplBusterOld::GetNextToken()
if
(
ch
==
'\''
)
if
(
ch
==
'\''
)
result
=
pt_STRING
;
result
=
pt_STRING
;
else
if
(
ch
==
0
)
else
if
(
ch
==
0
)
throw
runtime_error
(
"Unexpected end of selection, missing quote character?"
);
throw
std
::
runtime_error
(
"Unexpected end of selection, missing quote character?"
);
else
else
m_value_s
+=
ch
;
m_value_s
+=
ch
;
break
;
break
;
...
@@ -1570,14 +1556,14 @@ int TLSSelectionParserImplBusterOld::GetNextToken()
...
@@ -1570,14 +1556,14 @@ int TLSSelectionParserImplBusterOld::GetNextToken()
return
result
;
return
result
;
}
}
string
TLSSelectionParserImplBusterOld
::
ToString
(
int
token
)
st
d
::
st
ring
TLSSelectionParserImplBusterOld
::
ToString
(
int
token
)
{
{
switch
(
token
)
switch
(
token
)
{
{
case
pt_IDENT
:
return
"identifier ("
+
m_value_s
+
')'
;
case
pt_IDENT
:
return
"identifier ("
+
m_value_s
+
')'
;
case
pt_STRING
:
return
"string ("
+
m_value_s
+
')'
;
case
pt_STRING
:
return
"string ("
+
m_value_s
+
')'
;
case
pt_NUMBER
:
return
"number ("
+
to_string
(
m_value_i
)
+
')'
;
case
pt_NUMBER
:
return
"number ("
+
std
::
to_string
(
m_value_i
)
+
')'
;
case
pt_RANGE
:
return
"range ("
+
to_string
(
m_value_r
[
0
])
+
':'
+
to_string
(
m_value_r
[
1
])
+
')'
;
case
pt_RANGE
:
return
"range ("
+
std
::
to_string
(
m_value_r
[
0
])
+
':'
+
std
::
to_string
(
m_value_r
[
1
])
+
')'
;
case
pt_EOLN
:
return
"end of line"
;
case
pt_EOLN
:
return
"end of line"
;
case
pt_KW_ALL
:
return
"ALL"
;
case
pt_KW_ALL
:
return
"ALL"
;
...
@@ -1605,7 +1591,7 @@ TLSSelectionPtr TLSSelectionParserImplBusterOld::Parse()
...
@@ -1605,7 +1591,7 @@ TLSSelectionPtr TLSSelectionParserImplBusterOld::Parse()
Match
(
pt_KW_PDB
);
Match
(
pt_KW_PDB
);
// Match(pt_KW_ENTRY);
// Match(pt_KW_ENTRY);
throw
runtime_error
(
"Unimplemented PDB ENTRY specification"
);
throw
std
::
runtime_error
(
"Unimplemented PDB ENTRY specification"
);
}
}
TLSSelectionPtr
result
=
ParseAtomSelection
();
TLSSelectionPtr
result
=
ParseAtomSelection
();
...
@@ -1662,10 +1648,10 @@ TLSSelectionPtr TLSSelectionParserImplBusterOld::ParseFactor()
...
@@ -1662,10 +1648,10 @@ TLSSelectionPtr TLSSelectionParserImplBusterOld::ParseFactor()
{
{
Match
(
pt_KW_CHAIN
);
Match
(
pt_KW_CHAIN
);
string
chainID
=
m_value_s
;
st
d
::
st
ring
chainID
=
m_value_s
;
if
(
m_lookahead
==
pt_NUMBER
)
// sigh
if
(
m_lookahead
==
pt_NUMBER
)
// sigh
{
{
chainID
=
to_string
(
m_value_i
);
chainID
=
std
::
to_string
(
m_value_i
);
Match
(
pt_NUMBER
);
Match
(
pt_NUMBER
);
}
}
else
else
...
@@ -1678,7 +1664,7 @@ TLSSelectionPtr TLSSelectionParserImplBusterOld::ParseFactor()
...
@@ -1678,7 +1664,7 @@ TLSSelectionPtr TLSSelectionParserImplBusterOld::ParseFactor()
case
pt_KW_RESNAME
:
case
pt_KW_RESNAME
:
{
{
Match
(
pt_KW_RESNAME
);
Match
(
pt_KW_RESNAME
);
string
name
=
m_value_s
;
st
d
::
st
ring
name
=
m_value_s
;
Match
(
pt_IDENT
);
Match
(
pt_IDENT
);
result
.
reset
(
new
TLSSelectionByName
(
name
));
result
.
reset
(
new
TLSSelectionByName
(
name
));
break
;
break
;
...
@@ -1704,7 +1690,7 @@ TLSSelectionPtr TLSSelectionParserImplBusterOld::ParseFactor()
...
@@ -1704,7 +1690,7 @@ TLSSelectionPtr TLSSelectionParserImplBusterOld::ParseFactor()
break
;
break
;
default
:
default
:
throw
runtime_error
(
"Unexpected token "
+
ToString
(
m_lookahead
));
throw
std
::
runtime_error
(
"Unexpected token "
+
ToString
(
m_lookahead
));
}
}
return
result
;
return
result
;
...
@@ -1766,7 +1752,7 @@ TLSSelectionPtr TLSSelectionParserImplBusterOld::ParseChainResid()
...
@@ -1766,7 +1752,7 @@ TLSSelectionPtr TLSSelectionParserImplBusterOld::ParseChainResid()
int
from
,
to
;
int
from
,
to
;
from
=
to
=
m_value_i
;
from
=
to
=
m_value_i
;
string
chainID
=
m_value_s
;
st
d
::
st
ring
chainID
=
m_value_s
;
Match
(
pt_CHAINRESID
);
Match
(
pt_CHAINRESID
);
...
@@ -1776,7 +1762,7 @@ TLSSelectionPtr TLSSelectionParserImplBusterOld::ParseChainResid()
...
@@ -1776,7 +1762,7 @@ TLSSelectionPtr TLSSelectionParserImplBusterOld::ParseChainResid()
to
=
m_value_i
;
to
=
m_value_i
;
if
(
m_value_s
!=
chainID
)
if
(
m_value_s
!=
chainID
)
throw
runtime_error
(
"Cannot have two different chainIDs in a range selection"
);
throw
std
::
runtime_error
(
"Cannot have two different chainIDs in a range selection"
);
Match
(
pt_CHAINRESID
);
Match
(
pt_CHAINRESID
);
}
}
...
@@ -1807,7 +1793,7 @@ TLSSelectionPtr TLSSelectionParserImplBusterOld::ParseChainResid()
...
@@ -1807,7 +1793,7 @@ TLSSelectionPtr TLSSelectionParserImplBusterOld::ParseChainResid()
class
TLSSelectionParserBase
class
TLSSelectionParserBase
{
{
public
:
public
:
virtual
TLSSelectionPtr
Parse
(
const
string
&
selection
)
const
=
0
;
virtual
TLSSelectionPtr
Parse
(
const
st
d
::
st
ring
&
selection
)
const
=
0
;
virtual
~
TLSSelectionParserBase
()
{}
virtual
~
TLSSelectionParserBase
()
{}
};
};
...
@@ -1815,7 +1801,7 @@ template<typename IMPL>
...
@@ -1815,7 +1801,7 @@ template<typename IMPL>
class
TLSSelectionParser
class
TLSSelectionParser
{
{
public
:
public
:
virtual
TLSSelectionPtr
Parse
(
const
string
&
selection
)
const
virtual
TLSSelectionPtr
Parse
(
const
st
d
::
st
ring
&
selection
)
const
{
{
TLSSelectionPtr
result
;
TLSSelectionPtr
result
;
...
@@ -1824,9 +1810,9 @@ class TLSSelectionParser
...
@@ -1824,9 +1810,9 @@ class TLSSelectionParser
IMPL
p
(
selection
);
IMPL
p
(
selection
);
result
=
p
.
Parse
();
result
=
p
.
Parse
();
}
}
catch
(
const
exception
&
ex
)
catch
(
const
std
::
exception
&
ex
)
{
{
cerr
<<
"ParseError: "
<<
ex
.
what
()
<<
endl
;
std
::
cerr
<<
"ParseError: "
<<
ex
.
what
()
<<
std
::
endl
;
}
}
return
result
;
return
result
;
...
@@ -1836,7 +1822,7 @@ class TLSSelectionParser
...
@@ -1836,7 +1822,7 @@ class TLSSelectionParser
// --------------------------------------------------------------------
// --------------------------------------------------------------------
TLSSelectionPtr
ParseSelectionDetails
(
const
st
ring
&
program
,
const
string
&
selection
)
TLSSelectionPtr
ParseSelectionDetails
(
const
st
d
::
string
&
program
,
const
std
::
string
&
selection
)
{
{
TLSSelectionParser
<
TLSSelectionParserImplPhenix
>
phenix
;
TLSSelectionParser
<
TLSSelectionParserImplPhenix
>
phenix
;
TLSSelectionParser
<
TLSSelectionParserImplBuster
>
buster
;
TLSSelectionParser
<
TLSSelectionParserImplBuster
>
buster
;
...
@@ -1851,14 +1837,14 @@ TLSSelectionPtr ParseSelectionDetails(const string& program, const string& selec
...
@@ -1851,14 +1837,14 @@ TLSSelectionPtr ParseSelectionDetails(const string& program, const string& selec
if
(
not
result
)
if
(
not
result
)
{
{
if
(
cif
::
VERBOSE
)
if
(
cif
::
VERBOSE
)
cerr
<<
"Falling back to old BUSTER"
<<
endl
;
std
::
cerr
<<
"Falling back to old BUSTER"
<<
std
::
endl
;
result
=
busterOld
.
Parse
(
selection
);
result
=
busterOld
.
Parse
(
selection
);
}
}
if
(
not
result
)
if
(
not
result
)
{
{
if
(
cif
::
VERBOSE
)
if
(
cif
::
VERBOSE
)
cerr
<<
"Falling back to PHENIX"
<<
endl
;
std
::
cerr
<<
"Falling back to PHENIX"
<<
std
::
endl
;
result
=
phenix
.
Parse
(
selection
);
result
=
phenix
.
Parse
(
selection
);
}
}
}
}
...
@@ -1869,35 +1855,35 @@ TLSSelectionPtr ParseSelectionDetails(const string& program, const string& selec
...
@@ -1869,35 +1855,35 @@ TLSSelectionPtr ParseSelectionDetails(const string& program, const string& selec
if
(
not
result
)
if
(
not
result
)
{
{
if
(
cif
::
VERBOSE
)
if
(
cif
::
VERBOSE
)
cerr
<<
"Falling back to BUSTER"
<<
endl
;
std
::
cerr
<<
"Falling back to BUSTER"
<<
std
::
endl
;
result
=
buster
.
Parse
(
selection
);
result
=
buster
.
Parse
(
selection
);
}
}
if
(
not
result
)
if
(
not
result
)
{
{
if
(
cif
::
VERBOSE
)
if
(
cif
::
VERBOSE
)
cerr
<<
"Falling back to old BUSTER"
<<
endl
;
std
::
cerr
<<
"Falling back to old BUSTER"
<<
std
::
endl
;
result
=
busterOld
.
Parse
(
selection
);
result
=
busterOld
.
Parse
(
selection
);
}
}
}
}
else
else
{
{
if
(
cif
::
VERBOSE
)
if
(
cif
::
VERBOSE
)
cerr
<<
"No known program specified, trying PHENIX"
<<
endl
;
std
::
cerr
<<
"No known program specified, trying PHENIX"
<<
std
::
endl
;
result
=
phenix
.
Parse
(
selection
);
result
=
phenix
.
Parse
(
selection
);
if
(
not
result
)
if
(
not
result
)
{
{
if
(
cif
::
VERBOSE
)
if
(
cif
::
VERBOSE
)
cerr
<<
"Falling back to BUSTER"
<<
endl
;
std
::
cerr
<<
"Falling back to BUSTER"
<<
std
::
endl
;
result
=
buster
.
Parse
(
selection
);
result
=
buster
.
Parse
(
selection
);
}
}
if
(
not
result
)
if
(
not
result
)
{
{
if
(
cif
::
VERBOSE
)
if
(
cif
::
VERBOSE
)
cerr
<<
"Falling back to old BUSTER"
<<
endl
;
std
::
cerr
<<
"Falling back to old BUSTER"
<<
std
::
endl
;
result
=
busterOld
.
Parse
(
selection
);
result
=
busterOld
.
Parse
(
selection
);
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment