diff --git a/modules/io/pymod/__init__.py b/modules/io/pymod/__init__.py index a0fc73cc90d2983ace78bdb13f98e1769a714d48..82ab97c27b96400ea16d1bf5db285af1fea57c5b 100644 --- a/modules/io/pymod/__init__.py +++ b/modules/io/pymod/__init__.py @@ -20,7 +20,8 @@ from _io import * from ost import mol,conop def LoadPDB(filename, restrict_chains="", no_hetatms=False, - fault_tolerant=False, load_multi=False): + fault_tolerant=False, load_multi=False, + join_spread_atom_records=False): """ Load PDB file from disk. @@ -35,6 +36,10 @@ def LoadPDB(filename, restrict_chains="", no_hetatms=False, If load_multi is set to true, a list of entities will be returned instead of only the first. + + If join_spread_atom_records is set to true, atom records belonging to the + same residue are joined, even if they do not appear sequentially in the PDB + file. """ conop_inst=conop.Conopology.Instance() builder=conop_inst.GetBuilder("DEFAULT") @@ -45,6 +50,8 @@ def LoadPDB(filename, restrict_chains="", no_hetatms=False, flags=PDB.SKIP_FAULTY_RECORDS if no_hetatms: flags|=PDB.NO_HETATMS + if join_spread_atom_records: + flags|=PDB.JOIN_SPREAD_ATOM_RECORDS reader.SetFlags(flags) if load_multi: ent_list=[] diff --git a/modules/io/pymod/export_pdb_io.cc b/modules/io/pymod/export_pdb_io.cc index e984697ee8818aa07c7660d793f45e7e5a0e569a..5f252d31897a86ac906566f55f91e552d80cfff5 100644 --- a/modules/io/pymod/export_pdb_io.cc +++ b/modules/io/pymod/export_pdb_io.cc @@ -37,6 +37,7 @@ void export_pdb_io() .value("NO_HETATMS", PDB::NO_HETATMS) .value("SKIP_FAULTY_RECORDS", PDB::SKIP_FAULTY_RECORDS) .value("WRITE_MULTIPLE_MODELS", PDB::WRITE_MULTIPLE_MODELS) + .value("JOIN_SPREAD_ATOM_RECORDS", PDB::JOIN_SPREAD_ATOM_RECORDS) ; class_<PDBReader, boost::noncopyable>("PDBReader", init<String>()) .def("HasNext", &PDBReader::HasNext) diff --git a/modules/io/src/mol/pdb_io.hh b/modules/io/src/mol/pdb_io.hh index 5bc34e106011bc7c99cca3f8416087b8ffc49d9f..e14cfb2d44fa37f282f30cd802d3f9abeca39286 100644 --- a/modules/io/src/mol/pdb_io.hh +++ b/modules/io/src/mol/pdb_io.hh @@ -35,6 +35,29 @@ struct PDB { WRITE_MULTIPLE_MODELS=4, /// \brief enable for PQR PQR_FORMAT=8, + /// \brief Join atom records into one residue, even if the atom records + /// are not sequential. + /// + /// This is useful in the following case: + /// + /// \verbatim + /// ATOM 43 N AALA P 4 + /// ATOM 45 CA AALA P 4 + /// ATOM 47 C AALA P 4 + /// ATOM 48 O AALA P 4 + /// ATOM 49 N APRO P 5 + /// ATOM 50 CD APRO P 5 + /// ATOM 53 CA APRO P 5 + /// ATOM 55 CB APRO P 5 + /// ATOM 58 CG APRO P 5 + /// ATOM 61 C APRO P 5 + /// ATOM 62 O APRO P 5 + /// ATOM 550 CB AALA P 4 + /// \endverbatim + /// + /// By default, the atom 550 will start a new residue instead of being + /// joined with atoms 43-48 into one residue. + JOIN_SPREAD_ATOM_RECORDS=16 } Type; }; diff --git a/modules/io/src/mol/pdb_reader.cc b/modules/io/src/mol/pdb_reader.cc index 5c8f137f792bd62efaddbaec076af3f9c983725d..c59be53a623e88ad163a94086cfb486fe62b9c57 100644 --- a/modules/io/src/mol/pdb_reader.cc +++ b/modules/io/src/mol/pdb_reader.cc @@ -446,14 +446,21 @@ void PDBReader::ParseAndAddAtom(const String& line, int line_num, ++chain_count_; } } - if(update_residue) { - LOGN_DUMP("new residue " << rkey << " " << rnum); - curr_residue_=editor.AppendResidue(curr_chain_, rkey, rnum); + if (flags_ & PDB::JOIN_SPREAD_ATOM_RECORDS) { + curr_residue_=curr_chain_.FindResidue(rnum); + if (!curr_residue_.IsValid()) { + LOGN_DUMP("new residue " << rkey << " " << rnum); + curr_residue_=editor.AppendResidue(curr_chain_, rkey, rnum); + ++residue_count_; + } + } else { + LOGN_DUMP("new residue " << rkey << " " << rnum); + curr_residue_=editor.AppendResidue(curr_chain_, rkey, rnum); + ++residue_count_; + } assert(curr_residue_.IsValid()); - ++residue_count_; } - // finally add atom LOGN_DUMP("adding atom " << aname << " (" << s_ele << ") @" << apos); mol::AtomProp aprop;