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
700575ad
Unverified
Commit
700575ad
authored
Aug 15, 2022
by
Maarten L. Hekkelman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Merged
parent
9fe6e5df
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
61 additions
and
123 deletions
+61
-123
CMakeLists.txt
+3
-4
include/cif++/cif/validate.hpp
+1
-0
include/cif++/structure/BondMap.hpp
+1
-1
src/Cif++.cpp
+13
-49
src/cif/file.cpp
+3
-11
src/cif/validate.cpp
+1
-1
src/structure/BondMap.cpp
+11
-11
src/structure/Compound.cpp
+14
-14
src/structure/Structure.cpp
+14
-32
No files found.
CMakeLists.txt
View file @
700575ad
...
...
@@ -215,8 +215,8 @@ set(project_sources
# ${PROJECT_SOURCE_DIR}/src/pdb/PDB2Cif.cpp
# ${PROJECT_SOURCE_DIR}/src/pdb/PDB2CifRemark3.cpp
#
${PROJECT_SOURCE_DIR}/src/structure/AtomType.cpp
#
${PROJECT_SOURCE_DIR}/src/structure/BondMap.cpp
${
PROJECT_SOURCE_DIR
}
/src/structure/AtomType.cpp
${
PROJECT_SOURCE_DIR
}
/src/structure/BondMap.cpp
# ${PROJECT_SOURCE_DIR}/src/structure/Compound.cpp
# ${PROJECT_SOURCE_DIR}/src/structure/Secondary.cpp
# ${PROJECT_SOURCE_DIR}/src/structure/Structure.cpp
...
...
@@ -261,14 +261,13 @@ add_library(cifpp ${project_sources} ${project_headers} ${CMAKE_SOURCE_DIR}/src/
set_target_properties
(
cifpp PROPERTIES POSITION_INDEPENDENT_CODE ON
)
if
(
NEED_BOOST_REGEX
)
target_compile_definitions
(
cifpp PUBLIC USE_BOOST_REGEX=1
)
target_compile_definitions
(
cifpp PUBLIC USE_BOOST_REGEX=1
BOOST_REGEX_STANDALONE=1
)
endif
()
target_include_directories
(
cifpp
PUBLIC
"$<BUILD_INTERFACE:
${
PROJECT_SOURCE_DIR
}
/include>"
"$<INSTALL_INTERFACE:
${
CMAKE_INSTALL_INCLUDEDIR
}
>"
${
Boost_INCLUDE_DIR
}
)
target_include_directories
(
cifpp
...
...
include/cif++/cif/validate.hpp
View file @
700575ad
...
...
@@ -29,6 +29,7 @@
#include <filesystem>
#include <list>
#include <mutex>
#include <utility>
#include <cif++/utilities.hpp>
...
...
include/cif++/structure/BondMap.hpp
View file @
700575ad
...
...
@@ -30,7 +30,7 @@
#include <stdexcept>
#include <unordered_map>
#include <cif++/Structure.hpp>
#include <cif++/
structure/
Structure.hpp>
namespace
mmcif
{
...
...
src/Cif++.cpp
View file @
700575ad
...
...
@@ -38,7 +38,7 @@
#include <filesystem>
#include <
gzstream/g
zstream.hpp>
#include <
zstream/
zstream.hpp>
#include <boost/logic/tribool.hpp>
...
...
@@ -3448,50 +3448,24 @@ void File::load(const std::filesystem::path &p)
{
fs
::
path
path
(
p
);
if
(
path
.
extension
()
==
".gz"
)
{
gzstream
::
ifstream
in
(
p
);
zstream
::
ifstream
in
(
p
);
try
{
load
(
in
);
}
catch
(
const
std
::
exception
&
ex
)
{
if
(
cif
::
VERBOSE
>=
0
)
std
::
cerr
<<
"Error loading file "
<<
path
<<
std
::
endl
;
throw
;
}
try
{
load
(
in
);
}
else
catch
(
const
std
::
exception
&
ex
)
{
std
::
ifstream
inFile
(
p
,
std
::
ios_base
::
in
|
std
::
ios_base
::
binary
);
try
{
load
(
inFile
);
}
catch
(
const
std
::
exception
&
ex
)
{
if
(
cif
::
VERBOSE
>=
0
)
std
::
cerr
<<
"Error loading file "
<<
path
<<
std
::
endl
;
throw
;
}
if
(
cif
::
VERBOSE
>=
0
)
std
::
cerr
<<
"Error loading file "
<<
path
<<
std
::
endl
;
throw
;
}
}
void
File
::
save
(
const
std
::
filesystem
::
path
&
p
)
{
if
(
p
.
extension
()
==
".gz"
)
{
gzstream
::
ofstream
outFile
(
p
);
save
(
outFile
);
}
else
{
std
::
ofstream
outFile
(
p
,
std
::
ios_base
::
out
|
std
::
ios_base
::
binary
);
save
(
outFile
);
}
zstream
::
ofstream
outFile
(
p
);
save
(
outFile
);
}
void
File
::
load
(
std
::
istream
&
is
)
...
...
@@ -3526,23 +3500,13 @@ void File::load(std::istream &is, const std::string &datablock)
void
File
::
load
(
const
char
*
data
,
std
::
size_t
length
)
{
bool
gzipped
=
length
>
2
and
data
[
0
]
==
static_cast
<
char
>
(
0x1f
)
and
data
[
1
]
==
static_cast
<
char
>
(
0x8b
);
struct
membuf
:
public
std
::
streambuf
{
membuf
(
char
*
data
,
size_t
length
)
{
this
->
setg
(
data
,
data
,
data
+
length
);
}
}
buffer
(
const_cast
<
char
*>
(
data
),
length
);
if
(
gzipped
)
{
gzstream
::
istream
is
(
&
buffer
);
load
(
is
);
}
else
{
std
::
istream
is
(
&
buffer
);
load
(
is
);
}
zstream
::
istream
is
(
&
buffer
);
load
(
is
);
}
void
File
::
save
(
std
::
ostream
&
os
)
...
...
src/cif/file.cpp
View file @
700575ad
...
...
@@ -24,7 +24,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <
gzstream/g
zstream.hpp>
#include <
zstream/
zstream.hpp>
#include <cif++/cif/file.hpp>
...
...
@@ -161,16 +161,8 @@ void file::load(std::istream &is)
void
file
::
save
(
const
std
::
filesystem
::
path
&
p
)
const
{
if
(
p
.
extension
()
==
".gz"
)
{
gzstream
::
ofstream
outFile
(
p
);
save
(
outFile
);
}
else
{
std
::
ofstream
outFile
(
p
,
std
::
ios_base
::
binary
);
save
(
outFile
);
}
zstream
::
ofstream
outFile
(
p
);
save
(
outFile
);
}
void
file
::
save
(
std
::
ostream
&
os
)
const
...
...
src/cif/validate.cpp
View file @
700575ad
...
...
@@ -435,7 +435,7 @@ const validator &validator_factory::operator[](std::string_view dictionary_name)
if
(
std
::
filesystem
::
exists
(
p
,
ec
)
and
not
ec
)
{
g
xrio
::
ifstream
in
(
p
);
g
zstream
::
ifstream
in
(
p
);
if
(
not
in
.
is_open
())
throw
std
::
runtime_error
(
"Could not open dictionary ("
+
p
.
string
()
+
")"
);
...
...
src/structure/BondMap.cpp
View file @
700575ad
...
...
@@ -28,10 +28,10 @@
#include <fstream>
#include <mutex>
#include <cif++/BondMap.hpp>
#include <cif++/Cif++.hpp>
#include <cif++/cif.hpp>
#include <cif++/structure/BondMap.hpp>
#include <cif++/structure/Compound.hpp>
#include <cif++/utilities.hpp>
#include <cif++/Compound.hpp>
namespace
mmcif
{
...
...
@@ -233,7 +233,7 @@ BondMap::BondMap(const Structure &p)
link
[
b
].
insert
(
a
);
};
cif
::
D
atablock
&
db
=
p
.
datablock
();
cif
::
v2
::
d
atablock
&
db
=
p
.
datablock
();
// collect all compounds first
std
::
set
<
std
::
string
>
compounds
;
...
...
@@ -266,7 +266,7 @@ BondMap::BondMap(const Structure &p)
std
::
string
lastAsymID
,
lastAuthSeqID
;
int
lastSeqID
=
0
;
for
(
const
auto
&
[
asymID
,
seqID
,
authSeqID
]
:
db
[
"pdbx_poly_seq_scheme"
].
rows
<
std
::
string
,
int
,
std
::
string
>
(
"asym_id"
,
"seq_id"
,
"pdb_seq_num"
))
for
(
const
auto
&
[
asymID
,
seqID
,
authSeqID
]
:
db
[
"pdbx_poly_seq_scheme"
].
rows
<
std
::
string
,
int
,
std
::
string
>
(
"asym_id"
,
"seq_id"
,
"pdb_seq_num"
))
{
if
(
asymID
!=
lastAsymID
)
// first in a new sequece
{
...
...
@@ -298,7 +298,7 @@ BondMap::BondMap(const Structure &p)
int
seqId1
=
0
,
seqId2
=
0
;
std
::
string
authSeqId1
,
authSeqId2
;
cif
::
tie
(
asym1
,
asym2
,
atomId1
,
atomId2
,
seqId1
,
seqId2
,
authSeqId1
,
authSeqId2
)
=
cif
::
v2
::
tie
(
asym1
,
asym2
,
atomId1
,
atomId2
,
seqId1
,
seqId2
,
authSeqId1
,
authSeqId2
)
=
l
.
get
(
"ptnr1_label_asym_id"
,
"ptnr2_label_asym_id"
,
"ptnr1_label_atom_id"
,
"ptnr2_label_atom_id"
,
"ptnr1_label_seq_id"
,
"ptnr2_label_seq_id"
,
...
...
@@ -341,11 +341,11 @@ BondMap::BondMap(const Structure &p)
};
// loop over poly_seq_scheme
for
(
auto
r
:
db
[
"pdbx_poly_seq_scheme"
].
find
(
cif
::
K
ey
(
"mon_id"
)
==
c
))
for
(
auto
r
:
db
[
"pdbx_poly_seq_scheme"
].
find
(
cif
::
v2
::
k
ey
(
"mon_id"
)
==
c
))
{
std
::
string
asymID
;
int
seqID
;
cif
::
tie
(
asymID
,
seqID
)
=
r
.
get
(
"asym_id"
,
"seq_id"
);
cif
::
v2
::
tie
(
asymID
,
seqID
)
=
r
.
get
(
"asym_id"
,
"seq_id"
);
std
::
vector
<
Atom
>
rAtoms
;
copy_if
(
atoms
.
begin
(),
atoms
.
end
(),
back_inserter
(
rAtoms
),
...
...
@@ -363,10 +363,10 @@ BondMap::BondMap(const Structure &p)
}
// loop over pdbx_nonpoly_scheme
for
(
auto
r
:
db
[
"pdbx_nonpoly_scheme"
].
find
(
cif
::
K
ey
(
"mon_id"
)
==
c
))
for
(
auto
r
:
db
[
"pdbx_nonpoly_scheme"
].
find
(
cif
::
v2
::
k
ey
(
"mon_id"
)
==
c
))
{
std
::
string
asymID
;
cif
::
tie
(
asymID
)
=
r
.
get
(
"asym_id"
);
cif
::
v2
::
tie
(
asymID
)
=
r
.
get
(
"asym_id"
);
std
::
vector
<
Atom
>
rAtoms
;
copy_if
(
atoms
.
begin
(),
atoms
.
end
(),
back_inserter
(
rAtoms
),
...
...
@@ -389,7 +389,7 @@ BondMap::BondMap(const Structure &p)
}
// loop over pdbx_branch_scheme
for
(
const
auto
&
[
asym_id
,
pdb_seq_num
]
:
db
[
"pdbx_branch_scheme"
].
find
<
std
::
string
,
std
::
string
>
(
cif
::
K
ey
(
"mon_id"
)
==
c
,
"asym_id"
,
"pdb_seq_num"
))
for
(
const
auto
&
[
asym_id
,
pdb_seq_num
]
:
db
[
"pdbx_branch_scheme"
].
find
<
std
::
string
,
std
::
string
>
(
cif
::
v2
::
k
ey
(
"mon_id"
)
==
c
,
"asym_id"
,
"pdb_seq_num"
))
{
std
::
vector
<
Atom
>
rAtoms
;
copy_if
(
atoms
.
begin
(),
atoms
.
end
(),
back_inserter
(
rAtoms
),
...
...
src/structure/Compound.cpp
View file @
700575ad
...
...
@@ -32,11 +32,11 @@
#include <filesystem>
#include <fstream>
#include <cif++/
Cif++
.hpp>
#include <cif++/CifParser.hpp>
#include <cif++/
cif
.hpp>
//
#include <cif++/CifParser.hpp>
#include <cif++/utilities.hpp>
#include <cif++/Compound.hpp>
#include <cif++/
P
oint.hpp>
#include <cif++/
structure/
Compound.hpp>
#include <cif++/
p
oint.hpp>
namespace
fs
=
std
::
filesystem
;
...
...
@@ -112,14 +112,14 @@ struct CompoundBondLess
// --------------------------------------------------------------------
// Compound
Compound
::
Compound
(
cif
::
D
atablock
&
db
)
Compound
::
Compound
(
cif
::
v2
::
d
atablock
&
db
)
{
auto
&
chemComp
=
db
[
"chem_comp"
];
if
(
chemComp
.
size
()
!=
1
)
throw
std
::
runtime_error
(
"Invalid compound file, chem_comp should contain a single row"
);
cif
::
tie
(
mID
,
mName
,
mType
,
mFormula
,
mFormulaWeight
,
mFormalCharge
)
=
cif
::
v2
::
tie
(
mID
,
mName
,
mType
,
mFormula
,
mFormulaWeight
,
mFormalCharge
)
=
chemComp
.
front
().
get
(
"id"
,
"name"
,
"type"
,
"formula"
,
"formula_weight"
,
"pdbx_formal_charge"
);
// The name should not contain newline characters since that triggers validation errors later on
...
...
@@ -132,7 +132,7 @@ Compound::Compound(cif::Datablock &db)
{
CompoundAtom
atom
;
std
::
string
typeSymbol
;
cif
::
tie
(
atom
.
id
,
typeSymbol
,
atom
.
charge
,
atom
.
aromatic
,
atom
.
leavingAtom
,
atom
.
stereoConfig
,
atom
.
x
,
atom
.
y
,
atom
.
z
)
=
cif
::
v2
::
tie
(
atom
.
id
,
typeSymbol
,
atom
.
charge
,
atom
.
aromatic
,
atom
.
leavingAtom
,
atom
.
stereoConfig
,
atom
.
x
,
atom
.
y
,
atom
.
z
)
=
row
.
get
(
"atom_id"
,
"type_symbol"
,
"charge"
,
"pdbx_aromatic_flag"
,
"pdbx_leaving_atom_flag"
,
"pdbx_stereo_config"
,
"model_Cartn_x"
,
"model_Cartn_y"
,
"model_Cartn_z"
);
atom
.
typeSymbol
=
AtomTypeTraits
(
typeSymbol
).
type
();
...
...
@@ -144,13 +144,13 @@ Compound::Compound(cif::Datablock &db)
{
CompoundBond
bond
;
std
::
string
valueOrder
;
cif
::
tie
(
bond
.
atomID
[
0
],
bond
.
atomID
[
1
],
valueOrder
,
bond
.
aromatic
,
bond
.
stereoConfig
)
=
row
.
get
(
"atom_id_1"
,
"atom_id_2"
,
"value_order"
,
"pdbx_aromatic_flag"
,
"pdbx_stereo_config"
);
cif
::
v2
::
tie
(
bond
.
atomID
[
0
],
bond
.
atomID
[
1
],
valueOrder
,
bond
.
aromatic
,
bond
.
stereoConfig
)
=
row
.
get
(
"atom_id_1"
,
"atom_id_2"
,
"value_order"
,
"pdbx_aromatic_flag"
,
"pdbx_stereo_config"
);
bond
.
type
=
from_string
(
valueOrder
);
mBonds
.
push_back
(
std
::
move
(
bond
));
}
}
Compound
::
Compound
(
cif
::
D
atablock
&
db
,
const
std
::
string
&
id
,
const
std
::
string
&
name
,
const
std
::
string
&
type
,
const
std
::
string
&
group
)
Compound
::
Compound
(
cif
::
v2
::
d
atablock
&
db
,
const
std
::
string
&
id
,
const
std
::
string
&
name
,
const
std
::
string
&
type
,
const
std
::
string
&
group
)
:
mID
(
id
)
,
mName
(
name
)
,
mType
(
type
)
...
...
@@ -161,7 +161,7 @@ Compound::Compound(cif::Datablock &db, const std::string &id, const std::string
{
CompoundAtom
atom
;
std
::
string
typeSymbol
;
cif
::
tie
(
atom
.
id
,
typeSymbol
,
atom
.
charge
,
atom
.
x
,
atom
.
y
,
atom
.
z
)
=
cif
::
v2
::
tie
(
atom
.
id
,
typeSymbol
,
atom
.
charge
,
atom
.
x
,
atom
.
y
,
atom
.
z
)
=
row
.
get
(
"atom_id"
,
"type_symbol"
,
"charge"
,
"x"
,
"y"
,
"z"
);
atom
.
typeSymbol
=
AtomTypeTraits
(
typeSymbol
).
type
();
...
...
@@ -176,7 +176,7 @@ Compound::Compound(cif::Datablock &db, const std::string &id, const std::string
{
CompoundBond
bond
;
std
::
string
btype
;
cif
::
tie
(
bond
.
atomID
[
0
],
bond
.
atomID
[
1
],
btype
,
bond
.
aromatic
)
=
row
.
get
(
"atom_id_1"
,
"atom_id_2"
,
"type"
,
"aromatic"
);
cif
::
v2
::
tie
(
bond
.
atomID
[
0
],
bond
.
atomID
[
1
],
btype
,
bond
.
aromatic
)
=
row
.
get
(
"atom_id_1"
,
"atom_id_2"
,
"type"
,
"aromatic"
);
using
cif
::
iequals
;
...
...
@@ -446,7 +446,7 @@ class CCDCompoundFactoryImpl : public CompoundFactoryImpl
Compound
*
create
(
const
std
::
string
&
id
)
override
;
cif
::
D
atablockIndex
mIndex
;
cif
::
v2
::
d
atablockIndex
mIndex
;
fs
::
path
mCompoundsFile
;
};
...
...
@@ -562,7 +562,7 @@ Compound *CCP4CompoundFactoryImpl::create(const std::string &id)
auto
&
cat
=
mFile
[
"comp_list"
][
"chem_comp"
];
auto
rs
=
cat
.
find
(
cif
::
K
ey
(
"three_letter_code"
)
==
id
);
auto
rs
=
cat
.
find
(
cif
::
v2
::
k
ey
(
"three_letter_code"
)
==
id
);
if
(
rs
.
size
()
==
1
)
{
...
...
@@ -570,7 +570,7 @@ Compound *CCP4CompoundFactoryImpl::create(const std::string &id)
std
::
string
name
,
group
;
uint32_t
numberAtomsAll
,
numberAtomsNh
;
cif
::
tie
(
name
,
group
,
numberAtomsAll
,
numberAtomsNh
)
=
cif
::
v2
::
tie
(
name
,
group
,
numberAtomsAll
,
numberAtomsNh
)
=
row
.
get
(
"name"
,
"group"
,
"number_atoms_all"
,
"number_atoms_nh"
);
fs
::
path
resFile
=
mCLIBD_MON
/
cif
::
toLowerCopy
(
id
.
substr
(
0
,
1
))
/
(
id
+
".cif"
);
...
...
src/structure/Structure.cpp
View file @
700575ad
...
...
@@ -31,7 +31,7 @@
#include <iomanip>
#include <numeric>
#include <
gzstream/g
zstream.hpp>
#include <
zstream/
zstream.hpp>
#if __cpp_lib_format
#include <format>
...
...
@@ -1285,28 +1285,16 @@ float Branch::weight() const
void
File
::
load
(
const
std
::
filesystem
::
path
&
path
)
{
std
::
string
ext
=
path
.
extension
().
string
();
if
(
ext
==
".gz"
)
{
gzstream
::
ifstream
in
(
path
);
zstream
::
ifstream
in
(
path
);
auto
ext
=
path
.
extension
().
string
();
if
(
ext
==
".gz"
or
ext
=
".xz"
)
ext
=
path
.
stem
().
extension
().
string
();
if
(
ext
==
".pdb"
or
ext
==
".ent"
)
ReadPDBFile
(
in
,
*
this
);
else
cif
::
File
::
load
(
in
);
}
if
(
ext
==
".pdb"
or
ext
==
".ent"
)
ReadPDBFile
(
in
,
*
this
);
else
{
std
::
ifstream
in
(
path
,
std
::
ios_base
::
binary
);
if
(
ext
==
".pdb"
or
ext
==
".ent"
)
ReadPDBFile
(
in
,
*
this
);
else
cif
::
File
::
load
(
in
);
}
cif
::
File
::
load
(
in
);
// validate, otherwise lots of functionality won't work
loadDictionary
(
"mmcif_pdbx_v50"
);
...
...
@@ -1316,22 +1304,16 @@ void File::load(const std::filesystem::path &path)
void
File
::
save
(
const
std
::
filesystem
::
path
&
path
)
{
fs
::
path
file
=
path
.
filename
();
std
::
unique_ptr
<
std
::
ostream
>
outFile
;
zstream
::
ostream
outFile
(
path
);
if
(
file
.
extension
()
==
".gz"
)
{
outFile
.
reset
(
new
gzstream
::
ofstream
(
path
));
file
.
replace_extension
(
""
);
}
else
outFile
.
reset
(
new
std
::
ofstream
(
path
,
std
::
ios_base
::
out
|
std
::
ios_base
::
binary
));
auto
ext
=
path
.
extension
().
string
();
if
(
ext
==
".gz"
or
ext
=
".xz"
)
ext
=
path
.
stem
().
extension
().
string
();
if
(
file
.
extension
()
==
".pdb
"
)
WritePDBFile
(
*
outFile
,
data
());
if
(
ext
==
".pdb"
or
ext
==
".ent
"
)
WritePDBFile
(
outFile
,
data
());
else
cif
::
File
::
save
(
*
outFile
);
cif
::
File
::
save
(
outFile
);
}
// --------------------------------------------------------------------
...
...
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