Skip to content
Snippets Groups Projects
Commit a1c74efa authored by Bienchen's avatar Bienchen
Browse files

Expose ChainNameGenerator

parent b2879441
No related branches found
No related tags found
No related merge requests found
...@@ -152,6 +152,11 @@ void export_mmcif_io() ...@@ -152,6 +152,11 @@ void export_mmcif_io()
.def("Write", &WrapStarWriterWrite, (arg("data_name"), arg("filename"))) .def("Write", &WrapStarWriterWrite, (arg("data_name"), arg("filename")))
; ;
class_<ChainNameGenerator>("ChainNameGenerator", init<>())
.def("Get", &ChainNameGenerator::Get)
.def("Reset", &ChainNameGenerator::Reset)
;
class_<MMCifWriterEntity>("MMCifWriterEntity", no_init) class_<MMCifWriterEntity>("MMCifWriterEntity", no_init)
.def("FromPolymer", &MMCifWriterEntity::FromPolymer).staticmethod("FromPolymer") .def("FromPolymer", &MMCifWriterEntity::FromPolymer).staticmethod("FromPolymer")
.def("AddHet", &MMCifWriterEntity::AddHet, (arg("rnum"), arg("mon_id"))) .def("AddHet", &MMCifWriterEntity::AddHet, (arg("rnum"), arg("mon_id")))
......
...@@ -24,52 +24,6 @@ ...@@ -24,52 +24,6 @@
namespace { namespace {
// generates as many chain names as you want (potentially multiple characters)
struct ChainNameGenerator{
ChainNameGenerator() {
chain_names = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz";
n_chain_names = chain_names.size();
indices.push_back(-1);
}
String Get() {
int idx = indices.size() - 1;
indices[idx] += 1;
bool more_digits = false;
while(idx >= 0) {
if(indices[idx] >= n_chain_names) {
indices[idx] = 0;
if(idx>0) {
indices[idx-1] += 1;
--idx;
} else {
more_digits = true;
break;
}
} else {
break;
}
}
if(more_digits) {
indices.insert(indices.begin(), 0);
}
String ch_name(indices.size(), 'X');
for(uint i = 0; i < indices.size(); ++i) {
ch_name[i] = chain_names[indices[i]];
}
return ch_name;
}
void Reset() {
indices.clear();
indices.push_back(-1);
}
String chain_names;
int n_chain_names;
std::vector<int> indices;
};
void CheckValidEntityPolyType(const String& entity_poly_type) { void CheckValidEntityPolyType(const String& entity_poly_type) {
std::unordered_set<std::string> s = {"cyclic-pseudo-peptide", std::unordered_set<std::string> s = {"cyclic-pseudo-peptide",
"other", "other",
...@@ -1066,7 +1020,7 @@ namespace { ...@@ -1066,7 +1020,7 @@ namespace {
"is not mmcif_conform"); "is not mmcif_conform");
} }
ChainNameGenerator chain_name_gen; ost::io::ChainNameGenerator chain_name_gen;
std::set<String> unique_compounds; std::set<String> unique_compounds;
for(auto res_list: res_lists) { for(auto res_list: res_lists) {
...@@ -1465,6 +1419,45 @@ namespace { ...@@ -1465,6 +1419,45 @@ namespace {
namespace ost { namespace io { namespace ost { namespace io {
ChainNameGenerator::ChainNameGenerator() {
chain_names = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz";
n_chain_names = chain_names.size();
indices.push_back(-1);
}
String ChainNameGenerator::Get() {
int idx = indices.size() - 1;
indices[idx] += 1;
bool more_digits = false;
while(idx >= 0) {
if(indices[idx] >= n_chain_names) {
indices[idx] = 0;
if(idx>0) {
indices[idx-1] += 1;
--idx;
} else {
more_digits = true;
break;
}
} else {
break;
}
}
if(more_digits) {
indices.insert(indices.begin(), 0);
}
String ch_name(indices.size(), 'X');
for(uint i = 0; i < indices.size(); ++i) {
ch_name[i] = chain_names[indices[i]];
}
return ch_name;
}
void ChainNameGenerator::Reset() {
indices.clear();
indices.push_back(-1);
}
MMCifWriterEntity MMCifWriterEntity::FromPolymer(const String& entity_poly_type, MMCifWriterEntity MMCifWriterEntity::FromPolymer(const String& entity_poly_type,
const std::vector<String>& mon_ids, const std::vector<String>& mon_ids,
conop::CompoundLibPtr compound_lib) { conop::CompoundLibPtr compound_lib) {
......
...@@ -30,6 +30,18 @@ ...@@ -30,6 +30,18 @@
namespace ost { namespace io { namespace ost { namespace io {
// generates as many chain names as you want (potentially multiple characters)
struct ChainNameGenerator{
ChainNameGenerator();
String Get();
void Reset();
String chain_names;
int n_chain_names;
std::vector<int> indices;
};
struct MMCifWriterEntity { struct MMCifWriterEntity {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment