diff --git a/modules/base/pymod/table.py b/modules/base/pymod/table.py index 8af2ab6cc20f088401c9e80038d8bc98e31f8561..6146858baa5abc0236ea248db849fa8b6d7bcb5e 100644 --- a/modules/base/pymod/table.py +++ b/modules/base/pymod/table.py @@ -641,7 +641,7 @@ class Table(object): for row, d in zip(self.rows, data): row.append(d) - elif data!=None: + elif data!=None and len(self.cols)==0: if IsScalar(data): self.AddRow({col_name : data}) else: diff --git a/modules/mol/base/pymod/export_editors.cc b/modules/mol/base/pymod/export_editors.cc index e53a02d35ffc39d35e826c9f34938dfd2821c4a1..241fd007e47ec1da465feeb4ec869a4dc5127c18 100644 --- a/modules/mol/base/pymod/export_editors.cc +++ b/modules/mol/base/pymod/export_editors.cc @@ -42,11 +42,45 @@ BondHandle (EditorBase::*connect_b)(const AtomHandle&, const AtomHandle&, BondHandle (EditorBase::*connect_d)(const AtomHandle&, const AtomHandle&, Real, Real, Real, unsigned char)=&EditorBase::Connect; + +ChainHandle (EditorBase::*insert_chain_a)(const String& chain_name)=&EditorBase::InsertChain; +ChainHandle (EditorBase::*insert_chain_b)(const String& chain_name, + ChainHandle chain, bool deep)=&EditorBase::InsertChain; ResidueHandle (EditorBase::*append_a)(ChainHandle ch, const ResidueKey&)=&EditorBase::AppendResidue; ResidueHandle (EditorBase::*append_b)(ChainHandle ch, const ResidueKey&, const ResNum&)=&EditorBase::AppendResidue; +ResidueHandle (EditorBase::*append_c)(ChainHandle ch, ResidueHandle residue, + bool deep)=&EditorBase::AppendResidue; + +ResidueHandle (EditorBase::*insert_residue_before_a)(ChainHandle chain, int index, + const ResNum& num, + const ResidueKey& k)=&EditorBase::InsertResidueBefore; +ResidueHandle (EditorBase::*insert_residue_before_b)(ChainHandle chain, ResidueHandle residue, + int index,bool deep)=&EditorBase::InsertResidueBefore; + +ResidueHandle (EditorBase::*insert_residue_after_a)(ChainHandle chain, int index, + const ResNum& num, + const ResidueKey& k)=&EditorBase::InsertResidueAfter; +ResidueHandle (EditorBase::*insert_residue_after_b)(ChainHandle chain, ResidueHandle residue, + int index, bool deep)=&EditorBase::InsertResidueAfter; + +AtomHandle (EditorBase::*insert_atom_a)(ResidueHandle residue, const String& name, + const geom::Vec3& pos, const String& ele, + Real occupancy, Real b_factor, + bool is_hetatm)=&EditorBase::InsertAtom; +AtomHandle (EditorBase::*insert_atom_b)(ResidueHandle residue, AtomHandle atom)=&EditorBase::InsertAtom; + + +AtomHandle (EditorBase::*insert_alt_atom_a)(ResidueHandle residue, const String& name, + const String& alt_group, const geom::Vec3& pos, + const String& ele, Real occ, + Real b_factor)=&EditorBase::InsertAltAtom; +AtomHandle (EditorBase::*insert_alt_atom_b)(ResidueHandle residue, AtomHandle atom, + const String& alt_group)=&EditorBase::InsertAltAtom; + + void (ICSEditor::*set_torsion_a)(TorsionHandle, Real, bool)=&ICSEditor::SetTorsionAngle; void (ICSEditor::*set_torsion_b)(const AtomHandle&, const AtomHandle&, @@ -195,18 +229,27 @@ void export_Editors() #endif class_<EditorBase>("EditorBase", no_init) - .def("InsertChain", &EditorBase::InsertChain) - .def("InsertAtom", &EditorBase::InsertAtom, + .def("InsertChain", insert_chain_a) + .def("InsertChain", insert_chain_b,(arg("chain_name"),arg("chain"), arg("deep")=false)) + .def("InsertAtom", insert_atom_a, (arg("residue"), arg("name"), arg("pos"), arg("element")="", arg("occupancy")=1.0, arg("b_factor")=0.0, arg("is_hetatm")=false)) - .def("InsertAltAtom", &EditorBase::InsertAltAtom) + .def("InsertAtom", insert_atom_b) + .def("InsertAltAtom", insert_alt_atom_a) + .def("InsertAltAtom", insert_alt_atom_b) .def("DeleteResidue", &EditorBase::DeleteResidue) .def("DeleteChain", &EditorBase::DeleteChain) .def("DeleteAtom", &EditorBase::DeleteAtom) - .def("InsertResidueBefore", &EditorBase::InsertResidueBefore) - .def("InsertResidueAfter", &EditorBase::InsertResidueAfter) + .def("InsertResidueBefore", insert_residue_before_a) + .def("InsertResidueBefore", insert_residue_before_b, (arg("chain"), arg("residue"), + arg("index"), arg("deep")=false)) + .def("InsertResidueAfter", insert_residue_after_a) + .def("InsertResidueAfter", insert_residue_after_b, (arg("chain"), arg("residue"), + arg("index"), arg("deep")=false)) .def("AppendResidue", append_a) - .def("AppendResidue", append_b) + .def("AppendResidue", append_b) + .def("AppendResidue", append_c, (arg("chain"), arg("residue"), + arg("deep")=false)) .def("Connect", connect_a) .def("Connect", connect_b) .def("Connect", connect_c) diff --git a/modules/mol/base/src/editor_base.cc b/modules/mol/base/src/editor_base.cc index d75827806359c8dc5036fa7cf819abb0ce7ffcc6..49c1311b2f4ccdfb5ea5c4a650836c1a17f57cc6 100644 --- a/modules/mol/base/src/editor_base.cc +++ b/modules/mol/base/src/editor_base.cc @@ -40,6 +40,51 @@ ChainHandle EditorBase::InsertChain(const String& chain_name) return ent_.Impl()->InsertChain(chain_name); } +ChainHandle EditorBase::InsertChain(const String& chain_name, ChainHandle chain, bool deep) +{ + + impl::ChainImplPtr inserted_chain=ent_.Impl()->InsertChain(chain.Impl()); + inserted_chain->SetName(chain_name); + + if(deep){ + ResidueHandleIter it=chain.ResiduesBegin(), + it_end=chain.ResiduesEnd(); + for(;it!=it_end;++it){ + ResidueHandle res=*it; + this->AppendResidue(inserted_chain, res, true); + } + } + + return inserted_chain; + + + + /* + impl::ChainImplPtr new_chain=chain.Impl(); + new_chain->SetName(chain_name); + if(!deep) new_chain->DeleteAllResidues(); + return ent_.Impl()->InsertChain(new_chain); + */ + /* + if(deep){ + + ChainHandle inserted_chain=ent_.Impl()->InsertChain(chain_name); + + ResidueHandleIter it=chain.ResiduesBegin(), + it_end=chain.ResiduesEnd(); + for(;it!=it_end;++it){ + ResidueHandle res=*it; + this->AppendResidue(inserted_chain, res, true); + } + return inserted_chain; + } + + else{ + return ent_.Impl()->InsertChain(chain.GetName()); + } + */ +} + ResidueHandle EditorBase::AppendResidue(ChainHandle chain, const ResidueKey& k) { CheckHandleValidity(chain); @@ -54,6 +99,24 @@ ResidueHandle EditorBase::AppendResidue(ChainHandle chain, const ResidueKey& k, return ResidueHandle(chain.Impl()->AppendResidue(k, num)); } +ResidueHandle EditorBase::AppendResidue(ChainHandle chain, ResidueHandle residue, bool deep) +{ + CheckHandleValidity(chain); + + impl::ResidueImplPtr inserted_residue=chain.Impl()->AppendResidue(residue.Impl()); + if(deep) + { + AtomHandleIter it=residue.AtomsBegin(), + it_end=residue.AtomsEnd(); + for(;it!=it_end;++it) + { + AtomHandle atom=*it; + this->InsertAtom(inserted_residue,atom); + } + } + return inserted_residue; +} + ResidueHandle EditorBase::InsertResidueBefore(ChainHandle chain, int index, const ResNum& num, const ResidueKey& k) @@ -62,6 +125,34 @@ ResidueHandle EditorBase::InsertResidueBefore(ChainHandle chain, int index, return ResidueHandle(chain.Impl()->InsertResidueBefore(index, num, k)); } +ResidueHandle EditorBase::InsertResidueBefore(ChainHandle chain, + ResidueHandle residue, + int index, bool deep) +{ + CheckHandleValidity(chain); + + if(deep) + { + ResidueHandle inserted_residue=chain.Impl()->InsertResidueBefore(index, + residue.GetNumber(), + residue.GetKey()); + AtomHandleIter it=inserted_residue.AtomsBegin(), + it_end=inserted_residue.AtomsEnd(); + for(;it!=it_end;++it) + { + AtomHandle atom=*it; + this->InsertAtom(inserted_residue, atom); + } + return inserted_residue; + } + else + { + return ResidueHandle(chain.Impl()->InsertResidueBefore(index, + residue.GetNumber(), + residue.GetKey())); + } +} + ResidueHandle EditorBase::InsertResidueAfter(ChainHandle chain, int index, const ResNum& num, const ResidueKey& k) @@ -70,6 +161,30 @@ ResidueHandle EditorBase::InsertResidueAfter(ChainHandle chain, int index, return ResidueHandle(chain.Impl()->InsertResidueAfter(index, num, k)); } +ResidueHandle EditorBase::InsertResidueAfter(ChainHandle chain, ResidueHandle residue, + int index, bool deep) +{ + if(deep) + { + ResidueHandle inserted_residue=chain.Impl()->InsertResidueAfter(index, + residue.GetNumber(), + residue.GetKey()); + AtomHandleIter it=inserted_residue.AtomsBegin(), + it_end=inserted_residue.AtomsEnd(); + for(;it!=it_end;++it) + { + this->InsertAtom(inserted_residue, *it); + } + return inserted_residue; + } + else + { + return ResidueHandle(chain.Impl()->InsertResidueAfter(index, + residue.GetNumber(), + residue.GetKey())); + } +} + void EditorBase::RenameResidue(ResidueHandle res, const String& new_name) { CheckHandleValidity(res); @@ -116,6 +231,14 @@ AtomHandle EditorBase::InsertAtom(ResidueHandle res, const String& name, return atom; } +AtomHandle EditorBase::InsertAtom(ResidueHandle res, AtomHandle atom) +{ + CheckHandleValidity(res); + ent_.Impl()->MarkTraceDirty(); + AtomHandle a(res.Impl()->InsertAtom(atom.Impl())); + return a; +} + AtomHandle EditorBase::InsertAltAtom(ResidueHandle res, const String& name, const String& alt_group, const geom::Vec3& pos, @@ -130,6 +253,18 @@ AtomHandle EditorBase::InsertAltAtom(ResidueHandle res, const String& name, return atom; } +AtomHandle EditorBase::InsertAltAtom(ResidueHandle res, AtomHandle atom, + const String& alt_group) +{ + CheckHandleValidity(res); + ent_.Impl()->MarkTraceDirty(); + AtomHandle a(res.Impl()->InsertAltAtom(atom.GetName(), alt_group, + atom.GetPos(), atom.GetElement(), + atom.GetOccupancy(), atom.GetBFactor())); + this->UpdateTrace(); + return a; +} + void EditorBase::AddAltAtomPos(const String& group, const AtomHandle& atom, const geom::Vec3& position, Real occ, diff --git a/modules/mol/base/src/editor_base.hh b/modules/mol/base/src/editor_base.hh index 504311d547cf00f43e11fb5b1c49925a16564e34..7e969b9101a604d8e45b2270c5843a0317d38518 100644 --- a/modules/mol/base/src/editor_base.hh +++ b/modules/mol/base/src/editor_base.hh @@ -57,6 +57,9 @@ public: /// \return The newly created chain handle ChainHandle InsertChain(const String& chain_name); + //ChainHandle InsertChain(ChainHandle chain, bool deep=false); + ChainHandle InsertChain(const String& chain_name, ChainHandle chain, bool deep=false); + /// \name Inserting, removing and modifying order of residues ///@{ /// \brief Append residue to the end of the chain @@ -76,6 +79,9 @@ public: ResidueHandle AppendResidue(ChainHandle chain, const ResidueKey& k, const ResNum& num); + + ResidueHandle AppendResidue(ChainHandle chain, ResidueHandle residue, bool deep=false); + /// \brief Insert residue into chain /// /// Insert residue with residue number \var num and key \var k into the @@ -94,6 +100,9 @@ public: ResidueHandle InsertResidueBefore(ChainHandle chain, int index, const ResNum& num, const ResidueKey& k); + + ResidueHandle InsertResidueBefore(ChainHandle chain, ResidueHandle residue, + int index, bool deep=false); /// \brief insert residue into chain /// /// This method is identical to InsertResidueBefore() but inserts the @@ -102,6 +111,9 @@ public: ResidueHandle InsertResidueAfter(ChainHandle chain, int index, const ResNum& num, const ResidueKey& k); + + ResidueHandle InsertResidueAfter(ChainHandle chain, ResidueHandle residue, + int index, bool deep=false); /// \name Adding/removing atoms //@{ @@ -120,12 +132,19 @@ public: Real occupancy=1.0, Real b_factor=0.0, bool is_hetatm=false); + AtomHandle InsertAtom(ResidueHandle residue, AtomHandle atom); + /// \brief Insert new atom with alternative position indicator /// \sa EditorBase::AddAltAtomPos(), ResidueHandle AtomHandle InsertAltAtom(ResidueHandle residue, const String& name, const String& alt_group, const geom::Vec3& pos, const String& ele="", Real occ=1.0, Real b_factor=0.0); + + AtomHandle InsertAltAtom(ResidueHandle residue, AtomHandle atom, + const String& alt_group); + + /// \brief Add alternative atom position /// \param group is the name of the alternative atom position group. If no /// group of that name exists, it will be created. diff --git a/modules/mol/base/src/impl/chain_impl.hh b/modules/mol/base/src/impl/chain_impl.hh index bcb3436e2bc463dadcfe1ca6af4e1bbac48af24b..5c11bde4b14c9ba2244c3b40537757ef0b9ba1a1 100644 --- a/modules/mol/base/src/impl/chain_impl.hh +++ b/modules/mol/base/src/impl/chain_impl.hh @@ -119,6 +119,7 @@ public: /// \brief Append residue at end of chain. ResidueImplPtr AppendResidue(const ResidueKey& k, const ResNum& n); + // next residue, not necessarily in sequence ResidueImplPtr GetPrev(const ResidueImplPtr& r) const;