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 \
CifUtils.cpp
\
CifValidator.cpp
\
Compound.cpp
\
FixDMC.cpp
\
PDB2Cif.cpp
\
PDB2CifRemark3.cpp
\
Point.cpp
\
...
...
src/AtomType.cpp
View file @
4b4757ee
...
...
@@ -29,8 +29,6 @@
#include "cif++/AtomType.hpp"
#include "cif++/Cif++.hpp"
using
namespace
std
;
namespace
mmcif
{
...
...
@@ -1237,7 +1235,7 @@ SFDataArrayElement kELSFData[] = {
// --------------------------------------------------------------------
// AtomTypeTraits
AtomTypeTraits
::
AtomTypeTraits
(
const
string
&
symbol
)
AtomTypeTraits
::
AtomTypeTraits
(
const
st
d
::
st
ring
&
symbol
)
:
mInfo
(
nullptr
)
{
for
(
auto
&
i
:
data
::
kKnownAtoms
)
...
...
@@ -1250,20 +1248,20 @@ AtomTypeTraits::AtomTypeTraits(const string& symbol)
}
if
(
mInfo
==
nullptr
)
throw
invalid_argument
(
"Not a known element: "
+
symbol
);
throw
std
::
invalid_argument
(
"Not a known element: "
+
symbol
);
}
AtomTypeTraits
::
AtomTypeTraits
(
AtomType
t
)
{
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
];
assert
(
mInfo
->
type
==
t
);
}
bool
AtomTypeTraits
::
isElement
(
const
string
&
symbol
)
bool
AtomTypeTraits
::
isElement
(
const
st
d
::
st
ring
&
symbol
)
{
bool
result
=
false
;
...
...
@@ -1279,7 +1277,7 @@ bool AtomTypeTraits::isElement(const string& symbol)
return
result
;
}
bool
AtomTypeTraits
::
isMetal
(
const
string
&
symbol
)
bool
AtomTypeTraits
::
isMetal
(
const
st
d
::
st
ring
&
symbol
)
{
bool
result
=
false
;
...
...
@@ -1303,7 +1301,7 @@ auto AtomTypeTraits::wksf(int charge) const -> const SFData&
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
&
...
...
@@ -1314,7 +1312,7 @@ auto AtomTypeTraits::elsf() const -> const SFData&
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 @@
#include "cif++/CifValidator.hpp"
#include "cif++/CifUtils.hpp"
using
namespace
std
;
namespace
ba
=
boost
::
algorithm
;
namespace
io
=
boost
::
iostreams
;
namespace
fs
=
std
::
filesystem
;
...
...
@@ -115,7 +114,7 @@ void ItemValue::operator delete(void* p)
struct
ItemColumn
{
string
mName
;
// store lower-case, for optimization
st
d
::
st
ring
mName
;
// store lower-case, for optimization
const
ValidateItem
*
mValidator
;
};
...
...
@@ -128,9 +127,9 @@ struct ItemRow
void
drop
(
uint32_t
columnIx
);
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
<<
'{'
;
for
(
auto
v
=
mValues
;
v
!=
nullptr
;
v
=
v
->
mNext
)
...
...
@@ -152,7 +151,7 @@ struct ItemRow
uint32_t
mLineNr
=
0
;
};
ostream
&
operator
<<
(
ostream
&
os
,
const
ItemRow
&
r
)
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
ItemRow
&
r
)
{
os
<<
r
.
mCategory
->
name
()
<<
'['
;
for
(
auto
iv
=
r
.
mValues
;
iv
!=
nullptr
;
iv
=
iv
->
mNext
)
...
...
@@ -234,10 +233,10 @@ const char* ItemRow::c_str(uint32_t columnIx) const
namespace
detail
{
ItemReference
&
ItemReference
::
operator
=
(
const
string
&
value
)
ItemReference
&
ItemReference
::
operator
=
(
const
st
d
::
st
ring
&
value
)
{
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
);
return
*
this
;
...
...
@@ -342,7 +341,7 @@ std::ostream& operator<<(std::ostream& os, ItemReference& item)
// --------------------------------------------------------------------
// Datablock implementation
Datablock
::
Datablock
(
const
string
&
name
)
Datablock
::
Datablock
(
const
st
d
::
st
ring
&
name
)
:
mName
(
name
),
mValidator
(
nullptr
),
mNext
(
nullptr
)
{
}
...
...
@@ -352,11 +351,11 @@ Datablock::~Datablock()
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
);
for
(
auto
&
cat
:
mCategories
)
...
...
@@ -365,7 +364,7 @@ string Datablock::firstItem(const string& tag) const
{
for
(
auto
row
:
cat
)
{
result
=
row
[
itemName
].
as
<
string
>
();
result
=
row
[
itemName
].
as
<
st
d
::
st
ring
>
();
break
;
}
...
...
@@ -376,7 +375,7 @@ string Datablock::firstItem(const string& tag) const
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
;
iterator
i
=
find_if
(
begin
(),
end
(),
[
name
](
const
Category
&
cat
)
->
bool
...
...
@@ -388,17 +387,17 @@ auto Datablock::emplace(const string& name) -> tuple<iterator,bool>
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
;
std
::
tie
(
i
,
ignore
)
=
emplace
(
name
);
std
::
tie
(
i
,
std
::
ignore
)
=
emplace
(
name
);
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
{
return
iequals
(
cat
.
name
(),
name
);
});
...
...
@@ -409,7 +408,7 @@ Category* Datablock::get(const string& name)
bool
Datablock
::
isValid
()
{
if
(
mValidator
==
nullptr
)
throw
runtime_error
(
"Validator not specified"
);
throw
std
::
runtime_error
(
"Validator not specified"
);
bool
result
=
true
;
for
(
auto
&
cat
:
*
this
)
...
...
@@ -431,7 +430,7 @@ void Datablock::setValidator(Validator* 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"
);
int
ordNr
=
cat
.
size
()
+
1
;
...
...
@@ -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
)
cat
.
getTagOrder
(
tags
);
}
void
Datablock
::
write
(
ostream
&
os
)
void
Datablock
::
write
(
std
::
ostream
&
os
)
{
os
<<
"data_"
<<
mName
<<
endl
<<
"# "
<<
endl
;
os
<<
"data_"
<<
mName
<<
std
::
endl
<<
"# "
<<
std
::
endl
;
// mmcif support, sort of. First write the 'entry' Category
// and if it exists, _AND_ we have a Validator, write out the
...
...
@@ -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
<<
"# "
<<
endl
;
os
<<
"data_"
<<
mName
<<
std
::
endl
<<
"# "
<<
std
::
endl
;
vector
<
string
>
catOrder
;
std
::
vector
<
std
::
string
>
catOrder
;
for
(
auto
&
o
:
order
)
{
string
cat
,
Item
;
st
d
::
st
ring
cat
,
Item
;
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
);
}
...
...
@@ -508,10 +507,10 @@ void Datablock::write(ostream& os, const vector<string>& order)
if
(
cat
==
nullptr
)
continue
;
vector
<
string
>
items
;
std
::
vector
<
std
::
string
>
items
;
for
(
auto
&
o
:
order
)
{
string
catName
,
Item
;
st
d
::
st
ring
catName
,
Item
;
std
::
tie
(
catName
,
Item
)
=
splitTagName
(
o
);
if
(
catName
==
c
)
...
...
@@ -524,7 +523,7 @@ void Datablock::write(ostream& os, const vector<string>& order)
// for any Category we missed in the catOrder
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
;
cat
.
write
(
os
);
...
...
@@ -603,11 +602,11 @@ class RowComparator
}
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
>
...
...
@@ -617,19 +616,19 @@ RowComparator::RowComparator(Category* cat, KeyIter b, KeyIter e)
for
(
auto
ki
=
b
;
ki
!=
e
;
++
ki
)
{
string
k
=
*
ki
;
st
d
::
st
ring
k
=
*
ki
;
size_t
ix
=
cat
->
getColumnIndex
(
k
);
auto
iv
=
cv
->
getValidatorForItem
(
k
);
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
;
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
));
}
...
...
@@ -680,9 +679,9 @@ class CatIndex
void
reconstruct
();
// 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
)
{
...
...
@@ -691,7 +690,7 @@ class CatIndex
tail
->
mRow
->
mNext
=
nullptr
;
result
=
make_tuple
(
head
->
mRow
,
tail
->
mRow
);
result
=
std
::
make_tuple
(
head
->
mRow
,
tail
->
mRow
);
}
return
result
;
...
...
@@ -898,7 +897,7 @@ CatIndex::entry* CatIndex::insert(entry* h, ItemRow* v)
if
(
d
<
0
)
h
->
mLeft
=
insert
(
h
->
mLeft
,
v
);
else
if
(
d
>
0
)
h
->
mRight
=
insert
(
h
->
mRight
,
v
);
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
))
h
=
rotateLeft
(
h
);
...
...
@@ -969,9 +968,9 @@ void CatIndex::reconstruct()
insert
(
r
.
mData
);
// 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),
// [](Row r) -> ItemRow* { assert(r.mData); return r.mData; });
//
...
...
@@ -1039,7 +1038,7 @@ void CatIndex::reconstruct()
size_t
CatIndex
::
size
()
const
{
stack
<
entry
*>
s
;
st
d
::
st
ack
<
entry
*>
s
;
s
.
push
(
mRoot
);
size_t
result
=
0
;
...
...
@@ -1189,7 +1188,7 @@ RowSet& RowSet::operator=(RowSet&& rhs)
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
());
...
...
@@ -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
)
,
mHead
(
nullptr
),
mTail
(
nullptr
),
mIndex
(
nullptr
)
{
...
...
@@ -1258,12 +1257,12 @@ void Category::setValidator(Validator* v)
mCatValidator
=
nullptr
;
}
bool
Category
::
hasColumn
(
const
string
&
name
)
const
bool
Category
::
hasColumn
(
const
st
d
::
st
ring
&
name
)
const
{
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
;
...
...
@@ -1277,26 +1276,26 @@ size_t Category::getColumnIndex(const string& name) const
{
auto
iv
=
mCatValidator
->
getValidatorForItem
(
name
);
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
;
}
const
string
&
Category
::
getColumnName
(
size_t
columnIx
)
const
const
st
d
::
st
ring
&
Category
::
getColumnName
(
size_t
columnIx
)
const
{
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
)
result
.
push_back
(
c
.
mName
);
return
result
;
}
size_t
Category
::
addColumn
(
const
string
&
name
)
size_t
Category
::
addColumn
(
const
st
d
::
st
ring
&
name
)
{
size_t
result
=
getColumnIndex
(
name
);
...
...
@@ -1343,7 +1342,7 @@ void Category::sort(std::function<int(const Row&, const Row&)> comparator)
if
(
mHead
==
nullptr
)
return
;
vector
<
ItemRow
*>
rows
;
std
::
vector
<
ItemRow
*>
rows
;
for
(
auto
itemRow
=
mHead
;
itemRow
!=
nullptr
;
itemRow
=
itemRow
->
mNext
)
rows
.
push_back
(
itemRow
);
...
...
@@ -1382,9 +1381,9 @@ bool Category::empty() const
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
(),
[
field
](
ItemColumn
&
c
)
->
bool
{
return
iequals
(
c
.
mName
,
field
);
});
...
...
@@ -1450,7 +1449,7 @@ bool Category::exists(Condition&& cond) const
return
result
;
}
RowSet
Category
::
orderBy
(
std
::
initializer_list
<
string
>
items
)
RowSet
Category
::
orderBy
(
std
::
initializer_list
<
st
d
::
st
ring
>
items
)
{
RowSet
result
(
*
this
);
result
.
insert
(
result
.
begin
(),
begin
(),
end
());
...
...
@@ -1471,10 +1470,10 @@ void Category::clear()
}
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
tuple
<
Row
,
bool
>
result
=
make_tuple
(
Row
(),
true
);
std
::
tuple
<
Row
,
bool
>
result
=
std
::
make_tuple
(
Row
(),
true
);
if
(
mCatValidator
!=
nullptr
and
b
!=
e
)
{
...
...
@@ -1497,12 +1496,12 @@ tuple<Row,bool> Category::emplace(Iter b, Iter e)
}
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
)
{
unique_ptr
<
ItemRow
>
nr
(
new
ItemRow
{
nullptr
,
this
,
nullptr
});
std
::
unique_ptr
<
ItemRow
>
nr
(
new
ItemRow
{
nullptr
,
this
,
nullptr
});
Row
r
(
nr
.
get
());
auto
keys
=
keyFields
();
...
...
@@ -1516,13 +1515,13 @@ tuple<Row,bool> Category::emplace(Iter b, Iter e)
if
(
test
!=
nullptr
)
{
if
(
VERBOSE
>
1
)
cerr
<<
"Not inserting new record in "
<<
mName
<<
" (duplicate Key)"
<<
endl
;
result
=
make_tuple
(
Row
(
test
),
false
);
std
::
cerr
<<
"Not inserting new record in "
<<
mName
<<
" (duplicate Key)"
<<
std
::
endl
;
result
=
std
::
make_tuple
(
Row
(
test
),
false
);
}
}
}
if
(
get
<
1
>
(
result
))
if
(
std
::
get
<
1
>
(
result
))
{
auto
nr
=
new
ItemRow
{
nullptr
,
this
,
nullptr
};
...
...
@@ -1544,7 +1543,7 @@ tuple<Row,bool> Category::emplace(Iter b, Iter e)
for
(
auto
v
=
b
;
v
!=
e
;
++
v
)
r
.
assign
(
*
v
,
true
);
get
<
0
>
(
result
)
=
r
;
std
::
get
<
0
>
(
result
)
=
r
;
if
(
mIndex
!=
nullptr
)
mIndex
->
insert
(
nr
);
...
...
@@ -1553,7 +1552,7 @@ tuple<Row,bool> Category::emplace(Iter b, Iter e)
return
result
;
}
tuple
<
Row
,
bool
>
Category
::
emplace
(
Row
r
)
std
::
tuple
<
Row
,
bool
>
Category
::
emplace
(
Row
r
)
{
return
emplace
(
r
.
begin
(),
r
.
end
());
}
...
...
@@ -1603,7 +1602,7 @@ size_t Category::erase(Condition&& cond, std::function<void(const Row&)>&& verbo
void
Category
::
eraseOrphans
(
Condition
&&
cond
)
{
vector
<
ItemRow
*>
remove
;
std
::
vector
<
ItemRow
*>
remove
;
cond
.
prepare
(
*
this
);
...
...
@@ -1612,9 +1611,9 @@ void Category::eraseOrphans(Condition&& cond)
if
(
cond
(
*
this
,
r
)
and
isOrphan
(
r
))
{
if
(
VERBOSE
>
1
)
cerr
<<
"Removing orphaned record: "
<<
endl
<<
r
<<
endl
<<
endl
;
std
::
cerr
<<
"Removing orphaned record: "
<<
std
::
endl
<<
r
<<
std
::
endl
<<
std
::
endl
;
remove
.
push_back
(
r
.
mData
);
}
...
...
@@ -1639,7 +1638,7 @@ auto Category::erase(iterator pos) -> iterator
keys
=
iset
(
mCatValidator
->
mKeys
.
begin
(),
mCatValidator
->
mKeys
.
end
());
if
(
mHead
==
nullptr
)
throw
runtime_error
(
"erase"
);
throw
std
::
runtime_error
(
"erase"
);
if
(
mIndex
!=
nullptr
)
mIndex
->
erase
(
r
.
mData
);
...
...
@@ -1666,7 +1665,7 @@ auto Category::erase(iterator pos) -> iterator
// in mmcif_pdbx.dic dictionary.
//
// 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
// the child is removed as well, recursively of course.
...
...
@@ -1684,10 +1683,10 @@ auto Category::erase(iterator pos) -> iterator
{
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
return
result
;
}
void
Category
::
getTagOrder
(
vector
<
string
>&
tags
)
const
void
Category
::
getTagOrder
(
std
::
vector
<
std
::
string
>&
tags
)
const
{
for
(
auto
&
c
:
mColumns
)
tags
.
push_back
(
"_"
+
mName
+
"."
+
c
.
mName
);
...
...
@@ -1746,12 +1745,12 @@ bool Category::hasParent(Row r, const Category& parentCat, const ValidateLink& l
if
(
field
.
empty
())
{
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
{
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
result
=
parentCat
.
exists
(
std
::
move
(
cond
));
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
())
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
;
}
...
...
@@ -1785,16 +1784,16 @@ bool Category::isOrphan(Row r)
for
(
size_t
ix
=
0
;
ix
<
link
->
mChildKeys
.
size
();
++
ix
)
{
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
)
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
(
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
;
break
;
...
...
@@ -1823,7 +1822,7 @@ bool Category::hasChildren(Row r) const
{
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
();
...
...
@@ -1840,12 +1839,12 @@ bool Category::isValid()
bool
result
=
true
;
if
(
mValidator
==
nullptr
)
throw
runtime_error
(
"no Validator specified"
);
throw
std
::
runtime_error
(
"no Validator specified"
);
if
(
empty
())
{
if
(
VERBOSE
>
2
)
cerr
<<
"Skipping validation of empty Category "
<<
mName
<<
endl
;
std
::
cerr
<<
"Skipping validation of empty Category "
<<
mName
<<
std
::
endl
;
return
true
;
}
...
...
@@ -1947,8 +1946,8 @@ void Category::validateLinks() const
if
(
missing
)
{
cerr
<<
"Links for "
<<
linkValidator
->
mLinkGroupLabel
<<
" are incomplete"
<<
endl
<<
" There are "
<<
missing
<<
" items in "
<<
mName
<<
" that don't have matching parent items in "
<<
parent
->
mName
<<
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
<<
std
::
endl
;
}
}
}
...
...
@@ -1956,14 +1955,14 @@ void Category::validateLinks() const
const
Validator
&
Category
::
getValidator
()
const
{
if
(
mValidator
==
nullptr
)
throw
runtime_error
(
"no Validator defined yet"
);
throw
std
::
runtime_error
(
"no Validator defined yet"
);
return
*
mValidator
;
}
iset
Category
::
fields
()
const
{
if
(
mValidator
==
nullptr
)
throw
runtime_error
(
"No Validator specified"
);
throw
std
::
runtime_error
(
"No Validator specified"
);
if
(
mCatValidator
==
nullptr
)
mValidator
->
reportError
(
"undefined Category"
,
true
);
...
...
@@ -1977,7 +1976,7 @@ iset Category::fields() const
iset
Category
::
mandatoryFields
()
const
{
if
(
mValidator
==
nullptr
)
throw
runtime_error
(
"No Validator specified"
);
throw
std
::
runtime_error
(
"No Validator specified"
);
if
(
mCatValidator
==
nullptr
)
mValidator
->
reportError
(
"undefined Category"
,
true
);
...
...
@@ -1988,7 +1987,7 @@ iset Category::mandatoryFields() const
iset
Category
::
keyFields
()
const
{
if
(
mValidator
==
nullptr
)
throw
runtime_error
(
"No Validator specified"
);
throw
std
::
runtime_error
(
"No Validator specified"
);
if
(
mCatValidator
==
nullptr
)
mValidator
->
reportError
(
"undefined Category"
,
true
);
...
...
@@ -1996,15 +1995,15 @@ iset Category::keyFields() const
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
)
throw
runtime_error
(
"No Validator specified"
);
throw
std
::
runtime_error
(
"No Validator specified"
);
if
(
mCatValidator
==
nullptr
)
mValidator
->
reportError
(
"undefined Category"
,
true
);
set
<
size_t
>
result
;
s
td
::
s
et
<
size_t
>
result
;
for
(
auto
&
k
:
mCatValidator
->
mKeys
)
result
.
insert
(
getColumnIndex
(
k
));
...
...
@@ -2026,18 +2025,18 @@ set<size_t> Category::keyFieldsByIndex() const
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\\
;"
);
if
(
offset
>
0
)
os
<<
endl
;
os
<<
std
::
endl
;
os
<<
';'
<<
value
;
if
(
not
ba
::
ends_with
(
value
,
"
\n
"
))
os
<<
endl
;
os
<<
';'
<<
endl
;
os
<<
std
::
endl
;
os
<<
';'
<<
std
::
endl
;
offset
=
0
;
}
else
if
(
isUnquotedString
(
value
.
c_str
()))
...
...
@@ -2046,7 +2045,7 @@ size_t writeValue(ostream& os, string value, size_t offset, size_t width)
if
(
value
.
length
()
<
width
)
{
os
<<
string
(
width
-
value
.
length
(),
' '
);
os
<<
st
d
::
st
ring
(
width
-
value
.
length
(),
' '
);
offset
+=
width
;
}
else
...
...
@@ -2061,17 +2060,17 @@ size_t writeValue(ostream& os, string value, size_t offset, size_t width)
for
(
char
q
:
{
'\''
,
'"'
})
{
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
);
if
(
p
!=
string
::
npos
)
if
(
p
!=
st
d
::
st
ring
::
npos
)
continue
;
os
<<
q
<<
value
<<
q
;
if
(
value
.
length
()
+
2
<
width
)
{
os
<<
string
(
width
-
value
.
length
()
-
2
,
' '
);
os
<<
st
d
::
st
ring
(
width
-
value
.
length
()
-
2
,
' '
);
offset
+=
width
;
}
else
...
...
@@ -2087,9 +2086,9 @@ size_t writeValue(ostream& os, string value, size_t offset, size_t width)
if
(
not
done
)
{
if
(
offset
>
0
)
os
<<
endl
;
os
<<
';'
<<
value
<<
endl
<<
';'
<<
endl
;
os
<<
std
::
endl
;
os
<<
';'
<<
value
<<
std
::
endl
<<
';'
<<
std
::
endl
;
offset
=
0
;
}
}
...
...
@@ -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
())
return
;
...
...
@@ -2109,14 +2108,14 @@ void Category::write(ostream& os, const vector<int>& order, bool includeEmptyCol
if
(
needLoop
)
{
os
<<
"loop_"
<<
endl
;
os
<<
"loop_"
<<
std
::
endl
;
vector
<
size_t
>
columnWidths
;
std
::
vector
<
size_t
>
columnWidths
;
for
(
auto
cix
:
order
)
{
auto
&
col
=
mColumns
[
cix
];
os
<<
'_'
<<
mName
<<
'.'
<<
col
.
mName
<<
' '
<<
endl
;
os
<<
'_'
<<
mName
<<
'.'
<<
col
.
mName
<<
' '
<<
std
::
endl
;
columnWidths
.
push_back
(
2
);
}
...
...
@@ -2148,7 +2147,7 @@ void Category::write(ostream& os, const vector<int>& order, bool includeEmptyCol
{
size_t
w
=
columnWidths
[
cix
];
string
s
;
st
d
::
st
ring
s
;
for
(
auto
iv
=
Row
->
mValues
;
iv
!=
nullptr
;
iv
=
iv
->
mNext
)
{
if
(
iv
->
mColumnIndex
==
cix
)
...
...
@@ -2169,7 +2168,7 @@ void Category::write(ostream& os, const vector<int>& order, bool includeEmptyCol
if
(
offset
+
l
>=
132
and
offset
>
0
)
{
os
<<
endl
;
os
<<
std
::
endl
;
offset
=
0
;
}
...
...
@@ -2177,13 +2176,13 @@ void Category::write(ostream& os, const vector<int>& order, bool includeEmptyCol
if
(
offset
>=
132
)
{
os
<<
endl
;
os
<<
std
::
endl
;
offset
=
0
;
}
}
if
(
offset
>
0
)
os
<<
endl
;
os
<<
std
::
endl
;
}
}
else
...
...
@@ -2193,7 +2192,7 @@ void Category::write(ostream& os, const vector<int>& order, bool includeEmptyCol
for
(
auto
&
col
:
mColumns
)
{
string
tag
=
'_'
+
mName
+
'.'
+
col
.
mName
;
st
d
::
st
ring
tag
=
'_'
+
mName
+
'.'
+
col
.
mName
;
if
(
l
<
tag
.
length
())
l
=
tag
.
length
();
...
...
@@ -2205,9 +2204,9 @@ void Category::write(ostream& os, const vector<int>& order, bool includeEmptyCol
{
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
)
{
if
(
iv
->
mColumnIndex
==
cix
)
...
...
@@ -2223,32 +2222,32 @@ void Category::write(ostream& os, const vector<int>& order, bool includeEmptyCol
size_t
offset
=
l
;
if
(
s
.
length
()
+
l
>=
kMaxLineLength
)
{
os
<<
endl
;
os
<<
std
::
endl
;
offset
=
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
);
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
for
(
auto
&
c
:
columns
)
addColumn
(
c
);
vector
<
int
>
order
;
std
::
vector
<
int
>
order
;
order
.
reserve
(
mColumns
.
size
());
for
(
auto
&
c
:
columns
)
...
...
@@ -2307,15 +2306,15 @@ void Row::assign(const std::vector<Item>& values)
{
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
)
{
auto
columnIx
=
cat
->
addColumn
(
value
.
name
());
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
);
}
...
...
@@ -2337,29 +2336,29 @@ void Row::assign(const std::vector<Item>& values)
// continue;
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
)
{
string
pk
=
linked
->
mParentKeys
[
ix
];
string
ck
=
linked
->
mChildKeys
[
ix
];
st
d
::
st
ring
pk
=
linked
->
mParentKeys
[
ix
];
st
d
::
st
ring
ck
=
linked
->
mChildKeys
[
ix
];
if
(
changed
.
count
(
pk
)
>
0
)
{
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
]));
}
else
{
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
)
cr
.
assign
(
newValues
);
}
...
...
@@ -2371,24 +2370,24 @@ void Row::assign(const Item& value, bool 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
{
auto
cat
=
mData
->
mCategory
;
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
;
}
}
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
)
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
&
col
=
cat
->
mColumns
[
column
];
...
...
@@ -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
return
;
string
oldStrValue
=
oldValue
?
oldValue
:
""
;
st
d
::
st
ring
oldStrValue
=
oldValue
?
oldValue
:
""
;
// check the value
if
(
col
.
mValidator
)
...
...
@@ -2489,35 +2488,35 @@ void Row::assign(size_t column, const string& value, bool skipUpdateLinked)
continue
;
Condition
cond
;
string
childTag
;
st
d
::
st
ring
childTag
;
for
(
size_t
ix
=
0
;
ix
<
linked
->
mParentKeys
.
size
();
++
ix
)
{
string
pk
=
linked
->
mParentKeys
[
ix
];
string
ck
=
linked
->
mChildKeys
[
ix
];
st
d
::
st
ring
pk
=
linked
->
mParentKeys
[
ix
];
st
d
::
st
ring
ck
=
linked
->
mChildKeys
[
ix
];
// TODO add code to *NOT* test mandatory fiels for Empty
if
(
pk
==
iv
->
mTag
)
{
childTag
=
ck
;
cond
=
move
(
cond
)
&&
((
Key
(
ck
)
==
oldStrValue
)
or
Key
(
ck
)
==
Empty
());
cond
=
std
::
move
(
cond
)
&&
((
Key
(
ck
)
==
oldStrValue
)
or
Key
(
ck
)
==
Empty
());
}
else
{
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)
// {
// std::
cerr << "Parent: " << linked->mParentCategory << " Child: " << linked->mChildCategory <<
std::endl
// << cond << std::endl;
// std::
std::cerr << "Parent: " << linked->mParentCategory << " Child: " << linked->mChildCategory << std::
std::endl
// << cond << std::
std::
endl;
// }
auto
rows
=
childCat
->
find
(
move
(
cond
));
auto
rows
=
childCat
->
find
(
std
::
move
(
cond
));
for
(
auto
&
cr
:
rows
)
cr
.
assign
(
childTag
,
value
,
false
);
}
...
...
@@ -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
)
{
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
);
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
;
...
...
@@ -2642,7 +2641,7 @@ void Row::swap(size_t cix, ItemRow* a, ItemRow* b)
if
(
childCatValidator
==
nullptr
)
continue
;
string
linkChildColName
;
st
d
::
st
ring
linkChildColName
;
Condition
cond
[
2
];
for
(
size_t
ab
=
0
;
ab
<
2
;
++
ab
)
...
...
@@ -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
(
parentCatValidator
->
mMandatoryFields
.
begin
(),
parentCatValidator
->
mMandatoryFields
.
end
(),
link
->
mParentKeys
[
ix
])
!=
parentCatValidator
->
mMandatoryFields
.
end
();
string
childValue
;
st
d
::
st
ring
childValue
;
if
(
pcix
==
cix
)
{
...
...
@@ -2670,7 +2669,7 @@ void Row::swap(size_t cix, ItemRow* a, ItemRow* b)
}
else
{
string
ps
=
r
->
c_str
(
pcix
);
st
d
::
st
ring
ps
=
r
->
c_str
(
pcix
);
if
(
not
(
ps
.
empty
()
or
ps
==
"."
or
ps
==
"?"
))
childValue
=
ps
;
}
...
...
@@ -2678,12 +2677,12 @@ void Row::swap(size_t cix, ItemRow* a, ItemRow* b)
if
(
not
childValue
.
empty
())
{
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
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
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)
continue
;
if
(
VERBOSE
>
1
)
cerr
<<
"Fixing link from "
<<
cat
->
mName
<<
" to "
<<
childCat
->
mName
<<
" with "
<<
endl
<<
cond
[
ab
]
<<
endl
;
std
::
cerr
<<
"Fixing link from "
<<
cat
->
mName
<<
" to "
<<
childCat
->
mName
<<
" with "
<<
std
::
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
)
...
...
@@ -2720,12 +2719,12 @@ void Row::swap(size_t cix, ItemRow* a, ItemRow* b)
if
(
n
==
link
->
mChildKeys
.
size
())
{
if
(
VERBOSE
>
1
)
cerr
<<
"All empty columns, skipping"
<<
endl
;
std
::
cerr
<<
"All empty columns, skipping"
<<
std
::
endl
;
}
else
{
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
:
""
;
}
}
...
...
@@ -2800,11 +2799,11 @@ void Row::const_iterator::fetch()
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
Row
&
row
)
{
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
)
{
string
tagName
=
category
->
getColumnName
(
item
->
mColumnIndex
);
os
<<
'_'
<<
catName
<<
'.'
<<
tagName
<<
' '
<<
item
->
mText
<<
endl
;
st
d
::
st
ring
tagName
=
category
->
getColumnName
(
item
->
mColumnIndex
);
os
<<
'_'
<<
catName
<<
'.'
<<
tagName
<<
' '
<<
item
->
mText
<<
std
::
endl
;
}
return
os
;
...
...
@@ -2818,7 +2817,7 @@ File::File()
{
}
File
::
File
(
istream
&
is
,
bool
validate
)
File
::
File
(
std
::
istream
&
is
,
bool
validate
)
:
File
()
{
load
(
is
);
...
...
@@ -2831,9 +2830,9 @@ File::File(const std::string& path, bool validate)
{
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
;
}
}
...
...
@@ -2880,9 +2879,9 @@ void File::load(const std::string& 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
())
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
;
std
::
string
ext
;
...
...
@@ -2904,9 +2903,9 @@ void File::load(const std::string& p)
{
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
;
}
}
...
...
@@ -2915,7 +2914,7 @@ void File::save(const std::string& 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
;
if
(
path
.
extension
()
==
".gz"
)
...
...
@@ -2933,7 +2932,7 @@ void File::save(const std::string& p)
save
(
out
);
}
void
File
::
load
(
istream
&
is
)
void
File
::
load
(
std
::
istream
&
is
)
{
Validator
*
saved
=
mValidator
;
setValidator
(
nullptr
);
...
...
@@ -2948,7 +2947,7 @@ void File::load(istream& is)
}
}
void
File
::
save
(
ostream
&
os
)
void
File
::
save
(
std
::
ostream
&
os
)
{
Datablock
*
e
=
mHead
;
while
(
e
!=
nullptr
)
...
...
@@ -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
;
while
(
e
!=
nullptr
)
...
...
@@ -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
;
while
(
result
!=
nullptr
and
not
iequals
(
result
->
mName
,
name
))
...
...
@@ -2976,13 +2975,13 @@ Datablock* File::get(const string& name) const
return
const_cast
<
Datablock
*>
(
result
);
}
Datablock
&
File
::
operator
[](
const
string
&
name
)
Datablock
&
File
::
operator
[](
const
st
d
::
st
ring
&
name
)
{
Datablock
*
result
=
mHead
;
while
(
result
!=
nullptr
and
not
iequals
(
result
->
mName
,
name
))
result
=
result
->
mNext
;
if
(
result
==
nullptr
)
throw
runtime_error
(
"Datablock "
+
name
+
" does not exist"
);
throw
std
::
runtime_error
(
"Datablock "
+
name
+
" does not exist"
);
return
*
result
;
}
...
...
@@ -2991,7 +2990,7 @@ bool File::isValid()
if
(
mValidator
==
nullptr
)
{
if
(
VERBOSE
)
cerr
<<
"No dictionary loaded explicitly, loading default"
<<
endl
;
std
::
cerr
<<
"No dictionary loaded explicitly, loading default"
<<
std
::
endl
;
loadDictionary
();
}
...
...
@@ -3011,7 +3010,7 @@ void File::validateLinks() const
const
Validator
&
File
::
getValidator
()
const
{
if
(
mValidator
==
nullptr
)
throw
runtime_error
(
"no Validator defined yet"
);
throw
std
::
runtime_error
(
"no Validator defined yet"
);
return
*
mValidator
;
}
...
...
@@ -3037,7 +3036,7 @@ void File::loadDictionary(const char* dict)
}
catch
(...)
{}
fs
::
path
dictFile
=
string
(
"dictionaries/"
)
+
dict
+
".dic"
;
fs
::
path
dictFile
=
st
d
::
st
ring
(
"dictionaries/"
)
+
dict
+
".dic"
;
try
{
...
...
@@ -3054,7 +3053,7 @@ void File::loadDictionary(const char* dict)
if
(
dictData
)
{
struct
membuf
:
public
streambuf
struct
membuf
:
public
st
d
::
st
reambuf
{
membuf
(
char
*
dict
,
size_t
length
)
{
...
...
@@ -3062,19 +3061,19 @@ void File::loadDictionary(const char* dict)
}
}
buffer
(
const_cast
<
char
*>
(
dictData
.
data
()),
dictData
.
size
());
istream
is
(
&
buffer
);
std
::
istream
is
(
&
buffer
);
loadDictionary
(
is
);
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
);
p
.
loadDictionary
();
...
...
@@ -3090,7 +3089,7 @@ void File::setValidator(Validator* v)
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
)
d
->
getTagOrder
(
tags
);
...
...
src/CifParser.cpp
View file @
4b4757ee
...
...
@@ -32,7 +32,6 @@
#include "cif++/CifParser.hpp"
#include "cif++/CifValidator.hpp"
using
namespace
std
;
namespace
ba
=
boost
::
algorithm
;
extern
int
VERBOSE
;
...
...
@@ -54,8 +53,8 @@ const uint8_t kCharTraitsTable[128] = {
// --------------------------------------------------------------------
CifParserError
::
CifParserError
(
uint32_t
lineNr
,
const
string
&
message
)
:
runtime_error
(
"parse error at line "
+
to_string
(
lineNr
)
+
": "
+
message
)
CifParserError
::
CifParserError
(
uint32_t
lineNr
,
const
st
d
::
st
ring
&
message
)
:
std
::
runtime_error
(
"parse error at line "
+
std
::
to_string
(
lineNr
)
+
": "
+
message
)
{
}
...
...
@@ -94,7 +93,7 @@ SacParser::SacParser(std::istream& is)
mLookahead
=
getNextToken
();
}
void
SacParser
::
error
(
const
string
&
msg
)
void
SacParser
::
error
(
const
st
d
::
st
ring
&
msg
)
{
throw
CifParserError
(
mLineNr
,
msg
);
}
...
...
@@ -130,11 +129,11 @@ int SacParser::getNextChar()
if
(
VERBOSE
>=
6
)
{
cerr
<<
"getNextChar => "
;
std
::
cerr
<<
"getNextChar => "
;
if
(
iscntrl
(
result
)
or
not
isprint
(
result
))
cerr
<<
int
(
result
)
<<
endl
;
std
::
cerr
<<
int
(
result
)
<<
std
::
endl
;
else
cerr
<<
char
(
result
)
<<
endl
;
std
::
cerr
<<
char
(
result
)
<<
std
::
endl
;
}
return
result
;
...
...
@@ -181,14 +180,14 @@ void SacParser::restart()
void
SacParser
::
match
(
SacParser
::
CIFToken
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
();
}
SacParser
::
CIFToken
SacParser
::
getNextToken
()
{
const
auto
kEOF
=
char_traits
<
char
>::
eof
();
const
auto
kEOF
=
std
::
char_traits
<
char
>::
eof
();
CIFToken
result
=
eCIFTokenUnknown
;
int
quoteChar
=
0
;
...
...
@@ -291,7 +290,7 @@ SacParser::CIFToken SacParser::getNextToken()
error
(
"unterminated textfield"
);
else
if
(
not
isAnyPrint
(
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
;
case
eStateTextField
+
1
:
...
...
@@ -469,7 +468,7 @@ SacParser::CIFToken SacParser::getNextToken()
case
eStateValue
+
1
:
if
(
ch
==
'_'
)
// first _, check for keywords
{
string
s
=
toLowerCopy
(
mTokenValue
);
st
d
::
st
ring
s
=
toLowerCopy
(
mTokenValue
);
if
(
s
==
"global_"
)
result
=
eCIFTokenGLOBAL
;
...
...
@@ -511,12 +510,12 @@ SacParser::CIFToken SacParser::getNextToken()
if
(
VERBOSE
>=
5
)
{
cerr
<<
kTokenName
[
result
];
std
::
cerr
<<
kTokenName
[
result
];
if
(
mTokenType
!=
eCIFValueUnknown
)
cerr
<<
' '
<<
kValueName
[
mTokenType
];
std
::
cerr
<<
' '
<<
kValueName
[
mTokenType
];
if
(
result
!=
eCIFTokenEOF
)
cerr
<<
" '"
<<
mTokenValue
<<
'\''
;
cerr
<<
endl
;
std
::
cerr
<<
" '"
<<
mTokenValue
<<
'\''
;
std
::
cerr
<<
std
::
endl
;
}
return
result
;
...
...
@@ -558,7 +557,7 @@ void SacParser::parseGlobal()
void
SacParser
::
parseDataBlock
()
{
string
cat
;
st
d
::
st
ring
cat
;
while
(
mLookahead
==
eCIFTokenLOOP
or
mLookahead
==
eCIFTokenTag
or
mLookahead
==
eCIFTokenSAVE
)
{
...
...
@@ -570,11 +569,11 @@ void SacParser::parseDataBlock()
match
(
eCIFTokenLOOP
);
vector
<
string
>
tags
;
std
::
vector
<
std
::
string
>
tags
;
while
(
mLookahead
==
eCIFTokenTag
)
{
string
catName
,
itemName
;
st
d
::
st
ring
catName
,
itemName
;
std
::
tie
(
catName
,
itemName
)
=
splitTagName
(
mTokenValue
);
if
(
cat
.
empty
())
...
...
@@ -607,7 +606,7 @@ void SacParser::parseDataBlock()
case
eCIFTokenTag
:
{
string
catName
,
itemName
;
st
d
::
st
ring
catName
,
itemName
;
std
::
tie
(
catName
,
itemName
)
=
splitTagName
(
mTokenValue
);
if
(
not
iequals
(
cat
,
catName
))
...
...
@@ -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
);
mFile
.
append
(
mDataBlock
);
}
void
Parser
::
produceCategory
(
const
string
&
name
)
void
Parser
::
produceCategory
(
const
st
d
::
st
ring
&
name
)
{
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
()
{
if
(
VERBOSE
>=
4
)
cerr
<<
"producing row for category "
<<
mCat
->
name
()
<<
endl
;
std
::
cerr
<<
"producing row for category "
<<
mCat
->
name
()
<<
std
::
endl
;
mCat
->
emplace
({});
mRow
=
mCat
->
back
();
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
)
cerr
<<
"producing _"
<<
category
<<
'.'
<<
item
<<
" -> "
<<
value
<<
endl
;
std
::
cerr
<<
"producing _"
<<
category
<<
'.'
<<
item
<<
" -> "
<<
value
<<
std
::
endl
;
if
(
not
iequals
(
category
,
mCat
->
name
()))
error
(
"inconsistent categories in loop_"
);
...
...
@@ -688,9 +687,9 @@ void Parser::produceItem(const string& category, const string& item, const strin
struct
DictParserDataImpl
{
// temporary values for constructing dictionaries
vector
<
ValidateCategory
>
mCategoryValidators
;
map
<
string
,
vector
<
ValidateItem
>>
mItemValidators
;
s
et
<
tuple
<
string
,
string
>>
mLinkedItems
;
std
::
vector
<
ValidateCategory
>
mCategoryValidators
;
std
::
map
<
std
::
string
,
std
::
vector
<
ValidateItem
>>
mItemValidators
;
s
td
::
set
<
std
::
tuple
<
std
::
string
,
std
::
string
>>
mLinkedItems
;
};
DictParser
::
DictParser
(
Validator
&
validator
,
std
::
istream
&
is
)
...
...
@@ -708,7 +707,7 @@ void DictParser::parseSaveFrame()
if
(
not
mCollectedItemTypes
)
mCollectedItemTypes
=
collectItemTypes
();
string
saveFrameName
=
mTokenValue
;
st
d
::
st
ring
saveFrameName
=
mTokenValue
;
if
(
saveFrameName
.
empty
())
error
(
"Invalid save frame, should contain more than just 'save_' here"
);
...
...
@@ -727,14 +726,14 @@ void DictParser::parseSaveFrame()
match
(
eCIFTokenLOOP
);
vector
<
string
>
tags
;
std
::
vector
<
std
::
string
>
tags
;
while
(
mLookahead
==
eCIFTokenTag
)
{
string
catName
,
itemName
;
st
d
::
st
ring
catName
,
itemName
;
std
::
tie
(
catName
,
itemName
)
=
splitTagName
(
mTokenValue
);
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
))
error
(
"inconsistent categories in loop_"
);
...
...
@@ -758,11 +757,11 @@ void DictParser::parseSaveFrame()
}
else
{
string
catName
,
itemName
;
st
d
::
st
ring
catName
,
itemName
;
std
::
tie
(
catName
,
itemName
)
=
splitTagName
(
mTokenValue
);
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
);
...
...
@@ -778,22 +777,22 @@ void DictParser::parseSaveFrame()
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"
])
keys
.
push_back
(
get
<
1
>
(
splitTagName
(
k
[
"name"
].
as
<
string
>
())));
keys
.
push_back
(
std
::
get
<
1
>
(
splitTagName
(
k
[
"name"
].
as
<
std
::
string
>
())));
iset
groups
;
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
});
}
else
{
// 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
;
if
(
not
(
typeCode
.
empty
()
or
typeCode
==
"?"
))
...
...
@@ -801,9 +800,9 @@ void DictParser::parseSaveFrame()
iset
ess
;
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
;
if
(
defaultValue
.
empty
())
{
...
...
@@ -817,11 +816,11 @@ void DictParser::parseSaveFrame()
// collect the dict from our dataBlock and construct validators
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"
);
string
catName
,
itemName
;
st
d
::
st
ring
catName
,
itemName
;
std
::
tie
(
catName
,
itemName
)
=
splitTagName
(
tagName
);
if
(
catName
.
empty
()
or
itemName
.
empty
())
...
...
@@ -844,12 +843,12 @@ void DictParser::parseSaveFrame()
{
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
))
cerr
<<
"choosing "
<<
mandatory
<<
endl
;
std
::
cerr
<<
"choosing "
<<
mandatory
<<
std
::
endl
;
else
cerr
<<
"choosing "
<<
(
vi
->
mMandatory
?
"Y"
:
"N"
)
<<
endl
;
std
::
cerr
<<
"choosing "
<<
(
vi
->
mMandatory
?
"Y"
:
"N"
)
<<
std
::
endl
;
}
if
(
iequals
(
tagName
,
saveFrameName
))
...
...
@@ -859,7 +858,7 @@ void DictParser::parseSaveFrame()
if
(
vi
->
mType
!=
nullptr
and
tv
!=
nullptr
and
vi
->
mType
!=
tv
)
{
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"));
...
...
@@ -876,7 +875,7 @@ void DictParser::parseSaveFrame()
// collect the dict from our dataBlock and construct validators
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"
);
...
...
@@ -892,12 +891,12 @@ void DictParser::linkItems()
auto
&
dict
=
*
mDataBlock
;
map
<
tuple
<
string
,
string
,
int
>
,
size_t
>
linkIndex
;
vector
<
tuple
<
vector
<
string
>
,
vector
<
string
>>>
linkKeys
;
std
::
map
<
std
::
tuple
<
std
::
string
,
std
::
string
,
int
>
,
size_t
>
linkIndex
;
std
::
vector
<
std
::
tuple
<
std
::
vector
<
std
::
string
>
,
std
::
vector
<
std
::
string
>>>
linkKeys
;
for
(
auto
gl
:
dict
[
"pdbx_item_linked_group_list"
])
{
string
child
,
parent
;
st
d
::
st
ring
child
,
parent
;
int
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()
size_t
ix
=
linkIndex
.
at
(
key
);
get
<
0
>
(
linkKeys
.
at
(
ix
)).
push_back
(
piv
->
mTag
);
get
<
1
>
(
linkKeys
.
at
(
ix
)).
push_back
(
civ
->
mTag
);
std
::
get
<
0
>
(
linkKeys
.
at
(
ix
)).
push_back
(
piv
->
mTag
);
std
::
get
<
1
>
(
linkKeys
.
at
(
ix
)).
push_back
(
civ
->
mTag
);
}
// for (auto li: mImpl->mLinkedItems)
// {
// string child, parent;
// st
d::st
ring child, parent;
// std::tie(child, parent) = li;
//
// auto civ = mValidator.getValidatorForItem(child);
...
...
@@ -961,11 +960,11 @@ void DictParser::linkItems()
// look up the label
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
;
}
mValidator
.
addLinkValidator
(
move
(
link
));
mValidator
.
addLinkValidator
(
std
::
move
(
link
));
}
// now make sure the itemType is specified for all itemValidators
...
...
@@ -975,14 +974,14 @@ void DictParser::linkItems()
for
(
auto
&
iv
:
cv
.
mItemValidators
)
{
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
()
{
unique_ptr
<
Datablock
>
dict
;
std
::
unique_ptr
<
Datablock
>
dict
;
Datablock
*
savedDatablock
=
mDataBlock
;
try
...
...
@@ -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
;
}
// store all validators
for
(
auto
&
ic
:
mImpl
->
mCategoryValidators
)
mValidator
.
addCategoryValidator
(
move
(
ic
));
mValidator
.
addCategoryValidator
(
std
::
move
(
ic
));
mImpl
->
mCategoryValidators
.
clear
();
for
(
auto
&
iv
:
mImpl
->
mItemValidators
)
...
...
@@ -1025,7 +1024,7 @@ void DictParser::loadDictionary()
error
(
"Undefined category '"
+
iv
.
first
);
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
...
...
@@ -1040,8 +1039,8 @@ void DictParser::loadDictionary()
if
(
n
)
{
auto
r
=
info
->
front
();
mValidator
.
dictName
(
r
[
"title"
].
as
<
string
>
());
mValidator
.
dictVersion
(
r
[
"version"
].
as
<
string
>
());
mValidator
.
dictName
(
r
[
"title"
].
as
<
st
d
::
st
ring
>
());
mValidator
.
dictVersion
(
r
[
"version"
].
as
<
st
d
::
st
ring
>
());
}
mDataBlock
=
savedDatablock
;
...
...
@@ -1060,7 +1059,7 @@ bool DictParser::collectItemTypes()
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"
);
ba
::
replace_all
(
construct
,
"
\\
n"
,
"
\n
"
);
...
...
@@ -1073,9 +1072,9 @@ bool DictParser::collectItemTypes()
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"
));
}
...
...
@@ -1086,7 +1085,7 @@ bool DictParser::collectItemTypes()
// mFileImpl.mTypeValidators.erase(v);
if
(
VERBOSE
>=
5
)
cerr
<<
"Added type "
<<
code
<<
" ("
<<
primitiveCode
<<
") => "
<<
construct
<<
endl
;
std
::
cerr
<<
"Added type "
<<
code
<<
" ("
<<
primitiveCode
<<
") => "
<<
construct
<<
std
::
endl
;
result
=
true
;
}
...
...
src/CifUtils.cpp
View file @
4b4757ee
...
...
@@ -47,7 +47,6 @@
#include "cif++/CifUtils.hpp"
using
namespace
std
;
namespace
ba
=
boost
::
algorithm
;
namespace
cif
...
...
@@ -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
();
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)
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
;
auto
ai
=
a
.
begin
(),
bi
=
b
.
begin
();
...
...
@@ -134,15 +133,15 @@ int icompare(const char* a, const char* b)
return
d
;
}
void
toLower
(
string
&
s
)
void
toLower
(
st
d
::
st
ring
&
s
)
{
for
(
auto
&
c
:
s
)
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
)
c
=
tolower
(
c
);
return
result
;
...
...
@@ -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
())
throw
runtime_error
(
"empty tag"
);
throw
std
::
runtime_error
(
"empty tag"
);
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
(
'.'
);
if
(
s
==
string
::
npos
)
throw
runtime_error
(
"tag does not contain dot"
);
return
tuple
<
string
,
string
>
{
if
(
s
==
st
d
::
st
ring
::
npos
)
throw
std
::
runtime_error
(
"tag does not contain dot"
);
return
std
::
tuple
<
std
::
string
,
std
::
string
>
{
tag
.
substr
(
1
,
s
-
1
),
tag
.
substr
(
s
+
1
)
};
}
...
...
@@ -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
};
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
)
return
text
;
...
...
@@ -329,10 +328,10 @@ string::const_iterator nextLineBreak(string::const_iterator text, string::const_
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
;
vector
<
size_t
>
offsets
=
{
0
};
std
::
vector
<
std
::
string
>
result
;
std
::
vector
<
size_t
>
offsets
=
{
0
};
auto
b
=
text
.
begin
();
while
(
b
!=
text
.
end
())
...
...
@@ -346,9 +345,9 @@ vector<string> wrapLine(const string& text, unsigned int width)
size_t
count
=
offsets
.
size
()
-
1
;
vector
<
size_t
>
minima
(
count
+
1
,
1000000
);
std
::
vector
<
size_t
>
minima
(
count
+
1
,
1000000
);
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
)
{
...
...
@@ -390,12 +389,12 @@ vector<string> wrapLine(const string& text, unsigned int width)
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
"
));
vector
<
string
>
result
;
std
::
vector
<
std
::
string
>
result
;
for
(
auto
&
p
:
paragraphs
)
{
if
(
p
.
empty
())
...
...
@@ -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...
string
GetExecutablePath
()
st
d
::
st
ring
GetExecutablePath
()
{
WCHAR
buffer
[
4096
];
...
...
@@ -430,7 +429,7 @@ string GetExecutablePath()
wstring
ws
(
buffer
);
return
string
(
ws
.
begin
(),
ws
.
end
());
return
st
d
::
st
ring
(
ws
.
begin
(),
ws
.
end
());
}
#else
...
...
@@ -447,11 +446,13 @@ uint32_t get_terminal_width()
return
result
;
}
string
get_executable_path
()
st
d
::
st
ring
get_executable_path
()
{
using
namespace
std
::
literals
;
char
path
[
PATH_MAX
]
=
""
;
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
};
}
...
...
@@ -461,7 +462,7 @@ string get_executable_path()
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
)
,
mThread
(
std
::
bind
(
&
ProgressImpl
::
Run
,
this
))
,
mStart
(
boost
::
posix_time
::
second_clock
::
local_time
())
{}
...
...
@@ -478,10 +479,10 @@ struct ProgressImpl
void
PrintDone
();
int64_t
mMax
;
atomic
<
int64_t
>
mConsumed
;
std
::
atomic
<
int64_t
>
mConsumed
;
int64_t
mLastConsumed
=
0
;
int
mSpinnerIndex
=
0
;
string
mAction
,
mMessage
;
st
d
::
st
ring
mAction
,
mMessage
;
std
::
mutex
mMutex
;
std
::
thread
mThread
;
boost
::
timer
::
cpu_timer
mTimer
;
...
...
@@ -549,7 +550,7 @@ void ProgressImpl::PrintProgress()
uint32_t
width
=
get_terminal_width
();
string
msg
;
st
d
::
st
ring
msg
;
msg
.
reserve
(
width
+
1
);
if
(
mMessage
.
length
()
<=
20
)
{
...
...
@@ -604,23 +605,23 @@ void ProgressImpl::PrintProgress()
// msg += to_string(perc);
// msg += '%';
cout
<<
'\r'
<<
msg
;
cout
.
flush
();
std
::
cout
<<
'\r'
<<
msg
;
std
::
cout
.
flush
();
}
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
();
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
)
{
if
(
isatty
(
STDOUT_FILENO
))
...
...
src/CifValidator.cpp
View file @
4b4757ee
...
...
@@ -34,7 +34,6 @@
#include "cif++/CifParser.hpp"
#include "cif++/CifValidator.hpp"
using
namespace
std
;
namespace
ba
=
boost
::
algorithm
;
extern
int
VERBOSE
;
...
...
@@ -42,19 +41,19 @@ extern int VERBOSE;
namespace
cif
{
ValidationError
::
ValidationError
(
const
string
&
msg
)
ValidationError
::
ValidationError
(
const
st
d
::
st
ring
&
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
)
{
}
// --------------------------------------------------------------------
DDL_PrimitiveType
mapToPrimitiveType
(
const
string
&
s
)
DDL_PrimitiveType
mapToPrimitiveType
(
const
st
d
::
st
ring
&
s
)
{
DDL_PrimitiveType
result
;
if
(
iequals
(
s
,
"char"
))
...
...
@@ -90,7 +89,7 @@ int ValidateType::compare(const char* a, const char* b) const
double
db
=
strtod
(
b
,
nullptr
);
auto
d
=
da
-
db
;
if
(
abs
(
d
)
>
numeric_limits
<
double
>::
epsilon
())
if
(
std
::
abs
(
d
)
>
std
::
numeric_limits
<
double
>::
epsilon
())
{
if
(
d
>
0
)
result
=
1
;
...
...
@@ -177,12 +176,12 @@ int ValidateType::compare(const char* a, const char* b) const
//
// parent->mChildren.insert(this);
////
//// if (mCategory->mKeys ==
vector<
string>{mTag})
//// if (mCategory->mKeys ==
std::vector<std::
string>{mTag})
//// 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
!=
"."
)
{
...
...
@@ -206,19 +205,19 @@ void ValidateCategory::addItemValidator(ValidateItem&& v)
v
.
mCategory
=
this
;
auto
r
=
mItemValidators
.
insert
(
move
(
v
));
auto
r
=
mItemValidators
.
insert
(
std
::
move
(
v
));
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
;
auto
i
=
mItemValidators
.
find
(
ValidateItem
{
tag
});
if
(
i
!=
mItemValidators
.
end
())
result
=
&*
i
;
else
if
(
VERBOSE
>
4
)
cout
<<
"No validator for tag "
<<
tag
<<
endl
;
std
::
cout
<<
"No validator for tag "
<<
tag
<<
std
::
endl
;
return
result
;
}
...
...
@@ -234,12 +233,12 @@ Validator::~Validator()
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
)
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
;
...
...
@@ -247,33 +246,33 @@ const ValidateType* Validator::getValidatorForType(string typeCode) const
if
(
i
!=
mTypeValidators
.
end
())
result
=
&*
i
;
else
if
(
VERBOSE
>
4
)
cout
<<
"No validator for type "
<<
typeCode
<<
endl
;
std
::
cout
<<
"No validator for type "
<<
typeCode
<<
std
::
endl
;
return
result
;
}
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
)
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
;
auto
i
=
mCategoryValidators
.
find
(
ValidateCategory
{
category
});
if
(
i
!=
mCategoryValidators
.
end
())
result
=
&*
i
;
else
if
(
VERBOSE
>
4
)
cout
<<
"No validator for category "
<<
category
<<
endl
;
std
::
cout
<<
"No validator for category "
<<
category
<<
std
::
endl
;
return
result
;
}
ValidateItem
*
Validator
::
getValidatorForItem
(
string
tag
)
const
ValidateItem
*
Validator
::
getValidatorForItem
(
st
d
::
st
ring
tag
)
const
{
ValidateItem
*
result
=
nullptr
;
string
cat
,
item
;
st
d
::
st
ring
cat
,
item
;
std
::
tie
(
cat
,
item
)
=
splitTagName
(
tag
);
auto
*
cv
=
getValidatorForCategory
(
cat
);
...
...
@@ -281,7 +280,7 @@ ValidateItem* Validator::getValidatorForItem(string tag) const
result
=
const_cast
<
ValidateItem
*>
(
cv
->
getValidatorForItem
(
item
));
if
(
result
==
nullptr
and
VERBOSE
>
4
)
cout
<<
"No validator for item "
<<
tag
<<
endl
;
std
::
cout
<<
"No validator for item "
<<
tag
<<
std
::
endl
;
return
result
;
}
...
...
@@ -290,38 +289,38 @@ void Validator::addLinkValidator(ValidateLink&& v)
{
assert
(
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
ccv
=
getValidatorForCategory
(
v
.
mChildCategory
);
if
(
pcv
==
nullptr
)
throw
runtime_error
(
"unknown parent category "
+
v
.
mParentCategory
);
throw
std
::
runtime_error
(
"unknown parent category "
+
v
.
mParentCategory
);
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
)
{
auto
piv
=
pcv
->
getValidatorForItem
(
v
.
mParentKeys
[
i
]);
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
]);
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
)
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
)
{
...
...
@@ -332,9 +331,9 @@ vector<const ValidateLink*> Validator::getLinksForParent(const string& category)
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
)
{
...
...
@@ -345,12 +344,12 @@ vector<const ValidateLink*> Validator::getLinksForChild(const string& category)
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
)
throw
ValidationError
(
msg
);
else
if
(
VERBOSE
)
cerr
<<
msg
<<
endl
;
std
::
cerr
<<
msg
<<
std
::
endl
;
}
}
src/Compound.cpp
View file @
4b4757ee
...
...
@@ -32,21 +32,15 @@
#include <boost/algorithm/string.hpp>
#if __has_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++/Point.hpp"
#include "cif++/Compound.hpp"
#include "cif++/CifUtils.hpp"
using
namespace
std
;
namespace
ba
=
boost
::
algorithm
;
namespace
fs
=
std
::
filesystem
;
namespace
mmcif
{
...
...
@@ -83,12 +77,12 @@ struct CompoundBondLess
struct
IsomerSet
{
vector
<
string
>
compounds
;
std
::
vector
<
std
::
string
>
compounds
;
};
struct
IsomerSets
{
vector
<
IsomerSet
>
isomers
;
std
::
vector
<
IsomerSet
>
isomers
;
};
class
IsomerDB
...
...
@@ -97,8 +91,8 @@ class IsomerDB
static
IsomerDB
&
instance
();
size_t
count
(
const
string
&
compound
)
const
;
const
vector
<
string
>&
operator
[](
const
string
&
compound
)
const
;
size_t
count
(
const
st
d
::
st
ring
&
compound
)
const
;
const
std
::
vector
<
std
::
string
>&
operator
[](
const
std
::
string
&
compound
)
const
;
private
:
...
...
@@ -111,14 +105,14 @@ IsomerDB::IsomerDB()
{
auto
isomers
=
cif
::
rsrc_loader
::
load
(
"isomers.txt"
);
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
);
}
}
buffer
(
const_cast
<
char
*>
(
isomers
.
data
()),
isomers
.
size
());
istream
is
(
&
buffer
);
std
::
istream
is
(
&
buffer
);
// #else
// cerr << "resource support was not compiled in, falling back to a local file" << endl;
// fs::path isomersFile = "isomers.txt";
...
...
@@ -127,12 +121,12 @@ IsomerDB::IsomerDB()
// fs::ifstream is(isomersFile);
// 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
string
line
;
st
d
::
st
ring
line
;
while
(
getline
(
is
,
line
))
while
(
std
::
getline
(
is
,
line
))
{
IsomerSet
compounds
;
ba
::
split
(
compounds
.
compounds
,
line
,
ba
::
is_any_of
(
":"
));
...
...
@@ -148,7 +142,7 @@ IsomerDB& IsomerDB::instance()
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
;
for
(
auto
&
d
:
mData
.
isomers
)
...
...
@@ -159,7 +153,7 @@ size_t IsomerDB::count(const string& compound) const
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
)
{
...
...
@@ -167,7 +161,7 @@ const vector<string>& IsomerDB::operator[](const string& compound) const
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
struct
Node
{
string
id
;
st
d
::
st
ring
id
;
AtomType
symbol
;
vector
<
tuple
<
size_t
,
BondType
>>
links
;
std
::
vector
<
std
::
tuple
<
size_t
,
BondType
>>
links
;
size_t
hydrogens
=
0
;
};
// Check to see if the nodes a[iA] and b[iB] are the start of a similar sub structure
bool
SubStructuresAreIsomeric
(
const
vector
<
Node
>&
a
,
const
vector
<
Node
>&
b
,
size_t
iA
,
size_t
iB
,
vector
<
bool
>
visitedA
,
vector
<
bool
>
visitedB
,
vector
<
tuple
<
string
,
string
>>&
outMapping
)
const
std
::
vector
<
Node
>&
a
,
const
std
::
vector
<
Node
>&
b
,
size_t
iA
,
size_t
iB
,
std
::
vector
<
bool
>
visitedA
,
std
::
vector
<
bool
>
visitedB
,
std
::
vector
<
std
::
tuple
<
std
::
string
,
std
::
string
>>&
outMapping
)
{
auto
&
na
=
a
[
iA
];
auto
&
nb
=
b
[
iB
];
...
...
@@ -204,21 +198,21 @@ bool SubStructuresAreIsomeric(
// we now have two sets of links to compare.
// 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
);
for
(;;)
{
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
)
{
size_t
lA
,
lB
;
BondType
typeA
,
typeB
;
tie
(
lA
,
typeA
)
=
na
.
links
[
i
];
assert
(
lA
<
a
.
size
());
tie
(
lB
,
typeB
)
=
nb
.
links
[
ilb
[
i
]];
assert
(
lB
<
b
.
size
());
std
::
tie
(
lA
,
typeA
)
=
na
.
links
[
i
];
assert
(
lA
<
a
.
size
());
std
::
tie
(
lB
,
typeB
)
=
nb
.
links
[
ilb
[
i
]];
assert
(
lB
<
b
.
size
());
if
(
typeA
!=
typeB
or
visitedA
[
lA
]
!=
visitedB
[
lB
])
{
...
...
@@ -255,15 +249,15 @@ bool SubStructuresAreIsomeric(
return
result
;
}
bool
StructuresAreIsomeric
(
vector
<
CompoundAtom
>
atomsA
,
const
vector
<
CompoundBond
>&
bondsA
,
vector
<
CompoundAtom
>
atomsB
,
const
vector
<
CompoundBond
>&
bondsB
,
vector
<
tuple
<
string
,
string
>>&
outMapping
)
bool
StructuresAreIsomeric
(
std
::
vector
<
CompoundAtom
>
atomsA
,
const
std
::
vector
<
CompoundBond
>&
bondsA
,
std
::
vector
<
CompoundAtom
>
atomsB
,
const
std
::
vector
<
CompoundBond
>&
bondsB
,
std
::
vector
<
std
::
tuple
<
std
::
string
,
std
::
string
>>&
outMapping
)
{
assert
(
atomsA
.
size
()
==
atomsB
.
size
());
assert
(
bondsA
.
size
()
==
bondsB
.
size
());
vector
<
Node
>
a
,
b
;
map
<
string
,
size_t
>
ma
,
mb
;
std
::
vector
<
Node
>
a
,
b
;
std
::
map
<
std
::
string
,
size_t
>
ma
,
mb
;
for
(
auto
&
atomA
:
atomsA
)
{
...
...
@@ -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
())
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
))
{
...
...
@@ -350,7 +344,7 @@ Compound::Compound(const std::string& file, const std::string& id,
for
(
auto
row
:
compoundAtoms
)
{
string
id
,
symbol
,
energy
;
st
d
::
st
ring
id
,
symbol
,
energy
;
float
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,
for
(
auto
row
:
compBonds
)
{
CompoundBond
b
;
string
type
,
aromatic
;
st
d
::
st
ring
type
,
aromatic
;
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"
);
...
...
@@ -381,7 +375,7 @@ Compound::Compound(const std::string& file, const std::string& id,
else
{
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
;
}
...
...
@@ -415,7 +409,7 @@ Compound::Compound(const std::string& file, const std::string& id,
for
(
auto
row
:
db
[
"chem_comp_chir"
])
{
CompoundChiralCentre
cc
;
string
volumeSign
;
st
d
::
st
ring
volumeSign
;
cif
::
tie
(
cc
.
id
,
cc
.
atomIDCentre
,
cc
.
atomID
[
0
],
cc
.
atomID
[
1
],
cc
.
atomID
[
2
],
volumeSign
)
=
...
...
@@ -431,7 +425,7 @@ Compound::Compound(const std::string& file, const std::string& id,
else
{
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
;
}
...
...
@@ -442,7 +436,7 @@ Compound::Compound(const std::string& file, const std::string& id,
for
(
auto
row
:
compPlanes
)
{
string
atom_id
,
plane_id
;
st
d
::
st
ring
atom_id
,
plane_id
;
float
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,
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
;
}
}
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
;
for
(
auto
r
:
mAtoms
)
...
...
@@ -480,7 +474,7 @@ string Compound::formula() const
result
=
"C"
;
if
(
c
->
second
>
1
)
result
+=
to_string
(
c
->
second
);
result
+=
std
::
to_string
(
c
->
second
);
atoms
.
erase
(
c
);
...
...
@@ -489,7 +483,7 @@ string Compound::formula() const
{
result
+=
" H"
;
if
(
h
->
second
>
1
)
result
+=
to_string
(
h
->
second
);
result
+=
std
::
to_string
(
h
->
second
);
atoms
.
erase
(
h
);
}
...
...
@@ -502,12 +496,12 @@ string Compound::formula() const
result
+=
a
.
first
;
if
(
a
.
second
>
1
)
result
+=
to_string
(
a
.
second
);
result
+=
std
::
to_string
(
a
.
second
);
}
int
charge
=
lrint
(
chargeSum
);
if
(
charge
!=
0
)
result
+=
' '
+
to_string
(
charge
);
result
+=
' '
+
std
::
to_string
(
charge
);
return
result
;
}
...
...
@@ -532,9 +526,9 @@ int Compound::charge() const
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)
...
...
@@ -579,7 +573,7 @@ bool Compound::isSugar() const
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
=
{};
for
(
auto
&
a
:
mAtoms
)
...
...
@@ -592,12 +586,12 @@ CompoundAtom Compound::getAtomByID(const string& atomID) const
}
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
;
}
const
Compound
*
Compound
::
create
(
const
string
&
id
)
const
Compound
*
Compound
::
create
(
const
st
d
::
st
ring
&
id
)
{
auto
result
=
CompoundFactory
::
instance
().
get
(
id
);
if
(
result
==
nullptr
)
...
...
@@ -605,7 +599,7 @@ const Compound* Compound::create(const string& id)
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
(),
[
&
](
const
CompoundBond
&
b
)
...
...
@@ -617,7 +611,7 @@ bool Compound::atomsBonded(const string& atomId_1, const string& atomId_2) const
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
(),
[
&
](
const
CompoundBond
&
b
)
...
...
@@ -652,7 +646,7 @@ bool Compound::isIsomerOf(const Compound& c) const
break
;
// same number of atoms of each type?
map
<
AtomType
,
int
>
aTypeCount
,
bTypeCount
;
std
::
map
<
AtomType
,
int
>
aTypeCount
,
bTypeCount
;
bool
sameAtomNames
=
true
;
for
(
size_t
i
=
0
;
i
<
mAtoms
.
size
();
++
i
)
...
...
@@ -687,13 +681,13 @@ bool Compound::isIsomerOf(const Compound& c) const
// 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
);
if
(
cif
::
VERBOSE
and
result
)
{
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
;
...
...
@@ -702,20 +696,20 @@ bool Compound::isIsomerOf(const Compound& c) const
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
);
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
;
}
vector
<
string
>
Compound
::
isomers
()
const
std
::
vector
<
std
::
string
>
Compound
::
isomers
()
const
{
vector
<
string
>
result
;
std
::
vector
<
std
::
string
>
result
;
auto
&
db
=
IsomerDB
::
instance
();
if
(
db
.
count
(
mID
))
...
...
@@ -731,7 +725,7 @@ vector<string> Compound::isomers() const
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"
);
...
...
@@ -759,7 +753,7 @@ float Compound::bondAngle(const string& atomId_1, const string& atomId_2, const
// return c;
//}
float
Compound
::
chiralVolume
(
const
string
&
centreID
)
const
float
Compound
::
chiralVolume
(
const
st
d
::
st
ring
&
centreID
)
const
{
float
result
=
0
;
...
...
@@ -808,7 +802,7 @@ Link::Link(cif::Datablock& db)
for
(
auto
row
:
linkBonds
)
{
LinkBond
b
;
string
type
,
aromatic
;
st
d
::
st
ring
type
,
aromatic
;
cif
::
tie
(
b
.
atom
[
0
].
compID
,
b
.
atom
[
0
].
atomID
,
b
.
atom
[
1
].
compID
,
b
.
atom
[
1
].
atomID
,
type
,
b
.
distance
,
b
.
esd
)
=
...
...
@@ -825,7 +819,7 @@ Link::Link(cif::Datablock& db)
else
{
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
;
}
...
...
@@ -867,7 +861,7 @@ Link::Link(cif::Datablock& db)
for
(
auto
row
:
linkChir
)
{
LinkChiralCentre
cc
;
string
volumeSign
;
st
d
::
st
ring
volumeSign
;
cif
::
tie
(
cc
.
id
,
cc
.
atomCentre
.
compID
,
cc
.
atomCentre
.
atomID
,
cc
.
atom
[
0
].
compID
,
cc
.
atom
[
0
].
atomID
,
...
...
@@ -887,7 +881,7 @@ Link::Link(cif::Datablock& db)
else
{
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
;
}
...
...
@@ -898,7 +892,7 @@ Link::Link(cif::Datablock& db)
for
(
auto
row
:
linkPlanes
)
{
int
compID
;
string
atomID
,
planeID
;
st
d
::
st
ring
atomID
,
planeID
;
float
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)
auto
i
=
find_if
(
mPlanes
.
begin
(),
mPlanes
.
end
(),
[
&
](
auto
&
p
)
{
return
p
.
id
==
planeID
;});
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
});
}
else
...
...
@@ -921,7 +915,7 @@ const Link& Link::create(const std::string& id)
result
=
CompoundFactory
::
instance
().
createLink
(
id
);
if
(
result
==
nullptr
)
throw
runtime_error
(
"Link with id "
+
id
+
" not found"
);
throw
std
::
runtime_error
(
"Link with id "
+
id
+
" not found"
);
return
*
result
;
}
...
...
@@ -960,7 +954,7 @@ float Link::bondAngle(const LinkAtom& atom1, const LinkAtom& atom2, const LinkAt
return
result
;
}
float
Link
::
chiralVolume
(
const
string
&
centreID
)
const
float
Link
::
chiralVolume
(
const
st
d
::
st
ring
&
centreID
)
const
{
float
result
=
0
;
...
...
@@ -1001,7 +995,7 @@ float Link::chiralVolume(const string& centreID) const
// --------------------------------------------------------------------
// a factory class to generate compounds
const
map
<
string
,
char
>
kAAMap
{
const
std
::
map
<
std
::
string
,
char
>
kAAMap
{
{
"ALA"
,
'A'
},
{
"ARG"
,
'R'
},
{
"ASN"
,
'N'
},
...
...
@@ -1026,7 +1020,7 @@ const map<string,char> kAAMap{
{
"ASX"
,
'B'
}
};
const
map
<
string
,
char
>
kBaseMap
{
const
std
::
map
<
std
::
string
,
char
>
kBaseMap
{
{
"A"
,
'A'
},
{
"C"
,
'C'
},
{
"G"
,
'G'
},
...
...
@@ -1050,8 +1044,8 @@ class CompoundFactoryImpl
delete
mNext
;
}
Compound
*
get
(
string
id
);
Compound
*
create
(
string
id
);
Compound
*
get
(
st
d
::
st
ring
id
);
Compound
*
create
(
st
d
::
st
ring
id
);
const
Link
*
getLink
(
std
::
string
id
);
const
Link
*
createLink
(
std
::
string
id
);
...
...
@@ -1064,18 +1058,18 @@ class CompoundFactoryImpl
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"
];
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
;
result
=
synonym
[
"comp_id"
].
as
<
string
>
();
result
=
synonym
[
"comp_id"
].
as
<
st
d
::
st
ring
>
();
ba
::
trim
(
result
);
break
;
}
...
...
@@ -1086,13 +1080,13 @@ class CompoundFactoryImpl
return
result
;
}
bool
isKnownPeptide
(
const
string
&
resName
)
bool
isKnownPeptide
(
const
st
d
::
st
ring
&
resName
)
{
return
mKnownPeptides
.
count
(
resName
)
or
(
mNext
!=
nullptr
and
mNext
->
isKnownPeptide
(
resName
));
}
bool
isKnownBase
(
const
string
&
resName
)
bool
isKnownBase
(
const
st
d
::
st
ring
&
resName
)
{
return
mKnownBases
.
count
(
resName
)
or
(
mNext
!=
nullptr
and
mNext
->
isKnownBase
(
resName
));
...
...
@@ -1102,11 +1096,11 @@ class CompoundFactoryImpl
std
::
shared_timed_mutex
mMutex
;
std
::
string
mPath
;
vector
<
Compound
*>
mCompounds
;
vector
<
const
Link
*>
mLinks
;
/*unordered_*/
s
et
<
string
>
mKnownPeptides
;
s
et
<
string
>
mKnownBases
;
s
et
<
string
>
mMissing
;
std
::
vector
<
Compound
*>
mCompounds
;
std
::
vector
<
const
Link
*>
mLinks
;
/*unordered_*/
s
td
::
set
<
std
::
string
>
mKnownPeptides
;
s
td
::
set
<
std
::
string
>
mKnownBases
;
s
td
::
set
<
std
::
string
>
mMissing
;
cif
::
File
mFile
;
cif
::
Category
&
mChemComp
;
CompoundFactoryImpl
*
mNext
;
...
...
@@ -1121,7 +1115,7 @@ CompoundFactoryImpl::CompoundFactoryImpl(const std::string& file, CompoundFactor
for
(
auto
&
chemComp
:
mChemComp
)
{
string
group
,
threeLetterCode
;
st
d
::
st
ring
group
,
threeLetterCode
;
cif
::
tie
(
group
,
threeLetterCode
)
=
chemComp
.
get
(
"group"
,
"three_letter_code"
);
...
...
@@ -1136,17 +1130,17 @@ CompoundFactoryImpl::CompoundFactoryImpl(const std::string& file, CompoundFactor
//{
// CompoundFactoryImpl();
//
// Compound* get(string id);
// Compound* create(string id);
// Compound* get(st
d::st
ring id);
// Compound* create(st
d::st
ring id);
//
// void pushDictionary(const boost::filesystem::path& dictFile);
//
// // 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;
// fs::path mClibdMon;
// vector<Compound*> mCompounds;
//
std::
vector<Compound*> mCompounds;
// boost::shared_mutex mMutex;
//};
//
...
...
@@ -1154,7 +1148,7 @@ CompoundFactoryImpl::CompoundFactoryImpl(const std::string& file, CompoundFactor
//{
// const char* clibdMon = getenv("CLIBD_MON");
// 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;
//}
//
...
...
@@ -1165,7 +1159,7 @@ CompoundFactoryImpl::CompoundFactoryImpl(const std::string& file, CompoundFactor
// 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;
//
...
...
@@ -1195,7 +1189,7 @@ CompoundFactoryImpl::CompoundFactoryImpl(const std::string& file, CompoundFactor
// }
// catch (...)
// {
// throw_with_nested(runtime_error("Error while loading " + resFile));
// throw_with_nested(
std::
runtime_error("Error while loading " + resFile));
// }
//
// result = cf.get(name);
...
...
@@ -1203,12 +1197,12 @@ CompoundFactoryImpl::CompoundFactoryImpl(const std::string& file, CompoundFactor
// }
//
// if (result == nullptr)
// throw runtime_error("Failed to load datablock " + name);
// throw
std::
runtime_error("Failed to load datablock " + name);
//
// return *result;
//}
Compound
*
CompoundFactoryImpl
::
get
(
string
id
)
Compound
*
CompoundFactoryImpl
::
get
(
st
d
::
st
ring
id
)
{
std
::
shared_lock
lock
(
mMutex
);
...
...
@@ -1246,7 +1240,7 @@ Compound* CompoundFactoryImpl::create(std::string id)
{
auto
row
=
rs
.
front
();
string
name
,
group
;
st
d
::
st
ring
name
,
group
;
uint32_t
numberAtomsAll
,
numberAtomsNh
;
cif
::
tie
(
name
,
group
,
numberAtomsAll
,
numberAtomsNh
)
=
row
.
get
(
"name"
,
"group"
,
"number_atoms_all"
,
"number_atoms_nh"
);
...
...
@@ -1285,7 +1279,7 @@ Compound* CompoundFactoryImpl::create(std::string id)
return
result
;
}
const
Link
*
CompoundFactoryImpl
::
getLink
(
string
id
)
const
Link
*
CompoundFactoryImpl
::
getLink
(
st
d
::
st
ring
id
)
{
std
::
shared_lock
lock
(
mMutex
);
...
...
@@ -1341,7 +1335,7 @@ CompoundFactory::CompoundFactory()
{
const
char
*
clibdMon
=
getenv
(
"CLIBD_MON"
);
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"
;
...
...
@@ -1360,22 +1354,22 @@ CompoundFactory& CompoundFactory::instance()
return
*
sInstance
;
}
void
CompoundFactory
::
pushDictionary
(
const
string
&
inDictFile
)
void
CompoundFactory
::
pushDictionary
(
const
st
d
::
st
ring
&
inDictFile
)
{
if
(
not
fs
::
exists
(
inDictFile
))
throw
runtime_error
(
"file not found: "
+
inDictFile
);
throw
std
::
runtime_error
(
"file not found: "
+
inDictFile
);
// ifstream file(inDictFile);
// 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
{
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
;
}
}
...
...
@@ -1407,17 +1401,17 @@ const Link* CompoundFactory::createLink(std::string 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
);
}
bool
CompoundFactory
::
isKnownBase
(
const
string
&
resName
)
const
bool
CompoundFactory
::
isKnownBase
(
const
st
d
::
st
ring
&
resName
)
const
{
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
);
}
...
...
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 @@
#include <boost/date_time/gregorian/gregorian.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/format.hpp>
// #include <boost/numeric/ublas/matrix.hpp>
#include "cif++/AtomType.hpp"
#include "cif++/Compound.hpp"
#include "cif++/PDB2CifRemark3.hpp"
#include "cif++/CifUtils.hpp"
using
namespace
std
;
namespace
ba
=
boost
::
algorithm
;
using
cif
::
Datablock
;
...
...
@@ -53,12 +51,12 @@ using cif::iequals;
struct
TemplateLine
{
const
char
*
rx
;
int
nextStateOffset
;
const
char
*
category
;
initializer_list
<
const
char
*>
items
;
const
char
*
lsRestrType
=
nullptr
;
bool
createNew
;
const
char
*
rx
;
int
nextStateOffset
;
const
char
*
category
;
std
::
initializer_list
<
const
char
*>
items
;
const
char
*
lsRestrType
=
nullptr
;
bool
createNew
;
};
// --------------------------------------------------------------------
...
...
@@ -168,10 +166,10 @@ const TemplateLine kBusterTNT_Template[] = {
class
BUSTER_TNT_Remark3Parser
:
public
Remark3Parser
{
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
,
kBusterTNT_Template
,
sizeof
(
kBusterTNT_Template
)
/
sizeof
(
TemplateLine
),
regex
(
R"((BUSTER(?:-TNT)?)(?: (\d+(?:\..+)?))?)"
))
{}
std
::
regex
(
R"((BUSTER(?:-TNT)?)(?: (\d+(?:\..+)?))?)"
))
{}
};
const
TemplateLine
kCNS_Template
[]
=
{
...
...
@@ -261,9 +259,9 @@ const TemplateLine kCNS_Template[] = {
class
CNS_Remark3Parser
:
public
Remark3Parser
{
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
,
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
[]
=
{
...
...
@@ -339,9 +337,9 @@ const TemplateLine kPHENIX_Template[] = {
class
PHENIX_Remark3Parser
:
public
Remark3Parser
{
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
),
regex
(
R"((PHENIX)(?: \(PHENIX\.REFINE:) (\d+(?:\.[^)]+)?)\)?)"
))
{}
std
::
regex
(
R"((PHENIX)(?: \(PHENIX\.REFINE:) (\d+(?:\.[^)]+)?)\)?)"
))
{}
virtual
void
fixup
();
};
...
...
@@ -423,9 +421,9 @@ const TemplateLine kNUCLSQ_Template[] = {
class
NUCLSQ_Remark3Parser
:
public
Remark3Parser
{
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
),
regex
(
R"((NUCLSQ)(?: (\d+(?:\.\d+)?))?)"
))
{}
std
::
regex
(
R"((NUCLSQ)(?: (\d+(?:\.\d+)?))?)"
))
{}
virtual
void
fixup
()
{
...
...
@@ -512,9 +510,9 @@ const TemplateLine kPROLSQ_Template[] = {
class
PROLSQ_Remark3Parser
:
public
Remark3Parser
{
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
),
regex
(
R"((PROLSQ)(?: (\d+(?:\.\d+)?))?)"
))
{}
std
::
regex
(
R"((PROLSQ)(?: (\d+(?:\.\d+)?))?)"
))
{}
virtual
void
fixup
()
{
...
...
@@ -597,12 +595,12 @@ const TemplateLine kREFMAC_Template[] = {
class
REFMAC_Remark3Parser
:
public
Remark3Parser
{
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
),
regex
(
".+"
))
{}
std
::
regex
(
".+"
))
{}
virtual
string
program
()
{
return
"REFMAC"
;
}
virtual
string
version
()
{
return
""
;
}
virtual
st
d
::
st
ring
program
()
{
return
"REFMAC"
;
}
virtual
st
d
::
st
ring
version
()
{
return
""
;
}
};
const
TemplateLine
kREFMAC5_Template
[]
=
{
...
...
@@ -749,9 +747,9 @@ const TemplateLine kREFMAC5_Template[] = {
class
REFMAC5_Remark3Parser
:
public
Remark3Parser
{
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
),
regex
(
R"((REFMAC)(?: (\d+(?:\..+)?))?)"
))
{}
std
::
regex
(
R"((REFMAC)(?: (\d+(?:\..+)?))?)"
))
{}
};
const
TemplateLine
kSHELXL_Template
[]
=
{
...
...
@@ -807,9 +805,9 @@ const TemplateLine kSHELXL_Template[] = {
class
SHELXL_Remark3Parser
:
public
Remark3Parser
{
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
),
regex
(
R"((SHELXL)(?:-(\d+(?:\..+)?)))"
))
{}
std
::
regex
(
R"((SHELXL)(?:-(\d+(?:\..+)?)))"
))
{}
};
const
TemplateLine
kTNT_Template
[]
=
{
...
...
@@ -862,9 +860,9 @@ const TemplateLine kTNT_Template[] = {
class
TNT_Remark3Parser
:
public
Remark3Parser
{
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
),
regex
(
R"((TNT)(?: V. (\d+.+)?)?)"
))
{}
std
::
regex
(
R"((TNT)(?: V. (\d+.+)?)?)"
))
{}
};
const
TemplateLine
kXPLOR_Template
[]
=
{
...
...
@@ -940,9 +938,9 @@ const TemplateLine kXPLOR_Template[] = {
class
XPLOR_Remark3Parser
:
public
Remark3Parser
{
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
),
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
{
}
string
Remark3Parser
::
nextLine
()
st
d
::
st
ring
Remark3Parser
::
nextLine
()
{
mLine
.
clear
();
...
...
@@ -985,11 +983,11 @@ string Remark3Parser::nextLine()
if
(
valueIndent
>
4
)
{
string
indent
(
valueIndent
-
4
,
' '
);
st
d
::
st
ring
indent
(
valueIndent
-
4
,
' '
);
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
))
break
;
...
...
@@ -1024,21 +1022,21 @@ string Remark3Parser::nextLine()
}
if
(
cif
::
VERBOSE
>=
2
)
cerr
<<
"RM3: "
<<
mLine
<<
endl
;
std
::
cerr
<<
"RM3: "
<<
mLine
<<
std
::
endl
;
return
mLine
;
}
bool
Remark3Parser
::
match
(
const
char
*
expr
,
int
nextState
)
{
regex
rx
(
expr
);
std
::
regex
rx
(
expr
);
bool
result
=
regex_match
(
mLine
,
mM
,
rx
);
if
(
result
)
mState
=
nextState
;
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
;
}
...
...
@@ -1046,7 +1044,7 @@ bool Remark3Parser::match(const char* expr, int nextState)
float
Remark3Parser
::
parse
()
{
int
lineCount
=
0
,
dropped
=
0
;
string
remarks
;
st
d
::
st
ring
remarks
;
mState
=
0
;
while
(
mRec
!=
nullptr
)
...
...
@@ -1098,7 +1096,7 @@ float Remark3Parser::parse()
}
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
;
}
...
...
@@ -1114,43 +1112,43 @@ float Remark3Parser::parse()
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
))
result
=
m
[
1
].
str
();
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
))
result
=
m
[
2
].
str
();
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
;
for
(
auto
item
:
items
)
{
++
capture
;
string
value
=
mM
[
capture
].
str
();
st
d
::
st
ring
value
=
mM
[
capture
].
str
();
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
;
if
(
cif
::
VERBOSE
>=
3
)
cerr
<<
"storing: '"
<<
value
<<
"' in _"
<<
category
<<
'.'
<<
item
<<
endl
;
std
::
cerr
<<
"storing: '"
<<
value
<<
"' in _"
<<
category
<<
'.'
<<
item
<<
std
::
endl
;
auto
&
cat
=
mDb
[
category
];
if
(
cat
.
empty
()
or
createNew
)
...
...
@@ -1170,7 +1168,7 @@ void Remark3Parser::storeCapture(const char* category, initializer_list<const ch
});
else
if
(
iequals
(
category
,
"refine_hist"
))
{
string
dResHigh
,
dResLow
;
st
d
::
st
ring
dResHigh
,
dResLow
;
for
(
auto
r
:
mDb
[
"refine"
])
{
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
}
else
if
(
iequals
(
category
,
"pdbx_refine_tls_group"
))
{
string
tlsGroupID
;
st
d
::
st
ring
tlsGroupID
;
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
({
{
"pdbx_refine_id"
,
mExpMethod
},
...
...
@@ -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
;
int
capture
=
0
;
...
...
@@ -1250,9 +1248,9 @@ void Remark3Parser::storeRefineLsRestr(const char* type, initializer_list<const
{
++
capture
;
string
value
=
mM
[
capture
].
str
();
st
d
::
st
ring
value
=
mM
[
capture
].
str
();
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
;
if
(
not
r
)
...
...
@@ -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
);
if
(
rows
.
empty
())
...
...
@@ -1281,9 +1279,9 @@ void Remark3Parser::updateRefineLsRestr(const char* type, initializer_list<const
{
++
capture
;
string
value
=
mM
[
capture
].
str
();
st
d
::
st
ring
value
=
mM
[
capture
].
str
();
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
();
r
[
item
]
=
value
;
...
...
@@ -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
auto
getNextLine
=
[
&
]()
{
string
result
;
st
d
::
st
ring
result
;
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&
// All remark 3 records should start with the same data.
string
line
=
getNextLine
();
st
d
::
st
ring
line
=
getNextLine
();
if
(
line
!=
"REFINEMENT."
)
{
if
(
cif
::
VERBOSE
)
cerr
<<
"Unexpected data in REMARK 3"
<<
endl
;
std
::
cerr
<<
"Unexpected data in REMARK 3"
<<
std
::
endl
;
return
false
;
}
line
=
getNextLine
();
regex
rxp
(
R"(^PROGRAM\s*:\s*(.+))"
);
smatch
m
;
std
::
regex
rxp
(
R"(^PROGRAM\s*:\s*(.+))"
);
s
td
::
s
match
m
;
if
(
not
regex_match
(
line
,
m
,
rxp
))
if
(
not
std
::
regex_match
(
line
,
m
,
rxp
))
{
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
;
}
...
...
@@ -1339,11 +1337,11 @@ bool Remark3Parser::parse(const string& expMethod, PDBRecord* r, cif::Datablock&
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
)
{}
string
program
;
unique_ptr
<
Remark3Parser
>
parser
;
st
d
::
st
ring
program
;
std
::
unique_ptr
<
Remark3Parser
>
parser
;
float
score
;
bool
operator
<
(
const
programScore
&
rhs
)
const
...
...
@@ -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
)
{
unique_ptr
<
Remark3Parser
>
parser
(
p
);
std
::
unique_ptr
<
Remark3Parser
>
parser
(
p
);
float
score
;
try
...
...
@@ -1365,18 +1363,18 @@ bool Remark3Parser::parse(const string& expMethod, PDBRecord* r, cif::Datablock&
}
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'
;
score
=
0
;
}
if
(
cif
::
VERBOSE
>=
2
)
cerr
<<
"Score for "
<<
parser
->
program
()
<<
": "
<<
score
<<
endl
;
std
::
cerr
<<
"Score for "
<<
parser
->
program
()
<<
": "
<<
score
<<
std
::
endl
;
if
(
score
>
0
)
{
string
program
=
parser
->
program
();
string
version
=
parser
->
version
();
st
d
::
st
ring
program
=
parser
->
program
();
st
d
::
st
ring
version
=
parser
->
version
();
scores
.
emplace_back
(
program
,
parser
.
release
(),
score
);
}
...
...
@@ -1385,7 +1383,7 @@ bool Remark3Parser::parse(const string& expMethod, PDBRecord* r, cif::Datablock&
for
(
auto
p
=
make_split_iterator
(
line
,
ba
::
first_finder
(
", "
));
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"
))
tryParser
(
new
BUSTER_TNT_Remark3Parser
(
program
,
expMethod
,
r
,
db
));
...
...
@@ -1410,7 +1408,7 @@ bool Remark3Parser::parse(const string& expMethod, PDBRecord* r, cif::Datablock&
else
if
(
ba
::
starts_with
(
program
,
"X-PLOR"
))
tryParser
(
new
XPLOR_Remark3Parser
(
program
,
expMethod
,
r
,
db
));
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
());
...
...
@@ -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
;;
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
CNS_Remark3Parser
(
"CNS"
,
expMethod
,
r
,
db
));
...
...
@@ -1443,11 +1441,11 @@ bool Remark3Parser::parse(const string& expMethod, PDBRecord* r, cif::Datablock&
auto
&
best
=
scores
.
front
();
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"
];
string
program
=
best
.
parser
->
program
();
string
version
=
best
.
parser
->
version
();
st
d
::
st
ring
program
=
best
.
parser
->
program
();
st
d
::
st
ring
version
=
best
.
parser
->
version
();
software
.
emplace
({
{
"name"
,
program
},
...
...
src/Point.cpp
View file @
4b4757ee
...
...
@@ -29,8 +29,6 @@
#include "cif++/Point.hpp"
using
namespace
std
;
namespace
mmcif
{
...
...
@@ -38,7 +36,7 @@ namespace mmcif
quaternion
Normalize
(
quaternion
q
)
{
valarray
<
double
>
t
(
4
);
std
::
valarray
<
double
>
t
(
4
);
t
[
0
]
=
q
.
R_component_1
();
t
[
1
]
=
q
.
R_component_2
();
...
...
@@ -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
)
q
=
Normalize
(
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
);
return
make_tuple
(
angle
,
axis
);
return
std
::
make_tuple
(
angle
,
axis
);
}
Point
CenterPoints
(
vector
<
Point
>&
Points
)
Point
CenterPoints
(
std
::
vector
<
Point
>&
Points
)
{
Point
t
;
...
...
@@ -103,7 +101,7 @@ Point CenterPoints(vector<Point>& Points)
return
t
;
}
Point
Centroid
(
vector
<
Point
>&
Points
)
Point
Centroid
(
std
::
vector
<
Point
>&
Points
)
{
Point
result
;
...
...
@@ -115,12 +113,12 @@ Point Centroid(vector<Point>& Points)
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
;
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
[
1
]
=
b
[
i
].
mY
-
a
[
i
].
mY
;
...
...
@@ -131,7 +129,7 @@ double RMSd(const vector<Point>& a, const vector<Point>& b)
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
...
...
@@ -145,30 +143,30 @@ double RMSd(const vector<Point>& a, const vector<Point>& b)
// sqrt of a negative number)
double
LargestDepressedQuarticSolution
(
double
a
,
double
b
,
double
c
)
{
complex
<
double
>
P
=
-
(
a
*
a
)
/
12
-
c
;
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
>
P
=
-
(
a
*
a
)
/
12
-
c
;
std
::
complex
<
double
>
Q
=
-
(
a
*
a
*
a
)
/
108
+
(
a
*
c
)
/
3
-
(
b
*
b
)
/
8
;
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
)
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
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:
// result = (±W + sqrt(-(3 * alpha + 2 * y ± 2 * beta / W))) / 2;
// 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
[
1
]
=
((
W
+
sqrt
(
-
(
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
[
3
]
=
((
-
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
+
s
td
::
s
qrt
(
-
(
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
+
s
td
::
s
qrt
(
-
(
3.0
*
a
+
2.0
*
y
-
2.0
*
b
/
W
)))
/
2.0
).
real
();
return
t
.
max
();
}
...
...
@@ -286,10 +284,10 @@ double LargestDepressedQuarticSolution(double a, double b, double c)
Point
Nudge
(
Point
p
,
float
offset
)
{
static
std
::
random_device
rd
;
static
mt19937_64
rng
(
rd
());
static
std
::
mt19937_64
rng
(
rd
());
uniform_real_distribution
<>
randomAngle
(
0
,
2
*
kPI
);
normal_distribution
<>
randomOffset
(
0
,
offset
);
std
::
uniform_real_distribution
<>
randomAngle
(
0
,
2
*
kPI
);
std
::
normal_distribution
<>
randomOffset
(
0
,
offset
);
float
theta
=
randomAngle
(
rng
);
float
phi1
=
randomAngle
(
rng
)
-
kPI
;
...
...
src/Structure.cpp
View file @
4b4757ee
...
...
@@ -28,14 +28,7 @@
#include <numeric>
#include <fstream>
#if __has_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/iostreams/filtering_stream.hpp>
...
...
@@ -49,8 +42,7 @@ namespace fs = boost::filesystem;
#include "cif++/Cif2PDB.hpp"
// #include "cif++/AtomShape.hpp"
using
namespace
std
;
namespace
fs
=
std
::
filesystem
;
namespace
ba
=
boost
::
algorithm
;
namespace
io
=
boost
::
iostreams
;
...
...
@@ -75,12 +67,12 @@ void FileImpl::load(const std::string& 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
())
throw
runtime_error
(
"No such file: "
+
path
.
string
());
throw
std
::
runtime_error
(
"No such file: "
+
path
.
string
());
io
::
filtering_stream
<
io
::
input
>
in
;
string
ext
=
path
.
extension
().
string
();
st
d
::
st
ring
ext
=
path
.
extension
().
string
();
if
(
path
.
extension
()
==
".bz2"
)
{
...
...
@@ -107,14 +99,14 @@ void FileImpl::load(const std::string& p)
try
{
if
(
cif
::
VERBOSE
)
cerr
<<
"unrecognized file extension, trying cif"
<<
endl
;
std
::
cerr
<<
"unrecognized file extension, trying cif"
<<
std
::
endl
;
mData
.
load
(
in
);
}
catch
(
const
cif
::
CifParserError
&
e
)
{
if
(
cif
::
VERBOSE
)
cerr
<<
"Not cif, trying plain old PDB"
<<
endl
;
std
::
cerr
<<
"Not cif, trying plain old PDB"
<<
std
::
endl
;
// pffft...
in
.
reset
();
...
...
@@ -122,7 +114,7 @@ void FileImpl::load(const std::string& p)
if
(
inFile
.
is_open
())
inFile
.
seekg
(
0
);
else
inFile
.
open
(
path
,
ios_base
::
in
|
ios
::
binary
);
inFile
.
open
(
path
,
std
::
ios_base
::
in
|
std
::
ios
::
binary
);
if
(
path
.
extension
()
==
".bz2"
)
in
.
push
(
io
::
bzip2_decompressor
());
...
...
@@ -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
;
}
...
...
@@ -148,14 +140,14 @@ void FileImpl::load(const std::string& p)
// if (mData.getValidator() == nullptr)
mData
.
loadDictionary
(
"mmcif_pdbx"
);
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
)
{
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
;
if
(
path
.
extension
()
==
".gz"
)
...
...
@@ -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
)
{
auto
&
db
=
*
mFile
.
impl
().
mDb
;
...
...
@@ -205,7 +197,7 @@ struct AtomImpl
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
)
{
prefetch
();
...
...
@@ -227,7 +219,7 @@ struct AtomImpl
void
prefetch
()
{
// Prefetch some data
string
symbol
;
st
d
::
st
ring
symbol
;
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"
);
...
...
@@ -239,7 +231,7 @@ struct AtomImpl
mLocation
=
Point
(
x
,
y
,
z
);
string
compID
;
st
d
::
st
ring
compID
;
cif
::
tie
(
compID
)
=
mRow
.
get
(
"label_comp_id"
);
mCompound
=
Compound
::
create
(
compID
);
...
...
@@ -255,12 +247,12 @@ struct AtomImpl
// else
// 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())
// {
// int charge = mRow["pdbx_formal_charge"].as<int>();
// if (abs(charge) > 1)
// element += to_string(charge);
// element +=
std::
to_string(charge);
// if (charge < 0)
// element += '-';
// else
...
...
@@ -273,7 +265,7 @@ struct AtomImpl
// else if (not mRow["B_iso_or_equiv"].empty())
// result.set_u_iso(mRow["B_iso_or_equiv"].as<float>() / (8 * kPI * kPI));
// 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& cat = db["atom_site_anisotrop"];
...
...
@@ -324,7 +316,7 @@ struct AtomImpl
{
assert
(
not
mSymmetryCopy
);
if
(
mSymmetryCopy
)
throw
runtime_error
(
"Moving symmetry copy"
);
throw
std
::
runtime_error
(
"Moving symmetry copy"
);
if
(
not
mClone
)
{
...
...
@@ -346,17 +338,17 @@ struct AtomImpl
{
if
(
mCompound
==
nullptr
)
{
string
compID
;
st
d
::
st
ring
compID
;
cif
::
tie
(
compID
)
=
mRow
.
get
(
"label_comp_id"
);
mCompound
=
Compound
::
create
(
compID
);
if
(
cif
::
VERBOSE
and
mCompound
==
nullptr
)
cerr
<<
"Compound not found: '"
<<
compID
<<
'\''
<<
endl
;
std
::
cerr
<<
"Compound not found: '"
<<
compID
<<
'\''
<<
std
::
endl
;
}
if
(
mCompound
==
nullptr
)
throw
runtime_error
(
"no compound"
);
throw
std
::
runtime_error
(
"no compound"
);
return
*
mCompound
;
}
...
...
@@ -371,9 +363,9 @@ struct AtomImpl
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
);
if
(
i
==
mCachedProperties
.
end
())
...
...
@@ -382,7 +374,7 @@ struct AtomImpl
if
(
v
.
empty
())
return
kEmptyString
;
return
mCachedProperties
[
name
]
=
v
.
as
<
string
>
();
return
mCachedProperties
[
name
]
=
v
.
as
<
st
d
::
st
ring
>
();
}
else
return
i
->
second
;
...
...
@@ -404,21 +396,21 @@ struct AtomImpl
}
const
File
&
mFile
;
string
mID
;
st
d
::
st
ring
mID
;
AtomType
mType
;
string
mAtomID
;
string
mCompID
;
string
mAsymID
;
st
d
::
st
ring
mAtomID
;
st
d
::
st
ring
mCompID
;
st
d
::
st
ring
mAsymID
;
int
mSeqID
;
string
mAltID
;
st
d
::
st
ring
mAltID
;
Point
mLocation
;
int
mRefcount
;
cif
::
Row
mRow
;
mutable
const
Compound
*
mCompound
;
float
mRadius
=
nan
(
"4"
);
mutable
map
<
string
,
string
>
mCachedProperties
;
mutable
std
::
map
<
std
::
string
,
std
::
string
>
mCachedProperties
;
bool
mSymmetryCopy
=
false
;
bool
mClone
=
false
;
...
...
@@ -428,7 +420,7 @@ struct AtomImpl
// 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))
//{
//}
...
...
@@ -491,25 +483,25 @@ Atom& Atom::operator=(const Atom& rhs)
}
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
);
}
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
);
return
v
.
empty
()
?
0
:
stoi
(
v
);
}
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
));
}
const
string
&
Atom
::
id
()
const
const
st
d
::
st
ring
&
Atom
::
id
()
const
{
return
impl
()
->
mID
;
}
...
...
@@ -524,9 +516,9 @@ int Atom::charge() const
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
)
result
=
impl
()
->
mCompound
->
getAtomByID
(
impl
()
->
mAtomID
).
typeEnergy
;
...
...
@@ -538,12 +530,12 @@ float Atom::uIso() const
{
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"
);
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
);
else
throw
runtime_error
(
"Missing B_iso or U_iso"
);
throw
std
::
runtime_error
(
"Missing B_iso or U_iso"
);
return
result
;
}
...
...
@@ -558,22 +550,22 @@ float Atom::occupancy() const
return
property
<
float
>
(
"occupancy"
);
}
string
Atom
::
labelAtomID
()
const
st
d
::
st
ring
Atom
::
labelAtomID
()
const
{
return
impl
()
->
mAtomID
;
}
string
Atom
::
labelCompID
()
const
st
d
::
st
ring
Atom
::
labelCompID
()
const
{
return
impl
()
->
mCompID
;
}
string
Atom
::
labelAsymID
()
const
st
d
::
st
ring
Atom
::
labelAsymID
()
const
{
return
impl
()
->
mAsymID
;
}
string
Atom
::
labelAltID
()
const
st
d
::
st
ring
Atom
::
labelAltID
()
const
{
return
impl
()
->
mAltID
;
}
...
...
@@ -588,48 +580,48 @@ int Atom::labelSeqID() const
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
property
<
string
>
(
"auth_comp_id"
)
+
'_'
+
property
<
string
>
(
"auth_asym_id"
)
+
'_'
+
property
<
string
>
(
"auth_seq_id"
)
+
property
<
string
>
(
"pdbx_PDB_ins_code"
);
property
<
st
d
::
st
ring
>
(
"auth_comp_id"
)
+
'_'
+
property
<
st
d
::
st
ring
>
(
"auth_asym_id"
)
+
'_'
+
property
<
st
d
::
st
ring
>
(
"auth_seq_id"
)
+
property
<
st
d
::
st
ring
>
(
"pdbx_PDB_ins_code"
);
}
Point
Atom
::
location
()
const
...
...
@@ -652,7 +644,7 @@ void Atom::location(Point p)
// return impl()->mSymmetryCopy;
// }
// string Atom::symmetry() const
// st
d::st
ring Atom::symmetry() const
// {
// return clipper::Symop(impl()->mRTop).format() + "\n" + impl()->mRTop.format();
// }
...
...
@@ -690,7 +682,7 @@ bool Atom::operator==(const Atom& rhs) const
// // verbose
// 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
...
...
@@ -705,7 +697,7 @@ int Atom::compare(const Atom& b) const
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
)
...
...
@@ -723,8 +715,8 @@ std::ostream& operator<<(std::ostream& os, const Atom& atom)
// --------------------------------------------------------------------
// residue
Residue
::
Residue
(
const
Structure
&
structure
,
const
string
&
compoundID
,
const
st
ring
&
asymID
,
const
string
&
authSeqID
)
Residue
::
Residue
(
const
Structure
&
structure
,
const
st
d
::
st
ring
&
compoundID
,
const
st
d
::
string
&
asymID
,
const
std
::
string
&
authSeqID
)
:
mStructure
(
&
structure
),
mCompoundID
(
compoundID
)
,
mAsymID
(
asymID
),
mAuthSeqID
(
authSeqID
)
{
...
...
@@ -745,8 +737,8 @@ Residue::Residue(const Structure& structure, const string& compoundID,
assert
(
not
mAtoms
.
empty
());
}
Residue
::
Residue
(
const
Structure
&
structure
,
const
string
&
compoundID
,
const
string
&
asymID
,
int
seqID
)
Residue
::
Residue
(
const
Structure
&
structure
,
const
st
d
::
st
ring
&
compoundID
,
const
st
d
::
st
ring
&
asymID
,
int
seqID
)
:
mStructure
(
&
structure
),
mCompoundID
(
compoundID
)
,
mAsymID
(
asymID
),
mSeqID
(
seqID
)
{
...
...
@@ -766,43 +758,43 @@ Residue::Residue(const Structure& structure, const string& compoundID,
}
Residue
::
Residue
(
Residue
&&
rhs
)
:
mStructure
(
rhs
.
mStructure
),
mCompoundID
(
move
(
rhs
.
mCompoundID
)),
mAsymID
(
move
(
rhs
.
mAsymID
))
,
mSeqID
(
rhs
.
mSeqID
),
mAuthSeqID
(
rhs
.
mAuthSeqID
),
mAtoms
(
move
(
rhs
.
mAtoms
))
:
mStructure
(
rhs
.
mStructure
),
mCompoundID
(
std
::
move
(
rhs
.
mCompoundID
)),
mAsymID
(
std
::
move
(
rhs
.
mAsymID
))
,
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
;
}
Residue
&
Residue
::
operator
=
(
Residue
&&
rhs
)
{
//
cerr << "move assignment residue" <<
endl;
//
std::cerr << "move assignment residue" << std::
endl;
mStructure
=
rhs
.
mStructure
;
rhs
.
mStructure
=
nullptr
;
mCompoundID
=
move
(
rhs
.
mCompoundID
);
mAsymID
=
move
(
rhs
.
mAsymID
);
mCompoundID
=
std
::
move
(
rhs
.
mCompoundID
);
mAsymID
=
std
::
move
(
rhs
.
mAsymID
);
mSeqID
=
rhs
.
mSeqID
;
mAuthSeqID
=
rhs
.
mAuthSeqID
;
mAtoms
=
move
(
rhs
.
mAtoms
);
mAtoms
=
std
::
move
(
rhs
.
mAtoms
);
return
*
this
;
}
Residue
::~
Residue
()
{
//
cerr << "~Residue" <<
endl;
//
std::cerr << "~Residue" << std::
endl;
}
string
Residue
::
authInsCode
()
const
st
d
::
st
ring
Residue
::
authInsCode
()
const
{
assert
(
mStructure
);
string
result
;
st
d
::
st
ring
result
;
try
{
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
);
}
catch
(...)
...
...
@@ -812,15 +804,15 @@ string Residue::authInsCode() const
return
result
;
}
string
Residue
::
authAsymID
()
const
st
d
::
st
ring
Residue
::
authAsymID
()
const
{
assert
(
mStructure
);
string
result
;
st
d
::
st
ring
result
;
try
{
tie
(
result
,
ignore
,
ignore
)
=
mStructure
->
MapLabelToAuth
(
mAsymID
,
mSeqID
);
tie
(
result
,
std
::
ignore
,
std
::
ignore
)
=
mStructure
->
MapLabelToAuth
(
mAsymID
,
mSeqID
);
}
catch
(...)
{
...
...
@@ -830,17 +822,17 @@ string Residue::authAsymID() const
return
result
;
}
string
Residue
::
authSeqID
()
const
st
d
::
st
ring
Residue
::
authSeqID
()
const
{
assert
(
mStructure
);
string
result
;
st
d
::
st
ring
result
;
try
{
int
seqID
;
tie
(
ignore
,
seqID
,
ignore
)
=
mStructure
->
MapLabelToAuth
(
mAsymID
,
mSeqID
);
result
=
to_string
(
seqID
);
tie
(
std
::
ignore
,
seqID
,
std
::
ignore
)
=
mStructure
->
MapLabelToAuth
(
mAsymID
,
mSeqID
);
result
=
std
::
to_string
(
seqID
);
}
catch
(...)
{
...
...
@@ -853,14 +845,14 @@ const Compound& Residue::compound() const
{
auto
result
=
Compound
::
create
(
mCompoundID
);
if
(
result
==
nullptr
)
throw
runtime_error
(
"Failed to create compound "
+
mCompoundID
);
throw
std
::
runtime_error
(
"Failed to create compound "
+
mCompoundID
);
return
*
result
;
}
const
AtomView
&
Residue
::
atoms
()
const
{
if
(
mStructure
==
nullptr
)
throw
runtime_error
(
"Invalid Residue object"
);
throw
std
::
runtime_error
(
"Invalid Residue object"
);
return
mAtoms
;
}
...
...
@@ -868,7 +860,7 @@ const AtomView& Residue::atoms() const
std
::
string
Residue
::
unique_alt_id
()
const
{
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
();
});
...
...
@@ -878,7 +870,7 @@ std::string Residue::unique_alt_id() const
AtomView
Residue
::
unique_atoms
()
const
{
if
(
mStructure
==
nullptr
)
throw
runtime_error
(
"Invalid Residue object"
);
throw
std
::
runtime_error
(
"Invalid Residue object"
);
AtomView
result
;
std
::
string
firstAlt
;
...
...
@@ -907,7 +899,7 @@ AtomView Residue::unique_atoms() const
return
result
;
}
Atom
Residue
::
atomByID
(
const
string
&
atomID
)
const
Atom
Residue
::
atomByID
(
const
st
d
::
st
ring
&
atomID
)
const
{
Atom
result
;
...
...
@@ -939,40 +931,40 @@ bool Residue::isEntity() const
return
a1
.
size
()
==
a2
.
size
();
}
string
Residue
::
authID
()
const
st
d
::
st
ring
Residue
::
authID
()
const
{
string
result
;
st
d
::
st
ring
result
;
try
{
char
chainID
,
iCode
;
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
)
result
+=
iCode
;
}
catch
(...)
{
result
=
mAsymID
+
to_string
(
mSeqID
);
result
=
mAsymID
+
std
::
to_string
(
mSeqID
);
}
return
result
;
}
string
Residue
::
labelID
()
const
st
d
::
st
ring
Residue
::
labelID
()
const
{
if
(
mCompoundID
==
"HOH"
)
return
mAsymID
+
mAuthSeqID
;
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
)
pts
.
push_back
(
a
.
location
());
...
...
@@ -986,7 +978,7 @@ tuple<Point,float> Residue::centerAndRadius() const
radius
=
d
;
}
return
make_tuple
(
center
,
radius
);
return
std
::
make_tuple
(
center
,
radius
);
}
bool
Residue
::
hasAlternateAtoms
()
const
...
...
@@ -1008,11 +1000,11 @@ std::ostream& operator<<(std::ostream& os, const Residue& res)
// monomer
//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
)
,
mPolymer
(
&
polymer
)
,
mIndex
(
index
)
...
...
@@ -1020,15 +1012,15 @@ Monomer::Monomer(const Polymer& polymer, uint32_t index, int seqID, const string
}
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;
// mCompoundID = move(rhs.mCompoundID);
// mAsymID = move(rhs.mAsymID);
// mCompoundID =
std::
move(rhs.mCompoundID);
// mAsymID =
std::
move(rhs.mAsymID);
// mSeqID = rhs.mSeqID;
// mAtoms = move(rhs.mAtoms);
// mAtoms =
std::
move(rhs.mAtoms);
//
// mPolymer = rhs.mPolymer; rhs.mPolymer = nullptr;
// mIndex = rhs.mIndex;
...
...
@@ -1037,9 +1029,9 @@ cerr << "move constructor monomer" << endl;
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
;
mIndex
=
rhs
.
mIndex
;
...
...
@@ -1080,10 +1072,10 @@ float Monomer::phi() const
result
=
DihedralAngle
(
prev
.
C
().
location
(),
N
().
location
(),
CAlpha
().
location
(),
C
().
location
());
}
}
catch
(
const
exception
&
ex
)
catch
(
const
std
::
exception
&
ex
)
{
if
(
cif
::
VERBOSE
)
cerr
<<
ex
.
what
()
<<
endl
;
std
::
cerr
<<
ex
.
what
()
<<
std
::
endl
;
}
return
result
;
...
...
@@ -1102,10 +1094,10 @@ float Monomer::psi() const
result
=
DihedralAngle
(
N
().
location
(),
CAlpha
().
location
(),
C
().
location
(),
next
.
N
().
location
());
}
}
catch
(
const
exception
&
ex
)
catch
(
const
std
::
exception
&
ex
)
{
if
(
cif
::
VERBOSE
)
cerr
<<
ex
.
what
()
<<
endl
;
std
::
cerr
<<
ex
.
what
()
<<
std
::
endl
;
}
return
result
;
...
...
@@ -1126,10 +1118,10 @@ float Monomer::alpha() const
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
)
cerr
<<
ex
.
what
()
<<
endl
;
std
::
cerr
<<
ex
.
what
()
<<
std
::
endl
;
}
return
result
;
...
...
@@ -1154,11 +1146,11 @@ float Monomer::kappa() const
}
}
}
catch
(
const
exception
&
ex
)
catch
(
const
std
::
exception
&
ex
)
{
if
(
cif
::
VERBOSE
)
cerr
<<
"When trying to calculate kappa for "
<<
asymID
()
<<
':'
<<
seqID
()
<<
": "
<<
ex
.
what
()
<<
endl
;
std
::
cerr
<<
"When trying to calculate kappa for "
<<
asymID
()
<<
':'
<<
seqID
()
<<
": "
<<
ex
.
what
()
<<
std
::
endl
;
}
return
result
;
...
...
@@ -1177,11 +1169,11 @@ float Monomer::tco() const
result
=
CosinusAngle
(
C
().
location
(),
O
().
location
(),
prev
.
C
().
location
(),
prev
.
O
().
location
());
}
}
catch
(
const
exception
&
ex
)
catch
(
const
std
::
exception
&
ex
)
{
if
(
cif
::
VERBOSE
)
cerr
<<
"When trying to calculate tco for "
<<
asymID
()
<<
':'
<<
seqID
()
<<
": "
<<
ex
.
what
()
<<
endl
;
std
::
cerr
<<
"When trying to calculate tco for "
<<
asymID
()
<<
':'
<<
seqID
()
<<
": "
<<
ex
.
what
()
<<
std
::
endl
;
}
return
result
;
...
...
@@ -1196,17 +1188,17 @@ float Monomer::omega() const
if
(
not
is_last_in_chain
())
result
=
omega
(
*
this
,
mPolymer
->
operator
[](
mIndex
+
1
));
}
catch
(
const
exception
&
ex
)
catch
(
const
std
::
exception
&
ex
)
{
if
(
cif
::
VERBOSE
)
cerr
<<
"When trying to calculate omega for "
<<
asymID
()
<<
':'
<<
seqID
()
<<
": "
<<
ex
.
what
()
<<
endl
;
std
::
cerr
<<
"When trying to calculate omega for "
<<
asymID
()
<<
':'
<<
seqID
()
<<
": "
<<
ex
.
what
()
<<
std
::
endl
;
}
return
result
;
}
const
map
<
string
,
vector
<
string
>>
kChiAtomsMap
=
{
const
std
::
map
<
std
::
string
,
std
::
vector
<
std
::
string
>>
kChiAtomsMap
=
{
{
"ASP"
,
{
"CG"
,
"OD1"
}
},
{
"ASN"
,
{
"CG"
,
"OD1"
}
},
{
"ARG"
,
{
"CG"
,
"CD"
,
"NE"
,
"CZ"
}
},
...
...
@@ -1248,7 +1240,7 @@ float Monomer::chi(size_t nr) const
auto
i
=
kChiAtomsMap
.
find
(
mCompoundID
);
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
());
...
...
@@ -1410,7 +1402,7 @@ bool Monomer::isCis(const mmcif::Monomer& a, const mmcif::Monomer& b)
// if (index < polySeq.size())
// {
// int seqID;
// string asymID, monID;
// st
d::st
ring asymID, monID;
// cif::tie(asymID, seqID, monID) =
// polySeq[mIndex].get("asym_id", "seq_id", "mon_id");
//
...
...
@@ -1423,7 +1415,7 @@ bool Monomer::isCis(const mmcif::Monomer& a, const mmcif::Monomer& b)
// if (index >= mPolySeq.size())
// throw out_of_range("Invalid index for residue in polymer");
//
// string compoundID;
// st
d::st
ring compoundID;
// int seqID;
//
// auto r = mPolySeq[index];
...
...
@@ -1449,7 +1441,7 @@ bool Monomer::isCis(const mmcif::Monomer& a, const mmcif::Monomer& b)
// if (mIndex < polySeq.size())
// {
// int seqID;
// string asymID, monID;
// st
d::st
ring asymID, monID;
// cif::tie(asymID, seqID, monID) =
// polySeq[mIndex].get("asym_id", "seq_id", "mon_id");
//
...
...
@@ -1459,11 +1451,11 @@ bool Monomer::isCis(const mmcif::Monomer& a, const mmcif::Monomer& b)
// 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)
// , 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
// for (auto r: mPolySeq)
...
...
@@ -1473,35 +1465,35 @@ bool Monomer::isCis(const mmcif::Monomer& a, const mmcif::Monomer& b)
//}
//Polymer::Polymer(Polymer&& rhs)
// :
vector<Monomer>(
move(rhs))
// :
std::vector<Monomer>(std::
move(rhs))
// , 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;
//}
//
//Polymer& Polymer::operator=(Polymer&& rhs)
//{
//
vector<Monomer>::operator=(
move(rhs));
//
std::vector<Monomer>::operator=(std::
move(rhs));
// mStructure = rhs.mStructure; rhs.mStructure = nullptr;
// 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);
// 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
)
,
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
());
for
(
auto
r
:
mPolySeq
)
{
int
seqID
;
string
compoundID
;
st
d
::
st
ring
compoundID
;
cif
::
tie
(
seqID
,
compoundID
)
=
r
.
get
(
"seq_id"
,
"mon_id"
);
uint32_t
index
=
size
();
...
...
@@ -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
)
...
...
@@ -1531,7 +1523,7 @@ Monomer& Polymer::getBySeqID(int seqID)
if
(
m
.
seqID
()
==
seqID
)
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
...
...
@@ -1540,16 +1532,16 @@ const Monomer& Polymer::getBySeqID(int seqID) const
if
(
m
.
seqID
()
==
seqID
)
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
result
=
numeric_limits
<
int
>::
max
();
int
result
=
std
::
numeric_limits
<
int
>::
max
();
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
;
for
(
auto
&
m
:
*
this
)
...
...
@@ -1600,14 +1592,14 @@ void File::load(const std::string& p)
//
// struct entity
// {
// string id;
// string type;
// st
d::st
ring id;
// st
d::st
ring type;
// };
// vector<entity> entities;
//
std::
vector<entity> entities;
//
// for (auto& _e: db["entity"])
// {
// string type = _e["type"];
// st
d::st
ring type = _e["type"];
// ba::to_lower(type);
// entities.push_back({ _e["id"], type });
// }
...
...
@@ -1617,13 +1609,13 @@ void File::load(const std::string& p)
// {
// 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; });
// 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");
//
// auto r = find_if(m_residues.begin(), m_residues.end(), [=](residue_ptr& res) -> bool
...
...
@@ -1655,7 +1647,7 @@ cif::Datablock& File::data()
assert
(
mImpl
->
mDb
);
if
(
mImpl
==
nullptr
or
mImpl
->
mDb
==
nullptr
)
throw
runtime_error
(
"No data loaded"
);
throw
std
::
runtime_error
(
"No data loaded"
);
return
*
mImpl
->
mDb
;
}
...
...
@@ -1665,7 +1657,7 @@ cif::File& File::file()
assert
(
mImpl
);
if
(
mImpl
==
nullptr
)
throw
runtime_error
(
"No data loaded"
);
throw
std
::
runtime_error
(
"No data loaded"
);
return
mImpl
->
mData
;
}
...
...
@@ -1720,7 +1712,7 @@ void Structure::loadData()
for
(
auto
&
r
:
polySeqScheme
)
{
string
asymID
,
entityID
,
seqID
,
monID
;
st
d
::
st
ring
asymID
,
entityID
,
seqID
,
monID
;
cif
::
tie
(
asymID
,
entityID
,
seqID
,
monID
)
=
r
.
get
(
"asym_id"
,
"entity_id"
,
"seq_id"
,
"mon_id"
);
...
...
@@ -1732,7 +1724,7 @@ void Structure::loadData()
for
(
auto
&
r
:
nonPolyScheme
)
{
string
asymID
,
monID
,
pdbSeqNum
;
st
d
::
st
ring
asymID
,
monID
,
pdbSeqNum
;
cif
::
tie
(
asymID
,
monID
,
pdbSeqNum
)
=
r
.
get
(
"asym_id"
,
"mon_id"
,
"pdb_seq_num"
);
...
...
@@ -1745,7 +1737,7 @@ void Structure::loadData()
void
Structure
::
updateAtomIndex
()
{
mAtomIndex
=
vector
<
size_t
>
(
mAtoms
.
size
());
mAtomIndex
=
std
::
vector
<
size_t
>
(
mAtoms
.
size
());
iota
(
mAtomIndex
.
begin
(),
mAtomIndex
.
end
(),
0
);
...
...
@@ -1774,10 +1766,10 @@ AtomView Structure::waters() const
// Get the entity id for water
auto
&
entityCat
=
db
[
"entity"
];
string
waterEntityID
;
st
d
::
st
ring
waterEntityID
;
for
(
auto
&
e
:
entityCat
)
{
string
id
,
type
;
st
d
::
st
ring
id
,
type
;
cif
::
tie
(
id
,
type
)
=
e
.
get
(
"id"
,
"type"
);
if
(
ba
::
iequals
(
type
,
"water"
))
{
...
...
@@ -1788,28 +1780,28 @@ AtomView Structure::waters() const
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
);
}
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
;
});
// auto i = find_if(mAtoms.begin(), mAtoms.end(),
// [&id](auto& a) { return a.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
];
}
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
)
{
...
...
@@ -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
...
...
@@ -1837,25 +1829,25 @@ cif::Category& Structure::category(const char* name) const
return
db
[
name
];
}
tuple
<
char
,
int
,
char
>
Structure
::
MapLabelToAuth
(
const
string
&
asymID
,
int
seqID
)
const
std
::
tuple
<
char
,
int
,
char
>
Structure
::
MapLabelToAuth
(
const
st
d
::
st
ring
&
asymID
,
int
seqID
)
const
{
auto
&
db
=
*
getFile
().
impl
().
mDb
;
tuple
<
char
,
int
,
char
>
result
;
std
::
tuple
<
char
,
int
,
char
>
result
;
bool
found
=
false
;
for
(
auto
r
:
db
[
"pdbx_poly_seq_scheme"
].
find
(
cif
::
Key
(
"asym_id"
)
==
asymID
and
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
;
cif
::
tie
(
auth_asym_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
());
found
=
true
;
...
...
@@ -1868,13 +1860,13 @@ tuple<char,int,char> Structure::MapLabelToAuth(
cif
::
Key
(
"asym_id"
)
==
asymID
and
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
;
cif
::
tie
(
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
());
found
=
true
;
...
...
@@ -1885,13 +1877,13 @@ tuple<char,int,char> Structure::MapLabelToAuth(
return
result
;
}
tuple
<
string
,
int
,
string
,
string
>
Structure
::
MapLabelToPDB
(
const
st
ring
&
asymID
,
int
seqID
,
const
string
&
monID
,
const
string
&
authSeqID
)
const
std
::
tuple
<
std
::
string
,
int
,
std
::
string
,
std
::
string
>
Structure
::
MapLabelToPDB
(
const
st
d
::
string
&
asymID
,
int
seqID
,
const
std
::
string
&
monID
,
const
st
d
::
st
ring
&
authSeqID
)
const
{
auto
&
db
=
datablock
();
tuple
<
string
,
int
,
string
,
string
>
result
;
std
::
tuple
<
std
::
string
,
int
,
std
::
string
,
std
::
string
>
result
;
if
(
monID
==
"HOH"
)
{
...
...
@@ -1927,12 +1919,12 @@ tuple<string,int,string,string> Structure::MapLabelToPDB(
return
result
;
}
tuple
<
string
,
int
,
string
>
Structure
::
MapPDBToLabel
(
const
string
&
asymID
,
int
seqID
,
const
st
ring
&
compID
,
const
string
&
iCode
)
const
std
::
tuple
<
std
::
string
,
int
,
std
::
string
>
Structure
::
MapPDBToLabel
(
const
std
::
string
&
asymID
,
int
seqID
,
const
st
d
::
string
&
compID
,
const
std
::
string
&
iCode
)
const
{
auto
&
db
=
datablock
();
tuple
<
string
,
int
,
string
>
result
;
std
::
tuple
<
std
::
string
,
int
,
std
::
string
>
result
;
if
(
iCode
.
empty
())
{
...
...
@@ -1988,11 +1980,11 @@ cif::Datablock& Structure::datablock() const
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
);
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
;
...
...
@@ -2014,7 +2006,7 @@ void Structure::insertCompound(const string& compoundID, bool isEntity)
if
(
pdbxEntityNonpoly
.
find
(
cif
::
Key
(
"comp_id"
)
==
compoundID
).
empty
())
{
auto
&
entity
=
db
[
"entity"
];
st
ring
entityID
=
to_string
(
entity
.
size
()
+
1
);
st
d
::
string
entityID
=
std
::
to_string
(
entity
.
size
()
+
1
);
entity
.
emplace
({
{
"id"
,
entityID
},
...
...
@@ -2101,7 +2093,7 @@ void Structure::removeAtom(Atom& a)
for
(
auto
i
=
atomSites
.
begin
();
i
!=
atomSites
.
end
();
++
i
)
{
string
id
;
st
d
::
st
ring
id
;
cif
::
tie
(
id
)
=
i
->
get
(
"id"
);
if
(
id
==
a
.
id
())
...
...
@@ -2125,10 +2117,10 @@ void Structure::swapAtoms(Atom& a1, Atom& a2)
auto
rs2
=
atomSites
.
find
(
cif
::
Key
(
"id"
)
==
a2
.
id
());
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
)
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
r2
=
rs2
.
front
();
...
...
@@ -2149,12 +2141,12 @@ void Structure::moveAtom(Atom& a, Point p)
a
.
location
(
p
);
}
void
Structure
::
changeResidue
(
const
Residue
&
res
,
const
string
&
newCompound
,
const
vector
<
tuple
<
string
,
string
>>&
remappedAtoms
)
void
Structure
::
changeResidue
(
const
Residue
&
res
,
const
st
d
::
st
ring
&
newCompound
,
const
std
::
vector
<
std
::
tuple
<
std
::
string
,
std
::
string
>>&
remappedAtoms
)
{
cif
::
Datablock
&
db
=
*
mFile
.
impl
().
mDb
;
string
entityID
;
st
d
::
st
ring
entityID
;
// First make sure the compound is already known or insert it.
// 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,
for
(
auto
&
a
:
remappedAtoms
)
{
string
a1
,
a2
;
st
d
::
st
ring
a1
,
a2
;
tie
(
a1
,
a2
)
=
a
;
auto
i
=
find_if
(
atoms
.
begin
(),
atoms
.
end
(),
[
&
](
const
Atom
&
a
)
{
return
a
.
labelAtomID
()
==
a1
;
});
if
(
i
==
atoms
.
end
())
{
cerr
<<
"Missing atom for atom ID "
<<
a1
<<
endl
;
std
::
cerr
<<
"Missing atom for atom ID "
<<
a1
<<
std
::
endl
;
continue
;
}
...
...
src/Symmetry.cpp
View file @
4b4757ee
...
...
@@ -32,8 +32,6 @@
#include "cif++/Symmetry.hpp"
#include "cif++/CifUtils.hpp"
using
namespace
std
;
namespace
mmcif
{
...
...
@@ -51,7 +49,7 @@ int GetSpacegroupNumber(std::string spacegroup)
if
(
spacegroup
==
"P 21 21 2 A"
)
spacegroup
=
"P 21 21 2 (a)"
;
else
if
(
spacegroup
.
empty
())
throw
runtime_error
(
"No spacegroup, cannot continue"
);
throw
std
::
runtime_error
(
"No spacegroup, cannot continue"
);
int
result
=
0
;
...
...
@@ -88,7 +86,7 @@ int GetSpacegroupNumber(std::string spacegroup)
}
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
;
}
...
...
src/TlsParser.cpp
View file @
4b4757ee
...
...
@@ -26,32 +26,18 @@
#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 "cif++/CifUtils.hpp"
#include "cif++/Structure.hpp"
#include "cif++/TlsParser.hpp"
using
namespace
std
;
namespace
po
=
boost
::
program_options
;
namespace
ba
=
boost
::
algorithm
;
namespace
c
=
mmcif
;
namespace
cif
{
const
int
kResidueNrWildcard
=
numeric_limits
<
int
>::
min
(),
kNoSeqNum
=
numeric_limits
<
int
>::
max
()
-
1
;
using
namespace
std
;
kResidueNrWildcard
=
std
::
numeric_limits
<
int
>::
min
(),
kNoSeqNum
=
std
::
numeric_limits
<
int
>::
max
()
-
1
;
// --------------------------------------------------------------------
// We parse selection statements and create a selection expression tree
...
...
@@ -60,14 +46,14 @@ using namespace std;
struct
TLSResidue
{
string
chainID
;
int
seqNr
;
char
iCode
;
string
name
;
bool
selected
;
st
d
::
st
ring
chainID
;
int
seqNr
;
char
iCode
;
st
d
::
st
ring
name
;
bool
selected
;
string
asymID
;
int
seqID
;
st
d
::
st
ring
asymID
;
int
seqID
;
bool
operator
==
(
const
TLSResidue
&
rhs
)
const
{
...
...
@@ -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
();
bool
first
=
true
;
...
...
@@ -89,35 +75,35 @@ void DumpSelection(const vector<TLSResidue>& selected, int indentLevel)
// First print in PDB space
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
())
break
;
if
(
first
)
cout
<<
indent
<<
"PDB:"
<<
endl
;
std
::
cout
<<
indent
<<
"PDB:"
<<
std
::
endl
;
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
;
}
// Then in mmCIF space
if
(
not
first
)
cout
<<
indent
<<
"mmCIF:"
<<
endl
;
std
::
cout
<<
indent
<<
"mmCIF:"
<<
std
::
endl
;
i
=
selected
.
begin
();
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
())
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
;
for
(
auto
j
=
b
+
1
;
j
!=
e
;
++
j
)
...
...
@@ -127,18 +113,18 @@ void DumpSelection(const vector<TLSResidue>& selected, int indentLevel)
else
if
(
j
->
seqID
!=
to
)
// probably an insertion code
{
if
(
from
==
kNoSeqNum
or
to
==
kNoSeqNum
)
cout
<<
indent
<<
" >> "
<<
asymID
<<
endl
;
std
::
cout
<<
indent
<<
" >> "
<<
asymID
<<
std
::
endl
;
else
cout
<<
indent
<<
" >> "
<<
asymID
<<
' '
<<
from
<<
':'
<<
to
<<
endl
;
std
::
cout
<<
indent
<<
" >> "
<<
asymID
<<
' '
<<
from
<<
':'
<<
to
<<
std
::
endl
;
asymID
=
b
->
asymID
;
from
=
to
=
b
->
seqID
;
}
}
if
(
from
==
kNoSeqNum
or
to
==
kNoSeqNum
)
cout
<<
indent
<<
" >> "
<<
asymID
<<
endl
;
std
::
cout
<<
indent
<<
" >> "
<<
asymID
<<
std
::
endl
;
else
cout
<<
indent
<<
" >> "
<<
asymID
<<
' '
<<
from
<<
':'
<<
to
<<
endl
;
std
::
cout
<<
indent
<<
" >> "
<<
asymID
<<
' '
<<
from
<<
':'
<<
to
<<
std
::
endl
;
i
=
e
;
}
...
...
@@ -146,22 +132,22 @@ void DumpSelection(const vector<TLSResidue>& selected, int indentLevel)
if
(
first
)
{
if
(
isatty
(
STDOUT_FILENO
))
cout
<<
indent
<<
cif
::
coloured
(
"Empty selection"
)
<<
endl
;
std
::
cout
<<
indent
<<
cif
::
coloured
(
"Empty selection"
)
<<
std
::
endl
;
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...
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
;
if
(
pdbNamespace
)
...
...
@@ -177,7 +163,7 @@ vector<tuple<string,int,int>> TLSSelection::GetRanges(Datablock& db, bool pdbNam
continue
;
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
});
}
...
...
@@ -185,7 +171,7 @@ vector<tuple<string,int,int>> TLSSelection::GetRanges(Datablock& db, bool pdbNam
// ... those from the 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
)
{
...
...
@@ -204,7 +190,7 @@ vector<tuple<string,int,int>> TLSSelection::GetRanges(Datablock& db, bool pdbNam
continue
;
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
});
}
...
...
@@ -222,17 +208,17 @@ vector<tuple<string,int,int>> TLSSelection::GetRanges(Datablock& db, bool pdbNam
CollectResidues
(
db
,
selected
);
vector
<
tuple
<
string
,
int
,
int
>>
result
;
std
::
vector
<
std
::
tuple
<
std
::
string
,
int
,
int
>>
result
;
auto
i
=
selected
.
begin
();
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
())
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.
// 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
result
.
push_back
(
make_tuple
(
b
->
asymID
,
b
->
seqID
,
b
->
seqID
));
for
(
auto
j
=
b
+
1
;
j
!=
e
;
++
j
)
{
if
(
j
->
seqID
==
get
<
2
>
(
result
.
back
())
+
1
)
get
<
2
>
(
result
.
back
())
=
j
->
seqID
;
else
if
(
j
->
seqID
!=
get
<
2
>
(
result
.
back
()))
// probably an insertion code
if
(
j
->
seqID
==
std
::
get
<
2
>
(
result
.
back
())
+
1
)
std
::
get
<
2
>
(
result
.
back
())
=
j
->
seqID
;
else
if
(
j
->
seqID
!=
std
::
get
<
2
>
(
result
.
back
()))
// probably an insertion code
result
.
push_back
(
make_tuple
(
b
->
asymID
,
j
->
seqID
,
j
->
seqID
));
}
...
...
@@ -257,7 +243,7 @@ struct TLSSelectionNot : public TLSSelection
TLSSelectionNot
(
TLSSelectionPtr
selection
)
:
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
);
...
...
@@ -266,7 +252,7 @@ struct TLSSelectionNot : public TLSSelection
if
(
cif
::
VERBOSE
)
{
cout
<<
string
(
indentLevel
*
2
,
' '
)
<<
"NOT"
<<
endl
;
std
::
cout
<<
std
::
string
(
indentLevel
*
2
,
' '
)
<<
"NOT"
<<
std
::
endl
;
DumpSelection
(
residues
,
indentLevel
);
}
}
...
...
@@ -278,14 +264,14 @@ struct TLSSelectionAll : public TLSSelection
{
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
)
r
.
selected
=
true
;
if
(
cif
::
VERBOSE
)
{
cout
<<
string
(
indentLevel
*
2
,
' '
)
<<
"ALL"
<<
endl
;
std
::
cout
<<
std
::
string
(
indentLevel
*
2
,
' '
)
<<
"ALL"
<<
std
::
endl
;
DumpSelection
(
residues
,
indentLevel
);
}
}
...
...
@@ -293,10 +279,10 @@ struct TLSSelectionAll : public TLSSelection
struct
TLSSelectionChain
:
public
TLSSelectionAll
{
TLSSelectionChain
(
const
string
&
chainID
)
TLSSelectionChain
(
const
st
d
::
st
ring
&
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
==
"*"
;
...
...
@@ -305,12 +291,12 @@ struct TLSSelectionChain : public TLSSelectionAll
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
);
}
}
string
m_chain
;
st
d
::
st
ring
m_chain
;
};
struct
TLSSelectionResID
:
public
TLSSelectionAll
...
...
@@ -318,14 +304,14 @@ struct TLSSelectionResID : public TLSSelectionAll
TLSSelectionResID
(
int
seqNr
,
char
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
)
r
.
selected
=
r
.
seqNr
==
m_seq_nr
and
r
.
iCode
==
m_icode
;
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
);
}
}
...
...
@@ -339,7 +325,7 @@ struct TLSSelectionRangeSeq : public TLSSelectionAll
TLSSelectionRangeSeq
(
int
first
,
int
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
)
{
...
...
@@ -349,7 +335,7 @@ struct TLSSelectionRangeSeq : public TLSSelectionAll
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
);
}
}
...
...
@@ -362,21 +348,21 @@ struct TLSSelectionRangeID : public TLSSelectionAll
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
)
{}
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
s
et
<
string
>
chains
;
s
td
::
set
<
std
::
string
>
chains
;
for
(
auto
&
r
:
residues
)
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
{
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
{
return
r
.
chainID
==
chain
and
r
.
seqNr
==
m_last
and
r
.
iCode
==
m_icode_last
;
});
...
...
@@ -392,7 +378,7 @@ struct TLSSelectionRangeID : public TLSSelectionAll
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
);
}
}
...
...
@@ -409,7 +395,7 @@ struct TLSSelectionUnion : public TLSSelection
TLSSelectionUnion
(
TLSSelectionPtr
&
lhs
,
TLSSelectionPtr
&&
rhs
)
:
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
;
for_each
(
a
.
begin
(),
a
.
end
(),
[](
auto
&
r
)
{
r
.
selected
=
false
;
});
...
...
@@ -425,7 +411,7 @@ struct TLSSelectionUnion : public TLSSelection
if
(
cif
::
VERBOSE
)
{
cout
<<
string
(
indentLevel
*
2
,
' '
)
<<
"Union"
<<
endl
;
std
::
cout
<<
std
::
string
(
indentLevel
*
2
,
' '
)
<<
"Union"
<<
std
::
endl
;
DumpSelection
(
residues
,
indentLevel
);
}
}
...
...
@@ -442,7 +428,7 @@ struct TLSSelectionIntersection : public TLSSelection
TLSSelectionIntersection
(
TLSSelectionPtr
&
lhs
,
TLSSelectionPtr
&&
rhs
)
:
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
;
for_each
(
a
.
begin
(),
a
.
end
(),
[](
auto
&
r
)
{
r
.
selected
=
false
;
});
...
...
@@ -458,7 +444,7 @@ struct TLSSelectionIntersection : public TLSSelection
if
(
cif
::
VERBOSE
)
{
cout
<<
string
(
indentLevel
*
2
,
' '
)
<<
"Intersection"
<<
endl
;
std
::
cout
<<
std
::
string
(
indentLevel
*
2
,
' '
)
<<
"Intersection"
<<
std
::
endl
;
DumpSelection
(
residues
,
indentLevel
);
}
}
...
...
@@ -470,31 +456,31 @@ struct TLSSelectionIntersection : public TLSSelection
struct
TLSSelectionByName
:
public
TLSSelectionAll
{
public
:
TLSSelectionByName
(
const
string
&
resname
)
TLSSelectionByName
(
const
st
d
::
st
ring
&
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
)
r
.
selected
=
r
.
name
==
m_name
;
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
);
}
}
string
m_name
;
st
d
::
st
ring
m_name
;
};
struct
TLSSelectionByElement
:
public
TLSSelectionAll
{
public
:
TLSSelectionByElement
(
const
string
&
element
)
TLSSelectionByElement
(
const
st
d
::
st
ring
&
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
// residues that have just a single atom of type m_element.
...
...
@@ -506,12 +492,12 @@ struct TLSSelectionByElement : public TLSSelectionAll
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
);
}
}
string
m_element
;
st
d
::
st
ring
m_element
;
};
// --------------------------------------------------------------------
...
...
@@ -519,7 +505,7 @@ struct TLSSelectionByElement : public TLSSelectionAll
class
TLSSelectionParserImpl
{
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
())
{}
virtual
TLSSelectionPtr
Parse
()
=
0
;
...
...
@@ -528,12 +514,12 @@ class TLSSelectionParserImpl
virtual
int
GetNextToken
()
=
0
;
virtual
void
Match
(
int
token
);
virtual
string
ToString
(
int
token
)
=
0
;
virtual
st
d
::
st
ring
ToString
(
int
token
)
=
0
;
string
m_selection
;
string
::
iterator
m_p
,
m_end
;
st
d
::
st
ring
m_selection
;
st
d
::
st
ring
::
iterator
m_p
,
m_end
;
int
m_lookahead
;
string
m_token
;
st
d
::
st
ring
m_token
;
};
...
...
@@ -543,19 +529,19 @@ void TLSSelectionParserImpl::Match(int token)
m_lookahead
=
GetNextToken
();
else
{
string
expected
;
st
d
::
st
ring
expected
;
if
(
token
>=
256
)
expected
=
ToString
(
token
);
else
expected
=
{
char
(
token
)
};
string
found
;
st
d
::
st
ring
found
;
if
(
m_lookahead
>=
256
)
found
=
ToString
(
m_lookahead
)
+
" ("
+
m_token
+
')'
;
else
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)
class
TLSSelectionParserImplPhenix
:
public
TLSSelectionParserImpl
{
public
:
TLSSelectionParserImplPhenix
(
const
string
&
selection
)
TLSSelectionParserImplPhenix
(
const
st
d
::
st
ring
&
selection
)
:
TLSSelectionParserImpl
(
selection
)
{
m_lookahead
=
GetNextToken
();
...
...
@@ -601,10 +587,10 @@ class TLSSelectionParserImplPhenix : public TLSSelectionParserImpl
};
virtual
int
GetNextToken
();
virtual
string
ToString
(
int
token
);
virtual
st
d
::
st
ring
ToString
(
int
token
);
int
m_value_i
;
string
m_value_s
;
st
d
::
st
ring
m_value_s
;
char
m_icode
;
};
...
...
@@ -793,7 +779,7 @@ int TLSSelectionParserImplPhenix::GetNextToken()
if
(
ch
==
'\''
)
result
=
pt_STRING
;
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
m_value_s
+=
ch
;
break
;
...
...
@@ -814,7 +800,7 @@ int TLSSelectionParserImplPhenix::GetNextToken()
if
(
ch
==
'\"'
)
result
=
pt_STRING
;
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
m_value_s
+=
ch
;
break
;
...
...
@@ -857,7 +843,7 @@ int TLSSelectionParserImplPhenix::GetNextToken()
return
result
;
}
string
TLSSelectionParserImplPhenix
::
ToString
(
int
token
)
st
d
::
st
ring
TLSSelectionParserImplPhenix
::
ToString
(
int
token
)
{
switch
(
token
)
{
...
...
@@ -891,7 +877,7 @@ TLSSelectionPtr TLSSelectionParserImplPhenix::Parse()
Match
(
pt_KW_PDB
);
// Match(pt_KW_ENTRY);
throw
runtime_error
(
"Unimplemented PDB ENTRY specification"
);
throw
std
::
runtime_error
(
"Unimplemented PDB ENTRY specification"
);
}
TLSSelectionPtr
result
=
ParseAtomSelection
();
...
...
@@ -907,7 +893,7 @@ TLSSelectionPtr TLSSelectionParserImplPhenix::Parse()
Match
(
pt_EOLN
);
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
;
}
...
...
@@ -948,7 +934,7 @@ TLSSelectionPtr TLSSelectionParserImplPhenix::ParseFactor()
Match
(
'('
);
result
=
ParseAtomSelection
();
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
Match
(
')'
);
break
;
...
...
@@ -962,10 +948,10 @@ TLSSelectionPtr TLSSelectionParserImplPhenix::ParseFactor()
{
Match
(
pt_KW_CHAIN
);
string
chainID
=
m_value_s
;
st
d
::
st
ring
chainID
=
m_value_s
;
if
(
m_lookahead
==
pt_NUMBER
)
// sigh
{
chainID
=
to_string
(
m_value_i
);
chainID
=
std
::
to_string
(
m_value_i
);
Match
(
pt_NUMBER
);
}
else
...
...
@@ -978,7 +964,7 @@ TLSSelectionPtr TLSSelectionParserImplPhenix::ParseFactor()
case
pt_KW_RESNAME
:
{
Match
(
pt_KW_RESNAME
);
string
name
=
m_value_s
;
st
d
::
st
ring
name
=
m_value_s
;
Match
(
pt_IDENT
);
result
.
reset
(
new
TLSSelectionByName
(
name
));
break
;
...
...
@@ -987,7 +973,7 @@ TLSSelectionPtr TLSSelectionParserImplPhenix::ParseFactor()
case
pt_KW_ELEMENT
:
{
Match
(
pt_KW_ELEMENT
);
string
element
=
m_value_s
;
st
d
::
st
ring
element
=
m_value_s
;
Match
(
pt_IDENT
);
result
.
reset
(
new
TLSSelectionByElement
(
element
));
break
;
...
...
@@ -1050,7 +1036,7 @@ TLSSelectionPtr TLSSelectionParserImplPhenix::ParseFactor()
else
{
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
));
}
...
...
@@ -1067,7 +1053,7 @@ TLSSelectionPtr TLSSelectionParserImplPhenix::ParseFactor()
break
;
default
:
throw
runtime_error
(
"Unexpected token "
+
ToString
(
m_lookahead
)
+
" ("
+
m_token
+
')'
);
throw
std
::
runtime_error
(
"Unexpected token "
+
ToString
(
m_lookahead
)
+
" ("
+
m_token
+
')'
);
}
return
result
;
...
...
@@ -1078,7 +1064,7 @@ TLSSelectionPtr TLSSelectionParserImplPhenix::ParseFactor()
class
TLSSelectionParserImplBuster
:
public
TLSSelectionParserImpl
{
public
:
TLSSelectionParserImplBuster
(
const
string
&
selection
);
TLSSelectionParserImplBuster
(
const
st
d
::
st
ring
&
selection
);
virtual
TLSSelectionPtr
Parse
();
...
...
@@ -1092,19 +1078,19 @@ class TLSSelectionParserImplBuster : public TLSSelectionParserImpl
};
virtual
int
GetNextToken
();
virtual
string
ToString
(
int
token
);
virtual
st
d
::
st
ring
ToString
(
int
token
);
TLSSelectionPtr
ParseGroup
();
tuple
<
string
,
int
>
ParseAtom
();
std
::
tuple
<
std
::
string
,
int
>
ParseAtom
();
TLSSelectionPtr
ParseOldGroup
();
int
m_value_i
;
string
m_value_s
;
st
d
::
st
ring
m_value_s
;
bool
m_parsing_old_style
=
false
;
};
TLSSelectionParserImplBuster
::
TLSSelectionParserImplBuster
(
const
string
&
selection
)
TLSSelectionParserImplBuster
::
TLSSelectionParserImplBuster
(
const
st
d
::
st
ring
&
selection
)
:
TLSSelectionParserImpl
(
selection
)
{
m_lookahead
=
GetNextToken
();
...
...
@@ -1192,12 +1178,12 @@ int TLSSelectionParserImplBuster::GetNextToken()
return
result
;
}
string
TLSSelectionParserImplBuster
::
ToString
(
int
token
)
st
d
::
st
ring
TLSSelectionParserImplBuster
::
ToString
(
int
token
)
{
switch
(
token
)
{
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"
;
default
:
...
...
@@ -1210,7 +1196,7 @@ TLSSelectionPtr TLSSelectionParserImplBuster::ParseGroup()
{
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
sr
(
new
TLSSelectionRangeSeq
(
from
,
to
));
...
...
@@ -1226,13 +1212,13 @@ TLSSelectionPtr TLSSelectionParserImplBuster::ParseGroup()
do
{
string
chain1
;
st
d
::
st
ring
chain1
;
int
seqNr1
;
std
::
tie
(
chain1
,
seqNr1
)
=
ParseAtom
();
if
(
m_lookahead
==
'-'
)
{
string
chain2
;
st
d
::
st
ring
chain2
;
int
seqNr2
=
seqNr1
;
Match
(
'-'
);
...
...
@@ -1247,7 +1233,7 @@ TLSSelectionPtr TLSSelectionParserImplBuster::ParseGroup()
std
::
tie
(
chain2
,
seqNr2
)
=
ParseAtom
();
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
sr1
(
new
TLSSelectionRangeSeq
(
seqNr1
,
kResidueNrWildcard
));
...
...
@@ -1281,9 +1267,9 @@ TLSSelectionPtr TLSSelectionParserImplBuster::ParseGroup()
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
;
if
(
m_lookahead
==
'*'
)
...
...
@@ -1303,10 +1289,10 @@ tuple<string,int> TLSSelectionParserImplBuster::ParseAtom()
if
(
m_lookahead
==
':'
)
{
Match
(
':'
);
string
atom
=
m_value_s
;
st
d
::
st
ring
atom
=
m_value_s
;
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
);
}
...
...
@@ -1327,7 +1313,7 @@ TLSSelectionPtr TLSSelectionParserImplBuster::Parse()
class
TLSSelectionParserImplBusterOld
:
public
TLSSelectionParserImpl
{
public
:
TLSSelectionParserImplBusterOld
(
const
string
&
selection
)
TLSSelectionParserImplBusterOld
(
const
st
d
::
st
ring
&
selection
)
:
TLSSelectionParserImpl
(
selection
)
{
m_lookahead
=
GetNextToken
();
...
...
@@ -1368,10 +1354,10 @@ class TLSSelectionParserImplBusterOld : public TLSSelectionParserImpl
};
virtual
int
GetNextToken
();
virtual
string
ToString
(
int
token
);
virtual
st
d
::
st
ring
ToString
(
int
token
);
int
m_value_i
;
string
m_value_s
;
st
d
::
st
ring
m_value_s
;
int
m_value_r
[
2
];
};
...
...
@@ -1493,7 +1479,7 @@ int TLSSelectionParserImplBusterOld::GetNextToken()
case
st_CHAINRESID
:
if
(
isalpha
(
ch
))
{
m_value_s
+=
to_string
(
m_value_i
);
m_value_s
+=
std
::
to_string
(
m_value_i
);
m_value_s
+=
ch
;
state
=
st_IDENT
;
}
...
...
@@ -1533,7 +1519,7 @@ int TLSSelectionParserImplBusterOld::GetNextToken()
if
(
ch
==
'\''
)
result
=
pt_STRING
;
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
m_value_s
+=
ch
;
break
;
...
...
@@ -1570,14 +1556,14 @@ int TLSSelectionParserImplBusterOld::GetNextToken()
return
result
;
}
string
TLSSelectionParserImplBusterOld
::
ToString
(
int
token
)
st
d
::
st
ring
TLSSelectionParserImplBusterOld
::
ToString
(
int
token
)
{
switch
(
token
)
{
case
pt_IDENT
:
return
"identifier ("
+
m_value_s
+
')'
;
case
pt_STRING
:
return
"string ("
+
m_value_s
+
')'
;
case
pt_NUMBER
:
return
"number ("
+
to_string
(
m_value_i
)
+
')'
;
case
pt_RANGE
:
return
"range ("
+
to_string
(
m_value_r
[
0
])
+
':'
+
to_string
(
m_value_r
[
1
])
+
')'
;
case
pt_NUMBER
:
return
"number ("
+
std
::
to_string
(
m_value_i
)
+
')'
;
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_KW_ALL
:
return
"ALL"
;
...
...
@@ -1605,7 +1591,7 @@ TLSSelectionPtr TLSSelectionParserImplBusterOld::Parse()
Match
(
pt_KW_PDB
);
// Match(pt_KW_ENTRY);
throw
runtime_error
(
"Unimplemented PDB ENTRY specification"
);
throw
std
::
runtime_error
(
"Unimplemented PDB ENTRY specification"
);
}
TLSSelectionPtr
result
=
ParseAtomSelection
();
...
...
@@ -1662,10 +1648,10 @@ TLSSelectionPtr TLSSelectionParserImplBusterOld::ParseFactor()
{
Match
(
pt_KW_CHAIN
);
string
chainID
=
m_value_s
;
st
d
::
st
ring
chainID
=
m_value_s
;
if
(
m_lookahead
==
pt_NUMBER
)
// sigh
{
chainID
=
to_string
(
m_value_i
);
chainID
=
std
::
to_string
(
m_value_i
);
Match
(
pt_NUMBER
);
}
else
...
...
@@ -1678,7 +1664,7 @@ TLSSelectionPtr TLSSelectionParserImplBusterOld::ParseFactor()
case
pt_KW_RESNAME
:
{
Match
(
pt_KW_RESNAME
);
string
name
=
m_value_s
;
st
d
::
st
ring
name
=
m_value_s
;
Match
(
pt_IDENT
);
result
.
reset
(
new
TLSSelectionByName
(
name
));
break
;
...
...
@@ -1704,7 +1690,7 @@ TLSSelectionPtr TLSSelectionParserImplBusterOld::ParseFactor()
break
;
default
:
throw
runtime_error
(
"Unexpected token "
+
ToString
(
m_lookahead
));
throw
std
::
runtime_error
(
"Unexpected token "
+
ToString
(
m_lookahead
));
}
return
result
;
...
...
@@ -1766,7 +1752,7 @@ TLSSelectionPtr TLSSelectionParserImplBusterOld::ParseChainResid()
int
from
,
to
;
from
=
to
=
m_value_i
;
string
chainID
=
m_value_s
;
st
d
::
st
ring
chainID
=
m_value_s
;
Match
(
pt_CHAINRESID
);
...
...
@@ -1776,7 +1762,7 @@ TLSSelectionPtr TLSSelectionParserImplBusterOld::ParseChainResid()
to
=
m_value_i
;
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
);
}
...
...
@@ -1807,7 +1793,7 @@ TLSSelectionPtr TLSSelectionParserImplBusterOld::ParseChainResid()
class
TLSSelectionParserBase
{
public
:
virtual
TLSSelectionPtr
Parse
(
const
string
&
selection
)
const
=
0
;
virtual
TLSSelectionPtr
Parse
(
const
st
d
::
st
ring
&
selection
)
const
=
0
;
virtual
~
TLSSelectionParserBase
()
{}
};
...
...
@@ -1815,7 +1801,7 @@ template<typename IMPL>
class
TLSSelectionParser
{
public
:
virtual
TLSSelectionPtr
Parse
(
const
string
&
selection
)
const
virtual
TLSSelectionPtr
Parse
(
const
st
d
::
st
ring
&
selection
)
const
{
TLSSelectionPtr
result
;
...
...
@@ -1824,9 +1810,9 @@ class TLSSelectionParser
IMPL
p
(
selection
);
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
;
...
...
@@ -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
<
TLSSelectionParserImplBuster
>
buster
;
...
...
@@ -1851,14 +1837,14 @@ TLSSelectionPtr ParseSelectionDetails(const string& program, const string& selec
if
(
not
result
)
{
if
(
cif
::
VERBOSE
)
cerr
<<
"Falling back to old BUSTER"
<<
endl
;
std
::
cerr
<<
"Falling back to old BUSTER"
<<
std
::
endl
;
result
=
busterOld
.
Parse
(
selection
);
}
if
(
not
result
)
{
if
(
cif
::
VERBOSE
)
cerr
<<
"Falling back to PHENIX"
<<
endl
;
std
::
cerr
<<
"Falling back to PHENIX"
<<
std
::
endl
;
result
=
phenix
.
Parse
(
selection
);
}
}
...
...
@@ -1869,35 +1855,35 @@ TLSSelectionPtr ParseSelectionDetails(const string& program, const string& selec
if
(
not
result
)
{
if
(
cif
::
VERBOSE
)
cerr
<<
"Falling back to BUSTER"
<<
endl
;
std
::
cerr
<<
"Falling back to BUSTER"
<<
std
::
endl
;
result
=
buster
.
Parse
(
selection
);
}
if
(
not
result
)
{
if
(
cif
::
VERBOSE
)
cerr
<<
"Falling back to old BUSTER"
<<
endl
;
std
::
cerr
<<
"Falling back to old BUSTER"
<<
std
::
endl
;
result
=
busterOld
.
Parse
(
selection
);
}
}
else
{
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
);
if
(
not
result
)
{
if
(
cif
::
VERBOSE
)
cerr
<<
"Falling back to BUSTER"
<<
endl
;
std
::
cerr
<<
"Falling back to BUSTER"
<<
std
::
endl
;
result
=
buster
.
Parse
(
selection
);
}
if
(
not
result
)
{
if
(
cif
::
VERBOSE
)
cerr
<<
"Falling back to old BUSTER"
<<
endl
;
std
::
cerr
<<
"Falling back to old BUSTER"
<<
std
::
endl
;
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