📄 style_manager.cpp
字号:
if ((!backboneStyle && !generalStyle) || (backboneStyle && generalStyle)) { ERRORMSG("StyleManager::GetAtomStyle() - confused about style settings"); return false; } if (saveBackboneStyle) *saveBackboneStyle = backboneStyle; if (saveGeneralStyle) *saveGeneralStyle = generalStyle; // first check whether this atom is visible, based on show/hide and backbone and sidechain settings if (object->parentSet->showHideManager->IsHidden(residue)) ATOM_NOT_DISPLAYED; if (info->atomicNumber == 1 && !settings.hydrogensOn) ATOM_NOT_DISPLAYED; if (info->classification == Residue::eSideChainAtom && !generalStyle->isOn) ATOM_NOT_DISPLAYED; if (info->classification == Residue::eAlphaBackboneAtom || info->classification == Residue::ePartialBackboneAtom || info->classification == Residue::eCompleteBackboneAtom) { // is backbone of some sort // control presence of non CA/C1* backbone atoms if ((residue->IsAminoAcid() && info->classification != Residue::eAlphaBackboneAtom) || (residue->IsNucleotide() && info->code != " C1*")) { // skip if backbone off if (backboneStyle->type == StyleSettings::eOff) ATOM_NOT_DISPLAYED; // show only alpha atom if eTrace if (backboneStyle->type == StyleSettings::eTrace && info->classification != Residue::eAlphaBackboneAtom) ATOM_NOT_DISPLAYED; // don't show complete backbone if set to partial if (info->classification == Residue::eCompleteBackboneAtom && backboneStyle->type == StyleSettings::ePartial) ATOM_NOT_DISPLAYED; } // if this is alpha/C1* and backbone is off, but sidechains are on, then // let the atom be visible *and* take the style of the sidechain else if (backboneStyle->type == StyleSettings::eOff || (residue->IsNucleotide() && backboneStyle->type != StyleSettings::eComplete)) { const StyleSettings::GeneralStyle *sidechainStyle = NULL; if (residue->IsAminoAcid()) sidechainStyle = &(settings.proteinSidechains); else if (residue->IsNucleotide()) sidechainStyle = &(settings.nucleotideSidechains); if (sidechainStyle && sidechainStyle->isOn) { backboneStyle = NULL; generalStyle = sidechainStyle; } else ATOM_NOT_DISPLAYED; } } if (info->classification == Residue::eUnknownAtom && !generalStyle->isOn) ATOM_NOT_DISPLAYED; const Element *element = PeriodicTable.GetElement(info->atomicNumber); // determine radius switch (backboneStyle ? backboneStyle->style : generalStyle->style) { case StyleSettings::eWire: case StyleSettings::eWireWorm: case StyleSettings::eTubeWorm: // no atom, but don't do ATOM_NOT_DISPLAYED, because bonds to this atom // still may be displayed and need style info about this atom atomStyle->radius = 0.0; break; case StyleSettings::eTubes: atomStyle->radius = settings.tubeRadius; break; case StyleSettings::eBallAndStick: atomStyle->radius = settings.ballRadius; break; case StyleSettings::eSpaceFill: atomStyle->radius = element->vdWRadius * settings.spaceFillProportion; break; default: ERRORMSG("StyleManager::GetAtomStyle() - inappropriate style for atom"); return false; } // determine color StyleSettings::eColorScheme colorStyle = backboneStyle ? backboneStyle->colorScheme : generalStyle->colorScheme; switch (colorStyle) { case StyleSettings::eElement: atomStyle->color = element->color; break; case StyleSettings::eAligned: case StyleSettings::eIdentity: case StyleSettings::eVariety: case StyleSettings::eWeightedVariety: case StyleSettings::eInformationContent: case StyleSettings::eFit: case StyleSettings::eBlockFit: case StyleSettings::eBlockZFit: case StyleSettings::eBlockRowFit: if (molecule->sequence && molecule->parentSet->alignmentManager-> IsAligned(molecule->sequence, residue->id - 1)) { // assume seqIndex is rID - 1 const Vector * color = molecule->parentSet->alignmentManager-> GetAlignmentColor(molecule->sequence, residue->id - 1, colorStyle); if (color) atomStyle->color = *color; else atomStyle->color = GlobalColors()->Get(Colors::eUnaligned); break; } if (colorStyle != StyleSettings::eAligned) { atomStyle->color = GlobalColors()->Get(Colors::eUnaligned); break; } // if eAligned and not aligned, then fall through to use eObject coloring case StyleSettings::eObject: atomStyle->color = GlobalColors()->Get(Colors::eCycle1, object->id - 1); break; case StyleSettings::eDomain: atomStyle->color = (molecule->residueDomains[residue->id - 1] == Molecule::NO_DOMAIN_SET) ? GlobalColors()->Get(Colors::eNoDomain) : GlobalColors()->Get(Colors::eCycle1, molecule->residueDomains[residue->id - 1] - 1); break; case StyleSettings::eMolecule: atomStyle->color = GlobalColors()->Get(Colors::eCycle1, molecule->id - 1); break; case StyleSettings::eRainbow: { double pos = 1.0; if ((residue->IsAminoAcid() || residue->IsNucleotide()) && molecule->NResidues() > 1) { pos = 1.0 * (residue->id - 1) / (molecule->NResidues() - 1); } atomStyle->color = GlobalColors()->Get(Colors::eRainbowMap, pos); break; } case StyleSettings::eSecondaryStructure: if (molecule->IsResidueInHelix(residue->id)) atomStyle->color = GlobalColors()->Get(Colors::eHelix); else if (molecule->IsResidueInStrand(residue->id)) atomStyle->color = GlobalColors()->Get(Colors::eStrand); else atomStyle->color = GlobalColors()->Get(Colors::eCoil); break; case StyleSettings::eCharge: { int charge = (residue->IsAminoAcid()) ? GetCharge(residue->code) : 0; atomStyle->color = GlobalColors()->Get( (charge > 0) ? Colors::ePositive : ((charge < 0) ? Colors::eNegative : Colors::eNeutral)); break; } case StyleSettings::eTemperature: atomStyle->color = (coord && coord->averageTemperature != AtomCoord::NO_TEMPERATURE && object->maxTemperature != object->minTemperature) ? GlobalColors()->Get(Colors::eTemperatureMap, (coord->averageTemperature - object->minTemperature) / (object->maxTemperature - object->minTemperature)) : GlobalColors()->Get(Colors::eNoTemperature); break; case StyleSettings::eHydrophobicity: { double hydrophobicity = (residue->IsAminoAcid()) ? GetHydrophobicity(residue->code) : UNKNOWN_HYDROPHOBICITY; atomStyle->color = (hydrophobicity != UNKNOWN_HYDROPHOBICITY) ? GlobalColors()->Get(Colors::eHydrophobicityMap, hydrophobicity) : GlobalColors()->Get(Colors::eNoHydrophobicity); break; } case StyleSettings::eUserSelect: if (backboneStyle) atomStyle->color = backboneStyle->userColor; else atomStyle->color = generalStyle->userColor; break; default: ERRORMSG("StyleManager::GetAtomStyle() - inappropriate color scheme for atom"); return false; } // determine transparency and metal ion labeling atomStyle->centerLabel.erase(); if (molecule->IsSolvent()) atomStyle->style = eTransparentAtom; else if (IsMetal(info->atomicNumber) || (molecule->NResidues() == 1 && residue->NAtomsInGraph() == 1)) { atomStyle->style = eTransparentAtom; // always big spheres for metals or isolated atoms atomStyle->radius = element->vdWRadius * settings.spaceFillProportion; if (settings.ionLabelsOn) atomStyle->centerLabel = element->symbol; } else atomStyle->style = eSolidAtom; // add transparency; scale by occupancy if transparent if (atomStyle->style == eTransparentAtom) { atomStyle->alpha = 0.6; if (coord && coord->occupancy < 1 && coord->occupancy > 0) atomStyle->alpha *= coord->occupancy; } else atomStyle->alpha = 1.0; // determine whether it's highlighted, but *don't* set the color to the highlight // color yet, since this is used by the sequence viewer where the residue letter is // colored independently of the highlighted background atomStyle->isHighlighted = GlobalMessenger()->IsHighlighted(molecule, residue->id); atomStyle->name = info->glName; return true;}// this is basically a map from StyleSettings enums to StyleManager enums;// sets bond radius, toostatic bool SetBondStyleFromResidueStyle(StyleSettings::eDrawingStyle style, const StyleSettings& settings, BondStyle::EndStyle *end){ switch (style) { case StyleSettings::eWire: end->style = StyleManager::eLineBond; break; case StyleSettings::eTubes: end->style = StyleManager::eCylinderBond; end->radius = settings.tubeRadius; break; case StyleSettings::eBallAndStick: end->style = StyleManager::eCylinderBond; end->radius = settings.stickRadius; break; case StyleSettings::eSpaceFill: end->style = StyleManager::eLineBond; break; case StyleSettings::eWireWorm: end->style = StyleManager::eLineWormBond; break; case StyleSettings::eTubeWorm: end->style = StyleManager::eThickWormBond; end->radius = settings.tubeWormRadius; break; default: ERRORMSG("SetBondStyleFromResidueStyle() - invalid style for bond"); return false; } return true;}#define BOND_NOT_DISPLAYED do { \ bondStyle->end1.style = bondStyle->end2.style = eNotDisplayed; \ return true; } while (0)// Bond style is set by the residue style of the atoms at each end; the color// is taken from the atom style (GetAtomStyle()), as well as some convenience// style pointers (backboneStyle, generalStyle). Show/hide status is taken// from the atoms - if either is hidden, the bond isn't shown either.bool StyleManager::GetBondStyle(const Bond *bond, const AtomPntr& atom1, const AtomCoord *coord1, const AtomPntr& atom2, const AtomCoord *coord2, double bondLength, BondStyle *bondStyle) const{ const StructureObject *object; if (!bond->GetParentOfType(&object)) return false; const Residue::AtomInfo *info1 = object->graph->GetAtomInfo(atom1), *info2 = object->graph->GetAtomInfo(atom2); if (!info1 || !info2) BOND_NOT_DISPLAYED; AtomStyle atomStyle1, atomStyle2; const StyleSettings::BackboneStyle *backboneStyle1, *backboneStyle2; const StyleSettings::GeneralStyle *generalStyle1, *generalStyle2; if (!GetAtomStyle(info1->residue, atom1, coord1, &atomStyle1, &backboneStyle1, &generalStyle1) || !GetAtomStyle(info2->residue, atom2, coord2, &atomStyle2, &backboneStyle2, &generalStyle2)) return false; // if both atoms are hidden, or either one doesn't have coordinates, don't show the bond if ((atomStyle1.style == eNotDisplayed && atomStyle2.style == eNotDisplayed) || (!coord1 || !coord2)) BOND_NOT_DISPLAYED; // defaults bondStyle->end1.atomCap = bondStyle->end2.atomCap = false; bondStyle->end1.name = info1->glName; bondStyle->end2.name = info2->glName; bondStyle->midCap = false; // if one atom is hidden, check for special cases to see if bond is visible at all if (atomStyle1.style == eNotDisplayed || atomStyle2.style == eNotDisplayed) { bool isSpecial = false; // is residue PRO, and bond is between CD and N? if (info1->residue->IsAminoAcid() && info1->residue->nameGraph == "PRO" && atom1.mID == atom2.mID && atom1.rID == atom2.rID) { const Molecule *molecule; if (!info1->residue->GetParentOfType(&molecule)) return false; // atom1 is CD and is visible, switch N (atom2) to side chain style if (info1->code == " CD " && atomStyle1.style != eNotDisplayed && info2->code == " N ") { generalStyle2 = generalStyle1; backboneStyle2 = NULL; atomStyle2.isHighlighted = GlobalMessenger()->IsHighlighted(molecule, info2->residue->id); bondStyle->end2.atomCap = true; isSpecial = true; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -