MoleculeExporter.cpp (pymol-v2.1.0.tar.bz2) | : | MoleculeExporter.cpp (pymol-open-source-2.2.0) | ||
---|---|---|---|---|
skipping to change at line 30 | skipping to change at line 30 | |||
#include "ObjectMolecule.h" | #include "ObjectMolecule.h" | |||
#include "CoordSet.h" | #include "CoordSet.h" | |||
#include "Mol2Typing.h" | #include "Mol2Typing.h" | |||
#include "MmodTyping.h" | #include "MmodTyping.h" | |||
#include "Color.h" | #include "Color.h" | |||
#include "Util.h" | #include "Util.h" | |||
#include "Lex.h" | #include "Lex.h" | |||
#include "P.h" | #include "P.h" | |||
#include "PConv.h" | #include "PConv.h" | |||
#include "CifDataValueFormatter.h" | #include "CifDataValueFormatter.h" | |||
#include "MaeExportHelpers.h" | ||||
#ifdef _PYMOL_IP_EXTRAS | #ifdef _PYMOL_IP_EXTRAS | |||
#include "Property.h" | #include "Property.h" | |||
#endif | #endif | |||
#ifdef _PYMOL_NO_CXX11 | #ifdef _PYMOL_NO_CXX11 | |||
#define emplace_back push_back | #define emplace_back push_back | |||
#endif | #endif | |||
/* | /* | |||
skipping to change at line 244 | skipping to change at line 245 | |||
/* | /* | |||
* Populates the "m_bonds" vector | * Populates the "m_bonds" vector | |||
*/ | */ | |||
void populateBondRefs(); | void populateBondRefs(); | |||
protected: | protected: | |||
// functions to be implemented by derived classes | // functions to be implemented by derived classes | |||
virtual int getMultiDefault() const = 0; | virtual int getMultiDefault() const = 0; | |||
virtual bool isExcludedBond(int atm1, int atm2); | virtual bool isExcludedBond(int atm1, int atm2); | |||
virtual bool isExcludedBond(const BondType * bond); | ||||
virtual void writeAtom() = 0; | virtual void writeAtom() = 0; | |||
virtual void writeBonds() = 0; | virtual void writeBonds() = 0; | |||
virtual void beginObject(); | virtual void beginObject(); | |||
virtual void beginCoordSet(); | virtual void beginCoordSet(); | |||
virtual void endObject(); | virtual void endObject(); | |||
virtual void endCoordSet(); | virtual void endCoordSet(); | |||
virtual void beginMolecule() {} | virtual void beginMolecule() {} | |||
virtual void beginFile() {} | virtual void beginFile() {} | |||
}; | }; | |||
/* | /* | |||
* Return true if this bond should not be exported | * Return true if this bond should not be exported | |||
*/ | */ | |||
bool MoleculeExporter::isExcludedBond(int atm1, int atm2) { | bool MoleculeExporter::isExcludedBond(int atm1, int atm2) { | |||
return false; | return false; | |||
} | } | |||
bool MoleculeExporter::isExcludedBond(const BondType * bond) { | ||||
return isExcludedBond(bond->index[0], bond->index[1]); | ||||
} | ||||
void MoleculeExporter::beginObject() { | void MoleculeExporter::beginObject() { | |||
if (m_multi != cMolExportByCoordSet) { | if (m_multi != cMolExportByCoordSet) { | |||
resetTmpIDs(); | resetTmpIDs(); | |||
} | } | |||
if (m_multi == cMolExportByObject) { | if (m_multi == cMolExportByObject) { | |||
beginMolecule(); | beginMolecule(); | |||
} | } | |||
} | } | |||
skipping to change at line 406 | skipping to change at line 411 | |||
for (auto bond = obj->Bond, bond_end = obj->Bond + obj->NBond; | for (auto bond = obj->Bond, bond_end = obj->Bond + obj->NBond; | |||
bond != bond_end; ++bond) { | bond != bond_end; ++bond) { | |||
auto atm1 = bond->index[0]; | auto atm1 = bond->index[0]; | |||
auto atm2 = bond->index[1]; | auto atm2 = bond->index[1]; | |||
if (!(id1 = getTmpID(atm1)) || | if (!(id1 = getTmpID(atm1)) || | |||
!(id2 = getTmpID(atm2))) | !(id2 = getTmpID(atm2))) | |||
continue; | continue; | |||
if (isExcludedBond(atm1, atm2)) | if (isExcludedBond(bond)) | |||
continue; | continue; | |||
if (id1 > id2) | if (id1 > id2) | |||
std::swap(id1, id2); | std::swap(id1, id2); | |||
// emit bond | // emit bond | |||
m_bonds.emplace_back(BondRef { bond, id1, id2 }); | m_bonds.emplace_back(BondRef { bond, id1, id2 }); | |||
} | } | |||
} | } | |||
skipping to change at line 877 | skipping to change at line 882 | |||
void beginMolecule() { | void beginMolecule() { | |||
MoleculeExporter::beginMolecule(); | MoleculeExporter::beginMolecule(); | |||
m_offset += VLAprintf(m_buffer, m_offset, | m_offset += VLAprintf(m_buffer, m_offset, | |||
"%s\n PyMOL%3.3s 3D 0\n\n", | "%s\n PyMOL%3.3s 3D 0\n\n", | |||
getTitleOrName(), _PyMOL_VERSION); | getTitleOrName(), _PyMOL_VERSION); | |||
m_chiral_flag = 0; | m_chiral_flag = 0; | |||
} | } | |||
bool isExcludedBond(const BondType * bond) { | ||||
// MOL format doesn't know zero order bonds. Writing them as order "0" | ||||
// will produce a nonstandard file which may be rejected by other | ||||
// applications (e.g. RDKit). | ||||
if (bond->order == 0) { | ||||
return !SettingGetGlobal_b(G, cSetting_sdf_write_zero_order_bonds); | ||||
} | ||||
return false; | ||||
} | ||||
}; | }; | |||
// ----------------------------------------------------------------------------- ----- // | // ----------------------------------------------------------------------------- ----- // | |||
struct MoleculeExporterSDF : public MoleculeExporterMOL { | struct MoleculeExporterSDF : public MoleculeExporterMOL { | |||
int getMultiDefault() const { | int getMultiDefault() const { | |||
// multi-entry format | // multi-entry format | |||
return cMolExportByCoordSet; | return cMolExportByCoordSet; | |||
} | } | |||
skipping to change at line 1030 | skipping to change at line 1046 | |||
} | } | |||
}; | }; | |||
// ----------------------------------------------------------------------------- ----- // | // ----------------------------------------------------------------------------- ----- // | |||
struct MoleculeExporterMAE : public MoleculeExporter { | struct MoleculeExporterMAE : public MoleculeExporter { | |||
int m_n_atoms; | int m_n_atoms; | |||
int m_n_atoms_offset; | int m_n_atoms_offset; | |||
int m_n_arom_bonds; | int m_n_arom_bonds; | |||
std::map<int, const AtomInfoType *> m_atoms; | ||||
// quasi constructor | // quasi constructor | |||
void init(PyMOLGlobals * G_) { | void init(PyMOLGlobals * G_) { | |||
MoleculeExporter::init(G_); | MoleculeExporter::init(G_); | |||
m_n_arom_bonds = 0; | m_n_arom_bonds = 0; | |||
} | } | |||
int getMultiDefault() const { | int getMultiDefault() const { | |||
// multi-entry format | // multi-entry format | |||
skipping to change at line 1052 | skipping to change at line 1069 | |||
void beginFile() { | void beginFile() { | |||
m_offset += VLAprintf(m_buffer, m_offset, | m_offset += VLAprintf(m_buffer, m_offset, | |||
"{ s_m_m2io_version ::: 2.0.0 }\n" | "{ s_m_m2io_version ::: 2.0.0 }\n" | |||
"# created with PyMOL " _PyMOL_VERSION " #\n"); | "# created with PyMOL " _PyMOL_VERSION " #\n"); | |||
} | } | |||
void beginMolecule() { | void beginMolecule() { | |||
MoleculeExporter::beginMolecule(); | MoleculeExporter::beginMolecule(); | |||
std::string groupid = MaeExportGetSubGroupId(G, reinterpret_cast<CObject*>(m | ||||
_iter.obj)); | ||||
m_offset += VLAprintf(m_buffer, m_offset, | m_offset += VLAprintf(m_buffer, m_offset, | |||
"\nf_m_ct {\n" | "\nf_m_ct {\n" | |||
"s_m_subgroupid\n" | ||||
"s_m_title\n" | "s_m_title\n" | |||
":::\n" | ":::\n" | |||
"\"%s\"\n" | ||||
"\"%s\"\n", | "\"%s\"\n", | |||
groupid.c_str(), | ||||
getTitleOrName()); | getTitleOrName()); | |||
// defer until number of atoms known | // defer until number of atoms known | |||
m_n_atoms_offset = m_offset; | m_n_atoms_offset = m_offset; | |||
m_offset += VLAprintf(m_buffer, m_offset, | m_offset += VLAprintf(m_buffer, m_offset, | |||
"m_atom[X] {\n" // place holder | "m_atom[X] {\n" // place holder | |||
"# First column is atom index #\n" | "# First column is atom index #\n" | |||
"i_m_mmod_type\n" | "i_m_mmod_type\n" | |||
"r_m_x_coord\n" | "r_m_x_coord\n" | |||
skipping to change at line 1080 | skipping to change at line 1102 | |||
"s_m_insertion_code\n" | "s_m_insertion_code\n" | |||
"s_m_chain_name\n" | "s_m_chain_name\n" | |||
"s_m_pdb_residue_name\n" | "s_m_pdb_residue_name\n" | |||
"s_m_pdb_atom_name\n" | "s_m_pdb_atom_name\n" | |||
"i_m_atomic_number\n" | "i_m_atomic_number\n" | |||
"i_m_formal_charge\n" | "i_m_formal_charge\n" | |||
"s_m_color_rgb\n" | "s_m_color_rgb\n" | |||
"i_m_secondary_structure\n" | "i_m_secondary_structure\n" | |||
"r_m_pdb_occupancy\n" | "r_m_pdb_occupancy\n" | |||
"i_pdb_PDB_serial\n" | "i_pdb_PDB_serial\n" | |||
"i_m_visibility\n" | ||||
"i_m_representation\n" | ||||
"i_m_ribbon_style\n" | ||||
"i_m_ribbon_color\n" | ||||
"s_m_ribbon_color_rgb\n" | ||||
"s_m_label_format\n" | ||||
"i_m_label_color\n" | ||||
"s_m_label_user_text\n" | ||||
":::\n"); | ":::\n"); | |||
m_n_atoms = 0; | m_n_atoms = 0; | |||
} | } | |||
void beginObject() { | void beginObject() { | |||
MoleculeExporter::beginObject(); | MoleculeExporter::beginObject(); | |||
ObjectMoleculeVerifyChemistry(m_iter.obj, m_iter.state); | ObjectMoleculeVerifyChemistry(m_iter.obj, m_iter.state); | |||
} | } | |||
skipping to change at line 1125 | skipping to change at line 1155 | |||
name, | name, | |||
ai->protons, | ai->protons, | |||
ai->formalCharge, | ai->formalCharge, | |||
int(rgb[0] * 255), | int(rgb[0] * 255), | |||
int(rgb[1] * 255), | int(rgb[1] * 255), | |||
int(rgb[2] * 255), | int(rgb[2] * 255), | |||
ai->ssType[0] == 'H' ? 1 : ai->ssType[0] == 'S' ? 2 : 0, | ai->ssType[0] == 'H' ? 1 : ai->ssType[0] == 'S' ? 2 : 0, | |||
ai->q, | ai->q, | |||
ai->id); | ai->id); | |||
char ribbon_color_rgb[7] = "<>"; | ||||
MaeExportGetRibbonColor(G, m_iter, ribbon_color_rgb); | ||||
std::string label_user_text = MaeExportGetLabelUserText(G, ai); | ||||
m_offset += VLAprintf(m_buffer, m_offset, | ||||
"%d %d %d %d %s \"%s\" 2 \"%s\"\n", | ||||
(ai->visRep & ~(cRepCartoonBit | cRepRibbonBit)) ? 1 : 0, | ||||
MaeExportGetAtomStyle(G, m_iter), | ||||
MaeExportGetRibbonStyle(ai), | ||||
ribbon_color_rgb[0] == '<' ? 3 /* calphaatom */ : 0 /* constant */, | ||||
ribbon_color_rgb, | ||||
label_user_text.empty() ? "" : "%UT", | ||||
label_user_text.c_str()); | ||||
m_atoms[getTmpID()] = ai; | ||||
++m_n_atoms; | ++m_n_atoms; | |||
} | } | |||
void writeBonds() { | void writeBonds() { | |||
// atom count | // atom count | |||
m_n_atoms_offset += sprintf(m_buffer + m_n_atoms_offset, "m_atom[%d]", m_n_a toms); | m_n_atoms_offset += sprintf(m_buffer + m_n_atoms_offset, "m_atom[%d]", m_n_a toms); | |||
m_buffer[m_n_atoms_offset] = ' '; // overwrite terminator | m_buffer[m_n_atoms_offset] = ' '; // overwrite terminator | |||
if (!m_bonds.empty()) { | if (!m_bonds.empty()) { | |||
// table with zero rows not allowed | // table with zero rows not allowed | |||
m_offset += VLAprintf(m_buffer, m_offset, | m_offset += VLAprintf(m_buffer, m_offset, | |||
":::\n" | ":::\n" | |||
"}\n" // end atoms table | "}\n" // end atoms table | |||
"m_bond[%d] {\n" | "m_bond[%d] {\n" | |||
"# First column is bond index #\n" | "# First column is bond index #\n" | |||
"i_m_from\n" | "i_m_from\n" | |||
"i_m_to\n" | "i_m_to\n" | |||
"i_m_order\n" | "i_m_order\n" | |||
"i_m_from_rep\n" | ||||
"i_m_to_rep\n" | ||||
":::\n", (int) m_bonds.size()); | ":::\n", (int) m_bonds.size()); | |||
int b = 0; | int b = 0; | |||
for (auto bond_it = m_bonds.begin(); bond_it != m_bonds.end(); ++bond_it) { | for (auto bond_it = m_bonds.begin(); bond_it != m_bonds.end(); ++bond_it) { | |||
const auto& bond = *bond_it; | const auto& bond = *bond_it; | |||
int order = bond.ref->order; | int order = bond.ref->order; | |||
if (order > 3) { | if (order > 3) { | |||
++m_n_arom_bonds; | ++m_n_arom_bonds; | |||
order = 1; // aromatic bonds not supported | order = 1; // aromatic bonds not supported | |||
} | } | |||
m_offset += VLAprintf(m_buffer, m_offset, "%d %d %d %d\n", ++b, | m_offset += VLAprintf(m_buffer, m_offset, "%d %d %d %d\n", ++b, | |||
bond.id1, | bond.id1, | |||
bond.id2, | bond.id2, | |||
order); | order); | |||
int style = MaeExportGetBondStyle(m_atoms[bond.id1], m_atoms[bond.id2]); | ||||
m_offset += VLAprintf(m_buffer, m_offset, "%d %d\n", style, style); | ||||
} | } | |||
m_bonds.clear(); | m_bonds.clear(); | |||
} | } | |||
// end molecule | // end molecule | |||
m_offset += VLAprintf(m_buffer, m_offset, | m_offset += VLAprintf(m_buffer, m_offset, | |||
":::\n" | ":::\n" | |||
"}\n" // end bonds (or atoms) table | "}\n" // end bonds (or atoms) table | |||
"}\n"); | "}\n"); | |||
End of changes. 14 change blocks. | ||||
1 lines changed or deleted | 53 lines changed or added |