diff --git a/modules/io/pymod/export_mmcif_io.cc b/modules/io/pymod/export_mmcif_io.cc new file mode 100644 index 0000000000000000000000000000000000000000..4e0a47240f088518b582896862528703935aca64 --- /dev/null +++ b/modules/io/pymod/export_mmcif_io.cc @@ -0,0 +1,38 @@ +//------------------------------------------------------------------------------ +// This file is part of the OpenStructure project <www.openstructure.org> +// +// Copyright (C) 2008-2011 by the OpenStructure authors +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License as published by the Free +// Software Foundation; either version 3.0 of the License, or (at your option) +// any later version. +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +// details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +//------------------------------------------------------------------------------ +#include <boost/python.hpp> +using namespace boost::python; + +#include <ost/io/mol/io_profile.hh> +#include <ost/io/mol/mmcif_reader.hh> +using namespace ost; +using namespace ost::io; +using namespace ost::mol; + +void export_mmcif_io() +{ + class_<MMCifParser, boost::noncopyable>("MMCifParser", init<const String&, EntityHandle&, const IOProfile&>()) + .def("Parse", &MMCifParser::Parse) + .def("SetRestrictChains", &MMCifParser::SetRestrictChains) + .add_property("restrict_chains", + make_function(&MMCifParser::GetRestrictChains, + return_value_policy<copy_const_reference>()), + &MMCifParser::SetRestrictChains) + ; +} diff --git a/modules/io/src/mol/mmcif_reader.cc b/modules/io/src/mol/mmcif_reader.cc index 535aedbfa8fc6bbcd2f2ee41859a332a82798a81..6ed02b70651e1eaf9858e7142943de5d639034b5 100644 --- a/modules/io/src/mol/mmcif_reader.cc +++ b/modules/io/src/mol/mmcif_reader.cc @@ -53,7 +53,6 @@ void MMCifParser::Init() warned_name_mismatch_ = false; category_ = DONT_KNOW; chain_count_ = 0; - record_type_ = ""; atom_count_ = 0; residue_count_ = 0; auth_chain_id_ = false; @@ -72,7 +71,6 @@ void MMCifParser::ClearState() residue_count_ = 0; atom_count_ = 0; category_ = DONT_KNOW; - record_type_ = ""; warned_name_mismatch_ = false; } @@ -170,11 +168,6 @@ bool MMCifParser::ParseAtomIdent(const std::vector<StringRef>& columns, StringRef& atom_name, char& alt_loc) { - // is checking really neccessary? just by using OnBeginData, enough columns - // should be available! - if (!this->EnsureEnoughColumns(columns, 12)) { - return false; - } // ATOM name atom_name = columns[indices_[LABEL_ATOM_ID]]; if (profile_.calpha_only) { // unit test profile @@ -187,12 +180,12 @@ bool MMCifParser::ParseAtomIdent(const std::vector<StringRef>& columns, chain_name = columns[indices_[AUTH_ASYM_ID]].str(); } else { chain_name = columns[indices_[LABEL_ASYM_ID]].str(); - if (restrict_chains_.size() > 0 && // unit test - restrict_chains_.find(chain_name) == String::npos) { // unit test - return false; - } } - + if (restrict_chains_.size() > 0 && // unit test + restrict_chains_.find(chain_name) == String::npos) { // unit test + return false; + } + std::pair<bool, int> a_num = this->TryGetInt(columns[indices_[ID]], "_atom_site.id", profile_.fault_tolerant); // unit test @@ -236,7 +229,7 @@ void MMCifParser::ParseAndAddAtom(const std::vector<StringRef>& columns) alt_loc)) { return; } - Real occ, temp; + Real occ = 1.00f, temp = 0; geom::Vec3 apos; for (int i = CARTN_X; i <= CARTN_Z; ++i) { @@ -253,14 +246,10 @@ void MMCifParser::ParseAndAddAtom(const std::vector<StringRef>& columns) if (indices_[OCCUPANCY] != -1) { // unit test occ = this->TryGetReal(columns[indices_[OCCUPANCY]], "atom_site.occupancy"); - } else { - occ = 1.00f; } if (indices_[B_ISO_OR_EQUIV] != -1) { // unit test temp = this->TryGetReal(columns[indices_[B_ISO_OR_EQUIV]], "atom_site.B_iso_or_equiv"); - } else { - temp = 0; } // determine element @@ -370,20 +359,14 @@ void MMCifParser::ParseAndAddAtom(const std::vector<StringRef>& columns) ah = editor.InsertAtom(curr_residue_, aname, apos, s_ele); ++atom_count_; } - if (indices_[B_ISO_OR_EQUIV] != -1) {// unit test - ah.SetBFactor(temp); - } - if (indices_[OCCUPANCY] != -1) {// unit test - ah.SetOccupancy(occ); - } + ah.SetBFactor(temp); + + ah.SetOccupancy(occ); // record type - if (indices_[GROUP_PDB] != -1) { - record_type_ = columns[indices_[GROUP_PDB]].str(); - } else { - record_type_ = "ATOM"; - } - ah.SetHetAtom(record_type_[0]=='H'); + ah.SetHetAtom(indices_[GROUP_PDB] == -1 ? false : + columns[indices_[GROUP_PDB]][0]=='H'); + } void MMCifParser::OnDataRow(const StarLoopDesc& header, diff --git a/modules/io/src/mol/mmcif_reader.hh b/modules/io/src/mol/mmcif_reader.hh index 20f7bacd9d5a482526ad19ec9a273a2d65fa5617..93322dd267aac35220d579b0d9c68294cedbb554 100644 --- a/modules/io/src/mol/mmcif_reader.hh +++ b/modules/io/src/mol/mmcif_reader.hh @@ -29,13 +29,6 @@ namespace ost { namespace io { -/// \enum categories of the mmcif format -typedef enum { - ATOM_SITE, - DONT_KNOW -} MMCifCategory; - - /// \brief reader for the mmcif file format /// /// \section mmcif_format mmcif format description/ coverage @@ -183,6 +176,12 @@ private: GROUP_PDB ///< record name } AtomSiteItems; + /// \enum categories of the mmcif format + typedef enum { + ATOM_SITE, + DONT_KNOW + } MMCifCategory; + // members MMCifCategory category_; int indices_[MAX_ITEMS_IN_ROW]; ///< map items to values in loops @@ -196,7 +195,6 @@ private: int residue_count_; int atom_count_; bool warned_name_mismatch_; - String record_type_; bool go_on_; ///< flow control within the parser hooks //from pdbdreader //entity als member, fill in ondatarow