From 12f78739ed742a4daeeeafe6c410b8ff8ff96ad3 Mon Sep 17 00:00:00 2001 From: Marco Biasini <marco.biasini@unibas.ch> Date: Fri, 5 Nov 2010 09:45:54 +0100 Subject: [PATCH] fix pdb output for alt atom locations --- modules/io/src/mol/pdb_writer.cc | 3 ++- modules/io/tests/test_io_pdb.cc | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/modules/io/src/mol/pdb_writer.cc b/modules/io/src/mol/pdb_writer.cc index 8b16c2cce..94a6e8564 100644 --- a/modules/io/src/mol/pdb_writer.cc +++ b/modules/io/src/mol/pdb_writer.cc @@ -136,7 +136,8 @@ void write_atom(std::ostream& ostr, FormattedLine& line, } else { for (std::vector<String>::const_iterator i=names.begin(), e=names.end(); i!=e; ++i) { - p=atom.GetAltPos(*i); + geom::Mat4 tf=atom.GetEntity().GetTransformationMatrix(); + p=geom::Vec3(tf*geom::Vec4(atom.GetAltPos(*i))); line(30, 50).Clear(); if (i->size()>1) { diff --git a/modules/io/tests/test_io_pdb.cc b/modules/io/tests/test_io_pdb.cc index df8ff5295..5d78e6984 100644 --- a/modules/io/tests/test_io_pdb.cc +++ b/modules/io/tests/test_io_pdb.cc @@ -364,6 +364,31 @@ BOOST_AUTO_TEST_CASE(write_conect) "testfiles/pdb/conect-out.pdb")); } +BOOST_AUTO_TEST_CASE(alt_loc_tf) +{ + String fname("testfiles/pdb/alt-loc.pdb"); + // this scope is required to force the writer stream to be closed before + // opening the file again in compare_files. Avoids a race condition. + mol::EntityHandle ent=mol::CreateEntity(); + PDBReader reader(fname); + reader.Import(ent); + String out_name("testfiles/pdb/alt-loc-tf-out.pdb"); + { + PDBWriter writer(out_name); + geom::Mat4 shift; + shift.PasteTranslation(geom::Vec3(10,20,30)); + ent.RequestXCSEditor().ApplyTransform(shift); + writer.Write(ent); + } + PDBReader r2(out_name); + mol::EntityHandle ent2=mol::CreateEntity(); + r2.Import(ent2); + mol::ResidueHandle res1=ent2.FindResidue("A", mol::ResNum(1)); + mol::AtomHandle a1=res1.FindAtom("N"); + BOOST_CHECK_EQUAL(res1.GetAltAtomPos(a1, "A"), geom::Vec3(26,84,30)); + BOOST_CHECK_EQUAL(res1.GetAltAtomPos(a1, "B"), geom::Vec3(18,-108,30)); +} + BOOST_AUTO_TEST_CASE(res_name_too_long) { std::stringstream out; -- GitLab