garlic-1.6/0000755000076500007650000000000010445776565013132 5ustar zuciczucic00000000000000garlic-1.6/b0000644000076500007650000000010310375357446013263 0ustar zuciczucic00000000000000# Playing with porin. load 2por.pdb select 1-301 sequence from 1 garlic-1.6/key_release.c0000644000076500007650000000311007065471747015557 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= key_release.c Purpose: Handle KeyRelease events (just reset some flags). Input: (1) Pointer to GUIS structure, with GUI data. (2) Pointer to XKeyEvent structure. Output: (1) One flag changed in GUIS structure. (2) Return value. Return value: (1) Positive on success. (2) Negative on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======handle KeyRelease events:============================================*/ int KeyRelease_ (GUIS *guiSP, XKeyEvent *key_eventSP) { char stringA[STRINGSIZE]; KeySym key_symID; XComposeStatus compose_statusS; /* Get the KeySym: */ XLookupString (key_eventSP, stringA, STRINGSIZE, &key_symID, &compose_statusS); /* Select the proper action for a given KeySym: */ switch (key_symID) { /* Shift key released: */ case XK_Shift_L: case XK_Shift_R: guiSP->shift_pressedF = 0; break; /* Control key released: */ case XK_Control_L: case XK_Control_R: guiSP->control_pressedF = 0; break; /* Alt or meta key released: */ case XK_Alt_L: case XK_Alt_R: case XK_Meta_L: case XK_Meta_R: guiSP->alt_pressedF = 0; break; /* All other cases are ignored: */ default: ; } /* Return positive value: */ return 1; } /*===========================================================================*/ garlic-1.6/fix_chain.c0000644000076500007650000000355007311516150015205 0ustar zuciczucic00000000000000/* Copyright (C) 2001 Damir Zucic */ /*============================================================================= fix_chain.c Purpose: Fix the macromolecular chain. The newly created structure is very messy after the creation. This function has to move, rotate and connect residues. The initial conformation will be extended. The structure is brought to the specified conformation at the end of this function. Input: (1) Pointer to MolComplexS structure. (2) Pointer to RuntimeS structure (secondary structure is there). Output: (1) The conformation of the specified structure will be changed. (2) Return value. Return value: (1) Positive on success. (2) Negative on failure. ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int ResetPhi_ (MolComplexS *); int ResetPsi_ (MolComplexS *); int BuildChain_ (MolComplexS *); int ApplyStructure_ (MolComplexS *, RuntimeS *); /*======fix macromolecular chain:============================================*/ int FixChain_ (MolComplexS *mol_complexSP, RuntimeS *runtimeSP) { int n; /* Reset the phi angle in each residue (change it to -180 degrees): */ ResetPhi_ (mol_complexSP); /* Reset the psi angle in each residue (change it to 180 degrees): */ ResetPsi_ (mol_complexSP); /* Build the extended polypeptide chain: */ n = BuildChain_ (mol_complexSP); if (n < 0) return n; /* Apply the specified secondary structure: */ ApplyStructure_ (mol_complexSP, runtimeSP); /* If this point is reached, return positive value (success indicator): */ return 1; } /*===========================================================================*/ garlic-1.6/comm_fading.c0000644000076500007650000001423307465733433015537 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2002 Damir Zucic */ /*============================================================================= comm_fading.c Purpose: Execute fading command. Change fading mode or change the position of front or back fading surface. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) The number of macromolecular complexes. (3) Pointer to RuntimeS structure, with some runtime data. (4) Pointer to ConfigS structure, with configuration data. (5) Pointer to GUIS structure, with GUI data. (6) Pointer to NearestAtomS structure. (7) The number of pixels in the main window free area. (8) Pointer to refreshI. (9) String which contains fading surface specification and fading shift. Output: (1) The fading mode changed for each caught macromolecular complex. (2) Return value. Return value: (1) Positive (command) code on success. (2) Negative (error) code on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "commands.h" #include "typedefs.h" /*======function prototypes:=================================================*/ char *ExtractToken_ (char *, int, char *, char *); int ChangeFading_ (MolComplexS *, int, int); void MoveBackFading_ (MolComplexS *, int, ConfigS *, double); void MoveFrontFading_ (MolComplexS *, int, ConfigS *, double); size_t MainRefresh_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); int ControlRefresh_ (MolComplexS *, ConfigS *, GUIS *); /*======execute fading command:================================================*/ int CommandFading_ (MolComplexS *mol_complexSP, int mol_complexesN, RuntimeS *runtimeSP, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int *refreshIP, char *stringP) { char *remainderP; char tokenA[STRINGSIZE]; int surfaceID; double shift; /* Extract the first token: */ remainderP = ExtractToken_ (tokenA, STRINGSIZE, stringP, " \t\n"); if (!remainderP) { strcpy (runtimeSP->messageA, "Fading specification incomplete!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_FADING; } /* Switch fading off: */ if (strstr (tokenA, "OFF") == tokenA) { ChangeFading_ (mol_complexSP, mol_complexesN, 0); (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); return COMMAND_FADING; } /* Change fading to planar: */ else if (strstr (tokenA, "PLA") == tokenA) { ChangeFading_ (mol_complexSP, mol_complexesN, 1); (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); return COMMAND_FADING; } /* Change fading to spherical: */ else if (strstr (tokenA, "SPH") == tokenA) { ChangeFading_ (mol_complexSP, mol_complexesN, 2); (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); return COMMAND_FADING; } /* Change fading to semi-spherical: */ else if ((strstr (tokenA, "HALF-SPH") == tokenA) || (strstr (tokenA, "HALF_SPH") == tokenA)) { ChangeFading_ (mol_complexSP, mol_complexesN, 3); (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); return COMMAND_FADING; } /* Change fading to cylindrical: */ else if (strstr (tokenA, "CYL") == tokenA) { ChangeFading_ (mol_complexSP, mol_complexesN, 4); (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); return COMMAND_FADING; } /* Change fading to semi-cylindrical: */ else if ((strstr (tokenA, "HALF-CYL") == tokenA) || (strstr (tokenA, "HALF_CYL") == tokenA)) { ChangeFading_ (mol_complexSP, mol_complexesN, 5); (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); return COMMAND_FADING; } /* Identify the surface: */ else if (strstr (tokenA, "FRO") == tokenA) surfaceID = 1; else if (strstr (tokenA, "BAC") == tokenA) surfaceID = 2; else { strcpy (runtimeSP->messageA, "Bad surface (valid keywords are front and back)!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_BAD_SURFACE; } /* Extract the token which contains the shift: */ remainderP = ExtractToken_ (tokenA, STRINGSIZE, remainderP, " \t\n"); if (!remainderP) { strcpy (runtimeSP->messageA, "Fading shift missing!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_NO_SHIFT; } /* Extract the shift: */ if (sscanf (tokenA, "%lf", &shift) != 1) { strcpy (runtimeSP->messageA, "Fading specification is bad (unknown keyword used)!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_NO_SHIFT; } /* Move the specified fading surface: */ if (surfaceID == 1) { MoveFrontFading_ (mol_complexSP, mol_complexesN, configSP, shift); } else { MoveBackFading_ (mol_complexSP, mol_complexesN, configSP, shift); } /* Refresh the main window: */ (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); /* Refresh the control window: */ ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); /* Return positive value on success: */ return COMMAND_FADING; } /*===========================================================================*/ garlic-1.6/18porins2.script0000644000076500007650000001060210403772773016113 0ustar zuciczucic00000000000000# Loading and displaying 18 porins. # All structures will be displayed as cyan-blue backbones. # The following patterns will be outlined: # (1) very_polar - aromatic (red) # (2) aromatic - very_polar (yellow) # will be colored red. # Turn refreshing off, for better performance (don't forget # to switch the refreshing on at the end of this script!): refresh off # (1) 2POR: load 2por.pdb backbone 2 color cyan-blue pattern = arg lys asp glu asn gln / phe tyr trp select pattern color red pattern = phe tyr trp / arg lys asp glu asn gln select pattern color yellow position -120 -90 600 # (2) 1OPF: load 1opf.pdb backbone 2 color cyan-blue pattern = arg lys asp glu asn gln / phe tyr trp select pattern color red pattern = phe tyr trp / arg lys asp glu asn gln select pattern color yellow position -60 -90 600 # (3) 1PRN: load 1prn.pdb backbone 2 color cyan-blue pattern = arg lys asp glu asn gln / phe tyr trp select pattern color red pattern = phe tyr trp / arg lys asp glu asn gln select pattern color yellow position 0 -90 600 # (4) 1OSM: load 1osm.pdb backbone 2 color cyan-blue pattern = arg lys asp glu asn gln / phe tyr trp select pattern color red pattern = phe tyr trp / arg lys asp glu asn gln select pattern color yellow position 60 -90 600 # (5) 1E54: load 1e54.pdb backbone 2 color cyan-blue pattern = arg lys asp glu asn gln / phe tyr trp select pattern color red pattern = phe tyr trp / arg lys asp glu asn gln select pattern color yellow position 120 -90 600 # (6) 1MAL: load 1mal.pdb backbone 2 color cyan-blue pattern = arg lys asp glu asn gln / phe tyr trp select pattern color red pattern = phe tyr trp / arg lys asp glu asn gln select pattern color yellow position -120 -30 600 # (7) 1A0S: load 1a0s.pdb backbone 2 color cyan-blue pattern = arg lys asp glu asn gln / phe tyr trp select pattern color red pattern = phe tyr trp / arg lys asp glu asn gln select pattern color yellow position -60 -30 600 # (8) 1BXW: load 1bxw.pdb backbone 2 color cyan-blue pattern = arg lys asp glu asn gln / phe tyr trp select pattern color red pattern = phe tyr trp / arg lys asp glu asn gln select pattern color yellow position 0 -30 600 # (9) 1QJ8: load 1qj8.pdb backbone 2 color cyan-blue pattern = arg lys asp glu asn gln / phe tyr trp select pattern color red pattern = phe tyr trp / arg lys asp glu asn gln select pattern color yellow position 60 -30 600 # (10) 2FCP: load 2fcp.pdb backbone 2 color cyan-blue pattern = arg lys asp glu asn gln / phe tyr trp select pattern color red pattern = phe tyr trp / arg lys asp glu asn gln select pattern color yellow position 120 -30 600 # (11) 1FEP: load 1fep.pdb backbone 2 color cyan-blue pattern = arg lys asp glu asn gln / phe tyr trp select pattern color red pattern = phe tyr trp / arg lys asp glu asn gln select pattern color yellow position -120 30 600 # (12) 1KMO: load 1kmo.pdb backbone 2 color cyan-blue pattern = arg lys asp glu asn gln / phe tyr trp select pattern color red pattern = phe tyr trp / arg lys asp glu asn gln select pattern color yellow position -60 30 600 # (13) 1QD5: load 1qd5.pdb backbone 2 color cyan-blue pattern = arg lys asp glu asn gln / phe tyr trp select pattern color red pattern = phe tyr trp / arg lys asp glu asn gln select pattern color yellow position 0 30 600 # (14) 1I78: load 1i78.pdb backbone 2 color cyan-blue pattern = arg lys asp glu asn gln / phe tyr trp select pattern color red pattern = phe tyr trp / arg lys asp glu asn gln select pattern color yellow position 60 30 600 # (15) 1K24: load 1k24.pdb backbone 2 color cyan-blue pattern = arg lys asp glu asn gln / phe tyr trp select pattern color red pattern = phe tyr trp / arg lys asp glu asn gln select pattern color yellow position 120 30 600 # (16) 1NQE: load 1nqe.pdb backbone 2 color cyan-blue pattern = arg lys asp glu asn gln / phe tyr trp select pattern color red pattern = phe tyr trp / arg lys asp glu asn gln select pattern color yellow position -120 90 600 # (17) 1TLZ: load 1tlz.pdb backbone 2 color cyan-blue pattern = arg lys asp glu asn gln / phe tyr trp select pattern color red pattern = phe tyr trp / arg lys asp glu asn gln select pattern color yellow position -60 90 600 # (18) 1T16: load 1t16.pdb backbone 2 color cyan-blue pattern = arg lys asp glu asn gln / phe tyr trp select pattern color red pattern = phe tyr trp / arg lys asp glu asn gln select pattern color yellow position 0 90 600 # Switch refreshing on: refresh on # Group all structures: group all garlic-1.6/BUGS0000644000076500007650000000015407642257745013614 0ustar zuciczucic00000000000000There must be some bugs! Please report bugs to Damir Zucic: zucic@garlic.mefos.hr zucic@mia.os.carnet.hr garlic-1.6/wheel_bottom_view.c0000644000076500007650000003626307747226261017024 0ustar zuciczucic00000000000000/* Copyright (C) 2002-2003 Damir Zucic */ /*============================================================================= wheel_bottom_view.c Purpose: Draw the helical wheel clockwise. This wheel corresponds to the bottom view of the helix. Input: (1) Pointer to RuntimeS structure, with some runtime data. (2) Pointer to GUIS structure, with GUI data. (3) Pointer to NearestAtomS structure, with information about the atom occupying the given pixel. (4) The number of pixels in the main window free area. (5) The refreshI, used to check the NearestAtomS associated with a given pixel. It is currently unused in this function. Output: (1) Helical wheel drawn clockwise to the main window. (2) Return value. Return value: (1) The number of residues used to prepare the helical wheel. Notes: (1) The initial drawing destination is the hidden pixmap, and the content of this pixmap is copied later to the main window. (2) Labels (residue names) are drawn for the last 18 residues. ========includes:============================================================*/ #include #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int RefreshPixmap_ (Display *, Pixmap, GC, unsigned int, unsigned int, unsigned long); int ParseColor_ (RGBS *, unsigned long *, GUIS *, char *, char *); double Hydrophobicity_ (char *, int, int); unsigned long WeightColors_ (unsigned long, unsigned long, double, GUIS *); int DrawTitles_ (RuntimeS *, GUIS *); /*======draw helical wheel clockwise:========================================*/ size_t WheelBottomView_ (RuntimeS *runtimeSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int refreshI) { int max_length; int residuesN, residueI; RGBS rgbS; unsigned long phob_colorID, neutral_colorID, phil_colorID; int scaleI; double min_hyphob, max_hyphob, threshold_hyphob; double delta_hyphob1, delta_hyphob2; double inverse_range1, inverse_range2; char *residue_nameP; char residue_nameA[RESNAMESIZE]; double hyphob; double scale_factor; unsigned long residue_colorID; int square_width, screen_margin, screen_radius, half_screen_radius; int screen_x0, screen_y0; int screen_x1, screen_y1, screen_x2, screen_y2; int width, height; int helix_step, arc_start, arc_extent, arc_center; int serialI, range_startI, range_endI, residues_in_wheelN = 0; int wheelI = 0; double angle, delta_x, delta_y; int label_length; char labelA[SHORTSTRINGSIZE]; int text_width, text_height; int ref_angle; int inner_screen_radius, thickness1, thickness2; double alpha0, delta_alpha, alpha1, alpha2; XPoint pointSA[7]; unsigned long far_colorID, near_colorID; /* The number of residues in sequence buffer: */ residuesN = runtimeSP->residuesN; if (residuesN == 0) { strcpy (runtimeSP->messageA, "The sequence buffer is empty!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return 0; } /* The wheel_clockwiseF decides in which direction the sequence should be scanned: */ /* The maximal residue name length: */ max_length = RESNAMESIZE - 1; /* Residue array index range: */ range_startI = runtimeSP->range_startI; range_endI = runtimeSP->range_endI; /* Count the number of residues in the specified range: */ for (residueI = residuesN - 1; residueI >= 0; residueI--) { /* Check is the residue array index inside the range: */ if ((residueI < range_startI) || (residueI > range_endI)) continue; /* Increase the count of residues if current */ /* residue belongs to the specified range: */ residues_in_wheelN++; } /* Check the number of residues in a wheel: */ if (residues_in_wheelN == 0) { strcpy (runtimeSP->messageA, "The specified range is empty!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return 0; } /* Refresh the hidden pixmap, where drawing will be done: */ RefreshPixmap_ (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], guiSP->control_winS.x0, guiSP->input_winS.y0, guiSP->main_winS.bg_colorID); /*------draw arcs:-----------------------------------------------------------*/ /* Initialize colors used for hydrophobicity: */ ParseColor_ (&rgbS, &phob_colorID, guiSP, "RGB:FFFF/0000/0000", "white"); ParseColor_ (&rgbS, &neutral_colorID, guiSP, "RGB:FFFF/FFFF/FFFF", "white"); ParseColor_ (&rgbS, &phil_colorID, guiSP, "RGB:0000/0000/FFFF", "black"); /* Hydrophobicity scale index: */ scaleI = runtimeSP->hydrophobicity_scaleI; /* Minimal, maximal and threshold hydrophobicity for current complex: */ min_hyphob = Hydrophobicity_ ("", scaleI, 1); max_hyphob = Hydrophobicity_ ("", scaleI, 2); threshold_hyphob = Hydrophobicity_ ("", scaleI, 4); /* Inverse hydrophobicity ranges: */ delta_hyphob1 = max_hyphob - threshold_hyphob; if (delta_hyphob1 != 0.0) inverse_range1 = 1.0 / delta_hyphob1; else inverse_range1 = 0.0; delta_hyphob2 = threshold_hyphob - min_hyphob; if (delta_hyphob2 != 0.0) inverse_range2 = 1.0 / delta_hyphob2; else inverse_range2 = 0.0; /* Prepare geometric parameters: */ square_width = guiSP->main_win_free_area_height; if ((int) guiSP->main_win_free_area_width < square_width) { square_width = guiSP->main_win_free_area_width; } screen_margin = guiSP->main_winS.text_line_height + guiSP->main_winS.text_line_height / 2 + 2; screen_radius = square_width / 2 - screen_margin; if (screen_radius < 0) screen_radius = square_width / 2; half_screen_radius = screen_radius / 2; screen_x1 = guiSP->main_win_free_area_width / 2; screen_y1 = guiSP->main_win_free_area_height / 2; screen_x0 = screen_x1 - screen_radius; screen_y0 = screen_y1 - screen_radius; width = 2 * screen_radius; height = width; /* Prepare the helix step angle (degrees * 64): */ helix_step = runtimeSP->helix_step_angle * 64; /* Prepare the arc extent angle, (degrees * 64): */ arc_extent = (int) runtimeSP->arc_angle * 64; /* Initialize the arc start angle, (degrees * 64): */ arc_start = 5760 - arc_extent / 2; /* Prepare the text color: */ XSetForeground (guiSP->displaySP, guiSP->theGCA[0], guiSP->main_winS.fg_colorID); /* Prepare the arc edge color: */ XSetForeground (guiSP->displaySP, guiSP->theGCA[1], guiSP->black_colorID); /* Scan the sequence: */ for (residueI = residuesN - 1; residueI >= 0; residueI--) { /* Pointer to the current residue name: */ residue_nameP = runtimeSP->sequenceP + residueI * max_length; /* Check is the residue array index inside the range: */ if ((residueI < range_startI) || (residueI > range_endI)) continue; /* Copy the residue name: */ strncpy (residue_nameA, residue_nameP, max_length); residue_nameA[max_length] = '\0'; /* The corresponding hydrophobicity: */ hyphob = Hydrophobicity_ (residue_nameA, scaleI, 0); /* If hydrophobicity is below the threshold value: */ if (hyphob <= threshold_hyphob) { scale_factor = (threshold_hyphob - hyphob) * inverse_range2; residue_colorID = WeightColors_ (neutral_colorID, phil_colorID, scale_factor, guiSP); } /* If hydrophobicity is above the threshold value: */ else { scale_factor = (hyphob - threshold_hyphob) * inverse_range1; residue_colorID = WeightColors_ (neutral_colorID, phob_colorID, scale_factor, guiSP); } /* Prepare the color: */ XSetForeground (guiSP->displaySP, guiSP->theGCA[2], residue_colorID); /* Draw filled arc: */ XFillArc (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], screen_x0, screen_y0, width, height, arc_start, arc_extent); /* Draw the outer arc edge: */ XDrawArc (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], screen_x0, screen_y0, width, height, arc_start, arc_extent); /* Draw two straight lines from the arc origin to the edge: */ angle = DEG_TO_RAD * (double) arc_start / 64.0; delta_x = (double) screen_radius * cos (angle); delta_y = (double) screen_radius * sin (angle); delta_y *= -1; screen_x2 = screen_x1 + (int) delta_x; screen_y2 = screen_y1 + (int) delta_y; XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], screen_x1, screen_y1, screen_x2, screen_y2); angle = DEG_TO_RAD * (double) (arc_start + arc_extent) / 64.0; delta_x = (double) screen_radius * cos (angle); delta_y = (double) screen_radius * sin (angle); delta_y *= -1; screen_x2 = screen_x1 + (int) delta_x; screen_y2 = screen_y1 + (int) delta_y; XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], screen_x1, screen_y1, screen_x2, screen_y2); /* Draw labels for the last 18 residues (not for all!): */ if (residues_in_wheelN - wheelI <= 18) { arc_center = arc_start + arc_extent / 2; angle = DEG_TO_RAD * (double) arc_center / 64.0; delta_x = (double) screen_radius * cos (angle); delta_y = (double) screen_radius * sin (angle); delta_y *= -1; screen_x2 = screen_x1 + (int) delta_x; screen_y2 = screen_y1 + (int) delta_y; serialI = *(runtimeSP->serialIP + residueI); sprintf (labelA, "%d:%s", serialI, residue_nameA); label_length = strlen (labelA); text_width = XTextWidth (guiSP->main_winS.fontSP, labelA, label_length); text_height = guiSP->main_winS.font_height; if (screen_x2 < screen_x1) screen_x2 -= text_width - 1; if (screen_y2 > screen_y1) screen_y2 += text_height; else screen_y2 -= 2; XDrawString (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x2, screen_y2, labelA, label_length); } /* Update the arc start angle: */ arc_start += helix_step; if (arc_start > 23040) arc_start = arc_start - 23040; /* Update the wheel index: */ wheelI++; } /*------draw the hole in the wheel center:-----------------------------------*/ /* Prepare geometric parameters: */ screen_x0 = guiSP->main_win_free_area_width / 2 - half_screen_radius; screen_y0 = guiSP->main_win_free_area_height / 2 - half_screen_radius; width = 2 * half_screen_radius; height = width; XSetForeground (guiSP->displaySP, guiSP->theGCA[0], guiSP->main_winS.bg_colorID); XFillArc (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0, screen_y0, width, height, 0, 23040); /*------draw polygons which represent backbone:------------------------------*/ /* This should be done only if angle is not equal to zero: */ if (helix_step != 0) { /* Prepare far and near color: */ ParseColor_ (&rgbS, &far_colorID, guiSP, "RGB:4444/4444/4444", "white"); ParseColor_ (&rgbS, &near_colorID, guiSP, "RGB:FFFF/FFFF/FFFF", "white"); if (residuesN < 3) { ParseColor_ (&rgbS, &far_colorID, guiSP, "RGB:AAAA/AAAA/AAAA", "white"); } /* Prepare the polygon edge color: */ XSetForeground (guiSP->displaySP, guiSP->theGCA[2], guiSP->black_colorID); /* Prepare half of the helix step angle in radians: */ delta_alpha = DEG_TO_RAD * (double) helix_step / 128.0; /* Prepare the inner radius: */ inner_screen_radius = half_screen_radius * cos (delta_alpha); /* Prepare two thickness parameters: */ thickness1 = screen_radius / 10; if (thickness1 < 4) thickness1 = 4; thickness2 = thickness1 * cos (delta_alpha); if (thickness2 == 0) thickness2 = thickness1; /* Initialize the reference angle (X11 units): */ ref_angle = 5760; /* Reset the wheel index: */ wheelI = 0; /* Scan the sequence again: */ for (residueI = residuesN - 1; residueI >= 0; residueI--) { /* Check is this array index inside the range: */ if ((residueI < range_startI) || (residueI > range_endI)) { continue; } /* Convert the reference angle to radians: */ alpha0 = DEG_TO_RAD * (double) ref_angle / 64.0; /* Prepare two additional angles: */ alpha1 = alpha0 - delta_alpha; alpha2 = alpha0 + delta_alpha; /* Now prepare seven points. */ /* The first point: */ delta_x = (double) half_screen_radius * cos (alpha0); delta_y = (double) half_screen_radius * sin (alpha0); delta_y *= -1; screen_x2 = screen_x1 + (int) delta_x; screen_y2 = screen_y1 + (int) delta_y; pointSA[0].x = (short) screen_x2; pointSA[0].y = (short) screen_y2; /* The second point: */ delta_x = (double) inner_screen_radius * cos (alpha1); delta_y = (double) inner_screen_radius * sin (alpha1); delta_y *= -1; screen_x2 = screen_x1 + (int) delta_x; screen_y2 = screen_y1 + (int) delta_y; pointSA[1].x = (short) screen_x2; pointSA[1].y = (short) screen_y2; /* The third point: */ delta_x = (double) (inner_screen_radius + thickness2) * cos (alpha1); delta_y = (double) (inner_screen_radius + thickness2) * sin (alpha1); delta_y *= -1; screen_x2 = screen_x1 + (int) delta_x; screen_y2 = screen_y1 + (int) delta_y; pointSA[2].x = (short) screen_x2; pointSA[2].y = (short) screen_y2; /* The fourth point: */ delta_x = (double) (half_screen_radius + thickness1) * cos (alpha0); delta_y = (double) (half_screen_radius + thickness1) * sin (alpha0); delta_y *= -1; screen_x2 = screen_x1 + (int) delta_x; screen_y2 = screen_y1 + (int) delta_y; pointSA[3].x = (short) screen_x2; pointSA[3].y = (short) screen_y2; /* The fifth point: */ delta_x = (double) (inner_screen_radius + thickness2) * cos (alpha2); delta_y = (double) (inner_screen_radius + thickness2) * sin (alpha2); delta_y *= -1; screen_x2 = screen_x1 + (int) delta_x; screen_y2 = screen_y1 + (int) delta_y; pointSA[4].x = (short) screen_x2; pointSA[4].y = (short) screen_y2; /* The sixth point: */ delta_x = (double) inner_screen_radius * cos (alpha2); delta_y = (double) inner_screen_radius * sin (alpha2); delta_y *= -1; screen_x2 = screen_x1 + (int) delta_x; screen_y2 = screen_y1 + (int) delta_y; pointSA[5].x = (short) screen_x2; pointSA[5].y = (short) screen_y2; /* The seventh point is a copy of the first point: */ pointSA[6].x = pointSA[0].x; pointSA[6].y = pointSA[0].y; /* Prepare the polygon interior color: */ if (residues_in_wheelN > 1) { scale_factor = (double) wheelI / (double) (residues_in_wheelN - 1); } else scale_factor = 0.0; residue_colorID = WeightColors_ (far_colorID, near_colorID, scale_factor, guiSP); XSetForeground (guiSP->displaySP, guiSP->theGCA[2], residue_colorID); /* Draw the filled polygon: */ XFillPolygon (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], pointSA, 6, Complex, CoordModeOrigin); /* Draw the polygon edge: */ XDrawLines (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], pointSA, 7, CoordModeOrigin); /* Update the reference angle (X11 units): */ ref_angle += helix_step; if (ref_angle > 23040) ref_angle = ref_angle - 23040; /* Update the wheel index: */ wheelI++; } } /*------draw titles:---------------------------------------------------------*/ /* Draw titles: */ DrawTitles_ (runtimeSP, guiSP); /*------copy the prepared image to the main window:--------------------------*/ /* Copy hidden pixmap to the main window: */ XCopyArea (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->main_winS.ID, guiSP->theGCA[0], 0, 0, guiSP->main_win_free_area_width, guiSP->main_win_free_area_height, 0, 0); return (size_t) residuesN; } /*===========================================================================*/ garlic-1.6/TODO0000644000076500007650000000055410361457526013614 0ustar zuciczucic00000000000000This file will contain the list of planned changes and additions. Send suggestions to Damir Zucic: zucic@garlic.mefos.hr zucic@mefos.hr ============================================================================ FUTURE ENHANCEMENTS: ============================================================================ (1) Molecular surfaces. (2) Molecular dynamics. garlic-1.6/hyphob_function1.c0000644000076500007650000000713510443261101016530 0ustar zuciczucic00000000000000/* Copyright (C) 2006 Damir Zucic */ /*============================================================================= hyphob_function1.c Purpose: Draw the hydrophobicity function F1. The sequence stored to the main sequence buffer is used to calculate the function value. Input: (1) Pointer to the storage where the minimal function value will be stored. (2) Pointer to the storage where the maximal function value will be stored. (3) Pointer to RuntimeS structure. Output: (1) Function F1 calculated and stored. (2) Return value. Return value: (1) Positive on success. (2) Negative on failure. Notes: (1) The function F1 may be modified and used for many purposes. Originally, it was introduced while searching for the method which will be suitable for prediction of the porin secondary structure. ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======calculate the hydrophobicity function F1:============================*/ int HyphobFunction1_ (double *min_functionP, double *max_functionP, RuntimeS *runtimeSP) { int residuesN, residueI; /* Do not use size_t instead of int ! */ int max_length; int count; int windowI, combinedI; char *residue_nameP; char residue_nameA[RESNAMESIZE]; double function_value; /*------prepare some parameters:---------------------------------------------*/ /* The number of residues in the sequence buffer: */ residuesN = (int) runtimeSP->residuesN; if (residuesN == 0) return -1; /* The maximal residue name length: */ max_length = RESNAMESIZE - 1; /*------calculate the function F1:-------------------------------------------*/ /* Initialize the extreme values: */ *min_functionP = +999999.0; *max_functionP = -999999.0; /* 20060612.1446: */ /* Scan the window of 5 residues. Count ASP, ASN, GLU, GLN, ARG, LYS, HIS. */ /* Scan the sequence: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Reset the function value, it might be initialized before: */ *(runtimeSP->function1P + residueI) = 0.0; /* Reset the counter: */ count = 0; /* Scan the sliding window: */ for (windowI = -2; windowI <= 2; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI < 0) continue; if (combinedI >= residuesN) continue; /* Pointer to the residue name of */ /* the residue defined by combinedI: */ residue_nameP = runtimeSP->sequenceP + combinedI * max_length; /* Copy the residue name: */ strncpy (residue_nameA, residue_nameP, max_length); residue_nameA[max_length] = '\0'; /* Add +1 for charged and zwitterionic residues: */ if ((strcmp (residue_nameA, "ASP") == 0) || (strcmp (residue_nameA, "ASN") == 0) || (strcmp (residue_nameA, "GLU") == 0) || (strcmp (residue_nameA, "GLN") == 0) || (strcmp (residue_nameA, "ARG") == 0) || (strcmp (residue_nameA, "LYS") == 0) || (strcmp (residue_nameA, "HIS") == 0)) { count++; } } /* Store the function value: */ function_value = (double) count; *(runtimeSP->function1P + residueI) = function_value; /* Find the extreme values: */ if (function_value < *min_functionP) *min_functionP = function_value; if (function_value > *max_functionP) *max_functionP = function_value; /* End of residueI loop: */ } /*---------------------------------------------------------------------------*/ return 1; } /*===========================================================================*/ garlic-1.6/hyphob_function2.c0000644000076500007650000000727710443261123016544 0ustar zuciczucic00000000000000/* Copyright (C) 2006 Damir Zucic */ /*============================================================================= hyphob_function2.c Purpose: Draw the hydrophobicity function F2. The sequence stored to the main sequence buffer is used to calculate the function value. Input: (1) Pointer to the storage where the minimal function value will be stored. (2) Pointer to the storage where the maximal function value will be stored. (3) Pointer to RuntimeS structure. Output: (1) Function F2 calculated and stored. (2) Return value. Return value: (1) Positive on success. (2) Negative on failure. Notes: (1) The function F2 may be modified and used for many purposes. Originally, it was introduced while searching for the method which will be suitable for prediction of the porin secondary structure. ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======calculate the hydrophobicity function F2:============================*/ int HyphobFunction2_ (double *min_functionP, double *max_functionP, RuntimeS *runtimeSP) { int residuesN, residueI; /* Do not use size_t instead of int ! */ int max_length; int count; int windowI, combinedI; char *residue_nameP; char residue_nameA[RESNAMESIZE]; double function_value; /*------prepare some parameters:---------------------------------------------*/ /* The number of residues in the sequence buffer: */ residuesN = (int) runtimeSP->residuesN; if (residuesN == 0) return -1; /* The maximal residue name length: */ max_length = RESNAMESIZE - 1; /*------calculate the function F2:-------------------------------------------*/ /* Initialize the extreme values: */ *min_functionP = +999999.0; *max_functionP = -999999.0; /* 20060612.1447: */ /* Scan the window of 5 residues. Count ASP, */ /* ASN, GLU, GLN, ARG, LYS, HIS, SER and THR. */ /* Scan the sequence: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Reset the function value, it might be initialized before: */ *(runtimeSP->function2P + residueI) = 0.0; /* Reset the counter: */ count = 0; /* Scan the sliding window: */ for (windowI = -2; windowI <= 2; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI < 0) continue; if (combinedI >= residuesN) continue; /* Pointer to the residue name of */ /* the residue defined by combinedI: */ residue_nameP = runtimeSP->sequenceP + combinedI * max_length; /* Copy the residue name: */ strncpy (residue_nameA, residue_nameP, max_length); residue_nameA[max_length] = '\0'; /* Add +1 for some polar residues: */ if ((strcmp (residue_nameA, "ASP") == 0) || (strcmp (residue_nameA, "ASN") == 0) || (strcmp (residue_nameA, "GLU") == 0) || (strcmp (residue_nameA, "GLN") == 0) || (strcmp (residue_nameA, "ARG") == 0) || (strcmp (residue_nameA, "LYS") == 0) || (strcmp (residue_nameA, "HIS") == 0) || (strcmp (residue_nameA, "SER") == 0) || (strcmp (residue_nameA, "THR") == 0)) { count++; } } /* Store the function value: */ function_value = (double) count; *(runtimeSP->function2P + residueI) = function_value; /* Find the extreme values: */ if (function_value < *min_functionP) *min_functionP = function_value; if (function_value > *max_functionP) *max_functionP = function_value; /* End of residueI loop: */ } /*---------------------------------------------------------------------------*/ return 1; } /*===========================================================================*/ garlic-1.6/hyphob_function3.c0000644000076500007650000000732610443261476016553 0ustar zuciczucic00000000000000/* Copyright (C) 2006 Damir Zucic */ /*============================================================================= hyphob_function3.c Purpose: Draw the hydrophobicity function F3. The sequence stored to the main sequence buffer is used to calculate the function value. Input: (1) Pointer to the storage where the minimal function value will be stored. (2) Pointer to the storage where the maximal function value will be stored. (3) Pointer to RuntimeS structure. Output: (1) Function F3 calculated and stored. (2) Return value. Return value: (1) Positive on success. (2) Negative on failure. Notes: (1) The function F3 may be modified and used for many purposes. Originally, it was introduced while searching for the method which will be suitable for prediction of the porin secondary structure. ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======calculate the hydrophobicity function F3:============================*/ int HyphobFunction3_ (double *min_functionP, double *max_functionP, RuntimeS *runtimeSP) { int residuesN, residueI; /* Do not use size_t instead of int ! */ int max_length; int count; int windowI, combinedI; char *residue_nameP; char residue_nameA[RESNAMESIZE]; double function_value; /*------prepare some parameters:---------------------------------------------*/ /* The number of residues in the sequence buffer: */ residuesN = (int) runtimeSP->residuesN; if (residuesN == 0) return -1; /* The maximal residue name length: */ max_length = RESNAMESIZE - 1; /*------calculate the function F3:-------------------------------------------*/ /* Initialize the extreme values: */ *min_functionP = +999999.0; *max_functionP = -999999.0; /* 20060612.1450: */ /* Scan the window of 5 residues. Count LEU, */ /* ILE, VAL, ALA, MET, PHE, TYR, TRP and HIS. */ /* Scan the sequence: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Reset the function value, it might be initialized before: */ *(runtimeSP->function3P + residueI) = 0.0; /* Reset the counter: */ count = 0; /* Scan the sliding window: */ for (windowI = -2; windowI <= 2; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI < 0) continue; if (combinedI >= residuesN) continue; /* Pointer to the residue name of */ /* the residue defined by combinedI: */ residue_nameP = runtimeSP->sequenceP + combinedI * max_length; /* Copy the residue name: */ strncpy (residue_nameA, residue_nameP, max_length); residue_nameA[max_length] = '\0'; /* Add +1 for some hydrophobic residues: */ if ((strcmp (residue_nameA, "LEU") == 0) || (strcmp (residue_nameA, "ILE") == 0) || (strcmp (residue_nameA, "VAL") == 0) || (strcmp (residue_nameA, "MET") == 0) || (strcmp (residue_nameA, "ALA") == 0) || (strcmp (residue_nameA, "PHE") == 0) || (strcmp (residue_nameA, "TYR") == 0) || (strcmp (residue_nameA, "TRP") == 0) || (strcmp (residue_nameA, "HIS") == 0)) { count++; } } /* Scale and store the function value: */ function_value = -1.0 * (double) count; *(runtimeSP->function3P + residueI) = function_value; /* Find the extreme values: */ if (function_value < *min_functionP) *min_functionP = function_value; if (function_value > *max_functionP) *max_functionP = function_value; /* End of residueI loop: */ } /*---------------------------------------------------------------------------*/ return 1; } /*===========================================================================*/ garlic-1.6/hyphob_function4.c0000644000076500007650000000716310441772324016550 0ustar zuciczucic00000000000000/* Copyright (C) 2006 Damir Zucic */ /*============================================================================= hyphob_function4.c Purpose: Draw the hydrophobicity function F4. The sequence stored to the main sequence buffer is used to calculate the function value. Input: (1) Pointer to the storage where the minimal function value will be stored. (2) Pointer to the storage where the maximal function value will be stored. (3) Pointer to RuntimeS structure. Output: (1) Function F4 calculated and stored. (2) Return value. Return value: (1) Positive on success. (2) Negative on failure. Notes: (1) The function F4 may be modified and used for many purposes. Originally, it was introduced while searching for the method which will be suitable for prediction of the porin secondary structure. ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======calculate the hydrophobicity function F4:============================*/ int HyphobFunction4_ (double *min_functionP, double *max_functionP, RuntimeS *runtimeSP) { int residuesN, residueI; /* Do not use size_t instead of int ! */ int max_length; int count; int windowI, combinedI; char *residue_nameP; char residue_nameA[RESNAMESIZE]; double function_value; /*------prepare some parameters:---------------------------------------------*/ /* The number of residues in the sequence buffer: */ residuesN = (int) runtimeSP->residuesN; if (residuesN == 0) return -1; /* The maximal residue name length: */ max_length = RESNAMESIZE - 1; /*------calculate the function F4:-------------------------------------------*/ /* Initialize the extreme values: */ *min_functionP = +999999.0; *max_functionP = -999999.0; /* 20060608.1158: */ /* Scan the window of 7 residues. Count */ /* LEU, ILE, VAL, ALA, MET, PHE and TYR. */ /* Scan the sequence: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Reset the function value, it might be initialized before: */ *(runtimeSP->function4P + residueI) = 0.0; /* Reset the counter: */ count = 0; /* Scan the sliding window: */ for (windowI = -3; windowI <= 3; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI < 0) continue; if (combinedI >= residuesN) continue; /* Pointer to the residue name of */ /* the residue defined by combinedI: */ residue_nameP = runtimeSP->sequenceP + combinedI * max_length; /* Copy the residue name: */ strncpy (residue_nameA, residue_nameP, max_length); residue_nameA[max_length] = '\0'; /* Add +1 for selected hydrophobic residues: */ if ((strcmp (residue_nameA, "LEU") == 0) || (strcmp (residue_nameA, "ILE") == 0) || (strcmp (residue_nameA, "VAL") == 0) || (strcmp (residue_nameA, "MET") == 0) || (strcmp (residue_nameA, "ALA") == 0) || (strcmp (residue_nameA, "PHE") == 0) || (strcmp (residue_nameA, "TYR") == 0)) { count++; } } /* Scale and store the function value: */ function_value = 1.0 * (double) count; *(runtimeSP->function4P + residueI) = function_value; /* Find the extreme values: */ if (function_value < *min_functionP) *min_functionP = function_value; if (function_value > *max_functionP) *max_functionP = function_value; /* End of residueI loop: */ } /*---------------------------------------------------------------------------*/ return 1; } /*===========================================================================*/ garlic-1.6/hyphob_function5.c0000644000076500007650000001101710441773314016542 0ustar zuciczucic00000000000000/* Copyright (C) 2006 Damir Zucic */ /*============================================================================= hyphob_function5.c Purpose: Draw the hydrophobicity function F5. The sequence stored to the main sequence buffer is used to calculate the function value. Input: (1) Pointer to the storage where the minimal function value will be stored. (2) Pointer to the storage where the maximal function value will be stored. (3) Pointer to RuntimeS structure. Output: (1) Function F5 calculated and stored. (2) Return value. Return value: (1) Positive on success. (2) Negative on failure. Notes: (1) The function F5 may be modified and used for many purposes. Originally, it was introduced while searching for the method which will be suitable for prediction of the porin secondary structure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int HyphobFunction1_ (double *, double *, RuntimeS *); int HyphobFunction2_ (double *, double *, RuntimeS *); int HyphobFunction3_ (double *, double *, RuntimeS *); int HyphobFunction4_ (double *, double *, RuntimeS *); void InitHyphob_ (RuntimeS *); /*======calculate the hydrophobicity function F5:============================*/ int HyphobFunction5_ (double *f5minP, double *f5maxP, RuntimeS *runtimeSP) { int residuesN, residueI; /* Do not use size_t instead of int ! */ int max_length; char *residue_nameP; char residue_nameA[RESNAMESIZE]; double f1, f1min, f1max, f1before; double f2, f2min, f2max, f2before; double f3, f3min, f3max, f3before; double f4, f4min, f4max; double f5; int windowI, combinedI; double left_value, central_value, right_value; double weightA[5] = {1.00, 1.00, 1.00, 1.00, 1.00}; double average_value; /*------prepare some parameters:---------------------------------------------*/ /* The number of residues in the sequence buffer: */ residuesN = (int) runtimeSP->residuesN; if (residuesN == 0) return -1; /* The maximal residue name length: */ max_length = RESNAMESIZE - 1; /*------initialize (reset) F5:-----------------------------------------------*/ /* Initialize F5: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Reset the function F5, it might be initialized before: */ *(runtimeSP->function5P + residueI) = 0.0; } /*------calculate the function F1:-------------------------------------------*/ /* Calculate the function F1: */ HyphobFunction1_ (&f1min, &f1max, runtimeSP); /*------calculate the function F2:-------------------------------------------*/ /* Calculate the function F2: */ HyphobFunction2_ (&f2min, &f2max, runtimeSP); /*------calculate the function F3:-------------------------------------------*/ /* Calculate the function F3: */ HyphobFunction3_ (&f3min, &f3max, runtimeSP); /*------calculate the function F4:-------------------------------------------*/ /* Calculate the function F4: */ HyphobFunction4_ (&f4min, &f4max, runtimeSP); /*------calculate the function F5:-------------------------------------------*/ /* Initialize the extreme values: */ *f5minP = +999999.0; *f5maxP = -999999.0; /* Scan the sequence and calculate F5: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Prepare the pointer to the residue name: */ residue_nameP = runtimeSP->sequenceP + residueI * max_length; /* Copy the residue name: */ strncpy (residue_nameA, residue_nameP, max_length); residue_nameA[max_length] = '\0'; /* Initialize the function value: */ *(runtimeSP->function5P + residueI) = 0.0; /* Reset default F5 value: */ f5 = 0.0; /* 20060608.1205: */ /* Copy and use F1 and F3. */ f1 = *(runtimeSP->function1P + residueI); f3 = *(runtimeSP->function4P + residueI); f5 = f3 - f1; /* Scale and store the function value: */ *(runtimeSP->function5P + residueI) = 1.0 * f5; } /*------find the extreme values of F5:---------------------------------------*/ /* Find the extreme values of F5: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Find extreme values for F5: */ f5 = *(runtimeSP->function5P + residueI); if (f5 < *f5minP) *f5minP = f5; if (f5 > *f5maxP) *f5maxP = f5; } /*---------------------------------------------------------------------------*/ return 1; } /*===========================================================================*/ garlic-1.6/hyphob_function6.c0000644000076500007650000001561710441531753016554 0ustar zuciczucic00000000000000/* Copyright (C) 2006 Damir Zucic */ /*============================================================================= hyphob_function6.c Purpose: Draw the hydrophobicity function F6. The sequence stored to the main sequence buffer is used to calculate the function value. Input: (1) Pointer to the storage where the minimal function value will be stored. (2) Pointer to the storage where the maximal function value will be stored. (3) Pointer to RuntimeS structure. Output: (1) Function F6 calculated and stored. (2) Return value. Return value: (1) Positive on success. (2) Negative on failure. Notes: (1) The function F6 may be modified and used for many purposes. Originally, it was introduced while searching for the method which will be suitable for prediction of the porin secondary structure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int HyphobFunction1_ (double *, double *, RuntimeS *); int HyphobFunction2_ (double *, double *, RuntimeS *); int HyphobFunction3_ (double *, double *, RuntimeS *); int HyphobFunction4_ (double *, double *, RuntimeS *); void InitHyphob_ (RuntimeS *); /*======calculate the hydrophobicity function F6:============================*/ int HyphobFunction6_ (double *f6minP, double *f6maxP, RuntimeS *runtimeSP) { int residuesN, residueI; /* Do not use size_t instead of int ! */ int max_length; char *residue_nameP; char residue_nameA[RESNAMESIZE]; double f1, f1min, f1max, f1after; double f2, f2min, f2max, f2after; double f3, f3min, f3max, f3after; double f4, f4min, f4max; double f6; int windowI, combinedI; double left_value, central_value, right_value; double weightA[5] = {0.20, 0.40, 0.60, 0.80, 1.00}; double average_value; /*------prepare some parameters:---------------------------------------------*/ /* The number of residues in the sequence buffer: */ residuesN = (int) runtimeSP->residuesN; if (residuesN == 0) return -1; /* The maximal residue name length: */ max_length = RESNAMESIZE - 1; /*------initialize (reset) F6:-----------------------------------------------*/ /* Initialize F6: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Reset the function F6, it might be initialized before: */ *(runtimeSP->function6P + residueI) = 0.0; } /*------calculate the function F1:-------------------------------------------*/ /* Calculate the function F1: */ HyphobFunction1_ (&f1min, &f1max, runtimeSP); /*------calculate the function F2:-------------------------------------------*/ /* Calculate the function F2: */ HyphobFunction2_ (&f2min, &f2max, runtimeSP); /*------calculate the function F3:-------------------------------------------*/ /* Calculate the function F3: */ HyphobFunction3_ (&f3min, &f3max, runtimeSP); /*------calculate the function F4:-------------------------------------------*/ /* Calculate the function F4: */ HyphobFunction4_ (&f4min, &f4max, runtimeSP); /*------calculate the function F6:-------------------------------------------*/ /* Initialize the extreme values: */ *f6minP = +999999.0; *f6maxP = -999999.0; /* Scan the sequence and calculate F6: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Prepare the pointer to the residue name: */ residue_nameP = runtimeSP->sequenceP + residueI * max_length; /* Copy the residue name: */ strncpy (residue_nameA, residue_nameP, max_length); residue_nameA[max_length] = '\0'; /* Initialize the function value: */ *(runtimeSP->function6P + residueI) = 0.0; /* Skip 7 residues (a single transmembrane strand) at both edges: */ if ((residueI < 7) || (residueI > residuesN - 7)) continue; /* Reset default F6 value: */ f6 = 0.0; /* 20060607.1309: */ /* Copy and use the values of F1, F2, */ /* F3 and F4. Note the shifted indices! */ f1 = *(runtimeSP->function1P + residueI - 1); f1after = *(runtimeSP->function1P + residueI + 5); f2 = *(runtimeSP->function2P + residueI - 1); f2after = *(runtimeSP->function2P + residueI + 5); f3after = *(runtimeSP->function3P + residueI + 7); f3 = *(runtimeSP->function3P + residueI); f4 = *(runtimeSP->function4P + residueI); /* Apply the cryteria for nonzero peaks: */ if (f1 - 3.0 >= -0.001) { f6 = -1.0 * (f3after + f2 - f2after); if (f6 > 0.0) f6 = 0.0; } /* Scale and store the function value: */ *(runtimeSP->function6P + residueI) = 0.2 * f6; } /*------fill single-residue gaps in F6:--------------------------------------*/ /* Scan the sequence and check are there any positions where the value of */ /* F6 is zero, while it is different from zero at two adjacent positions. */ /* Fill such gaps, using the average value for two neighboring positions. */ for (residueI = 1; residueI < residuesN - 1; residueI++) { /* Prepare three values of F6: */ left_value = *(runtimeSP->function6P + residueI - 1); central_value = *(runtimeSP->function6P + residueI); right_value = *(runtimeSP->function6P + residueI + 1); /* Fill the gap in F6: */ if ((fabs (central_value) < 0.001) && (fabs (left_value) > 0.001) && (fabs (right_value) > 0.001)) { central_value = 0.5 * (left_value + right_value); *(runtimeSP->function6P + residueI) = central_value; } } /*------calculate the weighted average F6 value, over 5 residues:------------*/ /* Copy the old values into auxiliary buffer: */ for (residueI = 0; residueI < residuesN; residueI++) { *(runtimeSP->aux_doubleP + residueI) = *(runtimeSP->function6P + residueI); } /* Scan the sequence, omitting leading four residues: */ for (residueI = 4; residueI < residuesN; residueI++) { /* Reset the average value: */ average_value = 0.0; /* Scan the sliding window: */ for (windowI = 0; windowI < 5; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI - 4; if (combinedI < 0) continue; if (combinedI >= residuesN) continue; /* Copy the function value: */ f6 = *(runtimeSP->aux_doubleP + combinedI); /* Add the weighted function value to the average value: */ average_value += weightA[windowI] * f6; } /* Calculate and store the average value of F6: */ average_value /= 3.0; /* Divide by 3 */ *(runtimeSP->function6P + residueI) = average_value; } /*------find the extreme values of F6:---------------------------------------*/ /* Find the extreme values of F6: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Find extreme values for F6: */ f6 = *(runtimeSP->function6P + residueI); if (f6 < *f6minP) *f6minP = f6; if (f6 > *f6maxP) *f6maxP = f6; } /*---------------------------------------------------------------------------*/ return 1; } /*===========================================================================*/ garlic-1.6/hyphob_function7.c0000644000076500007650000001115210445772601016546 0ustar zuciczucic00000000000000/* Copyright (C) 2006 Damir Zucic */ /*============================================================================= hyphob_function7.c Purpose: Draw the hydrophobicity function F7. The sequence stored to the main sequence buffer is used to calculate the function value. Input: (1) Pointer to the storage where the minimal function value will be stored. (2) Pointer to the storage where the maximal function value will be stored. (3) Pointer to RuntimeS structure. Output: (1) Function F7 calculated and stored. (2) Return value. Return value: (1) Positive on success. (2) Negative on failure. Notes: (1) The function F7 may be modified and used for many purposes. Originally, it was introduced while searching for the method which will be suitable for prediction of the porin secondary structure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int HyphobFunction1_ (double *, double *, RuntimeS *); int HyphobFunction2_ (double *, double *, RuntimeS *); int HyphobFunction3_ (double *, double *, RuntimeS *); int HyphobFunction4_ (double *, double *, RuntimeS *); int HyphobFunction5_ (double *, double *, RuntimeS *); int HyphobFunction6_ (double *, double *, RuntimeS *); int HyphobFunction7_ (double *, double *, RuntimeS *); void InitHyphob_ (RuntimeS *); /*======calculate the hydrophobicity function F7:============================*/ int HyphobFunction7_ (double *f7minP, double *f7maxP, RuntimeS *runtimeSP) { int residuesN, residueI; /* Do not use size_t instead of int ! */ double f1, f1min, f1max; double f4, f4min, f4max; double f7; double average_value; int windowI, combinedI; double weightA[5] = {1.00, 1.00, 1.00, 1.00, 1.00}; /*------prepare some parameters:---------------------------------------------*/ /* The number of residues in the sequence buffer: */ residuesN = (int) runtimeSP->residuesN; if (residuesN == 0) return -1; /*------initialize (reset) F7:-----------------------------------------------*/ /* Initialize F7: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Reset the function F7, it might be initialized before: */ *(runtimeSP->function7P + residueI) = 0.0; } /*------calculate the function F1:-------------------------------------------*/ /* Calculate the function F1: */ HyphobFunction5_ (&f1min, &f1max, runtimeSP); /*------calculate the function F4:-------------------------------------------*/ /* Calculate the function F4: */ HyphobFunction6_ (&f4min, &f4max, runtimeSP); /*------calculate the function F7:-------------------------------------------*/ /* Initialize the extreme values: */ *f7minP = +999999.0; *f7maxP = -999999.0; /* Scan the sequence and calculate F7: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Initialize the function value: */ *(runtimeSP->function7P + residueI) = 0.0; /* 20060607.1258: */ /* F7[i] = F1[i] - F4[i] */ f1 = *(runtimeSP->function1P + residueI); f4 = *(runtimeSP->function4P + residueI); f7 = f1 - f4; /* Store the function value: */ *(runtimeSP->function7P + residueI) = f7; } /*------calculate the weighted average F7 value, over 5 residues:------------*/ #ifdef ALLDONE /*@@*/ for (residueI = 3; residueI < residuesN - 3; residueI++) { /* Reset the average value: */ average_value = 0.0; /* Scan the sliding window: */ for (windowI = 0; windowI < 5; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI - 2; if (combinedI < 0) continue; if (combinedI >= residuesN) continue; /* Copy the function value: */ f7 = *(runtimeSP->function7P + combinedI); /* Add the weighted function value to the average value: */ average_value += weightA[windowI] * f7; } /* Calculate and store the average value of F7: */ average_value /= 5.0; /* Divide by 5 */ *(runtimeSP->function7P + residueI) = average_value; } #endif /*@@*/ /*------find the extreme values of F7:---------------------------------------*/ /* Find the extreme values of F7: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Find extreme values for F7: */ f7 = *(runtimeSP->function7P + residueI); if (f7 < *f7minP) *f7minP = f7; if (f7 > *f7maxP) *f7maxP = f7; } /*---------------------------------------------------------------------------*/ return 1; } /*===========================================================================*/ garlic-1.6/extract_c.c0000644000076500007650000000346607315131137015241 0ustar zuciczucic00000000000000/* Copyright (C) 2001 Damir Zucic */ /*============================================================================= extract_c.c Purpose: Extract coordinates of the C atom for a given residue. Input: (1) Pointer to VectorS structure, where C coord. will be stored. (2) Pointer to AtomS structure, pointing to the first element of the atomic array. (3) Index of the first atom of a given residue. (4) Index of the last atom of a given residue. Output: (1) VectorS structure filled with data. (2) Return value. Return value: (1) The number of successfully extracted vectors (zero or one). Notes: (1) Some files contain more than one entry for some atoms. Garlic uses only the first entry and discards other entries for the same atom. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======extract C coordinates:===============================================*/ int ExtractC_ (VectorS *C_vectorSP, AtomS *atomSP, size_t atom_startI, size_t atom_endI) { int vectors_extractedN = 0; size_t atomI; AtomS *curr_atomSP; /* Scan the given residue: */ for (atomI = atom_startI; atomI <= atom_endI; atomI++) { /* Pointer to the current atom: */ curr_atomSP = atomSP + atomI; /* C: */ if (strcmp (curr_atomSP->raw_atomS.pure_atom_nameA, "C") == 0) { C_vectorSP->x = curr_atomSP->raw_atomS.x[0]; C_vectorSP->y = curr_atomSP->raw_atomS.y; C_vectorSP->z = curr_atomSP->raw_atomS.z[0]; vectors_extractedN++; break; } } /* Return the number of extracted vectors: */ return vectors_extractedN; } /*===========================================================================*/ garlic-1.6/extract_h.c0000644000076500007650000000346607315131443015246 0ustar zuciczucic00000000000000/* Copyright (C) 2001 Damir Zucic */ /*============================================================================= extract_c.c Purpose: Extract coordinates of the H atom for a given residue. Input: (1) Pointer to VectorS structure, where H coord. will be stored. (2) Pointer to AtomS structure, pointing to the first element of the atomic array. (3) Index of the first atom of a given residue. (4) Index of the last atom of a given residue. Output: (1) VectorS structure filled with data. (2) Return value. Return value: (1) The number of successfully extracted vectors (zero or one). Notes: (1) Some files contain more than one entry for some atoms. Garlic uses only the first entry and discards other entries for the same atom. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======extract H coordinates:===============================================*/ int ExtractH_ (VectorS *H_vectorSP, AtomS *atomSP, size_t atom_startI, size_t atom_endI) { int vectors_extractedN = 0; size_t atomI; AtomS *curr_atomSP; /* Scan the given residue: */ for (atomI = atom_startI; atomI <= atom_endI; atomI++) { /* Pointer to the current atom: */ curr_atomSP = atomSP + atomI; /* H: */ if (strcmp (curr_atomSP->raw_atomS.pure_atom_nameA, "H") == 0) { H_vectorSP->x = curr_atomSP->raw_atomS.x[0]; H_vectorSP->y = curr_atomSP->raw_atomS.y; H_vectorSP->z = curr_atomSP->raw_atomS.z[0]; vectors_extractedN++; break; } } /* Return the number of extracted vectors: */ return vectors_extractedN; } /*===========================================================================*/ garlic-1.6/extract_n.c0000644000076500007650000000346607315131176015257 0ustar zuciczucic00000000000000/* Copyright (C) 2001 Damir Zucic */ /*============================================================================= extract_n.c Purpose: Extract coordinates of the N atom for a given residue. Input: (1) Pointer to VectorS structure, where N coord. will be stored. (2) Pointer to AtomS structure, pointing to the first element of the atomic array. (3) Index of the first atom of a given residue. (4) Index of the last atom of a given residue. Output: (1) VectorS structure filled with data. (2) Return value. Return value: (1) The number of successfully extracted vectors (zero or one). Notes: (1) Some files contain more than one entry for some atoms. Garlic uses only the first entry and discards other entries for the same atom. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======extract N coordinates:===============================================*/ int ExtractN_ (VectorS *N_vectorSP, AtomS *atomSP, size_t atom_startI, size_t atom_endI) { int vectors_extractedN = 0; size_t atomI; AtomS *curr_atomSP; /* Scan the given residue: */ for (atomI = atom_startI; atomI <= atom_endI; atomI++) { /* Pointer to the current atom: */ curr_atomSP = atomSP + atomI; /* N: */ if (strcmp (curr_atomSP->raw_atomS.pure_atom_nameA, "N") == 0) { N_vectorSP->x = curr_atomSP->raw_atomS.x[0]; N_vectorSP->y = curr_atomSP->raw_atomS.y; N_vectorSP->z = curr_atomSP->raw_atomS.z[0]; vectors_extractedN++; break; } } /* Return the number of extracted vectors: */ return vectors_extractedN; } /*===========================================================================*/ garlic-1.6/extract_o.c0000644000076500007650000000346607315155227015263 0ustar zuciczucic00000000000000/* Copyright (C) 2001 Damir Zucic */ /*============================================================================= extract_o.c Purpose: Extract coordinates of the O atom for a given residue. Input: (1) Pointer to VectorS structure, where O coord. will be stored. (2) Pointer to AtomS structure, pointing to the first element of the atomic array. (3) Index of the first atom of a given residue. (4) Index of the last atom of a given residue. Output: (1) VectorS structure filled with data. (2) Return value. Return value: (1) The number of successfully extracted vectors (zero or one). Notes: (1) Some files contain more than one entry for some atoms. Garlic uses only the first entry and discards other entries for the same atom. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======extract O coordinates:===============================================*/ int ExtractO_ (VectorS *O_vectorSP, AtomS *atomSP, size_t atom_startI, size_t atom_endI) { int vectors_extractedN = 0; size_t atomI; AtomS *curr_atomSP; /* Scan the given residue: */ for (atomI = atom_startI; atomI <= atom_endI; atomI++) { /* Pointer to the current atom: */ curr_atomSP = atomSP + atomI; /* O: */ if (strcmp (curr_atomSP->raw_atomS.pure_atom_nameA, "O") == 0) { O_vectorSP->x = curr_atomSP->raw_atomS.x[0]; O_vectorSP->y = curr_atomSP->raw_atomS.y; O_vectorSP->z = curr_atomSP->raw_atomS.z[0]; vectors_extractedN++; break; } } /* Return the number of extracted vectors: */ return vectors_extractedN; } /*===========================================================================*/ garlic-1.6/plane_extent.c0000644000076500007650000001137507463437053015763 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= plane_extent.c Purpose: Find plane extent for the current image of the current plane. If drawing in stereo mode, there are two images of each plane. For mono mode, there is only one image. Input: (1) Pointer to minimal value of x, in screen units. (2) Pointer to maximal value of x, in screen units. (3) Pointer to minimal value of y, in screen units. (4) Pointer to maximal value of y, in screen units. (5) Pointer to PlaneS structure, with data about the current plane. (6) Pointer to ConfigS structure, with configuration data. (7) The current image index (0 or 1). Output: (1) Plane extent prepared (four integers). Return value: No return value. =============================================================================*/ #include #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======find plane extent:===================================================*/ void PlaneExtent_ (int *screen_x_minP, int *screen_x_maxP, int *screen_y_minP, int *screen_y_maxP, PlaneS *curr_planeSP, ConfigS *configSP, int curr_imageI) { int left_edge, right_edge; int center_screen_x, center_screen_y; double angle, sin_angle, cos_angle; double x1, y1, x2, y2, x3, y3, x4, y4; double x1rot, y1rot, x2rot, y2rot, x3rot, y3rot, x4rot, y4rot; double x_min, x_max, y_min, y_max; /* Left and right edge of the current image: */ left_edge = configSP->image_screen_x0[curr_imageI]; right_edge = configSP->image_screen_x1[curr_imageI]; /* Position of the window free area center: */ center_screen_x = curr_planeSP->center_screen_x[curr_imageI]; center_screen_y = curr_planeSP->center_screen_y; /* The shifted phi angle, used to rotate the "plane" bounding rectangle: */ angle = curr_planeSP->normal_phi[curr_imageI] - 4.712389; /* Sine and cosine of this angle: */ sin_angle = sin (angle); cos_angle = cos (angle); /* Four rectangle corners before rotation and translation: */ x1 = curr_planeSP->screen_a; y1 = curr_planeSP->screen_b[curr_imageI]; x2 = -curr_planeSP->screen_a; y2 = curr_planeSP->screen_b[curr_imageI]; x3 = -curr_planeSP->screen_a; y3 = -curr_planeSP->screen_b[curr_imageI]; x4 = curr_planeSP->screen_a; y4 = -curr_planeSP->screen_b[curr_imageI]; /* Four rectangle corners after rotation and translation: */ x1rot = x1 * cos_angle - y1 * sin_angle + center_screen_x; y1rot = x1 * sin_angle + y1 * cos_angle + center_screen_y; x2rot = x2 * cos_angle - y2 * sin_angle + center_screen_x; y2rot = x2 * sin_angle + y2 * cos_angle + center_screen_y; x3rot = x3 * cos_angle - y3 * sin_angle + center_screen_x; y3rot = x3 * sin_angle + y3 * cos_angle + center_screen_y; x4rot = x4 * cos_angle - y4 * sin_angle + center_screen_x; y4rot = x4 * sin_angle + y4 * cos_angle + center_screen_y; /* Find extreme values: */ x_min = x1rot; if (x2rot < x_min) x_min = x2rot; if (x3rot < x_min) x_min = x3rot; if (x4rot < x_min) x_min = x4rot; x_max = x1rot; if (x2rot > x_max) x_max = x2rot; if (x3rot > x_max) x_max = x3rot; if (x4rot > x_max) x_max = x4rot; y_min = y1rot; if (y2rot < y_min) y_min = y2rot; if (y3rot < y_min) y_min = y3rot; if (y4rot < y_min) y_min = y4rot; y_max = y1rot; if (y2rot > y_max) y_max = y2rot; if (y3rot > y_max) y_max = y3rot; if (y4rot > y_max) y_max = y4rot; /* Check extreme values: */ if (x_min < (double) left_edge) x_min = left_edge; if (x_min > (double) right_edge) x_min = right_edge; if (x_max < (double) left_edge) x_max = left_edge; if (x_max > (double) right_edge) x_max = right_edge; if (y_min < (double) configSP->image_screen_y0) y_min = configSP->image_screen_y0; if (y_min > (double) configSP->image_screen_y1) y_min = configSP->image_screen_y1; if (y_max < (double) configSP->image_screen_y0) y_max = configSP->image_screen_y0; if (y_max > (double) configSP->image_screen_y1) y_max = configSP->image_screen_y1; /* Extra check, to avoid overflow: */ if (x_min > (double) INT_MAX / 4) x_min = (double) INT_MAX / 4; if (x_min < (double) INT_MIN / 4) x_min = (double) INT_MIN / 4; if (x_max > (double) INT_MAX / 4) x_max = (double) INT_MAX / 4; if (x_max < (double) INT_MIN / 4) x_max = (double) INT_MIN / 4; if (y_min > (double) INT_MAX / 4) y_min = (double) INT_MAX / 4; if (y_min < (double) INT_MIN / 4) y_min = (double) INT_MIN / 4; if (y_max > (double) INT_MAX / 4) y_max = (double) INT_MAX / 4; if (y_max < (double) INT_MIN / 4) y_max = (double) INT_MIN / 4; /* Copy extreme values: */ *screen_x_minP = (int) x_min; *screen_x_maxP = (int) x_max; *screen_y_minP = (int) y_min; *screen_y_maxP = (int) y_max; } /*===========================================================================*/ garlic-1.6/ascorbic-acid.pdb0000644000076500007650000000264410364507375016301 0ustar zuciczucic00000000000000COMPND ASCORBIC ACID, VITAMIN C AUTHOR DAVE WOODCOCK 96 05 24 ATOM 1 C 1 0.182 0.119 -0.645 1.00 0.00 ATOM 2 C 1 0.591 -1.187 0.091 1.00 0.00 ATOM 3 C 1 1.908 -1.150 0.401 1.00 0.00 ATOM 4 C 1 2.407 0.104 0.031 1.00 0.00 ATOM 5 O 1 1.453 0.978 -0.535 1.00 0.00 ATOM 6 O 1 3.677 0.478 0.175 1.00 0.00 ATOM 7 O 1 2.621 -2.174 1.011 1.00 0.00 ATOM 8 O 1 -0.324 -2.236 0.293 1.00 0.00 ATOM 9 H 1 -0.030 -0.160 -1.688 1.00 0.00 ATOM 10 C 1 -1.084 0.762 0.207 1.00 0.00 ATOM 11 H 1 -1.959 0.100 0.315 1.00 0.00 ATOM 12 O 1 -0.591 1.195 1.590 1.00 0.00 ATOM 13 C 1 -1.585 2.076 -0.581 1.00 0.00 ATOM 14 O 1 -2.771 2.432 0.067 1.00 0.00 ATOM 15 H 1 1.946 -2.997 1.192 1.00 0.00 ATOM 16 H 1 -0.747 -2.497 -0.666 1.00 0.00 ATOM 17 H 1 0.118 2.004 1.470 1.00 0.00 ATOM 18 H 1 -1.839 1.784 -1.606 1.00 0.00 ATOM 19 H 1 -0.831 2.856 -0.721 1.00 0.00 ATOM 20 H 1 -2.572 2.906 1.016 1.00 0.00 TER 21 1 END garlic-1.6/count_residues.c0000644000076500007650000000441207105537163016316 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= count_residues.c Purpose: Count residues. Input: (1) Pointer to MolComplexS structure, with macromolecular data. Output: (1) Return value. Return value: (1) The number of residues (positive or zero). Notes: (1) The function which calls this function should check are there any atoms at all. Thus, there should be at least one atom. (2) Some hetero atoms may be counted as separate residues. This is typical for solvent molecules. ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======count residues:======================================================*/ size_t CountResidues_ (MolComplexS *mol_complexSP) { size_t residuesN = 0; size_t atomI, atomsN; RawAtomS *raw_atomSP; int previous_residueI = -9999, current_residueI; int previous_insertion_code = '\0', current_insertion_code; /* Prepare the number of atoms: */ atomsN = mol_complexSP->atomsN; /* Scan the macromolecular complex: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to raw atomic data: */ raw_atomSP = &(mol_complexSP->atomSP + atomI)->raw_atomS; /* Copy the residue sequence number and residue insertion code: */ current_residueI = raw_atomSP->residue_sequenceI; current_insertion_code = raw_atomSP->residue_insertion_code; /* Compare the current residue sequence number with the old one */ /* and the current residue insertion code with the old code: */ if ((current_residueI == previous_residueI) && (current_insertion_code == previous_insertion_code)) continue; /* If this point is reached, the current sequence number */ /* is different from the previous one, or insertion codes */ /* are different. This means that a new residue is found: */ residuesN++; /* Update the residue sequence index and residue insertion code: */ previous_residueI = current_residueI; previous_insertion_code = current_insertion_code; } /* Return the number of residues: */ return residuesN; } /*===========================================================================*/ garlic-1.6/singleatom.pdb0000644000076500007650000000012107646777213015755 0ustar zuciczucic00000000000000ATOM 1 N XXX 1 10.975 -2.428 6.735 1.00 27.59 1XXX 190 garlic-1.6/select_sphere.c0000644000076500007650000001132507647334206016115 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2003 Damir Zucic */ /*============================================================================= select_sphere.c Purpose: Select atoms inside the sphere defined by the sphere radius and the geometric center of current selection calculated for all selected atoms. Every caught macromolecular complex is taken into account. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. (3) Pointer to RuntimeS structure (sequence buffer is there). (4) Selection mode index (0 = overwrite, 1 = restrict, 2 = expand previous selection). Output: (1) The flag selectedF set to one for selected atoms in every caught macromolecular complex. (2) Return value. Return value: (1) The number of selected atoms (zero or positive value). ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======select sphere:=======================================================*/ long SelectSphere_ (MolComplexS *mol_complexSP, int mol_complexesN, RuntimeS *runtimeSP, int selection_modeI) { long selected_atomsN = 0; int mol_complexI; MolComplexS *curr_mol_complexSP; size_t atomsN, atomI; AtomS *curr_atomSP; double x = 0.0, y = 0.0, z = 0.0, denom; double center_x, center_y, center_z; double radius_squared; double delta_x, delta_y, delta_z, dist_squared; int sphereF; /* Calculate the geometric center position for currently selected atoms: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check is the current macromolecular complex caught: */ if (curr_mol_complexSP->catchF == 0) continue; /* Number of atoms in a macromolecular complex: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Scan all atoms in the current complex: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Check is this atom selected: */ if (curr_atomSP->selectedF == 0) continue; /* Update the number of selected atoms: */ selected_atomsN++; /* Prepare data required to find geometric center: */ x += curr_atomSP->raw_atomS.x[0]; y += curr_atomSP->raw_atomS.y; z += curr_atomSP->raw_atomS.z[0]; } } /* Check how many atoms are selected: */ if (selected_atomsN == 0) return (long) 0; /* Calculate the geometric center position: */ denom = 1.0 / (double) selected_atomsN; x *= denom; y *= denom; z *= denom; /* Update the geometric center position: */ center_x = x; center_y = y; center_z = z; /* Reset the number of selected atoms: */ selected_atomsN = 0; /* Prepare the squared radius: */ radius_squared = runtimeSP->sphere_radius * runtimeSP->sphere_radius; /* Select all atoms in a sphere: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check is the current macromolecular complex caught: */ if (curr_mol_complexSP->catchF == 0) continue; /* Number of atoms in a macromolecular complex: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Scan all atoms in the current complex: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Copy the coordinates: */ x = curr_atomSP->raw_atomS.x[0]; y = curr_atomSP->raw_atomS.y; z = curr_atomSP->raw_atomS.z[0]; /* The squared distance: */ delta_x = x - center_x; delta_y = y - center_y; delta_z = z - center_z; dist_squared = delta_x * delta_x + delta_y * delta_y + delta_z * delta_z; /* Compare the squared distance with the squared radius: */ sphereF = 1; if (dist_squared > radius_squared) sphereF = 0; /* Set the selection flag for the current atom: */ switch (selection_modeI) { /* Overwrite the previous selection: */ case 0: curr_atomSP->selectedF = sphereF; break; /* Restrict the previous selection: */ case 1: curr_atomSP->selectedF &= sphereF; break; /* Expand the previous selection: */ case 2: curr_atomSP->selectedF |= sphereF; break; default: ; } /* Check the selection flag; increase */ /* the count if flag is equal to one: */ if (curr_atomSP->selectedF) selected_atomsN++; } } /* Return the number of selected atoms: */ return selected_atomsN; } /*===========================================================================*/ garlic-1.6/init_membrane.c0000644000076500007650000001003407632076714016076 0ustar zuciczucic00000000000000/* Copyright (C) 2001-2003 Damir Zucic */ /*============================================================================= init_membrane.c Purpose: Initialize the membrane thickness and some other data required to draw two planes which are used to represent the membrane. It is done for all proteins, though makes sense only for membrane proteins. Input: (1) Pointer to MolComplexS structure, with macromolecular data. (2) Pointer to ConfigS structure, with configuration data. (3) Pointer to GUIS structure, with GUI data. Output: (1) Plane colors and some other data set for two planes which are used to represent the membrane. (2) Return value. Return value: (1) Positive always (trivial). ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int ParseColor_ (RGBS *, unsigned long *, GUIS *, char *, char *); /*======initialize some membrane data:=======================================*/ int InitializeMembrane_ (MolComplexS *mol_complexSP, ConfigS *configSP, GUIS *guiSP) { /* Initialize the membrane thickness: */ mol_complexSP->membraneS.thickness = MEMBRANE_THICKNESS; /* Initialize the membrane radius: */ mol_complexSP->membraneS.plane1S.circle_radius = 1.5 * MEMBRANE_THICKNESS; mol_complexSP->membraneS.plane2S.circle_radius = 1.5 * MEMBRANE_THICKNESS; /* Initialize the membrane transparency: */ mol_complexSP->membraneS.plane1S.transparency = DEFAULT_TRANSP; mol_complexSP->membraneS.plane2S.transparency = DEFAULT_TRANSP; /* There is a special flag used to hide or show the membrane, so */ /* the flags associated with individual planes are not required. */ mol_complexSP->membraneS.plane1S.hiddenF = 0; mol_complexSP->membraneS.plane2S.hiddenF = 0; /* Colors for the first (top) plane: */ /* Outer side near color for the first plane: */ ParseColor_ (&mol_complexSP->membraneS.plane1S.top_near_rgbS, &mol_complexSP->membraneS.plane1S.top_near_colorID, guiSP, "RGB:0000/8888/FFFF", "white"); /* Outer side far color for the first plane: */ ParseColor_ (&mol_complexSP->membraneS.plane1S.top_far_rgbS, &mol_complexSP->membraneS.plane1S.top_far_colorID, guiSP, "RGB:0000/2222/4444", "black"); /* Inner side near color for the first plane: */ ParseColor_ (&mol_complexSP->membraneS.plane1S.bottom_near_rgbS, &mol_complexSP->membraneS.plane1S.bottom_near_colorID, guiSP, "RGB:DDDD/8888/8888", "white"); /* Inner side far color for the first plane: */ ParseColor_ (&mol_complexSP->membraneS.plane1S.bottom_far_rgbS, &mol_complexSP->membraneS.plane1S.bottom_far_colorID, guiSP, "RGB:3333/2222/2222", "black"); /* Colors for the second (bottom) plane: */ /* Inner side near color for the second plane: */ ParseColor_ (&mol_complexSP->membraneS.plane2S.top_near_rgbS, &mol_complexSP->membraneS.plane2S.top_near_colorID, guiSP, "RGB:0000/8888/FFFF", "white"); /* Inner side far color for the second plane: */ ParseColor_ (&mol_complexSP->membraneS.plane2S.top_far_rgbS, &mol_complexSP->membraneS.plane2S.top_far_colorID, guiSP, "RGB:0000/2222/4444", "black"); /* Outer side near color for the second plane: */ ParseColor_ (&mol_complexSP->membraneS.plane2S.bottom_near_rgbS, &mol_complexSP->membraneS.plane2S.bottom_near_colorID, guiSP, "RGB:DDDD/8888/8888", "white"); /* Outer side far color for the second plane: */ ParseColor_ (&mol_complexSP->membraneS.plane2S.bottom_far_rgbS, &mol_complexSP->membraneS.plane2S.bottom_far_colorID, guiSP, "RGB:3333/2222/2222", "black"); /* Initialize transparencies: */ mol_complexSP->membraneS.plane1S.transparency = DEFAULT_TRANSP; mol_complexSP->membraneS.plane2S.transparency = DEFAULT_TRANSP; /* If this point is reached, return positive value (success indicator): */ return 1; } /*===========================================================================*/ garlic-1.6/warnmsg.c0000644000076500007650000000254507065475410014747 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= warnmsg.c Purpose: Print warning message. Input: (1) Program name. (2) Name of the function where something strange happened. (3) Name of the file which caused trouble, if file caused trouble. (4) \ (5) \ ... Warning message, split into four strings. (6) / Don't forget to put newline somewhere! (7) / Output: (1) Warning message written to stdout. Return value: No return value. ========includes:============================================================*/ #include #include /*======print warning message:===============================================*/ /* Note: there is no newline in the last four fprintf! */ void WarningMessage_ (char *module, char *function, char *filename, char *s1, char *s2, char *s3, char *s4) { fprintf (stdout, "WARNING>"); fprintf (stdout, " module: %s, function: %s", module, function); if (strlen (filename) != 0) fprintf (stdout, ", file: %s", filename); fprintf (stdout, "\n"); if (strlen (s1) != 0) fprintf (stdout, "%s", s1); if (strlen (s2) != 0) fprintf (stdout, "%s", s2); if (strlen (s3) != 0) fprintf (stdout, "%s", s3); if (strlen (s4) != 0) fprintf (stdout, "%s", s4); } /*===========================================================================*/ garlic-1.6/add_three_colors.c0000644000076500007650000000562507065455501016572 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= add_three_colors.c Purpose: Add (interpolate) three additional colors. Input: (1) The first input color. (2) The second input color. (3) Pointer to GUIS structure. (4) Pointer to the first output color. (5) Pointer to the second output color. (6) Pointer to the third output color. Output: (1) The first output color prepared. (2) The second output color prepared. (3) The third output color prepared. Return value: No return value. =============================================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======add (interpolate) three colors:======================================*/ void AddThreeColors_ (unsigned long input_color1ID, unsigned long input_color2ID, GUIS *guiSP, unsigned long *output_color1IDP, unsigned long *output_color2IDP, unsigned long *output_color3IDP) { unsigned long red_mask, green_mask, blue_mask; unsigned long red1, red2, red; unsigned long green1, green2, green; unsigned long blue1, blue2, blue; double r1, r2, g1, g2, b1, b2; static double w1 = 0.75, w2 = 0.25, w3 = 0.50; double r, g, b; /* Copy masks: */ red_mask = guiSP->visual_infoS.red_mask; green_mask = guiSP->visual_infoS.green_mask; blue_mask = guiSP->visual_infoS.blue_mask; /* Extract input color components: */ red1 = input_color1ID & red_mask; red2 = input_color2ID & red_mask; green1 = input_color1ID & green_mask; green2 = input_color2ID & green_mask; blue1 = input_color1ID & blue_mask; blue2 = input_color2ID & blue_mask; /* Convert to doubles: */ r1 = (double) red1; r2 = (double) red2; g1 = (double) green1; g2 = (double) green2; b1 = (double) blue1; b2 = (double) blue2; /* The first output color (components): */ r = w1 * r1 + w2 * r2; g = w1 * g1 + w2 * g2; b = w1 * b1 + w2 * b2; red = ((unsigned long) r) & red_mask; green = ((unsigned long) g) & green_mask; blue = ((unsigned long) b) & blue_mask; /* The first output color (value): */ *output_color1IDP = red | green | blue; /* The second output color (components): */ r = w3 * (r1 + r2); g = w3 * (g1 + g2); b = w3 * (b1 + b2); red = ((unsigned long) r) & red_mask; green = ((unsigned long) g) & green_mask; blue = ((unsigned long) b) & blue_mask; /* The second output color (value): */ *output_color2IDP = red | green | blue; /* The third output color (components): */ r = w2 * r1 + w1 * r2; g = w2 * g1 + w1 * g2; b = w2 * b1 + w1 * b2; red = ((unsigned long) r) & red_mask; green = ((unsigned long) g) & green_mask; blue = ((unsigned long) b) & blue_mask; /* The third output color (value): */ *output_color3IDP = red | green | blue; } /*===========================================================================*/ garlic-1.6/fading_shift.c0000644000076500007650000000552307272367453015724 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= fading_shift.c Purpose: Prepare the fading shift. By default, the normal fading shift is used (fading_shiftA[2] from ConfigS structure). See note 1 for all combinations of modifier keys. Input: (1) Pointer to ConfigS structure, with configuration data. (2) Pointer to GUIS structure, with GUI data. (3) The sign used to distinguish positive and negative shift. Output: (1) Return value. Return value: (1) Fading shift. Notes: (1) The following combinations of modifier keys may be used to select the fading shift: ------------------------------------------------------------- | modifiers fading shift ConfigS member | |-----------------------------------------------------------| | none normal (default) fading_stepA[2] | | shift large fading_stepA[3] | | alt+shift very large fading_stepA[4] | | control small fading_stepA[1] | | alt+control very small fading_stepA[0] | | control+shift normal fading_stepA[2] | | alt normal fading_stepA[2] | | alt+shift+control normal fading_stepA[2] | ------------------------------------------------------------- Note that some modifier combinations are ignored (alt alone, control+shift and alt+control+shift). ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======prepare fading shift:================================================*/ double FadingShift_ (ConfigS *configSP, GUIS *guiSP, double sign) { double fading_shift; int largeF, smallF, altF; /* Copy the flags: */ largeF = guiSP->shift_pressedF; smallF = guiSP->control_pressedF; altF = guiSP->alt_pressedF; /* Select the requested fading shift: */ if (altF) { if (largeF && !smallF) { fading_shift = configSP->fading_stepA[4]; } else if (smallF && !largeF) { fading_shift = configSP->fading_stepA[0]; } else { fading_shift = configSP->fading_stepA[2]; } } else { if (largeF && !smallF) { fading_shift = configSP->fading_stepA[3]; } else if (smallF && !largeF) { fading_shift = configSP->fading_stepA[1]; } else if (smallF && largeF) { fading_shift = configSP->fading_stepA[0]; } else { fading_shift = configSP->fading_stepA[2]; } } /* Take care for the sign: */ fading_shift *= sign; /* Return the fading shift: */ return fading_shift; } /*===========================================================================*/ garlic-1.6/read_file.c0000644000076500007650000000415707261652607015207 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= read_file.c Purpose: Try to recognize input file format; read file if recognized. In fact, this function does almost nothing: file format is recognized by RecogFileFormat_ and ReadPDBFile_ reads PDB file. Input: (1) Pointer to MolComplexS structure (macromolecular complexes). It should point to the first free MolComplexS structure. (2) Input file name (pointer). (3) Pointer to ConfigS structure, with configuration data. Output: (1) If PDB file is recognized, a function which read atomic data is called. (2) Return value. Return value: (1) Positive on success. (2) Zero if there is nothing to read (strlen (file_nameP) is zero). (3) Negative on failure. ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int RecogFileFormat_ (char *); int ReadPDBFile_ (MolComplexS *, char *, ConfigS *); void ErrorMessage_ (char *, char *, char *, char *, char *, char *, char *); /*======recognize file format, read file:====================================*/ int ReadFile_ (MolComplexS *mol_complexSP, char *file_nameP, ConfigS *configSP) { int file_format; /* Is file name specified at all? */ if (strlen (file_nameP) == 0) return 0; /* Try to recognize file format: */ file_format = RecogFileFormat_ (file_nameP); if (file_format < 0) return -1; /* Read file (switch could be used here, but I don't like it): */ if (file_format == PDB_FORMAT) { if (ReadPDBFile_ (mol_complexSP, file_nameP, configSP) < 0) return -2; else return 1; } /* If this point is reached, format is recognized, but file is not read: */ ErrorMessage_ ("garlic", "ReadFile_", file_nameP, "Unable to read file - file format not supported!\n", "", "", ""); return -3; } /*===========================================================================*/ garlic-1.6/init_buttons.c0000644000076500007650000001132407071121400015765 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= init_buttons.c Purpose: Initialize dummy buttons in control window, i.e. define edge coordinates for all windows. Input: (1) Pointer to ButtonS structure. Output: (1) ButtonS array of structures initialized. (2) Return value. Return value: (1) Positive always (trivial). Notes: (1) Indices are assigned as follows: 0 = KP_0 1 = KP_1 2 = KP_2 3 = KP_3 4 = KP_4 5 = KP_5 6 = KP_6 7 = KP_7 8 = KP_8 9 = KP_9 10 = KP_Decimal 11 = KP_Enter 12 = KP_Add 13 = KP_Subtract 14 = KP_Multiply 15 = KP_Divide 16 = F1 17 = F2 18 = F3 19 = F4 ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======initialize dummy buttons:============================================*/ int InitializeButtons_ (ButtonS *buttonSP) { ButtonS *curr_buttonSP; /* [0] KP_Zero: */ curr_buttonSP = buttonSP; curr_buttonSP->left_edge = 3; curr_buttonSP->top_edge = 162; curr_buttonSP->right_edge = 65; curr_buttonSP->bottom_edge = 192; /* [1] KP_1: */ curr_buttonSP = buttonSP + 1; curr_buttonSP->left_edge = 3; curr_buttonSP->top_edge = 130; curr_buttonSP->right_edge = 33; curr_buttonSP->bottom_edge = 160; /* [2] KP_2: */ curr_buttonSP = buttonSP + 2; curr_buttonSP->left_edge = 35; curr_buttonSP->top_edge = 130; curr_buttonSP->right_edge = 65; curr_buttonSP->bottom_edge = 160; /* [3] KP_3: */ curr_buttonSP = buttonSP + 3; curr_buttonSP->left_edge = 67; curr_buttonSP->top_edge = 130; curr_buttonSP->right_edge = 97; curr_buttonSP->bottom_edge = 160; /* [4] KP_4: */ curr_buttonSP = buttonSP + 4; curr_buttonSP->left_edge = 3; curr_buttonSP->top_edge = 98; curr_buttonSP->right_edge = 33; curr_buttonSP->bottom_edge = 128; /* [5] KP_5: */ curr_buttonSP = buttonSP + 5; curr_buttonSP->left_edge = 35; curr_buttonSP->top_edge = 98; curr_buttonSP->right_edge = 65; curr_buttonSP->bottom_edge = 128; /* [6] KP_6: */ curr_buttonSP = buttonSP + 6; curr_buttonSP->left_edge = 67; curr_buttonSP->top_edge = 98; curr_buttonSP->right_edge = 97; curr_buttonSP->bottom_edge = 128; /* [7] KP_7: */ curr_buttonSP = buttonSP + 7; curr_buttonSP->left_edge = 3; curr_buttonSP->top_edge = 66; curr_buttonSP->right_edge = 33; curr_buttonSP->bottom_edge = 96; /* [8] KP_8: */ curr_buttonSP = buttonSP + 8; curr_buttonSP->left_edge = 35; curr_buttonSP->top_edge = 66; curr_buttonSP->right_edge = 65; curr_buttonSP->bottom_edge = 96; /* [9] KP_9: */ curr_buttonSP = buttonSP + 9; curr_buttonSP->left_edge = 67; curr_buttonSP->top_edge = 66; curr_buttonSP->right_edge = 97; curr_buttonSP->bottom_edge = 96; /* [10] KP_Decimal: */ curr_buttonSP = buttonSP + 10; curr_buttonSP->left_edge = 67; curr_buttonSP->top_edge = 162; curr_buttonSP->right_edge = 97; curr_buttonSP->bottom_edge = 192; /* [11] KP_Enter: */ curr_buttonSP = buttonSP + 11; curr_buttonSP->left_edge = 99; curr_buttonSP->top_edge = 130; curr_buttonSP->right_edge = 129; curr_buttonSP->bottom_edge = 192; /* [12] KP_Add: */ curr_buttonSP = buttonSP + 12; curr_buttonSP->left_edge = 99; curr_buttonSP->top_edge = 66; curr_buttonSP->right_edge = 129; curr_buttonSP->bottom_edge = 128; /* [13] KP_Subtract: */ curr_buttonSP = buttonSP + 13; curr_buttonSP->left_edge = 99; curr_buttonSP->top_edge = 34; curr_buttonSP->right_edge = 129; curr_buttonSP->bottom_edge = 64; /* [14] KP_Multiply: */ curr_buttonSP = buttonSP + 14; curr_buttonSP->left_edge = 67; curr_buttonSP->top_edge = 34; curr_buttonSP->right_edge = 97; curr_buttonSP->bottom_edge = 64; /* [15] KP_Divide: */ curr_buttonSP = buttonSP + 15; curr_buttonSP->left_edge = 35; curr_buttonSP->top_edge = 34; curr_buttonSP->right_edge = 65; curr_buttonSP->bottom_edge = 64; /* [16] F1: */ curr_buttonSP = buttonSP + 16; curr_buttonSP->left_edge = 3; curr_buttonSP->top_edge = 288; curr_buttonSP->right_edge = 33; curr_buttonSP->bottom_edge = 326; /* [17] F2: */ curr_buttonSP = buttonSP + 17; curr_buttonSP->left_edge = 35; curr_buttonSP->top_edge = 288; curr_buttonSP->right_edge = 65; curr_buttonSP->bottom_edge = 326; /* [18] F3: */ curr_buttonSP = buttonSP + 18; curr_buttonSP->left_edge = 67; curr_buttonSP->top_edge = 288; curr_buttonSP->right_edge = 97; curr_buttonSP->bottom_edge = 326; /* [19] F4: */ curr_buttonSP = buttonSP + 19; curr_buttonSP->left_edge = 99; curr_buttonSP->top_edge = 288; curr_buttonSP->right_edge = 129; curr_buttonSP->bottom_edge = 326; /* Return positive value (trivial): */ return 1; } /*===========================================================================*/ garlic-1.6/center.c0000644000076500007650000001205110414504050014523 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2006 Damir Zucic */ /*============================================================================= center.c Purpose: Execute center command: calculate the geometric center position for currently selected atoms and use this position as a new origin of the internal coordinate system. Only one macromol. complex should be caught, otherwise this function will fail to work. Input: (1) Pointer to MolComplexS structure. (2) The number of macromolecular complexes. (3) Pointer to RuntimeS structure. (4) Pointer to ConfigS structure. (5) Pointer to GUIS structure. (6) Pointer to NearestAtomS structure. (7) The number of pixels in the main window free area. (8) Pointer to refreshI. Output: (1) (2) Return value. Return value: (1) Positive (command) code on success. (2) Negative (error) code on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "commands.h" #include "typedefs.h" /*======function prototypes:=================================================*/ size_t MainRefresh_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); int ControlRefresh_ (MolComplexS *, ConfigS *, GUIS *); /*======execute center command:==============================================*/ int Center_ (MolComplexS *mol_complexSP, int mol_complexesN, RuntimeS *runtimeSP, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int *refreshIP) { int mol_complexI; int caught_complexesN = 0; MolComplexS *curr_mol_complexSP; size_t atomsN, atomI; AtomS *curr_atomSP; size_t selected_atomsN = 0; double x = 0.0, y = 0.0, z = 0.0, denom; /* Count the number of currently caught macromolecular complexes: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { if ((mol_complexSP + mol_complexI)->catchF == 1) caught_complexesN++; } /* Check the number of cought complexes (must be equal to one): */ if (caught_complexesN != 1) { strcpy (runtimeSP->messageA, "One (and only one) complex should be caught!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_CENTER; } /* Find the cought complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /** Pointer to the current macromolecular complex: **/ curr_mol_complexSP = mol_complexSP + mol_complexI; /** Check is the current macromolecular complex caught: **/ if (curr_mol_complexSP->catchF == 0) continue; /** Number of atoms in a macromolecular complex: **/ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) { strcpy (runtimeSP->messageA, "There are no atoms in this macromol. complex!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_CENTER; } /** Scan all atoms in the current complex: **/ for (atomI = 0; atomI < atomsN; atomI++) { /*** Pointer to the current atom: ***/ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /*** Check is this atom selected: ***/ if (curr_atomSP->selectedF == 0) continue; /*** Update the number of selected atoms: ***/ selected_atomsN++; /*** Prepare data required to find geometric center: ***/ x += curr_atomSP->raw_atomS.x[0]; y += curr_atomSP->raw_atomS.y; z += curr_atomSP->raw_atomS.z[0]; } /** Check how many atoms are selected: **/ if (selected_atomsN == 0) { sprintf (runtimeSP->messageA, "There are no selected atoms!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_CENTER; } /** Calculate the geometric center position: **/ denom = 1.0 / (double) selected_atomsN; x *= denom; y *= denom; z *= denom; /** Update the geometric center position: **/ curr_mol_complexSP->geometric_center_vectorS.x = x; curr_mol_complexSP->geometric_center_vectorS.y = y; curr_mol_complexSP->geometric_center_vectorS.z = z; /** Update the rotation center position: **/ curr_mol_complexSP->rotation_center_vectorS.x = x; curr_mol_complexSP->rotation_center_vectorS.y = y; curr_mol_complexSP->rotation_center_vectorS.z = z; /** Update the slab center: **/ curr_mol_complexSP->slab_center_vectorS.x = x; curr_mol_complexSP->slab_center_vectorS.y = y; curr_mol_complexSP->slab_center_vectorS.z = z; /** Update the color fading center: **/ curr_mol_complexSP->fading_center_vectorS.x = x; curr_mol_complexSP->fading_center_vectorS.y = y; curr_mol_complexSP->fading_center_vectorS.z = z; /* Update the position_changedF: */ curr_mol_complexSP->position_changedF = 1; } /* Refresh the main window: */ (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); /* Refresh the control window: */ ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); /* Return the command code: */ return COMMAND_CENTER; } /*===========================================================================*/ garlic-1.6/interpolate_color.c0000644000076500007650000000372407065471701017014 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= interpolate_color.c Purpose: Interpolate (calculate) additional color, using two old colors. Input: (1) The first input color. (2) The second input color. (3) Pointer to GUIS structure. Output: (1) Return value. Return value: The pixel value calculated. =============================================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======interpolate color:===================================================*/ unsigned long InterpolateColor_ (unsigned long color1ID, unsigned long color2ID, GUIS *guiSP) { unsigned long colorID; unsigned long red_mask, green_mask, blue_mask; unsigned long red1, red2, red; unsigned long green1, green2, green; unsigned long blue1, blue2, blue; double r1, r2, g1, g2, b1, b2; double w = 0.5; double r, g, b; /* Copy masks: */ red_mask = guiSP->visual_infoS.red_mask; green_mask = guiSP->visual_infoS.green_mask; blue_mask = guiSP->visual_infoS.blue_mask; /* Extract input color components: */ red1 = color1ID & red_mask; red2 = color2ID & red_mask; green1 = color1ID & green_mask; green2 = color2ID & green_mask; blue1 = color1ID & blue_mask; blue2 = color2ID & blue_mask; /* Convert to doubles: */ r1 = (double) red1; r2 = (double) red2; g1 = (double) green1; g2 = (double) green2; b1 = (double) blue1; b2 = (double) blue2; /* Calculate new color components: */ r = w * (r1 + r2); g = w * (g1 + g2); b = w * (b1 + b2); red = ((unsigned long) r) & red_mask; green = ((unsigned long) g) & green_mask; blue = ((unsigned long) b) & blue_mask; /* Combine new color components: */ colorID = red | green | blue; /* Return the pixel value: */ return colorID; } /*===========================================================================*/ garlic-1.6/color.c0000644000076500007650000000747007573504735014420 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2002 Damir Zucic */ /*============================================================================= color.c Purpose: Execute color command: assign the requested color scheme to all currently selected atoms in each caught complex. This command may not be used to change the surface colors. The only value of the mode index (the last argument to ColorSchemes_) allowed in this function is zero. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) The number of macromolecular complexes. (3) Pointer to RuntimeS structure, with some runtime data. (4) Pointer to ConfigS structure, with configuration data. (5) Pointer to GUIS structure, with GUI data. (6) Pointer to NearestAtomS structure. (7) The number of pixels in the main window free area. (8) Pointer to refreshI. (9) String which contains the color scheme name. Output: (1) Atomic colors changed. (2) Return value. Return value: (1) Positive (command) code on success. (2) Negative (error) code on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "commands.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int FullColors_ (MolComplexS *, int, GUIS *, char *); char *ExtractToken_ (char *, int, char *, char *); int ColorSchemes_ (MolComplexS *, int, ConfigS *, GUIS *, char *, int); size_t MainRefresh_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); int ControlRefresh_ (MolComplexS *, ConfigS *, GUIS *); /*======execute color command:===============================================*/ int Color_ (MolComplexS *mol_complexSP, int mol_complexesN, RuntimeS *runtimeSP, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int *refreshIP, char *stringP) { char *commandP; char *remainderP; char tokenA[STRINGSIZE]; int n; /* Try to interpret the string as the full color */ /* specification. Use the original command string: */ commandP = runtimeSP->curr_commandA; if (FullColors_ (mol_complexSP, mol_complexesN, guiSP, commandP) > 0) { (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); return COMMAND_COLOR; } /* Extract the color scheme name: */ remainderP = ExtractToken_ (tokenA, STRINGSIZE, stringP, " \t\n"); if (!remainderP) { strcpy (runtimeSP->messageA, "Color scheme specification missing!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_NO_SCHEME; } /* Assign the requested predefined colors to all selected atoms. */ /* The mode index (the last ColorSchemes_ argument) should be set */ /* to zero, to define the atomic colors, not the surface colors. */ /** If some simple color scheme is requested: **/ n = ColorSchemes_ (mol_complexSP, mol_complexesN, configSP, guiSP, tokenA, 0); /** If scheme is not recognized: **/ if (n <= 0) { sprintf (runtimeSP->messageA, "Color scheme %s is not available!", tokenA); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_BAD_SCHEME; } /* Refresh the main window: */ (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); /* Refresh the control window: */ ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); /* Return positive value on success: */ return COMMAND_COLOR; } /*===========================================================================*/ garlic-1.6/special_select.c0000644000076500007650000004560210424410224016232 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2006 Damir Zucic */ /*============================================================================= special_select.c Purpose: Execute select command (the special version): try to interpret the selection string as the special keyword. Three selections modes are available: 0 = overwrite, 1 = restrict, 2 = expand previous selection. Special keywords are: ALL, *, POLAR, HYDROPHOBIC, AROMATIC, ALIPHATIC, SMALL, TINY, POSITIVE, NEGATIVE, BASIC, ACIDIC, CHARGED, MAIN_CHAIN, SIDE_CHAINS, HETERO, CIS, TRANS, BAD, COMPLEMENT, SEQUENCE, SPHERE, ALTERNATE, MODEL, ABOVE, BELOW, TRIPLET, TM, PATTERN, 2C3, 2CZ3, 2NZ3, 3C4, 3CZ4, 3NZ4, 3C5, 3CZ5, 3NZ5, 3P5, 4C5, 4CZ5, 4NZ5, 3C6, 3CZ6, 3NZ6, 4C6, 4CZ6, 4NZ6, 4P6, 5C6, 5CZ6, 5NZ6, 4C7, 4CZ7, 4NZ7, 5C7, 5CZ7, 5NZ7, 5P7, 6P7, 4C9, 4CZ9, 4NZ9, 5C9, 5CZ9, 5NZ9 and $1. Most keywords may be abbrev. to 3 characters. The exceptions are keywords HYDROPHOBIC (it may be replaced by PHO or shortened to HYDROPHO), 2CZ3, 2NZ3, 3CZ4, 3NZ4, 3CZ5, 3NZ5, 4CZ5, 4NZ5, 3CZ6, 3NZ6, 4CZ6, 4NZ6, 5CZ6, 5NZ6, 4CZ7, 4NZ7, 5CZ7, 5NZ7, 4CZ9, 5CZ9 and 5NZ9. The keyword $1 is a special selection keyword (not implemented yet, @@). Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. (3) Pointer to RuntimeS structure (the sequence buffer is there). (4) The selection string. (5) Selection mode index (0 = overwr., 1 = restrict, 2 = expand). Output: (1) The flag selectedF will be equal to one for selected atoms and equal to zero for all other atoms. (2) Return value. Return value: (1) The number of selected atoms, if selection is done in this function. (2) -1 if selection string is not suitable for this function. (3) Some other negative value on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ char *ExtractToken_ (char *, int, char *, char *); int ExtractIndex_ (char *); long SelectHetero_ (MolComplexS *, int, int); long SelectCisTrans_ (MolComplexS *, int, int, int); long SelectComplement_ (MolComplexS *, int, int); long SelectSequence_ (MolComplexS *, int, RuntimeS *, int); long SelectSphere_ (MolComplexS *, int, RuntimeS *, int); long SelectAlternate_ (MolComplexS *, int, int); long SelectModel_ (MolComplexS *, int, int, int); long SelectAbove_ (MolComplexS *, int, int); long SelectBelow_ (MolComplexS *, int, int); long SelectTriplet_ (MolComplexS *, int, int); long SelectTM_ (MolComplexS *, int, int); long SelectPattern_ (MolComplexS *, int, RuntimeS *, int); long Select2C3_ (MolComplexS *, int, int); long Select2CZ3_ (MolComplexS *, int, int); long Select2NZ3_ (MolComplexS *, int, int); long Select3C4_ (MolComplexS *, int, int); long Select3CZ4_ (MolComplexS *, int, int); long Select3NZ4_ (MolComplexS *, int, int); long Select3C5_ (MolComplexS *, int, int); long Select3CZ5_ (MolComplexS *, int, int); long Select3NZ5_ (MolComplexS *, int, int); long Select3P5_ (MolComplexS *, int, int); long Select4C5_ (MolComplexS *, int, int); long Select4CZ5_ (MolComplexS *, int, int); long Select4NZ5_ (MolComplexS *, int, int); long Select3C6_ (MolComplexS *, int, int); long Select3CZ6_ (MolComplexS *, int, int); long Select3NZ6_ (MolComplexS *, int, int); long Select4C6_ (MolComplexS *, int, int); long Select4CZ6_ (MolComplexS *, int, int); long Select4NZ6_ (MolComplexS *, int, int); long Select4P6_ (MolComplexS *, int, int); long Select5C6_ (MolComplexS *, int, int); long Select5CZ6_ (MolComplexS *, int, int); long Select5NZ6_ (MolComplexS *, int, int); long Select4C7_ (MolComplexS *, int, int); long Select4CZ7_ (MolComplexS *, int, int); long Select4NZ7_ (MolComplexS *, int, int); long Select5C7_ (MolComplexS *, int, int); long Select5CZ7_ (MolComplexS *, int, int); long Select5NZ7_ (MolComplexS *, int, int); long Select5P7_ (MolComplexS *, int, int); long Select6P7_ (MolComplexS *, int, int); long Select4C9_ (MolComplexS *, int, int); long Select4CZ9_ (MolComplexS *, int, int); long Select4NZ9_ (MolComplexS *, int, int); long Select5C9_ (MolComplexS *, int, int); long Select5CZ9_ (MolComplexS *, int, int); long Select5NZ9_ (MolComplexS *, int, int); int Include_ (SelectS *, char *); int Exclude_ (SelectS *, char *); long ApplySelection_ (MolComplexS *, int, SelectS *, SelectS *, int); /*======execute select command (special selection string):===================*/ long SpecialSelect_ (MolComplexS *mol_complexSP, int mol_complexesN, RuntimeS *runtimeSP, char *stringP, int selection_modeI) { long selected_atomsN; char tokenA[STRINGSIZE]; char full_stringA[STRINGSIZE]; char *P; int n; int slashesN = 0; SelectS include_selectS, exclude_selectS; int model_serialI; /* Purify the selection string (remove the leading and trailing separators): */ if (!ExtractToken_ (tokenA, STRINGSIZE, stringP, " ,;\t\n")) return (long) -1; /* Check the selection string: */ /** ALL: **/ if ((strstr (tokenA, "ALL") == tokenA) || (strstr (tokenA, "*") == tokenA)) strcpy (full_stringA, "*/*/*/*"); /** POLAR: **/ else if (strstr (tokenA, "POL") == tokenA) strcpy (full_stringA, "*/*/ARG,LYS,HIS,ASP,GLU,ASN,GLN,SER,THR,TRP,TYR/*"); /** HYDROPHOBIC: **/ else if ((strstr (tokenA, "HYDROPHO") == tokenA) || (strstr (tokenA, "PHO") == tokenA)) strcpy (full_stringA, "*/*/ALA,ILE,LEU,MET,PHE,TRP,VAL,TYR,CYS,GLY,HIS/*"); /** AROMATIC: **/ else if (strstr (tokenA, "ARO") == tokenA) strcpy (full_stringA, "*/*/PHE,TYR,TRP,HIS/*"); /** ALIPHATIC: **/ else if (strstr (tokenA, "ALI") == tokenA) strcpy (full_stringA, "*/*/ILE,LEU,VAL/*"); /** SMALL: **/ else if (strstr (tokenA, "SMA") == tokenA) strcpy (full_stringA, "*/*/GLY,ALA,SER,THR,CYS,VAL,PRO,ASP,ASN/*"); /** TINY: **/ else if (strstr (tokenA, "TIN") == tokenA) strcpy (full_stringA, "*/*/GLY,ALA,SER/*"); /** POSITIVE: **/ else if (strstr (tokenA, "POS") == tokenA) strcpy (full_stringA, "*/*/ARG,LYS,HIS/*"); /** NEGATIVE: **/ else if (strstr (tokenA, "NEG") == tokenA) strcpy (full_stringA, "*/*/GLU,ASP/*"); /** BASIC: **/ else if (strstr (tokenA, "BAS") == tokenA) strcpy (full_stringA, "*/*/ARG,LYS,HIS/*"); /** ACIDIC: **/ else if (strstr (tokenA, "ACI") == tokenA) strcpy (full_stringA, "*/*/GLU,ASP/*"); /** CHARGED: **/ else if (strstr (tokenA, "CHA") == tokenA) strcpy (full_stringA, "*/*/ARG,LYS,HIS,GLU,ASP/*"); /** MAIN_CHAIN: **/ else if (strstr (tokenA, "MAI") == tokenA) strcpy (full_stringA, "*/*/*/CA,C,N,O,H"); /** SIDE_CHAINS: **/ else if (strstr (tokenA, "SID") == tokenA) strcpy (full_stringA, "*/*/*/* EXCEPT CA,C,N,O,H"); /** HETERO: **/ else if (strstr (tokenA, "HET") == tokenA) { selected_atomsN = SelectHetero_ (mol_complexSP, mol_complexesN, selection_modeI); return selected_atomsN; } /** CIS: **/ else if (strstr (tokenA, "CIS") == tokenA) { selected_atomsN = SelectCisTrans_ (mol_complexSP, mol_complexesN, selection_modeI, 2); return selected_atomsN; } /** TRANS: **/ else if (strstr (tokenA, "TRA") == tokenA) { selected_atomsN = SelectCisTrans_ (mol_complexSP, mol_complexesN, selection_modeI, 1); return selected_atomsN; } /** BAD: **/ else if (strstr (tokenA, "BAD") == tokenA) { selected_atomsN = SelectCisTrans_ (mol_complexSP, mol_complexesN, selection_modeI, 0); return selected_atomsN; } /** COMPLEMENT: **/ else if (strstr (tokenA, "COM") == tokenA) { selected_atomsN = SelectComplement_ (mol_complexSP, mol_complexesN, selection_modeI); return selected_atomsN; } /** SEQUENCE: **/ else if (strstr (tokenA, "SEQ") == tokenA) { selected_atomsN = SelectSequence_ (mol_complexSP, mol_complexesN, runtimeSP, selection_modeI); return selected_atomsN; } /** SPHERE: **/ else if (strstr (tokenA, "SPH") == tokenA) { selected_atomsN = SelectSphere_ (mol_complexSP, mol_complexesN, runtimeSP, selection_modeI); return selected_atomsN; } /** ALTERNATE: **/ else if (strstr (tokenA, "ALT") == tokenA) { selected_atomsN = SelectAlternate_ (mol_complexSP, mol_complexesN, selection_modeI); return selected_atomsN; } /** MODEL: **/ else if (strstr (tokenA, "MOD") == tokenA) { model_serialI = ExtractIndex_ (stringP); selected_atomsN = SelectModel_ (mol_complexSP, mol_complexesN, selection_modeI, model_serialI); return selected_atomsN; } /** ABOVE: **/ else if (strstr (tokenA, "ABO") == tokenA) { selected_atomsN = SelectAbove_ (mol_complexSP, mol_complexesN, selection_modeI); return selected_atomsN; } /** BELOW: **/ else if (strstr (tokenA, "BEL") == tokenA) { selected_atomsN = SelectBelow_ (mol_complexSP, mol_complexesN, selection_modeI); return selected_atomsN; } /** TRIPLET: **/ else if (strstr (tokenA, "TRI") == tokenA) { selected_atomsN = SelectTriplet_ (mol_complexSP, mol_complexesN, selection_modeI); return selected_atomsN; } /** TM (transmembrane part): **/ else if (strstr (tokenA, "TM") == tokenA) { selected_atomsN = SelectTM_ (mol_complexSP, mol_complexesN, selection_modeI); return selected_atomsN; } /** PATTERN (sequence pattern): **/ else if (strstr (tokenA, "PAT") == tokenA) { selected_atomsN = SelectPattern_ (mol_complexSP, mol_complexesN, runtimeSP, selection_modeI); return selected_atomsN; } /** 2C3 (two or more charged in a fragment of three residues): **/ else if (strstr (tokenA, "2C3") == tokenA) { selected_atomsN = Select2C3_ (mol_complexSP, mol_complexesN, selection_modeI); return selected_atomsN; } /** 2CZ3 (two or more charged or zwitterionic in a fragment of three): **/ else if (strstr (tokenA, "2CZ3") == tokenA) { selected_atomsN = Select2CZ3_ (mol_complexSP, mol_complexesN, selection_modeI); return selected_atomsN; } /** 2NZ3 (two or more negative or zwitterionic in a fragment of three): **/ else if (strstr (tokenA, "2NZ3") == tokenA) { selected_atomsN = Select2NZ3_ (mol_complexSP, mol_complexesN, selection_modeI); return selected_atomsN; } /** 3C4 (three or more charged in a fragment of four residues): **/ else if (strstr (tokenA, "3C4") == tokenA) { selected_atomsN = Select3C4_ (mol_complexSP, mol_complexesN, selection_modeI); return selected_atomsN; } /** 3CZ4 (three or more charged or zwitterionic in a fragment of four): **/ else if (strstr (tokenA, "3CZ4") == tokenA) { selected_atomsN = Select3CZ4_ (mol_complexSP, mol_complexesN, selection_modeI); return selected_atomsN; } /** 3NZ4 (three or more negative or zwitterionic in a fragment of four): **/ else if (strstr (tokenA, "3NZ4") == tokenA) { selected_atomsN = Select3NZ4_ (mol_complexSP, mol_complexesN, selection_modeI); return selected_atomsN; } /** 3C5 (three or more charged in a fragment of five residues): **/ else if (strstr (tokenA, "3C5") == tokenA) { selected_atomsN = Select3C5_ (mol_complexSP, mol_complexesN, selection_modeI); return selected_atomsN; } /** 3CZ5 (three or more charged or zwitterionic in a fragment of five): **/ else if (strstr (tokenA, "3CZ5") == tokenA) { selected_atomsN = Select3CZ5_ (mol_complexSP, mol_complexesN, selection_modeI); return selected_atomsN; } /** 3NZ5 (three or more negative or zwitterionic in a fragment of five): **/ else if (strstr (tokenA, "3NZ5") == tokenA) { selected_atomsN = Select3NZ5_ (mol_complexSP, mol_complexesN, selection_modeI); return selected_atomsN; } /** 4C5 (four or more charged in a fragment of five residues): **/ else if (strstr (tokenA, "4C5") == tokenA) { selected_atomsN = Select4C5_ (mol_complexSP, mol_complexesN, selection_modeI); return selected_atomsN; } /** 4CZ5 (four or more charged or zwitterionic in a fragment of five): **/ else if (strstr (tokenA, "4CZ5") == tokenA) { selected_atomsN = Select4CZ5_ (mol_complexSP, mol_complexesN, selection_modeI); return selected_atomsN; } /** 4NZ5 (four or more negative or zwitterionic in a fragment of five): **/ else if (strstr (tokenA, "4NZ5") == tokenA) { selected_atomsN = Select4NZ5_ (mol_complexSP, mol_complexesN, selection_modeI); return selected_atomsN; } /** 3C6 (three or more charged in a fragment of six residues): **/ else if (strstr (tokenA, "3C6") == tokenA) { selected_atomsN = Select3C6_ (mol_complexSP, mol_complexesN, selection_modeI); return selected_atomsN; } /** 3CZ6 (three or more charged or zwitterionic in a fragment of six): **/ else if (strstr (tokenA, "3CZ6") == tokenA) { selected_atomsN = Select3CZ6_ (mol_complexSP, mol_complexesN, selection_modeI); return selected_atomsN; } /** 3NZ6 (three or more negative or zwitterionic in a fragment of six): **/ else if (strstr (tokenA, "3NZ6") == tokenA) { selected_atomsN = Select3NZ6_ (mol_complexSP, mol_complexesN, selection_modeI); return selected_atomsN; } /** 4C6 (four or more charged in a fragment of six residues): **/ else if (strstr (tokenA, "4C6") == tokenA) { selected_atomsN = Select4C6_ (mol_complexSP, mol_complexesN, selection_modeI); return selected_atomsN; } /** 4CZ6 (four or more charged or zwitterionic in a fragment of six): **/ else if (strstr (tokenA, "4CZ6") == tokenA) { selected_atomsN = Select4CZ6_ (mol_complexSP, mol_complexesN, selection_modeI); return selected_atomsN; } /** 4NZ6 (four or more negative or zwitterionic in a fragment of six): **/ else if (strstr (tokenA, "4NZ6") == tokenA) { selected_atomsN = Select4NZ6_ (mol_complexSP, mol_complexesN, selection_modeI); return selected_atomsN; } /** 4P6 (four or more polar in a fragment of six): **/ else if (strstr (tokenA, "4P6") == tokenA) { selected_atomsN = Select4P6_ (mol_complexSP, mol_complexesN, selection_modeI); return selected_atomsN; } /** 5C6 (five or more charged in a fragment of six residues): **/ else if (strstr (tokenA, "5C6") == tokenA) { selected_atomsN = Select5C6_ (mol_complexSP, mol_complexesN, selection_modeI); return selected_atomsN; } /** 5CZ6 (five or more charged or zwitterionic in a fragment of six): **/ else if (strstr (tokenA, "5CZ6") == tokenA) { selected_atomsN = Select5CZ6_ (mol_complexSP, mol_complexesN, selection_modeI); return selected_atomsN; } /** 5NZ6 (five or more negative or zwitterionic in a fragment of six): **/ else if (strstr (tokenA, "5NZ6") == tokenA) { selected_atomsN = Select5NZ6_ (mol_complexSP, mol_complexesN, selection_modeI); return selected_atomsN; } /** 4C7 (four or more charged in a fragment of seven residues): **/ else if (strstr (tokenA, "4C7") == tokenA) { selected_atomsN = Select4C7_ (mol_complexSP, mol_complexesN, selection_modeI); return selected_atomsN; } /** 4CZ7 (four or more charged or zwitterionic in a fragment of seven): **/ else if (strstr (tokenA, "4CZ7") == tokenA) { selected_atomsN = Select4CZ7_ (mol_complexSP, mol_complexesN, selection_modeI); return selected_atomsN; } /** 4NZ7 (four or more negative or zwitterionic in a fragment of seven): **/ else if (strstr (tokenA, "4NZ7") == tokenA) { selected_atomsN = Select4NZ7_ (mol_complexSP, mol_complexesN, selection_modeI); return selected_atomsN; } /** 5C7 (five or more charged in a fragment of seven residues): **/ else if (strstr (tokenA, "5C7") == tokenA) { selected_atomsN = Select5C7_ (mol_complexSP, mol_complexesN, selection_modeI); return selected_atomsN; } /** 5CZ7 (five or more charged or zwitterionic in a fragment of seven): **/ else if (strstr (tokenA, "5CZ7") == tokenA) { selected_atomsN = Select5CZ7_ (mol_complexSP, mol_complexesN, selection_modeI); return selected_atomsN; } /** 5NZ7 (five or more negative or zwitterionic in a fragment of seven): **/ else if (strstr (tokenA, "5NZ7") == tokenA) { selected_atomsN = Select5NZ7_ (mol_complexSP, mol_complexesN, selection_modeI); return selected_atomsN; } /** 3P5 (three or more polar in a fragment of five residues): **/ else if (strstr (tokenA, "3P5") == tokenA) { selected_atomsN = Select3P5_ (mol_complexSP, mol_complexesN, selection_modeI); return selected_atomsN; } /** 5P7 (five or more polar in a fragment of seven residues): **/ else if (strstr (tokenA, "5P7") == tokenA) { selected_atomsN = Select5P7_ (mol_complexSP, mol_complexesN, selection_modeI); return selected_atomsN; } /** 6P7 (six or more polar in a fragment of seven residues): **/ else if (strstr (tokenA, "6P7") == tokenA) { selected_atomsN = Select6P7_ (mol_complexSP, mol_complexesN, selection_modeI); return selected_atomsN; } /** 4C9 (four or more charged in a fragment of nine residues): **/ else if (strstr (tokenA, "4C9") == tokenA) { selected_atomsN = Select4C9_ (mol_complexSP, mol_complexesN, selection_modeI); return selected_atomsN; } /** 4CZ9 (four or more charged or zwitterionic in a fragment of nine): **/ else if (strstr (tokenA, "4CZ9") == tokenA) { selected_atomsN = Select4CZ9_ (mol_complexSP, mol_complexesN, selection_modeI); return selected_atomsN; } /** 4NZ9 (four or more negative or zwitterionic in a fragment of nine): **/ else if (strstr (tokenA, "4NZ9") == tokenA) { selected_atomsN = Select4NZ9_ (mol_complexSP, mol_complexesN, selection_modeI); return selected_atomsN; } /** 5C9 (five or more charged in a fragment of nine residues): **/ else if (strstr (tokenA, "5C9") == tokenA) { selected_atomsN = Select5C9_ (mol_complexSP, mol_complexesN, selection_modeI); return selected_atomsN; } /** 5CZ9 (five or more charged or zwitterionic in a fragment of nine): **/ else if (strstr (tokenA, "5CZ9") == tokenA) { selected_atomsN = Select5CZ9_ (mol_complexSP, mol_complexesN, selection_modeI); return selected_atomsN; } /** 5NZ9 (five or more negative or zwitterionic in a fragment of nine): **/ else if (strstr (tokenA, "5NZ9") == tokenA) { selected_atomsN = Select5NZ9_ (mol_complexSP, mol_complexesN, selection_modeI); return selected_atomsN; } /** String not recognized: **/ else return (long) -1; /* Must be -1! */ /* Count slashes: */ P = full_stringA; while ((n = *P++) != '\0') if (n == '/') slashesN++; if (slashesN != 3) return (long) -1; /* Identify chains, residue ranges, residue */ /* names and atoms which have to be included: */ if (Include_ (&include_selectS, full_stringA) < 0) return (long) -2; /* Identify chains, residue ranges, residue */ /* names and atoms which have to be excluded: */ if (Exclude_ (&exclude_selectS, full_stringA) < 0) return (long) -3; /* Do the selection: */ selected_atomsN = ApplySelection_ (mol_complexSP, mol_complexesN, &include_selectS, &exclude_selectS, selection_modeI); /* Return the number of selected atoms: */ return selected_atomsN; } /*===========================================================================*/ garlic-1.6/plot_mouse.c0000644000076500007650000001633507747226764015476 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2003 Damir Zucic */ /*============================================================================= plot_mouse.c Purpose: Handle MotionNotify events if the main window contains hydrophobicity plot(s). Input: (1) Pointer to RuntimeS structure, with runtime data. (2) Pointer to GUIS structure, with GUI data. (3) Pointer to NearestAtomS structure. (4) The number of pixels in the main window free area. (5) Pointer to refreshI. (6) Pointer to XMotionEvent structure. Output: (1) The information about residue covered by mouse pointer written to the output window. (2) Return value. Return value: (1) Positive on success. (2) Zero if event is ignored. (3) Negative on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======handle MotionNotify events for hydrophobicity plots:=================*/ int PlotMouse_ (RuntimeS *runtimeSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int refreshI, XMotionEvent *motion_eventSP) { int residue_name_length; int space_width, space_half_width; size_t pixelI; NearestAtomS *pixelSP; int central_residueI, first_residueI, last_residueI; int residueI; char *residue_nameP; char residue_nameA[RESNAMESIZE]; int residue_sequenceI; double value; static char stringA[STRINGSIZE]; int string_length; int line_height; int screen_x0, screen_y0; int text_width; int line_x0 = 0, line_x1 = 0; int width, height; /* Residue name length: */ residue_name_length = RESNAMESIZE - 1; /* Space half-width: */ space_width = XTextWidth (guiSP->main_winS.fontSP, " ", 1); space_half_width = space_width / 2; /* If the event came from child window, return zero: */ if (motion_eventSP->subwindow != None) return 0; /* Pixel index: */ pixelI = guiSP->main_win_free_area_width * motion_eventSP->y + motion_eventSP->x; /* Check the pixel index: */ if (pixelI >= pixelsN) return -1; /* Pointer to NearestAtomS structure assigned with this pixel: */ pixelSP = nearest_atomSP + pixelI; /* Check the refreshI associated with this pixel: */ if (pixelSP->last_refreshI != refreshI) return 0; /* Refresh the output window: */ XSetForeground (guiSP->displaySP, guiSP->theGCA[0], guiSP->output_winS.bg_colorID); XFillRectangle (guiSP->displaySP, guiSP->output_winS.ID, guiSP->theGCA[0], 0, 0, guiSP->output_winS.width, guiSP->output_winS.height); /* The central residue index: */ central_residueI = pixelSP->atomI; /* Space half-width: */ space_width = XTextWidth (guiSP->main_winS.fontSP, " ", 1); space_half_width = space_width / 2; /* Prepare the residue name: */ residue_nameP = runtimeSP->sequenceP + central_residueI * residue_name_length; strncpy (residue_nameA, residue_nameP, residue_name_length); residue_nameA[residue_name_length] = '\0'; /* Prepare the residue sequence number: */ residue_sequenceI = *(runtimeSP->serialIP + central_residueI); /* Prepare the function value (average */ /* hydrophob., hydrophobic moment etc.): */ value = pixelSP->z; /* Prepare the text foreground color: */ XSetForeground (guiSP->displaySP, guiSP->theGCA[0], guiSP->output_winS.fg_colorID); /* Text line height: */ line_height = guiSP->output_winS.text_line_height; /* The initial drawing position: */ screen_x0 = TEXTMARGIN; screen_y0 = guiSP->output_winS.font_height + 5; /* Draw residue name and residue sequence number: */ sprintf (stringA, "%s %d", residue_nameA, residue_sequenceI); stringA[SHORTSTRINGSIZE - 1] = '\0'; XDrawString (guiSP->displaySP, guiSP->output_winS.ID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, strlen (stringA)); /* Draw the function value: */ screen_y0 += line_height; strcpy (stringA, "value:"); XDrawString (guiSP->displaySP, guiSP->output_winS.ID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, strlen (stringA)); screen_y0 += line_height; sprintf (stringA, "%.3f", value); XDrawString (guiSP->displaySP, guiSP->output_winS.ID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, strlen (stringA)); /* Now it's time to draw the sequence neighborhood of the central residue. */ /* Indices of the first and the last residue in the neighbourhood: */ first_residueI = central_residueI - NEIGH_HALF_WIDTH; if (first_residueI < 0) first_residueI = 0; last_residueI = central_residueI + NEIGH_HALF_WIDTH; if (last_residueI > (int) runtimeSP->residuesN) { last_residueI = runtimeSP->residuesN; } /* Prepare the string with the left part of the neighborhood: */ stringA[0] = '\0'; strcat (stringA, " "); for (residueI = first_residueI; residueI <= last_residueI; residueI++) { /* The string width, without the central residue: */ if (residueI == central_residueI) { string_length = strlen (stringA); line_x0 = XTextWidth (guiSP->main_winS.fontSP, stringA, string_length) - space_half_width; } /* Pointer to residue name: */ residue_nameP = runtimeSP->sequenceP + residueI * residue_name_length; /* Add the residue name to the output string: */ strncpy (residue_nameA, residue_nameP, residue_name_length); residue_nameA[residue_name_length] = '\0'; strcat (stringA, residue_nameA); strcat (stringA, " "); /* The string width, including the central residue: */ if (residueI == central_residueI) { string_length = strlen (stringA); line_x1 = XTextWidth (guiSP->main_winS.fontSP, stringA, string_length) - space_half_width; } } /* String length: */ string_length = strlen (stringA); /* Text width: */ text_width = XTextWidth (guiSP->main_winS.fontSP, stringA, string_length); /* Prepare text background color: */ XSetForeground (guiSP->displaySP, guiSP->theGCA[0], guiSP->main_winS.bg_colorID); /* Refresh the string background: */ screen_x0 = 1; screen_y0 = 1; width = guiSP->control_winS.x0 - guiSP->main_winS.border_width - 2; if (width < 0) width = 0; height = guiSP->main_winS.font_height + 4; XFillRectangle (guiSP->displaySP, guiSP->main_winS.ID, guiSP->theGCA[0], screen_x0, screen_y0, (unsigned int) width, (unsigned int) height); /* Prepare text color: */ XSetForeground (guiSP->displaySP, guiSP->theGCA[0], guiSP->main_winS.fg_colorID); /* Draw the bounding rectangle: */ XDrawRectangle (guiSP->displaySP, guiSP->main_winS.ID, guiSP->theGCA[0], screen_x0, screen_y0, (unsigned int) width, (unsigned int) height); /* Draw the string which contains sequence neighborhood: */ screen_x0 = guiSP->control_winS.x0 / 2 - text_width / 2; screen_y0 = guiSP->main_winS.font_height + 1; XDrawString (guiSP->displaySP, guiSP->main_winS.ID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, string_length); /* Draw rectangle bounding the central residue: */ line_x0 += guiSP->control_winS.x0 / 2 - text_width / 2; line_x1 += guiSP->control_winS.x0 / 2 - text_width / 2; width = line_x1 - line_x0 + 1; if (width < 0) width = 0; height = guiSP->main_winS.font_height - 1; if (height < 0) height = 0; screen_y0 = height; XDrawRectangle (guiSP->displaySP, guiSP->main_winS.ID, guiSP->theGCA[0], line_x0, 4, (unsigned int) width, (unsigned int) height); /* Return positive value: */ return 1; } /*===========================================================================*/ garlic-1.6/extract_ncac.c0000644000076500007650000000524707272236267015736 0ustar zuciczucic00000000000000/* Copyright (C) 2001 Damir Zucic */ /*============================================================================= extract_ncac.c Purpose: Extract N, CA and C coordinates for a given residue. Input: (1) Pointer to VectorS structure, where N coord. will be stored. (2) Pointer to VectorS structure, where CA coord. will be stored. (3) Pointer to VectorS structure, where C coord. will be stored. (4) Pointer to AtomS structure, pointing to the first element of the atomic array. (5) Index of the first atom of a given residue. (6) Index of the last atom of a given residue. Output: (1) VectorS structures filled with data. (2) Return value. Return value: (1) The number of successfully extracted vectors (at least zero, at most three). Notes: (1) Some files contain more than one entry for some atoms. Garlic uses only the first entry and discards other entries for the same atom. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======extract N, CA and C coordinates:=====================================*/ int ExtractNCAC_ (VectorS *N_vectorSP, VectorS *CA_vectorSP, VectorS *C_vectorSP, AtomS *atomSP, size_t atom_startI, size_t atom_endI) { int vectors_extractedN = 0; size_t atomI; AtomS *curr_atomSP; int N_foundF = 0, CA_foundF = 0, C_foundF = 0; /* Scan the given residue: */ for (atomI = atom_startI; atomI <= atom_endI; atomI++) { /* Pointer to the current atom: */ curr_atomSP = atomSP + atomI; /* N: */ if (strcmp (curr_atomSP->raw_atomS.pure_atom_nameA, "N") == 0) { if (N_foundF) continue; N_vectorSP->x = curr_atomSP->raw_atomS.x[0]; N_vectorSP->y = curr_atomSP->raw_atomS.y; N_vectorSP->z = curr_atomSP->raw_atomS.z[0]; vectors_extractedN++; N_foundF = 1; } /* CA: */ else if (strcmp (curr_atomSP->raw_atomS.pure_atom_nameA, "CA") == 0) { if (CA_foundF) continue; CA_vectorSP->x = curr_atomSP->raw_atomS.x[0]; CA_vectorSP->y = curr_atomSP->raw_atomS.y; CA_vectorSP->z = curr_atomSP->raw_atomS.z[0]; vectors_extractedN++; CA_foundF = 1; } /* C: */ else if (strcmp (curr_atomSP->raw_atomS.pure_atom_nameA, "C") == 0) { if (C_foundF) continue; C_vectorSP->x = curr_atomSP->raw_atomS.x[0]; C_vectorSP->y = curr_atomSP->raw_atomS.y; C_vectorSP->z = curr_atomSP->raw_atomS.z[0]; vectors_extractedN++; C_foundF = 1; } } /* Return the number of extracted vectors: */ return vectors_extractedN; } /*===========================================================================*/ garlic-1.6/bond_style3_quad1.c0000644000076500007650000001760307461726633016620 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2002 Damir Zucic */ /*============================================================================= bond_style3_quad1.c Purpose: Draw bond which fits into quadrant 1 using style 3. See the file file bonds_style3.c for description of quadrants. Input: (1) Pointer to Aux1S structure, which contains required data. (2) Bond index. Output: (1) A single bond drawn. (2) Return value. Return value: (1) One if at least one pixel is drawn. (2) Zero otherwise. =============================================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======draw bond in quadrant 1 using style 3:===============================*/ int BondStyle3Quadrant1_ (Aux1S *aux1SP, int bondI) { long pixels_drawnN = 0; double recip_denom, x_to_y_scale, x_to_z_scale; int screen_x, screen_x1, delta_x, screen_y, line_screen_y; double d, atomic_z; int lineI; size_t pixelI; NearestAtomS *curr_pixelSP; /* Scale factor required to calculate screen_y from screen_x: */ if (aux1SP->screen_delta_x != 0) recip_denom = 1.0 / (double) aux1SP->screen_delta_x; else recip_denom = 0.0; x_to_y_scale = (double) aux1SP->screen_delta_y * recip_denom; /* Scale factor required to calculate z (in atomic units) from screen_x: */ x_to_z_scale = aux1SP->atomic_delta_z * recip_denom; /* Horizontal scan, from left to right: */ screen_x1 = (aux1SP->screen_x0 + aux1SP->screen_x1) / 2; for (screen_x = aux1SP->screen_x0; screen_x <= screen_x1; screen_x++) { /* Check is this pixel inside the area reserved for the */ /* current image (there are two images in stereo mode): */ if (screen_x < aux1SP->configSP->image_screen_x0[aux1SP->imageI]) { continue; } if (screen_x > aux1SP->configSP->image_screen_x1[aux1SP->imageI]) { continue; } /* Relative position: */ delta_x = screen_x - aux1SP->screen_x0; /* Find the corresponding screen_y: */ d = (double) aux1SP->screen_y0 + x_to_y_scale * (double) delta_x; screen_y = (int) (d + 0.5); /* z value (in atomic units): */ atomic_z = aux1SP->atomic_z0 + x_to_z_scale * (double) delta_x; /* Loop which draws lines (vertical scan): */ for (lineI = 0; lineI <= 4; lineI++) { /* Pixel position: */ line_screen_y = screen_y +lineI - 2; /* Check is this pixel inside the area reserved for the */ /* current image (there are two images in stereo mode): */ if (line_screen_y < aux1SP->configSP->image_screen_y0) { continue; } if (line_screen_y > aux1SP->configSP->image_screen_y1) { continue; } /* Current pixel index: */ pixelI = aux1SP->guiSP->main_win_free_area_width * line_screen_y + screen_x; /* Check pixel index: */ if (pixelI >= aux1SP->pixelsN) continue; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = aux1SP->nearest_atomSP + pixelI; /* Check was this pixel used already in */ /* this drawing step; if it was, compare */ /* the z value of the current atom with z */ /* value previously stored to this pixel: */ if (aux1SP->refreshI == curr_pixelSP->last_refreshI) { if (atomic_z >= curr_pixelSP->z) continue; } /* If this point is reached draw one pixel: */ XDrawPoint (aux1SP->guiSP->displaySP, aux1SP->guiSP->main_hidden_pixmapID, aux1SP->guiSP->theGCA[lineI], screen_x, line_screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = 3; curr_pixelSP->last_refreshI = aux1SP->refreshI; curr_pixelSP->mol_complexI = aux1SP->mol_complexI; curr_pixelSP->atomI = aux1SP->atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = atomic_z; curr_pixelSP->colorID = aux1SP->colorIDA[lineI]; /* Update the number of pixels drawn: */ pixels_drawnN++; } } /* Rounding the left end: */ do { /* The x coordinate: */ screen_x = aux1SP->screen_x0 - 1; /* Check: */ if (screen_x < aux1SP->configSP->image_screen_x0[aux1SP->imageI]) break; if (screen_x > aux1SP->configSP->image_screen_x1[aux1SP->imageI]) break; /* z value (in atomic units): */ atomic_z = aux1SP->atomic_z0; /* The y coordinate of central pixel: */ screen_y = aux1SP->screen_y0; /* Scan three lines: */ for (lineI = 0; lineI <= 2; lineI++) { /* Pixel position: */ line_screen_y = screen_y +lineI - 1; /* Check: */ if (line_screen_y < aux1SP->configSP->image_screen_y0) continue; if (line_screen_y > aux1SP->configSP->image_screen_y1) continue; /* Current pixel index: */ pixelI = aux1SP->guiSP->main_win_free_area_width * line_screen_y + screen_x; /* Check pixel index: */ if (pixelI >= aux1SP->pixelsN) break; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = aux1SP->nearest_atomSP + pixelI; /* Check was this pixel used already in this drawing step : */ if (aux1SP->refreshI == curr_pixelSP->last_refreshI) { if (atomic_z >= curr_pixelSP->z) continue; } /* If this point is reached draw one pixel: */ XDrawPoint (aux1SP->guiSP->displaySP, aux1SP->guiSP->main_hidden_pixmapID, aux1SP->guiSP->theGCA[lineI + 1], screen_x, line_screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = 3; curr_pixelSP->last_refreshI = aux1SP->refreshI; curr_pixelSP->mol_complexI = aux1SP->mol_complexI; curr_pixelSP->atomI = aux1SP->atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = atomic_z; curr_pixelSP->colorID = aux1SP->colorIDA[lineI + 1]; /* Update the number of pixels drawn: */ pixels_drawnN++; } /* End of single pass loop: */ } while (0); /* Rounding the right end: */ do { /* The x coordinate: */ screen_x = screen_x1 + 1; /* Check: */ if (screen_x < aux1SP->configSP->image_screen_x0[aux1SP->imageI]) break; if (screen_x > aux1SP->configSP->image_screen_x1[aux1SP->imageI]) break; /* Relative position: */ delta_x = screen_x1 - aux1SP->screen_x0; /* z value (in atomic units): */ atomic_z = aux1SP->atomic_z0 + x_to_z_scale * (double) delta_x; /* The y coordinate of central pixel: */ d = (double) aux1SP->screen_y0 + x_to_y_scale * (double) delta_x; screen_y = (int) (d + 0.5); /* Scan three lines: */ for (lineI = 0; lineI <= 2; lineI++) { /* Pixel position: */ line_screen_y = screen_y +lineI - 1; /* Check: */ if (line_screen_y < aux1SP->configSP->image_screen_y0) continue; if (line_screen_y > aux1SP->configSP->image_screen_y1) continue; /* Current pixel index: */ pixelI = aux1SP->guiSP->main_win_free_area_width * line_screen_y + screen_x; /* Check pixel index: */ if (pixelI >= aux1SP->pixelsN) break; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = aux1SP->nearest_atomSP + pixelI; /* Check was this pixel used already in this drawing step : */ if (aux1SP->refreshI == curr_pixelSP->last_refreshI) { if (atomic_z >= curr_pixelSP->z) continue; } /* If this point is reached draw one pixel: */ XDrawPoint (aux1SP->guiSP->displaySP, aux1SP->guiSP->main_hidden_pixmapID, aux1SP->guiSP->theGCA[lineI + 1], screen_x, line_screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = 3; curr_pixelSP->last_refreshI = aux1SP->refreshI; curr_pixelSP->mol_complexI = aux1SP->mol_complexI; curr_pixelSP->atomI = aux1SP->atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = atomic_z; curr_pixelSP->colorID = aux1SP->colorIDA[lineI + 1]; /* Update the number of pixels drawn: */ pixels_drawnN++; } /* End of single pass loop: */ } while (0); /* Check is at least one pixel drawn: */ if (pixels_drawnN > 0) return 1; /* If this point is reached, nothing is drawn: */ return 0; } /*===========================================================================*/ garlic-1.6/bond_style3_quad2.c0000644000076500007650000001770207461726640016617 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2002 Damir Zucic */ /*============================================================================= bond_style3_quad2.c Purpose: Draw bond which fits into quadrant 2 using style 3. See the file file bonds_style3.c for description of quadrants. Input: (1) Pointer to Aux1S structure, which contains required data. (2) Bond index. Output: (1) A single bond drawn. (2) Return value. Return value: (1) One if at least one pixel is drawn. (2) Zero otherwise. =============================================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======draw bond in quadrant 2 using style 3:===============================*/ int BondStyle3Quadrant2_ (Aux1S *aux1SP, int bondI) { long pixels_drawnN = 0; double recip_denom, y_to_x_scale, y_to_z_scale; int screen_x, line_screen_x, screen_y, screen_y1, delta_y; double d, atomic_z; int lineI; size_t pixelI; NearestAtomS *curr_pixelSP; /* Scale factor required to calculate screen_x from screen_y: */ if (aux1SP->screen_delta_y != 0) recip_denom = 1.0 / (double) aux1SP->screen_delta_y; else recip_denom = 0.0; y_to_x_scale = (double) aux1SP->screen_delta_x * recip_denom; /* Scale factor required to calculate z (in atomic units) from screen_y: */ y_to_z_scale = aux1SP->atomic_delta_z * recip_denom; /* Vertical scan (top to bottom): */ screen_y1 = (aux1SP->screen_y0 + aux1SP->screen_y1) / 2; for (screen_y = aux1SP->screen_y0; screen_y <= screen_y1; screen_y++) { /* Check is this pixel inside the area reserved for the */ /* current image (there are two images in stereo mode): */ if (screen_y < aux1SP->configSP->image_screen_y0) continue; if (screen_y > aux1SP->configSP->image_screen_y1) continue; /* Relative position: */ delta_y = screen_y - aux1SP->screen_y0; /* Find the corresponding screen_x: */ d = (double) aux1SP->screen_x0 + y_to_x_scale * (double) delta_y; screen_x = (int) (d + 0.5); /* z value (in atomic units): */ atomic_z = aux1SP->atomic_z0 + y_to_z_scale * (double) delta_y; /* Loop which draws five lines (horizontal scan): */ for (lineI = 0; lineI <= 4; lineI++) { /* Pixel position: */ line_screen_x = screen_x +lineI - 2; /* Check is this pixel inside the area reserved for the */ /* current image (there are two images in stereo mode): */ if (line_screen_x < aux1SP->configSP->image_screen_x0[aux1SP->imageI]) { continue; } if (line_screen_x > aux1SP->configSP->image_screen_x1[aux1SP->imageI]) { continue; } /* Current pixel index: */ pixelI = aux1SP->guiSP->main_win_free_area_width * screen_y + line_screen_x; /* Check pixel index: */ if (pixelI >= aux1SP->pixelsN) break; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = aux1SP->nearest_atomSP + pixelI; /* Check was this pixel used already in */ /* this drawing step; if it was, compare */ /* the z value of the current atom with z */ /* value previously stored to this pixel: */ if (aux1SP->refreshI == curr_pixelSP->last_refreshI) { if (atomic_z >= curr_pixelSP->z) continue; } /* If this point is reached draw pixel: */ XDrawPoint (aux1SP->guiSP->displaySP, aux1SP->guiSP->main_hidden_pixmapID, aux1SP->guiSP->theGCA[lineI], line_screen_x, screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = 3; curr_pixelSP->last_refreshI = aux1SP->refreshI; curr_pixelSP->mol_complexI = aux1SP->mol_complexI; curr_pixelSP->atomI = aux1SP->atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = atomic_z; curr_pixelSP->colorID = aux1SP->colorIDA[lineI]; /* Update the number of pixels drawn: */ pixels_drawnN++; } } /* Rounding the top end: */ do { /* The y coordinate: */ screen_y = aux1SP->screen_y0 - 1; /* Check: */ if (screen_y < aux1SP->configSP->image_screen_y0) break; if (screen_y > aux1SP->configSP->image_screen_y1) break; /* z value (in atomic units): */ atomic_z = aux1SP->atomic_z0; /* The x coordinate of central pixel: */ screen_x = aux1SP->screen_x0; /* Scan three lines: */ for (lineI = 0; lineI <= 2; lineI++) { /* Pixel position: */ line_screen_x = screen_x +lineI - 1; /* Check: */ if (line_screen_x < aux1SP->configSP->image_screen_x0[aux1SP->imageI]) { continue; } if (line_screen_x > aux1SP->configSP->image_screen_x1[aux1SP->imageI]) { continue; } /* Current pixel index: */ pixelI = aux1SP->guiSP->main_win_free_area_width * screen_y + line_screen_x; /* Check pixel index: */ if (pixelI >= aux1SP->pixelsN) break; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = aux1SP->nearest_atomSP + pixelI; /* Check was this pixel used already in this drawing step : */ if (aux1SP->refreshI == curr_pixelSP->last_refreshI) { if (atomic_z >= curr_pixelSP->z) continue; } /* If this point is reached draw one pixel: */ XDrawPoint (aux1SP->guiSP->displaySP, aux1SP->guiSP->main_hidden_pixmapID, aux1SP->guiSP->theGCA[lineI + 1], line_screen_x, screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = 3; curr_pixelSP->last_refreshI = aux1SP->refreshI; curr_pixelSP->mol_complexI = aux1SP->mol_complexI; curr_pixelSP->atomI = aux1SP->atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = atomic_z; curr_pixelSP->colorID = aux1SP->colorIDA[lineI + 1]; /* Update the number of pixels drawn: */ pixels_drawnN++; } /* End of single pass loop: */ } while (0); /* Rounding the bottom end: */ do { /* The y coordinate: */ screen_y = screen_y1 + 1; /* Check: */ if (screen_y < aux1SP->configSP->image_screen_y0) break; if (screen_y > aux1SP->configSP->image_screen_y1) break; /* Relative position: */ delta_y = screen_y1 - aux1SP->screen_y0; /* z value (in atomic units): */ atomic_z = aux1SP->atomic_z0 + y_to_z_scale * (double) delta_y; /* The x coordinate of central pixel: */ d = (double) aux1SP->screen_x0 + y_to_x_scale * (double) delta_y; screen_x = (int) (d + 0.5); /* Scan three lines: */ for (lineI = 0; lineI <= 2; lineI++) { /* Pixel position: */ line_screen_x = screen_x +lineI - 1; /* Check: */ if (line_screen_x < aux1SP->configSP->image_screen_x0[aux1SP->imageI]) { continue; } if (line_screen_x > aux1SP->configSP->image_screen_x1[aux1SP->imageI]) { continue; } /* Current pixel index: */ pixelI = aux1SP->guiSP->main_win_free_area_width * screen_y + line_screen_x; /* Check pixel index: */ if (pixelI >= aux1SP->pixelsN) break; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = aux1SP->nearest_atomSP + pixelI; /* Check was this pixel used already in this drawing step : */ if (aux1SP->refreshI == curr_pixelSP->last_refreshI) { if (atomic_z >= curr_pixelSP->z) continue; } /* If this point is reached draw one pixel: */ XDrawPoint (aux1SP->guiSP->displaySP, aux1SP->guiSP->main_hidden_pixmapID, aux1SP->guiSP->theGCA[lineI + 1], line_screen_x, screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = 3; curr_pixelSP->last_refreshI = aux1SP->refreshI; curr_pixelSP->mol_complexI = aux1SP->mol_complexI; curr_pixelSP->atomI = aux1SP->atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = atomic_z; curr_pixelSP->colorID = aux1SP->colorIDA[lineI + 1]; /* Update the number of pixels drawn: */ pixels_drawnN++; } /* End of single pass loop: */ } while (0); /* Check is at least one pixel drawn: */ if (pixels_drawnN > 0) return 1; /* If this point is reached, nothing is drawn: */ return 0; } /*===========================================================================*/ garlic-1.6/bond_style3_quad3.c0000644000076500007650000001760107461726646016624 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2002 Damir Zucic */ /*============================================================================= bond_style3_quad3.c Purpose: Draw bond which fits into quadrant 3 using style 3. See the file file bonds_style3.c for description of quadrants. Input: (1) Pointer to Aux1S structure, which contains required data. (2) Bond index. Output: (1) A single bond drawn. (2) Return value. Return value: (1) One if at least one pixel is drawn. (2) Zero otherwise. =============================================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======draw bond in quadrant 3 using style 3:===============================*/ int BondStyle3Quadrant3_ (Aux1S *aux1SP, int bondI) { long pixels_drawnN = 0; double recip_denom, x_to_y_scale, x_to_z_scale; int screen_x, screen_x1, delta_x, screen_y, line_screen_y; double d, atomic_z; int lineI; size_t pixelI; NearestAtomS *curr_pixelSP; /* Scale factor required to calculate screen_y from screen_x: */ if (aux1SP->screen_delta_x != 0) recip_denom = 1.0 / (double) aux1SP->screen_delta_x; else recip_denom = 0.0; x_to_y_scale = (double) aux1SP->screen_delta_y * recip_denom; /* Scale factor required to calculate z (in atomic units) from screen_x: */ x_to_z_scale = aux1SP->atomic_delta_z * recip_denom; /* Horizontal scan, from right to left: */ screen_x1 = (aux1SP->screen_x0 + aux1SP->screen_x1) / 2; for (screen_x = aux1SP->screen_x0; screen_x >= screen_x1; screen_x--) { /* Check is this pixel inside the area reserved for the */ /* current image (there are two images in stereo mode): */ if (screen_x < aux1SP->configSP->image_screen_x0[aux1SP->imageI]) { continue; } if (screen_x > aux1SP->configSP->image_screen_x1[aux1SP->imageI]) { continue; } /* Relative position: */ delta_x = screen_x - aux1SP->screen_x0; /* Find the corresponding screen_y: */ d = (double) aux1SP->screen_y0 + x_to_y_scale * (double) delta_x; screen_y = (int) (d + 0.5); /* z value (in atomic units): */ atomic_z = aux1SP->atomic_z0 + x_to_z_scale * (double) delta_x; /* Loop which draws five lines (vertical scan): */ for (lineI = 0; lineI <= 4; lineI++) { /* Pixel position: */ line_screen_y = screen_y +lineI - 2; /* Check is this pixel inside the area reserved for the */ /* current image (there are two images in stereo mode): */ if (line_screen_y < aux1SP->configSP->image_screen_y0) { continue; } if (line_screen_y > aux1SP->configSP->image_screen_y1) { continue; } /* Current pixel index: */ pixelI = aux1SP->guiSP->main_win_free_area_width * line_screen_y + screen_x; /* Check pixel index: */ if (pixelI >= aux1SP->pixelsN) break; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = aux1SP->nearest_atomSP + pixelI; /* Check was this pixel used already in */ /* this drawing step; if it was, compare */ /* the z value of the current atom with z */ /* value previously stored to this pixel: */ if (aux1SP->refreshI == curr_pixelSP->last_refreshI) { if (atomic_z >= curr_pixelSP->z) continue; } /* If this point is reached draw pixel: */ XDrawPoint (aux1SP->guiSP->displaySP, aux1SP->guiSP->main_hidden_pixmapID, aux1SP->guiSP->theGCA[lineI], screen_x, line_screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = 3; curr_pixelSP->last_refreshI = aux1SP->refreshI; curr_pixelSP->mol_complexI = aux1SP->mol_complexI; curr_pixelSP->atomI = aux1SP->atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = atomic_z; curr_pixelSP->colorID = aux1SP->colorIDA[lineI]; /* Update the number of pixels drawn: */ pixels_drawnN++; } } /* Rounding the right end: */ do { /* The x coordinate: */ screen_x = aux1SP->screen_x0 + 1; /* Check: */ if (screen_x < aux1SP->configSP->image_screen_x0[aux1SP->imageI]) break; if (screen_x > aux1SP->configSP->image_screen_x1[aux1SP->imageI]) break; /* z value (in atomic units): */ atomic_z = aux1SP->atomic_z0; /* The y coordinate of central pixel: */ screen_y = aux1SP->screen_y0; /* Scan three lines: */ for (lineI = 0; lineI <= 2; lineI++) { /* Pixel position: */ line_screen_y = screen_y +lineI - 1; /* Check: */ if (line_screen_y < aux1SP->configSP->image_screen_y0) continue; if (line_screen_y > aux1SP->configSP->image_screen_y1) continue; /* Current pixel index: */ pixelI = aux1SP->guiSP->main_win_free_area_width * line_screen_y + screen_x; /* Check pixel index: */ if (pixelI >= aux1SP->pixelsN) break; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = aux1SP->nearest_atomSP + pixelI; /* Check was this pixel used already in this drawing step : */ if (aux1SP->refreshI == curr_pixelSP->last_refreshI) { if (atomic_z >= curr_pixelSP->z) continue; } /* If this point is reached draw one pixel: */ XDrawPoint (aux1SP->guiSP->displaySP, aux1SP->guiSP->main_hidden_pixmapID, aux1SP->guiSP->theGCA[lineI + 1], screen_x, line_screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = 3; curr_pixelSP->last_refreshI = aux1SP->refreshI; curr_pixelSP->mol_complexI = aux1SP->mol_complexI; curr_pixelSP->atomI = aux1SP->atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = atomic_z; curr_pixelSP->colorID = aux1SP->colorIDA[lineI + 1]; /* Update the number of pixels drawn: */ pixels_drawnN++; } /* End of single pass loop: */ } while (0); /* Rounding the left end: */ do { /* The x coordinate: */ screen_x = screen_x1 - 1; /* Check: */ if (screen_x < aux1SP->configSP->image_screen_x0[aux1SP->imageI]) break; if (screen_x > aux1SP->configSP->image_screen_x1[aux1SP->imageI]) break; /* Relative position: */ delta_x = screen_x1 - aux1SP->screen_x0; /* z value (in atomic units): */ atomic_z = aux1SP->atomic_z0 + x_to_z_scale * (double) delta_x; /* The y coordinate of central pixel: */ d = (double) aux1SP->screen_y0 + x_to_y_scale * (double) delta_x; screen_y = (int) (d + 0.5); /* Scan three lines: */ for (lineI = 0; lineI <= 2; lineI++) { /* Pixel position: */ line_screen_y = screen_y +lineI - 1; /* Check: */ if (line_screen_y < aux1SP->configSP->image_screen_y0) continue; if (line_screen_y > aux1SP->configSP->image_screen_y1) continue; /* Current pixel index: */ pixelI = aux1SP->guiSP->main_win_free_area_width * line_screen_y + screen_x; /* Check pixel index: */ if (pixelI >= aux1SP->pixelsN) break; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = aux1SP->nearest_atomSP + pixelI; /* Check was this pixel used already in this drawing step : */ if (aux1SP->refreshI == curr_pixelSP->last_refreshI) { if (atomic_z >= curr_pixelSP->z) continue; } /* If this point is reached draw one pixel: */ XDrawPoint (aux1SP->guiSP->displaySP, aux1SP->guiSP->main_hidden_pixmapID, aux1SP->guiSP->theGCA[lineI + 1], screen_x, line_screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = 3; curr_pixelSP->last_refreshI = aux1SP->refreshI; curr_pixelSP->mol_complexI = aux1SP->mol_complexI; curr_pixelSP->atomI = aux1SP->atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = atomic_z; curr_pixelSP->colorID = aux1SP->colorIDA[lineI + 1]; /* Update the number of pixels drawn: */ pixels_drawnN++; } /* End of single pass loop: */ } while (0); /* Check is at least one pixel drawn: */ if (pixels_drawnN > 0) return 1; /* If this point is reached, nothing is drawn: */ return 0; } /*===========================================================================*/ garlic-1.6/bond_style3_quad4.c0000644000076500007650000001770107461726655016626 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2002 Damir Zucic */ /*============================================================================= bond_style3_quad4.c Purpose: Draw bond which fits into quadrant 4 using style 3. See the file file bonds_style3.c for description of quadrants. Input: (1) Pointer to Aux1S structure, which contains required data. (2) Bond index. Output: (1) A single bond drawn. (2) Return value. Return value: (1) One if at least one pixel is drawn. (2) Zero otherwise. =============================================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======draw bond in quadrant 4 using style 3:===============================*/ int BondStyle3Quadrant4_ (Aux1S *aux1SP, int bondI) { long pixels_drawnN = 0; double recip_denom, y_to_x_scale, y_to_z_scale; int screen_x, line_screen_x, screen_y, screen_y1, delta_y; double d, atomic_z; int lineI; size_t pixelI; NearestAtomS *curr_pixelSP; /* Scale factor required to calculate screen_x from screen_y: */ if (aux1SP->screen_delta_y != 0) recip_denom = 1.0 / (double) aux1SP->screen_delta_y; else recip_denom = 0.0; y_to_x_scale = (double) aux1SP->screen_delta_x * recip_denom; /* Scale factor required to calculate z (in atomic units) from screen_y: */ y_to_z_scale = aux1SP->atomic_delta_z * recip_denom; /* Vertical scan (bottom to top): */ screen_y1 = (aux1SP->screen_y0 + aux1SP->screen_y1) / 2; for (screen_y = aux1SP->screen_y0; screen_y >= screen_y1; screen_y--) { /* Check is this pixel inside the area reserved for the */ /* current image (there are two images in stereo mode): */ if (screen_y < aux1SP->configSP->image_screen_y0) continue; if (screen_y > aux1SP->configSP->image_screen_y1) continue; /* Relative position: */ delta_y = screen_y - aux1SP->screen_y0; /* Find the corresponding screen_x: */ d = (double) aux1SP->screen_x0 + y_to_x_scale * (double) delta_y; screen_x = (int) (d + 0.5); /* z value (in atomic units): */ atomic_z = aux1SP->atomic_z0 + y_to_z_scale * (double) delta_y; /* Loop which draws five lines (horizontal scan): */ for (lineI = 0; lineI <= 4; lineI++) { /* Pixel position: */ line_screen_x = screen_x +lineI - 2; /* Check is this pixel inside the area reserved for the */ /* current image (there are two images in stereo mode): */ if (line_screen_x < aux1SP->configSP->image_screen_x0[aux1SP->imageI]) { continue; } if (line_screen_x > aux1SP->configSP->image_screen_x1[aux1SP->imageI]) { continue; } /* Current pixel index: */ pixelI = aux1SP->guiSP->main_win_free_area_width * screen_y + line_screen_x; /* Check pixel index: */ if (pixelI >= aux1SP->pixelsN) break; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = aux1SP->nearest_atomSP + pixelI; /* Check was this pixel used already in */ /* this drawing step; if it was, compare */ /* the z value of the current atom with z */ /* value previously stored to this pixel: */ if (aux1SP->refreshI == curr_pixelSP->last_refreshI) { if (atomic_z >= curr_pixelSP->z) continue; } /* If this point is reached draw pixel: */ XDrawPoint (aux1SP->guiSP->displaySP, aux1SP->guiSP->main_hidden_pixmapID, aux1SP->guiSP->theGCA[lineI], line_screen_x, screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = 3; curr_pixelSP->last_refreshI = aux1SP->refreshI; curr_pixelSP->mol_complexI = aux1SP->mol_complexI; curr_pixelSP->atomI = aux1SP->atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = atomic_z; curr_pixelSP->colorID = aux1SP->colorIDA[lineI]; /* Update the number of pixels drawn: */ pixels_drawnN++; } } /* Rounding the bottom end: */ do { /* The y coordinate: */ screen_y = aux1SP->screen_y0 + 1; /* Check: */ if (screen_y < aux1SP->configSP->image_screen_y0) break; if (screen_y > aux1SP->configSP->image_screen_y1) break; /* z value (in atomic units): */ atomic_z = aux1SP->atomic_z0; /* The x coordinate of central pixel: */ screen_x = aux1SP->screen_x0; /* Scan three lines: */ for (lineI = 0; lineI <= 2; lineI++) { /* Pixel position: */ line_screen_x = screen_x +lineI - 1; /* Check: */ if (line_screen_x < aux1SP->configSP->image_screen_x0[aux1SP->imageI]) { continue; } if (line_screen_x > aux1SP->configSP->image_screen_x1[aux1SP->imageI]) { continue; } /* Current pixel index: */ pixelI = aux1SP->guiSP->main_win_free_area_width * screen_y + line_screen_x; /* Check pixel index: */ if (pixelI >= aux1SP->pixelsN) break; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = aux1SP->nearest_atomSP + pixelI; /* Check was this pixel used already in this drawing step : */ if (aux1SP->refreshI == curr_pixelSP->last_refreshI) { if (atomic_z >= curr_pixelSP->z) continue; } /* If this point is reached draw one pixel: */ XDrawPoint (aux1SP->guiSP->displaySP, aux1SP->guiSP->main_hidden_pixmapID, aux1SP->guiSP->theGCA[lineI + 1], line_screen_x, screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = 3; curr_pixelSP->last_refreshI = aux1SP->refreshI; curr_pixelSP->mol_complexI = aux1SP->mol_complexI; curr_pixelSP->atomI = aux1SP->atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = atomic_z; curr_pixelSP->colorID = aux1SP->colorIDA[lineI + 1]; /* Update the number of pixels drawn: */ pixels_drawnN++; } /* End of single pass loop: */ } while (0); /* Rounding the top end: */ do { /* The y coordinate: */ screen_y = screen_y1 - 1; /* Check: */ if (screen_y < aux1SP->configSP->image_screen_y0) break; if (screen_y > aux1SP->configSP->image_screen_y1) break; /* Relative position: */ delta_y = screen_y1 - aux1SP->screen_y0; /* z value (in atomic units): */ atomic_z = aux1SP->atomic_z0 + y_to_z_scale * (double) delta_y; /* The x coordinate of central pixel: */ d = (double) aux1SP->screen_x0 + y_to_x_scale * (double) delta_y; screen_x = (int) (d + 0.5); /* Scan three lines: */ for (lineI = 0; lineI <= 2; lineI++) { /* Pixel position: */ line_screen_x = screen_x +lineI - 1; /* Check: */ if (line_screen_x < aux1SP->configSP->image_screen_x0[aux1SP->imageI]) { continue; } if (line_screen_x > aux1SP->configSP->image_screen_x1[aux1SP->imageI]) { continue; } /* Current pixel index: */ pixelI = aux1SP->guiSP->main_win_free_area_width * screen_y + line_screen_x; /* Check pixel index: */ if (pixelI >= aux1SP->pixelsN) break; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = aux1SP->nearest_atomSP + pixelI; /* Check was this pixel used already in this drawing step : */ if (aux1SP->refreshI == curr_pixelSP->last_refreshI) { if (atomic_z >= curr_pixelSP->z) continue; } /* If this point is reached draw one pixel: */ XDrawPoint (aux1SP->guiSP->displaySP, aux1SP->guiSP->main_hidden_pixmapID, aux1SP->guiSP->theGCA[lineI + 1], line_screen_x, screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = 3; curr_pixelSP->last_refreshI = aux1SP->refreshI; curr_pixelSP->mol_complexI = aux1SP->mol_complexI; curr_pixelSP->atomI = aux1SP->atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = atomic_z; curr_pixelSP->colorID = aux1SP->colorIDA[lineI + 1]; /* Update the number of pixels drawn: */ pixels_drawnN++; } /* End of single pass loop: */ } while (0); /* Check is at least one pixel drawn: */ if (pixels_drawnN > 0) return 1; /* If this point is reached, nothing is drawn: */ return 0; } /*===========================================================================*/ garlic-1.6/extract_necz.c0000644000076500007650000000450307415612676015764 0ustar zuciczucic00000000000000/* Copyright (C) 2001, 2002 Damir Zucic */ /*============================================================================= extract_necz.c Purpose: Extract NE and CZ coordinates for a given residue. Input: (1) Pointer to VectorS structure, for NE coordinates. (2) Pointer to VectorS structure, for CZ coordinates. (3) Pointer to AtomS structure, pointing to the first element of the atomic array. (4) Index of the first atom of a given residue. (5) Index of the last atom of a given residue. Output: (1) VectorS structures filled with data. (2) Return value. Return value: (1) The number of successfully extracted vectors (at least zero, at most two). Notes: (1) Some files contain more than one entry for some atoms. Garlic uses only the first entry and discards other entries for the same atom. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======extract NE and CZ coordinates:=======================================*/ int ExtractNECZ_ (VectorS *NE_vectorSP, VectorS *CZ_vectorSP, AtomS *atomSP, size_t atom_startI, size_t atom_endI) { int vectors_extractedN = 0; size_t atomI; AtomS *curr_atomSP; char *atom_nameP; int NE_foundF = 0, CZ_foundF = 0; /* Scan the given residue: */ for (atomI = atom_startI; atomI <= atom_endI; atomI++) { /* Pointer to the current atom: */ curr_atomSP = atomSP + atomI; /* Pointer to the purified atom name: */ atom_nameP = curr_atomSP->raw_atomS.pure_atom_nameA; /* NE: */ if (strcmp (atom_nameP, "NE") == 0) { if (NE_foundF) continue; NE_vectorSP->x = curr_atomSP->raw_atomS.x[0]; NE_vectorSP->y = curr_atomSP->raw_atomS.y; NE_vectorSP->z = curr_atomSP->raw_atomS.z[0]; vectors_extractedN++; NE_foundF = 1; } /* CZ: */ else if (strcmp (atom_nameP, "CZ") == 0) { if (CZ_foundF) continue; CZ_vectorSP->x = curr_atomSP->raw_atomS.x[0]; CZ_vectorSP->y = curr_atomSP->raw_atomS.y; CZ_vectorSP->z = curr_atomSP->raw_atomS.z[0]; vectors_extractedN++; CZ_foundF = 1; } } /* Return the number of extracted vectors: */ return vectors_extractedN; } /*===========================================================================*/ garlic-1.6/sphere_slab.c0000644000076500007650000000602007065475214015552 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= sphere_slab.c Purpose: Check which atoms are inside the spherical slab. Spherical slab is defined by two concentric spheres. A given atom is inside the slab if it is outside the inner sphere and inside the outer sphere. Use this slab type to hide the inner part of a globular protein. Input: (1) Pointer to MolComplexS structure. Output: (1) Slab flag set for each atom. The value one is assigned to atoms inside the slab, zero to the rest. (2) Return value. Return value: The number of atoms inside the slab. ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======spherical slab:======================================================*/ size_t SphereSlab_ (MolComplexS *curr_mol_complexSP) { size_t atoms_inside_slabN = 0; size_t atomsN, atomI; AtomS *curr_atomSP; double x0, y0, z0, r0_squared, r1_squared; double x, y, z, rho_squared, r_squared; /* The number of atoms in a complex: */ atomsN = curr_mol_complexSP->atomsN; /* Copy the slab center coordinates: */ x0 = curr_mol_complexSP->slab_center_vectorS.x; y0 = curr_mol_complexSP->slab_center_vectorS.y; z0 = curr_mol_complexSP->slab_center_vectorS.z; r0_squared = curr_mol_complexSP->slab_back_relative_position; r0_squared *= r0_squared; r1_squared = curr_mol_complexSP->slab_front_relative_position; r1_squared *= r1_squared; /* Set the slab flag for each atom: */ for (atomI = 0; atomI < atomsN; atomI++) { /** Pointer to the current atom: **/ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /** Set the initial values of slab flags to one; this **/ /** will be changed later for atoms outside the slab: **/ curr_atomSP->inside_slabF = 1; curr_atomSP->inside_projected_slabF = 1; /** Distance between the current atom and the cylinder axis: **/ x = curr_atomSP->raw_atomS.x[0] - x0; z = curr_atomSP->raw_atomS.z[0] - z0; rho_squared = x * x + z * z; /** Distance between the current atom and the slab center: **/ y = curr_atomSP->raw_atomS.y - y0; r_squared = rho_squared + y * y; /** First prepare the inside_projected_slabF: */ if (rho_squared < r0_squared) curr_atomSP->inside_projected_slabF = 0; if (rho_squared > r1_squared) curr_atomSP->inside_projected_slabF = 0; /** If atom is inside the inner slab sphere, set **/ /** slab flag to zero and check the next atom: **/ if (r_squared < r0_squared) { curr_atomSP->inside_slabF = 0; continue; } /** If atom is outside the outer slab sphere: **/ if (r_squared > r1_squared) { curr_atomSP->inside_slabF = 0; continue; } /** If this points is reached, current atom is inside the slab: **/ atoms_inside_slabN++; } /* Return the number of atoms inside the slab: */ return atoms_inside_slabN; } /*===========================================================================*/ garlic-1.6/hybond_style.c0000644000076500007650000000340007461731743015767 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2002 Damir Zucic */ /*============================================================================= hybond_style.c Purpose: Change drawing style for hydrogen bonds. Input: (1) Pointer to MolComplexS structure. (2) Bond drawing style index. Output: (1) Bond drawing style changed for every hydrogen bond in a given complex. (2) Return value. Return value: (1) Positive if the given complex contains at least one atom. (2) Zero otherwise. ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======change hydrogen bond drawing style:==================================*/ int ChangeHybondStyle_ (MolComplexS *curr_mol_complexSP, int styleI) { size_t atomsN, atomI; AtomS *curr_atomSP; int bondsN, bondI; TrueBondS *curr_bondSP; /* Prepare and check the number of atoms in this complex: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) return 0; /* Check every atom: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to this atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* The number of bonds: */ bondsN = curr_atomSP->bondsN; /* Check every bond: */ for (bondI = 0; bondI < bondsN; bondI++) { /* Pointer to the structure with data about current bond: */ curr_bondSP = curr_atomSP->true_bondSA + bondI; /* If the current bond is not hydrogen bond, skip it: */ if (curr_bondSP->bond_typeI != 0) continue; /* Change the bond drawing style: */ curr_bondSP->bond_styleI = styleI; } } /* Return positive value: */ return 1; } /*===========================================================================*/ garlic-1.6/rotation_angle.c0000644000076500007650000000623607465734714016310 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2002 Damir Zucic */ /*============================================================================= rotation_angle.c Purpose: Prepare the rotation angle. By default, the normal rotation angle is copied (rotation_stepA[2] from ConfigS structure). See note 1 for available combinations of modifier keys. Modifier keys may be used to select the rotation angle. Input: (1) Pointer to ConfigS structure, with configuration data. (2) Pointer to GUIS structure, with GUI data. (3) The sign used to distinguish positive and negative rotation. Value +1.0 is used with positive rotation, while -1.0 defines negative rotation. Output: (1) Return value. Return value: (1) Rotation angle. Notes: (1) The following combinations of modifier keys may be used to select the rotation angle: ------------------------------------------------------------- | modifiers rotation step ConfigS member | |-----------------------------------------------------------| | none normal (default) rotation_stepA[2] | | shift large rotation_stepA[3] | | alt+shift very large rotation_stepA[4] | | control small rotation_stepA[1] | | alt+control very small rotation_stepA[0] | | shift+control very small rotation_stepA[2] | | alt normal rotation_stepA[2] | | alt+shift+control normal rotation_stepA[2] | ------------------------------------------------------------- Note that some modifier combinations are ignored (alt alone and alt+control+shift). (2) On some laptops the status of shift key may be changed before the KeyPress event is send for the keys on "numeric keypad". ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======prepare rotation angle:==============================================*/ double RotationAngle_ (ConfigS *configSP, GUIS *guiSP, double sign) { double rotation_angle; int largeF, smallF, altF; /* Copy the flags: */ largeF = guiSP->shift_pressedF; smallF = guiSP->control_pressedF; altF = guiSP->alt_pressedF; /* Select the requested rotation step: */ if (altF) { if (largeF && !smallF) { rotation_angle = configSP->rotation_stepA[4]; } else if (smallF && !largeF) { rotation_angle = configSP->rotation_stepA[0]; } else { rotation_angle = configSP->rotation_stepA[2]; } } else { if (largeF && !smallF) { rotation_angle = configSP->rotation_stepA[3]; } else if (smallF && !largeF) { rotation_angle = configSP->rotation_stepA[1]; } else if (smallF && largeF) { rotation_angle = configSP->rotation_stepA[0]; } else { rotation_angle = configSP->rotation_stepA[2]; } } /* Take care for the sign: */ rotation_angle *= sign; /* Return the rotation angle: */ return rotation_angle; } /*===========================================================================*/ garlic-1.6/extent.c0000644000076500007650000000747407374046611014606 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= extent.c Purpose: Find the spatial extent of a given macromolecular complex. Input: (1) Pointer to MolComplexS structure, with macromolecular data. Input data are read from this structure; output data will be stored there too. Output: (1) Two output vectors prepared. (2) Return value. Return value: (1) Positive if macromol. complex contains at least one atom. (2) Zero, if there are no atoms. Notes: (1) The absolute coordinate system has the following orientation: | | -(X)----------> x ... z points inside - the | z system is right-handed | | V y See also a small pixmap in the top left corner of the main window. (2) The minimal extent in each dimension is 5.0 angstroms. ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======find spatial extent:=================================================*/ int ComplexExtent_ (MolComplexS *mol_complexSP) { size_t atomI, atomsN; AtomS *curr_atomSP; double x_min, x_max, y_min, y_max, z_min, z_max; double x, y, z; double x_extent, y_extent, z_extent, max_extent; /* Initialize extent vectors: */ mol_complexSP->left_top_near_vectorS.x = 0.0; mol_complexSP->left_top_near_vectorS.y = 0.0; mol_complexSP->left_top_near_vectorS.z = 0.0; mol_complexSP->right_bottom_far_vectorS.x = 0.0; mol_complexSP->right_bottom_far_vectorS.y = 0.0; mol_complexSP->right_bottom_far_vectorS.z = 0.0; /* Return if there are no atoms: */ atomsN = mol_complexSP->atomsN; if (atomsN == 0) return 0; /* Initialize extreme values using the coordinates of the first atom: */ x_min = mol_complexSP->atomSP->raw_atomS.x[0]; x_max = x_min; y_min = mol_complexSP->atomSP->raw_atomS.y; y_max = y_min; z_min = mol_complexSP->atomSP->raw_atomS.z[0]; z_max = z_min; /* Find new extreme values; skip the first atom: */ for (atomI = 1; atomI < atomsN; atomI++) { /** Current AtomS pointer: **/ curr_atomSP = mol_complexSP->atomSP + atomI; /** Min./max.: **/ x = curr_atomSP->raw_atomS.x[0]; y = curr_atomSP->raw_atomS.y; z = curr_atomSP->raw_atomS.z[0]; if (x < x_min) x_min = x; if (y < y_min) y_min = y; if (z < z_min) z_min = z; if (x > x_max) x_max = x; if (y > y_max) y_max = y; if (z > z_max) z_max = z; } /* The extent in all three dimensions */ /* should be at least 5.0 angstroms: */ if (x_max - x_min < 5.0) { x_min = -2.5; x_max = 2.5; } if (y_max - y_min < 5.0) { y_min = -2.5; y_max = 2.5; } if (z_max - z_min < 5.0) { z_min = -2.5; z_max = 2.5; } /* Set new values: */ mol_complexSP->left_top_near_vectorS.x = x_min; mol_complexSP->left_top_near_vectorS.y = y_min; mol_complexSP->left_top_near_vectorS.z = z_min; mol_complexSP->right_bottom_far_vectorS.x = x_max; mol_complexSP->right_bottom_far_vectorS.y = y_max; mol_complexSP->right_bottom_far_vectorS.z = z_max; /* Find the maximal extent of the macromolecular complex: */ x_extent = mol_complexSP->right_bottom_far_vectorS.x - mol_complexSP->left_top_near_vectorS.x; y_extent = mol_complexSP->right_bottom_far_vectorS.y - mol_complexSP->left_top_near_vectorS.y; z_extent = mol_complexSP->right_bottom_far_vectorS.z - mol_complexSP->left_top_near_vectorS.z; max_extent = x_extent; if (y_extent > max_extent) max_extent = y_extent; if (z_extent > max_extent) max_extent = z_extent; mol_complexSP->max_extent = max_extent; /* Return 1 if there is at least one atom: */ return 1; } /*===========================================================================*/ garlic-1.6/2fcp.script0000644000076500007650000000032407051523311015163 0ustar zuciczucic00000000000000load 2fcp.pdb select side hide # Do not hide hetero atoms, there are some seleno-met (MSE) side chains! sel het color red select 1-158 hide rotate z -30 rotate x 20 rotate y -90 select main_chain atoms 0 bonds 3 garlic-1.6/Makefile0000644000076500007650000013114310445775624014570 0ustar zuciczucic00000000000000CC = gcc #CCOPT = -O CCOPT = -O3 #CCOPT = -O3 -g3 #CCOPT = -ansi -pedantic -g3 #CCOPT = -ansi -pedantic -O -Wall -Wstrict-prototypes -g3 HEADERS = defines.h typedefs.h LIBPATH = -L/usr/X11R6/lib LINKOPT = -lX11 -lm OBJECTS = garlic.o print_usage.o print_help.o print_version.o \ register.o alloc_gui.o alloc_config.o alloc_mol_complex.o \ free_memory.o display_init.o disp_color_cap.o \ color_shifts.o calc_params.o errmsg.o warnmsg.o \ openfile_r.o read_config.o open_config_file.o extract_int.o \ ex2ints.o extract_double.o ex2doubles.o extract_phrase.o \ extract_index.o ex_rot_steps.o ex_trans_steps.o \ ex_slab_steps.o ex_fading_steps.o extract_args.o \ parse_options.o parse_color.o load_font.o prepare_cursor.o \ print_config.o create_windows.o make_pixmap.o make_pixmap2.o \ rgbs_from_xcolor.o pixel_from_rgbs.o size_hints.o wmhints.o \ select_events.o hide_control.o load_complex.o read_file.o \ fileformat.o is_pdb.o read_pdb.o init_header.o pdb_atom.o \ extract_field.o copypur.o realloc_pdb.o headerline.o \ geomcenter.o init_slab.o init_fading.o flip_vector.o \ translate_complex.o extent.o stereo_data.o strong_bonds.o \ pseudo_bonds.o check_dist.o add_bond.o event_loop.o \ alloc_nearest.o init_nearest.o main_refresh.o key_press.o \ rotation_angle.o rotate.o translation_shift.o translate.o \ slab_shift.o move_back_slab.o move_front_slab.o \ fading_shift.o move_back_fading.o move_front_fading.o \ key_release.o refresh_pixmap.o slab.o no_slab.o \ planar_slab.o sphere_slab.o half_sphere_slab.o cylin_slab.o \ half_cylin_slab.o project_atoms.o fading.o prepare_color.o \ no_fading.o planar_fading.o sphere_fading.o \ half_sphere_fading.o cylin_fading.o half_cylin_fading.o \ reset_pos_flag.o atoms_style1.o atoms_style2.o \ atoms_style3.o atoms_style4.o atoms_style5.o atoms_style6.o \ atoms_style7.o bonds_style1.o bond_style1_quad1.o \ bond_style1_quad2.o bond_style1_quad3.o bond_style1_quad4.o \ bonds_style2.o bond_style2_quad1.o bond_style2_quad2.o \ bond_style2_quad3.o bond_style2_quad4.o bonds_style3.o \ interpolate_color.o bond_style3_quad1.o bond_style3_quad2.o \ bond_style3_quad3.o bond_style3_quad4.o bonds_style4.o \ add_two_colors.o bond_style4_quad1.o bond_style4_quad2.o \ bond_style4_quad3.o bond_style4_quad4.o bonds_style5.o \ add_three_colors.o bond_style5_quad1.o bond_style5_quad2.o \ bond_style5_quad3.o bond_style5_quad4.o draw_system.o \ motion_notify.o assign_hyphob.o control_refresh.o \ print_cursor_names.o main_resize.o init_runtime.o \ add_char.o input_refresh.o eat_left_char.o eat_right_char.o \ execute_command1.o execute_command2.o truncate_comm.o \ create_log_file.o load.o catch.o discard.o select.o \ full_select.o include.o chains.o residue_ranges.o \ extract_token.o extract_serials.o residue_names.o \ atom_names.o exclude.o skip_keyword.o apply_selection.o \ show.o hide.o color_schemes.o init_colors.o color.o \ special_select.o select_hetero.o select_element.o \ select_atoms.o quick_select.o replace_command.o atoms.o \ bonds.o execute_script.o comm_rotate.o comm_translate.o \ comm_slab.o comm_fading.o log.o prepare_backbone.o \ background.o text_background.o text_foreground.o \ change_slab.o change_fading.o full_colors.o is_old.o \ font.o cpk.o zebra.o chain.o color_hyphob.o mix_colors.o \ comm_backbone.o hide_no_refresh.o show_no_refresh.o \ backbone.o hybonds.o generate_hybonds.o hybond_style.o \ show_backbone.o hide_backbone.o pdb_id.o generate_plane.o \ stereo.o mono.o position.o copy_doubles.o title.o \ free_runtime.o draw_titles.o foreground.o prepare_oc.o \ select_complement.o labels.o draw_labels.o \ assign_radii.o spacefill.o spacefill_color.o draw_balls.o \ center.o save.o write_line.o big_spheres.o tag.o \ draw_tags.o tag_position.o button_press.o control_click.o \ identify_button.o init_buttons.o write_hints.o \ extract_sequence.o count_residues.o sequence.o \ parse_sequence.o sequence_from.o load_sequence.o \ select_sequence.o compare_sequences.o dihedral_angles.o \ extract_ncaco.o phi_from_cncac.o psi_from_ncaco.o \ vector_product.o absolute_value.o scalar_product.o \ omega_from_cacnca.o select_cis_trans.o \ ramachandran.o draw_ramachandran.o rama_frame.o \ rama_mouse.o read_fasta.o save_sequence.o wheel.o \ wheel_top_view.o wheel_bottom_view.o hydrophobicity.o \ weight_colors.o angle.o radius.o select_sphere.o \ disulfide_bonds.o venn.o draw_venn.o spacefill2.o \ sp2_color.o save_seq_w_numbers.o ssb.o select_alternate.o \ select_model.o color_model.o window.o plot.o draw_plots.o \ weighted_hydrophobicity.o average_hydrophobicity.o \ init_hyphob.o plot_mouse.o project_planes.o draw_planes.o \ plane_extent.o rotate_plane.o translate_plane.o \ comm_move.o plane.o select_above.o select_below.o big2.o \ scale.o pattern.o dock.o align_normal.o align_complexes.o \ docking_window.o docking_resize.o docking_refresh.o \ docking_project.o list_exposed_polar.o is_polar.o \ representative_atoms.o exclude_distant.o draw_bottom.o \ draw_top.o copy_sequence.o compare.o draw_comparison.o \ neighborhood.o draw_balls2.o comparison_mouse.o structure.o \ parse_sec_structure.o copy_sec_structure.o \ load_sec_structure.o save_sec_structure.o \ alloc_sec_structure.o sec_structure_from.o create.o \ open_template_file.o read_template_file.o \ ex_template_residues.o count_template_res.o \ create_structure.o required_atoms.o copy_template_atoms.o \ fix_chain.o reset_phi.o extract_hncac.o phi_from_hncac.o \ rotate_atom.o parallel_part.o reset_psi.o build_chain.o \ extract_ncac.o translate_range.o rotate_range.o \ apply_structure.o generate_phi_psi.o extract_nca.o \ extract_c.o replace.o extract_n.o refresh_backbone.o \ edit.o draw_edit_symbol.o draw_squid.o draw_seahorse.o \ are_atoms_bound.o bond_partners.o edit_phi.o edit_psi.o \ extract_cac.o small_ramachandran.o edit_omega.o \ small_omega.o extract_h.o extract_o.o psi_from_ncacn.o \ is_standard.o extract_four_atoms.o chi1_from_ncacbcg.o \ chi1_from_ncacbsg.o chi1_from_ncacbcg1.o \ chi1_from_ncacbog.o chi1_from_ncacbog1.o \ chi2_from_cacbcgcd.o chi2_from_cacbcgod1.o \ chi2_from_cacbcgnd1.o chi2_from_cacbcg1cd.o \ chi2_from_cacbcgcd1.o chi2_from_cacbcgsd.o \ chi3_from_cbcgcdne.o chi3_from_cbcgcdoe1.o \ chi3_from_cbcgcdce.o chi3_from_cbcgsdce.o \ chi4_from_cgcdnecz.o chi4_from_cgcdcenz.o \ chi5_from_cdnecznh1.o is_part_of_ring.o edit_bond.o \ edit_chi2.o extract_cacb.o edit_chi1.o extract_cbxg.o \ resize_complex.o membrane.o inform_user.o \ alpha_membrane.o extract_ca.o extract_vector.o \ alpha_membrane_center.o init_membrane.o alpha_normal.o \ project_membranes.o draw_membranes.o \ rotate_membrane.o translate_membrane.o select_triplet.o \ set.o set_phi.o set_psi.o set_omega.o set_chi1.o set_chi2.o \ set_chi3.o extract_cgxd.o set_chi4.o extract_cdxe.o \ set_chi5.o extract_necz.o pick_bond.o nice_bonds.o \ covalent.o covalent2.o half_nice_bond.o probe.o \ small_atoms.o small_atoms2.o draw_sticks.o half_stick.o \ command_refresh.o acceptor_dipole.o donor_dipole.o sticks.o \ balls.o blur.o blur_main_window.o group.o beta_membrane.o \ extract_cg.o select_tm.o parse_pattern.o select_pattern.o \ hyphob_function1.o hyphob_function2.o hyphob_function3.o \ hyphob_function4.o hyphob_function5.o hyphob_function6.o \ hyphob_function7.o color_size.o command_dump.o is_aromatic.o \ select_2c3.o select_2cz3.o select_2nz3.o \ select_3c4.o select_3cz4.o select_3nz4.o \ select_3c5.o select_3cz5.o select_3nz5.o select_3p5.o \ select_4c5.o select_4cz5.o select_4nz5.o \ select_3c6.o select_3cz6.o select_3nz6.o \ select_4c6.o select_4cz6.o select_4nz6.o select_4p6.o \ select_5c6.o select_5cz6.o select_5nz6.o \ select_4c7.o select_4cz7.o select_4nz7.o \ select_5c7.o select_5cz7.o select_5nz7.o select_5p7.o \ select_6p7.o \ select_4c9.o select_4cz9.o select_4nz9.o \ select_5c9.o select_5cz9.o select_5nz9.o \ color_weighted.o garlic: $(OBJECTS) $(CC) -o garlic $(LIBPATH) $(OBJECTS) $(LINKOPT) print_usage.o: print_usage.c $(HEADERS) $(CC) -c $(CCOPT) print_usage.c print_help.o: print_help.c $(HEADERS) $(CC) -c $(CCOPT) print_help.c print_version.o: print_version.c $(HEADERS) $(CC) -c $(CCOPT) print_version.c register.o: register.c $(HEADERS) $(CC) -c $(CCOPT) register.c garlic.o: garlic.c $(HEADERS) $(CC) -c $(CCOPT) garlic.c alloc_gui.o: alloc_gui.c $(HEADERS) $(CC) -c $(CCOPT) alloc_gui.c alloc_config.o: alloc_config.c $(HEADERS) $(CC) -c $(CCOPT) alloc_config.c alloc_mol_complex.o: alloc_mol_complex.c $(HEADERS) $(CC) -c $(CCOPT) alloc_mol_complex.c free_memory.o: free_memory.c $(HEADERS) $(CC) -c $(CCOPT) free_memory.c display_init.o: display_init.c $(HEADERS) $(CC) -c $(CCOPT) display_init.c disp_color_cap.o: disp_color_cap.c $(HEADERS) $(CC) -c $(CCOPT) disp_color_cap.c color_shifts.o: color_shifts.c $(HEADERS) $(CC) -c $(CCOPT) color_shifts.c calc_params.o: calc_params.c $(HEADERS) $(CC) -c $(CCOPT) calc_params.c errmsg.o: errmsg.c $(HEADERS) $(CC) -c $(CCOPT) errmsg.c warnmsg.o: warnmsg.c $(HEADERS) $(CC) -c $(CCOPT) warnmsg.c openfile_r.o: openfile_r.c $(HEADERS) $(CC) -c $(CCOPT) openfile_r.c read_config.o: read_config.c $(HEADERS) $(CC) -c $(CCOPT) read_config.c open_config_file.o: open_config_file.c $(HEADERS) $(CC) -c $(CCOPT) open_config_file.c extract_int.o: extract_int.c $(HEADERS) $(CC) -c $(CCOPT) extract_int.c ex2ints.o: ex2ints.c $(HEADERS) $(CC) -c $(CCOPT) ex2ints.c extract_double.o: extract_double.c $(HEADERS) $(CC) -c $(CCOPT) extract_double.c ex2doubles.o: ex2doubles.c $(HEADERS) $(CC) -c $(CCOPT) ex2doubles.c extract_phrase.o: extract_phrase.c $(HEADERS) $(CC) -c $(CCOPT) extract_phrase.c extract_index.o: extract_index.c $(HEADERS) $(CC) -c $(CCOPT) extract_index.c ex_rot_steps.o: ex_rot_steps.c $(HEADERS) $(CC) -c $(CCOPT) ex_rot_steps.c ex_trans_steps.o: ex_trans_steps.c $(HEADERS) $(CC) -c $(CCOPT) ex_trans_steps.c ex_slab_steps.o: ex_slab_steps.c $(HEADERS) $(CC) -c $(CCOPT) ex_slab_steps.c ex_fading_steps.o: ex_fading_steps.c $(HEADERS) $(CC) -c $(CCOPT) ex_fading_steps.c extract_args.o: extract_args.c $(HEADERS) $(CC) -c $(CCOPT) extract_args.c parse_options.o: parse_options.c $(HEADERS) $(CC) -c $(CCOPT) parse_options.c parse_color.o: parse_color.c $(HEADERS) $(CC) -c $(CCOPT) parse_color.c load_font.o: load_font.c $(HEADERS) $(CC) -c $(CCOPT) load_font.c prepare_cursor.o: prepare_cursor.c $(HEADERS) $(CC) -c $(CCOPT) prepare_cursor.c print_config.o: print_config.c $(HEADERS) $(CC) -c $(CCOPT) print_config.c create_windows.o: create_windows.c $(HEADERS) garlic.xpm control.xpm $(CC) -c $(CCOPT) create_windows.c make_pixmap.o: make_pixmap.c $(HEADERS) $(CC) -c $(CCOPT) make_pixmap.c make_pixmap2.o: make_pixmap2.c $(HEADERS) $(CC) -c $(CCOPT) make_pixmap2.c rgbs_from_xcolor.o: rgbs_from_xcolor.c $(HEADERS) $(CC) -c $(CCOPT) rgbs_from_xcolor.c pixel_from_rgbs.o: pixel_from_rgbs.c $(HEADERS) $(CC) -c $(CCOPT) pixel_from_rgbs.c size_hints.o: size_hints.c $(HEADERS) $(CC) -c $(CCOPT) size_hints.c wmhints.o: wmhints.c $(HEADERS) $(CC) -c $(CCOPT) wmhints.c select_events.o: select_events.c $(HEADERS) $(CC) -c $(CCOPT) select_events.c hide_control.o: hide_control.c $(HEADERS) $(CC) -c $(CCOPT) hide_control.c load_complex.o: load_complex.c $(HEADERS) $(CC) -c $(CCOPT) load_complex.c read_file.o: read_file.c $(HEADERS) $(CC) -c $(CCOPT) read_file.c fileformat.o: fileformat.c $(HEADERS) $(CC) -c $(CCOPT) fileformat.c is_pdb.o: is_pdb.c $(HEADERS) $(CC) -c $(CCOPT) is_pdb.c read_pdb.o: read_pdb.c $(HEADERS) $(CC) -c $(CCOPT) read_pdb.c init_header.o: init_header.c $(HEADERS) $(CC) -c $(CCOPT) init_header.c pdb_atom.o: pdb_atom.c $(HEADERS) $(CC) -c $(CCOPT) pdb_atom.c extract_field.o: extract_field.c $(HEADERS) $(CC) -c $(CCOPT) extract_field.c copypur.o: copypur.c $(HEADERS) $(CC) -c $(CCOPT) copypur.c realloc_pdb.o: realloc_pdb.c $(HEADERS) $(CC) -c $(CCOPT) realloc_pdb.c headerline.o: headerline.c $(HEADERS) $(CC) -c $(CCOPT) headerline.c geomcenter.o: geomcenter.c $(HEADERS) $(CC) -c $(CCOPT) geomcenter.c init_slab.o: init_slab.c $(HEADERS) $(CC) -c $(CCOPT) init_slab.c init_fading.o: init_fading.c $(HEADERS) $(CC) -c $(CCOPT) init_fading.c flip_vector.o: flip_vector.c $(HEADERS) $(CC) -c $(CCOPT) flip_vector.c translate_complex.o: translate_complex.c $(HEADERS) $(CC) -c $(CCOPT) translate_complex.c extent.o: extent.c $(HEADERS) $(CC) -c $(CCOPT) extent.c stereo_data.o: stereo_data.c $(HEADERS) $(CC) -c $(CCOPT) stereo_data.c strong_bonds.o: strong_bonds.c $(HEADERS) $(CC) -c $(CCOPT) strong_bonds.c pseudo_bonds.o: pseudo_bonds.c $(HEADERS) $(CC) -c $(CCOPT) pseudo_bonds.c check_dist.o: check_dist.c $(HEADERS) $(CC) -c $(CCOPT) check_dist.c add_bond.o: add_bond.c $(HEADERS) $(CC) -c $(CCOPT) add_bond.c event_loop.o: event_loop.c $(HEADERS) $(CC) -c $(CCOPT) event_loop.c alloc_nearest.o: alloc_nearest.c $(HEADERS) $(CC) -c $(CCOPT) alloc_nearest.c init_nearest.o: init_nearest.c $(HEADERS) $(CC) -c $(CCOPT) init_nearest.c main_refresh.o: main_refresh.c $(HEADERS) $(CC) -c $(CCOPT) main_refresh.c key_press.o: key_press.c $(HEADERS) $(CC) -c $(CCOPT) key_press.c rotation_angle.o: rotation_angle.c $(HEADERS) $(CC) -c $(CCOPT) rotation_angle.c rotate.o: rotate.c $(HEADERS) $(CC) -c $(CCOPT) rotate.c translation_shift.o: translation_shift.c $(HEADERS) $(CC) -c $(CCOPT) translation_shift.c translate.o: translate.c $(HEADERS) $(CC) -c $(CCOPT) translate.c slab_shift.o: slab_shift.c $(HEADERS) $(CC) -c $(CCOPT) slab_shift.c move_back_slab.o: move_back_slab.c $(HEADERS) $(CC) -c $(CCOPT) move_back_slab.c move_front_slab.o: move_front_slab.c $(HEADERS) $(CC) -c $(CCOPT) move_front_slab.c fading_shift.o: fading_shift.c $(HEADERS) $(CC) -c $(CCOPT) fading_shift.c move_back_fading.o: move_back_fading.c $(HEADERS) $(CC) -c $(CCOPT) move_back_fading.c move_front_fading.o: move_front_fading.c $(HEADERS) $(CC) -c $(CCOPT) move_front_fading.c key_release.o: key_release.c $(HEADERS) $(CC) -c $(CCOPT) key_release.c refresh_pixmap.o: refresh_pixmap.c $(HEADERS) $(CC) -c $(CCOPT) refresh_pixmap.c slab.o: slab.c $(HEADERS) $(CC) -c $(CCOPT) slab.c no_slab.o: no_slab.c $(HEADERS) $(CC) -c $(CCOPT) no_slab.c planar_slab.o: planar_slab.c $(HEADERS) $(CC) -c $(CCOPT) planar_slab.c sphere_slab.o: sphere_slab.c $(HEADERS) $(CC) -c $(CCOPT) sphere_slab.c half_sphere_slab.o: half_sphere_slab.c $(HEADERS) $(CC) -c $(CCOPT) half_sphere_slab.c cylin_slab.o: cylin_slab.c $(HEADERS) $(CC) -c $(CCOPT) cylin_slab.c half_cylin_slab.o: half_cylin_slab.c $(HEADERS) $(CC) -c $(CCOPT) half_cylin_slab.c project_atoms.o: project_atoms.c $(HEADERS) $(CC) -c $(CCOPT) project_atoms.c fading.o: fading.c $(HEADERS) $(CC) -c $(CCOPT) fading.c prepare_color.o: prepare_color.c $(HEADERS) $(CC) -c $(CCOPT) prepare_color.c no_fading.o: no_fading.c $(HEADERS) $(CC) -c $(CCOPT) no_fading.c planar_fading.o: planar_fading.c $(HEADERS) $(CC) -c $(CCOPT) planar_fading.c sphere_fading.o: sphere_fading.c $(HEADERS) $(CC) -c $(CCOPT) sphere_fading.c half_sphere_fading.o: half_sphere_fading.c $(HEADERS) $(CC) -c $(CCOPT) half_sphere_fading.c cylin_fading.o: cylin_fading.c $(HEADERS) $(CC) -c $(CCOPT) cylin_fading.c half_cylin_fading.o: half_cylin_fading.c $(HEADERS) $(CC) -c $(CCOPT) half_cylin_fading.c reset_pos_flag.o: reset_pos_flag.c $(HEADERS) $(CC) -c $(CCOPT) reset_pos_flag.c atoms_style1.o: atoms_style1.c $(HEADERS) $(CC) -c $(CCOPT) atoms_style1.c atoms_style2.o: atoms_style2.c $(HEADERS) $(CC) -c $(CCOPT) atoms_style2.c atoms_style3.o: atoms_style3.c $(HEADERS) $(CC) -c $(CCOPT) atoms_style3.c atoms_style4.o: atoms_style4.c $(HEADERS) $(CC) -c $(CCOPT) atoms_style4.c atoms_style5.o: atoms_style5.c $(HEADERS) $(CC) -c $(CCOPT) atoms_style5.c atoms_style6.o: atoms_style6.c $(HEADERS) $(CC) -c $(CCOPT) atoms_style6.c atoms_style7.o: atoms_style7.c $(HEADERS) $(CC) -c $(CCOPT) atoms_style7.c bonds_style1.o: bonds_style1.c $(HEADERS) $(CC) -c $(CCOPT) bonds_style1.c bond_style1_quad1.o: bond_style1_quad1.c $(HEADERS) $(CC) -c $(CCOPT) bond_style1_quad1.c bond_style1_quad2.o: bond_style1_quad2.c $(HEADERS) $(CC) -c $(CCOPT) bond_style1_quad2.c bond_style1_quad3.o: bond_style1_quad3.c $(HEADERS) $(CC) -c $(CCOPT) bond_style1_quad3.c bond_style1_quad4.o: bond_style1_quad4.c $(HEADERS) $(CC) -c $(CCOPT) bond_style1_quad4.c bonds_style2.o: bonds_style2.c $(HEADERS) $(CC) -c $(CCOPT) bonds_style2.c bond_style2_quad1.o: bond_style2_quad1.c $(HEADERS) $(CC) -c $(CCOPT) bond_style2_quad1.c bond_style2_quad2.o: bond_style2_quad2.c $(HEADERS) $(CC) -c $(CCOPT) bond_style2_quad2.c bond_style2_quad3.o: bond_style2_quad3.c $(HEADERS) $(CC) -c $(CCOPT) bond_style2_quad3.c bond_style2_quad4.o: bond_style2_quad4.c $(HEADERS) $(CC) -c $(CCOPT) bond_style2_quad4.c bonds_style3.o: bonds_style3.c $(HEADERS) $(CC) -c $(CCOPT) bonds_style3.c interpolate_color.o: interpolate_color.c $(HEADERS) $(CC) -c $(CCOPT) interpolate_color.c bond_style3_quad1.o: bond_style3_quad1.c $(HEADERS) $(CC) -c $(CCOPT) bond_style3_quad1.c bond_style3_quad2.o: bond_style3_quad2.c $(HEADERS) $(CC) -c $(CCOPT) bond_style3_quad2.c bond_style3_quad3.o: bond_style3_quad3.c $(HEADERS) $(CC) -c $(CCOPT) bond_style3_quad3.c bond_style3_quad4.o: bond_style3_quad4.c $(HEADERS) $(CC) -c $(CCOPT) bond_style3_quad4.c bonds_style4.o: bonds_style4.c $(HEADERS) $(CC) -c $(CCOPT) bonds_style4.c add_two_colors.o: add_two_colors.c $(HEADERS) $(CC) -c $(CCOPT) add_two_colors.c bond_style4_quad1.o: bond_style4_quad1.c $(HEADERS) $(CC) -c $(CCOPT) bond_style4_quad1.c bond_style4_quad2.o: bond_style4_quad2.c $(HEADERS) $(CC) -c $(CCOPT) bond_style4_quad2.c bond_style4_quad3.o: bond_style4_quad3.c $(HEADERS) $(CC) -c $(CCOPT) bond_style4_quad3.c bond_style4_quad4.o: bond_style4_quad4.c $(HEADERS) $(CC) -c $(CCOPT) bond_style4_quad4.c bonds_style5.o: bonds_style5.c $(HEADERS) $(CC) -c $(CCOPT) bonds_style5.c add_three_colors.o: add_three_colors.c $(HEADERS) $(CC) -c $(CCOPT) add_three_colors.c bond_style5_quad1.o: bond_style5_quad1.c $(HEADERS) $(CC) -c $(CCOPT) bond_style5_quad1.c bond_style5_quad2.o: bond_style5_quad2.c $(HEADERS) $(CC) -c $(CCOPT) bond_style5_quad2.c bond_style5_quad3.o: bond_style5_quad3.c $(HEADERS) $(CC) -c $(CCOPT) bond_style5_quad3.c bond_style5_quad4.o: bond_style5_quad4.c $(HEADERS) $(CC) -c $(CCOPT) bond_style5_quad4.c draw_system.o: draw_system.c $(HEADERS) system.xpm $(CC) -c $(CCOPT) draw_system.c motion_notify.o: motion_notify.c $(HEADERS) $(CC) -c $(CCOPT) motion_notify.c assign_hyphob.o: assign_hyphob.c $(HEADERS) $(CC) -c $(CCOPT) assign_hyphob.c control_refresh.o: control_refresh.c $(HEADERS) $(CC) -c $(CCOPT) control_refresh.c print_cursor_names.o: print_cursor_names.c $(HEADERS) $(CC) -c $(CCOPT) print_cursor_names.c main_resize.o: main_resize.c $(HEADERS) $(CC) -c $(CCOPT) main_resize.c init_runtime.o: init_runtime.c $(HEADERS) $(CC) -c $(CCOPT) init_runtime.c add_char.o: add_char.c $(HEADERS) $(CC) -c $(CCOPT) add_char.c input_refresh.o: input_refresh.c $(HEADERS) $(CC) -c $(CCOPT) input_refresh.c eat_left_char.o: eat_left_char.c $(HEADERS) $(CC) -c $(CCOPT) eat_left_char.c eat_right_char.o: eat_right_char.c $(HEADERS) $(CC) -c $(CCOPT) eat_right_char.c execute_command1.o: execute_command1.c $(HEADERS) $(CC) -c $(CCOPT) execute_command1.c execute_command2.o: execute_command2.c $(HEADERS) $(CC) -c $(CCOPT) execute_command2.c truncate_comm.o: truncate_comm.c $(HEADERS) $(CC) -c $(CCOPT) truncate_comm.c create_log_file.o: create_log_file.c $(HEADERS) $(CC) -c $(CCOPT) create_log_file.c load.o: load.c $(HEADERS) $(CC) -c $(CCOPT) load.c catch.o: catch.c $(HEADERS) $(CC) -c $(CCOPT) catch.c discard.o: discard.c $(HEADERS) $(CC) -c $(CCOPT) discard.c select.o: select.c $(HEADERS) $(CC) -c $(CCOPT) select.c full_select.o: full_select.c $(HEADERS) $(CC) -c $(CCOPT) full_select.c include.o: include.c $(HEADERS) $(CC) -c $(CCOPT) include.c chains.o: chains.c $(HEADERS) $(CC) -c $(CCOPT) chains.c residue_ranges.o: residue_ranges.c $(HEADERS) $(CC) -c $(CCOPT) residue_ranges.c extract_token.o: extract_token.c $(HEADERS) $(CC) -c $(CCOPT) extract_token.c extract_serials.o: extract_serials.c $(HEADERS) $(CC) -c $(CCOPT) extract_serials.c residue_names.o: residue_names.c $(HEADERS) $(CC) -c $(CCOPT) residue_names.c atom_names.o: atom_names.c $(HEADERS) $(CC) -c $(CCOPT) atom_names.c exclude.o: exclude.c $(HEADERS) $(CC) -c $(CCOPT) exclude.c skip_keyword.o: skip_keyword.c $(HEADERS) $(CC) -c $(CCOPT) skip_keyword.c apply_selection.o: apply_selection.c $(HEADERS) $(CC) -c $(CCOPT) apply_selection.c show.o: show.c $(HEADERS) $(CC) -c $(CCOPT) show.c hide.o: hide.c $(HEADERS) $(CC) -c $(CCOPT) hide.c color_schemes.o: color_schemes.c $(HEADERS) $(CC) -c $(CCOPT) color_schemes.c init_colors.o: init_colors.c $(HEADERS) $(CC) -c $(CCOPT) init_colors.c color.o: color.c $(HEADERS) $(CC) -c $(CCOPT) color.c special_select.o: special_select.c $(HEADERS) $(CC) -c $(CCOPT) special_select.c select_hetero.o: select_hetero.c $(HEADERS) $(CC) -c $(CCOPT) select_hetero.c select_element.o: select_element.c $(HEADERS) $(CC) -c $(CCOPT) select_element.c select_atoms.o: select_atoms.c $(HEADERS) $(CC) -c $(CCOPT) select_atoms.c quick_select.o: quick_select.c $(HEADERS) $(CC) -c $(CCOPT) quick_select.c replace_command.o: replace_command.c $(HEADERS) $(CC) -c $(CCOPT) replace_command.c atoms.o: atoms.c $(HEADERS) $(CC) -c $(CCOPT) atoms.c bonds.o: bonds.c $(HEADERS) $(CC) -c $(CCOPT) bonds.c execute_script.o: execute_script.c $(HEADERS) $(CC) -c $(CCOPT) execute_script.c comm_rotate.o: comm_rotate.c $(HEADERS) $(CC) -c $(CCOPT) comm_rotate.c comm_translate.o: comm_translate.c $(HEADERS) $(CC) -c $(CCOPT) comm_translate.c comm_slab.o: comm_slab.c $(HEADERS) $(CC) -c $(CCOPT) comm_slab.c comm_fading.o: comm_fading.c $(HEADERS) $(CC) -c $(CCOPT) comm_fading.c log.o: log.c $(HEADERS) $(CC) -c $(CCOPT) log.c prepare_backbone.o: prepare_backbone.c $(HEADERS) $(CC) -c $(CCOPT) prepare_backbone.c background.o: background.c $(HEADERS) $(CC) -c $(CCOPT) background.c text_background.o: text_background.c $(HEADERS) $(CC) -c $(CCOPT) text_background.c text_foreground.o: text_foreground.c $(HEADERS) $(CC) -c $(CCOPT) text_foreground.c change_slab.o: change_slab.c $(HEADERS) $(CC) -c $(CCOPT) change_slab.c change_fading.o: change_fading.c $(HEADERS) $(CC) -c $(CCOPT) change_fading.c full_colors.o: full_colors.c $(HEADERS) $(CC) -c $(CCOPT) full_colors.c is_old.o: is_old.c $(HEADERS) $(CC) -c $(CCOPT) is_old.c font.o: font.c $(HEADERS) $(CC) -c $(CCOPT) font.c cpk.o: cpk.c $(HEADERS) $(CC) -c $(CCOPT) cpk.c zebra.o: zebra.c $(HEADERS) $(CC) -c $(CCOPT) zebra.c chain.o: chain.c $(HEADERS) $(CC) -c $(CCOPT) chain.c color_hyphob.o: color_hyphob.c $(HEADERS) $(CC) -c $(CCOPT) color_hyphob.c mix_colors.o: mix_colors.c $(HEADERS) $(CC) -c $(CCOPT) mix_colors.c comm_backbone.o: comm_backbone.c $(HEADERS) $(CC) -c $(CCOPT) comm_backbone.c hide_no_refresh.o: hide_no_refresh.c $(HEADERS) $(CC) -c $(CCOPT) hide_no_refresh.c show_no_refresh.o: show_no_refresh.c $(HEADERS) $(CC) -c $(CCOPT) show_no_refresh.c backbone.o: backbone.c $(HEADERS) $(CC) -c $(CCOPT) backbone.c hybonds.o: hybonds.c $(HEADERS) $(CC) -c $(CCOPT) hybonds.c generate_hybonds.o: generate_hybonds.c $(HEADERS) $(CC) -c $(CCOPT) generate_hybonds.c hybond_style.o: hybond_style.c $(HEADERS) $(CC) -c $(CCOPT) hybond_style.c show_backbone.o: show_backbone.c $(HEADERS) $(CC) -c $(CCOPT) show_backbone.c hide_backbone.o: hide_backbone.c $(HEADERS) $(CC) -c $(CCOPT) hide_backbone.c pdb_id.o: pdb_id.c $(HEADERS) $(CC) -c $(CCOPT) pdb_id.c generate_plane.o: generate_plane.c $(HEADERS) $(CC) -c $(CCOPT) generate_plane.c stereo.o: stereo.c $(HEADERS) $(CC) -c $(CCOPT) stereo.c mono.o: mono.c $(HEADERS) $(CC) -c $(CCOPT) mono.c position.o: position.c $(HEADERS) $(CC) -c $(CCOPT) position.c copy_doubles.o: copy_doubles.c $(HEADERS) $(CC) -c $(CCOPT) copy_doubles.c title.o: title.c $(HEADERS) $(CC) -c $(CCOPT) title.c free_runtime.o: free_runtime.c $(HEADERS) $(CC) -c $(CCOPT) free_runtime.c draw_titles.o: draw_titles.c $(HEADERS) $(CC) -c $(CCOPT) draw_titles.c foreground.o: foreground.c $(HEADERS) $(CC) -c $(CCOPT) foreground.c prepare_oc.o: prepare_oc.c $(HEADERS) $(CC) -c $(CCOPT) prepare_oc.c select_complement.o: select_complement.c $(HEADERS) $(CC) -c $(CCOPT) select_complement.c labels.o: labels.c $(HEADERS) $(CC) -c $(CCOPT) labels.c draw_labels.o: draw_labels.c $(HEADERS) $(CC) -c $(CCOPT) draw_labels.c assign_radii.o: assign_radii.c $(HEADERS) $(CC) -c $(CCOPT) assign_radii.c spacefill.o: spacefill.c $(HEADERS) $(CC) -c $(CCOPT) spacefill.c spacefill_color.o: spacefill_color.c $(HEADERS) $(CC) -c $(CCOPT) spacefill_color.c draw_balls.o: draw_balls.c $(HEADERS) $(CC) -c $(CCOPT) draw_balls.c center.o: center.c $(HEADERS) $(CC) -c $(CCOPT) center.c save.o: save.c $(HEADERS) $(CC) -c $(CCOPT) save.c write_line.o: write_line.c $(HEADERS) $(CC) -c $(CCOPT) write_line.c big_spheres.o: big_spheres.c $(HEADERS) $(CC) -c $(CCOPT) big_spheres.c tag.o: tag.c $(HEADERS) $(CC) -c $(CCOPT) tag.c draw_tags.o: draw_tags.c $(HEADERS) $(CC) -c $(CCOPT) draw_tags.c tag_position.o: tag_position.c $(HEADERS) $(CC) -c $(CCOPT) tag_position.c button_press.o: button_press.c $(HEADERS) $(CC) -c $(CCOPT) button_press.c control_click.o: control_click.c $(HEADERS) $(CC) -c $(CCOPT) control_click.c identify_button.o: identify_button.c $(HEADERS) $(CC) -c $(CCOPT) identify_button.c init_buttons.o: init_buttons.c $(HEADERS) $(CC) -c $(CCOPT) init_buttons.c write_hints.o: write_hints.c $(HEADERS) $(CC) -c $(CCOPT) write_hints.c extract_sequence.o: extract_sequence.c $(HEADERS) $(CC) -c $(CCOPT) extract_sequence.c count_residues.o: count_residues.c $(HEADERS) $(CC) -c $(CCOPT) count_residues.c sequence.o: sequence.c $(HEADERS) $(CC) -c $(CCOPT) sequence.c parse_sequence.o: parse_sequence.c $(HEADERS) $(CC) -c $(CCOPT) parse_sequence.c sequence_from.o: sequence_from.c $(HEADERS) $(CC) -c $(CCOPT) sequence_from.c load_sequence.o: load_sequence.c $(HEADERS) $(CC) -c $(CCOPT) load_sequence.c select_sequence.o: select_sequence.c $(HEADERS) $(CC) -c $(CCOPT) select_sequence.c compare_sequences.o: compare_sequences.c $(HEADERS) $(CC) -c $(CCOPT) compare_sequences.c dihedral_angles.o: dihedral_angles.c $(HEADERS) $(CC) -c $(CCOPT) dihedral_angles.c extract_ncaco.o: extract_ncaco.c $(HEADERS) $(CC) -c $(CCOPT) extract_ncaco.c phi_from_cncac.o: phi_from_cncac.c $(HEADERS) $(CC) -c $(CCOPT) phi_from_cncac.c psi_from_ncaco.o: psi_from_ncaco.c $(HEADERS) $(CC) -c $(CCOPT) psi_from_ncaco.c vector_product.o: vector_product.c $(HEADERS) $(CC) -c $(CCOPT) vector_product.c absolute_value.o: absolute_value.c $(HEADERS) $(CC) -c $(CCOPT) absolute_value.c scalar_product.o: scalar_product.c $(HEADERS) $(CC) -c $(CCOPT) scalar_product.c omega_from_cacnca.o: omega_from_cacnca.c $(HEADERS) $(CC) -c $(CCOPT) omega_from_cacnca.c select_cis_trans.o: select_cis_trans.c $(HEADERS) $(CC) -c $(CCOPT) select_cis_trans.c ramachandran.o: ramachandran.c $(HEADERS) $(CC) -c $(CCOPT) ramachandran.c draw_ramachandran.o: draw_ramachandran.c $(HEADERS) $(CC) -c $(CCOPT) draw_ramachandran.c rama_frame.o: rama_frame.c $(HEADERS) $(CC) -c $(CCOPT) rama_frame.c rama_mouse.o: rama_mouse.c $(HEADERS) $(CC) -c $(CCOPT) rama_mouse.c read_fasta.o: read_fasta.c $(HEADERS) $(CC) -c $(CCOPT) read_fasta.c save_sequence.o: save_sequence.c $(HEADERS) $(CC) -c $(CCOPT) save_sequence.c wheel.o: wheel.c $(HEADERS) $(CC) -c $(CCOPT) wheel.c wheel_top_view.o: wheel_top_view.c $(HEADERS) $(CC) -c $(CCOPT) wheel_top_view.c wheel_bottom_view.o: wheel_bottom_view.c $(HEADERS) $(CC) -c $(CCOPT) wheel_bottom_view.c hydrophobicity.o: hydrophobicity.c $(HEADERS) $(CC) -c $(CCOPT) hydrophobicity.c weight_colors.o: weight_colors.c $(HEADERS) $(CC) -c $(CCOPT) weight_colors.c angle.o: angle.c $(HEADERS) $(CC) -c $(CCOPT) angle.c radius.o: radius.c $(HEADERS) $(CC) -c $(CCOPT) radius.c select_sphere.o: select_sphere.c $(HEADERS) $(CC) -c $(CCOPT) select_sphere.c disulfide_bonds.o: disulfide_bonds.c $(HEADERS) $(CC) -c $(CCOPT) disulfide_bonds.c venn.o: venn.c $(HEADERS) $(CC) -c $(CCOPT) venn.c draw_venn.o: draw_venn.c $(HEADERS) $(CC) -c $(CCOPT) draw_venn.c spacefill2.o: spacefill2.c $(HEADERS) $(CC) -c $(CCOPT) spacefill2.c sp2_color.o: sp2_color.c $(HEADERS) $(CC) -c $(CCOPT) sp2_color.c save_seq_w_numbers.o: save_seq_w_numbers.c $(HEADERS) $(CC) -c $(CCOPT) save_seq_w_numbers.c ssb.o: ssb.c $(HEADERS) $(CC) -c $(CCOPT) ssb.c select_alternate.o: select_alternate.c $(HEADERS) $(CC) -c $(CCOPT) select_alternate.c select_model.o: select_model.c $(HEADERS) $(CC) -c $(CCOPT) select_model.c color_model.o: color_model.c $(HEADERS) $(CC) -c $(CCOPT) color_model.c window.o: window.c $(HEADERS) $(CC) -c $(CCOPT) window.c plot.o: plot.c $(HEADERS) $(CC) -c $(CCOPT) plot.c draw_plots.o: draw_plots.c $(HEADERS) $(CC) -c $(CCOPT) draw_plots.c weighted_hydrophobicity.o: weighted_hydrophobicity.c $(HEADERS) $(CC) -c $(CCOPT) weighted_hydrophobicity.c average_hydrophobicity.o: average_hydrophobicity.c $(HEADERS) $(CC) -c $(CCOPT) average_hydrophobicity.c init_hyphob.o: init_hyphob.c $(HEADERS) $(CC) -c $(CCOPT) init_hyphob.c plot_mouse.o: plot_mouse.c $(HEADERS) $(CC) -c $(CCOPT) plot_mouse.c project_planes.o: project_planes.c $(HEADERS) $(CC) -c $(CCOPT) project_planes.c draw_planes.o: draw_planes.c $(HEADERS) $(CC) -c $(CCOPT) draw_planes.c plane_extent.o: plane_extent.c $(HEADERS) $(CC) -c $(CCOPT) plane_extent.c rotate_plane.o: rotate_plane.c $(HEADERS) $(CC) -c $(CCOPT) rotate_plane.c translate_plane.o: translate_plane.c $(HEADERS) $(CC) -c $(CCOPT) translate_plane.c comm_move.o: comm_move.c $(HEADERS) $(CC) -c $(CCOPT) comm_move.c plane.o: plane.c $(HEADERS) $(CC) -c $(CCOPT) plane.c select_above.o: select_above.c $(HEADERS) $(CC) -c $(CCOPT) select_above.c select_below.o: select_below.c $(HEADERS) $(CC) -c $(CCOPT) select_below.c big2.o: big2.c $(HEADERS) $(CC) -c $(CCOPT) big2.c scale.o: scale.c $(HEADERS) $(CC) -c $(CCOPT) scale.c pattern.o: pattern.c $(HEADERS) $(CC) -c $(CCOPT) pattern.c dock.o: dock.c $(HEADERS) $(CC) -c $(CCOPT) dock.c align_normal.o: align_normal.c $(HEADERS) $(CC) -c $(CCOPT) align_normal.c align_complexes.o: align_complexes.c $(HEADERS) $(CC) -c $(CCOPT) align_complexes.c docking_window.o: docking_window.c $(HEADERS) docking.xpm $(CC) -c $(CCOPT) docking_window.c docking_resize.o: docking_resize.c $(HEADERS) $(CC) -c $(CCOPT) docking_resize.c docking_refresh.o: docking_refresh.c $(HEADERS) $(CC) -c $(CCOPT) docking_refresh.c docking_project.o: docking_project.c $(HEADERS) $(CC) -c $(CCOPT) docking_project.c list_exposed_polar.o: list_exposed_polar.c $(HEADERS) $(CC) -c $(CCOPT) list_exposed_polar.c is_polar.o: is_polar.c $(HEADERS) $(CC) -c $(CCOPT) is_polar.c representative_atoms.o: representative_atoms.c $(HEADERS) $(CC) -c $(CCOPT) representative_atoms.c exclude_distant.o: exclude_distant.c $(HEADERS) $(CC) -c $(CCOPT) exclude_distant.c draw_bottom.o: draw_bottom.c $(HEADERS) $(CC) -c $(CCOPT) draw_bottom.c draw_top.o: draw_top.c $(HEADERS) $(CC) -c $(CCOPT) draw_top.c copy_sequence.o: copy_sequence.c $(HEADERS) $(CC) -c $(CCOPT) copy_sequence.c compare.o: compare.c $(HEADERS) $(CC) -c $(CCOPT) compare.c draw_comparison.o: draw_comparison.c $(HEADERS) $(CC) -c $(CCOPT) draw_comparison.c neighborhood.o: neighborhood.c $(HEADERS) $(CC) -c $(CCOPT) neighborhood.c draw_balls2.o: draw_balls2.c $(HEADERS) $(CC) -c $(CCOPT) draw_balls2.c comparison_mouse.o: comparison_mouse.c $(HEADERS) $(CC) -c $(CCOPT) comparison_mouse.c structure.o: structure.c $(HEADERS) $(CC) -c $(CCOPT) structure.c parse_sec_structure.o: parse_sec_structure.c $(HEADERS) $(CC) -c $(CCOPT) parse_sec_structure.c copy_sec_structure.o: copy_sec_structure.c $(HEADERS) $(CC) -c $(CCOPT) copy_sec_structure.c load_sec_structure.o: load_sec_structure.c $(HEADERS) $(CC) -c $(CCOPT) load_sec_structure.c save_sec_structure.o: save_sec_structure.c $(HEADERS) $(CC) -c $(CCOPT) save_sec_structure.c alloc_sec_structure.o: alloc_sec_structure.c $(HEADERS) $(CC) -c $(CCOPT) alloc_sec_structure.c sec_structure_from.o: sec_structure_from.c $(HEADERS) $(CC) -c $(CCOPT) sec_structure_from.c create.o: create.c $(HEADERS) $(CC) -c $(CCOPT) create.c open_template_file.o: open_template_file.c $(HEADERS) $(CC) -c $(CCOPT) open_template_file.c read_template_file.o: read_template_file.c $(HEADERS) $(CC) -c $(CCOPT) read_template_file.c ex_template_residues.o: ex_template_residues.c $(HEADERS) $(CC) -c $(CCOPT) ex_template_residues.c count_template_res.o: count_template_res.c $(HEADERS) $(CC) -c $(CCOPT) count_template_res.c create_structure.o: create_structure.c $(HEADERS) $(CC) -c $(CCOPT) create_structure.c required_atoms.o: required_atoms.c $(HEADERS) $(CC) -c $(CCOPT) required_atoms.c copy_template_atoms.o: copy_template_atoms.c $(HEADERS) $(CC) -c $(CCOPT) copy_template_atoms.c fix_chain.o: fix_chain.c $(HEADERS) $(CC) -c $(CCOPT) fix_chain.c reset_phi.o: reset_phi.c $(HEADERS) $(CC) -c $(CCOPT) reset_phi.c extract_hncac.o: extract_hncac.c $(HEADERS) $(CC) -c $(CCOPT) extract_hncac.c phi_from_hncac.o: phi_from_hncac.c $(HEADERS) $(CC) -c $(CCOPT) phi_from_hncac.c rotate_atom.o: rotate_atom.c $(HEADERS) $(CC) -c $(CCOPT) rotate_atom.c parallel_part.o: parallel_part.c $(HEADERS) $(CC) -c $(CCOPT) parallel_part.c reset_psi.o: reset_psi.c $(HEADERS) $(CC) -c $(CCOPT) reset_psi.c build_chain.o: build_chain.c $(HEADERS) $(CC) -c $(CCOPT) build_chain.c extract_ncac.o: extract_ncac.c $(HEADERS) $(CC) -c $(CCOPT) extract_ncac.c translate_range.o: translate_range.c $(HEADERS) $(CC) -c $(CCOPT) translate_range.c rotate_range.o: rotate_range.c $(HEADERS) $(CC) -c $(CCOPT) rotate_range.c apply_structure.o: apply_structure.c $(HEADERS) $(CC) -c $(CCOPT) apply_structure.c generate_phi_psi.o: generate_phi_psi.c $(HEADERS) $(CC) -c $(CCOPT) generate_phi_psi.c extract_nca.o: extract_nca.c $(HEADERS) $(CC) -c $(CCOPT) extract_nca.c extract_c.o: extract_c.c $(HEADERS) $(CC) -c $(CCOPT) extract_c.c replace.o: replace.c $(HEADERS) $(CC) -c $(CCOPT) replace.c extract_n.o: extract_n.c $(HEADERS) $(CC) -c $(CCOPT) extract_n.c refresh_backbone.o: refresh_backbone.c $(HEADERS) $(CC) -c $(CCOPT) refresh_backbone.c edit.o: edit.c $(HEADERS) $(CC) -c $(CCOPT) edit.c draw_edit_symbol.o: draw_edit_symbol.c $(HEADERS) $(CC) -c $(CCOPT) draw_edit_symbol.c draw_squid.o: draw_squid.c $(HEADERS) squid.xpm $(CC) -c $(CCOPT) draw_squid.c draw_seahorse.o: draw_seahorse.c $(HEADERS) seahorse.xpm $(CC) -c $(CCOPT) draw_seahorse.c are_atoms_bound.o: are_atoms_bound.c $(HEADERS) $(CC) -c $(CCOPT) are_atoms_bound.c bond_partners.o: bond_partners.c $(HEADERS) $(CC) -c $(CCOPT) bond_partners.c edit_phi.o: edit_phi.c $(HEADERS) $(CC) -c $(CCOPT) edit_phi.c edit_psi.o: edit_psi.c $(HEADERS) $(CC) -c $(CCOPT) edit_psi.c extract_cac.o: extract_cac.c $(HEADERS) $(CC) -c $(CCOPT) extract_cac.c small_ramachandran.o: small_ramachandran.c $(HEADERS) $(CC) -c $(CCOPT) small_ramachandran.c edit_omega.o: edit_omega.c $(HEADERS) $(CC) -c $(CCOPT) edit_omega.c small_omega.o: small_omega.c $(HEADERS) $(CC) -c $(CCOPT) small_omega.c extract_h.o: extract_h.c $(HEADERS) $(CC) -c $(CCOPT) extract_h.c extract_o.o: extract_o.c $(HEADERS) $(CC) -c $(CCOPT) extract_o.c psi_from_ncacn.o: psi_from_ncacn.c $(HEADERS) $(CC) -c $(CCOPT) psi_from_ncacn.c is_standard.o: is_standard.c $(HEADERS) $(CC) -c $(CCOPT) is_standard.c extract_four_atoms.o: extract_four_atoms.c $(HEADERS) $(CC) -c $(CCOPT) extract_four_atoms.c chi1_from_ncacbcg.o: chi1_from_ncacbcg.c $(HEADERS) $(CC) -c $(CCOPT) chi1_from_ncacbcg.c chi1_from_ncacbsg.o: chi1_from_ncacbsg.c $(HEADERS) $(CC) -c $(CCOPT) chi1_from_ncacbsg.c chi1_from_ncacbcg1.o: chi1_from_ncacbcg1.c $(HEADERS) $(CC) -c $(CCOPT) chi1_from_ncacbcg1.c chi1_from_ncacbog.o: chi1_from_ncacbog.c $(HEADERS) $(CC) -c $(CCOPT) chi1_from_ncacbog.c chi1_from_ncacbog1.o: chi1_from_ncacbog1.c $(HEADERS) $(CC) -c $(CCOPT) chi1_from_ncacbog1.c chi2_from_cacbcgcd.o: chi2_from_cacbcgcd.c $(HEADERS) $(CC) -c $(CCOPT) chi2_from_cacbcgcd.c chi2_from_cacbcgod1.o: chi2_from_cacbcgod1.c $(HEADERS) $(CC) -c $(CCOPT) chi2_from_cacbcgod1.c chi2_from_cacbcgnd1.o: chi2_from_cacbcgnd1.c $(HEADERS) $(CC) -c $(CCOPT) chi2_from_cacbcgnd1.c chi2_from_cacbcg1cd.o: chi2_from_cacbcg1cd.c $(HEADERS) $(CC) -c $(CCOPT) chi2_from_cacbcg1cd.c chi2_from_cacbcgcd1.o: chi2_from_cacbcgcd1.c $(HEADERS) $(CC) -c $(CCOPT) chi2_from_cacbcgcd1.c chi2_from_cacbcgsd.o: chi2_from_cacbcgsd.c $(HEADERS) $(CC) -c $(CCOPT) chi2_from_cacbcgsd.c chi3_from_cbcgcdne.o: chi3_from_cbcgcdne.c $(HEADERS) $(CC) -c $(CCOPT) chi3_from_cbcgcdne.c chi3_from_cbcgcdoe1.o: chi3_from_cbcgcdoe1.c $(HEADERS) $(CC) -c $(CCOPT) chi3_from_cbcgcdoe1.c chi3_from_cbcgcdce.o: chi3_from_cbcgcdce.c $(HEADERS) $(CC) -c $(CCOPT) chi3_from_cbcgcdce.c chi3_from_cbcgsdce.o: chi3_from_cbcgsdce.c $(HEADERS) $(CC) -c $(CCOPT) chi3_from_cbcgsdce.c chi4_from_cgcdnecz.o: chi4_from_cgcdnecz.c $(HEADERS) $(CC) -c $(CCOPT) chi4_from_cgcdnecz.c chi4_from_cgcdcenz.o: chi4_from_cgcdcenz.c $(HEADERS) $(CC) -c $(CCOPT) chi4_from_cgcdcenz.c chi5_from_cdnecznh1.o: chi5_from_cdnecznh1.c $(HEADERS) $(CC) -c $(CCOPT) chi5_from_cdnecznh1.c is_part_of_ring.o: is_part_of_ring.c $(HEADERS) $(CC) -c $(CCOPT) is_part_of_ring.c edit_bond.o: edit_bond.c $(HEADERS) $(CC) -c $(CCOPT) edit_bond.c edit_chi2.o: edit_chi2.c $(HEADERS) $(CC) -c $(CCOPT) edit_chi2.c extract_cacb.o: extract_cacb.c $(HEADERS) $(CC) -c $(CCOPT) extract_cacb.c edit_chi1.o: edit_chi1.c $(HEADERS) $(CC) -c $(CCOPT) edit_chi1.c extract_cbxg.o: extract_cbxg.c $(HEADERS) $(CC) -c $(CCOPT) extract_cbxg.c resize_complex.o: resize_complex.c $(HEADERS) $(CC) -c $(CCOPT) resize_complex.c membrane.o: membrane.c $(HEADERS) $(CC) -c $(CCOPT) membrane.c inform_user.o: inform_user.c $(HEADERS) $(CC) -c $(CCOPT) inform_user.c alpha_membrane.o: alpha_membrane.c $(HEADERS) $(CC) -c $(CCOPT) alpha_membrane.c extract_ca.o: extract_ca.c $(HEADERS) $(CC) -c $(CCOPT) extract_ca.c extract_vector.o: extract_vector.c $(HEADERS) $(CC) -c $(CCOPT) extract_vector.c alpha_membrane_center.o: alpha_membrane_center.c $(HEADERS) $(CC) -c $(CCOPT) alpha_membrane_center.c init_membrane.o: init_membrane.c $(HEADERS) $(CC) -c $(CCOPT) init_membrane.c alpha_normal.o: alpha_normal.c $(HEADERS) $(CC) -c $(CCOPT) alpha_normal.c project_membranes.o: project_membranes.c $(HEADERS) $(CC) -c $(CCOPT) project_membranes.c draw_membranes.o: draw_membranes.c $(HEADERS) $(CC) -c $(CCOPT) draw_membranes.c rotate_membrane.o: rotate_membrane.c $(HEADERS) $(CC) -c $(CCOPT) rotate_membrane.c translate_membrane.o: translate_membrane.c $(HEADERS) $(CC) -c $(CCOPT) translate_membrane.c select_triplet.o: select_triplet.c $(HEADERS) $(CC) -c $(CCOPT) select_triplet.c set.o: set.c $(HEADERS) $(CC) -c $(CCOPT) set.c set_phi.o: set_phi.c $(HEADERS) $(CC) -c $(CCOPT) set_phi.c set_psi.o: set_psi.c $(HEADERS) $(CC) -c $(CCOPT) set_psi.c set_omega.o: set_omega.c $(HEADERS) $(CC) -c $(CCOPT) set_omega.c set_chi1.o: set_chi1.c $(HEADERS) $(CC) -c $(CCOPT) set_chi1.c set_chi2.o: set_chi2.c $(HEADERS) $(CC) -c $(CCOPT) set_chi2.c set_chi3.o: set_chi3.c $(HEADERS) $(CC) -c $(CCOPT) set_chi3.c extract_cgxd.o: extract_cgxd.c $(HEADERS) $(CC) -c $(CCOPT) extract_cgxd.c set_chi4.o: set_chi4.c $(HEADERS) $(CC) -c $(CCOPT) set_chi4.c extract_cdxe.o: extract_cdxe.c $(HEADERS) $(CC) -c $(CCOPT) extract_cdxe.c set_chi5.o: set_chi5.c $(HEADERS) $(CC) -c $(CCOPT) set_chi5.c extract_necz.o: extract_necz.c $(HEADERS) $(CC) -c $(CCOPT) extract_necz.c pick_bond.o: pick_bond.c $(HEADERS) $(CC) -c $(CCOPT) pick_bond.c nice_bonds.o: nice_bonds.c $(HEADERS) $(CC) -c $(CCOPT) nice_bonds.c covalent.o: covalent.c $(HEADERS) $(CC) -c $(CCOPT) covalent.c covalent2.o: covalent2.c $(HEADERS) $(CC) -c $(CCOPT) covalent2.c half_nice_bond.o: half_nice_bond.c $(HEADERS) $(CC) -c $(CCOPT) half_nice_bond.c probe.o: probe.c $(HEADERS) $(CC) -c $(CCOPT) probe.c small_atoms.o: small_atoms.c $(HEADERS) $(CC) -c $(CCOPT) small_atoms.c small_atoms2.o: small_atoms2.c $(HEADERS) $(CC) -c $(CCOPT) small_atoms2.c draw_sticks.o: draw_sticks.c $(HEADERS) $(CC) -c $(CCOPT) draw_sticks.c half_stick.o: half_stick.c $(HEADERS) $(CC) -c $(CCOPT) half_stick.c command_refresh.o: command_refresh.c $(HEADERS) $(CC) -c $(CCOPT) command_refresh.c acceptor_dipole.o: acceptor_dipole.c $(HEADERS) $(CC) -c $(CCOPT) acceptor_dipole.c donor_dipole.o: donor_dipole.c $(HEADERS) $(CC) -c $(CCOPT) donor_dipole.c sticks.o: sticks.c $(HEADERS) $(CC) -c $(CCOPT) sticks.c balls.o: balls.c $(HEADERS) $(CC) -c $(CCOPT) balls.c blur.o: blur.c $(HEADERS) $(CC) -c $(CCOPT) blur.c blur_main_window.o: blur_main_window.c $(HEADERS) $(CC) -c $(CCOPT) blur_main_window.c group.o: group.c $(HEADERS) $(CC) -c $(CCOPT) group.c beta_membrane.o: beta_membrane.c $(HEADERS) $(CC) -c $(CCOPT) beta_membrane.c extract_cg.o: extract_cg.c $(HEADERS) $(CC) -c $(CCOPT) extract_cg.c select_tm.o: select_tm.c $(HEADERS) $(CC) -c $(CCOPT) select_tm.c parse_pattern.o: parse_pattern.c $(HEADERS) $(CC) -c $(CCOPT) parse_pattern.c select_pattern.o: select_pattern.c $(HEADERS) $(CC) -c $(CCOPT) select_pattern.c hyphob_function1.o: hyphob_function1.c $(HEADERS) $(CC) -c $(CCOPT) hyphob_function1.c hyphob_function2.o: hyphob_function2.c $(HEADERS) $(CC) -c $(CCOPT) hyphob_function2.c hyphob_function3.o: hyphob_function3.c $(HEADERS) $(CC) -c $(CCOPT) hyphob_function3.c hyphob_function4.o: hyphob_function4.c $(HEADERS) $(CC) -c $(CCOPT) hyphob_function4.c hyphob_function5.o: hyphob_function5.c $(HEADERS) $(CC) -c $(CCOPT) hyphob_function5.c hyphob_function6.o: hyphob_function6.c $(HEADERS) $(CC) -c $(CCOPT) hyphob_function6.c hyphob_function7.o: hyphob_function7.c $(HEADERS) $(CC) -c $(CCOPT) hyphob_function7.c color_size.o: color_size.c $(HEADERS) $(CC) -c $(CCOPT) color_size.c command_dump.o: command_dump.c $(HEADERS) $(CC) -c $(CCOPT) command_dump.c is_aromatic.o: is_aromatic.c $(HEADERS) $(CC) -c $(CCOPT) is_aromatic.c select_2c3.o: select_2c3.c $(HEADERS) $(CC) -c $(CCOPT) select_2c3.c select_2cz3.o: select_2cz3.c $(HEADERS) $(CC) -c $(CCOPT) select_2cz3.c select_2nz3.o: select_2nz3.c $(HEADERS) $(CC) -c $(CCOPT) select_2nz3.c select_3c4.o: select_3c4.c $(HEADERS) $(CC) -c $(CCOPT) select_3c4.c select_3cz4.o: select_3cz4.c $(HEADERS) $(CC) -c $(CCOPT) select_3cz4.c select_3nz4.o: select_3nz4.c $(HEADERS) $(CC) -c $(CCOPT) select_3nz4.c select_3c5.o: select_3c5.c $(HEADERS) $(CC) -c $(CCOPT) select_3c5.c select_3cz5.o: select_3cz5.c $(HEADERS) $(CC) -c $(CCOPT) select_3cz5.c select_3nz5.o: select_3nz5.c $(HEADERS) $(CC) -c $(CCOPT) select_3nz5.c select_3p5.o: select_3p5.c $(HEADERS) $(CC) -c $(CCOPT) select_3p5.c select_4c5.o: select_4c5.c $(HEADERS) $(CC) -c $(CCOPT) select_4c5.c select_4cz5.o: select_4cz5.c $(HEADERS) $(CC) -c $(CCOPT) select_4cz5.c select_4nz5.o: select_4nz5.c $(HEADERS) $(CC) -c $(CCOPT) select_4nz5.c select_3c6.o: select_3c6.c $(HEADERS) $(CC) -c $(CCOPT) select_3c6.c select_3cz6.o: select_3cz6.c $(HEADERS) $(CC) -c $(CCOPT) select_3cz6.c select_3nz6.o: select_3nz6.c $(HEADERS) $(CC) -c $(CCOPT) select_3nz6.c select_4c6.o: select_4c6.c $(HEADERS) $(CC) -c $(CCOPT) select_4c6.c select_4cz6.o: select_4cz6.c $(HEADERS) $(CC) -c $(CCOPT) select_4cz6.c select_4nz6.o: select_4nz6.c $(HEADERS) $(CC) -c $(CCOPT) select_4nz6.c select_4p6.o: select_4p6.c $(HEADERS) $(CC) -c $(CCOPT) select_4p6.c select_5c6.o: select_5c6.c $(HEADERS) $(CC) -c $(CCOPT) select_5c6.c select_5cz6.o: select_5cz6.c $(HEADERS) $(CC) -c $(CCOPT) select_5cz6.c select_5nz6.o: select_5nz6.c $(HEADERS) $(CC) -c $(CCOPT) select_5nz6.c select_4c7.o: select_4c7.c $(HEADERS) $(CC) -c $(CCOPT) select_4c7.c select_4cz7.o: select_4cz7.c $(HEADERS) $(CC) -c $(CCOPT) select_4cz7.c select_4nz7.o: select_4nz7.c $(HEADERS) $(CC) -c $(CCOPT) select_4nz7.c select_5c7.o: select_5c7.c $(HEADERS) $(CC) -c $(CCOPT) select_5c7.c select_5cz7.o: select_5cz7.c $(HEADERS) $(CC) -c $(CCOPT) select_5cz7.c select_5nz7.o: select_5nz7.c $(HEADERS) $(CC) -c $(CCOPT) select_5nz7.c select_5p7.o: select_5p7.c $(HEADERS) $(CC) -c $(CCOPT) select_5p7.c select_6p7.o: select_6p7.c $(HEADERS) $(CC) -c $(CCOPT) select_6p7.c select_4c9.o: select_4c9.c $(HEADERS) $(CC) -c $(CCOPT) select_4c9.c select_4cz9.o: select_4cz9.c $(HEADERS) $(CC) -c $(CCOPT) select_4cz9.c select_4nz9.o: select_4nz9.c $(HEADERS) $(CC) -c $(CCOPT) select_4nz9.c select_5c9.o: select_5c9.c $(HEADERS) $(CC) -c $(CCOPT) select_5c9.c select_5cz9.o: select_5cz9.c $(HEADERS) $(CC) -c $(CCOPT) select_5cz9.c select_5nz9.o: select_5nz9.c $(HEADERS) $(CC) -c $(CCOPT) select_5nz9.c color_weighted.o: color_weighted.c $(HEADERS) $(CC) -c $(CCOPT) color_weighted.c garlic-1.6/generate_hybonds.c0000644000076500007650000004352010445775274016616 0ustar zuciczucic00000000000000/* Copyright (C) 2002-2003 Damir Zucic */ /*============================================================================= generate_hybonds.c Purpose: Generate hydrogen bonds. Scan every macromolecular complex, check every atom. This function generates the internal bonds; it is not enabled to generate the bonds between two complexes. If bonds are available already, just change the bond drawing style. This function was heavily modified since version 1.3, to improve the identification of hydrogen bonds. Four parameters are used to check the validity of hydrogen bonds: (1) r12, the distance between two electric dipoles. (2) cos_theta1, the cosine of the angle between the first dipole and the vector between these two dipoles. (3) cos_theta2, the cosine of the angle between the second dipole and the same vector. (4) cos_theta12, the cosine of the angle between two dipoles. The vector between two dipoles connects the dipole centers. The first dipole contains the hydrogen bond acceptor. The second dipole contains the hydrogen bond donor. The electric dipole direction is from negative charge to positive charge. Input: (1) Pointer to MolComplexS structure, with macromolec. complexes. (2) The number of macromolecular complexes. (3) Pointer to ConfigS structure, with configuration data. (4) The bond drawing style index. Output: (1) Hydrogen bonds generated. (2) Return value. Return value: The number of hydrogen bonds (unsigned long). Notes: (1) Indentation is exceptionally 4 spaces. (2) The chemical (element) symbol is right justified in PDB file. (3) This function may be quite slow if generating bonds for some large structure. Be patient! (4) The interaction energy for two electric dipoles, separated by the distance which is large compared to dipole sizes: U12 = (p1 . p2 - 3 (n . p2)(n . p2)) / d12 ^ 3, ... where p1 and p2 are two dipoles (vectors), n is direction of the vector which connects two dipole centers and d12 is the absolute value of this vector. (5) If the hydrogen bond donor is one nitrogen atom, the variable expected_bound_carbonsN will be equal to the number of carbon atoms bound to this nitrogen. This number will be either one or two. If the hydrogen bond donor is one oxygen atom, the expected_bound_carbonsN will be used as flag. The value of this flag will be -1 for OG atom from SER, -2 for OG1 atom from THR and -3 for OH atom from TYR. ========includes:============================================================*/ #include #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int ChangeHybondStyle_ (MolComplexS *, int); int AcceptorDipole_ (VectorS *, VectorS *, AtomS *, MolComplexS *, int); int DonorDipole_ (VectorS *, VectorS *, int, double, AtomS *, MolComplexS *, int); double AbsoluteValue_ (VectorS *); double ScalarProduct_ (VectorS *, VectorS *); int AddBond_ (AtomS *, int, int, int, size_t, double, int); /*======generate hydrogen bonds:=============================================*/ unsigned long GenerateHyBonds_ (MolComplexS *mol_complexSP, int mol_complexesN, ConfigS *configSP, int styleI) { unsigned long hydrogen_bondsN = 0; double min_dist, max_dist; double min_distance_squared, max_distance_squared; double half_NH_bond_length; int mol_complexI; MolComplexS *curr_mol_complexSP; size_t atomsN, atom1I, atom2I; AtomS *atom1SP, *atom2SP; char alt_location; RawAtomS *raw_atom1SP, *raw_atom2SP; char *pure_atom_nameP, *pure_residue_nameP; int acceptor_foundF, donor_foundF; int main_chain_oxygenF, main_chain_nitrogenF; int n; VectorS center_vector1S, unit_vector1S; int second_letter; int expected_bound_carbonsN = 2; size_t residue1_arrayI; int neighborsF; int bondI; TrueBondS *current_bondSP; AtomS *partner_atomSP; double delta_x, delta_y, delta_z; double distance_squared, distance; VectorS center_vector2S, unit_vector2S; VectorS r12_vectorS; double r12, reciprocal_r12; double cos_theta1, cos_theta2, cos_theta12; /* Geometric parameters: */ min_dist = configSP->hydro_bond_length_min; max_dist = configSP->hydro_bond_length_max; min_distance_squared = configSP->hydro_min_squared; max_distance_squared = configSP->hydro_max_squared; /* Half of N-H bond length (half angstrom, hard-coded in this function): */ half_NH_bond_length = 0.5; /* Check every macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check is the current macromolecular complex caught: */ if (curr_mol_complexSP->catchF == 0) continue; /* Prepare and check the number of atoms in this complex: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Hydrogen bonds may be available already; if this */ /* is the case just change the bond drawing style: */ if (curr_mol_complexSP->hydrogen_bondsF == 1) { ChangeHybondStyle_ (curr_mol_complexSP, styleI); continue; } /* The outer atomic loop: */ for (atom1I = 0; atom1I < atomsN; atom1I++) { /* Pointer to the current atom (outer loop): */ atom1SP = curr_mol_complexSP->atomSP + atom1I; /* Ignore atoms at alternate positions: */ alt_location = atom1SP->raw_atomS.alt_location; if ((alt_location != ' ') && (alt_location != 'A')) continue; /* Pointer to raw atomic data: */ raw_atom1SP = &atom1SP->raw_atomS; /* Check is this atom a hydrogen bond acceptor. */ /* Purified atom name and purified residue name: */ pure_atom_nameP = raw_atom1SP->pure_atom_nameA; pure_residue_nameP = raw_atom1SP->pure_residue_nameA; /* Set the initial value of acceptor flag: */ acceptor_foundF = 0; /* Reset the flag main_chain_oxygenF. This flag will be equal */ /* to one if the donor atom is the main chain oxygen atom: */ main_chain_oxygenF = 0; /* Check the chemical symbol: */ if (strcmp (raw_atom1SP->chemical_symbolA, " O") == 0) { /* All oxygen atoms except OH from TYR, OG from SER and */ /* OG1 from THR are candidates for hydrogen bond acceptor. */ /* Single pass loop: */ do { /* OH from TYR side chain: */ if (strcmp (pure_atom_nameP, "OH") == 0) break; /* OG from SER side chain: */ if (strcmp (pure_atom_nameP, "OG") == 0) break; /* OG1 from THR side chain: */ if (strcmp (pure_atom_nameP, "OG1") == 0) break; /* If this point is reached, this oxygen atom is */ /* a good candidate for hydrogen bond acceptor: */ acceptor_foundF = 1; /* End of single pass loop: */ } while (0); /* Check is this atom the main chain oxygen atom: */ if (strcmp (pure_atom_nameP, "O") == 0) main_chain_oxygenF = 1; } /* The NE2 atom from HIS side chain: */ else if (strcmp (pure_atom_nameP, "NE2") == 0) { if (strcmp (pure_residue_nameP, "HIS") == 0) acceptor_foundF = 1; } /* Check the acceptor flag: */ if (!acceptor_foundF) continue; /* If this point is reached, the current */ /* atom is valid hydrogen bond acceptor. */ /* Prepare two vectors required to define the first */ /* dipole: the dipole center position and the unit vector */ /* (pointing from negative charge to positive charge). */ n = AcceptorDipole_ (¢er_vector1S, &unit_vector1S, atom1SP, curr_mol_complexSP, mol_complexI); if (n < 0) continue; /* The inner atomic loop: */ for (atom2I = 0; atom2I < atomsN; atom2I++) { /* Pointer to the current atom (inner loop): */ atom2SP = curr_mol_complexSP->atomSP + atom2I; /* If this atom belongs to the same */ /* residue as the first atom, skip it: */ if (atom2SP->residue_arrayI == atom1SP->residue_arrayI) continue; /* Ignore atoms at alternate positions: */ alt_location = atom2SP->raw_atomS.alt_location; if ((alt_location != ' ') && (alt_location != 'A')) continue; /* Pointer to raw atomic data: */ raw_atom2SP = &atom2SP->raw_atomS; /* Check is this atom a hydrogen bond donor. */ /* Quick check - it must be either oxygen or nitrogen: */ second_letter = raw_atom2SP->chemical_symbolA[1]; if ((second_letter != 'O') && (second_letter != 'N')) continue; /* Precise checks: */ /* Purified atom name and purified residue name: */ pure_atom_nameP = raw_atom2SP->pure_atom_nameA; pure_residue_nameP = raw_atom2SP->pure_residue_nameA; /* Set the initial value of donor flag: */ donor_foundF = 0; /* Reset the flag main_chain_nitrogenF. This flag will be equal */ /* to one if the donor atom is the main chain nitrogen atom: */ main_chain_nitrogenF = 0; /* The main chain nitrogen atom: */ if (strcmp (pure_atom_nameP, "N") == 0) { main_chain_nitrogenF = 1; expected_bound_carbonsN = 2; donor_foundF = 1; } /* The ND1 atom from HIS side chain: */ else if (strcmp (pure_atom_nameP, "ND1") == 0) { if (strcmp (pure_residue_nameP, "HIS") == 0) { expected_bound_carbonsN = 2; donor_foundF = 1; } } /* The ND2 atom from ASN side chain: */ else if (strcmp (pure_atom_nameP, "ND2") == 0) { if (strcmp (pure_residue_nameP, "ASN") == 0) { expected_bound_carbonsN = 1; donor_foundF = 1; } } /* The NE atom from ARG side chain: */ else if (strcmp (pure_atom_nameP, "NE") == 0) { if (strcmp (pure_residue_nameP, "ARG") == 0) { expected_bound_carbonsN = 2; donor_foundF = 1; } } /* The NE1 atom from TRP side chain: */ else if (strcmp (pure_atom_nameP, "NE1") == 0) { expected_bound_carbonsN = 2; if (strcmp (pure_residue_nameP, "TRP") == 0) { expected_bound_carbonsN = 2; donor_foundF = 1; } } /* The NE2 atom from GLN side chain: */ else if (strcmp (pure_atom_nameP, "NE2") == 0) { if (strcmp (pure_residue_nameP, "GLN") == 0) { expected_bound_carbonsN = 1; donor_foundF = 1; } } /* The NZ atom from LYS side chain: */ else if (strcmp (pure_atom_nameP, "NZ") == 0) { if (strcmp (pure_residue_nameP, "LYS") == 0) { expected_bound_carbonsN = 1; donor_foundF = 1; } } /* The NH1 atom from ARG side chain: */ else if (strcmp (pure_atom_nameP, "NH1") == 0) { if (strcmp (pure_residue_nameP, "ARG") == 0) { expected_bound_carbonsN = 1; donor_foundF = 1; } } /* The NH2 atom from ARG side chain: */ else if (strcmp (pure_atom_nameP, "NH2") == 0) { if (strcmp (pure_residue_nameP, "ARG") == 0) { expected_bound_carbonsN = 1; donor_foundF = 1; } } /* The OG atom from SER side chain: */ else if (strcmp (pure_atom_nameP, "OG") == 0) { if (strcmp (pure_residue_nameP, "SER") == 0) { expected_bound_carbonsN = -1; donor_foundF = 1; } } /* The OG1 atom from THR side chain: */ else if (strcmp (pure_atom_nameP, "OG1") == 0) { if (strcmp (pure_residue_nameP, "THR") == 0) { expected_bound_carbonsN = -2; donor_foundF = 1; } } /* The OH atom from TYR side chain: */ else if (strcmp (pure_atom_nameP, "OH") == 0) { if (strcmp (pure_residue_nameP, "TYR") == 0) { expected_bound_carbonsN = -3; donor_foundF = 1; } } /* Check the donor flag: */ if (!donor_foundF) continue; /* If this point is reached, this */ /* atom is the hydrogen bond donor. */ /* There is a chance that both donor and acceptor belong */ /* to the main chain. If, in addition, they belong to */ /* neighboring residues, this pair should be skipped. */ if ((main_chain_oxygenF) && (main_chain_nitrogenF)) { /* Copy the residue array index of the acceptor atom: */ residue1_arrayI = atom1SP->residue_arrayI; /* Reset the flag neighborsF. This flag will be equal to */ /* one if donor and acceptor belong to neighboring residues: */ neighborsF = 0; /* Check is the donor atom bound to at least */ /* one atom which belongs to this residue. */ /* Scan all bond partners of the donor atom. */ for (bondI = 0; bondI < atom2SP->bondsN; bondI++) { /* Pointer to the current bond: */ current_bondSP = atom2SP->true_bondSA + bondI; /* The bond partner should belong to the same complex: */ if (current_bondSP->neighbor_mol_complexI != mol_complexI) { continue; } /* Prepare the pointer to the bond partner: */ partner_atomSP = curr_mol_complexSP->atomSP + current_bondSP->neighbor_arrayI; /* Check the residue array index: */ if (partner_atomSP->residue_arrayI == residue1_arrayI) { neighborsF = 1; break; } } /* If donor and acceptor belong to neighboring residues */ /* and to the main chain in the same time, skip this pair: */ if (neighborsF) continue; } /* Calculate and check coordinate differences: */ delta_x = atom1SP->raw_atomS.x[0] - atom2SP->raw_atomS.x[0]; if (delta_x > max_dist) continue; delta_y = atom1SP->raw_atomS.y - atom2SP->raw_atomS.y; if (delta_y > max_dist) continue; delta_z = atom1SP->raw_atomS.z[0] - atom2SP->raw_atomS.z[0]; if (delta_z > max_dist) continue; /* Calculate and check the squared distance between two atoms: */ distance_squared = delta_x * delta_x + delta_y * delta_y + delta_z * delta_z; if (distance_squared > max_distance_squared) continue; if (distance_squared < min_distance_squared) continue; /* If this point is reached, the two given atoms may be */ /* hydrogen-bonded. Now the precise checks should be done. */ /* Prepare two vectors required to define the second */ /* dipole: the dipole center position and the unit vector */ /* (pointing from negative charge to positive charge). */ n = DonorDipole_ (¢er_vector2S, &unit_vector2S, expected_bound_carbonsN, half_NH_bond_length, atom2SP, curr_mol_complexSP, mol_complexI); if (n < 0) continue; /* Calculate the parameters required to check the */ /* hydrogen bond: three cosines and one distance. */ /* Prepare the vector which connects the centers of two dipoles: */ r12_vectorS.x = center_vector2S.x - center_vector1S.x; r12_vectorS.y = center_vector2S.y - center_vector1S.y; r12_vectorS.z = center_vector2S.z - center_vector1S.z; /* Calculate and check the absolute value of this vector. */ /* In this step, use some simple cryteria about r12 range. */ r12 = AbsoluteValue_ (&r12_vectorS); if (r12 >= 4.5) continue; if (r12 <= 2.0) continue; /* This covers zero value! */ reciprocal_r12 = 1.0 / r12; /*@@*/ /* TEMPORARY CRUDE CHECK. REPLACE THIS LATER! */ if (r12 > 3.7) continue; /* Calculate and check cos_theta1, the cosine of the */ /* angle between the first dipole and the vector between */ /* two dipoles. This cosine belongs to the hydrogen bond */ /* acceptor. For most hydrogen bonds, cos_theta1 is quite */ /* close to -1. Discard bond if cos_theta1 is positive. */ cos_theta1 = reciprocal_r12 * ScalarProduct_ (&r12_vectorS, &unit_vector1S); if (cos_theta1 > 0.0) continue; /* Calculate and check cos_theta2, the cosine of the */ /* angle between the second dipole and the vector between */ /* two dipoles. This cosine belongs to the hydrogen bond */ /* donor. For most hydrogen bonds, cos_theta2 is quite */ /* close to -1. Discard bond if cos_theta1 is positive. */ cos_theta2 = reciprocal_r12 * ScalarProduct_ (&r12_vectorS, &unit_vector2S); if (cos_theta2 > 0.0) continue; /* Check the product of cos_theta1 and cos_theta2, it */ /* should be larger than 0.5 (based on statistics): */ if (cos_theta1 * cos_theta2 < 0.5) continue; /* Calculate and check cos_theta12, the cosine of the angle */ /* between two dipoles. This cosine should be positive too. */ cos_theta12 = ScalarProduct_ (&unit_vector1S, &unit_vector2S); if (cos_theta12 < 0.0) continue; /*@@*/ /* CONTINUE HERE! */ /*------------------------------------------------------*/ /* @@ Some job should be done to finish this function: */ /* (1) Collect and analyse the best structures. */ /* (2) Prepare the cryteria for decision what is a good */ /* hydrogen bond and what is not. */ /* (3) Add these cryteria to this function. */ /*------------------------------------------------------*/ /* If this point is reached, add a new */ /* bond to both atoms (O = 1, N = 2): */ distance = sqrt (distance_squared); AddBond_ (atom1SP, 0, 0, mol_complexI, atom2I, distance, styleI); AddBond_ (atom2SP, 0, 0, mol_complexI, atom1I, distance, styleI); /* Update the counter: */ hydrogen_bondsN++; /*@@*/ /* TEMPORARY CHANGES: */ if (r12 > max_dist) continue; /*@@*/ #ifdef PLAYING_WITH_HYBONDS /*@@*/ /*@@*/ /* CREATE DUMMY ATOMS: */ printf ("ATOM%7ld J JEL%6ld %8.3f%8.3f%8.3f 1.00 10.00\n", hydrogen_bondsN + 100, hydrogen_bondsN + 100, 10.0 * r12, 10.0 * cos_theta1, 10.0 * cos_theta2); #endif /*@@*/ #ifdef PLAYING_WITH_HYBONDS /*@@*/ printf ("%8.3f%8.3f%8.3f\n", r12, cos_theta1, cos_theta2); /*@@*/ #endif /*@@*/ } } /* Set flag which says that hydrogen bonds are available: */ curr_mol_complexSP->hydrogen_bondsF = 1; } /* End of mol_complexI loop */ /* Return the number of hydrogen bonds: */ return hydrogen_bondsN; } /*===========================================================================*/ garlic-1.6/average_hydrophobicity.c0000644000076500007650000000641507762114062020020 0ustar zuciczucic00000000000000/* Copyright (C) 2003 Damir Zucic */ /*============================================================================= average_hydrophobicity.c Purpose: Calculate the average hydrophobicity. Input: (1) Pointer to the storage where the minimal average hydrophobicity will be stored. (2) Pointer to the storage where the maximal average hydrophobicity will be stored. (3) Pointer to RuntimeS structure. Output: (1) Average hydrophobicity calculated and stored. (2) Return value. Return value: (1) Positive on success. (2) Negative on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======calculate the average hydrophobicity:================================*/ int AverageHydrophobicity_ (double *min_valueP, double *max_valueP, RuntimeS *runtimeSP) { int residuesN, residueI; /* Do not use size_t instead of int ! */ int used_residuesN; int window_width, half_window_width, windowI, combinedI; double hydrophobicity, average_hydrophobicity = 0; /*------prepare some parameters:---------------------------------------------*/ /* The number of residues in sequence buffer: */ residuesN = (int) runtimeSP->residuesN; if (residuesN == 0) return -1; /* The sliding window width: */ window_width = runtimeSP->sliding_window_width; half_window_width = window_width / 2; /*------calculate the average hydrophobicity:--------------------------------*/ /* Initialize the extreme values: */ *min_valueP = +999999.0; *max_valueP = -999999.0; /* Scan the sequence: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Reset the number of residues used for averaging: */ used_residuesN = 0; /* Reset the average hydrophobicity: */ average_hydrophobicity = 0.0; /* Scan the sliding window: */ for (windowI = 0; windowI < window_width; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI - half_window_width + windowI; if (combinedI < 0) continue; if (combinedI >= residuesN) continue; /* The hydrophobicity of the residue defined by combinedI: */ hydrophobicity = (double) *(runtimeSP->hydrophobicityP + combinedI); /* Add hydrophobicity to the total: */ average_hydrophobicity += hydrophobicity; /* Increase the number of residues used for averaging: */ used_residuesN++; } /* Check how many residues were used: */ if (used_residuesN == window_width) { average_hydrophobicity /= (double) window_width; } else average_hydrophobicity = 0.0; /* Store the average hydrophobicity: */ *(runtimeSP->average_hydrophobicityP + residueI) = average_hydrophobicity; /* Dummy values should not be used to determine extremes: */ if (used_residuesN != window_width) continue; /* Find the extreme values: */ if (average_hydrophobicity < *min_valueP) { *min_valueP = average_hydrophobicity; } if (average_hydrophobicity > *max_valueP) { *max_valueP = average_hydrophobicity; } /* End of residueI loop: */ } /*---------------------------------------------------------------------------*/ return 1; } /*===========================================================================*/ garlic-1.6/move_front_fading.c0000644000076500007650000000527407070340027016750 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= move_front_fading.c Purpose: Change the position of the front fading surface for each caught macromolecular complex. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. (3) Pointer to ConfigS structure. (4) Translation shift. Output: (1) The front fading surface moved. Return value: No return value. Notes: (1) Indentation is exceptionally 4 spaces. ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======move the front fading surface:=======================================*/ void MoveFrontFading_ (MolComplexS *mol_complexSP, int mol_complexesN, ConfigS *configSP, double shift) { int mol_complexI; MolComplexS *curr_mol_complexSP; for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check is the current macromolecular complex caught: */ if (curr_mol_complexSP->catchF == 0) continue; /* Move front fading surface: */ switch (curr_mol_complexSP->fading_modeI) { /* Planar fading: */ case 1: /* Prepare the new position: */ curr_mol_complexSP->fading_front_relative_position += shift; /* Check it: */ if (curr_mol_complexSP->fading_front_relative_position > curr_mol_complexSP->fading_back_relative_position - MINFADINGSPACING) { curr_mol_complexSP->fading_front_relative_position = curr_mol_complexSP->fading_back_relative_position - MINFADINGSPACING; } break; /* Spherical, semi-spher., cylindrical and semi-cyl. fading: */ case 2: case 3: case 4: case 5: /* Prepare the new position: */ curr_mol_complexSP->fading_front_relative_position -= shift; /* Check it: */ if (curr_mol_complexSP->fading_front_relative_position < curr_mol_complexSP->fading_back_relative_position + MINFADINGSPACING) { curr_mol_complexSP->fading_front_relative_position = curr_mol_complexSP->fading_back_relative_position + MINFADINGSPACING; } if (curr_mol_complexSP->fading_front_relative_position < 0) { curr_mol_complexSP->fading_front_relative_position = 0.0; } break; /* Ignore all other cases: */ default: ; } /* Set the position_changedF: */ curr_mol_complexSP->position_changedF = 1; } } /*===========================================================================*/ garlic-1.6/draw_top.c0000644000076500007650000001437007230077521015102 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= draw_top.c Purpose: Draw the exposed polar residues at the surface of the top complex. This complex is colored red. Hydrogen bond donors are shown as crosses, acceptors as circles and residues which may be both donors and acceptors are shown as combined crosses and circles. Input: (1) Pointer to GUIS structure. (2) Pointer to RuntimeS structure. Output: (1) Symbols drawn to docking window. (2) Return value. Return value: The number of symbols. ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======draw exposed polar residues of the top complex:======================*/ int DrawTop_ (GUIS *guiSP, RuntimeS *runtimeSP) { int symbolsN = 0; int exposed_polarN, exposed_polarI; MolComplexS *curr_mol_complexSP; int *exposed_atomIP; ExposedResidueS *exposed_polarSP; int geom_returnF; Window root_windowID; int x0, y0; unsigned int width, height, border_width, bpp; int square_width, half_square_width; int screen_center_x0, screen_center_y0; int screen_x0, screen_y0, screen_x1, screen_y1; int screen_delta_x, screen_delta_y; double docking_area_width; double scale_factor; int atom_screen_radius; double plane_center_x, plane_center_z; ExposedResidueS *curr_exposedSP; AtomS *curr_atomSP; double x, z; double relative_x, relative_z; double d; int screen_x, screen_y; int donorI; /* Copy pointers: */ exposed_polarN = runtimeSP->exposed_polar2N; curr_mol_complexSP = runtimeSP->mol_complex2SP; exposed_atomIP = runtimeSP->exposed_atom2IP; exposed_polarSP = runtimeSP->exposed_polar2SP; /* Docking window geometry: */ geom_returnF = XGetGeometry(guiSP->displaySP, guiSP->docking_winS.ID, &root_windowID, &x0, &y0, &width, &height, &border_width, &bpp); /* Prepare some geometric parameters: */ square_width = (int) width - 8 * (int) guiSP->docking_winS.border_width; if (height < width) square_width = (int) height - 8 * (int) guiSP->docking_winS.border_width; half_square_width = square_width / 2; screen_center_x0 = width / 2; screen_center_y0 = height / 2; screen_x0 = screen_center_x0 - half_square_width; screen_y0 = screen_center_y0 - half_square_width; screen_x1 = screen_center_x0 + half_square_width; screen_y1 = screen_center_y0 + half_square_width; screen_delta_x = screen_x1 - screen_x0; screen_delta_y = screen_y1 - screen_y0; docking_area_width = runtimeSP->docking_area_width; if (docking_area_width != 0.0) { scale_factor = square_width / docking_area_width; } else scale_factor = 0.0; atom_screen_radius = (int) (scale_factor * 2.0); /* Copy the plane center position (plane belongs to bottom complex): */ plane_center_x = runtimeSP->mol_complex1SP->planeS.center_x[0]; plane_center_z = runtimeSP->mol_complex1SP->planeS.center_z[0]; /* Prepare the red color: */ XSetForeground (guiSP->displaySP, guiSP->theGCA[0], guiSP->red_colorID); /* Scan the list of exposed polar residues: */ for (exposed_polarI = 0; exposed_polarI < exposed_polarN; exposed_polarI++) { /* Pointer to the current exposed polar residue: */ curr_exposedSP = exposed_polarSP + exposed_polarI; /* If this residue is excluded check the next one: */ if (curr_exposedSP->excludedF) continue; /* Pointer to the representative atom: */ curr_atomSP = curr_mol_complexSP->atomSP + curr_exposedSP->representative_atomI; /* Copy the atomic coordinates: */ x = curr_atomSP->raw_atomS.x[0]; z = curr_atomSP->raw_atomS.z[0]; /* Position of the atom relative to the plane center: */ relative_x = x - plane_center_x; relative_z = z - plane_center_z; /* Atomic coordinates in screen units: */ d = scale_factor * relative_z + screen_center_x0; screen_x = (int) d; d = scale_factor * relative_x + screen_center_y0; screen_y = (int) d; /* Check the screen coordinates: */ if ((screen_x < screen_x0) || (screen_x > screen_x1)) continue; if ((screen_y < screen_y0) || (screen_y > screen_y1)) continue; /* Prepare the color index: */ donorI = (int) curr_exposedSP->donorI; /* If the current residue is hydrogen bond donor, draw cross: */ if ((donorI == 1) || (donorI == 2)) { XDrawLine (guiSP->displaySP, guiSP->docking_winS.ID, guiSP->theGCA[0], screen_x, screen_y + atom_screen_radius, screen_x, screen_y - atom_screen_radius); XDrawLine (guiSP->displaySP, guiSP->docking_winS.ID, guiSP->theGCA[0], screen_x - 1, screen_y + atom_screen_radius, screen_x - 1, screen_y - atom_screen_radius); XDrawLine (guiSP->displaySP, guiSP->docking_winS.ID, guiSP->theGCA[0], screen_x + 1, screen_y + atom_screen_radius, screen_x + 1, screen_y - atom_screen_radius); XDrawLine (guiSP->displaySP, guiSP->docking_winS.ID, guiSP->theGCA[0], screen_x - atom_screen_radius, screen_y, screen_x + atom_screen_radius, screen_y); XDrawLine (guiSP->displaySP, guiSP->docking_winS.ID, guiSP->theGCA[0], screen_x - atom_screen_radius, screen_y - 1, screen_x + atom_screen_radius, screen_y - 1); XDrawLine (guiSP->displaySP, guiSP->docking_winS.ID, guiSP->theGCA[0], screen_x - atom_screen_radius, screen_y + 1, screen_x + atom_screen_radius, screen_y + 1); } /* If the current residue is hydrogen bond acceptor, draw circle: */ if ((donorI == 0) || (donorI == 2)) { XDrawArc (guiSP->displaySP, guiSP->docking_winS.ID, guiSP->theGCA[0], screen_x - atom_screen_radius, screen_y - atom_screen_radius, (unsigned int) (2 * atom_screen_radius), (unsigned int) (2 * atom_screen_radius), 0, 23040); XDrawArc (guiSP->displaySP, guiSP->docking_winS.ID, guiSP->theGCA[0], screen_x - atom_screen_radius - 1, screen_y - atom_screen_radius - 1, (unsigned int) (2 * atom_screen_radius + 2), (unsigned int) (2 * atom_screen_radius + 2), 0, 23040); } /* Increment the counter: */ symbolsN++; } /* Return the number of symbols drawn: */ return symbolsN; } /*===========================================================================*/ garlic-1.6/porins.list0000644000076500007650000000027510402251106015311 0ustar zuciczucic00000000000000# List of experimentally solved porins. # 16 porins may be found here, more should be added. # 2006/03/04. 2POR 1OPF 1PRN 1OSM 1E54 1MAL 1A0S 1BXW 1QJ8 2FCP 1FEP 1KMO 1QD5 1I78 1K24 1NQE garlic-1.6/select_2c3.c0000644000076500007650000001515410153564055015213 0ustar zuciczucic00000000000000/* Copyright (C) 2004 Damir Zucic */ /*============================================================================= select_2c3.c Purpose: Select the sequence fragment which contains two or more charged residues in a window of three residues. ASP, GLU, ARG, LYS and HIS are treated as charged. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. (3) Selection mode index (0 = overwrite, 1 = restrict, 2 = expand previous selection). Output: (1) The flag selectedF set to one for selected atoms in every caught macromolecular complex. (2) Return value. Return value: (1) The number of selected atoms (zero or positive value). ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======select fragments with two or more charged residues:==================*/ long Select2C3_ (MolComplexS *mol_complexSP, int mol_complexesN, int selection_modeI) { long selected_atomsN = 0; int mol_complexI; MolComplexS *curr_mol_complexSP; int atomsN, atomI; AtomS *curr_atomSP; int residuesN, residueI, windowI, combinedI; ResidueS *curr_residueSP; AtomS *first_atomSP; char *nameP; int chargedN; int first_atomI, last_atomI; /* Check every macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check is the current macromolecular complex caught: */ if (curr_mol_complexSP->catchF == 0) continue; /* Prepare and check the number of atoms in the current complex: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Copy the number of residues in the current macromol. complex: */ residuesN = curr_mol_complexSP->residuesN; if (residuesN == 0) continue; /* Backup the current selection if selection mode is restrict: */ if (selection_modeI == 1) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Copy the selection flag: */ curr_atomSP->previous_selectedF = curr_atomSP->selectedF; } } /* Unselect everything if selection mode is overwrite or restrict: */ if ((selection_modeI == 0) || (selection_modeI == 1)) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Unselect the current atom: */ curr_atomSP->selectedF = 0; } } /* Scan the residues of the current macromolecular complex: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Reset the counter which counts charged residues: */ chargedN = 0; /* Scan the window of three residues, */ /* starting from the current residue: */ for (windowI = 0; windowI < 3; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI >= residuesN) break; /* Residue associated with the combined index: */ curr_residueSP = curr_mol_complexSP->residueSP + combinedI; /* Pointer to the first atom of current residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Pointer to the name of the current residue: */ nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Check is this residue charged: */ if ((strcmp (nameP, "ASP") == 0) || (strcmp (nameP, "GLU") == 0) || (strcmp (nameP, "ARG") == 0) || (strcmp (nameP, "LYS") == 0) || (strcmp (nameP, "HIS") == 0)) chargedN++; } /* If there were two or more charged residues in a */ /* window of three residues, the dublet is found. */ /* If there was one or less, take the next residue. */ if (chargedN < 2) continue; /* If this point is reached, scan the window of three */ /* residues again and select all charged residues. */ /* Scan the window of three residues, */ /* starting from the current residue: */ for (windowI = 0; windowI < 3; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI >= residuesN) break; /* Residue associated with the combined index: */ curr_residueSP = curr_mol_complexSP->residueSP + combinedI; /* Pointer to the first atom of current residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Pointer to the name of the current residue: */ nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Check is this residue charged: */ if ((strcmp (nameP, "ASP") != 0) && (strcmp (nameP, "GLU") != 0) && (strcmp (nameP, "ARG") != 0) && (strcmp (nameP, "LYS") != 0) && (strcmp (nameP, "HIS") != 0)) continue; /* If this point is reached, select */ /* all atoms of the current residue. */ /* The indices of the first and the */ /* last atom of the current residue: */ first_atomI = curr_residueSP->residue_startI; last_atomI = curr_residueSP->residue_endI; /* Select all atoms of the current residue: */ for (atomI = first_atomI; atomI <= last_atomI; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Select the current atom: */ curr_atomSP->selectedF = 1; /* Update the counter of selected atoms: */ selected_atomsN++; } } /* End of residueI loop: */ } /* Combine the current selection with the */ /* previous, if selection mode is restrict: */ if (selection_modeI == 1) { /* Reset the counter of selected atoms. The */ /* selected atoms should be counted again. */ selected_atomsN = 0; /* Combine the old and the new selection flag: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Combine selection flags: */ curr_atomSP->selectedF *= curr_atomSP->previous_selectedF; /* Check the selection flag; increase */ /* the count of selected residues if */ /* the selection flag is equal to one: */ if (curr_atomSP->selectedF) selected_atomsN++; } } /* Update the position_changedF (some atoms may have bad color): */ curr_mol_complexSP->position_changedF = 1; /* End of mol_complexI loop: */ } /* Return the number of selected atoms: */ return selected_atomsN; } /*===========================================================================*/ garlic-1.6/select_3c4.c0000644000076500007650000001515110140132212015170 0ustar zuciczucic00000000000000/* Copyright (C) 2004 Damir Zucic */ /*============================================================================= select_3c4.c Purpose: Select the sequence fragment which contains three or more charged residues in a window of four residues. ASP, GLU, ARG, LYS and HIS are treated as charged. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. (3) Selection mode index (0 = overwrite, 1 = restrict, 2 = expand previous selection). Output: (1) The flag selectedF set to one for selected atoms in every caught macromolecular complex. (2) Return value. Return value: (1) The number of selected atoms (zero or positive value). ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======select fragments with three or more charged residues:================*/ long Select3C4_ (MolComplexS *mol_complexSP, int mol_complexesN, int selection_modeI) { long selected_atomsN = 0; int mol_complexI; MolComplexS *curr_mol_complexSP; int atomsN, atomI; AtomS *curr_atomSP; int residuesN, residueI, windowI, combinedI; ResidueS *curr_residueSP; AtomS *first_atomSP; char *nameP; int chargedN; int first_atomI, last_atomI; /* Check every macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check is the current macromolecular complex caught: */ if (curr_mol_complexSP->catchF == 0) continue; /* Prepare and check the number of atoms in the current complex: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Copy the number of residues in the current macromol. complex: */ residuesN = curr_mol_complexSP->residuesN; if (residuesN == 0) continue; /* Backup the current selection if selection mode is restrict: */ if (selection_modeI == 1) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Copy the selection flag: */ curr_atomSP->previous_selectedF = curr_atomSP->selectedF; } } /* Unselect everything if selection mode is overwrite or restrict: */ if ((selection_modeI == 0) || (selection_modeI == 1)) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Unselect the current atom: */ curr_atomSP->selectedF = 0; } } /* Scan the residues of the current macromolecular complex: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Reset the counter which counts charged residues: */ chargedN = 0; /* Scan the window of four residues, */ /* starting from the current residue: */ for (windowI = 0; windowI < 4; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI >= residuesN) break; /* Residue associated with the combined index: */ curr_residueSP = curr_mol_complexSP->residueSP + combinedI; /* Pointer to the first atom of current residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Pointer to the name of the current residue: */ nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Check is this residue charged: */ if ((strcmp (nameP, "ASP") == 0) || (strcmp (nameP, "GLU") == 0) || (strcmp (nameP, "ARG") == 0) || (strcmp (nameP, "LYS") == 0) || (strcmp (nameP, "HIS") == 0)) chargedN++; } /* If there were three or more charged residues in */ /* a window of four residues, the triplet is found. */ /* If there were two or less, take the next residue. */ if (chargedN < 3) continue; /* If this point is reached, scan the window of four */ /* residues again and select all charged residues. */ /* Scan the window of four residues, */ /* starting from the current residue: */ for (windowI = 0; windowI < 4; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI >= residuesN) break; /* Residue associated with the combined index: */ curr_residueSP = curr_mol_complexSP->residueSP + combinedI; /* Pointer to the first atom of current residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Pointer to the name of the current residue: */ nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Check is this residue charged: */ if ((strcmp (nameP, "ASP") != 0) && (strcmp (nameP, "GLU") != 0) && (strcmp (nameP, "ARG") != 0) && (strcmp (nameP, "LYS") != 0) && (strcmp (nameP, "HIS") != 0)) continue; /* If this point is reached, select */ /* all atoms of the current residue. */ /* The indices of the first and the */ /* last atom of the current residue: */ first_atomI = curr_residueSP->residue_startI; last_atomI = curr_residueSP->residue_endI; /* Select all atoms of the current residue: */ for (atomI = first_atomI; atomI <= last_atomI; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Select the current atom: */ curr_atomSP->selectedF = 1; /* Update the counter of selected atoms: */ selected_atomsN++; } } /* End of residueI loop: */ } /* Combine the current selection with the */ /* previous, if selection mode is restrict: */ if (selection_modeI == 1) { /* Reset the counter of selected atoms. The */ /* selected atoms should be counted again. */ selected_atomsN = 0; /* Combine the old and the new selection flag: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Combine selection flags: */ curr_atomSP->selectedF *= curr_atomSP->previous_selectedF; /* Check the selection flag; increase */ /* the count of selected residues if */ /* the selection flag is equal to one: */ if (curr_atomSP->selectedF) selected_atomsN++; } } /* Update the position_changedF (some atoms may have bad color): */ curr_mol_complexSP->position_changedF = 1; /* End of mol_complexI loop: */ } /* Return the number of selected atoms: */ return selected_atomsN; } /*===========================================================================*/ garlic-1.6/select_3c5.c0000644000076500007650000001515110140122073015175 0ustar zuciczucic00000000000000/* Copyright (C) 2004 Damir Zucic */ /*============================================================================= select_3c5.c Purpose: Select the sequence fragment which contains three or more charged residues in a window of five residues. ASP, GLU, ARG, LYS and HIS are treated as charged. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. (3) Selection mode index (0 = overwrite, 1 = restrict, 2 = expand previous selection). Output: (1) The flag selectedF set to one for selected atoms in every caught macromolecular complex. (2) Return value. Return value: (1) The number of selected atoms (zero or positive value). ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======select fragments with three or more charged residues:================*/ long Select3C5_ (MolComplexS *mol_complexSP, int mol_complexesN, int selection_modeI) { long selected_atomsN = 0; int mol_complexI; MolComplexS *curr_mol_complexSP; int atomsN, atomI; AtomS *curr_atomSP; int residuesN, residueI, windowI, combinedI; ResidueS *curr_residueSP; AtomS *first_atomSP; char *nameP; int chargedN; int first_atomI, last_atomI; /* Check every macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check is the current macromolecular complex caught: */ if (curr_mol_complexSP->catchF == 0) continue; /* Prepare and check the number of atoms in the current complex: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Copy the number of residues in the current macromol. complex: */ residuesN = curr_mol_complexSP->residuesN; if (residuesN == 0) continue; /* Backup the current selection if selection mode is restrict: */ if (selection_modeI == 1) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Copy the selection flag: */ curr_atomSP->previous_selectedF = curr_atomSP->selectedF; } } /* Unselect everything if selection mode is overwrite or restrict: */ if ((selection_modeI == 0) || (selection_modeI == 1)) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Unselect the current atom: */ curr_atomSP->selectedF = 0; } } /* Scan the residues of the current macromolecular complex: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Reset the counter which counts charged residues: */ chargedN = 0; /* Scan the window of five residues, */ /* starting from the current residue: */ for (windowI = 0; windowI < 5; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI >= residuesN) break; /* Residue associated with the combined index: */ curr_residueSP = curr_mol_complexSP->residueSP + combinedI; /* Pointer to the first atom of current residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Pointer to the name of the current residue: */ nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Check is this residue charged: */ if ((strcmp (nameP, "ASP") == 0) || (strcmp (nameP, "GLU") == 0) || (strcmp (nameP, "ARG") == 0) || (strcmp (nameP, "LYS") == 0) || (strcmp (nameP, "HIS") == 0)) chargedN++; } /* If there were three or more charged residues in */ /* a window of five residues, the triplet is found. */ /* If there were two or less, take the next residue. */ if (chargedN < 3) continue; /* If this point is reached, scan the window of five */ /* residues again and select all charged residues. */ /* Scan the window of five residues, */ /* starting from the current residue: */ for (windowI = 0; windowI < 5; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI >= residuesN) break; /* Residue associated with the combined index: */ curr_residueSP = curr_mol_complexSP->residueSP + combinedI; /* Pointer to the first atom of current residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Pointer to the name of the current residue: */ nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Check is this residue charged: */ if ((strcmp (nameP, "ASP") != 0) && (strcmp (nameP, "GLU") != 0) && (strcmp (nameP, "ARG") != 0) && (strcmp (nameP, "LYS") != 0) && (strcmp (nameP, "HIS") != 0)) continue; /* If this point is reached, select */ /* all atoms of the current residue. */ /* The indices of the first and the */ /* last atom of the current residue: */ first_atomI = curr_residueSP->residue_startI; last_atomI = curr_residueSP->residue_endI; /* Select all atoms of the current residue: */ for (atomI = first_atomI; atomI <= last_atomI; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Select the current atom: */ curr_atomSP->selectedF = 1; /* Update the counter of selected atoms: */ selected_atomsN++; } } /* End of residueI loop: */ } /* Combine the current selection with the */ /* previous, if selection mode is restrict: */ if (selection_modeI == 1) { /* Reset the counter of selected atoms. The */ /* selected atoms should be counted again. */ selected_atomsN = 0; /* Combine the old and the new selection flag: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Combine selection flags: */ curr_atomSP->selectedF *= curr_atomSP->previous_selectedF; /* Check the selection flag; increase */ /* the count of selected residues if */ /* the selection flag is equal to one: */ if (curr_atomSP->selectedF) selected_atomsN++; } } /* Update the position_changedF (some atoms may have bad color): */ curr_mol_complexSP->position_changedF = 1; /* End of mol_complexI loop: */ } /* Return the number of selected atoms: */ return selected_atomsN; } /*===========================================================================*/ garlic-1.6/select_3c6.c0000644000076500007650000001515110140122201015167 0ustar zuciczucic00000000000000/* Copyright (C) 2004 Damir Zucic */ /*============================================================================= select_3c6.c Purpose: Select the sequence fragment which contains three or more charged residues in a window of six residues. ASP, GLU, ARG, LYS and HIS are treated as charged. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. (3) Selection mode index (0 = overwrite, 1 = restrict, 2 = expand previous selection). Output: (1) The flag selectedF set to one for selected atoms in every caught macromolecular complex. (2) Return value. Return value: (1) The number of selected atoms (zero or positive value). ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======select fragments with three or more charged residues:================*/ long Select3C6_ (MolComplexS *mol_complexSP, int mol_complexesN, int selection_modeI) { long selected_atomsN = 0; int mol_complexI; MolComplexS *curr_mol_complexSP; int atomsN, atomI; AtomS *curr_atomSP; int residuesN, residueI, windowI, combinedI; ResidueS *curr_residueSP; AtomS *first_atomSP; char *nameP; int chargedN; int first_atomI, last_atomI; /* Check every macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check is the current macromolecular complex caught: */ if (curr_mol_complexSP->catchF == 0) continue; /* Prepare and check the number of atoms in the current complex: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Copy the number of residues in the current macromol. complex: */ residuesN = curr_mol_complexSP->residuesN; if (residuesN == 0) continue; /* Backup the current selection if selection mode is restrict: */ if (selection_modeI == 1) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Copy the selection flag: */ curr_atomSP->previous_selectedF = curr_atomSP->selectedF; } } /* Unselect everything if selection mode is overwrite or restrict: */ if ((selection_modeI == 0) || (selection_modeI == 1)) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Unselect the current atom: */ curr_atomSP->selectedF = 0; } } /* Scan the residues of the current macromolecular complex: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Reset the counter which counts charged residues: */ chargedN = 0; /* Scan the window of six residues, */ /* starting from the current residue: */ for (windowI = 0; windowI < 6; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI >= residuesN) break; /* Residue associated with the combined index: */ curr_residueSP = curr_mol_complexSP->residueSP + combinedI; /* Pointer to the first atom of current residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Pointer to the name of the current residue: */ nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Check is this residue charged: */ if ((strcmp (nameP, "ASP") == 0) || (strcmp (nameP, "GLU") == 0) || (strcmp (nameP, "ARG") == 0) || (strcmp (nameP, "LYS") == 0) || (strcmp (nameP, "HIS") == 0)) chargedN++; } /* If there were three or more charged residues in */ /* a window of six residues, the triplet is found. */ /* If there were two or less, take the next residue. */ if (chargedN < 3) continue; /* If this point is reached, scan the window of six */ /* residues again and select all charged residues. */ /* Scan the window of six residues, */ /* starting from the current residue: */ for (windowI = 0; windowI < 6; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI >= residuesN) break; /* Residue associated with the combined index: */ curr_residueSP = curr_mol_complexSP->residueSP + combinedI; /* Pointer to the first atom of current residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Pointer to the name of the current residue: */ nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Check is this residue charged: */ if ((strcmp (nameP, "ASP") != 0) && (strcmp (nameP, "GLU") != 0) && (strcmp (nameP, "ARG") != 0) && (strcmp (nameP, "LYS") != 0) && (strcmp (nameP, "HIS") != 0)) continue; /* If this point is reached, select */ /* all atoms of the current residue. */ /* The indices of the first and the */ /* last atom of the current residue: */ first_atomI = curr_residueSP->residue_startI; last_atomI = curr_residueSP->residue_endI; /* Select all atoms of the current residue: */ for (atomI = first_atomI; atomI <= last_atomI; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Select the current atom: */ curr_atomSP->selectedF = 1; /* Update the counter of selected atoms: */ selected_atomsN++; } } /* End of residueI loop: */ } /* Combine the current selection with the */ /* previous, if selection mode is restrict: */ if (selection_modeI == 1) { /* Reset the counter of selected atoms. The */ /* selected atoms should be counted again. */ selected_atomsN = 0; /* Combine the old and the new selection flag: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Combine selection flags: */ curr_atomSP->selectedF *= curr_atomSP->previous_selectedF; /* Check the selection flag; increase */ /* the count of selected residues if */ /* the selection flag is equal to one: */ if (curr_atomSP->selectedF) selected_atomsN++; } } /* Update the position_changedF (some atoms may have bad color): */ curr_mol_complexSP->position_changedF = 1; /* End of mol_complexI loop: */ } /* Return the number of selected atoms: */ return selected_atomsN; } /*===========================================================================*/ garlic-1.6/is_part_of_ring.c0000644000076500007650000002033407747301703016431 0ustar zuciczucic00000000000000/* Copyright (C) 2001-2003 Damir Zucic */ /*============================================================================= is_part_of_ring.c Purpose: Check is the specified bond part of a ring or of some other closed structural element. The array indices of two atoms which form the bond are used to specify the chosen bond. Input: (1) Pointer to MolComplexS structure. (2) The macromolecular complex index. (3) The array index of the first atom of the chosen bond. (4) The array index of the second atom of the chosen bond. Output: (1) Return value. Return value: (1) Positive if bond is part of a ring. (2) Zero if the specified bond is not involved in formation of a ring or some other closed structural element. (3) Negative, if the macromolecular complex contains no atoms, if two specified atoms do not belong to the same residue or if this residue does not contain any atoms (rather strange). Notes: (1) Imagine that chemical bonds form a system of tunnels dug in a mountain. Atoms are treated as places where two, three or more tunnels are connected. The shock wave is initiated starting at the position of the first atom, propagating in a direction of the second atom. One or more shock waves will leave the second atom, but there will be no reflected wave. In each step, each of the waves will travel the distance between two neighboring atoms, i.e. the length of a single bond. The waves may branch, but no reflection is allowed. After the shock wave passes any tunnel section (half of a single bond), this section collapses so that shock waves cannot traverse it. If any of the waves reaches the atom where the whole process started (the first atom), both the first atom and the second atom belong to some closed structure (an aromatic ring or something like that). If this is the case no rotation is allowed about the specified bond. (2) Step indices are assigned to the atoms which were reached by shock waves. The first step index (one) is assigned to the first input atom. The second step index (two) is assigned to the second atom. After that, the whole residue is repeatedly scanned, atom by atom. For each atom, all bonds are scanned. The atom is reached by the shock wave in the current step if the step index assigned to at least one bond partner is equal to the previous step index. (3) The auxiliaryI index should be reinitialized before every use. ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======check is bond part of a closed structure:============================*/ int IsPartOfRing_ (MolComplexS *mol_complexSP, int mol_complexI, size_t atom1_arrayI, size_t atom2_arrayI) { MolComplexS *curr_mol_complexSP; size_t atomsN; int residueI; int start_atomI, end_atomI; int stepI, previous_stepI; AtomS *curr_atomSP; int atoms_in_residueN; int propagationF; int atomI; int atom_reachedF; int bondI; TrueBondS *curr_bondSP; AtomS *curr_neighborSP; /* Pointer to the chosen macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Prepare and check the number of atoms: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) return -1; /* Two specified atoms should belong to the same residue: */ residueI = (curr_mol_complexSP->atomSP + atom1_arrayI)->residue_arrayI; if ((int) (curr_mol_complexSP->atomSP + atom2_arrayI)->residue_arrayI != residueI) { return -2; } /* If this point is reached, both atoms belong to the same residue. */ /* Prepare and check the atomic array indices which */ /* define the residue to which both atoms belong. */ /* This check might be redundant but I am paranoic. */ start_atomI = (curr_mol_complexSP->residueSP + residueI)->residue_startI; end_atomI = (curr_mol_complexSP->residueSP + residueI)->residue_endI; if (((int) atom1_arrayI < start_atomI) || ((int) atom1_arrayI > end_atomI)) { return -3; } if (((int) atom2_arrayI < start_atomI) || ((int) atom2_arrayI > end_atomI)) { return -4; } /* Initialize the step index: */ stepI = 1; /*------reset auxiliaryI for each atom of a chosen residue:------------------*/ /* Scan the chosen residue, atom by atom: */ for (atomI = start_atomI; atomI <= end_atomI; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Reset the auxiliaryI: */ curr_atomSP->auxiliaryI = 0; } /*------the shock wave starts from the first atom:---------------------------*/ /* Associate the first step index with the first atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atom1_arrayI; curr_atomSP->auxiliaryI = 1; /*------the shock wave reaches the second atom:------------------------------*/ /* Associate the second step index with the second atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atom2_arrayI; curr_atomSP->auxiliaryI = 2; /*------further propagation of shock waves:----------------------------------*/ /* Now scan the residue repeatedly. The number of scans should not */ /* exceed the number of atoms in the residue, because the length */ /* of the fully extended residue is equal to number_of_atoms - 1. */ atoms_in_residueN = end_atomI - start_atomI + 1; /* Initialize the index of the previous step: */ previous_stepI = 2; /* The loop which counts steps should start from the third step: */ for (stepI = 3; stepI < atoms_in_residueN; stepI++) { /* Reset the wave propagation flag: */ propagationF = 0; /* In each step, scan the entire residue, atom by atom: */ for (atomI = start_atomI; atomI <= end_atomI; atomI++) { /* In the third step, the first atom of */ /* the specified bond should be skipped: */ if ((stepI == 3) && (atomI == (int) atom1_arrayI)) continue; /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* If the current atom was reached */ /* in the previous step, skip it: */ if (curr_atomSP->auxiliaryI == previous_stepI) continue; /* Reset the flag which says that the */ /* atom is reached by the shock wave: */ atom_reachedF = 0; /* Scan all bonds of the current atom: */ for (bondI = 0; bondI < curr_atomSP->bondsN; bondI++) { /* Pointer to the current bond: */ curr_bondSP = curr_atomSP->true_bondSA + bondI; /* Only the covalent bonds are taken into account. */ /* Hydrogen, disulfide and pseudo-bonds are ignored. */ if (curr_bondSP->bond_typeI != 1) continue; /* Bonds formed with atoms from another */ /* macromolecular complex are ignored: */ if (curr_bondSP->neighbor_mol_complexI != mol_complexI) { continue; } /* If the bond partner was reached by the shock */ /* wave in the previous step, the current atom */ /* is reached by the shock wave in this step: */ curr_neighborSP = mol_complexSP->atomSP + curr_bondSP->neighbor_arrayI; if (curr_neighborSP->auxiliaryI == previous_stepI) { /* Set the flag which says that the */ /* shock wave continues propagation: */ propagationF = 1; /* Set the flag which says that this */ /* atom is reached by the shock wave: */ atom_reachedF = 1; /* Do not inspect the remaining */ /* bonds, it is not necessary: */ break; } } /* If the current atom is reached in this step: */ if (atom_reachedF) { /* If the current atom is the first atom of the */ /* specified bond and if it was reached in this */ /* step, the bond is involved in ring formation: */ if (atomI == (int) atom1_arrayI) return 1; /* If the shock wave reached the current atom */ /* for the first time, store the step index: */ if (curr_atomSP->auxiliaryI == 0) { curr_atomSP->auxiliaryI = stepI; } } } /* If the shock wave is not propagating any more, break: */ if (!propagationF) break; /* Update the value of the previous step index: */ previous_stepI = stepI; } /*---------------------------------------------------------------------------*/ /* Return zero if this point is reached: */ return 0; } /*===========================================================================*/ garlic-1.6/select_4c5.c0000644000076500007650000001514610140122473015206 0ustar zuciczucic00000000000000/* Copyright (C) 2004 Damir Zucic */ /*============================================================================= select_4c5.c Purpose: Select the sequence fragment which contains four or more charged residues in a window of five residues. ASP, GLU, ARG, LYS and HIS are treated as charged. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. (3) Selection mode index (0 = overwrite, 1 = restrict, 2 = expand previous selection). Output: (1) The flag selectedF set to one for selected atoms in every caught macromolecular complex. (2) Return value. Return value: (1) The number of selected atoms (zero or positive value). ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======select fragments with four or more charged residues:=================*/ long Select4C5_ (MolComplexS *mol_complexSP, int mol_complexesN, int selection_modeI) { long selected_atomsN = 0; int mol_complexI; MolComplexS *curr_mol_complexSP; int atomsN, atomI; AtomS *curr_atomSP; int residuesN, residueI, windowI, combinedI; ResidueS *curr_residueSP; AtomS *first_atomSP; char *nameP; int chargedN; int first_atomI, last_atomI; /* Check every macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check is the current macromolecular complex caught: */ if (curr_mol_complexSP->catchF == 0) continue; /* Prepare and check the number of atoms in the current complex: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Copy the number of residues in the current macromol. complex: */ residuesN = curr_mol_complexSP->residuesN; if (residuesN == 0) continue; /* Backup the current selection if selection mode is restrict: */ if (selection_modeI == 1) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Copy the selection flag: */ curr_atomSP->previous_selectedF = curr_atomSP->selectedF; } } /* Unselect everything if selection mode is overwrite or restrict: */ if ((selection_modeI == 0) || (selection_modeI == 1)) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Unselect the current atom: */ curr_atomSP->selectedF = 0; } } /* Scan the residues of the current macromolecular complex: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Reset the counter which counts charged residues: */ chargedN = 0; /* Scan the window of five residues, */ /* starting from the current residue: */ for (windowI = 0; windowI < 5; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI >= residuesN) break; /* Residue associated with the combined index: */ curr_residueSP = curr_mol_complexSP->residueSP + combinedI; /* Pointer to the first atom of current residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Pointer to the name of the current residue: */ nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Check is this residue charged: */ if ((strcmp (nameP, "ASP") == 0) || (strcmp (nameP, "GLU") == 0) || (strcmp (nameP, "ARG") == 0) || (strcmp (nameP, "LYS") == 0) || (strcmp (nameP, "HIS") == 0)) chargedN++; } /* If there were four or more charged residues in */ /* a window of five residues, the quartet is found. */ /* If there were three or less, take the next res. */ if (chargedN < 4) continue; /* If this point is reached, scan the window of five */ /* residues again and select all charged residues. */ /* Scan the window of five residues, */ /* starting from the current residue: */ for (windowI = 0; windowI < 5; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI >= residuesN) break; /* Residue associated with the combined index: */ curr_residueSP = curr_mol_complexSP->residueSP + combinedI; /* Pointer to the first atom of current residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Pointer to the name of the current residue: */ nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Check is this residue charged: */ if ((strcmp (nameP, "ASP") != 0) && (strcmp (nameP, "GLU") != 0) && (strcmp (nameP, "ARG") != 0) && (strcmp (nameP, "LYS") != 0) && (strcmp (nameP, "HIS") != 0)) continue; /* If this point is reached, select */ /* all atoms of the current residue. */ /* The indices of the first and the */ /* last atom of the current residue: */ first_atomI = curr_residueSP->residue_startI; last_atomI = curr_residueSP->residue_endI; /* Select all atoms of the current residue: */ for (atomI = first_atomI; atomI <= last_atomI; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Select the current atom: */ curr_atomSP->selectedF = 1; /* Update the counter of selected atoms: */ selected_atomsN++; } } /* End of residueI loop: */ } /* Combine the current selection with the */ /* previous, if selection mode is restrict: */ if (selection_modeI == 1) { /* Reset the counter of selected atoms. The */ /* selected atoms should be counted again. */ selected_atomsN = 0; /* Combine the old and the new selection flag: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Combine selection flags: */ curr_atomSP->selectedF *= curr_atomSP->previous_selectedF; /* Check the selection flag; increase */ /* the count of selected residues if */ /* the selection flag is equal to one: */ if (curr_atomSP->selectedF) selected_atomsN++; } } /* Update the position_changedF (some atoms may have bad color): */ curr_mol_complexSP->position_changedF = 1; /* End of mol_complexI loop: */ } /* Return the number of selected atoms: */ return selected_atomsN; } /*===========================================================================*/ garlic-1.6/select_4c6.c0000644000076500007650000001514110140122602015174 0ustar zuciczucic00000000000000/* Copyright (C) 2004 Damir Zucic */ /*============================================================================= select_4c6.c Purpose: Select the sequence fragment which contains four or more charged residues in a window of six residues. ASP, GLU, ARG, LYS and HIS are treated as charged. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. (3) Selection mode index (0 = overwrite, 1 = restrict, 2 = expand previous selection). Output: (1) The flag selectedF set to one for selected atoms in every caught macromolecular complex. (2) Return value. Return value: (1) The number of selected atoms (zero or positive value). ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======select fragments with four or more charged residues:=================*/ long Select4C6_ (MolComplexS *mol_complexSP, int mol_complexesN, int selection_modeI) { long selected_atomsN = 0; int mol_complexI; MolComplexS *curr_mol_complexSP; int atomsN, atomI; AtomS *curr_atomSP; int residuesN, residueI, windowI, combinedI; ResidueS *curr_residueSP; AtomS *first_atomSP; char *nameP; int chargedN; int first_atomI, last_atomI; /* Check every macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check is the current macromolecular complex caught: */ if (curr_mol_complexSP->catchF == 0) continue; /* Prepare and check the number of atoms in the current complex: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Copy the number of residues in the current macromol. complex: */ residuesN = curr_mol_complexSP->residuesN; if (residuesN == 0) continue; /* Backup the current selection if selection mode is restrict: */ if (selection_modeI == 1) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Copy the selection flag: */ curr_atomSP->previous_selectedF = curr_atomSP->selectedF; } } /* Unselect everything if selection mode is overwrite or restrict: */ if ((selection_modeI == 0) || (selection_modeI == 1)) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Unselect the current atom: */ curr_atomSP->selectedF = 0; } } /* Scan the residues of the current macromolecular complex: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Reset the counter which counts charged residues: */ chargedN = 0; /* Scan the window of six residues, */ /* starting from the current residue: */ for (windowI = 0; windowI < 6; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI >= residuesN) break; /* Residue associated with the combined index: */ curr_residueSP = curr_mol_complexSP->residueSP + combinedI; /* Pointer to the first atom of current residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Pointer to the name of the current residue: */ nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Check is this residue charged: */ if ((strcmp (nameP, "ASP") == 0) || (strcmp (nameP, "GLU") == 0) || (strcmp (nameP, "ARG") == 0) || (strcmp (nameP, "LYS") == 0) || (strcmp (nameP, "HIS") == 0)) chargedN++; } /* If there were four or more charged residues in */ /* a window of six residues, the quartet is found. */ /* If there were three or less, take the next res. */ if (chargedN < 4) continue; /* If this point is reached, scan the window of six */ /* residues again and select all charged residues. */ /* Scan the window of six residues, */ /* starting from the current residue: */ for (windowI = 0; windowI < 6; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI >= residuesN) break; /* Residue associated with the combined index: */ curr_residueSP = curr_mol_complexSP->residueSP + combinedI; /* Pointer to the first atom of current residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Pointer to the name of the current residue: */ nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Check is this residue charged: */ if ((strcmp (nameP, "ASP") != 0) && (strcmp (nameP, "GLU") != 0) && (strcmp (nameP, "ARG") != 0) && (strcmp (nameP, "LYS") != 0) && (strcmp (nameP, "HIS") != 0)) continue; /* If this point is reached, select */ /* all atoms of the current residue. */ /* The indices of the first and the */ /* last atom of the current residue: */ first_atomI = curr_residueSP->residue_startI; last_atomI = curr_residueSP->residue_endI; /* Select all atoms of the current residue: */ for (atomI = first_atomI; atomI <= last_atomI; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Select the current atom: */ curr_atomSP->selectedF = 1; /* Update the counter of selected atoms: */ selected_atomsN++; } } /* End of residueI loop: */ } /* Combine the current selection with the */ /* previous, if selection mode is restrict: */ if (selection_modeI == 1) { /* Reset the counter of selected atoms. The */ /* selected atoms should be counted again. */ selected_atomsN = 0; /* Combine the old and the new selection flag: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Combine selection flags: */ curr_atomSP->selectedF *= curr_atomSP->previous_selectedF; /* Check the selection flag; increase */ /* the count of selected residues if */ /* the selection flag is equal to one: */ if (curr_atomSP->selectedF) selected_atomsN++; } } /* Update the position_changedF (some atoms may have bad color): */ curr_mol_complexSP->position_changedF = 1; /* End of mol_complexI loop: */ } /* Return the number of selected atoms: */ return selected_atomsN; } /*===========================================================================*/ garlic-1.6/select_4c7.c0000644000076500007650000001515710140122732015210 0ustar zuciczucic00000000000000/* Copyright (C) 2004 Damir Zucic */ /*============================================================================= select_4c7.c Purpose: Select the sequence fragment which contains four or more charged residues in a window of seven residues. ASP, GLU, ARG, LYS and HIS are treated as charged. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. (3) Selection mode index (0 = overwrite, 1 = restrict, 2 = expand previous selection). Output: (1) The flag selectedF set to one for selected atoms in every caught macromolecular complex. (2) Return value. Return value: (1) The number of selected atoms (zero or positive value). ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======select fragments with four or more charged residues:=================*/ long Select4C7_ (MolComplexS *mol_complexSP, int mol_complexesN, int selection_modeI) { long selected_atomsN = 0; int mol_complexI; MolComplexS *curr_mol_complexSP; int atomsN, atomI; AtomS *curr_atomSP; int residuesN, residueI, windowI, combinedI; ResidueS *curr_residueSP; AtomS *first_atomSP; char *nameP; int chargedN; int first_atomI, last_atomI; /* Check every macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check is the current macromolecular complex caught: */ if (curr_mol_complexSP->catchF == 0) continue; /* Prepare and check the number of atoms in the current complex: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Copy the number of residues in the current macromol. complex: */ residuesN = curr_mol_complexSP->residuesN; if (residuesN == 0) continue; /* Backup the current selection if selection mode is restrict: */ if (selection_modeI == 1) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Copy the selection flag: */ curr_atomSP->previous_selectedF = curr_atomSP->selectedF; } } /* Unselect everything if selection mode is overwrite or restrict: */ if ((selection_modeI == 0) || (selection_modeI == 1)) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Unselect the current atom: */ curr_atomSP->selectedF = 0; } } /* Scan the residues of the current macromolecular complex: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Reset the counter which counts charged residues: */ chargedN = 0; /* Scan the window of seven residues, */ /* starting from the current residue: */ for (windowI = 0; windowI < 7; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI >= residuesN) break; /* Residue associated with the combined index: */ curr_residueSP = curr_mol_complexSP->residueSP + combinedI; /* Pointer to the first atom of current residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Pointer to the name of the current residue: */ nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Check is this residue charged: */ if ((strcmp (nameP, "ASP") == 0) || (strcmp (nameP, "GLU") == 0) || (strcmp (nameP, "ARG") == 0) || (strcmp (nameP, "LYS") == 0) || (strcmp (nameP, "HIS") == 0)) chargedN++; } /* If there were four or more charged residues in */ /* a window of seven residues, the quartet is found. */ /* If there were three or less, take the next resid. */ if (chargedN < 4) continue; /* If this point is reached, scan the window of seven */ /* residues again and select all charged residues. */ /* Scan the window of seven residues, */ /* starting from the current residue: */ for (windowI = 0; windowI < 7; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI >= residuesN) break; /* Residue associated with the combined index: */ curr_residueSP = curr_mol_complexSP->residueSP + combinedI; /* Pointer to the first atom of current residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Pointer to the name of the current residue: */ nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Check is this residue charged: */ if ((strcmp (nameP, "ASP") != 0) && (strcmp (nameP, "GLU") != 0) && (strcmp (nameP, "ARG") != 0) && (strcmp (nameP, "LYS") != 0) && (strcmp (nameP, "HIS") != 0)) continue; /* If this point is reached, select */ /* all atoms of the current residue. */ /* The indices of the first and the */ /* last atom of the current residue: */ first_atomI = curr_residueSP->residue_startI; last_atomI = curr_residueSP->residue_endI; /* Select all atoms of the current residue: */ for (atomI = first_atomI; atomI <= last_atomI; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Select the current atom: */ curr_atomSP->selectedF = 1; /* Update the counter of selected atoms: */ selected_atomsN++; } } /* End of residueI loop: */ } /* Combine the current selection with the */ /* previous, if selection mode is restrict: */ if (selection_modeI == 1) { /* Reset the counter of selected atoms. The */ /* selected atoms should be counted again. */ selected_atomsN = 0; /* Combine the old and the new selection flag: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Combine selection flags: */ curr_atomSP->selectedF *= curr_atomSP->previous_selectedF; /* Check the selection flag; increase */ /* the count of selected residues if */ /* the selection flag is equal to one: */ if (curr_atomSP->selectedF) selected_atomsN++; } } /* Update the position_changedF (some atoms may have bad color): */ curr_mol_complexSP->position_changedF = 1; /* End of mol_complexI loop: */ } /* Return the number of selected atoms: */ return selected_atomsN; } /*===========================================================================*/ garlic-1.6/select_4c9.c0000644000076500007650000001514610402046147015216 0ustar zuciczucic00000000000000/* Copyright (C) 2006 Damir Zucic */ /*============================================================================= select_4c9.c Purpose: Select the sequence fragment which contains four or more charged residues in a window of nine residues. ASP, GLU, ARG, LYS and HIS are treated as charged. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. (3) Selection mode index (0 = overwrite, 1 = restrict, 2 = expand previous selection). Output: (1) The flag selectedF set to one for selected atoms in every caught macromolecular complex. (2) Return value. Return value: (1) The number of selected atoms (zero or positive value). ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======select fragments with four or more charged residues:=================*/ long Select4C9_ (MolComplexS *mol_complexSP, int mol_complexesN, int selection_modeI) { long selected_atomsN = 0; int mol_complexI; MolComplexS *curr_mol_complexSP; int atomsN, atomI; AtomS *curr_atomSP; int residuesN, residueI, windowI, combinedI; ResidueS *curr_residueSP; AtomS *first_atomSP; char *nameP; int chargedN; int first_atomI, last_atomI; /* Check every macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check is the current macromolecular complex caught: */ if (curr_mol_complexSP->catchF == 0) continue; /* Prepare and check the number of atoms in the current complex: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Copy the number of residues in the current macromol. complex: */ residuesN = curr_mol_complexSP->residuesN; if (residuesN == 0) continue; /* Backup the current selection if selection mode is restrict: */ if (selection_modeI == 1) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Copy the selection flag: */ curr_atomSP->previous_selectedF = curr_atomSP->selectedF; } } /* Unselect everything if selection mode is overwrite or restrict: */ if ((selection_modeI == 0) || (selection_modeI == 1)) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Unselect the current atom: */ curr_atomSP->selectedF = 0; } } /* Scan the residues of the current macromolecular complex: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Reset the counter which counts charged residues: */ chargedN = 0; /* Scan the window of nine residues, */ /* starting from the current residue: */ for (windowI = 0; windowI < 9; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI >= residuesN) break; /* Residue associated with the combined index: */ curr_residueSP = curr_mol_complexSP->residueSP + combinedI; /* Pointer to the first atom of current residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Pointer to the name of the current residue: */ nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Check is this residue charged: */ if ((strcmp (nameP, "ASP") == 0) || (strcmp (nameP, "GLU") == 0) || (strcmp (nameP, "ARG") == 0) || (strcmp (nameP, "LYS") == 0) || (strcmp (nameP, "HIS") == 0)) chargedN++; } /* If there were four or more charged residues in */ /* a window of nine residues, the quartet is found. */ /* If there were three or less, take the next res. */ if (chargedN < 4) continue; /* If this point is reached, scan the window of nine */ /* residues again and select all charged residues. */ /* Scan the window of nine residues, */ /* starting from the current residue: */ for (windowI = 0; windowI < 9; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI >= residuesN) break; /* Residue associated with the combined index: */ curr_residueSP = curr_mol_complexSP->residueSP + combinedI; /* Pointer to the first atom of current residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Pointer to the name of the current residue: */ nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Check is this residue charged: */ if ((strcmp (nameP, "ASP") != 0) && (strcmp (nameP, "GLU") != 0) && (strcmp (nameP, "ARG") != 0) && (strcmp (nameP, "LYS") != 0) && (strcmp (nameP, "HIS") != 0)) continue; /* If this point is reached, select */ /* all atoms of the current residue. */ /* The indices of the first and the */ /* last atom of the current residue: */ first_atomI = curr_residueSP->residue_startI; last_atomI = curr_residueSP->residue_endI; /* Select all atoms of the current residue: */ for (atomI = first_atomI; atomI <= last_atomI; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Select the current atom: */ curr_atomSP->selectedF = 1; /* Update the counter of selected atoms: */ selected_atomsN++; } } /* End of residueI loop: */ } /* Combine the current selection with the */ /* previous, if selection mode is restrict: */ if (selection_modeI == 1) { /* Reset the counter of selected atoms. The */ /* selected atoms should be counted again. */ selected_atomsN = 0; /* Combine the old and the new selection flag: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Combine selection flags: */ curr_atomSP->selectedF *= curr_atomSP->previous_selectedF; /* Check the selection flag; increase */ /* the count of selected residues if */ /* the selection flag is equal to one: */ if (curr_atomSP->selectedF) selected_atomsN++; } } /* Update the position_changedF (some atoms may have bad color): */ curr_mol_complexSP->position_changedF = 1; /* End of mol_complexI loop: */ } /* Return the number of selected atoms: */ return selected_atomsN; } /*===========================================================================*/ garlic-1.6/select_3p5.c0000644000076500007650000001505010415436322015222 0ustar zuciczucic00000000000000/* Copyright (C) 2004-2006 Damir Zucic */ /*============================================================================= select_3p5.c Purpose: Select the sequence fragment which contains three or more polar residues in a window of five residues. The following residues are treated as polar: ARG, LYS, HIS, ASP, GLU, ASN, GLN, SER, THR, TYR, TRP, ASX and GLX. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. (3) Selection mode index (0 = overwrite, 1 = restrict, 2 = exp. previous selection). Output: (1) The flag selectedF set to one for selected atoms in every caught macromolecular complex. (2) Return value. Return value: (1) The number of selected atoms (zero or positive value). ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int IsPolar_ (char *); /*======select fragments with three or more polar residues:==================*/ long Select3P5_ (MolComplexS *mol_complexSP, int mol_complexesN, int selection_modeI) { long selected_atomsN = 0; int mol_complexI; MolComplexS *curr_mol_complexSP; int atomsN, atomI; AtomS *curr_atomSP; int residuesN, residueI, windowI, combinedI; ResidueS *curr_residueSP; AtomS *first_atomSP; char *nameP; int polarN; int first_atomI, last_atomI; /* Check every macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check is the current macromolecular complex caught: */ if (curr_mol_complexSP->catchF == 0) continue; /* Prepare and check the number of atoms in the current complex: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Copy the number of residues in the current macromol. complex: */ residuesN = curr_mol_complexSP->residuesN; if (residuesN == 0) continue; /* Backup the current selection if selection mode is restrict: */ if (selection_modeI == 1) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Copy the selection flag: */ curr_atomSP->previous_selectedF = curr_atomSP->selectedF; } } /* Unselect everything if selection mode is overwrite or restrict: */ if ((selection_modeI == 0) || (selection_modeI == 1)) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Unselect the current atom: */ curr_atomSP->selectedF = 0; } } /* Scan the residues of the current macromolecular complex: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Reset the counter which counts polar residues: */ polarN = 0; /* Scan the window of five residues, */ /* starting from the current residue: */ for (windowI = 0; windowI < 5; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI >= residuesN) break; /* Residue associated with the combined index: */ curr_residueSP = curr_mol_complexSP->residueSP + combinedI; /* Pointer to the first atom of current residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Pointer to the name of the current residue: */ nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Check is this residue polar (negative */ /* return value signals apolar residue!): */ if (IsPolar_ (nameP) >= 0) polarN++; } /* If there were three or more polar residues in a */ /* window of five residues, the triplet is found. */ /* If there were two or less, take the next resid. */ if (polarN < 3) continue; /* If this point is reached, scan the window of */ /* five residues again and select polar residues. */ /* Scan the window of five residues, */ /* starting from the current residue: */ for (windowI = 0; windowI < 5; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI >= residuesN) break; /* Residue associated with the combined index: */ curr_residueSP = curr_mol_complexSP->residueSP + combinedI; /* Pointer to the first atom of current residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Pointer to the name of the current residue: */ nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Check is this residue polar (negative */ /* return value signals apolar residue!): */ if (IsPolar_ (nameP) < 0) continue; /* If this point is reached, select */ /* all atoms of the current residue. */ /* The indices of the first and the */ /* last atom of the current residue: */ first_atomI = curr_residueSP->residue_startI; last_atomI = curr_residueSP->residue_endI; /* Select all atoms of the current residue: */ for (atomI = first_atomI; atomI <= last_atomI; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Select the current atom: */ curr_atomSP->selectedF = 1; /* Update the counter of selected atoms: */ selected_atomsN++; } } /* End of residueI loop: */ } /* Combine the current selection with the */ /* previous, if selection mode is restrict: */ if (selection_modeI == 1) { /* Reset the counter of selected atoms. The */ /* selected atoms should be counted again. */ selected_atomsN = 0; /* Combine the old and the new selection flag: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Combine selection flags: */ curr_atomSP->selectedF *= curr_atomSP->previous_selectedF; /* Check the selection flag; increase */ /* the count of selected residues if */ /* the selection flag is equal to one: */ if (curr_atomSP->selectedF) selected_atomsN++; } } /* Update the position_changedF (some atoms may have bad color): */ curr_mol_complexSP->position_changedF = 1; /* End of mol_complexI loop: */ } /* Return the number of selected atoms: */ return selected_atomsN; } /*===========================================================================*/ garlic-1.6/select_5c6.c0000644000076500007650000001514410140373315015211 0ustar zuciczucic00000000000000/* Copyright (C) 2004 Damir Zucic */ /*============================================================================= select_5c6.c Purpose: Select the sequence fragment which contains five or more charged residues in a window of six residues. ASP, GLU, ARG, LYS and HIS are treated as charged. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. (3) Selection mode index (0 = overwrite, 1 = restrict, 2 = expand previous selection). Output: (1) The flag selectedF set to one for selected atoms in every caught macromolecular complex. (2) Return value. Return value: (1) The number of selected atoms (zero or positive value). ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======select fragments with five or more charged residues:=================*/ long Select5C6_ (MolComplexS *mol_complexSP, int mol_complexesN, int selection_modeI) { long selected_atomsN = 0; int mol_complexI; MolComplexS *curr_mol_complexSP; int atomsN, atomI; AtomS *curr_atomSP; int residuesN, residueI, windowI, combinedI; ResidueS *curr_residueSP; AtomS *first_atomSP; char *nameP; int chargedN; int first_atomI, last_atomI; /* Check every macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check is the current macromolecular complex caught: */ if (curr_mol_complexSP->catchF == 0) continue; /* Prepare and check the number of atoms in the current complex: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Copy the number of residues in the current macromol. complex: */ residuesN = curr_mol_complexSP->residuesN; if (residuesN == 0) continue; /* Backup the current selection if selection mode is restrict: */ if (selection_modeI == 1) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Copy the selection flag: */ curr_atomSP->previous_selectedF = curr_atomSP->selectedF; } } /* Unselect everything if selection mode is overwrite or restrict: */ if ((selection_modeI == 0) || (selection_modeI == 1)) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Unselect the current atom: */ curr_atomSP->selectedF = 0; } } /* Scan the residues of the current macromolecular complex: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Reset the counter which counts charged residues: */ chargedN = 0; /* Scan the window of six residues, */ /* starting from the current residue: */ for (windowI = 0; windowI < 6; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI >= residuesN) break; /* Residue associated with the combined index: */ curr_residueSP = curr_mol_complexSP->residueSP + combinedI; /* Pointer to the first atom of current residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Pointer to the name of the current residue: */ nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Check is this residue charged: */ if ((strcmp (nameP, "ASP") == 0) || (strcmp (nameP, "GLU") == 0) || (strcmp (nameP, "ARG") == 0) || (strcmp (nameP, "LYS") == 0) || (strcmp (nameP, "HIS") == 0)) chargedN++; } /* If there were five or more charged residues in */ /* a window of six residues, the quintet is found. */ /* If there were four or less, take the next resid. */ if (chargedN < 5) continue; /* If this point is reached, scan the window of six */ /* residues again and select all charged residues. */ /* Scan the window of six residues, */ /* starting from the current residue: */ for (windowI = 0; windowI < 6; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI >= residuesN) break; /* Residue associated with the combined index: */ curr_residueSP = curr_mol_complexSP->residueSP + combinedI; /* Pointer to the first atom of current residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Pointer to the name of the current residue: */ nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Check is this residue charged: */ if ((strcmp (nameP, "ASP") != 0) && (strcmp (nameP, "GLU") != 0) && (strcmp (nameP, "ARG") != 0) && (strcmp (nameP, "LYS") != 0) && (strcmp (nameP, "HIS") != 0)) continue; /* If this point is reached, select */ /* all atoms of the current residue. */ /* The indices of the first and the */ /* last atom of the current residue: */ first_atomI = curr_residueSP->residue_startI; last_atomI = curr_residueSP->residue_endI; /* Select all atoms of the current residue: */ for (atomI = first_atomI; atomI <= last_atomI; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Select the current atom: */ curr_atomSP->selectedF = 1; /* Update the counter of selected atoms: */ selected_atomsN++; } } /* End of residueI loop: */ } /* Combine the current selection with the */ /* previous, if selection mode is restrict: */ if (selection_modeI == 1) { /* Reset the counter of selected atoms. The */ /* selected atoms should be counted again. */ selected_atomsN = 0; /* Combine the old and the new selection flag: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Combine selection flags: */ curr_atomSP->selectedF *= curr_atomSP->previous_selectedF; /* Check the selection flag; increase */ /* the count of selected residues if */ /* the selection flag is equal to one: */ if (curr_atomSP->selectedF) selected_atomsN++; } } /* Update the position_changedF (some atoms may have bad color): */ curr_mol_complexSP->position_changedF = 1; /* End of mol_complexI loop: */ } /* Return the number of selected atoms: */ return selected_atomsN; } /*===========================================================================*/ garlic-1.6/select_5c7.c0000644000076500007650000001515710140123337015213 0ustar zuciczucic00000000000000/* Copyright (C) 2004 Damir Zucic */ /*============================================================================= select_5c7.c Purpose: Select the sequence fragment which contains five or more charged residues in a window of seven residues. ASP, GLU, ARG, LYS and HIS are treated as charged. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. (3) Selection mode index (0 = overwrite, 1 = restrict, 2 = expand previous selection). Output: (1) The flag selectedF set to one for selected atoms in every caught macromolecular complex. (2) Return value. Return value: (1) The number of selected atoms (zero or positive value). ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======select fragments with five or more charged residues:=================*/ long Select5C7_ (MolComplexS *mol_complexSP, int mol_complexesN, int selection_modeI) { long selected_atomsN = 0; int mol_complexI; MolComplexS *curr_mol_complexSP; int atomsN, atomI; AtomS *curr_atomSP; int residuesN, residueI, windowI, combinedI; ResidueS *curr_residueSP; AtomS *first_atomSP; char *nameP; int chargedN; int first_atomI, last_atomI; /* Check every macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check is the current macromolecular complex caught: */ if (curr_mol_complexSP->catchF == 0) continue; /* Prepare and check the number of atoms in the current complex: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Copy the number of residues in the current macromol. complex: */ residuesN = curr_mol_complexSP->residuesN; if (residuesN == 0) continue; /* Backup the current selection if selection mode is restrict: */ if (selection_modeI == 1) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Copy the selection flag: */ curr_atomSP->previous_selectedF = curr_atomSP->selectedF; } } /* Unselect everything if selection mode is overwrite or restrict: */ if ((selection_modeI == 0) || (selection_modeI == 1)) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Unselect the current atom: */ curr_atomSP->selectedF = 0; } } /* Scan the residues of the current macromolecular complex: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Reset the counter which counts charged residues: */ chargedN = 0; /* Scan the window of seven residues, */ /* starting from the current residue: */ for (windowI = 0; windowI < 7; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI >= residuesN) break; /* Residue associated with the combined index: */ curr_residueSP = curr_mol_complexSP->residueSP + combinedI; /* Pointer to the first atom of current residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Pointer to the name of the current residue: */ nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Check is this residue charged: */ if ((strcmp (nameP, "ASP") == 0) || (strcmp (nameP, "GLU") == 0) || (strcmp (nameP, "ARG") == 0) || (strcmp (nameP, "LYS") == 0) || (strcmp (nameP, "HIS") == 0)) chargedN++; } /* If there were five or more charged residues in */ /* a window of seven residues, the quintet is found. */ /* If there were four or less, take the next resid. */ if (chargedN < 5) continue; /* If this point is reached, scan the window of seven */ /* residues again and select all charged residues. */ /* Scan the window of seven residues, */ /* starting from the current residue: */ for (windowI = 0; windowI < 7; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI >= residuesN) break; /* Residue associated with the combined index: */ curr_residueSP = curr_mol_complexSP->residueSP + combinedI; /* Pointer to the first atom of current residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Pointer to the name of the current residue: */ nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Check is this residue charged: */ if ((strcmp (nameP, "ASP") != 0) && (strcmp (nameP, "GLU") != 0) && (strcmp (nameP, "ARG") != 0) && (strcmp (nameP, "LYS") != 0) && (strcmp (nameP, "HIS") != 0)) continue; /* If this point is reached, select */ /* all atoms of the current residue. */ /* The indices of the first and the */ /* last atom of the current residue: */ first_atomI = curr_residueSP->residue_startI; last_atomI = curr_residueSP->residue_endI; /* Select all atoms of the current residue: */ for (atomI = first_atomI; atomI <= last_atomI; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Select the current atom: */ curr_atomSP->selectedF = 1; /* Update the counter of selected atoms: */ selected_atomsN++; } } /* End of residueI loop: */ } /* Combine the current selection with the */ /* previous, if selection mode is restrict: */ if (selection_modeI == 1) { /* Reset the counter of selected atoms. The */ /* selected atoms should be counted again. */ selected_atomsN = 0; /* Combine the old and the new selection flag: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Combine selection flags: */ curr_atomSP->selectedF *= curr_atomSP->previous_selectedF; /* Check the selection flag; increase */ /* the count of selected residues if */ /* the selection flag is equal to one: */ if (curr_atomSP->selectedF) selected_atomsN++; } } /* Update the position_changedF (some atoms may have bad color): */ curr_mol_complexSP->position_changedF = 1; /* End of mol_complexI loop: */ } /* Return the number of selected atoms: */ return selected_atomsN; } /*===========================================================================*/ garlic-1.6/select_5c9.c0000644000076500007650000001514610140123455015214 0ustar zuciczucic00000000000000/* Copyright (C) 2004 Damir Zucic */ /*============================================================================= select_5c9.c Purpose: Select the sequence fragment which contains five or more charged residues in a window of nine residues. ASP, GLU, ARG, LYS and HIS are treated as charged. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. (3) Selection mode index (0 = overwrite, 1 = restrict, 2 = expand previous selection). Output: (1) The flag selectedF set to one for selected atoms in every caught macromolecular complex. (2) Return value. Return value: (1) The number of selected atoms (zero or positive value). ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======select fragments with five or more charged residues:=================*/ long Select5C9_ (MolComplexS *mol_complexSP, int mol_complexesN, int selection_modeI) { long selected_atomsN = 0; int mol_complexI; MolComplexS *curr_mol_complexSP; int atomsN, atomI; AtomS *curr_atomSP; int residuesN, residueI, windowI, combinedI; ResidueS *curr_residueSP; AtomS *first_atomSP; char *nameP; int chargedN; int first_atomI, last_atomI; /* Check every macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check is the current macromolecular complex caught: */ if (curr_mol_complexSP->catchF == 0) continue; /* Prepare and check the number of atoms in the current complex: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Copy the number of residues in the current macromol. complex: */ residuesN = curr_mol_complexSP->residuesN; if (residuesN == 0) continue; /* Backup the current selection if selection mode is restrict: */ if (selection_modeI == 1) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Copy the selection flag: */ curr_atomSP->previous_selectedF = curr_atomSP->selectedF; } } /* Unselect everything if selection mode is overwrite or restrict: */ if ((selection_modeI == 0) || (selection_modeI == 1)) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Unselect the current atom: */ curr_atomSP->selectedF = 0; } } /* Scan the residues of the current macromolecular complex: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Reset the counter which counts charged residues: */ chargedN = 0; /* Scan the window of nine residues, */ /* starting from the current residue: */ for (windowI = 0; windowI < 9; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI >= residuesN) break; /* Residue associated with the combined index: */ curr_residueSP = curr_mol_complexSP->residueSP + combinedI; /* Pointer to the first atom of current residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Pointer to the name of the current residue: */ nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Check is this residue charged: */ if ((strcmp (nameP, "ASP") == 0) || (strcmp (nameP, "GLU") == 0) || (strcmp (nameP, "ARG") == 0) || (strcmp (nameP, "LYS") == 0) || (strcmp (nameP, "HIS") == 0)) chargedN++; } /* If there were five or more charged residues in */ /* a window of nine residues, the quintet is found. */ /* If there were four or less, take the next resid. */ if (chargedN < 5) continue; /* If this point is reached, scan the window of nine */ /* residues again and select all charged residues. */ /* Scan the window of nine residues, */ /* starting from the current residue: */ for (windowI = 0; windowI < 9; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI >= residuesN) break; /* Residue associated with the combined index: */ curr_residueSP = curr_mol_complexSP->residueSP + combinedI; /* Pointer to the first atom of current residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Pointer to the name of the current residue: */ nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Check is this residue charged: */ if ((strcmp (nameP, "ASP") != 0) && (strcmp (nameP, "GLU") != 0) && (strcmp (nameP, "ARG") != 0) && (strcmp (nameP, "LYS") != 0) && (strcmp (nameP, "HIS") != 0)) continue; /* If this point is reached, select */ /* all atoms of the current residue. */ /* The indices of the first and the */ /* last atom of the current residue: */ first_atomI = curr_residueSP->residue_startI; last_atomI = curr_residueSP->residue_endI; /* Select all atoms of the current residue: */ for (atomI = first_atomI; atomI <= last_atomI; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Select the current atom: */ curr_atomSP->selectedF = 1; /* Update the counter of selected atoms: */ selected_atomsN++; } } /* End of residueI loop: */ } /* Combine the current selection with the */ /* previous, if selection mode is restrict: */ if (selection_modeI == 1) { /* Reset the counter of selected atoms. The */ /* selected atoms should be counted again. */ selected_atomsN = 0; /* Combine the old and the new selection flag: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Combine selection flags: */ curr_atomSP->selectedF *= curr_atomSP->previous_selectedF; /* Check the selection flag; increase */ /* the count of selected residues if */ /* the selection flag is equal to one: */ if (curr_atomSP->selectedF) selected_atomsN++; } } /* Update the position_changedF (some atoms may have bad color): */ curr_mol_complexSP->position_changedF = 1; /* End of mol_complexI loop: */ } /* Return the number of selected atoms: */ return selected_atomsN; } /*===========================================================================*/ garlic-1.6/select_4p6.c0000644000076500007650000001504310417443657015241 0ustar zuciczucic00000000000000/* Copyright (C) 2004-2006 Damir Zucic */ /*============================================================================= select_4p6.c Purpose: Select the sequence fragment which contains four or more polar residues in a window of six residues. The following residues are treated as polar: ARG, LYS, HIS, ASP, GLU, ASN, GLN, SER, THR, TYR, TRP, ASX and GLX. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. (3) Selection mode index (0 = overwrite, 1 = restrict, 2 = exp. previous selection). Output: (1) The flag selectedF set to one for selected atoms in every caught macromolecular complex. (2) Return value. Return value: (1) The number of selected atoms (zero or positive value). ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int IsPolar_ (char *); /*======select fragments with four or more polar residues:===================*/ long Select4P6_ (MolComplexS *mol_complexSP, int mol_complexesN, int selection_modeI) { long selected_atomsN = 0; int mol_complexI; MolComplexS *curr_mol_complexSP; int atomsN, atomI; AtomS *curr_atomSP; int residuesN, residueI, windowI, combinedI; ResidueS *curr_residueSP; AtomS *first_atomSP; char *nameP; int polarN; int first_atomI, last_atomI; /* Check every macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check is the current macromolecular complex caught: */ if (curr_mol_complexSP->catchF == 0) continue; /* Prepare and check the number of atoms in the current complex: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Copy the number of residues in the current macromol. complex: */ residuesN = curr_mol_complexSP->residuesN; if (residuesN == 0) continue; /* Backup the current selection if selection mode is restrict: */ if (selection_modeI == 1) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Copy the selection flag: */ curr_atomSP->previous_selectedF = curr_atomSP->selectedF; } } /* Unselect everything if selection mode is overwrite or restrict: */ if ((selection_modeI == 0) || (selection_modeI == 1)) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Unselect the current atom: */ curr_atomSP->selectedF = 0; } } /* Scan the residues of the current macromolecular complex: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Reset the counter which counts polar residues: */ polarN = 0; /* Scan the window of six residues, */ /* starting from the current residue: */ for (windowI = 0; windowI < 6; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI >= residuesN) break; /* Residue associated with the combined index: */ curr_residueSP = curr_mol_complexSP->residueSP + combinedI; /* Pointer to the first atom of current residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Pointer to the name of the current residue: */ nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Check is this residue polar (negative */ /* return value signals apolar residue!): */ if (IsPolar_ (nameP) >= 0) polarN++; } /* If there were four or more polar residues in a */ /* window of six residues, the quartet is found. */ /* If there were three or less, take the next r. */ if (polarN < 4) continue; /* If this point is reached, scan the window of */ /* six residues again and select polar residues. */ /* Scan the window of six residues, */ /* starting from the current residue: */ for (windowI = 0; windowI < 6; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI >= residuesN) break; /* Residue associated with the combined index: */ curr_residueSP = curr_mol_complexSP->residueSP + combinedI; /* Pointer to the first atom of current residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Pointer to the name of the current residue: */ nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Check is this residue polar (negative */ /* return value signals apolar residue!): */ if (IsPolar_ (nameP) < 0) continue; /* If this point is reached, select */ /* all atoms of the current residue. */ /* The indices of the first and the */ /* last atom of the current residue: */ first_atomI = curr_residueSP->residue_startI; last_atomI = curr_residueSP->residue_endI; /* Select all atoms of the current residue: */ for (atomI = first_atomI; atomI <= last_atomI; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Select the current atom: */ curr_atomSP->selectedF = 1; /* Update the counter of selected atoms: */ selected_atomsN++; } } /* End of residueI loop: */ } /* Combine the current selection with the */ /* previous, if selection mode is restrict: */ if (selection_modeI == 1) { /* Reset the counter of selected atoms. The */ /* selected atoms should be counted again. */ selected_atomsN = 0; /* Combine the old and the new selection flag: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Combine selection flags: */ curr_atomSP->selectedF *= curr_atomSP->previous_selectedF; /* Check the selection flag; increase */ /* the count of selected residues if */ /* the selection flag is equal to one: */ if (curr_atomSP->selectedF) selected_atomsN++; } } /* Update the position_changedF (some atoms may have bad color): */ curr_mol_complexSP->position_changedF = 1; /* End of mol_complexI loop: */ } /* Return the number of selected atoms: */ return selected_atomsN; } /*===========================================================================*/ garlic-1.6/weight_colors.c0000644000076500007650000000423507466710210016132 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2002 Damir Zucic */ /*============================================================================= weight_colors.c Purpose: Weight two colors to prepare the third color. Input: (1) The first color identifier. (2) The second color identifier. (3) Scale factor (double), which weights the second color. (4) Pointer to GUIS structure. Output: Return value. Return value: The identifier of the prepared (new) color. =============================================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======weight two colors:===================================================*/ unsigned long WeightColors_ (unsigned long color1ID, unsigned long color2ID, double scale_factor, GUIS *guiSP) { static unsigned long new_colorID; static unsigned long red_mask, green_mask, blue_mask; static unsigned long red1, red2, green1, green2, blue1, blue2; static long double r1, r2, g1, g2, b1, b2; static long double r, g, b; static unsigned long red, green, blue; /* Copy masks: */ red_mask = guiSP->visual_infoS.red_mask; green_mask = guiSP->visual_infoS.green_mask; blue_mask = guiSP->visual_infoS.blue_mask; /* Extract input color components: */ red1 = color1ID & red_mask; red2 = color2ID & red_mask; green1 = color1ID & green_mask; green2 = color2ID & green_mask; blue1 = color1ID & blue_mask; blue2 = color2ID & blue_mask; /* Convert to doubles: */ r1 = (long double) red1; r2 = (long double) red2; g1 = (long double) green1; g2 = (long double) green2; b1 = (long double) blue1; b2 = (long double) blue2; /* Calculate new color components: */ r = r1 + scale_factor * (r2 - r1); g = g1 + scale_factor * (g2 - g1); b = b1 + scale_factor * (b2 - b1); red = ((unsigned long) r) & red_mask; green = ((unsigned long) g) & green_mask; blue = ((unsigned long) b) & blue_mask; /* Combine new color components: */ new_colorID = red | green | blue; /* Return the identifier of the prepared color: */ return new_colorID; } /*===========================================================================*/ garlic-1.6/select_5p7.c0000644000076500007650000001505710137153757015246 0ustar zuciczucic00000000000000/* Copyright (C) 2004 Damir Zucic */ /*============================================================================= select_5p7.c Purpose: Select the sequence fragment which contains five or more polar residues in a window of seven residues. The following residues are treated as polar: ARG, LYS, HIS, ASP, GLU, ASN, GLN, SER, THR, TYR, TRP, ASX and GLX. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. (3) Selection mode index (0 = overwrite, 1 = restrict, 2 = expand previous selection). Output: (1) The flag selectedF set to one for selected atoms in every caught macromolecular complex. (2) Return value. Return value: (1) The number of selected atoms (zero or positive value). ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int IsPolar_ (char *); /*======select fragments with five or more polar residues:===================*/ long Select5P7_ (MolComplexS *mol_complexSP, int mol_complexesN, int selection_modeI) { long selected_atomsN = 0; int mol_complexI; MolComplexS *curr_mol_complexSP; int atomsN, atomI; AtomS *curr_atomSP; int residuesN, residueI, windowI, combinedI; ResidueS *curr_residueSP; AtomS *first_atomSP; char *nameP; int polarN; int first_atomI, last_atomI; /* Check every macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check is the current macromolecular complex caught: */ if (curr_mol_complexSP->catchF == 0) continue; /* Prepare and check the number of atoms in the current complex: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Copy the number of residues in the current macromol. complex: */ residuesN = curr_mol_complexSP->residuesN; if (residuesN == 0) continue; /* Backup the current selection if selection mode is restrict: */ if (selection_modeI == 1) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Copy the selection flag: */ curr_atomSP->previous_selectedF = curr_atomSP->selectedF; } } /* Unselect everything if selection mode is overwrite or restrict: */ if ((selection_modeI == 0) || (selection_modeI == 1)) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Unselect the current atom: */ curr_atomSP->selectedF = 0; } } /* Scan the residues of the current macromolecular complex: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Reset the counter which counts polar residues: */ polarN = 0; /* Scan the window of seven residues, */ /* starting from the current residue: */ for (windowI = 0; windowI < 7; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI >= residuesN) break; /* Residue associated with the combined index: */ curr_residueSP = curr_mol_complexSP->residueSP + combinedI; /* Pointer to the first atom of current residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Pointer to the name of the current residue: */ nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Check is this residue polar (negative */ /* return value signals apolar residue!): */ if (IsPolar_ (nameP) >= 0) polarN++; } /* If there were five or more polar residues in a */ /* window of seven residues, the quintet is found. */ /* If there were four or less, take the next res. */ if (polarN < 5) continue; /* If this point is reached, scan the window of */ /* seven residues again and select polar residues. */ /* Scan the window of seven residues, */ /* starting from the current residue: */ for (windowI = 0; windowI < 7; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI >= residuesN) break; /* Residue associated with the combined index: */ curr_residueSP = curr_mol_complexSP->residueSP + combinedI; /* Pointer to the first atom of current residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Pointer to the name of the current residue: */ nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Check is this residue polar (negative */ /* return value signals apolar residue!): */ if (IsPolar_ (nameP) < 0) continue; /* If this point is reached, select */ /* all atoms of the current residue. */ /* The indices of the first and the */ /* last atom of the current residue: */ first_atomI = curr_residueSP->residue_startI; last_atomI = curr_residueSP->residue_endI; /* Select all atoms of the current residue: */ for (atomI = first_atomI; atomI <= last_atomI; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Select the current atom: */ curr_atomSP->selectedF = 1; /* Update the counter of selected atoms: */ selected_atomsN++; } } /* End of residueI loop: */ } /* Combine the current selection with the */ /* previous, if selection mode is restrict: */ if (selection_modeI == 1) { /* Reset the counter of selected atoms. The */ /* selected atoms should be counted again. */ selected_atomsN = 0; /* Combine the old and the new selection flag: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Combine selection flags: */ curr_atomSP->selectedF *= curr_atomSP->previous_selectedF; /* Check the selection flag; increase */ /* the count of selected residues if */ /* the selection flag is equal to one: */ if (curr_atomSP->selectedF) selected_atomsN++; } } /* Update the position_changedF (some atoms may have bad color): */ curr_mol_complexSP->position_changedF = 1; /* End of mol_complexI loop: */ } /* Return the number of selected atoms: */ return selected_atomsN; } /*===========================================================================*/ garlic-1.6/select_6p7.c0000644000076500007650000001505410140373261015230 0ustar zuciczucic00000000000000/* Copyright (C) 2004 Damir Zucic */ /*============================================================================= select_6p7.c Purpose: Select the sequence fragment which contains six or more polar residues in a window of seven residues. The following residues are treated as polar: ARG, LYS, HIS, ASP, GLU, ASN, GLN, SER, THR, TYR, TRP, ASX and GLX. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. (3) Selection mode index (0 = overwrite, 1 = restrict, 2 = expand previous selection). Output: (1) The flag selectedF set to one for selected atoms in every caught macromolecular complex. (2) Return value. Return value: (1) The number of selected atoms (zero or positive value). ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int IsPolar_ (char *); /*======select fragments with six or more polar residues:====================*/ long Select6P7_ (MolComplexS *mol_complexSP, int mol_complexesN, int selection_modeI) { long selected_atomsN = 0; int mol_complexI; MolComplexS *curr_mol_complexSP; int atomsN, atomI; AtomS *curr_atomSP; int residuesN, residueI, windowI, combinedI; ResidueS *curr_residueSP; AtomS *first_atomSP; char *nameP; int polarN; int first_atomI, last_atomI; /* Check every macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check is the current macromolecular complex caught: */ if (curr_mol_complexSP->catchF == 0) continue; /* Prepare and check the number of atoms in the current complex: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Copy the number of residues in the current macromol. complex: */ residuesN = curr_mol_complexSP->residuesN; if (residuesN == 0) continue; /* Backup the current selection if selection mode is restrict: */ if (selection_modeI == 1) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Copy the selection flag: */ curr_atomSP->previous_selectedF = curr_atomSP->selectedF; } } /* Unselect everything if selection mode is overwrite or restrict: */ if ((selection_modeI == 0) || (selection_modeI == 1)) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Unselect the current atom: */ curr_atomSP->selectedF = 0; } } /* Scan the residues of the current macromolecular complex: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Reset the counter which counts polar residues: */ polarN = 0; /* Scan the window of seven residues, */ /* starting from the current residue: */ for (windowI = 0; windowI < 7; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI >= residuesN) break; /* Residue associated with the combined index: */ curr_residueSP = curr_mol_complexSP->residueSP + combinedI; /* Pointer to the first atom of current residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Pointer to the name of the current residue: */ nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Check is this residue polar (negative */ /* return value signals apolar residue!): */ if (IsPolar_ (nameP) >= 0) polarN++; } /* If there were six or more polar residues in a */ /* window of seven residues, the sextet is found. */ /* If there were five or less, take the next res. */ if (polarN < 6) continue; /* If this point is reached, scan the window of */ /* seven residues again and select polar residues. */ /* Scan the window of seven residues, */ /* starting from the current residue: */ for (windowI = 0; windowI < 7; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI >= residuesN) break; /* Residue associated with the combined index: */ curr_residueSP = curr_mol_complexSP->residueSP + combinedI; /* Pointer to the first atom of current residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Pointer to the name of the current residue: */ nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Check is this residue polar (negative */ /* return value signals apolar residue!): */ if (IsPolar_ (nameP) < 0) continue; /* If this point is reached, select */ /* all atoms of the current residue. */ /* The indices of the first and the */ /* last atom of the current residue: */ first_atomI = curr_residueSP->residue_startI; last_atomI = curr_residueSP->residue_endI; /* Select all atoms of the current residue: */ for (atomI = first_atomI; atomI <= last_atomI; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Select the current atom: */ curr_atomSP->selectedF = 1; /* Update the counter of selected atoms: */ selected_atomsN++; } } /* End of residueI loop: */ } /* Combine the current selection with the */ /* previous, if selection mode is restrict: */ if (selection_modeI == 1) { /* Reset the counter of selected atoms. The */ /* selected atoms should be counted again. */ selected_atomsN = 0; /* Combine the old and the new selection flag: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Combine selection flags: */ curr_atomSP->selectedF *= curr_atomSP->previous_selectedF; /* Check the selection flag; increase */ /* the count of selected residues if */ /* the selection flag is equal to one: */ if (curr_atomSP->selectedF) selected_atomsN++; } } /* Update the position_changedF (some atoms may have bad color): */ curr_mol_complexSP->position_changedF = 1; /* End of mol_complexI loop: */ } /* Return the number of selected atoms: */ return selected_atomsN; } /*===========================================================================*/ garlic-1.6/extract_double.c0000644000076500007650000000227207124207160016261 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= extract_double.c Purpose: Extract double value from a string. Input: Input string pointer. Output: Return value. Return value: (1) Double value read from input string, on success. (2) Zero on failure (separator not found or no digits available). ========includes:============================================================*/ #include #include #include /*======extract double from a string:========================================*/ double ExtractDouble_ (char *sP) { char *P0, *P1; int n; double value; /* Colon should be separator: */ if ((P0 = strstr (sP, ":")) == NULL) P0 = sP; /* Replace each non-numeric character (except */ /* minus sign and decimal point) with space: */ P1 = P0; while ((n = *P1++) != '\0') { if (!isdigit (n) && (n != '-') && (n != '.')) *(P1 - 1) = ' '; } /* Try to read double value: */ if (sscanf (P0, "%lf", &value) != 1) return 0.0; /* If everything worked fine, return the extracted double value: */ return value; } /*===========================================================================*/ garlic-1.6/parse_options.c0000644000076500007650000002267110357035611016151 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2006 Damir Zucic */ /*============================================================================= parse_options.c Purpose: Parse options which require connection to X server: geometry string, font name, cursor name and color specifications. These arguments were available before, but connection to X server was required prior to parsing. Input: (1) Pointer to GUIS structure, where data will be stored. (2) Pointer to ConfigS structure, with configuration data. Output: (1) Some data stored to GUIS structure. (2) Return value. Return value: (1) Positive on success. (2) Negative on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ void ErrorMessage_ (char *, char *, char *, char *, char *, char *, char *); FILE *CreateLogFile_ (char *); int LoadFont_ (WindowS *, Display *, char *); Cursor PrepareCursor_ (GUIS *, char *); int ParseColor_ (RGBS *, unsigned long *, GUIS *, char *, char *); /*======parse the remaining options:=========================================*/ int ParseOptions_ (GUIS *guiSP, ConfigS *configSP) { size_t rgb_struct_size; int flags; int x0, y0; unsigned int wx, wy; RGBS rgbS; int n; unsigned long dummyID; /* The size of RGBS structure: */ rgb_struct_size = sizeof (RGBS); /* Create (open) the log file, if requested: */ if (configSP->log_fileF) { configSP->log_fileP = CreateLogFile_ (configSP->log_file_nameA); if (configSP->log_fileP == NULL) { ErrorMessage_ ("garlic", "ParseArgs_", configSP->log_file_nameA, "Unable to create the log file!\n", "", "", ""); configSP->log_fileF = 0; return -1; } } /* Main window geometry: */ /** If default geometry should be used: **/ if (strstr (configSP->geometryA, "default")) { guiSP->main_winS.x0 = configSP->main_margin_left; guiSP->main_winS.y0 = configSP->main_margin_top; n = (int) guiSP->screen_width - (int) configSP->main_margin_left - (int) configSP->main_margin_right; if (n >= 0) guiSP->main_winS.width = (unsigned int) n; n = (int) guiSP->screen_height - (int) configSP->main_margin_top - (int) configSP->main_margin_bottom; if (n >= 0) guiSP->main_winS.height = (int) n; } /** If geometry string was specified through **/ /** .garlicrc file or through command line: **/ else { /*** Parse geometry string: ***/ flags = XParseGeometry (configSP->geometryA, &x0, &y0, &wx, &wy); /*** Main window width: ***/ if (WidthValue & flags) guiSP->main_winS.width = wx; /*** Main window height: ***/ if (HeightValue & flags) guiSP->main_winS.height = wy; /*** Main window x offset: ***/ if (XValue & flags) { if ((XNegative & flags) == 0) guiSP->main_winS.x0 = x0; else guiSP->main_winS.x0 = guiSP->screen_width - guiSP->main_winS.width + x0; } /*** Main window y offset: ***/ if (YValue & flags) { if ((YNegative & flags) == 0) guiSP->main_winS.y0 = y0; else guiSP->main_winS.y0 = guiSP->screen_height - guiSP->main_winS.height + y0; } } /* Main window background color: */ ParseColor_ (&guiSP->main_winS.bg_rgbS, &guiSP->main_winS.bg_colorID, guiSP, configSP->bg_colorA, "black"); /* Main window foreground color: */ ParseColor_ (&guiSP->main_winS.fg_rgbS, &guiSP->main_winS.fg_colorID, guiSP, configSP->fg_colorA, "white"); /* Text background color: */ ParseColor_ (&guiSP->input_winS.bg_rgbS, &guiSP->input_winS.bg_colorID, guiSP, configSP->text_bg_colorA, "black"); /** Don't forget the output window, it uses the same background color: **/ memcpy (&guiSP->output_winS.bg_rgbS, &guiSP->input_winS.bg_rgbS, rgb_struct_size); guiSP->output_winS.bg_colorID = guiSP->input_winS.bg_colorID; /* Text foreground color: */ ParseColor_ (&guiSP->input_winS.fg_rgbS, &guiSP->input_winS.fg_colorID, guiSP, configSP->text_fg_colorA, "white"); /** The same color is used for output window and control window: **/ memcpy (&guiSP->output_winS.fg_rgbS, &guiSP->input_winS.fg_rgbS, rgb_struct_size); guiSP->output_winS.fg_colorID = guiSP->input_winS.fg_colorID; guiSP->control_winS.fg_colorID = guiSP->input_winS.fg_colorID; /* Default colors for atoms and bonds: */ for (n = 0; n < MAXCOLORSURFACES; n++) { /** Left color: **/ ParseColor_ (&rgbS, &dummyID, guiSP, configSP->left_colorAA[n], "white"); configSP->left_rgbSA[n].red = rgbS.red; configSP->left_rgbSA[n].green = rgbS.green; configSP->left_rgbSA[n].blue = rgbS.blue; /** Middle color: **/ ParseColor_ (&rgbS, &dummyID, guiSP, configSP->middle_colorAA[n], "white"); configSP->middle_rgbSA[n].red = rgbS.red; configSP->middle_rgbSA[n].green = rgbS.green; configSP->middle_rgbSA[n].blue = rgbS.blue; /** Right color: **/ ParseColor_ (&rgbS, &dummyID, guiSP, configSP->right_colorAA[n], "black"); configSP->right_rgbSA[n].red = rgbS.red; configSP->right_rgbSA[n].green = rgbS.green; configSP->right_rgbSA[n].blue = rgbS.blue; } /* Prepare main font: */ /** Load font: **/ n = LoadFont_ (&guiSP->main_winS, guiSP->displaySP, configSP->font_nameA); if (n < 0) { ErrorMessage_ ("garlic", "ParseArgs_", "", "Failed to load font (after five attempts), exiting ...\n", "", "", ""); return -2; } /** Set this font to all GC's: **/ XSetFont(guiSP->displaySP, guiSP->theGCA[0], guiSP->main_winS.fontSP->fid); XSetFont(guiSP->displaySP, guiSP->theGCA[1], guiSP->main_winS.fontSP->fid); XSetFont(guiSP->displaySP, guiSP->theGCA[2], guiSP->main_winS.fontSP->fid); XSetFont(guiSP->displaySP, guiSP->theGCA[3], guiSP->main_winS.fontSP->fid); XSetFont(guiSP->displaySP, guiSP->theGCA[4], guiSP->main_winS.fontSP->fid); XSetFont(guiSP->displaySP, guiSP->theGCA[5], guiSP->main_winS.fontSP->fid); XSetFont(guiSP->displaySP, guiSP->theGCA[6], guiSP->main_winS.fontSP->fid); XSetFont(guiSP->displaySP, guiSP->theGCA[7], guiSP->main_winS.fontSP->fid); XSetFont(guiSP->displaySP, guiSP->theGCA[8], guiSP->main_winS.fontSP->fid); XSetFont(guiSP->displaySP, guiSP->theGCA[9], guiSP->main_winS.fontSP->fid); /** Initialize font heights: **/ n = guiSP->main_winS.fontSP->ascent + guiSP->main_winS.fontSP->descent; /*** Main window: ***/ guiSP->main_winS.quarter_font_height = (n + 3) / 4; guiSP->main_winS.half_font_height = (n + 1) / 2; guiSP->main_winS.font_height = n; guiSP->main_winS.text_line_height = guiSP->main_winS.font_height + guiSP->main_winS.quarter_font_height; /*** Output window: ***/ guiSP->output_winS.quarter_font_height = guiSP->main_winS.quarter_font_height; guiSP->output_winS.half_font_height = guiSP->main_winS.half_font_height; guiSP->output_winS.font_height = guiSP->main_winS.font_height; guiSP->output_winS.text_line_height = guiSP->main_winS.text_line_height; /*** Input window: ***/ guiSP->input_winS.quarter_font_height = guiSP->main_winS.quarter_font_height; guiSP->input_winS.half_font_height = guiSP->main_winS.half_font_height; guiSP->input_winS.font_height = guiSP->main_winS.font_height; guiSP->input_winS.text_line_height = guiSP->main_winS.text_line_height; /* Prepare main window cursor (hope it will work properly): */ guiSP->main_winS.cursorID = PrepareCursor_ (guiSP, configSP->cursor_nameA); guiSP->main_winS.cursorF = 1; /* Control window cursor: */ guiSP->control_winS.cursorID = XCreateFontCursor (guiSP->displaySP, XC_hand2); guiSP->control_winS.cursorF = 1; /* Input window cursor: */ guiSP->input_winS.cursorID = XCreateFontCursor (guiSP->displaySP, XC_pencil); guiSP->input_winS.cursorF = 1; /* Output window cursor: */ guiSP->output_winS.cursorID = XCreateFontCursor (guiSP->displaySP, XC_X_cursor); guiSP->output_winS.cursorF = 1; /* Prepare eighteen auxiliary colors: */ ParseColor_ (&rgbS, &guiSP->black_colorID, guiSP, "black", "black"); ParseColor_ (&rgbS, &guiSP->gray_colorID, guiSP, "gray", "white"); ParseColor_ (&rgbS, &guiSP->dark_gray_colorID, guiSP, "RGB:8888/8888/8888", "white"); ParseColor_ (&rgbS, &guiSP->white_colorID, guiSP, "white", "white"); ParseColor_ (&rgbS, &guiSP->red_colorID, guiSP, "red", "white"); ParseColor_ (&rgbS, &guiSP->dark_red_colorID, guiSP, "RGB:8888/0000/0000", "black"); ParseColor_ (&rgbS, &guiSP->green_colorID, guiSP, "green", "white"); ParseColor_ (&rgbS, &guiSP->dark_green_colorID, guiSP, "RGB:0000/8888/0000", "black"); ParseColor_ (&rgbS, &guiSP->blue_colorID, guiSP, "blue", "white"); ParseColor_ (&rgbS, &guiSP->dark_blue_colorID, guiSP, "RGB:0000/0000/8888", "black"); ParseColor_ (&rgbS, &guiSP->yellow_colorID, guiSP, "yellow", "white"); ParseColor_ (&rgbS, &guiSP->dark_yellow_colorID, guiSP, "RGB:8888/8888/0000", "black"); ParseColor_ (&rgbS, &guiSP->cyan_colorID, guiSP, "cyan", "white"); ParseColor_ (&rgbS, &guiSP->dark_cyan_colorID, guiSP, "RGB:0000/8888/8888", "black"); ParseColor_ (&rgbS, &guiSP->magenta_colorID, guiSP, "magenta", "white"); ParseColor_ (&rgbS, &guiSP->dark_magenta_colorID, guiSP, "RGB:8888/0000/8888", "black"); ParseColor_ (&rgbS, &guiSP->orange_colorID, guiSP, "orange", "white"); ParseColor_ (&rgbS, &guiSP->dark_orange_colorID, guiSP, "RGB:8888/4444/0000", "black"); /* Return positive value on success: */ return 1; } /*===========================================================================*/ garlic-1.6/button_press.c0000644000076500007650000002107607460763551016025 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2002 Damir Zucic */ /*============================================================================= button_press.c Purpose: Handle ButtonPress events (mouse buttons). Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. (3) Pointer to RuntimeS structure. (4) Pointer to ConfigS structure, with configuration data. (5) Pointer to GUIS structure, with GUI data. (6) Pointer to NearestAtomS structure. (7) The number of pixels in the main window free area. (8) Pointer to refreshI. (9) Pointer to XButtonEvent structure. Output: (1) If the click_modeI is equal to zero and the click occured in the main window, the interatomic distances and angles will be calculated. If the click_modeI is zero and the click occured in the control window, it will cause translation, rotation, slab change or fading change. If the click_modeI is equal to one, the click will choose the bond for editing. (2) Return value. Return value: (1) Positive on success. (2) Zero if event is ignored. (3) Negative on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int ControlClick_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *, XButtonEvent *); int PickBond_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *, NearestAtomS *); /*======handle ButtonPress events:===========================================*/ int ButtonPress_ (MolComplexS *mol_complexSP, int mol_complexesN, RuntimeS *runtimeSP, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int *refreshIP, XButtonEvent *button_eventSP) { int screen_x, screen_y, height; size_t pixelI; NearestAtomS *curr_pixelSP; int n; AtomS *atomSP; RawAtomS *raw_atomSP; static int atoms_pickedN; char stringA[STRINGSIZE]; static char label0A[SHORTSTRINGSIZE]; static char label1A[SHORTSTRINGSIZE]; static char label2A[SHORTSTRINGSIZE]; static char label3A[SHORTSTRINGSIZE]; static double x0, y0, z0, x1, y1, z1, x2, y2, z2, x3, y3, z3; double delta_x, delta_y, delta_z, distance_squared, distance; char formatA[100]; double dx10, dy10, dz10, dx32, dy32, dz32; double abs10, abs32, scalar_product; double cos_angle, angle; /* Check the main window drawing mode index: */ if (guiSP->main_window_modeI != 0) return 0; /* If the event came from child window, call the corresponding function: */ if (button_eventSP->subwindow != None) { /** Control window: **/ if (button_eventSP->subwindow == guiSP->control_winS.ID) { return ControlClick_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, refreshIP, button_eventSP); } } /*------If the event came from the main window:------------------------------*/ /* Prepare and check the pixel index: */ screen_x = button_eventSP->x; screen_y = button_eventSP->y; pixelI = guiSP->main_win_free_area_width * screen_y + screen_x; if (pixelI >= pixelsN) return -1; /* Pointer to the current pixel: */ curr_pixelSP = nearest_atomSP + pixelI; /* Chech last_refreshI - data associated with this pixel may be obsolete: */ if (curr_pixelSP->last_refreshI != *refreshIP) return 0; /* Check the edit mode index; if it is equal to one, the */ /* click should be used to choose the bond for editing: */ if (runtimeSP->click_modeI == 1) { n = PickBond_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, refreshIP, curr_pixelSP); if (n > 0) return 1; else return -2; } /* If this point is reached, the atom was picked successfully: */ atoms_pickedN++; if (atoms_pickedN > 4) atoms_pickedN = 4; /* Pointer to the current atom: */ atomSP = (mol_complexSP + curr_pixelSP->mol_complexI)->atomSP + curr_pixelSP->atomI; raw_atomSP = &atomSP->raw_atomS; /* Store the coordinates of the current atom: */ x0 = raw_atomSP->x[0]; y0 = raw_atomSP->y; z0 = raw_atomSP->z[0]; /* Prepare the label: */ sprintf (stringA, "%s %d %s", raw_atomSP->pure_residue_nameA, raw_atomSP->residue_sequenceI, raw_atomSP->pure_atom_nameA); strncpy (label0A, stringA, SHORTSTRINGSIZE - 1); label0A[SHORTSTRINGSIZE - 1] = '\0'; /* If coordinates are not available for at least two atoms, */ /* copy coordinates, copy label, set one flag and return: */ if (atoms_pickedN < 2) { x1 = x0; y1 = y0; z1 = z0; strncpy (label1A, label0A, SHORTSTRINGSIZE - 1); label1A[SHORTSTRINGSIZE - 1] = '\0'; return 2; } /* Prepare text background color: */ XSetForeground (guiSP->displaySP, guiSP->theGCA[1], guiSP->main_winS.bg_colorID); /* Prepare text color: */ XSetForeground (guiSP->displaySP, guiSP->theGCA[0], guiSP->main_winS.fg_colorID); /* Refresh text background: */ height = guiSP->main_winS.font_height + 4; screen_y = guiSP->main_win_free_area_height - height; XFillRectangle (guiSP->displaySP, guiSP->main_winS.ID, guiSP->theGCA[1], 0, screen_y, guiSP->main_win_free_area_width, height); /* Calculate distance to the atom which was previously clicked: */ delta_x = x0 - x1; delta_y = y0 - y1; delta_z = z0 - z1; distance_squared = delta_x * delta_x + delta_y * delta_y + delta_z * delta_z; distance = sqrt (distance_squared); /* Write distance to the output window. Note that */ /* this string is not drawn to hidden pixmap! */ strcpy (formatA, "dist. = %.2f A [%s]-->[%s]"); sprintf (stringA, formatA, distance, label1A, label0A); screen_x = 2; screen_y = guiSP->main_win_free_area_height - guiSP->main_winS.fontSP->descent - 2; XDrawString (guiSP->displaySP, guiSP->main_winS.ID, guiSP->theGCA[0], screen_x, screen_y, stringA, strlen (stringA)); /* Calculate the angle, if coordinates for four atoms are available: */ if (atoms_pickedN >= 4) { /** Prepare text coordinates: **/ height = guiSP->main_winS.font_height + 4; screen_y = guiSP->main_win_free_area_height - 2 * height; /** Refresh text background: **/ XFillRectangle (guiSP->displaySP, guiSP->main_winS.ID, guiSP->theGCA[1], 0, screen_y, guiSP->main_win_free_area_width, height); /** Calculate absolute values and scalar product: **/ dx10 = x0 - x1; dy10 = y0 - y1; dz10 = z0 - z1; abs10 = sqrt (dx10 * dx10 + dy10 * dy10 + dz10 * dz10); dx32 = x2 - x3; dy32 = y2 - y3; dz32 = z2 - z3; abs32 = sqrt (dx32 * dx32 + dy32 * dy32 + dz32 * dz32); scalar_product = dx10 * dx32 + dy10 * dy32 + dz10 * dz32; /** Calculate and write the angle, if atoms were properly chosen: **/ if ((abs10 != 0.0) && (abs32 != 0.0)) { /*** Calculate the angle. Remember that arc cosine ***/ /*** is very sensitive to floating point errors: ***/ cos_angle = scalar_product / (abs10 * abs32); if (cos_angle <= -1.0) angle = 180.0; else if (cos_angle >= 1.0) angle = 0.0; else angle = RAD_TO_DEG * acos (cos_angle); /*** Write angle to the output window. Note that ***/ /*** this string is not drawn to hidden pixmap! ***/ strcpy (formatA, "angle = %.2f deg [%s]-->[%s], [%s]-->[%s]"); sprintf (stringA, formatA, angle, label3A, label2A, label1A, label0A); screen_x = 2; screen_y = guiSP->main_win_free_area_height - height - guiSP->main_winS.fontSP->descent - 2; XDrawString (guiSP->displaySP, guiSP->main_winS.ID, guiSP->theGCA[0], screen_x, screen_y, stringA, strlen (stringA)); } /** On failure, inform user that at least four **/ /** atoms should be picked to calculate the angle: **/ else { screen_x = 2; screen_y = guiSP->main_win_free_area_height - height - guiSP->main_winS.fontSP->descent - 2; strcpy (stringA, "The same atom picked twice!"); XDrawString (guiSP->displaySP, guiSP->main_winS.ID, guiSP->theGCA[0], screen_x, screen_y, stringA, strlen (stringA)); } } /* Copy the coordinates and labels: */ x3 = x2; y3 = y2; z3 = z2; strncpy (label3A, label2A, SHORTSTRINGSIZE - 1); label3A[SHORTSTRINGSIZE - 1] = '\0'; x2 = x1; y2 = y1; z2 = z1; strncpy (label2A, label1A, SHORTSTRINGSIZE - 1); label2A[SHORTSTRINGSIZE - 1] = '\0'; x1 = x0; y1 = y0; z1 = z0; strncpy (label1A, label0A, SHORTSTRINGSIZE - 1); label1A[SHORTSTRINGSIZE - 1] = '\0'; /* Return positive value: */ return 3; } /*===========================================================================*/ garlic-1.6/truncate_comm.c0000644000076500007650000000242207070455170016120 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= truncate_comm.c Purpose: Truncate the command string, string length, carriage position and array of text widths. Input: (1) Pointer to RuntimeS structure. Output: (1) Command string truncated, command string length reset, carriage position reset and array of text widths reset. (2) Return value. Return value: (1) Positive always (trivial). ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======truncate command string:=============================================*/ int TruncateCommand_ (RuntimeS *runtimeSP) { int i; /* Truncate the command string: */ runtimeSP->curr_commandA[0] = '\0'; /* Reset the command string length and carriage position: */ runtimeSP->command_length = 0; runtimeSP->carriage_position = 0; /* Reset the array of text widths: */ for (i = 0; i < COMMSTRINGSIZE; i++) runtimeSP->left_part_widthA[i] = 0; /* Return positive value (success): */ return 1; } /*===========================================================================*/ garlic-1.6/init_hyphob.c0000644000076500007650000000465107761147055015611 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2003 Damir Zucic */ /*============================================================================= init_hyphob.c Purpose: Initialize hydrophobicity values associated with the general purpose sequence and with the reference sequence. Input: (1) Pointer to RuntimeS structure, with both input and output data. Output: (1) Hydrophobicity information initialized. Return value: No return value. Notes: (1) Check init_runtime.c for default hydrophobicity scale! ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ double Hydrophobicity_ (char *, int, int); /*======initialize hydrophobicity values:====================================*/ void InitHyphob_ (RuntimeS *runtimeSP) { int max_length; size_t residueI; int scaleI; char *residue_nameP; char residue_nameA[RESNAMESIZE]; double hydrophobicity; /* The maximal residue name length: */ max_length = RESNAMESIZE - 1; /* Hydrophobicity scale index: */ scaleI = runtimeSP->hydrophobicity_scaleI; /* Scan the general purpose sequence: */ for (residueI = 0; residueI < runtimeSP->residuesN; residueI++) { /* Pointer to the current residue name: */ residue_nameP = runtimeSP->sequenceP + residueI * max_length; /* Copy the residue name: */ strncpy (residue_nameA, residue_nameP, max_length); residue_nameA[max_length] = '\0'; /* The corresponding hydrophobicity: */ hydrophobicity = Hydrophobicity_ (residue_nameA, scaleI, 0); /* Store the hydrophobicity value: */ *(runtimeSP->hydrophobicityP + residueI) = hydrophobicity; } /* Scan the reference sequence: */ for (residueI = 0; residueI < runtimeSP->reference_residuesN; residueI++) { /* Pointer to the current residue name: */ residue_nameP = runtimeSP->reference_sequenceP + residueI * max_length; /* Copy the residue name: */ strncpy (residue_nameA, residue_nameP, max_length); residue_nameA[max_length] = '\0'; /* The corresponding hydrophobicity: */ hydrophobicity = Hydrophobicity_ (residue_nameA, scaleI, 0); /* Store the hydrophobicity value: */ *(runtimeSP->reference_hydrophobicityP + residueI) = hydrophobicity; } } /*===========================================================================*/ garlic-1.6/ex2doubles.c0000644000076500007650000000261107065470375015344 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= ex2doubles.c Purpose: Extract two double values from a string. Input: (1) Pointer to the first double value. (2) Pointer to the second double value. (3) Input string pointer. Output: (1) The first double value. (2) The second double value. (3) Return value. Return value: (1) Positive on success. (2) Negative on failure. ========includes:============================================================*/ #include #include #include /*======extract two double values from a string:=============================*/ int ExtractTwoDoubles_ (double *value1P, double *value2P, char *sP) { char *P0, *P1; int n; static double d1, d2; /* Colon should be separator: */ if ((P0 = strstr (sP, ":")) == NULL) P0 = sP; else P0++; /* Replace each non-numeric character (except */ /* minus sign and decimal point) with space: */ P1 = P0; while ((n = *P1++) != '\0') { if (!isdigit (n) && (n != '-') && (n != '.')) *(P1 - 1) = ' '; } /* Try to read two double values: */ if (sscanf (P0, " %lf %lf", &d1, &d2) != 2) return -1; /* On success, copy the extracted values: */ *value1P = d1; *value2P = d2; /* If everything worked fine, return positive integer: */ return 1; } /*===========================================================================*/ garlic-1.6/identify_button.c0000644000076500007650000000504607071125210016461 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= identify_button.c Purpose: Identify (dummy) button at which the ButtonPress event occured. If called for the first time, initialize the array of ButtonS structures, i.e. initialize edge coordinates for each button. Input: (1) Pointer to XButtonEvent structure. (2) Pointer to GUIS structure. Output: Return value. Return value: (1) Zero if called for the first time. (2) Button index (positive or zero), on success. (3) Negative on failure (no button pressed). Notes: (1) Indices are assigned as follows: 0 = KP_0 1 = KP_1 2 = KP_2 3 = KP_3 4 = KP_4 5 = KP_5 6 = KP_6 7 = KP_7 8 = KP_8 9 = KP_9 10 = KP_Decimal 11 = KP_Enter 12 = KP_Add 13 = KP_Subtract 14 = KP_Multiply 15 = KP_Divide 16 = F1 17 = F2 18 = F3 19 = F4 ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int InitializeButtons_ (ButtonS *); /*======identify (dummy) button:=============================================*/ int IdentifyButton_ (XButtonEvent *button_eventSP, GUIS *guiSP) { static int called_beforeF; static ButtonS buttonSA[20]; int x, y; int buttonI; int i; /* If this function is called for the first time, */ /* initialize edge coordinates for all buttons: */ if (called_beforeF == 0) { InitializeButtons_ (buttonSA); called_beforeF = 1; return 0; } /* The exact position where the click occured: */ x = button_eventSP->x - guiSP->control_winS.x0 - guiSP->control_winS.border_width; y = button_eventSP->y - guiSP->control_winS.y0 - guiSP->control_winS.border_width; /* Identify the button: */ buttonI = -1; for (i = 0; i < 20; i++) { /** Check is x between left and right edge: **/ if (x < buttonSA[i].left_edge) continue; if (x > buttonSA[i].right_edge) continue; /** Check is y between top and bottom edge: **/ if (y < buttonSA[i].top_edge) continue; if (y > buttonSA[i].bottom_edge) continue; /** If this point is reached, set buttonI and break from the loop: **/ buttonI = i; break; } /* Return the button index (negative if nothing was hit): */ return buttonI; } /*===========================================================================*/ garlic-1.6/adrenalin.pdb0000644000076500007650000000407207424035745015550 0ustar zuciczucic00000000000000HETATM 1 C 1 -2.935 -0.944 0.179 1.00 0.00 HETATM 2 C 1 -1.582 -1.307 0.179 1.00 0.00 HETATM 3 C 1 -0.584 -0.326 0.179 1.00 0.00 HETATM 4 C 1 -0.948 1.026 0.178 1.00 0.00 HETATM 5 C 1 -2.300 1.390 0.173 1.00 0.00 HETATM 6 C 1 -3.294 0.407 0.173 1.00 0.00 HETATM 7 O 1 -4.609 0.762 0.171 1.00 0.00 HETATM 8 O 1 -3.898 -1.907 0.182 1.00 0.00 HETATM 9 C 1 0.858 -0.789 0.182 1.00 0.00 HETATM 10 C 1 1.870 0.357 -0.026 1.00 0.00 HETATM 11 N 1 3.225 -0.209 -0.113 1.00 0.00 HETATM 12 C 1 4.220 0.849 -0.336 1.00 0.00 HETATM 13 H 1 -1.308 -2.362 0.181 1.00 0.00 HETATM 14 H 1 -0.194 1.811 0.181 1.00 0.00 HETATM 15 H 1 -2.578 2.444 0.171 1.00 0.00 HETATM 16 H 1 -4.973 0.649 -0.713 1.00 0.00 HETATM 17 H 1 -4.217 -2.039 1.082 1.00 0.00 HETATM 18 H 1 1.066 -1.271 1.137 1.00 0.00 HETATM 19 H 1 1.821 1.051 0.815 1.00 0.00 HETATM 20 H 1 1.639 0.883 -0.953 1.00 0.00 HETATM 21 H 1 3.443 -0.707 0.743 1.00 0.00 HETATM 22 H 1 4.201 1.556 0.493 1.00 0.00 HETATM 23 H 1 3.998 1.373 -1.265 1.00 0.00 HETATM 24 H 1 5.213 0.403 -0.406 1.00 0.00 HETATM 25 O 1 1.031 -1.751 -0.862 1.00 0.00 HETATM 26 H 1 0.837 -1.351 -1.716 1.00 0.00 garlic-1.6/fading.c0000644000076500007650000000611507157206161014513 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= fading.c Purpose: Prepare the left, middle and right color for each atom in a complex. These are the only colors required by fast drawing styles. Some slow drawing styles may require additional colors. The AtomS structure is not capable to store these additional colors, so they are not prepared here. Colors for hydrogen bonds are not generated here. In fact, this function does almost nothing - it just calls the proper function which takes care about color fading. Input: (1) Pointer to MolComplexS structure. (2) Number of macromolecular complexes. (3) Pointer to GUIS structure. Output: (1) Colors (pixel values) initialized for each atom in the complex. (2) Return value. Return value: The number of atoms which have colors different from near and far color. =============================================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ size_t NoFading_ (MolComplexS *, GUIS *); size_t PlanarFading_ (MolComplexS *, GUIS *); size_t SphereFading_ (MolComplexS *, GUIS *); size_t HalfSphereFading_ (MolComplexS *, GUIS *); size_t CylinFading_ (MolComplexS *, GUIS *); size_t HalfCylinFading_ (MolComplexS *, GUIS *); /*======prepare atomic colors (apply fading):================================*/ size_t Fading_ (MolComplexS *mol_complexSP, int mol_complexesN, GUIS *guiSP) { size_t atoms_in_sandwichN = 0; int mol_complexI; MolComplexS *curr_mol_complexSP; /* Check every macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /** Pointer to the current macromolecular complex: **/ curr_mol_complexSP = mol_complexSP + mol_complexI; /** Do not prepare new colors if position has not changed: **/ if (curr_mol_complexSP->position_changedF == 0) continue; /** Apply the proper fading: **/ switch (curr_mol_complexSP->fading_modeI) { /*** No fading at all: ***/ case 0: atoms_in_sandwichN += NoFading_ (curr_mol_complexSP, guiSP); break; /*** Planar: ***/ case 1: atoms_in_sandwichN += PlanarFading_ (curr_mol_complexSP, guiSP); break; /*** Spherical: ***/ case 2: atoms_in_sandwichN += SphereFading_ (curr_mol_complexSP, guiSP); break; /*** Semi-spherical: ***/ case 3: atoms_in_sandwichN += HalfSphereFading_ (curr_mol_complexSP, guiSP); break; /*** Cylindrical: ***/ case 4: atoms_in_sandwichN += CylinFading_ (curr_mol_complexSP, guiSP); break; /*** Semi-cylindrical: ***/ case 5: atoms_in_sandwichN += HalfCylinFading_ (curr_mol_complexSP, guiSP); break; /*** Unknown fading mode: ***/ default: ; } } /* Return the total number of atoms between the fading surfaces: */ return atoms_in_sandwichN; } /*===========================================================================*/ garlic-1.6/copy_doubles.c0000644000076500007650000000230007104006706015735 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= copy_doubles.c Purpose: Copy digits, signs and decimal points. Replace anything else with space. Input: (1) Output string pointer. (2) Input string pointer. (3) The number of characters to be copied. Output: (1) Output string. Return value: No return value. ========includes:============================================================*/ #include #include /*======copy digits, signs and decimal points:===============================*/ void CopyDoubles_ (char *output_stringP, char *input_stringP, int charsN) { int i, n; /* Fill the output string with zeros (the number of zeros is charsN): */ for (i = 0; i < charsN; i++) *(output_stringP + i) = '\0'; /* Copy digits, signs and decimal points: */ for (i = 0; i < charsN; i++) { n = *(input_stringP + i); if (n == '\0') { *(output_stringP + i) = '\0'; break; } if (isdigit (n) || (n == '-') || (n == '+') || (n == '.')) { *(output_stringP + i) = n; } else { *(output_stringP + i) = ' '; } } } /*===========================================================================*/ garlic-1.6/are_atoms_bound.c0000644000076500007650000000743707461732174016442 0ustar zuciczucic00000000000000/* Copyright (C) 2001-2002 Damir Zucic */ /*============================================================================= are_atoms_bound.c Purpose: Check are two specified atoms covalently bound. Both atoms belong to the same macromolecular complex. If atoms are bound, store the array indices. Input: (1) Pointer to size_t, where the array index of the first atom will be stored. (2) Pointer to size_t, where the array index of the second atom will be stored. (3) Pointer to MolComplexS structure, pointing to the first complex. (4) The macromolecular complex index. (5) The serial number of the first atom. (6) The serial number of the second atom. Output: (1) Return value. (2) Array index of the first atom. (3) Array index of the second atom. Return value: (1) Positive if two atoms exist and are covalently bound. (2) Negative in all other cases. Notes: (1) Disulfide bond and pseudo-bonds are not treated as covalent. ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======check are two atoms bound:===========================================*/ int AreAtomsBound_ (size_t *atom1_arrayIP, size_t *atom2_arrayIP, MolComplexS *mol_complexSP, int mol_complexI, int atom1_serialI, int atom2_serialI) { MolComplexS *curr_mol_complexSP; size_t atomsN, atomI, atom1I = 0, atom2I = 0; AtomS *curr_atomSP; int serial1F, serial2F; int curr_atom_serialI; AtomS *atom1SP; int bonds1N, bond1I; TrueBondS *curr_bondSP; /* Initialize array indices: */ *atom1_arrayIP = 0; *atom2_arrayIP = 0; /* Pointer to chosen macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Prepare and check the number of atoms: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) return -1; /* Initialize the flags which will signal */ /* the presence of both serial numbers: */ serial1F = 0; serial2F = 0; /* Scan the macromolecular complex: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Copy the atomic serial number: */ curr_atom_serialI = curr_atomSP->raw_atomS.serialI; /* Compare the serial number of the current */ /* atom with the first serial number: */ if (curr_atom_serialI == atom1_serialI) { atom1I = atomI; serial1F = 1; } /* Compare the serial number of the current */ /* atom with the second serial number: */ if (curr_atom_serialI == atom2_serialI) { atom2I = atomI; serial2F = 1; } } /* If one serial number was not found (or both), return negative value: */ if ((serial1F == 0) || (serial2F == 0)) return -2; /* If this point is reached, both serial numbers */ /* were found. Check is there a covalent bond! */ /* Pointer to the atom specified by the first serial number: */ atom1SP = curr_mol_complexSP->atomSP + atom1I; /* The number of bonds: */ bonds1N = atom1SP->bondsN; /* Scan bonds: */ for (bond1I = 0; bond1I < bonds1N; bond1I++) { /* Pointer to the current bond: */ curr_bondSP = atom1SP->true_bondSA + bond1I; /* If this is not a covalent bond, skip it: */ if (curr_bondSP->bond_typeI != 1) continue; /* Check to which complex belongs the partner: */ if (curr_bondSP->neighbor_mol_complexI != mol_complexI) continue; /* If this point is reached, this bond is covalent. Check who is the */ /* partner - is it the atom specified by the second serial number? */ if (curr_bondSP->neighbor_arrayI == atom2I) { *atom1_arrayIP = atom1I; *atom2_arrayIP = atom2I; return 1; } } /* Return negative value if this point is reached: */ return -3; } /*===========================================================================*/ garlic-1.6/align_normal.c0000644000076500007650000002475207400140652015725 0ustar zuciczucic00000000000000/* Copyright (C) 2000, 2001 Damir Zucic */ /*============================================================================= align_normal.c Purpose: Align normal vector of the specified complex with the specified axis. The entire macromolecular complex will be rotated. The membrane is not properly rotated! Input: (1) Pointer to MolComplexS structure. (2) Pointer to ConfigS structure. (3) Axis identifier (1 = x, 2 = y, 3 = z). (4) Orientation identifier (-1 = antiparallel, 1 = parallel). Output: (1) The macromolecular complex will be rotated. (2) Return value. Return value: (1) Positive on success. (2) Zero if no alignment is necessary. (3) Negative on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ void VectorProduct_ (VectorS *, VectorS *, VectorS *); double AbsoluteValue_ (VectorS *); double ScalarProduct_ (VectorS *, VectorS *); int PrepareStereoData_ (MolComplexS *, ConfigS *); /*======align normal vector with given axis:=================================*/ int AlignNormalVector_ (MolComplexS *mol_complexSP, ConfigS *configSP, int axisID, int orientationID) { size_t atomsN, atomI; VectorS normal_vectorS; VectorS target_vectorS; VectorS rotation_axis_vectorS; double a1, a2; double angle, cos_angle, sin_angle; double absolute_value, reciprocal_abs_value; VectorS unit_vector1S, unit_vector2S, unit_vector3S; double cos_stereo_angle, sin_stereo_angle; double x0, y0, z0; AtomS *curr_atomSP; VectorS radius_vectorS; double projection1, projection2; PlaneS *curr_planeSP; double x1, z1, x, z, x_new, z_new; /* Check the pointer to the macromolecular complex: */ if (!mol_complexSP) return -1; /* Are there any atoms at all? */ atomsN = mol_complexSP->atomsN; if (atomsN == 0) return -2; /* Copy the normal vector: */ normal_vectorS.x = mol_complexSP->planeS.normal_x[0]; normal_vectorS.y = mol_complexSP->planeS.normal_y; normal_vectorS.z = mol_complexSP->planeS.normal_z[0]; /* Prepare the target vector. After rotation the normal */ /* vector will be parallel or antiparallel to this vector: */ switch (axisID) { /* x axis: */ case 1: target_vectorS.x = 1; target_vectorS.y = 0; target_vectorS.z = 0; break; /* y axis: */ case 2: target_vectorS.x = 0; target_vectorS.y = 1; target_vectorS.z = 0; break; /* z axis: */ case 3: target_vectorS.x = 0; target_vectorS.y = 0; target_vectorS.z = 1; break; default: return -3; } /* Check the target orientation: */ if (orientationID == -1) { target_vectorS.x *= -1; target_vectorS.y *= -1; target_vectorS.z *= -1; } else if (orientationID != 1) return -4; /* The vector which defines the rotation axis: */ VectorProduct_ (&rotation_axis_vectorS, &normal_vectorS, &target_vectorS); /* Prepare the rotation angle and cosine and sine of this */ /* angle. Right-handed rotation is positive. Remember that */ /* arc cosine is very sensitive to floating point errors: */ a1 = AbsoluteValue_ (&normal_vectorS); a2 = AbsoluteValue_ (&target_vectorS); if ((a1 == 0.0) || (a2 == 0.0)) return -5; cos_angle = ScalarProduct_ (&normal_vectorS, &target_vectorS) / (a1 * a2); if (cos_angle <= -1.0) angle = 3.1415927; else if (cos_angle >= 1.0) angle = 0.0; else angle = acos (cos_angle); sin_angle = sin (angle); /* Prepare and check the absolute value of the rotation axis vector: */ absolute_value = AbsoluteValue_ (&rotation_axis_vectorS); if (absolute_value == 0.0) return -6; /* Prepare the unit vector which defines the rotation axis: */ reciprocal_abs_value = 1.0 / absolute_value; unit_vector1S.x = rotation_axis_vectorS.x * reciprocal_abs_value; unit_vector1S.y = rotation_axis_vectorS.y * reciprocal_abs_value; unit_vector1S.z = rotation_axis_vectorS.z * reciprocal_abs_value; /* Calculate cosine and sine of the stereo angle: */ cos_stereo_angle = cos (configSP->stereo_angle); sin_stereo_angle = sin (configSP->stereo_angle); /* Copy the rotation center coordinates: */ x0 = mol_complexSP->rotation_center_vectorS.x; y0 = mol_complexSP->rotation_center_vectorS.y; z0 = mol_complexSP->rotation_center_vectorS.z; /* Rotate every atom: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = mol_complexSP->atomSP + atomI; /* Coordinates relative to the rotation center: */ radius_vectorS.x = curr_atomSP->raw_atomS.x[0] - x0; radius_vectorS.y = curr_atomSP->raw_atomS.y - y0; radius_vectorS.z = curr_atomSP->raw_atomS.z[0] - z0; /* Prepare the third unit vector (the second is prepared last): */ VectorProduct_ (&unit_vector3S, &unit_vector1S, &radius_vectorS); /* If the absolute value is equal to zero it is */ /* not necessary to rotate the radius vector: */ absolute_value = AbsoluteValue_ (&unit_vector3S); if (absolute_value == 0.0) continue; /* Normalize the third unit vector: */ reciprocal_abs_value = 1.0 / absolute_value; unit_vector3S.x = unit_vector3S.x * reciprocal_abs_value; unit_vector3S.y = unit_vector3S.y * reciprocal_abs_value; unit_vector3S.z = unit_vector3S.z * reciprocal_abs_value; /* Prepare the second unit vector: */ VectorProduct_ (&unit_vector2S, &unit_vector3S, &unit_vector1S); /* Two projections of the radius vector: */ projection1 = ScalarProduct_ (&radius_vectorS, &unit_vector1S); projection2 = ScalarProduct_ (&radius_vectorS, &unit_vector2S); /* Rotate the radius vector: */ radius_vectorS.x = projection1 * unit_vector1S.x + projection2 * unit_vector2S.x * cos_angle + projection2 * unit_vector3S.x * sin_angle; radius_vectorS.y = projection1 * unit_vector1S.y + projection2 * unit_vector2S.y * cos_angle + projection2 * unit_vector3S.y * sin_angle; radius_vectorS.z = projection1 * unit_vector1S.z + projection2 * unit_vector2S.z * cos_angle + projection2 * unit_vector3S.z * sin_angle; /* Translate and store new coordinates: */ curr_atomSP->raw_atomS.x[0] = radius_vectorS.x + x0; curr_atomSP->raw_atomS.y = radius_vectorS.y + y0; curr_atomSP->raw_atomS.z[0] = radius_vectorS.z + z0; } /* Prepare stereo data, if required: */ if (configSP->stereoF) PrepareStereoData_ (mol_complexSP, configSP); /* Set the position_changedF: */ mol_complexSP->position_changedF = 1; /* Prepare the pointer to the current plane: */ curr_planeSP = &mol_complexSP->planeS; /* Rotate the plane center: */ /* Position of the plane center relative to the rotation center: */ radius_vectorS.x = curr_planeSP->center_x[0] - x0; radius_vectorS.y = curr_planeSP->center_y - y0; radius_vectorS.z = curr_planeSP->center_z[0] - z0; /* Prepare the third unit vector: */ VectorProduct_ (&unit_vector3S, &unit_vector1S, &radius_vectorS); /* If the absolute value is different from zero */ /* it is necessary to rotate the radius vector: */ absolute_value = AbsoluteValue_ (&unit_vector3S); if (absolute_value != 0.0) { /* Normalize the third unit vector: */ reciprocal_abs_value = 1.0 / absolute_value; unit_vector3S.x = unit_vector3S.x * reciprocal_abs_value; unit_vector3S.y = unit_vector3S.y * reciprocal_abs_value; unit_vector3S.z = unit_vector3S.z * reciprocal_abs_value; /* The second unit vector: */ VectorProduct_ (&unit_vector2S, &unit_vector3S, &unit_vector1S); /* Two projections of the radius vector: */ projection1 = ScalarProduct_ (&radius_vectorS, &unit_vector1S); projection2 = ScalarProduct_ (&radius_vectorS, &unit_vector2S); /* Rotate the radius vector: */ radius_vectorS.x = projection1 * unit_vector1S.x + projection2 * unit_vector2S.x * cos_angle + projection2 * unit_vector3S.x * sin_angle; radius_vectorS.y = projection1 * unit_vector1S.y + projection2 * unit_vector2S.y * cos_angle + projection2 * unit_vector3S.y * sin_angle; radius_vectorS.z = projection1 * unit_vector1S.z + projection2 * unit_vector2S.z * cos_angle + projection2 * unit_vector3S.z * sin_angle; /* Translate and store the rotated plane center: */ curr_planeSP->center_x[0] = radius_vectorS.x + x0; curr_planeSP->center_y = radius_vectorS.y + y0; curr_planeSP->center_z[0] = radius_vectorS.z + z0; /* Prepare stereo data for the plane center: */ x1 = mol_complexSP->geometric_center_vectorS.x; z1 = mol_complexSP->geometric_center_vectorS.z; x = curr_planeSP->center_x[0] - x1; z = curr_planeSP->center_z[0] - z1; x_new = x * cos_stereo_angle + z * sin_stereo_angle; z_new = -x * sin_stereo_angle + z * cos_stereo_angle; curr_planeSP->center_x[1] = x_new + x1; curr_planeSP->center_z[1] = z_new + z1; } /* Rotate the normal vector: */ /* Prepare the third unit vector: */ VectorProduct_ (&unit_vector3S, &unit_vector1S, &normal_vectorS); /* If the absolute value is zero there is */ /* no need to rotate the normal vector: */ absolute_value = AbsoluteValue_ (&unit_vector3S); if (absolute_value == 0.0) return 1; /* Normalize the third unit vector: */ reciprocal_abs_value = 1.0 / absolute_value; unit_vector3S.x = unit_vector3S.x * reciprocal_abs_value; unit_vector3S.y = unit_vector3S.y * reciprocal_abs_value; unit_vector3S.z = unit_vector3S.z * reciprocal_abs_value; /* The second unit vector: */ VectorProduct_ (&unit_vector2S, &unit_vector3S, &unit_vector1S); /* Two projections of the radius vector: */ projection1 = ScalarProduct_ (&normal_vectorS, &unit_vector1S); projection2 = ScalarProduct_ (&normal_vectorS, &unit_vector2S); /* Rotate the radius vector: */ normal_vectorS.x = projection1 * unit_vector1S.x + projection2 * unit_vector2S.x * cos_angle + projection2 * unit_vector3S.x * sin_angle; normal_vectorS.y = projection1 * unit_vector1S.y + projection2 * unit_vector2S.y * cos_angle + projection2 * unit_vector3S.y * sin_angle; normal_vectorS.z = projection1 * unit_vector1S.z + projection2 * unit_vector2S.z * cos_angle + projection2 * unit_vector3S.z * sin_angle; /* Translate and store the rotated normal vector: */ curr_planeSP->normal_x[0] = normal_vectorS.x; curr_planeSP->normal_y = normal_vectorS.y; curr_planeSP->normal_z[0] = normal_vectorS.z; /* Prepare stereo data for normal vector: */ curr_planeSP->normal_x[1] = curr_planeSP->normal_x[0] * cos_stereo_angle + curr_planeSP->normal_z[0] * sin_stereo_angle; curr_planeSP->normal_z[1] = -curr_planeSP->normal_x[0] * sin_stereo_angle + curr_planeSP->normal_z[0] * cos_stereo_angle; /* Return positive value on success: */ return 2; } /*===========================================================================*/ garlic-1.6/execute_script.c0000644000076500007650000001436007470715464016323 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2002 Damir Zucic */ /*============================================================================= execute_script.c Purpose: Read and execute the specified script file. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Pointer to the number of macromolecular complexes. (3) Pointer to the next macromolecular complex identifier. (4) Pointer to RuntimeS structure, with some runtime data. (5) Pointer to ConfigS structure, with configuration data. (6) Pointer to GUIS structure, with GUI data. (7) Pointer to pointer to NearestAtomS structure. (8) Pointer to the number of pixels in the main win. free area. (9) Pointer to refreshI. Output: (1) Some files may be loaded, data changed etc. (2) Return value. Return value: (1) If the attempt to open script file fails, the return value will be ERROR_OPEN_FAILURE. (2) If script is available, the return value will be equal to the return code of the last executed command. On success, the return will be (in most cases) positive. On failure, the return value will be (in most cases) negative. Notes: (1) This function is called by ExecuteCommand1_ but it calls ExecuteCommand2_, which is not capable to execute scripts. This helps to avoid infinite loops. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "commands.h" #include "typedefs.h" /*======function prototypes:=================================================*/ char *ExtractToken_ (char *, int, char *, char *); FILE *OpenFileForReading_ (char *); int ExecuteCommand2_ (MolComplexS *, int *, int *, RuntimeS *, ConfigS *, GUIS *, NearestAtomS **, size_t *, unsigned int *); int TruncateCommand_ (RuntimeS *); int InputRefresh_ (GUIS *, RuntimeS *); /*======execute script:======================================================*/ int ExecuteScript_ (MolComplexS *mol_complexSP, int *mol_complexesNP, int *next_mol_complexIDP, RuntimeS *runtimeSP, ConfigS *configSP, GUIS *guiSP, NearestAtomS **nearest_atomSPP, size_t *pixelsNP, unsigned int *refreshIP) { int command_code = 2; int line_length; char *remainderP; char tokenA[STRINGSIZE]; static FILE *fileP; char commandA[COMMSTRINGSIZE]; char *currP; /* If file is not opened yet: */ if (fileP == NULL) { /* Skip the first token: */ remainderP = ExtractToken_ (tokenA, STRINGSIZE, runtimeSP->curr_commandA, " \t\n"); if (!remainderP) return ERROR_EXECUTE; /* The second token should contain the file name: */ remainderP = ExtractToken_ (tokenA, STRINGSIZE, remainderP, " \t\n"); if (!remainderP) { strcpy (runtimeSP->messageA, "Script file not specified!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_NO_FILE_NAME; } /* Open the script file: */ if ((fileP = OpenFileForReading_ (tokenA)) == NULL) { sprintf (runtimeSP->messageA, "Unable to open script %s!", tokenA); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_OPEN_FAILURE; } /* On success, set the scriptF: */ runtimeSP->scriptF = 1; } /* Read the next (or the very first) line: */ while (fgets (commandA, COMMSTRINGSIZE, fileP)) { /* If the previous command was pause command, reset the pauseF: */ if (runtimeSP->pauseF) runtimeSP->pauseF = 0; /* The length of the command line: */ line_length = strlen (commandA); /* Skip empty lines and lines shorter than two characters: */ if (line_length < 3) continue; /* Skip comments: */ if (commandA[0] == '#') continue; /* Remove the terminal newline: */ if (commandA[line_length - 1] == '\n') { commandA[line_length - 1] = '\0'; line_length--; } /* Copy the command to RuntimeS structure: */ strncpy (runtimeSP->curr_commandA, commandA, line_length); runtimeSP->curr_commandA[line_length] = '\0'; /* Prepare other parameters associated with the current command: */ runtimeSP->command_length = line_length; runtimeSP->carriage_position = runtimeSP->command_length; /* Prepare the width (in pixels) of the command string: */ runtimeSP->left_part_widthA[line_length] = XTextWidth (guiSP->main_winS.fontSP, runtimeSP->curr_commandA, runtimeSP->carriage_position); /* Refresh the input window, so that user knows what is going on: */ InputRefresh_ (guiSP, runtimeSP); /* Print command to log file, if requested: */ if (configSP->log_fileF) { fprintf (configSP->log_fileP, "%s\n", runtimeSP->curr_commandA); fflush (configSP->log_fileP); } /* Copy the command string to the history buffer: */ currP = runtimeSP->commandsP + runtimeSP->next_commandI * COMMSTRINGSIZE; strcpy (currP, runtimeSP->curr_commandA); /* Execute the command: */ command_code = ExecuteCommand2_ (mol_complexSP, mol_complexesNP, next_mol_complexIDP, runtimeSP, configSP, guiSP, nearest_atomSPP, pixelsNP, refreshIP); /* Print the latest message to log file (if log file is used): */ if ((command_code < 0) && (configSP->log_fileF)) { fprintf (configSP->log_fileP, "#%s\n", runtimeSP->messageA); fflush (configSP->log_fileP); } /* Truncate the command string: */ TruncateCommand_ (runtimeSP); /* Refresh (redraw) the input window: */ InputRefresh_ (guiSP, runtimeSP); /* Update and check the command index */ /* and the total number of commands: */ runtimeSP->next_commandI++; if (runtimeSP->next_commandI >= MAXCOMMSTRINGS - 1) { runtimeSP->next_commandI = 0; } if (runtimeSP->highest_commandI < MAXCOMMSTRINGS - 1) { runtimeSP->highest_commandI++; } /* Update the old_commandI: */ runtimeSP->old_commandI = runtimeSP->next_commandI; /* If PAUSE command was issued, return to the caller: */ if (command_code == COMMAND_PAUSE) return COMMAND_PAUSE; /* If QUIT command was issued, break from the loop: */ if (command_code == COMMAND_QUIT) break; } /* Close the script file, reset the file pointer and reset the script flag: */ fclose (fileP); fileP = NULL; runtimeSP->scriptF = 0; /* If this point is reached, return the last command code: */ return command_code; } /*===========================================================================*/ garlic-1.6/load_sec_structure.c0000644000076500007650000001156307273765750017174 0ustar zuciczucic00000000000000/* Copyright (C) 2001 Damir Zucic */ /*============================================================================= load_sec_structure.c Purpose: Load secondary structure from a file. Input: (1) Pointer to RuntimeS structure. Output: (1) Secondary structure stored to the main sec. str. buffer. (2) Return value. Return value: (1) Positive on success. (2) Negative on failure. Notes: (1) The file which contains the secondary structure should be written in a sort of FASTA format (one letter code, but the first character in title line is '>'). The lines beginning with # are treated as comments. Empty lines are ignored. (2) The original command string is used because the copy was converted to uppercase. File names are case sensitive! ========includes:============================================================*/ #include #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ char *ExtractToken_ (char *, int, char *, char *); FILE *OpenFileForReading_ (char *); /*======load secondary structure from file:==================================*/ int LoadSecondaryStructure_ (RuntimeS *runtimeSP) { int i; char lineA[STRINGSIZE]; char *remainderP; char tokenA[STRINGSIZE]; FILE *fileP; int line_length; int n; int lineI = 0; char *P; int code; int columnI; size_t codeI = 0; /* Initialize the secondary structure buffer */ /* (use the code for extended conformation): */ runtimeSP->sec_structure_length = 0; for (i = 0; i < MAXRESIDUES; i++) *(runtimeSP->sec_structureP + i) = 'E'; /* Copy the original command string: */ strncpy (lineA, runtimeSP->curr_commandA, STRINGSIZE - 1); lineA[STRINGSIZE - 1] = '\0'; /* Skip two tokens: */ remainderP = ExtractToken_ (tokenA, STRINGSIZE, lineA, " \t\n"); if (!remainderP) return -1; remainderP = ExtractToken_ (tokenA, STRINGSIZE, remainderP, " \t\n"); if (!remainderP) return -2; /* The third token should contain the file name: */ remainderP = ExtractToken_ (tokenA, STRINGSIZE, remainderP, " \t\n"); if (!remainderP) { strcpy (runtimeSP->messageA, "File name missing!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return -3; } /* Try to open file: */ fileP = OpenFileForReading_ (tokenA); if (fileP == NULL) { strcpy (runtimeSP->messageA, "Failed to open file!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return -4; } /* Read file, line by line: */ while (fgets (lineA, STRINGSIZE, fileP)) { /* Remove the trailing newline: */ line_length = strlen (lineA); n = line_length - 1; if (line_length > 0) { if (lineA[n] == '\n') lineA[n] = '\0'; line_length--; } /* Empty lines are ignored: */ if (line_length == 0) continue; /* Lines beginning with # are treated as comments: */ if (lineA[0] == '#') continue; /* If the first character of the first useful line is */ /* not '>', input file format is not FASTA compliant. */ /* If it is, the line contains a protein description. */ if (lineI == 0) { if (lineA[0] != '>') { fclose (fileP); return -5; } else { lineI++; continue; } } /* If the first character of a line which is not the first useful */ /* line is '>', this signals another structure. Break from the loop: */ else { if (lineA[0] == '>') break; } /* Convert to uppercase: */ P = lineA; while ((code = *P++) != '\0') *(P - 1) = toupper (code); /* Parse line: */ for (columnI = 0; columnI < line_length; columnI++) { /* Check is there enough place left in the buffer: */ if (codeI > MAXRESIDUES - 10) { strcpy (runtimeSP->messageA, "Secondary structure too long!"); runtimeSP->message_length = strlen (runtimeSP->messageA); fclose (fileP); return -6; } /* The current character: */ code = lineA[columnI]; /* Identify residue: */ switch (code) { /* Valid codes: */ case 'C': case 'E': case 'G': case 'H': case 'T': break; /* Separators: */ case ' ': case ',': case '\t': continue; break; /* Bad codes: */ default: sprintf (runtimeSP->messageA, "Bad code found in input file!"); strcat (runtimeSP->messageA, " Valid codes: C E G H T."); runtimeSP->message_length = strlen (runtimeSP->messageA); return -7; } /* Store the secondary structure code: */ P = runtimeSP->sec_structureP + codeI; *P = code; /* Increment the counter: */ codeI++; } /* Update the line index (only useful lines are counted): */ lineI++; } /* Close file: */ fclose (fileP); /* Store the number of secondary structure codes: */ runtimeSP->sec_structure_length = codeI; /* Return positive value on success: */ return 1; } /*===========================================================================*/ garlic-1.6/pseudo_bonds.c0000644000076500007650000001025007747301213015741 0ustar zuciczucic00000000000000/* Copyright (C) 2001-2003 Damir Zucic */ /*============================================================================= pseudo_bonds.c Purpose: Prepare pseudo-bonds. Pseudo bonds are formed between neighboring Q atoms. In garlic, there are two pseudoelements, jellium and quarkonium (J and Q). These imaginary elements are used to draw polygonal lines and inert atoms. J atoms do not form any bonds, while Q atoms bind to neighboring Q atoms or, more precisely, to the atoms which are listed as the nearest neighbors in PDB file. The actual distance between neighboring Q atoms is not important. Input: (1) Pointer to MolComplexS structure. (2) The array index of a given macromolecular complex. (3) Pointer to ConfigS structure. Output: (1) Information about pseudo-bonds added. (2) Return value. Return value: (1) The total number of pseudo-bonds on success. (2) Zero if there are no pseudo-atoms. Notes: (1) Pseudo-bonds are treated as type 11. (2) Pair identifier and bond length are not important for pseudo- bonds. Both values are set to zero. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int AddBond_ (AtomS *, int, int, int, size_t, double, int); /*======prepare pseudo-bonds:================================================*/ size_t PseudoBonds_ (MolComplexS *mol_complexSP, int mol_complexI, ConfigS *configSP) { size_t pseudo_bondsN = 0; size_t atomsN, atomI; /* Use signed int to store the following indices: */ int neigh_start, neigh_end, neighborI, combinedI; size_t neighbor_arrayI; AtomS *curr_atomSP, *curr_neighborSP; char *symbolP; int serial1I, serial2I; char chain1ID, chain2ID; /* Return zero if there are no atoms: */ atomsN = mol_complexSP->atomsN; if (atomsN == 0) return 0; /* The first and the last neighbor to be checked: */ neigh_start = -1; /* Note the sign! */ neigh_end = 1; /* Scan all atoms: */ for (atomI = 0; atomI < atomsN; atomI++) { /** Pointer to the current atom: **/ curr_atomSP = mol_complexSP->atomSP + atomI; /** Only Q atoms form pseudo-bonds: **/ symbolP = curr_atomSP->raw_atomS.chemical_symbolA; if (strcmp (symbolP, " Q") != 0) continue; /** If this point is reached, initialize the number of bonds: **/ curr_atomSP->bondsN = 0; /** Copy the atomic serial number: **/ serial1I = curr_atomSP->raw_atomS.serialI; /** Copy the chain idenfier: **/ chain1ID = curr_atomSP->raw_atomS.chainID; /** Scan the neighborhood of a given atom: **/ for (neighborI = neigh_start; neighborI <= neigh_end; neighborI++) { /** Atom is not chemically bound to itself: **/ if (neighborI == 0) continue; /** Prepare and check the combined index: **/ combinedI = atomI + neighborI; if (combinedI < 0) continue; if (combinedI >= (int) atomsN) break; /** If combined index is good, use it as array index: **/ neighbor_arrayI = combinedI; /** Pointer to the current neighbor: **/ curr_neighborSP = mol_complexSP->atomSP + neighbor_arrayI; /** Copy the atomic serial number: **/ serial2I = curr_neighborSP->raw_atomS.serialI; /** Copy the chain idenfier: **/ chain2ID = curr_neighborSP->raw_atomS.chainID; /** Compare atomic serial numbers: **/ if ((serial1I + 1 != serial2I) && (serial1I != serial2I + 1)) { continue; } /** Compare chain identifiers: **/ if (chain1ID != chain2ID) continue; /** If this point is reached, the bond does exist! **/ /** Add bond to the current atom. Use dummy values **/ /** for pairID and bond length (set both to zero). **/ /** Pseudo bonds are treated as bonds of type 11. **/ AddBond_ (curr_atomSP, 0, 11, mol_complexI, neighbor_arrayI, 0.0, configSP->default_bond_styleI); /* Update the number of pseudo bonds: **/ pseudo_bondsN++; } } /* If this point is reached, return the total number of pseudo bonds: */ return pseudo_bondsN; } /*===========================================================================*/ garlic-1.6/add_two_colors.c0000644000076500007650000000476007065455536016303 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= add_two_colors.c Purpose: Add (interpolate) two additional colors. Input: (1) The first input color. (2) The second input color. (3) Pointer to GUIS structure. (4) Pointer to the first output color. (5) Pointer to the second output color. Output: (1) The first output color prepared. (2) The second output color prepared. Return value: No return value. =============================================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======add (interpolate) two colors:========================================*/ void AddTwoColors_ (unsigned long input_color1ID, unsigned long input_color2ID, GUIS *guiSP, unsigned long *output_color1IDP, unsigned long *output_color2IDP) { unsigned long red_mask, green_mask, blue_mask; unsigned long red1, red2, red; unsigned long green1, green2, green; unsigned long blue1, blue2, blue; double r1, r2, g1, g2, b1, b2; double w1, w2, r, g, b; /* Copy masks: */ red_mask = guiSP->visual_infoS.red_mask; green_mask = guiSP->visual_infoS.green_mask; blue_mask = guiSP->visual_infoS.blue_mask; /* Extract input color components: */ red1 = input_color1ID & red_mask; red2 = input_color2ID & red_mask; green1 = input_color1ID & green_mask; green2 = input_color2ID & green_mask; blue1 = input_color1ID & blue_mask; blue2 = input_color2ID & blue_mask; /* Convert to doubles: */ r1 = (double) red1; r2 = (double) red2; g1 = (double) green1; g2 = (double) green2; b1 = (double) blue1; b2 = (double) blue2; /* Weighting factors: */ w1 = 2.0 / 3.0; w2 = 1.0 / 3.0; /* The first output color (components): */ r = w1 * r1 + w2 * r2; g = w1 * g1 + w2 * g2; b = w1 * b1 + w2 * b2; red = ((unsigned long) r) & red_mask; green = ((unsigned long) g) & green_mask; blue = ((unsigned long) b) & blue_mask; /* The first output color (value): */ *output_color1IDP = red | green | blue; /* The second output color (components): */ r = w2 * r1 + w1 * r2; g = w2 * g1 + w1 * g2; b = w2 * b1 + w1 * b2; red = ((unsigned long) r) & red_mask; green = ((unsigned long) g) & green_mask; blue = ((unsigned long) b) & blue_mask; /* The second output color (value): */ *output_color2IDP = red | green | blue; } /*===========================================================================*/ garlic-1.6/reset_pos_flag.c0000644000076500007650000000211307065474620016256 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= reset_pos_flag.c Purpose: Reset position_changedF in each macromolecular complex. This flag is used to increase perfomance. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. Output: (1) In each macromolecular complex, position_changedF set to zero. Return value: No return value. ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======reset position_changedF flag in each complex:========================*/ void ResetPositionFlag_ (MolComplexS *mol_complexSP, int mol_complexesN) { int mol_complexI; for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) (mol_complexSP + mol_complexI)->position_changedF = 0; } /*===========================================================================*/ garlic-1.6/patt.script0000644000076500007650000000047210425643301015306 0ustar zuciczucic00000000000000# Playing with patterns. pattern = asp asn glu gln arg lys / asp asn glu gln arg lys his ser thr select pattern color green pattern = asp asn glu gln arg lys his ser thr / asp asn glu gln arg lys select pattern color yellow pattern = asp asn glu gln arg lys / asp asn glu gln arg lys select pattern color red garlic-1.6/extract_ca.c0000644000076500007650000000347107370620235015401 0ustar zuciczucic00000000000000/* Copyright (C) 2001 Damir Zucic */ /*============================================================================= extract_ca.c Purpose: Extract coordinates of the CA atom for a given residue. Input: (1) Pointer to VectorS structure, where CA coord. will be stored. (2) Pointer to AtomS structure, pointing to the first element of the atomic array. (3) Index of the first atom of a given residue. (4) Index of the last atom of a given residue. Output: (1) VectorS structure filled with data. (2) Return value. Return value: (1) The number of successfully extracted vectors (zero or one). Notes: (1) Some files contain more than one entry for some atoms. Garlic uses only the first entry and discards other entries for the same atom. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======extract CA coordinates:==============================================*/ int ExtractCA_ (VectorS *CA_vectorSP, AtomS *atomSP, size_t atom_startI, size_t atom_endI) { int vectors_extractedN = 0; size_t atomI; AtomS *curr_atomSP; /* Scan the given residue: */ for (atomI = atom_startI; atomI <= atom_endI; atomI++) { /* Pointer to the current atom: */ curr_atomSP = atomSP + atomI; /* CA: */ if (strcmp (curr_atomSP->raw_atomS.pure_atom_nameA, "CA") == 0) { CA_vectorSP->x = curr_atomSP->raw_atomS.x[0]; CA_vectorSP->y = curr_atomSP->raw_atomS.y; CA_vectorSP->z = curr_atomSP->raw_atomS.z[0]; vectors_extractedN++; break; } } /* Return the number of extracted vectors: */ return vectors_extractedN; } /*===========================================================================*/ garlic-1.6/extract_cg.c0000644000076500007650000000347107636353356015423 0ustar zuciczucic00000000000000/* Copyright (C) 2003 Damir Zucic */ /*============================================================================= extract_cg.c Purpose: Extract coordinates of the CG atom for a given residue. Input: (1) Pointer to VectorS structure, where CG coord. will be stored. (2) Pointer to AtomS structure, pointing to the first element of the atomic array. (3) Index of the first atom of a given residue. (4) Index of the last atom of a given residue. Output: (1) VectorS structure filled with data. (2) Return value. Return value: (1) The number of successfully extracted vectors (zero or one). Notes: (1) Some files contain more than one entry for some atoms. Garlic uses only the first entry and discards other entries for the same atom. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======extract CG coordinates:==============================================*/ int ExtractCG_ (VectorS *CG_vectorSP, AtomS *atomSP, size_t atom_startI, size_t atom_endI) { int vectors_extractedN = 0; size_t atomI; AtomS *curr_atomSP; /* Scan the given residue: */ for (atomI = atom_startI; atomI <= atom_endI; atomI++) { /* Pointer to the current atom: */ curr_atomSP = atomSP + atomI; /* CG: */ if (strcmp (curr_atomSP->raw_atomS.pure_atom_nameA, "CG") == 0) { CG_vectorSP->x = curr_atomSP->raw_atomS.x[0]; CG_vectorSP->y = curr_atomSP->raw_atomS.y; CG_vectorSP->z = curr_atomSP->raw_atomS.z[0]; vectors_extractedN++; break; } } /* Return the number of extracted vectors: */ return vectors_extractedN; } /*===========================================================================*/ garlic-1.6/patterns3.script0000644000076500007650000000052207647465621016300 0ustar zuciczucic00000000000000# This example is just a variation of patters.script; read description there. # 2003/04/17 pattern = phe trp tyr ile leu val met / * / asn asp gln glu arg lys his / * / asn asp arg lys select pattern color yellow pattern = asn asp arg lys / * / asn asp gln glu arg lys his / * / phe trp tyr ile leu val met select pattern color green garlic-1.6/cpk.c0000644000076500007650000001426707070336763014055 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= cpk.c Purpose: CPK color scheme (Corey, Pauling and Kultun). Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. (3) Pointer to GUIS structure, with GUI data. (4) Pointer to ColorSchemeS structure. Output: (1) Return value. Return value: (1) Positive always. Notes: (1) The color scheme used here is actually a modified CPK, not the original one. =============================================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======CPK color scheme:====================================================*/ int CPK_ (MolComplexS *mol_complexSP, int mol_complexesN, GUIS *guiSP, ColorSchemeS *color_schemeSP) { int carbonI = 6, nitrogenI = 9, oxygenI = 0; int sulfurI = 3, phosphorusI = 12, otherI = 5; int mol_complexI; MolComplexS *curr_mol_complexSP; size_t atomsN, atomI; AtomS *curr_atomSP; size_t rgb_struct_size; ColorSchemeS *schemeSP; int surfaceI; /* The size of RGBS structure: */ rgb_struct_size = sizeof (RGBS); /* Scan every macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check is the current macromolecular complex caught: */ if (curr_mol_complexSP->catchF == 0) continue; /* Number of atoms in a macromolecular complex: */ atomsN = curr_mol_complexSP->atomsN; /* Scan all atoms in the current complex: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Check is atom selected: */ if (curr_atomSP->selectedF == 0) continue; /* Set the number of color surfaces: */ curr_atomSP->surfacesN = 2; /* Carbon: */ if (curr_atomSP->raw_atomS.pure_atom_nameA[0] == 'C') { /* Pointer to the current color scheme: */ schemeSP = color_schemeSP + carbonI; /* Copy the color specifications: */ for (surfaceI = 0; surfaceI < 2; surfaceI++) { /* Left color: */ memcpy (curr_atomSP->left_rgbSA + surfaceI, schemeSP->left_rgbSA + surfaceI, rgb_struct_size); /* Middle color: */ memcpy (curr_atomSP->middle_rgbSA + surfaceI, schemeSP->middle_rgbSA + surfaceI, rgb_struct_size); /* Right color: */ memcpy (curr_atomSP->right_rgbSA + surfaceI, schemeSP->right_rgbSA + surfaceI, rgb_struct_size); } } /* Nitrogen: */ else if (curr_atomSP->raw_atomS.pure_atom_nameA[0] == 'N') { /* Pointer to the current color scheme: */ schemeSP = color_schemeSP + nitrogenI; /* Copy the color specifications: */ for (surfaceI = 0; surfaceI < 2; surfaceI++) { /* Left color: */ memcpy (curr_atomSP->left_rgbSA + surfaceI, schemeSP->left_rgbSA + surfaceI, rgb_struct_size); /* Middle color: */ memcpy (curr_atomSP->middle_rgbSA + surfaceI, schemeSP->middle_rgbSA + surfaceI, rgb_struct_size); /* Right color: */ memcpy (curr_atomSP->right_rgbSA + surfaceI, schemeSP->right_rgbSA + surfaceI, rgb_struct_size); } } /* Oxygen: */ else if (curr_atomSP->raw_atomS.pure_atom_nameA[0] == 'O') { /* Pointer to the current color scheme: */ schemeSP = color_schemeSP + oxygenI; /* Copy the color specifications: */ for (surfaceI = 0; surfaceI < 2; surfaceI++) { /* Left color: */ memcpy (curr_atomSP->left_rgbSA + surfaceI, schemeSP->left_rgbSA + surfaceI, rgb_struct_size); /* Middle color: */ memcpy (curr_atomSP->middle_rgbSA + surfaceI, schemeSP->middle_rgbSA + surfaceI, rgb_struct_size); /* Right color: */ memcpy (curr_atomSP->right_rgbSA + surfaceI, schemeSP->right_rgbSA + surfaceI, rgb_struct_size); } } /* Sulfur: */ else if (curr_atomSP->raw_atomS.pure_atom_nameA[0] == 'S') { /* Pointer to the current color scheme: */ schemeSP = color_schemeSP + sulfurI; /* Copy the color specifications: */ for (surfaceI = 0; surfaceI < 2; surfaceI++) { /* Left color: */ memcpy (curr_atomSP->left_rgbSA + surfaceI, schemeSP->left_rgbSA + surfaceI, rgb_struct_size); /* Middle color: */ memcpy (curr_atomSP->middle_rgbSA + surfaceI, schemeSP->middle_rgbSA + surfaceI, rgb_struct_size); /* Right color: */ memcpy (curr_atomSP->right_rgbSA + surfaceI, schemeSP->right_rgbSA + surfaceI, rgb_struct_size); } } /* Phosphorus: */ else if (curr_atomSP->raw_atomS.pure_atom_nameA[0] == 'P') { /* Pointer to the current color scheme: */ schemeSP = color_schemeSP + phosphorusI; /* Copy the color specifications: */ for (surfaceI = 0; surfaceI < 2; surfaceI++) { /* Left color: */ memcpy (curr_atomSP->left_rgbSA + surfaceI, schemeSP->left_rgbSA + surfaceI, rgb_struct_size); /* Middle color: */ memcpy (curr_atomSP->middle_rgbSA + surfaceI, schemeSP->middle_rgbSA + surfaceI, rgb_struct_size); /* Right color: */ memcpy (curr_atomSP->right_rgbSA + surfaceI, schemeSP->right_rgbSA + surfaceI, rgb_struct_size); } } /* Any other atom: */ else { /* Pointer to the current color scheme: */ schemeSP = color_schemeSP + otherI; /* Copy the color specifications: */ for (surfaceI = 0; surfaceI < 2; surfaceI++) { /* Left color: */ memcpy (curr_atomSP->left_rgbSA + surfaceI, schemeSP->left_rgbSA + surfaceI, rgb_struct_size); /* Middle color: */ memcpy (curr_atomSP->middle_rgbSA + surfaceI, schemeSP->middle_rgbSA + surfaceI, rgb_struct_size); /* Right color: */ memcpy (curr_atomSP->right_rgbSA + surfaceI, schemeSP->right_rgbSA + surfaceI, rgb_struct_size); } } } /* Reset the position_changedF: */ curr_mol_complexSP->position_changedF = 1; } /* Return positive value: */ return 1; } /*===========================================================================*/ garlic-1.6/count0000755000076500007650000000066210345404663014176 0ustar zuciczucic00000000000000echo ' ' echo '=============================' echo 'ls *.c | wc' echo '-----------------------------' ls *.c | wc echo '=============================' echo 'grep "(CCOPT)" Makefile | wc' echo '-----------------------------' grep "(CCOPT)" Makefile | wc echo '=============================' echo 'wc -l -c *.c | grep total' echo '-----------------------------' wc -l -c *.c | grep total echo '=============================' echo ' ' garlic-1.6/command_dump.c0000644000076500007650000002053110445772041015723 0ustar zuciczucic00000000000000/* Copyright (C) 2004-2006 Damir Zucic */ /*============================================================================= command_dump.c Purpose: Execute dump command: dump some numeric data to the specified file or to the standard output stream. Input: (1) Pointer to MolComplexS structure. (2) The number of macromolecular complexes. (3) Pointer to RuntimeS structure. (4) Pointer to the remainder of the command string. The remainder should contain only one keyword and optionally the output file name. The keywords are: AVE (AVERAGE), WEI (WEIGHTED), HYD (HYDROPHOBICITY), F1, F2, F3, F4, F5, F6 and F7. Output: (1) Numeric data written to the output file or to stdout stream. (2) Return value. Return value: (1) Positive (command) code on success. (2) Negative (error) code on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "commands.h" #include "typedefs.h" /*======function prototypes:=================================================*/ char *ExtractToken_ (char *, int, char *, char *); /*======execute dump command:================================================*/ int Dump_ (MolComplexS *mol_complexSP, int mol_complexesN, RuntimeS *runtimeSP, char *stringP) { char *remainderP; char tokenA[STRINGSIZE]; char keywordA[SHORTSTRINGSIZE]; int output_fileF = 0; char string_copyA[STRINGSIZE]; FILE *outfileP = NULL; size_t residueI; double d; /* Extract the first token, if present: */ remainderP = ExtractToken_ (tokenA, STRINGSIZE, stringP, " \t\n"); /* If there are no tokens in the remainder of */ /* the command string, the keyword is missing: */ if (!remainderP) { strcpy (runtimeSP->messageA, "At least one keyword is expected!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_DUMP; } /* Copy up to three letters of the first token for future use: */ strncpy (keywordA, tokenA, 3); keywordA[3] = '\0'; /* If the second token is present, it should contain the output file name: */ remainderP = ExtractToken_ (tokenA, STRINGSIZE, remainderP, " \t\n"); if (!remainderP) output_fileF = 0; /* 0 = send output to stdout */ else output_fileF = 1; /* 1 = send output to a file */ /* Extract the output file name (if requested) and open file: */ if (output_fileF) { /* Copy the original command string: */ strncpy (string_copyA, runtimeSP->curr_commandA, STRINGSIZE - 1); string_copyA[STRINGSIZE - 1] = '\0'; /* Skip two tokens; the third token should contain output file name: */ remainderP = ExtractToken_ (tokenA, STRINGSIZE, string_copyA, " \t\n"); if (!remainderP) { strcpy (runtimeSP->messageA, "Nasty error #1 in Dump_!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_DUMP; } remainderP = ExtractToken_ (tokenA, STRINGSIZE, remainderP, " \t\n"); if (!remainderP) { strcpy (runtimeSP->messageA, "Nasty error #2 in Dump_!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_DUMP; } remainderP = ExtractToken_ (tokenA, STRINGSIZE, remainderP, " \t\n"); if (!remainderP) { strcpy (runtimeSP->messageA, "Nasty error #3 in Dump_!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_DUMP; } /* Try to open output file: */ if (!(outfileP = fopen (tokenA, "w"))) { strcpy (runtimeSP->messageA, "Failed to open output file!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_DUMP; } } /* A paranoid check: */ if (!outfileP) output_fileF = 0; /* Dump the raw hydrophobicity, the average hydrophobicity or some */ /* other hydrophobicity function (F1, F2, F3, F4, F5, F6 or F7): */ if ((strstr (keywordA, "AVE") == keywordA) || (strstr (keywordA, "WEI") == keywordA) || (strstr (keywordA, "HYD") == keywordA) || (strstr (keywordA, "F1") == keywordA) || (strstr (keywordA, "F2") == keywordA) || (strstr (keywordA, "F3") == keywordA) || (strstr (keywordA, "F4") == keywordA) || (strstr (keywordA, "F5") == keywordA) || (strstr (keywordA, "F6") == keywordA) || (strstr (keywordA, "F7") == keywordA)) { /* Write the title: */ if (strstr (keywordA, "AVE") == keywordA) { if (output_fileF) fprintf (outfileP, "# Average hydrophobicity\n"); else fprintf (stdout, "# Average hydrophobicity\n"); } else if (strstr (keywordA, "WEI") == keywordA) { if (output_fileF) fprintf (outfileP, "# Weighted hydrophobicity\n"); else fprintf (stdout, "# Weighted hydrophobicity\n"); } else if (strstr (keywordA, "HYD") == keywordA) { if (output_fileF) fprintf (outfileP, "# Raw hydrophobicity\n"); else fprintf (stdout, "# Raw hydrophobicity\n"); } else if (strstr (keywordA, "F1") == keywordA) { if (output_fileF) fprintf (outfileP, "# Function F1\n"); else fprintf (stdout, "# Function F1\n"); } else if (strstr (keywordA, "F2") == keywordA) { if (output_fileF) fprintf (outfileP, "# Function F2\n"); else fprintf (stdout, "# Function F2\n"); } else if (strstr (keywordA, "F3") == keywordA) { if (output_fileF) fprintf (outfileP, "# Function F3\n"); else fprintf (stdout, "# Function F3\n"); } else if (strstr (keywordA, "F4") == keywordA) { if (output_fileF) fprintf (outfileP, "# Function F4\n"); else fprintf (stdout, "# Function F4\n"); } else if (strstr (keywordA, "F5") == keywordA) { if (output_fileF) fprintf (outfileP, "# Function F5\n"); else fprintf (stdout, "# Function F5\n"); } else if (strstr (keywordA, "F6") == keywordA) { if (output_fileF) fprintf (outfileP, "# Function F6\n"); else fprintf (stdout, "# Function F6\n"); } else if (strstr (keywordA, "F7") == keywordA) { if (output_fileF) fprintf (outfileP, "# Function F7\n"); else fprintf (stdout, "# Function F7\n"); } /* Write the values: */ for (residueI = 0; residueI < runtimeSP->residuesN; residueI++) { /* Write the serial number, without newline: */ if (output_fileF) fprintf (outfileP, "%8d", residueI); else fprintf (stdout, "%8d", residueI); /* Write the requested hydrophobicity function: */ if (strstr (keywordA, "AVE") == keywordA) { d = *(runtimeSP->average_hydrophobicityP + residueI); if (output_fileF) fprintf (outfileP, " %8.2f\n", d); else fprintf (stdout, " %8.2f\n", d); } else if (strstr (keywordA, "WEI") == keywordA) { d = *(runtimeSP->weighted_hydrophobicityP + residueI); if (output_fileF) fprintf (outfileP, " %8.2f\n", d); else fprintf (stdout, " %8.2f\n", d); } else if (strstr (keywordA, "HYD") == keywordA) { d = *(runtimeSP->hydrophobicityP + residueI); if (output_fileF) fprintf (outfileP, " %8.2f\n", d); else fprintf (stdout, " %8.2f\n", d); } else if (strstr (keywordA, "F1") == keywordA) { d = *(runtimeSP->function1P + residueI); if (output_fileF) fprintf (outfileP, " %8.2f\n", d); else fprintf (stdout, " %8.2f\n", d); } else if (strstr (keywordA, "F2") == keywordA) { d = *(runtimeSP->function2P + residueI); if (output_fileF) fprintf (outfileP, " %8.2f\n", d); else fprintf (stdout, " %8.2f\n", d); } else if (strstr (keywordA, "F3") == keywordA) { d = *(runtimeSP->function3P + residueI); if (output_fileF) fprintf (outfileP, " %8.2f\n", d); else fprintf (stdout, " %8.2f\n", d); } else if (strstr (keywordA, "F4") == keywordA) { d = *(runtimeSP->function4P + residueI); if (output_fileF) fprintf (outfileP, " %8.2f\n", d); else fprintf (stdout, " %8.2f\n", d); } else if (strstr (keywordA, "F5") == keywordA) { d = *(runtimeSP->function5P + residueI); if (output_fileF) fprintf (outfileP, " %8.2f\n", d); else fprintf (stdout, " %8.2f\n", d); } else if (strstr (keywordA, "F6") == keywordA) { d = *(runtimeSP->function6P + residueI); if (output_fileF) fprintf (outfileP, " %8.2f\n", d); else fprintf (stdout, " %8.2f\n", d); } else if (strstr (keywordA, "F7") == keywordA) { d = *(runtimeSP->function7P + residueI); if (output_fileF) fprintf (outfileP, " %8.2f\n", d); else fprintf (stdout, " %8.2f\n", d); } } } /* Close the output file, if opened before: */ if (output_fileF) fclose (outfileP); /* Return the command code: */ return COMMAND_DUMP; } /*===========================================================================*/ garlic-1.6/omp85.fasta0000644000076500007650000000155507750417432015116 0ustar zuciczucic00000000000000>tr|O30912 Outer membrane protein Omp85 - Neisseria meningitidis. MKLKQIASALMMLGISPLAFADFTIQDIRVEGLQRTEPSTVFNYLPVKVGDTYNDTHGSA IIKSLYATGFFDDVRVETADGQLLLTVIERPTIGSLNITGAKMLQNDAIKKNLESFGLAQ SQYFNQATLNQAVAGLKEEYLGRGKLNIQITPKVTKLARNRVDIDITIDEGKSAKITDIE FEGNQVYSDRKLMRQMSLTEGGIWTWLTRSNQFNEQKFAQDMEKVTDFYQNNGYFDFRIL DTDIQTNEDKTKQTIKITVHEGGRFRWGKVSIEGDTNEVPKAELEKLLTMKPGKWYERQQ MTAVLGEIQNRMGSAGYAYSEISVQPLPNAETKTVDFVLHIEPGRKIYVNEIHITGNNKT RDEVVRRELRQMESAPYDTSKLQRSKERVELLGYFDNVQFDAVPLAGTPDKVDLNMSLTE RSTGSLDLSAGWVQDTGLVMSAGVSQDNLFGTGKSAALRASRSKTTLNGSLSFTDPYFTA DGVSLGYDVYGKAFDPRKASTSIKQYKTTTAGAGIRMSVPVTEYDRVNFGLVAEHLTVNT YNKAPKHYADFIKKYGKTDGTDGSFKGWLYKGTVGWGRNKTDSALWPTRGYLTGVNAEIA LPGSKLQYYSATHNQTWFFPLSKTFTLMLGGEVGIAGGYGRTKEIPFFENFYGGGLGSVR GYESGTLGPKVYDEYGEKISYGGNKKANVSAELLFPMPGAKDARTVRLSLFADAGSVWDG KTYDDNSSSATGGRVQNIYGAGNTHKSTFTNELRYSAGGAVTWLSPLGPMKFRYAYPLKK KPEDEIQRFQFQLGTTF garlic-1.6/ex2ints.c0000644000076500007650000000246207065470410014656 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= ex2ints.c Purpose: Extract two integers from a string. Input: (1) Pointer to the first integer. (2) Pointer to the second integer. (3) Input string pointer. Output: (1) The first integer value. (2) The second integer value. (3) Return value. Return value: (1) Positive on success. (2) Negative on failure. ========includes:============================================================*/ #include #include #include /*======extract two integers from a string:==================================*/ int ExtractTwoIntegers_ (int *value1P, int *value2P, char *sP) { char *P0, *P1; int n; int n1, n2; /* Colon should be separator: */ if ((P0 = strstr (sP, ":")) == NULL) P0 = sP; else P0++; /* Replace each non-numeric character except minus sign with space: */ P1 = P0; while ((n = *P1++) != '\0') if (!isdigit (n) && (n != '-')) *(P1 - 1) = ' '; /* Try to read two integers: */ if (sscanf (P0, "%d %d", &n1, &n2) != 2) return -1; /* On success, copy the extracted values: */ *value1P = n1; *value2P = n2; /* If everything worked fine, return positive integer: */ return 1; } /*===========================================================================*/ garlic-1.6/log.c0000644000076500007650000000770310000511453014030 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2004 Damir Zucic */ /*============================================================================= log.c Purpose: Execute log command: open the specified log file for writing. If some log file was opened before, close it and create new file. First try to create file in the current working directory; if the first attempt fails, try to create log file in users home directory. Input: (1) Pointer to ConfigS structure, with configuration data. (2) Pointer to RuntimeS structure, with some runtime data. Output: (1) Log file created. (2) Return value. Return value: (1) Positive (command) code on success. (2) Negative (error) code on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include #include #include "defines.h" #include "commands.h" #include "typedefs.h" /*======function prototypes:=================================================*/ char *ExtractToken_ (char *, int, char *, char *); /*======execute log command:=================================================*/ int Log_ (ConfigS *configSP, RuntimeS *runtimeSP) { char *remainderP; char tokenA[STRINGSIZE]; char token_copyA[STRINGSIZE]; char *P; int n; static char *env_valueP; char path_nameA[STRINGSIZE]; /* Skip the first token: */ remainderP = ExtractToken_ (tokenA, STRINGSIZE, runtimeSP->curr_commandA, " \t\n"); if (!remainderP) return ERROR_LOG; /* The second token should contain the file name: */ remainderP = ExtractToken_ (tokenA, STRINGSIZE, remainderP, " \t\n"); if (!remainderP) { strcpy (runtimeSP->messageA, "Log file not specified!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_NO_FILE_NAME; } /* If the second token is keyword OFF, close the */ /* previous log file if opened at all and return: */ strncpy (token_copyA, tokenA, STRINGSIZE - 1); token_copyA[STRINGSIZE - 1] = '\0'; P = token_copyA; while ((n = *P++) != '\0') *(P - 1) = toupper (n); if (strstr (token_copyA, "OFF") == token_copyA) { fclose (configSP->log_fileP); configSP->log_fileF = 0; configSP->log_fileP = NULL; configSP->log_file_nameA[0] = '\0'; return COMMAND_LOG; } /* Some log file may be in use already; close it and reset associated data: */ if (configSP->log_fileF) { fclose (configSP->log_fileP); configSP->log_fileF = 0; configSP->log_fileP = NULL; configSP->log_file_nameA[0] = '\0'; } /* Open the fresh log file: */ configSP->log_fileP = fopen (tokenA, "w"); /* If the first attempt failed, try with users home directory: */ if (configSP->log_fileP == NULL) { /** Prepare the file name pointer: **/ P = tokenA; if (*P == '/') P++; /** The second attempt (using environment variable HOME): **/ if ((env_valueP = getenv ("HOME")) != NULL) { /*** Copy the value of the environment variable HOME: ***/ strncpy (path_nameA, env_valueP, STRINGSIZE - 1); path_nameA[STRINGSIZE - 1] = '\0'; /*** The last character should be slash: ***/ n = (int) strlen (path_nameA) - 1; if (path_nameA[n] != '/') strcat (path_nameA, "/"); /*** Concatename the file name to directory name: ***/ n = STRINGSIZE - (int) strlen (path_nameA) - 1; strncat (path_nameA, P, n); path_nameA[STRINGSIZE - 1] = '\0'; /*** The second attempt to open file: ***/ configSP->log_fileP = fopen (path_nameA, "w"); } } if (configSP->log_fileP == NULL) { sprintf (runtimeSP->messageA, "Unable to open log file %s!", tokenA); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_OPEN_FAILURE; } /* If this point is reached, log file is ready for use: */ strncpy (configSP->log_file_nameA, tokenA, STRINGSIZE - 1); configSP->log_file_nameA[STRINGSIZE - 1] = '\0'; configSP->log_fileF = 1; /* Return positive value on success: */ return COMMAND_LOG; } /*===========================================================================*/ garlic-1.6/alloc_sec_structure.c0000644000076500007650000000402007463607023017322 0ustar zuciczucic00000000000000/* Copyright (C) 2001 Damir Zucic */ /*============================================================================= alloc_sec_structure.c Purpose: Allocate and initialize the storage for the secondary structure associated with a macromolecular complex. Input: (1) Pointer to MolComplexS structure. Output: (1) Storage for the secondary structure information allocated and initialized, on success. (2) Return value. Return value: (1) Positive on success. (2) Negative on failure. Notes: (1) One letter codes are used for the secondary structure. (2) Default conformation is 'E' (extended). ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ void ErrorMessage_ (char *, char *, char *, char *, char *, char *, char *); /*======allocate storage for secondary structure:============================*/ int AllocSecondaryStructure_ (MolComplexS *mol_complexSP) { static size_t char_size; static size_t elementsN; static int i; /* Size of a single character: */ char_size = sizeof (char); /* Allocate storage for the secondary structure */ /* associated with the macromolecular complex: */ elementsN = MAXRESIDUES; mol_complexSP->secondary_structureP = (char *) malloc (elementsN); if (mol_complexSP->secondary_structureP == NULL) { ErrorMessage_ ("garlic", "AllocSecondaryStructure_", "", "Failed to allocate the secondary structure buffer!\n", "", "", ""); return -1; } /* Initialize the secondary structure buffer; */ /* use the code for extended conformation: */ for (i = 0; i < MAXRESIDUES; i++) { *(mol_complexSP->secondary_structureP + i) = 'E'; } /* Return positive value on success: */ return 1; } /*===========================================================================*/ garlic-1.6/draw_plots.c0000644000076500007650000023767410445765130015461 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2006 Damir Zucic */ /*============================================================================= draw_plots.c Purpose: Draw hydrophobicity plots. This function is used if the main win. drawing mode is equal to four. The sequence stored to the sequence buffer is used to calculate requested functions. More plots may be drawn simultaneosly. The following functions are available: - average hydrophobicity; - weighted hydrophobicity; - hydrophobic moment; - two sided hydrophobicity profiles (larger and smaller); - hydrophobicity function F1. - hydrophobicity function F2. - hydrophobicity function F3. - hydrophobicity function F4. - hydrophobicity function F5. Input: (1) Pointer to RuntimeS structure, with some runtime data. (2) Pointer to GUIS structure, with GUI data. (3) Pointer to NearestAtomS structure, with information about the atom occupying the given pixel. (4) The number of pixels in the main window free area. (5) The refreshI, used to check the NearestAtomS associated with a given pixel. It is currently unused in this function. Output: (1) Hydrophobicity plots should be drawn to the main window. (2) Return value. Return value: (1) The number of residues used in calculation, on success. (2) Zero on failure. Notes: (1) The initial drawing destination is the hidden pixmap, and the content of this pixmap is copied later to the main window. (2) The residue index is stored as the atomic index. The function value (average hydrophobicity, hydrophobic moment etc.) is stored as z coordinate. (3) Both sided hydrophobicity values (larger one and smaller one) are normalized (divided) by the sliding window width. This ensures that the sum of two values is equal to the average hydrophobicity value. (4) Red color is used to draw both the average hydrophobicity and the function F6. Blue color is used to draw both the hydroph. moment and the function F7. ========includes:============================================================*/ #include #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int RefreshPixmap_ (Display *, Pixmap, GC, unsigned int, unsigned int, unsigned long); int ParseColor_ (RGBS *, unsigned long *, GUIS *, char *, char *); int AverageHydrophobicity_ (double *, double *, RuntimeS *); int WeightedHydrophobicity_ (double *, double *, RuntimeS *); int HyphobFunction1_ (double *, double *, RuntimeS *); int HyphobFunction2_ (double *, double *, RuntimeS *); int HyphobFunction3_ (double *, double *, RuntimeS *); int HyphobFunction4_ (double *, double *, RuntimeS *); int HyphobFunction5_ (double *, double *, RuntimeS *); int HyphobFunction6_ (double *, double *, RuntimeS *); int HyphobFunction7_ (double *, double *, RuntimeS *); /*======draw hydrophobicity plots:===========================================*/ size_t DrawPlots_ (RuntimeS *runtimeSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int refreshI) { int residuesN, residueI; /* Do not use size_t instead of int ! */ int used_residuesN; int range_startI, range_endI, residues_in_plotN = 0; int visible_residueI; int window_width, half_window_width, windowI, combinedI; double angle_step, angle; double hydrophobicity; static double weighted_hydrophobicity = 0.0, average_hydrophobicity = 0; double min_average_hyphob, max_average_hyphob; double min_weighted_hyphob, max_weighted_hyphob; double hydrophobic_moment, abs_squared, moment_x, moment_y; double min_hyphob_moment, max_hyphob_moment; double min_sided_hyphob, max_sided_hyphob; int even_residuesN, odd_residuesN; double even_side_hyphob, odd_side_hyphob; double larger_side_hyphob, smaller_side_hyphob; int screen_width, screen_height; int screen_margin_x, screen_margin_top, screen_margin_bottom; int screen_delta_x, screen_delta_y; int residue_screen_width, half_residue_width; int residues_per_sectionN; int sectionsN, sectionI; int section_width, section_height; int frame_x0, frame_x1, frame_y0, frame_y1; int section_y0; unsigned long color1ID, color2ID, color3ID, color4ID; RGBS rgbS; double ordinate_min, ordinate_max, ordinate_range, ordinate_scale; int local_residueI; int screen_x0, screen_x1, screen_y0, screen_y1; double d; int residue_serialI; char stringA[SHORTSTRINGSIZE]; int string_length; int text_height, text_ascent, text_width, half_text_width; int old_screen_y = 0, screen_x, screen_y; int draw_vertical_lineF = 0; size_t pixelI; NearestAtomS *curr_pixelSP; int shift = 0; double min_function1 = 0.0, max_function1 = 0.0, function1; double min_function2 = 0.0, max_function2 = 0.0, function2; double min_function3 = 0.0, max_function3 = 0.0, function3; double min_function4 = 0.0, max_function4 = 0.0, function4; double min_function5 = 0.0, max_function5 = 0.0, function5; double min_function6 = 0.0, max_function6 = 0.0, function6; double min_function7 = 0.0, max_function7 = 0.0, function7; /*------prepare some parameters:---------------------------------------------*/ /* The number of residues in sequence buffer: */ residuesN = (int) runtimeSP->residuesN; if (residuesN == 0) { strcpy (runtimeSP->messageA, "The sequence buffer is empty!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return 0; } /* Paranoid check - at least one flag should be different from zero: */ if ((runtimeSP->average_hydrophobicityF == 0) && (runtimeSP->weighted_hydrophobicityF == 0) && (runtimeSP->hydrophobic_momentF == 0) && (runtimeSP->sided_hydrophobicityF == 0) && (runtimeSP->function1F == 0) && (runtimeSP->function2F == 0) && (runtimeSP->function3F == 0) && (runtimeSP->function4F == 0) && (runtimeSP->function5F == 0) && (runtimeSP->function6F == 0) && (runtimeSP->function7F == 0)) return 0; /* The range of residue array indices: */ range_startI = runtimeSP->range_startI; range_endI = runtimeSP->range_endI; /* Count the number of residues in the specified range: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Check is the residue array index inside the range: */ if ((residueI < range_startI) || (residueI > range_endI)) continue; /* Increase the count of residues if current */ /* residue belongs to the specified range: */ residues_in_plotN++; } /* Check the number of residues in a plot: */ if (residues_in_plotN == 0) { strcpy (runtimeSP->messageA, "The specified range is empty!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return 0; } /* The sliding window width: */ window_width = runtimeSP->sliding_window_width; half_window_width = window_width / 2; /* The helix step angle: */ angle_step = DEG_TO_RAD * runtimeSP->helix_step_angle; /*------refresh the hidden pixmap:-------------------------------------------*/ /* Refresh the hidden pixmap, where drawing will be done: */ RefreshPixmap_ (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], guiSP->control_winS.x0, guiSP->input_winS.y0, guiSP->main_winS.bg_colorID); /*------calculate the average hydrophobicity:--------------------------------*/ /* Initialize the extreme values: */ min_average_hyphob = +999999.0; max_average_hyphob = -999999.0; AverageHydrophobicity_ (&min_average_hyphob, &max_average_hyphob, runtimeSP); /*------calculate the weighted hydrophobicity:-------------------------------*/ /* Initialize the extreme values: */ min_weighted_hyphob = +999999.0; max_weighted_hyphob = -999999.0; WeightedHydrophobicity_ (&min_weighted_hyphob, &max_weighted_hyphob, runtimeSP); /*------calculate the hydrophobic moment:------------------------------------*/ /* Initialize the extreme values: */ min_hyphob_moment = +999999.0; max_hyphob_moment = -999999.0; /* Scan the sequence: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Reset the number of residues used for calculation: */ used_residuesN = 0; /* Reset the projections: */ moment_x = 0.0; moment_y = 0.0; /* Scan the sliding window: */ for (windowI = 0; windowI < window_width; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI - half_window_width + windowI; if (combinedI < 0) continue; if (combinedI >= residuesN) continue; /* The hydrophobicity of the residue defined by combinedI: */ hydrophobicity = *(runtimeSP->hydrophobicityP + combinedI); /* The angle: */ angle = angle_step * (double) windowI; /* Hydrophobic moment projections: */ moment_x += (double) hydrophobicity * cos (angle); moment_y += (double) hydrophobicity * sin (angle); /* Increase the number of residues used for calculation: */ used_residuesN++; } /* Calculate the hydrophobic moment: */ abs_squared = moment_x * moment_x + moment_y * moment_y; if (used_residuesN == window_width) { hydrophobic_moment = sqrt (abs_squared) / (double) window_width; } else hydrophobic_moment = 0.0; /* Store the hydrophobic moment: */ *(runtimeSP->hydrophobic_momentP + residueI) = hydrophobic_moment; /* Dummy values should not be used to determine extreme values: */ if (used_residuesN != window_width) continue; /* Find the extreme values: */ if (hydrophobic_moment < min_hyphob_moment) { min_hyphob_moment = hydrophobic_moment; } if (hydrophobic_moment > max_hyphob_moment) { max_hyphob_moment = hydrophobic_moment; } } /*------calculate two sided hydrophobicity values:---------------------------*/ /* Initialize the extreme values: */ min_sided_hyphob = +999999.0; max_sided_hyphob = -999999.0; /* Scan the sequence: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Reset two counts of residues used to calculate the side */ /* hydrophobicity (even and odd residues counted separately): */ even_residuesN = 0; odd_residuesN = 0; /* Reset side hydrophobicity values for even and odd residues: */ even_side_hyphob = 0.0; odd_side_hyphob = 0.0; /* Scan the sliding window: */ for (windowI = 0; windowI < window_width; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI - half_window_width + windowI; if (combinedI < 0) continue; if (combinedI >= residuesN) continue; /* The hydrophobicity of the residue defined by combinedI: */ hydrophobicity = (double) *(runtimeSP->hydrophobicityP + combinedI); /* Calculate the side hydrophobicity for even and odd */ /* residues. Update the number of even and odd residues. */ if (combinedI % 2) { odd_side_hyphob += hydrophobicity; odd_residuesN++; } else { even_side_hyphob += hydrophobicity; even_residuesN++; } } /* Divide both values by the sliding window width: */ if (even_residuesN != 0) even_side_hyphob /= (double) window_width; else even_side_hyphob = 0.0; if (odd_residuesN != 0) odd_side_hyphob /= (double) window_width; else odd_side_hyphob = 0.0; /* Check the total number of even and odd residues. If it is */ /* not equal to the sliding window width, reset both values! */ if (even_residuesN + odd_residuesN != window_width) { even_side_hyphob = 0.0; odd_side_hyphob = 0.0; } /* Store the larger value to the buffer reserved for upper line */ /* and the smaller value to the buffer reserver for bottom line: */ if (even_side_hyphob >= odd_side_hyphob) { larger_side_hyphob = even_side_hyphob; smaller_side_hyphob = odd_side_hyphob; } else { larger_side_hyphob = odd_side_hyphob; smaller_side_hyphob = even_side_hyphob; } *(runtimeSP->larger_sided_hyphobP + residueI) = larger_side_hyphob; *(runtimeSP->smaller_sided_hyphobP + residueI) = smaller_side_hyphob; /* Dummy values should not be used to determine extremes: */ if (even_residuesN + odd_residuesN != window_width) continue; /* Find the extreme values: */ if (smaller_side_hyphob < min_sided_hyphob) { min_sided_hyphob = smaller_side_hyphob; } if (larger_side_hyphob > max_sided_hyphob) { max_sided_hyphob = larger_side_hyphob; } } /*------calculate hydrophobicity functions, in reverse order.----------------*/ /* Note: some functions with higher number may call functions with */ /* lower number - that explains why reverse order should be used! */ /*------calculate the hydrophobicity function F7:----------------------------*/ if (runtimeSP->function7F) HyphobFunction7_ (&min_function7, &max_function7, runtimeSP); /*------calculate the hydrophobicity function F6:----------------------------*/ if (runtimeSP->function6F) HyphobFunction6_ (&min_function6, &max_function6, runtimeSP); /*------calculate the hydrophobicity function F5:----------------------------*/ if (runtimeSP->function5F) HyphobFunction5_ (&min_function5, &max_function5, runtimeSP); /*------calculate the hydrophobicity function F4:----------------------------*/ if (runtimeSP->function4F) HyphobFunction4_ (&min_function4, &max_function4, runtimeSP); /*------calculate the hydrophobicity function F3:----------------------------*/ if (runtimeSP->function3F) HyphobFunction3_ (&min_function3, &max_function3, runtimeSP); /*------calculate the hydrophobicity function F2:----------------------------*/ if (runtimeSP->function2F) HyphobFunction2_ (&min_function2, &max_function2, runtimeSP); /*------calculate the hydrophobicity function F1:----------------------------*/ if (runtimeSP->function1F) HyphobFunction1_ (&min_function1, &max_function1, runtimeSP); /*------prepare geometric parameters:----------------------------------------*/ /* Width, height and margins (margins will be updated later): */ screen_width = guiSP->main_win_free_area_width; screen_height = guiSP->main_win_free_area_height; screen_margin_x = screen_width / 40; if (screen_margin_x < 4) screen_margin_x = 4; screen_margin_bottom = screen_height / 40; if (screen_margin_bottom < 4) screen_margin_bottom = 4; screen_margin_top = 2 * screen_margin_bottom + guiSP->main_winS.font_height; screen_delta_x = screen_width - 2 * screen_margin_x; if (screen_delta_x < 10) screen_delta_x = 10; screen_delta_y = screen_height - screen_margin_top - screen_margin_bottom; if (screen_delta_y < 10) screen_delta_y = 10; /* Break the entire sequence range into more */ /* parts, if the number of residues is large: */ residue_screen_width = RESIDUE_WIDTH; half_residue_width = residue_screen_width / 2; if (residue_screen_width <= 0) return 0; residues_per_sectionN = screen_delta_x / residue_screen_width; if (residues_per_sectionN == 0) { sectionsN = 1; } else { sectionsN = (residues_in_plotN + residues_per_sectionN - 1) / residues_per_sectionN; } /* The screen height should be divided into equal portions: */ if (sectionsN == 0) section_height = screen_delta_y; else section_height = screen_delta_y / sectionsN; /* Avoid ugly proportions: */ if (section_height / residue_screen_width > 80) { section_height = 80 * residue_screen_width; } /* Update plot width, height and margins: */ if (residues_in_plotN > residues_per_sectionN) { screen_delta_x = residues_per_sectionN * residue_screen_width; } else { screen_delta_x = residues_in_plotN * residue_screen_width; } screen_margin_x = (screen_width - screen_delta_x) / 2; screen_margin_bottom = (screen_height - section_height * sectionsN - guiSP->main_winS.font_height) / 3; if (screen_margin_bottom < 4) screen_margin_bottom = 4; screen_margin_top = 2 * screen_margin_bottom + guiSP->main_winS.font_height; /* Set the section width: */ section_width = screen_delta_x; /*------draw frames:---------------------------------------------------------*/ /* Frame left and right edge: */ frame_x0 = screen_margin_x; frame_x1 = frame_x0 + section_width; /* Frame top and bottom edge: */ frame_y0 = screen_margin_top; frame_y1 = screen_margin_top + sectionsN * section_height; /* Prepare colors: */ ParseColor_ (&rgbS, &color1ID, guiSP, "RGB:3333/3333/3333", "black"); ParseColor_ (&rgbS, &color2ID, guiSP, "RGB:6666/6666/6666", "black"); ParseColor_ (&rgbS, &color3ID, guiSP, "RGB:AAAA/AAAA/AAAA", "white"); ParseColor_ (&rgbS, &color4ID, guiSP, "RGB:EEEE/EEEE/EEEE", "white"); XSetForeground (guiSP->displaySP, guiSP->theGCA[1], color1ID); XSetForeground (guiSP->displaySP, guiSP->theGCA[2], color2ID); XSetForeground (guiSP->displaySP, guiSP->theGCA[3], color3ID); XSetForeground (guiSP->displaySP, guiSP->theGCA[4], color4ID); XSetForeground (guiSP->displaySP, guiSP->theGCA[5], color3ID); XSetForeground (guiSP->displaySP, guiSP->theGCA[6], color2ID); XSetForeground (guiSP->displaySP, guiSP->theGCA[7], color1ID); /* Draw vertical lines: */ XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], frame_x0 - 3, frame_y0 - 3, frame_x0 - 3, frame_y1 + 3); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], frame_x0 - 2, frame_y0 - 3, frame_x0 - 2, frame_y1 + 3); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[3], frame_x0 - 1, frame_y0 - 3, frame_x0 - 1, frame_y1 + 3); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[4], frame_x0 - 0, frame_y0 - 3, frame_x0 - 0, frame_y1 + 3); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[5], frame_x0 + 1, frame_y0 - 3, frame_x0 + 1, frame_y1 + 3); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[6], frame_x0 + 2, frame_y0 - 3, frame_x0 + 2, frame_y1 + 3); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[7], frame_x0 + 3, frame_y0 - 3, frame_x0 + 3, frame_y1 + 3); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], frame_x1 - 3, frame_y0 - 3, frame_x1 - 3, frame_y1 + 3); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], frame_x1 - 2, frame_y0 - 3, frame_x1 - 2, frame_y1 + 3); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[3], frame_x1 - 1, frame_y0 - 3, frame_x1 - 1, frame_y1 + 3); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[4], frame_x1 - 0, frame_y0 - 3, frame_x1 - 0, frame_y1 + 3); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[5], frame_x1 + 1, frame_y0 - 3, frame_x1 + 1, frame_y1 + 3); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[6], frame_x1 + 2, frame_y0 - 3, frame_x1 + 2, frame_y1 + 3); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[7], frame_x1 + 3, frame_y0 - 3, frame_x1 + 3, frame_y1 + 3); /* Draw horizontal lines: */ for (sectionI = 0; sectionI <= sectionsN; sectionI++) { section_y0 = screen_margin_top + sectionI * section_height; XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], frame_x0 + 3, section_y0 - 3, frame_x1 - 3, section_y0 - 3); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], frame_x0 + 2, section_y0 - 2, frame_x1 - 2, section_y0 - 2); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[3], frame_x0 + 1, section_y0 - 1, frame_x1 - 1, section_y0 - 1); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[4], frame_x0 + 0, section_y0 - 0, frame_x1 - 0, section_y0 - 0); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[5], frame_x0 + 1, section_y0 + 1, frame_x1 - 1, section_y0 + 1); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[6], frame_x0 + 2, section_y0 + 2, frame_x1 - 2, section_y0 + 2); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[7], frame_x0 + 3, section_y0 + 3, frame_x1 - 3, section_y0 + 3); } /* Fix top and bottom of the frame: */ section_y0 = screen_margin_top; XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], frame_x0 - 3, section_y0 - 3, frame_x1 + 3, section_y0 - 3); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], frame_x0 - 2, section_y0 - 2, frame_x1 + 2, section_y0 - 2); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[3], frame_x0 - 1, section_y0 - 1, frame_x1 + 1, section_y0 - 1); section_y0 = screen_margin_top + sectionsN * section_height; XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], frame_x0 - 3, section_y0 + 3, frame_x1 + 3, section_y0 + 3); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], frame_x0 - 2, section_y0 + 2, frame_x1 + 2, section_y0 + 2); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[3], frame_x0 - 1, section_y0 + 1, frame_x1 + 1, section_y0 + 1); /*------prepare ordinate extreme values and scale factor:--------------------*/ /* Prepare extreme values for the ordinate axis: */ ordinate_min = +999999.0; ordinate_max = -999999.0; if (runtimeSP->average_hydrophobicityF) { if (min_average_hyphob < ordinate_min) { ordinate_min = min_average_hyphob; } if (max_average_hyphob > ordinate_max) { ordinate_max = max_average_hyphob; } } if (runtimeSP->weighted_hydrophobicityF) { if (min_weighted_hyphob < ordinate_min) { ordinate_min = min_weighted_hyphob; } if (max_weighted_hyphob > ordinate_max) { ordinate_max = max_weighted_hyphob; } } if (runtimeSP->hydrophobic_momentF) { if (min_hyphob_moment < ordinate_min) { ordinate_min = min_hyphob_moment; } if (max_hyphob_moment > ordinate_max) { ordinate_max = max_hyphob_moment; } } if (runtimeSP->sided_hydrophobicityF) { if (min_sided_hyphob < ordinate_min) { ordinate_min = min_sided_hyphob; } if (max_sided_hyphob > ordinate_max) { ordinate_max = max_sided_hyphob; } } if (runtimeSP->function1F) { if (min_function1 < ordinate_min) { ordinate_min = min_function1; } if (max_function1 > ordinate_max) { ordinate_max = max_function1; } } if (runtimeSP->function2F) { if (min_function2 < ordinate_min) { ordinate_min = min_function2; } if (max_function2 > ordinate_max) { ordinate_max = max_function2; } } if (runtimeSP->function3F) { if (min_function3 < ordinate_min) { ordinate_min = min_function3; } if (max_function3 > ordinate_max) { ordinate_max = max_function3; } } if (runtimeSP->function4F) { if (min_function4 < ordinate_min) { ordinate_min = min_function4; } if (max_function4 > ordinate_max) { ordinate_max = max_function4; } } if (runtimeSP->function5F) { if (min_function5 < ordinate_min) { ordinate_min = min_function5; } if (max_function5 > ordinate_max) { ordinate_max = max_function5; } } if (runtimeSP->function6F) { if (min_function6 < ordinate_min) { ordinate_min = min_function6; } if (max_function6 > ordinate_max) { ordinate_max = max_function6; } } if (runtimeSP->function7F) { if (min_function7 < ordinate_min) { ordinate_min = min_function7; } if (max_function7 > ordinate_max) { ordinate_max = max_function7; } } /* Shift both values slightly for esthetic reasons: */ ordinate_range = ordinate_max - ordinate_min; ordinate_min -= 0.15 * ordinate_range; ordinate_max += 0.15 * ordinate_range; /* Prepare the ordinate scale factor: */ ordinate_range = ordinate_max - ordinate_min; if (ordinate_range != 0.0) { ordinate_scale = (double) section_height / ordinate_range; } else ordinate_scale = 0.0; /*------draw vertical grid (every 10 residues):------------------------------*/ /* Initialize the visible residue index: */ visible_residueI = 0; /* Scan the sequence: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Check is the residue array index inside the range: */ if ((residueI < range_startI) || (residueI > range_endI)) { continue; } /* Draw line at the following positions: 10, 20, 30, ... */ if (((visible_residueI + 1) % 10) != 0) { visible_residueI++; continue; } /* Prepare the position: */ sectionI = visible_residueI / residues_per_sectionN; local_residueI = visible_residueI % residues_per_sectionN; screen_x = screen_margin_x + local_residueI * residue_screen_width; if ((screen_x >= frame_x1 - 3) || (screen_x <= frame_x0 + 3)) { visible_residueI++; continue; } /* Top and bottom of the vertical line: */ screen_y0 = screen_margin_top + (sectionI + 1) * section_height - 4; screen_y1 = screen_margin_top + sectionI * section_height + 4; /* Draw line: */ XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], screen_x, screen_y0, screen_x, screen_y1); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[4], screen_x + 1, screen_y0, screen_x + 1, screen_y1); /* Update the counter of visible residues: */ visible_residueI++; } /*------draw abscisa:--------------------------------------------------------*/ /* Left and right extent of the abscisa axis: */ screen_x0 = frame_x0 + 4; screen_x1 = frame_x1 - 4; /* Draw abscisa in each section: */ if ((ordinate_min < 0.0) && (ordinate_max > 0.0)) { for (sectionI = 0; sectionI < sectionsN; sectionI++) { d = -ordinate_min * ordinate_scale; screen_y0 = screen_margin_top + (sectionI + 1) * section_height - (int) d; XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], screen_x0, screen_y0 + 1, screen_x1, screen_y0 + 1); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[3], screen_x0, screen_y0, screen_x1, screen_y0); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[4], screen_x0, screen_y0 - 1, screen_x1, screen_y0 - 1); } } /*------draw labels:---------------------------------------------------------*/ /* Text height and ascent for the main window font: */ text_height = guiSP->main_winS.font_height; text_ascent = guiSP->main_winS.fontSP->ascent; /* Prepare the text color: */ XSetForeground (guiSP->displaySP, guiSP->theGCA[0], guiSP->main_winS.fg_colorID); /* Reset the visible residue index: */ visible_residueI = 0; /* Scan the sequence: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Check is the residue array index inside the range: */ if ((residueI < range_startI) || (residueI > range_endI)) { continue; } /* Write label at the following positions: 10, 20, 30, ... */ if (((visible_residueI + 1) % 10) != 0) { visible_residueI++; continue; } /* Use the stored sequence index: */ residue_serialI = *(runtimeSP->serialIP + residueI); /* Prepare section index and local residue index: */ sectionI = visible_residueI / residues_per_sectionN; local_residueI = visible_residueI % residues_per_sectionN; /* Prepare the label: */ sprintf (stringA, "%d", residue_serialI); string_length = strlen (stringA); text_width = XTextWidth (guiSP->main_winS.fontSP, stringA, strlen (stringA)); half_text_width = text_width / 2; /* Prepare the position where the label should be drawn: */ screen_x = screen_margin_x + local_residueI * residue_screen_width - half_text_width; if ((screen_x >= frame_x1 - text_width - 3) || (screen_x <= frame_x0 + 3)) { visible_residueI++; continue; } d = -ordinate_min * ordinate_scale; screen_y = screen_margin_top + (sectionI + 1) * section_height - 5; /* Draw the label: */ XDrawString (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x, screen_y, stringA, strlen (stringA)); /* Update the local residue index: */ visible_residueI++; } /*------draw average hydrophobicity (red line):------------------------------*/ if (runtimeSP->average_hydrophobicityF) { /* Prepare three colors for average hydrophobicity: */ ParseColor_ (&rgbS, &color1ID, guiSP, "RGB:FFFF/8888/8888", "white"); ParseColor_ (&rgbS, &color2ID, guiSP, "RGB:FFFF/0000/0000", "white"); ParseColor_ (&rgbS, &color3ID, guiSP, "RGB:8888/0000/0000", "black"); XSetForeground (guiSP->displaySP, guiSP->theGCA[1], color1ID); XSetForeground (guiSP->displaySP, guiSP->theGCA[2], color2ID); XSetForeground (guiSP->displaySP, guiSP->theGCA[3], color3ID); /* Reset the counter of visible residues: */ visible_residueI = 0; /* Scan the sequence: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Check is the residue array index inside the range: */ if ((residueI < range_startI) || (residueI > range_endI)) { continue; } /* Copy the average hydrophobicity: */ average_hydrophobicity = (double) *(runtimeSP->average_hydrophobicityP + residueI); /* Prepare the section index: */ sectionI = visible_residueI / residues_per_sectionN; /* Prepare the local residue index: */ local_residueI = visible_residueI % residues_per_sectionN; /* Prepare screen coordinates: */ screen_x0 = screen_margin_x + local_residueI * residue_screen_width - half_residue_width - 1; screen_x1 = screen_x0 + residue_screen_width + 2; d = (average_hydrophobicity - ordinate_min) * ordinate_scale; screen_y0 = screen_margin_top + sectionI * section_height; screen_y1 = screen_y0 + section_height; screen_y = screen_y1 - (int) d; /* Draw triple line: */ XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], screen_x0, screen_y - 1, screen_x1, screen_y - 1); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], screen_x0, screen_y, screen_x1, screen_y); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[3], screen_x0, screen_y + 1, screen_x1, screen_y + 1); /* Initialize the flag which says is */ /* it necessary to draw vertical line: */ draw_vertical_lineF = 1; /* For the first residue in the current */ /* section do not draw the vertical line: */ if (local_residueI == 0) { old_screen_y = screen_y0; draw_vertical_lineF = 0; } /* For the first residue, do not draw the vertical line: */ if (residueI == range_startI) { old_screen_y = screen_y; draw_vertical_lineF = 0; } /* Check is it necessary to draw vertical line: */ if (old_screen_y == screen_y) { old_screen_y = screen_y; draw_vertical_lineF = 0; } /* Prepare the shift which is required to draw corners; take */ /* the next res. if there is no need to draw vertical lines: */ if (old_screen_y < screen_y) shift = -1; else shift = +1; /* Draw three vertical lines: */ if (draw_vertical_lineF) { XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], screen_x0, old_screen_y - shift, screen_x0, screen_y - shift); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], screen_x0 + 1, old_screen_y, screen_x0 + 1, screen_y); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[3], screen_x0 + 2, old_screen_y + shift, screen_x0 + 2, screen_y + shift); } /* Copy the y coordinate for later use: */ old_screen_y = screen_y; /* Fill NearestAtomS array: */ for (screen_x = screen_x0 + 2; screen_x <= screen_x1 - 1; screen_x++) { for (screen_y = screen_y0; screen_y <= screen_y1; screen_y++) { /* Prepare index to the array */ /* of NearestAtomS structures: */ pixelI = guiSP->main_win_free_area_width * screen_y + screen_x; /* Check the pixel index: */ if (pixelI >= pixelsN) continue; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = nearest_atomSP + pixelI; /* Refresh NearestAtomS associated with */ /* this pixel; residue index is stored */ /* to location reserved for atom index. */ curr_pixelSP->last_refreshI = refreshI; curr_pixelSP->atomI = residueI; curr_pixelSP->z = average_hydrophobicity; } } /* Update the counter of visible residues: */ visible_residueI++; } } /*------draw weighted hydrophobicity (pink line):----------------------------*/ if (runtimeSP->weighted_hydrophobicityF) { /* Prepare three colors for weighted hydrophobicity: */ ParseColor_ (&rgbS, &color1ID, guiSP, "RGB:FFFF/8888/BBBB", "white"); ParseColor_ (&rgbS, &color2ID, guiSP, "RGB:FFFF/0000/BBBB", "white"); ParseColor_ (&rgbS, &color3ID, guiSP, "RGB:9999/0000/5555", "black"); XSetForeground (guiSP->displaySP, guiSP->theGCA[1], color1ID); XSetForeground (guiSP->displaySP, guiSP->theGCA[2], color2ID); XSetForeground (guiSP->displaySP, guiSP->theGCA[3], color3ID); /* Reset the counter of visible residues: */ visible_residueI = 0; /* Scan the sequence: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Check is the residue array index inside the range: */ if ((residueI < range_startI) || (residueI > range_endI)) { continue; } /* Copy the weighted hydrophobicity: */ weighted_hydrophobicity = (double) *(runtimeSP->weighted_hydrophobicityP + residueI); /* Prepare the section index: */ sectionI = visible_residueI / residues_per_sectionN; /* Prepare the local residue index: */ local_residueI = visible_residueI % residues_per_sectionN; /* Prepare screen coordinates: */ screen_x0 = screen_margin_x + local_residueI * residue_screen_width - half_residue_width - 1; screen_x1 = screen_x0 + residue_screen_width + 2; d = (weighted_hydrophobicity - ordinate_min) * ordinate_scale; screen_y0 = screen_margin_top + sectionI * section_height; screen_y1 = screen_y0 + section_height; screen_y = screen_y1 - (int) d; /* Draw triple line: */ XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], screen_x0, screen_y - 1, screen_x1, screen_y - 1); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], screen_x0, screen_y, screen_x1, screen_y); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[3], screen_x0, screen_y + 1, screen_x1, screen_y + 1); /* Initialize the flag which says is */ /* it necessary to draw vertical line: */ draw_vertical_lineF = 1; /* For the first residue in the current */ /* section do not draw the vertical line: */ if (local_residueI == 0) { old_screen_y = screen_y0; draw_vertical_lineF = 0; } /* For the first residue, do not draw the vertical line: */ if (residueI == range_startI) { old_screen_y = screen_y; draw_vertical_lineF = 0; } /* Check is it necessary to draw vertical line: */ if (old_screen_y == screen_y) { old_screen_y = screen_y; draw_vertical_lineF = 0; } /* Prepare the shift which is required to draw corners; take */ /* the next res. if there is no need to draw vertical lines: */ if (old_screen_y < screen_y) shift = -1; else shift = +1; /* Draw three vertical lines: */ if (draw_vertical_lineF) { XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], screen_x0, old_screen_y - shift, screen_x0, screen_y - shift); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], screen_x0 + 1, old_screen_y, screen_x0 + 1, screen_y); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[3], screen_x0 + 2, old_screen_y + shift, screen_x0 + 2, screen_y + shift); } /* Copy the y coordinate for later use: */ old_screen_y = screen_y; /* Fill NearestAtomS array: */ for (screen_x = screen_x0 + 2; screen_x <= screen_x1 - 1; screen_x++) { for (screen_y = screen_y0; screen_y <= screen_y1; screen_y++) { /* Prepare index to the array */ /* of NearestAtomS structures: */ pixelI = guiSP->main_win_free_area_width * screen_y + screen_x; /* Check the pixel index: */ if (pixelI >= pixelsN) continue; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = nearest_atomSP + pixelI; /* Refresh NearestAtomS associated with */ /* this pixel; residue index is stored */ /* to location reserved for atom index. */ curr_pixelSP->last_refreshI = refreshI; curr_pixelSP->atomI = residueI; curr_pixelSP->z = weighted_hydrophobicity; } } /* Update the counter of visible residues: */ visible_residueI++; } } /*------draw hydrophobic moment (blue line):---------------------------------*/ if (runtimeSP->hydrophobic_momentF) { /* Prepare three colors for hydrophobic moment: */ ParseColor_ (&rgbS, &color1ID, guiSP, "RGB:8888/DDDD/FFFF", "white"); ParseColor_ (&rgbS, &color2ID, guiSP, "RGB:0000/8888/FFFF", "white"); ParseColor_ (&rgbS, &color3ID, guiSP, "RGB:0000/4444/8888", "black"); XSetForeground (guiSP->displaySP, guiSP->theGCA[1], color1ID); XSetForeground (guiSP->displaySP, guiSP->theGCA[2], color2ID); XSetForeground (guiSP->displaySP, guiSP->theGCA[3], color3ID); /* Reset the counter of visible residues: */ visible_residueI = 0; /* Scan the sequence: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Check is the residue array index inside the range: */ if ((residueI < range_startI) || (residueI > range_endI)) { continue; } /* Copy the hydrophobic moment: */ hydrophobic_moment = (double) *(runtimeSP->hydrophobic_momentP + residueI); /* Prepare the section index: */ sectionI = visible_residueI / residues_per_sectionN; /* Prepare the local residue index: */ local_residueI = visible_residueI % residues_per_sectionN; /* Prepare screen coordinates: */ screen_x0 = screen_margin_x + local_residueI * residue_screen_width - half_residue_width - 1; screen_x1 = screen_x0 + residue_screen_width + 2; d = (hydrophobic_moment - ordinate_min) * ordinate_scale; screen_y0 = screen_margin_top + sectionI * section_height; screen_y1 = screen_y0 + section_height; screen_y = screen_y1 - (int) d; /* Draw triple line: */ XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], screen_x0, screen_y - 1, screen_x1, screen_y - 1); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], screen_x0, screen_y, screen_x1, screen_y); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[3], screen_x0, screen_y + 1, screen_x1, screen_y + 1); /* Initialize the flag which says is */ /* it necessary to draw vertical line: */ draw_vertical_lineF = 1; /* For the first residue in the current */ /* section do not draw the vertical line: */ if (local_residueI == 0) { old_screen_y = screen_y0; draw_vertical_lineF = 0; } /* For the first residue, do not draw the vertical line: */ if (residueI == range_startI) { old_screen_y = screen_y; draw_vertical_lineF = 0; } /* Check is it necessary to draw vertical line: */ if (old_screen_y == screen_y) { old_screen_y = screen_y; draw_vertical_lineF = 0; } /* Prepare the shift which is required to draw corners; take */ /* the next res. if there is no need to draw vertical lines: */ if (old_screen_y < screen_y0) shift = -1; else shift = +1; /* Draw three vertical lines: */ if (draw_vertical_lineF) { XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], screen_x0, old_screen_y - shift, screen_x0, screen_y - shift); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], screen_x0 + 1, old_screen_y, screen_x0 + 1, screen_y); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[3], screen_x0 + 2, old_screen_y + shift, screen_x0 + 2, screen_y + shift); } /* Copy the y coordinate for later use: */ old_screen_y = screen_y; /* Fill NearestAtomS array: */ for (screen_x = screen_x0 + 2; screen_x <= screen_x1 - 1; screen_x++) { for (screen_y = screen_y0; screen_y <= screen_y1; screen_y++) { /* Prepare index to the array */ /* of NearestAtomS structures: */ pixelI = guiSP->main_win_free_area_width * screen_y + screen_x; /* Check the pixel index: */ if (pixelI >= pixelsN) continue; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = nearest_atomSP + pixelI; /* Refresh NearestAtomS associated with */ /* this pixel; residue index is stored */ /* to location reserved for atom index. */ curr_pixelSP->last_refreshI = refreshI; curr_pixelSP->atomI = residueI; curr_pixelSP->z = hydrophobic_moment; } } /* Update the counter of visible residues: */ visible_residueI++; } } /*------draw sided hydrophobicities (two lines, two tones of magenta):-------*/ if (runtimeSP->sided_hydrophobicityF) { /*------draw upper line:---------------------------------------------*/ /* Prepare three colors for larger side hydrophobicity: */ ParseColor_ (&rgbS, &color1ID, guiSP, "RGB:FFFF/8888/DDDD", "white"); ParseColor_ (&rgbS, &color2ID, guiSP, "RGB:FFFF/0000/BBBB", "white"); ParseColor_ (&rgbS, &color3ID, guiSP, "RGB:9999/0000/5555", "black"); XSetForeground (guiSP->displaySP, guiSP->theGCA[1], color1ID); XSetForeground (guiSP->displaySP, guiSP->theGCA[2], color2ID); XSetForeground (guiSP->displaySP, guiSP->theGCA[3], color3ID); /* Reset the counter of visible residues: */ visible_residueI = 0; /* Scan the sequence: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Check is the residue array index inside the range: */ if ((residueI < range_startI) || (residueI > range_endI)) { continue; } /* Copy the larger side hydrophobicity: */ larger_side_hyphob = (double) *(runtimeSP->larger_sided_hyphobP + residueI); /* Prepare the section index: */ sectionI = visible_residueI / residues_per_sectionN; /* Prepare the local residue index: */ local_residueI = visible_residueI % residues_per_sectionN; /* Prepare screen coordinates: */ screen_x0 = screen_margin_x + local_residueI * residue_screen_width - half_residue_width - 1; screen_x1 = screen_x0 + residue_screen_width + 2; d = (larger_side_hyphob - ordinate_min) * ordinate_scale; screen_y0 = screen_margin_top + sectionI * section_height; screen_y1 = screen_y0 + section_height; screen_y = screen_y1 - (int) d; /* Draw triple line: */ XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], screen_x0, screen_y - 1, screen_x1, screen_y - 1); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], screen_x0, screen_y, screen_x1, screen_y); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[3], screen_x0, screen_y + 1, screen_x1, screen_y + 1); /* Initialize the flag which says is */ /* it necessary to draw vertical line: */ draw_vertical_lineF = 1; /* For the first residue in the current */ /* section do not draw the vertical line: */ if (local_residueI == 0) { old_screen_y = screen_y0; draw_vertical_lineF = 0; } /* For the first residue, do not draw the vertical line: */ if (residueI == range_startI) { old_screen_y = screen_y; draw_vertical_lineF = 0; } /* Check is it necessary to draw vertical line: */ if (old_screen_y == screen_y) { old_screen_y = screen_y; draw_vertical_lineF = 0; } /* Prepare the shift which is required to draw corners; take */ /* the next res. if there is no need to draw vertical lines: */ if (old_screen_y < screen_y) shift = -1; else shift = +1; /* Draw three vertical lines: */ if (draw_vertical_lineF) { XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], screen_x0, old_screen_y - shift, screen_x0, screen_y - shift); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], screen_x0 + 1, old_screen_y, screen_x0 + 1, screen_y); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[3], screen_x0 + 2, old_screen_y + shift, screen_x0 + 2, screen_y + shift); } /* Copy the y coordinate for later use: */ old_screen_y = screen_y; /* Fill NearestAtomS array: */ for (screen_x = screen_x0 + 2; screen_x <= screen_x1 - 1; screen_x++) { for (screen_y = screen_y0; screen_y <= screen_y1; screen_y++) { /* Prepare index to the array */ /* of NearestAtomS structures: */ pixelI = guiSP->main_win_free_area_width * screen_y + screen_x; /* Check the pixel index: */ if (pixelI >= pixelsN) continue; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = nearest_atomSP + pixelI; /* Refresh NearestAtomS associated with */ /* this pixel; residue index is stored */ /* to location reserved for atom index. */ curr_pixelSP->last_refreshI = refreshI; curr_pixelSP->atomI = residueI; curr_pixelSP->z = larger_side_hyphob; } } /* Update the counter of visible residues: */ visible_residueI++; } /*------draw bottom line:--------------------------------------------*/ /* Prepare three colors for smaller side hydrophobicity: */ ParseColor_ (&rgbS, &color1ID, guiSP, "RGB:DDDD/8888/FFFF", "white"); ParseColor_ (&rgbS, &color2ID, guiSP, "RGB:BBBB/0000/FFFF", "white"); ParseColor_ (&rgbS, &color3ID, guiSP, "RGB:5555/0000/9999", "black"); XSetForeground (guiSP->displaySP, guiSP->theGCA[1], color1ID); XSetForeground (guiSP->displaySP, guiSP->theGCA[2], color2ID); XSetForeground (guiSP->displaySP, guiSP->theGCA[3], color3ID); /* Reset the counter of visible residues: */ visible_residueI = 0; /* Scan the sequence: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Check is the residue array index inside the range: */ if ((residueI < range_startI) || (residueI > range_endI)) { continue; } /* Copy the smaller sided hydrophobicity: */ smaller_side_hyphob = (double) *(runtimeSP->smaller_sided_hyphobP + residueI); /* Prepare the section index: */ sectionI = visible_residueI / residues_per_sectionN; /* Prepare the local residue index: */ local_residueI = visible_residueI % residues_per_sectionN; /* Prepare screen coordinates: */ screen_x0 = screen_margin_x + local_residueI * residue_screen_width - half_residue_width - 1; screen_x1 = screen_x0 + residue_screen_width + 2; d = (smaller_side_hyphob - ordinate_min) * ordinate_scale; screen_y0 = screen_margin_top + sectionI * section_height; screen_y1 = screen_y0 + section_height; screen_y = screen_y1 - (int) d; /* Draw triple line: */ XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], screen_x0, screen_y - 1, screen_x1, screen_y - 1); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], screen_x0, screen_y, screen_x1, screen_y); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[3], screen_x0, screen_y + 1, screen_x1, screen_y + 1); /* Initialize the flag which says is */ /* it necessary to draw vertical line: */ draw_vertical_lineF = 1; /* For the first residue in the current */ /* section do not draw the vertical line: */ if (local_residueI == 0) { old_screen_y = screen_y0; draw_vertical_lineF = 0; } /* For the first residue, do not draw the vertical line: */ if (residueI == range_startI) { old_screen_y = screen_y; draw_vertical_lineF = 0; } /* Check is it necessary to draw vertical line: */ if (old_screen_y == screen_y) { old_screen_y = screen_y; draw_vertical_lineF = 0; } /* Prepare the shift which is required to draw corners; take */ /* the next res. if there is no need to draw vertical lines: */ if (old_screen_y < screen_y) shift = -1; else shift = +1; /* Draw three vertical lines: */ if (draw_vertical_lineF) { XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], screen_x0, old_screen_y - shift, screen_x0, screen_y - shift); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], screen_x0 + 1, old_screen_y, screen_x0 + 1, screen_y); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[3], screen_x0 + 2, old_screen_y + shift, screen_x0 + 2, screen_y + shift); } /* Copy the y coordinate for later use: */ old_screen_y = screen_y; /* Fill NearestAtomS array: */ for (screen_x = screen_x0 + 2; screen_x <= screen_x1 - 1; screen_x++) { for (screen_y = screen_y0; screen_y <= screen_y1; screen_y++) { /* Prepare index to the array */ /* of NearestAtomS structures: */ pixelI = guiSP->main_win_free_area_width * screen_y + screen_x; /* Check the pixel index: */ if (pixelI >= pixelsN) continue; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = nearest_atomSP + pixelI; /* Refresh NearestAtomS associated with */ /* this pixel; residue index is stored */ /* to location reserved for atom index. */ curr_pixelSP->last_refreshI = refreshI; curr_pixelSP->atomI = residueI; curr_pixelSP->z = smaller_side_hyphob; } } /* Update the counter of visible residues: */ visible_residueI++; } /*-------------------------------------------------------------------*/ } /*------draw hydrophobicity function F1 (orange line):-----------------------*/ if (runtimeSP->function1F) { /* Prepare three colors for function F1: */ ParseColor_ (&rgbS, &color1ID, guiSP, "RGB:FFFF/AAAA/5555", "white"); ParseColor_ (&rgbS, &color2ID, guiSP, "RGB:FFFF/8888/0000", "white"); ParseColor_ (&rgbS, &color3ID, guiSP, "RGB:8888/4444/0000", "black"); XSetForeground (guiSP->displaySP, guiSP->theGCA[1], color1ID); XSetForeground (guiSP->displaySP, guiSP->theGCA[2], color2ID); XSetForeground (guiSP->displaySP, guiSP->theGCA[3], color3ID); /* Reset the counter of visible residues: */ visible_residueI = 0; /* Scan the sequence: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Check is the residue array index inside the range: */ if ((residueI < range_startI) || (residueI > range_endI)) { continue; } /* Copy the function value: */ function1 = (double) *(runtimeSP->function1P + residueI); /* Prepare the section index: */ sectionI = visible_residueI / residues_per_sectionN; /* Prepare the local residue index: */ local_residueI = visible_residueI % residues_per_sectionN; /* Prepare screen coordinates: */ screen_x0 = screen_margin_x + local_residueI * residue_screen_width - half_residue_width - 1; screen_x1 = screen_x0 + residue_screen_width + 2; d = (function1 - ordinate_min) * ordinate_scale; screen_y0 = screen_margin_top + sectionI * section_height; screen_y1 = screen_y0 + section_height; screen_y = screen_y1 - (int) d; /* Draw triple line: */ XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], screen_x0, screen_y - 1, screen_x1, screen_y - 1); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], screen_x0, screen_y, screen_x1, screen_y); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[3], screen_x0, screen_y + 1, screen_x1, screen_y + 1); /* Initialize the flag which says is */ /* it necessary to draw vertical line: */ draw_vertical_lineF = 1; /* For the first residue in the current */ /* section do not draw the vertical line: */ if (local_residueI == 0) { old_screen_y = screen_y0; draw_vertical_lineF = 0; } /* For the first residue, do not draw the vertical line: */ if (residueI == range_startI) { old_screen_y = screen_y; draw_vertical_lineF = 0; } /* Check is it necessary to draw vertical line: */ if (old_screen_y == screen_y) { old_screen_y = screen_y; draw_vertical_lineF = 0; } /* Prepare the shift which is required to draw corners; take */ /* the next res. if there is no need to draw vertical lines: */ if (old_screen_y < screen_y) shift = -1; else shift = +1; /* Draw three vertical lines: */ if (draw_vertical_lineF) { XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], screen_x0, old_screen_y - shift, screen_x0, screen_y - shift); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], screen_x0 + 1, old_screen_y, screen_x0 + 1, screen_y); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[3], screen_x0 + 2, old_screen_y + shift, screen_x0 + 2, screen_y + shift); } /* Copy the y coordinate for later use: */ old_screen_y = screen_y; /* Fill NearestAtomS array: */ for (screen_x = screen_x0 + 2; screen_x <= screen_x1 - 1; screen_x++) { for (screen_y = screen_y0; screen_y <= screen_y1; screen_y++) { /* Prepare index to the array */ /* of NearestAtomS structures: */ pixelI = guiSP->main_win_free_area_width * screen_y + screen_x; /* Check the pixel index: */ if (pixelI >= pixelsN) continue; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = nearest_atomSP + pixelI; /* Refresh NearestAtomS associated with */ /* this pixel; residue index is stored */ /* to location reserved for atom index. */ curr_pixelSP->last_refreshI = refreshI; curr_pixelSP->atomI = residueI; curr_pixelSP->z = function1; } } /* Update the counter of visible residues: */ visible_residueI++; } } /*------draw hydrophobicity function F2 (green line):------------------------*/ if (runtimeSP->function2F) { /* Prepare three colors for function F2: */ ParseColor_ (&rgbS, &color1ID, guiSP, "RGB:9999/FFFF/7777", "white"); ParseColor_ (&rgbS, &color2ID, guiSP, "RGB:2222/FFFF/0000", "white"); ParseColor_ (&rgbS, &color3ID, guiSP, "RGB:1111/8888/0000", "black"); XSetForeground (guiSP->displaySP, guiSP->theGCA[1], color1ID); XSetForeground (guiSP->displaySP, guiSP->theGCA[2], color2ID); XSetForeground (guiSP->displaySP, guiSP->theGCA[3], color3ID); /* Reset the counter of visible residues: */ visible_residueI = 0; /* Scan the sequence: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Check is the residue array index inside the range: */ if ((residueI < range_startI) || (residueI > range_endI)) { continue; } /* Copy the function value: */ function2 = (double) *(runtimeSP->function2P + residueI); /* Prepare the section index: */ sectionI = visible_residueI / residues_per_sectionN; /* Prepare the local residue index: */ local_residueI = visible_residueI % residues_per_sectionN; /* Prepare screen coordinates: */ screen_x0 = screen_margin_x + local_residueI * residue_screen_width - half_residue_width - 1; screen_x1 = screen_x0 + residue_screen_width + 2; d = (function2 - ordinate_min) * ordinate_scale; screen_y0 = screen_margin_top + sectionI * section_height; screen_y1 = screen_y0 + section_height; screen_y = screen_y1 - (int) d; /* Draw triple line: */ XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], screen_x0, screen_y - 1, screen_x1, screen_y - 1); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], screen_x0, screen_y, screen_x1, screen_y); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[3], screen_x0, screen_y + 1, screen_x1, screen_y + 1); /* Initialize the flag which says is */ /* it necessary to draw vertical line: */ draw_vertical_lineF = 1; /* For the first residue in the current */ /* section do not draw the vertical line: */ if (local_residueI == 0) { old_screen_y = screen_y0; draw_vertical_lineF = 0; } /* For the first residue, do not draw the vertical line: */ if (residueI == range_startI) { old_screen_y = screen_y; draw_vertical_lineF = 0; } /* Check is it necessary to draw vertical line: */ if (old_screen_y == screen_y) { old_screen_y = screen_y; draw_vertical_lineF = 0; } /* Prepare the shift which is required to draw corners; take */ /* the next res. if there is no need to draw vertical lines: */ if (old_screen_y < screen_y) shift = -1; else shift = +1; /* Draw three vertical lines: */ if (draw_vertical_lineF) { XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], screen_x0, old_screen_y - shift, screen_x0, screen_y - shift); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], screen_x0 + 1, old_screen_y, screen_x0 + 1, screen_y); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[3], screen_x0 + 2, old_screen_y + shift, screen_x0 + 2, screen_y + shift); } /* Copy the y coordinate for later use: */ old_screen_y = screen_y; /* Fill NearestAtomS array: */ for (screen_x = screen_x0 + 2; screen_x <= screen_x1 - 1; screen_x++) { for (screen_y = screen_y0; screen_y <= screen_y1; screen_y++) { /* Prepare index to the array */ /* of NearestAtomS structures: */ pixelI = guiSP->main_win_free_area_width * screen_y + screen_x; /* Check the pixel index: */ if (pixelI >= pixelsN) continue; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = nearest_atomSP + pixelI; /* Refresh NearestAtomS associated with */ /* this pixel; residue index is stored */ /* to location reserved for atom index. */ curr_pixelSP->last_refreshI = refreshI; curr_pixelSP->atomI = residueI; curr_pixelSP->z = function2; } } /* Update the counter of visible residues: */ visible_residueI++; } } /*------draw hydrophobicity function F3 (yellow line):-----------------------*/ if (runtimeSP->function3F) { /* Prepare three colors for function F3: */ ParseColor_ (&rgbS, &color1ID, guiSP, "RGB:FFFF/FFFF/0000", "white"); ParseColor_ (&rgbS, &color2ID, guiSP, "RGB:DDDD/DDDD/0000", "white"); ParseColor_ (&rgbS, &color3ID, guiSP, "RGB:8888/8888/0000", "black"); XSetForeground (guiSP->displaySP, guiSP->theGCA[1], color1ID); XSetForeground (guiSP->displaySP, guiSP->theGCA[2], color2ID); XSetForeground (guiSP->displaySP, guiSP->theGCA[3], color3ID); /* Reset the counter of visible residues: */ visible_residueI = 0; /* Scan the sequence: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Check is the residue array index inside the range: */ if ((residueI < range_startI) || (residueI > range_endI)) { continue; } /* Copy the function value: */ function3 = (double) *(runtimeSP->function3P + residueI); /* Prepare the section index: */ sectionI = visible_residueI / residues_per_sectionN; /* Prepare the local residue index: */ local_residueI = visible_residueI % residues_per_sectionN; /* Prepare screen coordinates: */ screen_x0 = screen_margin_x + local_residueI * residue_screen_width - half_residue_width - 1; screen_x1 = screen_x0 + residue_screen_width + 2; d = (function3 - ordinate_min) * ordinate_scale; screen_y0 = screen_margin_top + sectionI * section_height; screen_y1 = screen_y0 + section_height; screen_y = screen_y1 - (int) d; /* Draw triple line: */ XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], screen_x0, screen_y - 1, screen_x1, screen_y - 1); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], screen_x0, screen_y, screen_x1, screen_y); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[3], screen_x0, screen_y + 1, screen_x1, screen_y + 1); /* Initialize the flag which says is */ /* it necessary to draw vertical line: */ draw_vertical_lineF = 1; /* For the first residue in the current */ /* section do not draw the vertical line: */ if (local_residueI == 0) { old_screen_y = screen_y0; draw_vertical_lineF = 0; } /* For the first residue, do not draw the vertical line: */ if (residueI == range_startI) { old_screen_y = screen_y; draw_vertical_lineF = 0; } /* Check is it necessary to draw vertical line: */ if (old_screen_y == screen_y) { old_screen_y = screen_y; draw_vertical_lineF = 0; } /* Prepare the shift which is required to draw corners; take */ /* the next res. if there is no need to draw vertical lines: */ if (old_screen_y < screen_y) shift = -1; else shift = +1; /* Draw three vertical lines: */ if (draw_vertical_lineF) { XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], screen_x0, old_screen_y - shift, screen_x0, screen_y - shift); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], screen_x0 + 1, old_screen_y, screen_x0 + 1, screen_y); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[3], screen_x0 + 2, old_screen_y + shift, screen_x0 + 2, screen_y + shift); } /* Copy the y coordinate for later use: */ old_screen_y = screen_y; /* Fill NearestAtomS array: */ for (screen_x = screen_x0 + 2; screen_x <= screen_x1 - 1; screen_x++) { for (screen_y = screen_y0; screen_y <= screen_y1; screen_y++) { /* Prepare index to the array */ /* of NearestAtomS structures: */ pixelI = guiSP->main_win_free_area_width * screen_y + screen_x; /* Check the pixel index: */ if (pixelI >= pixelsN) continue; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = nearest_atomSP + pixelI; /* Refresh NearestAtomS associated with */ /* this pixel; residue index is stored */ /* to location reserved for atom index. */ curr_pixelSP->last_refreshI = refreshI; curr_pixelSP->atomI = residueI; curr_pixelSP->z = function3; } } /* Update the counter of visible residues: */ visible_residueI++; } } /*------draw hydrophobicity function F4 (cyan line):-------------------------*/ if (runtimeSP->function4F) { /* Prepare three colors for function F4: */ ParseColor_ (&rgbS, &color1ID, guiSP, "RGB:0000/FFFF/FFFF", "white"); ParseColor_ (&rgbS, &color2ID, guiSP, "RGB:0000/DDDD/DDDD", "white"); ParseColor_ (&rgbS, &color3ID, guiSP, "RGB:0000/8888/8888", "black"); XSetForeground (guiSP->displaySP, guiSP->theGCA[1], color1ID); XSetForeground (guiSP->displaySP, guiSP->theGCA[2], color2ID); XSetForeground (guiSP->displaySP, guiSP->theGCA[3], color3ID); /* Reset the counter of visible residues: */ visible_residueI = 0; /* Scan the sequence: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Check is the residue array index inside the range: */ if ((residueI < range_startI) || (residueI > range_endI)) { continue; } /* Copy the function value: */ function4 = (double) *(runtimeSP->function4P + residueI); /* Prepare the section index: */ sectionI = visible_residueI / residues_per_sectionN; /* Prepare the local residue index: */ local_residueI = visible_residueI % residues_per_sectionN; /* Prepare screen coordinates: */ screen_x0 = screen_margin_x + local_residueI * residue_screen_width - half_residue_width - 1; screen_x1 = screen_x0 + residue_screen_width + 2; d = (function4 - ordinate_min) * ordinate_scale; screen_y0 = screen_margin_top + sectionI * section_height; screen_y1 = screen_y0 + section_height; screen_y = screen_y1 - (int) d; /* Draw triple line: */ XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], screen_x0, screen_y - 1, screen_x1, screen_y - 1); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], screen_x0, screen_y, screen_x1, screen_y); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[3], screen_x0, screen_y + 1, screen_x1, screen_y + 1); /* Initialize the flag which says is */ /* it necessary to draw vertical line: */ draw_vertical_lineF = 1; /* For the first residue in the current */ /* section do not draw the vertical line: */ if (local_residueI == 0) { old_screen_y = screen_y0; draw_vertical_lineF = 0; } /* For the first residue, do not draw the vertical line: */ if (residueI == range_startI) { old_screen_y = screen_y; draw_vertical_lineF = 0; } /* Check is it necessary to draw vertical line: */ if (old_screen_y == screen_y) { old_screen_y = screen_y; draw_vertical_lineF = 0; } /* Prepare the shift which is required to draw corners; take */ /* the next res. if there is no need to draw vertical lines: */ if (old_screen_y < screen_y) shift = -1; else shift = +1; /* Draw three vertical lines: */ if (draw_vertical_lineF) { XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], screen_x0, old_screen_y - shift, screen_x0, screen_y - shift); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], screen_x0 + 1, old_screen_y, screen_x0 + 1, screen_y); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[3], screen_x0 + 2, old_screen_y + shift, screen_x0 + 2, screen_y + shift); } /* Copy the y coordinate for later use: */ old_screen_y = screen_y; /* Fill NearestAtomS array: */ for (screen_x = screen_x0 + 2; screen_x <= screen_x1 - 1; screen_x++) { for (screen_y = screen_y0; screen_y <= screen_y1; screen_y++) { /* Prepare index to the array */ /* of NearestAtomS structures: */ pixelI = guiSP->main_win_free_area_width * screen_y + screen_x; /* Check the pixel index: */ if (pixelI >= pixelsN) continue; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = nearest_atomSP + pixelI; /* Refresh NearestAtomS associated with */ /* this pixel; residue index is stored */ /* to location reserved for atom index. */ curr_pixelSP->last_refreshI = refreshI; curr_pixelSP->atomI = residueI; curr_pixelSP->z = function4; } } /* Update the counter of visible residues: */ visible_residueI++; } } /*------draw hydrophobicity function F5 (dark blue line):--------------------*/ if (runtimeSP->function5F) { /* Prepare three colors for function F5: */ ParseColor_ (&rgbS, &color1ID, guiSP, "RGB:0000/0000/FFFF", "white"); ParseColor_ (&rgbS, &color2ID, guiSP, "RGB:0000/0000/BBBB", "white"); ParseColor_ (&rgbS, &color3ID, guiSP, "RGB:0000/0000/7777", "black"); XSetForeground (guiSP->displaySP, guiSP->theGCA[1], color1ID); XSetForeground (guiSP->displaySP, guiSP->theGCA[2], color2ID); XSetForeground (guiSP->displaySP, guiSP->theGCA[3], color3ID); /* Reset the counter of visible residues: */ visible_residueI = 0; /* Scan the sequence: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Check is the residue array index inside the range: */ if ((residueI < range_startI) || (residueI > range_endI)) { continue; } /* Copy the function value: */ function5 = (double) *(runtimeSP->function5P + residueI); /* Prepare the section index: */ sectionI = visible_residueI / residues_per_sectionN; /* Prepare the local residue index: */ local_residueI = visible_residueI % residues_per_sectionN; /* Prepare screen coordinates: */ screen_x0 = screen_margin_x + local_residueI * residue_screen_width - half_residue_width - 1; screen_x1 = screen_x0 + residue_screen_width + 2; d = (function5 - ordinate_min) * ordinate_scale; screen_y0 = screen_margin_top + sectionI * section_height; screen_y1 = screen_y0 + section_height; screen_y = screen_y1 - (int) d; /* Draw triple line: */ XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], screen_x0, screen_y - 1, screen_x1, screen_y - 1); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], screen_x0, screen_y, screen_x1, screen_y); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[3], screen_x0, screen_y + 1, screen_x1, screen_y + 1); /* Initialize the flag which says is */ /* it necessary to draw vertical line: */ draw_vertical_lineF = 1; /* For the first residue in the current */ /* section do not draw the vertical line: */ if (local_residueI == 0) { old_screen_y = screen_y0; draw_vertical_lineF = 0; } /* For the first residue, do not draw the vertical line: */ if (residueI == range_startI) { old_screen_y = screen_y; draw_vertical_lineF = 0; } /* Check is it necessary to draw vertical line: */ if (old_screen_y == screen_y) { old_screen_y = screen_y; draw_vertical_lineF = 0; } /* Prepare the shift which is required to draw corners; take */ /* the next res. if there is no need to draw vertical lines: */ if (old_screen_y < screen_y) shift = -1; else shift = +1; /* Draw three vertical lines: */ if (draw_vertical_lineF) { XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], screen_x0, old_screen_y - shift, screen_x0, screen_y - shift); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], screen_x0 + 1, old_screen_y, screen_x0 + 1, screen_y); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[3], screen_x0 + 2, old_screen_y + shift, screen_x0 + 2, screen_y + shift); } /* Copy the y coordinate for later use: */ old_screen_y = screen_y; /* Fill NearestAtomS array: */ for (screen_x = screen_x0 + 2; screen_x <= screen_x1 - 1; screen_x++) { for (screen_y = screen_y0; screen_y <= screen_y1; screen_y++) { /* Prepare index to the array */ /* of NearestAtomS structures: */ pixelI = guiSP->main_win_free_area_width * screen_y + screen_x; /* Check the pixel index: */ if (pixelI >= pixelsN) continue; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = nearest_atomSP + pixelI; /* Refresh NearestAtomS associated with */ /* this pixel; residue index is stored */ /* to location reserved for atom index. */ curr_pixelSP->last_refreshI = refreshI; curr_pixelSP->atomI = residueI; curr_pixelSP->z = function5; } } /* Update the counter of visible residues: */ visible_residueI++; } } /*------draw hydrophobicity function F6 (again red line):--------------------*/ if (runtimeSP->function6F) { /* Prepare three colors for function F6: */ /* Prepare three colors for average hydrophobicity: */ ParseColor_ (&rgbS, &color1ID, guiSP, "RGB:FFFF/8888/8888", "white"); ParseColor_ (&rgbS, &color2ID, guiSP, "RGB:FFFF/0000/0000", "white"); ParseColor_ (&rgbS, &color3ID, guiSP, "RGB:8888/0000/0000", "black"); XSetForeground (guiSP->displaySP, guiSP->theGCA[1], color1ID); XSetForeground (guiSP->displaySP, guiSP->theGCA[2], color2ID); XSetForeground (guiSP->displaySP, guiSP->theGCA[3], color3ID); /* Reset the counter of visible residues: */ visible_residueI = 0; /* Scan the sequence: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Check is the residue array index inside the range: */ if ((residueI < range_startI) || (residueI > range_endI)) { continue; } /* Copy the function value: */ function6 = (double) *(runtimeSP->function6P + residueI); /* Prepare the section index: */ sectionI = visible_residueI / residues_per_sectionN; /* Prepare the local residue index: */ local_residueI = visible_residueI % residues_per_sectionN; /* Prepare screen coordinates: */ screen_x0 = screen_margin_x + local_residueI * residue_screen_width - half_residue_width - 1; screen_x1 = screen_x0 + residue_screen_width + 2; d = (function6 - ordinate_min) * ordinate_scale; screen_y0 = screen_margin_top + sectionI * section_height; screen_y1 = screen_y0 + section_height; screen_y = screen_y1 - (int) d; /* Draw triple line: */ XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], screen_x0, screen_y - 1, screen_x1, screen_y - 1); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], screen_x0, screen_y, screen_x1, screen_y); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[3], screen_x0, screen_y + 1, screen_x1, screen_y + 1); /* Initialize the flag which says is */ /* it necessary to draw vertical line: */ draw_vertical_lineF = 1; /* For the first residue in the current */ /* section do not draw the vertical line: */ if (local_residueI == 0) { old_screen_y = screen_y0; draw_vertical_lineF = 0; } /* For the first residue, do not draw the vertical line: */ if (residueI == range_startI) { old_screen_y = screen_y; draw_vertical_lineF = 0; } /* Check is it necessary to draw vertical line: */ if (old_screen_y == screen_y) { old_screen_y = screen_y; draw_vertical_lineF = 0; } /* Prepare the shift which is required to draw corners; take */ /* the next res. if there is no need to draw vertical lines: */ if (old_screen_y < screen_y) shift = -1; else shift = +1; /* Draw three vertical lines: */ if (draw_vertical_lineF) { XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], screen_x0, old_screen_y - shift, screen_x0, screen_y - shift); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], screen_x0 + 1, old_screen_y, screen_x0 + 1, screen_y); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[3], screen_x0 + 2, old_screen_y + shift, screen_x0 + 2, screen_y + shift); } /* Copy the y coordinate for later use: */ old_screen_y = screen_y; /* Fill NearestAtomS array: */ for (screen_x = screen_x0 + 2; screen_x <= screen_x1 - 1; screen_x++) { for (screen_y = screen_y0; screen_y <= screen_y1; screen_y++) { /* Prepare index to the array */ /* of NearestAtomS structures: */ pixelI = guiSP->main_win_free_area_width * screen_y + screen_x; /* Check the pixel index: */ if (pixelI >= pixelsN) continue; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = nearest_atomSP + pixelI; /* Refresh NearestAtomS associated with */ /* this pixel; residue index is stored */ /* to location reserved for atom index. */ curr_pixelSP->last_refreshI = refreshI; curr_pixelSP->atomI = residueI; curr_pixelSP->z = function6; } } /* Update the counter of visible residues: */ visible_residueI++; } } /*------draw hydrophobicity function F7 (again blue line):-------------------*/ if (runtimeSP->function7F) { /* Prepare three colors for function F7: */ /* Prepare three colors for average hydrophobicity: */ ParseColor_ (&rgbS, &color1ID, guiSP, "RGB:8888/DDDD/FFFF", "white"); ParseColor_ (&rgbS, &color2ID, guiSP, "RGB:0000/8888/FFFF", "white"); ParseColor_ (&rgbS, &color3ID, guiSP, "RGB:0000/4444/8888", "black"); XSetForeground (guiSP->displaySP, guiSP->theGCA[1], color1ID); XSetForeground (guiSP->displaySP, guiSP->theGCA[2], color2ID); XSetForeground (guiSP->displaySP, guiSP->theGCA[3], color3ID); /* Reset the counter of visible residues: */ visible_residueI = 0; /* Scan the sequence: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Check is the residue array index inside the range: */ if ((residueI < range_startI) || (residueI > range_endI)) { continue; } /* Copy the function value: */ function7 = (double) *(runtimeSP->function7P + residueI); /* Prepare the section index: */ sectionI = visible_residueI / residues_per_sectionN; /* Prepare the local residue index: */ local_residueI = visible_residueI % residues_per_sectionN; /* Prepare screen coordinates: */ screen_x0 = screen_margin_x + local_residueI * residue_screen_width - half_residue_width - 1; screen_x1 = screen_x0 + residue_screen_width + 2; d = (function7 - ordinate_min) * ordinate_scale; screen_y0 = screen_margin_top + sectionI * section_height; screen_y1 = screen_y0 + section_height; screen_y = screen_y1 - (int) d; /* Draw triple line: */ XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], screen_x0, screen_y - 1, screen_x1, screen_y - 1); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], screen_x0, screen_y, screen_x1, screen_y); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[3], screen_x0, screen_y + 1, screen_x1, screen_y + 1); /* Initialize the flag which says is */ /* it necessary to draw vertical line: */ draw_vertical_lineF = 1; /* For the first residue in the current */ /* section do not draw the vertical line: */ if (local_residueI == 0) { old_screen_y = screen_y0; draw_vertical_lineF = 0; } /* For the first residue, do not draw the vertical line: */ if (residueI == range_startI) { old_screen_y = screen_y; draw_vertical_lineF = 0; } /* Check is it necessary to draw vertical line: */ if (old_screen_y == screen_y) { old_screen_y = screen_y; draw_vertical_lineF = 0; } /* Prepare the shift which is required to draw corners; take */ /* the next res. if there is no need to draw vertical lines: */ if (old_screen_y < screen_y) shift = -1; else shift = +1; /* Draw three vertical lines: */ if (draw_vertical_lineF) { XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], screen_x0, old_screen_y - shift, screen_x0, screen_y - shift); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], screen_x0 + 1, old_screen_y, screen_x0 + 1, screen_y); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[3], screen_x0 + 2, old_screen_y + shift, screen_x0 + 2, screen_y + shift); } /* Copy the y coordinate for later use: */ old_screen_y = screen_y; /* Fill NearestAtomS array: */ for (screen_x = screen_x0 + 2; screen_x <= screen_x1 - 1; screen_x++) { for (screen_y = screen_y0; screen_y <= screen_y1; screen_y++) { /* Prepare index to the array */ /* of NearestAtomS structures: */ pixelI = guiSP->main_win_free_area_width * screen_y + screen_x; /* Check the pixel index: */ if (pixelI >= pixelsN) continue; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = nearest_atomSP + pixelI; /* Refresh NearestAtomS associated with */ /* this pixel; residue index is stored */ /* to location reserved for atom index. */ curr_pixelSP->last_refreshI = refreshI; curr_pixelSP->atomI = residueI; curr_pixelSP->z = function7; } } /* Update the counter of visible residues: */ visible_residueI++; } } /*------copy the prepared image to the main window:--------------------------*/ /* Copy hidden pixmap to the main window: */ XCopyArea (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->main_winS.ID, guiSP->theGCA[0], 0, 0, guiSP->main_win_free_area_width, guiSP->main_win_free_area_height, 0, 0); return (size_t) residuesN; } /*===========================================================================*/ garlic-1.6/init_slab.c0000644000076500007650000000647607117422072015236 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= init_slab.c Purpose: Initialize slab data: reference point (center) position, front and back surface distance from the center. This function is not very precise, because it uses the complex spatial extent. The available extent is increased for 40%. The reason is that the initial slab should show all atoms, even after the rotation for 45 degrees. As - at least in theory - some structure may be planar, tilted 45 degrees with respect to z axis, there is a chance that the actual spatial extent is for a factor sqrt(2) larger than the calculated spatial extent. The 40% increase should ensure that all atoms will be visible after rotation. See note 1. Input: (1) Pointer to MolComplexS structure. Output: (1) Slab data initialized (center position, surface positions). Return value: No return value. Notes: (1) Illustration of the problem with the spatial extent: ______ | **| | ** | ... the molecule is positioned diagonally |** | in the "extent box". ------ The spatial extent of the molecule is larger than the width and height of the "extent box". (2) Soluble proteins are globular (approx. spherical). Membrane proteins usually look like cylinders. An asymmetric protein with geometric center significantly closer to one edge will cause this function to place slab surfaces at wrong places. It may happen that some atoms will be unvisible. This can be easily corrected at runtime - just set the proper slab. ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======initialize slab:=====================================================*/ void InitSlab_ (MolComplexS *mol_complexSP) { double initial_extent, half_initial_extent; /* Initialize the reference point: */ mol_complexSP->slab_center_vectorS.x = mol_complexSP->geometric_center_vectorS.x; mol_complexSP->slab_center_vectorS.y = mol_complexSP->geometric_center_vectorS.y; mol_complexSP->slab_center_vectorS.z = mol_complexSP->geometric_center_vectorS.z; /* Do the correction (add 40%; read the explanation above): */ initial_extent = 1.40 * mol_complexSP->max_extent; /* Half of the corrected maximal extent: */ half_initial_extent = 0.5 * initial_extent; /* Set the initial front and back surface distance */ /* from the center. This depends on the slab mode. */ switch (mol_complexSP->slab_modeI) { /** Slab off (slab not used, do nothing): **/ case 0: break; /** Planar: **/ case 1: mol_complexSP->slab_front_relative_position = -half_initial_extent; mol_complexSP->slab_back_relative_position = half_initial_extent; break; /** Sphere, half-sphere, cylinder and half-cylinder: **/ case 2: case 3: case 4: case 5: mol_complexSP->slab_front_relative_position = half_initial_extent; mol_complexSP->slab_back_relative_position = 0.0; break; /** Unsupported slab modes (do nothing): **/ default: ; } } /*===========================================================================*/ garlic-1.6/disp_color_cap.c0000644000076500007650000000643207066226775016261 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= disp_color_cap.c Purpose: Find display depth. Check is the TrueColor visual class supported. Prepare the colormap. Prepare the parameters for color allocation. TrueColor is the only visual class suitable for garlic. A server which is capable to support DirectColor should be capable to support TrueColor also. Some X servers do not support this visual at 8 bits per pixel: increase the color depth and try again! Input: (1) Pointer to GUIS structure (with GUI data). Output: (1) Data stored to GUIS structure. (2) Return value. Return value: (1) Positive on success. (2) Negative on failure. =============================================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ void ErrorMessage_ (char *, char *, char *, char *, char *, char *, char *); int PrepareColorShifts_ (GUIS *); /*======retrieve display color capabilities:=================================*/ int DisplayColorCapabilities_ (GUIS *guiSP) { Status status; Window root_windowID; int n; /*------depth:---------------------------------------------------------------*/ /* Default depth for default screen (maximal number of bits per pixel). */ /* Note: it is not possible to distinguish gray-scale and color screen */ /* by the number of bits per pixel; XVisualInfo structure must be used. */ guiSP->depth = DefaultDepth (guiSP->displaySP, guiSP->screenID); if (guiSP->depth <= 0) { ErrorMessage_ ("garlic", "DisplayColorCapabilities_", "", "Default depth <= 0\n", "", "", ""); return -1; } /*------visual:--------------------------------------------------------------*/ /* Check is TrueColor visual class supported */ /* by X server; if it is, prepare the visual: */ status = XMatchVisualInfo (guiSP->displaySP, guiSP->screenID, guiSP->depth, TrueColor, &guiSP->visual_infoS); if (status == 0) { fprintf (stdout, "Sorry, garlic refuses to work if TrueColor"); fprintf (stdout, " visual is not supported!\n"); fprintf (stdout, "The current color depth is %d bits per pixel.\n", guiSP->depth); fprintf (stdout, "Your X server does not support the TrueColor visual"); fprintf (stdout, " at this color depth.\n"); if (guiSP->depth <= 8) { fprintf (stdout, "Switch to at least 12 bits per pixel"); fprintf (stdout, " (or more -> 24 is recommended)!\n"); } return -2; } else guiSP->visualSP = guiSP->visual_infoS.visual; /*------colormap:------------------------------------------------------------*/ /* Prepare the colormap: */ root_windowID = RootWindow (guiSP->displaySP, guiSP->screenID); guiSP->colormapID = XCreateColormap (guiSP->displaySP, root_windowID, guiSP->visualSP, AllocNone); /*------parameters for fast color allocation:--------------------------------*/ n = PrepareColorShifts_ (guiSP); /*---------------------------------------------------------------------------*/ /* Return positive value on success: */ return 1; } /*===========================================================================*/ garlic-1.6/rainbow.script0000644000076500007650000000131007115454347016003 0ustar zuciczucic00000000000000# This script demonstrates what is garlic capable to do with colors. load trp.pdb pos 0 0 -100 color RGB:FFFF/8888/8888 RGB:FFFF/0000/0000 RGB:8888/0000/0000 RGB:FFFF/9999/7777 RGB:FFFF/8888/0000 RGB:8888/4444/0000 RGB:DDDD/FFFF/8888 RGB:8888/FFFF/0000 RGB:4444/8888/0000 RGB:8888/FFFF/8888 RGB:0000/FFFF/0000 RGB:0000/8888/0000 RGB:8888/FFFF/DDDD RGB:0000/FFFF/8888 RGB:0000/8888/4444 RGB:DDDD/FFFF/FFFF RGB:0000/FFFF/FFFF RGB:0000/8888/FFFF RGB:8888/DDDD/FFFF RGB:0000/8888/FFFF RGB:0000/4444/8888 RGB:8888/8888/FFFF RGB:0000/0000/FFFF RGB:0000/0000/8888 ato sp2 fading front -2 fading front 4 fading front -1 fading front -1 fading front 0.5 fading back -1 fading back -1 fading front -2 fading front 4 garlic-1.6/purge0000755000076500007650000000005410445771371014167 0ustar zuciczucic00000000000000rm *.o rm *~ rm dump* rm insert rm garlic garlic-1.6/set.c0000644000076500007650000001415207415613156014061 0ustar zuciczucic00000000000000/* Copyright (C) 2001, 2002 Damir Zucic */ /*============================================================================= set.c Purpose: Execute the command set: set the value of phi, psi, omega, chi1, chi2 or chi3 angle for all selected residues. A residue is treated as selected if the first atom of this residue is selected. For standard protein residues, this is typically N atom (nitrogen). Input: (1) Pointer to MolComplexS structure. (2) The number of macromolecular complexes. (3) Pointer to RuntimeS structure. (4) Pointer to ConfigS structure. (5) Pointer to GUIS structure. (6) Pointer to NearestAtomS structure. (7) The number of pixels in the main window free area. (8) Pointer to refreshI. (9) Pointer to the remainder of the command string. The command set must be accompanied by one of the following keywords: PHI, PSI, OMEGA, CHI1, CHI2, CHI3, CHI4 and CHI5. The keyword OMEGA may be abbreviated to three characters. Do not abbreviate the keywords CHI1, CHI2, CHI3, CHI4 and CHI5. In addition to one keyword, the remainder of the string must contain the numeric value (double) of the specified angle in degrees. Output: (1) The specified dihedral angle will be changed. (2) Return value. Return value: (1) Positive (command) code on success. (2) Negative (error) code on failure. Notes: (1) The side chain dihedral angles will not be set for proline. ========includes:============================================================*/ #include #include #include #include #include #include #include #include "defines.h" #include "commands.h" #include "typedefs.h" /*======function prototypes:=================================================*/ char *ExtractToken_ (char *, int, char *, char *); int SetPhi_ (MolComplexS *, ConfigS *, double); int SetPsi_ (MolComplexS *, ConfigS *, double); int SetOmega_ (MolComplexS *, ConfigS *, double); int SetChi1_ (MolComplexS *, ConfigS *, double); int SetChi2_ (MolComplexS *, ConfigS *, double); int SetChi3_ (MolComplexS *, ConfigS *, double); int SetChi4_ (MolComplexS *, ConfigS *, double); int SetChi5_ (MolComplexS *, ConfigS *, double); size_t MainRefresh_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); int ControlRefresh_ (MolComplexS *, ConfigS *, GUIS *); /*======execute the command set:=============================================*/ int Set_ (MolComplexS *mol_complexSP, int mol_complexesN, RuntimeS *runtimeSP, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int *refreshIP, char *stringP) { char *remainderP; char first_tokenA[SHORTSTRINGSIZE]; char second_tokenA[SHORTSTRINGSIZE]; char *P; int n; double angle; int mol_complexI; MolComplexS *curr_mol_complexSP; /* Extract the first token: */ remainderP = ExtractToken_ (first_tokenA, STRINGSIZE, stringP, " \t\n"); /* If the first token is not available, inform */ /* the user about the syntax of this command: */ if (!remainderP) { strcpy (runtimeSP->messageA, "Use the following syntax: set angle_name angle_in_degrees"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_SET; } /* If this point is reached, the first token is present. */ /* Extract the second token (the angle in degrees): */ remainderP = ExtractToken_ (second_tokenA, STRINGSIZE, remainderP, " \t\n"); if (!remainderP) { strcpy (runtimeSP->messageA, "The angle is missing!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_SET; } /* Try to extract the numeric value of the angle. */ /* Replace each non-numeric character (except */ /* minus sign and decimal point) with space: */ P = second_tokenA; while ((n = *P++) != '\0') { if (!isdigit (n) && (n != '-') && (n != '.')) *(P - 1) = ' '; } /* Try to extract the numeric value: */ if (sscanf (second_tokenA, "%lf", &angle) != 1) { strcpy (runtimeSP->messageA, "Unable to extract the angle!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_SET; } /* Convert degrees to radians: */ angle *= DEG_TO_RAD; /* The specified angle should be set for each */ /* selected residue in each caught complex. */ /* Scan the array of macromolecular complexes: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check is this complex caught: */ if (curr_mol_complexSP->catchF == 0) continue; /* Now try to recognize the keyword which specifies the angle. */ /* Keyword PHI: */ if (strstr (first_tokenA, "PHI") == first_tokenA) { SetPhi_ (curr_mol_complexSP, configSP, angle); } /* Keyword PSI: */ else if(strstr (first_tokenA, "PSI") == first_tokenA) { SetPsi_ (curr_mol_complexSP, configSP, angle); } /* Keyword OMEGA: */ else if (strstr (first_tokenA, "OME") == first_tokenA) { SetOmega_ (curr_mol_complexSP, configSP, angle); } /* Keyword CHI1: */ else if (strstr (first_tokenA, "CHI1") == first_tokenA) { SetChi1_ (curr_mol_complexSP, configSP, angle); } /* Keyword CHI2: */ else if (strstr (first_tokenA, "CHI2") == first_tokenA) { SetChi2_ (curr_mol_complexSP, configSP, angle); } /* Keyword CHI3: */ else if (strstr (first_tokenA, "CHI3") == first_tokenA) { SetChi3_ (curr_mol_complexSP, configSP, angle); } /* Keyword CHI4: */ else if (strstr (first_tokenA, "CHI4") == first_tokenA) { SetChi4_ (curr_mol_complexSP, configSP, angle); } /* Keyword CHI5: */ else if (strstr (first_tokenA, "CHI5") == first_tokenA) { SetChi5_ (curr_mol_complexSP, configSP, angle); } } /* Refresh the main window: */ (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); /* Refresh the control window: */ ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); /* Return the command code: */ return COMMAND_SET; } /*===========================================================================*/ garlic-1.6/tag.c0000644000076500007650000001351407463464601014044 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2002 Damir Zucic */ /*============================================================================= tag.c Purpose: Execute tag command: add the tag to the macromolecular complex which is currently handled. The maximal number of characters in the tag (including the terminal zero) is equal to TAGSIZE. Input: (1) Pointer to MolComplexS structure. (2) The number of macromolecular complexes. (3) Pointer to RuntimeS structure. (4) Pointer to ConfigS structure. (5) Pointer to GUIS structure. (6) Pointer to NearestAtomS structure. (7) The number of pixels in the main window free area. (8) Pointer to refreshI. Output: (1) The specified tag written or hidden. (2) Return value. Return value: (1) Positive (command) code on success. (2) Negative (error) code on failure. Notes: (1) This function uses the original command string, to preserve case in the tag string. The first token is the keyword tag. The second token is either the string, enclosed in duoble quotes, or the keyword OFF. The tag will be assigned to the macromolecular complex which is currently caught and drawn above this complex. It moves along with the complex. ----------------------------------------------------------- | Example Purpose | ----------------------------------------------------------- | TAG "PORIN" | Add the tag to currently caught complex | ----------------------------------------------------------- | TAG OFF | Hide the tag | ----------------------------------------------------------- ========includes:============================================================*/ #include #include #include #include #include #include #include #include "defines.h" #include "commands.h" #include "typedefs.h" /*======function prototypes:=================================================*/ char *ExtractToken_ (char *, int, char *, char *); size_t MainRefresh_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); int ControlRefresh_ (MolComplexS *, ConfigS *, GUIS *); /*======execute tag command:=================================================*/ int Tag_ (MolComplexS *mol_complexSP, int mol_complexesN, RuntimeS *runtimeSP, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int *refreshIP) { char *stringP; char tokenA[STRINGSIZE]; char *remainderP; char token_copyA[STRINGSIZE]; char *P; int n; int mol_complexI; MolComplexS *curr_mol_complexSP; size_t atomsN; char *dummyP; /* Skip the first token: */ stringP = ExtractToken_ (tokenA, STRINGSIZE, runtimeSP->curr_commandA, " \t\n"); if (!stringP) return ERROR_TAG; /* Extract the second token for the first time: */ remainderP = ExtractToken_ (tokenA, STRINGSIZE, stringP, " \t\n"); if (!remainderP) { strcpy (runtimeSP->messageA, "Missing tag!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_TAG; } /* Convert token to uppercase: */ strncpy (token_copyA, tokenA, STRINGSIZE - 1); P = token_copyA; while ((n = *P++) != '\0') *(P - 1) = toupper (n); /* If second token is the keyword OFF, hide tag for all caught complexes: */ if (strncmp (token_copyA, "OFF", 3) == 0) { /** Hide tag for each caught complex: **/ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /*** Pointer to the current macromolecular complex: ***/ curr_mol_complexSP = mol_complexSP + mol_complexI; /*** Check is the current macromolecular complex caught: ***/ if (curr_mol_complexSP->catchF == 0) continue; /*** Check the number of atoms in a macromol. complex: ***/ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /*** Hide tag (set flag to zero): ***/ curr_mol_complexSP->tagF = 0; } /** Refresh the main window: **/ (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); /** Refresh the control window: **/ ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); /** Return to the caller: **/ return COMMAND_TAG; } /* Extract the tag: */ /** At least one (single or double) quote should be present: **/ if ((strstr (stringP, "\"") == NULL) && (strstr (stringP, "'") == NULL)) { strcpy (runtimeSP->messageA, "The tag should be enclosed in qoutes!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_TAG; } /** Extract the second token again (the string enclosed in qoutes): **/ remainderP = strstr (stringP, "\"") + 1; dummyP = ExtractToken_ (tokenA, STRINGSIZE, remainderP, "\""); /* Assign (copy) this tag to each caught macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /** Pointer to the current macromolecular complex: **/ curr_mol_complexSP = mol_complexSP + mol_complexI; /** Check is the current macromolecular complex caught: **/ if (curr_mol_complexSP->catchF == 0) continue; /** Check the number of atoms in a macromol. complex: **/ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /** Assign (copy) tag: **/ strncpy (curr_mol_complexSP->tagA, tokenA, TAGSIZE - 1); curr_mol_complexSP->tagA[TAGSIZE - 1] = '\0'; /** Set flag: **/ curr_mol_complexSP->tagF = 1; } /* Refresh the main window: */ (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); /* Refresh the control window: */ ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); /* Return the command code: */ return COMMAND_TAG; } /*===========================================================================*/ garlic-1.6/ssb.c0000644000076500007650000001060707540350210014042 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2002 Damir Zucic */ /*============================================================================= ssb.c Purpose: Execute ssb command: change drawing style for disulfide bonds. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) The number of macromolecular complexes. (3) Pointer to RuntimeS structure, with some runtime data. (4) Pointer to ConfigS structure, with configuration data. (5) Pointer to GUIS structure, with GUI data. (6) Pointer to NearestAtomS structure. (7) The number of pixels in the main window free area. (8) Pointer to refreshI. (9) String which contains the bond drawing style name. Output: (1) The hiddenF set for each disulfide bond in each caught complex. (2) Return value. Return value: (1) Positive (command) code on success. (2) Negative (error) code on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "commands.h" #include "typedefs.h" /*======function prototypes:=================================================*/ char *ExtractToken_ (char *, int, char *, char *); size_t MainRefresh_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); int ControlRefresh_ (MolComplexS *, ConfigS *, GUIS *); /*======execute ssb command:=================================================*/ int SSB_ (MolComplexS *mol_complexSP, int mol_complexesN, RuntimeS *runtimeSP, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int *refreshIP, char *stringP) { char *remainderP; char tokenA[SHORTSTRINGSIZE]; int bond_styleI; int mol_complexI; MolComplexS *curr_mol_complexSP; size_t atomsN, atomI; AtomS *curr_atomSP; int bondI, bondsN; /* Extract the bond style name: */ remainderP = ExtractToken_ (tokenA, SHORTSTRINGSIZE, stringP, " \t\n"); if (!remainderP) { strcpy (runtimeSP->messageA, "Bond drawing style specification missing!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_NO_ATOM_STYLE; } /* Try to recognize the requested style: */ if (strcmp (tokenA, "0") == 0) bond_styleI = 0; else if (strcmp (tokenA, "1") == 0) bond_styleI = 1; else if (strcmp (tokenA, "2") == 0) bond_styleI = 2; else if (strcmp (tokenA, "3") == 0) bond_styleI = 3; else if (strcmp (tokenA, "4") == 0) bond_styleI = 4; else if (strcmp (tokenA, "5") == 0) bond_styleI = 5; else if (strstr (tokenA, "NIC") == tokenA) bond_styleI = NICE_BONDS; else { sprintf (runtimeSP->messageA, "Bond drawing style \"%s\" not available!", tokenA); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_BOND_STYLE; } /* Scan every macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /** Pointer to the current macromolecular complex: **/ curr_mol_complexSP = mol_complexSP + mol_complexI; /** Check is the current macromolecular complex caught: **/ if (curr_mol_complexSP->catchF == 0) continue; /** Number of bonds in a macromolecular complex: **/ atomsN = curr_mol_complexSP->atomsN; /** Scan all bonds in the current complex: **/ for (atomI = 0; atomI < atomsN; atomI++) { /** Pointer to the current bond: **/ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /** Check is atom selected: **/ if (curr_atomSP->selectedF == 0) continue; /** The number of bonds associated with a given atoms: **/ bondsN = curr_atomSP->bondsN; /** Scan all bonds: **/ for (bondI = 0; bondI < bondsN; bondI++) { /*** If this is not a disulfide bond, skip it: ***/ if (curr_atomSP->true_bondSA[bondI].bond_typeI != 2) { continue; } /*** Change the bond drawing style: ***/ curr_atomSP->true_bondSA[bondI].bond_styleI = bond_styleI; } } /* Reset the position_changedF: */ curr_mol_complexSP->position_changedF = 1; } /* Refresh the main window: */ (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); /* Refresh the control window: */ ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); /* Return positive value on success: */ return COMMAND_DISULFIDE; } /*===========================================================================*/ garlic-1.6/words0000644000076500007650000000223607762701310014176 0ustar zuciczucic00000000000000# check spelling for the following words: nitrogen oxygen neighbor neighboring neighborhood unable auxiliary cylinder symmetry diagonally disappeared primarily capabilities exceeded middle already overall seventeen success successful successfully sulfur overflow preserve visualization cleavage writing phosphorus thirteen weighting identifier necessary unnecessary specified miscellaneous phosphorus sacrifice really especially chose chosen choosing copied careful representing representation exceptionally anchor threshold property disulfide eighteen esthetic associated transparency semi-transparent ellipse below additional parallel omega gamma vertically approximately respectively across purified subtraction crosses circles colorful sandwich usually analyze analysis omit twelve twenty one bought frequent frequently perpendicular hypothetical imaginary experimentally preceding corrupt rearranged accompanied covalently opposite neither mutually non-standard repeatedly inefficient thickness patience collinear tuning sum manually farther offset override correspond hydrogen-bonded everything appropriate simultaneously azimuth barrel useless content sum stretch overview garlic-1.6/comm_translate.c0000644000076500007650000000737607362641733016313 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= comm_translate.c Purpose: Execute translate command. Translate all caught macromolecular complexes for a given shift along a given axis. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) The number of macromolecular complexes. (3) Pointer to RuntimeS structure, with some runtime data. (4) Pointer to ConfigS structure, with configuration data. (5) Pointer to GUIS structure, with GUI data. (6) Pointer to NearestAtomS structure. (7) The number of pixels in the main window free area. (8) Pointer to refreshI. (9) String which contains the translation axis name and the translation angle. Output: (1) Atomic coordinates changed. (2) Return value. Return value: (1) Positive (command) code on success. (2) Negative (error) code on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "commands.h" #include "typedefs.h" /*======function prototypes:=================================================*/ char *ExtractToken_ (char *, int, char *, char *); void Translate_ (MolComplexS *, int, RuntimeS *, ConfigS *, double, int); size_t MainRefresh_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); int ControlRefresh_ (MolComplexS *, ConfigS *, GUIS *); int DockingRefresh_ (RuntimeS *, GUIS *); /*======execute translate command:===========================================*/ int CommandTranslate_ (MolComplexS *mol_complexSP, int mol_complexesN, RuntimeS *runtimeSP, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int *refreshIP, char *stringP) { char *remainderP; char tokenA[STRINGSIZE]; int axisID; double shift; /* Extract axis name: */ remainderP = ExtractToken_ (tokenA, STRINGSIZE, stringP, " \t\n"); if (!remainderP) { strcpy (runtimeSP->messageA, "Axis specification missing!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_NO_AXIS; } /* Identify the axis: */ if (strcmp (tokenA, "X") == 0) axisID = 1; else if (strcmp (tokenA, "Y") == 0) axisID = 2; else if (strcmp (tokenA, "Z") == 0) axisID = 3; else { strcpy (runtimeSP->messageA, "Bad axis (only x, y and z are available)!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_BAD_AXIS; } /* Extract the token which contains the shift: */ remainderP = ExtractToken_ (tokenA, STRINGSIZE, remainderP, " \t\n"); if (!remainderP) { strcpy (runtimeSP->messageA, "Translation shift missing!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_NO_SHIFT; } /* Extract the shift: */ if (sscanf (tokenA, "%lf", &shift) != 1) { strcpy (runtimeSP->messageA, "Translation shift specification is bad!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_NO_SHIFT; } /* Translate all caught macromolecular complexes: */ Translate_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, shift, axisID); /* Refresh the main window: */ (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); /* Refresh the control window: */ ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); /* Refresh docking window, if docking is switched on: */ if (guiSP->dockingF) DockingRefresh_ (runtimeSP, guiSP); /* Return positive value on success: */ return COMMAND_TRANSLATE; } /*===========================================================================*/ garlic-1.6/cecropin_a.fasta0000644000076500007650000000011207747434573016247 0ustar zuciczucic00000000000000> Cecropin A antimicrobial peptide. KWKLFKKIEKVGQNIRDGIIKAGPAVAVVGQATQIAK garlic-1.6/print_usage.c0000644000076500007650000000176407065474433015617 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= print_usage.c Purpose: Print usage info. This function will be called if someone tryes to run garlic without X server. Input: No input. Output: Usage info written to stdout. Return value: No return value. ========includes:============================================================*/ #include /*======print usage info:====================================================*/ void PrintUsage_ (void) { fprintf (stdout, "\n=============================================\n"); fprintf (stdout, "Garlic, free molecular visualisation program.\n"); fprintf (stdout, "=============================================\n\n"); fprintf (stdout, "Usage:\n\n"); fprintf (stdout, " garlic [options] [infile] \n"); fprintf (stdout, " garlic -h ... print help\n"); } /*===========================================================================*/ garlic-1.6/anchor.xpm0000644000076500007650000001305307303426252015114 0ustar zuciczucic00000000000000/* XPM */ static char *anchor_xpm[] = { /* width height num_colors chars_per_pixel */ " 67 77 5 1", /* colors */ "a c None", "b c red", "c c RGB:FFFF/8888/8888", ". c black", "# c DarkRed", /* pixels */ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.....aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaa..ccccc..aaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaaaaa.ccccccccc.aaaaaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaaaa.cccbbbbbcc#.aaaaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaaa.ccbbb###bbb##.aaaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaaa.ccb######cb##.aaaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaa.ccbb##...ccbb##.aaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaa.ccb##.aaa.ccb##.aaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaa.ccb##.aaa.ccb##.aaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaa.ccb##.aaa.ccb##.aaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaa.ccbb#c...ccbb##.aaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaaa.ccbcccccccb##.aaaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaaa.ccbbbcccbbb##.aaaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaaaa.ccbbbbbb###.aaaaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaaaaa.cccbbb###.aaaaaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaa.ccbbb##.aaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaa.ccbbb##.aaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaa.ccbbb##.aaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaa........ccbbb##.......aaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaa.ccccccccccbbb##ccccccc..aaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaa.cccccccccccbbb#cccccccccc.aaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaa.ccbbbbbbbbbbbbbbbbbbbbbbb##.aaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaa.ccbbbbbbbbbbbbbbbbbbbbbbb##.aaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaa.###########bbb###########.aaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaa.#########cbbb##########.aaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaa........ccbbb##........aaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaa.ccbbb##.aaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaa.ccbbb##.aaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaa.ccbbb##.aaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaa.ccbbb##.aaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaa.ccbbb##.aaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaa.ccbbb##.aaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaa.ccbbb##.aaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaa.ccbbb##.aaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaa.ccbbb##.aaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaa.ccbbb##.aaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaa.ccbbb##.aaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaa.ccbbb##.aaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaa.ccbbb##.aaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaa.ccbbb##.aaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaa.ccbbb##.aaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaa.ccbbb##.aaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaa.ccbbb##.aaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "...aaaaaaaaaaaaaaaaaaaaaaaaaa.ccbbb##.aaaaaaaaaaaaaaaaaaaaaaaaaa...", ".#c.aaaaaaaaaaaaaaaaaaaaaaaaa.ccbbb##.aaaaaaaaaaaaaaaaaaaaaaaaa.c#.", "a.#c..aaaaaaaaaaaaaaaaaaaaaaa.ccbbb##.aaaaaaaaaaaaaaaaaaaaaaa..c#.a", "a.#bcc..aaaaaaaaaaaaaaaaaaaaa.ccbbb##.aaaaaaaaaaaaaaaaaaaaa..ccb#.a", "aa.#bbcc..aaaaaaaaaaaaaaaaaaa.ccbbb##.aaaaaaaaaaaaaaaaaaa..ccbb#.aa", "aaa.##bccc...aaaaaaaaaaaaaaaa.ccbbb##.aaaaaaaaaaaaaaaa...cccb##.aaa", "aaaa.##bbcccc...aaaaaaaaaaaaa.ccbbb##.aaaaaaaaaaaaa...ccccbb##.aaaa", "aaaaa.##bbbbcccc...aaaaaaaaa.cccbbb##c.aaaaaaaaa...ccccbbbb##.aaaaa", "aaaaaa.##bb.bbbbccc...aaaaaa.cccbbb#cc.aaaaaa...cccbbbb.bb##.aaaaaa", "aaaaaaa.##bb..#####.aaaaaaa.ccccbbbcccc.aaaaaaa.#####..bb##.aaaaaaa", "aaaaaaaa.##bbb.....aaaaaa..ccccbbbbbcccc..aaaaaa.....bbb##.aaaaaaaa", "aaaaaaaaa.##bbbbccc......ccccccbbbbbcccccc......cccbbbb##.aaaaaaaaa", "aaaaaaaaaa.###bbbbccccccccccccbbbbbbbccccccccccccbbbb###.aaaaaaaaaa", "aaaaaaaaaaa..###bbbbbbccccccbbbbbbbbbbbccccccbbbbbb###..aaaaaaaaaaa", "aaaaaaaaaaaaa..###bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb###..aaaaaaaaaaaaa", "aaaaaaaaaaaaaaa..###bbbbbbbbbbbbbbbbbbbbbbbbbbb###..aaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaa..###bbbbbbbbbbbbbbbbbbbbbbb###..aaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaa..####bbbbbbbbbbbbbbbbb####..aaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaa..####bbbbbbbbbbbbb####..aaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaa..####bbbbbbbbb####..aaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaa..####bbbbb####..aaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaaaa.####bbb####.aaaaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaaaaa.####b####.aaaaaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaa.#######.aaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.#####.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.#####.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.###.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.###.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.###.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.#.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.#.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.#.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" }; garlic-1.6/membrane.c0000644000076500007650000003145207641055373015060 0ustar zuciczucic00000000000000/* Copyright (C) 2001-2003 Damir Zucic */ /*============================================================================= membrane.c Purpose: Execute membrane command. Input: (1) Pointer to MolComplexS structure. (2) The number of macromolecular complexes. (3) Pointer to RuntimeS structure. (4) Pointer to ConfigS structure. (5) Pointer to GUIS structure. (6) Pointer to NearestAtomS structure. (7) The number of pixels in the main window free area. (8) Pointer to refreshI. (9) Pointer to the remainder of the command string. It may be empty or it may contain the keyword OFF, TRA (TRANSPARENCY), RAD (RADIUS), THI (THICKNESS) or BET (BETA). Output: (1) The membrane flag set. (2) Return value. Return value: (1) Positive (command) code on success. (2) Negative (error) code on failure. Notes: (1) By default, an alpha helix bundle protein is expected. This may be changed by using the keyword BETA. In that case, garlic will expect a beta barrel protein. A different method will be used to place the membrane with respect to the protein. ========includes:============================================================*/ #include #include #include #include #include #include #include #include "defines.h" #include "commands.h" #include "typedefs.h" /*======function prototypes:=================================================*/ char *ExtractToken_ (char *, int, char *, char *); void InformUser_ (GUIS *, char *); int AlphaMembrane_ (MolComplexS *, RuntimeS *, ConfigS *, GUIS *); int BetaMembrane_ (MolComplexS *, RuntimeS *, ConfigS *, GUIS *); size_t MainRefresh_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); int ControlRefresh_ (MolComplexS *, ConfigS *, GUIS *); /*======execute membrane command:============================================*/ int Membrane_ (MolComplexS *mol_complexSP, int mol_complexesN, RuntimeS *runtimeSP, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int *refreshIP, char *stringP) { char *remainderP; char tokenA[STRINGSIZE]; int mol_complexI; MolComplexS *curr_mol_complexSP; char *P; int n; double value; /* Extract the first token, if present: */ remainderP = ExtractToken_ (tokenA, STRINGSIZE, stringP, " \t\n"); /*---------------------------------------------------------------------------*/ /* If there are no tokens in the remainder of the command string, make the */ /* membrane visible and find the position of the membrane with respect to */ /* the structure. The same job should be done for each caught structure. */ /* In this case, only membrane proteins of helix bundle type are expected! */ if (!remainderP) { /* The sliding window width should be at least seven: */ if (runtimeSP->sliding_window_width < 7) { strcpy (runtimeSP->messageA, "The sliding window should contain"); strcat (runtimeSP->messageA, " at least seven residues!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_MEMBRANE; } /* Scan the array of macromolecular complexes: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check is the current macromolecular complex caught: */ if (curr_mol_complexSP->catchF == 0) continue; /* Set the flag which says that the membrane is defined: */ curr_mol_complexSP->membraneS.definedF = 1; /* Make the membrane visible: */ curr_mol_complexSP->membraneS.hiddenF = 0; /* Inform user that the following function may be slow: */ InformUser_ (guiSP, "This may take some time, please be patient!"); /* Find the position of the membrane: */ n = AlphaMembrane_ (curr_mol_complexSP, runtimeSP, configSP, guiSP); /* Set flags on success, write */ /* an error message on failure: */ if (n > 0) { /* Set the flag which says */ /* that membrane is defined: */ curr_mol_complexSP->membraneS.definedF = 1; /* Make the membrane visible: */ curr_mol_complexSP->membraneS.hiddenF = 0; } else { /* Reset flags: */ curr_mol_complexSP->membraneS.definedF = 0; curr_mol_complexSP->membraneS.hiddenF = 1; /* Write error message: */ strcpy (runtimeSP->messageA, "Unable to prepare the membrane position!"); runtimeSP->message_length = strlen (runtimeSP->messageA); /* Refresh the main window: */ (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); /* Refresh the control window: */ ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); return ERROR_MEMBRANE; } } } /*---------------------------------------------------------------------------*/ /* If keyword OFF is present, hide membrane(s): */ else if (strstr (tokenA, "OFF") == tokenA) { /* For each caught macromolecular complex, hide the membrane: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check is the current macromolecular complex caught: */ if (curr_mol_complexSP->catchF == 0) continue; /* Hide the membrane: */ curr_mol_complexSP->membraneS.hiddenF = 1; } } /*---------------------------------------------------------------------------*/ /* If keyword TRA (TRANSPARENCY) is present, change membrane transparency: */ else if (strstr (tokenA, "TRA") == tokenA) { /* Replace each non-numeric character (except */ /* minus sign and decimal point) with space: */ P = stringP; while ((n = *P++) != '\0') { if (!isdigit (n) && (n != '-') && (n != '.')) *(P - 1) = ' '; } /* Try to extract the membrane transparency: */ if (sscanf (stringP, "%lf", &value) != 1) { strcpy (runtimeSP->messageA, "Failed to extract the membrane transparency!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_MEMBRANE; } /* Check the value; it should be between 0 and 1: */ if ((value < 0.0) || (value > 1.0)) { strcpy (runtimeSP->messageA, "The value should be between 0 and 1!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_MEMBRANE; } /* If this point is reached, the membrane transparency is good: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check is the current macromolecular complex caught: */ if (curr_mol_complexSP->catchF == 0) continue; /* Set the membrane transparency: */ curr_mol_complexSP->membraneS.plane1S.transparency = value; curr_mol_complexSP->membraneS.plane2S.transparency = value; } } /*---------------------------------------------------------------------------*/ /* If keyword RAD (RADIUS) is present, change the circle radius: */ else if (strstr (tokenA, "RAD") == tokenA) { /* Replace each non-numeric character (except */ /* minus sign and decimal point) with space: */ P = stringP; while ((n = *P++) != '\0') { if (!isdigit (n) && (n != '-') && (n != '.')) *(P - 1) = ' '; } /* Try to extract the circle radius: */ if (sscanf (stringP, "%lf", &value) != 1) { strcpy (runtimeSP->messageA, "Failed to extract the membrane radius!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_MEMBRANE; } /* Check the value; it should be positive: */ if (value < 0.0) { strcpy (runtimeSP->messageA, "The value should be positive!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_MEMBRANE; } /* If this point is reached, the membrane radius is good: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check is the current macromolecular complex caught: */ if (curr_mol_complexSP->catchF == 0) continue; /* Set the membrane radius: */ curr_mol_complexSP->membraneS.plane1S.circle_radius = value; curr_mol_complexSP->membraneS.plane2S.circle_radius = value; /* Set the position_changedF, to force projection: */ curr_mol_complexSP->position_changedF = 1; } } /*---------------------------------------------------------------------------*/ /* If keyword THI (THICKNESS) is present, change the membrane thickness: */ else if (strstr (tokenA, "THI") == tokenA) { /* Replace each non-numeric character (except */ /* minus sign and decimal point) with space: */ P = stringP; while ((n = *P++) != '\0') { if (!isdigit (n) && (n != '-') && (n != '.')) *(P - 1) = ' '; } /* Try to extract the membrane thickness: */ if (sscanf (stringP, "%lf", &value) != 1) { strcpy (runtimeSP->messageA, "Failed to extract the membrane thickness!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_MEMBRANE; } /* Check the value; it should be positive and non-zero: */ if (value <= 0.0) { strcpy (runtimeSP->messageA, "The value should be positive!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_MEMBRANE; } /* If this point is reached, the membrane thickness is good: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check is the current macromolecular complex caught: */ if (curr_mol_complexSP->catchF == 0) continue; /* Set the membrane thickness: */ curr_mol_complexSP->membraneS.thickness = value; /* Set the position_changedF, to force projection: */ curr_mol_complexSP->position_changedF = 1; } } /*---------------------------------------------------------------------------*/ /* If keyword BET (BETA) is present, a beta barrel protein is expected: */ else if (strstr (tokenA, "BET") == tokenA) { /* The sliding window width should be at least five: */ if (runtimeSP->sliding_window_width < 5) { strcpy (runtimeSP->messageA, "The sliding window should contain"); strcat (runtimeSP->messageA, " at least five residues!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_MEMBRANE; } /* Scan the array of macromolecular complexes: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check is the current macromolecular complex caught: */ if (curr_mol_complexSP->catchF == 0) continue; /* Set the flag which says that the membrane is defined: */ curr_mol_complexSP->membraneS.definedF = 1; /* Make the membrane visible: */ curr_mol_complexSP->membraneS.hiddenF = 0; /* Inform user that the following function may be slow: */ InformUser_ (guiSP, "This may take some time, please be patient!"); /* Find the position of the membrane: */ n = BetaMembrane_ (curr_mol_complexSP, runtimeSP, configSP, guiSP); /* Set flags on success, write */ /* an error message on failure: */ if (n > 0) { /* Set the flag which says */ /* that membrane is defined: */ curr_mol_complexSP->membraneS.definedF = 1; /* Make the membrane visible: */ curr_mol_complexSP->membraneS.hiddenF = 0; } else { /* Reset flags: */ curr_mol_complexSP->membraneS.definedF = 0; curr_mol_complexSP->membraneS.hiddenF = 1; /* Write error message: */ strcpy (runtimeSP->messageA, "Unable to prepare the membrane position!"); runtimeSP->message_length = strlen (runtimeSP->messageA); /* Refresh the main window: */ (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); /* Refresh the control window: */ ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); return ERROR_MEMBRANE; } } } /*---------------------------------------------------------------------------*/ /* Keyword not recognized: */ else { strcpy (runtimeSP->messageA, "Keyword not recognized!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_MEMBRANE; } /*---------------------------------------------------------------------------*/ /* Refresh the main window: */ (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); /* Refresh the control window: */ ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); /* Return the command code: */ return COMMAND_MEMBRANE; } /*===========================================================================*/ garlic-1.6/read_template_file.c0000644000076500007650000001050307572500013017056 0ustar zuciczucic00000000000000/* Copyright (C) 2001, 2002 Damir Zucic */ /*============================================================================= read_template_file.c Purpose: Read the template file (file with atomic templates). These data will be used later to create new peptides and to replace or insert the residues. The input file format should be compatible with PDB. Input: (1) Pointer to RuntimeS structure. (2) Pointer to the template file. (3) Pointer to ConfigS structure. Output: (1) Atomic data stored to RuntimeS structure. (2) Return value. Return value: (1) The number of atoms read (zero or positive). ========includes:============================================================*/ #include #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int ParsePDBAtomicData_ (AtomS *, char *); int ExtractTemplateResidues_ (RuntimeS *); /*======read template file:==================================================*/ int ReadTemplateFile_ (RuntimeS *runtimeSP, FILE *template_fileP, ConfigS *configSP) { size_t rgb_struct_size; int line_size; char lineA[STRINGSIZE]; int first_char; int rec_typeI = 0; int template_atomI = 0; AtomS *curr_atomSP; int surfaceI; /* Prepare the size of the RGBS structure: */ rgb_struct_size = sizeof (RGBS); /* Prepare the line_size: */ line_size = sizeof (lineA); /* Read the entire file, line by line: */ while (fgets (lineA, line_size, template_fileP)) { /* Prepare the first character, it will be used */ /* to speed up the recognition of record type: */ first_char = *lineA; /* Check is there a chance that input line is ATOM or HETATM record: */ rec_typeI = 0; switch (first_char) { case 'A': if (strstr (lineA, "ATOM") == lineA) rec_typeI = 1; break; case 'H': if (strstr (lineA, "HETATM") == lineA) rec_typeI = 2; break; default: ; } /* Ignore this line if it is neither ATOM nor HETATM record: */ if (rec_typeI == 0) continue; /* If this point is reached, extract data if */ /* input line contains ATOM or HETATM record: */ /* Prepare the pointer to the current atom: */ curr_atomSP = runtimeSP->template_atomSP + template_atomI; /* Try to parse ATOM or HETATM line: */ if (ParsePDBAtomicData_ (curr_atomSP, lineA) < 0) continue; /* If this point is reached, parsing was successful! */ /* The initial drawing style for atoms: */ curr_atomSP->raw_atomS.atom_styleI = configSP->default_atom_styleI; /* Initialize the model serial number (trivial value): */ curr_atomSP->raw_atomS.model_serialI = 0; /* Initialize the selection flag: */ curr_atomSP->selectedF = 1; /* Initialize the hiddenF: */ curr_atomSP->hiddenF = 0; /* Put the atom inside the slab: */ curr_atomSP->inside_slabF = 1; /* Hide atomic label: */ curr_atomSP->labelF = 0; /* Set flag which distinguishes ATOM and HETATM data: */ if (rec_typeI == 1) curr_atomSP->raw_atomS.heteroF = 0; else curr_atomSP->raw_atomS.heteroF = 1; /* Set the number of color fading surfaces: */ curr_atomSP->surfacesN = configSP->default_surfacesN; /* Copy default basic colors: */ for (surfaceI = 0; surfaceI < MAXCOLORSURFACES; surfaceI++) { memcpy (curr_atomSP->left_rgbSA + surfaceI, configSP->left_rgbSA + surfaceI, rgb_struct_size); memcpy (curr_atomSP->middle_rgbSA + surfaceI, configSP->middle_rgbSA + surfaceI, rgb_struct_size); memcpy (curr_atomSP->right_rgbSA + surfaceI, configSP->right_rgbSA + surfaceI, rgb_struct_size); } /* Increment the counter: */ template_atomI++; /* Do not allow memory leak: */ if (template_atomI >= MAXTEMPLATEATOMS) break; } /* Store the number of template atoms: */ runtimeSP->template_atomsN = template_atomI; /* Initialize the residue data. If this function failes, the template */ /* file was bad; free storage and reset the number of template atoms. */ if (ExtractTemplateResidues_ (runtimeSP) < 0) { runtimeSP->template_atomsN = 0; if (runtimeSP->template_atomSP) { free (runtimeSP->template_atomSP); runtimeSP->template_atomSP = NULL; } return 0; } /* Return the number of template atoms on success: */ return template_atomI; } /*===========================================================================*/ garlic-1.6/strong_bonds.c0000644000076500007650000001403007747301200015752 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2003 Damir Zucic */ /*============================================================================= strong_bonds.c Purpose: Prepare strong bonds. In proteins, the waste majority of strong bonds (or all of them) are covalent bonds. Inter-atomic distances are used to recognize valid bonds. This function does not check the bond angles. For each atom, assume that bonds are established with neighboring atoms, as arranged in the input file. The width of a window to be scanned should be defined through .garlicrc . In garlic, there are two pseudoelements, jellium and quarkonium (J and Q). These imaginary elements are used to draw polygonal lines and inert atoms. Such elements were invented to adapt garlic for medical imaging. The idea was to represent the blood vessels in human brain as lines and axon retraction balls as points (inert atoms). J atoms do not form any bonds, while Q atoms bind to two neighboring Q atoms or, more precisely, only to the atoms which are listed as the nearest neighbors in PDB file. The actual distance between neighboring Q atoms is not important. Q atoms do not form bonds with atoms from another chain. For example, the i-th Q atom will form bonds with Q atoms with serial numbers i - 1 and i + 1 if all three atoms belong to the same chain. This function will not generate any pseudo-bonds (see pseudo_bonds.c). Input: (1) Pointer to MolComplexS structure, with macromolecular data. (2) The array index of a given macromolecular complex. (3) Pointer to ConfigS structure, with configuration data. Output: (1) Information about bonds added to each element of MolComplexS array of structures. (2) Return value. Return value: (1) The total number of bonds on success. (2) Zero if there are no atoms. (3) Negative, if there are some atoms but there are no bonds. Notes: (1) If some atoms are deleted or inserted, all bonds have to be updated. Note that array indices are shifted after addition or deletion of atoms; that's the most important reason for thorough revision of bonds. (2) This function may be used to update bonds, so it is important to reset the total number of bonds for each atom. (3) Hydrogen bonds are not treated here. (4) Disulfide bonds are not treated here. (5) It should be taken into account that hydrogen bond or even stronger bond may connect atoms from two different macromol. complexes. TrueBondS structure associated with a given atom must contain the information about the macromol. complex to which the neighboring atom belongs. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int CheckDistance_ (double *, AtomS *, AtomS *, ConfigS *); int AddBond_ (AtomS *, int, int, int, size_t, double, int); /*======prepare strong bonds:================================================*/ size_t StrongBonds_ (MolComplexS *mol_complexSP, int mol_complexI, ConfigS *configSP) { size_t total_bondsN = 0; size_t atomsN, atomI; /* Use signed int to store the following indices: */ int neigh_start, neigh_end, neighborI, combinedI; size_t neighbor_arrayI; AtomS *curr_atomSP, *curr_neighborSP; char *symbolP; int pairID; int bond_typeI; double distance; char alt_location1, alt_location2; /* Return zero if there are no atoms: */ atomsN = mol_complexSP->atomsN; if (atomsN == 0) return 0; /* Covalent bonds are treated as type 1: */ bond_typeI = 1; /* The first and the last neighbor to be checked: */ neigh_start = -1 * configSP->bond_candidates_backward; /* Note the sign! */ neigh_end = configSP->bond_candidates_forward; /* Scan all atoms: */ for (atomI = 0; atomI < atomsN; atomI++) { /** Pointer to the current atom: **/ curr_atomSP = mol_complexSP->atomSP + atomI; /** Initialize/reset the number of bonds for a given atom: **/ curr_atomSP->bondsN = 0; /** Ignore imaginary (J and Q) atoms: **/ symbolP = curr_atomSP->raw_atomS.chemical_symbolA; if (strcmp (symbolP, " J") == 0) continue; if (strcmp (symbolP, " Q") == 0) continue; /** Scan the neighborhood of a given atom: **/ for (neighborI = neigh_start; neighborI <= neigh_end; neighborI++) { /** Atom is not chemically bound to itself: **/ if (neighborI == 0) continue; /** Prepare and check the combined index: **/ combinedI = atomI + neighborI; if (combinedI < 0) continue; if (combinedI >= (int) atomsN) break; /** If combined index is good, use it as array index: **/ neighbor_arrayI = combinedI; /** Pointer to the current neighbor: **/ curr_neighborSP = mol_complexSP->atomSP + neighbor_arrayI; /** Check is there some sort of a chemical bond: **/ pairID = CheckDistance_ (&distance, curr_atomSP, curr_neighborSP, configSP); /** If bond is bad, check the next neighbor: **/ if (pairID <= 0) continue; /** Disulfide bonds should not be counted here: **/ if (pairID == 11) continue; /** Compare the alternate location indicators; **/ /** if both indicators are different from ' ' **/ /** and mutually different, the bond is bad! **/ alt_location1 = curr_atomSP->raw_atomS.alt_location; alt_location2 = curr_neighborSP->raw_atomS.alt_location; if ((alt_location1 != alt_location2) && (alt_location1 != ' ') && (alt_location2 != ' ')) { continue; } /** If this point is reached, the bond does exist! **/ /** Add bond to the current atom: **/ AddBond_ (curr_atomSP, pairID, bond_typeI, mol_complexI, neighbor_arrayI, distance, configSP->default_bond_styleI); /* Update the number of bonds in a macromolecular complex: **/ total_bondsN++; } } /* If this point is reached, return the total number of bonds: */ return total_bondsN; } /*===========================================================================*/ garlic-1.6/errmsg.c0000644000076500007650000000251507065470342014564 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= errmsg.c Purpose: Print error message. Input: (1) Program name. (2) Name of the function where error occured. (3) Name of the file which caused trouble, if file caused trouble. (4) \ (5) \ ... Error message, split into four strings. (6) / Don't forget to put newline somewhere! (7) / Output: (1) Error message written to stderr. Return value: No return value. ========includes:============================================================*/ #include #include /*======print error message:=================================================*/ /* Note: there is no newline in the last four fprintf! */ void ErrorMessage_ (char *module, char *function, char *filename, char *s1, char *s2, char *s3, char *s4) { fprintf (stderr, "\nERROR>"); fprintf (stderr, " module: %s, function: %s", module, function); if (strlen (filename) != 0) fprintf (stderr, ", file: %s", filename); fprintf (stderr, "\n"); if (strlen (s1) != 0) fprintf (stderr, "%s", s1); if (strlen (s2) != 0) fprintf (stderr, "%s", s2); if (strlen (s3) != 0) fprintf (stderr, "%s", s3); if (strlen (s4) != 0) fprintf (stderr, "%s", s4); } /*===========================================================================*/ garlic-1.6/README0000644000076500007650000000363010364506574014003 0ustar zuciczucic00000000000000================== Garlic version 1.6 ================== WHAT IS THIS? This README file describes garlic, free molecular viewer and editor written for unix and unix clones. Garlic was written by Damir Zucic, at the University of Osijek, Croatia (the address may be found below). HOW TO OBTAIN GARLIC? The latest version of garlic may be found at: http://garlic.mefos.hr/garlic The version 1.6 should be at: http://garlic.mefos.hr/garlic-1.6 TECHNICAL REQUIREMENTS To compile and run garlic, the following requirements should be met: (1) The operating system should be unix or some unix clone, preferably linux. (2) The X window system is required (X11R6, but other versions may work too). (3) The X server should be capable to support TrueColor visual (some older servers are not capable to offer this visual). (4) Color monitor and video-card should be capable to support the color depth of at least 8 bits per pixel (24 bits per pixel recommended). (5) GNU C or some other C compiler capable to compile ANSI C code is required. HOW TO INSTALL GARLIC? Read the file INSTALL or the web page: http://garlic.mefos.hr/garlic-1.6/install GARLIC DOCUMENTATION The latest documentation may be found at http://garlic.mefos.hr/garlic - be sure to read the tutorial and the sections which describe commands and controls. Print the reference card and keep it at hand during your garlic sessions. The interactive help will be added later. DOWNLOADABLE DOCUMENTATION If you prefer to copy the entire documentation to your local machine, there is a packed version of HTML documentation: http://garlic.mefos.hr/garlic-1.6/source/ AUTHOR Damir Zucic Medicinski fakultet Huttlerova 4 31000 Osijek Croatia Europe Phone: Osijek area: 512-855 Other parts of Croatia: 031-512-855 International: 00-385-31-512-855 e-mail: zucic@garlic.mefos.hr zucic@mia.os.carnet.hr Osijek, January 09, 2006. garlic-1.6/tsx.fasta0000644000076500007650000000057210124276560014754 0ustar zuciczucic00000000000000>sp|P22786|TSX_ECOLI Nucleoside-specific channel-forming protein tsx precursor MKKTLLAAGAVLALSSSFTVNAAENDKPQYLSDWWHQSVNVVGSYHTRFGPQIRNDTYLE YEAFAKKDWFDFYGYADAPVFFGGNSDAKGIWNHGSPLFMEIEPRFSIDKLTNTDLSFGP FKEWYFANNYIYDMGRNKDGRQSTWYMGLGTDIDTGLPMSLSMNVYAKYQWQNYGAANEN EWDGYRFKIKYFVPITDLWGGQLSYIGFTNFDWGSDLGDDSGNAINGIKTRTNNSIASSH ILALNYDHWHYSVVARYWHDGGQWNDDAELNFGNGNFNVRSTGWGGYLVVGYNF garlic-1.6/bond_style5_quad1.c0000644000076500007650000002010307461726730016605 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2002 Damir Zucic */ /*============================================================================= bond_style5_quad1.c Purpose: Draw bond which fits into quadrant 1 using style 5. See the file file bonds_style5.c for description of quadrants. Input: (1) Pointer to Aux1S structure, which contains required data. (2) Bond index. Output: (1) A single bond drawn. (2) Return value. Return value: (1) One if at least one pixel is drawn. (2) Zero otherwise. =============================================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======draw bond in quadrant 1 using style 5:===============================*/ int BondStyle5Quadrant1_ (Aux1S *aux1SP, int bondI) { long pixels_drawnN = 0; double recip_denom, x_to_y_scale, x_to_z_scale; int screen_x, screen_x1, delta_x, screen_y, line_screen_y; double d, atomic_z; int lineI; size_t pixelI; NearestAtomS *curr_pixelSP; int edge_y, columnI; static int edge_maskAA[9][3] = {{0, 0, 0}, {1, 1, 0}, {1, 1, 1}, {1, 1, 1}, {1, 1, 1}, {1, 1, 1}, {1, 1, 1}, {1, 1, 0}, {0, 0, 0}}; /* Scale factor required to calculate screen_y from screen_x: */ if (aux1SP->screen_delta_x != 0) recip_denom = 1.0 / aux1SP->screen_delta_x; else recip_denom = 0.0; x_to_y_scale = aux1SP->screen_delta_y * recip_denom; /* Scale factor required to calculate z (in atomic units) from screen_x: */ x_to_z_scale = aux1SP->atomic_delta_z * recip_denom; /* Horizontal scan, from left to right: */ screen_x1 = aux1SP->screen_x0 + (aux1SP->screen_delta_x + 1) / 2; for (screen_x = aux1SP->screen_x0; screen_x <= screen_x1; screen_x++) { /* Check is this pixel inside the area reserved for the */ /* current image (there are two images in stereo mode): */ if (screen_x < aux1SP->configSP->image_screen_x0[aux1SP->imageI]) { continue; } if (screen_x > aux1SP->configSP->image_screen_x1[aux1SP->imageI]) { continue; } /* Relative position: */ delta_x = screen_x - aux1SP->screen_x0; /* Find the corresponding screen_y: */ d = aux1SP->screen_y0 + x_to_y_scale * delta_x; screen_y = (int) (d + 0.5); /* z value (in atomic units): */ atomic_z = aux1SP->atomic_z0 + x_to_z_scale * delta_x; /* Loop which draws lines (vertical scan): */ for (lineI = 0; lineI < 9; lineI++) { /* Pixel position: */ line_screen_y = screen_y +lineI - 4; /* Check is this pixel inside the area reserved for the */ /* current image (there are two images in stereo mode): */ if (line_screen_y < aux1SP->configSP->image_screen_y0) { continue; } if (line_screen_y > aux1SP->configSP->image_screen_y1) { continue; } /* Current pixel index: */ pixelI = aux1SP->guiSP->main_win_free_area_width * line_screen_y + screen_x; /* Check pixel index: */ if (pixelI >= aux1SP->pixelsN) break; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = aux1SP->nearest_atomSP + pixelI; /* Check was this pixel used already in */ /* this drawing step; if it was, compare */ /* the z value of the current atom with z */ /* value previously stored to this pixel: */ if (aux1SP->refreshI == curr_pixelSP->last_refreshI) { if (atomic_z >= curr_pixelSP->z) continue; } /* If this point is reached draw one pixel: */ XDrawPoint (aux1SP->guiSP->displaySP, aux1SP->guiSP->main_hidden_pixmapID, aux1SP->guiSP->theGCA[lineI], screen_x, line_screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = 5; curr_pixelSP->last_refreshI = aux1SP->refreshI; curr_pixelSP->mol_complexI = aux1SP->mol_complexI; curr_pixelSP->atomI = aux1SP->atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = atomic_z; curr_pixelSP->colorID = aux1SP->colorIDA[lineI]; /* Update the number of pixels drawn: */ pixels_drawnN++; } } /* Rounding the left end: */ edge_y = aux1SP->screen_y0; atomic_z = aux1SP->atomic_z0; for (columnI = 0; columnI < 3; columnI++) { /* Prepare and check screen_x: */ screen_x = aux1SP->screen_x0 - columnI - 1; if (screen_x < aux1SP->configSP->image_screen_x0[aux1SP->imageI]) continue; if (screen_x > aux1SP->configSP->image_screen_x1[aux1SP->imageI]) continue; /* Vertical scan: */ for (lineI = 0; lineI < 9; lineI++) { /* Pixel y coordinate: */ line_screen_y = edge_y + lineI - 4; /* Check line_screen_y: */ if (line_screen_y < aux1SP->configSP->image_screen_y0) continue; if (line_screen_y > aux1SP->configSP->image_screen_y1) continue; /* Check the mask: */ if (!edge_maskAA[lineI][columnI]) continue; /* Current pixel index: */ pixelI = aux1SP->guiSP->main_win_free_area_width * line_screen_y + screen_x; /* Check pixel index: */ if (pixelI >= aux1SP->pixelsN) break; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = aux1SP->nearest_atomSP + pixelI; /* Check was this pixel used already in this drawing step : */ if (aux1SP->refreshI == curr_pixelSP->last_refreshI) { if (atomic_z >= curr_pixelSP->z) continue; } /* If this point is reached draw one pixel: */ XDrawPoint (aux1SP->guiSP->displaySP, aux1SP->guiSP->main_hidden_pixmapID, aux1SP->guiSP->theGCA[lineI], screen_x, line_screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = 5; curr_pixelSP->last_refreshI = aux1SP->refreshI; curr_pixelSP->mol_complexI = aux1SP->mol_complexI; curr_pixelSP->atomI = aux1SP->atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = atomic_z; curr_pixelSP->colorID = aux1SP->colorIDA[lineI]; /* Update the number of pixels drawn: */ pixels_drawnN++; } } /* Rounding the right end: */ delta_x = screen_x1 - aux1SP->screen_x0; d = (double) aux1SP->screen_y0 + x_to_y_scale * (double) delta_x; edge_y = (int) (d + 0.5); atomic_z = aux1SP->atomic_z0; atomic_z = aux1SP->atomic_z0 + x_to_z_scale * (double) delta_x; for (columnI = 0; columnI < 3; columnI++) { /* Prepare and check screen_x: */ screen_x = screen_x1 + columnI + 1; if (screen_x < aux1SP->configSP->image_screen_x0[aux1SP->imageI]) continue; if (screen_x > aux1SP->configSP->image_screen_x1[aux1SP->imageI]) continue; /* Vertical scan: */ for (lineI = 0; lineI < 9; lineI++) { /* Pixel y coordinate: */ line_screen_y = edge_y + lineI - 4; /* Check line_screen_y: */ if (line_screen_y < aux1SP->configSP->image_screen_y0) continue; if (line_screen_y > aux1SP->configSP->image_screen_y1) continue; /* Check the mask: */ if (!edge_maskAA[lineI][columnI]) continue; /* Current pixel index: */ pixelI = aux1SP->guiSP->main_win_free_area_width * line_screen_y + screen_x; /* Check pixel index: */ if (pixelI >= aux1SP->pixelsN) break; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = aux1SP->nearest_atomSP + pixelI; /* Check was this pixel used already in this drawing step : */ if (aux1SP->refreshI == curr_pixelSP->last_refreshI) { if (atomic_z >= curr_pixelSP->z) continue; } /* If this point is reached draw one pixel: */ XDrawPoint (aux1SP->guiSP->displaySP, aux1SP->guiSP->main_hidden_pixmapID, aux1SP->guiSP->theGCA[lineI], screen_x, line_screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = 5; curr_pixelSP->last_refreshI = aux1SP->refreshI; curr_pixelSP->mol_complexI = aux1SP->mol_complexI; curr_pixelSP->atomI = aux1SP->atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = atomic_z; curr_pixelSP->colorID = aux1SP->colorIDA[lineI]; /* Update the number of pixels drawn: */ pixels_drawnN++; } } /* Check is at least one pixel drawn: */ if (pixels_drawnN > 0) return 1; /* If this point is reached, nothing is drawn: */ return 0; } /*===========================================================================*/ garlic-1.6/bond_style5_quad2.c0000644000076500007650000002005407461726734016617 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2002 Damir Zucic */ /*============================================================================= bond_style5_quad2.c Purpose: Draw bond which fits into quadrant 2 using style 5. See the file file bonds_style5.c for description of quadrants. Input: (1) Pointer to Aux1S structure, which contains required data. (2) Bond index. Output: (1) A single bond drawn. (2) Return value. Return value: (1) One if at least one pixel is drawn. (2) Zero otherwise. =============================================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======draw bond in quadrant 2 using style 5:===============================*/ int BondStyle5Quadrant2_ (Aux1S *aux1SP, int bondI) { long pixels_drawnN = 0; double recip_denom, y_to_x_scale, y_to_z_scale; int screen_x, line_screen_x, screen_y, screen_y1, delta_y; double d, atomic_z; int lineI; size_t pixelI; NearestAtomS *curr_pixelSP; int edge_x, rowI; static int edge_maskAA[9][3] = {{0, 0, 0}, {1, 1, 0}, {1, 1, 1}, {1, 1, 1}, {1, 1, 1}, {1, 1, 1}, {1, 1, 1}, {1, 1, 0}, {0, 0, 0}}; /* Scale factor required to calculate screen_x from screen_y: */ if (aux1SP->screen_delta_y != 0) recip_denom = 1.0 / aux1SP->screen_delta_y; else recip_denom = 0.0; y_to_x_scale = aux1SP->screen_delta_x * recip_denom; /* Scale factor required to calculate z (in atomic units) from screen_y: */ y_to_z_scale = aux1SP->atomic_delta_z * recip_denom; /* Vertical scan (top to bottom): */ screen_y1 = aux1SP->screen_y0 + (aux1SP->screen_delta_y + 1) / 2; for (screen_y = aux1SP->screen_y0; screen_y <= screen_y1; screen_y++) { /* Check is this pixel inside the area reserved for the */ /* current image (there are two images in stereo mode): */ if (screen_y < aux1SP->configSP->image_screen_y0) continue; if (screen_y > aux1SP->configSP->image_screen_y1) continue; /* Relative position: */ delta_y = screen_y - aux1SP->screen_y0; /* Find the corresponding screen_x: */ d = aux1SP->screen_x0 + y_to_x_scale * delta_y; screen_x = (int) (d + 0.5); /* z value (in atomic units): */ atomic_z = aux1SP->atomic_z0 + y_to_z_scale * delta_y; /* Loop which draws lines (horizontal scan): */ for (lineI = 0; lineI < 9; lineI++) { /* Pixel position: */ line_screen_x = screen_x +lineI - 4; /* Check is this pixel inside the area reserved for the */ /* current image (there are two images in stereo mode): */ if (line_screen_x < aux1SP->configSP->image_screen_x0[aux1SP->imageI]) { continue; } if (line_screen_x > aux1SP->configSP->image_screen_x1[aux1SP->imageI]) { continue; } /* Current pixel index: */ pixelI = aux1SP->guiSP->main_win_free_area_width * screen_y + line_screen_x; /* Check pixel index: */ if (pixelI >= aux1SP->pixelsN) break; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = aux1SP->nearest_atomSP + pixelI; /* Check was this pixel used already in */ /* this drawing step; if it was, compare */ /* the z value of the current atom with z */ /* value previously stored to this pixel: */ if (aux1SP->refreshI == curr_pixelSP->last_refreshI) { if (atomic_z >= curr_pixelSP->z) continue; } /* If this point is reached draw pixel: */ XDrawPoint (aux1SP->guiSP->displaySP, aux1SP->guiSP->main_hidden_pixmapID, aux1SP->guiSP->theGCA[lineI], line_screen_x, screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = 5; curr_pixelSP->last_refreshI = aux1SP->refreshI; curr_pixelSP->mol_complexI = aux1SP->mol_complexI; curr_pixelSP->atomI = aux1SP->atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = atomic_z; curr_pixelSP->colorID = aux1SP->colorIDA[lineI]; /* Update the number of pixels drawn: */ pixels_drawnN++; } } /* Rounding the top end: */ edge_x = aux1SP->screen_x0; atomic_z = aux1SP->atomic_z0; for (rowI = 0; rowI < 3; rowI++) { /* Prepare and check screen_y: */ screen_y = aux1SP->screen_y0 - rowI - 1; if (screen_y < aux1SP->configSP->image_screen_y0) continue; if (screen_y > aux1SP->configSP->image_screen_y1) continue; /* Vertical scan: */ for (lineI = 0; lineI < 9; lineI++) { /* Pixel x coordinate: */ line_screen_x = edge_x + lineI - 4; /* Check line_screen_x: */ if (line_screen_x < aux1SP->configSP->image_screen_x0[aux1SP->imageI]) { continue; } if (line_screen_x > aux1SP->configSP->image_screen_x1[aux1SP->imageI]) { continue; } /* Check the mask: */ if (!edge_maskAA[lineI][rowI]) continue; /* Current pixel index: */ pixelI = aux1SP->guiSP->main_win_free_area_width * screen_y + line_screen_x; /* Check pixel index: */ if (pixelI >= aux1SP->pixelsN) break; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = aux1SP->nearest_atomSP + pixelI; /* Check was this pixel used already in this drawing step : */ if (aux1SP->refreshI == curr_pixelSP->last_refreshI) { if (atomic_z >= curr_pixelSP->z) continue; } /* If this point is reached draw one pixel: */ XDrawPoint (aux1SP->guiSP->displaySP, aux1SP->guiSP->main_hidden_pixmapID, aux1SP->guiSP->theGCA[lineI], line_screen_x, screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = 5; curr_pixelSP->last_refreshI = aux1SP->refreshI; curr_pixelSP->mol_complexI = aux1SP->mol_complexI; curr_pixelSP->atomI = aux1SP->atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = atomic_z; curr_pixelSP->colorID = aux1SP->colorIDA[lineI]; /* Update the number of pixels drawn: */ pixels_drawnN++; } } /* Rounding the bottom end: */ delta_y = screen_y1 - aux1SP->screen_y0; d = (double) aux1SP->screen_x0 + y_to_x_scale * (double) delta_y; edge_x = (int) (d + 0.5); atomic_z = aux1SP->atomic_z0 + y_to_z_scale * (double) delta_y; for (rowI = 0; rowI < 3; rowI++) { /* Prepare and check screen_y: */ screen_y = screen_y1 + rowI + 1; if (screen_y < aux1SP->configSP->image_screen_y0) continue; if (screen_y > aux1SP->configSP->image_screen_y1) continue; /* Vertical scan: */ for (lineI = 0; lineI < 9; lineI++) { /* Pixel x coordinate: */ line_screen_x = edge_x + lineI - 4; /* Check line_screen_x: */ if (line_screen_x < aux1SP->configSP->image_screen_x0[aux1SP->imageI]) { continue; } if (line_screen_x > aux1SP->configSP->image_screen_x1[aux1SP->imageI]) { continue; } /* Check the mask: */ if (!edge_maskAA[lineI][rowI]) continue; /* Current pixel index: */ pixelI = aux1SP->guiSP->main_win_free_area_width * screen_y + line_screen_x; /* Check pixel index: */ if (pixelI >= aux1SP->pixelsN) break; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = aux1SP->nearest_atomSP + pixelI; /* Check was this pixel used already in this drawing step : */ if (aux1SP->refreshI == curr_pixelSP->last_refreshI) { if (atomic_z >= curr_pixelSP->z) continue; } /* If this point is reached draw one pixel: */ XDrawPoint (aux1SP->guiSP->displaySP, aux1SP->guiSP->main_hidden_pixmapID, aux1SP->guiSP->theGCA[lineI], line_screen_x, screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = 5; curr_pixelSP->last_refreshI = aux1SP->refreshI; curr_pixelSP->mol_complexI = aux1SP->mol_complexI; curr_pixelSP->atomI = aux1SP->atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = atomic_z; curr_pixelSP->colorID = aux1SP->colorIDA[lineI]; /* Update the number of pixels drawn: */ pixels_drawnN++; } } /* Check is at least one pixel drawn: */ if (pixels_drawnN > 0) return 1; /* If this point is reached, nothing is drawn: */ return 0; } /*===========================================================================*/ garlic-1.6/bond_style5_quad3.c0000644000076500007650000002004107461726745016616 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2002 Damir Zucic */ /*============================================================================= bond_style4_quad3.c Purpose: Draw bond which fits into quadrant 3 using style 4. See the file file bonds_style4.c for description of quadrants. Input: (1) Pointer to Aux1S structure, which contains required data. (2) Bond index. Output: (1) A single bond drawn. (2) Return value. Return value: (1) One if at least one pixel is drawn. (2) Zero otherwise. =============================================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======draw bond in quadrant 3 using style 5:===============================*/ int BondStyle5Quadrant3_ (Aux1S *aux1SP, int bondI) { long pixels_drawnN = 0; double recip_denom, x_to_y_scale, x_to_z_scale; int screen_x, screen_x1, delta_x, screen_y, line_screen_y; double d, atomic_z; int lineI; size_t pixelI; NearestAtomS *curr_pixelSP; int edge_y, columnI; static int edge_maskAA[9][3] = {{0, 0, 0}, {1, 1, 0}, {1, 1, 1}, {1, 1, 1}, {1, 1, 1}, {1, 1, 1}, {1, 1, 1}, {1, 1, 0}, {0, 0, 0}}; /* Scale factor required to calculate screen_y from screen_x: */ if (aux1SP->screen_delta_x != 0) recip_denom = 1.0 / aux1SP->screen_delta_x; else recip_denom = 0.0; x_to_y_scale = aux1SP->screen_delta_y * recip_denom; /* Scale factor required to calculate z (in atomic units) from screen_x: */ x_to_z_scale = aux1SP->atomic_delta_z * recip_denom; /* Horizontal scan, from right to left: */ screen_x1 = aux1SP->screen_x0 + (aux1SP->screen_delta_x + 1) / 2; for (screen_x = aux1SP->screen_x0; screen_x >= screen_x1; screen_x--) { /* Check is this pixel inside the area reserved for the */ /* current image (there are two images in stereo mode): */ if (screen_x < aux1SP->configSP->image_screen_x0[aux1SP->imageI]) { continue; } if (screen_x > aux1SP->configSP->image_screen_x1[aux1SP->imageI]) { continue; } /* Relative position: */ delta_x = screen_x - aux1SP->screen_x0; /* Find the corresponding screen_y: */ d = aux1SP->screen_y0 + x_to_y_scale * delta_x; screen_y = (int) (d + 0.5); /* z value (in atomic units): */ atomic_z = aux1SP->atomic_z0 + x_to_z_scale * delta_x; /* Loop which draws lines (vertical scan): */ for (lineI = 0; lineI < 9; lineI++) { /* Pixel position: */ line_screen_y = screen_y +lineI - 4; /* Check is this pixel inside the area reserved for the */ /* current image (there are two images in stereo mode): */ if (line_screen_y < aux1SP->configSP->image_screen_y0) { continue; } if (line_screen_y > aux1SP->configSP->image_screen_y1) { continue; } /* Current pixel index: */ pixelI = aux1SP->guiSP->main_win_free_area_width * line_screen_y + screen_x; /* Check pixel index: */ if (pixelI >= aux1SP->pixelsN) break; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = aux1SP->nearest_atomSP + pixelI; /* Check was this pixel used already in */ /* this drawing step; if it was, compare */ /* the z value of the current atom with z */ /* value previously stored to this pixel: */ if (aux1SP->refreshI == curr_pixelSP->last_refreshI) { if (atomic_z >= curr_pixelSP->z) continue; } /* If this point is reached draw pixel: */ XDrawPoint (aux1SP->guiSP->displaySP, aux1SP->guiSP->main_hidden_pixmapID, aux1SP->guiSP->theGCA[lineI], screen_x, line_screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = 5; curr_pixelSP->last_refreshI = aux1SP->refreshI; curr_pixelSP->mol_complexI = aux1SP->mol_complexI; curr_pixelSP->atomI = aux1SP->atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = atomic_z; curr_pixelSP->colorID = aux1SP->colorIDA[lineI]; /* Update the number of pixels drawn: */ pixels_drawnN++; } } /* Rounding the right end: */ edge_y = aux1SP->screen_y0; atomic_z = aux1SP->atomic_z0; for (columnI = 0; columnI < 3; columnI++) { /* Prepare and check screen_x: */ screen_x = aux1SP->screen_x0 + columnI + 1; if (screen_x < aux1SP->configSP->image_screen_x0[aux1SP->imageI]) continue; if (screen_x > aux1SP->configSP->image_screen_x1[aux1SP->imageI]) continue; /* Vertical scan: */ for (lineI = 0; lineI < 9; lineI++) { /* Pixel y coordinate: */ line_screen_y = edge_y + lineI - 4; /* Check line_screen_y: */ if (line_screen_y < aux1SP->configSP->image_screen_y0) continue; if (line_screen_y > aux1SP->configSP->image_screen_y1) continue; /* Check the mask: */ if (!edge_maskAA[lineI][columnI]) continue; /* Current pixel index: */ pixelI = aux1SP->guiSP->main_win_free_area_width * line_screen_y + screen_x; /* Check pixel index: */ if (pixelI >= aux1SP->pixelsN) break; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = aux1SP->nearest_atomSP + pixelI; /* Check was this pixel used already in this drawing step : */ if (aux1SP->refreshI == curr_pixelSP->last_refreshI) { if (atomic_z >= curr_pixelSP->z) continue; } /* If this point is reached draw one pixel: */ XDrawPoint (aux1SP->guiSP->displaySP, aux1SP->guiSP->main_hidden_pixmapID, aux1SP->guiSP->theGCA[lineI], screen_x, line_screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = 5; curr_pixelSP->last_refreshI = aux1SP->refreshI; curr_pixelSP->mol_complexI = aux1SP->mol_complexI; curr_pixelSP->atomI = aux1SP->atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = atomic_z; curr_pixelSP->colorID = aux1SP->colorIDA[lineI]; /* Update the number of pixels drawn: */ pixels_drawnN++; } } /* Rounding the left end: */ delta_x = screen_x1 - aux1SP->screen_x0; d = (double) aux1SP->screen_y0 + x_to_y_scale * (double) delta_x; edge_y = (int) (d + 0.5); atomic_z = aux1SP->atomic_z0 + x_to_z_scale * (double) delta_x; for (columnI = 0; columnI < 3; columnI++) { /* Prepare and check screen_x: */ screen_x = screen_x1 - columnI - 1; if (screen_x < aux1SP->configSP->image_screen_x0[aux1SP->imageI]) continue; if (screen_x > aux1SP->configSP->image_screen_x1[aux1SP->imageI]) continue; /* Vertical scan: */ for (lineI = 0; lineI < 9; lineI++) { /* Pixel y coordinate: */ line_screen_y = edge_y + lineI - 4; /* Check line_screen_y: */ if (line_screen_y < aux1SP->configSP->image_screen_y0) continue; if (line_screen_y > aux1SP->configSP->image_screen_y1) continue; /* Check the mask: */ if (!edge_maskAA[lineI][columnI]) continue; /* Current pixel index: */ pixelI = aux1SP->guiSP->main_win_free_area_width * line_screen_y + screen_x; /* Check pixel index: */ if (pixelI >= aux1SP->pixelsN) break; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = aux1SP->nearest_atomSP + pixelI; /* Check was this pixel used already in this drawing step : */ if (aux1SP->refreshI == curr_pixelSP->last_refreshI) { if (atomic_z >= curr_pixelSP->z) continue; } /* If this point is reached draw one pixel: */ XDrawPoint (aux1SP->guiSP->displaySP, aux1SP->guiSP->main_hidden_pixmapID, aux1SP->guiSP->theGCA[lineI], screen_x, line_screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = 5; curr_pixelSP->last_refreshI = aux1SP->refreshI; curr_pixelSP->mol_complexI = aux1SP->mol_complexI; curr_pixelSP->atomI = aux1SP->atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = atomic_z; curr_pixelSP->colorID = aux1SP->colorIDA[lineI]; /* Update the number of pixels drawn: */ pixels_drawnN++; } } /* Check is at least one pixel drawn: */ if (pixels_drawnN > 0) return 1; /* If this point is reached, nothing is drawn: */ return 0; } /*===========================================================================*/ garlic-1.6/bond_style5_quad4.c0000644000076500007650000002005307461726754016622 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2002 Damir Zucic */ /*============================================================================= bond_style5_quad4.c Purpose: Draw bond which fits into quadrant 4 using style 5. See the file file bonds_style5.c for description of quadrants. Input: (1) Pointer to Aux1S structure, which contains required data. (2) Bond index. Output: (1) A single bond drawn. (2) Return value. Return value: (1) One if at least one pixel is drawn. (2) Zero otherwise. =============================================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======draw bond in quadrant 4 using style 5:===============================*/ int BondStyle5Quadrant4_ (Aux1S *aux1SP, int bondI) { long pixels_drawnN = 0; double recip_denom, y_to_x_scale, y_to_z_scale; int screen_x, line_screen_x, screen_y, screen_y1, delta_y; double d, atomic_z; int lineI; size_t pixelI; NearestAtomS *curr_pixelSP; int edge_x, rowI; static int edge_maskAA[9][3] = {{0, 0, 0}, {1, 1, 0}, {1, 1, 1}, {1, 1, 1}, {1, 1, 1}, {1, 1, 1}, {1, 1, 1}, {1, 1, 0}, {0, 0, 0}}; /* Scale factor required to calculate screen_x from screen_y: */ if (aux1SP->screen_delta_y != 0) recip_denom = 1.0 / aux1SP->screen_delta_y; else recip_denom = 0.0; y_to_x_scale = aux1SP->screen_delta_x * recip_denom; /* Scale factor required to calculate z (in atomic units) from screen_y: */ y_to_z_scale = aux1SP->atomic_delta_z * recip_denom; /* Vertical scan (bottom to top): */ screen_y1 = aux1SP->screen_y0 + (aux1SP->screen_delta_y + 1) / 2; for (screen_y = aux1SP->screen_y0; screen_y >= screen_y1; screen_y--) { /* Check is this pixel inside the area reserved for the */ /* current image (there are two images in stereo mode): */ if (screen_y < aux1SP->configSP->image_screen_y0) continue; if (screen_y > aux1SP->configSP->image_screen_y1) continue; /* Relative position: */ delta_y = screen_y - aux1SP->screen_y0; /* Find the corresponding screen_x: */ d = aux1SP->screen_x0 + y_to_x_scale * delta_y; screen_x = (int) (d + 0.5); /* z value (in atomic units): */ atomic_z = aux1SP->atomic_z0 + y_to_z_scale * delta_y; /* Loop which draws lines (horizontal scan): */ for (lineI = 0; lineI < 9; lineI++) { /* Pixel position: */ line_screen_x = screen_x +lineI - 4; /* Check is this pixel inside the area reserved for the */ /* current image (there are two images in stereo mode): */ if (line_screen_x < aux1SP->configSP->image_screen_x0[aux1SP->imageI]) { continue; } if (line_screen_x > aux1SP->configSP->image_screen_x1[aux1SP->imageI]) { continue; } /* Current pixel index: */ pixelI = aux1SP->guiSP->main_win_free_area_width * screen_y + line_screen_x; /* Check pixel index: */ if (pixelI >= aux1SP->pixelsN) break; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = aux1SP->nearest_atomSP + pixelI; /* Check was this pixel used already in */ /* this drawing step; if it was, compare */ /* the z value of the current atom with z */ /* value previously stored to this pixel: */ if (aux1SP->refreshI == curr_pixelSP->last_refreshI) { if (atomic_z >= curr_pixelSP->z) continue; } /* If this point is reached draw pixel: */ XDrawPoint (aux1SP->guiSP->displaySP, aux1SP->guiSP->main_hidden_pixmapID, aux1SP->guiSP->theGCA[lineI], line_screen_x, screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = 5; curr_pixelSP->last_refreshI = aux1SP->refreshI; curr_pixelSP->mol_complexI = aux1SP->mol_complexI; curr_pixelSP->atomI = aux1SP->atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = atomic_z; curr_pixelSP->colorID = aux1SP->colorIDA[lineI]; /* Update the number of pixels drawn: */ pixels_drawnN++; } } /* Rounding the bottom end: */ edge_x = aux1SP->screen_x0; atomic_z = aux1SP->atomic_z0; for (rowI = 0; rowI < 3; rowI++) { /* Prepare and check screen_y: */ screen_y = aux1SP->screen_y0 + rowI + 1; if (screen_y < aux1SP->configSP->image_screen_y0) continue; if (screen_y > aux1SP->configSP->image_screen_y1) continue; /* Vertical scan: */ for (lineI = 0; lineI < 9; lineI++) { /* Pixel x coordinate: */ line_screen_x = edge_x + lineI - 4; /* Check line_screen_x: */ if (line_screen_x < aux1SP->configSP->image_screen_x0[aux1SP->imageI]) { continue; } if (line_screen_x > aux1SP->configSP->image_screen_x1[aux1SP->imageI]) { continue; } /* Check the mask: */ if (!edge_maskAA[lineI][rowI]) continue; /* Current pixel index: */ pixelI = aux1SP->guiSP->main_win_free_area_width * screen_y + line_screen_x; /* Check pixel index: */ if (pixelI >= aux1SP->pixelsN) break; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = aux1SP->nearest_atomSP + pixelI; /* Check was this pixel used already in this drawing step : */ if (aux1SP->refreshI == curr_pixelSP->last_refreshI) { if (atomic_z >= curr_pixelSP->z) continue; } /* If this point is reached draw one pixel: */ XDrawPoint (aux1SP->guiSP->displaySP, aux1SP->guiSP->main_hidden_pixmapID, aux1SP->guiSP->theGCA[lineI], line_screen_x, screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = 5; curr_pixelSP->last_refreshI = aux1SP->refreshI; curr_pixelSP->mol_complexI = aux1SP->mol_complexI; curr_pixelSP->atomI = aux1SP->atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = atomic_z; curr_pixelSP->colorID = aux1SP->colorIDA[lineI]; /* Update the number of pixels drawn: */ pixels_drawnN++; } } /* Rounding the top end: */ delta_y = screen_y1 - aux1SP->screen_y0; d = (double) aux1SP->screen_x0 + y_to_x_scale * (double) delta_y; edge_x = (int) (d + 0.5); atomic_z = aux1SP->atomic_z0 + y_to_z_scale * (double) delta_y; for (rowI = 0; rowI < 3; rowI++) { /* Prepare and check screen_y: */ screen_y = screen_y1 - rowI - 1; if (screen_y < aux1SP->configSP->image_screen_y0) continue; if (screen_y > aux1SP->configSP->image_screen_y1) continue; /* Vertical scan: */ for (lineI = 0; lineI < 9; lineI++) { /* Pixel x coordinate: */ line_screen_x = edge_x + lineI - 4; /* Check line_screen_x: */ if (line_screen_x < aux1SP->configSP->image_screen_x0[aux1SP->imageI]) { continue; } if (line_screen_x > aux1SP->configSP->image_screen_x1[aux1SP->imageI]) { continue; } /* Check the mask: */ if (!edge_maskAA[lineI][rowI]) continue; /* Current pixel index: */ pixelI = aux1SP->guiSP->main_win_free_area_width * screen_y + line_screen_x; /* Check pixel index: */ if (pixelI >= aux1SP->pixelsN) break; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = aux1SP->nearest_atomSP + pixelI; /* Check was this pixel used already in this drawing step : */ if (aux1SP->refreshI == curr_pixelSP->last_refreshI) { if (atomic_z >= curr_pixelSP->z) continue; } /* If this point is reached draw one pixel: */ XDrawPoint (aux1SP->guiSP->displaySP, aux1SP->guiSP->main_hidden_pixmapID, aux1SP->guiSP->theGCA[lineI], line_screen_x, screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = 5; curr_pixelSP->last_refreshI = aux1SP->refreshI; curr_pixelSP->mol_complexI = aux1SP->mol_complexI; curr_pixelSP->atomI = aux1SP->atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = atomic_z; curr_pixelSP->colorID = aux1SP->colorIDA[lineI]; /* Update the number of pixels drawn: */ pixels_drawnN++; } } /* Check is at least one pixel drawn: */ if (pixels_drawnN > 0) return 1; /* If this point is reached, nothing is drawn: */ return 0; } /*===========================================================================*/ garlic-1.6/water.pdb0000644000076500007650000000043407744714673014744 0ustar zuciczucic00000000000000HEADER WATER MOLECULE COMPND WATER HETATM 1 O 0 -0.001 -0.386 -0.039 1.00 0.00 HETATM 2 H 0 0.741 0.194 -0.007 1.00 0.00 HETATM 3 H 0 -0.740 0.192 0.046 1.00 0.00 garlic-1.6/bonds_style1.c0000644000076500007650000001741607461727032015702 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2002 Damir Zucic */ /*============================================================================= bonds_style1.c Purpose: Draw bonds, using style 1 (a single line per bond). Half of each bond is drawn and another half is assigned to the partner. Middle color is used. The z value is calculated for each pixel. A bond is visible only if both atoms forming this bond are visible. Input: (1) Pointer to MolComplexS structure. (2) Number of macromolecular complexes. (3) Pointer to ConfigS structure, with configuration data. (4) Pointer to GUIS structure. (5) Pointer to NearestAtomS structure, with information about the atom occupying the given pixel. (6) The number of pixels in the main window free area. (7) The refreshI, used to check the NearestAtomS associated with a given pixel. Output: (1) Atoms drawn to the hidden pixmap. (2) Return value. Return value: (1) The number of bonds drawn. Notes: (1) Indentation is exceptionally 4 spaces. (2) Deep indentation is allowed in this function. This is not my favorite coding style but it may help to improve performance. (3) The vector from the current atom to the bond partner belongs to one of five regions. If atomic positions are exactly the same, the vector belongs to the region "zero". Otherwise, it belongs to one of four quadrants. Quadrants are arranged as shown here: *** 4 *** o-----> *** *** | X *** *** | 3 *** 1 V *** *** Y *** *** *** 2 *** (4) Nothing is drawn for bonds perpendicular to the screen. =============================================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int BondStyle1Quadrant1_ (Aux1S *, int); int BondStyle1Quadrant2_ (Aux1S *, int); int BondStyle1Quadrant3_ (Aux1S *, int); int BondStyle1Quadrant4_ (Aux1S *, int); /*======draw bonds using style 1 (a single line):============================*/ size_t DrawBondsStyle1_ (MolComplexS *mol_complexSP, int mol_complexesN, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int refreshI) { size_t bonds_drawnN = 0; int imageI, imagesN; Aux1S aux1S; int mol_complexI; MolComplexS *curr_mol_complexSP, *partner_mol_complexSP; size_t atomsN, atomI; AtomS *curr_atomSP, *partner_atomSP; int bondsN, bondI; TrueBondS *curr_bondSP; int screen_abs_delta_x, screen_abs_delta_y; int regionI; double z_shift, delta_z_sign; int hybonds_hiddenF; /* Number of images: */ if (configSP->stereoF) imagesN = 2; else imagesN = 1; /* Prepare the auxiliary Aux1S structure, used to */ /* reduce the number of arguments in function calls: */ aux1S.configSP = configSP; aux1S.guiSP = guiSP; aux1S.nearest_atomSP = nearest_atomSP; aux1S.pixelsN = pixelsN; aux1S.refreshI = refreshI; /* Draw each macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Prepare and check the number of atoms: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Copy the macromol. complex index into aux1S: */ aux1S.mol_complexI = mol_complexI; /* Copy the flag which says are hydrogen bonds hidden or not: */ hybonds_hiddenF = curr_mol_complexSP->hydrogen_bonds_hiddenF; /* Draw bonds which have the given style: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Check is atom hidden: */ if (curr_atomSP->hiddenF) continue; /* Check is atom inside slab: */ if (!curr_atomSP->inside_slabF) continue; /* Check is atom inside window: */ if (!curr_atomSP->inside_windowF) continue; /* Prepare the color: */ XSetForeground (guiSP->displaySP, guiSP->theGCA[0], curr_atomSP->left_colorID); /* Copy the color value into Aux1S: */ aux1S.colorIDA[0] = curr_atomSP->left_colorID; /* Copy the atomic index into aux1S: */ aux1S.atomI = atomI; /* Number of bonds: */ bondsN = curr_atomSP->bondsN; /* Bond loop: */ for (bondI = 0; bondI < bondsN; bondI++) { /* Pointer to the structure with data about current bond: */ curr_bondSP = curr_atomSP->true_bondSA + bondI; /* Check bond drawing style: */ if (curr_bondSP->bond_styleI != 1) continue; /* If the current bond is hydrogen bond, it may be hidden: */ if (curr_bondSP->bond_typeI == 0) { if (hybonds_hiddenF) continue; } /* The complex which contains the atom forming the bond: */ partner_mol_complexSP = mol_complexSP + curr_bondSP->neighbor_mol_complexI; /* Pointer to the bond partner: */ partner_atomSP = partner_mol_complexSP->atomSP + curr_bondSP->neighbor_arrayI; /* If partner is not visible, do not draw this bond: */ if (partner_atomSP->hiddenF) continue; /* Draw one (mono) or two bonds (stereo): */ for (imageI = 0; imageI < imagesN; imageI++) { /* Copy imageI to aux1S: */ aux1S.imageI = imageI; /* Prepare screen coordinates of */ /* both atoms involved in bond: */ aux1S.screen_x0 = curr_atomSP->raw_atomS.screen_x[imageI]; aux1S.screen_y0 = curr_atomSP->raw_atomS.screen_y; aux1S.screen_x1 = partner_atomSP->raw_atomS.screen_x[imageI]; aux1S.screen_y1 = partner_atomSP->raw_atomS.screen_y; aux1S.atomic_z0 = curr_atomSP->raw_atomS.z[imageI]; aux1S.atomic_z1 = partner_atomSP->raw_atomS.z[imageI]; /* Prepare differences: */ aux1S.screen_delta_x = aux1S.screen_x1 - aux1S.screen_x0; aux1S.screen_delta_y = aux1S.screen_y1 - aux1S.screen_y0; aux1S.atomic_delta_z = aux1S.atomic_z1 - aux1S.atomic_z0; /* Tilt the bond to ensure the proper stacking of bonds: */ delta_z_sign = 1.0; if (aux1S.atomic_delta_z < 0) delta_z_sign = -1.0; z_shift = delta_z_sign * Z_SHIFT; aux1S.atomic_z0 += z_shift; aux1S.atomic_z1 -= z_shift; aux1S.atomic_delta_z -= 3 * z_shift; /* Some absolute differences: */ screen_abs_delta_x = abs (aux1S.screen_delta_x); screen_abs_delta_y = abs (aux1S.screen_delta_y); /* Find the region: */ if (screen_abs_delta_x >= screen_abs_delta_y) { if (aux1S.screen_delta_x >= 0) regionI = 1; else regionI = 3; } else { if (aux1S.screen_delta_y >= 0) regionI = 2; else regionI = 4; } if ((aux1S.screen_delta_x == 0) && (aux1S.screen_delta_y == 0)) { regionI = 0; } /* Each region has its own drawing procedure: */ switch (regionI) { /* Both atoms are projected to the same point, */ /* i.e. this bond is perpendicular to the screen: */ case 0: /* Do nothing! */ break; /* Right quadrant: */ case 1: BondStyle1Quadrant1_ (&aux1S, bondI); break; /* Bottom quadrant (check Note 3!): */ case 2: BondStyle1Quadrant2_ (&aux1S, bondI); break; /* Left quadrant: */ case 3: BondStyle1Quadrant3_ (&aux1S, bondI); break; /* Top quadrant (check Note 3!): */ case 4: BondStyle1Quadrant4_ (&aux1S, bondI); break; /* This should be the impossible case: */ default: ; } /* Update the counter: */ bonds_drawnN++; } /* imageI loop */ } /* bondI loop */ } /* atomI loop */ } /* mol_complexI loop */ /* Return the number of bonds which were drawn: */ return bonds_drawnN; } /*===========================================================================*/ garlic-1.6/bonds_style2.c0000644000076500007650000002044307461727051015676 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2002 Damir Zucic */ /*============================================================================= bonds_style2.c Purpose: Draw bonds, using style 2 (three lines per bond). Half of each bond is drawn and another half is assigned to the partner. The z value is calculated for each pixel. A bond is visible only if both atoms forming this bond are visible. Input: (1) Pointer to MolComplexS structure. (2) Number of macromolecular complexes. (3) Pointer to ConfigS structure, with configuration data. (4) Pointer to GUIS structure. (5) Pointer to NearestAtomS structure, with information about the atom occupying the given pixel. (6) The number of pixels in the main window free area. (7) The refreshI, used to check the NearestAtomS associated with a given pixel. Output: (1) Atoms drawn to the hidden pixmap. (2) Return value. Return value: (1) The number of bonds drawn. Notes: (1) Indentation is exceptionally 4 spaces. (2) Deep indentation is allowed in this function. This is not my favorite coding style but it may help to improve performance. (3) The vector from the current atom to the bond partner belongs to one of five regions. If atomic positions are exactly the same, the vector belongs to the region "zero". Otherwise, it belongs to one of four quadrants. Quadrants are arranged as shown here: *** 4 *** o-----> *** *** | X *** *** | 3 *** 1 V *** *** Y *** *** *** 2 *** (4) Nothing is drawn for bonds perpendicular to the screen. (5) This function is very similar to DrawBondsStyle1_ (). Please don't ask me why I have not combined these two functions in a single function. The current approach results in somewhat larger executable but bond drawing functions remain fairly simple. =============================================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int BondStyle2Quadrant1_ (Aux1S *, int); int BondStyle2Quadrant2_ (Aux1S *, int); int BondStyle2Quadrant3_ (Aux1S *, int); int BondStyle2Quadrant4_ (Aux1S *, int); /*======draw bonds using style 2 (three lines per bond):=====================*/ size_t DrawBondsStyle2_ (MolComplexS *mol_complexSP, int mol_complexesN, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int refreshI) { size_t bonds_drawnN = 0; int imageI, imagesN; Aux1S aux1S; int mol_complexI; MolComplexS *curr_mol_complexSP, *partner_mol_complexSP; size_t atomsN, atomI; AtomS *curr_atomSP, *partner_atomSP; int bondsN, bondI; TrueBondS *curr_bondSP; int screen_abs_delta_x, screen_abs_delta_y; int regionI; double z_shift, delta_z_sign; int hybonds_hiddenF; /* Number of images: */ if (configSP->stereoF) imagesN = 2; else imagesN = 1; /* Prepare the auxiliary Aux1S structure, used to */ /* reduce the number of arguments in function calls: */ aux1S.configSP = configSP; aux1S.guiSP = guiSP; aux1S.nearest_atomSP = nearest_atomSP; aux1S.pixelsN = pixelsN; aux1S.refreshI = refreshI; /* Draw each macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Prepare and check the number of atoms: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Copy the macromol. complex index into aux1S: */ aux1S.mol_complexI = mol_complexI; /* Copy the flag which says are hydrogen bonds hidden or not: */ hybonds_hiddenF = curr_mol_complexSP->hydrogen_bonds_hiddenF; /* Draw bonds which have the given style: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Check is atom hidden: */ if (curr_atomSP->hiddenF) continue; /* Check is atom inside slab: */ if (!curr_atomSP->inside_slabF) continue; /* Check is atom inside window: */ if (!curr_atomSP->inside_windowF) continue; /* Prepare colors: */ XSetForeground (guiSP->displaySP, guiSP->theGCA[0], curr_atomSP->left_colorID); XSetForeground (guiSP->displaySP, guiSP->theGCA[1], curr_atomSP->middle_colorID); XSetForeground (guiSP->displaySP, guiSP->theGCA[2], curr_atomSP->right_colorID); /* Copy colors to aux1S: */ aux1S.colorIDA[0] = curr_atomSP->left_colorID; aux1S.colorIDA[1] = curr_atomSP->middle_colorID; aux1S.colorIDA[2] = curr_atomSP->right_colorID; /* Copy the atomic index into aux1S: */ aux1S.atomI = atomI; /* Number of bonds: */ bondsN = curr_atomSP->bondsN; /* Bond loop: */ for (bondI = 0; bondI < bondsN; bondI++) { /* Pointer to the structure with data about current bond: */ curr_bondSP = curr_atomSP->true_bondSA + bondI; /* Check bond drawing style: */ if (curr_bondSP->bond_styleI != 2) continue; /* If the current bond is hydrogen bond, it may be hidden: */ if (curr_bondSP->bond_typeI == 0) { if (hybonds_hiddenF) continue; } /* The complex which contains the atom forming the bond: */ partner_mol_complexSP = mol_complexSP + curr_bondSP->neighbor_mol_complexI; /* Pointer to the bond partner: */ partner_atomSP = partner_mol_complexSP->atomSP + curr_bondSP->neighbor_arrayI; /* If partner is not visible, do not draw this bond: */ if (partner_atomSP->hiddenF) continue; /* Draw one (mono) or two bonds (stereo): */ for (imageI = 0; imageI < imagesN; imageI++) { /* Copy imageI to aux1S: */ aux1S.imageI = imageI; /* Prepare screen coordinates of */ /* both atoms involved in bond: */ aux1S.screen_x0 = curr_atomSP->raw_atomS.screen_x[imageI]; aux1S.screen_y0 = curr_atomSP->raw_atomS.screen_y; aux1S.screen_x1 = partner_atomSP->raw_atomS.screen_x[imageI]; aux1S.screen_y1 = partner_atomSP->raw_atomS.screen_y; aux1S.atomic_z0 = curr_atomSP->raw_atomS.z[imageI]; aux1S.atomic_z1 = partner_atomSP->raw_atomS.z[imageI]; /* Prepare differences: */ aux1S.screen_delta_x = aux1S.screen_x1 - aux1S.screen_x0; aux1S.screen_delta_y = aux1S.screen_y1 - aux1S.screen_y0; aux1S.atomic_delta_z = aux1S.atomic_z1 - aux1S.atomic_z0; /* Tilt the bond to ensure the proper stacking of bonds: */ delta_z_sign = 1.0; if (aux1S.atomic_delta_z < 0) delta_z_sign = -1.0; z_shift = delta_z_sign * Z_SHIFT; aux1S.atomic_z0 += z_shift; aux1S.atomic_z1 -= z_shift; aux1S.atomic_delta_z -= 3 * z_shift; /* Some absolute differences: */ screen_abs_delta_x = abs (aux1S.screen_delta_x); screen_abs_delta_y = abs (aux1S.screen_delta_y); /* Find the region: */ if (screen_abs_delta_x >= screen_abs_delta_y) { if (aux1S.screen_delta_x >= 0) regionI = 1; else regionI = 3; } else { if (aux1S.screen_delta_y >= 0) regionI = 2; else regionI = 4; } if ((aux1S.screen_delta_x == 0) && (aux1S.screen_delta_y == 0)) { regionI = 0; } /* Each region has its own drawing procedure: */ switch (regionI) { /* Both atoms are projected to the same point, */ /* i.e. this bond is perpendicular to the screen: */ case 0: /* Do nothing! */ break; /* Right quadrant: */ case 1: BondStyle2Quadrant1_ (&aux1S, bondI); break; /* Bottom quadrant (check Note 3!): */ case 2: BondStyle2Quadrant2_ (&aux1S, bondI); break; /* Left quadrant: */ case 3: BondStyle2Quadrant3_ (&aux1S, bondI); break; /* Top quadrant (check Note 3!): */ case 4: BondStyle2Quadrant4_ (&aux1S, bondI); break; /* This should be the impossible case: */ default: ; } /* Update the counter: */ bonds_drawnN++; } /* imageI loop */ } /* bondI loop */ } /* atomI loop */ } /* mol_complexI loop */ /* Return the number of bonds which were drawn: */ return bonds_drawnN; } /*===========================================================================*/ garlic-1.6/bonds_style3.c0000644000076500007650000002115007461727070015674 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2002 Damir Zucic */ /*============================================================================= bonds_style3.c Purpose: Draw bonds using style 3 (five lines per bond). Half of each bond is drawn and another half is assigned to the partner. The z value is calculated for each pixel. A bond is visible only if both atoms forming this bond are visible. Input: (1) Pointer to MolComplexS structure. (2) Number of macromolecular complexes. (3) Pointer to ConfigS structure, with configuration data. (4) Pointer to GUIS structure. (5) Pointer to NearestAtomS structure, with information about the atom occupying the given pixel. (6) The number of pixels in the main window free area. (7) The refreshI, used to check the NearestAtomS associated with a given pixel. Output: (1) Atoms drawn to the hidden pixmap. (2) Return value. Return value: (1) The number of bonds drawn. Notes: (1) Indentation is exceptionally 4 spaces. (2) Deep indentation is allowed in this function. This is not my favorite coding style but it may help to improve performance. (3) The vector from the current atom to the bond partner belongs to one of five regions. If atomic positions are exactly the same, the vector belongs to the region "zero". Otherwise, it belongs to one of four quadrants. Quadrants are arranged as shown here: *** 4 *** o-----> *** *** | X *** *** | 3 *** 1 V *** *** Y *** *** *** 2 *** (4) Nothing is drawn for bonds perpendicular to the screen. (5) Two additional colors are prepared. =============================================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ unsigned long InterpolateColor_ (unsigned long, unsigned long, GUIS *); int BondStyle3Quadrant1_ (Aux1S *, int); int BondStyle3Quadrant2_ (Aux1S *, int); int BondStyle3Quadrant3_ (Aux1S *, int); int BondStyle3Quadrant4_ (Aux1S *, int); /*======draw bonds using style 3 (five lines per bond):======================*/ size_t DrawBondsStyle3_ (MolComplexS *mol_complexSP, int mol_complexesN, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int refreshI) { size_t bonds_drawnN = 0; int imageI, imagesN; Aux1S aux1S; int mol_complexI; MolComplexS *curr_mol_complexSP, *partner_mol_complexSP; size_t atomsN, atomI; unsigned int color1ID, color2ID; AtomS *curr_atomSP, *partner_atomSP; int bondsN, bondI; TrueBondS *curr_bondSP; int screen_abs_delta_x, screen_abs_delta_y; int regionI; double z_shift, delta_z_sign; int hybonds_hiddenF; /* Number of images: */ if (configSP->stereoF) imagesN = 2; else imagesN = 1; /* Prepare the auxiliary Aux1S structure, used to */ /* reduce the number of arguments in function calls: */ aux1S.configSP = configSP; aux1S.guiSP = guiSP; aux1S.nearest_atomSP = nearest_atomSP; aux1S.pixelsN = pixelsN; aux1S.refreshI = refreshI; /* Draw each macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Prepare and check the number of atoms: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Copy the macromol. complex index into aux1S: */ aux1S.mol_complexI = mol_complexI; /* Copy the flag which says are hydrogen bonds hidden or not: */ hybonds_hiddenF = curr_mol_complexSP->hydrogen_bonds_hiddenF; /* Draw bonds which have the given style: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Check is atom hidden: */ if (curr_atomSP->hiddenF) continue; /* Check is atom inside slab: */ if (!curr_atomSP->inside_slabF) continue; /* Check is atom inside window: */ if (!curr_atomSP->inside_windowF) continue; /* Prepare two additional colors: */ color1ID = InterpolateColor_ (curr_atomSP->left_colorID, curr_atomSP->middle_colorID, guiSP); color2ID = InterpolateColor_ (curr_atomSP->middle_colorID, curr_atomSP->right_colorID, guiSP); /* Prepare GC's: */ XSetForeground (guiSP->displaySP, guiSP->theGCA[0], curr_atomSP->left_colorID); XSetForeground (guiSP->displaySP, guiSP->theGCA[1], color1ID); XSetForeground (guiSP->displaySP, guiSP->theGCA[2], curr_atomSP->middle_colorID); XSetForeground (guiSP->displaySP, guiSP->theGCA[3], color2ID); XSetForeground (guiSP->displaySP, guiSP->theGCA[4], curr_atomSP->right_colorID); /* Copy color values to aux1S: */ aux1S.colorIDA[0] = curr_atomSP->left_colorID; aux1S.colorIDA[1] = color1ID; aux1S.colorIDA[2] = curr_atomSP->middle_colorID; aux1S.colorIDA[3] = color2ID; aux1S.colorIDA[4] = curr_atomSP->right_colorID; /* Copy the atomic index into aux1S: */ aux1S.atomI = atomI; /* Number of bonds: */ bondsN = curr_atomSP->bondsN; /* Bond loop: */ for (bondI = 0; bondI < bondsN; bondI++) { /* Pointer to the structure with data about current bond: */ curr_bondSP = curr_atomSP->true_bondSA + bondI; /* Check bond drawing style: */ if (curr_bondSP->bond_styleI != 3) continue; /* If the current bond is hydrogen bond, it may be hidden: */ if (curr_bondSP->bond_typeI == 0) { if (hybonds_hiddenF) continue; } /* The complex which contains the atom forming the bond: */ partner_mol_complexSP = mol_complexSP + curr_bondSP->neighbor_mol_complexI; /* Pointer to the bond partner: */ partner_atomSP = partner_mol_complexSP->atomSP + curr_bondSP->neighbor_arrayI; /* If partner is not visible, do not draw this bond: */ if (partner_atomSP->hiddenF) continue; /* Draw one (mono) or two bonds (stereo): */ for (imageI = 0; imageI < imagesN; imageI++) { /* Copy imageI to aux1S: */ aux1S.imageI = imageI; /* Prepare screen coordinates of */ /* both atoms involved in bond: */ aux1S.screen_x0 = curr_atomSP->raw_atomS.screen_x[imageI]; aux1S.screen_y0 = curr_atomSP->raw_atomS.screen_y; aux1S.screen_x1 = partner_atomSP->raw_atomS.screen_x[imageI]; aux1S.screen_y1 = partner_atomSP->raw_atomS.screen_y; aux1S.atomic_z0 = curr_atomSP->raw_atomS.z[imageI]; aux1S.atomic_z1 = partner_atomSP->raw_atomS.z[imageI]; /* Prepare differences: */ aux1S.screen_delta_x = aux1S.screen_x1 - aux1S.screen_x0; aux1S.screen_delta_y = aux1S.screen_y1 - aux1S.screen_y0; aux1S.atomic_delta_z = aux1S.atomic_z1 - aux1S.atomic_z0; /* Shift and tilt bond to ensure */ /* the proper stacking of bonds: */ delta_z_sign = 1.0; if (aux1S.atomic_delta_z < 0) delta_z_sign = -1.0; z_shift = delta_z_sign * Z_SHIFT; aux1S.atomic_z0 += z_shift; aux1S.atomic_z1 -= z_shift; aux1S.atomic_delta_z -= 3 * z_shift; /* Some absolute differences: */ screen_abs_delta_x = abs (aux1S.screen_delta_x); screen_abs_delta_y = abs (aux1S.screen_delta_y); /* Find the region: */ if (screen_abs_delta_x >= screen_abs_delta_y) { if (aux1S.screen_delta_x >= 0) regionI = 1; else regionI = 3; } else { if (aux1S.screen_delta_y >= 0) regionI = 2; else regionI = 4; } if ((aux1S.screen_delta_x == 0) && (aux1S.screen_delta_y == 0)) { regionI = 0; } /* Each region has its own drawing procedure: */ switch (regionI) { /* Both atoms are projected to the same point, */ /* i.e. this bond is perpendicular to the screen: */ case 0: /* Do nothing! */ break; /* Right quadrant: */ case 1: BondStyle3Quadrant1_ (&aux1S, bondI); break; /* Bottom quadrant (check Note 3!): */ case 2: BondStyle3Quadrant2_ (&aux1S, bondI); break; /* Left quadrant: */ case 3: BondStyle3Quadrant3_ (&aux1S, bondI); break; /* Top quadrant (check Note 3!): */ case 4: BondStyle3Quadrant4_ (&aux1S, bondI); break; /* This should be the impossible case: */ default: ; } /* Update the counter: */ bonds_drawnN++; } /* imageI loop */ } /* bondI loop */ } /* atomI loop */ } /* mol_complexI loop */ /* Return the number of bonds which were drawn: */ return bonds_drawnN; } /*===========================================================================*/ garlic-1.6/bonds_style4.c0000644000076500007650000002163507461727103015702 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2002 Damir Zucic */ /*============================================================================= bonds_style4.c Purpose: Draw bonds using style 4 (seven lines per bond). Half of each bond is drawn and another half is assigned to the partner. The z value is calculated for each pixel. A bond is visible only if both atoms forming this bond are visible. Input: (1) Pointer to MolComplexS structure. (2) Number of macromolecular complexes. (3) Pointer to ConfigS structure, with configuration data. (4) Pointer to GUIS structure. (5) Pointer to NearestAtomS structure, with information about the atom occupying the given pixel. (6) The number of pixels in the main window free area. (7) The refreshI, used to check the NearestAtomS associated with a given pixel. Output: (1) Atoms drawn to the hidden pixmap. (2) Return value. Return value: (1) The number of bonds drawn. Notes: (1) Indentation is exceptionally 4 spaces. (2) Deep indentation is allowed in this function. This is not my favorite coding style but it may help to improve performance. (3) The vector from the current atom to the bond partner belongs to one of five regions. If atomic positions are exactly the same, the vector belongs to the region "zero". Otherwise, it belongs to one of four quadrants. Quadrants are arranged as shown here: *** 4 *** o-----> *** *** | X *** *** | 3 *** 1 V *** *** Y *** *** *** 2 *** (4) Nothing is drawn for bonds perpendicular to the screen. (5) Two additional colors are prepared. =============================================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ void AddTwoColors_ (unsigned long, unsigned long, GUIS *, unsigned long *, unsigned long *); int BondStyle4Quadrant1_ (Aux1S *, int); int BondStyle4Quadrant2_ (Aux1S *, int); int BondStyle4Quadrant3_ (Aux1S *, int); int BondStyle4Quadrant4_ (Aux1S *, int); /*======draw bonds using style 4 (seven lines per bond):=====================*/ size_t DrawBondsStyle4_ (MolComplexS *mol_complexSP, int mol_complexesN, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int refreshI) { size_t bonds_drawnN = 0; int imageI, imagesN; Aux1S aux1S; int mol_complexI; MolComplexS *curr_mol_complexSP, *partner_mol_complexSP; size_t atomsN, atomI; unsigned long color1ID, color2ID, color3ID, color4ID; AtomS *curr_atomSP, *partner_atomSP; int bondsN, bondI; TrueBondS *curr_bondSP; int screen_abs_delta_x, screen_abs_delta_y; int regionI; double z_shift, delta_z_sign; int hybonds_hiddenF; /* Number of images: */ if (configSP->stereoF) imagesN = 2; else imagesN = 1; /* Prepare the auxiliary Aux1S structure, used to */ /* reduce the number of arguments in function calls: */ aux1S.configSP = configSP; aux1S.guiSP = guiSP; aux1S.nearest_atomSP = nearest_atomSP; aux1S.pixelsN = pixelsN; aux1S.refreshI = refreshI; /* Draw each macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Prepare and check the number of atoms: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Copy the macromol. complex index into aux1S: */ aux1S.mol_complexI = mol_complexI; /* Copy the flag which says are hydrogen bonds hidden or not: */ hybonds_hiddenF = curr_mol_complexSP->hydrogen_bonds_hiddenF; /* Draw bonds which have the given style: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Check is atom hidden: */ if (curr_atomSP->hiddenF) continue; /* Check is atom inside slab: */ if (!curr_atomSP->inside_slabF) continue; /* Check is atom inside window: */ if (!curr_atomSP->inside_windowF) continue; /* Prepare four additional colors: */ AddTwoColors_ (curr_atomSP->left_colorID, curr_atomSP->middle_colorID, guiSP, &color1ID, &color2ID); AddTwoColors_ (curr_atomSP->middle_colorID, curr_atomSP->right_colorID, guiSP, &color3ID, &color4ID); /* Prepare seven GC's: */ XSetForeground (guiSP->displaySP, guiSP->theGCA[0], curr_atomSP->left_colorID); XSetForeground (guiSP->displaySP, guiSP->theGCA[1], color1ID); XSetForeground (guiSP->displaySP, guiSP->theGCA[2], color2ID); XSetForeground (guiSP->displaySP, guiSP->theGCA[3], curr_atomSP->middle_colorID); XSetForeground (guiSP->displaySP, guiSP->theGCA[4], color3ID); XSetForeground (guiSP->displaySP, guiSP->theGCA[5], color4ID); XSetForeground (guiSP->displaySP, guiSP->theGCA[6], curr_atomSP->right_colorID); /* Copy color values to aux1S: */ aux1S.colorIDA[0] = curr_atomSP->left_colorID; aux1S.colorIDA[1] = color1ID; aux1S.colorIDA[2] = color2ID; aux1S.colorIDA[3] = curr_atomSP->middle_colorID; aux1S.colorIDA[4] = color3ID; aux1S.colorIDA[5] = color4ID; aux1S.colorIDA[6] = curr_atomSP->right_colorID; /* Copy the atomic index into aux1S: */ aux1S.atomI = atomI; /* Number of bonds: */ bondsN = curr_atomSP->bondsN; /* Bond loop: */ for (bondI = 0; bondI < bondsN; bondI++) { /* Pointer to the structure with data about current bond: */ curr_bondSP = curr_atomSP->true_bondSA + bondI; /* Check bond drawing style: */ if (curr_bondSP->bond_styleI != 4) continue; /* If the current bond is hydrogen bond, it may be hidden: */ if (curr_bondSP->bond_typeI == 0) { if (hybonds_hiddenF) continue; } /* The complex which contains the atom forming the bond: */ partner_mol_complexSP = mol_complexSP + curr_bondSP->neighbor_mol_complexI; /* Pointer to the bond partner: */ partner_atomSP = partner_mol_complexSP->atomSP + curr_bondSP->neighbor_arrayI; /* If partner is not visible, do not draw this bond: */ if (partner_atomSP->hiddenF) continue; /* Draw one (mono) or two bonds (stereo): */ for (imageI = 0; imageI < imagesN; imageI++) { /* Copy imageI to aux1S: */ aux1S.imageI = imageI; /* Prepare screen coordinates of */ /* both atoms involved in bond: */ aux1S.screen_x0 = curr_atomSP->raw_atomS.screen_x[imageI]; aux1S.screen_y0 = curr_atomSP->raw_atomS.screen_y; aux1S.screen_x1 = partner_atomSP->raw_atomS.screen_x[imageI]; aux1S.screen_y1 = partner_atomSP->raw_atomS.screen_y; aux1S.atomic_z0 = curr_atomSP->raw_atomS.z[imageI]; aux1S.atomic_z1 = partner_atomSP->raw_atomS.z[imageI]; /* Prepare differences: */ aux1S.screen_delta_x = aux1S.screen_x1 - aux1S.screen_x0; aux1S.screen_delta_y = aux1S.screen_y1 - aux1S.screen_y0; aux1S.atomic_delta_z = aux1S.atomic_z1 - aux1S.atomic_z0; /* Shift and tilt bond to ensure */ /* the proper stacking of bonds: */ delta_z_sign = 1.0; if (aux1S.atomic_delta_z < 0) delta_z_sign = -1.0; z_shift = delta_z_sign * Z_SHIFT; aux1S.atomic_z0 += z_shift; aux1S.atomic_z1 -= z_shift; aux1S.atomic_delta_z -= 3 * z_shift; /* Some absolute differences: */ screen_abs_delta_x = abs (aux1S.screen_delta_x); screen_abs_delta_y = abs (aux1S.screen_delta_y); /* Find the region: */ if (screen_abs_delta_x >= screen_abs_delta_y) { if (aux1S.screen_delta_x >= 0) regionI = 1; else regionI = 3; } else { if (aux1S.screen_delta_y >= 0) regionI = 2; else regionI = 4; } if ((aux1S.screen_delta_x == 0) && (aux1S.screen_delta_y == 0)) { regionI = 0; } /* Each region has its own drawing procedure: */ switch (regionI) { /* Both atoms are projected to the same point, */ /* i.e. this bond is perpendicular to the screen: */ case 0: /* Do nothing! */ break; /* Right quadrant: */ case 1: BondStyle4Quadrant1_ (&aux1S, bondI); break; /* Bottom quadrant (check Note 3!): */ case 2: BondStyle4Quadrant2_ (&aux1S, bondI); break; /* Left quadrant: */ case 3: BondStyle4Quadrant3_ (&aux1S, bondI); break; /* Top quadrant (check Note 3!): */ case 4: BondStyle4Quadrant4_ (&aux1S, bondI); break; /* This should be the impossible case: */ default: ; } /* Update the counter: */ bonds_drawnN++; } /* imageI loop */ } /* bondI loop */ } /* atomI loop */ } /* mol_complexI loop */ /* Return the number of bonds which were drawn: */ return bonds_drawnN; } /*===========================================================================*/ garlic-1.6/bonds_style5.c0000644000076500007650000002224407461727114015702 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2002 Damir Zucic */ /*============================================================================= bonds_style5.c Purpose: Draw bonds using style 5 (nine lines per bond). Half of each bond is drawn and another half is assigned to the partner. The z value is calculated for each pixel. A bond is visible only if both atoms forming this bond are visible. Input: (1) Pointer to MolComplexS structure. (2) Number of macromolecular complexes. (3) Pointer to ConfigS structure, with configuration data. (4) Pointer to GUIS structure. (5) Pointer to NearestAtomS structure, with information about the atom occupying the given pixel. (6) The number of pixels in the main window free area. (7) The refreshI, used to check the NearestAtomS associated with a given pixel. Output: (1) Atoms drawn to the hidden pixmap. (2) Return value. Return value: (1) The number of bonds drawn. Notes: (1) Indentation is exceptionally 4 spaces. (2) Deep indentation is allowed in this function. This is not my favorite coding style but it may help to improve performance. (3) The vector from the current atom to the bond partner belongs to one of five regions. If atomic positions are exactly the same, the vector belongs to the region "zero". Otherwise, it belongs to one of four quadrants. Quadrants are arranged as shown here: *** 4 *** o-----> *** *** | X *** *** | 3 *** 1 V *** *** Y *** *** *** 2 *** (4) Nothing is drawn for bonds perpendicular to the screen. (5) Two additional colors are prepared. =============================================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ void AddThreeColors_ (unsigned long, unsigned long, GUIS *, unsigned long *, unsigned long *, unsigned long *); int BondStyle5Quadrant1_ (Aux1S *, int); int BondStyle5Quadrant2_ (Aux1S *, int); int BondStyle5Quadrant3_ (Aux1S *, int); int BondStyle5Quadrant4_ (Aux1S *, int); /*======draw bonds using style 5 (nine lines per bond):======================*/ size_t DrawBondsStyle5_ (MolComplexS *mol_complexSP, int mol_complexesN, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int refreshI) { size_t bonds_drawnN = 0; int imageI, imagesN; Aux1S aux1S; int mol_complexI; MolComplexS *curr_mol_complexSP, *partner_mol_complexSP; size_t atomsN, atomI; unsigned long color1ID, color2ID, color3ID; unsigned long color4ID, color5ID, color6ID; AtomS *curr_atomSP, *partner_atomSP; int bondsN, bondI; TrueBondS *curr_bondSP; int screen_abs_delta_x, screen_abs_delta_y; int regionI; double z_shift, delta_z_sign; int hybonds_hiddenF; /* Number of images: */ if (configSP->stereoF) imagesN = 2; else imagesN = 1; /* Prepare the auxiliary Aux1S structure, used to */ /* reduce the number of arguments in function calls: */ aux1S.configSP = configSP; aux1S.guiSP = guiSP; aux1S.nearest_atomSP = nearest_atomSP; aux1S.pixelsN = pixelsN; aux1S.refreshI = refreshI; /* Draw each macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Prepare and check the number of atoms: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Copy the macromol. complex index into aux1S: */ aux1S.mol_complexI = mol_complexI; /* Copy the flag which says are hydrogen bonds hidden or not: */ hybonds_hiddenF = curr_mol_complexSP->hydrogen_bonds_hiddenF; /* Draw bonds which have the given style: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Check is atom hidden: */ if (curr_atomSP->hiddenF) continue; /* Check is atom inside slab: */ if (!curr_atomSP->inside_slabF) continue; /* Check is atom inside window: */ if (!curr_atomSP->inside_windowF) continue; /* Prepare six additional colors: */ AddThreeColors_ (curr_atomSP->left_colorID, curr_atomSP->middle_colorID, guiSP, &color1ID, &color2ID, &color3ID); AddThreeColors_ (curr_atomSP->middle_colorID, curr_atomSP->right_colorID, guiSP, &color4ID, &color5ID, &color6ID); /* Prepare nine GC's: */ XSetForeground (guiSP->displaySP, guiSP->theGCA[0], curr_atomSP->left_colorID); XSetForeground (guiSP->displaySP, guiSP->theGCA[1], color1ID); XSetForeground (guiSP->displaySP, guiSP->theGCA[2], color2ID); XSetForeground (guiSP->displaySP, guiSP->theGCA[3], color3ID); XSetForeground (guiSP->displaySP, guiSP->theGCA[4], curr_atomSP->middle_colorID); XSetForeground (guiSP->displaySP, guiSP->theGCA[5], color4ID); XSetForeground (guiSP->displaySP, guiSP->theGCA[6], color5ID); XSetForeground (guiSP->displaySP, guiSP->theGCA[7], color6ID); XSetForeground (guiSP->displaySP, guiSP->theGCA[8], curr_atomSP->right_colorID); /* Copy color values to aux1S: */ aux1S.colorIDA[0] = curr_atomSP->left_colorID; aux1S.colorIDA[1] = color1ID; aux1S.colorIDA[2] = color2ID; aux1S.colorIDA[3] = color3ID; aux1S.colorIDA[4] = curr_atomSP->middle_colorID; aux1S.colorIDA[5] = color4ID; aux1S.colorIDA[6] = color5ID; aux1S.colorIDA[7] = color6ID; aux1S.colorIDA[8] = curr_atomSP->right_colorID; /* Copy the atomic index into aux1S: */ aux1S.atomI = atomI; /* Number of bonds: */ bondsN = curr_atomSP->bondsN; /* Bond loop: */ for (bondI = 0; bondI < bondsN; bondI++) { /* Pointer to the structure with data about current bond: */ curr_bondSP = curr_atomSP->true_bondSA + bondI; /* Check bond drawing style: */ if (curr_bondSP->bond_styleI != 5) continue; /* If the current bond is hydrogen bond, it may be hidden: */ if (curr_bondSP->bond_typeI == 0) { if (hybonds_hiddenF) continue; } /* The complex which contains the atom forming the bond: */ partner_mol_complexSP = mol_complexSP + curr_bondSP->neighbor_mol_complexI; /* Pointer to the bond partner: */ partner_atomSP = partner_mol_complexSP->atomSP + curr_bondSP->neighbor_arrayI; /* If partner is not visible, do not draw this bond: */ if (partner_atomSP->hiddenF) continue; /* Draw one (mono) or two bonds (stereo): */ for (imageI = 0; imageI < imagesN; imageI++) { /* Copy imageI to aux1S: */ aux1S.imageI = imageI; /* Prepare screen coordinates of */ /* both atoms involved in bond: */ aux1S.screen_x0 = curr_atomSP->raw_atomS.screen_x[imageI]; aux1S.screen_y0 = curr_atomSP->raw_atomS.screen_y; aux1S.screen_x1 = partner_atomSP->raw_atomS.screen_x[imageI]; aux1S.screen_y1 = partner_atomSP->raw_atomS.screen_y; aux1S.atomic_z0 = curr_atomSP->raw_atomS.z[imageI]; aux1S.atomic_z1 = partner_atomSP->raw_atomS.z[imageI]; /* Prepare differences: */ aux1S.screen_delta_x = aux1S.screen_x1 - aux1S.screen_x0; aux1S.screen_delta_y = aux1S.screen_y1 - aux1S.screen_y0; aux1S.atomic_delta_z = aux1S.atomic_z1 - aux1S.atomic_z0; /* Shift and tilt bond to ensure */ /* the proper stacking of bonds: */ delta_z_sign = 1.0; if (aux1S.atomic_delta_z < 0) delta_z_sign = -1.0; z_shift = delta_z_sign * Z_SHIFT; aux1S.atomic_z0 += z_shift; aux1S.atomic_z1 -= z_shift; aux1S.atomic_delta_z -= 3 * z_shift; /* Some absolute differences: */ screen_abs_delta_x = abs (aux1S.screen_delta_x); screen_abs_delta_y = abs (aux1S.screen_delta_y); /* Find the region: */ if (screen_abs_delta_x >= screen_abs_delta_y) { if (aux1S.screen_delta_x >= 0) regionI = 1; else regionI = 3; } else { if (aux1S.screen_delta_y >= 0) regionI = 2; else regionI = 4; } if ((aux1S.screen_delta_x == 0) && (aux1S.screen_delta_y == 0)) { regionI = 0; } /* Each region has its own drawing procedure: */ switch (regionI) { /* Both atoms are projected to the same point, */ /* i.e. this bond is perpendicular to the screen: */ case 0: /* Do nothing! */ break; /* Right quadrant: */ case 1: BondStyle5Quadrant1_ (&aux1S, bondI); break; /* Bottom quadrant (check Note 3!): */ case 2: BondStyle5Quadrant2_ (&aux1S, bondI); break; /* Left quadrant: */ case 3: BondStyle5Quadrant3_ (&aux1S, bondI); break; /* Top quadrant (check Note 3!): */ case 4: BondStyle5Quadrant4_ (&aux1S, bondI); break; /* This should be the impossible case: */ default: ; } /* Update the counter: */ bonds_drawnN++; } /* imageI loop */ } /* bondI loop */ } /* atomI loop */ } /* mol_complexI loop */ /* Return the number of bonds which were drawn: */ return bonds_drawnN; } /*===========================================================================*/ garlic-1.6/ramachandran.c0000644000076500007650000000773407117406201015703 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= ramachandran.c Purpose: Execute ramachandran command: draw Ramachandran plot. Input: (1) Pointer to MolComplexS structure. (2) The number of macromolecular complexes. (3) Pointer to RuntimeS structure. (4) Pointer to ConfigS structure. (5) Pointer to GUIS structure. (6) Pointer to NearestAtomS structure. (7) The number of pixels in the main window free area. (8) Pointer to refreshI. (9) Pointer to the remainder of the command string. This command may be given without keyword, with keyword SEL or with keyword OFF. Output: (1) The main window mode changed to 1 (default is zero), i.e. the main window will be switched to Ramachandran plot. (2) Return value. Return value: (1) Positive (command) code on success. (2) Negative (error) code on failure. Notes: (1) This command reinitializes the NearestAtomS array, except if the additional keyword is not recognized. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "commands.h" #include "typedefs.h" /*======function prototypes:=================================================*/ char *ExtractToken_ (char *, int, char *, char *); void InitNearest_ (NearestAtomS *, size_t); size_t MainRefresh_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); int ControlRefresh_ (MolComplexS *, ConfigS *, GUIS *); /*======execute ramachandran command:========================================*/ int Ramachandran_ (MolComplexS *mol_complexSP, int mol_complexesN, RuntimeS *runtimeSP, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int *refreshIP, char *stringP) { char *remainderP; char tokenA[SHORTSTRINGSIZE]; /* Initialize / reset the rama_selectionF (described in typedefs.h): */ runtimeSP->rama_selectionF = 0; /* Extract the first token: */ remainderP = ExtractToken_ (tokenA, STRINGSIZE, stringP, " \t\n"); /* If available, the first token should contain keyword OFF or SEL: */ if (remainderP) { /* If keyword OFF is present, switch to default drawing mode: */ if (strstr (tokenA, "OFF") == tokenA) { /* Reset drawing mode index: */ guiSP->main_window_modeI = 0; /* Reinitialize the NearestAtomS array: */ InitNearest_ (nearest_atomSP, pixelsN); *refreshIP = 1; /* Refresh the main window: */ (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); /* Refresh the control window: */ ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); /* Return the command code: */ return COMMAND_RAMACHANDRAN; } /* If keyword SEL is present, set the flag which signals that */ /* Ramachandran plot should be drawn only for selected residues: */ else if (strstr (tokenA, "SEL") == tokenA) { runtimeSP->rama_selectionF = 1; } /* If keyword recognition fails: */ else { sprintf (runtimeSP->messageA, "Keyword %s not recognized!", tokenA); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_RAMACHANDRAN; } } /* Set the main window drawing mode index: */ guiSP->main_window_modeI = 1; /* Reinitialize the NearestAtomS array and refresh index: */ InitNearest_ (nearest_atomSP, pixelsN); *refreshIP = 1; /* Refresh the main window: */ (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); /* Refresh the control window: */ ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); /* Return the command code: */ return COMMAND_RAMACHANDRAN; } /*===========================================================================*/ garlic-1.6/color_size.c0000644000076500007650000001152307763100574015436 0ustar zuciczucic00000000000000/* Copyright (C) 2003 Damir Zucic */ /*============================================================================= color_size.c Purpose: Size color scheme: assign colors according to the side chain size. The smallest residue (GLY) will be colored blue and the largest residue (TRP) will be colored red. The size is defined as the total number of carbon, oxygen and nitrogen atoms. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. (3) Pointer to GUIS structure, with GUI data. (4) Pointer to ColorSchemeS structure. Output: (1) Return value. Return value: (1) Positive always. =============================================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int MixColors_ (AtomS *, ColorSchemeS *, ColorSchemeS *, double, GUIS *); /*======size color scheme:===================================================*/ int ColorSize_ (MolComplexS *mol_complexSP, int mol_complexesN, GUIS *guiSP, ColorSchemeS *color_schemeSP) { size_t rgb_struct_size; ColorSchemeS *blue_schemeSP, *white_schemeSP, *red_schemeSP; static double min_size = 0, threshold_size = 4, max_size = 10; double delta_size1, delta_size2; double inverse_range1, inverse_range2; int mol_complexI; MolComplexS *curr_mol_complexSP; int residuesN, residueI; ResidueS *residueSP; AtomS *first_atomSP; char *residue_nameP; int i; static char amino_acidAA[23][4] = {"ALA","ARG","ASN","ASP","CYS","GLN","GLU","GLY","HIS","ILE", "LEU","LYS","MET","PHE","PRO","SER","THR","TRP","TYR","VAL", "ASX","GLX","UNK"}; static double res_sizeA[23] = { 1.0, 7.0, 4.0, 4.0, 2.0, 5.0, 5.0, 0.0, 6.0, 4.0, 4.0, 5.0, 4.0, 7.0, 3.0, 2.0, 3.0, 10.0, 8.0, 3.0, 4.0, 5.0, 5.0 }; double res_size; size_t startI, endI, atomI; AtomS *atomSP; double scale_factor; /* The size of RGBS structure: */ rgb_struct_size = sizeof (RGBS); /* Red scheme pointer: */ red_schemeSP = color_schemeSP + 0; /* White scheme pointer: */ white_schemeSP = color_schemeSP + 6; /* Blue scheme pointer: */ blue_schemeSP = color_schemeSP + 2; /* Inverse size ranges: */ delta_size1 = max_size - threshold_size; if (delta_size1 != 0.0) inverse_range1 = 1.0 / delta_size1; else inverse_range1 = 0.0; delta_size2 = threshold_size - min_size; if (delta_size2 != 0.0) inverse_range2 = 1.0 / delta_size2; else inverse_range2 = 0.0; /* Scan every macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check is the current macromolecular complex caught: */ if (curr_mol_complexSP->catchF == 0) continue; /* Copy and check the number of residues: */ residuesN = curr_mol_complexSP->residuesN; if (residuesN == 0) continue; /* Scan the macromolecular complex, residue by residue: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Pointer to the current residue: */ residueSP = mol_complexSP->residueSP + residueI; /* Pointer to the first atom of this residue: */ first_atomSP = mol_complexSP->atomSP + residueSP->residue_startI; /* Pointer to the residue name: */ residue_nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* The threshold value is used as default: */ res_size = threshold_size; /* Compare the purified residue name with 23 standard names: */ for (i = 0; i < 23; i++) { /* If amino acid is recognized: */ if (strcmp (residue_nameP, amino_acidAA[i]) == 0) { res_size = res_sizeA[i]; break; } } /* All atoms of this residue should be colored: */ /* The range of atomic indices for the current residue: */ startI = residueSP->residue_startI; endI = residueSP->residue_endI; /* Scan the whole residue: */ for (atomI = startI; atomI <= endI; atomI++) { /* Pointer to the current atom: */ atomSP = mol_complexSP->atomSP + atomI; /* If residue size is below threshold value: */ if (res_size <= threshold_size) { scale_factor = (threshold_size - res_size) * inverse_range2; MixColors_ (atomSP, white_schemeSP, blue_schemeSP, scale_factor, guiSP); } /* If residue size is above threshold value: */ else { scale_factor = (res_size - threshold_size) * inverse_range1; MixColors_ (atomSP, white_schemeSP, red_schemeSP, scale_factor, guiSP); } } } /* Reset the position_changedF: */ curr_mol_complexSP->position_changedF = 1; } /* Return positive value: */ return 1; } /*===========================================================================*/ garlic-1.6/compare.c0000644000076500007650000001322507244015565014714 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= compare.c Purpose: Execute compare command: compare the sequence from the general purpose buffer with the sequence from the reference buffer. The keywords are: OFF, ZOOM, CORNER. Input: (1) Pointer to MolComplexS structure. (2) The number of macromolecular complexes. (3) Pointer to RuntimeS structure. (4) Pointer to ConfigS structure. (5) Pointer to GUIS structure. (6) Pointer to NearestAtomS structure. (7) The number of pixels in the main window free area. (8) Pointer to refreshI. (9) Pointer to the remainder of the command string. The command may be given with a list of keywords. Output: (1) The main window mode changed to 5 (default is zero). (2) Return value. Return value: (1) Positive (command) code on success. (2) Negative (error) code on failure. Notes: (1) This command reinitializes the NearestAtomS array, except if at additional keyword is not recognized. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "commands.h" #include "typedefs.h" /*======function prototypes:=================================================*/ char *ExtractToken_ (char *, int, char *, char *); void InitNearest_ (NearestAtomS *, size_t); size_t MainRefresh_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); int ControlRefresh_ (MolComplexS *, ConfigS *, GUIS *); int ExtractIndex_ (char *); int ExtractTwoIntegers_ (int *, int *, char *); /*======execute compare command:=============================================*/ int Compare_ (MolComplexS *mol_complexSP, int mol_complexesN, RuntimeS *runtimeSP, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int *refreshIP, char *stringP) { char *remainderP; char tokenA[SHORTSTRINGSIZE]; int zoom_factor; int residue1I, residue2I; int segment_width, minimal_score; /* Extract the first token: */ remainderP = ExtractToken_ (tokenA, STRINGSIZE, stringP, " \t\n"); /* If no token is available, set the main window drawing */ /* mode, refresh the main and the control window and return: */ if (!remainderP) { /* Set the main window drawing mode index: */ guiSP->main_window_modeI = 5; } /* If keyword OFF is present, switch to default drawing mode: */ else if (strstr (tokenA, "OFF") == tokenA) { /* Reset drawing mode index: */ guiSP->main_window_modeI = 0; } /* If keyword ZOOM is present: */ else if (strstr (tokenA, "ZOO") == tokenA) { /* Try to read the zoom factor: */ zoom_factor = ExtractIndex_ (stringP); if (zoom_factor <= 0) { strcpy (runtimeSP->messageA, "Bad zoom factor!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_COMPARE; } /* Store the zoom factor: */ runtimeSP->zoom_factor = zoom_factor; /* Set the main window drawing mode index: */ guiSP->main_window_modeI = 5; } /* If keyword CORNER is present: */ else if (strstr (tokenA, "COR") == tokenA) { /* Try to extract two offsets: */ if (ExtractTwoIntegers_ (&residue1I, &residue2I, stringP) < 0) { strcpy (runtimeSP->messageA, "Unable to read corner position!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_COMPARE; } /* Check signs: */ if ((residue1I < 0) || (residue2I < 0)) { strcpy (runtimeSP->messageA, "Both indices must be positive!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_COMPARE; } /* Check upper limits: */ if ((residue1I >= MAXRESIDUES) || (residue2I >= MAXRESIDUES)) { strcpy (runtimeSP->messageA, "At least one index is too large!"); return ERROR_COMPARE; } /* Store offsets: */ runtimeSP->reference_offset = residue1I; runtimeSP->sequence_offset = residue2I; /* Set the main window drawing mode index: */ guiSP->main_window_modeI = 5; } /* If keyword recognition failes, try to extract the segment width and */ /* the minimal score. Do not forget to set the main window drawing mode! */ else { /* Try to extract two integers: */ if (ExtractTwoIntegers_ (&minimal_score, &segment_width, stringP) < 0) { strcpy (runtimeSP->messageA, "Syntax error!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_COMPARE; } /* Check values: */ if ((segment_width < 1) || (minimal_score < 1)) { strcpy (runtimeSP->messageA, "Positive integers expected!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_COMPARE; } else if (minimal_score > segment_width) { strcpy (runtimeSP->messageA, "The minimal score should not"); strcat (runtimeSP->messageA, " exceed the segment width!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_COMPARE; } /* Store segment width and minimal score: */ runtimeSP->minimal_score = minimal_score; runtimeSP->segment_width = segment_width; /* Set the main window drawing mode index: */ guiSP->main_window_modeI = 5; } /* Reinitialize the NearestAtomS array and refresh index: */ InitNearest_ (nearest_atomSP, pixelsN); *refreshIP = 1; /* Refresh the main window: */ (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); /* Refresh the control window: */ ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); /* Return the command code: */ return COMMAND_COMPARE; } /*===========================================================================*/ garlic-1.6/18-porins.script0000644000076500007650000000604610140164441016076 0ustar zuciczucic00000000000000# Loading and displaying 18 porins. # All structures will be displayed as cyan-blue backbones. # Pairs of charged and zwitterionic residues will be shown in red. # Performance tuning: refresh off # (1) 2POR: load 2por.pdb backbone 2 color cyan-blue pattern = arg lys asp glu asn gln / arg lys asp glu asn gln select pattern color red position -120 -90 600 # (2) 1OPF: load 1opf.pdb backbone 2 color cyan-blue pattern = arg lys asp glu asn gln / arg lys asp glu asn gln select pattern color red position -60 -90 600 # (3) 1PRN: load 1prn.pdb backbone 2 color cyan-blue pattern = arg lys asp glu asn gln / arg lys asp glu asn gln select pattern color red position 0 -90 600 # (4) 1OSM: load 1osm.pdb backbone 2 color cyan-blue pattern = arg lys asp glu asn gln / arg lys asp glu asn gln select pattern color red position 60 -90 600 # (5) 1E54: load 1e54.pdb backbone 2 color cyan-blue pattern = arg lys asp glu asn gln / arg lys asp glu asn gln select pattern color red position 120 -90 600 # (6) 1MAL: load 1mal.pdb backbone 2 color cyan-blue pattern = arg lys asp glu asn gln / arg lys asp glu asn gln select pattern color red position -120 -30 600 # (7) 1A0S: load 1a0s.pdb backbone 2 color cyan-blue pattern = arg lys asp glu asn gln / arg lys asp glu asn gln select pattern color red position -60 -30 600 # (8) 1BXW: load 1bxw.pdb backbone 2 color cyan-blue pattern = arg lys asp glu asn gln / arg lys asp glu asn gln select pattern color red position 0 -30 600 # (9) 1QJ8: load 1qj8.pdb backbone 2 color cyan-blue pattern = arg lys asp glu asn gln / arg lys asp glu asn gln select pattern color red position 60 -30 600 # (10) 2FCP: load 2fcp.pdb backbone 2 color cyan-blue pattern = arg lys asp glu asn gln / arg lys asp glu asn gln select pattern color red position 120 -30 600 # (11) 1FEP: load 1fep.pdb backbone 2 color cyan-blue pattern = arg lys asp glu asn gln / arg lys asp glu asn gln select pattern color red position -120 30 600 # (12) 1KMO: load 1kmo.pdb backbone 2 color cyan-blue pattern = arg lys asp glu asn gln / arg lys asp glu asn gln select pattern color red position -60 30 600 # (13) 1QD5: load 1qd5.pdb backbone 2 color cyan-blue pattern = arg lys asp glu asn gln / arg lys asp glu asn gln select pattern color red position 0 30 600 # (14) 1I78: load 1i78.pdb backbone 2 color cyan-blue pattern = arg lys asp glu asn gln / arg lys asp glu asn gln select pattern color red position 60 30 600 # (15) 1K24: load 1k24.pdb backbone 2 color cyan-blue pattern = arg lys asp glu asn gln / arg lys asp glu asn gln select pattern color red position 120 30 600 # (16) 1NQE: load 1nqe.pdb backbone 2 color cyan-blue pattern = arg lys asp glu asn gln / arg lys asp glu asn gln select pattern color red position -120 90 600 # (17) 1TLZ: load 1tlz.pdb backbone 2 color cyan-blue pattern = arg lys asp glu asn gln / arg lys asp glu asn gln select pattern color red position -60 90 600 # (18) 1T16: load 1t16.pdb backbone 2 color cyan-blue pattern = arg lys asp glu asn gln / arg lys asp glu asn gln select pattern color red position 0 90 600 # Switch refreshing on: refresh on garlic-1.6/scale.c0000644000076500007650000000777110140420674014354 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2004 Damir Zucic */ /*============================================================================= scale.c Purpose: Execute scale command: change the hydrophobicity scale. This scale will be assigned to all caught macromolecular complexes and to the sequence stored in the sequence buffer. Input: (1) Pointer to MolComplexS structure. (2) The number of macromolecular complexes. (3) Pointer to RuntimeS structure. (4) Pointer to the remainder of the command string. The remainder should contain the hydrophobicity scale name. The keywords are EIS (EISENBERG), INT (INTERFACE), IN2, KD (KYTE-DOOLITLE), OCT (OCTANOL) and DIF (DIFFERENTIAL, octanol minus interface). Output: (1) Hydrophobicity scale changed for each caught complex and for the sequence stored in the sequence buffer. (2) Return value. Return value: (1) Positive (command) code on success. (2) Negative (error) code on failure. Notes: (1) The main window content will not be refreshed. (2) Check init_runtime.c for default hydrophobicity scale! ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "commands.h" #include "typedefs.h" /*======function prototypes:=================================================*/ char *ExtractToken_ (char *, int, char *, char *); int AssignHydrophobicity_ (MolComplexS *, int); void InitHyphob_ (RuntimeS *); /*======execute scale command:===============================================*/ int Scale_ (MolComplexS *mol_complexSP, int mol_complexesN, RuntimeS *runtimeSP, char *stringP) { char *remainderP; char tokenA[STRINGSIZE]; int scaleI = 2; int mol_complexI; MolComplexS *curr_mol_complexSP; /* Extract the first token, if present: */ remainderP = ExtractToken_ (tokenA, STRINGSIZE, stringP, " \t\n"); /* If there are no tokens in the remainder of the */ /* command string, the scale name is missing: */ if (!remainderP) { strcpy (runtimeSP->messageA, "Scale name missing!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_SCALE; } /* OCT (OCTANOL); before it was WHI (WHITE): */ else if (strstr (tokenA, "OCT") == tokenA) scaleI = 0; /* For compatibility reasons, check for the old */ /* (obsolete) keyword for White octanol scale: */ else if (strstr (tokenA, "WHI") == tokenA) { strcpy (runtimeSP->messageA, "Keyword WHITE (WHI) is obsolete, please use OCTANOL (OCT)!"); runtimeSP->message_length = strlen (runtimeSP->messageA); scaleI = 0; } /* KD (KYTE-DOOLITLE): */ else if (strstr (tokenA, "KD") == tokenA) scaleI = 1; /* EIS (EISENBERG): */ else if (strstr (tokenA, "EIS") == tokenA) scaleI = 2; /* INT (INTERFACE): */ else if (strstr (tokenA, "INT") == tokenA) scaleI = 3; /* IN2 (modified interface scale): */ else if (strstr (tokenA, "IN2") == tokenA) scaleI = 4; /* DIF (differential, octanol-interface): */ else if (strstr (tokenA, "DIF") == tokenA) scaleI = 5; /* Keyword not recognized: */ else { strcpy (runtimeSP->messageA, "Keyword not recognized!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_SCALE; } /* For each caught macromolecular complex, change the scale: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check is the current macromolecular complex caught: */ if (curr_mol_complexSP->catchF == 0) continue; /* Change hydrophobicity scale: */ AssignHydrophobicity_ (curr_mol_complexSP, scaleI); } /* Update the hydrophobicity scale index in RuntimeS structure: */ runtimeSP->hydrophobicity_scaleI = scaleI; /* Update hydrophobicity values assigned to residues in the sequence buffer: */ InitHyphob_ (runtimeSP); /* Return the command code: */ return COMMAND_SCALE; } /*===========================================================================*/ garlic-1.6/chi3_from_cbcgsdce.c0000644000076500007650000000727307341277031016756 0ustar zuciczucic00000000000000/* Copyright (C) 2001 Damir Zucic */ /*============================================================================= chi3_from_cbcgsdce.c Purpose: Calculate dihedral angle chi3, using CB, CG, SD and CE coordinates. Input: (1) Pointer to AtomS structure, pointing to the first atom of the current macromolecular complex. (2) Index of the first atom of the current residue. (3) Index of the last atom of the currrent residue. Output: Return value. Return value: (1) Dihedral angle chi3, on success. (2) BADDIHEDANGLE on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int ExtractFourAtoms_ (VectorS *, VectorS *, VectorS *, VectorS *, char *, char *, char *, char *, AtomS *, size_t, size_t); void VectorProduct_ (VectorS *, VectorS *, VectorS *); double AbsoluteValue_ (VectorS *); double ScalarProduct_ (VectorS *, VectorS *); /*======calculate chi3 from CB, CG, SD and CE:===============================*/ double Chi3FromCBCGSDCE_ (AtomS *atomSP, size_t atom_startI, size_t atom_endI) { static VectorS CB_vectorS, CG_vectorS, SD_vectorS, CE_vectorS; int n; VectorS CG_CB_vectorS, CG_SD_vectorS; VectorS SD_CG_vectorS, SD_CE_vectorS; VectorS u1S, u2S; VectorS v1S, v2S; double denom, ratio, alpha; double chi3; /* Extract CB, CG, SD and CE coordinates: */ n = ExtractFourAtoms_ (&CB_vectorS, &CG_vectorS, &SD_vectorS, &CE_vectorS, "CB", "CG", "SD", "CE", atomSP, atom_startI, atom_endI); /* All four atoms are required to calculate the angle chi3: */ if (n < 4) return BADDIHEDANGLE; /* The first pair of auxiliary vectors: */ CG_CB_vectorS.x = CB_vectorS.x - CG_vectorS.x; CG_CB_vectorS.y = CB_vectorS.y - CG_vectorS.y; CG_CB_vectorS.z = CB_vectorS.z - CG_vectorS.z; CG_SD_vectorS.x = SD_vectorS.x - CG_vectorS.x; CG_SD_vectorS.y = SD_vectorS.y - CG_vectorS.y; CG_SD_vectorS.z = SD_vectorS.z - CG_vectorS.z; /* The second pair of auxiliary vectors: */ SD_CG_vectorS.x = CG_vectorS.x - SD_vectorS.x; SD_CG_vectorS.y = CG_vectorS.y - SD_vectorS.y; SD_CG_vectorS.z = CG_vectorS.z - SD_vectorS.z; SD_CE_vectorS.x = CE_vectorS.x - SD_vectorS.x; SD_CE_vectorS.y = CE_vectorS.y - SD_vectorS.y; SD_CE_vectorS.z = CE_vectorS.z - SD_vectorS.z; /* Two vectors perpendicular to CG_SD_vectorS, mutually orthogonal, */ /* the second in the plane defined by CG_CB_vectorS and CG_SD_vectorS: */ VectorProduct_ (&u1S, &CG_CB_vectorS, &CG_SD_vectorS); VectorProduct_ (&u2S, &u1S, &CG_SD_vectorS); /* Two vectors perpendicular to SD_CG_vectorS, mutually orthogonal, */ /* the second in the plane defined by SD_CG_vectorS and SD_CE_vectorS: */ VectorProduct_ (&v1S, &SD_CG_vectorS, &SD_CE_vectorS); VectorProduct_ (&v2S, &SD_CG_vectorS, &v1S); /* Calculate the angle alpha, which will be used to calculate chi3: */ /* Avoid division by zero: */ denom = AbsoluteValue_ (&u1S) * AbsoluteValue_ (&v1S); if (denom == 0.0) return BADDIHEDANGLE; /* Use the scalar product to calculate the cosine of the angle: */ ratio = ScalarProduct_ (&u1S, &v1S) / denom; /* Arc cosine is very sensitive to floating point errors: */ if (ratio <= -1.0) alpha = 3.1415927; else if (ratio >= 1.0) alpha = 0.0; else alpha = acos (ratio); /* There are two possible solutions; the right one is resolved here: */ if (ScalarProduct_ (&v2S, &u1S) >= 0) chi3 = alpha; else chi3 = -alpha; /* Return the angle (in radians): */ return chi3; } /*===========================================================================*/ garlic-1.6/edit_omega.c0000644000076500007650000001166607370732506015373 0ustar zuciczucic00000000000000/* Copyright (C) 2001 Damir Zucic */ /*============================================================================= edit_omega.c Purpose: Edit omega angle. If edit_single_bondF is zero, edit omega for every selected residue in the specified macromolecular complex. If the flag edit_single_bondF is different from zero, edit only the omega angle for the bond specified by the given atomic array indices. If the peptide bond is formed by residues I and I + 1, it is assigned to residue I + 1. The same is valid for omega. A residue is treated as selected if the first atom of this residue is selected. For protein residues, this is typically N atom (nitrogen). Input: (1) Pointer to MolComplexS structure. (2) Pointer to RuntimeS structure. (3) Pointer to ConfigS structure. (4) Rotation angle. Output: (1) Omega angle changed for chosen residue(s). (2) Return value. Return value: (1) Positive always (trivial). ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int ExtractC_ (VectorS *, AtomS *, size_t, size_t); int ExtractN_ (VectorS *, AtomS *, size_t, size_t); int RotateAtom_ (AtomS *, VectorS *, VectorS *, double); int DihedralAngles_ (MolComplexS *, ConfigS *); /*======change omega angle for selected residues:============================*/ int EditOmega_ (MolComplexS *mol_complexSP, RuntimeS *runtimeSP, ConfigS *configSP, double delta_omega) { int residuesN, residueI; size_t atomsN; ResidueS *residueSP; size_t startI, endI, atomI; AtomS *atomSP; ResidueS *previous_residueSP; size_t previous_startI, previous_endI; int atom1_foundF, atom2_foundF; int n; VectorS C_vectorS; VectorS N_vectorS; /* Copy the number of residues in the current complex: */ residuesN = mol_complexSP->residuesN; /* Copy the number of atoms in the current complex: */ atomsN = mol_complexSP->atomsN; /* Scan residues, but skip the first one: */ for (residueI = 1; residueI < residuesN; residueI++) { /* Pointer to the current residue: */ residueSP = mol_complexSP->residueSP + residueI; /* The atomic index range for the current residue: */ startI = residueSP->residue_startI; endI = residueSP->residue_endI; /* Pointer to the first atom of the current residue: */ atomSP = mol_complexSP->atomSP + startI; /* Pointer to the previous residue (be sure */ /* that residueI never starts from zero!): */ previous_residueSP = mol_complexSP->residueSP + residueI - 1; /* The atomic index range for the previous residue: */ previous_startI = previous_residueSP->residue_startI; previous_endI = previous_residueSP->residue_endI; /* Editing of a single omega angle requested: */ if (runtimeSP->edit_single_bondF) { /* Reset flags: */ atom1_foundF = 0; atom2_foundF = 0; /* Check does the first atom belong to either the */ /* current residue or to the previous residue: */ if ((runtimeSP->atom1_arrayI >= startI) && (runtimeSP->atom1_arrayI <= endI )) { atom1_foundF = 1; } else if ((runtimeSP->atom1_arrayI >= previous_startI) && (runtimeSP->atom1_arrayI <= previous_endI )) { atom1_foundF = 1; } /* Check does the second atom belong to either */ /* the current residue or to the previous one: */ if ((runtimeSP->atom2_arrayI >= startI) && (runtimeSP->atom2_arrayI <= endI )) { atom2_foundF = 1; } else if ((runtimeSP->atom2_arrayI >= previous_startI) && (runtimeSP->atom2_arrayI <= previous_endI )) { atom2_foundF = 1; } /* Both atoms are required to specify the C-N bond: */ if ((atom1_foundF == 0) || (atom2_foundF == 0)) continue; } /* Editing of omega angles for all selected residues requested: */ else { /* If the first atom of the current residue is */ /* not selected, the residue is not selected: */ if (atomSP->selectedF == 0) continue; } /* The coordinates of the C atom of the previous residue: */ n = ExtractC_ (&C_vectorS, mol_complexSP->atomSP, previous_startI, previous_endI); if (n != 1) continue; /* The coordinates of the N atom of the current residue: */ n = ExtractN_ (&N_vectorS, mol_complexSP->atomSP, startI, endI); if (n != 1) continue; /* Rotate the current residue and all atoms */ /* after the current residue about C-N bond: */ for (atomI = startI; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ atomSP = mol_complexSP->atomSP + atomI; /* Rotate atom: */ RotateAtom_ (atomSP, &C_vectorS, &N_vectorS, delta_omega); } } /* Update dihedral angles and cis-trans flags: */ DihedralAngles_ (mol_complexSP, configSP); /* Return positive value (trivial): */ return 1; } /*===========================================================================*/ garlic-1.6/pdb_atom.c0000644000076500007650000002527307626762034015065 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2003 Damir Zucic */ /*============================================================================= pdb_atom.c Purpose: Parse the line (string) with atomic coordinates; store data to AtomS structure. ATOM or HETATM line is expected as input. This function contains detailed format specification for lines with atomic data. If updating garlic program for the newer version of PDB format, modify this function. Check AtomS definition in typedefs.h file and all functions which use atomic data. Add some data if necessary but try to avoid removal or change of original data. Input: (1) Pointer to AtomS structure, where atomic data will be stored. (2) Input line (string), read from PDB file. Output: (1) Data stored to AtomS structure. (2) Return value. Return value: (1) Positive on success. (3) Negative on failure. Notes: (1) The first character in PDB line has index 1 (one). The C programming language has 0 (zero) as the index of the first array element. Therefore each position listed in this file is shifted for one compared to indices from PDB specification: C_language_index = PDB_column_index - 1 (2) PDB format has certain drawbacks: the width of the field for atom serial number is too small, so the format may be changed soon (Damir Zucic, Feb 18, 1999). (3) Some structures deposited at PDB (http://www.pdb.bnl.gov) are not compliant with the format specification used here! (4) The input line is taken into account if it is long enough to contain all fields preceding occupancy. If missing, occupancy and temperature factor are set to zero. ========includes:============================================================*/ #include #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ void ErrorMessage_ (char *, char *, char *, char *, char *, char *, char *); int ExtractField_ (char *, int, int, char *); void CopyPurified_ (char *, char *); /*======parse PDB ATOM or HETATM line:=======================================*/ int ParsePDBAtomicData_ (AtomS * atomSP, char *lineP) { /*=================================================================*/ /* PDB ATOM and HETATM tokens: ANSI C range: PDB range: */ /*=================================================================*/ static int atom_serial_start = 6; /* 7 ~ 11 */ static int atom_serial_end = 10; static int atom_name_start = 12; /* 13 ~ 16 */ static int atom_name_end = 15; static int chemical_symbol_start = 12; /* 13 ~ 14 */ static int chemical_symbol_end = 13; static int remoteness_ind_start = 14; /* 15 ~ 15 */ static int remoteness_ind_end = 14; static int branch_desig_start = 15; /* 16 ~ 16 */ static int branch_desig_end = 15; static int alt_location_start = 16; /* 17 ~ 17 */ static int alt_location_end = 16; static int residue_name_start = 17; /* 18 ~ 20 */ static int residue_name_end = 19; static int chainID_start = 21; /* 22 ~ 22 */ static int chainID_end = 21; static int residue_sequence_start = 22; /* 23 ~ 26 */ static int residue_sequence_end = 25; static int insertion_code_start = 26; /* 27 ~ 27 */ static int insertion_code_end = 26; static int x_start = 30; /* 31 ~ 38 */ static int x_end = 37; static int y_start = 38; /* 39 ~ 46 */ static int y_end = 45; static int z_start = 46; /* 47 ~ 54 */ static int z_end = 53; static int occupancy_start = 54; /* 55 ~ 60 */ static int occupancy_end = 59; static int temperature_factor_start = 60; /* 61 ~ 66 */ static int temperature_factor_end = 65; static int segmentID_start = 72; /* 73 ~ 76 */ static int segmentID_end = 75; static int element_symbol_start = 76; /* 77 ~ 78 */ static int element_symbol_end = 77; static int charge_start = 78; /* 79 ~ 80 */ static int charge_end = 79; /* Other auxiliary variables: */ int line_length; char substringA[STRINGSIZE]; int int_value; double double_value; int error_messagesN = 0; int n; /* Store the line length to avoid repeated calls of strlen: */ line_length = strlen (lineP); /* Remove the trailing newline, if present: */ if (*(lineP + line_length - 1) == '\n') { *(lineP + line_length - 1) = '\0'; line_length--; } /* Check the line length; if too short, return: */ /* Note: the line which does not contain */ /* three coordinates is not a good line! */ if (line_length < z_end + 1) return -1; /* Some entries may be missing; initialize all data: */ atomSP->raw_atomS.serialI = 0; *atomSP->raw_atomS.atom_nameA = '\0'; *atomSP->raw_atomS.pure_atom_nameA = '\0'; *atomSP->raw_atomS.chemical_symbolA = '\0'; atomSP->raw_atomS.remoteness_indicator = ' '; atomSP->raw_atomS.branch_designator = ' '; atomSP->raw_atomS.alt_location = ' '; *atomSP->raw_atomS.residue_nameA = '\0'; *atomSP->raw_atomS.pure_residue_nameA = '\0'; atomSP->raw_atomS.chainID = ' '; atomSP->raw_atomS.residue_sequenceI = 0; atomSP->raw_atomS.residue_insertion_code = ' '; atomSP->raw_atomS.x[0] = 0.0; atomSP->raw_atomS.y = 0.0; atomSP->raw_atomS.z[0] = 0.0; atomSP->raw_atomS.occupancy = 1.0; atomSP->raw_atomS.temperature_factor = 0.0; *atomSP->raw_atomS.segmentA = '\0'; *atomSP->raw_atomS.elementA = '\0'; *atomSP->raw_atomS.pure_elementA = '\0'; *atomSP->raw_atomS.chargeA = '\0'; /* Atom serial number: */ ExtractField_ (substringA, atom_serial_start, atom_serial_end, lineP); if (sscanf (substringA, "%d", &int_value) != 1) { int_value = 0; } atomSP->raw_atomS.serialI = int_value; /* Atom name (including spaces): */ ExtractField_ (atomSP->raw_atomS.atom_nameA, atom_name_start, atom_name_end, lineP); /* Purified atom name (spaces removed): */ CopyPurified_ (atomSP->raw_atomS.pure_atom_nameA, atomSP->raw_atomS.atom_nameA); /* Chemical symbol: */ ExtractField_ (atomSP->raw_atomS.chemical_symbolA, chemical_symbol_start, chemical_symbol_end, lineP); /* Chemical symbol should be clean and right justified. However, */ /* the symbol for hydrogen (and perhaps some other atoms) may be */ /* preceded by a single digit. Check the first character of the */ /* chemical symbol. If a digit is found, replace it by space. */ n = atomSP->raw_atomS.chemical_symbolA[0]; if (isdigit (n)) { atomSP->raw_atomS.chemical_symbolA[0] = ' '; } /* Remoteness indicator (transliterated Greek letter): */ ExtractField_ (substringA, remoteness_ind_start, remoteness_ind_end, lineP); atomSP->raw_atomS.remoteness_indicator = *substringA; /* Branch designator: */ ExtractField_ (substringA, branch_desig_start, branch_desig_end, lineP); atomSP->raw_atomS.branch_designator = *substringA; /* Alternate location indicator: */ ExtractField_ (substringA, alt_location_start, alt_location_end, lineP); atomSP->raw_atomS.alt_location = *substringA; /* Residue name (with spaces): */ ExtractField_ (atomSP->raw_atomS.residue_nameA, residue_name_start, residue_name_end, lineP); /* Purified residue name (spaces removed): */ CopyPurified_ (atomSP->raw_atomS.pure_residue_nameA, atomSP->raw_atomS.residue_nameA); /* Chain identifier: */ ExtractField_ (substringA, chainID_start, chainID_end, lineP); atomSP->raw_atomS.chainID = *substringA; /* Residue sequence number: */ ExtractField_ (substringA, residue_sequence_start, residue_sequence_end, lineP); if (sscanf (substringA, "%d", &int_value) != 1) { int_value = 0; } atomSP->raw_atomS.residue_sequenceI = int_value; /* Insertion code: */ ExtractField_ (substringA, insertion_code_start, insertion_code_end, lineP); atomSP->raw_atomS.residue_insertion_code = *substringA; /* Atom x coordinate: */ ExtractField_ (substringA, x_start, x_end, lineP); if (sscanf (substringA, "%lf", &double_value) != 1) { error_messagesN++; if (error_messagesN > MAXMESSAGES) return -2; ErrorMessage_ ("garlic", "ParsePDBAtomicData_", "", "Failed to extract x coordinate!\n", "", "", ""); return -2; } atomSP->raw_atomS.x[0] = double_value; /* Atom y coordinate: */ ExtractField_ (substringA, y_start, y_end, lineP); if (sscanf (substringA, "%lf", &double_value) != 1) { error_messagesN++; if (error_messagesN > MAXMESSAGES) return -3; ErrorMessage_ ("garlic", "ParsePDBAtomicData_", "", "Failed to extract y coordinate!\n", "", "", ""); return -3; } atomSP->raw_atomS.y = double_value; /* Atom z coordinate: */ ExtractField_ (substringA, z_start, z_end, lineP); if (sscanf (substringA, "%lf", &double_value) != 1) { error_messagesN++; if (error_messagesN > MAXMESSAGES) return -4; ErrorMessage_ ("garlic", "ParsePDBAtomicData_", "", "Failed to extract z coordinate!\n", "", "", ""); return -4; } atomSP->raw_atomS.z[0] = double_value; /*------the following fields may be missing in some files:-------------------*/ /* Occupancy: */ if (line_length < occupancy_end + 1) return 1; ExtractField_ (substringA, occupancy_start, occupancy_end, lineP); if (sscanf (substringA, "%lf", &double_value) != 1) { double_value = 0.0; } atomSP->raw_atomS.occupancy = double_value; /* Isotropic temperature factor: */ if (line_length < temperature_factor_end + 1) return 2; ExtractField_ (substringA, temperature_factor_start, temperature_factor_end, lineP); if (sscanf (substringA, "%lf", &double_value) != 1) { double_value = 0.00; } atomSP->raw_atomS.temperature_factor = double_value; /* Segment identifier: */ if (line_length < segmentID_end + 1) return 3; ExtractField_ (atomSP->raw_atomS.segmentA, segmentID_start, segmentID_end, lineP); /* Element symbol: */ if (line_length < element_symbol_end + 1) return 4; ExtractField_ (atomSP->raw_atomS.elementA, element_symbol_start, element_symbol_end, lineP); /* Purified element symbol (spaces removed): */ CopyPurified_ (atomSP->raw_atomS.pure_elementA, atomSP->raw_atomS.elementA); /* Charge: */ if (line_length < charge_end + 1) return 5; ExtractField_ (atomSP->raw_atomS.chargeA, charge_start, charge_end, lineP); return 6; } /*===========================================================================*/ garlic-1.6/weighted_hydrophobicity.c0000644000076500007650000000651010445763457020214 0ustar zuciczucic00000000000000/* Copyright (C) 2006 Damir Zucic */ /*============================================================================= weighted_hydrophobicity.c Purpose: Calculate the (average) weighted hydrophobicity. Input: (1) Pointer to the storage where the minimal weighted hydrophobicity will be stored. (2) Pointer to the storage where the maximal weighted hydrophobicity will be stored. (3) Pointer to RuntimeS structure. Output: (1) Weighted hydrophobicity calculated and stored. (2) Return value. Return value: (1) Positive on success. (2) Negative on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======calculate the weighted hydrophobicity:===============================*/ int WeightedHydrophobicity_ (double *min_valueP, double *max_valueP, RuntimeS *runtimeSP) { int residuesN, residueI; /* Do not use size_t instead of int ! */ int used_residuesN; static int window_width = 11, half_window_width = 5; static double weightA[11] = {+1.0, +1.0, +1.0, +1.0, +1.0, 0.0, -1.0, -1.0, -1.0, -1.0, -1.0}; int windowI, combinedI; double hydrophobicity, weighted_hydrophobicity = 0; /*------prepare some parameters:---------------------------------------------*/ /* The number of residues in sequence buffer: */ residuesN = (int) runtimeSP->residuesN; if (residuesN == 0) return -1; /*------calculate the weighted hydrophobicity:--------------------------------*/ /* Initialize the extreme values: */ *min_valueP = +999999.0; *max_valueP = -999999.0; /* Scan the sequence: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Reset the number of residues used for weighting: */ used_residuesN = 0; /* Reset the weighted hydrophobicity: */ weighted_hydrophobicity = 0.0; /* Scan the sliding window: */ for (windowI = 0; windowI < window_width; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI - half_window_width + windowI; if (combinedI < 0) continue; if (combinedI >= residuesN) continue; /* The hydrophobicity of the residue defined by combinedI: */ hydrophobicity = (double) *(runtimeSP->hydrophobicityP + combinedI); /* Update the weighted hydrophobicity: */ weighted_hydrophobicity += hydrophobicity * weightA[windowI]; /* Increase the number of residues used for averaging: */ used_residuesN++; } /* Check how many residues were used: */ if (used_residuesN == window_width) { weighted_hydrophobicity /= (double) window_width; } else weighted_hydrophobicity = 0.0; /* Store the weighted hydrophobicity: */ *(runtimeSP->weighted_hydrophobicityP + residueI) = weighted_hydrophobicity; /* Dummy values should not be used to determine extremes: */ if (used_residuesN != window_width) continue; /* Find the extreme values: */ if (weighted_hydrophobicity < *min_valueP) { *min_valueP = weighted_hydrophobicity; } if (weighted_hydrophobicity > *max_valueP) { *max_valueP = weighted_hydrophobicity; } /* End of residueI loop: */ } /*---------------------------------------------------------------------------*/ return 1; } /*===========================================================================*/ garlic-1.6/docking.xpm0000644000076500007650000000564107303426313015262 0ustar zuciczucic00000000000000/* XPM */ static char *docking_xpm[] = { /* width height num_colors chars_per_pixel */ "48 48 17 1", /* Colors: */ " c None", ". c #56563F3F4848", "X c #71715C5C5C5C", "o c #97977D7D7C7C", "O c #A9A992928F8F", "+ c #BCBCA4A4A8A8", "@ c #CDCDA4A4A8A8", "# c #E9E9D4D4E6E6", "$ c #FEFEFEFEFCFC", "% c #B8B893939B9B", "& c #A6A683837979", "* c #969668685454", "= c #90904C4C3131", "- c #4A4A1D1D1B1B", "; c #959555552F2F", ": c #737348483131", "> c #747434340E0E", /* Pixels: */ " ", " ", " ", " .XoO+@@OOoO+@@#$$#@+%%O%%%%O% ", " .Xoo+@@+ooO+@#$##@@+%+%OO+O%OO ", " .ooO+@@+OoO%@###@+@+++%OOOOOO+ ", " .Xoo+@@OooO+@#@+O+@@@@++OO&OOO ", " .XooO+@@Ooo&@@@+O%+@@##@+%%&o&O ", " .oXXOO++&**o+@+o&+@#####@%O&OOO ", " .o*X*o*Oo*=&OOo*o%@#$$$##+OO&OO ", " .*o*XX****.****o&O@#$$$$#OO&o&o ", " .*o**====-;=:*X*o&@#$$$$@+OOOO& ", " .o**=::>==.=;**X*&+@#$##+OOOOo ", " .X***;>=;:==::***o%+@@+@+o&OOO ", " -Xo&%*>*=>=.>:X*;*oO@++OOOOOO ", " .o@+*=;=->>.>:XX*oOOO&ooO%%O ", " -o@&;>:>>>->>::XXX*oXoOOO%O ", " .X:>>>>->>>->=:.XX**o&o&O ", " -.:>->;>.>>>=**=:X*ooooo% ", " %:X:>->=>=;**&Oooo**o&% ", " %o%o=;**&**;X:*ooooo* ", " &%&%&%&o&o*o*oo ", " ", " ", " &o*o*o*ooo ", " &%&%&%&o&o*o*oo ", " %o%o=;**&**;X:*ooooo* ", " %:X:>->=>=;**&Oooo**o&% ", " -.:>->;>.>>>=**=:X*ooooo% ", " .X:>>>>->>>->=:.XX**o&o&O ", " -o@&;>:>>>->>::XXX*oXoOOO%O ", " .o@+*=;=->>.>:XX*oOOO&ooO%%O ", " -Xo&%*>*=>=.>:X*;*oO@++OOOOOO ", " .X***;>=;:==::***o%+@@+@+o&OOO ", " .o**=::>==.=;**X*&+@#$##+OOOOo ", " .*o**====-;=:*X*o&@#$$$$@+OOOO& ", " .*o*XX****.****o&O@#$$$$#OO&o&o ", " .o*X*o*Oo*=&OOo*o%@#$$$##+OO&OO ", " .oXXOO++&**o+@+o&+@#####@%O&OOO ", " .XooO+@@Ooo&@@@+O%+@@##@+%%&o&O ", " .Xoo+@@OooO+@#@+O+@@@@++OO&OOO ", " .ooO+@@+OoO%@###@+@+++%OOOOOO+ ", " .Xoo+@@+ooO+@#$##@@+%+%OO+O%OO ", " .XoO+@@OOoO+@@#$$#@+%%O%%%%O% ", " .XooO@@+OOO+@@#####@++O%++O&* ", " ", " ", " "}; garlic-1.6/adrenaline.pdb0000644000076500007650000000407207424035745015715 0ustar zuciczucic00000000000000HETATM 1 C 1 -2.935 -0.944 0.179 1.00 0.00 HETATM 2 C 1 -1.582 -1.307 0.179 1.00 0.00 HETATM 3 C 1 -0.584 -0.326 0.179 1.00 0.00 HETATM 4 C 1 -0.948 1.026 0.178 1.00 0.00 HETATM 5 C 1 -2.300 1.390 0.173 1.00 0.00 HETATM 6 C 1 -3.294 0.407 0.173 1.00 0.00 HETATM 7 O 1 -4.609 0.762 0.171 1.00 0.00 HETATM 8 O 1 -3.898 -1.907 0.182 1.00 0.00 HETATM 9 C 1 0.858 -0.789 0.182 1.00 0.00 HETATM 10 C 1 1.870 0.357 -0.026 1.00 0.00 HETATM 11 N 1 3.225 -0.209 -0.113 1.00 0.00 HETATM 12 C 1 4.220 0.849 -0.336 1.00 0.00 HETATM 13 H 1 -1.308 -2.362 0.181 1.00 0.00 HETATM 14 H 1 -0.194 1.811 0.181 1.00 0.00 HETATM 15 H 1 -2.578 2.444 0.171 1.00 0.00 HETATM 16 H 1 -4.973 0.649 -0.713 1.00 0.00 HETATM 17 H 1 -4.217 -2.039 1.082 1.00 0.00 HETATM 18 H 1 1.066 -1.271 1.137 1.00 0.00 HETATM 19 H 1 1.821 1.051 0.815 1.00 0.00 HETATM 20 H 1 1.639 0.883 -0.953 1.00 0.00 HETATM 21 H 1 3.443 -0.707 0.743 1.00 0.00 HETATM 22 H 1 4.201 1.556 0.493 1.00 0.00 HETATM 23 H 1 3.998 1.373 -1.265 1.00 0.00 HETATM 24 H 1 5.213 0.403 -0.406 1.00 0.00 HETATM 25 O 1 1.031 -1.751 -0.862 1.00 0.00 HETATM 26 H 1 0.837 -1.351 -1.716 1.00 0.00 garlic-1.6/rgbs_from_xcolor.c0000644000076500007650000000165407065474662016647 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= rgbs_from_xcolor.c Purpose: Copy RGB values from Xcolor structure to RGBS structure. Input: (1) Pointer to RGBS structure (output goes there). (2) Pointer to XColor structure (contains input data). Output: (1) Data stored to RGBS. Return value: No return value. =============================================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======copy RGB values from XColor to RGBS structure:=======================*/ void RGBSFromXColor_ (RGBS *rgbSP, XColor *colorSP) { rgbSP->red = colorSP->red; rgbSP->green = colorSP->green; rgbSP->blue = colorSP->blue; } /*===========================================================================*/ garlic-1.6/sp2_color.c0000644000076500007650000001251107465675154015200 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2002 Damir Zucic */ /*============================================================================= sp2_color.c Purpose: Prepare spacefill color, version 2. In this function white, left, middle, right and black color are used. Input: (1) Pointer to AtomS structure. (2) Pointer to GUIS structure. (3) Cosine of the angle between the vector from sphere center and the current pixel and the light source unit vector. It will be used to calculate the angle. Output: (1) Return value. Return value: The pixel (color) value. Notes: (1) This function may be quite slow (a lot of math). =============================================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======spacefill color:=====================================================*/ unsigned long Sp2Color_ (AtomS *curr_atomSP, GUIS *guiSP, double cos_angle) { static long double angle; static long double angle1 = 10.0, angle2 = 40.0; static long double angle3 = 80.0, angle4 = 130.0; static long double delta_angle; static long double w0 = 0.100000, w1 = 0.033333; static long double w2 = 0.025000, w3 = 0.020000; static unsigned long colorID; static unsigned long red_mask, green_mask, blue_mask; static unsigned long red1, red2, red; static unsigned long green1, green2, green; static unsigned long blue1, blue2, blue; static long double r1, r2, g1, g2, b1, b2; static long double r, g, b; /* Calculate the angle, in degrees: */ if (cos_angle <= -1.0) angle = 180.0; else if (cos_angle >= 1.0) angle = 0.0; else angle = RAD_TO_DEG * acos (cos_angle); /* Copy masks: */ red_mask = guiSP->visual_infoS.red_mask; green_mask = guiSP->visual_infoS.green_mask; blue_mask = guiSP->visual_infoS.blue_mask; /* Find sector and prepare color components: */ if (angle >= angle4) { return (guiSP->black_colorID); } else if (angle >= angle3) { /* Extract input color components: */ red1 = curr_atomSP->right_colorID & red_mask; red2 = guiSP->black_colorID & red_mask; green1 = curr_atomSP->right_colorID & green_mask; green2 = guiSP->black_colorID & green_mask; blue1 = curr_atomSP->right_colorID & blue_mask; blue2 = guiSP->black_colorID & blue_mask; /* Convert to doubles: */ r1 = (long double) red1; r2 = (long double) red2; g1 = (long double) green1; g2 = (long double) green2; b1 = (long double) blue1; b2 = (long double) blue2; /* Calculate new color components: */ delta_angle = angle - angle3; r = r1 + w3 * (r2 - r1) * delta_angle; g = g1 + w3 * (g2 - g1) * delta_angle; b = b1 + w3 * (b2 - b1) * delta_angle; } else if (angle >= angle2) { /* Extract input color components: */ red1 = curr_atomSP->middle_colorID & red_mask; red2 = curr_atomSP->right_colorID & red_mask; green1 = curr_atomSP->middle_colorID & green_mask; green2 = curr_atomSP->right_colorID & green_mask; blue1 = curr_atomSP->middle_colorID & blue_mask; blue2 = curr_atomSP->right_colorID & blue_mask; /* Convert to doubles: */ r1 = (long double) red1; r2 = (long double) red2; g1 = (long double) green1; g2 = (long double) green2; b1 = (long double) blue1; b2 = (long double) blue2; /* Calculate new color components: */ delta_angle = angle - angle2; r = r1 + w2 * (r2 - r1) * delta_angle; g = g1 + w2 * (g2 - g1) * delta_angle; b = b1 + w2 * (b2 - b1) * delta_angle; } else if (angle >= angle1) { /* Extract input color components: */ red1 = curr_atomSP->left_colorID & red_mask; red2 = curr_atomSP->middle_colorID & red_mask; green1 = curr_atomSP->left_colorID & green_mask; green2 = curr_atomSP->middle_colorID & green_mask; blue1 = curr_atomSP->left_colorID & blue_mask; blue2 = curr_atomSP->middle_colorID & blue_mask; /* Convert to doubles: */ r1 = (long double) red1; r2 = (long double) red2; g1 = (long double) green1; g2 = (long double) green2; b1 = (long double) blue1; b2 = (long double) blue2; /* Calculate new color components: */ delta_angle = angle - angle1; r = r1 + w1 * (r2 - r1) * delta_angle; g = g1 + w1 * (g2 - g1) * delta_angle; b = b1 + w1 * (b2 - b1) * delta_angle; } else { /* Extract input color components: */ red1 = guiSP->white_colorID & red_mask; red2 = curr_atomSP->left_colorID & red_mask; green1 = guiSP->white_colorID & green_mask; green2 = curr_atomSP->left_colorID & green_mask; blue1 = guiSP->white_colorID & blue_mask; blue2 = curr_atomSP->left_colorID & blue_mask; /* Convert to doubles: */ r1 = (long double) red1; r2 = (long double) red2; g1 = (long double) green1; g2 = (long double) green2; b1 = (long double) blue1; b2 = (long double) blue2; /* Calculate new color components: */ delta_angle = angle; r = r1 + w0 * (r2 - r1) * delta_angle; g = g1 + w0 * (g2 - g1) * delta_angle; b = b1 + w0 * (b2 - b1) * delta_angle; } /* Check new color components: */ if (r < 0.0) r = 0.0; if (g < 0.0) g = 0.0; if (b < 0.0) b = 0.0; /* Convert new color components: */ red = ((unsigned long) r) & red_mask; green = ((unsigned long) g) & green_mask; blue = ((unsigned long) b) & blue_mask; /* Combine new color components: */ colorID = red | green | blue; /* Return the pixel value: */ return colorID; } /*===========================================================================*/ garlic-1.6/.garlicrc0000644000076500007650000002176110364510522014703 0ustar zuciczucic00000000000000# Personal initialization file for garlic, free molecular viewer and editor. # Version 1.6. # Last modification: January 21, 2006. # Geometry of the main window. Use the keyword default, or specify the # geometry string (for example 780x560+10+10). main window geometry: default # Margins; used only if geometry string is not given. Geometry string may be # given through command line arguments. main window left margin: 50 pixels main window right margin: 50 pixels main window top margin: 50 pixels main window bottom margin: 70 pixels # Main font: main font: 10x20 # Main window cursor. If you don't like default cursor, replace it; read # the file /usr/include/X11/cursorfont.h ; remove the XC_ prefix to obtain # the cursor name. main window cursor: default # A small coordinate system may be displayed in the top left corner (yes/no): show coordinate system: yes # Control window (top right corner) may be visible or hidden (yes/no): show control window: yes # Sequence neighborhood of the residue under the pointer may be hidden, # visible and short or visible and verbose (no/yes/verbose): show sequence neighborhood: verbose # Stereo flag (yes/no): display stereo image: no # Parameters for stereo image: stereo internal margin (screen units): 10 pixels stereo angle: 5.0 degrees # Light source theta and phi angle (theta is defined with respect to z axis, # phi with respect to x axis: light source theta angle: 150 degrees light source phi angle: 225 degrees # Default slab mode (possible modes are off, planar, sphere, half-sphere, # cylinder and half-cylinder): default slab mode: planar # Default color fading mode (off, planar, sphere, half-sphere, cylinder and # half-cylinder): default color fading mode: planar # Default drawing style for atoms (0, 1, 2, 3, 4, 5, 6 or 7): default atom drawing style: 2 # Default drawing style for bonds (0, 1, 2, 3, 4 or 5): default bond drawing style: 3 # Default drawing style for backbone: default backbone drawing style: 5 # Window colors: main window background color: black main window foreground color: white text background color: black text foreground color: white # The number of color fading surfaces: number of color fading surfaces: 3 # Default colors for atoms and bonds. For each fading surface, three colors # should be specified. The surface index is a small integer following the # word color. The largest surface index is equal to: # (number of color fading surfaces) - 1, # which is in this case 2. Color may be changed at runtime, of course. # This choice of colors is equivalent to the color scheme COLD. left color 0: RGB:DDDD/FFFF/FFFF middle color 0: RGB:0000/FFFF/FFFF right color 0: RGB:0000/8888/FFFF left color 1: RGB:0000/8888/FFFF middle color 1: RGB:0000/0000/FFFF right color 1: RGB:0000/0000/8888 left color 2: RGB:0000/0000/8888 middle color 2: RGB:0000/0000/4444 right color 2: RGB:0000/0000/2222 # Default color schemes for molecular surfaces. Choose from this list: # red, green, blue, cyan, magenta, yellow, white, orange, # cyan-blue, cyan-green, yellow-green, magenta-blue, magenta-red, # orange-yellow, orange-red. Do not use the following color schemes: # hot, cold, monochrome, cpk, zebra, chain, hyphob and model. surface outer color scheme: magenta surface inner color scheme: blue # Rotation steps. Normal steps is used if numeric key is pressed without # any modifier. Large step is selected by holding [shift] while pressing # the key, and very large step is selected by using both [alt] and [shift]. # Small step is selected by holding [control] while pressing the key, and # very small step by using both [alt] and [control]. rotations steps: 0.2 1.0 5.0 30.0 90.0 # Five translation steps (very small, small, normal, large and very large). # Use angstrom units. translation steps: 0.2 1.0 5.0 25.0 100.0 # Five slab steps (very small, small, normal, large and very large). # Use angstrom units. slab steps: 0.2 1.0 5.0 20.0 80.0 # Five fading steps (very small, small, normal, large and very large). # Use angstrom units. fading steps: 0.2 1.0 5.0 20.0 80.0 # Window size limits: used only if screen width and/or height are larger # than values specified here. By default, screen width and height are used. maximal main window width: 3000 pixels maximal main window height: 2500 pixels # The nearest line (bond) thickness; used only if drawing bonds as lines # and line thickness is used for perspective. the nearest line thickness: 5 pixels # Screen dimensions and position of garlic user in real world. Use realistic # values. Do not change units (mm). Strange values may cause image distortions. screen width in real world: 270 millimeters screen height in real world: 195 millimeters distance between user and screen in real world: 500 millimeters # Scaling information: used to scale user and screen down to atomic scale. # Only screen width is required, in angstrom units. screen width in atomic world: 1.0 angstroms # User z coordinate in atomic coordinate system. It must be negative # and absolute value should be quite large. The x axis points to the right, # y axis downward and z axis in direction opposite to observers direction. user position in atomic coordinate system: -150.0 angstroms # Maximal bond length is used to check which atoms and bonds are invisible. # It is assumed that there are no atoms with radius larger than this length. maximal bond length: 2.3 angstroms # Crude limits for bond lengths. No distinction between N-CA and C-N is made. # Use angstrom units. Be tolerant, there are many bad structures around. # Generic bond length is used for atomic pairs which are not recognized. approximate C-C bond length: from 1.3 to 1.8 angstroms approximate C-N bond length: from 1.0 to 1.7 angstroms approximate C-O bond length: from 1.0 to 1.7 angstroms approximate C-S bond length: from 1.4 to 2.1 angstroms approximate C-H bond length: from 0.8 to 1.2 angstroms approximate N-O bond length: from 1.2 to 1.7 angstroms approximate N-H bond length: from 0.9 to 1.3 angstroms approximate O-H bond length: from 0.7 to 1.3 angstroms approximate S-H bond length: from 0.9 to 1.6 angstroms approximate O-P bond length: from 1.2 to 1.8 angstroms approximate S-S bond length: from 1.8 to 2.3 angstroms generic bond length: from 0.8 to 2.0 angstroms hydrogen bond length: from 2.0 to 5.0 angstroms # Hydrogen bond C-O...N angle range (obsolete since version 1.3!): hydrogen bond C-O...N angle: from 125 to 180 degrees # The upper limit for CA-CA distance for neighbouring residues. Used to # draw backbone, connection neighbouring CA atoms. maximal CA-CA distance: 4.1 angstroms # Atomic radii, used for spacefill style. 70% of van der Waals radius may be # a good choice. hydrogen radius: 0.70 angstroms carbon radius: 1.20 angstroms nitrogen radius: 1.05 angstroms oxygen radius: 1.00 angstroms sulfur radius: 1.25 angstroms phosphorus radius: 1.25 angstroms generic radius: 1.40 angstroms # Covalent atomic radii, used for covalent style. hydrogen covalent radius: 0.30 angstroms carbon covalent radius: 0.77 angstroms nitrogen covalent radius: 0.70 angstroms oxygen covalent radius: 0.66 angstroms sulfur covalent radius: 1.04 angstroms phosphorus covalent radius: 1.10 angstroms generic covalent radius: 1.20 angstroms # Small atomic radii. 70% of covalent radius may be a good choice. hydrogen small radius: 0.21 angstroms carbon small radius: 0.54 angstroms nitrogen small radius: 0.49 angstroms oxygen small radius: 0.46 angstroms sulfur small radius: 0.73 angstroms phosphorus small radius: 0.77 angstroms generic small radius: 0.84 angstroms # Van der Waals radii. hydrogen van der Waals radius: 1.00 angstroms carbon van der Waals radius: 1.70 angstroms nitrogen van der Waals radius: 1.50 angstroms oxygen van der Waals radius: 1.40 angstroms sulfur van der Waals radius: 1.80 angstroms phosphorus van der Waals radius: 1.80 angstroms generic van der Waals radius: 2.00 angstroms # Default ball radius (used to draw atoms as balls of equal size): default ball radius: 0.40 angstroms # Default bond probe radius, used to draw nice bonds with curved surfaces: default bond probe radius: 0.80 angstroms # Default stick radius, used to draw bonds as sticks: default stick radius: 0.15 angstroms # For a given atom, the chemical bonds are identified by inspecting # distances to the neighboring atoms. The array with atomic data should # be scanned in forward and backward direction (with respect to the given atom) # to find which atoms are bound to the given atom. The following parameters # define how many neighboring atoms should be checked in each direction. number of bond candidates: 50 before and 50 after the given atom # Blur rectangle width and height (default values). Bluring is used to reduce # the contrast. The color of the pixel in the center of the rectangle is # calculated by averaging the colors of all pixels in the rectangle. Both # values should be positive integers. blur rectangle width: 3 blur rectangle height: 3 garlic-1.6/write_line.c0000644000076500007650000001372707612775050015437 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2003 Damir Zucic */ /*============================================================================= write_line.c Purpose: Write a single line to output file. PDB format version 2.1 is used as the output format. Input: (1) Pointer to the output file. (1) Pointer to RawAtomS structure, with raw atomic data. Output: (1) Data written to file. (2) Return value. Return value: (1) Positive always (trivial). Notes: (1) Some columns (positions in line) are unused in PDB format. For that reason it is important to remove the terminal zeros for most characters! For simplicity, zero was removed everywhere. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======write line to output file:===========================================*/ int WriteLine_ (FILE *fileP, RawAtomS *raw_atomSP) { /*=================================================================*/ /* PDB ATOM and HETATM tokens: ANSI C range: PDB range: */ /*=================================================================*/ static int atom_serial_start = 6; /* 7 ~ 11 */ static int atom_serial_end = 10; static int atom_name_start = 12; /* 13 ~ 16 */ static int atom_name_end = 15; static int chemical_symbol_start = 12; /* 13 ~ 14 */ static int chemical_symbol_end = 13; static int remoteness_ind_start = 14; /* 15 ~ 15 */ static int remoteness_ind_end = 14; static int branch_desig_start = 15; /* 16 ~ 16 */ static int branch_desig_end = 15; static int alt_location_start = 16; /* 17 ~ 17 */ static int alt_location_end = 16; static int residue_name_start = 17; /* 18 ~ 20 */ static int residue_name_end = 19; static int chainID_start = 21; /* 22 ~ 22 */ static int chainID_end = 21; static int residue_sequence_start = 22; /* 23 ~ 26 */ static int residue_sequence_end = 25; static int insertion_code_start = 26; /* 27 ~ 27 */ static int insertion_code_end = 26; static int x_start = 30; /* 31 ~ 38 */ static int z_end = 53; static int occupancy_start = 54; /* 55 ~ 60 */ static int occupancy_end = 59; static int temperature_factor_start = 60; /* 61 ~ 66 */ static int temperature_factor_end = 65; static int segmentID_start = 72; /* 73 ~ 76 */ static int segmentID_end = 75; static int element_symbol_start = 76; /* 77 ~ 78 */ static int element_symbol_end = 77; static int charge_start = 78; /* 79 ~ 80 */ int i; char stringA[STRINGSIZE]; char *currP; /* Fill line with 80 spaces: */ for (i = 0; i < 80; i++) stringA[i] = ' '; /* The first token should be "ATOM " or "HETATM": */ currP = stringA; if (raw_atomSP->heteroF) strncpy (stringA, "HETATM", 6); else strncpy (stringA, "ATOM ", 6); *(stringA + 6) = ' '; /* The second token should be the atom serial number: */ currP = stringA + atom_serial_start; sprintf (currP, "%5d", raw_atomSP->serialI); *(stringA + atom_serial_end + 1) = ' '; /* Atom name: */ currP = stringA + atom_name_start; sprintf (currP, "%-4.4s", raw_atomSP->atom_nameA); *(stringA + atom_name_end + 1) = ' '; /* Chemical symbol: */ currP = stringA + chemical_symbol_start; sprintf (currP, "%-2.2s", raw_atomSP->chemical_symbolA); *(stringA + chemical_symbol_end + 1) = ' '; /* Remoteness indicator: */ currP = stringA + remoteness_ind_start; sprintf (currP, "%c", raw_atomSP->remoteness_indicator); *(stringA + remoteness_ind_end + 1) = ' '; /* Branch designator: */ currP = stringA + branch_desig_start; sprintf (currP, "%c", raw_atomSP->branch_designator); *(stringA + branch_desig_end + 1) = ' '; /* Alternate location indicator: */ currP = stringA + alt_location_start; sprintf (currP, "%c", raw_atomSP->alt_location); *(stringA + alt_location_end + 1) = ' '; /* Residue name: */ currP = stringA + residue_name_start; sprintf (currP, "%-3.3s", raw_atomSP->residue_nameA); *(stringA + residue_name_end + 1) = ' '; /* Chain identifier: */ currP = stringA + chainID_start; sprintf (currP, "%c", raw_atomSP->chainID); *(stringA + chainID_end + 1) = ' '; /* Residue sequence number: */ currP = stringA + residue_sequence_start; sprintf (currP, "%4d", raw_atomSP->residue_sequenceI); *(stringA + residue_sequence_end + 1) = ' '; /* Insertion code for residues: */ currP = stringA + insertion_code_start; sprintf (currP, "%c", raw_atomSP->residue_insertion_code); *(stringA + insertion_code_end + 1) = ' '; /* The coordinates x, y and z: */ currP = stringA + x_start; sprintf (currP, "%8.3f%8.3f%8.3f", raw_atomSP->x[0], raw_atomSP->y, raw_atomSP->z[0]); *(stringA + z_end + 1) = ' '; /* Occupancy: */ currP = stringA + occupancy_start; sprintf (currP, "%6.2f", raw_atomSP->occupancy); *(stringA + occupancy_end + 1) = ' '; /* Temperature factor: */ currP = stringA + temperature_factor_start; sprintf (currP, "%6.2f", raw_atomSP->temperature_factor); *(stringA + temperature_factor_end + 1) = ' '; /* Segment identifier: */ currP = stringA + segmentID_start; sprintf (currP, "%-4.4s", raw_atomSP->segmentA); *(stringA + segmentID_end + 1) = ' '; /* Element symbol: */ currP = stringA + element_symbol_start; sprintf (currP, "%-2.2s", raw_atomSP->elementA); *(stringA + element_symbol_end + 1) = ' '; /* Charge: */ currP = stringA + charge_start; sprintf (currP, "%-2.2s", raw_atomSP->chargeA); /* Print line to file: */ fprintf (fileP, "%s\n", stringA); /* Return positive value: */ return 1; } /*===========================================================================*/ garlic-1.6/headerline.c0000644000076500007650000000574107065471411015367 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= headerline.c Purpose: Check the input line; if recognized as mandatory record, copy the line to HeaderS structure, which is member of MolComplexS structure. The trailing newline is removed (if present at all). The PDB header contains, among others, a keyword called HEADER. Don't get confused with the usage of word "header"! Input: (1) Pointer to HeaderS structure, where line should be added if recognized as mandatory record. (2) Input line. (3) The first character in the line. Output: (1) If line is mandatory, it will be added to HeaderS structure. (2) Return value. Return value: (1) Positive if line added to HeaderS structure. (2) Zero if line does not contain mandatory record. (3) Negative if line does contain mandatory record, but the maximal number of records of this type is reached already. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======check line, copy it if contains mandatory record:====================*/ int CopyHeaderLine_ (HeaderS *hSP, char *lineP, int first_char) { char *P; P = hSP->dataP; /* Check is there a mandatory record in input line: */ switch (first_char) { case 'H': if (strstr (lineP, "HEADER") != lineP) return 0; if (hSP->header_linesN >= MAXHEADERLINES) return -1; hSP->header_linesN++; P += hSP->header_offset + hSP->header_linesN * HEADERLINESIZE; break; case 'T': if (strstr (lineP, "TITLE") != lineP) return 0; if (hSP->title_linesN >= MAXTITLELINES) return -2; hSP->title_linesN++; P += hSP->title_offset + hSP->title_linesN * HEADERLINESIZE; break; case 'C': if (strstr (lineP, "COMPND") != lineP) return 0; if (hSP->compnd_linesN >= MAXCOMPNDLINES) return -3; hSP->compnd_linesN++; P += hSP->compnd_offset + hSP->compnd_linesN * HEADERLINESIZE; break; case 'S': if (strstr (lineP, "SOURCE") != lineP) return 0; if (hSP->source_linesN >= MAXSOURCELINES) return -4; hSP->source_linesN++; P += hSP->source_offset + hSP->source_linesN * HEADERLINESIZE; break; case 'E': if (strstr (lineP, "EXPDTA") != lineP) return 0; if (hSP->expdta_linesN >= MAXEXPDTALINES) return -5; hSP->expdta_linesN++; P += hSP->expdta_offset + hSP->expdta_linesN * HEADERLINESIZE; break; case 'A': if (strstr (lineP, "AUTHOR") != lineP) return 0; if (hSP->author_linesN >= MAXAUTHORLINES) return -6; hSP->author_linesN++; P += hSP->author_offset + hSP->author_linesN * HEADERLINESIZE; break; default: return 0; } /* If this point is reached, line contains mandatory record - copy it: */ strncpy (P, lineP, HEADERLINESIZE - 1); *(P + HEADERLINESIZE - 1) = '\0'; return 1; } /*===========================================================================*/ garlic-1.6/set_phi.c0000644000076500007650000001153107414072133014710 0ustar zuciczucic00000000000000/* Copyright (C) 2001 Damir Zucic */ /*============================================================================= set_phi.c Purpose: Set the phi angle for each selected residue in the specified complex. A residue is treated as selected if the first atom of this residue is selected. For proteins, this is typically the N atom (nitrogen). Input: (1) Pointer to MolComplexS structure. (2) Pointer to ConfigS structure. (3) The phi angle in degrees. Output: (1) Phi angle set for each selected residue in each caught complex. (2) Return value. Return value: (1) Positive always (trivial). Notes: (1) This function uses only the main chain atoms to calculate the phi angle. The coordinates of H atoms are not used. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int ExtractNCAC_ (VectorS *, VectorS *, VectorS *, AtomS *, size_t, size_t); int ExtractC_ (VectorS *, AtomS *, size_t, size_t); double PhiFromCNCAC_ (VectorS *, VectorS *, VectorS *, VectorS *, ConfigS *); int RotateAtom_ (AtomS *, VectorS *, VectorS *, double); int DihedralAngles_ (MolComplexS *, ConfigS *); /*======set phi angle(s):====================================================*/ int SetPhi_ (MolComplexS *mol_complexSP, ConfigS *configSP, double phi_new) { int residuesN, residueI; size_t atomsN, atomI; ResidueS *current_residueSP; AtomS *first_atomSP; size_t current_startI, current_endI; int n; static VectorS N_vectorS, CA_vectorS, C_vectorS; ResidueS *previous_residueSP; size_t previous_startI, previous_endI; static VectorS previousC_vectorS; double phi_old, delta_phi; AtomS *atomSP; /* Copy the number of residues in the specified complex: */ residuesN = mol_complexSP->residuesN; /* Copy the number of atoms in the specified complex: */ atomsN = mol_complexSP->atomsN; /* Scan residues, but skip the first one: */ for (residueI = 1; residueI < residuesN; residueI++) { /* Pointer to the current residue: */ current_residueSP = mol_complexSP->residueSP + residueI; /* Pointer to the first atom of this residue: */ first_atomSP = mol_complexSP->atomSP + current_residueSP->residue_startI; /* If the first atom of this residue is not */ /* selected, the residue is not selected: */ if (first_atomSP->selectedF == 0) continue; /* The range of atomic indices for the current residue: */ current_startI = current_residueSP->residue_startI; current_endI = current_residueSP->residue_endI; /* Try to extract N, CA and C coordinates for the current residue: */ n = ExtractNCAC_ (&N_vectorS, &CA_vectorS, &C_vectorS, mol_complexSP->atomSP, current_startI, current_endI); if (n < 3) continue; /* The C atom of the previous residue is required. */ /* Pointer to the previous residue: */ previous_residueSP = mol_complexSP->residueSP + residueI - 1; /* The atomic index range for the previous residue: */ previous_startI = previous_residueSP->residue_startI; previous_endI = previous_residueSP->residue_endI; /* Try to extract the C atom from the previous residue: */ n = ExtractC_ (&previousC_vectorS, mol_complexSP->atomSP, previous_startI, previous_endI); if (n < 1) break; /* Calculate and check the old phi: */ phi_old = PhiFromCNCAC_ (&previousC_vectorS, &N_vectorS, &CA_vectorS, &C_vectorS, configSP); if (phi_old == BADDIHEDANGLE) continue; /* Calculate the difference: */ delta_phi = phi_new - phi_old; /* Rotate all atoms of the current residue */ /* (except H, N and CA) about N-CA bond: */ for (atomI = current_startI; atomI <= current_endI; atomI++) { /* Pointer to the current atom: */ atomSP = mol_complexSP->atomSP + atomI; /* Do not rotate H, N and CA: */ if ((strcmp (atomSP->raw_atomS.pure_atom_nameA, "H") == 0) || (strcmp (atomSP->raw_atomS.pure_atom_nameA, "N") == 0) || (strcmp (atomSP->raw_atomS.pure_atom_nameA, "CA") == 0)) { continue; } /* Rotate the current atom about N-CA bond: */ RotateAtom_ (atomSP, &N_vectorS, &CA_vectorS, delta_phi); } /* Rotate all atoms after the current residue about N-CA bond: */ for (atomI = current_endI + 1; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ atomSP = mol_complexSP->atomSP + atomI; /* Rotate atom: */ RotateAtom_ (atomSP, &N_vectorS, &CA_vectorS, delta_phi); } } /* Update dihedral angles and cis-trans flags: */ DihedralAngles_ (mol_complexSP, configSP); /* Set the position_changedF: */ mol_complexSP->position_changedF = 1; /* Return positive value (trivial): */ return 1; } /*===========================================================================*/ garlic-1.6/psi_from_ncacn.c0000644000076500007650000001040607315721614016242 0ustar zuciczucic00000000000000/* Copyright (C) 2000, 2001 Damir Zucic */ /*============================================================================= psi_from_ncacn.c Purpose: Calculate dihedral angle psi, using N[i], CA[i], C[i] and N[i+1]. Input: (1) Pointer to VectorS structure, with N atom coordinates. (2) Pointer to VectorS structure, with CA atom coordinates. (3) Pointer to VectorS structure, with C atom coordinates. (4) Pointer to VectorS structure, with N atom coordinates for the next residue. (5) Pointer to ConfigS structure. Output: Return value. Return value: (1) Dihedral angle psi, on success. (2) BADDIHEDANGLE on failure. Notes: (1) This should help you to understand phi and psi definitions: ........./................ | H * - * N | | \ phi1 = 180 | | * CA | residue 1 | / psi1 = 180 | | O * - * C | |........\...............| | N * - * H | | / phi2 = 180 | | CA * | residue 2 | \ psi2 = 180 | | C * - * O | |......../...............| ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ void VectorProduct_ (VectorS *, VectorS *, VectorS *); double AbsoluteValue_ (VectorS *); double ScalarProduct_ (VectorS *, VectorS *); /*======calculate psi from N[i], CA[i], C[i] and N[i+1]:=====================*/ double PsiFromNCACN_ (VectorS *N_vectorSP, VectorS *CA_vectorSP, VectorS *C_vectorSP, VectorS *nextN_vectorSP, ConfigS *configSP) { VectorS CA_N_vectorS, CA_C_vectorS; VectorS C_CA_vectorS, C_nextN_vectorS; double bond_length_squared; VectorS u1S, u2S; VectorS v1S, v2S; double denom, ratio; double alpha, psi; /* The first pair of auxiliary vectors: */ CA_N_vectorS.x = N_vectorSP->x - CA_vectorSP->x; CA_N_vectorS.y = N_vectorSP->y - CA_vectorSP->y; CA_N_vectorS.z = N_vectorSP->z - CA_vectorSP->z; CA_C_vectorS.x = C_vectorSP->x - CA_vectorSP->x; CA_C_vectorS.y = C_vectorSP->y - CA_vectorSP->y; CA_C_vectorS.z = C_vectorSP->z - CA_vectorSP->z; /* The second pair of auxiliary vectors: */ C_CA_vectorS.x = CA_vectorSP->x - C_vectorSP->x; C_CA_vectorS.y = CA_vectorSP->y - C_vectorSP->y; C_CA_vectorS.z = CA_vectorSP->z - C_vectorSP->z; C_nextN_vectorS.x = nextN_vectorSP->x - C_vectorSP->x; C_nextN_vectorS.y = nextN_vectorSP->y - C_vectorSP->y; C_nextN_vectorS.z = nextN_vectorSP->z - C_vectorSP->z; /* Check the distance between C and nextN: */ bond_length_squared = C_nextN_vectorS.x * C_nextN_vectorS.x + C_nextN_vectorS.y * C_nextN_vectorS.y + C_nextN_vectorS.z * C_nextN_vectorS.z; if (bond_length_squared < configSP->C_N_min_squared) return BADDIHEDANGLE; if (bond_length_squared > configSP->C_N_max_squared) return BADDIHEDANGLE; /* Two vectors perpendicular to CA_C_vectorS, mutually orthogonal, */ /* the second in the plane defined by CA_N_vectorS and CA_C_vectorS: */ VectorProduct_ (&u1S, &CA_N_vectorS, &CA_C_vectorS); VectorProduct_ (&u2S, &u1S, &CA_C_vectorS); /* Two vectors perpendicular to C_CA_vectorS, mutually orthogonal, the */ /* second in the plane defined by C_CA_vectorS and C_nextN_vectorS: */ VectorProduct_ (&v1S, &C_CA_vectorS, &C_nextN_vectorS); VectorProduct_ (&v2S, &C_CA_vectorS, &v1S); /* Calculate the angle alpha, which will be used to calculate psi: */ /* Avoid division by zero: */ denom = AbsoluteValue_ (&u1S) * AbsoluteValue_ (&v1S); if (denom == 0.0) return BADDIHEDANGLE; /* Use the scalar product to calculate the cosine of the angle: */ ratio = ScalarProduct_ (&u1S, &v1S) / denom; /* Arc cosine is very sensitive to floating point errors: */ if (ratio <= -1.0) alpha = 3.1415927; else if (ratio >= 1.0) alpha = 0.0; else alpha = acos (ratio); /* There are two possible solutions; the right one is resolved here: */ if (ScalarProduct_ (&v2S, &u1S) >= 0) psi = alpha; else psi = -alpha; /* Return the angle (in radians): */ return psi; } /*===========================================================================*/ garlic-1.6/psi_from_ncaco.c0000644000076500007650000000736607315722000016244 0ustar zuciczucic00000000000000/* Copyright (C) 2000, 2001 Damir Zucic */ /*============================================================================= psi_from_ncaco.c Purpose: Calculate dihedral angle psi, using N[i], CA[i], C[i] and O[i]. Input: (1) Pointer to VectorS structure, with N atom coordinates. (2) Pointer to VectorS structure, with CA atom coordinates. (3) Pointer to VectorS structure, with C atom coordinates. (4) Pointer to VectorS structure, with O atom coordinates. Output: Return value. Return value: (1) Dihedral angle psi, on success. (2) BADDIHEDANGLE on failure. Notes: (1) This should help you to understand phi and psi definitions: ........./................ | H * - * N | | \ phi1 = 180 | | * CA | residue 1 | / psi1 = 180 | | O * - * C | |........\...............| | N * - * H | | / phi2 = 180 | | CA * | residue 2 | \ psi2 = 180 | | C * - * O | |......../...............| ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ void VectorProduct_ (VectorS *, VectorS *, VectorS *); double AbsoluteValue_ (VectorS *); double ScalarProduct_ (VectorS *, VectorS *); /*======calculate psi from N[i], CA[i], C[i] and O[i]:=======================*/ double PsiFromNCACO_ (VectorS *N_vectorSP, VectorS *CA_vectorSP, VectorS *C_vectorSP, VectorS *O_vectorSP) { VectorS CA_N_vectorS, CA_C_vectorS; VectorS C_O_vectorS, C_CA_vectorS; VectorS u1S, u2S; VectorS v1S, v2S; double denom, ratio; double alpha, psi; /* The first pair of auxiliary vectors: */ CA_N_vectorS.x = N_vectorSP->x - CA_vectorSP->x; CA_N_vectorS.y = N_vectorSP->y - CA_vectorSP->y; CA_N_vectorS.z = N_vectorSP->z - CA_vectorSP->z; CA_C_vectorS.x = C_vectorSP->x - CA_vectorSP->x; CA_C_vectorS.y = C_vectorSP->y - CA_vectorSP->y; CA_C_vectorS.z = C_vectorSP->z - CA_vectorSP->z; /* The second pair of auxiliary vectors: */ C_O_vectorS.x = O_vectorSP->x - C_vectorSP->x; C_O_vectorS.y = O_vectorSP->y - C_vectorSP->y; C_O_vectorS.z = O_vectorSP->z - C_vectorSP->z; C_CA_vectorS.x = CA_vectorSP->x - C_vectorSP->x; C_CA_vectorS.y = CA_vectorSP->y - C_vectorSP->y; C_CA_vectorS.z = CA_vectorSP->z - C_vectorSP->z; /* Two vectors perpendicular to CA_C_vectorS, mutually orthogonal, */ /* the second in the plane defined by CA_N_vectorS and CA_C_vectorS: */ VectorProduct_ (&u1S, &CA_N_vectorS, &CA_C_vectorS); VectorProduct_ (&u2S, &u1S, &CA_C_vectorS); /* Two vectors perpendicular to C_CA_vectorS, mutually orthogonal, */ /* the second in the plane defined by C_O_vectorS and C_CA_vectorS: */ VectorProduct_ (&v1S, &C_O_vectorS, &C_CA_vectorS); VectorProduct_ (&v2S, &C_CA_vectorS, &v1S); /* Calculate the angle alpha, which will be used to calculate psi: */ /* Avoid division by zero: */ denom = AbsoluteValue_ (&u1S) * AbsoluteValue_ (&v1S); if (denom == 0.0) return BADDIHEDANGLE; /* Use the scalar product to calculate the cosine of the angle: */ ratio = ScalarProduct_ (&u1S, &v1S) / denom; /* Arc cosine is very sensitive to floating point errors: */ if (ratio <= -1.0) alpha = 3.1415927; else if (ratio >= 1.0) alpha = 0.0; else alpha = acos (ratio); /* There are two possible solutions; the right one is resolved here: */ if (ScalarProduct_ (&v2S, &u1S) >= 0) psi = alpha; else psi = -alpha; /* Return the angle (in radians): */ return psi; } /*===========================================================================*/ garlic-1.6/set_psi.c0000644000076500007650000001127607414073277014743 0ustar zuciczucic00000000000000/* Copyright (C) 2001 Damir Zucic */ /*============================================================================= set_psi.c Purpose: Set the psi angle for each selected residue in the specified complex. A residue is treated as selected if the first atom of this residue is selected. For proteins, this is typically the N atom (nitrogen). Input: (1) Pointer to MolComplexS structure. (2) Pointer to ConfigS structure. (3) The psi angle in degrees. Output: (1) Psi angle set for each selected residue in each caught complex. (2) Return value. Return value: (1) Positive always (trivial). Notes: (1) This function uses the atoms N, CA, C of the current residue and and the N atom of the next residue. The O atom of the current residue is not used. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int ExtractNCAC_ (VectorS *, VectorS *, VectorS *, AtomS *, size_t, size_t); int ExtractN_ (VectorS *, AtomS *, size_t, size_t); double PsiFromNCACN_ (VectorS *, VectorS *, VectorS *, VectorS *, ConfigS *); int RotateAtom_ (AtomS *, VectorS *, VectorS *, double); int DihedralAngles_ (MolComplexS *, ConfigS *); /*======set psi angle(s):====================================================*/ int SetPsi_ (MolComplexS *mol_complexSP, ConfigS *configSP, double psi_new) { int residuesN, residueI; size_t atomsN, atomI; ResidueS *current_residueSP; AtomS *first_atomSP; size_t current_startI, current_endI; int n; static VectorS N_vectorS, CA_vectorS, C_vectorS; ResidueS *next_residueSP; size_t next_startI, next_endI; static VectorS nextN_vectorS; double psi_old, delta_psi; AtomS *atomSP; /* Copy the number of residues in the specified complex: */ residuesN = mol_complexSP->residuesN; /* Copy the number of atoms in the specified complex: */ atomsN = mol_complexSP->atomsN; /* Scan residues, but omit the last one: */ for (residueI = 0; residueI < residuesN - 1; residueI++) { /* Pointer to the current residue: */ current_residueSP = mol_complexSP->residueSP + residueI; /* Pointer to the first atom of this residue: */ first_atomSP = mol_complexSP->atomSP + current_residueSP->residue_startI; /* If the first atom of this residue is not */ /* selected, the residue is not selected: */ if (first_atomSP->selectedF == 0) continue; /* The range of atomic indices for the current residue: */ current_startI = current_residueSP->residue_startI; current_endI = current_residueSP->residue_endI; /* Try to extract N, CA and C coordinates for the current residue: */ n = ExtractNCAC_ (&N_vectorS, &CA_vectorS, &C_vectorS, mol_complexSP->atomSP, current_startI, current_endI); if (n < 3) continue; /* The N atom of the next residue is required. */ /* Pointer to the next residue: */ next_residueSP = mol_complexSP->residueSP + residueI + 1; /* The atomic index range for the next residue: */ next_startI = next_residueSP->residue_startI; next_endI = next_residueSP->residue_endI; /* Try to extract the N atom from the next residue: */ n = ExtractN_ (&nextN_vectorS, mol_complexSP->atomSP, next_startI, next_endI); if (n < 1) break; /* Calculate and check the old psi: */ psi_old = PsiFromNCACN_ (&N_vectorS, &CA_vectorS, &C_vectorS, &nextN_vectorS, configSP); if (psi_old == BADDIHEDANGLE) continue; /* Calculate the difference: */ delta_psi = psi_new - psi_old; /* Rotate the O atom of the current residue about CA-C bond: */ for (atomI = current_startI; atomI <= current_endI; atomI++) { /* Pointer to the current atom: */ atomSP = mol_complexSP->atomSP + atomI; /* The only atom which should be rotated is O: */ if (strcmp (atomSP->raw_atomS.pure_atom_nameA, "O") != 0) { continue; } /* If this point is reached, rotate O about CA-C bond: */ RotateAtom_ (atomSP, &CA_vectorS, &C_vectorS, delta_psi); } /* Rotate all atoms after the current residue about CA-C bond: */ for (atomI = current_endI + 1; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ atomSP = mol_complexSP->atomSP + atomI; /* Rotate atom: */ RotateAtom_ (atomSP, &CA_vectorS, &C_vectorS, delta_psi); } } /* Update dihedral angles and cis-trans flags: */ DihedralAngles_ (mol_complexSP, configSP); /* Set the position_changedF: */ mol_complexSP->position_changedF = 1; /* Return positive value (trivial): */ return 1; } /*===========================================================================*/ garlic-1.6/neighborhood.c0000644000076500007650000000760010157110544015723 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2004 Damir Zucic */ /*============================================================================= neighborhood.c Purpose: Execute neighborhood command: show or hide sequence neighborhood. Input: (1) Pointer to MolComplexS structure. (2) The number of macromolecular complexes. (3) Pointer to RuntimeS structure. (4) Pointer to ConfigS structure. (5) Pointer to GUIS structure. (6) Pointer to NearestAtomS structure. (7) The number of pixels in the main window free area. (8) Pointer to refreshI. (9) Pointer to the remainder of the command string. This command may be given without keyword or with keyword OFF. Output: (1) The show_sequence_neighborhoodF flag set to zero, one or two. Values: 0 = hide, 1 = show residue names, 2 = show residue names, serial numbers and chain identifiers. (2) Return value. Return value: (1) Positive (command) code on success. (2) Negative (error) code on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "commands.h" #include "typedefs.h" /*======function prototypes:=================================================*/ char *ExtractToken_ (char *, int, char *, char *); size_t MainRefresh_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); int ControlRefresh_ (MolComplexS *, ConfigS *, GUIS *); /*======execute neighborhood command:========================================*/ int Neighborhood_ (MolComplexS *mol_complexSP, int mol_complexesN, RuntimeS *runtimeSP, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int *refreshIP, char *stringP) { char *remainderP; char tokenA[SHORTSTRINGSIZE]; /* Extract the first token: */ remainderP = ExtractToken_ (tokenA, STRINGSIZE, stringP, " \t\n"); /* If available, the first token should contain keyword OFF: */ if (remainderP) { /* If keyword OFF is present, set flag value to zero: */ if (strstr (tokenA, "OFF") == tokenA) { /* Set flag: */ configSP->show_sequence_neighborhoodF = 0; /* Refresh the main window: */ (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); /* Refresh the control window: */ ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); /* Return the command code: */ return COMMAND_NEIGHBORHOOD; } /* If keyword VER (VERBOSE) is present, set flag to two: */ else if (strstr (tokenA, "VER") == tokenA) { /* Set flag: */ configSP->show_sequence_neighborhoodF = 2; /* Refresh the main window: */ (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); /* Refresh the control window: */ ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); /* Return the command code: */ return COMMAND_NEIGHBORHOOD; } /* If keyword recognition fails: */ else { sprintf (runtimeSP->messageA, "Keyword %s not recognized!", tokenA); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_NEIGHBORHOOD; } } /* If this point is reached, there are no keywords. Set flag value to one: */ configSP->show_sequence_neighborhoodF = 1; /* Refresh the main window: */ (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); /* Refresh the control window: */ ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); /* Return the command code: */ return COMMAND_NEIGHBORHOOD; } /*===========================================================================*/ garlic-1.6/replace.c0000644000076500007650000007777207747301651014724 0ustar zuciczucic00000000000000/* Copyright (C) 2001-2003 Damir Zucic */ /*============================================================================= replace.c Purpose: Execute replace command: replace selected residues with template residues, using the sequence from the sequence buffer. This function works only for protein structures. Input: (1) Pointer to MolComplexS structure. (2) The number of macromolecular complexes. (3) The first free macromolecular complex identifier. (4) Pointer to RuntimeS structure. (5) Pointer to ConfigS structure. (6) Pointer to GUIS structure. (7) Pointer to NearestAtomS structure. (8) The number of pixels in the main window free area. (9) Pointer to refreshI. Output: (1) Selected residues replaced. (2) Return value. Return value: (1) Positive (command) code on success. (2) Negative (error) code on failure. Notes: (1) If exiting from this function before it ends, do not forget to free the storage used for the temporary structure. It is also important to reset pointers and counts. Note that the same MolComplexS structure may be used more than once for the temporary molecular structure. (2) Residue indices used in this function should be of the type int, not size_t. The type size_t may be unsigned so it is not safe for subtraction. (3) This function resets the edit mode index. ========includes:============================================================*/ #include #include #include #include #include #include #include #include #include "defines.h" #include "commands.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int CountRequiredAtoms_ (RuntimeS *, int); int CopyTemplateAtoms_ (MolComplexS *, RuntimeS *, ResidueS *, int); int ExtractSequence_ (MolComplexS *); int ResetPhi_ (MolComplexS *); int ResetPsi_ (MolComplexS *); int ExtractNCA_ (VectorS *, VectorS *, AtomS *, size_t, size_t); int RotateAtom_ (AtomS *, VectorS *, VectorS *, double); int ExtractC_ (VectorS *, AtomS *, size_t, size_t); int ExtractNCAC_ (VectorS *, VectorS *, VectorS *, AtomS *, size_t, size_t); int ExtractN_ (VectorS *, AtomS *, size_t, size_t); void TranslateRange_ (AtomS *, size_t, size_t, double, double, double); void VectorProduct_ (VectorS *, VectorS *, VectorS *); double AbsoluteValue_ (VectorS *); double ScalarProduct_ (VectorS *, VectorS *); void RotateRange_ (AtomS *, size_t, size_t, VectorS *, VectorS *, double); int ParallelPart_ (VectorS *, VectorS *, VectorS *); int PrepareStereoData_ (MolComplexS *, ConfigS *); size_t StrongBonds_ (MolComplexS *, int, ConfigS *); size_t PseudoBonds_ (MolComplexS *, int, ConfigS *); size_t DisulfideBonds_ (MolComplexS *, int, ConfigS *); int RefreshBackbone_ (MolComplexS *, ConfigS *); int AssignRadii_ (MolComplexS *, ConfigS *); int AssignHydrophobicity_ (MolComplexS *, int); int DihedralAngles_ (MolComplexS *, ConfigS *); size_t MainRefresh_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); int ControlRefresh_ (MolComplexS *, ConfigS *, GUIS *); /*======execute replace command:=============================================*/ int Replace_ (MolComplexS *mol_complexSP, int mol_complexesN, int next_mol_complexID, RuntimeS *runtimeSP, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int *refreshIP) { int max_length; size_t char_size, atom_struct_size; MolComplexS *curr_mol_complexSP; int old_atomsN, new_atomsN; int total_residuesN, residueI; int selected_residuesN = 0, selected_residueI = 0; ResidueS *old_residueSP; AtomS *old_first_atomSP; int residue_recognizedF; int template_residuesN, template_residueI; ResidueS *template_residueSP; AtomS *template_first_atomSP; char *curr_template_nameP; char bad_residue_nameA[10]; char *old_residue_nameP, *new_residue_nameP; double phi, psi, delta_phi, delta_psi; int deleted_atomsN = 0, inserted_atomsN = 0; size_t new_memory_size; static AtomS *reallocated_atomSP; int temporary_mol_complexI; static MolComplexS *temporary_mol_complexSP; int required_atomsN; size_t elementsN; int n; ResidueS *new_residueSP; size_t old_atom_startI, old_atom_endI; size_t template_atom_startI, template_atom_endI; size_t new_atom_startI, new_atom_endI; VectorS old_N_vectorS, old_CA_vectorS, old_C_vectorS; VectorS new_N_vectorS, new_CA_vectorS, new_C_vectorS; int residue_sequenceI; int atomI; AtomS *atomSP; char *residue_nameP; char *atom_nameP; double delta_x, delta_y, delta_z; VectorS vector1S, vector2S, vector3S; VectorS axis_vectorS; double denominator, ratio, angle; VectorS old_parallel_vectorS, old_perpendicular_vectorS; VectorS new_parallel_vectorS, new_perpendicular_vectorS; AtomS *new_first_atomSP; int current_atomsN; int delta_atomsN; AtomS *source_atomSP, *dest_atomSP; int trailing_atomsN; size_t bytesN; int atoms_in_new_residue; /* The maximal residue name length: */ max_length = RESNAMESIZE - 1; /* Size of some data types: */ char_size = sizeof (char); atom_struct_size = sizeof (AtomS); /* Prepare the pointer to default complex: */ curr_mol_complexSP = mol_complexSP + runtimeSP->default_complexI; /** Number of atoms in a macromolecular complex: **/ old_atomsN = curr_mol_complexSP->atomsN; if (old_atomsN == 0) { strcpy (runtimeSP->messageA, "Default structure is empty!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_REPLACE; } /* Prepare the total number of residues: */ total_residuesN = curr_mol_complexSP->residuesN; /* Prepare the number of template residues: */ template_residuesN = runtimeSP->template_residuesN; /* Check how many residues are selected in default structure. */ /* A residue is treated as selected if the first atom of this */ /* residue is selected. For proteins, this is usualy N atom. */ for (residueI = 0; residueI < total_residuesN; residueI++) { /* Pointer to the old residue: */ old_residueSP = curr_mol_complexSP->residueSP + residueI; /* Pointer to the first atom: */ old_first_atomSP = curr_mol_complexSP->atomSP + old_residueSP->residue_startI; /* If the first atom is not selected, do */ /* not count this residue as selected: */ if (old_first_atomSP->selectedF == 0) continue; /* Update the number of selected residues: */ selected_residuesN++; } /* Compare the number of selected residues with the number of */ /* residues in the main sequence buffer; this function will */ /* refuse to replace residues if these numbers are not equal: */ if (selected_residuesN != (int) runtimeSP->residuesN) { sprintf (runtimeSP->messageA, "%d resid. selected but sequence buffer contains %d!", selected_residuesN, runtimeSP->residuesN); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_REPLACE; } /* Check the residues which should be replaced. Garlic will */ /* refuse to replace nucleic bases and/or hetero residues. */ for (residueI = 0; residueI < total_residuesN; residueI++) { /* Pointer to the old residue: */ old_residueSP = curr_mol_complexSP->residueSP + residueI; /* Pointer to the first atom: */ old_first_atomSP = curr_mol_complexSP->atomSP + old_residueSP->residue_startI; /* If the first atom is not selected, skip this residue: */ if (old_first_atomSP->selectedF == 0) continue; /* Name of old residue: */ old_residue_nameP = old_first_atomSP->raw_atomS.pure_residue_nameA; /* If the current residue is recognized, this flag will be set to */ /* one; if recognition failes, the value will remain unchanged: */ residue_recognizedF = 0; /* Scan the list of template residues: */ for (template_residueI = 0; template_residueI < template_residuesN; template_residueI++) { /* Pointer to the current template residue: */ template_residueSP = runtimeSP->template_residueSP + template_residueI; /* Pointer to the first atom of */ /* the current template residue: */ old_first_atomSP = runtimeSP->template_atomSP + template_residueSP->residue_startI; /* Pointer to the current template residue name: */ curr_template_nameP = old_first_atomSP->raw_atomS.pure_residue_nameA; /* Compare the current residue name */ /* with the template residue name: */ if (strncmp (old_residue_nameP, curr_template_nameP, max_length) == 0) { residue_recognizedF = 1; break; } } /* If residue recognition failed, the replacement will not work: */ if (!residue_recognizedF) { strncpy (bad_residue_nameA, old_residue_nameP, max_length); bad_residue_nameA[max_length] = '\0'; sprintf (runtimeSP->messageA, "Don't know how to replace the residue %s", bad_residue_nameA); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_REPLACE; } } /* Check the sequence in the main sequence buffer: */ for (residueI = 0; residueI < (int) runtimeSP->residuesN; residueI++) { /* Prepare the pointer to the current residue name: */ new_residue_nameP = runtimeSP->sequenceP + residueI * max_length; /* If the current residue is recognized, this flag will be set to */ /* one; if recognition failes, the value will remain unchanged: */ residue_recognizedF = 0; /* Scan the list of template residues: */ for (template_residueI = 0; template_residueI < template_residuesN; template_residueI++) { /* Pointer to the current template residue: */ template_residueSP = runtimeSP->template_residueSP + template_residueI; /* Pointer to the first atom of */ /* the current template residue: */ template_first_atomSP = runtimeSP->template_atomSP + template_residueSP->residue_startI; /* Pointer to the current template residue name: */ curr_template_nameP = template_first_atomSP->raw_atomS.pure_residue_nameA; /* Compare the current residue name */ /* with the template residue name: */ if (strncmp (new_residue_nameP, curr_template_nameP, max_length) == 0) { residue_recognizedF = 1; break; } } /* If residue recognition failed, the */ /* atomic structure cannot be created: */ if (!residue_recognizedF) { strncpy (bad_residue_nameA, new_residue_nameP, max_length); bad_residue_nameA[max_length] = '\0'; sprintf (runtimeSP->messageA, "Residue not recognized: %s", bad_residue_nameA); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_REPLACE; } } /* Some residues might be replaced by prolines. Check the */ /* phi angle, because it has a limited range for prolines: */ for (residueI = 0; residueI < total_residuesN; residueI++) { /* Pointer to the old residue: */ old_residueSP = curr_mol_complexSP->residueSP + residueI; /* Pointer to the first atom: */ old_first_atomSP = curr_mol_complexSP->atomSP + old_residueSP->residue_startI; /* If the first atom is not selected, skip this residue: */ if (old_first_atomSP->selectedF == 0) continue; /* Name of the old residue: */ old_residue_nameP = old_first_atomSP->raw_atomS.pure_residue_nameA; /* Name of the new residue: */ new_residue_nameP = runtimeSP->sequenceP + selected_residueI * max_length; /* If new residue is proline, check what was the old one: */ do { /* Is new residue proline? */ if (strncmp (new_residue_nameP, "PRO", max_length) != 0) { break; } /* Is old residue proline? */ if (strcmp (old_residue_nameP, "PRO") == 0) break; /* If this point is reached the new residue is */ /* proline and the old one is something else. */ /* Check the old phi angle: it should be in the */ /* range between -90 degrees and -40 degrees if */ /* replacing non-proline residue by proline: */ phi = old_residueSP->phi; if ((phi >= -1.5707963) && (phi <= -0.6981317)) break; /* If this point is reached, garlic will not be */ /* able to replace the old residue by proline: */ sprintf (runtimeSP->messageA, "Unable to replace %s %d by proline!", old_residue_nameP, old_first_atomSP->raw_atomS.residue_sequenceI); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_REPLACE; /* End of single-pass loop: */ } while (0); /* Update index: */ selected_residueI++; } /* Count the number of atoms which should be deleted: */ for (residueI = 0; residueI < total_residuesN; residueI++) { /* Pointer to the old residue: */ old_residueSP = curr_mol_complexSP->residueSP + residueI; /* The start index and the end index of the old residue: */ old_atom_startI = old_residueSP->residue_startI; old_atom_endI = old_residueSP->residue_endI; /* Pointer to the first atom: */ old_first_atomSP = curr_mol_complexSP->atomSP + old_atom_startI; /* If the first atom is not selected, skip this residue: */ if (old_first_atomSP->selectedF == 0) continue; /* Update the number of atoms which should be deleted: */ deleted_atomsN += (int) old_atom_endI - (int) old_atom_startI + 1; } /* Count the number of atoms which should be inserted: */ for (residueI = 0; residueI < (int) runtimeSP->residuesN; residueI++) { /* Prepare the pointer to the current residue name: */ new_residue_nameP = runtimeSP->sequenceP + residueI * max_length; /* Scan the list of template residues: */ for (template_residueI = 0; template_residueI < template_residuesN; template_residueI++) { /* Pointer to the current template residue: */ template_residueSP = runtimeSP->template_residueSP + template_residueI; /* The start index and the end index of the new residue: */ template_atom_startI = template_residueSP->residue_startI; template_atom_endI = template_residueSP->residue_endI; /* Pointer to the first atom of */ /* the current template residue: */ template_first_atomSP = runtimeSP->template_atomSP + template_atom_startI; /* Pointer to the current template residue name: */ curr_template_nameP = template_first_atomSP->raw_atomS.pure_residue_nameA; /* Compare the current residue name */ /* with the template residue name: */ if (strncmp (new_residue_nameP, curr_template_nameP, max_length) == 0) { inserted_atomsN += (int) template_atom_endI - (int) template_atom_startI + 1; break; } } } /* Calculate the number of atoms after the insertion: */ new_atomsN = old_atomsN + inserted_atomsN - deleted_atomsN; /* Check the available storage and reallocate memory if necessary: */ if (new_atomsN > (int) curr_mol_complexSP->max_atomsN + 100) { /* Prepare the number of bytes: */ new_memory_size = new_atomsN * atom_struct_size; /* Try to reallocate storage: */ reallocated_atomSP = realloc (curr_mol_complexSP->atomSP, new_memory_size); /* If reallocation fails return the error code. */ /* The original data should not be corrupted. */ if (!reallocated_atomSP) { strcpy (runtimeSP->messageA, "Memory reallocation failed!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_REPLACE; } /* If this point is reached, reallocation was successfull. */ /* Copy the pointer and update the maximal number of atoms. */ curr_mol_complexSP->atomSP = reallocated_atomSP; curr_mol_complexSP->max_atomsN = new_atomsN; } /* Create the temporary structure, to copy the residues */ /* which will replace the selected part of the structure. */ /* Do not allocate storage for header and backbone data. */ /* Prepare the index of the new structure: */ temporary_mol_complexI = mol_complexesN; /* Prepare the pointer to the new macromolecular complex: */ temporary_mol_complexSP = mol_complexSP + temporary_mol_complexI; /* Prepare the identifier for the new macromolecular complex: */ temporary_mol_complexSP->mol_complexID = next_mol_complexID; /* Count the number of atoms: */ required_atomsN = CountRequiredAtoms_ (runtimeSP, runtimeSP->residuesN); /* Prepare the maximal number of atoms in the new structure: */ elementsN = required_atomsN + 125; temporary_mol_complexSP->max_atomsN = elementsN; /* Allocate the memory for atomic coordinates (add some extra space): */ temporary_mol_complexSP->atomSP = (AtomS *) calloc (elementsN, atom_struct_size); if (temporary_mol_complexSP->atomSP == NULL) { strcpy (runtimeSP->messageA, "Failed to allocate storage for the temporary structure!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_REPLACE; } /* Copy the required template residues: */ for (residueI = 0; residueI < (int) runtimeSP->residuesN; residueI++) { /* The name of the residue which will be inserted: */ new_residue_nameP = runtimeSP->sequenceP + residueI * max_length; /* Scan the list of template residues: */ for (template_residueI = 0; template_residueI < template_residuesN; template_residueI++) { /* Pointer to the current template residue: */ template_residueSP = runtimeSP->template_residueSP + template_residueI; /* Pointer to the first atom of */ /* the current template residue: */ template_first_atomSP = runtimeSP->template_atomSP + template_residueSP->residue_startI; /* Pointer to the current template residue name: */ curr_template_nameP = template_first_atomSP->raw_atomS.pure_residue_nameA; /* Compare the current residue name */ /* with the template residue name; */ /* if they match, prepare the number */ /* of atoms and add it to the total. */ if (strncmp (new_residue_nameP, curr_template_nameP, max_length) == 0) { /* Copy template atoms: */ CopyTemplateAtoms_ (temporary_mol_complexSP, runtimeSP, template_residueSP, residueI); break; } } } /* Prepare the sequence (residue) information for the temporary */ /* structure. Do not forget to free the storage and to reset */ /* the pointer allocated in the function ExtractSequence_ ! */ n = ExtractSequence_ (temporary_mol_complexSP); if (n < 0) { strcpy (runtimeSP->messageA, "Unable to extract sequence from the temporary structure!"); runtimeSP->message_length = strlen (runtimeSP->messageA); free (temporary_mol_complexSP->atomSP); temporary_mol_complexSP->atomSP = NULL; temporary_mol_complexSP->atomsN = 0; temporary_mol_complexSP->max_atomsN = 0; temporary_mol_complexSP->mol_complexID = 0; return ERROR_REPLACE; } /* Reset dihedral angles: */ ResetPhi_ (temporary_mol_complexSP); ResetPsi_ (temporary_mol_complexSP); /* Set the initial value for selected_residueI: */ selected_residueI = 0; /* Copy dihedral angles, copy the residue sequence */ /* numbers and translate and rotate new residues: */ for (residueI = 0; residueI < total_residuesN; residueI++) { /* Pointer to the old residue: */ old_residueSP = curr_mol_complexSP->residueSP + residueI; /* Pointer to the first atom of the old residue: */ old_first_atomSP = curr_mol_complexSP->atomSP + old_residueSP->residue_startI; /* If the first atom is not selected, skip this residue: */ if (old_first_atomSP->selectedF == 0) continue; /* The start and the end atomic index of the old residue: */ old_atom_startI = old_residueSP->residue_startI; old_atom_endI = old_residueSP->residue_endI; /* Prepare pointer to the new residue: */ new_residueSP = temporary_mol_complexSP->residueSP + selected_residueI; /* Update and check the index used to distinguish selected residues: */ selected_residueI++; if (selected_residueI > selected_residuesN) break; /* The start index and the end index of the new residue: */ new_atom_startI = new_residueSP->residue_startI; new_atom_endI = new_residueSP->residue_endI; /*------copy the residue sequence number:----------------------------*/ residue_sequenceI = old_first_atomSP->raw_atomS.residue_sequenceI; for (atomI = (int) new_atom_startI; atomI <= (int) new_atom_endI; atomI++) { /* Pointer to the current new atom: */ dest_atomSP = temporary_mol_complexSP->atomSP + atomI; /* Copy the residue sequence number: */ dest_atomSP->raw_atomS.residue_sequenceI = residue_sequenceI; } /*------copy the phi angle:------------------------------------------*/ /* The phi angle for the old residue: */ phi = old_residueSP->phi; /* The rotation angle: */ delta_phi = phi + 3.1415927; /* Coordinates of the new N and CA: */ n = ExtractNCA_ (&new_N_vectorS, &new_CA_vectorS, temporary_mol_complexSP->atomSP, new_atom_startI, new_atom_endI); if (n < 2) continue; /* Scan the new residue: */ for (atomI = (int) new_atom_startI; atomI <= (int) new_atom_endI; atomI++) { /* Pointer to the current atom: */ atomSP = temporary_mol_complexSP->atomSP + atomI; /* Skip proline: */ residue_nameP = atomSP->raw_atomS.pure_residue_nameA; if (strcmp (residue_nameP, "PRO") == 0) continue; /* Do not rotate H, N and CA: */ atom_nameP = atomSP->raw_atomS.pure_atom_nameA; if ((strcmp (atom_nameP, "H") == 0) || (strcmp (atom_nameP, "N") == 0) || (strcmp (atom_nameP, "CA") == 0)) { continue; } /* Rotate the current atom about N-CA bond: */ RotateAtom_ (atomSP, &new_N_vectorS, &new_CA_vectorS, delta_phi); } /*------copy the psi angle:------------------------------------------*/ /* The psi angle for the old residue: */ psi = old_residueSP->psi; /* The rotation angle: */ delta_psi = psi - 3.1415927; /* Coordinates of the new C: */ n = ExtractC_ (&new_C_vectorS, temporary_mol_complexSP->atomSP, new_atom_startI, new_atom_endI); if (n < 1) continue; /* Scan the new residue: */ for (atomI = (int) new_atom_startI; atomI <= (int) new_atom_endI; atomI++) { /* Pointer to the current atom: */ atomSP = temporary_mol_complexSP->atomSP + atomI; /* Rotate only the O atom: */ if (strcmp (atomSP->raw_atomS.pure_atom_nameA, "O") != 0) { continue; } /* Rotate O atom about CA-C bond: */ RotateAtom_ (atomSP, &new_CA_vectorS, &new_C_vectorS, delta_psi); } /*------translate new residue:---------------------------------------*/ /* Coordinates of the old N, CA and C: */ n = ExtractNCAC_ (&old_N_vectorS, &old_CA_vectorS, &old_C_vectorS, curr_mol_complexSP->atomSP, old_atom_startI, old_atom_endI); if (n < 3) continue; /* Initial coordinates of the new N atom: */ n = ExtractN_ (&new_N_vectorS, temporary_mol_complexSP->atomSP, new_atom_startI, new_atom_endI); if (n < 1) continue; /* The translation shift for the new residue: */ delta_x = old_N_vectorS.x - new_N_vectorS.x; delta_y = old_N_vectorS.y - new_N_vectorS.y; delta_z = old_N_vectorS.z - new_N_vectorS.z; /* Translate the new residue: */ TranslateRange_ (temporary_mol_complexSP->atomSP, new_atom_startI, new_atom_endI, delta_x, delta_y, delta_z); /*------the first rotation:------------------------------------------*/ /* Extract the updated N and CA coordinates of the new residue: */ n = ExtractNCA_ (&new_N_vectorS, &new_CA_vectorS, temporary_mol_complexSP->atomSP, new_atom_startI, new_atom_endI); if (n < 2) continue; /* The vector parallel to N-CA bond of the new residue: */ vector1S.x = new_CA_vectorS.x - new_N_vectorS.x; vector1S.y = new_CA_vectorS.y - new_N_vectorS.y; vector1S.z = new_CA_vectorS.z - new_N_vectorS.z; /* The vector parallel to the N-CA bond of the old residue: */ vector2S.x = old_CA_vectorS.x - old_N_vectorS.x; vector2S.y = old_CA_vectorS.y - old_N_vectorS.y; vector2S.z = old_CA_vectorS.z - old_N_vectorS.z; /* The rotation axis vector is perpendicular to both N-CA bonds: */ VectorProduct_ (&axis_vectorS, &vector1S, &vector2S); /* Calculate the rotation angle, but remember that arc */ /* cosine is very sensitive to floating point errors: */ denominator = AbsoluteValue_ (&vector1S) * AbsoluteValue_ (&vector2S); if (denominator == 0.0) continue; ratio = ScalarProduct_ (&vector1S, &vector2S) / denominator; if (ratio <= -1.0) angle = 3.1415927; else if (ratio >= 1.0) angle = 0.0; else angle = acos (ratio); /* Rotate the new residue: */ RotateRange_ (temporary_mol_complexSP->atomSP, new_atom_startI, new_atom_endI, &new_N_vectorS, &axis_vectorS, angle); /*------the second rotation:-----------------------------------------*/ /* Extract the updated N, CA and C coordinates of the new residue: */ n = ExtractNCAC_ (&new_N_vectorS, &new_CA_vectorS, &new_C_vectorS, temporary_mol_complexSP->atomSP, new_atom_startI, new_atom_endI); if (n < 3) continue; /* The rotation axis vector is parallel */ /* to the N-CA bond of the new residue: */ axis_vectorS.x = new_CA_vectorS.x - new_N_vectorS.x; axis_vectorS.y = new_CA_vectorS.y - new_N_vectorS.y; axis_vectorS.z = new_CA_vectorS.z - new_N_vectorS.z; /* CA-C vector (old residue): */ vector1S.x = old_C_vectorS.x - old_CA_vectorS.x; vector1S.y = old_C_vectorS.y - old_CA_vectorS.y; vector1S.z = old_C_vectorS.z - old_CA_vectorS.z; /* The parallel part of CA-C vector (old residue): */ n = ParallelPart_ (&old_parallel_vectorS, &axis_vectorS, &vector1S); if (n < 0) continue; /* The perpendicular part of CA-C vector (old residue): */ old_perpendicular_vectorS.x = vector1S.x - old_parallel_vectorS.x; old_perpendicular_vectorS.y = vector1S.y - old_parallel_vectorS.y; old_perpendicular_vectorS.z = vector1S.z - old_parallel_vectorS.z; /* CA-C vector (new residue): */ vector2S.x = new_C_vectorS.x - new_CA_vectorS.x; vector2S.y = new_C_vectorS.y - new_CA_vectorS.y; vector2S.z = new_C_vectorS.z - new_CA_vectorS.z; /* The parallel part of CA-C vector (new residue): */ n = ParallelPart_ (&new_parallel_vectorS, &axis_vectorS, &vector2S); if (n < 0) continue; /* The perpendicular part of CA-C vector (new residue): */ new_perpendicular_vectorS.x = vector2S.x - new_parallel_vectorS.x; new_perpendicular_vectorS.y = vector2S.y - new_parallel_vectorS.y; new_perpendicular_vectorS.z = vector2S.z - new_parallel_vectorS.z; /* Calculate the rotation angle, but remember that arc */ /* cosine is very sensitive to floating point errors: */ denominator = AbsoluteValue_ (&old_perpendicular_vectorS) * AbsoluteValue_ (&new_perpendicular_vectorS); if (denominator == 0.0) continue; ratio = ScalarProduct_ (&old_perpendicular_vectorS, &new_perpendicular_vectorS) / denominator; if (ratio < -1.0) angle = 3.1415927; else if (ratio > 1.0) angle = 0.0; else angle = acos (ratio); /* The sign of the angle is still unknown. Prepare */ /* the vector which is perpendicular to both the */ /* rotation axis and to CA-C bond for old residue: */ VectorProduct_ (&vector3S, &axis_vectorS, &old_perpendicular_vectorS); if (ScalarProduct_ (&new_perpendicular_vectorS, &vector3S) > 0.0) { angle *= -1; } /* Rotate the new residue: */ RotateRange_ (temporary_mol_complexSP->atomSP, new_atom_startI, new_atom_endI, &new_N_vectorS, &axis_vectorS, angle); } /* Now it is time to replace the residues. Scan the structure backwards. */ /* Set the initial value for the current number of atoms: */ current_atomsN = old_atomsN; /* Set the initial value for selected_residueI: */ selected_residueI = selected_residuesN; /* Scan the old complex backwards. Note that the index must be signed. */ /* Unsigned index will cause the following loop to execute forever! */ for (residueI = total_residuesN - 1; residueI >= 0; residueI--) { /* Pointer to the old residue: */ old_residueSP = curr_mol_complexSP->residueSP + residueI; /* The start index and the end index of the old residue: */ old_atom_startI = old_residueSP->residue_startI; old_atom_endI = old_residueSP->residue_endI; /* Pointer to the first atom of the old residue: */ old_first_atomSP = curr_mol_complexSP->atomSP + old_atom_startI; /* If the first atom is not selected, skip this residue: */ if (old_first_atomSP->selectedF == 0) continue; /* Update and check the index used to distinguish selected residues: */ selected_residueI--; if (selected_residueI < 0) break; /* Prepare the pointer to the new residue: */ new_residueSP = temporary_mol_complexSP->residueSP + selected_residueI; /* The start index and the end index of the new residue: */ new_atom_startI = new_residueSP->residue_startI; new_atom_endI = new_residueSP->residue_endI; /* Pointer to the first atom of the new residue: */ new_first_atomSP = temporary_mol_complexSP->atomSP + new_atom_startI; /* The new residue may be different in size from the old residue: */ delta_atomsN = ((int) new_atom_endI - (int) new_atom_startI) - ((int) old_atom_endI - (int) old_atom_startI); /* If delta_atomsN is not zero and if not dealing with the */ /* last residue, the storage for atomic data has to be */ /* rearranged. Prepare the source and destination pointer */ /* and the number of bytes which have to be shifted. After */ /* that, shift all atoms after the current old residue. */ /* Do not forget to update the total number of atoms! */ if ((delta_atomsN != 0) && (residueI != total_residuesN - 1)) { /* Source and destination pointer: */ source_atomSP = curr_mol_complexSP->atomSP + old_atom_endI + 1; dest_atomSP = source_atomSP + delta_atomsN; /* The number of atoms after the */ /* last atom of the old residue: */ if (current_atomsN > (int) old_atom_endI) /* Paranoid check */ { trailing_atomsN = current_atomsN - old_atom_endI - 1; } else trailing_atomsN = 0; /* The number of bytes to be moved in memory: */ bytesN = trailing_atomsN * atom_struct_size; /* Rearrange atomic data (move part of the atomic array): */ memmove (dest_atomSP, source_atomSP, bytesN); /* Update the number of atoms in the structure: */ current_atomsN += delta_atomsN; } /* Now, finally, insert the new residue: */ if (new_atom_endI >= new_atom_startI) /* Paranoid check, again */ { atoms_in_new_residue = new_atom_endI - new_atom_startI + 1; } else atoms_in_new_residue = 0; bytesN = atoms_in_new_residue * atom_struct_size; memcpy (old_first_atomSP, new_first_atomSP, bytesN); } /* Update the position_changedF flag: */ curr_mol_complexSP->position_changedF = 1; /* Delete the temporary structure and reset pointers and counts: */ free (temporary_mol_complexSP->atomSP); temporary_mol_complexSP->atomSP = NULL; temporary_mol_complexSP->atomsN = 0; temporary_mol_complexSP->max_atomsN = 0; temporary_mol_complexSP->mol_complexID = 0; free (temporary_mol_complexSP->residueSP); temporary_mol_complexSP->residueSP = NULL; temporary_mol_complexSP->residuesN = 0; /* Update the number of atoms (after the replacement): */ curr_mol_complexSP->atomsN = new_atomsN; /* Update atomic serial numbers: */ for (atomI = 0; atomI < new_atomsN; atomI++) { atomSP = curr_mol_complexSP->atomSP + atomI; atomSP->raw_atomS.serialI = atomI + 1; } /* Prepare the stereo data (coordinates for the right image): */ if (configSP->stereoF) PrepareStereoData_ (curr_mol_complexSP, configSP); /* Update strong bonds: */ StrongBonds_ (curr_mol_complexSP, runtimeSP->default_complexI, configSP); /* Update pseudo-bonds: */ PseudoBonds_ (curr_mol_complexSP, runtimeSP->default_complexI, configSP); /* Prepare disulfide bonds: */ DisulfideBonds_ (curr_mol_complexSP, runtimeSP->default_complexI, configSP); /* Refresh backbone data: */ RefreshBackbone_ (curr_mol_complexSP, configSP); /* Assign radius to each atom: */ AssignRadii_ (curr_mol_complexSP, configSP); /* Assign default hydrophobicity to each atom: */ AssignHydrophobicity_ (curr_mol_complexSP, curr_mol_complexSP->hydrophobicity_scaleI); /* Refresh the sequence information: */ if (curr_mol_complexSP->residueSP) { free (curr_mol_complexSP->residueSP); curr_mol_complexSP->residueSP = NULL; curr_mol_complexSP->residuesN = 0; } ExtractSequence_ (curr_mol_complexSP); /* Calculate dihedral angles and cis-trans flags: */ DihedralAngles_ (curr_mol_complexSP, configSP); /*@@*/ /* Update the secondary structure information: */ /* Reset the editing mode index: */ runtimeSP->edit_modeI = 0; /* Reset the edit_single_bondF flag: */ runtimeSP->edit_single_bondF = 0; /* Reset the main window mode index: */ guiSP->main_window_modeI = 0; /* Refresh the main window: */ (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); /* Refresh the control window: */ ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); /* Return the command code: */ return COMMAND_REPLACE; } /*===========================================================================*/ garlic-1.6/read_fasta.c0000644000076500007650000001265607260715563015371 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= read_fasta.c Purpose: Read a single chain sequence from FASTA file. Return negative value if file is not in FASTA format. The letters J, O and U are translated as UNK (unknown) residue, as well as letter X. Input: (1) Pointer to RuntimeS structure. (2) Pointer to input file name. Output: (1) Sequence stored to the sequence buffer. (2) Return value. Return value: (1) Positive on success. (2) Negative on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include #include "defines.h" #include "commands.h" #include "typedefs.h" /*======function prototypes:=================================================*/ FILE *OpenFileForReading_ (char *); void InitHyphob_ (RuntimeS *); /*======read FASTA file (sequence in one letter code):=======================*/ int ReadFasta_ (RuntimeS *runtimeSP, char *file_nameP) { int max_length; char lineA[STRINGSIZE]; FILE *fileP; int line_length; int n; int lineI = 0; char *P; int columnI; size_t residueI = 0; size_t offset; /* The maximal residue name length: */ max_length = RESNAMESIZE - 1; /* Try to open file: */ fileP = OpenFileForReading_ (file_nameP); if (fileP == NULL) { strcpy (runtimeSP->messageA, "Failed to open file!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return -1; } /* Read file, line by line: */ while (fgets (lineA, STRINGSIZE, fileP)) { /* Remove the trailing newline: */ line_length = strlen (lineA); n = line_length - 1; if (line_length > 0) { if (lineA[n] == '\n') lineA[n] = '\0'; line_length--; } /* Empty lines are ignored: */ if (line_length == 0) continue; /* Lines beginning with # are treated as comments: */ if (lineA[0] == '#') continue; /* If the first character of the first useful line is */ /* not '>', input file format is not FASTA compliant. */ /* If it is, the line contains a protein description. */ if (lineI == 0) { if (lineA[0] != '>') { fclose (fileP); return -1; } else { lineI++; continue; } } /* If the first character of a line which is not the first useful */ /* line is '>', this signals another sequence. Break from the loop: */ else { if (lineA[0] == '>') break; } /* Convert to uppercase: */ P = lineA; while ((n = *P++) != '\0') *(P - 1) = toupper (n); /* Parse line: */ for (columnI = 0; columnI < line_length; columnI++) { /* Check is there enough place left in the buffer: */ offset = max_length * residueI; if (offset > runtimeSP->sequence_buffer_size - 10 * max_length) { strcpy (runtimeSP->messageA, "Sequence too long!"); runtimeSP->message_length = strlen (runtimeSP->messageA); fclose (fileP); return -2; } /* The current character: */ n = lineA[columnI]; /* Pointer to the position where */ /* residue name should be copied: */ P = runtimeSP->sequenceP + offset; /* Identify residue: */ switch (n) { case 'A': strncpy (P, "ALA", max_length); break; case 'B': strncpy (P, "ASX", max_length); break; case 'C': strncpy (P, "CYS", max_length); break; case 'D': strncpy (P, "ASP", max_length); break; case 'E': strncpy (P, "GLU", max_length); break; case 'F': strncpy (P, "PHE", max_length); break; case 'G': strncpy (P, "GLY", max_length); break; case 'H': strncpy (P, "HIS", max_length); break; case 'I': strncpy (P, "ILE", max_length); break; case 'J': strncpy (P, "UNK", max_length); break; case 'K': strncpy (P, "LYS", max_length); break; case 'L': strncpy (P, "LEU", max_length); break; case 'M': strncpy (P, "MET", max_length); break; case 'N': strncpy (P, "ASN", max_length); break; case 'O': strncpy (P, "UNK", max_length); break; case 'P': strncpy (P, "PRO", max_length); break; case 'Q': strncpy (P, "GLN", max_length); break; case 'R': strncpy (P, "ARG", max_length); break; case 'S': strncpy (P, "SER", max_length); break; case 'T': strncpy (P, "THR", max_length); break; case 'U': strncpy (P, "UNK", max_length); break; case 'V': strncpy (P, "VAL", max_length); break; case 'W': strncpy (P, "TRP", max_length); break; case 'X': strncpy (P, "UNK", max_length); break; case 'Y': strncpy (P, "TYR", max_length); break; case 'Z': strncpy (P, "GLX", max_length); break; default: ; } /* Update the residue index: */ residueI++; } /* Update the line index (only useful lines are counted): */ lineI++; } /* Close file: */ fclose (fileP); /* Store the number of residues: */ runtimeSP->residuesN = residueI; /* Reinitialize serial numbers: */ for (residueI = 0; residueI < runtimeSP->residuesN; residueI++) { *(runtimeSP->serialIP + residueI) = residueI + 1; } /* Reinitialize disulfide flags: */ for (residueI = 0; residueI < runtimeSP->residuesN; residueI++) { *(runtimeSP->disulfideFP + residueI) = 0; } /* Initialize hydrophobicity values: */ InitHyphob_ (runtimeSP); /* Return positive value on success: */ return 1; } /*===========================================================================*/ garlic-1.6/save_seq_w_numbers.c0000644000076500007650000000543707260721775017170 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= save_seq_w_numbers.c Purpose: Save sequence to file. This function outputs three letters code accompained with serial numbers. Input: (1) Pointer to RuntimeS structure. Output: (1) Sequence stored to file. (2) Return value. Return value: (1) Positive on success. (2) Negative on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ char *ExtractToken_ (char *, int, char *, char *); /*======save sequence (with numbers) to file:================================*/ int SaveSequenceWithNumbers_ (RuntimeS *runtimeSP) { int max_length; char lineA[STRINGSIZE]; char *remainderP; char tokenA[STRINGSIZE]; FILE *fileP; size_t residueI; char *nameP; int serialI; char residue_nameA[RESNAMESIZE]; /* The maximal residue name length: */ max_length = RESNAMESIZE - 1; /* Copy the original command string: */ strncpy (lineA, runtimeSP->curr_commandA, STRINGSIZE - 1); lineA[STRINGSIZE - 1] = '\0'; /* Skip two tokens: */ remainderP = ExtractToken_ (tokenA, STRINGSIZE, lineA, " \t\n"); if (!remainderP) return -1; remainderP = ExtractToken_ (tokenA, STRINGSIZE, remainderP, " \t\n"); if (!remainderP) return -2; /* The third token should contain the file name: */ remainderP = ExtractToken_ (tokenA, STRINGSIZE, remainderP, " \t\n"); if (!remainderP) { strcpy (runtimeSP->messageA, "File name missing!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return -3; } /* Try to open file: */ fileP = fopen (tokenA, "w"); if (fileP == NULL) { strcpy (runtimeSP->messageA, "Failed to open file!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return -4; } /* Write sequence to file: */ for (residueI = 0; residueI < runtimeSP->residuesN; residueI++) { /* Prepare the pointer to the current residue name: */ nameP = runtimeSP->sequenceP + residueI * max_length; /* Copy serial number: */ serialI = *(runtimeSP->serialIP + residueI); /* Copy residue name: */ strncpy (residue_nameA, nameP, max_length); residue_nameA[max_length] = '\0'; /* Print serial number and residue name: */ fprintf (fileP, "%4d %-4s", serialI, residue_nameA); /* Add newline after every five residues: */ if (((residueI + 1) % 5) == 0) fprintf (fileP, "\n"); } /* Add newline at the end of file: */ fprintf (fileP, "\n"); /* Close file: */ fclose (fileP); /* Return positive value on success: */ return 1; } /*===========================================================================*/ garlic-1.6/load_font.c0000644000076500007650000000417507065473714015244 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= load_font.c Purpose: Load font. If this is not posssible, try some replacements. Input: (1) Pointer to WindowS structure, where font structure pointer will be stored. (2) Pointer to display structure. (3) Font name (string). Output: (1) Font structure pointer initialized. (2) Font flag set. (3) Return value. Return value: (1) Positive on success. (2) Negative on failure. ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======load font:===========================================================*/ int LoadFont_ (WindowS *winSP, Display *displaySP, char *font_nameP) { static XFontStruct *fontSP; /* The first attempt: */ fontSP = XLoadQueryFont (displaySP, font_nameP); if (fontSP) { winSP->fontSP = fontSP; winSP->fontF = 1; return 1; } else printf ("The font %s not available, trying 10x20 ...\n", font_nameP); /* The second attempt - trying 10x20: */ fontSP = XLoadQueryFont (displaySP, "10x20"); if (fontSP) { winSP->fontSP = fontSP; winSP->fontF = 1; return 2; } else printf ("The font 10x20 not available, trying 9x15 ...\n"); /* The third attempt - 9x15: */ fontSP = XLoadQueryFont (displaySP, "9x15"); if (fontSP) { winSP->fontSP = fontSP; winSP->fontF = 1; return 3; } else printf ("The font 9x15 not available, trying 7x14...\n"); /* The fourth attempt - 7x14: */ fontSP = XLoadQueryFont (displaySP, "7x14"); if (fontSP) { winSP->fontSP = fontSP; winSP->fontF = 1; return 4; } else printf ("The font 7x14 not available, trying fixed ...\n"); /* The fifth (and last) attempt - fixed font: */ fontSP = XLoadQueryFont (displaySP, "fixed"); if (fontSP) { winSP->fontSP = fontSP; winSP->fontF = 1; return 5; } else printf ("Fixed font not available, wouldn't try any more.\n"); return -1; } /*===========================================================================*/ garlic-1.6/seahorse.xpm0000644000076500007650000003002607306674323015461 0ustar zuciczucic00000000000000/* XPM */ static char * seahorse_xpm[] = { /* width height num_colors chars_per_pixel */ "80 143 11 1", /* Colors: */ " c None", ". c #6A1715", "+ c #D8A779", "@ c #443002", "# c #CED1CB", "$ c #C5884C", "% c #864A32", "& c #C26523", "* c #629AC2", "= c #604002", "- c #6A96A2", /* Pixels: */ " . +. . .. ", " .@ ..+ .#...$ .$. ", " @ @+ .%&. @ .#@ @#.@ ", " @.. @ @ ..$. ..%.@ .+.. ", " @... @.. @#@ .$.#+ .@.$. ", " . @#.. %. ..@$..@ ...$@ ", " . @. . .@..@@.%#@.#@@ @$$*@ ", " @ @@@.##%...@@*$@#@ .#$#. ", " @ @@@+..$.%.$#@@@%@ .$$. ", " @@@@@@@@.##$#$&$$%$$$@.+@$.@. ", " ..@&$&$.$.$.+ #+$+$&#@#.%$$.@ ", " @@...$.$..$$#.@&$$=@@@$..%.@@ ", " ... @.@#...$@&@.%$$$@###@.%@&%.. ", " =&%. @....@.%...$.%.@$@@#####@@#.$...@ ", " ==.&.=.@ @#@##$.+..%.%.%$@+@##%@@##@#%+%$..@. ", " ...&&&#@.#+# #&.$@.#..@+@++%##@@%##@#$$...@. ", " . .. ##+##.&+#+#.&$.@.@+++@##@@@##@@+%....@@@. ", " %+$#+$+.++$.$.#.@%.@@@+%#####@%..%.%......@@@ @@@. ", " . .. ..+#$&+.$&@+++@+.@&@@.@@@@###%@.@@.&&@&..&........@@... ", " .= %.==. =+$#@$+.$..@++@@.@.@%@@@@@@@%&%..%..@%..@@%...%.@...%.. ", " .==. **..=+&&...+..$@@@@+@.@@.+.$@.@$.@.%.%..+$..%......@..%&.@.. ", " .. &&%%%+$.$#@..@@..++@@.#@@.@.%.@%.$.&%...%&$..@@.@@@@.@.@.@..", " .=. .=. $&.$&+$+&@.+@+++@+.+@&+.@$@$$.%.%@+$&....+$.%@@.@..#@.@.%.", " = .... .=. +$@@@+++##+#$+@+@@+@@+##&+@#$...###&%.%...$$@.@@..@...@. ", " == .%... =%*%..& ###+#++@@@@@...@@++++++@+++##.....%.%.@.@@.%..%@. ", " =. $+%..*%+$*+&+$+###++..@..%..@.@@@@.@@@...@.@@ @@ ", " .== &+$%%%&.&$@.&$+@+#+..%@..%.%@@..@@ .@ ", " .... .=..@%#%.@&+&+&++++++$@.%......@. ", " =$$%= @=%$&@..+$&$+#$+&$..@.@@.%@@.% ", " .+&$%====#&*...&+#+@@&$+ = .@.. ", " . .. .+%+#&+&%+@&&+$+&&&$ ..% ", " == =&%$+%@@$&#@&$+&&&. ", " ...==%. @=%%...=&$&&$+@$@&= ", " .=.%%%.%@.*+%++++&$&&$++++= ", " .=.**+$*$+@.&#+&+&+++&#+= ", " ==&&#&+#$%.@$+$&$$&+#++= ", " =. =.@&@&&%=.&+$+&+$+&++= ", " =$ =.&$$++$$+++#++&#+++= ", " ..%. &.$+$$#++&+&$#&+#+#+= ", " . ##.=%=.%$$&$++$#++#@&+++$= ", " ==&&**$**+%$@@+&++$#++.&#+*.. ", " .=.=%+&$$+&..+#&$+&+++#+$#-. ", " ...%...&+%$&&%+#+$+++$+$#+$*. ", " &= ..$#..&+#%%+$+$%+$+#&##&%$#= ", " +*=$=.++%*$$#%*+*$+$&+$++##+%#* ", " .. +$%%*$+$@@+&+$+++$&$+$+###$*. ", " === &&%+$@=.+$+++++#++$@@++#++#. ", " .=%%==.&&$%..&##++#+#++&&$++&+$%& ", " ...%%**++#%%+++$#++#+#+++#+$&+%%. ", " .&&#.+%$+##+##++#+#&$++&+$$**= ", " =%$%&%++##+++#++$+$&+#+#&$*#.. ", " ..%$++#+####++$+#++++$+##+++$*-. ", " &.=.#*###+#+#+#+#++++#+#$&+######$+#. ", " .$+++#+###&#+#+#+#++#+++#&$++++#$$*#= ", " .=..&$+&#@..$&++#+#&+$+#&&@.+#&++*++$. ", " ==.%%.$.=.&#++###+++$+++@@+&#&#**%.. ", " .$%&=%%#+++++&$+#&#$+#&++&+$$*#== ", " =%+%%&+##$++&+&$++&+++#$+#&+#$*#= ", " ==%$$%%++++&+$&+@@$&&$+&&++$+&%+#= ", " . %%%%$--##$++#@&&&&+$+$#+##+&+$##= ", " =+##$+#*++##+##&+++#&+@&&&++$+$#+#$#*. ", " .&#&&&%%@@$+&+&$++&$+#+@+$#++&#+&+++$= ", " ===&+&%.=&+#+$++&+&+$&+#+++++#-#.##. ", " =##++.==$$+##++$&#&$++&$###++&++$#$= ", " =$@@$%..%++##+++&&+$@+#+@&@+$&#+$+&+. ", " =&...%%%%%+$+#$++$&@&#+++@@&$&&$++$$%. ", " .#%$+#.%$.$#$+%&$&&$&+++$+&&+&+&&#+$+. ", " = ==.$$$$$+###+#+&+&$+$&&++##$++&&%&*= ", " =%%+.%&#######++$&&$+##+#+#$+$$+%. ", " .&#$&$..@#&&&+#####+++++##+&+&+$%#*. ", " ==##%#&.=.$+%+%$+##++++#+#+###+#%+$*. ", " =..###%$%=.##+$$&$++#++#+$+##+#++#+*#*. ", " =$+#&###+$%%++%*&&$+#++#+#++###+####++$%= ", " =@..%%#$#%+*+++&$&++++++#+#+$+$+&#+#+%&*= ", " ==.%*##+#+*#+#+%&$++++++##+@@+#+&+$%&+=. ", " =#$+#$%&###+#++%&%% $+&$#%&#$+#&$*&%= ", " .##$+-+%+$$%%&$+$$+#$&+++#$+#&+##+*. ", " =.$###$#&&&..$+%%%%$&####+#&#+##&+$*$= ", " ..%%$+%+####+.=.++++$&.$#+#+$#++++$++*+*%. ", " &&& $=.=%##&#@=&+.&.+%%$#-+++#&+#+$$&+$$. ", " &.====.%++#$+++$%$+%%%++&+##+$+-+#+#%$%*. ", " . .%#+@..@.&$+$$%++.%%@++++#&$&++$+&$= ", " =.&=$%%&&..$&$%+%%%%.%$.=.$+*+%$+#= ", " .=.#++$.%%%++$+$$+&%$#..+#$+$#$#.. ", " =..%#*$%*$#.%%+$++$%*%+*$*$+&***#+. ", " =$$$& &$& &&%$####$+%+#++&$%#$+$&.. ", " =====..%+*%=+$$&$*+&*+&@=*+%#+$.==. ", " . %#+%%$$..+#+#$+%=...%#.= ", " ..=..-++%+&%@$$#+##*$%==== %= ", " .&#=..+%$%$+$##$#-#+#%== .=. ", " .=%%%%%%..%$&$&++$##%= ", " %% =..%=%###$##% ", " .%%$$&%%$##+#+&#= ", " & .$%%-%%&+$####+#= ", " =.#$+%++.$+=@#####+= ", " =..@..-$.%%%.%+#++##. ", " .@=$$#%$$$$#+#####= ", " $$%$$##+$#####+#. ", " =%& =#+$#&$++=$#+####= ", " =$%..%####.+&&#$.-##+##= ", " .#$%#%&=$$%+%$$+#####$ ", " ==.=#-..#$$%&##$$#+##% ", " =..%%%$%.%%$$&%$-###% ", " ==.$#$++%$#####+#% ", " =%==%$*$$$#$$####% ", " ....$%.&%$$%$++##& ", " =*%.%%##**####$ ", " =$%..$%%$%######% ", " =. =$$.+#$#+-+##$ ", " =+$*$#++#####% ", " .... #+$#$$+=%+#+#+ ", " .%+#$. $+$-##$$-$###+ ", " &####$ %%$%$$####$##% ", " .%$-#$..=%$.+#$$@####-% ", " %$#-$#= =#$$$-+#$##+##= ", " =--#$%= =.$+$###$####- ", " %#-$*= =##*$#%$##*###. ", " .=%#$%. %%#$-#*$####-+. ", " .&.$+-. &-=%$#$##+##%= ", " ==-%&.% .%#%$*$%###+#-= ", " .%=..+.% .%%$#*$#######= ", " =+.$%=&. &-#--%-#*##+#-= ", " ==&==.+=. =$$#$-+#####$%. ", " .&..%=%= $$*$-%##+###%= ", " .%=%&=+&= =##*-$%$###+*%= ", " .+==.+%=. $$$%#-##*###%& ", " .=%&%==&= ==#*#+$#####++= ", " %&==%&+===%%-#=-######.=& ", " ===%==%%%$%%#-##+#+###+%. ", " =&=+%=&+=$##$-######+-.= ", " &==&==%%=$##+###*###$&+ ", " =%==+%&%&$###-###*$#*%= ", " =+=%===%=%#+#+##$**$&= ", " %=&=+%+&=&-###-###$$+. ", " =%==&==%+==-#+-++**&= ", " &==&==%==%=*$$-*#-.= ", " .+==%&=&=+&%.*$%=.& ", " =%&=+=%%=%=&.+.&=. ", " .=+%==+=&==%=%%= ", " =&=&%&=%&+=+= ", " ===+=+=&%==. ", " .%=&%===& ", " "}; garlic-1.6/hyb.script0000644000076500007650000000031307572170312015120 0ustar zuciczucic00000000000000load 2por.pdb hyb dis all load 2fcp.pdb hyb dis all load 1msl.pdb hyb dis all load hucb.pdb hyb dis all load 1prc.pdb hyb dis all load /home/zucic/pdb/1aba.pdb hyb dis all load 2brd.pdb hyb dis all quit garlic-1.6/full_colors.c0000644000076500007650000001311507572477744015626 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2002 Damir Zucic */ /*============================================================================= full_colors.c Purpose: This function handles the precise color definitions. The input string is expected at least three tokens, specifying three near and three far colors. The keyword old may be used to leave any of the old colors unchanged. See the table below for mapping of tokens. If six colors are defined, there will be two color surfaces; nine colors define three color surfaces etc. Input: (1) Pointer to MolComplexS structure. (2) Number of macromolecular complexes. (3) Pointer to GUIS structure, with GUI data. (4) String with six colors. Output: (1) Return value. Return value: (1) Positive on success. (2) Negative on failure. Notes: (1) Mapping tokens to colors: ================== | token | color | ================== | 1 | left | | 2 | middle | | 3 | right | ================== =============================================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ char *ExtractToken_ (char *, int, char *, char *); int IsOld_ (char *); int ParseColor_ (RGBS *, unsigned long *, GUIS *, char *, char *); /*======full color specifications:===========================================*/ int FullColors_ (MolComplexS *mol_complexSP, int mol_complexesN, GUIS *guiSP, char *stringP) { char *remainderP; char tokenA[SHORTSTRINGSIZE]; int tokensN = 0; int surfacesN, surfaceI; size_t rgb_struct_size; RGBS rgbS; unsigned long dummyID; static ColorSchemeS color_schemeS; int leftF[MAXCOLORSURFACES]; int middleF[MAXCOLORSURFACES]; int rightF[MAXCOLORSURFACES]; int mol_complexI; MolComplexS *curr_mol_complexSP; size_t atomsN, atomI; AtomS *curr_atomSP; /* Skip the first token: */ remainderP = ExtractToken_ (tokenA, SHORTSTRINGSIZE, stringP, " \t,;"); if (remainderP == NULL) return -1; /* Count tokens: */ while ((remainderP = ExtractToken_ (tokenA, SHORTSTRINGSIZE, remainderP, " \t,;")) != NULL) tokensN++; /* Check the number of tokens: */ if (tokensN == 0) return -2; if ((tokensN % 3) != 0) return -3; /* Prepare the number of surfaces: */ surfacesN = tokensN / 3; if (surfacesN > MAXCOLORSURFACES) return -4; /*------extract and parse colors:--------------------------------------------*/ /* Skip the first token: */ remainderP = ExtractToken_ (tokenA, SHORTSTRINGSIZE, stringP, " \t,;"); if (remainderP == NULL) return -5; /* The size of RGBS structure: */ rgb_struct_size = sizeof (RGBS); /* Parse all tokens: */ for (surfaceI = 0; surfaceI < surfacesN; surfaceI++) { /** Left color: **/ remainderP = ExtractToken_ (tokenA, SHORTSTRINGSIZE, remainderP, " \t,;"); if (remainderP == NULL) return -6; if (IsOld_ (tokenA)) leftF[surfaceI] = 0; else { leftF[surfaceI] = 1; ParseColor_ (&rgbS, &dummyID, guiSP, tokenA, "white"); memcpy (color_schemeS.left_rgbSA + surfaceI, &rgbS, rgb_struct_size); } /** Middle color: **/ remainderP = ExtractToken_ (tokenA, SHORTSTRINGSIZE, remainderP, " \t,;"); if (remainderP == NULL) return -7; if (IsOld_ (tokenA)) middleF[surfaceI] = 0; else { middleF[surfaceI] = 1; ParseColor_ (&rgbS, &dummyID, guiSP, tokenA, "gray"); memcpy (color_schemeS.middle_rgbSA + surfaceI, &rgbS, rgb_struct_size); } /** Right color: **/ remainderP = ExtractToken_ (tokenA, SHORTSTRINGSIZE, remainderP, " \t,;"); if (remainderP == NULL) return -8; if (IsOld_ (tokenA)) rightF[surfaceI] = 0; else { rightF[surfaceI] = 1; ParseColor_ (&rgbS, &dummyID, guiSP, tokenA, "black"); memcpy (color_schemeS.right_rgbSA + surfaceI, &rgbS, rgb_struct_size); } } /*------assign colors to selected atoms:-------------------------------------*/ /* Scan every macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /** Pointer to the current macromolecular complex: **/ curr_mol_complexSP = mol_complexSP + mol_complexI; /** Check is the current macromolecular complex caught: **/ if (curr_mol_complexSP->catchF == 0) continue; /** Number of atoms in a macromolecular complex: **/ atomsN = curr_mol_complexSP->atomsN; /** Scan all atoms in the current complex: **/ for (atomI = 0; atomI < atomsN; atomI++) { /** Pointer to the current atom: **/ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /** Check is atom selected: **/ if (curr_atomSP->selectedF == 0) continue; /** Set the number of color surfaces: **/ curr_atomSP->surfacesN = surfacesN; /** Copy the color specifications: **/ for (surfaceI = 0; surfaceI < surfacesN; surfaceI++) { /*** Left color: ***/ if (leftF[surfaceI]) { memcpy (curr_atomSP->left_rgbSA + surfaceI, color_schemeS.left_rgbSA + surfaceI, rgb_struct_size); } /*** Middle color: ***/ if (middleF[surfaceI]) { memcpy (curr_atomSP->middle_rgbSA + surfaceI, color_schemeS.middle_rgbSA + surfaceI, rgb_struct_size); } /*** Right color: ***/ if (rightF[surfaceI]) { memcpy (curr_atomSP->right_rgbSA + surfaceI, color_schemeS.right_rgbSA + surfaceI, rgb_struct_size); } } } /* Reset the position_changedF: */ curr_mol_complexSP->position_changedF = 1; } /* Return positive value on success: */ return 1; } /*===========================================================================*/ garlic-1.6/event_loop.c0000644000076500007650000002126407747301227015443 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2003 Damir Zucic */ /*============================================================================= event_loop.c Purpose: Take and process events. Input: (1) Pointer to the array of MolComplexS structures. (2) Pointer to the number of macromolecular complexes. (3) Pointer to the next macromolecular complex identifier. (4) Pointer to pointer to the array of NearestAtomS structures. (5) Pointer to the number of pixels in the main window free area. (6) Pointer to ConfigS structure, with configuration data. (7) Pointer to GUIS structure, with GUI data and the rest of command line options. (8) Events (from event queue). (9) Molecular coordinates read from one or more files, on request. Output: (1) Graphics, text and other useful things. (2) Array pointed at by MolComplexS structure pointer may be filled with data. (3) Number of macromolecular complexes updated, if at least one complex is loaded at runtime. (4) Return value. Return value: (1) Positive if everything worked fine. (2) Negative if something failed. Notes: (1) When a new macromolecular complex is loaded, *next_mol_complexIDP should be used as complex identifier. The m. complex index should not be used, because one of the previously initialized complex identifiers may have the value equal to current_complexI. This may happen if one or more objects are discarded from memory. (2) The refreshI index is updated before refreshing the main window. The lowest value of refreshI should be one. Never reset to zero! The value zero is reserved as the initial value for last_refreshI member of NearestAtomS structure. Pixels which have last_refreshI value set to zero are free for drawing; there is no need to check the z coordinate associated with this pixel. Otherwise, if the last_refreshI is equal to the current refreshI, the z coordinate of a given atom should be compared with a z value stored in the NearestAtomS structure associated with a given pixel. It is assumed that refreshI is updated no more than once in each event handling function. If this is not the case, the care should be taken to avoid refreshI overflow. (3) A single action may result in several Expose events. The server guarantees that such Expose events are sent contiguously. The last event has the xexpose.count equal to zero. In this program only the last Expose event is processed. (4) Note the unusual indentation of while (1) loop. (5) The array of NearestAtomS structures may be reallocated, so it is neccesary to use pointer to pointer. The array is freed later. ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "commands.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int InitRuntime_ (RuntimeS *, ConfigS *); void InitNearest_ (NearestAtomS *, size_t); size_t MainRefresh_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); int ControlRefresh_ (MolComplexS *, ConfigS *, GUIS *); int InputRefresh_ (GUIS *, RuntimeS *); int DockingRefresh_ (RuntimeS *, GUIS *); int KeyPress_ (MolComplexS *, int *, int *, RuntimeS *, ConfigS *, GUIS *, NearestAtomS **, size_t *, unsigned int *, XKeyEvent *); int KeyRelease_ (GUIS *, XKeyEvent *); int MotionNotify_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int, XMotionEvent *); int DockingResize_ (RuntimeS *, GUIS *, XConfigureEvent *); int MainResize_ (NearestAtomS **, size_t *, MolComplexS *, int, ConfigS *, GUIS *, XConfigureEvent *); int FreeRuntime_ (RuntimeS *); int ButtonPress_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *, XButtonEvent *); /*======do the remaining initializations; take and process events:===========*/ int EventLoop_ (MolComplexS *mol_complexSP, int *mol_complexesNP, int *next_mol_complexIDP, NearestAtomS **nearest_atomSPP, size_t *pixelsNP, ConfigS *configSP, GUIS *guiSP) { static XEvent eventS; static unsigned int refreshI = 1; static XClientMessageEvent *client_eventSP; static RuntimeS runtimeS; static int command_code; /* Initialize memory for some runtime data and do some initializations: */ if (InitRuntime_ (&runtimeS, configSP) < 0) return -1; /* The event loop: */ while (1) { /* Take the next event: */ XNextEvent (guiSP->displaySP, &eventS); /* Check the current refreshI value; reset it and initialize the */ /* NearestAtomS array if maximal value is reached or exceeded: */ if (refreshI >= MAXREFRESHI) { InitNearest_ (*nearest_atomSPP, *pixelsNP); refreshI = 1; } /* Handle the event: */ switch (eventS.type) { /*---------------------------------------------------------------------------*/ case Expose: /* A single action may result in several Expose */ /* events. Only the last one is taken seriously: */ if (eventS.xexpose.count != 0) continue; /* Update refresh index before use: */ refreshI++; /* Refreshing the main window: */ MainRefresh_ (mol_complexSP, *mol_complexesNP, &runtimeS, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshI); /* Refresh the control window: */ ControlRefresh_ (mol_complexSP + runtimeS.default_complexI, configSP, guiSP); /* Refresh the input window: */ InputRefresh_ (guiSP, &runtimeS); /* Refresh docking window, if docking is switched on: */ if (guiSP->dockingF) DockingRefresh_ (&runtimeS, guiSP); /* Flush the output buffer: */ XFlush (guiSP->displaySP); /* Reset modifier flags: */ guiSP->shift_pressedF = 0; guiSP->control_pressedF = 0; guiSP->alt_pressedF = 0; /* End of case Expose: */ break; /*---------------------------------------------------------------------------*/ case KeyPress: /* Handle KeyPress_ event: */ command_code = KeyPress_ (mol_complexSP, mol_complexesNP, next_mol_complexIDP, &runtimeS, configSP, guiSP, nearest_atomSPP, pixelsNP, &refreshI, &eventS.xkey); /* Flush the output buffer: */ XFlush (guiSP->displaySP); /* Break from event loop if quit command issued: */ if (command_code == COMMAND_QUIT) { /** Free memory used for runtime data: **/ FreeRuntime_ (&runtimeS); /** Return to caller: **/ return 1; } /* End of case KeyPress: */ break; /*---------------------------------------------------------------------------*/ case KeyRelease: KeyRelease_ (guiSP, &eventS.xkey); /* End of case KeyRelease: */ break; /*---------------------------------------------------------------------------*/ case MotionNotify: MotionNotify_ (mol_complexSP, *mol_complexesNP, &runtimeS, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshI, &eventS.xmotion); /* End of case MotionNotify: */ break; /*---------------------------------------------------------------------------*/ case ButtonPress: ButtonPress_ (mol_complexSP, *mol_complexesNP, &runtimeS, configSP, guiSP, *nearest_atomSPP, *pixelsNP, &refreshI, &eventS.xbutton); /* End of case ButtonPress: */ break; /*---------------------------------------------------------------------------*/ case ButtonRelease: break; /*---------------------------------------------------------------------------*/ case ConfigureNotify: /* If event belongs to docking window: */ if (eventS.xconfigure.window == guiSP->docking_winS.ID) { DockingResize_ (&runtimeS, guiSP, &eventS.xconfigure); } /* If event belongs to the main window: */ else { MainResize_ (nearest_atomSPP, pixelsNP, mol_complexSP, *mol_complexesNP, configSP, guiSP, &eventS.xconfigure); } break; /*---------------------------------------------------------------------------*/ case ClientMessage: client_eventSP = (XClientMessageEvent *) &eventS; if ((client_eventSP->message_type == guiSP->protocols_atom) && (client_eventSP->data.l[0] == (long) guiSP->delete_window_atom)) { return 1; } break; /*---------------------------------------------------------------------------*/ default: /* Do nothing */ ; /*---------------------------------------------------------------------------*/ } /* End of switch (eventS.type) */ } /* End of while (1) loop */ /* Return positive value on success: */ return 1; } /*===========================================================================*/ garlic-1.6/half_sphere_slab.c0000644000076500007650000000664207065471372016557 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= half_sphere_slab.c Purpose: Check which atoms are inside the semi-spherical slab. Semi-spher. slab is defined by two concentric spheres and a single plane, passing through the slab center. A given atom is inside the slab if it is outside the inner sphere, inside the outer sphere and in front of the plane. Use this slab type to hide the entire rear half as well as the inner part of a globular protein. The position of the plane is fixed, while the position of both spherical surfaces may be adjusted. Input: (1) Pointer to MolComplexS structure. Output: (1) Slab flag set for each atom. The value one is assigned to atoms inside the slab, zero to the rest. (2) Return value. Return value: The number of atoms inside the slab. ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======semi-spherical slab:=================================================*/ size_t HalfSphereSlab_ (MolComplexS *curr_mol_complexSP) { size_t atoms_inside_slabN = 0; size_t atomsN, atomI; AtomS *curr_atomSP; double x0, y0, z0, r0_squared, r1_squared; double x, y, z, rho_squared, r_squared; /* The number of atoms in a complex: */ atomsN = curr_mol_complexSP->atomsN; /* Copy the slab center coordinates: */ x0 = curr_mol_complexSP->slab_center_vectorS.x; y0 = curr_mol_complexSP->slab_center_vectorS.y; z0 = curr_mol_complexSP->slab_center_vectorS.z; r0_squared = curr_mol_complexSP->slab_back_relative_position; r0_squared *= r0_squared; r1_squared = curr_mol_complexSP->slab_front_relative_position; r1_squared *= r1_squared; /* Set the slab flag for each atom: */ for (atomI = 0; atomI < atomsN; atomI++) { /** Pointer to the current atom: **/ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /** Set the initial values of slab flags to one; this **/ /** will be changed later for atoms outside the slab: **/ curr_atomSP->inside_slabF = 1; curr_atomSP->inside_projected_slabF = 1; /** Distance between the current atom and the cylinder axis: **/ x = curr_atomSP->raw_atomS.x[0] - x0; z = curr_atomSP->raw_atomS.z[0] - z0; rho_squared = x * x + z * z; /** Distance between the current atom and the slab center: **/ y = curr_atomSP->raw_atomS.y - y0; r_squared = rho_squared + y * y; /** First prepare the inside_projected_slabF: */ if (rho_squared < r0_squared) curr_atomSP->inside_projected_slabF = 0; if (rho_squared > r1_squared) curr_atomSP->inside_projected_slabF = 0; /** If atom is behind the back plane, set slab **/ /** flags to zero and go to check the next atom: **/ if (z > 0.0) { curr_atomSP->inside_slabF = 0; curr_atomSP->inside_projected_slabF = 0; continue; } /** If atom is inside the inner slab sphere: **/ if (r_squared < r0_squared) { curr_atomSP->inside_slabF = 0; continue; } /** If atom is outside the outer slab sphere: **/ if (r_squared > r1_squared) { curr_atomSP->inside_slabF = 0; continue; } /** If this points is reached, current atom is inside the slab: **/ atoms_inside_slabN++; } /* Return the number of atoms inside the slab: */ return atoms_inside_slabN; } /*===========================================================================*/ garlic-1.6/print_cursor_names.c0000644000076500007650000000531107065474404017201 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= print_cursor_names.c Purpose: Print cursor names to stdout. Input: No input. Output: Cursor names printed to stdout. Return value: No return value. ========includes:============================================================*/ #include #include /*======print cursor names:==================================================*/ void PrintCursorNames_ (void) { int i, j, name_length; static char nameAA[78][20] = {"X_cursor", "arrow", "based_arrow_down", "based_arrow_up", "boat", "bogosity", "bottom_left_corner", "bottom_right_corner", "bottom_side", "bottom_tee", "box_spiral", "center_ptr", "circle", "clock", "coffee_mug", "cross", "cross_reverse", "crosshair", "diamond_cross", "dot", "dotbox", "double_arrow", "draft_large", "draft_small", "draped_box", "exchange", "fleur", "gobbler", "gumby", "hand1", "hand2", "heart", "icon", "iron_cross", "left_ptr", "left_side", "left_tee", "leftbutton", "ll_angle", "lr_angle", "man", "middlebutton", "mouse", "pencil", "pirate", "plus", "question_arrow", "right_ptr", "right_side", "right_tee", "rightbutton", "rtl_logo", "sailboat", "sb_down_arrow", "sb_h_double_arrow", "sb_left_arrow", "sb_right_arrow", "sb_up_arrow", "sb_v_double_arrow", "shuttle", "sizing", "spider", "spraycan", "star", "target", "tcross", "top_left_arrow", "top_left_corner", "top_right_corner", "top_side", "top_tee", "trek", "ul_angle", "umbrella", "ur_angle", "watch", "xterm", "num_glyphs"}; printf ("\n"); printf ("==========================================================\n"); printf ("X11 cursors (hard-coded custom cursor is used as default):\n"); printf ("==========================================================\n"); for (i = 0; i < 78; i++) { name_length = strlen (nameAA[i]); for (j = 0; j < name_length; j++) printf ("%c", nameAA[i][j]); if (((i + 1) % 3) == 0) printf ("\n"); else for (j = name_length; j < 21; j++) printf (" "); } printf ("==========================================================\n"); } /*===========================================================================*/ garlic-1.6/extract_serials.c0000644000076500007650000000304307125735710016456 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= extract_serials.c Purpose: Extract two residue serial numbers from a string. Minus [-], colon [:] and tilde [~] are accepted as token separators. Input: (1) Pointer to the first serial number. (2) Pointer to the second serial number. (3) Pointer to string. Output: (1) The first serial number set. (2) The second serial number set. (3) Return value. Return value: (1) Positive on success. (2) Negative on failure. ========includes:============================================================*/ #include #include /*======extract residue ranges:==============================================*/ int ExtractSerials_ (int *serial1P, int *serial2P, char *stringP) { char *tokenP; int n; /* Take the first token: */ if ((tokenP = strtok (stringP, "-:~")) == NULL) return -1; /* Read the first serial number: */ if (sscanf (tokenP, "%d", &n) != 1) return -2; *serial1P = n; /* Try to extract the second token: */ tokenP = strtok (NULL, "-:~"); /* If the second token is not present, the second */ /* serial number should be equal to the first one: */ if (tokenP == NULL) { *serial2P = *serial1P; } /* If the second token is present, read the */ /* second serial number from this token: */ else { if (sscanf (tokenP, "%d", &n) != 1) return -3; *serial2P = n; } /* Return positive value on success: */ return 1; } /*===========================================================================*/ garlic-1.6/zebra.c0000644000076500007650000000676007070340562014372 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= zebra.c Purpose: Zebra color scheme (alternating colors). Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. (3) Pointer to GUIS structure, with GUI data. (4) Pointer to ColorSchemeS structure. Output: (1) Return value. Return value: (1) Positive always. =============================================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======zebra color scheme:==================================================*/ int Zebra_ (MolComplexS *mol_complexSP, int mol_complexesN, GUIS *guiSP, ColorSchemeS *color_schemeSP) { int mol_complexI; MolComplexS *curr_mol_complexSP; size_t atomsN, atomI; AtomS *curr_atomSP; size_t rgb_struct_size; ColorSchemeS *red_schemeSP, *cyan_blue_schemeSP; int surfaceI; int parity; /* The size of RGBS structure: */ rgb_struct_size = sizeof (RGBS); /* Red scheme pointer: */ red_schemeSP = color_schemeSP + 0; /* Cyan scheme pointer: */ cyan_blue_schemeSP = color_schemeSP + 9; /* Scan every macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check is the current macromolecular complex caught: */ if (curr_mol_complexSP->catchF == 0) continue; /* Number of atoms in a macromolecular complex: */ atomsN = curr_mol_complexSP->atomsN; /* Scan all atoms in the current complex: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Check is atom selected: */ if (curr_atomSP->selectedF == 0) continue; /* Set the number of color surfaces: */ curr_atomSP->surfacesN = 2; /* Check the parity (0 = even, 1 = odd): */ parity = curr_atomSP->raw_atomS.residue_sequenceI % 2; /* Even atoms should be red: */ if (!parity) { /* Copy the color specifications: */ for (surfaceI = 0; surfaceI < 2; surfaceI++) { /* Left color: */ memcpy (curr_atomSP->left_rgbSA + surfaceI, red_schemeSP->left_rgbSA + surfaceI, rgb_struct_size); /* Middle color: */ memcpy (curr_atomSP->middle_rgbSA + surfaceI, red_schemeSP->middle_rgbSA + surfaceI, rgb_struct_size); /* Right color: */ memcpy (curr_atomSP->right_rgbSA + surfaceI, red_schemeSP->right_rgbSA + surfaceI, rgb_struct_size); } } /* Odd atoms should be cyan: */ else { /* Copy the color specifications: */ for (surfaceI = 0; surfaceI < 2; surfaceI++) { /* Left color: */ memcpy (curr_atomSP->left_rgbSA + surfaceI, cyan_blue_schemeSP->left_rgbSA + surfaceI, rgb_struct_size); /* Middle color: */ memcpy (curr_atomSP->middle_rgbSA + surfaceI, cyan_blue_schemeSP->middle_rgbSA + surfaceI, rgb_struct_size); /* Right color: */ memcpy (curr_atomSP->right_rgbSA + surfaceI, cyan_blue_schemeSP->right_rgbSA + surfaceI, rgb_struct_size); } } } /* Reset the position_changedF: */ curr_mol_complexSP->position_changedF = 1; } /* Return positive value: */ return 1; } /*===========================================================================*/ garlic-1.6/chi2_from_cacbcg1cd.c0000644000076500007650000000735007341220615017002 0ustar zuciczucic00000000000000/* Copyright (C) 2001 Damir Zucic */ /*============================================================================= chi2_from_cacbcg1cd.c Purpose: Calculate dihedral angle chi2, using CA, CB, CG1 and CD coordinates. Input: (1) Pointer to AtomS structure, pointing to the first atom of the current macromolecular complex. (2) Index of the first atom of the current residue. (3) Index of the last atom of the currrent residue. Output: Return value. Return value: (1) Dihedral angle chi2, on success. (2) BADDIHEDANGLE on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int ExtractFourAtoms_ (VectorS *, VectorS *, VectorS *, VectorS *, char *, char *, char *, char *, AtomS *, size_t, size_t); void VectorProduct_ (VectorS *, VectorS *, VectorS *); double AbsoluteValue_ (VectorS *); double ScalarProduct_ (VectorS *, VectorS *); /*======calculate chi2 from CA, CB, CG1 and CD:==============================*/ double Chi2FromCACBCG1CD_ (AtomS *atomSP, size_t atom_startI, size_t atom_endI) { static VectorS CA_vectorS, CB_vectorS, CG1_vectorS, CD_vectorS; int n; VectorS CB_CA_vectorS, CB_CG1_vectorS; VectorS CG1_CB_vectorS, CG1_CD_vectorS; VectorS u1S, u2S; VectorS v1S, v2S; double denom, ratio, alpha; double chi2; /* Extract CA, CB, CG1 and CD coordinates: */ n = ExtractFourAtoms_ (&CA_vectorS, &CB_vectorS, &CG1_vectorS, &CD_vectorS, "CA", "CB", "CG1", "CD", atomSP, atom_startI, atom_endI); /* All four atoms are required to calculate the angle chi2: */ if (n < 4) return BADDIHEDANGLE; /* The first pair of auxiliary vectors: */ CB_CA_vectorS.x = CA_vectorS.x - CB_vectorS.x; CB_CA_vectorS.y = CA_vectorS.y - CB_vectorS.y; CB_CA_vectorS.z = CA_vectorS.z - CB_vectorS.z; CB_CG1_vectorS.x = CG1_vectorS.x - CB_vectorS.x; CB_CG1_vectorS.y = CG1_vectorS.y - CB_vectorS.y; CB_CG1_vectorS.z = CG1_vectorS.z - CB_vectorS.z; /* The second pair of auxiliary vectors: */ CG1_CB_vectorS.x = CB_vectorS.x - CG1_vectorS.x; CG1_CB_vectorS.y = CB_vectorS.y - CG1_vectorS.y; CG1_CB_vectorS.z = CB_vectorS.z - CG1_vectorS.z; CG1_CD_vectorS.x = CD_vectorS.x - CG1_vectorS.x; CG1_CD_vectorS.y = CD_vectorS.y - CG1_vectorS.y; CG1_CD_vectorS.z = CD_vectorS.z - CG1_vectorS.z; /* Two vectors perpendicular to CB_CG1_vectorS, mutually orthogonal, */ /* the second in the plane defined by CB_CA_vectorS and CB_CG1_vectorS: */ VectorProduct_ (&u1S, &CB_CA_vectorS, &CB_CG1_vectorS); VectorProduct_ (&u2S, &u1S, &CB_CG1_vectorS); /* Two vectors perpendicular to CG1_CB_vectorS, mutually orthogonal, */ /* the second in the plane defined by CG1_CB_vectorS and CG1_CD_vectorS: */ VectorProduct_ (&v1S, &CG1_CB_vectorS, &CG1_CD_vectorS); VectorProduct_ (&v2S, &CG1_CB_vectorS, &v1S); /* Calculate the angle alpha, which will be used to calculate chi2: */ /* Avoid division by zero: */ denom = AbsoluteValue_ (&u1S) * AbsoluteValue_ (&v1S); if (denom == 0.0) return BADDIHEDANGLE; /* Use the scalar product to calculate the cosine of the angle: */ ratio = ScalarProduct_ (&u1S, &v1S) / denom; /* Arc cosine is very sensitive to floating point errors: */ if (ratio <= -1.0) alpha = 3.1415927; else if (ratio >= 1.0) alpha = 0.0; else alpha = acos (ratio); /* There are two possible solutions; the right one is resolved here: */ if (ScalarProduct_ (&v2S, &u1S) >= 0) chi2 = alpha; else chi2 = -alpha; /* Return the angle (in radians): */ return chi2; } /*===========================================================================*/ garlic-1.6/main_resize.c0000644000076500007650000001060707155645032015573 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= main_resize.c Purpose: Handle ConfigureNotify event for the main window. Input: (1) Pointer to pointer to NearestAtomS structure. (2) Pointer to the number of pixels in the main window free area. (3) Pointer to MolComplexS structure, with macromol. complexes. (4) Number of macromolecular complexes. (5) Pointer to ConfigS structure, with configuration data. (6) Pointer to GUIS structure, with GUI data. (7) Pointer to XConfigureEvent structure. Output: (1) Geometric parameters updated, buffers resized. (2) Return value. Return value: (1) Positive on success. (2) Zero if nothing should be done. (3) Negative on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int CalculateParameters_ (ConfigS *, GUIS *); NearestAtomS *AllocateNearest_ (size_t *, GUIS *); void InitNearest_ (NearestAtomS *, size_t); /*======handle ConfigureNotify event for the main window:====================*/ int MainResize_ (NearestAtomS **nearest_atomSPP, size_t *pixelsNP, MolComplexS *mol_complexSP, int mol_complexesN, ConfigS *configSP, GUIS *guiSP, XConfigureEvent *configure_eventSP) { int old_width, old_height, new_width, new_height; int delta_width, delta_height; int n; int mol_complexI; /* If this event was not generated for the main window, do nothing: */ if (configure_eventSP->window != guiSP->main_winS.ID) return 0; /* Old main window width and height: */ old_width = guiSP->main_winS.width; old_height = guiSP->main_winS.height; /* New width and height of the main window: */ guiSP->main_winS.width = configure_eventSP->width; guiSP->main_winS.height = configure_eventSP->height; new_width = guiSP->main_winS.width; new_height = guiSP->main_winS.height; /* Calculate differences: */ delta_width = new_width - old_width; delta_height = new_height - old_height; /* If nothing has changed, do nothing and return zero: */ if ((delta_width == 0) && (delta_height == 0)) return 0; /* Update positions and dimensions of child windows: */ n = (int) guiSP->control_winS.x0 + delta_width; if (n < 0) n = 0; guiSP->control_winS.x0 = n; n = (int) guiSP->input_winS.y0 + delta_height; if (n < 0) n = 0; guiSP->input_winS.y0 = n; n = (int) guiSP->input_winS.width + delta_width; if (n < 100) n = 100; guiSP->input_winS.width = (unsigned int) n; n = (int) guiSP->output_winS.x0 + delta_width; if (n < 0) n = 0; guiSP->output_winS.x0 = n; n = (int) guiSP->output_winS.height + delta_height; if (n < 50) n = 50; guiSP->output_winS.height = (unsigned int) n; /* Main window free area width and height: */ n = (int) guiSP->main_win_free_area_width + delta_width; if (n < 0) n = 0; guiSP->main_win_free_area_width = (unsigned int) n; n = (int) guiSP->main_win_free_area_height + delta_height; if (n < 0) n = 0; guiSP->main_win_free_area_height = (unsigned int) n; /* Refresh calculated parameters: */ if (CalculateParameters_ (configSP, guiSP) < 0) return -1; /* Resize input and output window: */ XResizeWindow (guiSP->displaySP, guiSP->input_winS.ID, guiSP->input_winS.width, guiSP->input_winS.height); XResizeWindow (guiSP->displaySP, guiSP->output_winS.ID, guiSP->output_winS.width, guiSP->output_winS.height); /* Resize the main hidden pixmap: */ if ((guiSP->main_hidden_pixmapF) && (guiSP->main_win_free_area_height > 0)) { XFreePixmap (guiSP->displaySP, guiSP->main_hidden_pixmapID); guiSP->main_hidden_pixmapID = XCreatePixmap ( guiSP->displaySP, DefaultRootWindow (guiSP->displaySP), guiSP->main_win_free_area_width, guiSP->main_win_free_area_height, guiSP->depth); } /* Resize the NearestAtomS array: */ if (*nearest_atomSPP) { free (*nearest_atomSPP); *nearest_atomSPP = AllocateNearest_ (pixelsNP, guiSP); InitNearest_ (*nearest_atomSPP, *pixelsNP); } /* Set the position_changedF flag for each macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { (mol_complexSP + mol_complexI)->position_changedF = 1; } /* Return positive value: */ return 1; } /*===========================================================================*/ garlic-1.6/translation_shift.c0000644000076500007650000000635407272231254017022 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= translation_shift.c Purpose: Prepare the translation shift. By default, the normal translation shift is copied (translation_shiftA[2] from ConfigS structure). See note 1 for combination of modifier keys. Modifier keys may be used to select the translation shift. Input: (1) Pointer to ConfigS structure, with configuration data. (2) Pointer to GUIS structure, with GUI data. (3) The sign used to distinguish positive and negative translat. Value +1.0 is used with positive translation, while -1.0 defines negative translation. Output: (1) Return value. Return value: (1) Translation shift. Notes: (1) The following combinations of modifier keys may be used to select the translation shift: ------------------------------------------------------------- | modifiers translation shift ConfigS member | |-----------------------------------------------------------| | none normal (default) translation_stepA[2] | | shift large translation_stepA[3] | | alt+shift very large translation_stepA[4] | | control small translation_stepA[1] | | alt+control very small translation_stepA[0] | | shift+control very small translation_stepA[2] | | alt normal translation_stepA[2] | | alt+shift+control normal translation_stepA[2] | ------------------------------------------------------------- Note that some modifier combinations are ignored (alt alone and alt+control+shift). (2) On some laptops the status of shift key may be changed before the KeyPress event is send for the keys on "numeric keypad". ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======prepare translation shift:===========================================*/ double TranslationShift_ (ConfigS *configSP, GUIS *guiSP, double sign) { double translation_shift; int largeF, smallF, altF; /* Copy the flags: */ largeF = guiSP->shift_pressedF; smallF = guiSP->control_pressedF; altF = guiSP->alt_pressedF; /* Select the requested translation shift: */ if (altF) { if (largeF && !smallF) { translation_shift = configSP->translation_stepA[4]; } else if (smallF && !largeF) { translation_shift = configSP->translation_stepA[0]; } else { translation_shift = configSP->translation_stepA[2]; } } else { if (largeF && !smallF) { translation_shift = configSP->translation_stepA[3]; } else if (smallF && !largeF) { translation_shift = configSP->translation_stepA[1]; } else if (smallF && largeF) { translation_shift = configSP->translation_stepA[0]; } else { translation_shift = configSP->translation_stepA[2]; } } /* Take care for the sign: */ translation_shift *= sign; /* Return the translation shift: */ return translation_shift; } /*===========================================================================*/ garlic-1.6/init_fading.c0000644000076500007650000000433707117422156015542 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= init_fading.c Purpose: Initialize color fading data: reference point (center) position, front surface and back surface distance from the center. Input: (1) Pointer to MolComplexS structure. Output: (1) Color fading parameters initialized. Return value: No return value. ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======initialize color fading parameters:==================================*/ void InitFading_ (MolComplexS *mol_complexSP) { double relative_z0, relative_z1; double fading_z0, fading_z1; /* Initialize the reference point: */ mol_complexSP->fading_center_vectorS.x = mol_complexSP->geometric_center_vectorS.x; mol_complexSP->fading_center_vectorS.y = mol_complexSP->geometric_center_vectorS.y; mol_complexSP->fading_center_vectorS.z = mol_complexSP->geometric_center_vectorS.z; /* Prepare the extreme z values (relative to the fading center): */ relative_z0 = mol_complexSP->left_top_near_vectorS.z - mol_complexSP->fading_center_vectorS.z; relative_z1 = mol_complexSP->right_bottom_far_vectorS.z - mol_complexSP->fading_center_vectorS.z; /* Set the initial front and back surface distance */ /* from the center. This depends on fading style. */ switch (mol_complexSP->fading_modeI) { /** Fading off (all atoms should be colored as near atoms): **/ case 0: break; /** Planar: **/ case 1: fading_z0 = relative_z0; fading_z1 = relative_z1; mol_complexSP->fading_front_relative_position = fading_z0; mol_complexSP->fading_back_relative_position = fading_z1; break; /** Sphere, half-sphere, cylinder and half-cylinder: **/ case 2: case 3: case 4: case 5: fading_z0 = -relative_z0; fading_z1 = 0.0; mol_complexSP->fading_front_relative_position = fading_z0; mol_complexSP->fading_back_relative_position = fading_z1; /** Unsupported fading modes (do nothing): **/ default: ; } } /*===========================================================================*/ garlic-1.6/change_fading.c0000644000076500007650000000355007465733221016024 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= change_fading.c Purpose: Change fading mode for each caught macromolecular complex. Input: (1) Pointer to MolComplexS structure. (2) Number of macromolecular complexes. (3) Fading mode index. Output: (1) Fading mode changed for each caught macromolecular complex. (2) Return value. Return value: (1) The number of complexes for which the fading mode was changed. ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ void InitFading_ (MolComplexS *); /*======change fading mode:====================================================*/ int ChangeFading_ (MolComplexS *mol_complexSP, int mol_complexesN, int fading_modeI) { int changesN = 0; int mol_complexI; MolComplexS *curr_mol_complexSP; /* Check every macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /** Pointer to the current macromolecular complex: **/ curr_mol_complexSP = mol_complexSP + mol_complexI; /** Do not apply fading if position has not changed: **/ if (curr_mol_complexSP->catchF== 0) continue; /** Change the fading mode: **/ curr_mol_complexSP->fading_modeI = fading_modeI; /** Initialize fading: **/ InitFading_ (curr_mol_complexSP); /** Change the position_changedF: **/ curr_mol_complexSP->position_changedF = 1; /** Increase the count: **/ changesN++; } /* Return the number of m. complexes for */ /* for which the fading mode was changed: */ return changesN; } /*===========================================================================*/ garlic-1.6/wheel_top_view.c0000644000076500007650000003626107747226240016315 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2003 Damir Zucic */ /*============================================================================= wheel_top_view.c Purpose: Draw the helical wheel counterclockwise. This wheel corresponds to the top view of the helix. Input: (1) Pointer to RuntimeS structure, with some runtime data. (2) Pointer to GUIS structure, with GUI data. (3) Pointer to NearestAtomS structure, with information about the atom occupying the given pixel. (4) The number of pixels in the main window free area. (5) The refreshI, used to check the NearestAtomS associated with a given pixel. It is currently unused in this function. Output: (1) Helical wheel drawn counterclockwise to the main window. (2) Return value. Return value: (1) The number of residues used to prepare the helical wheel. Notes: (1) The initial drawing destination is the hidden pixmap, and the content of this pixmap is copied later to the main window. (2) Labels (residue names) are drawn for the last 18 residues. ========includes:============================================================*/ #include #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int RefreshPixmap_ (Display *, Pixmap, GC, unsigned int, unsigned int, unsigned long); int ParseColor_ (RGBS *, unsigned long *, GUIS *, char *, char *); double Hydrophobicity_ (char *, int, int); unsigned long WeightColors_ (unsigned long, unsigned long, double, GUIS *); int DrawTitles_ (RuntimeS *, GUIS *); /*======draw helical wheel counterclockwise:=================================*/ size_t WheelTopView_ (RuntimeS *runtimeSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int refreshI) { int max_length; int residuesN, residueI; RGBS rgbS; unsigned long phob_colorID, neutral_colorID, phil_colorID; int scaleI; double min_hyphob, max_hyphob, threshold_hyphob; double delta_hyphob1, delta_hyphob2; double inverse_range1, inverse_range2; char *residue_nameP; char residue_nameA[RESNAMESIZE]; double hyphob; double scale_factor; unsigned long residue_colorID; int square_width, screen_margin, screen_radius, half_screen_radius; int screen_x0, screen_y0; int screen_x1, screen_y1, screen_x2, screen_y2; int width, height; int helix_step, arc_start, arc_extent, arc_center; int serialI, range_startI, range_endI, residues_in_wheelN = 0; int wheelI = 0; double angle, delta_x, delta_y; int label_length; char labelA[SHORTSTRINGSIZE]; int text_width, text_height; int ref_angle; int inner_screen_radius, thickness1, thickness2; double alpha0, delta_alpha, alpha1, alpha2; XPoint pointSA[7]; unsigned long far_colorID, near_colorID; /* The number of residues in sequence buffer: */ residuesN = runtimeSP->residuesN; if (residuesN == 0) { strcpy (runtimeSP->messageA, "The sequence buffer is empty!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return 0; } /* The wheel_clockwiseF decides in which direction the sequence should be scanned: */ /* The maximal residue name length: */ max_length = RESNAMESIZE - 1; /* Residue array index range: */ range_startI = runtimeSP->range_startI; range_endI = runtimeSP->range_endI; /* Count the number of residues in the specified range: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Check is the residue array index inside the range: */ if ((residueI < range_startI) || (residueI > range_endI)) continue; /* Increase the count of residues if current */ /* residue belongs to the specified range: */ residues_in_wheelN++; } /* Check the number of residues in a wheel: */ if (residues_in_wheelN == 0) { strcpy (runtimeSP->messageA, "The specified range is empty!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return 0; } /* Refresh the hidden pixmap, where drawing will be done: */ RefreshPixmap_ (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], guiSP->control_winS.x0, guiSP->input_winS.y0, guiSP->main_winS.bg_colorID); /*------draw arcs:-----------------------------------------------------------*/ /* Initialize colors used for hydrophobicity: */ ParseColor_ (&rgbS, &phob_colorID, guiSP, "RGB:FFFF/0000/0000", "white"); ParseColor_ (&rgbS, &neutral_colorID, guiSP, "RGB:FFFF/FFFF/FFFF", "white"); ParseColor_ (&rgbS, &phil_colorID, guiSP, "RGB:0000/0000/FFFF", "black"); /* Hydrophobicity scale index: */ scaleI = runtimeSP->hydrophobicity_scaleI; /* Minimal, maximal and threshold hydrophobicity for current complex: */ min_hyphob = Hydrophobicity_ ("", scaleI, 1); max_hyphob = Hydrophobicity_ ("", scaleI, 2); threshold_hyphob = Hydrophobicity_ ("", scaleI, 4); /* Inverse hydrophobicity ranges: */ delta_hyphob1 = max_hyphob - threshold_hyphob; if (delta_hyphob1 != 0.0) inverse_range1 = 1.0 / delta_hyphob1; else inverse_range1 = 0.0; delta_hyphob2 = threshold_hyphob - min_hyphob; if (delta_hyphob2 != 0.0) inverse_range2 = 1.0 / delta_hyphob2; else inverse_range2 = 0.0; /* Prepare geometric parameters: */ square_width = guiSP->main_win_free_area_height; if ((int) guiSP->main_win_free_area_width < square_width) { square_width = guiSP->main_win_free_area_width; } screen_margin = guiSP->main_winS.text_line_height + guiSP->main_winS.text_line_height / 2 + 2; screen_radius = square_width / 2 - screen_margin; if (screen_radius < 0) screen_radius = square_width / 2; half_screen_radius = screen_radius / 2; screen_x1 = guiSP->main_win_free_area_width / 2; screen_y1 = guiSP->main_win_free_area_height / 2; screen_x0 = screen_x1 - screen_radius; screen_y0 = screen_y1 - screen_radius; width = 2 * screen_radius; height = width; /* Prepare the helix step angle (degrees * 64): */ helix_step = runtimeSP->helix_step_angle * 64; /* Prepare the arc extent angle, (degrees * 64): */ arc_extent = (int) runtimeSP->arc_angle * 64; /* Initialize the arc start angle, (degrees * 64): */ arc_start = 5760 - arc_extent / 2; /* Prepare the text color: */ XSetForeground (guiSP->displaySP, guiSP->theGCA[0], guiSP->main_winS.fg_colorID); /* Prepare the arc edge color: */ XSetForeground (guiSP->displaySP, guiSP->theGCA[1], guiSP->black_colorID); /* Scan the sequence: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Pointer to the current residue name: */ residue_nameP = runtimeSP->sequenceP + residueI * max_length; /* Check is the residue array index inside the range: */ if ((residueI < range_startI) || (residueI > range_endI)) continue; /* Copy the residue name: */ strncpy (residue_nameA, residue_nameP, max_length); residue_nameA[max_length] = '\0'; /* The corresponding hydrophobicity: */ hyphob = Hydrophobicity_ (residue_nameA, scaleI, 0); /* If hydrophobicity is below the threshold value: */ if (hyphob <= threshold_hyphob) { scale_factor = (threshold_hyphob - hyphob) * inverse_range2; residue_colorID = WeightColors_ (neutral_colorID, phil_colorID, scale_factor, guiSP); } /* If hydrophobicity is above the threshold value: */ else { scale_factor = (hyphob - threshold_hyphob) * inverse_range1; residue_colorID = WeightColors_ (neutral_colorID, phob_colorID, scale_factor, guiSP); } /* Prepare the color: */ XSetForeground (guiSP->displaySP, guiSP->theGCA[2], residue_colorID); /* Draw filled arc: */ XFillArc (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], screen_x0, screen_y0, width, height, arc_start, arc_extent); /* Draw the outer arc edge: */ XDrawArc (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], screen_x0, screen_y0, width, height, arc_start, arc_extent); /* Draw two straight lines from the arc origin to the edge: */ angle = DEG_TO_RAD * (double) arc_start / 64.0; delta_x = (double) screen_radius * cos (angle); delta_y = (double) screen_radius * sin (angle); delta_y *= -1; screen_x2 = screen_x1 + (int) delta_x; screen_y2 = screen_y1 + (int) delta_y; XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], screen_x1, screen_y1, screen_x2, screen_y2); angle = DEG_TO_RAD * (double) (arc_start + arc_extent) / 64.0; delta_x = (double) screen_radius * cos (angle); delta_y = (double) screen_radius * sin (angle); delta_y *= -1; screen_x2 = screen_x1 + (int) delta_x; screen_y2 = screen_y1 + (int) delta_y; XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], screen_x1, screen_y1, screen_x2, screen_y2); /* Draw labels for the last 18 residues (not for all!): */ if (residues_in_wheelN - wheelI <= 18) { arc_center = arc_start + arc_extent / 2; angle = DEG_TO_RAD * (double) arc_center / 64.0; delta_x = (double) screen_radius * cos (angle); delta_y = (double) screen_radius * sin (angle); delta_y *= -1; screen_x2 = screen_x1 + (int) delta_x; screen_y2 = screen_y1 + (int) delta_y; serialI = *(runtimeSP->serialIP + residueI); sprintf (labelA, "%d:%s", serialI, residue_nameA); label_length = strlen (labelA); text_width = XTextWidth (guiSP->main_winS.fontSP, labelA, label_length); text_height = guiSP->main_winS.font_height; if (screen_x2 < screen_x1) screen_x2 -= text_width - 1; if (screen_y2 > screen_y1) screen_y2 += text_height; else screen_y2 -= 2; XDrawString (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x2, screen_y2, labelA, label_length); } /* Update the arc start angle: */ arc_start += helix_step; if (arc_start > 23040) arc_start = arc_start - 23040; /* Update the wheel index: */ wheelI++; } /*------draw the hole in the wheel center:-----------------------------------*/ /* Prepare geometric parameters: */ screen_x0 = guiSP->main_win_free_area_width / 2 - half_screen_radius; screen_y0 = guiSP->main_win_free_area_height / 2 - half_screen_radius; width = 2 * half_screen_radius; height = width; XSetForeground (guiSP->displaySP, guiSP->theGCA[0], guiSP->main_winS.bg_colorID); XFillArc (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0, screen_y0, width, height, 0, 23040); /*------draw polygons which represent backbone:------------------------------*/ /* This should be done only if angle is not equal to zero: */ if (helix_step != 0) { /* Prepare far and near color: */ ParseColor_ (&rgbS, &far_colorID, guiSP, "RGB:4444/4444/4444", "white"); ParseColor_ (&rgbS, &near_colorID, guiSP, "RGB:FFFF/FFFF/FFFF", "white"); if (residuesN < 3) { ParseColor_ (&rgbS, &far_colorID, guiSP, "RGB:AAAA/AAAA/AAAA", "white"); } /* Prepare the polygon edge color: */ XSetForeground (guiSP->displaySP, guiSP->theGCA[2], guiSP->black_colorID); /* Prepare half of the helix step angle in radians: */ delta_alpha = DEG_TO_RAD * (double) helix_step / 128.0; /* Prepare the inner radius: */ inner_screen_radius = half_screen_radius * cos (delta_alpha); /* Prepare two thickness parameters: */ thickness1 = screen_radius / 10; if (thickness1 < 4) thickness1 = 4; thickness2 = thickness1 * cos (delta_alpha); if (thickness2 == 0) thickness2 = thickness1; /* Initialize the reference angle (X11 units): */ ref_angle = 5760; /* Reset the wheel index: */ wheelI = 0; /* Scan the sequence again: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Check is this array index inside the range: */ if ((residueI < range_startI) || (residueI > range_endI)) { continue; } /* Convert the reference angle to radians: */ alpha0 = DEG_TO_RAD * (double) ref_angle / 64.0; /* Prepare two additional angles: */ alpha1 = alpha0 - delta_alpha; alpha2 = alpha0 + delta_alpha; /* Now prepare seven points. */ /* The first point: */ delta_x = (double) half_screen_radius * cos (alpha0); delta_y = (double) half_screen_radius * sin (alpha0); delta_y *= -1; screen_x2 = screen_x1 + (int) delta_x; screen_y2 = screen_y1 + (int) delta_y; pointSA[0].x = (short) screen_x2; pointSA[0].y = (short) screen_y2; /* The second point: */ delta_x = (double) inner_screen_radius * cos (alpha1); delta_y = (double) inner_screen_radius * sin (alpha1); delta_y *= -1; screen_x2 = screen_x1 + (int) delta_x; screen_y2 = screen_y1 + (int) delta_y; pointSA[1].x = (short) screen_x2; pointSA[1].y = (short) screen_y2; /* The third point: */ delta_x = (double) (inner_screen_radius + thickness2) * cos (alpha1); delta_y = (double) (inner_screen_radius + thickness2) * sin (alpha1); delta_y *= -1; screen_x2 = screen_x1 + (int) delta_x; screen_y2 = screen_y1 + (int) delta_y; pointSA[2].x = (short) screen_x2; pointSA[2].y = (short) screen_y2; /* The fourth point: */ delta_x = (double) (half_screen_radius + thickness1) * cos (alpha0); delta_y = (double) (half_screen_radius + thickness1) * sin (alpha0); delta_y *= -1; screen_x2 = screen_x1 + (int) delta_x; screen_y2 = screen_y1 + (int) delta_y; pointSA[3].x = (short) screen_x2; pointSA[3].y = (short) screen_y2; /* The fifth point: */ delta_x = (double) (inner_screen_radius + thickness2) * cos (alpha2); delta_y = (double) (inner_screen_radius + thickness2) * sin (alpha2); delta_y *= -1; screen_x2 = screen_x1 + (int) delta_x; screen_y2 = screen_y1 + (int) delta_y; pointSA[4].x = (short) screen_x2; pointSA[4].y = (short) screen_y2; /* The sixth point: */ delta_x = (double) inner_screen_radius * cos (alpha2); delta_y = (double) inner_screen_radius * sin (alpha2); delta_y *= -1; screen_x2 = screen_x1 + (int) delta_x; screen_y2 = screen_y1 + (int) delta_y; pointSA[5].x = (short) screen_x2; pointSA[5].y = (short) screen_y2; /* The seventh point is a copy of the first point: */ pointSA[6].x = pointSA[0].x; pointSA[6].y = pointSA[0].y; /* Prepare the polygon interior color: */ if (residues_in_wheelN > 1) { scale_factor = (double) wheelI / (double) (residues_in_wheelN - 1); } else scale_factor = 0.0; residue_colorID = WeightColors_ (far_colorID, near_colorID, scale_factor, guiSP); XSetForeground (guiSP->displaySP, guiSP->theGCA[2], residue_colorID); /* Draw the filled polygon: */ XFillPolygon (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], pointSA, 6, Complex, CoordModeOrigin); /* Draw the polygon edge: */ XDrawLines (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], pointSA, 7, CoordModeOrigin); /* Update the reference angle (X11 units): */ ref_angle += helix_step; if (ref_angle > 23040) ref_angle = ref_angle - 23040; /* Update the wheel index: */ wheelI++; } } /*------draw titles:---------------------------------------------------------*/ /* Draw titles: */ DrawTitles_ (runtimeSP, guiSP); /*------copy the prepared image to the main window:--------------------------*/ /* Copy hidden pixmap to the main window: */ XCopyArea (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->main_winS.ID, guiSP->theGCA[0], 0, 0, guiSP->main_win_free_area_width, guiSP->main_win_free_area_height, 0, 0); return (size_t) residuesN; } /*===========================================================================*/ garlic-1.6/beta_membrane.c0000644000076500007650000015077207762725570016071 0ustar zuciczucic00000000000000/* Copyright (C) 2003 Damir Zucic */ /*============================================================================= beta_membrane.c Purpose: Find the position and orientation of the membrane with respect to the macromolecular structure. The structure in question should be some membrane protein of beta barrel type. This function wil fail to work properly for alpha helix bundle proteins. Input: (1) Pointer to MolComplexS structure, with the chosen structure. (2) Pointer to RuntimeS structure. (3) Pointer to ConfigS structure (stereo angle required). (4) Pointer to GUIS structure. Output: (1) The membrane position and orientation will be calculated for the first time or updated. (2) Return value. Return value: (1) Positive on success. (2) Negative on failure. Notes: (1) A short description of some tricks used in this function: ------------------------------------------------------------- Step 1: Find the geometric center for CA atoms. Ignore hetero atoms (water, lipids, cofactors etc.). Ignore all other atoms too (C, N, O, side chain atoms etc.). ------------------------------------------------------------- Step 2: Use the CA geometric center and some arbitrary vector to create an axis in space. Associate a cylinder with this axis. The length of this cylinder should be 120 angstroms and the radius may be arbitrary. Divide the cylinder into patches of equal size. The height of a single patch should be 3.0 angstroms (see the parameter CELL_LINEAR_WIDTH in defines.h) and the patch angular width should correspond to the angular range of 36 degrees. Note that the radius of the cylinder and the width of a single patch are not important: what really matters is the angular range of a single patch. Associate an array of cells (data structures) with this cylinder. Scan the protein structure, residue by residue. For a given residue, check the CA-CB vector. If this vector points inwards with respect to the given axis, ignore this residue. Otherwise, project the CB atom position to the surface of the cylinder. Identify the patch to which the CB atom was projected. Find the distance between the CB atom and the axis. Check the distance which was stored before to the cell associated with the patch to which the CB atom was projected. If the current CB is more distant from the axis than the CB atom which was the most distant atom projected before to this patch, occupy the cell with the current CB atom: store the hydrophobicity of the current residue and the distance between CB and the axis. ------------------------------------------------------------- Step 3: Divide the cylinder surface into stripes, parallel to the cylinder surface. For each cell in each stripe, calculate the average hydrophobicity over a given number of neighboring cells. These cells should belong to the same stripe. The sliding window should be comparable to the membrane thickness (or slightly smaller). The unused cells should be ignored. It is possible that average hydrophobicity will not be available for all cells after this step, but this should not cause any major problems. Most of the cells in the central part of the cylinder surface will be filled with average hydrophobicity. ------------------------------------------------------------- Step 4: Divide the cylinder surface into rings. In this step, the averaged hydrophobicities will be used to calculate the second average, this time combining values from the cells which belong to the same ring. This procedure is repeated for each ring. Ignore cells which were skipped in the previous step, i.e. which are missing the average hydrophobicity value. ------------------------------------------------------------- Step 5: Find the most hydrophobic ring. Store the second average of hydrophobicity for later usage. The same procedure is repeated for a number of axes, to cover the full space angle of 4 PI steradijans. Find the axis which gives the highest second average of hydrophobicity. Use the unit vector of this axis as the initial unit vector perpendicular to the membrane. Together with the CA center, this is just enough to define the membrane. ------------------------------------------------------------- Step 6: Refine the orientation of the normal vector. Look for two rings of aromatic residues, PHE, TRP and TYR. Ignore HIS. The transmembrane part of the beta barrel protein has a ring of aromatic residues PHE, TRP and TYR at each end. Ignore all residues pointing outwards with respect to the axis. Project eacg CG atom to a number of cells, covering few angstroms. ------------------------------------------------------------- Step 7: Refine the position of the membrane center. Up to now the position of CA center was used as the membrane center but this is obviously wrong. Project CG atoms of PHE, TRP and TYR over a number of cells, so that each CG covers few angstroms. ------------------------------------------------------------- (2) The minimal distance between the point (x, y, z) and the axis passing through the point (x0, y0, z0), pointing in direction (l, m, n) is: 1 d^2 = --------------- { [ (x - x0) m - (y - y0) l ]^2 + l^2 + m^2 + n^2 [ (y - y0) n - (z - z0) m ]^2 + [ (z - z0) l - (x - x0) n ]^2 } Using x - x0 = dx, y - y0 = dy, z - z0 = dz, l = ex, m = ey and n = ez, where ex, ey and ez are three components of the axis unit vector, the equation looks simpler: distance_squared = (dx * ey - dy * ex)^2 + (dy * ez - dz * ey)^2 + (dz * ex - dx * ez)^2 . The formula was taken from the famous mathematical handbook by I.N. Bronstein and K.A. Semendjajew. However, it was used only for debugging and later it was removed. The distance is now calculated using the absolute value of the perpendicular component of the CA_center_CB_vectorS. The expression from the book was used only to do one extra check. (3) Two strange terms are used here: beta cells and simple cells. The auxiliary cylinder is divided into "beta cells" and the axis used for refinement is divided into "simple cells". (4) Indentation is exceptionally 4 spaces. ========includes:============================================================*/ #include #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int ExtractCA_ (VectorS *, AtomS *, size_t, size_t); int ExtractCACB_ (VectorS *, VectorS *, AtomS *, size_t, size_t); double ScalarProduct_ (VectorS *, VectorS *); void VectorProduct_ (VectorS *, VectorS *, VectorS *); double AbsoluteValue_ (VectorS *); int ExtractCG_ (VectorS *, AtomS *, size_t, size_t); /*======find membrane position (beta barrel version):========================*/ int BetaMembrane_ (MolComplexS *mol_complexSP, RuntimeS *runtimeSP, ConfigS *configSP, GUIS *guiSP) { double membrane_thickness; int simple_cells_along_axisN; double simple_cell_width, recip_simple_width; double projection_width; int simple_window_width, half_simple_window_width; double scan_half_width; int simple_scan_half_width; int max_simpleI, simple_thickness, half_simple_thickness; int beta_cells_along_axisN, cells_in_ringN, half_cells_in_ringN; double beta_cell_linear_width, recip_beta_lin_width; double beta_cell_angular_width, recip_beta_ang_width; int half_window_width, window_width; int beta_index_offset, simple_index_offset; size_t atomsN; int residuesN, residueI; ResidueS *residueSP; int n; VectorS CA_vectorS; VectorS CA_center_vectorS; int CA_atomsN; double reciprocal_denominator; int thetaI, max_thetaI, phiI, max_phiI; double theta, theta_step, phi, phi_step; VectorS axis_unit_vectorS; VectorS aux_vectorS; double scalar_product; double abs_value, reciprocal_abs_value; VectorS unit_vector2S, unit_vector3S; int beta_cellI; BetaCellS *beta_cellSP; VectorS CB_vectorS; VectorS CA_CB_vectorS; VectorS CA_center_CB_vectorS; VectorS parallel_vectorS; VectorS perpendicular_vectorS; double distance; double sin_angle, cos_angle, angle; int axialI, radialI; int localI, combined_radialI; AtomS *first_atomSP; double hydrophobicity, average_hydrophobicity; int cells_usedN; int windowI; int combined_axialI; double second_average; int best_second_average_foundF; double best_second_average; VectorS best_unit_vectorS; VectorS i1_unit_vectorS, j1_unit_vectorS, k1_unit_vectorS; int total_phe_trp_tyrN; char *pure_residue_nameP; double cos_theta, sin_theta, cos_phi, sin_phi; int two_rings_count, best_two_rings_count; int central_simpleI, start_simpleI, end_simpleI, simpleI; int phe_trp_tyrNA[SIMPLE_CELLS_ALONG_AXIS]; VectorS CG_vectorS; VectorS CA_center_CG_vectorS; int start_pointI, end_pointI, pointI; double shift, best_shift; VectorS center_vectorS; VectorS radius_vectorS; double projection; int ring1I, ring2I; /*---------------------------------------------------------------------------*/ /* Copy the membrane thickness: */ membrane_thickness = mol_complexSP->membraneS.thickness; /* Copy the number of simple cells along the axis: */ simple_cells_along_axisN = SIMPLE_CELLS_ALONG_AXIS; /* Prepare the linear width of a single simple cell: */ simple_cell_width = SIMPLE_CELL_WIDTH; recip_simple_width = 1.0 / simple_cell_width; /* Prepare the projection width. The projection of */ /* CG atom will be smeared over a number of cells. */ projection_width = 5.0; /* angstroms. */ /* Prepare the width of a simple window. A single CG atom will */ /* be projected over a number of cells. The simple_window_width */ /* defines how many cells will be covered by a single CG atom. */ simple_window_width = recip_simple_width * projection_width; half_simple_window_width = simple_window_width / 2; /* During the refinement of the membrane center, a range of positions */ /* along the refined unit vector should be scanned. It is defined here: */ scan_half_width = 100.0; simple_scan_half_width = (int) (scan_half_width * recip_simple_width); /* The initial number of simple cells across the given membrane thickness. */ /* This value will be changed before the refinement of the membrane center. */ simple_thickness = (int) (membrane_thickness / simple_cell_width); if (simple_thickness < 3) simple_thickness = 3; half_simple_thickness = simple_thickness / 2; /* Maximal value of the simple index. The simple index is */ /* used during the refinement. The maximal value set here */ /* should prevent the array overflow. Note that ten cells */ /* are wasted, to ensure there will be no array overflow. */ max_simpleI = simple_cells_along_axisN - 1 - simple_thickness - 10; if (max_simpleI < 0) max_simpleI = 0; /* Copy the number of beta cells along the axis of the auxiliary cylinder: */ beta_cells_along_axisN = BETA_CELLS_ALONG_AXIS; /* Copy the number of cells in a single ring around the auxiliary cylinder: */ cells_in_ringN = BETA_CELLS_IN_RING; half_cells_in_ringN = cells_in_ringN / 2; /* Prepare the linear width of a single beta cell: */ beta_cell_linear_width = BETA_CELL_LINEAR_WIDTH; recip_beta_lin_width = 1.0 / beta_cell_linear_width; /* Prepare the angular width of a single beta cell: */ beta_cell_angular_width = 6.2831853 / (double) cells_in_ringN; recip_beta_ang_width = 1.0 / beta_cell_angular_width; /* Prepare the sliding window width. This number should */ /* be odd. It should not reach the hydrophilic residues. */ n = (int) (membrane_thickness / beta_cell_linear_width); half_window_width = (n - 1) / 2; if (half_window_width < 1) return -1; window_width = 2 * half_window_width + 1; /* The height of the CA center with respect to the base of the */ /* cylinder should reach the middle of the auxiliary cylinder. */ /* To ensure this, the axial index should be shifted properly: */ beta_index_offset = beta_cells_along_axisN / 2; /* During the refinement, the CA center should be */ /* projected to the central cell along the axis. */ simple_index_offset = simple_cells_along_axisN / 2; /* Copy and check the number of atoms: */ atomsN = mol_complexSP->atomsN; if (atomsN == 0) return -2; /* Copy and check the number of residues: */ residuesN = mol_complexSP->residuesN; if (residuesN < window_width) return -3; /*------(1) find the geometric center for CA atoms:-------------------------*/ /* Initialize the CA center: */ CA_center_vectorS.x = 0.0; CA_center_vectorS.y = 0.0; CA_center_vectorS.z = 0.0; /* Initialize the number of CA atoms: */ CA_atomsN = 0; /* Scan the macromol. complex, residue by residue, ignoring water molecules: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Pointer to the current residue: */ residueSP = mol_complexSP->residueSP + residueI; /* Try to extraxt the coordinates of CA atom: */ n = ExtractCA_ (&CA_vectorS, mol_complexSP->atomSP, residueSP->residue_startI, residueSP->residue_endI); if (n < 1) continue; /* Update the CA geometric center: */ CA_center_vectorS.x += CA_vectorS.x; CA_center_vectorS.y += CA_vectorS.y; CA_center_vectorS.z += CA_vectorS.z; /* Update the counter of CA atoms: */ CA_atomsN++; } /* If there were no CA atoms at all, return error indicator: */ if (CA_atomsN == 0) return -4; /* Calculate the geometric center of CA atoms: */ reciprocal_denominator = 1.0 / (double) CA_atomsN; CA_center_vectorS.x *= reciprocal_denominator; CA_center_vectorS.y *= reciprocal_denominator; CA_center_vectorS.z *= reciprocal_denominator; /* Take this point as the initial membrane center: */ mol_complexSP->membraneS.center_x = CA_center_vectorS.x; mol_complexSP->membraneS.center_y = CA_center_vectorS.y; mol_complexSP->membraneS.center_z = CA_center_vectorS.z; /*------scan a number of directions in space:--------------------------------*/ /* Initialize the parameters which define a total number of directions: */ max_thetaI = 18; max_phiI = 72; /* Prepare the angular increments. Note that only half of the full theta */ /* angle is used: we do not distinguish two sides of the membrane here. */ theta_step = 1.5707963 / (double) max_thetaI; phi_step = 6.2831853 / (double) max_phiI; /* Initialize the flag which will be set to one if the */ /* best second average of hydrophobicity will be found: */ best_second_average_foundF = 0; /* Initialize the best second average, just to avoid compiler complaints: */ best_second_average = -99999.00; /* Initialize the best axis unit vector, for any case: */ best_unit_vectorS.x = 0.0; best_unit_vectorS.y = 1.0; best_unit_vectorS.z = 0.0; /* Scan a number of directions in space. The spherical polar system is used. */ /* Theta scan: */ for (thetaI = 0; thetaI <= max_thetaI; thetaI++) { /* Prepare the angle theta: */ theta = (double) thetaI * theta_step; /* Phi scan: */ for (phiI = 0; phiI <= max_phiI; phiI++) { /* Avoid to check too many directions close */ /* to the pole. If the theta angle is equal */ /* to zero, one phi value should be enough: */ if (thetaI == 0) { if (phiI != 0) continue; } /* If theta is too small, skip every second direction: */ if (thetaI <= 2) { n = phiI / 2; if (n * 2 != phiI) continue; } /* Prepare the angle phi: */ phi = (double) phiI * phi_step; /* The unit vector which defines the axis direction: */ axis_unit_vectorS.x = sin (theta) * cos (phi); axis_unit_vectorS.y = sin (theta) * sin (phi); axis_unit_vectorS.z = cos (theta); /* Two additional vectors are associated with each axis: */ /* unit_vector2S and unit_vector3S. These two vectors will */ /* be used to define which cell is the first one in each */ /* ring of cells. Without these two vectors, it will be */ /* unclear to which cell the CB atom should be projected. */ /* To prepare the unit_vector2S, use the unit vector parallel */ /* to the x axis to define the plane. If it is too close to the */ /* cylinder axis use the unit vector parallel to the y axis. */ /* The first choice of auxiliary vector: */ aux_vectorS.x = 1.0; aux_vectorS.y = 0.0; aux_vectorS.z = 0.0; /* Check the scalar product with the axis unit vector. Both */ /* vectors are normalized, so in the worst case the scalar */ /* product will be equal to one. A value above 0.9 is taken */ /* as a threshold to recognize the bad pair of unit vectors. */ if (ScalarProduct_ (&aux_vectorS, &axis_unit_vectorS) > 0.9) { /* The second choice: */ aux_vectorS.x = 0.0; aux_vectorS.y = 1.0; aux_vectorS.z = 0.0; } /* Now it is certain that axis_unit_vectorS and */ /* aux_vectorS are not parallel. Calculate and */ /* normalize the vector product of these vectors. */ VectorProduct_ (&unit_vector2S, &axis_unit_vectorS, &aux_vectorS); abs_value = AbsoluteValue_ (&unit_vector2S); if (abs_value == 0.0) continue; /* Yes, I am paranoic! */ reciprocal_abs_value = 1.0 / abs_value; unit_vector2S.x *= reciprocal_abs_value; unit_vector2S.y *= reciprocal_abs_value; unit_vector2S.z *= reciprocal_abs_value; /* Prepare the third unit vector. As both axis_unit_vectorS */ /* and unit_vector2S are normalized and mutually orthogonal, */ /* the vector product of these vectors will be normalized too. */ VectorProduct_ (&unit_vector3S, &axis_unit_vectorS, &unit_vector2S); /* Reset the array of BetaCellS structures: */ for (beta_cellI = 0; beta_cellI < runtimeSP->beta_cellsN; beta_cellI++) { beta_cellSP = runtimeSP->beta_cellSP + beta_cellI; beta_cellSP->cell_usedF = 0; beta_cellSP->distance = 0.0; beta_cellSP->hydrophobicity = 0.0; beta_cellSP->cells_usedN = 0; beta_cellSP->average_calculatedF = 0; beta_cellSP->average_hydrophobicity = 0.0; } /*------(2) project surface CB atoms to cylinder surface:------------*/ /* Scan residues: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Pointer to the current residue: */ residueSP = mol_complexSP->residueSP + residueI; /* Try to extract the CA and CB coordinates: */ n = ExtractCACB_ (&CA_vectorS, &CB_vectorS, mol_complexSP->atomSP, residueSP->residue_startI, residueSP->residue_endI); if (n < 2) continue; /* Prepare the vector from CA to CB: */ CA_CB_vectorS.x = CB_vectorS.x - CA_vectorS.x; CA_CB_vectorS.y = CB_vectorS.y - CA_vectorS.y; CA_CB_vectorS.z = CB_vectorS.z - CA_vectorS.z; /* The vector from the CA geometric center */ /* to the CB atom of the current residue: */ CA_center_CB_vectorS.x = CB_vectorS.x - CA_center_vectorS.x; CA_center_CB_vectorS.y = CB_vectorS.y - CA_center_vectorS.y; CA_center_CB_vectorS.z = CB_vectorS.z - CA_center_vectorS.z; /* The scalar product between this */ /* vector and the axis unit vector: */ scalar_product = ScalarProduct_ (&CA_center_CB_vectorS, &axis_unit_vectorS); /* The parallel component of the vector from the */ /* CA center to the CB atom of the current residue: */ parallel_vectorS.x = scalar_product * axis_unit_vectorS.x; parallel_vectorS.y = scalar_product * axis_unit_vectorS.y; parallel_vectorS.z = scalar_product * axis_unit_vectorS.z; /* The perpendicular component: */ perpendicular_vectorS.x = CA_center_CB_vectorS.x - parallel_vectorS.x; perpendicular_vectorS.y = CA_center_CB_vectorS.y - parallel_vectorS.y; perpendicular_vectorS.z = CA_center_CB_vectorS.z - parallel_vectorS.z; /* Calculate and check the distance from the axis. */ /* Skip residues whose CB atoms are too close to */ /* the axis, they do not belong to the barrel wall. */ /* A limit of eight angstroms might be reasonable. */ distance = AbsoluteValue_ (&perpendicular_vectorS); if (distance <= 8.0) continue; /* Check the scalar product between the CA-CB vector and */ /* the perpendicular component of the vector from the CA */ /* center to the CB atom of the current residue. If it */ /* is negative the CA-CB vector points towards the axis. */ scalar_product = ScalarProduct_ (&CA_CB_vectorS, &perpendicular_vectorS); if (scalar_product < 0.0) continue; /* If this point is reached, the CA-CB bond */ /* points outwards with respect to the axis. */ /* Project the CB coordinates to the */ /* surface of the auxiliary cylinder. */ /* To find the cell to which CB should be projected, */ /* two indices are required: axial and radial index. */ /* The parallel part of the vector from the CA center */ /* to the CB atom will be used to calculate the axial */ /* index of the cell to which the CB atom should be */ /* projected. The perpendicular component of the same */ /* vector will be used to calculate the radial index. */ /* Axial index is calculated from the projection of the */ /* parallel component of CA_center_CB_vectorS to the axis: */ scalar_product = ScalarProduct_ (¶llel_vectorS, &axis_unit_vectorS); axialI = (int) (recip_beta_lin_width * scalar_product) + beta_index_offset; /* Check the axial index, to avoid the arary overflow: */ if (axialI < 0) continue; if (axialI >= beta_cells_along_axisN) continue; /* The angle in radians is required to calculate the */ /* radial index. The angular range if from 0 to 2 PI. */ /* Calculate the arc cosine using the scalar product between the */ /* perpendicular component of the CA_center_CB_vectorS and the */ /* unit_vector2S. The result will be in the range from 0 to PI. */ scalar_product = ScalarProduct_ (&perpendicular_vectorS, &unit_vector2S); cos_angle = scalar_product / distance; if (cos_angle <= -1.0) angle = 3.1415927; else if (cos_angle >= 1.0) angle = 0.0; else angle = acos (cos_angle); /* The scalar product between the perpendicular */ /* component of the CA_center_CB_vectorS and the */ /* unit_vector3S is used to resolve the ambiguity. */ /* If it is negative, the angle should be fixed. */ scalar_product = ScalarProduct_ (&perpendicular_vectorS, &unit_vector3S); if (scalar_product < 0.0) angle = 6.2831853 - angle; /* Now it is possible to calculate the radial index: */ radialI = recip_beta_ang_width * angle; /* Check the radial index, to avoid the arary overflow: */ if (radialI < 0) continue; if (radialI >= cells_in_ringN) continue; /* Check the cell defined by the given pair */ /* of indices and two adjacent cells in the */ /* plane which is perpendicular to the axis. */ /* Scan the window of three cells: */ for (localI = -1; localI <= 1; localI++) { /* Prepare and check the combined index: */ combined_radialI = radialI + localI; if (combined_radialI < 0) { combined_radialI = cells_in_ringN - 1; } else if (combined_radialI >= cells_in_ringN) { combined_radialI = 0; } /* Now the cell to which the CB atom should be */ /* projected is identified. Check was it used */ /* before. If not, just store the information */ /* about this CB atom. If it was used, compare */ /* the distance from the axis of this CB atom */ /* with the value which was stored before to */ /* the cell defined by the given axialI and */ /* combined_radialI. If this CB atom is not the */ /* most distant CB atom projected to this cell, */ /* ignore it. If it is, change the cell content. */ /* The index of BetaCellsS structure to */ /* which the CB atom should be projected. */ /* The array is indexed ring by ring. */ beta_cellI = axialI * cells_in_ringN + combined_radialI; /* A true paranoic will make some extra checks: */ if (beta_cellI < 0) continue; if (beta_cellI >= runtimeSP->beta_cellsN) continue; /* The pointer to this BetaCellS structure: */ beta_cellSP = runtimeSP->beta_cellSP + beta_cellI; /* If this cell was not used before, just fill it: */ if (beta_cellSP->cell_usedF == 0) { beta_cellSP->cell_usedF = 1; beta_cellSP->distance = distance; first_atomSP = mol_complexSP->atomSP + residueSP->residue_startI; hydrophobicity = first_atomSP->raw_atomS.hydrophobicity; beta_cellSP->hydrophobicity = hydrophobicity; } /* If it was used before, compare the old and new distance: */ else { if (beta_cellSP->distance > distance) continue; /* If this point is reached, the given CB atom is the */ /* most distant CB atom projected to the given cell. */ beta_cellSP->distance = distance; first_atomSP = mol_complexSP->atomSP + residueSP->residue_startI; hydrophobicity = first_atomSP->raw_atomS.hydrophobicity; beta_cellSP->hydrophobicity = hydrophobicity; } /* End of localI loop: */ } /* End of residueI loop: */ } /*------(3) calculate average hydrophob. (axial scan):---------------*/ /* Now comes the averaging. */ /* Scan the cylinder surface, stripe by stripe. All stripes are */ /* parallel to the axis. The sliding window width (used to calculate */ /* the average hydrophobicity with a given residue in the center) */ /* is set to cover the entire membrane thickness (but no more than */ /* that). For example, if membrane thickness is 30 angstroms the */ /* window width will be about 10, because in axis direction one cell */ /* covers 3 angstroms. Odd number is recommended, so the final width */ /* is 9. If 11 cells were used hydrophilic residues may be reached. */ /* The outermost loop scans the surface, stripe by stripe: */ for (radialI = 0; radialI < cells_in_ringN; radialI++) { /* The next loop scans the given stripe, cell by cell. The cells */ /* which are too close to either top or bottom edge are skipped. */ for (axialI = 0; axialI < beta_cells_along_axisN; axialI++) { if (axialI < half_window_width) continue; if (axialI + half_window_width >= beta_cells_along_axisN) { continue; } /* Reset the number of useful cells in the sliding window: */ cells_usedN = 0; /* Reset the average hydrophobicity: */ average_hydrophobicity = 0.0; /* Somewhere above the flag average_calculatedF */ /* was cleared (set to zero) for all cells. It */ /* is not necessary to clear these flags again. */ /* The innermost loop scans the sliding */ /* window centered at the given cell: */ for (windowI = 0; windowI < window_width; windowI++) { /* Prepare the combined axial index: */ combined_axialI = axialI + windowI - half_window_width; /* The cell array index: */ beta_cellI = combined_axialI * cells_in_ringN + radialI; /* Pointer to the current cell: */ beta_cellSP = runtimeSP->beta_cellSP + beta_cellI; /* If this cell was unused, skip it: */ if (beta_cellSP->cell_usedF == 0) continue; /* If this point is reached, this cell is useful. */ /* Add the hydrophobicity of this cell to the total: */ average_hydrophobicity += beta_cellSP->hydrophobicity; /* Update the counter: */ cells_usedN++; } /* If there were too many unused cells in this sliding */ /* window, the cell in the center of this sliding window */ /* should be treated as useless. The cell will be treated */ /* as useful if at least half_window_width + 1 cells in */ /* the sliding window associated with this cell were used. */ if (cells_usedN < half_window_width + 1) continue; /* Divide the total hydrophobicity by the number of cells: */ average_hydrophobicity /= (double) cells_usedN; /* Store the average hydrophobicity and the number */ /* of used cells and set the flag which says that */ /* average hydrophob. was successfully calculated. */ /* Store it to the cell which was in the middle */ /* of the sliding window which was just scanned. */ beta_cellI = axialI * cells_in_ringN + radialI; beta_cellSP = runtimeSP->beta_cellSP + beta_cellI; beta_cellSP->average_hydrophobicity = average_hydrophobicity; beta_cellSP->cells_usedN = cells_usedN; beta_cellSP->average_calculatedF = 1; } } /*------(4) calculate average hydrophob. (radial scan):--------------*/ /* The outermost loop scans the surface, ring by ring: */ for (axialI = 0; axialI < beta_cells_along_axisN; axialI++) { /* Reset the number of useful cells in the ring: */ cells_usedN = 0; /* Reset the second average of hydrophobicity: */ second_average = 0.0; /* The next loop scans the entire ring at the */ /* given height defined by axialI, cell by cell: */ for (radialI = 0; radialI < cells_in_ringN; radialI++) { /* The cell array index: */ beta_cellI = axialI * cells_in_ringN + radialI; /* Pointer to this cell: */ beta_cellSP = runtimeSP->beta_cellSP + beta_cellI; /* If the average hydrophobicity is not */ /* available for this cell, skip it: */ if (beta_cellSP->average_calculatedF == 0) continue; /* If this point is reached, this cell is useful. */ /* Add the hydrophobicity of this cell to the total: */ second_average += beta_cellSP->average_hydrophobicity; /* Update the counter: */ cells_usedN++; } /* At least half of the cells in this ring should be */ /* useful, otherwise the second average is useless: */ if (cells_usedN < half_cells_in_ringN) continue; /* Divide the total by the number of cells: */ second_average /= (double) cells_usedN; /* If this is the first second average at all, just copy it: */ if (best_second_average_foundF == 0) { best_second_average = second_average; best_second_average_foundF = 1; best_unit_vectorS.x = axis_unit_vectorS.x; best_unit_vectorS.y = axis_unit_vectorS.y; best_unit_vectorS.z = axis_unit_vectorS.z; continue; } /*------(5) check is it the most hydrophobic ring:---------------*/ /* Now check is there any chance that this value is the */ /* highest value of the second average up to now. If it */ /* is, update the best value and store theta and phi: */ if (second_average > best_second_average) { best_second_average = second_average; best_second_average_foundF = 1; best_unit_vectorS.x = axis_unit_vectorS.x; best_unit_vectorS.y = axis_unit_vectorS.y; best_unit_vectorS.z = axis_unit_vectorS.z; } } /* End of phiI loop: */ } /* End of thetaI loop: */ } /*------store the normal vector (raw):---------------------------------------*/ /* Store (copy) the components of the normal */ /* vector because the refinement may fail. */ /* The normal vector of the first plane points to the same direction: */ mol_complexSP->membraneS.plane1S.normal_x[0] = best_unit_vectorS.x; mol_complexSP->membraneS.plane1S.normal_y = best_unit_vectorS.y; mol_complexSP->membraneS.plane1S.normal_z[0] = best_unit_vectorS.z; /* The normal vector of the second plane points to the opposite direction: */ mol_complexSP->membraneS.plane2S.normal_x[0] = -best_unit_vectorS.x; mol_complexSP->membraneS.plane2S.normal_y = -best_unit_vectorS.y; mol_complexSP->membraneS.plane2S.normal_z[0] = -best_unit_vectorS.z; /*------prepare stereo data (raw):-------------------------------------------*/ /* Prepare the stereo data for both normal vectors. */ /* This is useful because the refinement may fail. */ /* Prepare the sine and cosine of the stereo angle: */ sin_angle = sin (configSP->stereo_angle); cos_angle = cos (configSP->stereo_angle); /* Calculate the stereo data: */ mol_complexSP->membraneS.plane1S.normal_x[1] = mol_complexSP->membraneS.plane1S.normal_x[0] * cos_angle + mol_complexSP->membraneS.plane1S.normal_z[0] * sin_angle; mol_complexSP->membraneS.plane1S.normal_z[1] = -mol_complexSP->membraneS.plane1S.normal_x[0] * sin_angle + mol_complexSP->membraneS.plane1S.normal_z[0] * cos_angle; mol_complexSP->membraneS.plane2S.normal_x[1] = mol_complexSP->membraneS.plane2S.normal_x[0] * cos_angle + mol_complexSP->membraneS.plane2S.normal_z[0] * sin_angle; mol_complexSP->membraneS.plane2S.normal_z[1] = -mol_complexSP->membraneS.plane2S.normal_x[0] * sin_angle + mol_complexSP->membraneS.plane2S.normal_z[0] * cos_angle; /*------(6) search two rings of PHE, TRP and TYR:----------------------------*/ /* In this procedure, a new coordinate system will be used. Three axes */ /* of this system are defined by i1_unit_vectorS, j1_unit_vectorS and */ /* k1_unit_vectorS. The best unit vector found in the procedure above will */ /* be used to define the z axis, i.e. it will be used as k1_unit_vectorS. */ /* Prepare the unit vector which define the z axis of a new system: */ k1_unit_vectorS.x = best_unit_vectorS.x; k1_unit_vectorS.y = best_unit_vectorS.y; k1_unit_vectorS.z = best_unit_vectorS.z; /* To prepare the unit vector which defines the y axis of a new */ /* system, use the unit vector parallel to the x axis of the main */ /* coordinate system to define the plane. If it is too close to new */ /* z axis use the unit vector parallel to y axis of the main system. */ /* The first choice of auxiliary vector: */ aux_vectorS.x = 1.0; aux_vectorS.y = 0.0; aux_vectorS.z = 0.0; /* Check the scalar product with k1_unit_vectorS. Both these */ /* vectors are normalized, so in the worst case the scalar */ /* product will be equal to one. A value above 0.9 is taken */ /* as a threshold to recognize the bad pair of unit vectors. */ if (ScalarProduct_ (&aux_vectorS, &k1_unit_vectorS) > 0.9) { /* The second choice: */ aux_vectorS.x = 0.0; aux_vectorS.y = 1.0; aux_vectorS.z = 0.0; } /* Now it is certain that k1_unit_vectorS and aux_vectorS are */ /* not parallel. Calculate and normalize the vector product. */ VectorProduct_ (&j1_unit_vectorS, &k1_unit_vectorS, &aux_vectorS); abs_value = AbsoluteValue_ (&j1_unit_vectorS); if (abs_value == 0.0) return -5; /* Yes, I am paranoic! */ reciprocal_abs_value = 1.0 / abs_value; j1_unit_vectorS.x *= reciprocal_abs_value; j1_unit_vectorS.y *= reciprocal_abs_value; j1_unit_vectorS.z *= reciprocal_abs_value; /* The third unit vector, parallel to x axis of a new system: */ VectorProduct_ (&i1_unit_vectorS, &j1_unit_vectorS, &k1_unit_vectorS); /* Initialize the total number of PHE, TRP and */ /* TYR residues in this macromolecular complex. */ total_phe_trp_tyrN = 0; /* Scan the macromolecular complex, residue by residue. For each */ /* residue, check is it PHE, TRP or TYR. If it is, set auxiliaryI */ /* of the first atom to one. If not, set the auxiliaryI to zero. */ for (residueI = 0; residueI < residuesN; residueI++) { /* Pointer to the current residue: */ residueSP = mol_complexSP->residueSP + residueI; /* Pointer to the first atom: */ first_atomSP = mol_complexSP->atomSP + residueSP->residue_startI; /* The purified residue name (without spaces): */ pure_residue_nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Check the purified residue name: */ if (strcmp (pure_residue_nameP, "PHE") == 0) { first_atomSP->auxiliaryI = 1; total_phe_trp_tyrN++; } else if (strcmp (pure_residue_nameP, "TRP") == 0) { first_atomSP->auxiliaryI = 2; total_phe_trp_tyrN++; } else if (strcmp (pure_residue_nameP, "TYR") == 0) { first_atomSP->auxiliaryI = 3; total_phe_trp_tyrN++; } else first_atomSP->auxiliaryI = 0; } if (total_phe_trp_tyrN <= 1) return -6; /* Scan a cone about the k1_unit_vectorS. */ /* The spherical polar system is used. */ /* Initialize the parameters which define a total number of directions: */ max_thetaI = 30; max_phiI = 72; /* Prepare the angular increments. The maximal allowed */ /* deviation from the initial vector is 45 degrees. */ theta_step = 0.7853982 / (double) max_thetaI; phi_step = 6.2831853 / (double) max_phiI; /* Reset the highest number of PHE, TRP */ /* and TYR residues in two selected rings: */ best_two_rings_count = 0; /* Theta scan: */ for (thetaI = 0; thetaI <= max_thetaI; thetaI++) { /* Prepare the angle theta: */ theta = (double) thetaI * theta_step; /* Phi scan: */ for (phiI = 0; phiI <= max_phiI; phiI++) { /* Avoid to check too many directions close */ /* to the pole. If the theta angle is equal */ /* to zero, one phi value should be enough: */ if (thetaI == 0) { if (phiI != 0) continue; } /* If theta is too small, skip every second direction: */ if (thetaI <= 2) { n = phiI / 2; if (n * 2 != phiI) continue; } /* Prepare the angle phi: */ phi = (double) phiI * phi_step; /* The unit vector which defines the axis direction: */ cos_theta = cos (theta); sin_theta = sin (theta); cos_phi = cos (phi); sin_phi = sin (phi); axis_unit_vectorS.x = sin_theta * cos_phi * i1_unit_vectorS.x + sin_theta * sin_phi * j1_unit_vectorS.x + cos_theta * k1_unit_vectorS.x; axis_unit_vectorS.y = sin_theta * cos_phi * i1_unit_vectorS.y + sin_theta * sin_phi * j1_unit_vectorS.y + cos_theta * k1_unit_vectorS.y; axis_unit_vectorS.z = sin_theta * cos_phi * i1_unit_vectorS.z + sin_theta * sin_phi * j1_unit_vectorS.z + cos_theta * k1_unit_vectorS.z; /* Reset the array which counts PHE, TRP */ /* and TYR residues projected to the axis: */ for (simpleI = 0; simpleI < simple_cells_along_axisN; simpleI++) { phe_trp_tyrNA[simpleI] = 0; } /* Scan residues: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Pointer to the current residue: */ residueSP = mol_complexSP->residueSP + residueI; /* Pointer to the first atom of this residue: */ first_atomSP = mol_complexSP->atomSP + residueSP->residue_startI; /* Check the auxiliaryI of the first atom; if */ /* it is equal to zero, ignore this residue. */ if (first_atomSP->auxiliaryI == 0) continue; /* Try to extract the CA and CB coordinates: */ n = ExtractCACB_ (&CA_vectorS, &CB_vectorS, mol_complexSP->atomSP, residueSP->residue_startI, residueSP->residue_endI); if (n < 2) continue; /* Prepare the vector from CA to CB: */ CA_CB_vectorS.x = CB_vectorS.x - CA_vectorS.x; CA_CB_vectorS.y = CB_vectorS.y - CA_vectorS.y; CA_CB_vectorS.z = CB_vectorS.z - CA_vectorS.z; /* The vector from the CA geometric center */ /* to the CB atom of the current residue: */ CA_center_CB_vectorS.x = CB_vectorS.x - CA_center_vectorS.x; CA_center_CB_vectorS.y = CB_vectorS.y - CA_center_vectorS.y; CA_center_CB_vectorS.z = CB_vectorS.z - CA_center_vectorS.z; /* The scalar product between this */ /* vector and the axis unit vector: */ scalar_product = ScalarProduct_ (&CA_center_CB_vectorS, &axis_unit_vectorS); /* The parallel component of the vector from the */ /* CA center to the CB atom of the current residue: */ parallel_vectorS.x = scalar_product * axis_unit_vectorS.x; parallel_vectorS.y = scalar_product * axis_unit_vectorS.y; parallel_vectorS.z = scalar_product * axis_unit_vectorS.z; /* The perpendicular component: */ perpendicular_vectorS.x = CA_center_CB_vectorS.x - parallel_vectorS.x; perpendicular_vectorS.y = CA_center_CB_vectorS.y - parallel_vectorS.y; perpendicular_vectorS.z = CA_center_CB_vectorS.z - parallel_vectorS.z; /* Calculate and check the distance from the axis. */ /* Skip residues whose CB atoms are too close to */ /* the axis, they do not belong to the barrel wall. */ /* A limit of eleven angstroms might be reasonable. */ distance = AbsoluteValue_ (&perpendicular_vectorS); if (distance <= 11.0) continue; /* Check the scalar product between the CA-CB vector and */ /* the perpendicular component of the vector from the CA */ /* center to the CB atom of the current residue. If it */ /* is negative the CA-CB vector points towards the axis. */ scalar_product = ScalarProduct_ (&CA_CB_vectorS, &perpendicular_vectorS); if (scalar_product < 0.0) continue; /* If this point is reached, the CA-CB bond */ /* points outwards with respect to the axis. */ /* Extract the coordinates of the CG atom: */ n = ExtractCG_ (&CG_vectorS, mol_complexSP->atomSP, residueSP->residue_startI, residueSP->residue_endI); if (n < 1) continue; /* The CG atom will be projected over a number of cells. */ /* The index of the central cell will be calculated from */ /* parallel part of the vector from CA center to CG atom. */ /* The vector from the CA geometric center */ /* to the CG atom of the current residue: */ CA_center_CG_vectorS.x = CG_vectorS.x - CA_center_vectorS.x; CA_center_CG_vectorS.y = CG_vectorS.y - CA_center_vectorS.y; CA_center_CG_vectorS.z = CG_vectorS.z - CA_center_vectorS.z; /* The scalar product between this */ /* vector and the axis unit vector: */ scalar_product = ScalarProduct_ (&CA_center_CG_vectorS, &axis_unit_vectorS); /* The parallel component of the vector from the */ /* CA center to the CG atom of the current residue: */ parallel_vectorS.x = scalar_product * axis_unit_vectorS.x; parallel_vectorS.y = scalar_product * axis_unit_vectorS.y; parallel_vectorS.z = scalar_product * axis_unit_vectorS.z; /* The index of central simple cell is calculated */ /* from the projection of the parallel component of */ /* CA_center_CB_vectorS to the axis_unit_vectorS: */ scalar_product = ScalarProduct_ (¶llel_vectorS, &axis_unit_vectorS); central_simpleI = (int) (recip_simple_width * scalar_product) + simple_index_offset; /* The CG atom will be projected over a number of cells. */ /* The side chains which form the ring of aromatic */ /* residues are not perfectly aligned and for that */ /* reason the CG atom will be smeared over more cells. */ /* This should improve recognition of aromatic rings. */ start_simpleI = central_simpleI - half_simple_window_width; end_simpleI = start_simpleI + simple_window_width; /* Smear CG projection over a number of cells: */ for (simpleI = start_simpleI; simpleI <= end_simpleI; simpleI++) { /* Do not allow array overflow: */ if (simpleI < 0) continue; if (simpleI >= simple_cells_along_axisN) break; /* Update the number of PHE, TRP and TYR residues which */ /* were projected to the cell defined by this simpleI: */ phe_trp_tyrNA[simpleI]++; } /* End of residueI loop: */ } /* For this orientation, check the total number of PHE, TRP and TYR */ /* residues in two rings separated by the given membrane thickness. */ for (simpleI = 0; simpleI < max_simpleI; simpleI++) { two_rings_count = phe_trp_tyrNA[simpleI] + phe_trp_tyrNA[simpleI + simple_thickness]; if (two_rings_count > best_two_rings_count) { best_two_rings_count = two_rings_count; best_unit_vectorS.x = axis_unit_vectorS.x; best_unit_vectorS.y = axis_unit_vectorS.y; best_unit_vectorS.z = axis_unit_vectorS.z; } } /* End of phiI loop: */ } /* End of thetaI loop: */ } /*------store the normal vector (refined):-----------------------------------*/ /* Store (copy) the components of the normal vector. */ /* The normal vector of the first plane points to the same direction: */ mol_complexSP->membraneS.plane1S.normal_x[0] = best_unit_vectorS.x; mol_complexSP->membraneS.plane1S.normal_y = best_unit_vectorS.y; mol_complexSP->membraneS.plane1S.normal_z[0] = best_unit_vectorS.z; /* The normal vector of the second plane points to the opposite direction: */ mol_complexSP->membraneS.plane2S.normal_x[0] = -best_unit_vectorS.x; mol_complexSP->membraneS.plane2S.normal_y = -best_unit_vectorS.y; mol_complexSP->membraneS.plane2S.normal_z[0] = -best_unit_vectorS.z; /*------prepare stereo data (refined):---------------------------------------*/ /* Prepare the stereo data for both normal vectors. */ /* Prepare the sine and cosine of the stereo angle: */ sin_angle = sin (configSP->stereo_angle); cos_angle = cos (configSP->stereo_angle); /* Calculate the stereo data: */ mol_complexSP->membraneS.plane1S.normal_x[1] = mol_complexSP->membraneS.plane1S.normal_x[0] * cos_angle + mol_complexSP->membraneS.plane1S.normal_z[0] * sin_angle; mol_complexSP->membraneS.plane1S.normal_z[1] = -mol_complexSP->membraneS.plane1S.normal_x[0] * sin_angle + mol_complexSP->membraneS.plane1S.normal_z[0] * cos_angle; mol_complexSP->membraneS.plane2S.normal_x[1] = mol_complexSP->membraneS.plane2S.normal_x[0] * cos_angle + mol_complexSP->membraneS.plane2S.normal_z[0] * sin_angle; mol_complexSP->membraneS.plane2S.normal_z[1] = -mol_complexSP->membraneS.plane2S.normal_x[0] * sin_angle + mol_complexSP->membraneS.plane2S.normal_z[0] * cos_angle; /*------update auxiliaryI:---------------------------------------------------*/ /* In this section, the auxiliaryI for PHE, TRP and TYR will */ /* be set to zero for side chains which are pointing inwards. */ /* This should improve performance: the axis orientation during */ /* the membrane center refinement is not subject to change. */ for (residueI = 0; residueI < residuesN; residueI++) { /* Pointer to the current residue: */ residueSP = mol_complexSP->residueSP + residueI; /* Pointer to the first atom of this residue: */ first_atomSP = mol_complexSP->atomSP + residueSP->residue_startI; /* Check the auxiliaryI of the first atom; if */ /* it is equal to zero, ignore this residue. */ if (first_atomSP->auxiliaryI == 0) continue; /* Try to extract the CA and CB coordinates: */ n = ExtractCACB_ (&CA_vectorS, &CB_vectorS, mol_complexSP->atomSP, residueSP->residue_startI, residueSP->residue_endI); if (n < 2) continue; /* Prepare the vector from CA to CB: */ CA_CB_vectorS.x = CB_vectorS.x - CA_vectorS.x; CA_CB_vectorS.y = CB_vectorS.y - CA_vectorS.y; CA_CB_vectorS.z = CB_vectorS.z - CA_vectorS.z; /* The vector from the CA geometric center */ /* to the CB atom of the current residue: */ CA_center_CB_vectorS.x = CB_vectorS.x - CA_center_vectorS.x; CA_center_CB_vectorS.y = CB_vectorS.y - CA_center_vectorS.y; CA_center_CB_vectorS.z = CB_vectorS.z - CA_center_vectorS.z; /* The scalar product between this */ /* vector and the axis unit vector: */ scalar_product = ScalarProduct_ (&CA_center_CB_vectorS, &axis_unit_vectorS); /* The parallel component of the vector from the */ /* CA center to the CB atom of the current residue: */ parallel_vectorS.x = scalar_product * axis_unit_vectorS.x; parallel_vectorS.y = scalar_product * axis_unit_vectorS.y; parallel_vectorS.z = scalar_product * axis_unit_vectorS.z; /* The perpendicular component: */ perpendicular_vectorS.x = CA_center_CB_vectorS.x - parallel_vectorS.x; perpendicular_vectorS.y = CA_center_CB_vectorS.y - parallel_vectorS.y; perpendicular_vectorS.z = CA_center_CB_vectorS.z - parallel_vectorS.z; /* Calculate and check the distance from the axis. */ /* Skip residues whose CB atoms are too close to */ /* the axis, they do not belong to the barrel wall. */ /* A limit of eleven angstroms might be reasonable. */ distance = AbsoluteValue_ (&perpendicular_vectorS); if (distance <= 11.0) continue; /* Check the scalar product between the CA-CB vector and */ /* the perpendicular component of the vector from the CA */ /* center to the CB atom of the current residue. If it */ /* is negative the CA-CB vector points towards the axis. */ scalar_product = ScalarProduct_ (&CA_CB_vectorS, &perpendicular_vectorS); if (scalar_product < 0.0) first_atomSP->auxiliaryI = 0; } /*------(7) refine the membrane center:--------------------------------------*/ /* Initialize the best shift: */ best_shift = 0.0; /* Reset the highest number of PHE, TRP */ /* and TYR residues in two selected rings: */ best_two_rings_count = 0; /* Scan a number of positions along the refined axis. The old CA */ /* center should fall in the middle of the array of simple cells. */ start_pointI = -simple_scan_half_width; end_pointI = simple_scan_half_width; for (pointI = start_pointI; pointI <= end_pointI; pointI++) { /* Shift, in angstroms: */ shift = (double) pointI * simple_cell_width; /* Presumed membrane center position: */ center_vectorS.x = CA_center_vectorS.x + shift * best_unit_vectorS.x; center_vectorS.y = CA_center_vectorS.y + shift * best_unit_vectorS.y; center_vectorS.z = CA_center_vectorS.z + shift * best_unit_vectorS.z; /* Reset the array which counts PHE, TRP */ /* and TYR residues projected to the axis: */ for (simpleI = 0; simpleI < simple_cells_along_axisN; simpleI++) { phe_trp_tyrNA[simpleI] = 0; } /* Scan the macromolecular complex, residue by residue: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Pointer to the current residue: */ residueSP = mol_complexSP->residueSP + residueI; /* Pointer to the first atom of this residue: */ first_atomSP = mol_complexSP->atomSP + residueSP->residue_startI; /* Check the auxiliaryI of the first atom; if */ /* it is equal to zero, ignore this residue. It */ /* is either of wrong type or points inwards. */ if (first_atomSP->auxiliaryI == 0) continue; /* Extract the coordinates of the CG atom: */ n = ExtractCG_ (&CG_vectorS, mol_complexSP->atomSP, residueSP->residue_startI, residueSP->residue_endI); if (n < 1) continue; /* The parallel part of the vector from the presumed membrane */ /* center to the CG atom will be used to calculate the index */ /* of the cell to which the CG atom should be projected. */ /* The vector from the current center to */ /* the CG atom of the current residue: */ radius_vectorS.x = CG_vectorS.x - center_vectorS.x; radius_vectorS.y = CG_vectorS.y - center_vectorS.y; radius_vectorS.z = CG_vectorS.z - center_vectorS.z; /* Projection of this vector to the axis: */ projection = ScalarProduct_ (&radius_vectorS, &best_unit_vectorS); /* The index of the central simple cell: */ central_simpleI = (int) (recip_simple_width * projection) + simple_index_offset; /* The CG atom will be projected over a number of cells. */ /* The side chains which form the ring of aromatic */ /* residues are not perfectly aligned and for that */ /* reason the CG atom will be smeared over more cells. */ start_simpleI = central_simpleI - half_simple_window_width; end_simpleI = start_simpleI + simple_window_width; /* Smear CG projection over a number of cells: */ for (simpleI = start_simpleI; simpleI <= end_simpleI; simpleI++) { /* Do not allow array overflow: */ if (simpleI < 0) continue; if (simpleI >= simple_cells_along_axisN) break; /* Update the number of PHE, TRP and TYR residues which */ /* were projected to the cell defined by this simpleI: */ phe_trp_tyrNA[simpleI]++; } /* End of residueI loop: */ } /* Check the count of PHE, TRP and TYR residues in two rings: */ ring1I = simple_index_offset - half_simple_thickness; if (ring1I < 0) continue; if (ring1I >= simple_cells_along_axisN) continue; ring2I = ring1I + simple_thickness; if (ring2I < 0) continue; if (ring2I >= simple_cells_along_axisN) continue; two_rings_count = phe_trp_tyrNA[ring1I] + phe_trp_tyrNA[ring2I]; if (two_rings_count > best_two_rings_count) { best_two_rings_count = two_rings_count; best_shift = shift; } /* End of pointI loop: */ } /*------update the membrane center:------------------------------------------*/ /* Update the membrane center: */ /* Update the membrane center: */ mol_complexSP->membraneS.center_x = CA_center_vectorS.x + best_shift * best_unit_vectorS.x; mol_complexSP->membraneS.center_y = CA_center_vectorS.y + best_shift * best_unit_vectorS.y; mol_complexSP->membraneS.center_z = CA_center_vectorS.z + best_shift * best_unit_vectorS.z; /*---------------------------------------------------------------------------*/ /* Return positive value on success: */ return 1; } /*===========================================================================*/ garlic-1.6/motion_notify.c0000644000076500007650000005013310173730562016156 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2003 Damir Zucic */ /*============================================================================= motion_notify.c Purpose: Handle MotionNotify events. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. (3) Pointer to RuntimeS structure, with some runtime data. (4) Pointer to ConfigS structure, with configuration data. (5) Pointer to GUIS structure, with GUI data. (6) Pointer to NearestAtomS structure. (7) The number of pixels in the main window free area. (8) Pointer to refreshI. (9) Pointer to XMotionEvent structure. Output: (1) Some data related to the atom under the pointer written to output window. (2) Sequence neighborhood of the residue under the pointer may be written to the main window (if requested). (3) Return value. Return value: (1) Positive on success. (2) Zero if event is ignored. (3) Negative on failure. Notes: (1) Indentation is exceptionally 4 spaces. ========includes:============================================================*/ #include #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int RamaMouse_ (MolComplexS *, int, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int, XMotionEvent *); int PlotMouse_ (RuntimeS *, GUIS *, NearestAtomS *, size_t, unsigned int, XMotionEvent *); int ComparisonMouse_ (RuntimeS *, GUIS *, NearestAtomS *, size_t, XMotionEvent *); int ExtractN_ (VectorS *, AtomS *, size_t, size_t); int ExtractC_ (VectorS *, AtomS *, size_t, size_t); /*======handle MotionNotify events:==========================================*/ int MotionNotify_ (MolComplexS *mol_complexSP, int mol_complexesN, RuntimeS *runtimeSP, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int refreshI, XMotionEvent *motion_eventSP) { size_t pixelI; NearestAtomS *pixelSP; MolComplexS *curr_mol_complexSP; AtomS *curr_atomSP; RawAtomS *raw_atomSP; static char stringA[STRINGSIZE]; int text_line_height; int screen_x0, screen_y0; double tf; double x, y, z; ResidueS *curr_residueSP; double phi, psi, omega, chi1, chi2, chi3; int central_residueI, first_residueI, last_residueI; int space_width, space_half_width; int residueI; AtomS *first_atomSP; char *residue_nameP; char residue_nameA[RESNAMESIZE]; char serial_and_chainA[SHORTSTRINGSIZE]; int residue_name_length, string_length; int text_width; int line_x0 = 0, line_x1 = 0; int width, height; ResidueS *central_residueSP; size_t first_atomI, last_atomI; int octantI; int n; VectorS N_vectorS, C_vectorS; double delta_x, delta_y; double rho, cos_angle, sin_angle, angle; int top_left_x, top_left_y; /*------Ramachandran plot:---------------------------------------------------*/ /* If main window contains Ramachandran plot: */ if (guiSP->main_window_modeI == 1) { return RamaMouse_ (mol_complexSP, mol_complexesN, configSP, guiSP, nearest_atomSP, pixelsN, refreshI, motion_eventSP); } /*------hydrophobicity plots:------------------------------------------------*/ /* If main window contains hydrophobicity plots: */ else if (guiSP->main_window_modeI == 4) { return PlotMouse_ (runtimeSP, guiSP, nearest_atomSP, pixelsN, refreshI, motion_eventSP); } /*------sequence comparison plot:--------------------------------------------*/ /* If main window contains sequence comparison: */ else if (guiSP->main_window_modeI == 5) { return ComparisonMouse_ (runtimeSP, guiSP, nearest_atomSP, pixelsN, motion_eventSP); } /*---------------------------------------------------------------------------*/ /* If the event came from child window, return zero: */ if (motion_eventSP->subwindow != None) return 0; /*------output window:-------------------------------------------------------*/ /* Pixel index: */ pixelI = guiSP->main_win_free_area_width * motion_eventSP->y + motion_eventSP->x; /* Check the pixel index: */ if (pixelI >= pixelsN) return -1; /* Pointer to NearestAtomS structure assigned to this pixel: */ pixelSP = nearest_atomSP + pixelI; /* Check the refreshI associated with this pixel: */ if (pixelSP->last_refreshI != refreshI) return 0; /* Check the style index associated with this pixel; */ /* if only plane was drawn to this pixel, there is */ /* no atomic information associated with the pixel: */ if (pixelSP->styleI == PLANE_STYLE) return 0; /* Refresh the output window: */ XSetForeground (guiSP->displaySP, guiSP->theGCA[0], guiSP->output_winS.bg_colorID); XFillRectangle (guiSP->displaySP, guiSP->output_winS.ID, guiSP->theGCA[0], 0, 0, guiSP->output_winS.width, guiSP->output_winS.height); /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + pixelSP->mol_complexI; /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + pixelSP->atomI; /* Pointer to raw atomic data: */ raw_atomSP = &curr_atomSP->raw_atomS; /* Pointer to the current residue: */ curr_residueSP = curr_mol_complexSP->residueSP + curr_atomSP->residue_arrayI; /* Prepare the text foreground color: */ XSetForeground (guiSP->displaySP, guiSP->theGCA[0], guiSP->output_winS.fg_colorID); /* Text line height: */ text_line_height = guiSP->output_winS.font_height; /* The initial drawing position: */ screen_x0 = TEXTMARGIN; screen_y0 = guiSP->output_winS.font_height + 1; /* Draw the unique PDB identifier: */ sprintf (stringA, "(%d) %s", curr_mol_complexSP->mol_complexID, curr_mol_complexSP->unique_PDB_codeA); stringA[STRINGSIZE - 1] = '\0'; XDrawString (guiSP->displaySP, guiSP->output_winS.ID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, strlen (stringA)); /* Draw residue data: */ screen_y0 += text_line_height; sprintf (stringA, "%s %d %c", raw_atomSP->residue_nameA, raw_atomSP->residue_sequenceI, raw_atomSP->chainID); stringA[STRINGSIZE - 1] = '\0'; XDrawString (guiSP->displaySP, guiSP->output_winS.ID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, strlen (stringA)); /* Draw atom name, alternate location indicator, */ /* atom serial number and chemical element symbol: */ screen_y0 += text_line_height; sprintf (stringA, "%s%c %d %s", raw_atomSP->pure_atom_nameA, raw_atomSP->alt_location, raw_atomSP->serialI, raw_atomSP->chemical_symbolA); stringA[STRINGSIZE - 1] = '\0'; XDrawString (guiSP->displaySP, guiSP->output_winS.ID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, strlen (stringA)); /* Temperature factor: */ screen_y0 += text_line_height; tf = raw_atomSP->temperature_factor; if (tf < 99.99) sprintf (stringA, "t.f.: %5.2f", tf); else sprintf (stringA, "t.f. :%.2f", tf); stringA[STRINGSIZE - 1] = '\0'; XDrawString (guiSP->displaySP, guiSP->output_winS.ID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, strlen (stringA)); /* Hydrophobicity: */ screen_y0 += text_line_height; sprintf (stringA, "phob:%6.2f", raw_atomSP->hydrophobicity); stringA[STRINGSIZE - 1] = '\0'; XDrawString (guiSP->displaySP, guiSP->output_winS.ID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, strlen (stringA)); /* Selection status: */ screen_y0 += text_line_height; if (curr_atomSP->selectedF) strcpy (stringA, "selected"); else strcpy (stringA, "not selected"); XDrawString (guiSP->displaySP, guiSP->output_winS.ID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, strlen (stringA)); /* The angle phi (see dihedral_angles.c for definition): */ screen_y0 += text_line_height; phi = curr_residueSP->phi; if (phi == BADDIHEDANGLE) { strcpy (stringA, "phi: missing"); XDrawString (guiSP->displaySP, guiSP->output_winS.ID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, strlen (stringA)); } else { phi *= RAD_TO_DEG; sprintf (stringA, "phi: %7.2f", phi); stringA[STRINGSIZE - 1] = '\0'; XDrawString (guiSP->displaySP, guiSP->output_winS.ID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, strlen (stringA)); } /* The angle psi (see dihedral_angles.c for definition): */ screen_y0 += text_line_height; psi = curr_residueSP->psi; if (psi == BADDIHEDANGLE) { strcpy (stringA, "psi: missing"); XDrawString (guiSP->displaySP, guiSP->output_winS.ID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, strlen (stringA)); } else { psi *= RAD_TO_DEG; sprintf (stringA, "psi: %7.2f", psi); stringA[STRINGSIZE - 1] = '\0'; XDrawString (guiSP->displaySP, guiSP->output_winS.ID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, strlen (stringA)); } /* The angle omega (see dihedral_angles.c for definition): */ screen_y0 += text_line_height; omega = curr_residueSP->omega; if (omega == BADDIHEDANGLE) { strcpy (stringA, "ome: missing"); XDrawString (guiSP->displaySP, guiSP->output_winS.ID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, strlen (stringA)); } else { omega *= RAD_TO_DEG; sprintf (stringA, "ome: %7.2f", omega); stringA[STRINGSIZE - 1] = '\0'; XDrawString (guiSP->displaySP, guiSP->output_winS.ID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, strlen (stringA)); } /* The angle chi1 (see dihedral_angles.c for definition): */ screen_y0 += text_line_height; chi1 = curr_residueSP->chi1; if (chi1 == BADDIHEDANGLE) { strcpy (stringA, "chi1: -"); XDrawString (guiSP->displaySP, guiSP->output_winS.ID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, strlen (stringA)); } else { chi1 *= RAD_TO_DEG; sprintf (stringA, "chi1:%7.2f", chi1); stringA[STRINGSIZE - 1] = '\0'; XDrawString (guiSP->displaySP, guiSP->output_winS.ID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, strlen (stringA)); } /* The angle chi2 (see dihedral_angles.c for definition): */ screen_y0 += text_line_height; chi2 = curr_residueSP->chi2; if (chi2 == BADDIHEDANGLE) { strcpy (stringA, "chi2: -"); XDrawString (guiSP->displaySP, guiSP->output_winS.ID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, strlen (stringA)); } else { chi2 *= RAD_TO_DEG; sprintf (stringA, "chi2:%7.2f", chi2); stringA[STRINGSIZE - 1] = '\0'; XDrawString (guiSP->displaySP, guiSP->output_winS.ID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, strlen (stringA)); } /* The angle chi3 (see dihedral_angles.c for definition): */ screen_y0 += text_line_height; chi3 = curr_residueSP->chi3; if (chi3 == BADDIHEDANGLE) { strcpy (stringA, "chi3: -"); XDrawString (guiSP->displaySP, guiSP->output_winS.ID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, strlen (stringA)); } else { chi3 *= RAD_TO_DEG; sprintf (stringA, "chi3:%7.2f", chi3); stringA[STRINGSIZE - 1] = '\0'; XDrawString (guiSP->displaySP, guiSP->output_winS.ID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, strlen (stringA)); } /* x coordinate: */ screen_y0 += text_line_height; x = raw_atomSP->x[0]; if (x < 9999.999) sprintf (stringA, "x: %8.3f", x); else sprintf (stringA, "x: %.3f", x); stringA[STRINGSIZE - 1] = '\0'; XDrawString (guiSP->displaySP, guiSP->output_winS.ID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, strlen (stringA)); /* y coordinate: */ screen_y0 += text_line_height; y = raw_atomSP->y; if (y < 9999.999) sprintf (stringA, "y: %8.3f", y); else sprintf (stringA, "y: %.3f", y); stringA[STRINGSIZE - 1] = '\0'; XDrawString (guiSP->displaySP, guiSP->output_winS.ID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, strlen (stringA)); /* z coordinate: */ screen_y0 += text_line_height; z = raw_atomSP->z[0]; if (z < 9999.999) sprintf (stringA, "z: %8.3f", z); else sprintf (stringA, "z: %.3f", z); stringA[STRINGSIZE - 1] = '\0'; XDrawString (guiSP->displaySP, guiSP->output_winS.ID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, strlen (stringA)); /*------sequence neighborhood:-----------------------------------------------*/ /* Write the sequence neighborhood of the */ /* residue under the pointer, if requested: */ if (configSP->show_sequence_neighborhoodF) { /* The central residue index: */ central_residueI = curr_atomSP->residue_arrayI; /*------draw text:-------------------------------------------------------*/ /* Space half-width: */ space_width = XTextWidth (guiSP->main_winS.fontSP, " ", 1); space_half_width = space_width / 2; /* Indices of the first and the last residue in the neighbourhood: */ first_residueI = central_residueI - NEIGH_HALF_WIDTH; if (first_residueI < 0) first_residueI = 0; last_residueI = central_residueI + NEIGH_HALF_WIDTH; if (last_residueI >= (int) curr_mol_complexSP->residuesN) { last_residueI = (int) curr_mol_complexSP->residuesN - 1; } /* Prepare the string: */ stringA[0] = '\0'; residue_name_length = RESNAMESIZE - 1; strcat (stringA, " "); for (residueI = first_residueI; residueI <= last_residueI; residueI++) { /* The string width, without the central residue: */ if (residueI == central_residueI) { string_length = strlen (stringA); line_x0 = XTextWidth (guiSP->main_winS.fontSP, stringA, string_length) - space_half_width; } /* Pointer to current residue: */ curr_residueSP = curr_mol_complexSP->residueSP + residueI; /* Pointer to the first atom of the current residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Pointer to residue name: */ residue_nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Add the residue name to the output string: */ strncpy (residue_nameA, residue_nameP, residue_name_length); residue_nameA[residue_name_length] = '\0'; strcat (stringA, residue_nameA); /* If the output should be verbose, i.e. should contain */ /* residue serial numbers and chain identifiers, add them: */ if (configSP->show_sequence_neighborhoodF == 2) { /* If chain identifier is trivial (space character), ignore it: */ if (first_atomSP->raw_atomS.chainID == ' ') { sprintf (serial_and_chainA, "%d", first_atomSP->raw_atomS.residue_sequenceI); serial_and_chainA[SHORTSTRINGSIZE - 1] = '\0'; } /* If chain identifier is not trivial, add it: */ else { sprintf (serial_and_chainA, "%d%c", first_atomSP->raw_atomS.residue_sequenceI, first_atomSP->raw_atomS.chainID); serial_and_chainA[SHORTSTRINGSIZE - 1] = '\0'; } /* Append the serial number and chain ID to residue name: */ strcat (stringA, serial_and_chainA); } /* Add a single space: */ strcat (stringA, " "); /* The string width, including the central residue: */ if (residueI == central_residueI) { string_length = strlen (stringA); line_x1 = XTextWidth (guiSP->main_winS.fontSP, stringA, string_length) - space_half_width; } } /* String length: */ string_length = strlen (stringA); /* Text width: */ text_width = XTextWidth (guiSP->main_winS.fontSP, stringA, string_length); /* Prepare text background color: */ XSetForeground (guiSP->displaySP, guiSP->theGCA[0], guiSP->main_winS.bg_colorID); /* Refresh the string background: */ screen_x0 = 1; screen_y0 = 1; width = guiSP->control_winS.x0 - guiSP->main_winS.border_width - 2; if (width < 0) width = 0; height = guiSP->main_winS.font_height + 4; XFillRectangle (guiSP->displaySP, guiSP->main_winS.ID, guiSP->theGCA[0], screen_x0, screen_y0, (unsigned int) width, (unsigned int) height); /* Prepare text color: */ XSetForeground (guiSP->displaySP, guiSP->theGCA[0], guiSP->main_winS.fg_colorID); /* Draw the bounding rectangle: */ XDrawRectangle (guiSP->displaySP, guiSP->main_winS.ID, guiSP->theGCA[0], screen_x0, screen_y0, (unsigned int) width, (unsigned int) height); /* Draw the string which contains sequence neighborhood: */ screen_x0 = guiSP->control_winS.x0 / 2 - text_width / 2; screen_y0 = guiSP->main_winS.font_height + 1; XDrawString (guiSP->displaySP, guiSP->main_winS.ID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, string_length); /* Draw rectangle bounding the central residue: */ line_x0 += guiSP->control_winS.x0 / 2 - text_width / 2; line_x1 += guiSP->control_winS.x0 / 2 - text_width / 2; width = line_x1 - line_x0 + 1; if (width < 0) width = 0; height = guiSP->main_winS.font_height - 1; if (height < 0) height = 0; XDrawRectangle (guiSP->displaySP, guiSP->main_winS.ID, guiSP->theGCA[0], line_x0, 4, (unsigned int) width, (unsigned int) height); /*------draw the small arrow:--------------------------------------------*/ /* Only the N and C atom of the central residue will be used. */ central_residueSP = curr_mol_complexSP->residueSP + central_residueI; first_atomI = central_residueSP->residue_startI; last_atomI = central_residueSP->residue_endI; /* Initialize the octant index: */ octantI = 8; /* Formal, single pass loop: */ do { /* Try to extract the N atom coordinates: */ n = ExtractN_ (&N_vectorS, curr_mol_complexSP->atomSP, first_atomI, last_atomI); if (n < 1) break; /* Try to extract the C atom coordinates: */ n = ExtractC_ (&C_vectorS, curr_mol_complexSP->atomSP, first_atomI, last_atomI); /* Now project the vector from N to C to the XY plane: */ delta_x = C_vectorS.x - N_vectorS.x; delta_y = C_vectorS.y - N_vectorS.y; /* Prepare sine and cosine of the angle: */ rho = sqrt (delta_x * delta_x + delta_y * delta_y); if (rho < 0.001) break; cos_angle = delta_x / rho; if (cos_angle <= -0.999) angle = 3.1415927; else if (cos_angle >= 0.999) angle = 0.0; else angle = acos (cos_angle); sin_angle = delta_y / rho; if (sin_angle < 0.0) angle = 6.2831853 - angle; /* Identify the octant: */ if (angle < 0.392699087) octantI = 0; else if (angle < 1.178097262) octantI = 1; else if (angle < 1.963495437) octantI = 2; else if (angle < 2.748893609) octantI = 3; else if (angle < 3.534291783) octantI = 4; else if (angle < 4.319689957) octantI = 5; else if (angle < 5.105088131) octantI = 6; else if (angle < 5.890486305) octantI = 7; else octantI = 0; /* End of formal loop: */ } while (0); /* Prepare the arrow position: */ top_left_x = guiSP->control_winS.x0 / 2 - 16; top_left_y = 4 + height + 4; /* Draw the proper arrow: */ switch (octantI) { case 0: XCopyArea (guiSP->displaySP, guiSP->small_arrows_pixmapID, guiSP->main_winS.ID, guiSP->theGCA[0], 0, 0, 32, 32, top_left_x, top_left_y); break; case 1: XCopyArea (guiSP->displaySP, guiSP->small_arrows_pixmapID, guiSP->main_winS.ID, guiSP->theGCA[0], 0, 31, 32, 32, top_left_x, top_left_y); break; case 2: XCopyArea (guiSP->displaySP, guiSP->small_arrows_pixmapID, guiSP->main_winS.ID, guiSP->theGCA[0], 0, 62, 32, 32, top_left_x, top_left_y); break; case 3: XCopyArea (guiSP->displaySP, guiSP->small_arrows_pixmapID, guiSP->main_winS.ID, guiSP->theGCA[0], 0, 93, 32, 32, top_left_x, top_left_y); break; case 4: XCopyArea (guiSP->displaySP, guiSP->small_arrows_pixmapID, guiSP->main_winS.ID, guiSP->theGCA[0], 0, 124, 32, 32, top_left_x, top_left_y); break; case 5: XCopyArea (guiSP->displaySP, guiSP->small_arrows_pixmapID, guiSP->main_winS.ID, guiSP->theGCA[0], 0, 155, 32, 32, top_left_x, top_left_y); break; case 6: XCopyArea (guiSP->displaySP, guiSP->small_arrows_pixmapID, guiSP->main_winS.ID, guiSP->theGCA[0], 0, 186, 32, 32, top_left_x, top_left_y); break; case 7: XCopyArea (guiSP->displaySP, guiSP->small_arrows_pixmapID, guiSP->main_winS.ID, guiSP->theGCA[0], 0, 217, 32, 32, top_left_x, top_left_y); break; default: XCopyArea (guiSP->displaySP, guiSP->small_arrows_pixmapID, guiSP->main_winS.ID, guiSP->theGCA[0], 0, 248, 32, 32, top_left_x, top_left_y); } } /*---------------------------------------------------------------------------*/ /* Return positive value: */ return 1; } /*===========================================================================*/ garlic-1.6/secstr.fasta0000644000076500007650000000024707275447361015454 0ustar zuciczucic00000000000000>1xxx_ mol:protein length:103 Sample secondary structure CCCCCCCCCCCEEEEEEEEEEECCCCCCCCCCCHHHHHHHHHHHHHHHHHHHHCCCCCEEEEEEEECCCCCCCCC CCCCCCCCHHHHHHHHHHHCCCCCCCCC garlic-1.6/extract_vector.c0000644000076500007650000001422307633607620016322 0ustar zuciczucic00000000000000/* Copyright (C) 2001-2003 Damir Zucic */ /*============================================================================= extract_vector.c Purpose: Find the highest average hydrophobicity using the current sliding window width. Extract the coordinates of eight atoms which define the start and the end of the window which has this maximum at the center and prepare one vector. Input: (1) Pointer to VectorS structure, where the extracted vector will be stored. (2) Pointer to MolComplexS structure, with the chosen structure. (3) Pointer to RuntimeS structure. (4) The threshold value for the average hydrophobicity. Output: (1) On success, one vector will be prepared and initialized. (2) Return value. Return value: (1) Positive on success. (2) Negative on failure. ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int ExtractCA_ (VectorS *, AtomS *, size_t, size_t); /*======extract vector:======================================================*/ int ExtractVector_ (VectorS *vectorSP, MolComplexS *mol_complexSP, RuntimeS *runtimeSP, double threshold) { int residuesN, residueI; int window_width, half_window_width; double max_average_hyphob, min_average_hyphob; int central_residueI, window_startI, window_endI; double average_hyphob; int vectors_extractedN; ResidueS *residueSP; VectorS vector1S, vector2S, vector3S, vector4S; VectorS vector5S, vector6S, vector7S, vector8S; /* Copy the number of residues: */ residuesN = mol_complexSP->residuesN; if (residuesN == 0) return -1; /* The sliding window width should be at least eight: */ window_width = runtimeSP->sliding_window_width; if (window_width < 8) return -2; half_window_width = window_width / 2; /* Initialize the maximal and minimal average hydrophobicity: */ max_average_hyphob = -999999.0; min_average_hyphob = 999999.0; /* Initialize the index of the residue which is */ /* in the middle of the most hydrophobic segment. */ central_residueI = -1; /* Find the sequence position with the highest average hydrophobicity. */ /* Find also the values of maximal and minimal average hydrophobicity. */ for (residueI = 0; residueI < residuesN; residueI++) { average_hyphob = *(runtimeSP->average_hydrophobicityP + residueI); if (average_hyphob > max_average_hyphob) { max_average_hyphob = average_hyphob; central_residueI = residueI; } else if (average_hyphob < min_average_hyphob) { min_average_hyphob = average_hyphob; } } /* This should never happen but I am paranoic: */ if (central_residueI == -1) return -3; /* Check is the maximal average hydrophobicity above the threshold: */ if (max_average_hyphob < threshold) return -4; /* Now use the index of the central residue to define the entire */ /* sliding window which contains the maximal average hydrophobicity: */ window_startI = central_residueI - half_window_width; window_endI = window_startI + window_width; /* Check both indices; if the central residue is too close */ /* to the first or to the last residue, discard this peak: */ if ((window_startI < 0) || (window_startI >= residuesN)) return -5; /* Use the first four residues from the sliding window to */ /* define the first point in space and the last four residues */ /* to define the second point in space. Use these two points */ /* to prepare the initial normal vector. This vector should be */ /* approximately perpendicular to the membrane. The coordinates */ /* of CA atoms are used (some structures contain only CA atoms). */ /* Prepare eight vectors: */ vectors_extractedN = 0; residueSP = mol_complexSP->residueSP + window_startI; vectors_extractedN += ExtractCA_ (&vector1S, mol_complexSP->atomSP, residueSP->residue_startI, residueSP->residue_endI); residueSP = mol_complexSP->residueSP + window_startI + 1; vectors_extractedN += ExtractCA_ (&vector2S, mol_complexSP->atomSP, residueSP->residue_startI, residueSP->residue_endI); residueSP = mol_complexSP->residueSP + window_startI + 2; vectors_extractedN += ExtractCA_ (&vector3S, mol_complexSP->atomSP, residueSP->residue_startI, residueSP->residue_endI); residueSP = mol_complexSP->residueSP + window_startI + 3; vectors_extractedN += ExtractCA_ (&vector4S, mol_complexSP->atomSP, residueSP->residue_startI, residueSP->residue_endI); residueSP = mol_complexSP->residueSP + window_endI; vectors_extractedN += ExtractCA_ (&vector5S, mol_complexSP->atomSP, residueSP->residue_startI, residueSP->residue_endI); residueSP = mol_complexSP->residueSP + window_endI - 1; vectors_extractedN += ExtractCA_ (&vector6S, mol_complexSP->atomSP, residueSP->residue_startI, residueSP->residue_endI); residueSP = mol_complexSP->residueSP + window_endI - 2; vectors_extractedN += ExtractCA_ (&vector7S, mol_complexSP->atomSP, residueSP->residue_startI, residueSP->residue_endI); residueSP = mol_complexSP->residueSP + window_endI - 3; vectors_extractedN += ExtractCA_ (&vector8S, mol_complexSP->atomSP, residueSP->residue_startI, residueSP->residue_endI); if (vectors_extractedN != 8) return -6; /* The first (crude) estimate of the normal vector: */ vectorSP->x = vector5S.x + vector6S.x + vector7S.x + vector8S.x - vector1S.x - vector2S.x - vector3S.x - vector4S.x; vectorSP->y = vector5S.y + vector6S.y + vector7S.y + vector8S.y - vector1S.y - vector2S.y - vector3S.y - vector4S.y; vectorSP->z = vector5S.z + vector6S.z + vector7S.z + vector8S.z - vector1S.z - vector2S.z - vector3S.z - vector4S.z; /* Remove the highest peak. Replace the average hydrophobicities */ /* in the whole interval by the minimal average hydrophobicity. */ for (residueI = window_startI; residueI <= window_endI; residueI++) { *(runtimeSP->average_hydrophobicityP + residueI) = min_average_hyphob; } /* Return positive value on success: */ return 1; } /*===========================================================================*/ garlic-1.6/generate_phi_psi.c0000644000076500007650000000455007274504013016566 0ustar zuciczucic00000000000000/* Copyright (C) 2001 Damir Zucic */ /*============================================================================= generate_phi_psi.c Purpose: Generate the angles phi and psi. Use the specified secondary structure code. The pseudo-random seed should be initialized somewhere else (check the function ApplyStructure_ ()). Note that small deviations from ideal values are introduced. This is good if you want to prepare the Ramachandran plot for the new structure. Input: (1) Pointer to double, where phi angle will be stored. (2) Pointer to double, where psi angle will be stored. (3) Secondary structure one letter code. Output: (1) Angles psi and psi generated. (2) Return value. Return value: (1) Positive if code is recognized. (2) Negative if code is not recognized. ========includes:============================================================*/ #include #include #include #include "defines.h" /*======generate angles phi and psi:=========================================*/ int GeneratePhiAndPsi_ (double *phiP, double *psiP, int sec_structure_code) { double phi0, psi0; double max_value, reciprocal_denominator; double radius, angle; double delta_phi, delta_psi; /* Prepare the mean values: */ switch (sec_structure_code) { /* Beta sheet, coil, turn: */ case 'E': case 'C': case 'T': phi0 = -2.426008; /* -139.0 degrees */ psi0 = 2.356195; /* +135.0 degrees */ break; /* Alpha helix: */ case 'H': phi0 = -0.994838; /* -57.0 degrees */ psi0 = -0.820305; /* -47.0 degrees */ break; /* 3-10 helix: */ case 'G': phi0 = -1.239184; /* -71.0 degrees */ psi0 = -0.314159; /* -18.0 degrees */ break; /* Do not change phi and psi if code is not recognized: */ default: return -1; } /* Prepare denominator: */ max_value = (double) RAND_MAX; if (max_value != 0.0) reciprocal_denominator = 1.0 / max_value; else reciprocal_denominator = 1.0; /* Generate small deviations: */ radius = (double) rand () * reciprocal_denominator; angle = 6.2831853 * ((double) rand () * reciprocal_denominator); delta_phi = 0.087266463 * radius * cos (angle); delta_psi = 0.087266463 * radius * sin (angle); /* Combine mean values and deviations: */ *phiP = phi0 + delta_phi; *psiP = psi0 + delta_psi; /* Return positive value: */ return 1; } /*===========================================================================*/ garlic-1.6/phi_from_cncac.c0000644000076500007650000001061507315721670016220 0ustar zuciczucic00000000000000/* Copyright (C) 2000, 2001 Damir Zucic */ /*============================================================================= phi_from_cncac.c Purpose: Calculate dihedral angle phi, using C[i-1], N[i], CA[i] and C[i]. Check the distance between C[i-1] and N[i]. Input: (1) Pointer to VectorS structure, with C atom coordinates for the previous residue. (2) Pointer to VectorS structure, with N atom coordinates. (3) Pointer to VectorS structure, with CA atom coordinates. (4) Pointer to VectorS structure, with C atom coordinates. (5) Pointer to ConfigS structure. Output: Return value. Return value: (1) Dihedral angle phi, on success. (2) BADDIHEDANGLE on failure. Notes: (1) This should help you to understand phi and psi definitions: ........./................ | H * - * N | | \ phi1 = 180 | | * CA | residue 1 | / psi1 = 180 | | O * - * C | |........\...............| | N * - * H | | / phi2 = 180 | | CA * | residue 2 | \ psi2 = 180 | | C * - * O | |......../...............| ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ void VectorProduct_ (VectorS *, VectorS *, VectorS *); double AbsoluteValue_ (VectorS *); double ScalarProduct_ (VectorS *, VectorS *); /*======calculate phi from C[i-1], N[i], CA[i] and C[i]:=====================*/ double PhiFromCNCAC_ (VectorS *previousC_vectorSP, VectorS *N_vectorSP, VectorS *CA_vectorSP, VectorS *C_vectorSP, ConfigS *configSP) { VectorS N_previousC_vectorS, N_CA_vectorS; double bond_length_squared; VectorS CA_N_vectorS, CA_C_vectorS; VectorS u1S, u2S; VectorS v1S, v2S; double denom, ratio; double alpha, phi; /* The first pair of auxiliary vectors: */ N_previousC_vectorS.x = previousC_vectorSP->x - N_vectorSP->x; N_previousC_vectorS.y = previousC_vectorSP->y - N_vectorSP->y; N_previousC_vectorS.z = previousC_vectorSP->z - N_vectorSP->z; N_CA_vectorS.x = CA_vectorSP->x - N_vectorSP->x; N_CA_vectorS.y = CA_vectorSP->y - N_vectorSP->y; N_CA_vectorS.z = CA_vectorSP->z - N_vectorSP->z; /* Check the distance between N and previousC: */ bond_length_squared = N_previousC_vectorS.x * N_previousC_vectorS.x + N_previousC_vectorS.y * N_previousC_vectorS.y + N_previousC_vectorS.z * N_previousC_vectorS.z; if (bond_length_squared < configSP->C_N_min_squared) return BADDIHEDANGLE; if (bond_length_squared > configSP->C_N_max_squared) return BADDIHEDANGLE; /* The second pair of auxiliary vectors: */ CA_N_vectorS.x = N_vectorSP->x - CA_vectorSP->x; CA_N_vectorS.y = N_vectorSP->y - CA_vectorSP->y; CA_N_vectorS.z = N_vectorSP->z - CA_vectorSP->z; CA_C_vectorS.x = C_vectorSP->x - CA_vectorSP->x; CA_C_vectorS.y = C_vectorSP->y - CA_vectorSP->y; CA_C_vectorS.z = C_vectorSP->z - CA_vectorSP->z; /* Two vectors perpendicular to N_CA_vectorS, mutually orthogonal, the */ /* second in the plane defined by N_previousC_vectorS and N_CA_vectorS: */ VectorProduct_ (&u1S, &N_previousC_vectorS, &N_CA_vectorS); VectorProduct_ (&u2S, &u1S, &N_CA_vectorS); /* Two vectors perpendicular to CA_N_vectorS, mutually orthogonal, */ /* the second in the plane defined by CA_N_vectorS and CA_C_vectorS: */ VectorProduct_ (&v1S, &CA_N_vectorS, &CA_C_vectorS); VectorProduct_ (&v2S, &CA_N_vectorS, &v1S); /* Calculate the angle alpha, which will be used to calculate phi: */ /* Avoid division by zero: */ denom = AbsoluteValue_ (&u1S) * AbsoluteValue_ (&v1S); if (denom == 0.0) return BADDIHEDANGLE; /* Use the scalar product to calculate the cosine of the angle: */ ratio = ScalarProduct_ (&u1S, &v1S) / denom; /* Arc cosine is very sensitive to floating point errors: */ if (ratio <= -1.0) alpha = 3.1415927; else if (ratio >= 1.0) alpha = 0.0; else alpha = acos (ratio); /* There are two possible solutions; the right one is resolved here: */ if (ScalarProduct_ (&v2S, &u1S) >= 0) phi = alpha; else phi = -alpha; /* Return the angle (in radians): */ return phi; } /*===========================================================================*/ garlic-1.6/select_triplet.c0000644000076500007650000001502407747232625016315 0ustar zuciczucic00000000000000/* Copyright (C) 2001-2003 Damir Zucic */ /*============================================================================= select_triplet.c Purpose: Select the triplet of positive residues. If there is a total of at least three ARG or LYS in a window of five residues, treat these three residues as a triplet. ARG and LYS will be selected and the other residues in the same window will be ignored. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. (3) Selection mode index (0 = overwrite, 1 = restrict, 2 = expand previous selection). Output: (1) The flag selectedF set to one for selected atoms in every caught macromolecular complex. (2) Return value. Return value: (1) The number of selected atoms (zero or positive value). ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======select triplets of positive residues:================================*/ long SelectTriplet_ (MolComplexS *mol_complexSP, int mol_complexesN, int selection_modeI) { long selected_atomsN = 0; int mol_complexI; MolComplexS *curr_mol_complexSP; int atomsN, atomI; AtomS *curr_atomSP; int residuesN, residueI, windowI, combinedI; ResidueS *curr_residueSP; AtomS *first_atomSP; char *nameP; int positiveN; int first_atomI, last_atomI; /* Check every macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check is the current macromolecular complex caught: */ if (curr_mol_complexSP->catchF == 0) continue; /* Prepare and check the number of atoms in the current complex: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Copy the number of residues in the current macromol. complex: */ residuesN = curr_mol_complexSP->residuesN; if (residuesN == 0) continue; /* Backup the current selection if selection mode is restrict: */ if (selection_modeI == 1) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Copy the selection flag: */ curr_atomSP->previous_selectedF = curr_atomSP->selectedF; } } /* Unselect everything if selection mode is overwrite or restrict: */ if ((selection_modeI == 0) || (selection_modeI == 1)) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Unselect the current atom: */ curr_atomSP->selectedF = 0; } } /* Scan the residues of the current macromolecular complex: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Reset the counter which counts positive residues: */ positiveN = 0; /* Scan the window of five residues, */ /* starting from the current residue: */ for (windowI = 0; windowI < 5; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI >= residuesN) break; /* Residue associated with the combined index: */ curr_residueSP = curr_mol_complexSP->residueSP + combinedI; /* Pointer to the first atom of current residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Pointer to the name of the current residue: */ nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Check is this residue positive (ARG or LYS): */ if ((strcmp (nameP, "ARG") == 0) || (strcmp (nameP, "LYS") == 0)) positiveN++; } /* If there were three or more positive residues in */ /* a window of five residues, the triplet is found. */ /* If there were two or less, take the next residue. */ if (positiveN < 3) continue; /* If this point is reached, scan the window of five */ /* residues again and select all positive residues. */ /* Scan the window of five residues, */ /* starting from the current residue: */ for (windowI = 0; windowI < 5; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI >= residuesN) break; /* Residue associated with the combined index: */ curr_residueSP = curr_mol_complexSP->residueSP + combinedI; /* Pointer to the first atom of current residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Pointer to the name of the current residue: */ nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Check is this residue positive (ARG or LYS). */ if ((strcmp (nameP, "ARG") != 0) && (strcmp (nameP, "LYS") != 0)) continue; /* If this point is reached, select */ /* all atoms of the current residue. */ /* The indices of the first and the */ /* last atom of the current residue: */ first_atomI = curr_residueSP->residue_startI; last_atomI = curr_residueSP->residue_endI; /* Select all atoms of the current residue: */ for (atomI = first_atomI; atomI <= last_atomI; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Select the current atom: */ curr_atomSP->selectedF = 1; /* Update the counter of selected atoms: */ selected_atomsN++; } } /* End of residueI loop: */ } /* Combine the current selection with the */ /* previous, if selection mode is restrict: */ if (selection_modeI == 1) { /* Reset the counter of selected atoms. The */ /* selected atoms should be counted again. */ selected_atomsN = 0; /* Combine the old and the new selection flag: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Combine selection flags: */ curr_atomSP->selectedF *= curr_atomSP->previous_selectedF; /* Check the selection flag; increase */ /* the count of selected residues if */ /* the selection flag is equal to one: */ if (curr_atomSP->selectedF) selected_atomsN++; } } /* Update the position_changedF (some atoms may have bad color): */ curr_mol_complexSP->position_changedF = 1; /* End of mol_complexI loop: */ } /* Return the number of selected atoms: */ return selected_atomsN; } /*===========================================================================*/ garlic-1.6/move_back_slab.c0000644000076500007650000000520407070340000016171 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= move_back_slab.c Purpose: Change the position of the back slab surface for each caught macromolecular complex. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. (3) Pointer to ConfigS structure. (4) Translation shift. Output: (1) The back slab surface moved. Return value: No return value. Notes: (1) Indentation is exceptionally 4 spaces. ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======move the back slab surface:==========================================*/ void MoveBackSlab_ (MolComplexS *mol_complexSP, int mol_complexesN, ConfigS *configSP, double shift) { int mol_complexI; MolComplexS *curr_mol_complexSP; for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check is the current macromolecular complex caught: */ if (curr_mol_complexSP->catchF == 0) continue; /* Move back slab surface: */ switch (curr_mol_complexSP->slab_modeI) { /* Planar slab: */ case 1: /* Prepare the new position: */ curr_mol_complexSP->slab_back_relative_position += shift; /* Check it: */ if (curr_mol_complexSP->slab_back_relative_position < curr_mol_complexSP->slab_front_relative_position + MINSLABSPACING) { curr_mol_complexSP->slab_back_relative_position = curr_mol_complexSP->slab_front_relative_position + MINSLABSPACING; } break; /* Spherical, semi-spher., cylindrical and semi-cyl. slab: */ case 2: case 3: case 4: case 5: /* Prepare the new position: */ curr_mol_complexSP->slab_back_relative_position -= shift; /* Check it: */ if (curr_mol_complexSP->slab_back_relative_position > curr_mol_complexSP->slab_front_relative_position - MINSLABSPACING) { curr_mol_complexSP->slab_back_relative_position = curr_mol_complexSP->slab_front_relative_position - MINSLABSPACING; } if (curr_mol_complexSP->slab_back_relative_position < 0) { curr_mol_complexSP->slab_back_relative_position = 0.0; } break; /* Ignore all other cases: */ default: ; } /* Set the position_changedF: */ curr_mol_complexSP->position_changedF = 1; } } /*===========================================================================*/ garlic-1.6/tag_position.c0000644000076500007650000000601207072063007015752 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= tag_position.c Purpose: Find the tag position in screen coordinates. Input: (1) Pointer to horizontal position of the left image. (2) Pointer to horizontal position of the right image. (3) Pointer to vertical position. (4) Pointer to MolComplexS structure. (5) The number of images (1 for mono, 2 for stereo). Output: (1) Horizontal position set (two values for stereo mode). (2) Vertical position set. (3) Return value. Return value: (1) Positive if macromol. complex contains at least one atom. (2) Zero, if there are no atoms. ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======find tag position:===================================================*/ int TagPosition_ (int *tag_screen_left_xP, int *tag_screen_right_xP, int *tag_screen_yP, MolComplexS *curr_mol_complexSP, int imagesN) { size_t atomsN, atomI; AtomS *curr_atomSP; int screen_left_x_min, screen_left_x_max; int screen_right_x_min = 0, screen_right_x_max = 0; int screen_y_min, screen_y_max; int screen_left_x, screen_right_x, screen_y; /* Return if there are no atoms: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) return 0; /* Initialize extreme values using the screen coordinates of the first atom: */ screen_left_x_min = curr_mol_complexSP->atomSP->raw_atomS.screen_x[0]; screen_left_x_max = screen_left_x_min; screen_y_min = curr_mol_complexSP->atomSP->raw_atomS.screen_y; screen_y_max = screen_y_min; if (imagesN == 2) { screen_right_x_min = curr_mol_complexSP->atomSP->raw_atomS.screen_x[1]; screen_right_x_max = screen_right_x_min; } /* Find new extreme values; skip the first atom: */ for (atomI = 1; atomI < atomsN; atomI++) { /** Current AtomS pointer: **/ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /** Min./max.: **/ screen_left_x = curr_atomSP->raw_atomS.screen_x[0]; screen_y = curr_atomSP->raw_atomS.screen_y; if (screen_left_x < screen_left_x_min) { screen_left_x_min = screen_left_x; } if (screen_left_x > screen_left_x_max) { screen_left_x_max = screen_left_x; } if (screen_y < screen_y_min) screen_y_min = screen_y; if (screen_y > screen_y_max) screen_y_max = screen_y; if (imagesN == 2) { screen_right_x = curr_atomSP->raw_atomS.screen_x[1]; if (screen_right_x < screen_right_x_min) { screen_right_x_min = screen_right_x; } if (screen_right_x > screen_right_x_max) { screen_right_x_max = screen_right_x; } } } /* Set new values: */ *tag_screen_left_xP = (screen_left_x_min + screen_left_x_max) / 2; *tag_screen_right_xP = (screen_right_x_min + screen_right_x_max) / 2; *tag_screen_yP = screen_y_min; /* Return 1 if this point is reached: */ return 1; } /*===========================================================================*/ garlic-1.6/half_cylin_slab.c0000644000076500007650000000606507374046535016410 0ustar zuciczucic00000000000000/* Copyright (C) 2000, 2001 Damir Zucic */ /*============================================================================= half_cylin_slab.c Purpose: Check which atoms are inside the semi-cylindrical slab. Semi-cyl. slab is defined by two concentric cylinders and a plane which cuts both cylinders in equal halves. A given atom is inside the slab if it is outside the inner cylinder, inside the outer cylinder and in front of a plane. The symmetry axis is y. Use this slab type to hide the rear half as well as the inner part of a porin-like protein. Input: (1) Pointer to MolComplexS structure. Output: (1) Slab flag set for each atom. The value one is assigned to atoms inside the slab, zero to the rest. (2) Return value. Return value: The number of atoms inside the slab. ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======semi-cylindrical slab:===============================================*/ size_t HalfCylinSlab_ (MolComplexS *curr_mol_complexSP) { size_t atoms_inside_slabN = 0; size_t atomsN, atomI; AtomS *curr_atomSP; double x0, z0, rho0_squared, rho1_squared; double x, z, rho_squared; /* The number of atoms in a complex: */ atomsN = curr_mol_complexSP->atomsN; /* Copy the slab center coordinates: */ x0 = curr_mol_complexSP->slab_center_vectorS.x; z0 = curr_mol_complexSP->slab_center_vectorS.z; rho0_squared = curr_mol_complexSP->slab_back_relative_position; rho0_squared *= rho0_squared; rho1_squared = curr_mol_complexSP->slab_front_relative_position; rho1_squared *= rho1_squared; /* Set the slab flag for each atom: */ for (atomI = 0; atomI < atomsN; atomI++) { /** Pointer to the current atom: **/ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /** Set the initial values of slab flags to one; this **/ /** will be changed later for atoms outside the slab: **/ curr_atomSP->inside_slabF = 1; curr_atomSP->inside_projected_slabF = 1; /** Distance between the current atom and the cylinder axis: **/ x = curr_atomSP->raw_atomS.x[0] - x0; z = curr_atomSP->raw_atomS.z[0] - z0; rho_squared = x * x + z * z; /** If atom is behind the rear plane, set slab **/ /** flags to zero and go to check the next atom: **/ if (z > 0.0) { curr_atomSP->inside_slabF = 0; curr_atomSP->inside_projected_slabF = 0; continue; } /** If atom is inside the inner cylinder: **/ if (rho_squared < rho0_squared) { curr_atomSP->inside_slabF = 0; curr_atomSP->inside_projected_slabF = 0; continue; } /** If atom is outside the outer slab cylinder: **/ if (rho_squared > rho1_squared) { curr_atomSP->inside_slabF = 0; curr_atomSP->inside_projected_slabF = 0; continue; } /** If this points is reached, current atom is inside the slab: **/ atoms_inside_slabN++; } /* Return the number of atoms inside the slab: */ return atoms_inside_slabN; } /*===========================================================================*/ garlic-1.6/select_complement.c0000644000076500007650000000614607465735041016777 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2002 Damir Zucic */ /*============================================================================= select_complement.c Purpose: Select the complement - atoms which were not selected previously will be selected, atoms which were selected will be unselected. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. (3) Selection mode index (0 = overwrite, 1 = restrict, 2 = expand previous selection). Output: (1) The flag selectedF set to zero for atoms which were selected before and to one for atoms which were not selected. This is done for every caught macromolecular complex. (2) Return value. Return value: (1) The number of selected atoms (zero or positive value). Notes: (1) Indentation is exceptionally four spaces. (2) The position_changedF is updated, because some atoms may not have the proper color. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======select complement:===================================================*/ long SelectComplement_ (MolComplexS *mol_complexSP, int mol_complexesN, int selection_modeI) { long selected_atomsN = 0; int mol_complexI; MolComplexS *curr_mol_complexSP; size_t atomsN, atomI; AtomS *curr_atomSP; int previousF, newF; /* Check every macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /** Pointer to the current macromolecular complex: **/ curr_mol_complexSP = mol_complexSP + mol_complexI; /** Check is the current macromolecular complex caught: **/ if (curr_mol_complexSP->catchF == 0) continue; /** Number of atoms in a macromolecular complex: **/ atomsN = curr_mol_complexSP->atomsN; /** Scan all atoms in the current complex: **/ for (atomI = 0; atomI < atomsN; atomI++) { /** Pointer to the current atom: **/ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /** Check the current selectF value: **/ previousF = curr_atomSP->selectedF; /** Prepare the new selectF value: **/ if (previousF == 0) newF = 1; else newF = 0; /** Change the selection flag for the current atom: **/ switch (selection_modeI) { /*** Overwrite the previous selection: ***/ case 0: curr_atomSP->selectedF = newF; break; /*** Restrict the previous selection: ***/ case 1: curr_atomSP->selectedF &= newF; break; /*** Expand the previous selection: ***/ case 2: curr_atomSP->selectedF |= newF; break; default: ; } /** Check the selection flag; increase **/ /** the count if flag is equal to one: **/ if (curr_atomSP->selectedF) selected_atomsN++; } /** Update the position_changedF (some atoms may have bad color): **/ curr_mol_complexSP->position_changedF = 1; } /* Return the number of selected atoms: */ return selected_atomsN; } /*===========================================================================*/ garlic-1.6/ex_rot_steps.c0000644000076500007650000000333507612772235016010 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2003 Damir Zucic */ /*============================================================================= ex_rot_steps.c Purpose: Extract rotation steps (five doubles) from a string. Input: (1) Pointer to ConfigS structure, where values will be stored. (2) Input string pointer. Output: Return value. Return value: (1) Positive on success. (2) Negative on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======extract rotation steps from a string:================================*/ int ExtractRotationSteps_ (ConfigS *configSP, char *sP) { char *P0, *P1; int n; double d1, d2, d3, d4, d5; /* Colon should be separator: */ if ((P0 = strstr (sP, ":")) == NULL) P0 = sP; /* Replace each non-numeric character (except */ /* minus sign and decimal point) with space: */ P1 = P0; while ((n = *P1++) != '\0') { if (!isdigit (n) && (n != '-') && (n != '.')) *(P1 - 1) = ' '; } /* Try to read five doubles: */ if (sscanf (P0, "%lf %lf %lf %lf %lf", &d1, &d2, &d3, &d4, &d5) != 5) { return -1; } /* Convert degrees to radians: */ d1 *= DEG_TO_RAD; d2 *= DEG_TO_RAD; d3 *= DEG_TO_RAD; d4 *= DEG_TO_RAD; d5 *= DEG_TO_RAD; /* Copy rotation steps to ConfigS: */ configSP->rotation_stepA[0] = d1; configSP->rotation_stepA[1] = d2; configSP->rotation_stepA[2] = d3; configSP->rotation_stepA[3] = d4; configSP->rotation_stepA[4] = d5; /* If everything worked fine, return positive number: */ return 1; } /*===========================================================================*/ garlic-1.6/scalar_product.c0000644000076500007650000000172007106523540016262 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= scalar_product.c Purpose: Calculate the scalar product of two vectors. Input: (1) Pointer to VectorS structure, with the first vector. (2) Pointer to VectorS structure, with the second vector. Output: Return value. Return value: Scalar product of two vectors (double value). ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======calculate scalar product of two vectors:=============================*/ double ScalarProduct_ (VectorS *vector1SP, VectorS *vector2SP) { return (vector1SP->x * vector2SP->x + vector1SP->y * vector2SP->y + vector1SP->z * vector2SP->z); } /*===========================================================================*/ garlic-1.6/docking_window.c0000644000076500007650000002253307303426237016273 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= docking_window.c Purpose: Prepare docking window, docking icon and storage required for docking. Input: (1) Pointer to RuntimeS structure. (2) Pointer to GUIS structure. Output: (1) Docking window created or mapped. Return value: (1) Positive on success. (2) Zero if docking window was created before. (3) Negative on failure. Notes: (1) The index of exposed atom is of the type int, though size_t is used elsewhere. The reason is that int may have negative value, while size_t is unsigned on many systems. Negative values are used to signal that data stored to a given box are obsolete. ========includes:============================================================*/ #include #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" #include "docking.xpm" /*======function prototypes:=================================================*/ void ErrorMessage_ (char *, char *, char *, char *, char *, char *, char *); int MakePixmap_ (WindowS *, GUIS *, char **); /*======prepare docking window:==============================================*/ int PrepareDockingWindow_ (RuntimeS *runtimeSP, GUIS *guiSP) { XSetWindowAttributes docking_attribS; unsigned long docking_value_mask; XSetWindowAttributes docking_icon_attribS; unsigned long docking_icon_value_mask; static char docking_win_titleA[SHORTSTRINGSIZE]; char *docking_win_titleP; static char docking_icon_titleA[SHORTSTRINGSIZE]; char *docking_icon_titleP; XTextProperty docking_win_titleS, docking_icon_titleS; XSizeHints *size_hintsSP; XWMHints *wm_hintsSP; XClassHint *class_hintsSP; long event_mask; int width; size_t elementsN, int_size; size_t exposed_polar_size; /* If docking window was created before, just make it visible: */ if (guiSP->docking_window_createdF) { if (guiSP->docking_window_mappedF == 0) { XMapWindow (guiSP->displaySP, guiSP->docking_winS.ID); } return 0; } /*------create docking window:-----------------------------------------------*/ /* Docking window width and height: */ guiSP->docking_winS.width = guiSP->screen_width / 3; guiSP->docking_winS.height = guiSP->docking_winS.width; /* Position of the top left corner: */ guiSP->docking_winS.x0 = (int) guiSP->docking_winS.width - 20; guiSP->docking_winS.y0 = (int) guiSP->docking_winS.height - 20; /* Set window attributes: */ docking_attribS.border_pixel = guiSP->main_winS.fg_colorID; docking_attribS.background_pixel = guiSP->main_winS.bg_colorID; docking_attribS.cursor = guiSP->main_winS.cursorID; docking_attribS.colormap = guiSP->colormapID; docking_value_mask = CWBorderPixel | CWBackPixel | CWCursor | CWColormap; guiSP->docking_winS.border_width = 1; /* Border width: */ guiSP->docking_winS.border_width = guiSP->main_winS.border_width; /* Create docking window (root window is the parent) and set flag: */ guiSP->docking_winS.ID = XCreateWindow ( guiSP->displaySP, DefaultRootWindow (guiSP->displaySP), guiSP->docking_winS.x0, guiSP->docking_winS.y0, guiSP->docking_winS.width, guiSP->docking_winS.height, guiSP->docking_winS.border_width, guiSP->depth, InputOutput, guiSP->visualSP, docking_value_mask, &docking_attribS); guiSP->docking_window_createdF = 1; /* Prepare docking window name: */ strcpy (docking_win_titleA, "Docking"); docking_win_titleP = docking_win_titleA; /* Set docking window name: */ if (!XStringListToTextProperty (&docking_win_titleP, 1, &docking_win_titleS)) { ErrorMessage_ ("garlic", "PrepareDockingWindow_", "", "XStringListToTextProperty failed!\n", "", "", ""); return -1; } /*------docking icon window:-------------------------------------------------*/ /* Create docking icon pixmap: */ if (MakePixmap_ (&guiSP->docking_icon_winS, guiSP, docking_xpm) < 0) return -2; /* Set icon window attributes: */ docking_icon_attribS.border_pixel = BlackPixel (guiSP->displaySP, guiSP->screenID); docking_icon_attribS.background_pixmap = guiSP->docking_icon_winS.pixmapID; docking_icon_attribS.colormap = guiSP->colormapID; docking_icon_value_mask = CWBorderPixel | CWBackPixmap | CWColormap; guiSP->docking_icon_winS.x0 = 440; guiSP->docking_icon_winS.y0 = 50; guiSP->docking_icon_winS.border_width = 1; /* Create docking icon window: */ guiSP->docking_icon_winS.ID = XCreateWindow ( guiSP->displaySP, DefaultRootWindow (guiSP->displaySP), guiSP->docking_icon_winS.x0, guiSP->docking_icon_winS.y0, guiSP->docking_icon_winS.width, guiSP->docking_icon_winS.height, guiSP->docking_icon_winS.border_width, guiSP->depth, InputOutput, guiSP->visualSP, docking_icon_value_mask, &docking_icon_attribS); /* Set docking icon window colormap: */ XSetWindowColormap (guiSP->displaySP, guiSP->docking_icon_winS.ID, guiSP->colormapID); /* Prepare docking icon window name: */ strcpy (docking_icon_titleA, "Docking"); docking_icon_titleP = docking_icon_titleA; /* Set docking icon window name: */ if (!XStringListToTextProperty (&docking_icon_titleP, 1, &docking_icon_titleS)) { ErrorMessage_ ("garlic", "PrepareDockingWindow_", "", "Failed to allocate storage for XTextProperty structure!\n", "", "", ""); return -3; } /*------set window manager properties:---------------------------------------*/ /* Allocate and set size hints: */ size_hintsSP = XAllocSizeHints (); if (!size_hintsSP) { ErrorMessage_ ("garlic", "PrepareDockingWindow_", "", "Failed to allocate storage for size hints!\n", "", "", ""); return -4; } size_hintsSP->flags = PPosition | PSize | PMinSize; size_hintsSP->min_width = 100; size_hintsSP->min_height = 100; /* Allocate and set window manager hints: */ wm_hintsSP = XAllocWMHints (); if (!wm_hintsSP) { ErrorMessage_ ("garlic", "PrepareDockingWindow_", "", "Failed to allocate storage for window manager hints!\n", "", "", ""); return -5; } wm_hintsSP->initial_state = NormalState; wm_hintsSP->input = True; wm_hintsSP->icon_pixmap = guiSP->docking_icon_winS.pixmapID; wm_hintsSP->flags = StateHint | IconPixmapHint | InputHint; /* Allocate and set class hints: */ class_hintsSP = XAllocClassHint (); if (!class_hintsSP) { ErrorMessage_ ("garlic", "PrepareDockingWindow_", "", "Failed to allocate storage for class hints!\n", "", "", ""); return -6; } class_hintsSP->res_name = "docking"; class_hintsSP->res_class = "Garlic"; /* Set window manager properties: */ XSetWMProperties (guiSP->displaySP, guiSP->docking_winS.ID, &docking_win_titleS, &docking_icon_titleS, NULL, 0, size_hintsSP, wm_hintsSP, class_hintsSP); /*------select events:-------------------------------------------------------*/ event_mask = ExposureMask | KeyPressMask | KeyReleaseMask | StructureNotifyMask; /* Selects ConfigureNotify event */ XSelectInput (guiSP->displaySP, guiSP->docking_winS.ID, event_mask); /*------allocate storage required to project two structures:-----------------*/ /* The total number of cells across docking area: */ width = runtimeSP->docking_matrix_width; /* The number of elements in the array which contains */ /* indices of exposed atoms and size of a single element: */ elementsN = width * width; int_size = sizeof (int); /* Allocate the array reserved for the first complex (bottom molecule): */ runtimeSP->exposed_atom1IP = (int *) calloc (elementsN, int_size); if (!runtimeSP->exposed_atom1IP) { ErrorMessage_ ("garlic", "PrepareDockingWindow_", "", "Failed to allocate storage for exposed_atom1IP!\n", "", "", ""); return -7; } /* Allocate the array for the second complex (top molecule): */ runtimeSP->exposed_atom2IP = (int *) calloc (elementsN, int_size); if (!runtimeSP->exposed_atom2IP) { ErrorMessage_ ("garlic", "PrepareDockingWindow_", "", "Failed to allocate storage for exposed_atom2IP!\n", "", "", ""); return -8; } /*------allocate storage for two lists of exposed polar residues:------------*/ /* The size of ExposedResidueS structure: */ exposed_polar_size = sizeof (ExposedResidueS); /* Allocate the storage for the exposed polar residues (bottom complex): */ runtimeSP->exposed_polar1SP = (ExposedResidueS *) calloc (MAX_EXPOSED_RESIDUES, exposed_polar_size); if (runtimeSP->exposed_polar1SP == NULL) { ErrorMessage_ ("garlic", "PrepareDockingWindow_", "", "Failed to allocate memory", " for exposed polar residues (bottom complex)!\n", "", ""); return -9; } /* Allocate the storage for the exposed polar residues (top complex): */ runtimeSP->exposed_polar2SP = (ExposedResidueS *) calloc (MAX_EXPOSED_RESIDUES, exposed_polar_size); if (runtimeSP->exposed_polar2SP == NULL) { ErrorMessage_ ("garlic", "PrepareDockingWindow_", "", "Failed to allocate memory", " for exposed polar residues (top complex)!\n", "", ""); return -10; } /*------map docking window:--------------------------------------------------*/ /* Map docking window and set flag: */ XMapWindow (guiSP->displaySP, guiSP->docking_winS.ID); guiSP->docking_window_mappedF = 1; /*---------------------------------------------------------------------------*/ /* Return positive value on success: */ return 1; } /*===========================================================================*/ garlic-1.6/porins3.script0000644000076500007650000000145410114555122015732 0ustar zuciczucic00000000000000# Searching for sequence motifs characteristic for porins. # This script covers the following patterns: # # aromatic-anything-aliphatic # charged-anything-TYR-anything-hydrophobic # # 2004/04/26 # Hide water and other hetero atoms: select hetero hide # Draw just a backbone, using blue color: select complement show backbone 4 color cyan-blue # Select the first pattern: pattern = ARG LYS ASP GLU ASN GLN SER THR / * / ARG LYS ASP GLU ASN GLN SER THR / * / PHE TYR TRP / * / LEU ILE VAL ALA GLY MET / * / LEU ILE VAL ALA GLY MET select pattern color red # Select the second pattern (the first pattern is reversed here): pattern = LEU ILE VAL ALA GLY MET / * / LEU ILE VAL ALA GLY MET / * / PHE TYR TRP / * / ARG LYS ASP GLU ASN GLN SER THR / * / ARG LYS ASP GLU ASN GLN SER THR select pattern color yellow garlic-1.6/chains.c0000644000076500007650000000354007065464013014527 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= chains.c Purpose: Extract chain identifiers from the list. Input: (1) Pointer to SelectS structure, where data will be stored. (2) Pointer to the string with list of chain identifiers. Output: (1) Some data added to SelectS structure. (2) Return value. Return value: (1) Positive on success. (2) Negative on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======extract chain ID's:==================================================*/ int ExtractChains_ (SelectS *selectSP, char *stringP) { char *P, *tokenP; int chainI; /* Check the string length: */ if (strlen (stringP) == 0) return -1; /* Initialize all_chainsF (1 = select all chains): */ selectSP->all_chainsF = 0; /* Initialize the number of chain identifiers: */ selectSP->chainsN = 0; /* If wildcard (asterisk) is present, set all_chainsF to one and return: */ if (strstr (stringP, "*")) { selectSP->all_chainsF = 1; return 1; } /* Parse the list of chain identifiers: */ P = stringP; while ((tokenP = strtok (P, " \t,;")) != NULL) { /** Ensure the proper operation of strtok: **/ P = NULL; /** Check the token length - it should be equal to one: **/ if (strlen (tokenP) != 1) return -1; /** Copy the chain identifier and update the count: **/ chainI = selectSP->chainsN; selectSP->chainIDA[chainI] = *tokenP; /** Update and check the count: **/ selectSP->chainsN++; if (selectSP->chainsN >= MAXFIELDS) break; } /* Return positive value on success: */ return 1; } /*===========================================================================*/ garlic-1.6/extract_phrase.c0000644000076500007650000000337507124207344016302 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= extract_phrase.c Purpose: Extract phrase: copy the string, removing leading and trailing spaces, tabs and newline. Maximal phrase length is SHORTSTRINGSIZE - 1. Input: (1) Output string pointer. (2) Input string pointer. Output: (1) Substring stored at location pointed at by output string pointer. (2) Return value. Return value: (1) Output string length, on success. (2) Negative on failure. Notes: (1) Color specification in .garlicrc may contain a colon. Be careful! ========includes:============================================================*/ #include #include #include "defines.h" /*======extract phrase:======================================================*/ int ExtractPhrase_ (char *outP, char *inP) { char *currP; int i, n; /* Colon must be present (the leftmost one is a separator): */ if ((currP = strstr (inP, ":")) == NULL) { *outP = '\0'; return 0; } /* Skip the leading spaces and tabs (and newline, if line is bad): */ currP++; /* The character following colon */ while ((n = *currP) != '\0') { if ((n != ' ') && (n != '\t') && (n != '\n')) break; currP++; } /* Copy the rest, but no more than SHORTSTRINGSIZE - 1 character: */ i = 0; while ((n = *currP++) != '\0') { *(outP + i) = n; if (i >= SHORTSTRINGSIZE - 1) break; i++; } *(outP + i) = '\0'; /* Remove the trailing spaces, tabs and newline: */ n = strlen (outP); currP = outP + n - 1; while (currP != outP) { n = *currP; if ((n == ' ') || (n == '\t') || (n == '\n')) *currP = '\0'; else break; currP--; } return strlen (outP); } /*===========================================================================*/ garlic-1.6/backbone.c0000644000076500007650000004101407461726442015033 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2002 Damir Zucic */ /*============================================================================= backbone.c Purpose: Draw backbone. Input: (1) Pointer to MolComplexS structure. (2) Number of macromolecular complexes. (3) Pointer to ConfigS structure, with configuration data. (4) Pointer to GUIS structure. (5) Pointer to NearestAtomS structure, with information about the atom occupying the given pixel. (6) The number of pixels in the main window free area. (7) The refreshI, used to check the NearestAtomS associated with a given pixel. Output: (1) Bonds drawn to the hidden pixmap. (2) Return value. Return value: (1) The number of bonds drawn. Notes: (1) Indentation is exceptionally 4 spaces. (2) This function includes all drawing styles. =============================================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ unsigned long InterpolateColor_ (unsigned long, unsigned long, GUIS *); void AddTwoColors_ (unsigned long, unsigned long, GUIS *, unsigned long *, unsigned long *); void AddThreeColors_ (unsigned long, unsigned long, GUIS *, unsigned long *, unsigned long *, unsigned long *); int BondStyle1Quadrant1_ (Aux1S *, int); int BondStyle1Quadrant2_ (Aux1S *, int); int BondStyle1Quadrant3_ (Aux1S *, int); int BondStyle1Quadrant4_ (Aux1S *, int); int BondStyle2Quadrant1_ (Aux1S *, int); int BondStyle2Quadrant2_ (Aux1S *, int); int BondStyle2Quadrant3_ (Aux1S *, int); int BondStyle2Quadrant4_ (Aux1S *, int); int BondStyle3Quadrant1_ (Aux1S *, int); int BondStyle3Quadrant2_ (Aux1S *, int); int BondStyle3Quadrant3_ (Aux1S *, int); int BondStyle3Quadrant4_ (Aux1S *, int); int BondStyle4Quadrant1_ (Aux1S *, int); int BondStyle4Quadrant2_ (Aux1S *, int); int BondStyle4Quadrant3_ (Aux1S *, int); int BondStyle4Quadrant4_ (Aux1S *, int); int BondStyle5Quadrant1_ (Aux1S *, int); int BondStyle5Quadrant2_ (Aux1S *, int); int BondStyle5Quadrant3_ (Aux1S *, int); int BondStyle5Quadrant4_ (Aux1S *, int); /*======draw backbone:=======================================================*/ size_t DrawBackbone_ (MolComplexS *mol_complexSP, int mol_complexesN, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int refreshI) { size_t bonds_drawnN = 0; int imageI, imagesN; Aux1S aux1S; int mol_complexI; MolComplexS *curr_mol_complexSP; size_t c_alphaI, c_alphaN; BackboneS *curr_backboneSP; AtomS *curr_atomSP, *partner_atomSP; unsigned long color1ID, color2ID, color3ID; unsigned long color4ID, color5ID, color6ID; double z_shift, delta_z_sign; int screen_abs_delta_x, screen_abs_delta_y; int regionI; int styleI; int bondI; /* Number of images: */ if (configSP->stereoF) imagesN = 2; else imagesN = 1; /* Prepare the auxiliary Aux1S structure, used to */ /* reduce the number of arguments in function calls: */ aux1S.configSP = configSP; aux1S.guiSP = guiSP; aux1S.nearest_atomSP = nearest_atomSP; aux1S.pixelsN = pixelsN; aux1S.refreshI = refreshI; /* Initialize the bond index. The negative value */ /* means that backbone is not a true chemical bond: */ bondI = -1; /* Scan each macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check the number of atoms (the complex may be discarded): */ if (curr_mol_complexSP->atomsN == 0) continue; /* Prepare and check the number of CA atoms: */ c_alphaN = curr_mol_complexSP->c_alphaN; if (c_alphaN == 0) continue; /* Copy the macromol. complex index into aux1S: */ aux1S.mol_complexI = mol_complexI; /* Draw backbone for each CA atoms: */ for (c_alphaI = 0; c_alphaI < c_alphaN; c_alphaI++) { /* Pointer to the current BackboneS structure: */ curr_backboneSP = curr_mol_complexSP->backboneSP + c_alphaI; /* The current backbone element may be hidden: */ if (curr_backboneSP->hiddenF) continue; /* Pointer to the current CA atom: */ curr_atomSP = curr_mol_complexSP->atomSP + curr_backboneSP->c_alphaI; /* Check is atom inside slab: */ if (!curr_atomSP->inside_slabF) continue; /* Check is atom inside window: */ if (!curr_atomSP->inside_windowF) continue; /* Copy the style index: */ styleI = curr_backboneSP->backbone_styleI; /* Prepare colors: */ switch (styleI) { case 1: XSetForeground (guiSP->displaySP, guiSP->theGCA[0], curr_atomSP->left_colorID); aux1S.colorIDA[0] = curr_atomSP->left_colorID; break; case 2: XSetForeground (guiSP->displaySP, guiSP->theGCA[0], curr_atomSP->left_colorID); XSetForeground (guiSP->displaySP, guiSP->theGCA[1], curr_atomSP->middle_colorID); XSetForeground (guiSP->displaySP, guiSP->theGCA[2], curr_atomSP->right_colorID); aux1S.colorIDA[0] = curr_atomSP->left_colorID; aux1S.colorIDA[1] = curr_atomSP->middle_colorID; aux1S.colorIDA[2] = curr_atomSP->right_colorID; break; case 3: color1ID = InterpolateColor_ (curr_atomSP->left_colorID, curr_atomSP->middle_colorID, guiSP); color2ID = InterpolateColor_ (curr_atomSP->middle_colorID, curr_atomSP->right_colorID, guiSP); XSetForeground (guiSP->displaySP, guiSP->theGCA[0], curr_atomSP->left_colorID); XSetForeground (guiSP->displaySP, guiSP->theGCA[1], color1ID); XSetForeground (guiSP->displaySP, guiSP->theGCA[2], curr_atomSP->middle_colorID); XSetForeground (guiSP->displaySP, guiSP->theGCA[3], color2ID); XSetForeground (guiSP->displaySP, guiSP->theGCA[4], curr_atomSP->right_colorID); aux1S.colorIDA[0] = curr_atomSP->left_colorID; aux1S.colorIDA[1] = color1ID; aux1S.colorIDA[2] = curr_atomSP->middle_colorID; aux1S.colorIDA[3] = color2ID; aux1S.colorIDA[4] = curr_atomSP->right_colorID; break; case 4: AddTwoColors_ (curr_atomSP->left_colorID, curr_atomSP->middle_colorID, guiSP, &color1ID, &color2ID); AddTwoColors_ (curr_atomSP->middle_colorID, curr_atomSP->right_colorID, guiSP, &color3ID, &color4ID); XSetForeground (guiSP->displaySP, guiSP->theGCA[0], curr_atomSP->left_colorID); XSetForeground (guiSP->displaySP, guiSP->theGCA[1], color1ID); XSetForeground (guiSP->displaySP, guiSP->theGCA[2], color2ID); XSetForeground (guiSP->displaySP, guiSP->theGCA[3], curr_atomSP->middle_colorID); XSetForeground (guiSP->displaySP, guiSP->theGCA[4], color3ID); XSetForeground (guiSP->displaySP, guiSP->theGCA[5], color4ID); XSetForeground (guiSP->displaySP, guiSP->theGCA[6], curr_atomSP->right_colorID); aux1S.colorIDA[0] = curr_atomSP->left_colorID; aux1S.colorIDA[1] = color1ID; aux1S.colorIDA[2] = color2ID; aux1S.colorIDA[3] = curr_atomSP->middle_colorID; aux1S.colorIDA[4] = color3ID; aux1S.colorIDA[5] = color4ID; aux1S.colorIDA[6] = curr_atomSP->right_colorID; break; case 5: AddThreeColors_ (curr_atomSP->left_colorID, curr_atomSP->middle_colorID, guiSP, &color1ID, &color2ID, &color3ID); AddThreeColors_ (curr_atomSP->middle_colorID, curr_atomSP->right_colorID, guiSP, &color4ID, &color5ID, &color6ID); XSetForeground (guiSP->displaySP, guiSP->theGCA[0], curr_atomSP->left_colorID); XSetForeground (guiSP->displaySP, guiSP->theGCA[1], color1ID); XSetForeground (guiSP->displaySP, guiSP->theGCA[2], color2ID); XSetForeground (guiSP->displaySP, guiSP->theGCA[3], color3ID); XSetForeground (guiSP->displaySP, guiSP->theGCA[4], curr_atomSP->middle_colorID); XSetForeground (guiSP->displaySP, guiSP->theGCA[5], color4ID); XSetForeground (guiSP->displaySP, guiSP->theGCA[6], color5ID); XSetForeground (guiSP->displaySP, guiSP->theGCA[7], color6ID); XSetForeground (guiSP->displaySP, guiSP->theGCA[8], curr_atomSP->right_colorID); aux1S.colorIDA[0] = curr_atomSP->left_colorID; aux1S.colorIDA[1] = color1ID; aux1S.colorIDA[2] = color2ID; aux1S.colorIDA[3] = color3ID; aux1S.colorIDA[4] = curr_atomSP->middle_colorID; aux1S.colorIDA[5] = color4ID; aux1S.colorIDA[6] = color5ID; aux1S.colorIDA[7] = color6ID; aux1S.colorIDA[8] = curr_atomSP->right_colorID; break; } /* Copy the atomic index into aux1S: */ aux1S.atomI = curr_backboneSP->c_alphaI; /* Draw bond to the previous CA atom: */ if (curr_backboneSP->previous_c_alphaF) { /* Pointer to the bond partner: */ partner_atomSP = curr_mol_complexSP->atomSP + curr_backboneSP->previous_c_alphaI; /* Draw one (mono) or two bonds (stereo): */ for (imageI = 0; imageI < imagesN; imageI++) { /* Copy imageI to aux1S: */ aux1S.imageI = imageI; /* Prepare screen coordinates of */ /* both atoms involved in bond: */ aux1S.screen_x0 = curr_atomSP->raw_atomS.screen_x[imageI]; aux1S.screen_y0 = curr_atomSP->raw_atomS.screen_y; aux1S.screen_x1 = partner_atomSP->raw_atomS.screen_x[imageI]; aux1S.screen_y1 = partner_atomSP->raw_atomS.screen_y; aux1S.atomic_z0 = curr_atomSP->raw_atomS.z[imageI]; aux1S.atomic_z1 = partner_atomSP->raw_atomS.z[imageI]; /* Prepare differences: */ aux1S.screen_delta_x = aux1S.screen_x1 - aux1S.screen_x0; aux1S.screen_delta_y = aux1S.screen_y1 - aux1S.screen_y0; aux1S.atomic_delta_z = aux1S.atomic_z1 - aux1S.atomic_z0; /* Shift and tilt bond to ensure */ /* the proper stacking of bonds: */ delta_z_sign = 1.0; if (aux1S.atomic_delta_z < 0) delta_z_sign = -1.0; z_shift = delta_z_sign * Z_SHIFT; aux1S.atomic_z0 += z_shift; aux1S.atomic_z1 -= z_shift; aux1S.atomic_delta_z -= 3 * z_shift; /* Some absolute differences: */ screen_abs_delta_x = abs (aux1S.screen_delta_x); screen_abs_delta_y = abs (aux1S.screen_delta_y); /* Find the region: */ if (screen_abs_delta_x >= screen_abs_delta_y) { if (aux1S.screen_delta_x >= 0) regionI = 1; else regionI = 3; } else { if (aux1S.screen_delta_y >= 0) regionI = 2; else regionI = 4; } if ((aux1S.screen_delta_x == 0) && (aux1S.screen_delta_y == 0)) { regionI = 0; } /* Each region has its own drawing procedure: */ switch (regionI) { /* Both atoms are projected to the same point, */ /* i.e. this bond is perpendicular to the screen: */ case 0: /* Do nothing! */ break; /* Right quadrant: */ case 1: switch (styleI) { case 1: BondStyle1Quadrant1_ (&aux1S, bondI); break; case 2: BondStyle2Quadrant1_ (&aux1S, bondI); break; case 3: BondStyle3Quadrant1_ (&aux1S, bondI); break; case 4: BondStyle4Quadrant1_ (&aux1S, bondI); break; case 5: BondStyle5Quadrant1_ (&aux1S, bondI); break; default: ; } break; /* Bottom quadrant (check Note 3!): */ case 2: switch (styleI) { case 1: BondStyle1Quadrant2_ (&aux1S, bondI); break; case 2: BondStyle2Quadrant2_ (&aux1S, bondI); break; case 3: BondStyle3Quadrant2_ (&aux1S, bondI); break; case 4: BondStyle4Quadrant2_ (&aux1S, bondI); break; case 5: BondStyle5Quadrant2_ (&aux1S, bondI); break; default: ; } break; /* Left quadrant: */ case 3: switch (styleI) { case 1: BondStyle1Quadrant3_ (&aux1S, bondI); break; case 2: BondStyle2Quadrant3_ (&aux1S, bondI); break; case 3: BondStyle3Quadrant3_ (&aux1S, bondI); break; case 4: BondStyle4Quadrant3_ (&aux1S, bondI); break; case 5: BondStyle5Quadrant3_ (&aux1S, bondI); break; default: ; } break; /* Top quadrant (check Note 3!): */ case 4: switch (styleI) { case 1: BondStyle1Quadrant4_ (&aux1S, bondI); break; case 2: BondStyle2Quadrant4_ (&aux1S, bondI); break; case 3: BondStyle3Quadrant4_ (&aux1S, bondI); break; case 4: BondStyle4Quadrant4_ (&aux1S, bondI); break; case 5: BondStyle5Quadrant4_ (&aux1S, bondI); break; default: ; } break; /* This should be the impossible case: */ default: ; } /* Update the counter: */ bonds_drawnN++; } /* imageI loop */ } /* Draw bond to the next CA atom: */ if (curr_backboneSP->next_c_alphaF) { /* Pointer to the bond partner: */ partner_atomSP = curr_mol_complexSP->atomSP + curr_backboneSP->next_c_alphaI; /* Draw one (mono) or two bonds (stereo): */ for (imageI = 0; imageI < imagesN; imageI++) { /* Copy imageI to aux1S: */ aux1S.imageI = imageI; /* Prepare screen coordinates of */ /* both atoms involved in bond: */ aux1S.screen_x0 = curr_atomSP->raw_atomS.screen_x[imageI]; aux1S.screen_y0 = curr_atomSP->raw_atomS.screen_y; aux1S.screen_x1 = partner_atomSP->raw_atomS.screen_x[imageI]; aux1S.screen_y1 = partner_atomSP->raw_atomS.screen_y; aux1S.atomic_z0 = curr_atomSP->raw_atomS.z[imageI]; aux1S.atomic_z1 = partner_atomSP->raw_atomS.z[imageI]; /* Prepare differences: */ aux1S.screen_delta_x = aux1S.screen_x1 - aux1S.screen_x0; aux1S.screen_delta_y = aux1S.screen_y1 - aux1S.screen_y0; aux1S.atomic_delta_z = aux1S.atomic_z1 - aux1S.atomic_z0; /* Shift and tilt bond to ensure */ /* the proper stacking of bonds: */ delta_z_sign = 1.0; if (aux1S.atomic_delta_z < 0) delta_z_sign = -1.0; z_shift = delta_z_sign * Z_SHIFT; aux1S.atomic_z0 += z_shift; aux1S.atomic_z1 -= z_shift; aux1S.atomic_delta_z -= 3 * z_shift; /* Some absolute differences: */ screen_abs_delta_x = abs (aux1S.screen_delta_x); screen_abs_delta_y = abs (aux1S.screen_delta_y); /* Find the region: */ if (screen_abs_delta_x >= screen_abs_delta_y) { if (aux1S.screen_delta_x >= 0) regionI = 1; else regionI = 3; } else { if (aux1S.screen_delta_y >= 0) regionI = 2; else regionI = 4; } if ((aux1S.screen_delta_x == 0) && (aux1S.screen_delta_y == 0)) { regionI = 0; } /* Each region has its own drawing procedure: */ switch (regionI) { /* Both atoms are projected to the same point, */ /* i.e. this bond is perpendicular to the screen: */ case 0: /* Do nothing! */ break; /* Right quadrant: */ case 1: switch (styleI) { case 1: BondStyle1Quadrant1_ (&aux1S, bondI); break; case 2: BondStyle2Quadrant1_ (&aux1S, bondI); break; case 3: BondStyle3Quadrant1_ (&aux1S, bondI); break; case 4: BondStyle4Quadrant1_ (&aux1S, bondI); break; case 5: BondStyle5Quadrant1_ (&aux1S, bondI); break; default: ; } break; /* Bottom quadrant (check Note 3!): */ case 2: switch (styleI) { case 1: BondStyle1Quadrant2_ (&aux1S, bondI); break; case 2: BondStyle2Quadrant2_ (&aux1S, bondI); break; case 3: BondStyle3Quadrant2_ (&aux1S, bondI); break; case 4: BondStyle4Quadrant2_ (&aux1S, bondI); break; case 5: BondStyle5Quadrant2_ (&aux1S, bondI); break; default: ; } break; /* Left quadrant: */ case 3: switch (styleI) { case 1: BondStyle1Quadrant3_ (&aux1S, bondI); break; case 2: BondStyle2Quadrant3_ (&aux1S, bondI); break; case 3: BondStyle3Quadrant3_ (&aux1S, bondI); break; case 4: BondStyle4Quadrant3_ (&aux1S, bondI); break; case 5: BondStyle5Quadrant3_ (&aux1S, bondI); break; default: ; } break; /* Top quadrant (check Note 3!): */ case 4: switch (styleI) { case 1: BondStyle1Quadrant4_ (&aux1S, bondI); break; case 2: BondStyle2Quadrant4_ (&aux1S, bondI); break; case 3: BondStyle3Quadrant4_ (&aux1S, bondI); break; case 4: BondStyle4Quadrant4_ (&aux1S, bondI); break; case 5: BondStyle5Quadrant4_ (&aux1S, bondI); break; default: ; } break; /* This should be the impossible case: */ default: ; } /* Update the counter: */ bonds_drawnN++; } /* imageI loop */ } } /* c_alphaI loop */ } /* mol_complexI loop */ return bonds_drawnN; } /*===========================================================================*/ garlic-1.6/geo.script0000644000076500007650000000035707070456146015125 0ustar zuciczucic00000000000000color RGB:FFFF/5555/5555 RGB:FFFF/0000/0000 RGB:8888/0000/0000 RGB:FFFF/8888/0000 RGB:AAAA/5555/0000 RGB:6666/3333/0000 RGB:4444/FFFF/4444 RGB:0000/FFFF/0000 RGB:0000/8888/0000 RGB:5555/5555/FFFF RGB:0000/0000/FFFF RGB:0000/0000/8888 garlic-1.6/key_press.c0000644000076500007650000004441707463465534015311 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= key_press.c Purpose: Handle KeyPress events. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. (3) Pointer to the next macromolecular complex identifier. (4) Pointer to RuntimeS structure, with some runtime data. (5) Pointer to ConfigS structure, with configuration data. (6) Pointer to GUIS structure, with GUI data. (7) Pointer to pointer to NearestAtomS structure. (8) Pointer to the number of pixels in the main window free area. (9) Pointer to refreshI. (10) Pointer to XKeyEvent structure. Output: (1) Some action performed. (2) Return value. Return value: (1) Positive or zero on success. If positive value is returned, it should be interpreted as command code returned by the function ExecuteCommand1_ (). (2) Negative, if ExecuteCommand1_ () function failes. The value should be interpreted as (internal) error code. Notes: (1) The value of refreshI (*refreshIP) may be changed in this function. It is checked in EventLoop_ (see event_loop.c). It is assumed that refreshI is updated no more than once in each event handling function. If this is not the case, the care should be taken to avoid refreshI overflow. ========includes:============================================================*/ #include #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ double RotationAngle_ (ConfigS *, GUIS *, double); int Rotate_ (MolComplexS *, int, RuntimeS *, ConfigS *, double, int); size_t MainRefresh_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); int ControlRefresh_ (MolComplexS *, ConfigS *, GUIS *); int DockingRefresh_ (RuntimeS *, GUIS *); double TranslationShift_ (ConfigS *, GUIS *, double); void Translate_ (MolComplexS *, int, RuntimeS *, ConfigS *, double, int); double SlabShift_ (ConfigS *, GUIS *, double); void MoveBackSlab_ (MolComplexS *, int, ConfigS *, double); void MoveFrontSlab_ (MolComplexS *, int, ConfigS *, double); double FadingShift_ (ConfigS *, GUIS *, double); void MoveBackFading_ (MolComplexS *, int, ConfigS *, double); void MoveFrontFading_ (MolComplexS *, int, ConfigS *, double); int AddCharToCommand_ (RuntimeS *, GUIS *, int); int InputRefresh_ (GUIS *, RuntimeS *); int EatLeftChar_ (RuntimeS *); int EatRightChar_ (RuntimeS *); int ExecuteCommand1_ (MolComplexS *, int *, int *, RuntimeS *, ConfigS *, GUIS *, NearestAtomS **, size_t *, unsigned int *); int TruncateCommand_ (RuntimeS *); int ReplaceCommand_ (RuntimeS *, int, GUIS *); void InitNearest_ (NearestAtomS *, size_t); /*======handle KeyPress events:==============================================*/ int KeyPress_ (MolComplexS *mol_complexSP, int *mol_complexesNP, int *next_mol_complexIDP, RuntimeS *runtimeSP, ConfigS *configSP, GUIS *guiSP, NearestAtomS **nearest_atomSPP, size_t *pixelsNP, unsigned int *refreshIP, XKeyEvent *key_eventSP) { static char stringA[STRINGSIZE]; static KeySym key_symID; static XComposeStatus compose_statusS; static double rotation_angle; static double shift; static int carriage_pos, comm_length; static int new_char; static int command_code; static int n; /* Get the KeySym: */ XLookupString (key_eventSP, stringA, STRINGSIZE, &key_symID, &compose_statusS); /* Select the proper action for a given KeySym: */ switch (key_symID) { /*------modifiers:-----------------------------------------------------------*/ /* Shift key pressed: */ case XK_Shift_L: case XK_Shift_R: guiSP->shift_pressedF = 1; break; /* Control key pressed: */ case XK_Control_L: case XK_Control_R: guiSP->control_pressedF = 1; break; /* Alt or meta key pressed: */ case XK_Alt_L: case XK_Alt_R: case XK_Meta_L: case XK_Meta_R: guiSP->alt_pressedF = 1; break; /*------rotations:-----------------------------------------------------------*/ /* Right-handed (positive) rotation about x: */ case XK_KP_2: case XK_KP_Down: (*refreshIP)++; rotation_angle = RotationAngle_ (configSP, guiSP, 1.0); Rotate_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, rotation_angle, 1); MainRefresh_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, *refreshIP); ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); if (guiSP->dockingF) DockingRefresh_ (runtimeSP, guiSP); break; /* Left-handed (negative) rotation about x: */ case XK_KP_8: case XK_KP_Up: (*refreshIP)++; rotation_angle = RotationAngle_ (configSP, guiSP, -1.0); Rotate_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, rotation_angle, 1); MainRefresh_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, *refreshIP); ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); if (guiSP->dockingF) DockingRefresh_ (runtimeSP, guiSP); break; /* Right-handed (positive) rotation about y: */ case XK_KP_4: case XK_KP_Left: (*refreshIP)++; rotation_angle = RotationAngle_ (configSP, guiSP, +1.0); Rotate_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, rotation_angle, 2); MainRefresh_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, *refreshIP); ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); if (guiSP->dockingF) DockingRefresh_ (runtimeSP, guiSP); break; /* Left-handed (negative) rotation about y: */ case XK_KP_6: case XK_KP_Right: (*refreshIP)++; rotation_angle = RotationAngle_ (configSP, guiSP, -1.0); Rotate_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, rotation_angle, 2); MainRefresh_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, *refreshIP); ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); if (guiSP->dockingF) DockingRefresh_ (runtimeSP, guiSP); break; /* Right-handed (positive) rotation about z: */ case XK_KP_9: case XK_KP_Prior: (*refreshIP)++; rotation_angle = RotationAngle_ (configSP, guiSP, +1.0); Rotate_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, rotation_angle, 3); MainRefresh_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, *refreshIP); ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); if (guiSP->dockingF) DockingRefresh_ (runtimeSP, guiSP); break; /* Left-handed (negative) rotation about z: */ case XK_KP_7: case XK_KP_Home: (*refreshIP)++; rotation_angle = RotationAngle_ (configSP, guiSP, -1.0); Rotate_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, rotation_angle, 3); MainRefresh_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, *refreshIP); ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); if (guiSP->dockingF) DockingRefresh_ (runtimeSP, guiSP); break; /*------translations:--------------------------------------------------------*/ /* Positive translation along x: */ case XK_KP_Multiply: case XK_KP_F4: (*refreshIP)++; shift = TranslationShift_ (configSP, guiSP, +1.0); Translate_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, shift, 1); MainRefresh_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, *refreshIP); if (guiSP->dockingF) DockingRefresh_ (runtimeSP, guiSP); break; /* Negative translation along x: */ case XK_KP_Divide: case XK_KP_F3: (*refreshIP)++; shift = TranslationShift_ (configSP, guiSP, -1.0); Translate_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, shift, 1); MainRefresh_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, *refreshIP); if (guiSP->dockingF) DockingRefresh_ (runtimeSP, guiSP); break; /* Positive translation along y: */ case XK_KP_Add: case XK_KP_Separator: (*refreshIP)++; shift = TranslationShift_ (configSP, guiSP, +1.0); Translate_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, shift, 2); MainRefresh_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, *refreshIP); if (guiSP->dockingF) DockingRefresh_ (runtimeSP, guiSP); break; /* Negative translation along y: */ case XK_KP_Subtract: (*refreshIP)++; shift = TranslationShift_ (configSP, guiSP, -1.0); Translate_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, shift, 2); MainRefresh_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, *refreshIP); if (guiSP->dockingF) DockingRefresh_ (runtimeSP, guiSP); break; /* Positive translation along z: */ case XK_KP_5: case XK_KP_Begin: (*refreshIP)++; shift = TranslationShift_ (configSP, guiSP, +1.0); Translate_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, shift, 3); MainRefresh_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, *refreshIP); if (guiSP->dockingF) DockingRefresh_ (runtimeSP, guiSP); break; /* Negative translation along z: */ case XK_KP_0: case XK_KP_Insert: (*refreshIP)++; shift = TranslationShift_ (configSP, guiSP, -1.0); Translate_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, shift, 3); MainRefresh_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, *refreshIP); if (guiSP->dockingF) DockingRefresh_ (runtimeSP, guiSP); break; /*------slab:----------------------------------------------------------------*/ /* Push the back slab surface farther: */ case XK_KP_1: case XK_KP_End: (*refreshIP)++; shift = SlabShift_ (configSP, guiSP, 1.0); MoveBackSlab_ (mol_complexSP, *mol_complexesNP, configSP, shift); MainRefresh_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, *refreshIP); ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); break; /* Pull the back slab surface closer: */ case XK_KP_3: case XK_KP_Next: (*refreshIP)++; shift = SlabShift_ (configSP, guiSP, -1.0); MoveBackSlab_ (mol_complexSP, *mol_complexesNP, configSP, shift); MainRefresh_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, *refreshIP); ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); break; /* Push the front slab surface farther: */ case XK_KP_Delete: case XK_KP_Decimal: (*refreshIP)++; shift = SlabShift_ (configSP, guiSP, 1.0); MoveFrontSlab_ (mol_complexSP, *mol_complexesNP, configSP, shift); MainRefresh_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, *refreshIP); ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); break; /* Pull the front slab surface closer: */ case XK_KP_Enter: (*refreshIP)++; shift = SlabShift_ (configSP, guiSP, -1.0); MoveFrontSlab_ (mol_complexSP, *mol_complexesNP, configSP, shift); MainRefresh_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, *refreshIP); ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); break; /*------fading:--------------------------------------------------------------*/ /* Push the back fading surface farther: */ case XK_F1: (*refreshIP)++; shift = FadingShift_ (configSP, guiSP, 1.0); MoveBackFading_ (mol_complexSP, *mol_complexesNP, configSP, shift); MainRefresh_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, *refreshIP); ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); break; /* Pull the back fading surface closer: */ case XK_F2: (*refreshIP)++; shift = FadingShift_ (configSP, guiSP, -1.0); MoveBackFading_ (mol_complexSP, *mol_complexesNP, configSP, shift); MainRefresh_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, *refreshIP); ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); break; /* Push the front fading surface farther: */ case XK_F3: (*refreshIP)++; shift = FadingShift_ (configSP, guiSP, 1.0); MoveFrontFading_ (mol_complexSP, *mol_complexesNP, configSP, shift); MainRefresh_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, *refreshIP); ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); break; /* Pull the front fading surface closer: */ case XK_F4: (*refreshIP)++; shift = FadingShift_ (configSP, guiSP, -1.0); MoveFrontFading_ (mol_complexSP, *mol_complexesNP, configSP, shift); MainRefresh_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, *refreshIP); ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); break; /*------line editing:--------------------------------------------------------*/ /* Move the input window carriage (keyboard cursor) to the left: */ case XK_Left: carriage_pos = runtimeSP->carriage_position; carriage_pos--; if (carriage_pos >= 0) { runtimeSP->carriage_position = carriage_pos; InputRefresh_ (guiSP, runtimeSP); } break; /* Move the input window carriage (keyboard cursor) to the right: */ case XK_Right: carriage_pos = runtimeSP->carriage_position; comm_length = runtimeSP->command_length; carriage_pos++; if (carriage_pos <= comm_length) { runtimeSP->carriage_position = carriage_pos; InputRefresh_ (guiSP, runtimeSP); } break; /* Replace the current command with the previous one, if available: */ case XK_Up: n = ReplaceCommand_ (runtimeSP, -1, guiSP); if (n < 0) break; InputRefresh_ (guiSP, runtimeSP); break; /* Replace the current command with the next one (if available): */ case XK_Down: n = ReplaceCommand_ (runtimeSP, +1, guiSP); if (n < 0) break; InputRefresh_ (guiSP, runtimeSP); break; /* Move the input window carriage to the beginning of command line: */ case XK_Home: runtimeSP->carriage_position = 0; InputRefresh_ (guiSP, runtimeSP); break; /* Move the input window carrriage to the end of command line: */ case XK_End: runtimeSP->carriage_position = runtimeSP->command_length; InputRefresh_ (guiSP, runtimeSP); break; /* Remove one character on the left side: */ case XK_BackSpace: EatLeftChar_ (runtimeSP); InputRefresh_ (guiSP, runtimeSP); break; /* Remove one character on the right side: */ case XK_Delete: EatRightChar_ (runtimeSP); InputRefresh_ (guiSP, runtimeSP); break; /*------command execution:---------------------------------------------------*/ /* Print command string to log file (if requested), */ /* execute command, truncate command string, reset */ /* the string length and refresh the input window. */ /* If some kind of error occurs, the return code */ /* should be negative. In that case, print the */ /* error message to log file (if it is requested). */ case XK_Return: /** Print command to log file, if requested: **/ if (configSP->log_fileF) { fprintf (configSP->log_fileP, "%s\n", runtimeSP->curr_commandA); fflush (configSP->log_fileP); } /** Parse command string and execute command: **/ command_code = ExecuteCommand1_ ( mol_complexSP, mol_complexesNP, next_mol_complexIDP, runtimeSP, configSP, guiSP, nearest_atomSPP, pixelsNP, refreshIP); /** Print the latest message to log file, if requested: **/ if ((command_code < 0) && (configSP->log_fileF)) { fprintf (configSP->log_fileP, "#%s\n", runtimeSP->messageA); fflush (configSP->log_fileP); } /** Truncate the command string: **/ TruncateCommand_ (runtimeSP); /** Refresh (redraw) the input window: **/ InputRefresh_ (guiSP, runtimeSP); /** Update and check the command index **/ /** and the total number of commands: **/ runtimeSP->next_commandI++; if (runtimeSP->next_commandI >= MAXCOMMSTRINGS - 1) { runtimeSP->next_commandI = 0; } if (runtimeSP->highest_commandI < MAXCOMMSTRINGS - 1) { runtimeSP->highest_commandI++; } /** Update the old_commandI: **/ runtimeSP->old_commandI = runtimeSP->next_commandI; /** Return command code to the caller: **/ return command_code; break; /*------escape key causes return to the main drawing mode:-------------------*/ /* Reset main window drawing mode and refresh the main window: */ case XK_Escape: /* Reset drawing mode index: */ guiSP->main_window_modeI = 0; /* Reinitialize the NearestAtomS array: */ InitNearest_ (*nearest_atomSPP, *pixelsNP); *refreshIP = 1; /* Refresh the main window: */ (*refreshIP)++; MainRefresh_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, *refreshIP); /* Refresh the control window: */ ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); break; /*------character input:-----------------------------------------------------*/ /* All other keys should belong to the current command string: */ default: /** Check the character: **/ new_char = stringA[0]; if (!isprint (new_char)) break; /** Append the character to the command string: **/ if (AddCharToCommand_ (runtimeSP, guiSP, new_char) < 0) break; /** Refresh the input window: **/ InputRefresh_ (guiSP, runtimeSP); ; /*---------------------------------------------------------------------------*/ } /* Return zero if this point is reached: */ return 0; } /*===========================================================================*/ garlic-1.6/ccacaa.script0000644000076500007650000000014010043201141015505 0ustar zuciczucic00000000000000# Preparing data for publication. load 2por.pdb sel 1-301 seq from 1 win 18 sca int plot hyd garlic-1.6/draw_labels.c0000644000076500007650000001000707611073612015533 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2003 Damir Zucic */ /*============================================================================= draw_labels.c Purpose: Draw atomic labels to the main window. Note that drawing is not done to the hidden pixmap! Input: (1) Pointer to MolComplexS structure. (2) Number of macromolecular complexes. (3) Pointer to ConfigS structure. (4) Pointer to GUIS structure. Output: (1) Labels drawn to hidden pixmap. (2) Return value. Return value: The number of labels drawn. =============================================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======draw labels:=========================================================*/ size_t DrawLabels_ (MolComplexS *mol_complexSP, int mol_complexesN, ConfigS *configSP, GUIS *guiSP) { size_t labels_drawnN = 0; int imageI, imagesN; int left_edge[2], right_edge[2]; int mol_complexI; MolComplexS *curr_mol_complexSP; size_t atomsN, atomI; AtomS *curr_atomSP; int screen_x, screen_y; static char stringA[SHORTSTRINGSIZE]; int string_length, text_width; /* Number of images: */ if (configSP->stereoF) imagesN = 2; else imagesN = 1; /* Left and right image edge (in stereo mode there are two images): */ left_edge[0] = configSP->image_screen_x0[0]; right_edge[0] = configSP->image_screen_x1[0]; left_edge[1] = configSP->image_screen_x0[1]; right_edge[1] = configSP->image_screen_x1[1]; /* Prepare the text color: */ XSetForeground (guiSP->displaySP, guiSP->theGCA[0], guiSP->main_winS.fg_colorID); /* Check every macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Prepare and check the number of atoms: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Check every atom: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Check flag: */ if (curr_atomSP->labelF != 1) continue; /* Check is atom hidden: */ if (curr_atomSP->hiddenF) continue; /* Check is atom inside slab: */ if (!curr_atomSP->inside_slabF) continue; /* Check is atom inside window: */ if (!curr_atomSP->inside_windowF) continue; /* Draw one (mono) or two labels (stereo): */ for (imageI = 0; imageI < imagesN; imageI++) { /* Prepare the coordinates: */ screen_x = curr_atomSP->raw_atomS.screen_x[imageI]; screen_y = curr_atomSP->raw_atomS.screen_y; /* Check is this atom really visible: */ if (screen_x < left_edge[imageI]) continue; if (screen_x >= right_edge[imageI]) continue; /* Prepare label: */ if (curr_atomSP->raw_atomS.chainID == ' ') { sprintf (stringA, "%s %d %s%c", curr_atomSP->raw_atomS.residue_nameA, curr_atomSP->raw_atomS.residue_sequenceI, curr_atomSP->raw_atomS.pure_atom_nameA, curr_atomSP->raw_atomS.alt_location); } else { sprintf (stringA, "%s %d%c %s%c", curr_atomSP->raw_atomS.residue_nameA, curr_atomSP->raw_atomS.residue_sequenceI, curr_atomSP->raw_atomS.chainID, curr_atomSP->raw_atomS.pure_atom_nameA, curr_atomSP->raw_atomS.alt_location); } /* String length: */ string_length = strlen (stringA); /* Prepare the string size in pixels: */ text_width = XTextWidth (guiSP->main_winS.fontSP, stringA, string_length); /* Draw label: */ XDrawString (guiSP->displaySP, guiSP->main_winS.ID, guiSP->theGCA[0], screen_x - text_width / 2, screen_y, stringA, string_length); /* Update the counter: */ labels_drawnN++; } /* imageI loop */ } /* atomI loop */ } /* mol_complexI loop */ /* Return the number of labels which were drawn: */ return labels_drawnN; } /*===========================================================================*/ garlic-1.6/is_aromatic.c0000644000076500007650000000174610120252766015556 0ustar zuciczucic00000000000000/* Copyright (C) 2004 Damir Zucic */ /*============================================================================= is_aromatic.c Purpose: Check is the specified residue aromatic. Input: (1) Residue name (purified, i.e. without spaces). Output: (1) Return value. Return value: (1) Zero, if residue is not aromatic. (2) One, if residue is aromatic. ========includes:============================================================*/ #include #include /*======check is the specified residue aromatic:=============================*/ int IsAromatic_ (char *pure_residue_nameP) { static char aromatic_nameAA[4][4] = {"HIS", "PHE", "TRP", "TYR"}; int i; /* Compare only the first three characters: */ for (i = 0; i < 4; i++) { if (!strcmp (aromatic_nameAA[i], pure_residue_nameP)) return 1; } /* If this point is reached, the specified residue is not aromatic: */ return 0; } /*===========================================================================*/ garlic-1.6/big.fasta0000644000076500007650000000236407314062242014675 0ustar zuciczucic00000000000000> big polyalanine AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA garlic-1.6/chi2_from_cacbcgcd1.c0000644000076500007650000000731407341220675017010 0ustar zuciczucic00000000000000/* Copyright (C) 2001 Damir Zucic */ /*============================================================================= chi2_from_cacbcgcd1.c Purpose: Calculate dihedral angle chi2, using CA, CB, CG and CD1 coordinates. Input: (1) Pointer to AtomS structure, pointing to the first atom of the current macromolecular complex. (2) Index of the first atom of the current residue. (3) Index of the last atom of the currrent residue. Output: Return value. Return value: (1) Dihedral angle chi2, on success. (2) BADDIHEDANGLE on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int ExtractFourAtoms_ (VectorS *, VectorS *, VectorS *, VectorS *, char *, char *, char *, char *, AtomS *, size_t, size_t); void VectorProduct_ (VectorS *, VectorS *, VectorS *); double AbsoluteValue_ (VectorS *); double ScalarProduct_ (VectorS *, VectorS *); /*======calculate chi2 from CA, CB, CG and CD1:==============================*/ double Chi2FromCACBCGCD1_ (AtomS *atomSP, size_t atom_startI, size_t atom_endI) { static VectorS CA_vectorS, CB_vectorS, CG_vectorS, CD1_vectorS; int n; VectorS CB_CA_vectorS, CB_CG_vectorS; VectorS CG_CB_vectorS, CG_CD1_vectorS; VectorS u1S, u2S; VectorS v1S, v2S; double denom, ratio, alpha; double chi2; /* Extract CA, CB, CG and CD1 coordinates: */ n = ExtractFourAtoms_ (&CA_vectorS, &CB_vectorS, &CG_vectorS, &CD1_vectorS, "CA", "CB", "CG", "CD1", atomSP, atom_startI, atom_endI); /* All four atoms are required to calculate the angle chi2: */ if (n < 4) return BADDIHEDANGLE; /* The first pair of auxiliary vectors: */ CB_CA_vectorS.x = CA_vectorS.x - CB_vectorS.x; CB_CA_vectorS.y = CA_vectorS.y - CB_vectorS.y; CB_CA_vectorS.z = CA_vectorS.z - CB_vectorS.z; CB_CG_vectorS.x = CG_vectorS.x - CB_vectorS.x; CB_CG_vectorS.y = CG_vectorS.y - CB_vectorS.y; CB_CG_vectorS.z = CG_vectorS.z - CB_vectorS.z; /* The second pair of auxiliary vectors: */ CG_CB_vectorS.x = CB_vectorS.x - CG_vectorS.x; CG_CB_vectorS.y = CB_vectorS.y - CG_vectorS.y; CG_CB_vectorS.z = CB_vectorS.z - CG_vectorS.z; CG_CD1_vectorS.x = CD1_vectorS.x - CG_vectorS.x; CG_CD1_vectorS.y = CD1_vectorS.y - CG_vectorS.y; CG_CD1_vectorS.z = CD1_vectorS.z - CG_vectorS.z; /* Two vectors perpendicular to CB_CG_vectorS, mutually orthogonal, */ /* the second in the plane defined by CB_CA_vectorS and CB_CG_vectorS: */ VectorProduct_ (&u1S, &CB_CA_vectorS, &CB_CG_vectorS); VectorProduct_ (&u2S, &u1S, &CB_CG_vectorS); /* Two vectors perpendicular to CG_CB_vectorS, mutually orthogonal, */ /* the second in the plane defined by CG_CB_vectorS and CG_CD1_vectorS: */ VectorProduct_ (&v1S, &CG_CB_vectorS, &CG_CD1_vectorS); VectorProduct_ (&v2S, &CG_CB_vectorS, &v1S); /* Calculate the angle alpha, which will be used to calculate chi2: */ /* Avoid division by zero: */ denom = AbsoluteValue_ (&u1S) * AbsoluteValue_ (&v1S); if (denom == 0.0) return BADDIHEDANGLE; /* Use the scalar product to calculate the cosine of the angle: */ ratio = ScalarProduct_ (&u1S, &v1S) / denom; /* Arc cosine is very sensitive to floating point errors: */ if (ratio <= -1.0) alpha = 3.1415927; else if (ratio >= 1.0) alpha = 0.0; else alpha = acos (ratio); /* There are two possible solutions; the right one is resolved here: */ if (ScalarProduct_ (&v2S, &u1S) >= 0) chi2 = alpha; else chi2 = -alpha; /* Return the angle (in radians): */ return chi2; } /*===========================================================================*/ garlic-1.6/background.c0000644000076500007650000000531107071062120015365 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= background.c Purpose: Execute background command: change the main window background color. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) The number of macromolecular complexes. (3) Pointer to RuntimeS structure, with some runtime data. (4) Pointer to ConfigS structure, with configuration data. (5) Pointer to GUIS structure, with GUI data. (6) Pointer to NearestAtomS structure. (7) The number of pixels in the main window free area. (8) Pointer to refreshI. Output: (1) Log file created. (2) Return value. Return value: (1) Positive (command) code on success. (2) Negative (error) code on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "commands.h" #include "typedefs.h" /*======function prototypes:=================================================*/ char *ExtractToken_ (char *, int, char *, char *); int ParseColor_ (RGBS *, unsigned long *, GUIS *, char *, char *); size_t MainRefresh_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); /*======execute bg command:==================================================*/ int Background_ (MolComplexS *mol_complexSP, int mol_complexesN, RuntimeS *runtimeSP, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int *refreshIP) { char *remainderP; char tokenA[STRINGSIZE]; /* Skip the first token: */ remainderP = ExtractToken_ (tokenA, STRINGSIZE, runtimeSP->curr_commandA, " \t\n"); if (!remainderP) return ERROR_BACKGROUND; /* The second token should contain the color: */ remainderP = ExtractToken_ (tokenA, STRINGSIZE, remainderP, " \t\n"); if (!remainderP) { strcpy (runtimeSP->messageA, "Main window background color missing!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_NO_COLOR; } /* Prepare the main window background color: */ strncpy (configSP->bg_colorA, tokenA, SHORTSTRINGSIZE - 1); configSP->bg_colorA[SHORTSTRINGSIZE - 1] = '\0'; ParseColor_ (&guiSP->main_winS.bg_rgbS, &guiSP->main_winS.bg_colorID, guiSP, configSP->bg_colorA, "black"); /* Refresh the main window: */ (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); /* Return positive value on success: */ return COMMAND_BACKGROUND; } /*===========================================================================*/ garlic-1.6/draw_system.c0000644000076500007650000000431707611074023015621 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2003 Damir Zucic */ /*============================================================================= draw_system.c Purpose: Put small legend describing the coordinate system to the top left corner of the main window. Do not create pixmap, just use raw pixmap data. Red color is treated as transparent. Read system.xpm to check the pixmap! Input: (1) Pointer to GUIS structure, with GUI data. (2) Pixmap file (included as header). Output: (1) Small transparent pixmap drawn to the top left corner of the main window. (2) Return value. Return value: (1) Positive on success. (2) Negative on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" #include "system.xpm" /*======put coordinate system description to the top left corner:============*/ int DrawSystem_ (GUIS *guiSP) { static int width = 50, height = 54, i, j, screen_x, screen_y; int current_char; /* Prepare two graphics contexts (set colors): */ XSetForeground (guiSP->displaySP, guiSP->theGCA[0], guiSP->black_colorID); XSetForeground (guiSP->displaySP, guiSP->theGCA[1], guiSP->white_colorID); /* Draw the pixmap to the screen, leaving part of the background visible: */ for (i = 0; i < height; i++) /* i is line index */ { for (j = 0; j < width; j++) /* j is column index */ { /** Prepare the pixel position: **/ screen_x = j; screen_y = i + guiSP->main_winS.font_height + 7; /** Check the current character: **/ current_char = system_xpm[i + 4][j]; switch (current_char) { case '#': /* Do nothing - transparent color (red)! */ break; case 'a': XDrawPoint (guiSP->displaySP, guiSP->main_winS.ID, guiSP->theGCA[0], screen_x, screen_y); break; case '.': XDrawPoint (guiSP->displaySP, guiSP->main_winS.ID, guiSP->theGCA[1], screen_x, screen_y); break; default: ; } } } /* Return positive value on success: */ return 1; } /*===========================================================================*/ garlic-1.6/make_pixmap2.c0000644000076500007650000001142010157104573015631 0ustar zuciczucic00000000000000/* Copyright (C) 2004 Damir Zucic */ /*============================================================================= makepixmap2.c Purpose: Make pixmap from an array of strings. Array is obtained from the file which is included in calling function; MakePixmap_ receives pointer to char pointer. Xpm library is not used here. Xpm is quite good, but raw Xlib was chosen to make the whole garlic package as portable as possible. Though many systems have Xpm library, there are still some which don't. Pixmap should be hard-coded (included) in calling function. This function should be used to create pixmap which is not bound to any window. Pixmaps bound to windows should be created using the function MakePixmap_ (make_pixmap.c). Input: (1) Pointer to the pixmap identifier. (2) Pointer to the pixmap width. (3) Pointer to the pixmap height. (4) Pointer to GUIS structure. (5) Pointer to char pointer, with pixmap data. There are no special checks: if pixmap file is bad, core dump may be expected. Check each pixmap with a program like cxpm. Up to 256 color allowed. pixmap data. It has file scope. This file is not checked; if it is bad, core dump may be expected. If icon pixmap is changed it may be checked with cxpm program. Up to 256 colors allowed. Output: (1) Pixmap created. (2) Pixmap identifier. (3) Pixmap width. (4) Pixmap height. (5) Return value. Return value: (1) Positive on success. (2) Negative on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ void ErrorMessage_ (char *, char *, char *, char *, char *, char *, char *); void RGBSFromXColor_ (RGBS *, XColor *); unsigned long PixelFromRGBS_ (RGBS *, GUIS *); /*======make pixmap from an array of strings, version 2:=====================*/ int MakePixmap2_ (Pixmap *pixmapIDP, unsigned int *pixmap_widthP, unsigned int *pixmap_heightP, GUIS *guiSP, char **dataPP) { unsigned int width, height, colorsN; Status status; XColor colorS; RGBS rgbS; unsigned long black_colorID; Pixmap pixmapID; int i, j; char line_copyA[STRINGSIZE]; int n; char *P, *P1; unsigned long pixel; unsigned long colorIDA[256]; int offset; /* Extract pixmap dimensions and number of colors: */ if (sscanf (*dataPP, "%u %u %u", &width, &height, &colorsN) != 3) { ErrorMessage_ ("garlic", "MakePixmap_", "", "Failed to extract data from pixmap header!\n", "", "", ""); return -1; } /* Check the number of colors: */ if (colorsN > 256) { ErrorMessage_ ("garlic", "MakePixmap_", "", "Number of colors in pixmap limited to 256!\n", "", "", ""); return -2; } /* Store pixmap width and height: */ *pixmap_widthP = width; *pixmap_heightP = height; /* Prepare the black color (replacement for unrecognized colors): */ status = XParseColor (guiSP->displaySP, guiSP->colormapID, "black", &colorS); if (status) { RGBSFromXColor_ (&rgbS, &colorS); black_colorID = PixelFromRGBS_ (&rgbS, guiSP); } else { ErrorMessage_ ("garlic", "MakePixmap_", "", "Unable to parse black color!\n", "", "", ""); return -3; } /* Create pixmap: */ pixmapID = XCreatePixmap (guiSP->displaySP, DefaultRootWindow (guiSP->displaySP), width, height, guiSP->depth); *pixmapIDP = pixmapID; /* Parse colors: */ /* (Note: be sure that pixmap is good, no check is done here!) */ for (i = 1; i < (int) colorsN + 1; i++) { /** Copy the i-th line: **/ strncpy (line_copyA, *(dataPP + i), STRINGSIZE - 1); line_copyA[STRINGSIZE - 1] = '\0'; /** The first token is the color array index: **/ n = line_copyA[0]; /** Skip the first character and take one token; **/ /** it should be letter 'c' or 's' - ignore it: **/ P1 = line_copyA + 1; P = strtok (P1, " \t"); /** The next token is color specification; **/ P = strtok (NULL, " \t\""); /** This token is expected to specify some color; parse it: **/ status = XParseColor (guiSP->displaySP, guiSP->colormapID, P, &colorS); if (status) { RGBSFromXColor_ (&rgbS, &colorS); pixel = PixelFromRGBS_ (&rgbS, guiSP); } else pixel = black_colorID; colorIDA[n] = pixel; } /* Parse pixels and draw pixmap using default graphics context: */ offset = colorsN + 1; for (j = 0; j < (int) height; j++) { offset = j + colorsN + 1; for (i = 0; i < (int) width; i++) { P = *(dataPP + offset) + i; n = *P; XSetForeground (guiSP->displaySP, guiSP->theGCA[0], colorIDA[n]); XDrawPoint (guiSP->displaySP, pixmapID, guiSP->theGCA[0], i, j); } } return 1; } /*===========================================================================*/ garlic-1.6/chi2_from_cacbcgnd1.c0000644000076500007650000000732207341214017017013 0ustar zuciczucic00000000000000/* Copyright (C) 2001 Damir Zucic */ /*============================================================================= chi2_from_cacbcgnd1.c Purpose: Calculate dihedral angle chi2, using CA, CB, CG and ND1 coordinates. Input: (1) Pointer to AtomS structure, pointing to the first atom of the current macromolecular complex. (2) Index of the first atom of the current residue. (3) Index of the last atom of the currrent residue. Output: Return value. Return value: (1) Dihedral angle chi2, on success. (2) BADDIHEDANGLE on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int ExtractFourAtoms_ (VectorS *, VectorS *, VectorS *, VectorS *, char *, char *, char *, char *, AtomS *, size_t, size_t); void VectorProduct_ (VectorS *, VectorS *, VectorS *); double AbsoluteValue_ (VectorS *); double ScalarProduct_ (VectorS *, VectorS *); /*======calculate chi2 from CA, CB, CG and ND1:==============================*/ double Chi2FromCACBCGND1_ (AtomS *atomSP, size_t atom_startI, size_t atom_endI) { static VectorS CA_vectorS, CB_vectorS, CG_vectorS, ND1_vectorS; int n; VectorS CB_CA_vectorS, CB_CG_vectorS; VectorS CG_CB_vectorS, CG_ND1_vectorS; VectorS u1S, u2S; VectorS v1S, v2S; double denom, ratio, alpha; double chi2; /* Extract CA, CB, CG and ND1 coordinates: */ n = ExtractFourAtoms_ (&CA_vectorS, &CB_vectorS, &CG_vectorS, &ND1_vectorS, "CA", "CB", "CG", "ND1", atomSP, atom_startI, atom_endI); /* All four atoms are required to calculate the angle chi2: */ if (n < 4) return BADDIHEDANGLE; /* The first pair of auxiliary vectors: */ CB_CA_vectorS.x = CA_vectorS.x - CB_vectorS.x; CB_CA_vectorS.y = CA_vectorS.y - CB_vectorS.y; CB_CA_vectorS.z = CA_vectorS.z - CB_vectorS.z; CB_CG_vectorS.x = CG_vectorS.x - CB_vectorS.x; CB_CG_vectorS.y = CG_vectorS.y - CB_vectorS.y; CB_CG_vectorS.z = CG_vectorS.z - CB_vectorS.z; /* The second pair of auxiliary vectors: */ CG_CB_vectorS.x = CB_vectorS.x - CG_vectorS.x; CG_CB_vectorS.y = CB_vectorS.y - CG_vectorS.y; CG_CB_vectorS.z = CB_vectorS.z - CG_vectorS.z; CG_ND1_vectorS.x = ND1_vectorS.x - CG_vectorS.x; CG_ND1_vectorS.y = ND1_vectorS.y - CG_vectorS.y; CG_ND1_vectorS.z = ND1_vectorS.z - CG_vectorS.z; /* Two vectors perpendicular to CB_CG_vectorS, mutually orthogonal, */ /* the second in the plane defined by CB_CA_vectorS and CB_CG_vectorS: */ VectorProduct_ (&u1S, &CB_CA_vectorS, &CB_CG_vectorS); VectorProduct_ (&u2S, &u1S, &CB_CG_vectorS); /* Two vectors perpendicular to CG_CB_vectorS, mutually orthogonal, */ /* the second in the plane defined by CG_CB_vectorS and CG_ND1_vectorS: */ VectorProduct_ (&v1S, &CG_CB_vectorS, &CG_ND1_vectorS); VectorProduct_ (&v2S, &CG_CB_vectorS, &v1S); /* Calculate the angle alpha, which will be used to calculate chi2: */ /* Avoid division by zero: */ denom = AbsoluteValue_ (&u1S) * AbsoluteValue_ (&v1S); if (denom == 0.0) return BADDIHEDANGLE; /* Use the scalar product to calculate the cosine of the angle: */ ratio = ScalarProduct_ (&u1S, &v1S) / denom; /* Arc cosine is very sensitive to floating point errors: */ if (ratio <= -1.0) alpha = 3.1415927; else if (ratio >= 1.0) alpha = 0.0; else alpha = acos (ratio); /* There are two possible solutions; the right one is resolved here: */ if (ScalarProduct_ (&v2S, &u1S) >= 0) chi2 = alpha; else chi2 = -alpha; /* Return the angle (in radians): */ return chi2; } /*===========================================================================*/ garlic-1.6/chi2_from_cacbcgod1.c0000644000076500007650000000732207341213441017014 0ustar zuciczucic00000000000000/* Copyright (C) 2001 Damir Zucic */ /*============================================================================= chi2_from_cacbcgod1.c Purpose: Calculate dihedral angle chi2, using CA, CB, CG and OD1 coordinates. Input: (1) Pointer to AtomS structure, pointing to the first atom of the current macromolecular complex. (2) Index of the first atom of the current residue. (3) Index of the last atom of the currrent residue. Output: Return value. Return value: (1) Dihedral angle chi2, on success. (2) BADDIHEDANGLE on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int ExtractFourAtoms_ (VectorS *, VectorS *, VectorS *, VectorS *, char *, char *, char *, char *, AtomS *, size_t, size_t); void VectorProduct_ (VectorS *, VectorS *, VectorS *); double AbsoluteValue_ (VectorS *); double ScalarProduct_ (VectorS *, VectorS *); /*======calculate chi2 from CA, CB, CG and OD1:==============================*/ double Chi2FromCACBCGOD1_ (AtomS *atomSP, size_t atom_startI, size_t atom_endI) { static VectorS CA_vectorS, CB_vectorS, CG_vectorS, OD1_vectorS; int n; VectorS CB_CA_vectorS, CB_CG_vectorS; VectorS CG_CB_vectorS, CG_OD1_vectorS; VectorS u1S, u2S; VectorS v1S, v2S; double denom, ratio, alpha; double chi2; /* Extract CA, CB, CG and OD1 coordinates: */ n = ExtractFourAtoms_ (&CA_vectorS, &CB_vectorS, &CG_vectorS, &OD1_vectorS, "CA", "CB", "CG", "OD1", atomSP, atom_startI, atom_endI); /* All four atoms are required to calculate the angle chi2: */ if (n < 4) return BADDIHEDANGLE; /* The first pair of auxiliary vectors: */ CB_CA_vectorS.x = CA_vectorS.x - CB_vectorS.x; CB_CA_vectorS.y = CA_vectorS.y - CB_vectorS.y; CB_CA_vectorS.z = CA_vectorS.z - CB_vectorS.z; CB_CG_vectorS.x = CG_vectorS.x - CB_vectorS.x; CB_CG_vectorS.y = CG_vectorS.y - CB_vectorS.y; CB_CG_vectorS.z = CG_vectorS.z - CB_vectorS.z; /* The second pair of auxiliary vectors: */ CG_CB_vectorS.x = CB_vectorS.x - CG_vectorS.x; CG_CB_vectorS.y = CB_vectorS.y - CG_vectorS.y; CG_CB_vectorS.z = CB_vectorS.z - CG_vectorS.z; CG_OD1_vectorS.x = OD1_vectorS.x - CG_vectorS.x; CG_OD1_vectorS.y = OD1_vectorS.y - CG_vectorS.y; CG_OD1_vectorS.z = OD1_vectorS.z - CG_vectorS.z; /* Two vectors perpendicular to CB_CG_vectorS, mutually orthogonal, */ /* the second in the plane defined by CB_CA_vectorS and CB_CG_vectorS: */ VectorProduct_ (&u1S, &CB_CA_vectorS, &CB_CG_vectorS); VectorProduct_ (&u2S, &u1S, &CB_CG_vectorS); /* Two vectors perpendicular to CG_CB_vectorS, mutually orthogonal, */ /* the second in the plane defined by CG_CB_vectorS and CG_OD1_vectorS: */ VectorProduct_ (&v1S, &CG_CB_vectorS, &CG_OD1_vectorS); VectorProduct_ (&v2S, &CG_CB_vectorS, &v1S); /* Calculate the angle alpha, which will be used to calculate chi2: */ /* Avoid division by zero: */ denom = AbsoluteValue_ (&u1S) * AbsoluteValue_ (&v1S); if (denom == 0.0) return BADDIHEDANGLE; /* Use the scalar product to calculate the cosine of the angle: */ ratio = ScalarProduct_ (&u1S, &v1S) / denom; /* Arc cosine is very sensitive to floating point errors: */ if (ratio <= -1.0) alpha = 3.1415927; else if (ratio >= 1.0) alpha = 0.0; else alpha = acos (ratio); /* There are two possible solutions; the right one is resolved here: */ if (ScalarProduct_ (&v2S, &u1S) >= 0) chi2 = alpha; else chi2 = -alpha; /* Return the angle (in radians): */ return chi2; } /*===========================================================================*/ garlic-1.6/sample.fasta0000644000076500007650000000036707112034673015421 0ustar zuciczucic00000000000000>1l00_ mol:protein length:164 Lysozyme (E.C. 3.2.1.17) Mutant With Gln 105 MNIFEMLRIDEGLRLKIYKDTEGYYTIGIGHLLTKSPSLNAAKSELDKAIGRNCNGVITKDEAEKLFNQDVDAAV RGILRNAKLKPVYDSLDAVRRCALINMVFAMGETGVAGFTNSLRMLQQKRWDEAAVNLAKSRWYNQTPNRAKRVI TTFRTGTWDAYKNL garlic-1.6/extract_four_atoms.c0000644000076500007650000000656007341017725017200 0ustar zuciczucic00000000000000/* Copyright (C) 2001 Damir Zucic */ /*============================================================================= extract_four_atoms.c Purpose: Extract the coordinates of the four atoms. The atoms are defined given by the purified atomic names (like "N", "CA", "CB" etc.). Input: (1) Pointer to VectorS structure for the first atom. (2) Pointer to VectorS structure for the second atom. (3) Pointer to VectorS structure for the third atom. (4) Pointer to VectorS structure for the fourth atom. (5) Pointer to the name of the first atom. (6) Pointer to the name of the second atom. (7) Pointer to the name of the third atom. (8) Pointer to the name of the fourth atom. (9) Pointer to AtomS structure, pointing to the first element of the atomic array. (10) Index of the first atom of a given residue. (11) Index of the last atom of a given residue. Output: (1) VectorS structures filled with data. (2) Return value. Return value: (1) The number of successfully extracted vectors (at least zero, at most four). Notes: (1) Some files contain more than one entry for some atoms. Only the first entry is used here. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======extract four atoms:==================================================*/ int ExtractFourAtoms_ (VectorS *vector1SP, VectorS *vector2SP, VectorS *vector3SP, VectorS *vector4SP, char *name1P, char *name2P, char *name3P, char *name4P, AtomS *atomSP, size_t atom_startI, size_t atom_endI) { int vectors_extractedN = 0; size_t atomI; AtomS *curr_atomSP; int found1F = 0, found2F = 0, found3F = 0, found4F = 0; /* Scan the given residue: */ for (atomI = atom_startI; atomI <= atom_endI; atomI++) { /* Pointer to the current atom: */ curr_atomSP = atomSP + atomI; /* The first atom: */ if (strcmp (curr_atomSP->raw_atomS.pure_atom_nameA, name1P) == 0) { if (found1F) continue; vector1SP->x = curr_atomSP->raw_atomS.x[0]; vector1SP->y = curr_atomSP->raw_atomS.y; vector1SP->z = curr_atomSP->raw_atomS.z[0]; vectors_extractedN++; found1F = 1; } /* The second atom: */ else if (strcmp (curr_atomSP->raw_atomS.pure_atom_nameA, name2P) == 0) { if (found2F) continue; vector2SP->x = curr_atomSP->raw_atomS.x[0]; vector2SP->y = curr_atomSP->raw_atomS.y; vector2SP->z = curr_atomSP->raw_atomS.z[0]; vectors_extractedN++; found2F = 1; } /* The third atom: */ else if (strcmp (curr_atomSP->raw_atomS.pure_atom_nameA, name3P) == 0) { if (found3F) continue; vector3SP->x = curr_atomSP->raw_atomS.x[0]; vector3SP->y = curr_atomSP->raw_atomS.y; vector3SP->z = curr_atomSP->raw_atomS.z[0]; vectors_extractedN++; found3F = 1; } /* The fourth atom: */ else if (strcmp (curr_atomSP->raw_atomS.pure_atom_nameA, name4P) == 0) { if (found4F) continue; vector4SP->x = curr_atomSP->raw_atomS.x[0]; vector4SP->y = curr_atomSP->raw_atomS.y; vector4SP->z = curr_atomSP->raw_atomS.z[0]; vectors_extractedN++; found4F = 1; } } /* Return the number of extracted vectors: */ return vectors_extractedN; } /*===========================================================================*/ garlic-1.6/exclude.c0000644000076500007650000001116710124233376014713 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2004 Damir Zucic */ /*============================================================================= exclude.c Purpose: Identify chains, residue ranges, residue names and atom names which have to be excluded from selection. Input: (1) Pointer to SelectS structure, where data will be stored. (2) Pointer to the selection string. Output: (1) SelectS structure filled with data. (2) Return value. Return value: (1) Positive on success. (2) Negative on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ char *ExtractToken_ (char *, int, char *, char *); char *SkipKeyword_ (char *, char *); int ExtractChains_ (SelectS *, char *); int ExtractResidueRanges_ (SelectS *, char *); int ExtractResidueNames_ (SelectS *, char *); int ExtractAtomNames_ (SelectS *, char *); /*======identify excluded ranges and names:==================================*/ int Exclude_ (SelectS *exclude_selectSP, char *stringP) { char string_copyA[STRINGSIZE]; char *remainderP; char tokenA[STRINGSIZE]; char *exceptP, *dataP; /* Copy the input string to preserve it: */ strncpy (string_copyA, stringP, STRINGSIZE - 1); string_copyA[STRINGSIZE - 1] = '\0'; /* Pointer to the remainder of the string */ /* initially points to the whole string: */ remainderP = stringP; /* The first token should contain chain identifiers: */ remainderP = ExtractToken_ (tokenA, STRINGSIZE, remainderP, "/"); if (remainderP == NULL) return -1; /* If keyword exc is present, skip one token and extract chain identifiers: */ if ((exceptP = strstr (tokenA, "EXC")) != NULL) { /** Skip one token: **/ if ((dataP = SkipKeyword_ (exceptP, " \t,;")) == NULL) return -2; /** Extract chain identifiers: **/ if (ExtractChains_ (exclude_selectSP, dataP) < 0) return -3; } /* If keyword exc is not present, initialize flag and count: */ else { /** Initialize all_chainsF (1 = select all chains): **/ exclude_selectSP->all_chainsF = 0; /** Initialize the number of chain identifiers: **/ exclude_selectSP->chainsN = 0; } /* The second token should contain residue ranges: */ remainderP = ExtractToken_ (tokenA, STRINGSIZE, remainderP, "/"); if (remainderP == NULL) return -4; /* If keyword exc is present, skip one token and extract residue ranges: */ if ((exceptP = strstr (tokenA, "EXC")) != NULL) { /** Skip one token: **/ if ((dataP = SkipKeyword_ (exceptP, " \t,;")) == NULL) return -5; /** Extract residue ranges: **/ if (ExtractResidueRanges_ (exclude_selectSP, dataP) < 0) return -6; } /* If keyword exc is not present, initialize flag and count: */ else { /* Initialize all_residue_serialF (1 = select all serial numbers): */ exclude_selectSP->all_residue_serialF = 0; /* Initialize the number of ranges: */ exclude_selectSP->residue_serial_rangesN = 0; } /* The third token should contain residue names: */ remainderP = ExtractToken_ (tokenA, STRINGSIZE, remainderP, "/"); if (remainderP == NULL) return -7; /* If keyword exc is present, skip one token and extract residue names: */ if ((exceptP = strstr (tokenA, "EXC")) != NULL) { /** Skip one token: **/ if ((dataP = SkipKeyword_ (exceptP, " \t,;")) == NULL) return -8; /** Extract residue names: **/ if (ExtractResidueNames_ (exclude_selectSP, dataP) < 0) return -9; } /* If keyword exc is not present, initialize flag and count: */ else { /* Initialize all_residue_namesF (1 = select all residue names): */ exclude_selectSP->all_residue_namesF = 0; /* Initialize the number of residue names: */ exclude_selectSP->residue_namesN = 0; } /* The fourth (the last) token should contain atom names: */ remainderP = ExtractToken_ (tokenA, STRINGSIZE, remainderP, "/"); if (remainderP == NULL) return -10; /* If keyword exc is present, skip one token and extract atom names: */ if ((exceptP = strstr (tokenA, "EXC")) != NULL) { /** Skip one token: **/ if ((dataP = SkipKeyword_ (exceptP, " \t,;")) == NULL) return -11; /** Extract chain identifiers: **/ if (ExtractAtomNames_ (exclude_selectSP, dataP) < 0) return -12; } /* If keyword exc is not present, initialize flag and count: */ else { /* Initialize all_atom_namesF (1 = select all atom names): */ exclude_selectSP->all_atom_namesF = 0; /* Initialize the number of atom names: */ exclude_selectSP->atom_namesN = 0; } /* Return positive value on success: */ return 1; } /*===========================================================================*/ garlic-1.6/parse_color.c0000644000076500007650000000356507065474147015612 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= parse_color.c Purpose: Parse color string and prepare color structure and color ID. Input: (1) Pointer to RGBS structure, where color components will be stored. (2) Pointer to color ID (unsigned long). (3) Pointer to GUIS structure, with input data. (4) Color string pointer. Output: (1) XColor structure initialized. (2) Color ID initialized. (3) Return value. Return value: (1) Positive on success. (2) Negative on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ void RGBSFromXColor_ (RGBS *, XColor *); unsigned long PixelFromRGBS_ (RGBS *, GUIS *); /*======parse color string:==================================================*/ int ParseColor_ (RGBS *rgbSP, unsigned long *colorIDP, GUIS *guiSP, char *color_stringP, char *default_color_stringP) { Status status; XColor colorS; /* The first attempt: */ status = XParseColor (guiSP->displaySP, guiSP->colormapID, color_stringP, &colorS); if (status) { RGBSFromXColor_ (rgbSP, &colorS); *colorIDP = PixelFromRGBS_ (rgbSP, guiSP); return 1; } /* The second attempt (if the first one failed): */ status = XParseColor (guiSP->displaySP, guiSP->colormapID, default_color_stringP, &colorS); if (status) { RGBSFromXColor_ (rgbSP, &colorS); *colorIDP = PixelFromRGBS_ (rgbSP, guiSP); return 2; } /* If this point is reached, both attempts to allocate color failed: */ return -1; } /*===========================================================================*/ garlic-1.6/ex_fading_steps.c0000644000076500007650000000312307612772205016424 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2003 Damir Zucic */ /*============================================================================= ex_fading_steps.c Purpose: Extract fading steps (five doubles) from a string. Input: (1) Pointer to ConfigS structure, where values will be stored. (2) Input string pointer. Output: Return value. Return value: (1) Positive on success. (2) Negative on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======extract fading steps from a string:==================================*/ int ExtractFadingSteps_ (ConfigS *configSP, char *sP) { char *P0, *P1; int n; double d1, d2, d3, d4, d5; /* Colon should be separator: */ if ((P0 = strstr (sP, ":")) == NULL) P0 = sP; /* Replace each non-numeric character (except */ /* minus sign and decimal point) with space: */ P1 = P0; while ((n = *P1++) != '\0') { if (!isdigit (n) && (n != '-') && (n != '.')) *(P1 - 1) = ' '; } /* Try to read five doubles: */ if (sscanf (P0, "%lf %lf %lf %lf %lf", &d1, &d2, &d3, &d4, &d5) != 5) { return -1; } /* Copy fading steps to ConfigS: */ configSP->fading_stepA[0] = d1; configSP->fading_stepA[1] = d2; configSP->fading_stepA[2] = d3; configSP->fading_stepA[3] = d4; configSP->fading_stepA[4] = d5; /* If everything worked fine, return positive number: */ return 1; } /*===========================================================================*/ garlic-1.6/init_runtime.c0000644000076500007650000004216610445770737016010 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2006 Damir Zucic */ /*============================================================================= init_runtime.c Purpose: Initialize some runtime data and allocate required memory. Input: (1) Pointer to RuntimeS structure. (2) Pointer to ConfigS structure. Output: (1) Runtime parameters initialized. (2) Return value. Return value: (1) Positive on success. (2) Negative on failure. Notes: (1) The buffers exposed_atom1IP and exposed_atom2IP will be allocated only if docking is required. Otherwise, there is no need to allocate these buffers. The allocation is done in a function which creates docking window. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ void ErrorMessage_ (char *, char *, char *, char *, char *, char *, char *); FILE *OpenTemplateFile_ (void); int ReadTemplateFile_ (RuntimeS *, FILE *, ConfigS *); /*======initialize runtime:==================================================*/ int InitRuntime_ (RuntimeS *runtimeSP, ConfigS *configSP) { size_t char_size; size_t int_size, double_size; size_t atom_struct_size; size_t beta_cell_size; size_t elementsN; int i; double d; int width; FILE *template_fileP; /* Initialize the click_modeI: */ runtimeSP->click_modeI = 0; /* Initialize the edit_modeI: */ runtimeSP->edit_modeI = 0; /* Initialize edit_single_bondF flag: */ runtimeSP->edit_single_bondF = 0; /* Default caught macromolecular complex: */ runtimeSP->default_complexI = 0; /* Initialize the scriptF (0 = interactive mode, 1 = script mode): */ runtimeSP->scriptF = 0; /* Initialize the pauseF (0 = do not stop execution, 1 = pause): */ runtimeSP->pauseF = 0; /* Initialize the rama_selectionF: */ runtimeSP->rama_selectionF = 0; /* Initialize the wheel_clockwiseF: */ runtimeSP->wheel_clockwiseF = 0; /* Initialize the groupF: */ runtimeSP->groupF = 0; /* Size of a single character: */ char_size = sizeof (char); /* Size of integer: */ int_size = sizeof (int); /* Size of double: */ double_size = sizeof (double); /* Size of AtomS: */ atom_struct_size = sizeof (AtomS); /* Size of BetaCellS: */ beta_cell_size = sizeof (BetaCellS); /* Allocate memory for command strings (the history buffer): */ elementsN = MAXCOMMSTRINGS * COMMSTRINGSIZE; runtimeSP->commandsP = (char *) calloc (elementsN, char_size); if (runtimeSP->commandsP == NULL) { ErrorMessage_ ("garlic", "InitRuntime_", "", "Failed to allocate memory for command strings!\n", "", "", ""); return -1; } /* Initialize next_commandI, old_commandI and highest_commandI: */ runtimeSP->next_commandI = 0; runtimeSP->old_commandI = 0; runtimeSP->highest_commandI = -1; /* Initialize the carriage (keyboard cursor) position: */ runtimeSP->carriage_position = 0; /* Zero initialize the curr_commandA: */ runtimeSP->curr_commandA[0] = '\0'; /* Initialize the length of the current command and carriage position: */ runtimeSP->command_length = 0; runtimeSP->carriage_position = 0; /* Zero initialize the messageA: */ runtimeSP->messageA[0] = '\0'; /* Initialize the length of the message: */ runtimeSP->message_length = 0; /* Allocate memory for titles: */ elementsN = MAXTITLES * TITLESTRINGSIZE; runtimeSP->titlesP = (char *) calloc (elementsN, char_size); if (runtimeSP->titlesP == NULL) { ErrorMessage_ ("garlic", "InitRuntime_", "", "Failed to allocate memory for title strings!\n", "", "", ""); return -2; } /* All titles are initially hidden: */ for (i = 0; i < MAXTITLES; i++) runtimeSP->title_hiddenF[i] = 1; /* Initialize positions of titles: */ for (i = 0; i < MAXTITLES; i++) { runtimeSP->title_screen_x[i] = 10; runtimeSP->title_screen_y[i] = 10; } /* Initialize the size of the sequence buffer: */ runtimeSP->sequence_buffer_size = MAXRESIDUES * (RESNAMESIZE - 1); /* Initialize the number of residues in the sequence buffer: */ runtimeSP->residuesN = 0; /* Allocate the sequence buffer: */ elementsN = runtimeSP->sequence_buffer_size; runtimeSP->sequenceP = (char *) calloc (elementsN, char_size); if (runtimeSP->sequenceP == NULL) { ErrorMessage_ ("garlic", "InitRuntime_", "", "Failed to allocate the sequence buffer!\n", "", "", ""); return -3; } /* Initialize the size of the pattern buffer: */ runtimeSP->pattern_buffer_size = MAX_RES_IN_PATT * (RESNAMESIZE - 1); /* Initialize the number of residues in the pattern buffer: */ runtimeSP->residues_in_patternN = 0; /* Initialize the pattern tolerance: */ runtimeSP->pattern_tolerance = 0; /* Allocate the pattern buffer: */ elementsN = runtimeSP->pattern_buffer_size; runtimeSP->patternP = (char *) calloc (elementsN, char_size); if (runtimeSP->patternP == NULL) { ErrorMessage_ ("garlic", "InitRuntime_", "", "Failed to allocate the pattern buffer!\n", "", "", ""); return -4; } /* Initialize the array with the number of residues per set: */ for (i = 0; i < MAX_PATT_LENGTH; i++) { runtimeSP->namesNA[i] = 0; } /* Allocate the secondary structure buffer: */ elementsN = MAXRESIDUES; runtimeSP->sec_structureP = (char *) calloc (elementsN, char_size); if (runtimeSP->sec_structureP == NULL) { ErrorMessage_ ("garlic", "InitRuntime_", "", "Failed to allocate the secondary structure buffer!\n", "", "", ""); return -5; } /* Fill the buffer with the code for extended conformation: */ runtimeSP->sec_structure_length = MAXRESIDUES; for (i = 0; i < MAXRESIDUES; i++) *(runtimeSP->sec_structureP + i) = 'E'; /* Allocate memory for disulfide flags (see typedefs.h): */ elementsN = MAXRESIDUES; runtimeSP->disulfideFP = (int *) calloc (elementsN, int_size); if (runtimeSP->disulfideFP == NULL) { ErrorMessage_ ("garlic", "InitRuntime_", "", "Failed to allocate memory for disulfide flags!\n", "", "", ""); return -6; } /* Allocate memory for serial numbers: */ elementsN = MAXRESIDUES; runtimeSP->serialIP = (int *) calloc (elementsN, int_size); if (runtimeSP->serialIP == NULL) { ErrorMessage_ ("garlic", "InitRuntime_", "", "Failed to allocate memory for residue serial numbers!\n", "", "", ""); return -7; } /* Allocate memory for numeric residue codes: */ elementsN = MAXRESIDUES; runtimeSP->residue_codeIP = (int *) calloc (elementsN, int_size); if (runtimeSP->residue_codeIP == NULL) { ErrorMessage_ ("garlic", "InitRuntime_", "", "Failed to allocate memory for numeric residue codes!\n", "", "", ""); return -8; } /* Allocate memory for hydrophobicity values: */ elementsN = MAXRESIDUES; runtimeSP->hydrophobicityP = (double *) calloc (elementsN, double_size); if (runtimeSP->hydrophobicityP == NULL) { ErrorMessage_ ("garlic", "InitRuntime_", "", "Failed to allocate memory for hydrophobicity values!\n", "", "", ""); return -9; } /* Allocate memory for average hydrophobicity: */ elementsN = MAXRESIDUES; runtimeSP->average_hydrophobicityP = (double *) calloc (elementsN, double_size); if (runtimeSP->average_hydrophobicityP == NULL) { ErrorMessage_ ("garlic", "InitRuntime_", "", "Failed to allocate memory for average hydrophobicity!\n", "", "", ""); return -10; } /* Allocate memory for weighted hydrophobicity: */ elementsN = MAXRESIDUES; runtimeSP->weighted_hydrophobicityP = (double *) calloc (elementsN, double_size); if (runtimeSP->weighted_hydrophobicityP == NULL) { ErrorMessage_ ("garlic", "InitRuntime_", "", "Failed to allocate memory for weighted hydrophobicity!\n", "", "", ""); return -11; } /* Allocate memory for hydrophobic moment: */ elementsN = MAXRESIDUES; runtimeSP->hydrophobic_momentP = (double *) calloc (elementsN, double_size); if (runtimeSP->hydrophobic_momentP == NULL) { ErrorMessage_ ("garlic", "InitRuntime_", "", "Failed to allocate memory for hydrophobic moment!\n", "", "", ""); return -12; } /* Allocate memory for sided hydrophobicity (two buffers): */ elementsN = MAXRESIDUES; runtimeSP->larger_sided_hyphobP = (double *) calloc (elementsN, double_size); if (runtimeSP->larger_sided_hyphobP == NULL) { ErrorMessage_ ("garlic", "InitRuntime_", "", "Failed to allocate memory for larger sided hydrophobicity!\n", "", "", ""); return -13; } runtimeSP->smaller_sided_hyphobP = (double *) calloc (elementsN, double_size); if (runtimeSP->smaller_sided_hyphobP == NULL) { ErrorMessage_ ("garlic", "InitRuntime_", "", "Failed to allocate memory for smaller sided hydrophobicity!\n", "", "", ""); return -14; } /* Allocate memory for hydrophobicity function F1: */ elementsN = MAXRESIDUES; runtimeSP->function1P = (double *) calloc (elementsN, double_size); if (runtimeSP->function1P == NULL) { ErrorMessage_ ("garlic", "InitRuntime_", "", "Failed to allocate memory for function F1!\n", "", "", ""); return -15; } /* Allocate memory for hydrophobicity function F2: */ elementsN = MAXRESIDUES; runtimeSP->function2P = (double *) calloc (elementsN, double_size); if (runtimeSP->function2P == NULL) { ErrorMessage_ ("garlic", "InitRuntime_", "", "Failed to allocate memory for function F2!\n", "", "", ""); return -16; } /* Allocate memory for hydrophobicity function F3: */ elementsN = MAXRESIDUES; runtimeSP->function3P = (double *) calloc (elementsN, double_size); if (runtimeSP->function3P == NULL) { ErrorMessage_ ("garlic", "InitRuntime_", "", "Failed to allocate memory for function F3!\n", "", "", ""); return -17; } /* Allocate memory for hydrophobicity function F4: */ elementsN = MAXRESIDUES; runtimeSP->function4P = (double *) calloc (elementsN, double_size); if (runtimeSP->function4P == NULL) { ErrorMessage_ ("garlic", "InitRuntime_", "", "Failed to allocate memory for function F4!\n", "", "", ""); return -18; } /* Allocate memory for hydrophobicity function F5: */ elementsN = MAXRESIDUES; runtimeSP->function5P = (double *) calloc (elementsN, double_size); if (runtimeSP->function5P == NULL) { ErrorMessage_ ("garlic", "InitRuntime_", "", "Failed to allocate memory for function F5!\n", "", "", ""); return -19; } /* Allocate memory for hydrophobicity function F6: */ elementsN = MAXRESIDUES; runtimeSP->function6P = (double *) calloc (elementsN, double_size); if (runtimeSP->function6P == NULL) { ErrorMessage_ ("garlic", "InitRuntime_", "", "Failed to allocate memory for function F6!\n", "", "", ""); return -20; } /* Allocate memory for hydrophobicity function F7: */ elementsN = MAXRESIDUES; runtimeSP->function7P = (double *) calloc (elementsN, double_size); if (runtimeSP->function7P == NULL) { ErrorMessage_ ("garlic", "InitRuntime_", "", "Failed to allocate memory for function F7!\n", "", "", ""); return -21; } /* Allocate memory for auxiliary integers: */ elementsN = MAXRESIDUES; runtimeSP->auxiliaryIP = (int *) calloc (elementsN, int_size); if (runtimeSP->auxiliaryIP == NULL) { ErrorMessage_ ("garlic", "InitRuntime_", "", "Failed to allocate memory", " for auxiliary integers!\n", "", ""); return -22; } /* Allocate memory for auxiliary double values: */ elementsN = MAXRESIDUES; runtimeSP->aux_doubleP = (double *) calloc (elementsN, double_size); if (runtimeSP->aux_doubleP == NULL) { ErrorMessage_ ("garlic", "InitRuntime_", "", "Failed to allocate memory", " for auxiliary double values!\n", "", ""); return -23; } /* Initialize the number of residues in the reference sequence buffer: */ runtimeSP->reference_residuesN = 0; /* Allocate the reference sequence buffer: */ elementsN = runtimeSP->sequence_buffer_size; runtimeSP->reference_sequenceP = (char *) calloc (elementsN, char_size); if (runtimeSP->reference_sequenceP == NULL) { ErrorMessage_ ("garlic", "InitRuntime_", "", "Failed to allocate the reference sequence buffer!\n", "", "", ""); return -24; } /* Initialize the reference secondary structure length: */ runtimeSP->reference_sec_str_length = 0; /* Allocate the reference secondary structure buffer: */ elementsN = MAXRESIDUES; runtimeSP->reference_sec_structureP = (char *) calloc (elementsN, char_size); if (runtimeSP->reference_sec_structureP == NULL) { ErrorMessage_ ("garlic", "InitRuntime_", "", "Failed to allocate", " the reference secondary structure buffer!\n", "", ""); return -25; } /* Allocate memory for reference serial numbers: */ elementsN = MAXRESIDUES; runtimeSP->reference_serialIP = (int *) calloc (elementsN, int_size); if (runtimeSP->reference_serialIP == NULL) { ErrorMessage_ ("garlic", "InitRuntime_", "", "Failed to allocate memory", " for reference residue serial numbers!\n", "", ""); return -26; } /* Allocate memory for reference numeric residue codes: */ elementsN = MAXRESIDUES; runtimeSP->reference_residue_codeIP = (int *) calloc (elementsN, int_size); if (runtimeSP->reference_residue_codeIP == NULL) { ErrorMessage_ ("garlic", "InitRuntime_", "", "Failed to allocate memory", " for reference numeric residue codes!\n", "", ""); return -27; } /* Allocate memory for reference hydrophobicity values: */ elementsN = MAXRESIDUES; runtimeSP->reference_hydrophobicityP = (double *) calloc (elementsN, double_size); if (runtimeSP->reference_hydrophobicityP == NULL) { ErrorMessage_ ("garlic", "InitRuntime_", "", "Failed to allocate memory", " for reference hydrophobicity values!\n", "", ""); return -28; } /* Initialize the zoom factor: */ runtimeSP->zoom_factor = 2; /* Initialize the sequence offsets. Some sequences */ /* are long, so they will not fit into main window. */ /* This may also happen if large zoom factor is used. */ runtimeSP->sequence_offset = 0; runtimeSP->reference_offset = 0; /* Initialize the segment width and the minimal */ /* score (used when comparing two sequences): */ runtimeSP->segment_width = SEGMENT_WIDTH; runtimeSP->minimal_score = MINIMAL_SCORE; /* Initialize the hydrophobicity scale index (default: Eisenberg scale, 2): */ runtimeSP->hydrophobicity_scaleI = 2; /* Initialize the helix step angle, in degrees: */ runtimeSP->helix_step_angle = 100.0; /* Initialize the arc (extent) angle, in degrees: */ runtimeSP->arc_angle = 10.0; /* Initialize the sphere radius: */ runtimeSP->sphere_radius = 8.0; /* Initialize the sliding window width: */ runtimeSP->sliding_window_width = 11; /* Initialize flags related to hydrophobicity functions: */ runtimeSP->average_hydrophobicityF = 0; runtimeSP->weighted_hydrophobicityF = 0; runtimeSP->hydrophobic_momentF = 0; runtimeSP->sided_hydrophobicityF = 0; runtimeSP->function1F = 0; runtimeSP->function2F = 0; runtimeSP->function3F = 0; runtimeSP->function4F = 0; runtimeSP->function5F = 0; runtimeSP->function6F = 0; runtimeSP->function7F = 0; /* Initialize range indices: */ runtimeSP->range_startI = 0; runtimeSP->range_endI = 0; /* Initialize docking area width and docking cell width: */ runtimeSP->docking_area_width = DOCKING_AREA_WIDTH; runtimeSP->docking_cell_width = DOCKING_CELL_WIDTH; /* Initialize the number of cells across */ /* docking area; this number must be even. */ d = DOCKING_AREA_WIDTH / DOCKING_CELL_WIDTH; width = (int) d; if (width % 2) width++; runtimeSP->docking_matrix_width = width; /* Allocate the storage for template atoms. These atoms will be */ /* used to create peptides, replace residues, insert residues etc. */ elementsN = MAXTEMPLATEATOMS; runtimeSP->template_atomSP = (AtomS *) calloc (elementsN, atom_struct_size); if (runtimeSP->template_atomSP == NULL) { ErrorMessage_ ("garlic", "InitRuntime_", "", "Failed to allocate memory for template atoms!\n", "", "", ""); runtimeSP->max_template_atomsN = 0; return -29; } else runtimeSP->max_template_atomsN = MAXTEMPLATEATOMS; /* Try to open the file residues.pdb, which should contain the */ /* residue templates . The first directory to be searched is */ /* the current working directory, the second is $HOME/garlic, */ /* the fourth is /usr/local/lib/garlic and the last directory */ /* to be searched for residues.pdb file is /usr/lib/garlic. */ if ((template_fileP = OpenTemplateFile_ ()) == NULL) { runtimeSP->template_atomsN = 0; runtimeSP->template_residuesN = 0; } /* Read the template file: */ else { ReadTemplateFile_ (runtimeSP, template_fileP, configSP); fclose (template_fileP); } /* Reset the blur flag: */ runtimeSP->blurF = 0; /* Initialize the size of blur rectangle: */ runtimeSP->blur_width = configSP->blur_default_width; runtimeSP->blur_height = configSP->blur_default_height; /* Allocate the storage for the array of beta cells on */ /* the surface of the auxiliary cylinder. This cylinder */ /* is used to find position and orientation of bilayer */ /* membrane with respect to the beta barel protein. */ runtimeSP->beta_cellsN = BETA_CELLS_ALONG_AXIS * BETA_CELLS_IN_RING; elementsN = runtimeSP->beta_cellsN; runtimeSP->beta_cellSP = (BetaCellS *) calloc (elementsN, beta_cell_size); if (runtimeSP->beta_cellSP == NULL) { ErrorMessage_ ("garlic", "InitRuntime_", "", "Failed to allocate memory for beta cells!\n", "", "", ""); return -30; } /* Return positive value on success: */ return 1; } /*===========================================================================*/ garlic-1.6/half_nice_bond.c0000644000076500007650000010620107572710662016201 0ustar zuciczucic00000000000000/* Copyright (C) 2002 Damir Zucic */ /*============================================================================= half_nice_bond.c Purpose: Draw half of a nice bond. Nice bond is a curved bond, constructed by using three spheres (two atoms and one probe). Input: (1) Pointer to Aux2S structure, which contains required data. (2) Bond index. Output: (1) Half of a nice bond drawn. (2) Return value. Return value: (1) Positive on success. (2) Negative on failure. Notes: (1) Read the file nice_bonds.c, related drawings and mathematical formulas are there. (2) The special case (alpha2 > PI/2) requires careful treatment. (3) The bond is drawn circle by circle. Only one half of each circle is drawn, because it is assumed that another side of the circle is invisible to the observer. The rear side of the bond is not drawn! (4) Two different factors (nominator_x and nominator_y) are used to project the circle center, but only one (nominator_x) to calculate the offset of the point at the surface. This has to be done like that because two factors were used to project the atoms, while only one factor (x) was used to prepare the projection of the atomic radius when using some spacefill style to draw atoms. (5) Indentation is exceptionally 4 spaces. =============================================================================*/ #include #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ double AbsoluteValue_ (VectorS *); double ScalarProduct_ (VectorS *, VectorS *); void VectorProduct_ (VectorS *, VectorS *, VectorS *); unsigned long SpacefillColor_ (AtomS *, GUIS *, double); unsigned long Sp2Color_ (AtomS *, GUIS *, double); unsigned long WeightColors_ (unsigned long, unsigned long, double, GUIS *); /*======draw half of a nice bond:============================================*/ int HalfNiceBond_ (Aux2S *aux2SP, int bondI) { static int imageI; static int image_center_screen_x, image_center_screen_y; static int left_edge, right_edge, bottom_edge; static double screen_atomic_z; static double nominator_x, nominator_y; static RawAtomS *raw_atom1SP, *raw_atom2SP; static double user_screen_atomic_distance; static double atomic_to_screen_scale; static double user_atomic_position; static VectorS *light_vectorSP; static double delta_x, delta_y, delta_z, rho; static double angle, cos_angle, sin_angle; static int atom1_styleI, atom2_styleI; static double r1, r2, r3; static AtomS *far_atomSP; static double far_radius, far_z; static double denominator, reciprocal_denominator; static double pixel_atomic_size; static double r13, r23, d0; static double cos_alpha1, alpha1, sin_alpha1; static double cos_alpha2; static double u0min, u0max, v0max; static double a0, rho0; static double scale_factor; static VectorS start0_vectorS, end0_vectorS; static double linear_increment, double_linear_increment; static double angular_increment; static double reciprocal_delta_u0; static double delta_a0_u0, root_argument; static VectorS unit_vector0S, unit_vector1S, unit_vector2S; static VectorS aux_vector0S, aux_vector1S; static double abs_value, reciprocal_abs_value; static double u0, v0; static double circle_x0, circle_y0, circle_z0; static double projection_factor_x, projection_factor_y; static double rationalized_x, rationalized_y; static int circle_screen_x0, circle_screen_y0; static double r13_1, r13_2; static double probe_offset_x, probe_offset_y, probe_offset_z; static double probe_x, probe_y, probe_z; static double surface_offset_1, surface_offset_2; static double surface_offset_x, surface_offset_y, surface_offset_z; static double surface_x, surface_y, surface_z; static int surface_screen_x, surface_screen_y; static size_t pixelI; static NearestAtomS *curr_pixelSP; static int drawF; static double shifted_z; static VectorS normal_vectorS; static double normal_abs_value; static double scalar_product; static double cos_light_angle; static unsigned long colorID, aux_color1ID, aux_color2ID, aux_color3ID; static int localI; static int pixel_screen_x, pixel_screen_y; static int pixel_shift_xA[4] = { 0, 1, 0, 1}; static int pixel_shift_yA[4] = { 0, 0, 1, 1}; static int octantI; static double pi_over_eight; static int pixel_shift_x, pixel_shift_y; static int local_pixelsN; static unsigned long colorIDA[5]; /*---------------------------------------------------------------------------*/ /* Copy some data and prepare some parameters. */ /* Image index: */ imageI = aux2SP->imageI; /* Image center, in screen units: */ image_center_screen_x = aux2SP->configSP->center_screen_x[imageI]; image_center_screen_y = aux2SP->configSP->center_screen_y; /* Bounding rectangle: */ left_edge = aux2SP->configSP->image_screen_x0[imageI]; right_edge = aux2SP->configSP->image_screen_x1[imageI]; bottom_edge = (int) aux2SP->guiSP->main_win_free_area_height; /* Screen position, in atomic units: */ screen_atomic_z = aux2SP->configSP->screen_atomic_z; /* Prepare two factors which are required for scaling: */ nominator_x = aux2SP->configSP->user_screen_atomic_distance * aux2SP->configSP->atomic_to_screen_scale_x; nominator_y = aux2SP->configSP->user_screen_atomic_distance * aux2SP->configSP->atomic_to_screen_scale_y; /* Pointers to raw atomic data: */ raw_atom1SP = &aux2SP->atom1SP->raw_atomS; raw_atom2SP = &aux2SP->atom2SP->raw_atomS; /* Both atoms should be on the opposite side of */ /* the screen, with respect to the observer: */ if (raw_atom1SP->z[imageI] < screen_atomic_z) return -1; if (raw_atom2SP->z[imageI] < screen_atomic_z) return -2; /* Distance between user and screen, in atomic units: */ user_screen_atomic_distance = aux2SP->configSP->user_screen_atomic_distance; /* The scale factor required for conversion from atomic to */ /* screen units. There are originally two such factors. Use */ /* the larger one here because it goes to denominator. */ if (aux2SP->configSP->atomic_to_screen_scale_x > aux2SP->configSP->atomic_to_screen_scale_y) { atomic_to_screen_scale = aux2SP->configSP->atomic_to_screen_scale_x; } else atomic_to_screen_scale = aux2SP->configSP->atomic_to_screen_scale_y; /* User position in atomic units: */ user_atomic_position = aux2SP->configSP->user_atomic_position; /* Pointer to the light source vector: */ light_vectorSP = &aux2SP->configSP->light_vectorS; /*---------------------------------------------------------------------------*/ /* Copy and check the atomic radii. Two atoms forming the bond */ /* should be drawn using some sort of spacefill drawing style. */ /* Radius of the first atom (the current bond belongs to this atom): */ atom1_styleI = raw_atom1SP->atom_styleI; if ((atom1_styleI == SPACEFILL) || (atom1_styleI == SPACEFILL2)) { r1 = raw_atom1SP->radius; } else if ((atom1_styleI == COVALENT) || (atom1_styleI == COVALENT2)) { r1 = raw_atom1SP->covalent_radius; } else if ((atom1_styleI == SMALL_ATOM) || (atom1_styleI == SMALL_ATOM2)) { r1 = raw_atom1SP->small_radius; } else if ((atom1_styleI == BIG_SPHERE) || (atom1_styleI == BIG_SPHERE2)) { r1 = raw_atom1SP->van_der_Waals_radius; } else return -3; /* Radius of the second atom (the bond partner of the first atom): */ atom2_styleI = raw_atom2SP->atom_styleI; if ((atom2_styleI == SPACEFILL) || (atom2_styleI == SPACEFILL2)) { r2 = raw_atom2SP->radius; } else if ((atom2_styleI == COVALENT) || (atom2_styleI == COVALENT2)) { r2 = raw_atom2SP->covalent_radius; } else if ((atom2_styleI == SMALL_ATOM) || (atom2_styleI == SMALL_ATOM2)) { r2 = raw_atom2SP->small_radius; } else if ((atom2_styleI == BIG_SPHERE) || (atom2_styleI == BIG_SPHERE2)) { r2 = raw_atom2SP->van_der_Waals_radius; } else return -4; /* The probe radius should be larger than zero: */ r3 = aux2SP->bond_probe_radius; if (r3 <= 0.001) return -5; /*---------------------------------------------------------------------------*/ /* Now estimate the size (in atomic units) of the pixel which */ /* represents the most distant point. This point belongs to */ /* the atom (i.e. sphere) which is farther from the observer. */ /* The atom with higher z value is treated as the farther one. */ /* Find which atom has higher z value (in most cases, but */ /* not always, this atom is farther from the observer): */ if (raw_atom2SP->z[imageI] > raw_atom1SP->z[imageI]) { far_atomSP = aux2SP->atom2SP; far_radius = r2; } else { far_atomSP = aux2SP->atom1SP; far_radius = r1; } /* Find the z coordinate of the most distant point: */ far_z = far_atomSP->raw_atomS.z[imageI] + far_radius; /* Check is this point on the opposite side of */ /* the screen, with respect to the observer. */ /* If it is, the entire bond will be invisible. */ if (far_z < screen_atomic_z) return -6; /* Prepare denominator required to calculate */ /* the atomic size of the most distant pixel: */ denominator = user_screen_atomic_distance * atomic_to_screen_scale; if (denominator <= 0.001) return -7; /* The size of the most distant pixel in atomic units: */ pixel_atomic_size = 1.0 * (far_z - user_atomic_position) / denominator; /*---------------------------------------------------------------------------*/ /* Calculate and check some geometric parameters */ /* (check definitions in the file nice_bonds.c). */ /* Relative distances: */ r13 = r1 + r3; if (r13 <= 0.001) return -8; r23 = r2 + r3; d0 = aux2SP->curr_bondSP->bond_length; if (d0 <= 0.001) return -9; /* Prepare and carefuly check the angle alpha1: */ cos_alpha1 = (r13 * r13 + d0 * d0 - r23 * r23) / (2 * d0 * r13); if (cos_alpha1 <= 0.001) return -10; else if (cos_alpha1 < -0.999) return -11; else if (cos_alpha1 > 0.999) return -12; if (cos_alpha1 <= -0.999) alpha1 = 3.1415927; else if (cos_alpha1 == 0.999) alpha1 = 0.0; else alpha1 = acos (cos_alpha1); sin_alpha1 = sin (alpha1); /* Cosine of the angle alpha2, required to */ /* handle the special case (alpha2 > PI/2): */ cos_alpha2 = (r23 * r23 + d0 * d0 - r13 * r13) / (2 * d0 * r23); /* The remaining ranges and distances: */ u0min = r1 * cos_alpha1; if (cos_alpha2 > 0.0) u0max = r13 * cos_alpha1; else u0max = d0 - r2 * cos_alpha2; v0max = r1 * sin_alpha1; a0 = r13 * cos_alpha1; rho0 = r13 * sin_alpha1; /*---------------------------------------------------------------------------*/ /* Find the start point and the end point, which define the bond axis. */ /* Distance between two atoms which form the bond (three components): */ delta_x = raw_atom2SP->x[imageI] - raw_atom1SP->x[imageI]; delta_y = raw_atom2SP->y - raw_atom1SP->y; delta_z = raw_atom2SP->z[imageI] - raw_atom1SP->z[imageI]; /* Prepare the start point: */ scale_factor = u0min / d0; start0_vectorS.x = raw_atom1SP->x[imageI] + scale_factor * delta_x; start0_vectorS.y = raw_atom1SP->y + scale_factor * delta_y; start0_vectorS.z = raw_atom1SP->z[imageI] + scale_factor * delta_z; /* Prepare the end point: */ scale_factor = u0max / d0; end0_vectorS.x = raw_atom1SP->x[imageI] + scale_factor * delta_x; end0_vectorS.y = raw_atom1SP->y + scale_factor * delta_y; end0_vectorS.z = raw_atom1SP->z[imageI] + scale_factor * delta_z; /* Both points should be on the opposite side */ /* of the screen, with respect to the observer: */ if (start0_vectorS.z < screen_atomic_z) return -13; if ( end0_vectorS.z < screen_atomic_z) return -14; /*---------------------------------------------------------------------------*/ /* Prepare three unit vectors, required for angular scan. These */ /* three vectors define the plane, required to define the circle. */ /* Prepare the unit vector pointing from the start point to the end point: */ unit_vector0S.x = end0_vectorS.x - start0_vectorS.x; unit_vector0S.y = end0_vectorS.y - start0_vectorS.y; unit_vector0S.z = end0_vectorS.z - start0_vectorS.z; abs_value = AbsoluteValue_ (&unit_vector0S); if (abs_value <= 0.001) return -15; reciprocal_abs_value = 1.0 / abs_value; unit_vector0S.x *= reciprocal_abs_value; unit_vector0S.y *= reciprocal_abs_value; unit_vector0S.z *= reciprocal_abs_value; /* Prepare the unit vector parallel to z axis: */ aux_vector0S.x = 0.0; aux_vector0S.y = 0.0; aux_vector0S.z = 1.0; /* Check the absolute value of the vector product between unit_vector0S */ /* and aux_vector0S; if the absolute value is too small, use aux_vector0S */ /* perpendicular to z axis (the vector parallel to x axis will be good): */ VectorProduct_ (&aux_vector1S, &unit_vector0S, &aux_vector0S); abs_value = AbsoluteValue_ (&aux_vector1S); if (abs_value < 0.001) { aux_vector0S.x = 1.0; aux_vector0S.y = 0.0; aux_vector0S.z = 0.0; } /* Prepare the unit vector perpendicular to unit_vector0S */ /* and to z axis. This is the first vector required to */ /* define the plane, which is used to define the circle. */ VectorProduct_ (&unit_vector1S, &unit_vector0S, &aux_vector0S); abs_value = AbsoluteValue_ (&unit_vector1S); reciprocal_abs_value = 1.0 / abs_value; unit_vector1S.x *= reciprocal_abs_value; unit_vector1S.y *= reciprocal_abs_value; unit_vector1S.z *= reciprocal_abs_value; /* Prepare the second unit vector required to define the plane: */ VectorProduct_ (&unit_vector2S, &unit_vector0S, &unit_vector1S); /*---------------------------------------------------------------------------*/ /* Prepare the linear increment. This variable should be used as */ /* the maximal translational step, to prevent holes in the surface. */ /* The linear increment should be smaller than pixel size: */ linear_increment = 0.70 * pixel_atomic_size; double_linear_increment = 2.0 * linear_increment; /* Check the distance between the start point and end point. */ /* The curved surface will be drawn only if this distance is */ /* at least three times larger than the linear increment. */ if (u0max - u0min < 3.0 * linear_increment) return -16; /*---------------------------------------------------------------------------*/ /* Prepare the angular increment. This variable should be used as */ /* the maximal angular step, to prevent holes in the surface. */ /* Calculate the angular increment, in radians: */ if (v0max <= 0.001) return -17; angular_increment = 0.70 * linear_increment / v0max; /* Be sure that the angular increment is not larger than PI/4: */ if (angular_increment > 0.78539816) angular_increment = 0.78539816; /*---------------------------------------------------------------------------*/ /* Draw half of the bond. */ /* Prepare some factors which are used to */ /* reduce the number of multiplications: */ delta_x = end0_vectorS.x - start0_vectorS.x; delta_y = end0_vectorS.y - start0_vectorS.y; delta_z = end0_vectorS.z - start0_vectorS.z; reciprocal_delta_u0 = 1.0 / (u0max - u0min); /* Loop which scans the variable u0 (see nice_bonds.c for definition): */ for (u0 = u0min - double_linear_increment; u0 <= u0max; u0 += linear_increment) { /* Calculate and check v0: */ if (u0 < 0.0) v0 = v0max; else { delta_a0_u0 = a0 - u0; root_argument = r3 * r3 - delta_a0_u0 * delta_a0_u0; if (root_argument <= 0.000001) continue; v0 = rho0 - sqrt (root_argument); if (v0 <= 0.001) continue; } /* Reduce v0 slightly, to ensure better connection with the atom: */ if (v0 > v0max) v0 = v0max; v0 -= pixel_atomic_size; if (v0 < 0.001) v0 = 0.0; /* Calculate the position of the point on the axis, */ /* defined by u0. This point is the circle center. */ scale_factor = (u0 - u0min) * reciprocal_delta_u0; circle_x0 = start0_vectorS.x + delta_x * scale_factor; circle_y0 = start0_vectorS.y + delta_y * scale_factor; circle_z0 = start0_vectorS.z + delta_z * scale_factor; /* Prepare the reciprocal denominator, used to */ /* reduce the number of mathematical operations: */ denominator = circle_z0 - user_atomic_position; if (denominator <= 0.001) continue; reciprocal_denominator = 1.0 / denominator; /* Prepare two factors required for projection: */ projection_factor_x = nominator_x * reciprocal_denominator; projection_factor_y = nominator_y * reciprocal_denominator; /* Project the position of the circle center. Note that */ /* two different projection factors are used here! */ rationalized_x = circle_x0 * projection_factor_x; rationalized_y = circle_y0 * projection_factor_y; circle_screen_x0 = (int) rationalized_x + image_center_screen_x; circle_screen_y0 = (int) rationalized_y + image_center_screen_y; /* The angular loop, required to create the rotational surface: */ for (angle = 0.0; angle <= 6.2831853; angle += angular_increment) { /* Cosine and sine of the angle: */ cos_angle = cos (angle); sin_angle = sin (angle); /* Calculate the relative position of the probe */ /* center with respect to the center of the */ /* first atom. Note that a0 is the parallel */ /* component of r13 with respect to the u0 axis */ /* and rho0 is the perpendicular component. */ r13_1 = rho0 * cos_angle; r13_2 = rho0 * sin_angle; probe_offset_x = a0 * unit_vector0S.x + r13_1 * unit_vector1S.x + r13_2 * unit_vector2S.x; probe_offset_y = a0 * unit_vector0S.y + r13_1 * unit_vector1S.y + r13_2 * unit_vector2S.y; probe_offset_z = a0 * unit_vector0S.z + r13_1 * unit_vector1S.z + r13_2 * unit_vector2S.z; /* Calculate the absolute position of the probe sphere: */ probe_x = raw_atom1SP->x[imageI] + probe_offset_x; probe_y = raw_atom1SP->y + probe_offset_y; probe_z = raw_atom1SP->z[imageI] + probe_offset_z; /* Relative position of the point at the */ /* surface with respect to the circle center: */ surface_offset_1 = v0 * cos_angle; surface_offset_2 = v0 * sin_angle; surface_offset_x = surface_offset_1 * unit_vector1S.x + surface_offset_2 * unit_vector2S.x; surface_offset_y = surface_offset_1 * unit_vector1S.y + surface_offset_2 * unit_vector2S.y; surface_offset_z = surface_offset_1 * unit_vector1S.z + surface_offset_2 * unit_vector2S.z; /* Calculate the coordinates of the point at bond surface: */ surface_x = circle_x0 + surface_offset_x; surface_y = circle_y0 + surface_offset_y; surface_z = circle_z0 + surface_offset_z; /* The vector from the point at the surface */ /* to the center of the spherical probe: */ normal_vectorS.x = probe_x - surface_x; normal_vectorS.y = probe_y - surface_y; normal_vectorS.z = probe_z - surface_z; /* If this vector has a positive z component, */ /* do not draw this point because it is not on */ /* the side which is visible for the observer: */ if (normal_vectorS.z >= 0.0) continue; /* Calculate the absolute value of this vector: */ normal_abs_value = AbsoluteValue_ (&normal_vectorS); /* Project the relative position of surface point. Note */ /* that projection_factor_x is used in both equations! */ rationalized_x = surface_offset_x * projection_factor_x; rationalized_y = surface_offset_y * projection_factor_x; /* Combine the projection of the circle */ /* center and projection of the relative */ /* position of the point at the surface: */ surface_screen_x = (int) rationalized_x + circle_screen_x0; surface_screen_y = (int) rationalized_y + circle_screen_y0; /* Prepare the color. */ /* The scalar product between the normal */ /* vector and the light source vector: */ scalar_product = ScalarProduct_ (&normal_vectorS, light_vectorSP); /* Cosine of the angle between the normal */ /* vector and the light source unit vector: */ if (normal_abs_value <= 0.001) cos_light_angle = 0.0; else cos_light_angle = scalar_product / normal_abs_value; /* Prepare color: */ switch (atom1_styleI) { case SPACEFILL: case COVALENT: case SMALL_ATOM: case BIG_SPHERE: colorID = SpacefillColor_ (aux2SP->atom1SP, aux2SP->guiSP, cos_light_angle); break; case SPACEFILL2: case COVALENT2: case SMALL_ATOM2: case BIG_SPHERE2: colorID = Sp2Color_ (aux2SP->atom1SP, aux2SP->guiSP, cos_light_angle); break; default: colorID = aux2SP->guiSP->white_colorID; } /* Set color to GC: */ XSetForeground (aux2SP->guiSP->displaySP, aux2SP->guiSP->theGCA[0], colorID); /* Draw four pixels: */ for (localI = 0; localI < 4; localI++) { /* Prepare and check the pixel position: */ pixel_screen_x = surface_screen_x + pixel_shift_xA[localI]; pixel_screen_y = surface_screen_y + pixel_shift_yA[localI]; if (pixel_screen_x < 0) continue; if (pixel_screen_x < left_edge) continue; if (pixel_screen_x >= right_edge) continue; if (pixel_screen_y < 0) continue; if (pixel_screen_y >= bottom_edge) continue; /* Prepare and check the index for the */ /* array of NearestAtomS structures: */ pixelI = aux2SP->guiSP->main_win_free_area_width * pixel_screen_y + pixel_screen_x; if (pixelI >= aux2SP->pixelsN) continue; /* Pointer to NearestAtomS struct. */ /* assigned to the current pixel: */ curr_pixelSP = aux2SP->nearest_atomSP + pixelI; /*------------------------------------------------------------*/ /* There are three cases when this pixel should be drawn: */ /* (1) Nothing was drawn to this pixel in this drawing step. */ /* (2) Drawing was done but the point at the bond surface is */ /* closer to the observer than the point drawn before. */ /* (3) Drawing was done and the point at the bond surface is */ /* more distant than the point drawn before. However, the */ /* pixel belongs to the atom to which this bond belongs */ /* and the z coordinate of the point at the bond surface */ /* is just slightly larger than the stored z value. */ /*------------------------------------------------------------*/ /* Assume initially that drawing is not necessary: */ drawF = 0; /* Check for the cases when drawing is necessary: */ do { /* Case (1) - no drawing was done before: */ if (aux2SP->refreshI != curr_pixelSP->last_refreshI) { drawF = 1; break; } /* If this point is reached, drawing was done before. */ /* Case (2): drawing was done before, but the point at the */ /* bond surface is closer than the point drawn before. */ if (surface_z < curr_pixelSP->z) { drawF = 1; break; } /* Now check the conditions for the case (3): */ /* The pixel should belong to the surface of the atom: */ if (curr_pixelSP->bondI != -1) break; /* The pixel should belong to the */ /* same atom and macromol. complex: */ if (curr_pixelSP->mol_complexI != aux2SP->mol_complexI) break; if (curr_pixelSP->atomI != aux2SP->atomI) break; /* If z is too large, no drawing will be done: */ shifted_z = curr_pixelSP->z + 2.0 * pixel_atomic_size; if (surface_z > shifted_z) break; /* Case (3): all conditions were satisfied. */ drawF = 1; /* End of inner single pass loop: */ } while (0); /* Check is drawing necessary at all: */ if (drawF == 0) continue; /* Draw the current pixel: */ XDrawPoint (aux2SP->guiSP->displaySP, aux2SP->guiSP->main_hidden_pixmapID, aux2SP->guiSP->theGCA[0], pixel_screen_x, pixel_screen_y); /* Refresh the NearestAtomS structure */ /* associated with the current pixel: */ curr_pixelSP->styleI = atom1_styleI; curr_pixelSP->last_refreshI = aux2SP->refreshI; curr_pixelSP->mol_complexI = aux2SP->mol_complexI; curr_pixelSP->atomI = aux2SP->atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = surface_z; curr_pixelSP->colorID = colorID; } } } /*---------------------------------------------------------------------------*/ /* Change the linear and the angular increment, before color smoothing. */ /* Reduce the linear increment: */ linear_increment *= 0.70; double_linear_increment = 2.0 * linear_increment; /* Reduce the angular increment: */ angular_increment *= 0.70; /*---------------------------------------------------------------------------*/ /* For most of the pixels, the original color will be replaced by the color */ /* calculated by averaging the colors of up to five neighboring pixels. */ /* Prepare some factors which are used to */ /* reduce the number of multiplications: */ delta_x = end0_vectorS.x - start0_vectorS.x; delta_y = end0_vectorS.y - start0_vectorS.y; delta_z = end0_vectorS.z - start0_vectorS.z; rho = sqrt (delta_x * delta_x + delta_y * delta_y); /* Identify the octant which contains this half of the bond: */ if (rho >= 0.001) { cos_angle = delta_x / rho; if (cos_angle <= -0.999) angle = 3.1415927; else if (cos_angle >= 0.999) angle = 0.0; else angle = acos (cos_angle); sin_angle = delta_y / rho; if (sin_angle < 0.0) angle = 6.2831853 - angle; pi_over_eight = 3.1415927 / 8.0; if (angle < 1.0 * pi_over_eight) octantI = 0; else if (angle < 3.0 * pi_over_eight) octantI = 1; else if (angle < 5.0 * pi_over_eight) octantI = 2; else if (angle < 7.0 * pi_over_eight) octantI = 3; else if (angle < 9.0 * pi_over_eight) octantI = 4; else if (angle < 11.0 * pi_over_eight) octantI = 5; else if (angle < 13.0 * pi_over_eight) octantI = 6; else if (angle < 15.0 * pi_over_eight) octantI = 7; else octantI = 0; } else octantI = 0; /* Prepare the shifts which define neighboring pixels: */ switch (octantI) { case 0: pixel_shift_x = -1; pixel_shift_y = 0; break; case 1: pixel_shift_x = -1; pixel_shift_y = -1; break; case 2: pixel_shift_x = 0; pixel_shift_y = -1; break; case 3: pixel_shift_x = 1; pixel_shift_y = -1; break; case 4: pixel_shift_x = 1; pixel_shift_y = 0; break; case 5: pixel_shift_x = 1; pixel_shift_y = 1; break; case 6: pixel_shift_x = 0; pixel_shift_y = 1; break; case 7: pixel_shift_x = -1; pixel_shift_y = 1; break; default: pixel_shift_x = 0; pixel_shift_y = 0; } for (u0 = u0min - double_linear_increment; u0 <= u0max; u0 += linear_increment) { /* Calculate and check v0: */ if (u0 < 0.0) v0 = v0max; else { delta_a0_u0 = a0 - u0; root_argument = r3 * r3 - delta_a0_u0 * delta_a0_u0; if (root_argument <= 0.000001) continue; v0 = rho0 - sqrt (root_argument); if (v0 <= 0.001) continue; } /* Reduce v0 slightly, to ensure better connection with the atom: */ if (v0 > v0max) v0 = v0max; v0 -= pixel_atomic_size; if (v0 <= 0.001) v0 = 0.0; /* Calculate the position of the point on the axis, */ /* defined by u0. This point is the circle center. */ scale_factor = (u0 - u0min) * reciprocal_delta_u0; circle_x0 = start0_vectorS.x + delta_x * scale_factor; circle_y0 = start0_vectorS.y + delta_y * scale_factor; circle_z0 = start0_vectorS.z + delta_z * scale_factor; /* Prepare the reciprocal denominator, used to */ /* reduce the number of mathematical operations: */ denominator = circle_z0 - user_atomic_position; if (denominator <= 0.001) continue; reciprocal_denominator = 1.0 / denominator; /* Prepare two factors required for projection: */ projection_factor_x = nominator_x * reciprocal_denominator; projection_factor_y = nominator_y * reciprocal_denominator; /* Project the position of the circle center. Note that */ /* two different projection factors are used here! */ rationalized_x = circle_x0 * projection_factor_x; rationalized_y = circle_y0 * projection_factor_y; circle_screen_x0 = (int) rationalized_x + image_center_screen_x; circle_screen_y0 = (int) rationalized_y + image_center_screen_y; /* The angular loop, required to create the rotational surface: */ for (angle = 0.0; angle <= 6.2831853; angle += angular_increment) { /* Cosine and sine of the angle: */ cos_angle = cos (angle); sin_angle = sin (angle); /* Calculate the relative position of the probe */ /* center with respect to the center of the */ /* first atom. Note that a0 is the parallel */ /* component of r13 with respect to the u0 axis */ /* and rho0 is the perpendicular component. */ r13_1 = rho0 * cos_angle; r13_2 = rho0 * sin_angle; probe_offset_x = a0 * unit_vector0S.x + r13_1 * unit_vector1S.x + r13_2 * unit_vector2S.x; probe_offset_y = a0 * unit_vector0S.y + r13_1 * unit_vector1S.y + r13_2 * unit_vector2S.y; probe_offset_z = a0 * unit_vector0S.z + r13_1 * unit_vector1S.z + r13_2 * unit_vector2S.z; /* Calculate the absolute position of the probe sphere: */ probe_x = raw_atom1SP->x[imageI] + probe_offset_x; probe_y = raw_atom1SP->y + probe_offset_y; probe_z = raw_atom1SP->z[imageI] + probe_offset_z; /* Relative position of the point at the */ /* surface with respect to the circle center: */ surface_offset_1 = v0 * cos_angle; surface_offset_2 = v0 * sin_angle; surface_offset_x = surface_offset_1 * unit_vector1S.x + surface_offset_2 * unit_vector2S.x; surface_offset_y = surface_offset_1 * unit_vector1S.y + surface_offset_2 * unit_vector2S.y; surface_offset_z = surface_offset_1 * unit_vector1S.z + surface_offset_2 * unit_vector2S.z; /* Calculate the coordinates of the point at bond surface: */ surface_x = circle_x0 + surface_offset_x; surface_y = circle_y0 + surface_offset_y; surface_z = circle_z0 + surface_offset_z; /* The vector from the point at the surface */ /* to the center of the spherical probe: */ normal_vectorS.x = probe_x - surface_x; normal_vectorS.y = probe_y - surface_y; normal_vectorS.z = probe_z - surface_z; /* If this vector has a positive z component, do */ /* not redraw this point because it is not on */ /* the side which is visible for the observer: */ if (normal_vectorS.z > 0.0) continue; /* Project the relative position of surface point. Note */ /* that projection_factor_x is used in both equations! */ rationalized_x = surface_offset_x * projection_factor_x; rationalized_y = surface_offset_y * projection_factor_x; /* Combine the projection of the circle */ /* center and projection of the relative */ /* position of the point at the surface: */ surface_screen_x = (int) rationalized_x + circle_screen_x0; surface_screen_y = (int) rationalized_y + circle_screen_y0; /* Prepare the screen coordinates of the current pixel: */ pixel_screen_x = surface_screen_x; pixel_screen_y = surface_screen_y; /* Prepare and check the index for the */ /* array of NearestAtomS structures: */ pixelI = aux2SP->guiSP->main_win_free_area_width * pixel_screen_y + pixel_screen_x; if (pixelI >= aux2SP->pixelsN) continue; /* Pointer to NearestAtomS struct. */ /* assigned to the current pixel: */ curr_pixelSP = aux2SP->nearest_atomSP + pixelI; /* Check is this pixel visible at all: */ if (surface_z > curr_pixelSP->z + 0.1 * pixel_atomic_size) continue; /* Reset the counter which says how many */ /* pixels should be taken into account: */ local_pixelsN = 0; /* Retrieve up to five colors of neighboring pixels: */ for (localI = -2; localI <= 2; localI++) { /* Very close to the atom the colors of atomic pixels */ /* should contribute more to ensure better connection: */ if (localI < 0) { if (u0 <= u0min + double_linear_increment) continue; } /* Pixel coordinates in screen units: */ pixel_screen_x = surface_screen_x + localI * pixel_shift_x; pixel_screen_y = surface_screen_y + localI * pixel_shift_y; if (pixel_screen_x < 0) continue; if (pixel_screen_x < left_edge) continue; if (pixel_screen_x >= right_edge) continue; if (pixel_screen_y < 0) continue; if (pixel_screen_y >= bottom_edge) continue; /* Prepare and check the index for the */ /* array of NearestAtomS structures: */ pixelI = aux2SP->guiSP->main_win_free_area_width * pixel_screen_y + pixel_screen_x; if (pixelI >= aux2SP->pixelsN) continue; /* Pointer to NearestAtomS struct. */ /* assigned to the current pixel: */ curr_pixelSP = aux2SP->nearest_atomSP + pixelI; /* If nothing was drawn to this pixel in this step, skip it: */ if (aux2SP->refreshI != curr_pixelSP->last_refreshI) continue; /* The pixel should belong to the */ /* same atom and macromol. complex: */ if (curr_pixelSP->mol_complexI != aux2SP->mol_complexI) continue; if (curr_pixelSP->atomI != aux2SP->atomI) continue; /* If this point is reached, copy the color of this pixel. */ colorIDA[local_pixelsN] = curr_pixelSP->colorID; /* Update the counter which says how many */ /* pixels should be taken into account: */ local_pixelsN++; } /* Replace the original color of the current pixel with the color */ /* calculated by averaging the colors of three neighboring pixels: */ if (local_pixelsN == 0) { continue; } else if (local_pixelsN == 1) { colorID = colorIDA[0]; } else if (local_pixelsN == 2) { colorID = WeightColors_ (colorIDA[0], colorIDA[1], 0.5, aux2SP->guiSP); } else if (local_pixelsN == 3) { aux_color1ID = WeightColors_ (colorIDA[0], colorIDA[1], 0.5, aux2SP->guiSP); colorID = WeightColors_ (aux_color1ID, colorIDA[2], 0.33333, aux2SP->guiSP); } else if (local_pixelsN == 4) { aux_color1ID = WeightColors_ (colorIDA[0], colorIDA[1], 0.5, aux2SP->guiSP); aux_color2ID = WeightColors_ (colorIDA[2], colorIDA[3], 0.5, aux2SP->guiSP); colorID = WeightColors_ (aux_color1ID, aux_color2ID, 0.5, aux2SP->guiSP); } else if (local_pixelsN == 5) { aux_color1ID = WeightColors_ (colorIDA[0], colorIDA[1], 0.5, aux2SP->guiSP); aux_color2ID = WeightColors_ (colorIDA[2], colorIDA[3], 0.5, aux2SP->guiSP); aux_color3ID = WeightColors_ (aux_color1ID, aux_color2ID, 0.5, aux2SP->guiSP); colorID = WeightColors_ (aux_color3ID, colorIDA[4], 0.2, aux2SP->guiSP); } else continue; /* Set color to GC: */ XSetForeground (aux2SP->guiSP->displaySP, aux2SP->guiSP->theGCA[0], colorID); /* Prepare and check the position of the first pixel: */ pixel_screen_x = surface_screen_x; pixel_screen_y = surface_screen_y; if (pixel_screen_x < 0) continue; if (pixel_screen_x < left_edge) continue; if (pixel_screen_x >= right_edge) continue; if (pixel_screen_y < 0) continue; if (pixel_screen_y >= bottom_edge) continue; /* Prepare and check the index for the */ /* array of NearestAtomS structures: */ pixelI = aux2SP->guiSP->main_win_free_area_width * pixel_screen_y + pixel_screen_x; if (pixelI >= aux2SP->pixelsN) continue; /* Pointer to NearestAtomS struct. */ /* assigned to the current pixel: */ curr_pixelSP = aux2SP->nearest_atomSP + pixelI; /* Redraw the current pixel: */ XDrawPoint (aux2SP->guiSP->displaySP, aux2SP->guiSP->main_hidden_pixmapID, aux2SP->guiSP->theGCA[0], pixel_screen_x, pixel_screen_y); /* Refresh the colorID member of the NearestAtomS */ /* structure associated with the current pixel: */ curr_pixelSP->colorID = colorID; } } /*---------------------------------------------------------------------------*/ /* If this point is reached, the entire bond was drawn: */ return 1; } /*===========================================================================*/ garlic-1.6/system.xpm0000644000076500007650000000601407303426372015170 0ustar zuciczucic00000000000000/* XPM */ static char *system_xpm[] = { /* width height num_colors chars_per_pixel */ " 50 54 3 1", /* colors */ ". c white", "# c red", "a c black", /* pixels */ "##################################################", "##################################################", "#######.....######################################", "#####..aaaaa..####################################", "####.aaa...aaa.###################################", "###.aaa.###.aaa.##################################", "###.aaaa.#.aaaa.######################...#########", "##.aa.aaa.aaa.aa.######################.a...######", "##.a.#.aaaaa.#.a........................aaaa...###", "##.a.##.aaa.##.a.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...", "##.a.#.aaaaa.#.a........................aaaa...###", "##.aa.aaa.aaa.aa.######################.a...######", "###.aaaa.#.aaaa.######################...#########", "###.aaa.###.aaa.##################################", "####.aaa...aaa.###################################", "#####..aaaaa..####################################", "#######.....####.........#########...######...####", "########.a.#####.aaaaaaa.#########.aa.####.aa.####", "########.a.#####.a....aa.##########.aa.##.aa.#####", "########.a.#####...##.aa.###########.aa..aa.######", "########.a.#########.aa.#############.aaaa.#######", "########.a.########.aa.###############.aa.########", "########.a.#######.aa.###############.aaaa.#######", "########.a.######.aa.###############.aa..aa.######", "########.a.#####.aa.##...##########.aa.##.aa.#####", "########.a.#####.aa....a.#########.aa.####.aa.####", "########.a.#####.aaaaaaa.#########.a.######.a.####", "########.a.#####.........#########...######...####", "########.a.#######################################", "########.a.#######################################", "########.a.#######################################", "########.a.#######################################", "########.a.#######################################", "########.a.#######################################", "########.a.#######################################", "########.a.#######################################", "########.a.###...######...########################", "########.a.###.aa.####.aa.########################", "########.a.####.aa.##.aa.#########################", "########.a.#####.aa..aa.##########################", "########.a.######.aaaa.###########################", "########.a.#######.aa.############################", "######.#.a.#.#####.aa.############################", "######...a...#####.aa.############################", "######.aaaaa.#####.aa.############################", "#######.aaa.######.aa.############################", "#######.aaa.######.aa.############################", "#######.aaa.######....############################", "########.a.#######################################", "########.a.#######################################", "########.a.#######################################", "#########.########################################", "#########.########################################", "#########.########################################" }; garlic-1.6/select_element.c0000644000076500007650000001071507647334025016261 0ustar zuciczucic00000000000000/* Copyright (C) 2001-2003 Damir Zucic */ /*============================================================================= select_element.c Purpose: Try to interpret the selection string as the request to select the the specified chemical element. There are three selection modes: 0 = overwrite, 1 = restrict, 2 = expand the previous selection. This function expects that the second token in the command line is the keyword ELEMENT (short version is ELE). If it is not found, the function will return negative value. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. (3) The selection string. (4) Selection mode index (0 = overwr., 1 = restrict, 2 = expand). Output: (1) The flag selectedF will be equal to one for selected atoms and equal to zero for all other atoms. (2) Return value. Return value: (1) The number of selected atoms, if selection is done in this function. (2) Negative value on failure. Notes: (1) The standard chemical symbols should be used to specify the chemical elements. In addition to well known elements, two imaginary elements were added: jellium (J) and quarkonium (Q). Jellium is inert - it is never involved in chemical bonds. Quarkonium binds to neighboring atoms in the list of Q atoms, i.e. to quarkonium atoms which have adjacent atomic serial numbers. The actual distance between quarkonium atoms is not important. Quarkonium may be used for polygonal lines in 3D. J and Q were introduced to adapt garlic for visualization of medical data. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ char *ExtractToken_ (char *, int, char *, char *); /*======select the specified chemical element:===============================*/ long SelectElement_ (MolComplexS *mol_complexSP, int mol_complexesN, char *stringP, int selection_modeI) { long selected_atomsN = 0; char *remainderP; char tokenA[STRINGSIZE]; int mol_complexI; MolComplexS *curr_mol_complexSP; size_t atomsN, atomI; AtomS *curr_atomSP; char *P; char chemical_symbolA[20]; int elementF; /* Extract the first token and check it (look for substring ELE): */ remainderP = ExtractToken_ (tokenA, STRINGSIZE, stringP, " \t\n"); if (!strstr (tokenA, "ELE")) return (long) -1; /* Try to extract one more token (chemical symbol expected): */ remainderP = ExtractToken_ (tokenA, STRINGSIZE, remainderP, " \t\n"); if (!remainderP) return (long) -2; /* Check every macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check is the current macromolecular complex caught: */ if (curr_mol_complexSP->catchF == 0) continue; /* Number of atoms in a macromolecular complex: */ atomsN = curr_mol_complexSP->atomsN; /* Scan all atoms in the current complex: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Extract the chemical symbol of the current atom: */ P = curr_atomSP->raw_atomS.chemical_symbolA; remainderP = ExtractToken_ (chemical_symbolA, 20, P, " \t"); if (!remainderP) continue; /* Check the chemical symbol: */ elementF = 0; if (strcmp (chemical_symbolA, tokenA) == 0) elementF = 1; /* Set the selection flag for the current atom: */ switch (selection_modeI) { /* Overwrite the previous selection: */ case 0: curr_atomSP->selectedF = elementF; break; /* Restrict the previous selection: */ case 1: curr_atomSP->selectedF &= elementF; break; /* Expand the previous selection: */ case 2: curr_atomSP->selectedF |= elementF; break; default: ; } /* Check the selection flag; increase */ /* the count if flag is equal to one: */ if (curr_atomSP->selectedF) selected_atomsN++; } /* Update the position_changedF (some atoms may have bad color): */ curr_mol_complexSP->position_changedF = 1; } /* Return the number of selected atoms: */ return selected_atomsN; } /*===========================================================================*/ garlic-1.6/atoms_style1.c0000644000076500007650000001164707470714171015720 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2002 Damir Zucic */ /*============================================================================= atoms_style1.c Purpose: Draw atoms, using style 1 (a single dot per atom). Input: (1) Pointer to MolComplexS structure. (2) Number of macromolecular complexes. (3) Pointer to ConfigS structure, with configuration data. (4) Pointer to GUIS structure. (5) Pointer to NearestAtomS structure, with information about the atom occupying the given pixel. (6) The number of pixels in the main window free area. (7) The refreshI, used to check the NearestAtomS associated with a given pixel. Output: (1) Atoms drawn to the hidden pixmap. (2) Return value. Return value: (1) The number of atoms drawn. Notes: (1) Indentation is exceptionally 4 spaces. =============================================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======draw atoms using style 1 (dot):======================================*/ size_t DrawAtomsStyle1_ (MolComplexS *mol_complexSP, int mol_complexesN, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int refreshI) { size_t atoms_drawnN = 0; int imageI, imagesN; int left_edge[2], right_edge[2]; int mol_complexI; MolComplexS *curr_mol_complexSP; size_t atomsN, atomI; AtomS *curr_atomSP; int screen_x, screen_y; size_t pixelI; NearestAtomS *curr_pixelSP; double z; int bondI; /* Initialize the bond index. The negative value means that pixels */ /* filled in this function are not a part of some chemical bond. */ bondI = -1; /* Number of images: */ if (configSP->stereoF) imagesN = 2; else imagesN = 1; /* Left and right image edge (in stereo mode there are two images): */ left_edge[0] = configSP->image_screen_x0[0]; right_edge[0] = configSP->image_screen_x1[0]; left_edge[1] = configSP->image_screen_x0[1]; right_edge[1] = configSP->image_screen_x1[1]; /* Draw each macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Prepare and check the number of atoms: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Draw atoms which have the given style: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Check style: */ if (curr_atomSP->raw_atomS.atom_styleI != 1) continue; /* Check is atom hidden: */ if (curr_atomSP->hiddenF) continue; /* Check is atom inside slab: */ if (!curr_atomSP->inside_slabF) continue; /* Check is atom inside window: */ if (!curr_atomSP->inside_windowF) continue; /* Prepare the middle color (the only one used here): */ XSetForeground (guiSP->displaySP, guiSP->theGCA[0], curr_atomSP->middle_colorID); /* Draw one (mono) or two pixels (stereo): */ for (imageI = 0; imageI < imagesN; imageI++) { /* Single pass loop: */ do { /* Prepare the coordinates: */ screen_x = curr_atomSP->raw_atomS.screen_x[imageI]; screen_y = curr_atomSP->raw_atomS.screen_y; /* Check is this pixel inside the area reserved for the */ /* current image (there are two images in stereo mode): */ if (screen_x < left_edge[imageI]) break; if (screen_x >= right_edge[imageI]) break; /* Prepare index to the array */ /* of NearestAtomS structures: */ pixelI = guiSP->main_win_free_area_width * screen_y + screen_x; /* Check the pixel index: */ if (pixelI >= pixelsN) break; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = nearest_atomSP + pixelI; /* Current atom z: */ z = curr_atomSP->raw_atomS.z[imageI]; /* Check was this pixel used already in */ /* this drawing step; if it was, compare */ /* the z value of the current atom with z */ /* value previously stored to this pixel: */ if (refreshI == curr_pixelSP->last_refreshI) { if (z >= curr_pixelSP->z) break; } /* If all test were passed, draw the atom: */ XDrawPoint (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x, screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = 1; curr_pixelSP->last_refreshI = refreshI; curr_pixelSP->mol_complexI = mol_complexI; curr_pixelSP->atomI = atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = z; curr_pixelSP->colorID = curr_atomSP->middle_colorID; /* Update the counter: */ atoms_drawnN++; } while (0); } /* imageI loop */ } /* atomI loop */ } /* mol_complexI loop */ /* Return the number of atoms which were drawn: */ return atoms_drawnN; } /*===========================================================================*/ garlic-1.6/atoms_style2.c0000644000076500007650000003124007470714206015707 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2002 Damir Zucic */ /*============================================================================= atoms_style2.c Purpose: Draw atoms, using style 2 (3x3 cross). Input: (1) Pointer to MolComplexS structure. (2) Number of macromolecular complexes. (3) Pointer to ConfigS structure, with configuration data. (4) Pointer to GUIS structure. (5) Pointer to NearestAtomS structure, with information about the atom occupying the given pixel. (6) The number of pixels in the main window free area. (7) The refreshI, used to check the NearestAtomS associated with a given pixel. Output: (1) Atoms drawn to the hidden pixmap. (2) Return value. Return value: (1) The number of atoms drawn. Notes: (1) Indentation is exceptionally 4 spaces. =============================================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======draw atoms using style 2 (3x3 cross):================================*/ size_t DrawAtomsStyle2_ (MolComplexS *mol_complexSP, int mol_complexesN, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int refreshI) { size_t atoms_drawnN = 0; int imageI, imagesN; int left_edge[2], right_edge[2]; int mol_complexI; MolComplexS *curr_mol_complexSP; size_t atomsN, atomI; AtomS *curr_atomSP; int atom_drawnF; int screen_x, screen_y; size_t pixelI; NearestAtomS *curr_pixelSP; double z; int bondI; /* Initialize the bond index. The negative value means that pixels */ /* filled in this function are not a part of some chemical bond. */ bondI = -1; /* Number of images: */ if (configSP->stereoF) imagesN = 2; else imagesN = 1; /* Left and right image edge (in stereo mode there are two images): */ left_edge[0] = configSP->image_screen_x0[0]; right_edge[0] = configSP->image_screen_x1[0]; left_edge[1] = configSP->image_screen_x0[1]; right_edge[1] = configSP->image_screen_x1[1]; /* Draw each macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Prepare and check the number of atoms: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Draw atoms which have the given style: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Check style: */ if (curr_atomSP->raw_atomS.atom_styleI != 2) continue; /* Check is atom hidden: */ if (curr_atomSP->hiddenF) continue; /* Check is atom inside slab: */ if (!curr_atomSP->inside_slabF) continue; /* Check is atom inside window: */ if (!curr_atomSP->inside_windowF) continue; /* Reset the flag: */ atom_drawnF = 0; /*------pixels which are colored in "left" color:----------------------------*/ /* Prepare the color: */ XSetForeground (guiSP->displaySP, guiSP->theGCA[0], curr_atomSP->left_colorID); /*......pixel (-1,0).........................................................*/ /* Draw one (mono) or two pixels (stereo): */ for (imageI = 0; imageI < imagesN; imageI++) { /* Single pass loop: */ do { /* Prepare the coordinates: */ screen_x = curr_atomSP->raw_atomS.screen_x[imageI] - 1; screen_y = curr_atomSP->raw_atomS.screen_y; /* Check is this pixel inside the area reserved for the */ /* current image (there are two images in stereo mode): */ if (screen_x < left_edge[imageI]) break; if (screen_x >= right_edge[imageI]) break; /* Prepare index to the array */ /* of NearestAtomS structures: */ pixelI = guiSP->main_win_free_area_width * screen_y + screen_x; /* Check the pixel index: */ if (pixelI >= pixelsN) break; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = nearest_atomSP + pixelI; /* Current atom z: */ z = curr_atomSP->raw_atomS.z[imageI]; /* Check was this pixel used already in */ /* this drawing step; if it was, compare */ /* the z value of the current atom with z */ /* value previously stored to this pixel: */ if (refreshI == curr_pixelSP->last_refreshI) { if (z >= curr_pixelSP->z) break; } /* If all test were passed, draw the pixel: */ XDrawPoint (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x, screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = 2; curr_pixelSP->last_refreshI = refreshI; curr_pixelSP->mol_complexI = mol_complexI; curr_pixelSP->atomI = atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = z; curr_pixelSP->colorID = curr_atomSP->left_colorID; /* Set the flag: */ atom_drawnF = 1; } while (0); } /*......pixel (0,-1).........................................................*/ /* Draw one (mono) or two pixels (stereo): */ for (imageI = 0; imageI < imagesN; imageI++) { /* Single pass loop: */ do { /* Prepare the coordinates: */ screen_x = curr_atomSP->raw_atomS.screen_x[imageI]; screen_y = curr_atomSP->raw_atomS.screen_y - 1; /* Check is this pixel inside the area reserved for the */ /* current image (there are two images in stereo mode): */ if (screen_x < left_edge[imageI]) break; if (screen_x > right_edge[imageI]) break; /* Prepare index to the array */ /* of NearestAtomS structures: */ pixelI = guiSP->main_win_free_area_width * screen_y + screen_x; /* Check the pixel index: */ if (pixelI >= pixelsN) break; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = nearest_atomSP + pixelI; /* Current atom z: */ z = curr_atomSP->raw_atomS.z[imageI]; /* Check was this pixel used already in */ /* this drawing step; if it was, compare */ /* the z value of the current atom with z */ /* value previously stored to this pixel: */ if (refreshI == curr_pixelSP->last_refreshI) { if (z >= curr_pixelSP->z) break; } /* If all test were passed, draw the pixel: */ XDrawPoint (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x, screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = 2; curr_pixelSP->last_refreshI = refreshI; curr_pixelSP->mol_complexI = mol_complexI; curr_pixelSP->atomI = atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = z; curr_pixelSP->colorID = curr_atomSP->left_colorID; /* Set the flag: */ atom_drawnF = 1; } while (0); } /*------pixels which are colored in "middle" color:--------------------------*/ /* Prepare the color: */ XSetForeground (guiSP->displaySP, guiSP->theGCA[1], curr_atomSP->middle_colorID); /*......pixel (0,0)..........................................................*/ /* Draw one (mono) or two pixels (stereo): */ for (imageI = 0; imageI < imagesN; imageI++) { /* Single pass loop: */ do { /* Prepare the coordinates: */ screen_x = curr_atomSP->raw_atomS.screen_x[imageI]; screen_y = curr_atomSP->raw_atomS.screen_y; /* Check is this pixel inside the area reserved for the */ /* current image (there are two images in stereo mode): */ if (screen_x < left_edge[imageI]) break; if (screen_x > right_edge[imageI]) break; /* Prepare index to the array */ /* of NearestAtomS structures: */ pixelI = guiSP->main_win_free_area_width * screen_y + screen_x; /* Check the pixel index: */ if (pixelI >= pixelsN) break; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = nearest_atomSP + pixelI; /* Current atom z: */ z = curr_atomSP->raw_atomS.z[imageI]; /* Check was this pixel used already in */ /* this drawing step; if it was, compare */ /* the z value of the current atom with z */ /* value previously stored to this pixel: */ if (refreshI == curr_pixelSP->last_refreshI) { if (z >= curr_pixelSP->z) break; } /* If all test were passed, draw the pixel: */ XDrawPoint (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], screen_x, screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = 2; curr_pixelSP->last_refreshI = refreshI; curr_pixelSP->mol_complexI = mol_complexI; curr_pixelSP->atomI = atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = z; curr_pixelSP->colorID = curr_atomSP->middle_colorID; /* Set the flag: */ atom_drawnF = 1; } while (0); } /*------pixels which are colored in "right" color:---------------------------*/ /* Prepare the color: */ XSetForeground (guiSP->displaySP, guiSP->theGCA[2], curr_atomSP->right_colorID); /*......pixel (0,1)..........................................................*/ /* Draw one (mono) or two pixels (stereo): */ for (imageI = 0; imageI < imagesN; imageI++) { /* Single pass loop: */ do { /* Prepare the coordinates: */ screen_x = curr_atomSP->raw_atomS.screen_x[imageI]; screen_y = curr_atomSP->raw_atomS.screen_y + 1; /* Check is this pixel inside the area reserved for the */ /* current image (there are two images in stereo mode): */ if (screen_x < left_edge[imageI]) break; if (screen_x > right_edge[imageI]) break; /* Prepare index to the array */ /* of NearestAtomS structures: */ pixelI = guiSP->main_win_free_area_width * screen_y + screen_x; /* Check the pixel index: */ if (pixelI >= pixelsN) break; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = nearest_atomSP + pixelI; /* Current atom z: */ z = curr_atomSP->raw_atomS.z[imageI]; /* Check was this pixel used already in */ /* this drawing step; if it was, compare */ /* the z value of the current atom with z */ /* value previously stored to this pixel: */ if (refreshI == curr_pixelSP->last_refreshI) { if (z >= curr_pixelSP->z) break; } /* If all test were passed, draw the pixel: */ XDrawPoint (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], screen_x, screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = 2; curr_pixelSP->last_refreshI = refreshI; curr_pixelSP->mol_complexI = mol_complexI; curr_pixelSP->atomI = atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = z; curr_pixelSP->colorID = curr_atomSP->right_colorID; /* Set the flag: */ atom_drawnF = 1; } while (0); } /*......pixel (1,0)..........................................................*/ /* Draw one (mono) or two pixels (stereo): */ for (imageI = 0; imageI < imagesN; imageI++) { /* Single pass loop: */ do { /* Prepare the coordinates: */ screen_x = curr_atomSP->raw_atomS.screen_x[imageI] + 1; screen_y = curr_atomSP->raw_atomS.screen_y; /* Check is this pixel inside the area reserved for the */ /* current image (there are two images in stereo mode): */ if (screen_x < left_edge[imageI]) break; if (screen_x > right_edge[imageI]) break; /* Prepare index to the array */ /* of NearestAtomS structures: */ pixelI = guiSP->main_win_free_area_width * screen_y + screen_x; /* Check the pixel index: */ if (pixelI >= pixelsN) break; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = nearest_atomSP + pixelI; /* Current atom z: */ z = curr_atomSP->raw_atomS.z[imageI]; /* Check was this pixel used already in */ /* this drawing step; if it was, compare */ /* the z value of the current atom with z */ /* value previously stored to this pixel: */ if (refreshI == curr_pixelSP->last_refreshI) { if (z >= curr_pixelSP->z) break; } /* If all test were passed, draw the pixel: */ XDrawPoint (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], screen_x, screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = 2; curr_pixelSP->last_refreshI = refreshI; curr_pixelSP->mol_complexI = mol_complexI; curr_pixelSP->atomI = atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = z; curr_pixelSP->colorID = curr_atomSP->right_colorID; /* Set the flag: */ atom_drawnF = 1; } while (0); } /*---------------------------------------------------------------------------*/ /* Check is at least one pixel drawn; */ /* increase the counter if it is true: */ if (atom_drawnF != 0) atoms_drawnN++; } } return atoms_drawnN; } /*===========================================================================*/ garlic-1.6/atoms_style3.c0000644000076500007650000004743707470714240015725 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2002 Damir Zucic */ /*============================================================================= atoms_style3.c Purpose: Draw atoms, using style 3 (3x3 square). Input: (1) Pointer to MolComplexS structure. (2) Number of macromolecular complexes. (3) Pointer to ConfigS structure, with configuration data. (4) Pointer to GUIS structure. (5) Pointer to NearestAtomS structure, with information about the atom occupying the given pixel. (6) The number of pixels in the main window free area. (7) The refreshI, used to check the NearestAtomS associated with a given pixel. Output: (1) Atoms drawn to the hidden pixmap. (2) Return value. Return value: (1) The number of atoms drawn. Notes: (1) Indentation is exceptionally 4 spaces. =============================================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======draw atoms using style 3 (3x3 square):===============================*/ size_t DrawAtomsStyle3_ (MolComplexS *mol_complexSP, int mol_complexesN, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int refreshI) { size_t atoms_drawnN = 0; int imageI, imagesN; int left_edge[2], right_edge[2]; int mol_complexI; MolComplexS *curr_mol_complexSP; size_t atomsN, atomI; AtomS *curr_atomSP; int atom_drawnF; int screen_x, screen_y; size_t pixelI; NearestAtomS *curr_pixelSP; double z; int bondI; /* Initialize the bond index. The negative value means that pixels */ /* filled in this function are not a part of some chemical bond. */ bondI = -1; /* Number of images: */ if (configSP->stereoF) imagesN = 2; else imagesN = 1; /* Left and right image edge (in stereo mode there are two images): */ left_edge[0] = configSP->image_screen_x0[0]; right_edge[0] = configSP->image_screen_x1[0]; left_edge[1] = configSP->image_screen_x0[1]; right_edge[1] = configSP->image_screen_x1[1]; /* Draw each macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Prepare and check the number of atoms: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Draw atoms which have the given style: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Check style: */ if (curr_atomSP->raw_atomS.atom_styleI != 3) continue; /* Check is atom hidden: */ if (curr_atomSP->hiddenF) continue; /* Check is atom inside slab: */ if (!curr_atomSP->inside_slabF) continue; /* Check is atom inside window: */ if (!curr_atomSP->inside_windowF) continue; /* Reset the flag: */ atom_drawnF = 0; /*------pixels which are colored in "left" color:----------------------------*/ /* Prepare the color: */ XSetForeground (guiSP->displaySP, guiSP->theGCA[0], curr_atomSP->left_colorID); /*......pixel (-1,0).........................................................*/ /* Draw one (mono) or two pixels (stereo): */ for (imageI = 0; imageI < imagesN; imageI++) { /* Single pass loop: */ do { /* Prepare the coordinates: */ screen_x = curr_atomSP->raw_atomS.screen_x[imageI] - 1; screen_y = curr_atomSP->raw_atomS.screen_y; /* Check is this pixel inside the area reserved for the */ /* current image (there are two images in stereo mode): */ if (screen_x < left_edge[imageI]) break; if (screen_x >= right_edge[imageI]) break; /* Prepare index to the array */ /* of NearestAtomS structures: */ pixelI = guiSP->main_win_free_area_width * screen_y + screen_x; /* Check the pixel index: */ if (pixelI >= pixelsN) break; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = nearest_atomSP + pixelI; /* Current atom z: */ z = curr_atomSP->raw_atomS.z[imageI]; /* Check was this pixel used already in */ /* this drawing step; if it was, compare */ /* the z value of the current atom with z */ /* value previously stored to this pixel: */ if (refreshI == curr_pixelSP->last_refreshI) { if (z >= curr_pixelSP->z) break; } /* If all test were passed, draw the pixel: */ XDrawPoint (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x, screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = 3; curr_pixelSP->last_refreshI = refreshI; curr_pixelSP->mol_complexI = mol_complexI; curr_pixelSP->atomI = atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = z; curr_pixelSP->colorID = curr_atomSP->left_colorID; /* Set the flag: */ atom_drawnF = 1; } while (0); } /*......pixel (-1,-1)........................................................*/ /* Draw one (mono) or two pixels (stereo): */ for (imageI = 0; imageI < imagesN; imageI++) { /* Single pass loop: */ do { /* Prepare the coordinates: */ screen_x = curr_atomSP->raw_atomS.screen_x[imageI] - 1; screen_y = curr_atomSP->raw_atomS.screen_y - 1; /* Check is this pixel inside the area reserved for the */ /* current image (there are two images in stereo mode): */ if (screen_x < left_edge[imageI]) break; if (screen_x > right_edge[imageI]) break; /* Prepare index to the array */ /* of NearestAtomS structures: */ pixelI = guiSP->main_win_free_area_width * screen_y + screen_x; /* Check the pixel index: */ if (pixelI >= pixelsN) break; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = nearest_atomSP + pixelI; /* Current atom z: */ z = curr_atomSP->raw_atomS.z[imageI]; /* Check was this pixel used already in */ /* this drawing step; if it was, compare */ /* the z value of the current atom with z */ /* value previously stored to this pixel: */ if (refreshI == curr_pixelSP->last_refreshI) { if (z >= curr_pixelSP->z) break; } /* If all test were passed, draw the pixel: */ XDrawPoint (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x, screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = 3; curr_pixelSP->last_refreshI = refreshI; curr_pixelSP->mol_complexI = mol_complexI; curr_pixelSP->atomI = atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = z; curr_pixelSP->colorID = curr_atomSP->left_colorID; /* Set the flag: */ atom_drawnF = 1; } while (0); } /*......pixel (0,-1).........................................................*/ /* Draw one (mono) or two pixels (stereo): */ for (imageI = 0; imageI < imagesN; imageI++) { /* Single pass loop: */ do { /* Prepare the coordinates: */ screen_x = curr_atomSP->raw_atomS.screen_x[imageI]; screen_y = curr_atomSP->raw_atomS.screen_y - 1; /* Check is this pixel inside the area reserved for the */ /* current image (there are two images in stereo mode): */ if (screen_x < left_edge[imageI]) break; if (screen_x > right_edge[imageI]) break; /* Prepare index to the array */ /* of NearestAtomS structures: */ pixelI = guiSP->main_win_free_area_width * screen_y + screen_x; /* Check the pixel index: */ if (pixelI >= pixelsN) break; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = nearest_atomSP + pixelI; /* Current atom z: */ z = curr_atomSP->raw_atomS.z[imageI]; /* Check was this pixel used already in */ /* this drawing step; if it was, compare */ /* the z value of the current atom with z */ /* value previously stored to this pixel: */ if (refreshI == curr_pixelSP->last_refreshI) { if (z >= curr_pixelSP->z) break; } /* If all test were passed, draw the pixel: */ XDrawPoint (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x, screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = 3; curr_pixelSP->last_refreshI = refreshI; curr_pixelSP->mol_complexI = mol_complexI; curr_pixelSP->atomI = atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = z; curr_pixelSP->colorID = curr_atomSP->left_colorID; /* Set the flag: */ atom_drawnF = 1; } while (0); } /*------pixels which are colored in "middle" color:--------------------------*/ /* Prepare the color: */ XSetForeground (guiSP->displaySP, guiSP->theGCA[1], curr_atomSP->middle_colorID); /*......pixel (-1,1).........................................................*/ /* Draw one (mono) or two pixels (stereo): */ for (imageI = 0; imageI < imagesN; imageI++) { /* Single pass loop: */ do { /* Prepare the coordinates: */ screen_x = curr_atomSP->raw_atomS.screen_x[imageI] - 1; screen_y = curr_atomSP->raw_atomS.screen_y + 1; /* Check is this pixel inside the area reserved for the */ /* current image (there are two images in stereo mode): */ if (screen_x < left_edge[imageI]) break; if (screen_x > right_edge[imageI]) break; /* Prepare index to the array */ /* of NearestAtomS structures: */ pixelI = guiSP->main_win_free_area_width * screen_y + screen_x; /* Check the pixel index: */ if (pixelI >= pixelsN) break; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = nearest_atomSP + pixelI; /* Current atom z: */ z = curr_atomSP->raw_atomS.z[imageI]; /* Check was this pixel used already in */ /* this drawing step; if it was, compare */ /* the z value of the current atom with z */ /* value previously stored to this pixel: */ if (refreshI == curr_pixelSP->last_refreshI) { if (z >= curr_pixelSP->z) break; } /* If all test were passed, draw the pixel: */ XDrawPoint (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], screen_x, screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = 3; curr_pixelSP->last_refreshI = refreshI; curr_pixelSP->mol_complexI = mol_complexI; curr_pixelSP->atomI = atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = z; curr_pixelSP->colorID = curr_atomSP->middle_colorID; /* Set the flag: */ atom_drawnF = 1; } while (0); } /*......pixel (0,0)..........................................................*/ /* Draw one (mono) or two pixels (stereo): */ for (imageI = 0; imageI < imagesN; imageI++) { /* Single pass loop: */ do { /* Prepare the coordinates: */ screen_x = curr_atomSP->raw_atomS.screen_x[imageI]; screen_y = curr_atomSP->raw_atomS.screen_y; /* Check is this pixel inside the area reserved for the */ /* current image (there are two images in stereo mode): */ if (screen_x < left_edge[imageI]) break; if (screen_x > right_edge[imageI]) break; /* Prepare index to the array */ /* of NearestAtomS structures: */ pixelI = guiSP->main_win_free_area_width * screen_y + screen_x; /* Check the pixel index: */ if (pixelI >= pixelsN) break; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = nearest_atomSP + pixelI; /* Current atom z: */ z = curr_atomSP->raw_atomS.z[imageI]; /* Check was this pixel used already in */ /* this drawing step; if it was, compare */ /* the z value of the current atom with z */ /* value previously stored to this pixel: */ if (refreshI == curr_pixelSP->last_refreshI) { if (z >= curr_pixelSP->z) break; } /* If all test were passed, draw the pixel: */ XDrawPoint (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], screen_x, screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = 3; curr_pixelSP->last_refreshI = refreshI; curr_pixelSP->mol_complexI = mol_complexI; curr_pixelSP->atomI = atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = z; curr_pixelSP->colorID = curr_atomSP->middle_colorID; /* Set the flag: */ atom_drawnF = 1; } while (0); } /*......pixel (1,-1).........................................................*/ /* Draw one (mono) or two pixels (stereo): */ for (imageI = 0; imageI < imagesN; imageI++) { /* Single pass loop: */ do { /* Prepare the coordinates: */ screen_x = curr_atomSP->raw_atomS.screen_x[imageI] + 1; screen_y = curr_atomSP->raw_atomS.screen_y - 1; /* Check is this pixel inside the area reserved for the */ /* current image (there are two images in stereo mode): */ if (screen_x < left_edge[imageI]) break; if (screen_x > right_edge[imageI]) break; /* Prepare index to the array */ /* of NearestAtomS structures: */ pixelI = guiSP->main_win_free_area_width * screen_y + screen_x; /* Check the pixel index: */ if (pixelI >= pixelsN) break; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = nearest_atomSP + pixelI; /* Current atom z: */ z = curr_atomSP->raw_atomS.z[imageI]; /* Check was this pixel used already in */ /* this drawing step; if it was, compare */ /* the z value of the current atom with z */ /* value previously stored to this pixel: */ if (refreshI == curr_pixelSP->last_refreshI) { if (z >= curr_pixelSP->z) break; } /* If all test were passed, draw the pixel: */ XDrawPoint (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], screen_x, screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = 3; curr_pixelSP->last_refreshI = refreshI; curr_pixelSP->mol_complexI = mol_complexI; curr_pixelSP->atomI = atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = z; curr_pixelSP->colorID = curr_atomSP->middle_colorID; /* Set the flag: */ atom_drawnF = 1; } while (0); } /*------pixels which are colored in "right" color:---------------------------*/ /* Prepare the color: */ XSetForeground (guiSP->displaySP, guiSP->theGCA[2], curr_atomSP->right_colorID); /*......pixel (0,1)..........................................................*/ /* Draw one (mono) or two pixels (stereo): */ for (imageI = 0; imageI < imagesN; imageI++) { /* Single pass loop: */ do { /* Prepare the coordinates: */ screen_x = curr_atomSP->raw_atomS.screen_x[imageI]; screen_y = curr_atomSP->raw_atomS.screen_y + 1; /* Check is this pixel inside the area reserved for the */ /* current image (there are two images in stereo mode): */ if (screen_x < left_edge[imageI]) break; if (screen_x > right_edge[imageI]) break; /* Prepare index to the array */ /* of NearestAtomS structures: */ pixelI = guiSP->main_win_free_area_width * screen_y + screen_x; /* Check the pixel index: */ if (pixelI >= pixelsN) break; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = nearest_atomSP + pixelI; /* Current atom z: */ z = curr_atomSP->raw_atomS.z[imageI]; /* Check was this pixel used already in */ /* this drawing step; if it was, compare */ /* the z value of the current atom with z */ /* value previously stored to this pixel: */ if (refreshI == curr_pixelSP->last_refreshI) { if (z >= curr_pixelSP->z) break; } /* If all test were passed, draw the pixel: */ XDrawPoint (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], screen_x, screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = 3; curr_pixelSP->last_refreshI = refreshI; curr_pixelSP->mol_complexI = mol_complexI; curr_pixelSP->atomI = atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = z; curr_pixelSP->colorID = curr_atomSP->right_colorID; /* Set the flag: */ atom_drawnF = 1; } while (0); } /*......pixel (1,1)..........................................................*/ /* Draw one (mono) or two pixels (stereo): */ for (imageI = 0; imageI < imagesN; imageI++) { /* Single pass loop: */ do { /* Prepare the coordinates: */ screen_x = curr_atomSP->raw_atomS.screen_x[imageI] + 1; screen_y = curr_atomSP->raw_atomS.screen_y + 1; /* Check is this pixel inside the area reserved for the */ /* current image (there are two images in stereo mode): */ if (screen_x < left_edge[imageI]) break; if (screen_x > right_edge[imageI]) break; /* Prepare index to the array */ /* of NearestAtomS structures: */ pixelI = guiSP->main_win_free_area_width * screen_y + screen_x; /* Check the pixel index: */ if (pixelI >= pixelsN) break; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = nearest_atomSP + pixelI; /* Current atom z: */ z = curr_atomSP->raw_atomS.z[imageI]; /* Check was this pixel used already in */ /* this drawing step; if it was, compare */ /* the z value of the current atom with z */ /* value previously stored to this pixel: */ if (refreshI == curr_pixelSP->last_refreshI) { if (z >= curr_pixelSP->z) break; } /* If all test were passed, draw the pixel: */ XDrawPoint (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], screen_x, screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = 3; curr_pixelSP->last_refreshI = refreshI; curr_pixelSP->mol_complexI = mol_complexI; curr_pixelSP->atomI = atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = z; curr_pixelSP->colorID = curr_atomSP->right_colorID; /* Set the flag: */ atom_drawnF = 1; } while (0); } /*......pixel (1,0)..........................................................*/ /* Draw one (mono) or two pixels (stereo): */ for (imageI = 0; imageI < imagesN; imageI++) { /* Single pass loop: */ do { /* Prepare the coordinates: */ screen_x = curr_atomSP->raw_atomS.screen_x[imageI] + 1; screen_y = curr_atomSP->raw_atomS.screen_y; /* Check is this pixel inside the area reserved for the */ /* current image (there are two images in stereo mode): */ if (screen_x < left_edge[imageI]) break; if (screen_x > right_edge[imageI]) break; /* Prepare index to the array */ /* of NearestAtomS structures: */ pixelI = guiSP->main_win_free_area_width * screen_y + screen_x; /* Check the pixel index: */ if (pixelI >= pixelsN) break; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = nearest_atomSP + pixelI; /* Current atom z: */ z = curr_atomSP->raw_atomS.z[imageI]; /* Check was this pixel used already in */ /* this drawing step; if it was, compare */ /* the z value of the current atom with z */ /* value previously stored to this pixel: */ if (refreshI == curr_pixelSP->last_refreshI) { if (z >= curr_pixelSP->z) break; } /* If all test were passed, draw the pixel: */ XDrawPoint (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], screen_x, screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = 3; curr_pixelSP->last_refreshI = refreshI; curr_pixelSP->mol_complexI = mol_complexI; curr_pixelSP->atomI = atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = z; curr_pixelSP->colorID = curr_atomSP->right_colorID; /* Set the flag: */ atom_drawnF = 1; } while (0); } /*---------------------------------------------------------------------------*/ /* Check is at least one pixel drawn; */ /* increase the counter if it is true: */ if (atom_drawnF != 0) atoms_drawnN++; } } return atoms_drawnN; } /*===========================================================================*/ garlic-1.6/atoms_style4.c0000644000076500007650000001511607470714262015717 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2002 Damir Zucic */ /*============================================================================= atoms_style4.c Purpose: Draw atoms, using style 4 (5x5 circle). Input: (1) Pointer to MolComplexS structure. (2) Number of macromolecular complexes. (3) Pointer to ConfigS structure, with configuration data. (4) Pointer to GUIS structure. (5) Pointer to NearestAtomS structure, with information about the atom occupying the given pixel. (6) The number of pixels in the main window free area. (7) The refreshI, used to check the NearestAtomS associated with a given pixel. Output: (1) Atoms drawn to the hidden pixmap. (2) Return value. Return value: (1) The number of atoms drawn. Notes: (1) Indentation is exceptionally 4 spaces. (2) The second index of indexAA and circle_maskAA is treated as row index. This is somewhat unusual, but more practical in this function. =============================================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======draw atoms using style 4 (5x5 circle):===============================*/ size_t DrawAtomsStyle4_ (MolComplexS *mol_complexSP, int mol_complexesN, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int refreshI) { size_t atoms_drawnN = 0; int imageI, imagesN; int left_edge[2], right_edge[2]; int mol_complexI; MolComplexS *curr_mol_complexSP; size_t atomsN, atomI; AtomS *curr_atomSP; unsigned long colorIDA[3]; static int indexAA[5][5] = {{0, 1, 1, 2, 0}, {1, 0, 0, 1, 2}, /* Be sure to read Note 2 ! */ {1, 0, 0, 1, 2}, {2, 1, 1, 2, 2}, {0, 2, 2, 2, 0}}; int atom_drawnF; int screen_x0, screen_y0; int i, j, screen_x, screen_y; static int circle_maskAA[5][5] = {{0, 1, 1, 1, 0}, {1, 1, 1, 1, 1}, /* Be sure to read Note 2 ! */ {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {0, 1, 1, 1, 0}}; size_t pixelI; NearestAtomS *curr_pixelSP; double z; double atomic_radius; static int levelAA[5][5] = {{0, 0, 0, 0, 0}, {0, 1, 1, 1, 0}, {0, 1, 1, 1, 0}, {0, 1, 1, 1, 0}, {0, 0, 0, 0, 0}}; int bondI; /* Initialize the bond index. The negative value means that pixels */ /* filled in this function are not a part of any chemical bond. */ bondI = -1; /* Number of images: */ if (configSP->stereoF) imagesN = 2; else imagesN = 1; /* Left and right image edge (in stereo mode there are two images): */ left_edge[0] = configSP->image_screen_x0[0]; right_edge[0] = configSP->image_screen_x1[0]; left_edge[1] = configSP->image_screen_x0[1]; right_edge[1] = configSP->image_screen_x1[1]; /* Atomic radius: */ atomic_radius = 3.0 * configSP->screen_to_atomic_scale_x; /* Draw each macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Prepare and check the number of atoms: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Draw atoms which have the given style: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Check style: */ if (curr_atomSP->raw_atomS.atom_styleI != 4) continue; /* Check is atom hidden: */ if (curr_atomSP->hiddenF) continue; /* Check is atom inside slab: */ if (!curr_atomSP->inside_slabF) continue; /* Check is atom inside window: */ if (!curr_atomSP->inside_windowF) continue; /* Prepare colors: */ colorIDA[0] = curr_atomSP->left_colorID; colorIDA[1] = curr_atomSP->middle_colorID; colorIDA[2] = curr_atomSP->right_colorID; /* Set these colors as foreground colors in three auxiliary GC's: */ XSetForeground (guiSP->displaySP, guiSP->theGCA[0], colorIDA[0]); XSetForeground (guiSP->displaySP, guiSP->theGCA[1], colorIDA[1]); XSetForeground (guiSP->displaySP, guiSP->theGCA[2], colorIDA[2]); /* Reset the flag: */ atom_drawnF = 0; /* Draw one (mono) or two pixels (stereo): */ for (imageI = 0; imageI < imagesN; imageI++) { /* Prepare the coordinates and 5x5 box edge indices: */ screen_x0 = curr_atomSP->raw_atomS.screen_x[imageI]; screen_y0 = curr_atomSP->raw_atomS.screen_y; /* Horizontal scan of the neighbourhood: */ for (i = 0; i < 5; i++) { /* Vertical scan of the neighbourhood: */ for (j = 0; j < 5; j++) { /* Single pass loop: */ do { /* Current pixel coordinates: */ screen_x = screen_x0 + i - 2; screen_y = screen_y0 + j - 2; /* Check is the pixel inside the area */ /* reserved for the current image (in */ /* stereo mode there are two images): */ if (screen_x < left_edge[imageI]) break; if (screen_x >= right_edge[imageI]) break; /* Check the circle mask: */ if (circle_maskAA[j][i] == 0) break; /* Prepare index to the array */ /* of NearestAtomS structures: */ pixelI = guiSP->main_win_free_area_width * screen_y + screen_x; /* Check the pixel index: */ if (pixelI >= pixelsN) break; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = nearest_atomSP + pixelI; /* Current atom z: */ z = curr_atomSP->raw_atomS.z[imageI] + atomic_radius * (double) levelAA[j][i]; /* Check was this pixel used already in */ /* this drawing step; if it was, compare */ /* the z value of the current atom with z */ /* value previously stored to this pixel: */ if (refreshI == curr_pixelSP->last_refreshI) { if (z >= curr_pixelSP->z) break; } /* Draw the pixel: */ XDrawPoint (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[indexAA[j][i]], screen_x, screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = 4; curr_pixelSP->last_refreshI = refreshI; curr_pixelSP->mol_complexI = mol_complexI; curr_pixelSP->atomI = atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = z; curr_pixelSP->colorID = colorIDA[indexAA[j][i]]; /* Set the flag: */ atom_drawnF = 1; } while (0); } } } /*---------------------------------------------------------------------------*/ /* Check is at least one pixel drawn; */ /* increase the counter if it is true: */ if (atom_drawnF != 0) atoms_drawnN++; } } return atoms_drawnN; } /*===========================================================================*/ garlic-1.6/atoms_style5.c0000644000076500007650000001554407470714300015716 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2002 Damir Zucic */ /*============================================================================= atoms_style5.c Purpose: Draw atoms, using style 5 (7x7 circle). Input: (1) Pointer to MolComplexS structure. (2) Number of macromolecular complexes. (3) Pointer to ConfigS structure, with configuration data. (4) Pointer to GUIS structure. (5) Pointer to NearestAtomS structure, with information about the atom occupying the given pixel. (6) The number of pixels in the main window free area. (7) The refreshI, used to check the NearestAtomS associated with a given pixel. Output: (1) Atoms drawn to the hidden pixmap. (2) Return value. Return value: (1) The number of atoms drawn. Notes: (1) Indentation is exceptionally 4 spaces. (2) The second index of indexAA and circle_maskAA is treated as row index. This is somewhat unusual, but more practical in this function. =============================================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======draw atoms using style 5 (7x7 circle):===============================*/ size_t DrawAtomsStyle5_ (MolComplexS *mol_complexSP, int mol_complexesN, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int refreshI) { size_t atoms_drawnN = 0; int imageI, imagesN; int left_edge[2], right_edge[2]; int mol_complexI; MolComplexS *curr_mol_complexSP; size_t atomsN, atomI; AtomS *curr_atomSP; unsigned long colorIDA[3]; static int indexAA[7][7] = {{0, 0, 1, 1, 2, 0, 0}, {0, 0, 0, 0, 1, 2, 0}, {1, 0, 0, 0, 1, 2, 2}, /* Be sure to read Note 2 ! */ {1, 0, 0, 1, 1, 2, 2}, {2, 1, 1, 1, 2, 2, 2}, {0, 2, 2, 2, 2, 2, 0}, {0, 0, 2, 2, 2, 0, 0}}; int atom_drawnF; int screen_x0, screen_y0; int i, j, screen_x, screen_y; static int circle_maskAA[7][7] = {{0, 0, 1, 1, 1, 0, 0}, {0, 1, 1, 1, 1, 1, 0}, {1, 1, 1, 1, 1, 1, 1}, /* Be sure to read Note 2 ! */ {1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 1}, {0, 1, 1, 1, 1, 1, 0}, {0, 0, 1, 1, 1, 0, 0}}; size_t pixelI; NearestAtomS *curr_pixelSP; double z; double half_atomic_radius; static int levelAA[7][7] = {{0, 0, 0, 0, 0, 0, 0}, {0, 0, 1, 1, 1, 0, 0}, {0, 1, 2, 2, 2, 1, 0}, {0, 1, 2, 2, 2, 1, 0}, {0, 1, 2, 2, 2, 1, 0}, {0, 0, 1, 1, 1, 0, 0}, {0, 0, 0, 0, 0, 0, 0}}; int bondI; /* Initialize the bond index. The negative value means that pixels */ /* filled in this function are not a part of any chemical bond. */ bondI = -1; /* Number of images: */ if (configSP->stereoF) imagesN = 2; else imagesN = 1; /* Left and right image edge (in stereo mode there are two images): */ left_edge[0] = configSP->image_screen_x0[0]; right_edge[0] = configSP->image_screen_x1[0]; left_edge[1] = configSP->image_screen_x0[1]; right_edge[1] = configSP->image_screen_x1[1]; /* Atomic radius: */ half_atomic_radius = 2.5 * configSP->screen_to_atomic_scale_x; /* Draw each macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Prepare and check the number of atoms: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Draw atoms which have the given style: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Check style: */ if (curr_atomSP->raw_atomS.atom_styleI != 5) continue; /* Check is atom hidden: */ if (curr_atomSP->hiddenF) continue; /* Check is atom inside slab: */ if (!curr_atomSP->inside_slabF) continue; /* Check is atom inside window: */ if (!curr_atomSP->inside_windowF) continue; /* Prepare colors: */ colorIDA[0] = curr_atomSP->left_colorID; colorIDA[1] = curr_atomSP->middle_colorID; colorIDA[2] = curr_atomSP->right_colorID; /* Set these colors as foreground colors in three auxiliary GC's: */ XSetForeground (guiSP->displaySP, guiSP->theGCA[0], colorIDA[0]); XSetForeground (guiSP->displaySP, guiSP->theGCA[1], colorIDA[1]); XSetForeground (guiSP->displaySP, guiSP->theGCA[2], colorIDA[2]); /* Reset the flag: */ atom_drawnF = 0; /* Draw one (mono) or two pixels (stereo): */ for (imageI = 0; imageI < imagesN; imageI++) { /* Prepare the coordinates and 7x7 box edge indices: */ screen_x0 = curr_atomSP->raw_atomS.screen_x[imageI]; screen_y0 = curr_atomSP->raw_atomS.screen_y; /* Horizontal scan of the neighbourhood: */ for (i = 0; i < 7; i++) { /* Vertical scan of the neighbourhood: */ for (j = 0; j < 7; j++) { /* Single pass loop: */ do { /* Current pixel coordinates: */ screen_x = screen_x0 + i - 3; screen_y = screen_y0 + j - 3; /* Check is the pixel inside the area */ /* reserved for the current image (in */ /* stereo mode there are two images): */ if (screen_x < left_edge[imageI]) break; if (screen_x >= right_edge[imageI]) break; /* Check the circle mask: */ if (circle_maskAA[j][i] == 0) break; /* Prepare index to the array */ /* of NearestAtomS structures: */ pixelI = guiSP->main_win_free_area_width * screen_y + screen_x; /* Check the pixel index: */ if (pixelI >= pixelsN) break; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = nearest_atomSP + pixelI; /* Current atom z: */ z = curr_atomSP->raw_atomS.z[imageI] + half_atomic_radius * (double) levelAA[j][i]; /* Check was this pixel used already in */ /* this drawing step; if it was, compare */ /* the z value of the current atom with z */ /* value previously stored to this pixel: */ if (refreshI == curr_pixelSP->last_refreshI) { if (z >= curr_pixelSP->z) break; } /* Draw the pixel: */ XDrawPoint (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[indexAA[j][i]], screen_x, screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = 5; curr_pixelSP->last_refreshI = refreshI; curr_pixelSP->mol_complexI = mol_complexI; curr_pixelSP->atomI = atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = z; curr_pixelSP->colorID = colorIDA[indexAA[j][i]]; /* Set the flag: */ atom_drawnF = 1; } while (0); } } } /*---------------------------------------------------------------------------*/ /* Check is at least one pixel drawn; */ /* increase the counter if it is true: */ if (atom_drawnF != 0) atoms_drawnN++; } } return atoms_drawnN; } /*===========================================================================*/ garlic-1.6/atoms_style6.c0000644000076500007650000001626707470714315015730 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2002 Damir Zucic */ /*============================================================================= atoms_style6.c Purpose: Draw atoms, using style 6 (9x9 circle). Input: (1) Pointer to MolComplexS structure. (2) Number of macromolecular complexes. (3) Pointer to ConfigS structure, with configuration data. (4) Pointer to GUIS structure. (5) Pointer to NearestAtomS structure, with information about the atom occupying the given pixel. (6) The number of pixels in the main window free area. (7) The refreshI, used to check the NearestAtomS associated with a given pixel. Output: (1) Atoms drawn to the hidden pixmap. (2) Return value. Return value: (1) The number of atoms drawn. Notes: (1) Indentation is exceptionally 4 spaces. (2) The second index of indexAA and circle_maskAA is treated as row index. This is somewhat unusual, but more practical in this function. =============================================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======draw atoms using style 6 (9x9 circle):===============================*/ size_t DrawAtomsStyle6_ (MolComplexS *mol_complexSP, int mol_complexesN, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int refreshI) { size_t atoms_drawnN = 0; int imageI, imagesN; int left_edge[2], right_edge[2]; int mol_complexI; MolComplexS *curr_mol_complexSP; size_t atomsN, atomI; AtomS *curr_atomSP; unsigned long colorIDA[3]; static int indexAA[9][9] = {{0, 0, 0, 1, 1, 2, 0, 0, 0}, {0, 1, 0, 0, 1, 1, 2, 2, 0}, {0, 0, 0, 0, 0, 1, 1, 2, 0}, {1, 0, 0, 0, 0, 1, 1, 2, 2}, /* Be sure to read Note 2 ! */ {1, 1, 0, 0, 1, 1, 1, 2, 2}, {2, 1, 1, 1, 1, 1, 2, 2, 2}, {0, 2, 1, 1, 1, 2, 2, 2, 0}, {0, 2, 2, 2, 2, 2, 2, 2, 0}, {0, 0, 0, 2, 2, 2, 0, 0, 0}}; int atom_drawnF; int screen_x0, screen_y0; int i, j, screen_x, screen_y; static int circle_maskAA[9][9] = {{0, 0, 0, 1, 1, 1, 0, 0, 0}, {0, 1, 1, 1, 1, 1, 1, 1, 0}, {0, 1, 1, 1, 1, 1, 1, 1, 0}, {1, 1, 1, 1, 1, 1, 1, 1, 1}, /* Be sure to read Note 2 ! */ {1, 1, 1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 1, 1, 1}, {0, 1, 1, 1, 1, 1, 1, 1, 0}, {0, 1, 1, 1, 1, 1, 1, 1, 0}, {0, 0, 0, 1, 1, 1, 0, 0, 0}}; size_t pixelI; NearestAtomS *curr_pixelSP; double z; double third_atomic_radius; static int levelAA[9][9] = {{0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 1, 1, 1, 0, 0, 0}, {0, 0, 1, 2, 2, 2, 1, 0, 0}, {0, 1, 2, 3, 3, 3, 2, 1, 0}, {0, 1, 2, 3, 3, 3, 2, 1, 0}, {0, 1, 2, 3, 3, 3, 2, 1, 0}, {0, 0, 1, 2, 2, 2, 1, 0, 0}, {0, 0, 0, 1, 1, 1, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0}}; int bondI; /* Initialize the bond index. The negative value means that pixels */ /* filled in this function are not a part of any chemical bond. */ bondI = -1; /* Number of images: */ if (configSP->stereoF) imagesN = 2; else imagesN = 1; /* Left and right image edge (in stereo mode there are two images): */ left_edge[0] = configSP->image_screen_x0[0]; right_edge[0] = configSP->image_screen_x1[0]; left_edge[1] = configSP->image_screen_x0[1]; right_edge[1] = configSP->image_screen_x1[1]; /* Atomic radius: */ third_atomic_radius = 2.5 * configSP->screen_to_atomic_scale_x; /* Draw each macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Prepare and check the number of atoms: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Draw atoms which have the given style: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Check style: */ if (curr_atomSP->raw_atomS.atom_styleI != 6) continue; /* Check is atom hidden: */ if (curr_atomSP->hiddenF) continue; /* Check is atom inside slab: */ if (!curr_atomSP->inside_slabF) continue; /* Check is atom inside window: */ if (!curr_atomSP->inside_windowF) continue; /* Prepare colors: */ colorIDA[0] = curr_atomSP->left_colorID; colorIDA[1] = curr_atomSP->middle_colorID; colorIDA[2] = curr_atomSP->right_colorID; /* Set these colors as foreground colors in three auxiliary GC's: */ XSetForeground (guiSP->displaySP, guiSP->theGCA[0], colorIDA[0]); XSetForeground (guiSP->displaySP, guiSP->theGCA[1], colorIDA[1]); XSetForeground (guiSP->displaySP, guiSP->theGCA[2], colorIDA[2]); /* Reset the flag: */ atom_drawnF = 0; /* Draw one (mono) or two pixels (stereo): */ for (imageI = 0; imageI < imagesN; imageI++) { /* Prepare the coordinates and 9x9 box edge indices: */ screen_x0 = curr_atomSP->raw_atomS.screen_x[imageI]; screen_y0 = curr_atomSP->raw_atomS.screen_y; /* Horizontal scan of the neighbourhood: */ for (i = 0; i < 9; i++) { /* Vertical scan of the neighbourhood: */ for (j = 0; j < 9; j++) { /* Single pass loop: */ do { /* Current pixel coordinates: */ screen_x = screen_x0 + i - 4; screen_y = screen_y0 + j - 4; /* Check is the pixel inside the area */ /* reserved for the current image (in */ /* stereo mode there are two images): */ if (screen_x < left_edge[imageI]) break; if (screen_x >= right_edge[imageI]) break; /* Check the circle mask: */ if (circle_maskAA[j][i] == 0) break; /* Prepare index to the array */ /* of NearestAtomS structures: */ pixelI = guiSP->main_win_free_area_width * screen_y + screen_x; /* Check the pixel index: */ if (pixelI >= pixelsN) break; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = nearest_atomSP + pixelI; /* Current atom z: */ z = curr_atomSP->raw_atomS.z[imageI] + third_atomic_radius * (double) levelAA[j][i]; /* Check was this pixel used already in */ /* this drawing step; if it was, compare */ /* the z value of the current atom with z */ /* value previously stored to this pixel: */ if (refreshI == curr_pixelSP->last_refreshI) { if (z >= curr_pixelSP->z) break; } /* Draw the pixel: */ XDrawPoint (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[indexAA[j][i]], screen_x, screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = 6; curr_pixelSP->last_refreshI = refreshI; curr_pixelSP->mol_complexI = mol_complexI; curr_pixelSP->atomI = atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = z; curr_pixelSP->colorID = colorIDA[indexAA[j][i]]; /* Set the flag: */ atom_drawnF = 1; } while (0); } } } /*---------------------------------------------------------------------------*/ /* Check is at least one pixel drawn; */ /* increase the counter if it is true: */ if (atom_drawnF != 0) atoms_drawnN++; } } return atoms_drawnN; } /*===========================================================================*/ garlic-1.6/atoms_style7.c0000644000076500007650000001714707470714330015724 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2002 Damir Zucic */ /*============================================================================= atoms_style7.c Purpose: Draw atoms, using style 7 (11x11 circle). Input: (1) Pointer to MolComplexS structure. (2) Number of macromolecular complexes. (3) Pointer to ConfigS structure, with configuration data. (4) Pointer to GUIS structure. (5) Pointer to NearestAtomS structure, with information about the atom occupying the given pixel. (6) The number of pixels in the main window free area. (7) The refreshI, used to check the NearestAtomS associated with a given pixel. Output: (1) Atoms drawn to the hidden pixmap. (2) Return value. Return value: (1) The number of atoms drawn. Notes: (1) Indentation is exceptionally 4 spaces. (2) The second index of indexAA and circle_maskAA is treated as row index. This is somewhat unusual, but more practical in this function. =============================================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======draw atoms using style 7 (11x11 circle):=============================*/ size_t DrawAtomsStyle7_ (MolComplexS *mol_complexSP, int mol_complexesN, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int refreshI) { size_t atoms_drawnN = 0; int imageI, imagesN; int left_edge[2], right_edge[2]; int mol_complexI; MolComplexS *curr_mol_complexSP; size_t atomsN, atomI; AtomS *curr_atomSP; unsigned long colorIDA[3]; static int indexAA[11][11] = {{0, 0, 1, 1, 1, 1, 1, 2, 2, 0, 0}, {0, 1, 0, 0, 0, 0, 1, 1, 2, 2, 0}, {1, 0, 0, 0, 0, 0, 0, 1, 1, 2, 2}, {1, 0, 0, 0, 0, 0, 0, 1, 1, 2, 2}, /* Be sure to read Note 2 ! */ {1, 0, 0, 0, 0, 0, 0, 1, 1, 2, 2}, {1, 0, 0, 0, 0, 0, 0, 1, 1, 2, 2}, {1, 1, 0, 0, 0, 0, 1, 1, 1, 2, 2}, {2, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2}, {2, 2, 1, 1, 1, 1, 1, 2, 2, 2, 2}, {0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0}, {0, 0, 2, 2, 2, 2, 2, 2, 2, 0, 0}}; int atom_drawnF; int screen_x0, screen_y0; int i, j, screen_x, screen_y; static int circle_maskAA[11][11] = {{0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0}, {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, /* Be sure to read Note 2 ! */ {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0}, {0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0}}; size_t pixelI; NearestAtomS *curr_pixelSP; double z; double third_atomic_radius; static int levelAA[11][11] = {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0}, {0, 0, 1, 2, 2, 2, 2, 2, 1, 0, 0}, {0, 1, 2, 2, 3, 3, 3, 2, 2, 1, 0}, {0, 1, 2, 3, 3, 4, 3, 3, 2, 1, 0}, {0, 1, 2, 3, 4, 4, 4, 3, 2, 1, 0}, {0, 1, 2, 3, 3, 4, 3, 3, 2, 1, 0}, {0, 1, 2, 2, 3, 3, 3, 2, 2, 1, 0}, {0, 0, 1, 2, 2, 2, 2, 2, 1, 0, 0}, {0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}; int bondI; /* Initialize the bond index. The negative value means that pixels */ /* filled in this function are not a part of any chemical bond. */ bondI = -1; /* Number of images: */ if (configSP->stereoF) imagesN = 2; else imagesN = 1; /* Left and right image edge (in stereo mode there are two images): */ left_edge[0] = configSP->image_screen_x0[0]; right_edge[0] = configSP->image_screen_x1[0]; left_edge[1] = configSP->image_screen_x0[1]; right_edge[1] = configSP->image_screen_x1[1]; /* Atomic radius: */ third_atomic_radius = 2.5 * configSP->screen_to_atomic_scale_x; /* Draw each macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Prepare and check the number of atoms: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Draw atoms which have the given style: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Check style: */ if (curr_atomSP->raw_atomS.atom_styleI != 7) continue; /* Check is atom hidden: */ if (curr_atomSP->hiddenF) continue; /* Check is atom inside slab: */ if (!curr_atomSP->inside_slabF) continue; /* Check is atom inside window: */ if (!curr_atomSP->inside_windowF) continue; /* Prepare colors: */ colorIDA[0] = curr_atomSP->left_colorID; colorIDA[1] = curr_atomSP->middle_colorID; colorIDA[2] = curr_atomSP->right_colorID; /* Set these colors as foreground colors in three auxiliary GC's: */ XSetForeground (guiSP->displaySP, guiSP->theGCA[0], colorIDA[0]); XSetForeground (guiSP->displaySP, guiSP->theGCA[1], colorIDA[1]); XSetForeground (guiSP->displaySP, guiSP->theGCA[2], colorIDA[2]); /* Reset the flag: */ atom_drawnF = 0; /* Draw one (mono) or two pixels (stereo): */ for (imageI = 0; imageI < imagesN; imageI++) { /* Prepare the coordinates and 9x9 box edge indices: */ screen_x0 = curr_atomSP->raw_atomS.screen_x[imageI]; screen_y0 = curr_atomSP->raw_atomS.screen_y; /* Horizontal scan of the neighbourhood: */ for (i = 0; i < 11; i++) { /* Vertical scan of the neighbourhood: */ for (j = 0; j < 11; j++) { /* Single pass loop: */ do { /* Current pixel coordinates: */ screen_x = screen_x0 + i - 5; screen_y = screen_y0 + j - 5; /* Check is the pixel inside the area */ /* reserved for the current image (in */ /* stereo mode there are two images): */ if (screen_x < left_edge[imageI]) break; if (screen_x >= right_edge[imageI]) break; /* Check the circle mask: */ if (circle_maskAA[j][i] == 0) break; /* Prepare index to the array */ /* of NearestAtomS structures: */ pixelI = guiSP->main_win_free_area_width * screen_y + screen_x; /* Check the pixel index: */ if (pixelI >= pixelsN) break; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = nearest_atomSP + pixelI; /* Current atom z: */ z = curr_atomSP->raw_atomS.z[imageI] + third_atomic_radius * (double) levelAA[j][i]; /* Check was this pixel used already in */ /* this drawing step; if it was, compare */ /* the z value of the current atom with z */ /* value previously stored to this pixel: */ if (refreshI == curr_pixelSP->last_refreshI) { if (z >= curr_pixelSP->z) break; } /* Draw the pixel: */ XDrawPoint (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[indexAA[j][i]], screen_x, screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = 7; curr_pixelSP->last_refreshI = refreshI; curr_pixelSP->mol_complexI = mol_complexI; curr_pixelSP->atomI = atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = z; curr_pixelSP->colorID = colorIDA[indexAA[j][i]]; /* Set the flag: */ atom_drawnF = 1; } while (0); } } } /*---------------------------------------------------------------------------*/ /* Check is at least one pixel drawn; */ /* increase the counter if it is true: */ if (atom_drawnF != 0) atoms_drawnN++; } } return atoms_drawnN; } /*===========================================================================*/ garlic-1.6/half_sphere_fading.c0000644000076500007650000001455207066752153017065 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= half_sphere_fading.c Purpose: Prepare the left, middle and right color for each atom in a complex. The color fading is semi-spherical: two spherical surfaces and one plane are used. The plane is parallel to x-y plane; it is passing through the fading center. Input: (1) Pointer to MolComplexS structure. (2) Pointer to GUIS structure. Output: (1) left_colorID, middle_colorID and right_colorID members of AtomS structure initialized for each atom in macromolecular complex. (2) Return value. Return value: (1) On success, the number of atoms which have colors different from near and far color. These atoms are located in the area between the front and back surface. (2) Zero on failure. Notes: (1) Do not skip hidden atoms, the color of these atoms may be used for backbone drawing! =============================================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ unsigned long PixelFromRGBS_ (RGBS *, GUIS *); unsigned long PrepareColor_ (RGBS *, RGBS *, double, GUIS *); /*======semi-spherical fading:===============================================*/ size_t HalfSphereFading_ (MolComplexS *curr_mol_complexSP, GUIS *guiSP) { size_t atoms_between_surfacesN = 0; size_t atomsN, atomI; AtomS *curr_atomSP; int surfacesN, surfaceI, inner_surfaceI, outer_surfaceI; double r_out, r_out_squared, r_in, r_in_squared; double x0, y0, z0; double overall_range, internal_range; double inverse_internal_range; double x, y, z, r_squared, r, delta_r, scale_factor; int near_surfaceI, far_surfaceI; /* The radius of the front (outer) surface: */ r_out = curr_mol_complexSP->fading_front_relative_position; r_out_squared = r_out * r_out; /* The radius of the back (inner) surface: */ r_in = curr_mol_complexSP->fading_back_relative_position; r_in_squared = r_in * r_in; /* Check: */ if (r_in >= r_out) return 0; /* The overall range: */ overall_range = r_out - r_in; /* Fading center coordinates: */ x0 = curr_mol_complexSP->fading_center_vectorS.x; y0 = curr_mol_complexSP->fading_center_vectorS.y; z0 = curr_mol_complexSP->fading_center_vectorS.z; /* The number of atoms in a complex: */ atomsN = curr_mol_complexSP->atomsN; /* Assign three colors to each atom: */ for (atomI = 0; atomI < atomsN; atomI++) { /** Pointer to the current atom: **/ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /** Is atom out of slab? **/ if (!curr_atomSP->inside_slabF) continue; /** Check the number of color fading surfaces: **/ surfacesN = curr_atomSP->surfacesN; /*** If there is only one, there is no fading: ***/ if (surfacesN == 1) { curr_atomSP->left_colorID = PixelFromRGBS_ (curr_atomSP->left_rgbSA, guiSP); curr_atomSP->middle_colorID = PixelFromRGBS_ (curr_atomSP->middle_rgbSA, guiSP); curr_atomSP->right_colorID = PixelFromRGBS_ (curr_atomSP->right_rgbSA, guiSP); continue; } /** Atomic coordinates (relative to fading center): **/ x = curr_atomSP->raw_atomS.x[0] - x0; y = curr_atomSP->raw_atomS.y - y0; z = curr_atomSP->raw_atomS.z[0] - z0; /** Check is atom behind the plane; if it is, treat it as far atom: **/ if (z > 0.0) { surfaceI = surfacesN - 1; curr_atomSP->left_colorID = PixelFromRGBS_ (curr_atomSP->left_rgbSA + surfaceI, guiSP); curr_atomSP->middle_colorID = PixelFromRGBS_ (curr_atomSP->middle_rgbSA + surfaceI, guiSP); curr_atomSP->right_colorID = PixelFromRGBS_ (curr_atomSP->right_rgbSA + surfaceI, guiSP); continue; } /** Distance between the current atom and the fading center: **/ r_squared = x * x + y * y + z * z; /** Atoms which are too far from the fading **/ /** center should be treated as near atoms: **/ if (r_squared >= r_out_squared) { curr_atomSP->left_colorID = PixelFromRGBS_ (curr_atomSP->left_rgbSA, guiSP); curr_atomSP->middle_colorID = PixelFromRGBS_ (curr_atomSP->middle_rgbSA, guiSP); curr_atomSP->right_colorID = PixelFromRGBS_ (curr_atomSP->right_rgbSA, guiSP); continue; } /** Atoms which are to close to the fading **/ /** center should be treated as far atoms: **/ if (r_squared <= r_in_squared) { surfaceI = surfacesN - 1; curr_atomSP->left_colorID = PixelFromRGBS_ (curr_atomSP->left_rgbSA + surfaceI, guiSP); curr_atomSP->middle_colorID = PixelFromRGBS_ (curr_atomSP->middle_rgbSA + surfaceI, guiSP); curr_atomSP->right_colorID = PixelFromRGBS_ (curr_atomSP->right_rgbSA + surfaceI, guiSP); continue; } /** If this point is reached, current atom is in **/ /** the area between two surfaces; colors should **/ /** be calculated weighting near and far colors: **/ /** Prepare auxiliary variables: **/ if (surfacesN > 1) { r = sqrt (r_squared); internal_range = overall_range / (double) (surfacesN - 1); inverse_internal_range = 1.0 / internal_range; inner_surfaceI = (int) floor ((r - r_in) * inverse_internal_range); outer_surfaceI = inner_surfaceI + 1; delta_r = outer_surfaceI * internal_range + r_in - r; scale_factor = delta_r * inverse_internal_range; far_surfaceI = surfacesN - inner_surfaceI - 1; near_surfaceI = far_surfaceI - 1; } else { scale_factor = 0.0; far_surfaceI = 0; near_surfaceI = 0; } /** Left color: **/ curr_atomSP->left_colorID = PrepareColor_ (curr_atomSP->left_rgbSA + near_surfaceI, curr_atomSP->left_rgbSA + far_surfaceI, scale_factor, guiSP); /** Middle color: **/ curr_atomSP->middle_colorID = PrepareColor_ (curr_atomSP->middle_rgbSA + near_surfaceI, curr_atomSP->middle_rgbSA + far_surfaceI, scale_factor, guiSP); /** Right color: **/ curr_atomSP->right_colorID = PrepareColor_ (curr_atomSP->right_rgbSA + near_surfaceI, curr_atomSP->right_rgbSA + far_surfaceI, scale_factor, guiSP); /** Update the number of atoms in the area between two surfaces: **/ atoms_between_surfacesN++; } /* Return the number of atoms which have */ /* colors different from near and far colors: */ return atoms_between_surfacesN; } /*===========================================================================*/ garlic-1.6/count_template_res.c0000644000076500007650000000460307264302350017153 0ustar zuciczucic00000000000000/* Copyright (C) 2001 Damir Zucic */ /*============================================================================= count_template_res.c Purpose: Count the template residues. Input: (1) Pointer to RuntimeS structure, with template atoms. Output: (1) Return value. Return value: (1) The number of template residues (positive or zero). Notes: (1) The function which calls this function should check are there any atoms at all. Thus, there should be at least one atom. (2) Some hetero atoms may be counted as separate residues. This is typical for solvent molecules. ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======count template residues:=============================================*/ int CountTemplateResidues_ (RuntimeS *runtimeSP) { int template_residuesN = 0; int template_atomI, template_atomsN; RawAtomS *raw_atomSP; int previous_residueI = -9999, current_residueI; int previous_insertion_code = '\0', current_insertion_code; /* Prepare the number of template atoms: */ template_atomsN = runtimeSP->template_atomsN; /* Scan the template atoms: */ for (template_atomI = 0; template_atomI < template_atomsN; template_atomI++) { /* Pointer to raw atomic data: */ raw_atomSP = &(runtimeSP->template_atomSP + template_atomI)->raw_atomS; /* Copy the residue sequence number and residue insertion code: */ current_residueI = raw_atomSP->residue_sequenceI; current_insertion_code = raw_atomSP->residue_insertion_code; /* Compare the current residue sequence number with the old one */ /* and the current residue insertion code with the old code: */ if ((current_residueI == previous_residueI) && (current_insertion_code == previous_insertion_code)) continue; /* If this point is reached, the current sequence number */ /* is different from the previous one, or insertion codes */ /* are different. This means that a new residue is found: */ template_residuesN++; /* Update the residue sequence index and residue insertion code: */ previous_residueI = current_residueI; previous_insertion_code = current_insertion_code; } /* Return the number of residues: */ return template_residuesN; } /*===========================================================================*/ garlic-1.6/masks.txt0000644000076500007650000000316307014037451014772 0ustar zuciczucic00000000000000X.h:/* Input Event Masks. Used as event-mask window attribute and as arguments X.h:#define NoEventMask 0L X.h:#define KeyPressMask (1L<<0) X.h:#define KeyReleaseMask (1L<<1) X.h:#define ButtonPressMask (1L<<2) X.h:#define ButtonReleaseMask (1L<<3) X.h:#define EnterWindowMask (1L<<4) X.h:#define LeaveWindowMask (1L<<5) X.h:#define PointerMotionMask (1L<<6) X.h:#define PointerMotionHintMask (1L<<7) X.h:#define Button1MotionMask (1L<<8) X.h:#define Button2MotionMask (1L<<9) X.h:#define Button3MotionMask (1L<<10) X.h:#define Button4MotionMask (1L<<11) X.h:#define Button5MotionMask (1L<<12) X.h:#define ButtonMotionMask (1L<<13) X.h:#define KeymapStateMask (1L<<14) X.h:#define ExposureMask (1L<<15) X.h:#define VisibilityChangeMask (1L<<16) X.h:#define StructureNotifyMask (1L<<17) X.h:#define ResizeRedirectMask (1L<<18) X.h:#define SubstructureNotifyMask (1L<<19) X.h:#define SubstructureRedirectMask (1L<<20) X.h:#define FocusChangeMask (1L<<21) X.h:#define PropertyChangeMask (1L<<22) X.h:#define ColormapChangeMask (1L<<23) X.h:#define OwnerGrabButtonMask (1L<<24) X.h:#define ShiftMask (1<<0) X.h:#define LockMask (1<<1) X.h:#define ControlMask (1<<2) X.h:#define Mod1Mask (1<<3) X.h:#define Mod2Mask (1<<4) X.h:#define Mod3Mask (1<<5) X.h:#define Mod4Mask (1<<6) X.h:#define Mod5Mask (1<<7) X.h:#define Button1Mask (1<<8) X.h:#define Button2Mask (1<<9) X.h:#define Button3Mask (1<<10) X.h:#define Button4Mask (1<<11) X.h:#define Button5Mask (1<<12) X.h:#define CWEventMask (1L<<11) X.h:#define GCPlaneMask (1L<<1) X.h:#define GCClipMask (1L<<19) garlic-1.6/color_model.c0000644000076500007650000000624007461732103015556 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2002 Damir Zucic */ /*============================================================================= color_model.c Purpose: Model color scheme: assign different colors to different models. This should be useful with NMR structures. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. (3) Pointer to GUIS structure, with GUI data. (4) Pointer to ColorSchemeS structure. Output: (1) Return value. Return value: (1) Positive always. =============================================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======model color scheme:==================================================*/ int ColorModel_ (MolComplexS *mol_complexSP, int mol_complexesN, GUIS *guiSP, ColorSchemeS *color_schemeSP) { int mol_complexI; MolComplexS *curr_mol_complexSP; size_t atomsN, atomI; AtomS *curr_atomSP; size_t rgb_struct_size; ColorSchemeS *schemeSP; int surfaceI; int old_modelI = 0; int color_schemeI = -1; /* The size of RGBS structure: */ rgb_struct_size = sizeof (RGBS); /* Initialize the pointer to color scheme: */ schemeSP = color_schemeSP; /* Scan every macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check is the current macromolecular complex caught: */ if (curr_mol_complexSP->catchF == 0) continue; /* Number of atoms in a macromolecular complex: */ atomsN = curr_mol_complexSP->atomsN; /* Scan all atoms in the current complex: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Check is atom selected: */ if (curr_atomSP->selectedF == 0) continue; /* Set the number of color surfaces: */ curr_atomSP->surfacesN = 2; /* Check the model serial number: */ if (curr_atomSP->raw_atomS.model_serialI != old_modelI) { /* Store the model serial number: */ old_modelI = curr_atomSP->raw_atomS.model_serialI; /* Change color: */ color_schemeI++; /* Thirteen color schemes are used for models: */ if (color_schemeI >= 13) color_schemeI = 0; /* Prepare the color scheme pointer: */ schemeSP = color_schemeSP + color_schemeI; } /* Copy the color specifications: */ for (surfaceI = 0; surfaceI < 2; surfaceI++) { /* Left color: */ memcpy (curr_atomSP->left_rgbSA + surfaceI, schemeSP->left_rgbSA + surfaceI, rgb_struct_size); /* Middle color: */ memcpy (curr_atomSP->middle_rgbSA + surfaceI, schemeSP->middle_rgbSA + surfaceI, rgb_struct_size); /* Right color: */ memcpy (curr_atomSP->right_rgbSA + surfaceI, schemeSP->right_rgbSA + surfaceI, rgb_struct_size); } } /* Reset the position_changedF: */ curr_mol_complexSP->position_changedF = 1; } /* Return positive value: */ return 1; } /*===========================================================================*/ garlic-1.6/small_arrows.xpm0000644000076500007650000002406510157124147016353 0ustar zuciczucic00000000000000/* XPM */ static char * small_arrows_xpm[] = { /* width height num_colors chars_per_pixel */ " 32 280 5 1", /* colors */ ". c #FFFFFF", "+ c #000000", "@ c #0000CF", "# c #0000FF", "$ c #007FFF", /* pixels */ "................................", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++@@++++++++++++.", ".++++++++++++++++@@@+++++++++++.", ".++++++++++++++++@#@@++++++++++.", ".+++++@@@@@@@@@@@@##@@+++++++++.", ".+++++@@@@@@@@@@@@###@@++++++++.", ".+++++@@##############@@+++++++.", ".+++++@@###############@@++++++.", ".+++++@@################@$+++++.", ".+++++@@################$$+++++.", ".+++++@@###############$$++++++.", ".+++++@@##############$$+++++++.", ".+++++@$$$$$$$$$$@###$$++++++++.", ".+++++$$$$$$$$$$$@##$$+++++++++.", ".++++++++++++++++@#$$++++++++++.", ".++++++++++++++++@$$+++++++++++.", ".++++++++++++++++$$++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", "................................", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".+++++++++++@@+++++++++++++++++.", ".++++++++++@@@@++++++++++++++++.", ".+++++++++@@@@@@+++++++++++++++.", ".++++++++@@@##@@@++++++++++++++.", ".+++++++@@@####@@@+++++++++++++.", ".++++++@@@######@@@+++++@++++++.", ".+++++@@@########@@@+++@@++++++.", ".+++++$$$#########@@@+@@@++++++.", ".++++++$$$#########@@@@#@++++++.", ".+++++++$$$#########@@##@++++++.", ".++++++++$$$############@++++++.", ".+++++++++$$$###########@++++++.", ".++++++++++$$$##########@++++++.", ".+++++++++++$$$#########@++++++.", ".++++++++++++$$@########@++++++.", ".+++++++++++++@@########@++++++.", ".++++++++++++@@#########@++++++.", ".+++++++++++@@##########@++++++.", ".++++++++++$$$$$$$$$$$$$$++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", "................................", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++$@@@@@@@@@++++++++++.", ".++++++++++$$@@@@@@@@++++++++++.", ".++++++++++$$######@@++++++++++.", ".++++++++++$$######@@++++++++++.", ".++++++++++$$######@@++++++++++.", ".++++++++++$$######@@++++++++++.", ".++++++++++$$######@@++++++++++.", ".++++++++++$$######@@++++++++++.", ".++++++++++$$######@@++++++++++.", ".++++++++++$$######@@++++++++++.", ".++++++++++$$######@@++++++++++.", ".+++++++$@@@@######@@@@@+++++++.", ".+++++++$$############@@+++++++.", ".++++++++$$##########@@++++++++.", ".+++++++++$$########@@+++++++++.", ".++++++++++$$######@@++++++++++.", ".+++++++++++$$####@@+++++++++++.", ".++++++++++++$$##@@++++++++++++.", ".+++++++++++++$$@@+++++++++++++.", ".++++++++++++++$$++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", "................................", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".+++++++++++++++++$@+++++++++++.", ".++++++++++++++++$$@@++++++++++.", ".+++++++++++++++$$$@@@+++++++++.", ".++++++++++++++$$$##@@@++++++++.", ".+++++++++++++$$$####@@@+++++++.", ".++++++$+++++$$$######@@@++++++.", ".++++++$@+++$$$########@@@+++++.", ".++++++$@@+$$$#########@@@+++++.", ".++++++$#@@$$#########@@@++++++.", ".++++++$##@@#########@@@+++++++.", ".++++++$############@@@++++++++.", ".++++++$###########@@@+++++++++.", ".++++++$##########@@@++++++++++.", ".++++++$#########@@@+++++++++++.", ".++++++$########@@@++++++++++++.", ".++++++$########@@+++++++++++++.", ".++++++$#########@@++++++++++++.", ".++++++$##########@@+++++++++++.", ".++++++$@@@@@@@@@@@@@++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", "................................", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++$$++++++++++++++++.", ".+++++++++++$$@++++++++++++++++.", ".++++++++++$$#@++++++++++++++++.", ".+++++++++$$##@$$$$$$$$$$$+++++.", ".++++++++$$###@$$$$$$$$$$@+++++.", ".+++++++$$##############@@+++++.", ".++++++$$###############@@+++++.", ".+++++$$################@@+++++.", ".+++++$@################@@+++++.", ".++++++@@###############@@+++++.", ".+++++++@@##############@@+++++.", ".++++++++@@###@@@@@@@@@@@@+++++.", ".+++++++++@@##@@@@@@@@@@@@+++++.", ".++++++++++@@#@++++++++++++++++.", ".+++++++++++@@@++++++++++++++++.", ".++++++++++++@@++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", "................................", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++$$$$$$$$$$$$$$++++++++++.", ".++++++@##########@@+++++++++++.", ".++++++@#########@@++++++++++++.", ".++++++@########@@+++++++++++++.", ".++++++@########@$$++++++++++++.", ".++++++@#########$$$+++++++++++.", ".++++++@##########$$$++++++++++.", ".++++++@###########$$$+++++++++.", ".++++++@############$$$++++++++.", ".++++++@##@@#########$$$+++++++.", ".++++++@#@@@@#########$$$++++++.", ".++++++@@@+@@@#########$$$+++++.", ".++++++@@+++@@@########@@@+++++.", ".++++++@+++++@@@######@@@++++++.", ".+++++++++++++@@@####@@@+++++++.", ".++++++++++++++@@@##@@@++++++++.", ".+++++++++++++++@@@@@@+++++++++.", ".++++++++++++++++@@@@++++++++++.", ".+++++++++++++++++@@+++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", "................................", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++$$++++++++++++++.", ".+++++++++++++@@$$+++++++++++++.", ".++++++++++++@@##$$++++++++++++.", ".+++++++++++@@####$$+++++++++++.", ".++++++++++@@######$$++++++++++.", ".+++++++++@@########$$+++++++++.", ".++++++++@@##########$$++++++++.", ".+++++++@@############$$+++++++.", ".+++++++@@@@@######@@@@$+++++++.", ".++++++++++@@######$$++++++++++.", ".++++++++++@@######$$++++++++++.", ".++++++++++@@######$$++++++++++.", ".++++++++++@@######$$++++++++++.", ".++++++++++@@######$$++++++++++.", ".++++++++++@@######$$++++++++++.", ".++++++++++@@######$$++++++++++.", ".++++++++++@@######$$++++++++++.", ".++++++++++@@######$$++++++++++.", ".++++++++++@@@@@@@@$$++++++++++.", ".++++++++++@@@@@@@@@$++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", "................................", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++@@@@@@@@@@@@@$++++++.", ".+++++++++++@@##########$++++++.", ".++++++++++++@@#########$++++++.", ".+++++++++++++@@########$++++++.", ".++++++++++++@@@########$++++++.", ".+++++++++++@@@#########$++++++.", ".++++++++++@@@##########$++++++.", ".+++++++++@@@###########$++++++.", ".++++++++@@@############$++++++.", ".+++++++@@@#########@@##$++++++.", ".++++++@@@#########$$@@#$++++++.", ".+++++@@@#########$$$+@@$++++++.", ".+++++@@@########$$$+++@$++++++.", ".++++++@@@######$$$+++++$++++++.", ".+++++++@@@####$$$+++++++++++++.", ".++++++++@@@##$$$++++++++++++++.", ".+++++++++@@@$$$+++++++++++++++.", ".++++++++++@@$$++++++++++++++++.", ".+++++++++++@$+++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", "................................", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++@$$$++++++++++++++@@@$++++.", ".++++@##$$++++++++++++@@##$++++.", ".++++@###$$++++++++++@@###$++++.", ".++++@@###$$++++++++@@###$$++++.", ".+++++@@###$$++++++@@###$$+++++.", ".++++++@@###$$++++@@###$$++++++.", ".+++++++@@###$$++@@###$$+++++++.", ".++++++++@@###$$@@###$$++++++++.", ".+++++++++@@###$@###$$+++++++++.", ".++++++++++@@######$$++++++++++.", ".+++++++++++@@####$$+++++++++++.", ".+++++++++++@@####$$+++++++++++.", ".++++++++++@@######$$++++++++++.", ".+++++++++@@###$@###$$+++++++++.", ".++++++++@@###$$@@###$$++++++++.", ".+++++++@@###$$++@@###$$+++++++.", ".++++++@@###$$++++@@###$$++++++.", ".+++++@@###$$++++++@@###$$+++++.", ".++++@@###$$++++++++@@###$$++++.", ".++++@###$$++++++++++@@###$++++.", ".++++@##$$++++++++++++@@##$++++.", ".++++@$$$++++++++++++++@@@$++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", ".++++++++++++++++++++++++++++++.", "................................"}; garlic-1.6/slab_shift.c0000644000076500007650000000573507272367311015413 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= slab_shift.c Purpose: Prepare the slab shift. By default, the normal slab shift is used (slab_shiftA[2] from ConfigS structure). See note 1 for possible combinations of modifier keys. Modifier keys are used to select the slab shift. Input: (1) Pointer to ConfigS structure, with configuration data. (2) Pointer to GUIS structure, with GUI data. (3) The sign used to distinguish positive and negative shift. Output: (1) Return value. Return value: (1) Slab shift. Notes: (1) The following combinations of modifier keys may be used to select the slab shift: ------------------------------------------------------------- | modifiers slab shift ConfigS member | |-----------------------------------------------------------| | none normal (default) slab_stepA[2] | | shift large slab_stepA[3] | | alt+shift very large slab_stepA[4] | | control small slab_stepA[1] | | alt+control very small slab_stepA[0] | | control+shift normal slab_stepA[2] | | alt normal slab_stepA[2] | | alt+shift+control normal slab_stepA[2] | ------------------------------------------------------------- Note that some modifier combinations are ignored (alt alone, control+shift and alt+control+shift). (2) On some laptops the status of shift key may be changed before the KeyPress event is send for the keys on "numeric keypad". ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======prepare slab shift:==================================================*/ double SlabShift_ (ConfigS *configSP, GUIS *guiSP, double sign) { double slab_shift; int largeF, smallF, altF; /* Copy the flags: */ largeF = guiSP->shift_pressedF; smallF = guiSP->control_pressedF; altF = guiSP->alt_pressedF; /* Select the requested slab shift: */ if (altF) { if (largeF && !smallF) { slab_shift = configSP->slab_stepA[4]; } else if (smallF && !largeF) { slab_shift = configSP->slab_stepA[0]; } else { slab_shift = configSP->slab_stepA[2]; } } else { if (largeF && !smallF) { slab_shift = configSP->slab_stepA[3]; } else if (smallF && !largeF) { slab_shift = configSP->slab_stepA[1]; } else if (smallF && largeF) { slab_shift = configSP->slab_stepA[0]; } else { slab_shift = configSP->slab_stepA[2]; } } /* Take care for the sign: */ slab_shift *= sign; /* Return the slab shift: */ return slab_shift; } /*===========================================================================*/ garlic-1.6/show_no_refresh.c0000644000076500007650000000342407076135507016462 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= show_no_refresh.c Purpose: Show selected atoms but do not refresh graphics. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) The number of macromolecular complexes. Output: (1) The hiddenF set for each atom in each caught complex. (2) Return value. Return value: (1) Always positive (trivial). ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======show selected atoms:=================================================*/ int ShowNoRefresh_ (MolComplexS *mol_complexSP, int mol_complexesN) { int mol_complexI; MolComplexS *curr_mol_complexSP; size_t atomsN, atomI; AtomS *curr_atomSP; /* Check every macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /** Pointer to the current macromolecular complex: **/ curr_mol_complexSP = mol_complexSP + mol_complexI; /** Check is the current macromolecular complex caught: **/ if (curr_mol_complexSP->catchF == 0) continue; /** Number of atoms in a macromolecular complex: **/ atomsN = curr_mol_complexSP->atomsN; /** Scan all atoms in the current complex: **/ for (atomI = 0; atomI < atomsN; atomI++) { /** Pointer to the current atom: **/ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /** Check the selection flag; show selected atoms: **/ if (curr_atomSP->selectedF) curr_atomSP->hiddenF = 0; } } /* Return positive value (trivial): */ return 1; } /*===========================================================================*/ garlic-1.6/alpha_membrane.c0000644000076500007650000004660507747232511016231 0ustar zuciczucic00000000000000/* Copyright (C) 2001-2003 Damir Zucic */ /*============================================================================= alpha_membrane.c Purpose: Find the position and orientation of the membrane with respect to the macromolecular structure. The structure in question should be some membrane protein of alpha helix bundle type. Otherwise, this function will fail to work properly. Input: (1) Pointer to MolComplexS structure, with the chosen structure. (2) Pointer to RuntimeS structure. (3) Pointer to ConfigS structure (stereo angle required). (4) Pointer to GUIS structure. Output: (1) The membrane position and orientation will be calculated for the first time or updated. (2) Return value. Return value: (1) Positive on success. (2) Negative on failure. Notes: (1) A short description of some tricks used in this function: ------------------------------------------------------------- In the first step, the approximate membrane orientation is determined. The current sliding window width is used to calculate the average hydrophobicity for the entire sequence, chain by chain. The residue with the highest average hydroph. is identified and treated as the central residue of the most hydrophobic structural motif. The four residues which are at the beginning of the most hydrophobic window are identified, as well as the four residues at the end of this window. These eight atoms are used to define the first vector which should be approximately perpendicular to the membrane. After the first step, the second most hydrophobic segment is found. The second vector is calculated in the same manner as the first vector. The procedure is repeated to find all segments with the average hydrophobicity above the specified threshold. All extracted vectors are normalized and combined (added) into a single vector. This vector is treated as the normal vector of the membrane. In addition to the normal vector, the geometric center of the whole structure is used as the reference point. ------------------------------------------------------------- In the second step, all residues are projected to the axis defined by the reference point and by the normal vector. The axis is divided into a number of cells ("boxes") and the projected residues are grouped into these cells, depending on the distance of the projection from the reference point. For each cell, the total projected hydrophobicity is calculated. After the total hydrophobicity value is calculated for all individual cells, the set of cells is scanned to calculate the average hydrophobicity for the specified number of cells. The sliding window width multiplied by the width of a single cell (in angstroms) should be similar to the thickness of the phospholipid bilayer. At the end of the second step, the cell with the highest average hydrophobicity is found and the reference point is moved to the position of this cell. ------------------------------------------------------------- The third step is the refinement of the normal vector. The normal vector is declined from its original direction to scan a set of alternative positions. For each trial, the average hydrophobicity associated with the cell which is nearest to the reference point is calculated. Again, the sliding window width should be similar to the membrane thickness. The best normal vector is the one which gives the highest average hydrophobicity at the reference point. This operation is done twice. ------------------------------------------------------------- In the fourth step the position of the membrane center is refined once more. ------------------------------------------------------------- (2) The components of the normal vector are used to initialize the corresponding members of two PlaneS structures which are used to define the membrane. (3) An interesting article (from Stephen White Laboratory) about the structure of lipid bilayers may be found at: http://blanco.biomol.uci.edu/Bilayer_Struc_frames.html ========includes:============================================================*/ #include #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ double Hydrophobicity_ (char *, int, int); int ExtractCA_ (VectorS *, AtomS *, size_t, size_t); int ExtractVector_ (VectorS *, MolComplexS *, RuntimeS *, double); double AbsoluteValue_ (VectorS *); double ScalarProduct_ (VectorS *, VectorS *); int AlphaMembraneCenter_ (MolComplexS *, VectorS *); int AlphaNormalVector_ (VectorS *, MolComplexS *, double); /*======find membrane position (helix bundle version):=======================*/ int AlphaMembrane_ (MolComplexS *mol_complexSP, RuntimeS *runtimeSP, ConfigS *configSP, GUIS *guiSP) { int max_length; int residuesN, residueI, start_residueI, end_residueI; ResidueS *residueSP; AtomS *first_atomSP; char *residue_nameP, *destP; int scaleI; size_t offset; char residue_nameA[RESNAMESIZE]; double hydrophobicity, average_hyphob; int window_width, half_window_width, windowI, combinedI; int used_residuesN; double mean_value, standard_deviation, threshold; double difference, total; double max_average_hyphob, min_average_hyphob; int central_residueI, window_startI, window_endI; int vectors_extractedN; VectorS vector1S, vector2S, vector3S, vector4S; VectorS vector5S, vector6S, vector7S, vector8S; VectorS normal_vectorS; int n; double scalar_product; double abs_value, reciprocal_denominator; double tilt_step; double sin_angle, cos_angle; /*------check the number of residues:----------------------------------------*/ /* The minimal number of residues is equal to the sliding window width: */ if ((int) mol_complexSP->residuesN < runtimeSP->sliding_window_width) { return -1; } /*------copy the sequence:---------------------------------------------------*/ /* The maximal residue name length: */ max_length = RESNAMESIZE - 1; /* Copy the number of residues: */ residuesN = mol_complexSP->residuesN; if (residuesN == 0) return -2; /* Scan the macromolecular complex, residue by residue: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Pointer to the current residue: */ residueSP = mol_complexSP->residueSP + residueI; /* Pointer to the first atom: */ first_atomSP = mol_complexSP->atomSP + residueSP->residue_startI; /* Pointer to the residue name associated with this atom: */ residue_nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Prepare and check the position in the general purpose */ /* sequence buffer where the residue name will be copied: */ offset = max_length * residueI; if (offset > runtimeSP->sequence_buffer_size - 10 * max_length) { return -3; } /* Copy the residue name: */ destP = runtimeSP->sequenceP + offset; strncpy (destP, residue_nameP, max_length); } /* Store the number of residues to RuntimeS: */ runtimeSP->residuesN = residuesN; /*------assign the hydrophobicity values:------------------------------------*/ /* Hydrophobicity scale index: */ scaleI = runtimeSP->hydrophobicity_scaleI; /* Scan the general purpose sequence: */ for (residueI = 0; residueI < (int) runtimeSP->residuesN; residueI++) { /* Pointer to the current residue name: */ residue_nameP = runtimeSP->sequenceP + residueI * max_length; /* Copy the residue name: */ strncpy (residue_nameA, residue_nameP, max_length); residue_nameA[max_length] = '\0'; /* The corresponding hydrophobicity: */ hydrophobicity = Hydrophobicity_ (residue_nameA, scaleI, 0); /* Store the hydrophobicity value: */ *(runtimeSP->hydrophobicityP + residueI) = hydrophobicity; } /*------calculate the average hydrophobicity:--------------------------------*/ /* The sliding window width should be at least seven: */ window_width = runtimeSP->sliding_window_width; if (window_width < 7) return -4; half_window_width = window_width / 2; /* Scan the sequence: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Reset the number of residues used for averaging: */ used_residuesN = 0; /* Reset the average hydrophobicity: */ average_hyphob = 0.0; /* Scan the sliding window: */ for (windowI = 0; windowI < window_width; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI - half_window_width + windowI; if (combinedI < 0) continue; if (combinedI >= residuesN) continue; /* The hydrophobicity of the residue defined by combinedI: */ hydrophobicity = (double) *(runtimeSP->hydrophobicityP + combinedI); /* Add hydrophobicity to the total: */ average_hyphob += hydrophobicity; /* Increase the number of residues used for averaging: */ used_residuesN++; } /* Check how many residues were used: */ if (used_residuesN == window_width) { average_hyphob /= (double) window_width; } else average_hyphob = 0.0; /* Store the average hydrophobicity: */ *(runtimeSP->average_hydrophobicityP + residueI) = average_hyphob; } /*------calculate the mean value and the standard deviation:-----------------*/ /* Initialize the counter and the overall */ /* mean value of average hydrophobicity: */ used_residuesN = 0; mean_value = 0.0; /* Scan the sequence skipping the residues for which the */ /* average hydrophobicity was not calculated properly: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Skip the residues which are too close to */ /* the start or to the end of the sequence: */ start_residueI = residueI - half_window_width; if (start_residueI < 0) continue; end_residueI = residueI - half_window_width + window_width - 1; if (end_residueI >= residuesN) continue; /* Add the average hydrophobicity to the mean_value: */ mean_value += *(runtimeSP->average_hydrophobicityP + residueI); /* Increment the counter: */ used_residuesN++; } /* Check was there at least one residue: */ if (used_residuesN == 0) return -5; /* Calculate the overall mean value of the average hydrophobicity: */ mean_value /= (double) used_residuesN; /* Initialize the variable which is used */ /* to calculate the standard deviation: */ total = 0.0; /* Now scan the sequence again, to calculate squared */ /* differences required for the standard deviation: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Skip the residues which are too close to */ /* the start or to the end of the sequence: */ start_residueI = residueI - half_window_width; if (start_residueI < 0) continue; end_residueI = residueI - half_window_width + window_width - 1; if (end_residueI >= residuesN) continue; /* Calculate the difference between the average */ /* hydrophobicity and the overall mean value: */ difference = *(runtimeSP->average_hydrophobicityP + residueI) - mean_value; /* Add the square of this difference to the total: */ total += difference * difference; } /* Calculate the standard deviation: */ standard_deviation = sqrt (total / (double) used_residuesN); /* Prepare the threshold value, required */ /* to identify the transmembrane segments. */ threshold = mean_value + 1.5 * standard_deviation; /*------the first estimate of the normal vector:-----------------------------*/ /* Initialize the maximal and minimal average hydrophobicity: */ max_average_hyphob = -999999.0; min_average_hyphob = 999999.0; /* Initialize the index of the residue which is */ /* in the middle of the most hydrophobic segment. */ central_residueI = -1; /* Find the sequence position with the highest average hydrophobicity. */ /* Find also the values of maximal and minimal average hydrophobicity. */ for (residueI = 0; residueI < residuesN; residueI++) { average_hyphob = *(runtimeSP->average_hydrophobicityP + residueI); if (average_hyphob > max_average_hyphob) { max_average_hyphob = average_hyphob; central_residueI = residueI; } else if (average_hyphob < min_average_hyphob) { min_average_hyphob = average_hyphob; } } /* This should never happen but I am paranoic: */ if (central_residueI == -1) return -6; /* Check the maximal average hydrophobicity: */ if (max_average_hyphob < threshold) return -7; /* Now use the index of the central residue to define the entire */ /* sliding window which contains the maximal average hydrophobicity: */ window_startI = central_residueI - half_window_width; window_endI = window_startI + window_width; /* Check both indices; if the central residue is too close to */ /* the first or to the last residue, something went wrong: */ if ((window_startI < 0) || (window_startI >= residuesN)) return -8; /* Use the first four residues from the sliding window to */ /* define the first point in space and the last four residues */ /* to define the second point in space. Use these two points */ /* to prepare the initial normal vector. This vector should be */ /* approximately perpendicular to the membrane. The coordinates */ /* of CA atoms are used (some structures contain only CA atoms). */ /* Prepare eight vectors: */ vectors_extractedN = 0; residueSP = mol_complexSP->residueSP + window_startI; vectors_extractedN += ExtractCA_ (&vector1S, mol_complexSP->atomSP, residueSP->residue_startI, residueSP->residue_endI); residueSP = mol_complexSP->residueSP + window_startI + 1; vectors_extractedN += ExtractCA_ (&vector2S, mol_complexSP->atomSP, residueSP->residue_startI, residueSP->residue_endI); residueSP = mol_complexSP->residueSP + window_startI + 2; vectors_extractedN += ExtractCA_ (&vector3S, mol_complexSP->atomSP, residueSP->residue_startI, residueSP->residue_endI); residueSP = mol_complexSP->residueSP + window_startI + 3; vectors_extractedN += ExtractCA_ (&vector4S, mol_complexSP->atomSP, residueSP->residue_startI, residueSP->residue_endI); residueSP = mol_complexSP->residueSP + window_endI; vectors_extractedN += ExtractCA_ (&vector5S, mol_complexSP->atomSP, residueSP->residue_startI, residueSP->residue_endI); residueSP = mol_complexSP->residueSP + window_endI - 1; vectors_extractedN += ExtractCA_ (&vector6S, mol_complexSP->atomSP, residueSP->residue_startI, residueSP->residue_endI); residueSP = mol_complexSP->residueSP + window_endI - 2; vectors_extractedN += ExtractCA_ (&vector7S, mol_complexSP->atomSP, residueSP->residue_startI, residueSP->residue_endI); residueSP = mol_complexSP->residueSP + window_endI - 3; vectors_extractedN += ExtractCA_ (&vector8S, mol_complexSP->atomSP, residueSP->residue_startI, residueSP->residue_endI); if (vectors_extractedN != 8) return -9; /* The first (crude) estimate of the normal vector: */ normal_vectorS.x = vector5S.x + vector6S.x + vector7S.x + vector8S.x - vector1S.x - vector2S.x - vector3S.x - vector4S.x; normal_vectorS.y = vector5S.y + vector6S.y + vector7S.y + vector8S.y - vector1S.y - vector2S.y - vector3S.y - vector4S.y; normal_vectorS.z = vector5S.z + vector6S.z + vector7S.z + vector8S.z - vector1S.z - vector2S.z - vector3S.z - vector4S.z; /* Remove the highest peak. Replace the average hydrophobicities */ /* in the whole interval by the minimal average hydrophobicity. */ for (residueI = window_startI; residueI <= window_endI; residueI++) { *(runtimeSP->average_hydrophobicityP + residueI) = min_average_hyphob; } /*------update the normal vector by adding more vectors:---------------------*/ /* Extract all peaks above the specified threshold: */ while (1) { /* Try to extract one vector: */ n = ExtractVector_ (&vector1S, mol_complexSP, runtimeSP, threshold); if (n < 0) break; /* Now check the scalar product between the */ /* current normal vector and this new vector. */ /* If it is negative, flip the new vector. */ scalar_product = ScalarProduct_ (&normal_vectorS, &vector1S); if (scalar_product < 0.0) { vector1S.x = -vector1S.x; vector1S.y = -vector1S.y; vector1S.z = -vector1S.z; } /* Update the normal vector by adding the new vector: */ normal_vectorS.x += vector1S.x; normal_vectorS.y += vector1S.y; normal_vectorS.z += vector1S.z; } /*------normalize the normal vector:-----------------------------------------*/ /* Make sure that the absolute value of the normal vector is equal to one: */ abs_value = AbsoluteValue_ (&normal_vectorS); if (abs_value == 0.0) return -10; reciprocal_denominator = 1.0 / abs_value; normal_vectorS.x *= reciprocal_denominator; normal_vectorS.y *= reciprocal_denominator; normal_vectorS.z *= reciprocal_denominator; /*------the first estimate of the membrane center:---------------------------*/ /* Take the geometric center as the initial membrane center: */ mol_complexSP->membraneS.center_x = mol_complexSP->geometric_center_vectorS.x; mol_complexSP->membraneS.center_y = mol_complexSP->geometric_center_vectorS.y; mol_complexSP->membraneS.center_z = mol_complexSP->geometric_center_vectorS.z; /* Find a better estimate of the membrane center: */ AlphaMembraneCenter_ (mol_complexSP, &normal_vectorS); /*------refine the normal vector twice, using different steps:---------------*/ /* Refine the normal vector which defines the membrane. */ /* The first passage - use a large tilt step: */ tilt_step = 0.05; AlphaNormalVector_ (&normal_vectorS, mol_complexSP, tilt_step); /* The second passage - use a small tilt step: */ tilt_step = 0.01; AlphaNormalVector_ (&normal_vectorS, mol_complexSP, tilt_step); /*------refine the membrane center once more:--------------------------------*/ AlphaMembraneCenter_ (mol_complexSP, &normal_vectorS); /*------store the normal vector:---------------------------------------------*/ /* Store (copy) the components of the normal vector. */ /* The normal vector of the first plane points to the same direction: */ mol_complexSP->membraneS.plane1S.normal_x[0] = normal_vectorS.x; mol_complexSP->membraneS.plane1S.normal_y = normal_vectorS.y; mol_complexSP->membraneS.plane1S.normal_z[0] = normal_vectorS.z; /* The normal vector of the second plane points to the opposite direction: */ mol_complexSP->membraneS.plane2S.normal_x[0] = -normal_vectorS.x; mol_complexSP->membraneS.plane2S.normal_y = -normal_vectorS.y; mol_complexSP->membraneS.plane2S.normal_z[0] = -normal_vectorS.z; /* Prepare the stereo data for these two normal vectors. */ /* Prepare the sine and cosine of the stereo angle: */ sin_angle = sin (configSP->stereo_angle); cos_angle = cos (configSP->stereo_angle); /* Calculate the stereo data: */ mol_complexSP->membraneS.plane1S.normal_x[1] = mol_complexSP->membraneS.plane1S.normal_x[0] * cos_angle + mol_complexSP->membraneS.plane1S.normal_z[0] * sin_angle; mol_complexSP->membraneS.plane1S.normal_z[1] = -mol_complexSP->membraneS.plane1S.normal_x[0] * sin_angle + mol_complexSP->membraneS.plane1S.normal_z[0] * cos_angle; mol_complexSP->membraneS.plane2S.normal_x[1] = mol_complexSP->membraneS.plane2S.normal_x[0] * cos_angle + mol_complexSP->membraneS.plane2S.normal_z[0] * sin_angle; mol_complexSP->membraneS.plane2S.normal_z[1] = -mol_complexSP->membraneS.plane2S.normal_x[0] * sin_angle + mol_complexSP->membraneS.plane2S.normal_z[0] * cos_angle; /*---------------------------------------------------------------------------*/ /* Return positive value on success: */ return 1; } /*===========================================================================*/ garlic-1.6/colors.script0000644000076500007650000000232707540360036015645 0ustar zuciczucic00000000000000# Show predefined color schemes, version 1.2. # This script will work if you use default .garlicrc script. # This script requires garlic version 1.2! load trp.pdb pos -18 -15 0 ato sp2 bon nice color red # Now inform user that refreshing is off: title 1 50 50 "Please be patient ..." # Switch refreshing off: refresh off load trp.pdb pos -6 -15 0 ato sp2 bon nice color green load trp.pdb pos 6 -15 0 ato sp2 bon nice color blue load trp.pdb pos 18 -15 0 ato sp2 bon nice color yellow load trp.pdb pos -18 -5 0 ato sp2 bon nice color cyan load trp.pdb pos -6 -5 0 ato sp2 bon nice color magenta load trp.pdb pos 6 -5 0 ato sp2 bon nice color white load trp.pdb pos 18 -5 0 ato sp2 bon nice color yellow-green load trp.pdb pos -18 5 0 ato sp2 bon nice color cyan-green load trp.pdb pos -6 5 0 ato sp2 bon nice color cyan-blue load trp.pdb pos 6 5 0 ato sp2 bon nice color magenta-blue load trp.pdb pos 18 5 0 ato sp2 bon nice color magenta-red load trp.pdb pos -18 15 0 ato sp2 bon nice color orange load trp.pdb pos -6 15 0 ato sp2 bon nice color hot load trp.pdb pos 6 15 0 ato sp2 bon nice color cold load trp.pdb pos 18 15 0 ato sp2 bon nice color cpk # Hide the title: title 1 off # Switch refreshing on: refresh garlic-1.6/big.structure0000644000076500007650000000236407314062274015644 0ustar zuciczucic00000000000000> big polyalanine HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH garlic-1.6/align_complexes.c0000644000076500007650000000715507400140211016421 0ustar zuciczucic00000000000000/* Copyright (C) 2000, 2001 Damir Zucic */ /*============================================================================= align_complexes.c Purpose: Align two macromolecular complexes vertically. The first complex will be placed at the bottom, while the second will be placed at the top. A small separation will be left between them. Input: (1) Pointer to MolComplexS structure, with the first complex. (2) Pointer to MolComplexS structure, with the second complex. (3) Pointer to ConfigS structure. Output: (1) Two macromolecular complexes will be translated. (2) Return value. Return value: (1) Positive on success. (2) Negative on failure. ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ void TranslateComplex_ (MolComplexS *, VectorS *, ConfigS *, int); void TranslatePlane_ (MolComplexS *, VectorS *); void TranslateMembrane_ (MolComplexS *, VectorS *); /*======align two complexes vertically:======================================*/ int AlignComplexes_ (MolComplexS *mol_complex1SP, MolComplexS *mol_complex2SP, ConfigS *configSP) { size_t atomI; AtomS *curr_atomSP; double y, y1_min, y2_max; VectorS shift_vectorS; /* Check pointers: */ if (!mol_complex1SP) return -1; if (!mol_complex2SP) return -2; /* Both complexes should contain at least one atom: */ if (mol_complex1SP->atomsN == 0) return -3; if (mol_complex2SP->atomsN == 0) return -4; /* For the first complex, find the minimal y: */ y1_min = mol_complex1SP->atomSP->raw_atomS.y; for (atomI = 0; atomI < mol_complex1SP->atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = mol_complex1SP->atomSP + atomI; /* The y coordinate of the current atom: */ y = curr_atomSP->raw_atomS.y; /* Compare y with y1_min: */ if (y < y1_min) y1_min = y; } /* For the second complex, find the maximal y: */ y2_max = mol_complex2SP->atomSP->raw_atomS.y; for (atomI = 0; atomI < mol_complex2SP->atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = mol_complex2SP->atomSP + atomI; /* The y coordinate of the current atom: */ y = curr_atomSP->raw_atomS.y; /* Compare y with y2_max: */ if (y > y2_max) y2_max = y; } /* Prepare the translation vector for the first complex. The geometric */ /* center should be moved to y axis, slightly below the system origin: */ shift_vectorS.x = -1.0 * mol_complex1SP->geometric_center_vectorS.x; shift_vectorS.y = -1.0 *(y1_min - 0.5 * DOCKING_GAP); shift_vectorS.z = -1.0 * mol_complex1SP->geometric_center_vectorS.z; /* Translate the first complex and associated objects: */ TranslateComplex_ (mol_complex1SP, &shift_vectorS, configSP, 0); TranslatePlane_ (mol_complex1SP, &shift_vectorS); TranslateMembrane_ (mol_complex1SP, &shift_vectorS); /* Prepare the translation vector for the second complex. The geometric */ /* center should be moved to y axis, slightly above the system origin: */ shift_vectorS.x = -1.0 * mol_complex2SP->geometric_center_vectorS.x; shift_vectorS.y = -1.0 *(y2_max + 0.5 * DOCKING_GAP); shift_vectorS.z = -1.0 * mol_complex2SP->geometric_center_vectorS.z; /* Translate the second complex and associated objects: */ TranslateComplex_ (mol_complex2SP, &shift_vectorS, configSP, 0); TranslatePlane_ (mol_complex2SP, &shift_vectorS); TranslateMembrane_ (mol_complex2SP, &shift_vectorS); /* Return positive value on success: */ return 1; } /*===========================================================================*/ garlic-1.6/radius.c0000644000076500007650000000371207117163362014553 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= radius.c Purpose: Execute radius command: define the radius of the sphere around the geometric center calculated for the current selection. This radius may be used to select all atoms which are inside this sphere. Default (hard-coded) value is 8.0 angstroms. Input: (1) Pointer to RuntimeS structure. (2) Pointer to the remainder of the command string. Output: (1) The sphere radius set. (2) Return value. Return value: (1) Positive (command) code on success. (2) Negative (error) code on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include #include "defines.h" #include "commands.h" #include "typedefs.h" /*======execute radius command:==============================================*/ int Radius_ (RuntimeS *runtimeSP, char *stringP) { char *P; int n; double value; /* Replace each non-numeric character (except */ /* minus sign and decimal point) with space: */ P = stringP; while ((n = *P++) != '\0') { if (!isdigit (n) && (n != '-') && (n != '.')) *(P - 1) = ' '; } /* Try to extract the radius: */ if (sscanf (stringP, "%lf", &value) != 1) { strcpy (runtimeSP->messageA, "Failed to extract the sphere radius!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_RADIUS; } /* Check the radius (must be positive): */ if (value < 0.0) { strcpy (runtimeSP->messageA, "Positive value expected!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_RADIUS; } /* On success, copy the extracted radius to RuntimeS structure: */ runtimeSP->sphere_radius = value; /* Return the command code: */ return COMMAND_RADIUS; } /*===========================================================================*/ garlic-1.6/create_structure.c0000644000076500007650000003104407632075771016656 0ustar zuciczucic00000000000000/* Copyright (C) 2001-2003 Damir Zucic */ /*============================================================================= create_structure.c Purpose: Create the new structure. Use the sequence from the main sequence buffer and the secondary structure from the main secondary structure buffer. Atomic data should be copied from the template data. This function works only with protein sequences. This functions should be compared with load_complex.c, to check what should be prepared in addition to complete the structure. Input: (1) Pointer to MolComplexS structure. (2) Pointer to the number of macromolecular complexes. (3) Pointer to the next macromolecular complex identifier. (4) Pointer to RuntimeS structure. (5) The number of residues. (6) Pointer to ConfigS structure. (7) Pointer to GUIS structure. Output: (1) Allocate memory and create structure. (2) Return value. Return value: (1) Positive on success. (2) Negative on failure. Notes: (1) The number of atoms in the structure is updated in the function CopyTemplateAtoms_ (). ========includes:============================================================*/ #include #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ void ErrorMessage_ (char *, char *, char *, char *, char *, char *, char *); void InitializeHeader_ (HeaderS *); int CountRequiredAtoms_ (RuntimeS *, int); int CopyTemplateAtoms_ (MolComplexS *, RuntimeS *, ResidueS *, int); int ExtractSequence_ (MolComplexS *); int FixChain_ (MolComplexS *, RuntimeS *); int GeometricCenter_ (MolComplexS *); void FlipVector_ (VectorS *, VectorS *); void TranslateComplex_ (MolComplexS *, VectorS *, ConfigS *, int); int ComplexExtent_ (MolComplexS *); void InitSlab_ (MolComplexS *); void InitFading_ (MolComplexS *); int PrepareStereoData_ (MolComplexS *, ConfigS *); size_t StrongBonds_ (MolComplexS *, int, ConfigS *); size_t PseudoBonds_ (MolComplexS *, int, ConfigS *); size_t DisulfideBonds_ (MolComplexS *, int, ConfigS *); int PrepareBackbone_ (MolComplexS *, ConfigS *); int AssignRadii_ (MolComplexS *, ConfigS *); int AssignHydrophobicity_ (MolComplexS *, int); int DihedralAngles_ (MolComplexS *, ConfigS *); int AllocSecondaryStructure_ (MolComplexS *); /*@@*/ /* Generate secondary structure */ int GeneratePlane_ (MolComplexS *, ConfigS *, GUIS *); int InitializeMembrane_ (MolComplexS *, ConfigS *, GUIS *); /*======create new structure:================================================*/ int CreateStructure_ (MolComplexS *mol_complexSP, int *mol_complexesNP, int *next_mol_complexIDP, RuntimeS *runtimeSP, int residuesN, ConfigS *configSP, GUIS *guiSP) { int max_length; size_t char_size, atom_struct_size; int new_mol_complexI; static MolComplexS *new_mol_complexSP; int new_mol_complexID; int required_atomsN; size_t elementsN; int residueI; char *curr_residue_nameP; int template_residuesN, template_residueI; ResidueS *template_residueSP; AtomS *first_atomSP; char *curr_template_nameP; int n; VectorS shift_vectorS; /* Shift to geometric center */ int default_hyphob_scaleI = 2; int mol_complexI; MolComplexS *curr_mol_complexSP; /* The maximal residue name length: */ max_length = RESNAMESIZE - 1; /* Size of some data types: */ char_size = sizeof (char); atom_struct_size = sizeof (AtomS); /* Prepare the index of the new structure: */ new_mol_complexI = *mol_complexesNP; /* Prepare the pointer to the new macromolecular complex: */ new_mol_complexSP = mol_complexSP + new_mol_complexI; /* Initialize the file name: */ new_mol_complexSP->file_nameA[0] = '\0'; /* Prepare the identifier for the new macromolecular complex: */ new_mol_complexID = *next_mol_complexIDP; new_mol_complexSP->mol_complexID = new_mol_complexID; /* Update the next macromolecular complex identifier: */ (*next_mol_complexIDP)++; /* Update the number of macromolecular complexes: */ (*mol_complexesNP)++; /* Allocate memory for header strings: */ new_mol_complexSP->headerS.total_linesN = MAXHEADERLINES + MAXTITLELINES + MAXCOMPNDLINES + MAXSOURCELINES + MAXEXPDTALINES + MAXAUTHORLINES; elementsN = new_mol_complexSP->headerS.total_linesN * HEADERLINESIZE + 100; new_mol_complexSP->headerS.dataP = (char *) calloc (elementsN, char_size); if (new_mol_complexSP->headerS.dataP == NULL) { ErrorMessage_ ("garlic", "CreateStructure_", "", "Failed to allocate memory for header data!\n", "", "", ""); return -1; } /* Initialize the unique PDB identifier: */ strcpy (new_mol_complexSP->unique_PDB_codeA, "XXXX"); /* Initialize the memory reserved for text and initialize offsets: */ InitializeHeader_ (&new_mol_complexSP->headerS); /* Set the initial number of atoms (it will grow up later): */ new_mol_complexSP->atomsN = 0; /* Count the number of atoms: */ required_atomsN = CountRequiredAtoms_ (runtimeSP, residuesN); /* Prepare the maximal number of atoms in the new structure: */ elementsN = required_atomsN + 125; new_mol_complexSP->max_atomsN = elementsN; /* Allocate the memory for atomic coordinates (add some extra space): */ new_mol_complexSP->atomSP = (AtomS *) calloc (elementsN, atom_struct_size); if (new_mol_complexSP->atomSP == NULL) { ErrorMessage_ ("garlic", "CreateStructure_", "", "Failed to allocate memory for atomic data!\n", "", "", ""); free (new_mol_complexSP->headerS.dataP); new_mol_complexSP->headerS.dataP = NULL; return -2; } /* Copy the required template residues. */ /* The number of template residues: */ template_residuesN = runtimeSP->template_residuesN; /* Scan the sequence: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Prepare the pointer to the current residue name: */ curr_residue_nameP = runtimeSP->sequenceP + residueI * max_length; /* Scan the list of template residues: */ for (template_residueI = 0; template_residueI < template_residuesN; template_residueI++) { /* Pointer to the current template residue: */ template_residueSP = runtimeSP->template_residueSP + template_residueI; /* Pointer to the first atom of */ /* the current template residue: */ first_atomSP = runtimeSP->template_atomSP + template_residueSP->residue_startI; /* Pointer to the current template residue name: */ curr_template_nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Compare the current residue name */ /* with the template residue name; */ /* if they match, prepare the number */ /* of atoms and add it to the total. */ if (strncmp (curr_residue_nameP, curr_template_nameP, max_length) == 0) { /* Copy template atoms: */ CopyTemplateAtoms_ (new_mol_complexSP, runtimeSP, template_residueSP, residueI); break; } } } /* Extract sequence information: */ ExtractSequence_ (new_mol_complexSP); /* Fix the macromolecular chain: */ n = FixChain_ (new_mol_complexSP, runtimeSP); if (n < 0) { ErrorMessage_ ("garlic", "CreateStructure_", "", "Unable to fix the polypeptide chain!\n", "", "", ""); free (new_mol_complexSP->headerS.dataP); new_mol_complexSP->headerS.dataP = NULL; free (new_mol_complexSP->atomSP); new_mol_complexSP->atomSP = NULL; return n; } /* Initialize the move bits: */ new_mol_complexSP->move_bits = STRUCTURE_MASK | PLANE_MASK | MEMBRANE_MASK | ENVELOPE_MASK; /* Find geometric center: */ GeometricCenter_ (new_mol_complexSP); /* Flip vector (multiply by -1): */ FlipVector_ (&shift_vectorS, &new_mol_complexSP->geometric_center_vectorS); /* Translate geometric center of the complex to */ /* the origin of the absolute coordinate system: */ TranslateComplex_ (new_mol_complexSP, &shift_vectorS, configSP, 0); /* Initial rotation center position: */ new_mol_complexSP->rotation_center_vectorS.x = 0.0; new_mol_complexSP->rotation_center_vectorS.y = 0.0; new_mol_complexSP->rotation_center_vectorS.z = 0.0; /* Spatial extend of the whole macromolecular complex: */ ComplexExtent_ (new_mol_complexSP); /* Initialize the slab mode (use the current default slab mode): */ new_mol_complexSP->slab_modeI = configSP->default_slab_modeI; /* Initialize slab: */ InitSlab_ (new_mol_complexSP); /* Initialize the color fading mode (use the current default fading mode): */ new_mol_complexSP->fading_modeI = configSP->default_fading_modeI; /* Initialize color fading parameters: */ InitFading_ (new_mol_complexSP); /* Prepare the stereo data (coordinates for the right image): */ if (configSP->stereoF) PrepareStereoData_ (new_mol_complexSP, configSP); /* Prepare bonds; use inter-atomic */ /* distances for identification: */ StrongBonds_ (new_mol_complexSP, new_mol_complexI, configSP); /* Prepare pseudo-bonds: */ PseudoBonds_ (new_mol_complexSP, new_mol_complexI, configSP); /* Prepare disulfide bonds: */ DisulfideBonds_ (new_mol_complexSP, new_mol_complexI, configSP); /* Prepare backbone data - allocate and */ /* fill the array of BackboneS structures: */ PrepareBackbone_ (new_mol_complexSP, configSP); /* Assign radius to each atom: */ AssignRadii_ (new_mol_complexSP, configSP); /* Assign default hydrophobicity to each atom: */ AssignHydrophobicity_ (new_mol_complexSP, default_hyphob_scaleI); /* The sequence information was extracted before, no need to do this again. */ /* Calculate dihedral angles and cis_trans flags: */ DihedralAngles_ (new_mol_complexSP, configSP); /* Allocate and initialize the storage for the secondary structure: */ if (AllocSecondaryStructure_ (new_mol_complexSP) < 0) { ErrorMessage_ ("garlic", "CreateStructure_", "", "Failed to allocate memory for secondary structure!\n", "", "", ""); free (new_mol_complexSP->headerS.dataP); new_mol_complexSP->headerS.dataP = NULL; free (new_mol_complexSP->atomSP); new_mol_complexSP->atomSP = NULL; return -4; } /*@@*/ /* Generate the secondary structure information: */ /* Generate the plane (represented by an ellipse): */ GeneratePlane_ (new_mol_complexSP, configSP, guiSP); /* Initialize data required to draw the membrane: */ InitializeMembrane_ (new_mol_complexSP, configSP, guiSP); /* Initialize the flag reserved for hydrogen bonds: if value */ /* is equal to zero, hydrogen bonds are missing or obsolete. */ new_mol_complexSP->hydrogen_bondsF = 0; /* The hydrogen bonds are initially invisible: */ new_mol_complexSP->hydrogen_bonds_hiddenF = 1; /* The membrane is initially undefined: */ new_mol_complexSP->membraneS.definedF = 0; /* Set the probe radius (copy default value): */ new_mol_complexSP->bond_probe_radius = configSP->default_bond_probe_radius; /* Set the stick radius (used to draw bonds as sticks; copy default value): */ new_mol_complexSP->stick_radius = configSP->default_stick_radius; /* Set the group_memberF to zero: */ new_mol_complexSP->group_memberF = 0; /* If some structures were grouped, break */ /* the group, i.e. reset the group flag: */ runtimeSP->groupF = 0; /* If some structures were involved in a formation of a */ /* group, restore the original rotation center vectors: */ for (mol_complexI = 0; mol_complexI < *mol_complexesNP; mol_complexI++) { /* Prepare the pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check was this complex a group member: */ if (curr_mol_complexSP->group_memberF == 0) continue; /* If this point is reached, the current complex was a group member. */ /* Restore the original rotation center vector: */ curr_mol_complexSP->rotation_center_vectorS.x = curr_mol_complexSP->backup_vectorS.x; curr_mol_complexSP->rotation_center_vectorS.y = curr_mol_complexSP->backup_vectorS.y; curr_mol_complexSP->rotation_center_vectorS.z = curr_mol_complexSP->backup_vectorS.z; /* Reset the group_memberF: */ curr_mol_complexSP->group_memberF = 0; } /* Set the catch flag to indicate that the new */ /* complex is the only one which is caught, i.e. */ /* affected by movement, slab and fading controls: */ for (mol_complexI = 0; mol_complexI < *mol_complexesNP; mol_complexI++) { /** Pointer to the current macromolecular complex: **/ curr_mol_complexSP = mol_complexSP + mol_complexI; /** The catch flag for the new complex should be set to one: **/ if (curr_mol_complexSP->mol_complexID == new_mol_complexID) { curr_mol_complexSP->catchF = 1; } /** All other catch flags should be set to zero: **/ else curr_mol_complexSP->catchF = 0; } /* Return positive value on success: */ return 1; } /*===========================================================================*/ garlic-1.6/structure.c0000644000076500007650000001136010346115545015320 0ustar zuciczucic00000000000000/* Copyright (C) 2001 Damir Zucic */ /*============================================================================= structure.c Purpose: Execute structure command. This command may be used to define or copy the secondary structure. The structure is stored to the structure buffer. The command is used with at least one keyword. Keywords: RESET, =, FROM, LOAD (READ) and SAVE. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) The number of macromolecular complexes. (3) Pointer to RuntimeS structure. (4) Pointer to the string with command parameters. Output: (1) Secondary structure stored to the structure buffer. (2) Return value. Return value: (1) Positive (command) code on success. (2) Negative (error) code on failure. Notes: (1) Use one letter codes to define the secondary structure: C = coil, E = strand, G = 3-10 helix, H = alpha helix, T = turn. (2) Space, comma and tab may be used as separators. ========includes:============================================================*/ #include #include #include #include #include #include #include #include "defines.h" #include "commands.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int ParseSecondaryStructure_ (RuntimeS *, char *); char *ExtractToken_ (char *, int, char *, char *); int SecondaryStructureFrom_ (MolComplexS *, int, RuntimeS *, char *); int CopySecondaryStructure_ (RuntimeS *); int LoadSecondaryStructure_ (RuntimeS *); int SaveSecondaryStructure_ (RuntimeS *); /*======execute structure command:===========================================*/ int Structure_ (MolComplexS *mol_complexSP, int mol_complexesN, RuntimeS *runtimeSP, char *stringP) { char string_copyA[STRINGSIZE]; char *P; char *sec_structureP; int n; char *remainderP; char tokenA[SHORTSTRINGSIZE]; int i; /* Copy the original command string: */ strncpy (string_copyA, runtimeSP->curr_commandA, STRINGSIZE - 1); string_copyA[STRINGSIZE - 1] = '\0'; /* Check is the equality sign present in the original command string: */ if ((P = strstr (string_copyA, "=")) != NULL) { /* Prepare the pointer to the string with the secondary structure: */ sec_structureP = P + 1; /* Convert the secondary structure to uppercase: */ P = sec_structureP; while ((n = *P++) != '\0') *(P - 1) = toupper (n); /* Parse and store the secondary structure: */ n = ParseSecondaryStructure_ (runtimeSP, sec_structureP); if (n > 0) return COMMAND_STRUCTURE; else return ERROR_STRUCTURE; } /* If this point is reached, the equality sign was not found */ /* in the original command string. Check for other keywords. */ /* Take the first token; it should be present: */ remainderP = ExtractToken_ (tokenA, SHORTSTRINGSIZE, stringP, " \t\n"); if (!remainderP) { strcpy (runtimeSP->messageA, "Command parameter(s) missing!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_STRUCTURE; } /* Reset the secondary structure, if requested by keyword RES (RESET). */ /* The entire buffer will be filled with codes for extended structure. */ if (strstr (tokenA, "RES") == tokenA) { runtimeSP->sec_structure_length = MAXRESIDUES; for (i = 0; i < MAXRESIDUES; i++) { *(runtimeSP->sec_structureP + i) = 'E'; } return COMMAND_STRUCTURE; } /* Copy the secondary structure from macromol. */ /* complex, if requested by keyword FRO (FROM): */ else if (strstr (tokenA, "FRO") == tokenA) { n = SecondaryStructureFrom_ (mol_complexSP, mol_complexesN, runtimeSP, remainderP); if (n > 0) return COMMAND_STRUCTURE; else return ERROR_STRUCTURE; } /* Copy the secondary structure from the main */ /* structure buffer to the reference buffer: */ else if (strstr (tokenA, "COP") == tokenA) { CopySecondaryStructure_ (runtimeSP); return COMMAND_STRUCTURE; } /* Load the secondary structure from file, if */ /* requested by keyword LOA (LOAD) or REA (READ): */ else if ((strstr (tokenA, "LOA") == tokenA) || (strstr (tokenA, "REA") == tokenA)) { n = LoadSecondaryStructure_ (runtimeSP); if (n > 0) return COMMAND_STRUCTURE; else return ERROR_STRUCTURE; } /* Save the secondary structure, if requested by keyword SAV: */ else if (strstr (tokenA, "SAV") == tokenA) { n = SaveSecondaryStructure_ (runtimeSP); if (n > 0) return COMMAND_STRUCTURE; else return ERROR_STRUCTURE; } /* If keyword recognition failed: */ else { strcpy (runtimeSP->messageA, "Keyword not recognized!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_STRUCTURE; } /* Return the command code: */ return COMMAND_STRUCTURE; } /*===========================================================================*/ garlic-1.6/select_model.c0000644000076500007650000000566007465735110015731 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2002 Damir Zucic */ /*============================================================================= select_model.c Purpose: Select atoms which belong to the specified model. This should be useful with NMR structures. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. (3) Selection mode index (0 = overwrite, 1 = restrict, 2 = expand previous selection). Output: (1) The flag selectedF set for all atoms which belong to the specified model, in all currently caught macromol. complexes. (2) Return value. Return value: (1) The number of selected atoms (zero or positive value). Notes: (1) The position_changedF is updated, because some atoms may not have the proper color. ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======select atoms which belong to the specified model:====================*/ long SelectModel_ (MolComplexS *mol_complexSP, int mol_complexesN, int selection_modeI, int model_serialI) { long selected_atomsN = 0; int mol_complexI; MolComplexS *curr_mol_complexSP; size_t atomsN, atomI; AtomS *curr_atomSP; int modelF; /* Check every macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /** Pointer to the current macromolecular complex: **/ curr_mol_complexSP = mol_complexSP + mol_complexI; /** Check is the current macromolecular complex caught: **/ if (curr_mol_complexSP->catchF == 0) continue; /** Number of atoms in a macromolecular complex: **/ atomsN = curr_mol_complexSP->atomsN; /** Scan all atoms in the current complex: **/ for (atomI = 0; atomI < atomsN; atomI++) { /** Pointer to the current atom: **/ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /** Check the model serial number: **/ modelF = 0; if (curr_atomSP->raw_atomS.model_serialI == model_serialI) { modelF = 1; } /** Set the selection flag for the current atom: **/ switch (selection_modeI) { /*** Overwrite the previous selection: ***/ case 0: curr_atomSP->selectedF = modelF; break; /*** Restrict the previous selection: ***/ case 1: curr_atomSP->selectedF &= modelF; break; /*** Expand the previous selection: ***/ case 2: curr_atomSP->selectedF |= modelF; break; default: ; } /** Check the selection flag; increase **/ /** the count if flag is equal to one: **/ if (curr_atomSP->selectedF) selected_atomsN++; } /** Update the position_changedF (some atoms may have bad color): **/ curr_mol_complexSP->position_changedF = 1; } /* Return the number of selected atoms: */ return selected_atomsN; } /*===========================================================================*/ garlic-1.6/read_pdb.c0000644000076500007650000001746507747301162015037 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2003 Damir Zucic */ /*============================================================================= read_pdb.c Purpose: Read PDB file and store atomic data. The most important data (atomic coordinates) are extracted from ATOM and HETATM records. The following mandatory records are read: HEADER, TITLE, COMPND, SOURCE, EXPDTA and AUTHOR. Other mandatory and optional records are ignored in current version of the program. This version of garlic program is capable to read PDB format version 2.1; see pdb_atom.c for details about format. PDB documentation says that order of records is important, but garlic does not care for it. Input: (1) Pointer to MolComplexS structure (macromolecular complex). It should point to the first free MolComplexS structure. (2) Input file name (pointer). (3) Pointer to ConfigS structure, with configuration data. Output: (1) Allocate memory, read file and store data to allocated memory. (2) Return value. Return value: (1) Positive on success. (2) Negative on failure. Notes: (1) This function first checks are there any atomic coordinates in the current line, though atomic data should be expected after header data. There are many more lines with atomic coordinates, so the reversed order of checking ensures faster reading. (2) Memory reallocation was tested by reading a single PDB file containing 32 MB of valid PDB records. (3) Many older PDB files have some other data after the temperature factor instead of data specified by the format used here. (4) Some flags are set and default colors assigned to each atom immediately after parsing atomic data. ========includes:============================================================*/ #include #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ void ErrorMessage_ (char *, char *, char *, char *, char *, char *, char *); FILE *OpenFileForReading_ (char *); void InitializeHeader_ (HeaderS *); int ParsePDBAtomicData_ (AtomS *, char *); int ReallocPDBMemory_ (AtomS **, AtomS **, size_t *, size_t); int CopyHeaderLine_ (HeaderS *, char *, int); int PDBIdentifier_ (MolComplexS *, char *); /*======read PDB file:=======================================================*/ int ReadPDBFile_ (MolComplexS *mol_complexSP, char *file_nameP, ConfigS *configSP) { FILE *fileP; size_t rgb_struct_size; size_t memory_size; AtomS *curr_atomSP; char lineA[STRINGSIZE]; int line_size; int rec_typeI = 0, first_char; int n; int PDB_ID_foundF = 0; int model_serialI = 1; int model_serial_start = 10, model_serial_end = 13; char *P; /* Open file for reading: */ if ((fileP = OpenFileForReading_ (file_nameP)) == NULL) { ErrorMessage_ ("garlic", "ReadPDBFile_", file_nameP, "Failed to open file!\n", "", "", ""); return -1; } /* Allocate memory for header strings: */ mol_complexSP->headerS.total_linesN = MAXHEADERLINES + MAXTITLELINES + MAXCOMPNDLINES + MAXSOURCELINES + MAXEXPDTALINES + MAXAUTHORLINES; memory_size = mol_complexSP->headerS.total_linesN * HEADERLINESIZE + 100; if ((mol_complexSP->headerS.dataP = (char *) malloc (memory_size)) == NULL) { ErrorMessage_ ("garlic", "ReadPDBFile", "", "Failed to allocate memory for header data!\n", "", "", ""); fclose (fileP); return -2; } /* Initialize the unique PDB identifier: */ strcpy (mol_complexSP->unique_PDB_codeA, "XXXX"); /* Initialize the memory reserved for text and initialize offsets: */ InitializeHeader_ (&mol_complexSP->headerS); /* Allocate the initial amount of memory for atomic coordinates: */ mol_complexSP->atomsN = 0; /* It was zero before, this is just a reminder */ mol_complexSP->max_atomsN = ATOMS_IN_CHUNK; memory_size = mol_complexSP->max_atomsN * sizeof (AtomS); if ((mol_complexSP->atomSP = (AtomS *) malloc (memory_size)) == NULL) { ErrorMessage_ ("garlic", "ReadPDBFile_", "", "Failed to allocate memory for atomic data!\n", "", "", ""); fclose (fileP); return -3; } curr_atomSP = mol_complexSP->atomSP; /* Prepare the size of the RGBS structure: */ rgb_struct_size = sizeof (RGBS); /* Read the entire file, line by line: */ line_size = sizeof (lineA); while (fgets (lineA, line_size, fileP)) { /* Prepare the first character, it will be used */ /* to speed up the recognition of record type: */ first_char = *lineA; /* Check is there a chance that input line is ATOM or HETATM record: */ rec_typeI = 0; switch (first_char) { case 'A': if (strstr (lineA, "ATOM") == lineA) rec_typeI = 1; break; case 'H': if (strstr (lineA, "HETATM") == lineA) rec_typeI = 2; break; default: ; } /* Extract data if input line contains ATOM or HETATM record: */ if (rec_typeI > 0) { /** Try to parse ATOM or HETATM line: **/ if (ParsePDBAtomicData_ (curr_atomSP, lineA) < 0) continue; /** If this point is reached, parsing was successful! **/ /** The initial drawing style for atoms: **/ curr_atomSP->raw_atomS.atom_styleI = configSP->default_atom_styleI; /** Copy the model serial number: **/ curr_atomSP->raw_atomS.model_serialI = model_serialI; /** By default, after loading the atom is selected: **/ curr_atomSP->selectedF = 1; /** By default, the atom is not hidden: **/ curr_atomSP->hiddenF = 0; /** By default, the atom is inside the slab: **/ curr_atomSP->inside_slabF = 1; /** By default, atomic label is hidden: **/ curr_atomSP->labelF = 0; /** Set flag which distinguishes ATOM and HETATM data: **/ if (rec_typeI == 1) curr_atomSP->raw_atomS.heteroF = 0; else curr_atomSP->raw_atomS.heteroF = 1; /** Set the number of color fading surfaces: **/ curr_atomSP->surfacesN = configSP->default_surfacesN; /** Copy default basic colors: **/ for (n = 0; n < MAXCOLORSURFACES; n++) { memcpy (curr_atomSP->left_rgbSA + n, configSP->left_rgbSA + n, rgb_struct_size); memcpy (curr_atomSP->middle_rgbSA + n, configSP->middle_rgbSA + n, rgb_struct_size); memcpy (curr_atomSP->right_rgbSA + n, configSP->right_rgbSA + n, rgb_struct_size); } /** Increase the number of atoms, update pointer: **/ mol_complexSP->atomsN++; curr_atomSP++; /** Check is there enough memory left; reallocate if not: **/ n = ReallocPDBMemory_ (&mol_complexSP->atomSP, &curr_atomSP, &mol_complexSP->max_atomsN, mol_complexSP->atomsN); /*** If reallocation fails, close file and return: ***/ if (n < 0) { mol_complexSP->atomsN = 0; fclose (fileP); return -4; } /** Take the next line: **/ continue; } /* Check is there a keyword MODEL in this line (NMR structures): */ if (strstr (lineA, "MODEL") == lineA) { /* Check the line length (do not */ /* forget that newline is there): */ if ((int) strlen (lineA) < model_serial_end + 2) continue; /* Try to read the model serial number: */ P = lineA + model_serial_start; if (sscanf (P, "%d", &n) != 1) continue; /* Update the model serial number: */ model_serialI = n; /** Take the next line: **/ continue; } /* Check for records which are mandatory */ /* but do not contain atomic coordinates: */ /* (ATOM and HETATM are not mandatory!) */ CopyHeaderLine_ (&mol_complexSP->headerS, lineA, first_char); /* Check for the unique PDB identifier, if not found before: */ if (!PDB_ID_foundF) { n = PDBIdentifier_ (mol_complexSP, lineA); if (n > 0) PDB_ID_foundF = 1; } } /* Close file: */ fclose (fileP); /* Set the flag which forces projection of coordinates: */ mol_complexSP->position_changedF = 1; /* Return positive value on success: */ return 1; } /*===========================================================================*/ garlic-1.6/select_tm.c0000644000076500007650000001067007642050542015242 0ustar zuciczucic00000000000000/* Copyright (C) 2003 Damir Zucic */ /*============================================================================= select_tm.c Purpose: Select transmembrane part of the macromolecular complex. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. (3) Selection mode index (0 = overwrite, 1 = restrict, 2 = expand previous selection). Output: (1) The flag selectedF set to one for selected atoms in every caught macromolecular complex. (2) Return value. Return value: (1) The number of selected atoms (zero or positive value). Notes: (1) Half of the membrane thickness is expanded by two angstroms to include atoms which are outside, but close to the membrane. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ double ScalarProduct_ (VectorS *, VectorS *); /*======select transmembrane part:===========================================*/ long SelectTM_ (MolComplexS *mol_complexSP, int mol_complexesN, int selection_modeI) { long selected_atomsN = 0; int mol_complexI; MolComplexS *curr_mol_complexSP; size_t atomsN, atomI; VectorS normal_vectorS; double membrane_center_x, membrane_center_y, membrane_center_z; double half_thickness; AtomS *curr_atomSP; double x, y, z; VectorS curr_vectorS; int transmembraneF; double projection; double absolute_value; /* Select all atoms above the plane: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check is the current macromolecular complex caught: */ if (curr_mol_complexSP->catchF == 0) continue; /* Number of atoms in a macromolecular complex: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Check is membrane defined at all: */ if (curr_mol_complexSP->membraneS.definedF == 0) continue; /* The normal vector: */ normal_vectorS.x = curr_mol_complexSP->membraneS.plane1S.normal_x[0]; normal_vectorS.y = curr_mol_complexSP->membraneS.plane1S.normal_y; normal_vectorS.z = curr_mol_complexSP->membraneS.plane1S.normal_z[0]; /* Position of the plane center: */ membrane_center_x = curr_mol_complexSP->membraneS.center_x; membrane_center_y = curr_mol_complexSP->membraneS.center_y; membrane_center_z = curr_mol_complexSP->membraneS.center_z; /* Half of the membrane thickness enlarged by a margin of */ /* two angstroms. This margin allows inclusion of some */ /* atoms which are outside the TM area, but not too far. */ half_thickness = 0.5 * curr_mol_complexSP->membraneS.thickness + 2.0; /* Scan all atoms in the current complex: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Copy the coordinates: */ x = curr_atomSP->raw_atomS.x[0]; y = curr_atomSP->raw_atomS.y; z = curr_atomSP->raw_atomS.z[0]; /* Position of the atom relative to the membrane center: */ curr_vectorS.x = x - membrane_center_x; curr_vectorS.y = y - membrane_center_y; curr_vectorS.z = z - membrane_center_z; /* Reset the flag: */ transmembraneF = 0; /* Check the scalar product with the unit direction vector: */ projection = ScalarProduct_ (&curr_vectorS, &normal_vectorS); /* Take the absolute value: */ absolute_value = fabs (projection); /* Compare this value with half of the membrane thickness: */ if (absolute_value <= half_thickness) transmembraneF = 1; /* Set the selection flag for the current atom: */ switch (selection_modeI) { /* Overwrite the previous selection: */ case 0: curr_atomSP->selectedF = transmembraneF; break; /* Restrict the previous selection: */ case 1: curr_atomSP->selectedF &= transmembraneF; break; /* Expand the previous selection: */ case 2: curr_atomSP->selectedF |= transmembraneF; break; default: ; } /* Check the selection flag; increase */ /* the count if flag is equal to one: */ if (curr_atomSP->selectedF) selected_atomsN++; } } /* Return the number of selected atoms: */ return selected_atomsN; } /*===========================================================================*/ garlic-1.6/set_chi1.c0000644000076500007650000001351607415612642014767 0ustar zuciczucic00000000000000/* Copyright (C) 2001, 2002 Damir Zucic */ /*============================================================================= set_chi1.c Purpose: Set the chi1 angle for each selected residue in the given complex. A residue is treated as selected if the first atom of this residue is selected. For proteins, this is typically the N atom (nitrogen). Input: (1) Pointer to MolComplexS structure. (2) Pointer to ConfigS structure. (3) The chi1 angle in degrees. Output: (1) Chi1 set for each selected residue in each caught complex. (2) Return value. Return value: (1) Positive always (trivial). Notes: (1) This function ignores ALA, GLY and PRO. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int IsStandard_ (char *); double Chi1FromNCACBCG_ (AtomS *, size_t, size_t); double Chi1FromNCACBSG_ (AtomS *, size_t, size_t); double Chi1FromNCACBCG1_ (AtomS *, size_t, size_t); double Chi1FromNCACBOG_ (AtomS *, size_t, size_t); double Chi1FromNCACBOG1_ (AtomS *, size_t, size_t); int ExtractCACB_ (VectorS *, VectorS *, AtomS *, size_t, size_t); int RotateAtom_ (AtomS *, VectorS *, VectorS *, double); int DihedralAngles_ (MolComplexS *, ConfigS *); /*======set chi1:============================================================*/ int SetChi1_ (MolComplexS *mol_complexSP, ConfigS *configSP, double chi1_new) { int residuesN, residueI; size_t atomsN, atomI; ResidueS *current_residueSP; AtomS *first_atomSP; char *residue_nameP; size_t current_startI, current_endI; int residue_typeI; double chi1_old, delta_chi1; int n; static VectorS CA_vectorS, CB_vectorS; AtomS *atomSP; char *atom_nameP; /* Copy the number of residues in the specified complex: */ residuesN = mol_complexSP->residuesN; /* Copy the number of atoms in the specified complex: */ atomsN = mol_complexSP->atomsN; /* Scan the residues: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Pointer to the current residue: */ current_residueSP = mol_complexSP->residueSP + residueI; /* Pointer to the first atom of this residue: */ first_atomSP = mol_complexSP->atomSP + current_residueSP->residue_startI; /* If the first atom of this residue is not */ /* selected, the residue is not selected: */ if (first_atomSP->selectedF == 0) continue; /* The name of the current residue: */ residue_nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* The range of atomic indices for the current residue: */ current_startI = current_residueSP->residue_startI; current_endI = current_residueSP->residue_endI; /* Check is the current residue from */ /* the set of 20 standard residues: */ residue_typeI = IsStandard_ (residue_nameP); /* Do nothing for ALA, GLY and PRO: */ if ((residue_typeI == 0) || (residue_typeI == 7) || (residue_typeI == 14)) continue; /* Now calculate and check the old chi1 value. */ /* Initialize the old chi1: */ chi1_old = BADDIHEDANGLE; /* Calculate the chi1_old: */ switch (residue_typeI) { /* Use N, CA, CB and CG for ARG, ASN, ASP, GLN, */ /* GLU, HIS, LEU, LYS, MET, PHE, TRP and TYR: */ case 1: /* ARG */ case 2: /* ASN */ case 3: /* ASP */ case 5: /* GLN */ case 6: /* GLU */ case 8: /* HIS */ case 10: /* LEU */ case 11: /* LYS */ case 12: /* MET */ case 13: /* PHE */ case 17: /* TRP */ case 18: /* TYR */ chi1_old = Chi1FromNCACBCG_ (mol_complexSP->atomSP, current_startI, current_endI); break; /* Use N, CA, CB and SG for CYS: */ case 4: /* CYS */ chi1_old = Chi1FromNCACBSG_ (mol_complexSP->atomSP, current_startI, current_endI); break; /* Use N, CA, CB and CG1 for ILE and VAL: */ case 9: /* ILE */ case 19: /* VAL */ chi1_old = Chi1FromNCACBCG1_ (mol_complexSP->atomSP, current_startI, current_endI); break; /* Use N, CA, CB and OG for SER: */ case 15: /* SER */ chi1_old = Chi1FromNCACBOG_ (mol_complexSP->atomSP, current_startI, current_endI); break; /* Use N, CA, CB and OG1 for THR: */ case 16: /* THR */ chi1_old = Chi1FromNCACBOG1_ (mol_complexSP->atomSP, current_startI, current_endI); break; /* At present, exotic residues are ignored: */ default: ; } /* Check the value: */ if (chi1_old == BADDIHEDANGLE) continue; /* Calculate the difference: */ delta_chi1 = chi1_new - chi1_old; /* Extract CA and CB coordinates: */ n = ExtractCACB_ (&CA_vectorS, &CB_vectorS, mol_complexSP->atomSP, current_startI, current_endI); if (n < 2) continue; /* Change the chi1 angle: */ for (atomI = current_startI; atomI <= current_endI; atomI++) { /* Pointer to the current atom: */ atomSP = mol_complexSP->atomSP + atomI; /* Pointer to the purified atom name: */ atom_nameP = atomSP->raw_atomS.pure_atom_nameA; /* Do not rotate H, N, CA, HA, C, O and CB: */ if (strcmp (atom_nameP, "H" ) == 0) continue; if (strcmp (atom_nameP, "N" ) == 0) continue; if (strcmp (atom_nameP, "CA") == 0) continue; if (strcmp (atom_nameP, "HA") == 0) continue; if (strcmp (atom_nameP, "C" ) == 0) continue; if (strcmp (atom_nameP, "O" ) == 0) continue; if (strcmp (atom_nameP, "CB") == 0) continue; /* Rotate the current atom about CA-CB bond: */ RotateAtom_ (atomSP, &CA_vectorS, &CB_vectorS, delta_chi1); } } /* Update dihedral angles and cis-trans flags: */ DihedralAngles_ (mol_complexSP, configSP); /* Set the position_changedF: */ mol_complexSP->position_changedF = 1; /* Return positive value (trivial): */ return 1; } /*===========================================================================*/ garlic-1.6/set_chi2.c0000644000076500007650000001421007415612652014761 0ustar zuciczucic00000000000000/* Copyright (C) 2001, 2002 Damir Zucic */ /*============================================================================= set_chi2.c Purpose: Set the chi2 angle for each selected residue in the given complex. A residue is treated as selected if the first atom of this residue is selected. For proteins, this is typically the N atom (nitrogen). Input: (1) Pointer to MolComplexS structure. (2) Pointer to ConfigS structure. (3) The chi2 angle in degrees. Output: (1) Chi2 set for each selected residue in each caught complex. (2) Return value. Return value: (1) Positive always (trivial). Notes: (1) This function ignores ALA, CYS, GLY, PRO, SER, THR and VAL. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int IsStandard_ (char *); double Chi2FromCACBCGCD_ (AtomS *, size_t, size_t); double Chi2FromCACBCGOD1_ (AtomS *, size_t, size_t); double Chi2FromCACBCGND1_ (AtomS *, size_t, size_t); double Chi2FromCACBCG1CD_ (AtomS *, size_t, size_t); double Chi2FromCACBCGCD1_ (AtomS *, size_t, size_t); double Chi2FromCACBCGSD_ (AtomS *, size_t, size_t); int ExtractCBXG_ (VectorS *, VectorS *, AtomS *, size_t, size_t); int RotateAtom_ (AtomS *, VectorS *, VectorS *, double); int DihedralAngles_ (MolComplexS *, ConfigS *); /*======set chi2:============================================================*/ int SetChi2_ (MolComplexS *mol_complexSP, ConfigS *configSP, double chi2_new) { int residuesN, residueI; size_t atomsN, atomI; ResidueS *current_residueSP; AtomS *first_atomSP; char *residue_nameP; size_t current_startI, current_endI; int residue_typeI; double chi2_old, delta_chi2; int n; static VectorS CB_vectorS, XG_vectorS; AtomS *atomSP; char *atom_nameP; /* Copy the number of residues in the specified complex: */ residuesN = mol_complexSP->residuesN; /* Copy the number of atoms in the specified complex: */ atomsN = mol_complexSP->atomsN; /* Scan the residues: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Pointer to the current residue: */ current_residueSP = mol_complexSP->residueSP + residueI; /* Pointer to the first atom of this residue: */ first_atomSP = mol_complexSP->atomSP + current_residueSP->residue_startI; /* If the first atom of this residue is not */ /* selected, the residue is not selected: */ if (first_atomSP->selectedF == 0) continue; /* The name of the current residue: */ residue_nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* The range of atomic indices for the current residue: */ current_startI = current_residueSP->residue_startI; current_endI = current_residueSP->residue_endI; /* Check is the current residue from */ /* the set of 20 standard residues: */ residue_typeI = IsStandard_ (residue_nameP); /* Do nothing for ALA, CYS, GLY, PRO, SER, THR and VAL: */ if ((residue_typeI == 0) || (residue_typeI == 4) || (residue_typeI == 7) || (residue_typeI == 14) || (residue_typeI == 15) || (residue_typeI == 16) || (residue_typeI == 19)) continue; /* Now calculate and check the old chi2 value. */ /* Initialize the old chi2: */ chi2_old = BADDIHEDANGLE; /* Calculate the chi2_old: */ switch (residue_typeI) { /* Use CA, CB, CG and CD for ARG, GLN, GLU, LYS: */ case 1: /* ARG */ case 5: /* GLN */ case 6: /* GLU */ case 11: /* LYS */ chi2_old =Chi2FromCACBCGCD_ (mol_complexSP->atomSP, current_startI, current_endI); break; /* Use CA, CB, CG and OD1 for ASN and ASP: */ case 2: /* ASN */ case 3: /* ASP */ chi2_old =Chi2FromCACBCGOD1_ (mol_complexSP->atomSP, current_startI, current_endI); break; /* Use CA, CB, CG and ND1 for HIS: */ case 8: /* HIS */ chi2_old =Chi2FromCACBCGND1_ (mol_complexSP->atomSP, current_startI, current_endI); break; /* Use CA, CB, CG1 and CD for ILE: */ case 9: /* ILE */ chi2_old =Chi2FromCACBCG1CD_ (mol_complexSP->atomSP, current_startI, current_endI); break; /* Use CA, CB, CG and CD1 for LEU, PHE, TRP and TYR: */ case 10: /* LEU */ case 13: /* PHE */ case 17: /* TRP */ case 18: /* TYR */ chi2_old =Chi2FromCACBCGCD1_ (mol_complexSP->atomSP, current_startI, current_endI); break; /* Use CA, CB, CG and SD for MET: */ case 12: /* MET */ chi2_old =Chi2FromCACBCGSD_ (mol_complexSP->atomSP, current_startI, current_endI); break; /* At present, exotic residues are ignored: */ default: ; } /* Check the value: */ if (chi2_old == BADDIHEDANGLE) continue; /* Calculate the difference: */ delta_chi2 = chi2_new - chi2_old; /* Extract CB and XG coordinates: */ n = ExtractCBXG_ (&CB_vectorS, &XG_vectorS, mol_complexSP->atomSP, current_startI, current_endI); if (n < 2) continue; /* Change the chi2 angle: */ for (atomI = current_startI; atomI <= current_endI; atomI++) { /* Pointer to the current atom: */ atomSP = mol_complexSP->atomSP + atomI; /* Pointer to the purified atom name: */ atom_nameP = atomSP->raw_atomS.pure_atom_nameA; /* Do not rotate H, N, CA, HA, C, O, CB and HB: */ if (strcmp (atom_nameP, "H" ) == 0) continue; if (strcmp (atom_nameP, "N" ) == 0) continue; if (strcmp (atom_nameP, "CA") == 0) continue; if (strcmp (atom_nameP, "HA") == 0) continue; if (strcmp (atom_nameP, "C" ) == 0) continue; if (strcmp (atom_nameP, "O" ) == 0) continue; if (strcmp (atom_nameP, "CB") == 0) continue; if (strcmp (atom_nameP, "HB") == 0) continue; /* Rotate the current atom about CB-XG bond: */ RotateAtom_ (atomSP, &CB_vectorS, &XG_vectorS, delta_chi2); } } /* Update dihedral angles and cis-trans flags: */ DihedralAngles_ (mol_complexSP, configSP); /* Set the position_changedF: */ mol_complexSP->position_changedF = 1; /* Return positive value (trivial): */ return 1; } /*===========================================================================*/ garlic-1.6/set_chi3.c0000644000076500007650000001316407415612631014766 0ustar zuciczucic00000000000000/* Copyright (C) 2001, 2002 Damir Zucic */ /*============================================================================= set_chi3.c Purpose: Set the chi3 angle for each selected residue in the given complex. A residue is treated as selected if the first atom of this residue is selected. For proteins, this is typically the N atom (nitrogen). Input: (1) Pointer to MolComplexS structure. (2) Pointer to ConfigS structure. (3) The chi3 angle in degrees. Output: (1) Chi3 set for each selected residue in each caught complex. (2) Return value. Return value: (1) Positive always (trivial). Notes: (1) This function sets the chi3 angle for ARG, GLN, GLU, LYS and MET. All other residues are ignored. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int IsStandard_ (char *); double Chi3FromCBCGCDNE_ (AtomS *, size_t, size_t); double Chi3FromCBCGCDOE1_ (AtomS *, size_t, size_t); double Chi3FromCBCGCDCE_ (AtomS *, size_t, size_t); double Chi3FromCBCGSDCE_ (AtomS *, size_t, size_t); int ExtractCGXD_ (VectorS *, VectorS *, AtomS *, size_t, size_t); int RotateAtom_ (AtomS *, VectorS *, VectorS *, double); int DihedralAngles_ (MolComplexS *, ConfigS *); /*======set chi3:============================================================*/ int SetChi3_ (MolComplexS *mol_complexSP, ConfigS *configSP, double chi3_new) { int residuesN, residueI; size_t atomsN, atomI; ResidueS *current_residueSP; AtomS *first_atomSP; char *residue_nameP; size_t current_startI, current_endI; int residue_typeI; double chi3_old, delta_chi3; int n; static VectorS CG_vectorS, XD_vectorS; AtomS *atomSP; char *atom_nameP; /* Copy the number of residues in the specified complex: */ residuesN = mol_complexSP->residuesN; /* Copy the number of atoms in the specified complex: */ atomsN = mol_complexSP->atomsN; /* Scan the residues: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Pointer to the current residue: */ current_residueSP = mol_complexSP->residueSP + residueI; /* Pointer to the first atom of this residue: */ first_atomSP = mol_complexSP->atomSP + current_residueSP->residue_startI; /* If the first atom of this residue is not */ /* selected, the residue is not selected: */ if (first_atomSP->selectedF == 0) continue; /* The name of the current residue: */ residue_nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* The range of atomic indices for the current residue: */ current_startI = current_residueSP->residue_startI; current_endI = current_residueSP->residue_endI; /* Check is the current residue from */ /* the set of 20 standard residues: */ residue_typeI = IsStandard_ (residue_nameP); /* This function works for ARG, GLN, GLU, LYS and MET: */ if ((residue_typeI != 1) && (residue_typeI != 5) && (residue_typeI != 6) && (residue_typeI != 11) && (residue_typeI != 12)) continue; /* Now calculate and check the old chi3 value. */ /* Initialize the old chi3: */ chi3_old = BADDIHEDANGLE; /* Calculate the chi3_old: */ switch (residue_typeI) { /* Use CB, CG, CD and NE for ARG: */ case 1: /* ARG */ chi3_old = Chi3FromCBCGCDNE_ (mol_complexSP->atomSP, current_startI, current_endI); break; /* Use CB, CG, CD and OE1 for GLN and GLU: */ case 5: /* GLN */ case 6: /* GLU */ chi3_old = Chi3FromCBCGCDOE1_ (mol_complexSP->atomSP, current_startI, current_endI); break; /* Use CB, CG, CD and CE for LYS: */ case 11: /* LYS */ chi3_old = Chi3FromCBCGCDCE_ (mol_complexSP->atomSP, current_startI, current_endI); break; /* Use CB, CG, SD and CE for MET: */ case 12: /* MET */ chi3_old = Chi3FromCBCGSDCE_ (mol_complexSP->atomSP, current_startI, current_endI); break; /* At present, exotic residues are ignored: */ default: ; } /* Check the value: */ if (chi3_old == BADDIHEDANGLE) continue; /* Calculate the difference: */ delta_chi3 = chi3_new - chi3_old; /* Extract CG and XD coordinates: */ n = ExtractCGXD_ (&CG_vectorS, &XD_vectorS, mol_complexSP->atomSP, current_startI, current_endI); if (n < 2) continue; /* Change the chi3 angle: */ for (atomI = current_startI; atomI <= current_endI; atomI++) { /* Pointer to the current atom: */ atomSP = mol_complexSP->atomSP + atomI; /* Pointer to the purified atom name: */ atom_nameP = atomSP->raw_atomS.pure_atom_nameA; /* Do not rotate H, N, CA, HA, C, O, CB, HB, CG and HG: */ if (strcmp (atom_nameP, "H" ) == 0) continue; if (strcmp (atom_nameP, "N" ) == 0) continue; if (strcmp (atom_nameP, "CA") == 0) continue; if (strcmp (atom_nameP, "HA") == 0) continue; if (strcmp (atom_nameP, "C" ) == 0) continue; if (strcmp (atom_nameP, "O" ) == 0) continue; if (strcmp (atom_nameP, "CB") == 0) continue; if (strcmp (atom_nameP, "HB") == 0) continue; if (strcmp (atom_nameP, "CG") == 0) continue; if (strcmp (atom_nameP, "HG") == 0) continue; /* Rotate the current atom about CG-XD bond: */ RotateAtom_ (atomSP, &CG_vectorS, &XD_vectorS, delta_chi3); } } /* Update dihedral angles and cis-trans flags: */ DihedralAngles_ (mol_complexSP, configSP); /* Set the position_changedF: */ mol_complexSP->position_changedF = 1; /* Return positive value (trivial): */ return 1; } /*===========================================================================*/ garlic-1.6/set_chi4.c0000644000076500007650000001215707415612661014773 0ustar zuciczucic00000000000000/* Copyright (C) 2001, 2002 Damir Zucic */ /*============================================================================= set_chi4.c Purpose: Set the chi4 angle for each selected residue in the given complex. A residue is treated as selected if the first atom of this residue is selected. For proteins, this is typically the N atom (nitrogen). Input: (1) Pointer to MolComplexS structure. (2) Pointer to ConfigS structure. (3) The chi4 angle in degrees. Output: (1) Chi4 set for each selected residue in each caught complex. (2) Return value. Return value: (1) Positive always (trivial). Notes: (1) This function sets the chi4 angle for ARG and LYS. All other residues are ignored. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int IsStandard_ (char *); double Chi4FromCGCDNECZ_ (AtomS *, size_t, size_t); double Chi4FromCGCDCENZ_ (AtomS *, size_t, size_t); int ExtractCDXE_ (VectorS *, VectorS *, AtomS *, size_t, size_t); int RotateAtom_ (AtomS *, VectorS *, VectorS *, double); int DihedralAngles_ (MolComplexS *, ConfigS *); /*======set chi4:============================================================*/ int SetChi4_ (MolComplexS *mol_complexSP, ConfigS *configSP, double chi4_new) { int residuesN, residueI; size_t atomsN, atomI; ResidueS *current_residueSP; AtomS *first_atomSP; char *residue_nameP; size_t current_startI, current_endI; int residue_typeI; double chi4_old, delta_chi4; int n; static VectorS CD_vectorS, XE_vectorS; AtomS *atomSP; char *atom_nameP; /* Copy the number of residues in the specified complex: */ residuesN = mol_complexSP->residuesN; /* Copy the number of atoms in the specified complex: */ atomsN = mol_complexSP->atomsN; /* Scan the residues: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Pointer to the current residue: */ current_residueSP = mol_complexSP->residueSP + residueI; /* Pointer to the first atom of this residue: */ first_atomSP = mol_complexSP->atomSP + current_residueSP->residue_startI; /* If the first atom of this residue is not */ /* selected, the residue is not selected: */ if (first_atomSP->selectedF == 0) continue; /* The name of the current residue: */ residue_nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* The range of atomic indices for the current residue: */ current_startI = current_residueSP->residue_startI; current_endI = current_residueSP->residue_endI; /* Check is the current residue from */ /* the set of 20 standard residues: */ residue_typeI = IsStandard_ (residue_nameP); /* This function works for ARG and LYS: */ if ((residue_typeI != 1) && (residue_typeI != 11)) continue; /* Now calculate and check the old chi4 value. */ /* Initialize the old chi4: */ chi4_old = BADDIHEDANGLE; /* Calculate the chi4_old: */ switch (residue_typeI) { /* Use CG, CD, NE and CZ for ARG: */ case 1: /* ARG */ chi4_old = Chi4FromCGCDNECZ_ (mol_complexSP->atomSP, current_startI, current_endI); break; /* Use CG, CD, NE and CZ for LYS: */ case 11: chi4_old = Chi4FromCGCDCENZ_ (mol_complexSP->atomSP, current_startI, current_endI); break; /* At present, exotic residues are ignored: */ default: ; } /* Check the value: */ if (chi4_old == BADDIHEDANGLE) continue; /* Calculate the difference: */ delta_chi4 = chi4_new - chi4_old; /* Extract CD and XE coordinates: */ n = ExtractCDXE_ (&CD_vectorS, &XE_vectorS, mol_complexSP->atomSP, current_startI, current_endI); if (n < 2) continue; /* Change the chi4 angle: */ for (atomI = current_startI; atomI <= current_endI; atomI++) { /* Pointer to the current atom: */ atomSP = mol_complexSP->atomSP + atomI; /* Pointer to the purified atom name: */ atom_nameP = atomSP->raw_atomS.pure_atom_nameA; /* Do not rotate H, N, CA, HA, C, */ /* O, CB, HB, CG, HG, CD and HD: */ if (strcmp (atom_nameP, "H" ) == 0) continue; if (strcmp (atom_nameP, "N" ) == 0) continue; if (strcmp (atom_nameP, "CA") == 0) continue; if (strcmp (atom_nameP, "HA") == 0) continue; if (strcmp (atom_nameP, "C" ) == 0) continue; if (strcmp (atom_nameP, "O" ) == 0) continue; if (strcmp (atom_nameP, "CB") == 0) continue; if (strcmp (atom_nameP, "HB") == 0) continue; if (strcmp (atom_nameP, "CG") == 0) continue; if (strcmp (atom_nameP, "HG") == 0) continue; if (strcmp (atom_nameP, "CD") == 0) continue; if (strcmp (atom_nameP, "HD") == 0) continue; /* Rotate the current atom about CD-XE bond: */ RotateAtom_ (atomSP, &CD_vectorS, &XE_vectorS, delta_chi4); } } /* Update dihedral angles and cis-trans flags: */ DihedralAngles_ (mol_complexSP, configSP); /* Set the position_changedF: */ mol_complexSP->position_changedF = 1; /* Return positive value (trivial): */ return 1; } /*===========================================================================*/ garlic-1.6/set_chi5.c0000644000076500007650000001157007415612745014775 0ustar zuciczucic00000000000000/* Copyright (C) 2001, 2002 Damir Zucic */ /*============================================================================= set_chi5.c Purpose: Set the chi5 angle for each selected residue in the given complex. A residue is treated as selected if the first atom of this residue is selected. For proteins, this is typically the N atom (nitrogen). Input: (1) Pointer to MolComplexS structure. (2) Pointer to ConfigS structure. (3) The chi5 angle in degrees. Output: (1) Chi5 set for each selected residue in each caught complex. (2) Return value. Return value: (1) Positive always (trivial). Notes: (1) This function sets the chi5 angle for ARG. All other residues are ignored. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int IsStandard_ (char *); double Chi5FromCDNECZNH1_ (AtomS *, size_t, size_t); int ExtractNECZ_ (VectorS *, VectorS *, AtomS *, size_t, size_t); int RotateAtom_ (AtomS *, VectorS *, VectorS *, double); int DihedralAngles_ (MolComplexS *, ConfigS *); /*======set chi5:============================================================*/ int SetChi5_ (MolComplexS *mol_complexSP, ConfigS *configSP, double chi5_new) { int residuesN, residueI; size_t atomsN, atomI; ResidueS *current_residueSP; AtomS *first_atomSP; char *residue_nameP; size_t current_startI, current_endI; int residue_typeI; double chi5_old, delta_chi5; int n; static VectorS NE_vectorS, CZ_vectorS; AtomS *atomSP; char *atom_nameP; /* Copy the number of residues in the specified complex: */ residuesN = mol_complexSP->residuesN; /* Copy the number of atoms in the specified complex: */ atomsN = mol_complexSP->atomsN; /* Scan the residues: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Pointer to the current residue: */ current_residueSP = mol_complexSP->residueSP + residueI; /* Pointer to the first atom of this residue: */ first_atomSP = mol_complexSP->atomSP + current_residueSP->residue_startI; /* If the first atom of this residue is not */ /* selected, the residue is not selected: */ if (first_atomSP->selectedF == 0) continue; /* The name of the current residue: */ residue_nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* The range of atomic indices for the current residue: */ current_startI = current_residueSP->residue_startI; current_endI = current_residueSP->residue_endI; /* Check is the current residue from */ /* the set of 20 standard residues: */ residue_typeI = IsStandard_ (residue_nameP); /* This function works for ARG only: */ if (residue_typeI != 1) continue; /* Now calculate and check the old chi5 value. */ /* Initialize the old chi5: */ chi5_old = BADDIHEDANGLE; /* Calculate the chi5_old (the residue */ /* is ARG if this point is reached): */ /* Use CD, NE, CZ and NH1 for ARG: */ chi5_old = Chi5FromCDNECZNH1_ (mol_complexSP->atomSP, current_startI, current_endI); /* Check the value: */ if (chi5_old == BADDIHEDANGLE) continue; /* Calculate the difference: */ delta_chi5 = chi5_new - chi5_old; /* Extract NE and CZ coordinates: */ n = ExtractNECZ_ (&NE_vectorS, &CZ_vectorS, mol_complexSP->atomSP, current_startI, current_endI); if (n < 2) continue; /* Change the chi5 angle: */ for (atomI = current_startI; atomI <= current_endI; atomI++) { /* Pointer to the current atom: */ atomSP = mol_complexSP->atomSP + atomI; /* Pointer to the purified atom name: */ atom_nameP = atomSP->raw_atomS.pure_atom_nameA; /* Do not rotate H, N, CA, HA, C, O, */ /* CB, HB, CG, HG, CD, HD, NE and HE: */ if (strcmp (atom_nameP, "H" ) == 0) continue; if (strcmp (atom_nameP, "N" ) == 0) continue; if (strcmp (atom_nameP, "CA") == 0) continue; if (strcmp (atom_nameP, "HA") == 0) continue; if (strcmp (atom_nameP, "C" ) == 0) continue; if (strcmp (atom_nameP, "O" ) == 0) continue; if (strcmp (atom_nameP, "CB") == 0) continue; if (strcmp (atom_nameP, "HB") == 0) continue; if (strcmp (atom_nameP, "CG") == 0) continue; if (strcmp (atom_nameP, "HG") == 0) continue; if (strcmp (atom_nameP, "CD") == 0) continue; if (strcmp (atom_nameP, "HD") == 0) continue; if (strcmp (atom_nameP, "NE") == 0) continue; if (strcmp (atom_nameP, "HE") == 0) continue; /* Rotate the current atom about NE-CZ bond: */ RotateAtom_ (atomSP, &NE_vectorS, &CZ_vectorS, delta_chi5); } } /* Update dihedral angles and cis-trans flags: */ DihedralAngles_ (mol_complexSP, configSP); /* Set the position_changedF: */ mol_complexSP->position_changedF = 1; /* Return positive value (trivial): */ return 1; } /*===========================================================================*/ garlic-1.6/two-positive.script0000644000076500007650000000043410120261673017005 0ustar zuciczucic00000000000000# Playing with porin. # please load some porin structure before executing this script! backbone 4 color cyan-blue select hetero sel com sequence from 1 pattern = arg lys his / arg lys his select pattern color red pattern = arg lys his / * /arg lys his select pattern color magenta garlic-1.6/draw_planes.c0000644000076500007650000002034307150760733015564 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= draw_planes.c Purpose: Draw plane for each macromolecular complex. Only visible planes will be drawn. Input: (1) Pointer to MolComplexS structure. (2) Number of macromolecular complexes. (3) Pointer to ConfigS structure, with configuration data. (4) Pointer to GUIS structure. (5) Pointer to NearestAtomS structure, with information about the atom occupying the given pixel. (6) The number of pixels in the main window free area. (7) The refreshI, used to check the NearestAtomS associated with a given pixel. Output: (1) Plane drawn for each macromolecular complex, if visible. (2) Return value. Return value: (1) Positive always (trivial). Notes: (1) Indentation is exceptionally 4 spaces. =============================================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ void PlaneExtent_ (int *, int *, int *, int *, PlaneS *, ConfigS *, int); unsigned long WeightColors_ (unsigned long, unsigned long, double, GUIS *); /*======draw planes:=========================================================*/ int DrawPlanes_ (MolComplexS *mol_complexSP, int mol_complexesN, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int refreshI) { int imagesN, imageI; int mol_complexI; MolComplexS *curr_mol_complexSP; size_t atomsN; PlaneS *curr_planeSP; int center_screen_x, center_screen_y; double angle, sin_angle, cos_angle; double reciprocal_a, reciprocal_b; double reciprocal_diameter; double coeff; int screen_x_min, screen_x_max, screen_y_min, screen_y_max; int screen_x, screen_y; double x_relative, y_relative, x_rotated, y_rotated; double ratio_x, ratio_y, d; double plane_delta_z, plane_z; size_t pixelI; NearestAtomS *curr_pixelSP; double scale_factor; unsigned long plane_colorID, old_colorID, colorID; /* Number of images: */ if (configSP->stereoF) imagesN = 2; else imagesN = 1; /* Draw plane, if visible, for each macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Prepare and check the number of atoms: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Pointer to the current plane: */ curr_planeSP = &curr_mol_complexSP->planeS; /* Check is the current plane hidden: */ if (curr_planeSP->hiddenF) continue; /* Draw one image (mono) or two images (stereo): */ for (imageI = 0; imageI < imagesN; imageI++) { /* Plane center position: */ center_screen_x = curr_planeSP->center_screen_x[imageI]; center_screen_y = curr_planeSP->center_screen_y; /* The shifted phi angle, used to rotate */ /* the rectangle bounding the ellipsa : */ angle = curr_planeSP->normal_phi[imageI] - 4.712389; /* Sine and cosine of this angle: */ sin_angle = sin (angle); cos_angle = cos (angle); /* Reciprocal values of half axes: */ if (curr_planeSP->screen_a == 0.0) reciprocal_a = 0.0; else reciprocal_a = 1.0 / curr_planeSP->screen_a; if (curr_planeSP->screen_b[imageI] == 0.0) reciprocal_b = 0.0; else reciprocal_b = 1.0 / curr_planeSP->screen_b[imageI]; /* Reciprocal diameter (required for color fading effect): */ if (curr_planeSP->circle_radius == 0.0) reciprocal_diameter = 0.0; else reciprocal_diameter = 0.5 / curr_planeSP->circle_radius; /* The coefficient used to calculate z value for a given pixel: */ if (curr_planeSP->screen_b[imageI] == 0.0) coeff = 0.0; else { coeff = curr_planeSP->circle_radius * sin (curr_planeSP->normal_theta[imageI]) / curr_planeSP->screen_b[imageI]; if (curr_planeSP->normal_theta[imageI] >= 1.5707963) coeff *= -1; } /* Find the plane extent: */ PlaneExtent_ (&screen_x_min, &screen_x_max, &screen_y_min, &screen_y_max, curr_planeSP, configSP, imageI); /* Scan the rectangle bounding ellipse: */ for (screen_x = screen_x_min; screen_x <= screen_x_max; screen_x++) { for (screen_y = screen_y_min; screen_y <= screen_y_max; screen_y++) { /* Pixel position relative to the plane center position: */ x_relative = screen_x - center_screen_x; y_relative = screen_y - center_screen_y; /* Rotated pixel position (rotation is anticlockwise here): */ x_rotated = x_relative * cos_angle + y_relative * sin_angle; y_rotated = -x_relative * sin_angle + y_relative * cos_angle; /* Check is it inside bounding ellipse: */ ratio_x = x_rotated * reciprocal_a; ratio_y = y_rotated * reciprocal_b; d = ratio_x * ratio_x + ratio_y * ratio_y; if (d > 1.0) continue; /* Calculate the z value for this pixel: */ plane_delta_z = coeff * y_rotated; plane_z = curr_planeSP->center_z[imageI] + plane_delta_z; /* The current pixel index: */ pixelI = guiSP->main_win_free_area_width * screen_y + screen_x; /* Check pixel index: */ if (pixelI >= pixelsN) continue; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = nearest_atomSP + pixelI; /* If something was drawn to the current */ /* pixel in this step, compare z values: */ if (curr_pixelSP->last_refreshI == refreshI) { /* If the point drawn before is closer to the */ /* observer than plane, do not draw anything: */ if (curr_pixelSP->z < plane_z) { continue; } /* If the plane is closer than the */ /* point drawn before, mix colors: */ else { /* The plane color: */ scale_factor = (plane_delta_z + curr_planeSP->circle_radius) * reciprocal_diameter; if (scale_factor < 0.0) scale_factor = 0.0; if (scale_factor > 1.0) scale_factor = 1.0; if (curr_planeSP->visible_sideI[imageI] == 0) { plane_colorID = WeightColors_ ( curr_planeSP->top_near_colorID, curr_planeSP->top_far_colorID, scale_factor, guiSP); } else { plane_colorID = WeightColors_ ( curr_planeSP->bottom_near_colorID, curr_planeSP->bottom_far_colorID, scale_factor, guiSP); } /* The color of the object which was */ /* drawn before the current plane: */ old_colorID = curr_pixelSP->colorID; /* The weighting factor which should be used */ /* to mix the plane color and the old color: */ scale_factor = curr_planeSP->transparency; /* Mix the plane color and the old color: */ colorID = WeightColors_ (plane_colorID, old_colorID, scale_factor, guiSP); } } /* If nothing was drawn to the current pixel */ /* in this drawing step, prepare the color: */ else { /* Prepare the scale factor used to weight (mix) colors: */ scale_factor = (plane_delta_z + curr_planeSP->circle_radius) * reciprocal_diameter; if (scale_factor < 0.0) scale_factor = 0.0; if (scale_factor > 1.0) scale_factor = 1.0; /* Prepare the color by weighting */ /* (mixing) near and far color: */ if (curr_planeSP->visible_sideI[imageI] == 0) { colorID = WeightColors_ ( curr_planeSP->top_near_colorID, curr_planeSP->top_far_colorID, scale_factor, guiSP); } else { colorID = WeightColors_ ( curr_planeSP->bottom_near_colorID, curr_planeSP->bottom_far_colorID, scale_factor, guiSP); } /* Set the style index associated with the current pixel */ /* to signal that only plane was drawn to this pixel: */ curr_pixelSP->styleI = PLANE_STYLE; } /* Draw point: */ XSetForeground (guiSP->displaySP, guiSP->theGCA[0], colorID); XDrawPoint (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x, screen_y); /* Update refresh index, z value and */ /* color value for the current pixel: */ curr_pixelSP->last_refreshI = refreshI; curr_pixelSP->z = plane_z; curr_pixelSP->colorID = colorID; } } } } /* Return positive value (trivial): */ return 1; } /*===========================================================================*/ garlic-1.6/rotate_membrane.c0000644000076500007650000001253607400136064016426 0ustar zuciczucic00000000000000/* Copyright (C) 2001 Damir Zucic */ /*============================================================================= rotate_membrane.c Purpose: Rotate the membrane associated with the given macromolecular complex. Input: (1) Pointer to MolComplexS structure. (2) Pointer to ConfigS structure. (3) Rotation angle. (4) Rotation axis identifier (1 = x, 2 = y, 3 = z). Output: (1) The membrane associated with the specified macromolecular complex will be rotated. Return value: No return value. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======rotate membrane:=====================================================*/ void RotateMembrane_ (MolComplexS *curr_mol_complexSP, ConfigS *configSP, double rotation_angle, int axisID) { double cos_angle, sin_angle; double cos_stereo_angle, sin_stereo_angle; MembraneS *membraneSP; double x0, y0, z0; double x, y, z; static double x_new, y_new, z_new; PlaneS *plane1SP, *plane2SP; /* Calculate cosine and sine of the rotation angle: */ cos_angle = cos (rotation_angle); sin_angle = sin (rotation_angle); /* Calculate cosine and sine of the stereo angle: */ cos_stereo_angle = cos (configSP->stereo_angle); sin_stereo_angle = sin (configSP->stereo_angle); /* Pointer to the membrane: */ membraneSP = &curr_mol_complexSP->membraneS; /*------rotate the membrane center, if required:-----------------------------*/ /* If membrane if moved together with the */ /* structure, rotate the membrane center: */ if (curr_mol_complexSP->move_bits & STRUCTURE_MASK) { /* Copy the rotation center coordinates: */ x0 = curr_mol_complexSP->rotation_center_vectorS.x; y0 = curr_mol_complexSP->rotation_center_vectorS.y; z0 = curr_mol_complexSP->rotation_center_vectorS.z; /* Position of the membrane center relative to the rotation center: */ x = membraneSP->center_x - x0; y = membraneSP->center_y - y0; z = membraneSP->center_z - z0; /* Rotate these coordinates: */ switch (axisID) { /* Rotate around x: */ case 1: x_new = x; y_new = y * cos_angle - z * sin_angle; z_new = y * sin_angle + z * cos_angle; break; /* Rotate around y: */ case 2: x_new = x * cos_angle + z * sin_angle; y_new = y; z_new = -x * sin_angle + z * cos_angle; break; /* Rotate around z: */ case 3: x_new = x * cos_angle - y * sin_angle; y_new = x * sin_angle + y * cos_angle; z_new = z; break; /* The impossible case: */ default: ; break; } /* Translate and store new coordinates: */ membraneSP->center_x = x_new + x0; membraneSP->center_y = y_new + y0; membraneSP->center_z = z_new + z0; } /*------rotate the first plane:----------------------------------------------*/ /* Pointer to the first plane: */ plane1SP = &membraneSP->plane1S; /* Copy the normal vector components: */ x = plane1SP->normal_x[0]; y = plane1SP->normal_y; z = plane1SP->normal_z[0]; /* Rotate the normal vector: */ switch (axisID) { /* Rotate around x: */ case 1: x_new = x; y_new = y * cos_angle - z * sin_angle; z_new = y * sin_angle + z * cos_angle; break; /* Rotate around y: */ case 2: x_new = x * cos_angle + z * sin_angle; y_new = y; z_new = -x * sin_angle + z * cos_angle; break; /* Rotate around z: */ case 3: x_new = x * cos_angle - y * sin_angle; y_new = x * sin_angle + y * cos_angle; z_new = z; break; /* The impossible case: */ default: ; break; } /* Store the rotated vector: */ plane1SP->normal_x[0] = x_new; plane1SP->normal_y = y_new; plane1SP->normal_z[0] = z_new; /* Prepare stereo data for normal vector: */ plane1SP->normal_x[1] = plane1SP->normal_x[0] * cos_stereo_angle + plane1SP->normal_z[0] * sin_stereo_angle; plane1SP->normal_z[1] = -plane1SP->normal_x[0] * sin_stereo_angle + plane1SP->normal_z[0] * cos_stereo_angle; /*------rotate the second plane:---------------------------------------------*/ /* Pointer to the second plane: */ plane2SP = &membraneSP->plane2S; /* Copy the normal vector components: */ x = plane2SP->normal_x[0]; y = plane2SP->normal_y; z = plane2SP->normal_z[0]; /* Rotate the normal vector: */ switch (axisID) { /* Rotate around x: */ case 1: x_new = x; y_new = y * cos_angle - z * sin_angle; z_new = y * sin_angle + z * cos_angle; break; /* Rotate around y: */ case 2: x_new = x * cos_angle + z * sin_angle; y_new = y; z_new = -x * sin_angle + z * cos_angle; break; /* Rotate around z: */ case 3: x_new = x * cos_angle - y * sin_angle; y_new = x * sin_angle + y * cos_angle; z_new = z; break; /* The impossible case: */ default: ; break; } /* Store the rotated vector: */ plane2SP->normal_x[0] = x_new; plane2SP->normal_y = y_new; plane2SP->normal_z[0] = z_new; /* Prepare stereo data for normal vector: */ plane2SP->normal_x[1] = plane2SP->normal_x[0] * cos_stereo_angle + plane2SP->normal_z[0] * sin_stereo_angle; plane2SP->normal_z[1] = -plane2SP->normal_x[0] * sin_stereo_angle + plane2SP->normal_z[0] * cos_stereo_angle; /*---------------------------------------------------------------------------*/ /* Set the position_changedF: */ curr_mol_complexSP->position_changedF = 1; } /*===========================================================================*/ garlic-1.6/save_sequence.c0000644000076500007650000000516607260721760016120 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= save_sequence.c Purpose: Save sequence to file. This function outputs three letters code. Input: (1) Pointer to RuntimeS structure. Output: (1) Sequence stored to file. (2) Return value. Return value: (1) Positive on success. (2) Negative on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ char *ExtractToken_ (char *, int, char *, char *); /*======save sequence to file:===============================================*/ int SaveSequence_ (RuntimeS *runtimeSP) { int max_length; char lineA[STRINGSIZE]; char *remainderP; char tokenA[STRINGSIZE]; FILE *fileP; size_t residueI; char *nameP; char residue_nameA[RESNAMESIZE]; /* The maximal residue name length: */ max_length = RESNAMESIZE - 1; /* Copy the original command string: */ strncpy (lineA, runtimeSP->curr_commandA, STRINGSIZE - 1); lineA[STRINGSIZE - 1] = '\0'; /* Skip two tokens: */ remainderP = ExtractToken_ (tokenA, STRINGSIZE, lineA, " \t\n"); if (!remainderP) return -1; remainderP = ExtractToken_ (tokenA, STRINGSIZE, remainderP, " \t\n"); if (!remainderP) return -2; /* The third token should contain the file name: */ remainderP = ExtractToken_ (tokenA, STRINGSIZE, remainderP, " \t\n"); if (!remainderP) { strcpy (runtimeSP->messageA, "File name missing!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return -3; } /* Try to open file: */ fileP = fopen (tokenA, "w"); if (fileP == NULL) { strcpy (runtimeSP->messageA, "Failed to open file!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return -4; } /* Write sequence to file: */ for (residueI = 0; residueI < runtimeSP->residuesN; residueI++) { /* Prepare the pointer to the current residue name: */ nameP = runtimeSP->sequenceP + residueI * max_length; /* Copy residue name: */ strncpy (residue_nameA, nameP, max_length); residue_nameA[max_length] = '\0'; /* Print residue name: */ fprintf (fileP, "%-4s", residue_nameA); /* Add newline after each tenth residue: */ if (((residueI + 1) % 10) == 0) fprintf (fileP, "\n"); } /* Add newline at the end of file: */ fprintf (fileP, "\n"); /* Close file: */ fclose (fileP); /* Return positive value on success: */ return 1; } /*===========================================================================*/ garlic-1.6/init_nearest.c0000644000076500007650000000444007065471615015754 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= init_nearest.c Purpose: Initialize last_refreshI and styleI for each NearestAtomS structure. For a given pixel, the NearestAtomS structure stores information about the last atom drawn in that pixel. If the current refreshI in the event loop is larger than last_refreshI for a given pixel, the pixel is free for drawing. If these two values are equal, the z coordinate associated with a given pixel should be compared with the z coordinate of the current atom. This function must be called if: (1) The main window is resized. (2) A new macromolecular complex is loaded. (3) A previously loaded complex is discarded. (4) Atoms are deleted or inserted. (5) Visibility status of at least one atom is changed. (6) The refreshI in EventLoop_ function is reset. Input: (1) Pointer to an array of NearestAtomS structures. (2) Number of array elements (the maximal number of pixels). Output: (1) The last_refreshI in each NearestAtomS structure initialized. (2) The styleI in each NearestAtomS structure initialized. Return value: No return value. Notes: (1) The initial last_refreshI index value to zero. The lowest value of the refreshI in event_loop.c is one. All pixel which have the last_refreshI equal to zero are thus free for drawing - there is no need to compare the z coord. of the current atom (bond) with the z value associated with a given pixel. (2) The initial styleI index value is zero. (3) By the way, as calloc is used to reallocate the memory, this function is unnecessary. ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======initialize the array of NearestAtomS structures:=====================*/ void InitNearest_ (NearestAtomS *nearest_atomSP, size_t max_pixelsN) { size_t i = 0; NearestAtomS *curr_pixelSP; for (i = 0; i < max_pixelsN; i++) { curr_pixelSP = nearest_atomSP + i; curr_pixelSP->last_refreshI = 0; curr_pixelSP->styleI = 0; } } /*===========================================================================*/ garlic-1.6/chi2_from_cacbcgcd.c0000644000076500007650000000727307341211764016732 0ustar zuciczucic00000000000000/* Copyright (C) 2001 Damir Zucic */ /*============================================================================= chi2_from_cacbcgcd.c Purpose: Calculate dihedral angle chi2, using CA, CB, CG and CD coordinates. Input: (1) Pointer to AtomS structure, pointing to the first atom of the current macromolecular complex. (2) Index of the first atom of the current residue. (3) Index of the last atom of the currrent residue. Output: Return value. Return value: (1) Dihedral angle chi2, on success. (2) BADDIHEDANGLE on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int ExtractFourAtoms_ (VectorS *, VectorS *, VectorS *, VectorS *, char *, char *, char *, char *, AtomS *, size_t, size_t); void VectorProduct_ (VectorS *, VectorS *, VectorS *); double AbsoluteValue_ (VectorS *); double ScalarProduct_ (VectorS *, VectorS *); /*======calculate chi2 from CA, CB, CG and CD:===============================*/ double Chi2FromCACBCGCD_ (AtomS *atomSP, size_t atom_startI, size_t atom_endI) { static VectorS CA_vectorS, CB_vectorS, CG_vectorS, CD_vectorS; int n; VectorS CB_CA_vectorS, CB_CG_vectorS; VectorS CG_CB_vectorS, CG_CD_vectorS; VectorS u1S, u2S; VectorS v1S, v2S; double denom, ratio, alpha; double chi2; /* Extract CA, CB, CG and CD coordinates: */ n = ExtractFourAtoms_ (&CA_vectorS, &CB_vectorS, &CG_vectorS, &CD_vectorS, "CA", "CB", "CG", "CD", atomSP, atom_startI, atom_endI); /* All four atoms are required to calculate the angle chi2: */ if (n < 4) return BADDIHEDANGLE; /* The first pair of auxiliary vectors: */ CB_CA_vectorS.x = CA_vectorS.x - CB_vectorS.x; CB_CA_vectorS.y = CA_vectorS.y - CB_vectorS.y; CB_CA_vectorS.z = CA_vectorS.z - CB_vectorS.z; CB_CG_vectorS.x = CG_vectorS.x - CB_vectorS.x; CB_CG_vectorS.y = CG_vectorS.y - CB_vectorS.y; CB_CG_vectorS.z = CG_vectorS.z - CB_vectorS.z; /* The second pair of auxiliary vectors: */ CG_CB_vectorS.x = CB_vectorS.x - CG_vectorS.x; CG_CB_vectorS.y = CB_vectorS.y - CG_vectorS.y; CG_CB_vectorS.z = CB_vectorS.z - CG_vectorS.z; CG_CD_vectorS.x = CD_vectorS.x - CG_vectorS.x; CG_CD_vectorS.y = CD_vectorS.y - CG_vectorS.y; CG_CD_vectorS.z = CD_vectorS.z - CG_vectorS.z; /* Two vectors perpendicular to CB_CG_vectorS, mutually orthogonal, */ /* the second in the plane defined by CB_CA_vectorS and CB_CG_vectorS: */ VectorProduct_ (&u1S, &CB_CA_vectorS, &CB_CG_vectorS); VectorProduct_ (&u2S, &u1S, &CB_CG_vectorS); /* Two vectors perpendicular to CG_CB_vectorS, mutually orthogonal, */ /* the second in the plane defined by CG_CB_vectorS and CG_CD_vectorS: */ VectorProduct_ (&v1S, &CG_CB_vectorS, &CG_CD_vectorS); VectorProduct_ (&v2S, &CG_CB_vectorS, &v1S); /* Calculate the angle alpha, which will be used to calculate chi2: */ /* Avoid division by zero: */ denom = AbsoluteValue_ (&u1S) * AbsoluteValue_ (&v1S); if (denom == 0.0) return BADDIHEDANGLE; /* Use the scalar product to calculate the cosine of the angle: */ ratio = ScalarProduct_ (&u1S, &v1S) / denom; /* Arc cosine is very sensitive to floating point errors: */ if (ratio <= -1.0) alpha = 3.1415927; else if (ratio >= 1.0) alpha = 0.0; else alpha = acos (ratio); /* There are two possible solutions; the right one is resolved here: */ if (ScalarProduct_ (&v2S, &u1S) >= 0) chi2 = alpha; else chi2 = -alpha; /* Return the angle (in radians): */ return chi2; } /*===========================================================================*/ garlic-1.6/chi2_from_cacbcgsd.c0000644000076500007650000000727307341221472016747 0ustar zuciczucic00000000000000/* Copyright (C) 2001 Damir Zucic */ /*============================================================================= chi2_from_cacbcgsd.c Purpose: Calculate dihedral angle chi2, using CA, CB, CG and SD coordinates. Input: (1) Pointer to AtomS structure, pointing to the first atom of the current macromolecular complex. (2) Index of the first atom of the current residue. (3) Index of the last atom of the currrent residue. Output: Return value. Return value: (1) Dihedral angle chi2, on success. (2) BADDIHEDANGLE on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int ExtractFourAtoms_ (VectorS *, VectorS *, VectorS *, VectorS *, char *, char *, char *, char *, AtomS *, size_t, size_t); void VectorProduct_ (VectorS *, VectorS *, VectorS *); double AbsoluteValue_ (VectorS *); double ScalarProduct_ (VectorS *, VectorS *); /*======calculate chi2 from CA, CB, CG and SD:===============================*/ double Chi2FromCACBCGSD_ (AtomS *atomSP, size_t atom_startI, size_t atom_endI) { static VectorS CA_vectorS, CB_vectorS, CG_vectorS, SD_vectorS; int n; VectorS CB_CA_vectorS, CB_CG_vectorS; VectorS CG_CB_vectorS, CG_SD_vectorS; VectorS u1S, u2S; VectorS v1S, v2S; double denom, ratio, alpha; double chi2; /* Extract CA, CB, CG and SD coordinates: */ n = ExtractFourAtoms_ (&CA_vectorS, &CB_vectorS, &CG_vectorS, &SD_vectorS, "CA", "CB", "CG", "SD", atomSP, atom_startI, atom_endI); /* All four atoms are required to calculate the angle chi2: */ if (n < 4) return BADDIHEDANGLE; /* The first pair of auxiliary vectors: */ CB_CA_vectorS.x = CA_vectorS.x - CB_vectorS.x; CB_CA_vectorS.y = CA_vectorS.y - CB_vectorS.y; CB_CA_vectorS.z = CA_vectorS.z - CB_vectorS.z; CB_CG_vectorS.x = CG_vectorS.x - CB_vectorS.x; CB_CG_vectorS.y = CG_vectorS.y - CB_vectorS.y; CB_CG_vectorS.z = CG_vectorS.z - CB_vectorS.z; /* The second pair of auxiliary vectors: */ CG_CB_vectorS.x = CB_vectorS.x - CG_vectorS.x; CG_CB_vectorS.y = CB_vectorS.y - CG_vectorS.y; CG_CB_vectorS.z = CB_vectorS.z - CG_vectorS.z; CG_SD_vectorS.x = SD_vectorS.x - CG_vectorS.x; CG_SD_vectorS.y = SD_vectorS.y - CG_vectorS.y; CG_SD_vectorS.z = SD_vectorS.z - CG_vectorS.z; /* Two vectors perpendicular to CB_CG_vectorS, mutually orthogonal, */ /* the second in the plane defined by CB_CA_vectorS and CB_CG_vectorS: */ VectorProduct_ (&u1S, &CB_CA_vectorS, &CB_CG_vectorS); VectorProduct_ (&u2S, &u1S, &CB_CG_vectorS); /* Two vectors perpendicular to CG_CB_vectorS, mutually orthogonal, */ /* the second in the plane defined by CG_CB_vectorS and CG_SD_vectorS: */ VectorProduct_ (&v1S, &CG_CB_vectorS, &CG_SD_vectorS); VectorProduct_ (&v2S, &CG_CB_vectorS, &v1S); /* Calculate the angle alpha, which will be used to calculate chi2: */ /* Avoid division by zero: */ denom = AbsoluteValue_ (&u1S) * AbsoluteValue_ (&v1S); if (denom == 0.0) return BADDIHEDANGLE; /* Use the scalar product to calculate the cosine of the angle: */ ratio = ScalarProduct_ (&u1S, &v1S) / denom; /* Arc cosine is very sensitive to floating point errors: */ if (ratio <= -1.0) alpha = 3.1415927; else if (ratio >= 1.0) alpha = 0.0; else alpha = acos (ratio); /* There are two possible solutions; the right one is resolved here: */ if (ScalarProduct_ (&v2S, &u1S) >= 0) chi2 = alpha; else chi2 = -alpha; /* Return the angle (in radians): */ return chi2; } /*===========================================================================*/ garlic-1.6/select_pattern.c0000644000076500007650000002054507747233256016314 0ustar zuciczucic00000000000000/* Copyright (C) 2003 Damir Zucic */ /*============================================================================= select_pattern.c Purpose: Select sequence pattern. Some residues are similar; pattern allows the specification of a number of residues at a given place of some sequence fragment. Example: GLU GLN ASP ASN ARG LYS / ALA / TYR ; this pattern represents a fragment of three residues. The first one may be GLU, GLN, ASP, ASN, ARG or LYS while the second and the third must be ALA and TYR. The maximal number of residues in the given sequence pattern is defined in defines.h (MAXPATTLENGTH). Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. (3) Pointer to RuntimeS structure (the pattern buffer is there). (4) Selection mode index (0 = overwrite, 1 = restrict, 2 = expand previous selection). Output: (1) The flag selectedF will be set to one for selected atoms in every caught macromolecular complex. (2) Return value. Return value: (1) The number of selected atoms (zero or positive value). Notes: (1) Indentation is exceptionally 4 spaces. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ /*======select sequence pattern:=============================================*/ long SelectPattern_ (MolComplexS *mol_complexSP, int mol_complexesN, RuntimeS *runtimeSP, int selection_modeI) { long selected_atomsN = 0; int max_length; int window_width, windowI; int mol_complexI; MolComplexS *curr_mol_complexSP; int atomsN, atomI; AtomS *curr_atomSP; int residuesN, max_residueI, residueI; int combinedI; ResidueS *curr_residueSP; AtomS *first_atomSP; char *checked_nameP, *acceptable_nameP; int name_offset; int score; int nameI; int first_atomI, last_atomI; /* The maximal residue name length: */ max_length = RESNAMESIZE - 1; /* Copy and check the number of residues in the sequence pattern: */ window_width = runtimeSP->pattern_length; if (window_width == 0) return (long) 0; /* Scan all caught macromol. complexes and search the specified pattern: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check is the current macromolecular complex caught: */ if (curr_mol_complexSP->catchF == 0) continue; /* Number of atoms in a macromolecular complex: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Copy and check the number of residues: */ residuesN = curr_mol_complexSP->residuesN; if (residuesN == 0) continue; /* The maximal residue index: */ max_residueI = residuesN - window_width; /* Backup the current selection if selection mode is restrict: */ if (selection_modeI == 1) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Copy the selection flag: */ curr_atomSP->previous_selectedF = curr_atomSP->selectedF; } } /* Unselect everything if selection mode is overwrite or restrict: */ if ((selection_modeI == 0) || (selection_modeI == 1)) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Unselect the current atom: */ curr_atomSP->selectedF = 0; } } /* Scan the residues of the current macromolecular complex: */ for (residueI = 0; residueI <= max_residueI; residueI++) { /* Reset the score: */ score = 0; /* Reset the name offset. The name offset helps to find the */ /* first name from the specified set. When the value is equal to */ /* zero, it is the offset of the first name from the first set. */ name_offset = 0; /* Scan the given number of residues, */ /* starting from the current residue: */ for (windowI = 0; windowI < window_width; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI >= residuesN) break; /* Residue associated with the combined index: */ curr_residueSP = curr_mol_complexSP->residueSP + combinedI; /* Pointer to the first atom of current residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Pointer to the name of the current */ /* residue from the current structure: */ checked_nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Scan the set of names. Name sets are building blocks of */ /* the pattern. The pattern length is equal to the total */ /* number of sets. The window width is equal to the pattern */ /* length. The current name set is defined by the windowI. */ for (nameI = 0; nameI < runtimeSP->namesNA[windowI]; nameI++) { /* Pointer to the name from the set of names: */ acceptable_nameP = runtimeSP->patternP + max_length * (name_offset + nameI); /* Check for wildcard: */ if (*acceptable_nameP == '*') { /* Increment score, wildcard matches any residue name: */ score++; /* The number of names in this set should */ /* be equal to one (see parse_pattern.c); */ /* this command was not really necessary: */ break; } /* If this point is reached, no wildcard was */ /* found. Compare the current residue name */ /* with the given name from the current set: */ if (strncmp (acceptable_nameP, checked_nameP, max_length) == 0) { /* Increment the score: */ score++; /* Break from the loop, one match is enough: */ break; } /* End of nameI loop: */ } /* Update the name offset. This is the offset of the first */ /* name from the next set. It will be used in the next step. */ name_offset += runtimeSP->namesNA[windowI]; /* End of windowI loop: */ } /* Check the total score. If the sum of the total score and */ /* the tolerance is equal to the window width or even larger, */ /* the current sequence fragment matches the given pattern. */ if (score + runtimeSP->pattern_tolerance >= window_width) { /* Scan the window again and select all atoms from this window: */ for (windowI = 0; windowI < window_width; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI >= residuesN) break; /* Residue associated with the combined index: */ curr_residueSP = curr_mol_complexSP->residueSP + combinedI; /* The indices of the first and the */ /* last atom of the current residue: */ first_atomI = curr_residueSP->residue_startI; last_atomI = curr_residueSP->residue_endI; /* Select all atoms of the current residue: */ for (atomI = first_atomI; atomI <= last_atomI; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Select the current atom: */ curr_atomSP->selectedF = 1; /* Update the counter of selected atoms: */ selected_atomsN++; } } } /* End of residueI loop: */ } /* Combine the current selection with the */ /* previous, if selection mode is restrict: */ if (selection_modeI == 1) { /* Reset the counter of selected atoms. The */ /* selected atoms should be counted again. */ selected_atomsN = 0; /* Combine the old and the new selection flag: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Combine selection flags: */ curr_atomSP->selectedF *= curr_atomSP->previous_selectedF; /* Check the selection flag; increase */ /* the count of selected residues if */ /* the selection flag is equal to one: */ if (curr_atomSP->selectedF) selected_atomsN++; } } /* Update the position_changedF (some atoms may have bad color): */ curr_mol_complexSP->position_changedF = 1; /* End of mol_complexI loop: */ } /* Return the number of selected atoms: */ return selected_atomsN; } /*===========================================================================*/ garlic-1.6/select_events.c0000644000076500007650000000201407065474753016134 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= selectev.c Purpose: Select events. Input: Pointer to GUIS structure. Output: X server informed about events which should be reported for given windows. Return value: No return value. ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======select events:=======================================================*/ void SelectEvents_ (GUIS *guiSP) { long event_mask; event_mask = ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | StructureNotifyMask; /* Selects ConfigureNotify event */ XSelectInput (guiSP->displaySP, guiSP->main_winS.ID, event_mask); } /*===========================================================================*/ garlic-1.6/position.c0000644000076500007650000001625207612773677015153 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2003 Damir Zucic */ /*============================================================================= position.c Purpose: Execute position command: move all caught macromol. complexes to the specified place (position). The geometric center will be set to this position. Input: (1) Pointer to MolComplexS structure. (2) The number of macromolecular complexes. (3) Pointer to RuntimeS structure. (4) Pointer to ConfigS structure. (5) Pointer to GUIS structure. (6) Pointer to NearestAtomS structure. (7) The number of pixels in the main window free area. (8) Pointer to refreshI. (9) Pointer to the remainder of the command string. The remainder should contain three numeric values (x, y and z coordinate of a new position). Output: (1) All caught macromolecular complexes moved to the specified position. (2) Return value. Return value: (1) Positive (command) code on success. (2) Negative (error) code on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "commands.h" #include "typedefs.h" /*======function prototypes:=================================================*/ void CopyDoubles_ (char *, char *, int); void TranslatePlane_ (MolComplexS *, VectorS *); void TranslateMembrane_ (MolComplexS *, VectorS *); size_t MainRefresh_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); int ControlRefresh_ (MolComplexS *, ConfigS *, GUIS *); /*======execute stereo command:==============================================*/ int CommandPosition_ (MolComplexS *mol_complexSP, int mol_complexesN, RuntimeS *runtimeSP, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int *refreshIP, char *stringP) { char copyA[STRINGSIZE]; double x0, y0, z0, x1, y1, z1; double delta_x, delta_y, delta_z; int mol_complexI; MolComplexS *curr_mol_complexSP; size_t atomsN, atomI; AtomS *curr_atomSP; VectorS shift_vectorS; /* Copy digits, signs and decimal points: */ CopyDoubles_ (copyA, stringP, STRINGSIZE - 1); copyA[STRINGSIZE - 1] = '\0'; /* The input string should contain three numeric values: */ if (sscanf (copyA, "%lf %lf %lf\n", &x0, &y0, &z0) != 3) { strcpy (runtimeSP->messageA, "Three coordinates (x, y and z) expected!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_POSITION; } /* Shift every caught macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /** Pointer to the current macromolecular complex: **/ curr_mol_complexSP = mol_complexSP + mol_complexI; /** Check is the current macromolecular complex caught: **/ if (curr_mol_complexSP->catchF == 0) continue; /** Number of atoms in a macromolecular complex: **/ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /** Check is it necessary to translate the plane: */ if (curr_mol_complexSP->move_bits & PLANE_MASK) { /*** If plane should be moved independently: ***/ if (!(curr_mol_complexSP->move_bits & STRUCTURE_MASK)) { x1 = curr_mol_complexSP->planeS.center_x[0]; y1 = curr_mol_complexSP->planeS.center_y; z1 = curr_mol_complexSP->planeS.center_z[0]; } /*** If plane is bound to the structure: ***/ else { x1 = curr_mol_complexSP->geometric_center_vectorS.x; y1 = curr_mol_complexSP->geometric_center_vectorS.y; z1 = curr_mol_complexSP->geometric_center_vectorS.z; } /*** Prepare shift vector and translate the plane: ***/ shift_vectorS.x = x0 - x1; shift_vectorS.y = y0 - y1; shift_vectorS.z = z0 - z1; TranslatePlane_ (curr_mol_complexSP, &shift_vectorS); } /** Check is it necessary to translate the membrane: **/ if (curr_mol_complexSP->move_bits & MEMBRANE_MASK) { /*** If membrane should be moved independently: ***/ if (!(curr_mol_complexSP->move_bits & STRUCTURE_MASK)) { x1 = curr_mol_complexSP->membraneS.center_x; y1 = curr_mol_complexSP->membraneS.center_y; z1 = curr_mol_complexSP->membraneS.center_z; } /*** If membrane is bound to the structure: ***/ else { x1 = curr_mol_complexSP->geometric_center_vectorS.x; y1 = curr_mol_complexSP->geometric_center_vectorS.y; z1 = curr_mol_complexSP->geometric_center_vectorS.z; } /*** Prepare shift vector and translate the membrane: ***/ shift_vectorS.x = x0 - x1; shift_vectorS.y = y0 - y1; shift_vectorS.z = z0 - z1; TranslateMembrane_ (curr_mol_complexSP, &shift_vectorS); } /** Check is it necessary to translate the structure at all: **/ if (!(curr_mol_complexSP->move_bits & STRUCTURE_MASK)) continue; /** Prepare shifts: **/ delta_x = x0 - curr_mol_complexSP->geometric_center_vectorS.x; delta_y = y0 - curr_mol_complexSP->geometric_center_vectorS.y; delta_z = z0 - curr_mol_complexSP->geometric_center_vectorS.z; /** Scan all atoms in the current complex: **/ for (atomI = 0; atomI < atomsN; atomI++) { /** Pointer to the current atom: **/ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /** Move atom to the new position: **/ curr_atomSP->raw_atomS.x[0] += delta_x; curr_atomSP->raw_atomS.y += delta_y; curr_atomSP->raw_atomS.z[0] += delta_z; if (configSP->stereoF) { curr_atomSP->raw_atomS.x[1] += delta_x; curr_atomSP->raw_atomS.z[1] += delta_z; } } /** Update the geometric center: **/ curr_mol_complexSP->geometric_center_vectorS.x += delta_x; curr_mol_complexSP->geometric_center_vectorS.y += delta_y; curr_mol_complexSP->geometric_center_vectorS.z += delta_z; /** Update the extent vectors: **/ curr_mol_complexSP->left_top_near_vectorS.x += delta_x; curr_mol_complexSP->left_top_near_vectorS.y += delta_y; curr_mol_complexSP->left_top_near_vectorS.z += delta_z; curr_mol_complexSP->right_bottom_far_vectorS.x += delta_x; curr_mol_complexSP->right_bottom_far_vectorS.y += delta_y; curr_mol_complexSP->right_bottom_far_vectorS.z += delta_z; /** Update the rotation center: **/ curr_mol_complexSP->rotation_center_vectorS.x += delta_x; curr_mol_complexSP->rotation_center_vectorS.y += delta_y; curr_mol_complexSP->rotation_center_vectorS.z += delta_z; /** Update the slab center: **/ curr_mol_complexSP->slab_center_vectorS.x += delta_x; curr_mol_complexSP->slab_center_vectorS.y += delta_y; curr_mol_complexSP->slab_center_vectorS.z += delta_z; /** Update the color fading center: **/ curr_mol_complexSP->fading_center_vectorS.x += delta_x; curr_mol_complexSP->fading_center_vectorS.y += delta_y; curr_mol_complexSP->fading_center_vectorS.z += delta_z; /** Update the position_changedF flag: **/ curr_mol_complexSP->position_changedF = 1; } /* Refresh the main window: */ (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); /* Refresh the control window: */ ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); /* Return the command code: */ return COMMAND_POSITION; } /*===========================================================================*/ garlic-1.6/pattern.c0000644000076500007650000001047407651024516014744 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2003 Damir Zucic */ /*============================================================================= pattern.c Purpose: Execute pattern command: define the residue pattern. Residue pattern is relatively short, but more flexible than sequence. More than one residue may be specified at the given position. The length of pattern is fixed, i.e. deletions and insertions are not allowed. Asterisk may be used to allow any residue at the given position. The only keyword which may be combined with the command PATTERN is TOLERANCE. Default tolerance is zero. The command PAT TOL (long form: PATTERN TOLERANCE) may be used to change the tolerance. When searching the given structure for some pattern, the tolerance defines how many mismatches are acceptable. Input: (1) Pointer to MolComplexS structure. (2) The number of macromolecular complexes. (3) Pointer to RuntimeS structure. (4) Pointer to the string with command parameters. Output: (1) Pattern stored to the pattern buffer. (2) Return value. Return value: (1) Positive (command) code on success. (2) Negative (error) code on failure. Notes: (1) The pattern is expected in three letters code. One letter code may be missinterpreted as valid three letters code. ========includes:============================================================*/ #include #include #include #include #include #include #include #include "defines.h" #include "commands.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int ParsePattern_ (RuntimeS *, char *); char *ExtractToken_ (char *, int, char *, char *); /*======execute pattern command:=============================================*/ int Pattern_ (MolComplexS *mol_complexSP, int mol_complexesN, RuntimeS *runtimeSP, char *stringP) { char string_copyA[STRINGSIZE]; char *P; char *patternP; int n; char *remainderP; char tokenA[SHORTSTRINGSIZE]; int tolerance; /* Copy the original command string: */ strncpy (string_copyA, runtimeSP->curr_commandA, STRINGSIZE - 1); string_copyA[STRINGSIZE - 1] = '\0'; /* Check is the equality sign present in the original command string: */ if ((P = strstr (string_copyA, "=")) != NULL) { /* Prepare the pointer to the pattern: */ patternP = P + 1; /* Convert pattern to uppercase: */ P = patternP; while ((n = *P++) != '\0') *(P - 1) = toupper (n); /* Parse and store the pattern: */ n = ParsePattern_ (runtimeSP, patternP); if (n > 0) return COMMAND_PATTERN; else return ERROR_PATTERN; } /* If this point is reached, the equality sign was not found */ /* in the original command string. Check for keyword TOLERANCE. */ /* Take the first token; it should be present: */ remainderP = ExtractToken_ (tokenA, SHORTSTRINGSIZE, stringP, " \t\n"); if (!remainderP) { strcpy (runtimeSP->messageA, "Command parameter(s) missing!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_PATTERN; } /* If keyword TOLERANCE (short form: TOL) is present, extract tolerance: */ if (strstr (tokenA, "TOL") == tokenA) { /* Replace each non-numeric character (except */ /* minus sign and decimal point) with space: */ P = stringP; while ((n = *P++) != '\0') { if (!isdigit (n) && (n != '-') && (n != '.')) *(P - 1) = ' '; } /* Try to extract the pattern tolerance: */ if (sscanf (stringP, "%d", &tolerance) != 1) { strcpy (runtimeSP->messageA, "Failed to extract the pattern tolerance!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_PATTERN; } /* Check the value; negative value is not acceptable: */ if (tolerance < 0) { strcpy (runtimeSP->messageA, "Negative tolerance is not accepted!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_PATTERN; } /* If this point is reached, new tolerance is good. Store it: */ runtimeSP->pattern_tolerance = tolerance; /*@@*/ return COMMAND_PATTERN; } /* If keyword recognition failed: */ else { strcpy (runtimeSP->messageA, "Keyword not recognized!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_PATTERN; } /* Return the command code: */ return COMMAND_PATTERN; } /*===========================================================================*/ garlic-1.6/pixel_from_rgbs.c0000644000076500007650000000261307065474246016454 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= pixel_from_rgbs.c Purpose: Prepare pixel value (color) from RGB components. This function is used instead of XAllocColor, which is too slow. Garlic uses only the TrueColor visual, so that the pixel value is created from raw RGB values by simple bit shifting. Input: (1) Pointer to RGBS structure, with raw RGB values. (2) Pointer to GUIS structure. Output: (1) Return value. Return value: (1) Pixel value (unsigned long). =============================================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======prepare pixel value from RGB components:=============================*/ unsigned long PixelFromRGBS_ (RGBS *rgbSP, GUIS *guiSP) { unsigned long pixel; /* Prepare the pixel value (color): */ pixel = (((unsigned long) rgbSP->red >> guiSP->red_right_shift) << guiSP->red_left_shift) | (((unsigned long) rgbSP->green >> guiSP->green_right_shift) << guiSP->green_left_shift) | (((unsigned long) rgbSP->blue >> guiSP->blue_right_shift) << guiSP->blue_left_shift); /* Return the pixel value: */ return pixel; } /*===========================================================================*/ garlic-1.6/project_atoms.c0000644000076500007650000001224607463466223016145 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2002 Damir Zucic */ /*============================================================================= project_atoms.c Purpose: For each macromolecular complex, project atoms to the screen. Do not project atoms which fall outside the visible area. The maximal bond length (see .garlicrc file) is used as the maximal atomic diameter. This parameter is used to prepare rationalized parameters which are used here (see calc_params.c). Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. (3) Pointer to ConfigS structure, with configuration data. Output: (1) Data added to each array element in a given MolComplexS structure. (2) Return value. Return value: The number of projected atoms. Notes: (1) Project all atoms, even if some of them are out of slab. There may be some bonds connecting atoms inside and outside the slab. ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======project atoms:=======================================================*/ size_t ProjectAtoms_ (MolComplexS *mol_complexSP, int mol_complexesN, ConfigS *configSP) { static size_t projected_atomsN = 0; static int mol_complexI; static int imagesN, imageI; static MolComplexS *curr_mol_complexSP; static double nominator_x, nominator_y, user_atomic_position; static double x0, y0, z0, x1, y1; static int center_screen_x[2], center_screen_y; static size_t atomsN, atomI; static AtomS *curr_atomSP; static double denominator, reciprocal_denominator; static double rationalized_x, rationalized_y = 0; /* The number of images (1 for mono, 2 for stereo): */ if (configSP->stereoF == 1) imagesN = 2; else imagesN = 1; /* Prepare the factors which are used to */ /* reduce the number of multiplications: */ nominator_x = configSP->user_screen_atomic_distance * configSP->atomic_to_screen_scale_x; nominator_y = configSP->user_screen_atomic_distance * configSP->atomic_to_screen_scale_y; /* Prepare the user position in atomic coordinates: */ user_atomic_position = configSP->user_atomic_position; /* Copy range parameters: */ x0 = configSP->rationalized_x0; y0 = configSP->rationalized_y0; x1 = configSP->rationalized_x1; y1 = configSP->rationalized_y1; z0 = configSP->win_atomic_z0; /* Position of the window free area center: */ center_screen_x[0] = configSP->center_screen_x[0]; center_screen_x[1] = configSP->center_screen_x[1]; center_screen_y = configSP->center_screen_y; /* Project every macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Do not project coordinates if position has not changed: */ if (curr_mol_complexSP->position_changedF == 0) continue; /* Scan the entire macromolecular complex: */ atomsN = curr_mol_complexSP->atomsN; for (atomI = 0; atomI < atomsN; atomI++) { /** Prepare the current atom pointer: **/ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /** Prepare one image (mono) or two images (stereo): **/ for (imageI = 0; imageI < imagesN; imageI++) { /*** Prepare the factor required for projection: ***/ denominator = curr_atomSP->raw_atomS.z[imageI] - user_atomic_position; if (denominator == 0.0) continue; reciprocal_denominator = 1.0 / denominator; /*** If atom is on the wrong side of the screen, ***/ /*** set the flag and do not project this atom: ***/ if (curr_atomSP->raw_atomS.z[imageI] < z0) { curr_atomSP->inside_windowF = 0; break; } /*** Calculate the projection to the ***/ /*** screen, in rationalized units: ***/ rationalized_x = curr_atomSP->raw_atomS.x[imageI] * nominator_x * reciprocal_denominator; rationalized_y = curr_atomSP->raw_atomS.y * nominator_y * reciprocal_denominator; /*** Check is the atom at least partly visible: ***/ if (rationalized_x < x0) { curr_atomSP->inside_windowF = 0; break; } else if (rationalized_x > x1) { curr_atomSP->inside_windowF = 0; break; } else if (rationalized_y < y0) { curr_atomSP->inside_windowF = 0; break; } else if (rationalized_y > y1) { curr_atomSP->inside_windowF = 0; break; } else curr_atomSP->inside_windowF = 1; /*** If this point is reached, atom is at least ***/ /*** partly visible; calculate and store horiz. ***/ /*** component of the projection to the screen: ***/ curr_atomSP->raw_atomS.screen_x[imageI] = (int) rationalized_x + center_screen_x[imageI]; } /** Check is anything visible; if not, take the next atom: **/ if (curr_atomSP->inside_windowF == 0) continue; /** Vertical component of screen projection: **/ curr_atomSP->raw_atomS.screen_y = (int) rationalized_y + center_screen_y; /** Increase the number of visible atoms: **/ projected_atomsN++; } } return projected_atomsN; } /*===========================================================================*/ garlic-1.6/full_select.c0000644000076500007650000000525307647334302015571 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2003 Damir Zucic */ /*============================================================================= full_select.c Purpose: Execute select command: select the specified atoms in all caught macromolecular complexes. In this function, the selection cryteria should be precise (three slashes expected). Three selections modes are available: 0 = overwrite, 1 = restrict, 2 = expand previous selection. If this function failes to interpret the selection string, it will leave the job to other functions. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. (3) The selection string. (4) Selection mode index (0 = overwr., 1 = restrict, 2 = expand). Output: (1) The flag selectedF will be equal to one for selected atoms and equal to zero for all other atoms. (2) Return value. Return value: (1) The number of selected atoms, if selection is done in this function. (2) -1 if selection string is not suitable for this function. (3) Some other negative value on failure. Notes: (1) This function will not handle the selection string if this string does not contain three slashes. ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int Include_ (SelectS *, char *); int Exclude_ (SelectS *, char *); long ApplySelection_ (MolComplexS *, int, SelectS *, SelectS *, int); /*======execute select command (full selection string):======================*/ long FullSelect_ (MolComplexS *mol_complexSP, int mol_complexesN, char *stringP, int selection_modeI) { long selected_atomsN; char *P; int n; int slashesN = 0; SelectS include_selectS, exclude_selectS; /* Count slashes: */ P = stringP; while ((n = *P++) != '\0') if (n == '/') slashesN++; if (slashesN != 3) return (long) -1; /* Identify chains, residue ranges, residue */ /* names and atoms which have to be included: */ if (Include_ (&include_selectS, stringP) < 0) return (long) -2; /* Identify chains, residue ranges, residue */ /* names and atoms which have to be excluded: */ if (Exclude_ (&exclude_selectS, stringP) < 0) return (long) -3; /* Do the selection: */ selected_atomsN = ApplySelection_ (mol_complexSP, mol_complexesN, &include_selectS, &exclude_selectS, selection_modeI); /* Return the number of selected atoms: */ return selected_atomsN; } /*===========================================================================*/ garlic-1.6/calc_params.c0000644000076500007650000002266607302174547015545 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= calc_params.c Purpose: Calculate some parameters, required to speed up projection of atom to the screen. These parameters depend on configuration, so they are stored to ConfigS structure. Input: (1) Pointer to ConfigS structure, where some data will be stored. (2) Pointer to GUIS structure, with information about screen size. Output: (1) Some elements of ConfigS structure initialized. (2) Return value. Return value: (1) Positive on success. (2) Negative on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ void ErrorMessage_ (char *, char *, char *, char *, char *, char *, char *); /*======calculate auxiliary paramaters:======================================*/ int CalculateParameters_ (ConfigS *configSP, GUIS *guiSP) { double sin_theta; /* User-screen distance in atomic coordinates: */ if (configSP->screen_real_width == 0.0) { ErrorMessage_ ("garlic", "CalculateParameters_", "", "Screen real width not initialized!\n", "", "", ""); return -1; } configSP->user_screen_atomic_distance = configSP->user_screen_real_distance * configSP->screen_atomic_width / configSP->screen_real_width; /* Screen height, in atomic coordinates: */ configSP->screen_atomic_height = configSP->screen_atomic_width * configSP->screen_real_height / configSP->screen_real_width; /* Screen position in atomic coordinates, in absolute coordinate system: */ configSP->screen_atomic_z = configSP->user_atomic_position + configSP->user_screen_atomic_distance; /* Horizontal scale factor for conversion from atomic to screen units: */ if (configSP->screen_atomic_width == 0.0) { ErrorMessage_ ("garlic", "CalculateParameters_", "", "Screen atomic width not initialized!\n", "", "", ""); return -2; } configSP->atomic_to_screen_scale_x = (double) guiSP->screen_width / configSP->screen_atomic_width; /* Vertical scale factor for conversion from atomic to screen units: */ if (configSP->screen_atomic_height == 0.0) { ErrorMessage_ ("garlic", "CalculateParameters_", "", "Screen atomic height not initialized!\n", "", "", ""); return -3; } configSP->atomic_to_screen_scale_y = (double) guiSP->screen_height / configSP->screen_atomic_height; /* Horizontal scale factor for conversion from screen to atomic units: */ if (configSP->atomic_to_screen_scale_x != 0.0) { configSP->screen_to_atomic_scale_x = 1.0 / configSP->atomic_to_screen_scale_x; } else configSP->screen_to_atomic_scale_x = 0.0; /* Window free area width in atomic units: */ if (guiSP->screen_width == 0) { ErrorMessage_ ("garlic", "CalculateParameters_", "", "Screen width not initialized!\n", "", "", ""); return -4; } configSP->win_atomic_free_width = configSP->screen_atomic_width * (double) guiSP->control_winS.x0 / (double) guiSP->screen_width; /* Window free area height in atomic units: */ if (guiSP->screen_height == 0) { ErrorMessage_ ("garlic", "CalculateParameters_", "", "Screen height not initialized!\n", "", "", ""); return -5; } configSP->win_atomic_free_height = configSP->screen_atomic_height * (double) guiSP->input_winS.y0 / (double) guiSP->screen_height; /* Image extents, in screen units: */ /** Mono: **/ if (configSP->stereoF == 0) { configSP->image_screen_x0[0] = 0; configSP->image_screen_x1[0] = guiSP->control_winS.x0 - 1; } /** Stereo: **/ else { configSP->image_screen_x0[0] = 0; configSP->image_screen_x1[0] = (guiSP->control_winS.x0 - configSP->stereo_screen_margin) / 2; configSP->image_screen_x0[1] = configSP->image_screen_x1[0] + configSP->stereo_screen_margin; configSP->image_screen_x1[1] = guiSP->control_winS.x0 - 1; } /** Both: **/ configSP->image_screen_y0 = 0; configSP->image_screen_y1 = guiSP->input_winS.y0; /* Positions of window edges, in atomic units: */ /** Mono: **/ if (configSP->stereoF == 0) { configSP->win_atomic_x1 = configSP->win_atomic_free_width / 2.0; } /** Stereo: **/ else { configSP->win_atomic_x1 = configSP->win_atomic_free_width / 4.0; } /** Both: **/ configSP->win_atomic_x0 = -configSP->win_atomic_x1; configSP->win_atomic_y1 = configSP->win_atomic_free_height / 2.0; configSP->win_atomic_y0 = -configSP->win_atomic_y1; configSP->win_atomic_z0 = configSP->screen_atomic_z; /* Data used to identify atoms which are invisible and */ /* have invisible bonds (outside the window free area). */ /* Note that for mono image the limits cover the whole */ /* window plus one maximal bond length on each side! */ /* For stereo image horizontal limits cover half of the */ /* window plus one maximal bond length on each side. */ /** Horizontal limits: **/ configSP->rationalized_x0 = (configSP->win_atomic_x0 - configSP->max_bond_length) * configSP->atomic_to_screen_scale_x; configSP->rationalized_x1 = (configSP->win_atomic_x1 + configSP->max_bond_length) * configSP->atomic_to_screen_scale_x; /** Vertical limits: **/ configSP->rationalized_y0 = (configSP->win_atomic_y0 - configSP->max_bond_length) * configSP->atomic_to_screen_scale_y; configSP->rationalized_y1 = (configSP->win_atomic_y1 + configSP->max_bond_length) * configSP->atomic_to_screen_scale_y; /* Image center, in screen units: */ /** Mono: **/ if (configSP->stereoF == 0) { configSP->center_screen_x[0] = guiSP->control_winS.x0 / 2; } /** Stereo: **/ else { configSP->center_screen_x[0] = (guiSP->control_winS.x0 - configSP->stereo_screen_margin) / 4; configSP->center_screen_x[1] = 3 * configSP->center_screen_x[0] + configSP->stereo_screen_margin; } /** Both: **/ configSP->center_screen_y = guiSP->input_winS.y0 / 2; /* The stereo internal margin, in atomic_units: */ if (configSP->atomic_to_screen_scale_x == 0) { ErrorMessage_ ("garlic", "CalculateParameters_", "", "Scale factor (atomic to screen units) not initialized!\n", "", "", ""); return -6; } configSP->stereo_atomic_margin = (double) configSP->stereo_screen_margin / configSP->atomic_to_screen_scale_x; /* Bond length parameters: */ configSP->C_C_min_squared = configSP->C_C_bond_length_min * configSP->C_C_bond_length_min; configSP->C_C_max_squared = configSP->C_C_bond_length_max * configSP->C_C_bond_length_max; configSP->C_N_min_squared = configSP->C_N_bond_length_min * configSP->C_N_bond_length_min; configSP->C_N_max_squared = configSP->C_N_bond_length_max * configSP->C_N_bond_length_max; configSP->C_O_min_squared = configSP->C_O_bond_length_min * configSP->C_O_bond_length_min; configSP->C_O_max_squared = configSP->C_O_bond_length_max * configSP->C_O_bond_length_max; configSP->C_S_min_squared = configSP->C_S_bond_length_min * configSP->C_S_bond_length_min; configSP->C_S_max_squared = configSP->C_S_bond_length_max * configSP->C_S_bond_length_max; configSP->C_H_min_squared = configSP->C_H_bond_length_min * configSP->C_H_bond_length_min; configSP->C_H_max_squared = configSP->C_H_bond_length_max * configSP->C_H_bond_length_max; configSP->N_O_min_squared = configSP->N_O_bond_length_min * configSP->N_O_bond_length_min; configSP->N_O_max_squared = configSP->N_O_bond_length_max * configSP->N_O_bond_length_max; configSP->N_H_min_squared = configSP->N_H_bond_length_min * configSP->N_H_bond_length_min; configSP->N_H_max_squared = configSP->N_H_bond_length_max * configSP->N_H_bond_length_max; configSP->O_H_min_squared = configSP->O_H_bond_length_min * configSP->O_H_bond_length_min; configSP->O_H_max_squared = configSP->O_H_bond_length_max * configSP->O_H_bond_length_max; configSP->S_H_min_squared = configSP->S_H_bond_length_min * configSP->S_H_bond_length_min; configSP->S_H_max_squared = configSP->S_H_bond_length_max * configSP->S_H_bond_length_max; configSP->O_P_min_squared = configSP->O_P_bond_length_min * configSP->O_P_bond_length_min; configSP->O_P_max_squared = configSP->O_P_bond_length_max * configSP->O_P_bond_length_max; configSP->S_S_min_squared = configSP->S_S_bond_length_min * configSP->S_S_bond_length_min; configSP->S_S_max_squared = configSP->S_S_bond_length_max * configSP->S_S_bond_length_max; configSP->generic_min_squared = configSP->generic_bond_length_min * configSP->generic_bond_length_min; configSP->generic_max_squared = configSP->generic_bond_length_max * configSP->generic_bond_length_max; configSP->hydro_min_squared = configSP->hydro_bond_length_min * configSP->hydro_bond_length_min; configSP->hydro_max_squared = configSP->hydro_bond_length_max * configSP->hydro_bond_length_max; /* The maximal CA-CA distance squared: */ configSP->CA_CA_dist_max_squared = configSP->CA_CA_dist_max * configSP->CA_CA_dist_max; /* The light source unit vector: */ sin_theta = sin (configSP->light_theta); configSP->light_vectorS.x = sin_theta * cos (configSP->light_phi); configSP->light_vectorS.y = sin_theta * sin (configSP->light_phi); configSP->light_vectorS.z = cos (configSP->light_theta); /* If this point is reached, everything worked fine: */ return 1; } /*===========================================================================*/ garlic-1.6/big2.c0000644000076500007650000003165607747302110014112 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2003 Damir Zucic */ /*============================================================================= big2.c Purpose: Draw atoms as big spheres, version 2 (spacefill style 2). Input: (1) Pointer to MolComplexS structure. (2) Number of macromolecular complexes. (3) Pointer to ConfigS structure, with configuration data. (4) Pointer to GUIS structure. (5) Pointer to NearestAtomS structure, with information about the atom occupying the given pixel. (6) The number of pixels in the main window free area. (7) The refreshI, used to check the NearestAtomS associated with a given pixel. Output: (1) Spheres drawn to the hidden pixmap. (2) Return value. Return value: (1) Positive always (trivial). Notes: (1) Indentation is exceptionally 4 spaces. (2) The atomic radii used in this function are based on the radii used in spacefill drawing function (sp2.c). The values used here are 50% larger. =============================================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ unsigned long Sp2Color_ (AtomS *, GUIS *, double); /*======draw atoms as big spheres, version 2:================================*/ int DrawBigSpheres2_ (MolComplexS *mol_complexSP, int mol_complexesN, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int refreshI) { int imageI, imagesN; double scale_factor, user_atomic_position; int left_edge[2], right_edge[2]; int mol_complexI; MolComplexS *curr_mol_complexSP; size_t atomsN, atomI; AtomS *curr_atomSP; int screen_x0, screen_y0; double radius, radius_squared; double denominator, reciprocal_denominator; int screen_radius; long screen_radius_squared; int screen_x1, screen_y1, screen_x2, screen_y2; int screen_x, screen_y; long delta_x, delta_y, distance_squared; double z0, front_z, delta_z, z; size_t pixelI; NearestAtomS *curr_pixelSP; double denominator2, reciprocal_denominator2; double rho_squared; VectorS vectorS; double abs_value, abs_value_squared; double scalar_product, cos_angle; unsigned long colorID; int bondI; /* Initialize the bond index. The negative value means that pixels */ /* filled in this function are not a part of any chemical bond. */ bondI = -1; /* Number of images: */ if (configSP->stereoF) imagesN = 2; else imagesN = 1; scale_factor = configSP->user_screen_atomic_distance * configSP->atomic_to_screen_scale_x; /* Prepare the user position in atomic coordinates: */ user_atomic_position = configSP->user_atomic_position; /* Left and right image edge (in stereo mode there are two images): */ left_edge[0] = configSP->image_screen_x0[0]; right_edge[0] = configSP->image_screen_x1[0]; left_edge[1] = configSP->image_screen_x0[1]; right_edge[1] = configSP->image_screen_x1[1]; /*------first pass - fill NearestAtomS array with planar atoms:--------------*/ /* Draw each macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Prepare and check the number of atoms: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Draw atoms which have the given style: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Check style: */ if (curr_atomSP->raw_atomS.atom_styleI != BIG_SPHERE2) continue; /* Check is atom hidden: */ if (curr_atomSP->hiddenF) continue; /* Check is atom inside slab: */ if (!curr_atomSP->inside_slabF) continue; /* Check is atom inside window: */ if (!curr_atomSP->inside_windowF) continue; /* Atomic radius, in atomic units: */ radius = curr_atomSP->raw_atomS.van_der_Waals_radius; /* The y coordinate of atomic center, in screen units: */ screen_y0 = curr_atomSP->raw_atomS.screen_y; /* Prepare one image (mono) or two images (stereo): */ for (imageI = 0; imageI < imagesN; imageI++) { /* The z coordinate of atomic center, in atomic units: */ z0 = curr_atomSP->raw_atomS.z[imageI]; /* Prepare the factor required for projection of atomic radius: */ denominator = z0 - user_atomic_position; if (denominator == 0.0) continue; reciprocal_denominator = 1.0 / denominator; /* Atomic radius in screen units: */ screen_radius = (int) (radius * scale_factor * reciprocal_denominator + 0.5); /* Screen radius squared (used to improve speed): */ screen_radius_squared = (long) screen_radius * (long) screen_radius; /* The x coordinate of atomic center, in screen units: */ screen_x0 = curr_atomSP->raw_atomS.screen_x[imageI]; /* Define the bounding rectangle: */ screen_x1 = screen_x0 - screen_radius; screen_y1 = screen_y0 - screen_radius; screen_x2 = screen_x0 + screen_radius; screen_y2 = screen_y0 + screen_radius; /* Horizontal scan: */ for (screen_x = screen_x1; screen_x <= screen_x2; screen_x++) { /* Check horizontal position: */ if (screen_x < left_edge[imageI]) continue; if (screen_x >= right_edge[imageI]) continue; /* Vertical scan: */ for (screen_y = screen_y1; screen_y <= screen_y2; screen_y++) { /* Check vertical position: */ if (screen_y < 0) continue; if (screen_y >= (int) guiSP->main_win_free_area_height) { continue; } /* Check distance from the circle center: */ delta_x = (long) (screen_x - screen_x0); delta_y = (long) (screen_y - screen_y0); distance_squared = delta_x * delta_x + delta_y * delta_y; if (distance_squared > screen_radius_squared) continue; /* Prepare index to the array */ /* of NearestAtomS structures: */ pixelI = guiSP->main_win_free_area_width * screen_y + screen_x; /* Check the pixel index: */ if (pixelI >= pixelsN) continue; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = nearest_atomSP + pixelI; /* Check was this pixel used already in */ /* this drawing step; if it was, compare */ /* the z value of the current atom with z */ /* value previously stored to this pixel: */ if (refreshI == curr_pixelSP->last_refreshI) { if (z0 > curr_pixelSP->z) continue; } /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = BIG_SPHERE2; curr_pixelSP->last_refreshI = refreshI; curr_pixelSP->mol_complexI = mol_complexI; curr_pixelSP->atomI = atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = z0; } } } /* imageI loop */ } /* atomI loop */ } /* mol_complexI loop */ /*------second pass - draw spherical atoms:----------------------------------*/ /* Draw each macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Prepare and check the number of atoms: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Draw atoms which have the given style: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Check style: */ if (curr_atomSP->raw_atomS.atom_styleI != BIG_SPHERE2) continue; /* Check is atom hidden: */ if (curr_atomSP->hiddenF) continue; /* Check is atom inside slab: */ if (!curr_atomSP->inside_slabF) continue; /* Check is atom inside window: */ if (!curr_atomSP->inside_windowF) continue; /* Atomic radius, in atomic units: */ radius = curr_atomSP->raw_atomS.van_der_Waals_radius; /* Squared atomic radius: */ radius_squared = radius * radius; /* The y coordinate of atomic center, in screen units: */ screen_y0 = curr_atomSP->raw_atomS.screen_y; /* Prepare one image (mono) or two images (stereo): */ for (imageI = 0; imageI < imagesN; imageI++) { /* The z coordinate of atomic center, in atomic units: */ z0 = curr_atomSP->raw_atomS.z[imageI]; /* The z coordinate of the nearest */ /* point of a given atom (sphere): */ front_z = z0 - radius; /* Prepare the factor required for projection of atomic radius: */ denominator = z0 - user_atomic_position; if (denominator == 0.0) continue; reciprocal_denominator = 1.0 / denominator; /* Atomic radius in screen units: */ screen_radius = (int) (radius * scale_factor * reciprocal_denominator + 0.5); /* Square of the atomic radius (in screen units): */ screen_radius_squared = (long) screen_radius * (long) screen_radius; /* Reciprocal value will be used to improve performance: */ denominator2 = (double) screen_radius_squared; if (denominator2 == 0.0) continue; reciprocal_denominator2 = 1.0 / denominator2; /* The x coordinate of atomic center, in screen units: */ screen_x0 = curr_atomSP->raw_atomS.screen_x[imageI]; /* Define the bounding rectangle: */ screen_x1 = screen_x0 - screen_radius; screen_y1 = screen_y0 - screen_radius; screen_x2 = screen_x0 + screen_radius; screen_y2 = screen_y0 + screen_radius; /* Horizontal scan: */ for (screen_x = screen_x1; screen_x <= screen_x2; screen_x++) { /* Check horizontal position: */ if (screen_x < left_edge[imageI]) continue; if (screen_x > right_edge[imageI]) continue; /* Vertical scan: */ for (screen_y = screen_y1; screen_y <= screen_y2; screen_y++) { /* Check vertical position: */ if (screen_y < 0) continue; if (screen_y >= (int) guiSP->main_win_free_area_height) { continue; } /* Check distance from the circle center: */ delta_x = (long) (screen_x - screen_x0); delta_y = (long) (screen_y - screen_y0); distance_squared = delta_x * delta_x + delta_y * delta_y; if (distance_squared > screen_radius_squared) continue; /* Prepare index to the array */ /* of NearestAtomS structures: */ pixelI = guiSP->main_win_free_area_width * screen_y + screen_x; /* Check the pixel index: */ if (pixelI >= pixelsN) continue; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = nearest_atomSP + pixelI; /* Check z value (this is just a quick check): */ if (refreshI == curr_pixelSP->last_refreshI) { if (front_z > curr_pixelSP->z) continue; } /* Calculate the accurate z value: */ rho_squared = radius_squared * (double) distance_squared * reciprocal_denominator2; delta_z = sqrt (fabs (radius_squared - rho_squared)); z = z0 - delta_z; /* Check z value (precise check): */ if (refreshI == curr_pixelSP->last_refreshI) { if (z > curr_pixelSP->z) continue; } /* The vector from sphere center to the current pixel: */ vectorS.x = (double) delta_x; vectorS.y = (double) delta_y; vectorS.z = - sqrt (fabs (screen_radius_squared - vectorS.x * vectorS.x - vectorS.y * vectorS.y)); abs_value_squared = vectorS.x * vectorS.x + vectorS.y * vectorS.y + vectorS.z * vectorS.z; abs_value = sqrt (abs_value_squared); /* The scalar product between this */ /* vector and light source vector: */ scalar_product = vectorS.x * configSP->light_vectorS.x + vectorS.y * configSP->light_vectorS.y + vectorS.z * configSP->light_vectorS.z; /* Cosine of the angle between the vector to the */ /* current pixel and the light source unit vector: */ if (abs_value == 0.0) cos_angle = 0.0; else cos_angle = scalar_product / abs_value; /* Prepare color: */ colorID = Sp2Color_ (curr_atomSP, guiSP, cos_angle); XSetForeground (guiSP->displaySP, guiSP->theGCA[0], colorID); XDrawPoint (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x, screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = BIG_SPHERE2; curr_pixelSP->last_refreshI = refreshI; curr_pixelSP->mol_complexI = mol_complexI; curr_pixelSP->atomI = atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = z; curr_pixelSP->colorID = colorID; } } } /* imageI loop */ } /* atomI loop */ } /* mol_complexI loop */ /*---------------------------------------------------------------------------*/ /* Return positive value (trivial): */ return 1; } /*===========================================================================*/ garlic-1.6/alloc_nearest.c0000644000076500007650000000437307463606773016117 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2002 Damir Zucic */ /*============================================================================= alloc_nearest.c Purpose: Allocate memory for NearestAtomS array. The role of this array is described in typedefs.h file. This function is called only once. It allocates many bytes, so when garlic crashes, really big core file should be expected. If the main window is enlarged the NearestAtomS array should be reallocated. Input: (1) Pointer to the number of pixels in the free area of the main window. It is initialized with the number of allocated array elements. (2) Pointer to GUIS structure. Output: (1) Memory allocated. (2) The number of pixels updated. (3) Return value. Return value: (1) Pointer to allocated memory, on success. (2) NULL on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ void ErrorMessage_ (char *, char *, char *, char *, char *, char *, char *); /*======allocate memory for NearestAtomS array:==============================*/ NearestAtomS *AllocateNearest_ (size_t *pixelsNP, GUIS *guiSP) { static size_t elementsN; static size_t struct_size; static size_t mem_size; static NearestAtomS *nearest_atomSP; /* Prepare the parameters which define the size of memory chunk: */ elementsN = (size_t) guiSP->main_win_free_area_width * (size_t) guiSP->main_win_free_area_height; struct_size = sizeof (NearestAtomS); /* Allocate memory: */ nearest_atomSP = (NearestAtomS *) calloc (elementsN, struct_size); /* On failure: */ if (nearest_atomSP == NULL) { ErrorMessage_ ("garlic", "AllocateNearest_", "", "Failed to allocate memory for NearestAtomS array!\n", "", "", ""); mem_size = elementsN * struct_size; fprintf (stderr, "A total of %d bytes required.\n", mem_size); *pixelsNP = 0; return NULL; } /* On success, update the number of pixels: */ *pixelsNP = elementsN; return nearest_atomSP; } /*===========================================================================*/ garlic-1.6/draw_sticks.c0000644000076500007650000001212407604160107015571 0ustar zuciczucic00000000000000/* Copyright (C) 2002 Damir Zucic */ /*============================================================================= draw_sticks.c Purpose: Draw sticks (sort of spacefill style for bonds). Half of each bond is drawn and another half is assigned to the partner. Find the z value for each pixel. A bond is visible only if both atoms forming this bond are visible. Drawing direction: 1 -> 2. Input: (1) Pointer to MolComplexS structure. (2) Number of macromolecular complexes. (3) Pointer to ConfigS structure. (4) Pointer to GUIS structure. (5) Pointer to NearestAtomS structure, with information about the atom occupying the given pixel. (6) The number of pixels in the main window free area. (7) The refreshI, used to check the NearestAtomS associated with a given pixel. Output: (1) Sticks drawn to the hidden pixmap. (2) Return value. Return value: (1) The number of bonds drawn. Notes: (1) Indentation is exceptionally 4 spaces. (2) This drawing style is not allowed for hydrogen bonds. =============================================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int HalfStick_ (Aux2S *, int); /*======draw bonds as sticks:================================================*/ size_t DrawSticks_ (MolComplexS *mol_complexSP, int mol_complexesN, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int refreshI) { static size_t bonds_drawnN = 0; static int imageI, imagesN; static int mol_complexI; static MolComplexS *curr_mol_complexSP, *partner_mol_complexSP; static size_t atomsN, atomI; static AtomS *curr_atomSP, *partner_atomSP; static int bondsN, bondI; static TrueBondS *curr_bondSP; static Aux2S aux2S; /* Return if there are no structures: */ if (mol_complexesN == 0) return 0; /* Number of images: */ if (configSP->stereoF) imagesN = 2; else imagesN = 1; /* Copy some important pointers and parameters: */ aux2S.configSP = configSP; aux2S.guiSP = guiSP; aux2S.nearest_atomSP = nearest_atomSP; aux2S.pixelsN = pixelsN; aux2S.refreshI = refreshI; /* Draw each macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Prepare and check the number of atoms: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Copy the macromolecular complex index: */ aux2S.mol_complexI = mol_complexI; /* Copy the stick radius: */ aux2S.stick_radius = curr_mol_complexSP->stick_radius; /* Draw bonds which have the given style: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Check is atom hidden: */ if (curr_atomSP->hiddenF) continue; /* Check is atom inside slab: */ if (!curr_atomSP->inside_slabF) continue; /* Check is atom inside window: */ if (!curr_atomSP->inside_windowF) continue; /* Copy the pointer to the current atom: */ aux2S.atom1SP = curr_atomSP; /* Copy the atomic index: */ aux2S.atomI = atomI; /* Number of bonds: */ bondsN = curr_atomSP->bondsN; /* Bond loop: */ for (bondI = 0; bondI < bondsN; bondI++) { /* Pointer to the structure with data about current bond: */ curr_bondSP = curr_atomSP->true_bondSA + bondI; /* Check bond drawing style: */ if (curr_bondSP->bond_styleI != STICK_BONDS) continue; /* If the current bond is hydrogen bond, skip it: */ if (curr_bondSP->bond_typeI == 0) continue; /* The complex which contains the atom forming the bond: */ partner_mol_complexSP = mol_complexSP + curr_bondSP->neighbor_mol_complexI; /* Pointer to the bond partner: */ partner_atomSP = partner_mol_complexSP->atomSP + curr_bondSP->neighbor_arrayI; /* If partner is not visible, do not draw this bond: */ if (partner_atomSP->hiddenF) continue; /* Check is the partner inside the slab: */ if (!partner_atomSP->inside_slabF) continue; /* Check is the partner inside the window: */ if (!partner_atomSP->inside_windowF) continue; /* Copy the bond index: */ aux2S.bondI = bondI; /* Copy the pointer to the current bond: */ aux2S.curr_bondSP = curr_bondSP; /* Copy the pointer to the bond partner: */ aux2S.atom2SP = partner_atomSP; /* Draw one (mono) or two bonds (stereo): */ for (imageI = 0; imageI < imagesN; imageI++) { /* Copy the image index: */ aux2S.imageI = imageI; /* Draw half of a stick: */ HalfStick_ (&aux2S, bondI); /* Update the counter: */ bonds_drawnN++; } /* imageI loop */ } /* bondI loop */ } /* atomI loop */ } /* mol_complexI loop */ /* Return the number of bonds which were drawn: */ return bonds_drawnN; } /*===========================================================================*/ garlic-1.6/project_planes.c0000644000076500007650000001540507377375535016315 0ustar zuciczucic00000000000000/* Copyright (C) 2000, 2001 Damir Zucic */ /*============================================================================= project_planes.c Purpose: For each macromolecular complex, project plane to the screen. The plane is represented by a circle in space, which projects into an ellipse. The plane is projected always, even if not visible. This function prepares only parameters which are kept in PlaneS structure, associated with a given macromolecular complex. Other parameters will be prepared in a function which draws plane to the screen. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. (3) Pointer to ConfigS structure, with configuration data. Output: (1) Parameters which define plane projection to the screen will be calculated for each macromolecular complex containing at least one atom. Return value: No return value. ========includes:============================================================*/ #include #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======project planes:=======================================================*/ void ProjectPlanes_ (MolComplexS *mol_complexSP, int mol_complexesN, ConfigS *configSP) { double nominator_x, nominator_y, user_atomic_position; int center_screen_x[2], center_screen_y; int mol_complexI; MolComplexS *curr_mol_complexSP; PlaneS *curr_planeSP; int imagesN, imageI; double denominator, reciprocal_denominator; double normal_x, normal_y, normal_z; double rationalized_x, rationalized_y; double scalar_product, abs_value_squared, abs_value; double cos_theta, cos_phi, angle; double value1, value2; /* The number of images (1 for mono, 2 for stereo): */ if (configSP->stereoF == 1) imagesN = 2; else imagesN = 1; /* Prepare the factors which are used to */ /* reduce the number of multiplications: */ nominator_x = configSP->user_screen_atomic_distance * configSP->atomic_to_screen_scale_x; nominator_y = configSP->user_screen_atomic_distance * configSP->atomic_to_screen_scale_y; /* Prepare the user position in atomic coordinates: */ user_atomic_position = configSP->user_atomic_position; /* Position of the window free area center (stereo data): */ center_screen_x[0] = configSP->center_screen_x[0]; center_screen_x[1] = configSP->center_screen_x[1]; center_screen_y = configSP->center_screen_y; /* Project plane for each macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* If this complex contains no atoms, ignore it: */ if (curr_mol_complexSP->atomsN == 0) continue; /* Projection is not necessary if the position is unchanged: */ if (curr_mol_complexSP->position_changedF == 0) continue; /* Pointer to the current plane: */ curr_planeSP = &curr_mol_complexSP->planeS; /* Stereo data should be prepared: */ for (imageI = 0; imageI < imagesN; imageI++) { /*------prepare auxilliary parameters:-----------------------*/ denominator = curr_planeSP->center_z[imageI] - user_atomic_position; if (denominator == 0.0) reciprocal_denominator = 0.0; else reciprocal_denominator = 1.0 / denominator; normal_x = curr_planeSP->normal_x[imageI]; normal_y = curr_planeSP->normal_y; normal_z = curr_planeSP->normal_z[imageI]; /*------project plane center to the screen:------------------*/ /* Prepare rationalized coordinates: */ rationalized_x = curr_planeSP->center_x[imageI] * nominator_x * reciprocal_denominator; rationalized_y = curr_planeSP->center_y * nominator_y * reciprocal_denominator; /* Keep them in a reasonable range: */ if (rationalized_x > (double) INT_MAX / 4) rationalized_x = (double) INT_MAX / 4; else if (rationalized_x < (double) INT_MIN / 4) rationalized_x = (double) INT_MIN / 4; if (rationalized_y > (double) INT_MAX / 4) rationalized_y = (double) INT_MAX / 4; else if (rationalized_y < (double) INT_MIN / 4) rationalized_y = (double) INT_MIN / 4; /* Prepare screen coordinates of the plane center: */ curr_planeSP->center_screen_x[imageI] = (int) rationalized_x + center_screen_x[imageI]; curr_planeSP->center_screen_y = (int) rationalized_y + center_screen_y; /*------angle between normal vector and z axis:--------------*/ scalar_product = normal_z; abs_value_squared = normal_x * normal_x + normal_y * normal_y + normal_z * normal_z; abs_value = sqrt (abs_value_squared); if (abs_value == 0.0) { cos_theta = 0.0; curr_planeSP->normal_theta[imageI] = 1.5707963; } else { cos_theta = scalar_product / abs_value; if (cos_theta <= -1.0) angle = 3.1415927; else if (cos_theta >= 1.0) angle = 0.0; else angle = acos (cos_theta); curr_planeSP->normal_theta[imageI] = angle; } /*------visible side index (0 = top, 1 = bottom):------------*/ if (cos_theta <= 0.0) curr_planeSP->visible_sideI[imageI] = 0; else curr_planeSP->visible_sideI[imageI] = 1; /*------angle between x and project. of n. v. to xy plane:---*/ /* Prepare and check the cosine of normal_phi: */ abs_value = sqrt (normal_x * normal_x + normal_y * normal_y); cos_phi = normal_x / abs_value; if (cos_phi > 1.0) cos_phi = 1.0; if (cos_phi < -1.0) cos_phi = -1.0; /* The special case (undefined phi): */ if ((normal_x == 0.0) && (normal_y == 0.0)) { curr_planeSP->normal_phi[imageI] = 0.0; } /* If y component of the normal vector is positive: */ else if (normal_y >= 0.0) { if (cos_phi <= -1.0) angle = 3.1415927; else if (cos_phi >= 1.0) angle = 0.0; else angle = acos (cos_phi); curr_planeSP->normal_phi[imageI] = angle; } /* If y component of the normal vector is negative: */ else { if (cos_phi <= -1.0) angle = 3.1415927; else if (cos_phi >= 1.0) angle = 0.0; else angle = acos (cos_phi); curr_planeSP->normal_phi[imageI] = 6.2831853 - angle; } /*------large half axis of the ellipse in screen units:------*/ value1 = curr_planeSP->circle_radius * nominator_x * reciprocal_denominator; value2 = curr_planeSP->circle_radius * nominator_y * reciprocal_denominator; if (value1 > value2) curr_planeSP->screen_a = value1; else curr_planeSP->screen_a = value2; /*------small half axis of the ellipse (stereo data):--------*/ curr_planeSP->screen_b[imageI] = curr_planeSP->screen_a * fabs (cos_theta); /* The minimal value should be one: */ if (curr_planeSP->screen_b[imageI] < 1.0) curr_planeSP->screen_b[imageI] = 1.0; } } } /*===========================================================================*/ garlic-1.6/prepare_oc.c0000644000076500007650000000504207461731661015406 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2002 Damir Zucic */ /*============================================================================= prepare_oc.c Purpose: Prepare O-C vector, used to check the hydrogen bond angle. This function assumes that the atom you specify is an oxygen atom. No check is done! Input: (1) Pointer to VectorS structure. (2) Pointer to AtomS structure. (3) Pointer to MolComplexS structure, pointing to the first such structure. (3) Macromolecular complex index. Output: (1) O-C vector may be prepared. (2) Return value. Return value: (1) Positive on success. (2) Negative on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======prepare O-C vector:==================================================*/ int PrepareOCVector_ (VectorS *O_C_vectorSP, AtomS *atom1SP, MolComplexS *mol_complexSP, int mol_complexI) { int bondsN, bondI; int carbon_foundF; TrueBondS *curr_bondSP; int neighbor_mol_complexI; AtomS *atom2SP; /* Prepare and check the number of bonds associated with a given atom: */ bondsN = atom1SP->bondsN; if (bondsN <= 0) return -1; /* Try to find the carbon atom: */ carbon_foundF = 0; for (bondI = 0; bondI < bondsN; bondI++) { /** Pointer to the current bond: **/ curr_bondSP = atom1SP->true_bondSA + bondI; /** The neighbor should belong to the same macromol. complex: **/ neighbor_mol_complexI = curr_bondSP->neighbor_mol_complexI; if (neighbor_mol_complexI != mol_complexI) continue; /** Pointer to the neighboring atom: **/ atom2SP = (mol_complexSP + neighbor_mol_complexI)->atomSP + curr_bondSP->neighbor_arrayI; /** Check is neighboring atom carbon: **/ if (strcmp (atom2SP->raw_atomS.chemical_symbolA, " C") != 0) continue; /** If this point is reached, the neighboring **/ /** atom is carbon; prepare the O-C vector: **/ O_C_vectorSP->x = atom2SP->raw_atomS.x[0] - atom1SP->raw_atomS.x[0]; O_C_vectorSP->y = atom2SP->raw_atomS.y - atom1SP->raw_atomS.y; O_C_vectorSP->z = atom2SP->raw_atomS.z[0] - atom1SP->raw_atomS.z[0]; /** Set the flag which says that carbon atom was found: **/ carbon_foundF = 1; /** Break from the loop, job is done: **/ break; } /* Return negative value on failure: */ if (!carbon_foundF) return -2; /* Return positive value on success: */ return 1; } /*===========================================================================*/ garlic-1.6/blur.c0000644000076500007650000000746307611075042014233 0ustar zuciczucic00000000000000/* Copyright (C) 2003 Damir Zucic */ /*============================================================================= blur.c Purpose: Execute blur command: set blur flag and define blur rectangle size. Blur will not affect labels, tags, titles and the small coordinate system in the top left corner. Input: (1) Pointer to MolComplexS structure. (2) The number of macromolecular complexes. (3) Pointer to RuntimeS structure. (4) Pointer to ConfigS structure. (5) Pointer to GUIS structure. (6) Pointer to NearestAtomS structure. (7) The number of pixels in the main window free area. (8) Pointer to refreshI. (9) Pointer to the remainder of the command string. This command may be given without any keyword, with the keyword OFF or with two positive integers (blur rectangle width and height). Output: (1) The blur flag set and (on request) the blur rectangle width and height changed. (2) Return value. Return value: (1) Positive (command) code on success. (2) Negative (error) code on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "commands.h" #include "typedefs.h" /*======function prototypes:=================================================*/ char *ExtractToken_ (char *, int, char *, char *); int ExtractTwoIntegers_ (int *, int *, char *); size_t MainRefresh_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); int ControlRefresh_ (MolComplexS *, ConfigS *, GUIS *); /*======execute blur command:================================================*/ int Blur_ (MolComplexS *mol_complexSP, int mol_complexesN, RuntimeS *runtimeSP, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int *refreshIP, char *stringP) { char *remainderP; char tokenA[SHORTSTRINGSIZE]; char *P; int n; int width, height; /* Set the blur flag to one. This may change */ /* later, if the keyword OFF will be found. */ runtimeSP->blurF = 1; /* Extract the first token: */ remainderP = ExtractToken_ (tokenA, STRINGSIZE, stringP, " \t\n"); /* If available, the first token should contain */ /* the keyword OFF or two positive integers: */ if (remainderP) { /* If keyword OFF is present, reset the blur flag to zero: */ if (strstr (tokenA, "OFF") == tokenA) { /* Reset the blur flag: */ runtimeSP->blurF = 0; } /* If the keyword OFF is not present, */ /* two positive integers are expected: */ else { /* Replace each minus in the input string with space: */ P = stringP; while ((n = *P++) != '\0') { if (n == '-') *(P - 1) = ' '; } /* If reading fails: */ if (ExtractTwoIntegers_ (&width, &height, stringP) < 0) { strcpy (runtimeSP->messageA, "Two positive integers expected!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_BLUR; } /* If two integers were successfully read, check them: */ if ((width <= 0) || (height <= 0)) { strcpy (runtimeSP->messageA, "Two positive integers expected!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_BLUR; } /* Store the extracted width and height: */ runtimeSP->blur_width = width; runtimeSP->blur_height = height; } } /* Refresh the main window: */ (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); /* Refresh the control window: */ ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); /* Return the command code: */ return COMMAND_BLUR; } /*===========================================================================*/ garlic-1.6/translate_membrane.c0000644000076500007650000000225207400133502017111 0ustar zuciczucic00000000000000/* Copyright (C) 2001 Damir Zucic */ /*============================================================================= translate_membrane.c Purpose: Translate the membrane. Input: (1) Pointer to MolComplexS structure. (2) Pointer to VectorS structure, with shift vector. Output: (1) Membrane translated. Return value: No return value. ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======translate membrane:==================================================*/ void TranslateMembrane_ (MolComplexS *curr_mol_complexSP, VectorS *shift_vectorSP) { MembraneS *membraneSP; /* Pointer to the current membrane: */ membraneSP = &curr_mol_complexSP->membraneS; /* Translate the membrane center: */ membraneSP->center_x += shift_vectorSP->x; membraneSP->center_y += shift_vectorSP->y; membraneSP->center_z += shift_vectorSP->z; /* Set the position_changedF: */ curr_mol_complexSP->position_changedF = 1; } /*===========================================================================*/ garlic-1.6/1mal.script0000644000076500007650000000024307050335203015163 0ustar zuciczucic00000000000000load 1mal.pdb select side hide select hetero hide select 22-37, 105-124, 237-266, 353-360, 374-406 hide rotate x 90 rotate y 120 select main_chain atoms 0 bonds 3 garlic-1.6/refresh_backbone.c0000644000076500007650000001012607747301666016555 0ustar zuciczucic00000000000000/* Copyright (C) 2001-2003 Damir Zucic */ /*============================================================================= refresh_backbone.c Purpose: Refresh the backbone information. Input: (1) Pointer to MolComplexS structure. (2) Pointer to ConfigS structure. Output: (1) The array of BackboneS structures refreshed. (2) Return value. Return value: (1) Positive on success. (2) Zero if there are no atoms. ========includes:============================================================*/ #include #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ void ErrorMessage_ (char *, char *, char *, char *, char *, char *, char *); /*======refresh backbone data:===============================================*/ int RefreshBackbone_ (MolComplexS *mol_complexSP, ConfigS *configSP) { size_t atomI, atomsN; AtomS *curr_atomSP; int c_alphaI = 0; BackboneS *curr_backboneSP; size_t atom1I, atom2I; AtomS *atom0SP, *atom1SP, *atom2SP; double x0, y0, z0, x1, y1, z1, x2, y2, z2, delta_x, delta_y, delta_z; double d1_squared, d2_squared; double max_dist_squared; /* Return zero if there are no atoms in this macromolecular complex: */ atomsN = mol_complexSP->atomsN; if (atomsN == 0) return 0; /* The maximal distance squared: */ max_dist_squared = configSP->CA_CA_dist_max_squared; /* Initialize the BackboneS pointer: */ curr_backboneSP = mol_complexSP->backboneSP; /* Scan the macromolecular complex and copy */ /* the updated array indices of CA atoms: */ for (atomI = 0; atomI < atomsN; atomI++) { /** Pointer to the current atom: **/ curr_atomSP = mol_complexSP->atomSP + atomI; /** Check the purified atom name: **/ if (strcmp (curr_atomSP->raw_atomS.pure_atom_nameA, "CA") != 0) continue; /** Pointer to the current BackboneS structure: **/ curr_backboneSP = mol_complexSP->backboneSP + c_alphaI; /** Copy the index of the current atom: **/ curr_backboneSP->c_alphaI = atomI; /** Update and check the counter of CA atoms: **/ c_alphaI++; if (c_alphaI >= (int) mol_complexSP->c_alphaN) break; } /* Check distances between neighbouring CA atoms: */ for (c_alphaI = 0; c_alphaI < (int) mol_complexSP->c_alphaN; c_alphaI++) { /** Pointer to the current BackboneS: **/ curr_backboneSP = mol_complexSP->backboneSP + c_alphaI; /** Pointer to the current CA atom: **/ atom0SP = mol_complexSP->atomSP + curr_backboneSP->c_alphaI; /** Position of the current CA atom: **/ x0 = atom0SP->raw_atomS.x[0]; y0 = atom0SP->raw_atomS.y; z0 = atom0SP->raw_atomS.z[0]; /** Check distances between current CA, previous CA and next CA: **/ /*** For the first CA, the previous CA does not exist: ***/ if (c_alphaI > 0) { atom1I = (curr_backboneSP - 1)->c_alphaI; atom1SP = mol_complexSP->atomSP + atom1I; x1 = atom1SP->raw_atomS.x[0]; y1 = atom1SP->raw_atomS.y; z1 = atom1SP->raw_atomS.z[0]; delta_x = x1 - x0; delta_y = y1 - y0; delta_z = z1 - z0; d1_squared = delta_x * delta_x + delta_y * delta_y + delta_z * delta_z; if (d1_squared <= max_dist_squared) { curr_backboneSP->previous_c_alphaF = 1; curr_backboneSP->previous_c_alphaI = atom1I; } else curr_backboneSP->previous_c_alphaF = 0; } /*** For the last CA, the next CA does not exist: ***/ if (c_alphaI < (int) mol_complexSP->c_alphaN - 1) { atom2I = (curr_backboneSP + 1)->c_alphaI; atom2SP = mol_complexSP->atomSP + atom2I; x2 = atom2SP->raw_atomS.x[0]; y2 = atom2SP->raw_atomS.y; z2 = atom2SP->raw_atomS.z[0]; delta_x = x2 - x0; delta_y = y2 - y0; delta_z = z2 - z0; d2_squared = delta_x * delta_x + delta_y * delta_y + delta_z * delta_z; if (d2_squared <= max_dist_squared) { curr_backboneSP->next_c_alphaF = 1; curr_backboneSP->next_c_alphaI = atom2I; } else curr_backboneSP->next_c_alphaF = 0; } } /* Return positive value on success: */ return 1; } /*===========================================================================*/ garlic-1.6/extract_cac.c0000644000076500007650000000441407306011754015541 0ustar zuciczucic00000000000000/* Copyright (C) 2001 Damir Zucic */ /*============================================================================= extract_cac.c Purpose: Extract CA and C coordinates for a given residue. Input: (1) Pointer to VectorS structure, where CA coord. will be stored. (2) Pointer to VectorS structure, where C coord. will be stored. (3) Pointer to AtomS structure, pointing to the first element of the atomic array. (4) Index of the first atom of a given residue. (5) Index of the last atom of a given residue. Output: (1) VectorS structures filled with data. (2) Return value. Return value: (1) The number of successfully extracted vectors (at least zero, at most two). Notes: (1) Some files contain more than one entry for some atoms. Garlic uses only the first entry and discards other entries for the same atom. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======extract CA and C coordinates:========================================*/ int ExtractCAC_ (VectorS *CA_vectorSP, VectorS *C_vectorSP, AtomS *atomSP, size_t atom_startI, size_t atom_endI) { int vectors_extractedN = 0; size_t atomI; AtomS *curr_atomSP; int CA_foundF = 0, C_foundF = 0; /* Scan the given residue: */ for (atomI = atom_startI; atomI <= atom_endI; atomI++) { /* Pointer to the current atom: */ curr_atomSP = atomSP + atomI; /* CA: */ if (strcmp (curr_atomSP->raw_atomS.pure_atom_nameA, "CA") == 0) { if (CA_foundF) continue; CA_vectorSP->x = curr_atomSP->raw_atomS.x[0]; CA_vectorSP->y = curr_atomSP->raw_atomS.y; CA_vectorSP->z = curr_atomSP->raw_atomS.z[0]; vectors_extractedN++; CA_foundF = 1; } /* C: */ else if (strcmp (curr_atomSP->raw_atomS.pure_atom_nameA, "C") == 0) { if (C_foundF) continue; C_vectorSP->x = curr_atomSP->raw_atomS.x[0]; C_vectorSP->y = curr_atomSP->raw_atomS.y; C_vectorSP->z = curr_atomSP->raw_atomS.z[0]; vectors_extractedN++; C_foundF = 1; } } /* Return the number of extracted vectors: */ return vectors_extractedN; } /*===========================================================================*/ garlic-1.6/title.c0000644000076500007650000001611407117143352014402 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= title.c Purpose: Execute title command: write the title to the specified position at the screen. The same command may be used to hide the title. Input: (1) Pointer to MolComplexS structure. (2) The number of macromolecular complexes. (3) Pointer to RuntimeS structure. (4) Pointer to ConfigS structure. (5) Pointer to GUIS structure. (6) Pointer to NearestAtomS structure. (7) The number of pixels in the main window free area. (8) Pointer to refreshI. Output: (1) The specified title written or hidden. (2) Return value. Return value: (1) Positive (command) code on success. (2) Negative (error) code on failure. Notes: (1) This function uses the original command string, to preserve case. The first token is the keyword title (tit). The rest of the command string may contain three numeric values and the title string, three numeric values, or one numeric value and keyword OFF. Here are some examples: ------------------------------------------------------------- | Example Purpose | ------------------------------------------------------------- | TITLE 1 100 50 "PORIN" | Add the title number 1 to the | | | screen at the position (100, 50) | ------------------------------------------------------------- | TITLE 2 200 80 | Move the title number 2 to the | | | position (200, 80) | ------------------------------------------------------------- | TITLE 4 OFF | Hide the title number 4 | ------------------------------------------------------------- (2) The lowest title index is zero. The highest is MAXTITLES - 1. ========includes:============================================================*/ #include #include #include #include #include #include #include #include "defines.h" #include "commands.h" #include "typedefs.h" /*======function prototypes:=================================================*/ char *ExtractToken_ (char *, int, char *, char *); size_t MainRefresh_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); int ControlRefresh_ (MolComplexS *, ConfigS *, GUIS *); /*======execute title command:===============================================*/ int Title_ (MolComplexS *mol_complexSP, int mol_complexesN, RuntimeS *runtimeSP, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int *refreshIP) { char *stringP; char *remainderP; char tokenA[STRINGSIZE]; int tokensN = 0; int titleI, screen_x, screen_y; char *P; int n; /* Skip the first token: */ stringP = ExtractToken_ (tokenA, STRINGSIZE, runtimeSP->curr_commandA, " \t\n"); if (!stringP) return ERROR_TITLE; /* Count tokens: */ remainderP = stringP; while ((remainderP = ExtractToken_ (tokenA, STRINGSIZE, remainderP, " \t,;")) != NULL) tokensN++; /* If there are too few tokens: */ if (tokensN < 2) { strcpy (runtimeSP->messageA, "Command incomplete!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_TITLE; } /* In all three cases, the first token should contain the title index: */ remainderP = ExtractToken_ (tokenA, STRINGSIZE, stringP, " \t,;"); if ((sscanf (tokenA, "%d", &titleI) != 1) || (titleI < 0) || (titleI > MAXTITLES - 1)) { strcpy (runtimeSP->messageA, "Bad token index!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_TITLE; } /* Add new title: */ if (tokensN >= 4) { /** At least one (single or double) quote should be present: */ if ((strstr (remainderP, "\"") == NULL) && (strstr (remainderP, "'") == NULL)) { strcpy (runtimeSP->messageA, "The title string should be enclosed in qoutes!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_TITLE; } /** The second token contains the x coordinate in screen units: **/ remainderP = ExtractToken_ (tokenA, STRINGSIZE, remainderP, " \t,;"); if (sscanf (tokenA, "%d", &screen_x) != 1) { strcpy (runtimeSP->messageA, "Bad x coordinate!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_TITLE; } /** The third token contains the y coordinate in screen units: **/ remainderP = ExtractToken_ (tokenA, STRINGSIZE, remainderP, " \t,;"); if (sscanf (tokenA, "%d", &screen_y) != 1) { strcpy (runtimeSP->messageA, "Bad y coordinate!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_TITLE; } /** Copy the coordinates: **/ runtimeSP->title_screen_x[titleI] = screen_x; runtimeSP->title_screen_y[titleI] = screen_y; /** The title string should be enclosed in single or double quotes: **/ remainderP = strstr (remainderP, "\"") + 1; ExtractToken_ (tokenA, STRINGSIZE, remainderP, "\""); /* Copy the title: */ P = runtimeSP->titlesP + titleI * TITLESTRINGSIZE; strncpy (P, tokenA, TITLESTRINGSIZE - 1); *(P + TITLESTRINGSIZE - 1) = '\0'; /** Unhide the specified title: **/ runtimeSP->title_hiddenF[titleI] = 0; } /* Move title to a new position: */ else if (tokensN == 3) { /** The second token contains the x coordinate in screen units: **/ remainderP = ExtractToken_ (tokenA, STRINGSIZE, remainderP, " \t,;"); if (sscanf (tokenA, "%d", &screen_x) != 1) { strcpy (runtimeSP->messageA, "Bad x coordinate!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_TITLE; } /** The third token cotains the y coordinate in screen units: **/ ExtractToken_ (tokenA, STRINGSIZE, remainderP, " \t,;"); if (sscanf (tokenA, "%d", &screen_y) != 1) { strcpy (runtimeSP->messageA, "Bad y coordinate!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_TITLE; } /** Copy new coordinates: **/ runtimeSP->title_screen_x[titleI] = screen_x; runtimeSP->title_screen_y[titleI] = screen_y; } /* Hide title: */ else if (tokensN == 2) { /** The second token should be the keyword OFF: **/ ExtractToken_ (tokenA, STRINGSIZE, remainderP, " \t,;"); P = tokenA; while ((n = *P++) != '\0') *(P - 1) = toupper (n); if (strstr (tokenA, "OFF") != tokenA) { n = STRINGSIZE - 100; if (n < 0) n = 0; tokenA[n] = '\0'; sprintf (runtimeSP->messageA, "Keyword %s not recognized!", tokenA); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_TITLE; } /** Hide the specified title: **/ runtimeSP->title_hiddenF[titleI] = 1; } /* Refresh the main window: */ (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); /* Refresh the control window: */ ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); /* Return the command code: */ return COMMAND_TITLE; } /*===========================================================================*/ garlic-1.6/extract_int.c0000644000076500007650000000213607124206504015601 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= extract_int.c Purpose: Extract integer from string. Start reading after the colon, if present. Input: Input string pointer. Output: Return value. Return value: (1) Integer read from string, on success. (2) Zero if there are no digits. ========includes:============================================================*/ #include #include #include /*======extract integer from a string:=======================================*/ int ExtractInteger_ (char *sP) { char *P0, *P1; int n; /* Colon should be separator: */ if ((P0 = strstr (sP, ":")) == NULL) P0 = sP; /* Replace each non-numeric character except minus sign with space: */ P1 = P0; while ((n = *P1++) != '\0') if (!isdigit (n) && (n != '-')) *(P1 - 1) = ' '; /* Try to read one integer: */ if (sscanf (P0, "%d", &n) != 1) return 0; /* If everything worked fine, return the extracted integer: */ return n; } /*===========================================================================*/ garlic-1.6/no_slab.c0000644000076500007650000000265707065474110014706 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= no_slab.c Purpose: Set the slab flag for each atom in a macromolecular complex to one. Return the total number of atoms in a complex. Input: (1) Pointer to MolComplexS structure. Output: (1) Slab flag set to one for each atom. This means that slab is not not used, i.e. all atoms are inside the slab. (2) Return value. Return value: The total number of atoms in a macromolecular complex. ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======slab not used:=======================================================*/ size_t NoSlab_ (MolComplexS *curr_mol_complexSP) { size_t atoms_inside_slabN; size_t atomsN, atomI; /* The number of atoms in a complex: */ atomsN = curr_mol_complexSP->atomsN; atoms_inside_slabN = atomsN; /* Set both slab flags for each atom to one: */ for (atomI = 0; atomI < atomsN; atomI++) { (curr_mol_complexSP->atomSP + atomI)->inside_slabF = 1; (curr_mol_complexSP->atomSP + atomI)->inside_projected_slabF = 1; } /* Return the total number of atoms in the macromolecular complex: */ return atoms_inside_slabN; } /*===========================================================================*/ garlic-1.6/extract_nca.c0000644000076500007650000000441407274626540015565 0ustar zuciczucic00000000000000/* Copyright (C) 2001 Damir Zucic */ /*============================================================================= extract_nca.c Purpose: Extract N and CA coordinates for a given residue. Input: (1) Pointer to VectorS structure, where N coord. will be stored. (2) Pointer to VectorS structure, where CA coord. will be stored. (3) Pointer to AtomS structure, pointing to the first element of the atomic array. (4) Index of the first atom of a given residue. (5) Index of the last atom of a given residue. Output: (1) VectorS structures filled with data. (2) Return value. Return value: (1) The number of successfully extracted vectors (at least zero, at most two). Notes: (1) Some files contain more than one entry for some atoms. Garlic uses only the first entry and discards other entries for the same atom. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======extract N and CA coordinates:========================================*/ int ExtractNCA_ (VectorS *N_vectorSP, VectorS *CA_vectorSP, AtomS *atomSP, size_t atom_startI, size_t atom_endI) { int vectors_extractedN = 0; size_t atomI; AtomS *curr_atomSP; int N_foundF = 0, CA_foundF = 0; /* Scan the given residue: */ for (atomI = atom_startI; atomI <= atom_endI; atomI++) { /* Pointer to the current atom: */ curr_atomSP = atomSP + atomI; /* N: */ if (strcmp (curr_atomSP->raw_atomS.pure_atom_nameA, "N") == 0) { if (N_foundF) continue; N_vectorSP->x = curr_atomSP->raw_atomS.x[0]; N_vectorSP->y = curr_atomSP->raw_atomS.y; N_vectorSP->z = curr_atomSP->raw_atomS.z[0]; vectors_extractedN++; N_foundF = 1; } /* CA: */ else if (strcmp (curr_atomSP->raw_atomS.pure_atom_nameA, "CA") == 0) { if (CA_foundF) continue; CA_vectorSP->x = curr_atomSP->raw_atomS.x[0]; CA_vectorSP->y = curr_atomSP->raw_atomS.y; CA_vectorSP->z = curr_atomSP->raw_atomS.z[0]; vectors_extractedN++; CA_foundF = 1; } } /* Return the number of extracted vectors: */ return vectors_extractedN; } /*===========================================================================*/ garlic-1.6/is_old.c0000644000076500007650000000235507156465740014547 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= is_old.c Purpose: Convert the string to uppercase and compare it with the word "OLD". If they are equal, return 1, otherwise return 0. Input: (1) Output string pointer. Output: (1) Return value. Return value: (1) Positive, if input string contains the word "OLD". (2) Zero otherwise. ========includes:============================================================*/ #include #include #include #include "defines.h" /*======compare the string with the word "OLD":==============================*/ int IsOld_ (char *stringP) { char string_copyA[SHORTSTRINGSIZE]; char *P; int n; /* Copy the input string: */ strncpy (string_copyA, stringP, SHORTSTRINGSIZE - 1); string_copyA[SHORTSTRINGSIZE - 1] = '\0'; /* Convert the string copy to uppercase: */ P = string_copyA; while ((n = *P++) != '\0') *(P - 1) = toupper (n); /* Check the string content - compare it with the word "OLD": */ if (strcmp (string_copyA, "OLD") != 0) return 0; /* If this point is reached, string contains the word "OLD": */ return 1; } /*===========================================================================*/ garlic-1.6/is_pdb.c0000644000076500007650000000722507117421625014526 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= is_pdb.c Purpose: Check is input file in PDB format. Check up to 100 lines: if 80% or more lines contain PDB keywords, file is recognized as PDB file. If there are less than 10 lines, at least one should contain some PDB keyword. Lines which contain less than six characters are not counted. Input: (1) File name. Output: (1) Return value. Return value: (1) PDB_FORMAT identifier on success (see defines.h for values). (3) Negative on failure. Notes: (1) Note that END record contains only three characters. The lines with END record do not contain any data. (2) Read openfile_r.c, fopen () is there. ========includes:============================================================*/ #include #include #include "defines.h" /*======function prototypes:=================================================*/ void ErrorMessage_ (char *, char *, char *, char *, char *, char *, char *); FILE *OpenFileForReading_ (char *); /*======check is file format PDB format:=====================================*/ int IsPDB_ (char *file_nameP) { FILE *fileP; int lineI = 0; char lineA[STRINGSIZE]; int line_size, i, line_length; int total_linesN = 0; int good_linesN = 0; double percentage; static char PDBKeywordAA[PDB_KEYWORDS][7] = {"HEADER", "OBSLTE", "TITLE ", "CAVEAT", "COMPND", "SOURCE", "KEYWDS", "EXPDTA", "AUTHOR", "REVDAT", "SPRSDE", "JRNL ", "REMARK", "DBREF ", "SEQADV", "SEQRES", "MODRES", "HET ", "HETNAM", "HETSYN", "FORMUL", "HELIX ", "SHEET ", "TURN ", "SSBOND", "LINK ", "HYDBND", "SLTBRG", "CISPEP", "SITE ", "CRYST1", "ORIGX1", "ORIGX2", "ORIGX3", "SCALE1", "SCALE2", "SCALE3", "MTRIX1", "MTRIX2", "MTRIX3", "TVECT ", "MODEL ", "ATOM ", "SIGATM", "ANISOU", "SIGUIJ", "TER ", "HETATM", "ENDMDL", "CONECT", "MASTER", "END"}; /* PDB cares for the order! */ /* Open file: */ fileP = OpenFileForReading_ (file_nameP); if (fileP == NULL) { ErrorMessage_ ("garlic", "IsPDB_", file_nameP, "Failed to open file!\n", "", "", ""); return OPEN_FAILURE; } /* Read up to 100 lines: */ line_size = sizeof (lineA); while (lineI++ < 100) { /* Read next line: */ if (fgets (lineA, line_size, fileP) == NULL) break; /* Remove the trailing newline: */ line_length = strlen (lineA); if (line_length == 0) continue; if (lineA[line_length - 1] == '\n') lineA[line_length - 1] = '\0'; /* Lines shorter than 6 characters are not counted: */ if (line_length < 6) continue; /* Truncate line to six characters: */ lineA[6] = '\0'; /* Increase count of lines read: */ total_linesN++; /* Look for PDB keywords: */ for (i = 0; i < PDB_KEYWORDS; i++) { /** Compare the first character: **/ if (*lineA != PDBKeywordAA[i][0]) continue; /** Compare with entire keyword: **/ if (strcmp (lineA, PDBKeywordAA[i]) != 0) continue; /** If this point is reached, PDB keyword is found: **/ good_linesN++; } } /* Close file: */ fclose (fileP); /* Check how many lines were taken into account: */ if (total_linesN == 0) return -1; /* Return PDB_FORMAT identifier if at least 80% of PDB lines were found: */ percentage = (double) good_linesN / (double) total_linesN; if (percentage >= 0.80) return PDB_FORMAT; /* See defines.h ! */ /* If there are only 10 lines or less, at least */ /* one line should contain a valid PDB keyword: */ if (total_linesN <= 10) { if (good_linesN >= 1) return PDB_FORMAT; } /* If this point is reached, file format is not PDB: */ return -2; } /*===========================================================================*/ garlic-1.6/save_sec_structure.c0000644000076500007650000000517407747302133017200 0ustar zuciczucic00000000000000/* Copyright (C) 2001-2003 Damir Zucic */ /*============================================================================= save_sec_structure.c Purpose: Save secondary structure to the specified file. This function outputs one letter secondary structure codes in a format similar to FASTA. Input: (1) Pointer to RuntimeS structure. Output: (1) Secondary structure stored to the specified file. (2) Return value. Return value: (1) Positive on success. (2) Negative on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ char *ExtractToken_ (char *, int, char *, char *); /*======save secondary structure to file:====================================*/ int SaveSecondaryStructure_ (RuntimeS *runtimeSP) { char lineA[STRINGSIZE]; char *remainderP; char tokenA[STRINGSIZE]; FILE *fileP; int codeI; int code; /* Copy the original command string: */ strncpy (lineA, runtimeSP->curr_commandA, STRINGSIZE - 1); lineA[STRINGSIZE - 1] = '\0'; /* Skip two tokens: */ remainderP = ExtractToken_ (tokenA, STRINGSIZE, lineA, " \t\n"); if (!remainderP) return -1; remainderP = ExtractToken_ (tokenA, STRINGSIZE, remainderP, " \t\n"); if (!remainderP) return -2; /* The third token should contain the file name: */ remainderP = ExtractToken_ (tokenA, STRINGSIZE, remainderP, " \t\n"); if (!remainderP) { strcpy (runtimeSP->messageA, "File name missing!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return -3; } /* Try to open file: */ fileP = fopen (tokenA, "w"); if (fileP == NULL) { strcpy (runtimeSP->messageA, "Failed to open file!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return -4; } /* Write the first line to the output file: */ fprintf (fileP, ">1xxx %d codes\n", runtimeSP->sec_structure_length); /* Write secondary structure codes to file: */ for (codeI = 0; codeI < (int) runtimeSP->sec_structure_length; codeI++) { /* Prepare the current secondary structure code: */ code = *(runtimeSP->sec_structureP + codeI); /* Print residue name: */ fprintf (fileP, "%c", code); /* Add newline after each 75 residues: */ if (((codeI + 1) % 75) == 0) fprintf (fileP, "\n"); } /* Add newline at the end of file: */ fprintf (fileP, "\n"); /* Close file: */ fclose (fileP); /* Return positive value on success: */ return 1; } /*===========================================================================*/ garlic-1.6/move_front_slab.c0000644000076500007650000000521407070340063016433 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= move_front_slab.c Purpose: Change the position of the front slab surface for each caught macromolecular complex. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. (3) Pointer to ConfigS structure. (4) Translation shift. Output: (1) The front slab surface moved. Return value: No return value. Notes: (1) Indentation is exceptionally 4 spaces. ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======move the front slab surface:=========================================*/ void MoveFrontSlab_ (MolComplexS *mol_complexSP, int mol_complexesN, ConfigS *configSP, double shift) { int mol_complexI; MolComplexS *curr_mol_complexSP; for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check is the current macromolecular complex caught: */ if (curr_mol_complexSP->catchF == 0) continue; /* Move front slab surface: */ switch (curr_mol_complexSP->slab_modeI) { /* Planar slab: */ case 1: /* Prepare the new position: */ curr_mol_complexSP->slab_front_relative_position += shift; /* Check it: */ if (curr_mol_complexSP->slab_front_relative_position > curr_mol_complexSP->slab_back_relative_position - MINSLABSPACING) { curr_mol_complexSP->slab_front_relative_position = curr_mol_complexSP->slab_back_relative_position - MINSLABSPACING; } break; /* Spherical, semi-spher., cylindrical and semi-cyl. slab: */ case 2: case 3: case 4: case 5: /* Prepare the new position: */ curr_mol_complexSP->slab_front_relative_position -= shift; /* Check it: */ if (curr_mol_complexSP->slab_front_relative_position < curr_mol_complexSP->slab_back_relative_position + MINSLABSPACING) { curr_mol_complexSP->slab_front_relative_position = curr_mol_complexSP->slab_back_relative_position + MINSLABSPACING; } if (curr_mol_complexSP->slab_front_relative_position < 0) { curr_mol_complexSP->slab_front_relative_position = 0.0; } break; /* Ignore all other cases: */ default: ; } /* Set the position_changedF: */ curr_mol_complexSP->position_changedF = 1; } } /*===========================================================================*/ garlic-1.6/dock.c0000644000076500007650000001735507465734237014227 0ustar zuciczucic00000000000000/* Copyright (C) 2000, 2001 Damir Zucic */ /*============================================================================= dock.c Purpose: Execute dock command. Input: (1) Pointer to MolComplexS structure. (2) The number of macromolecular complexes. (3) Pointer to RuntimeS structure. (4) Pointer to ConfigS structure. (5) Pointer to GUIS structure. (6) Pointer to NearestAtomS structure. (7) The number of pixels in the main window free area. (8) Pointer to refreshI. (9) Pointer to the remainder of the command string. This command may be given without keyword or with keyword OFF. Output: (1) Switch to docking mode. Docking window mapped. (2) Return value. Return value: (1) Positive (command) code on success. (2) Negative (error) code on failure. Notes: (1) Docking window should be created if docking is called for the first time. If docking is switched off, this window should be hidden. ========includes:============================================================*/ #include #include #include #include #include #include #include #include "defines.h" #include "commands.h" #include "typedefs.h" /*======function prototypes:=================================================*/ char *ExtractToken_ (char *, int, char *, char *); int AlignNormalVector_ (MolComplexS *, ConfigS *, int, int); int AlignComplexes_ (MolComplexS *, MolComplexS *, ConfigS *); int PrepareDockingWindow_ (RuntimeS *, GUIS *); size_t MainRefresh_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); int ControlRefresh_ (MolComplexS *, ConfigS *, GUIS *); int DockingRefresh_ (RuntimeS *, GUIS *); /*======execute dock command:================================================*/ int Dock_ (MolComplexS *mol_complexSP, int mol_complexesN, RuntimeS *runtimeSP, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int *refreshIP, char *stringP) { char *remainderP; char tokenA[STRINGSIZE]; char *P; int n; int mol_complexI; MolComplexS *curr_mol_complexSP; static int complex1ID, complex2ID, curr_complexID; int complex1F = 0, complex2F = 0; static MolComplexS *mol_complex1SP, *mol_complex2SP; unsigned int width, height; int x0, y0; /* Extract the first token, if present: */ remainderP = ExtractToken_ (tokenA, STRINGSIZE, stringP, " \t\n"); /* If there are no additional tokens in the remainder */ /* of the command string, the command is incomplete: */ if (!remainderP) { strcpy (runtimeSP->messageA, "The command string is incomplete!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_DOCK; } /*------switch docking off:--------------------------------------------------*/ /* If keyword OFF is present, exit docking mode and hide docking window: */ else if (strstr (tokenA, "OFF") == tokenA) { /* Reset flag: */ guiSP->dockingF = 0; /* Hide docking window if it was created and mapped: */ if (guiSP->docking_window_createdF) { if (guiSP->docking_window_mappedF) { XUnmapWindow (guiSP->displaySP, guiSP->docking_winS.ID); guiSP->docking_window_mappedF = 0; } } /* Reset molecular pointers: */ mol_complex1SP = NULL; mol_complex2SP = NULL; /* Return the command code: */ return COMMAND_DOCK; } /*------read two complex identifiers:----------------------------------------*/ /* If this point is reached, keyword OFF was not found. */ /* Replace each non-numeric character (except */ /* minus sign and decimal point) with space: */ P = stringP; while ((n = *P++) != '\0') { if (!isdigit (n) && (n != '-') && (n != '.')) *(P - 1) = ' '; } /* Try to extract two identifiers: */ if (sscanf (stringP, "%d %d", &complex1ID, &complex2ID) != 2) { strcpy (runtimeSP->messageA, "Failed to extract two identifiers!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_DOCK; } /* The identifiers should not be equal: */ if (complex1ID == complex2ID) { strcpy (runtimeSP->messageA, "The identifiers should not be equal!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_DOCK; } /* Check both identifiers (do they refer to available complexes): */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* If there are no atoms in the current complex, ignore it: */ if (curr_mol_complexSP->atomsN == 0) continue; /* Compare the identifier of the current */ /* complex with both complex identifiers: */ curr_complexID = curr_mol_complexSP->mol_complexID; if (curr_complexID == complex1ID) { complex1F = 1; mol_complex1SP = curr_mol_complexSP; } else if (curr_complexID == complex2ID) { complex2F = 1; mol_complex2SP = curr_mol_complexSP; } } /* If the first identifier refers to nonexisting complex: */ if ((complex1F == 0) && (complex2F == 1)) { sprintf (runtimeSP->messageA, "The first identifier (%d) is bad!", complex1ID); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_DOCK; } /* If the second identifier refers to nonexisting complex: */ else if ((complex1F == 1) && (complex2F == 0)) { sprintf (runtimeSP->messageA, "The second identifier (%d) is bad!", complex2ID); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_DOCK; } /* If both identifiers refer to nonexisting complexes: */ else if ((complex1F == 0) && (complex2F == 0)) { sprintf (runtimeSP->messageA, "Both identifiers (%d, %d) are bad!", complex1ID, complex2ID); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_DOCK; } /*------set docking flag:----------------------------------------------------*/ guiSP->dockingF = 1; /*------store molecular pointers:--------------------------------------------*/ runtimeSP->mol_complex1SP = mol_complex1SP; runtimeSP->mol_complex2SP = mol_complex2SP; /*------bind planes (and other things) to structures:------------------------*/ mol_complex1SP->move_bits = STRUCTURE_MASK | PLANE_MASK | MEMBRANE_MASK | ENVELOPE_MASK; mol_complex2SP->move_bits = STRUCTURE_MASK | PLANE_MASK | MEMBRANE_MASK | ENVELOPE_MASK; /*------align normal vectors:------------------------------------------------*/ /* The normal vector of the first complex should be antiparallel to y axis: */ AlignNormalVector_ (mol_complex1SP, configSP, 2, -1); /* The normal vector of the second complex should be parallel to y axis: */ AlignNormalVector_ (mol_complex2SP, configSP, 2, +1); /*------align two structures vertically:-------------------------------------*/ AlignComplexes_ (mol_complex1SP, mol_complex2SP, configSP); /*------resize the main window and move it to the upper left corner:---------*/ width = 2 * guiSP->screen_width / 3 - 40; height = guiSP->screen_height - 45; x0 = 10; y0 = 30; XResizeWindow (guiSP->displaySP, guiSP->main_winS.ID, width, height); XMoveWindow (guiSP->displaySP, guiSP->main_winS.ID, x0, y0); /*------create docking window if not created before:-------------------------*/ PrepareDockingWindow_ (runtimeSP, guiSP); /*------refresh windows:-----------------------------------------------------*/ /* Refresh the main window: */ (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); /* Refresh the control window: */ ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); /* Refresh docking window: */ DockingRefresh_ (runtimeSP, guiSP); /* Return the command code: */ return COMMAND_DOCK; } /*===========================================================================*/ garlic-1.6/edit.c0000644000076500007650000005546707501463524014227 0ustar zuciczucic00000000000000/* Copyright (C) 2001, 2002 Damir Zucic */ /*============================================================================= edit.c Purpose: Execute edit command: set the editing mode index. The actual editing is not done here. The functions which are doing this job are called by the functions which handle KeyPress events. If using the keyword BOND, two atomic serial numbers have to be specified. Input: (1) Pointer to MolComplexS structure. (2) The number of macromolecular complexes. (3) Pointer to RuntimeS structure. (4) Pointer to ConfigS structure. (5) Pointer to GUIS structure. (6) Pointer to NearestAtomS structure. (7) The number of pixels in the main window free area. (8) Pointer to refreshI. (9) Pointer to the remainder of the command string. The command edit must be accompanied by one of the following keywords: OFF, ATOMS, PHI, PSI, OMEGA, MAIN, BOND, SIDE, DIMENSIONS or CLICK. Long keywords may be abbreviated to three characters. The keyword BOND should be followed by the serial numbers of two atoms which form the bond. Output: (1) The specified editing mode switched on or off. (2) Return value. Return value: (1) Positive (command) code on success. (2) Negative (error) code on failure. Notes: (1) The keyword BOND always forces editing of a single bond. The keywords PHI, PSI, OMEGA, MAIN and SIDE may be used to edit more than one bond. The flag edit_single_bondF decides how many bonds should be modified. (2) The keyword DIMENSIONS may be used to edit special objects. It is not suitable for molecular structures. It should be used to change the size of the object which consists of special atoms (quarkonium and jellium). (3) The keyword CLICK is used to set the click_modeI index. If this index is set to one, the pointer may be used to pick one bond for editing. The command EDIT CLICK resets the edit_modeI index. All other combinations reset the click_modeI to zero. (4) Each call to this function resets the edit mode index. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "commands.h" #include "typedefs.h" /*======function prototypes:=================================================*/ char *ExtractToken_ (char *, int, char *, char *); int ExtractTwoIntegers_ (int *, int *, char *); int BondPartners_ (RuntimeS *, MolComplexS *, ResidueS *, char *, char *); int AreAtomsBound_ (size_t *, size_t *, MolComplexS *, int, int, int); int IsPartOfRing_ (MolComplexS *, int, size_t, size_t); size_t MainRefresh_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); int ControlRefresh_ (MolComplexS *, ConfigS *, GUIS *); /*======execute edit command:================================================*/ int Edit_ (MolComplexS *mol_complexSP, int mol_complexesN, RuntimeS *runtimeSP, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int *refreshIP, char *stringP) { int old_edit_modeI; char *remainderP; char tokenA[SHORTSTRINGSIZE]; MolComplexS *default_mol_complexSP; int residuesN, residueI; int selected_residue_foundF; static ResidueS *curr_residueSP; static size_t startI, endI, atomI; AtomS *atomSP; int n; ResidueS *previous_residueSP; size_t previous_startI, previous_endI; int atom1_serialI, atom2_serialI; size_t atom1_arrayI, atom2_arrayI; AtomS *atom1SP, *atom2SP; char *atom1_pure_nameP, *atom2_pure_nameP; int atom_foundF; /* Copy the old edit_modeI: */ old_edit_modeI = runtimeSP->edit_modeI; /* Each call to this function resets the edit_modeI: */ runtimeSP->edit_modeI = 0; /* Reset the edit_single_bondF flag: */ runtimeSP->edit_single_bondF = 0; /* Reset the click_modeI; CLICK is the only */ /* keyword which may set this index to one: */ runtimeSP->click_modeI = 0; /* Extract the first token: */ remainderP = ExtractToken_ (tokenA, STRINGSIZE, stringP, " \t\n"); /* If not available, inform user that some keyword is mandatory: */ if (!remainderP) { strcpy (runtimeSP->messageA, "What do you want to edit?"); runtimeSP->message_length = strlen (runtimeSP->messageA); if (old_edit_modeI != 0) { (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); } return ERROR_EDIT; } /* If this point is reached, the keyword is present. */ /* Prepare the pointer to default macromolecular complex: */ default_mol_complexSP = mol_complexSP + runtimeSP->default_complexI; /* The number of residues in default macromolecular complex: */ residuesN = default_mol_complexSP->residuesN; /* Check is the keyword OFF specified: */ if (strstr (tokenA, "OFF") == tokenA) { /* Set the edit mode index: */ runtimeSP->edit_modeI = 0; } /* Keyword ATOMS: */ else if (strstr (tokenA, "ATO") == tokenA) { /* Set the edit mode index: */ runtimeSP->edit_modeI = 1; } /* Keyword PHI: */ else if (strstr (tokenA, "PHI") == tokenA) { /* Find the first selected residue: */ selected_residue_foundF = 0; for (residueI = 0; residueI < residuesN; residueI++) { /* Pointer to the current residue: */ curr_residueSP = default_mol_complexSP->residueSP + residueI; /* Pointer to the first atom: */ atomSP = default_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* If the first atom is not selected, do */ /* not treat this residue as selected: */ if (atomSP->selectedF) { selected_residue_foundF = 1; break; } } /* At least one residue should be selected: */ if (!selected_residue_foundF) { strcpy (runtimeSP->messageA, "At least one residue should be selected!"); runtimeSP->message_length = strlen (runtimeSP->messageA); if (old_edit_modeI != 0) { (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); } return ERROR_EDIT; } /* Extract serial numbers and array indices of */ /* the atoms which form this bond (N and CA): */ n = BondPartners_ (runtimeSP, default_mol_complexSP, curr_residueSP, "N", "CA"); if (n < 0) { strcpy (runtimeSP->messageA, "Unable to extract data for atoms N and CA!"); runtimeSP->message_length = strlen (runtimeSP->messageA); if (old_edit_modeI != 0) { (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); } return ERROR_EDIT; } /* Set the edit mode index: */ runtimeSP->edit_modeI = 2; } /* Keyword PSI: */ else if (strstr (tokenA, "PSI") == tokenA) { /* Find the first selected residue: */ selected_residue_foundF = 0; for (residueI = 0; residueI < residuesN; residueI++) { /* Pointer to the current residue: */ curr_residueSP = default_mol_complexSP->residueSP + residueI; /* Pointer to the first atom: */ atomSP = default_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* If the first atom is not selected, do */ /* not treat this residue as selected: */ if (atomSP->selectedF) { selected_residue_foundF = 1; break; } } /* At least one residue should be selected: */ if (!selected_residue_foundF) { strcpy (runtimeSP->messageA, "At least one residue should be selected!"); runtimeSP->message_length = strlen (runtimeSP->messageA); if (old_edit_modeI != 0) { (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); } return ERROR_EDIT; } /* Extract serial numbers and array indices of */ /* the atoms which form this bond (CA and C): */ n = BondPartners_ (runtimeSP, default_mol_complexSP, curr_residueSP, "CA", "C"); if (n < 0) { strcpy (runtimeSP->messageA, "Unable to extract data for atoms CA and C!"); runtimeSP->message_length = strlen (runtimeSP->messageA); if (old_edit_modeI != 0) { (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); } return ERROR_EDIT; } /* Set the edit mode index: */ runtimeSP->edit_modeI = 3; } /* Keyword OMEGA: */ else if (strstr (tokenA, "OME") == tokenA) { /* Find the first selected residue, but skip the first one: */ selected_residue_foundF = 0; for (residueI = 1; residueI < residuesN; residueI++) { /* Pointer to the current residue: */ curr_residueSP = default_mol_complexSP->residueSP + residueI; /* Prepare the atomic index range: */ startI = curr_residueSP->residue_startI; endI = curr_residueSP->residue_endI; /* Pointer to the first atom: */ atomSP = default_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* If the first atom is not selected, do */ /* not treat this residue as selected: */ if (atomSP->selectedF) { selected_residue_foundF = 1; break; } } /* At least one residue should be selected: */ if (!selected_residue_foundF) { strcpy (runtimeSP->messageA, "Select at least one residue"); strcat (runtimeSP->messageA, " (but not the first one)!"); runtimeSP->message_length = strlen (runtimeSP->messageA); if (old_edit_modeI != 0) { (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); } return ERROR_EDIT; } /* If this point is reached, the current residue is selected. */ /* To define the C-N bond, the previous residue is required. */ /* Prepare the pointer to the previous residue: */ previous_residueSP = default_mol_complexSP->residueSP + residueI - 1; /* Prepare the atomic index range: */ previous_startI = previous_residueSP->residue_startI; previous_endI = previous_residueSP->residue_endI; /* Prepare the array and serial indices for C */ /* and N atom. C atom belongs to the previous */ /* residue and N to the current residue. */ /* Find the serial number of C atom of the previous residue: */ /* Try to find atom: */ atom_foundF = 0; for (atomI = previous_startI; atomI <= previous_endI; atomI++) { /* Pointer to the current atom: */ atomSP = mol_complexSP->atomSP + atomI; /* Check the purified name of this atom: */ if (strcmp (atomSP->raw_atomS.pure_atom_nameA, "C") == 0) { atom1_serialI = atomSP->raw_atomS.serialI; atom1_arrayI = atomI; atom_foundF = 1; break; } } /* If C atom is missing write error message and return: */ if (!atom_foundF) { strcpy (runtimeSP->messageA, "C atom (required for C-N bond) is missing!"); runtimeSP->message_length = strlen (runtimeSP->messageA); if (old_edit_modeI != 0) { (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); } return ERROR_EDIT; } /* The serial number of N atom of the current residue: */ atom_foundF = 0; for (atomI = startI; atomI <= endI; atomI++) { /* Pointer to the current atom: */ atomSP = mol_complexSP->atomSP + atomI; /* Check the purified name of this atom: */ if (strcmp (atomSP->raw_atomS.pure_atom_nameA, "N") == 0) { atom2_serialI = atomSP->raw_atomS.serialI; atom2_arrayI = atomI; atom_foundF = 1; break; } } /* If N atom is missing write error message and return: */ if (!atom_foundF) { strcpy (runtimeSP->messageA, "N atom (required for C-N bond) is missing!"); runtimeSP->message_length = strlen (runtimeSP->messageA); if (old_edit_modeI != 0) { (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); } return ERROR_EDIT; } /* Store the serial numbers and the array indices: */ runtimeSP->atom1_serialI = atom1_serialI; runtimeSP->atom2_serialI = atom2_serialI; runtimeSP->atom1_arrayI = atom1_arrayI; runtimeSP->atom2_arrayI = atom2_arrayI; /* Set the edit mode index: */ runtimeSP->edit_modeI = 4; } /* Keyword MAIN: */ else if (strstr (tokenA, "MAI") == tokenA) { /* Find the first selected residue: */ selected_residue_foundF = 0; for (residueI = 0; residueI < residuesN; residueI++) { /* Pointer to the current residue: */ curr_residueSP = default_mol_complexSP->residueSP + residueI; /* Pointer to the first atom: */ atomSP = default_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* If the first atom is not selected, do */ /* not treat this residue as selected: */ if (atomSP->selectedF) { selected_residue_foundF = 1; break; } } /* At least one residue should be selected: */ if (!selected_residue_foundF) { strcpy (runtimeSP->messageA, "At least one residue should be selected!"); runtimeSP->message_length = strlen (runtimeSP->messageA); if (old_edit_modeI != 0) { (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); } return ERROR_EDIT; } /* Extract the serial numbers and the array indices */ /* of N and CA atoms for the first selected residue: */ n = BondPartners_ (runtimeSP, default_mol_complexSP, curr_residueSP, "N", "CA"); if (n < 0) { strcpy (runtimeSP->messageA, "Unable to extract data for atoms N and CA!"); runtimeSP->message_length = strlen (runtimeSP->messageA); if (old_edit_modeI != 0) { (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); } return ERROR_EDIT; } /* Set the edit mode index: */ runtimeSP->edit_modeI = 5; } /* Keyword BOND: */ else if (strstr (tokenA, "BON") == tokenA) { /* Try to extract serial numbers for two atoms: */ if (ExtractTwoIntegers_ (&atom1_serialI, &atom2_serialI, stringP) < 0) { strcpy (runtimeSP->messageA, "Failed to extract serial numbers"); strcat (runtimeSP->messageA, " of two atoms which form the bond!"); runtimeSP->message_length = strlen (runtimeSP->messageA); if (old_edit_modeI != 0) { (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); } return ERROR_EDIT; } /* Check signs: */ if ((atom1_serialI < 0) || (atom2_serialI < 0)) { strcpy (runtimeSP->messageA, "Both indices must be positive!"); runtimeSP->message_length = strlen (runtimeSP->messageA); if (old_edit_modeI != 0) { (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); } return ERROR_EDIT; } /* Check are the atoms specified by the */ /* given serial numbers bound at all: */ n = AreAtomsBound_ (&atom1_arrayI, &atom2_arrayI, mol_complexSP, runtimeSP->default_complexI, atom1_serialI, atom2_serialI); if (n < 0) { strcpy (runtimeSP->messageA, "The specified atoms are not covalently bound!"); runtimeSP->message_length = strlen (runtimeSP->messageA); if (old_edit_modeI != 0) { (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); } return ERROR_EDIT; } /* Check is it possible to rotate the specified bond. */ /* It is not possible to edit the bond which is part */ /* of a ring or some other closed structural element. */ n = IsPartOfRing_ (mol_complexSP, runtimeSP->default_complexI, atom1_arrayI, atom2_arrayI); if (n > 0) { strcpy (runtimeSP->messageA, "The specified bond is part of a ring!"); runtimeSP->message_length = strlen (runtimeSP->messageA); if (old_edit_modeI != 0) { (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); } return ERROR_EDIT; } /* Store the serial numbers and the array indices: */ runtimeSP->atom1_serialI = atom1_serialI; runtimeSP->atom2_serialI = atom2_serialI; runtimeSP->atom1_arrayI = atom1_arrayI; runtimeSP->atom2_arrayI = atom2_arrayI; /* Prepare the purified names for two given atoms: */ atom1SP = default_mol_complexSP->atomSP + atom1_arrayI; atom2SP = default_mol_complexSP->atomSP + atom2_arrayI; atom1_pure_nameP = atom1SP->raw_atomS.pure_atom_nameA; atom2_pure_nameP = atom2SP->raw_atomS.pure_atom_nameA; /* If two atoms form the N-CA bond, the current command */ /* is equivalent to EDIT PHI. If they form the CA-C bond, */ /* the command is equivalent to EDIT PSI. If they form */ /* the C-N bond, the command is equivalent to EDIT OMEGA. */ /* The first combination equivalent to EDIT PHI: */ if ((strcmp (atom1_pure_nameP, "N" ) == 0) && (strcmp (atom2_pure_nameP, "CA") == 0)) { runtimeSP->edit_modeI = 2; runtimeSP->edit_single_bondF = 1; } /* The second combination equivalent to EDIT PHI: */ else if ((strcmp (atom1_pure_nameP, "CA") == 0) && (strcmp (atom2_pure_nameP, "N" ) == 0)) { runtimeSP->edit_modeI = 2; runtimeSP->edit_single_bondF = 1; } /* The first combination equivalent to EDIT PSI: */ else if ((strcmp (atom1_pure_nameP, "CA") == 0) && (strcmp (atom2_pure_nameP, "C" ) == 0)) { runtimeSP->edit_modeI = 3; runtimeSP->edit_single_bondF = 1; } /* The second combination equivalent to EDIT PSI: */ else if ((strcmp (atom1_pure_nameP, "CA") == 0) && (strcmp (atom2_pure_nameP, "C" ) == 0)) { runtimeSP->edit_modeI = 3; runtimeSP->edit_single_bondF = 1; } /* The first combination equivalent to EDIT OMEGA: */ else if ((strcmp (atom1_pure_nameP, "C") == 0) && (strcmp (atom2_pure_nameP, "N") == 0)) { runtimeSP->edit_modeI = 4; runtimeSP->edit_single_bondF = 1; } /* The second combination equivalent to EDIT OMEGA: */ else if ((strcmp (atom1_pure_nameP, "N") == 0) && (strcmp (atom2_pure_nameP, "C") == 0)) { runtimeSP->edit_modeI = 4; runtimeSP->edit_single_bondF = 1; /* Swap the array and serial indices. The second array */ /* index will be used in small_omega.c to recognize */ /* the residue to which the nitrogen atom belongs: */ runtimeSP->atom2_arrayI = atom1_arrayI; runtimeSP->atom1_arrayI = atom2_arrayI; runtimeSP->atom1_serialI = atom2_serialI; runtimeSP->atom2_serialI = atom1_serialI; } /* All other combinations are not equivalent to */ /* special cases EDIT PHI, EDIT PSI and EDIT OMEGA: */ else { runtimeSP->edit_modeI = 6; runtimeSP->edit_single_bondF = 1; } } /* Keyword SIDE: */ else if (strstr (tokenA, "SID") == tokenA) { /* Find the first selected residue: */ selected_residue_foundF = 0; for (residueI = 0; residueI < residuesN; residueI++) { /* Pointer to the current residue: */ curr_residueSP = default_mol_complexSP->residueSP + residueI; /* Pointer to the first atom: */ atomSP = default_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* If the first atom is not selected, do */ /* not treat this residue as selected: */ if (atomSP->selectedF) { selected_residue_foundF = 1; break; } } /* At least one residue should be selected: */ if (!selected_residue_foundF) { strcpy (runtimeSP->messageA, "At least one residue should be selected!"); runtimeSP->message_length = strlen (runtimeSP->messageA); if (old_edit_modeI != 0) { (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); } return ERROR_EDIT; } /* Extract serial numbers and array indices of CA and CB atoms: */ n = BondPartners_ (runtimeSP, default_mol_complexSP, curr_residueSP, "CA", "CB"); if (n < 0) { strcpy (runtimeSP->messageA, "Unable to extract data for atoms CA and CB!"); runtimeSP->message_length = strlen (runtimeSP->messageA); if (old_edit_modeI != 0) { (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); } return ERROR_EDIT; } /* Set the edit mode index: */ runtimeSP->edit_modeI = 7; } /* Keyword DIMENSIONS: */ else if (strstr (tokenA, "DIM") == tokenA) { /* Set the edit mode index: */ runtimeSP->edit_modeI = 101; } /* Keyword CLICK: */ else if (strstr (tokenA, "CLI") == tokenA) { /* Reset the edit mode index: */ runtimeSP->edit_modeI = 0; /* Set the click mode index to one: */ runtimeSP->click_modeI = 1; } /* If keyword recognition failed: */ else { strcpy (runtimeSP->messageA, "Keyword not recognized!"); runtimeSP->message_length = strlen (runtimeSP->messageA); if (old_edit_modeI != 0) { (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); } return ERROR_EDIT; } /* Refresh the main window: */ (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); /* Refresh the control window: */ ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); /* Return the command code: */ return COMMAND_EDIT; } /*===========================================================================*/ garlic-1.6/draw_balls2.c0000644000076500007650000003126007747301605015462 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2003 Damir Zucic */ /*============================================================================= balls2.c Purpose: Draw atoms as balls, version 2 (ball style). Input: (1) Pointer to MolComplexS structure. (2) Number of macromolecular complexes. (3) Pointer to ConfigS structure, with configuration data. (4) Pointer to GUIS structure. (5) Pointer to NearestAtomS structure, with information about the atom occupying the given pixel. (6) The number of pixels in the main window free area. (7) The refreshI, used to check the NearestAtomS associated with a given pixel. Output: (1) Spheres drawn to the hidden pixmap. (2) Return value. Return value: (1) Positive always (trivial). Notes: (1) Indentation is exceptionally 4 spaces. =============================================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ unsigned long Sp2Color_ (AtomS *, GUIS *, double); /*======draw atoms as balls, version 2:======================================*/ int DrawBalls2_ (MolComplexS *mol_complexSP, int mol_complexesN, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int refreshI) { int imageI, imagesN; double scale_factor, user_atomic_position; int left_edge[2], right_edge[2]; int mol_complexI; MolComplexS *curr_mol_complexSP; size_t atomsN, atomI; AtomS *curr_atomSP; int screen_x0, screen_y0; double radius, radius_squared; double denominator, reciprocal_denominator; int screen_radius; long screen_radius_squared; int screen_x1, screen_y1, screen_x2, screen_y2; int screen_x, screen_y; long delta_x, delta_y, distance_squared; double z0, front_z, delta_z, z; size_t pixelI; NearestAtomS *curr_pixelSP; double denominator2, reciprocal_denominator2; double rho_squared; VectorS vectorS; double abs_value, abs_value_squared; double scalar_product, cos_angle; unsigned long colorID; int bondI; /* Initialize the bond index. The negative value means that pixels */ /* filled in this function are not a part of any chemical bond. */ bondI = -1; /* Number of images: */ if (configSP->stereoF) imagesN = 2; else imagesN = 1; scale_factor = configSP->user_screen_atomic_distance * configSP->atomic_to_screen_scale_x; /* Prepare the user position in atomic coordinates: */ user_atomic_position = configSP->user_atomic_position; /* Left and right image edge (in stereo mode there are two images): */ left_edge[0] = configSP->image_screen_x0[0]; right_edge[0] = configSP->image_screen_x1[0]; left_edge[1] = configSP->image_screen_x0[1]; right_edge[1] = configSP->image_screen_x1[1]; /*------first pass - fill NearestAtomS array with planar atoms:--------------*/ /* Draw each macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Prepare and check the number of atoms: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Draw atoms which have the given style: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Check style: */ if (curr_atomSP->raw_atomS.atom_styleI != BALL2) continue; /* Check is atom hidden: */ if (curr_atomSP->hiddenF) continue; /* Check is atom inside slab: */ if (!curr_atomSP->inside_slabF) continue; /* Check is atom inside window: */ if (!curr_atomSP->inside_windowF) continue; /* Copy the atomic radius: */ radius = curr_atomSP->raw_atomS.ball_radius; /* Squared atomic radius: */ radius_squared = radius * radius; /* The y coordinate of atomic center, in screen units: */ screen_y0 = curr_atomSP->raw_atomS.screen_y; /* Prepare one image (mono) or two images (stereo): */ for (imageI = 0; imageI < imagesN; imageI++) { /* The z coordinate of atomic center, in atomic units: */ z0 = curr_atomSP->raw_atomS.z[imageI]; /* Prepare the factor required for projection of atomic radius: */ denominator = z0 - user_atomic_position; if (denominator == 0.0) continue; reciprocal_denominator = 1.0 / denominator; /* Atomic radius in screen units: */ screen_radius = (int) (radius * scale_factor * reciprocal_denominator + 0.5); /* Screen radius squared (used to improve speed): */ screen_radius_squared = (long) screen_radius * (long) screen_radius; /* The x coordinate of atomic center, in screen units: */ screen_x0 = curr_atomSP->raw_atomS.screen_x[imageI]; /* Define the bounding rectangle: */ screen_x1 = screen_x0 - screen_radius; screen_y1 = screen_y0 - screen_radius; screen_x2 = screen_x0 + screen_radius; screen_y2 = screen_y0 + screen_radius; /* Horizontal scan: */ for (screen_x = screen_x1; screen_x <= screen_x2; screen_x++) { /* Check horizontal position: */ if (screen_x < left_edge[imageI]) continue; if (screen_x >= right_edge[imageI]) continue; /* Vertical scan: */ for (screen_y = screen_y1; screen_y <= screen_y2; screen_y++) { /* Check vertical position: */ if (screen_y < 0) continue; if (screen_y >= (int) guiSP->main_win_free_area_height) { continue; } /* Check distance from the circle center: */ delta_x = (long) (screen_x - screen_x0); delta_y = (long) (screen_y - screen_y0); distance_squared = delta_x * delta_x + delta_y * delta_y; if (distance_squared > screen_radius_squared) continue; /* Prepare index to the array */ /* of NearestAtomS structures: */ pixelI = guiSP->main_win_free_area_width * screen_y + screen_x; /* Check the pixel index: */ if (pixelI >= pixelsN) continue; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = nearest_atomSP + pixelI; /* Check was this pixel used already in */ /* this drawing step; if it was, compare */ /* the z value of the current atom with z */ /* value previously stored to this pixel: */ if (refreshI == curr_pixelSP->last_refreshI) { if (z0 > curr_pixelSP->z) continue; } /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = BALL2; curr_pixelSP->last_refreshI = refreshI; curr_pixelSP->mol_complexI = mol_complexI; curr_pixelSP->atomI = atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = z0; } } } /* imageI loop */ } /* atomI loop */ } /* mol_complexI loop */ /*------second pass - draw spherical atoms:----------------------------------*/ /* Draw each macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Prepare and check the number of atoms: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Draw atoms which have the given style: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Check style: */ if (curr_atomSP->raw_atomS.atom_styleI != BALL2) continue; /* Check is atom hidden: */ if (curr_atomSP->hiddenF) continue; /* Check is atom inside slab: */ if (!curr_atomSP->inside_slabF) continue; /* Check is atom inside window: */ if (!curr_atomSP->inside_windowF) continue; /* Copy the atomic radius: */ radius = curr_atomSP->raw_atomS.ball_radius; /* Squared atomic radius: */ radius_squared = radius * radius; /* The y coordinate of atomic center, in screen units: */ screen_y0 = curr_atomSP->raw_atomS.screen_y; /* Prepare one image (mono) or two images (stereo): */ for (imageI = 0; imageI < imagesN; imageI++) { /* The z coordinate of atomic center, in atomic units: */ z0 = curr_atomSP->raw_atomS.z[imageI]; /* The z coordinate of the nearest */ /* point of a given atom (sphere): */ front_z = z0 - radius; /* Prepare the factor required for projection of atomic radius: */ denominator = z0 - user_atomic_position; if (denominator == 0.0) continue; reciprocal_denominator = 1.0 / denominator; /* Atomic radius in screen units: */ screen_radius = (int) (radius * scale_factor * reciprocal_denominator + 0.5); /* Square of the atomic radius (in screen units): */ screen_radius_squared = (long) screen_radius * (long) screen_radius; /* Reciprocal value will be used to improve performance: */ denominator2 = (double) screen_radius_squared; if (denominator2 == 0.0) continue; reciprocal_denominator2 = 1.0 / denominator2; /* The x coordinate of atomic center, in screen units: */ screen_x0 = curr_atomSP->raw_atomS.screen_x[imageI]; /* Define the bounding rectangle: */ screen_x1 = screen_x0 - screen_radius; screen_y1 = screen_y0 - screen_radius; screen_x2 = screen_x0 + screen_radius; screen_y2 = screen_y0 + screen_radius; /* Horizontal scan: */ for (screen_x = screen_x1; screen_x <= screen_x2; screen_x++) { /* Check horizontal position: */ if (screen_x < left_edge[imageI]) continue; if (screen_x > right_edge[imageI]) continue; /* Vertical scan: */ for (screen_y = screen_y1; screen_y <= screen_y2; screen_y++) { /* Check vertical position: */ if (screen_y < 0) continue; if (screen_y >= (int) guiSP->main_win_free_area_height) { continue; } /* Check distance from the circle center: */ delta_x = (long) (screen_x - screen_x0); delta_y = (long) (screen_y - screen_y0); distance_squared = delta_x * delta_x + delta_y * delta_y; if (distance_squared > screen_radius_squared) continue; /* Prepare index to the array */ /* of NearestAtomS structures: */ pixelI = guiSP->main_win_free_area_width * screen_y + screen_x; /* Check the pixel index: */ if (pixelI >= pixelsN) continue; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = nearest_atomSP + pixelI; /* Check z value (this is just a quick check): */ if (refreshI == curr_pixelSP->last_refreshI) { if (front_z > curr_pixelSP->z) continue; } /* Calculate the accurate z value: */ rho_squared = radius_squared * (double) distance_squared * reciprocal_denominator2; delta_z = sqrt (fabs (radius_squared - rho_squared)); z = z0 - delta_z; /* Check z value (precise check): */ if (refreshI == curr_pixelSP->last_refreshI) { if (z > curr_pixelSP->z) continue; } /* The vector from sphere center to the current pixel: */ vectorS.x = (double) delta_x; vectorS.y = (double) delta_y; vectorS.z = -delta_z * scale_factor * reciprocal_denominator; abs_value_squared = vectorS.x * vectorS.x + vectorS.y * vectorS.y + vectorS.z * vectorS.z; abs_value = sqrt (abs_value_squared); /* The scalar product between this */ /* vector and light source vector: */ scalar_product = vectorS.x * configSP->light_vectorS.x + vectorS.y * configSP->light_vectorS.y + vectorS.z * configSP->light_vectorS.z; /* Cosine of the angle between the vector to the */ /* current pixel and the light source unit vector: */ if (abs_value == 0.0) cos_angle = 0.0; else cos_angle = scalar_product / abs_value; /* Prepare color: */ colorID = Sp2Color_ (curr_atomSP, guiSP, cos_angle); XSetForeground (guiSP->displaySP, guiSP->theGCA[0], colorID); XDrawPoint (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x, screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = BALL2; curr_pixelSP->last_refreshI = refreshI; curr_pixelSP->mol_complexI = mol_complexI; curr_pixelSP->atomI = atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = z; curr_pixelSP->colorID = colorID; } } } /* imageI loop */ } /* atomI loop */ } /* mol_complexI loop */ /*---------------------------------------------------------------------------*/ /* Return positive value (trivial): */ return 1; } /*===========================================================================*/ garlic-1.6/extract_field.c0000644000076500007650000000215407124206424016073 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= extract_field.c Purpose: Extract field (substring) from ATOM or HETATM line (string). Arguments are not checked: it should be done in caller! Input: (1) Output string pointer. (2) Position of the first character. (3) Position of the last character. (4) Input string pointer. Output: (1) Substring stored at location pointed at by output string pointer. (2) Return value. Return value: (1) Output substring length. ========includes:============================================================*/ #include #include /*======extract field (substring):===========================================*/ int ExtractField_ (char *substringP, int start, int end, char *stringP) { int i; /* Copy (end - start + 1) characters: */ for (i = start; i <= end; i++) *(substringP + i - start) = *(stringP + i); /* Terminate the substring: */ *(substringP + i - start) = '\0'; return strlen (substringP); } /*===========================================================================*/ garlic-1.6/select_above.c0000644000076500007650000000715207465734704015733 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2002 Damir Zucic */ /*============================================================================= select_above.c Purpose: Select atoms above the plane. The normal vector defines what is up and what is down. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. (3) Selection mode index (0 = overwrite, 1 = restrict, 2 = expand previous selection). Output: (1) The flag selectedF set to one for selected atoms in every caught macromolecular complex. (2) Return value. Return value: (1) The number of selected atoms (zero or positive value). ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ double ScalarProduct_ (VectorS *, VectorS *); /*======select atoms above the plane:========================================*/ long SelectAbove_ (MolComplexS *mol_complexSP, int mol_complexesN, int selection_modeI) { long selected_atomsN = 0; int mol_complexI; MolComplexS *curr_mol_complexSP; size_t atomsN, atomI; VectorS normal_vectorS; double plane_center_x, plane_center_y, plane_center_z; AtomS *curr_atomSP; double x, y, z; VectorS curr_vectorS; int aboveF; /* Select all atoms above the plane: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check is the current macromolecular complex caught: */ if (curr_mol_complexSP->catchF == 0) continue; /* Number of atoms in a macromolecular complex: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* The normal vector: */ normal_vectorS.x = curr_mol_complexSP->planeS.normal_x[0]; normal_vectorS.y = curr_mol_complexSP->planeS.normal_y; normal_vectorS.z = curr_mol_complexSP->planeS.normal_z[0]; /* Position of the plane center: */ plane_center_x = curr_mol_complexSP->planeS.center_x[0]; plane_center_y = curr_mol_complexSP->planeS.center_y; plane_center_z = curr_mol_complexSP->planeS.center_z[0]; /* Scan all atoms in the current complex: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Copy the coordinates: */ x = curr_atomSP->raw_atomS.x[0]; y = curr_atomSP->raw_atomS.y; z = curr_atomSP->raw_atomS.z[0]; /* Position of the atom relative to the plane center: */ curr_vectorS.x = x - plane_center_x; curr_vectorS.y = y - plane_center_y; curr_vectorS.z = z - plane_center_z; /* Reset the flag: */ aboveF = 0; /* Check the sign of the scalar product: */ if (ScalarProduct_ (&curr_vectorS, &normal_vectorS) > 0.0) { aboveF = 1; } /* Set the selection flag for the current atom: */ switch (selection_modeI) { /* Overwrite the previous selection: */ case 0: curr_atomSP->selectedF = aboveF; break; /* Restrict the previous selection: */ case 1: curr_atomSP->selectedF &= aboveF; break; /* Expand the previous selection: */ case 2: curr_atomSP->selectedF |= aboveF; break; default: ; } /* Check the selection flag; increase */ /* the count if flag is equal to one: */ if (curr_atomSP->selectedF) selected_atomsN++; } } /* Return the number of selected atoms: */ return selected_atomsN; } /*===========================================================================*/ garlic-1.6/command_refresh.c0000644000076500007650000000465507520500137016420 0ustar zuciczucic00000000000000/* Copyright (C) 2002 Damir Zucic */ /*============================================================================= command_refresh.c Purpose: Execute refresh command: turn refreshing ON or OFF. Input: (1) Pointer to MolComplexS structure. (2) The number of macromolecular complexes. (3) Pointer to RuntimeS structure. (4) Pointer to ConfigS structure. (5) Pointer to GUIS structure. (6) Pointer to NearestAtomS structure. (7) The number of pixels in the main window free area. (8) Pointer to refreshI. (9) Pointer to the remainder of the command string. The only keyword is OFF. Output: (1) The main window refresh flag set to zero (OFF) or one (ON). (2) Return value. Return value: (1) Positive (command) code on success. (2) Negative (error) code on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "commands.h" #include "typedefs.h" /*======function prototypes:=================================================*/ void InformUser_ (GUIS *, char *); size_t MainRefresh_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); int ControlRefresh_ (MolComplexS *, ConfigS *, GUIS *); /*======execute plot command:================================================*/ int CommandRefresh_ (MolComplexS *mol_complexSP, int mol_complexesN, RuntimeS *runtimeSP, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int *refreshIP, char *stringP) { /* If keyword OFF is present, switch refreshing */ /* off and inform user that refreshing is off: */ if (strstr (stringP, "OFF")) { guiSP->main_window_refreshF = 0; InformUser_ (guiSP, "Refreshing off!"); return COMMAND_REFRESH; } /* If this point is reached, there is no keyword OFF: */ /* Set flag to one: */ guiSP->main_window_refreshF = 1; /* Refresh the main window: */ (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); /* Refresh the control window: */ ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); /* Return the command code: */ return COMMAND_REFRESH; } /*===========================================================================*/ garlic-1.6/bond_style2_quad1.c0000644000076500007650000001753207461726600016612 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2002 Damir Zucic */ /*============================================================================= bond_style2_quad1.c Purpose: Draw bond which fits into quadrant 1 using style 2. See the file file bonds_style2.c for description of quadrants. Input: (1) Pointer to Aux1S structure, which contains required data. (2) Bond index. Output: (1) A single bond drawn. (2) Return value. Return value: (1) One if at least one pixel is drawn. (2) Zero otherwise. =============================================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======draw bond in quadrant 1 using style 2:===============================*/ int BondStyle2Quadrant1_ (Aux1S *aux1SP, int bondI) { long pixels_drawnN = 0; double recip_denom, x_to_y_scale, x_to_z_scale; int screen_x, screen_x1, delta_x, screen_y, line_screen_y; double d, atomic_z; int lineI; size_t pixelI; NearestAtomS *curr_pixelSP; /* Scale factor required to calculate screen_y from screen_x: */ if (aux1SP->screen_delta_x != 0) recip_denom = 1.0 / aux1SP->screen_delta_x; else recip_denom = 0.0; x_to_y_scale = aux1SP->screen_delta_y * recip_denom; /* Scale factor required to calculate z (in atomic units) from screen_x: */ x_to_z_scale = aux1SP->atomic_delta_z * recip_denom; /* Horizontal scan, from left to right: */ screen_x1 = aux1SP->screen_x0 + (aux1SP->screen_delta_x + 1) / 2; for (screen_x = aux1SP->screen_x0; screen_x <= screen_x1; screen_x++) { /* Check is this pixel inside the area reserved for the */ /* current image (there are two images in stereo mode): */ if (screen_x < aux1SP->configSP->image_screen_x0[aux1SP->imageI]) { continue; } if (screen_x > aux1SP->configSP->image_screen_x1[aux1SP->imageI]) { continue; } /* Relative position: */ delta_x = screen_x - aux1SP->screen_x0; /* Find the corresponding screen_y: */ d = aux1SP->screen_y0 + x_to_y_scale * delta_x; screen_y = (int) (d + 0.5); /* z value (in atomic units): */ atomic_z = aux1SP->atomic_z0 + x_to_z_scale * delta_x; /* Loop which draws three lines (vertical scan): */ for (lineI = 0; lineI <= 2; lineI++) { /* Pixel position: */ line_screen_y = screen_y +lineI - 1; /* Check is this pixel inside the area reserved for the */ /* current image (there are two images in stereo mode): */ if (line_screen_y < aux1SP->configSP->image_screen_y0) { continue; } if (line_screen_y > aux1SP->configSP->image_screen_y1) { continue; } /* Current pixel index: */ pixelI = aux1SP->guiSP->main_win_free_area_width * line_screen_y + screen_x; /* Check pixel index: */ if (pixelI >= aux1SP->pixelsN) break; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = aux1SP->nearest_atomSP + pixelI; /* Check was this pixel used already in */ /* this drawing step; if it was, compare */ /* the z value of the current atom with z */ /* value previously stored to this pixel: */ if (aux1SP->refreshI == curr_pixelSP->last_refreshI) { if (atomic_z >= curr_pixelSP->z) continue; } /* If this point is reached draw pixel: */ XDrawPoint (aux1SP->guiSP->displaySP, aux1SP->guiSP->main_hidden_pixmapID, aux1SP->guiSP->theGCA[lineI], screen_x, line_screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = 2; curr_pixelSP->last_refreshI = aux1SP->refreshI; curr_pixelSP->mol_complexI = aux1SP->mol_complexI; curr_pixelSP->atomI = aux1SP->atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = atomic_z; curr_pixelSP->colorID = aux1SP->colorIDA[lineI]; /* Update the number of pixels drawn: */ pixels_drawnN++; } } /* Rounding the left end: */ do { /* Pixel position: */ screen_x = aux1SP->screen_x0 - 1; screen_y = aux1SP->screen_y0; /* Check is this pixel inside the area reserved for the */ /* current image (there are two images in stereo mode): */ if (screen_x < aux1SP->configSP->image_screen_x0[aux1SP->imageI]) break; if (screen_x > aux1SP->configSP->image_screen_x1[aux1SP->imageI]) break; if (screen_y < aux1SP->configSP->image_screen_y0) break; if (screen_y > aux1SP->configSP->image_screen_y1) break; /* Current pixel index: */ pixelI = aux1SP->guiSP->main_win_free_area_width * screen_y + screen_x; /* Check pixel index: */ if (pixelI >= aux1SP->pixelsN) break; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = aux1SP->nearest_atomSP + pixelI; /* Relative position: */ delta_x = screen_x - aux1SP->screen_x0; /* z value (in atomic units): */ atomic_z = aux1SP->atomic_z0 + x_to_z_scale * delta_x; /* Check was this pixel used already in */ /* this drawing step; if it was, compare */ /* the z value of the current atom with z */ /* value previously stored to this pixel: */ if (aux1SP->refreshI == curr_pixelSP->last_refreshI) { if (atomic_z >= curr_pixelSP->z) continue; } /* If this point is reached draw one pixel: */ XDrawPoint (aux1SP->guiSP->displaySP, aux1SP->guiSP->main_hidden_pixmapID, aux1SP->guiSP->theGCA[1], screen_x, screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = 2; curr_pixelSP->last_refreshI = aux1SP->refreshI; curr_pixelSP->mol_complexI = aux1SP->mol_complexI; curr_pixelSP->atomI = aux1SP->atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = atomic_z; curr_pixelSP->colorID = aux1SP->colorIDA[1]; /* Update the number of pixels drawn: */ pixels_drawnN++; /* End of single pass loop: */ } while (0); /* Rounding the right end: */ do { /* Pixel position: */ screen_x = screen_x1 + 1; d = aux1SP->screen_y0 + x_to_y_scale * (screen_x1 - aux1SP->screen_x0); screen_y = (int) (d + 0.5); /* Check is this pixel inside the area reserved for the */ /* current image (there are two images in stereo mode): */ if (screen_x < aux1SP->configSP->image_screen_x0[aux1SP->imageI]) break; if (screen_x > aux1SP->configSP->image_screen_x1[aux1SP->imageI]) break; if (screen_y < aux1SP->configSP->image_screen_y0) break; if (screen_y > aux1SP->configSP->image_screen_y1) break; /* Current pixel index: */ pixelI = aux1SP->guiSP->main_win_free_area_width * screen_y + screen_x; /* Check pixel index: */ if (pixelI >= aux1SP->pixelsN) break; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = aux1SP->nearest_atomSP + pixelI; /* Relative position: */ delta_x = screen_x - aux1SP->screen_x0; /* z value (in atomic units): */ atomic_z = aux1SP->atomic_z0 + x_to_z_scale * delta_x; /* Check was this pixel used already in */ /* this drawing step; if it was, compare */ /* the z value of the current atom with z */ /* value previously stored to this pixel: */ if (aux1SP->refreshI == curr_pixelSP->last_refreshI) { if (atomic_z >= curr_pixelSP->z) continue; } /* If this point is reached draw one pixel: */ XDrawPoint (aux1SP->guiSP->displaySP, aux1SP->guiSP->main_hidden_pixmapID, aux1SP->guiSP->theGCA[1], screen_x, screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = 2; curr_pixelSP->last_refreshI = aux1SP->refreshI; curr_pixelSP->mol_complexI = aux1SP->mol_complexI; curr_pixelSP->atomI = aux1SP->atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = atomic_z; curr_pixelSP->colorID = aux1SP->colorIDA[1]; /* Update the number of pixels drawn: */ pixels_drawnN++; /* End of single pass loop: */ } while (0); /* Check is at least one pixel drawn: */ if (pixels_drawnN > 0) return 1; /* If this point is reached, nothing is drawn: */ return 0; } /*===========================================================================*/ garlic-1.6/bond_style2_quad2.c0000644000076500007650000001755607461726604016625 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2002 Damir Zucic */ /*============================================================================= bond_style2_quad2.c Purpose: Draw bond which fits into quadrant 2 using style 2. See the file file bonds_style2.c for description of quadrants. Input: (1) Pointer to Aux1S structure, which contains required data. (2) Bond index. Output: (1) A single bond drawn. (2) Return value. Return value: (1) One if at least one pixel is drawn. (2) Zero otherwise. =============================================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======draw bond in quadrant 2 using style 2:===============================*/ int BondStyle2Quadrant2_ (Aux1S *aux1SP, int bondI) { long pixels_drawnN = 0; double recip_denom, y_to_x_scale, y_to_z_scale; int screen_x, line_screen_x, screen_y, screen_y1, delta_y; double d, atomic_z; int lineI; size_t pixelI; NearestAtomS *curr_pixelSP; /* Scale factor required to calculate screen_x from screen_y: */ if (aux1SP->screen_delta_y != 0) recip_denom = 1.0 / aux1SP->screen_delta_y; else recip_denom = 0.0; y_to_x_scale = aux1SP->screen_delta_x * recip_denom; /* Scale factor required to calculate z (in atomic units) from screen_y: */ y_to_z_scale = aux1SP->atomic_delta_z * recip_denom; /* Vertical scan (top to bottom): */ screen_y1 = aux1SP->screen_y0 + (aux1SP->screen_delta_y + 1) / 2; for (screen_y = aux1SP->screen_y0; screen_y <= screen_y1; screen_y++) { /* Check is this pixel inside the area reserved for the */ /* current image (there are two images in stereo mode): */ if (screen_y < aux1SP->configSP->image_screen_y0) continue; if (screen_y > aux1SP->configSP->image_screen_y1) continue; /* Relative position: */ delta_y = screen_y - aux1SP->screen_y0; /* Find the corresponding screen_x: */ d = aux1SP->screen_x0 + y_to_x_scale * delta_y; screen_x = (int) (d + 0.5); /* z value (in atomic units): */ atomic_z = aux1SP->atomic_z0 + y_to_z_scale * delta_y; /* Loop which draws three lines (horizontal scan): */ for (lineI = 0; lineI <= 2; lineI++) { /* Pixel position: */ line_screen_x = screen_x +lineI - 1; /* Check is this pixel inside the area reserved for the */ /* current image (there are two images in stereo mode): */ if (line_screen_x < aux1SP->configSP->image_screen_x0[aux1SP->imageI]) { continue; } if (line_screen_x > aux1SP->configSP->image_screen_x1[aux1SP->imageI]) { continue; } /* Current pixel index: */ pixelI = aux1SP->guiSP->main_win_free_area_width * screen_y + line_screen_x; /* Check pixel index: */ if (pixelI >= aux1SP->pixelsN) break; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = aux1SP->nearest_atomSP + pixelI; /* Check was this pixel used already in */ /* this drawing step; if it was, compare */ /* the z value of the current atom with z */ /* value previously stored to this pixel: */ if (aux1SP->refreshI == curr_pixelSP->last_refreshI) { if (atomic_z >= curr_pixelSP->z) continue; } /* If this point is reached draw pixel: */ XDrawPoint (aux1SP->guiSP->displaySP, aux1SP->guiSP->main_hidden_pixmapID, aux1SP->guiSP->theGCA[lineI], line_screen_x, screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = 2; curr_pixelSP->last_refreshI = aux1SP->refreshI; curr_pixelSP->mol_complexI = aux1SP->mol_complexI; curr_pixelSP->atomI = aux1SP->atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = atomic_z; curr_pixelSP->colorID = aux1SP->colorIDA[lineI]; /* Update the number of pixels drawn: */ pixels_drawnN++; } } /* Rounding the top end: */ do { /* Pixel position: */ screen_x = aux1SP->screen_x0; screen_y = aux1SP->screen_y0 - 1; /* Check is this pixel inside the area reserved for the */ /* current image (there are two images in stereo mode): */ if (screen_x < aux1SP->configSP->image_screen_x0[aux1SP->imageI]) break; if (screen_x > aux1SP->configSP->image_screen_x1[aux1SP->imageI]) break; if (screen_y < aux1SP->configSP->image_screen_y0) break; if (screen_y > aux1SP->configSP->image_screen_y1) break; /* Current pixel index: */ pixelI = aux1SP->guiSP->main_win_free_area_width * screen_y + screen_x; /* Check pixel index: */ if (pixelI >= aux1SP->pixelsN) break; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = aux1SP->nearest_atomSP + pixelI; /* Relative position: */ delta_y = screen_y - aux1SP->screen_y0; /* z value (in atomic units): */ atomic_z = aux1SP->atomic_z0 + y_to_z_scale * delta_y; /* Check was this pixel used already in */ /* this drawing step; if it was, compare */ /* the z value of the current atom with z */ /* value previously stored to this pixel: */ if (aux1SP->refreshI == curr_pixelSP->last_refreshI) { if (atomic_z >= curr_pixelSP->z) continue; } /* If this point is reached draw one pixel: */ XDrawPoint (aux1SP->guiSP->displaySP, aux1SP->guiSP->main_hidden_pixmapID, aux1SP->guiSP->theGCA[1], screen_x, screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = 2; curr_pixelSP->last_refreshI = aux1SP->refreshI; curr_pixelSP->mol_complexI = aux1SP->mol_complexI; curr_pixelSP->atomI = aux1SP->atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = atomic_z; curr_pixelSP->colorID = aux1SP->colorIDA[1]; /* Update the number of pixels drawn: */ pixels_drawnN++; /* End of single pass loop: */ } while (0); /* Rounding the bottom end: */ do { /* Pixel position: */ screen_y = screen_y1 + 1; d = aux1SP->screen_x0 + y_to_x_scale * (screen_y1 - aux1SP->screen_y0); screen_x = (int) (d + 0.5); /* Check is this pixel inside the area reserved for the */ /* current image (there are two images in stereo mode): */ if (screen_x < aux1SP->configSP->image_screen_x0[aux1SP->imageI]) { break; } if (screen_x > aux1SP->configSP->image_screen_x1[aux1SP->imageI]) { break; } if (screen_y < aux1SP->configSP->image_screen_y0) break; if (screen_y > aux1SP->configSP->image_screen_y1) break; /* Current pixel index: */ pixelI = aux1SP->guiSP->main_win_free_area_width * screen_y + screen_x; /* Check pixel index: */ if (pixelI >= aux1SP->pixelsN) break; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = aux1SP->nearest_atomSP + pixelI; /* Relative position: */ delta_y = screen_y - aux1SP->screen_y0; /* z value (in atomic units): */ atomic_z = aux1SP->atomic_z0 + y_to_z_scale * delta_y; /* Check was this pixel used already in */ /* this drawing step; if it was, compare */ /* the z value of the current atom with z */ /* value previously stored to this pixel: */ if (aux1SP->refreshI == curr_pixelSP->last_refreshI) { if (atomic_z >= curr_pixelSP->z) continue; } /* If this point is reached draw one pixel: */ XDrawPoint (aux1SP->guiSP->displaySP, aux1SP->guiSP->main_hidden_pixmapID, aux1SP->guiSP->theGCA[1], screen_x, screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = 2; curr_pixelSP->last_refreshI = aux1SP->refreshI; curr_pixelSP->mol_complexI = aux1SP->mol_complexI; curr_pixelSP->atomI = aux1SP->atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = atomic_z; curr_pixelSP->colorID = aux1SP->colorIDA[1]; /* Update the number of pixels drawn: */ pixels_drawnN++; /* End of single pass loop: */ } while (0); /* Check is at least one pixel drawn: */ if (pixels_drawnN > 0) return 1; /* If this point is reached, nothing is drawn: */ return 0; } /*===========================================================================*/ garlic-1.6/bond_style2_quad3.c0000644000076500007650000001760207461726615016620 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2002 Damir Zucic */ /*============================================================================= bond_style2_quad3.c Purpose: Draw bond which fits into quadrant 3 using style 2. See the file file bonds_style2.c for description of quadrants. Input: (1) Pointer to Aux1S structure, which contains required data. (2) Bond index. Output: (1) A single bond drawn. (2) Return value. Return value: (1) One if at least one pixel is drawn. (2) Zero otherwise. =============================================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======draw bond in quadrant 3 using style 2:===============================*/ int BondStyle2Quadrant3_ (Aux1S *aux1SP, int bondI) { long pixels_drawnN = 0; double recip_denom, x_to_y_scale, x_to_z_scale; int screen_x, screen_x1, delta_x, screen_y, line_screen_y; double d, atomic_z; int lineI; size_t pixelI; NearestAtomS *curr_pixelSP; /* Scale factor required to calculate screen_y from screen_x: */ if (aux1SP->screen_delta_x != 0) recip_denom = 1.0 / aux1SP->screen_delta_x; else recip_denom = 0.0; x_to_y_scale = aux1SP->screen_delta_y * recip_denom; /* Scale factor required to calculate z (in atomic units) from screen_x: */ x_to_z_scale = aux1SP->atomic_delta_z * recip_denom; /* Horizontal scan, from right to left: */ screen_x1 = aux1SP->screen_x0 + (aux1SP->screen_delta_x + 1) / 2; for (screen_x = aux1SP->screen_x0; screen_x >= screen_x1; screen_x--) { /* Check is this pixel inside the area reserved for the */ /* current image (there are two images in stereo mode): */ if (screen_x < aux1SP->configSP->image_screen_x0[aux1SP->imageI]) { continue; } if (screen_x > aux1SP->configSP->image_screen_x1[aux1SP->imageI]) { continue; } /* Relative position: */ delta_x = screen_x - aux1SP->screen_x0; /* Find the corresponding screen_y: */ d = aux1SP->screen_y0 + x_to_y_scale * delta_x; screen_y = (int) (d + 0.5); /* z value (in atomic units): */ atomic_z = aux1SP->atomic_z0 + x_to_z_scale * delta_x; /* Loop which draws three lines (vertical scan): */ for (lineI = 0; lineI <= 2; lineI++) { /* Pixel position: */ line_screen_y = screen_y +lineI - 1; /* Check is this pixel inside the area reserved for the */ /* current image (there are two images in stereo mode): */ if (line_screen_y < aux1SP->configSP->image_screen_y0) { continue; } if (line_screen_y > aux1SP->configSP->image_screen_y1) { continue; } /* Current pixel index: */ pixelI = aux1SP->guiSP->main_win_free_area_width * line_screen_y + screen_x; /* Check pixel index: */ if (pixelI >= aux1SP->pixelsN) break; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = aux1SP->nearest_atomSP + pixelI; /* Check was this pixel used already in */ /* this drawing step; if it was, compare */ /* the z value of the current atom with z */ /* value previously stored to this pixel: */ if (aux1SP->refreshI == curr_pixelSP->last_refreshI) { if (atomic_z >= curr_pixelSP->z) continue; } /* If this point is reached draw pixel: */ XDrawPoint (aux1SP->guiSP->displaySP, aux1SP->guiSP->main_hidden_pixmapID, aux1SP->guiSP->theGCA[lineI], screen_x, line_screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = 2; curr_pixelSP->last_refreshI = aux1SP->refreshI; curr_pixelSP->mol_complexI = aux1SP->mol_complexI; curr_pixelSP->atomI = aux1SP->atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = atomic_z; curr_pixelSP->colorID = aux1SP->colorIDA[lineI]; /* Update the number of pixels drawn: */ pixels_drawnN++; } } /* Rounding the right end: */ do { /* Pixel position: */ screen_x = aux1SP->screen_x0 + 1; screen_y = aux1SP->screen_y0; /* Check is this pixel inside the area reserved for the */ /* current image (there are two images in stereo mode): */ if (screen_x < aux1SP->configSP->image_screen_x0[aux1SP->imageI]) { break; } if (screen_x > aux1SP->configSP->image_screen_x1[aux1SP->imageI]) { break; } if (screen_y < aux1SP->configSP->image_screen_y0) break; if (screen_y > aux1SP->configSP->image_screen_y1) break; /* Current pixel index: */ pixelI = aux1SP->guiSP->main_win_free_area_width * screen_y + screen_x; /* Check pixel index: */ if (pixelI >= aux1SP->pixelsN) break; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = aux1SP->nearest_atomSP + pixelI; /* Relative position: */ delta_x = screen_x - aux1SP->screen_x0; /* z value (in atomic units): */ atomic_z = aux1SP->atomic_z0 + x_to_z_scale * delta_x; /* Check was this pixel used already in */ /* this drawing step; if it was, compare */ /* the z value of the current atom with z */ /* value previously stored to this pixel: */ if (aux1SP->refreshI == curr_pixelSP->last_refreshI) { if (atomic_z >= curr_pixelSP->z) continue; } /* If this point is reached draw one pixel: */ XDrawPoint (aux1SP->guiSP->displaySP, aux1SP->guiSP->main_hidden_pixmapID, aux1SP->guiSP->theGCA[1], screen_x, screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = 2; curr_pixelSP->last_refreshI = aux1SP->refreshI; curr_pixelSP->mol_complexI = aux1SP->mol_complexI; curr_pixelSP->atomI = aux1SP->atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = atomic_z; curr_pixelSP->colorID = aux1SP->colorIDA[1]; /* Update the number of pixels drawn: */ pixels_drawnN++; /* End of single pass loop: */ } while (0); /* Rounding the left end: */ do { /* Pixel position: */ screen_x = screen_x1 - 1; d = aux1SP->screen_y0 + x_to_y_scale * (screen_x1 - aux1SP->screen_x0); screen_y = (int) (d + 0.5); /* Check is this pixel inside the area reserved for the */ /* current image (there are two images in stereo mode): */ if (screen_x < aux1SP->configSP->image_screen_x0[aux1SP->imageI]) { break; } if (screen_x > aux1SP->configSP->image_screen_x1[aux1SP->imageI]) { break; } if (screen_y < aux1SP->configSP->image_screen_y0) break; if (screen_y > aux1SP->configSP->image_screen_y1) break; /* Current pixel index: */ pixelI = aux1SP->guiSP->main_win_free_area_width * screen_y + screen_x; /* Check pixel index: */ if (pixelI >= aux1SP->pixelsN) break; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = aux1SP->nearest_atomSP + pixelI; /* Relative position: */ delta_x = screen_x - aux1SP->screen_x0; /* z value (in atomic units): */ atomic_z = aux1SP->atomic_z0 + x_to_z_scale * delta_x; /* Check was this pixel used already in */ /* this drawing step; if it was, compare */ /* the z value of the current atom with z */ /* value previously stored to this pixel: */ if (aux1SP->refreshI == curr_pixelSP->last_refreshI) { if (atomic_z >= curr_pixelSP->z) continue; } /* If this point is reached draw one pixel: */ XDrawPoint (aux1SP->guiSP->displaySP, aux1SP->guiSP->main_hidden_pixmapID, aux1SP->guiSP->theGCA[1], screen_x, screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = 2; curr_pixelSP->last_refreshI = aux1SP->refreshI; curr_pixelSP->mol_complexI = aux1SP->mol_complexI; curr_pixelSP->atomI = aux1SP->atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = atomic_z; curr_pixelSP->colorID = aux1SP->colorIDA[1]; /* Update the number of pixels drawn: */ pixels_drawnN++; /* End of single pass loop: */ } while (0); /* Check is at least one pixel drawn: */ if (pixels_drawnN > 0) return 1; /* If this point is reached, nothing is drawn: */ return 0; } /*===========================================================================*/ garlic-1.6/bond_style2_quad4.c0000644000076500007650000001765307461726622016625 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2002 Damir Zucic */ /*============================================================================= bond_style2_quad4.c Purpose: Draw bond which fits into quadrant 4 using style 2. See the file file bonds_style2.c for description of quadrants. Input: (1) Pointer to Aux1S structure, which contains required data. (2) Bond index. Output: (1) A single bond drawn. (2) Return value. Return value: (1) One if at least one pixel is drawn. (2) Zero otherwise. =============================================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======draw bond in quadrant 4 using style 2:===============================*/ int BondStyle2Quadrant4_ (Aux1S *aux1SP, int bondI) { long pixels_drawnN = 0; double recip_denom, y_to_x_scale, y_to_z_scale; int screen_x, line_screen_x, screen_y, screen_y1, delta_y; double d, atomic_z; int lineI; size_t pixelI; NearestAtomS *curr_pixelSP; /* Scale factor required to calculate screen_x from screen_y: */ if (aux1SP->screen_delta_y != 0) recip_denom = 1.0 / aux1SP->screen_delta_y; else recip_denom = 0.0; y_to_x_scale = aux1SP->screen_delta_x * recip_denom; /* Scale factor required to calculate z (in atomic units) from screen_y: */ y_to_z_scale = aux1SP->atomic_delta_z * recip_denom; /* Vertical scan (bottom to top): */ screen_y1 = aux1SP->screen_y0 + (aux1SP->screen_delta_y + 1) / 2; for (screen_y = aux1SP->screen_y0; screen_y >= screen_y1; screen_y--) { /* Check is this pixel inside the area reserved for the */ /* current image (there are two images in stereo mode): */ if (screen_y < aux1SP->configSP->image_screen_y0) continue; if (screen_y > aux1SP->configSP->image_screen_y1) continue; /* Relative position: */ delta_y = screen_y - aux1SP->screen_y0; /* Find the corresponding screen_x: */ d = aux1SP->screen_x0 + y_to_x_scale * delta_y; screen_x = (int) (d + 0.5); /* z value (in atomic units): */ atomic_z = aux1SP->atomic_z0 + y_to_z_scale * delta_y; /* Loop which draws three lines (horizontal scan): */ for (lineI = 0; lineI <= 2; lineI++) { /* Pixel position: */ line_screen_x = screen_x +lineI - 1; /* Check is this pixel inside the area reserved for the */ /* current image (there are two images in stereo mode): */ if (line_screen_x < aux1SP->configSP->image_screen_x0[aux1SP->imageI]) { continue; } if (line_screen_x > aux1SP->configSP->image_screen_x1[aux1SP->imageI]) { continue; } /* Current pixel index: */ pixelI = aux1SP->guiSP->main_win_free_area_width * screen_y + line_screen_x; /* Check pixel index: */ if (pixelI >= aux1SP->pixelsN) break; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = aux1SP->nearest_atomSP + pixelI; /* Check was this pixel used already in */ /* this drawing step; if it was, compare */ /* the z value of the current atom with z */ /* value previously stored to this pixel: */ if (aux1SP->refreshI == curr_pixelSP->last_refreshI) { if (atomic_z >= curr_pixelSP->z) continue; } /* If this point is reached draw pixel: */ XDrawPoint (aux1SP->guiSP->displaySP, aux1SP->guiSP->main_hidden_pixmapID, aux1SP->guiSP->theGCA[lineI], line_screen_x, screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = 2; curr_pixelSP->last_refreshI = aux1SP->refreshI; curr_pixelSP->mol_complexI = aux1SP->mol_complexI; curr_pixelSP->atomI = aux1SP->atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = atomic_z; curr_pixelSP->colorID = aux1SP->colorIDA[lineI]; /* Update the number of pixels drawn: */ pixels_drawnN++; } } /* Rounding the bottom end: */ do { /* Pixel position: */ screen_x = aux1SP->screen_x0; screen_y = aux1SP->screen_y0 + 1; /* Check is this pixel inside the area reserved for the */ /* current image (there are two images in stereo mode): */ if (screen_x < aux1SP->configSP->image_screen_x0[aux1SP->imageI]) { break; } if (screen_x > aux1SP->configSP->image_screen_x1[aux1SP->imageI]) { break; } if (screen_y < aux1SP->configSP->image_screen_y0) break; if (screen_y > aux1SP->configSP->image_screen_y1) break; /* Current pixel index: */ pixelI = aux1SP->guiSP->main_win_free_area_width * screen_y + screen_x; /* Check pixel index: */ if (pixelI >= aux1SP->pixelsN) break; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = aux1SP->nearest_atomSP + pixelI; /* Relative position: */ delta_y = screen_y - aux1SP->screen_y0; /* z value (in atomic units): */ atomic_z = aux1SP->atomic_z0 + y_to_z_scale * delta_y; /* Check was this pixel used already in */ /* this drawing step; if it was, compare */ /* the z value of the current atom with z */ /* value previously stored to this pixel: */ if (aux1SP->refreshI == curr_pixelSP->last_refreshI) { if (atomic_z >= curr_pixelSP->z) continue; } /* If this point is reached draw one pixel: */ XDrawPoint (aux1SP->guiSP->displaySP, aux1SP->guiSP->main_hidden_pixmapID, aux1SP->guiSP->theGCA[1], screen_x, screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = 2; curr_pixelSP->last_refreshI = aux1SP->refreshI; curr_pixelSP->mol_complexI = aux1SP->mol_complexI; curr_pixelSP->atomI = aux1SP->atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = atomic_z; curr_pixelSP->colorID = aux1SP->colorIDA[1]; /* Update the number of pixels drawn: */ pixels_drawnN++; /* End of single pass loop: */ } while (0); /* Rounding the top end: */ do { /* Pixel position: */ screen_y = screen_y1 - 1; delta_y = screen_y1 - aux1SP->screen_y0; d = aux1SP->screen_x0 + y_to_x_scale * (screen_y1 - aux1SP->screen_y0); screen_x = (int) (d + 0.5); /* Check is this pixel inside the area reserved for the */ /* current image (there are two images in stereo mode): */ if (screen_x < aux1SP->configSP->image_screen_x0[aux1SP->imageI]) { break; } if (screen_x > aux1SP->configSP->image_screen_x1[aux1SP->imageI]) { break; } if (screen_y < aux1SP->configSP->image_screen_y0) break; if (screen_y > aux1SP->configSP->image_screen_y1) break; /* Current pixel index: */ pixelI = aux1SP->guiSP->main_win_free_area_width * screen_y + screen_x; /* Check pixel index: */ if (pixelI >= aux1SP->pixelsN) break; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = aux1SP->nearest_atomSP + pixelI; /* Relative position: */ delta_y = screen_y - aux1SP->screen_y0; /* z value (in atomic units): */ atomic_z = aux1SP->atomic_z0 + y_to_z_scale * delta_y; /* Check was this pixel used already in */ /* this drawing step; if it was, compare */ /* the z value of the current atom with z */ /* value previously stored to this pixel: */ if (aux1SP->refreshI == curr_pixelSP->last_refreshI) { if (atomic_z >= curr_pixelSP->z) continue; } /* If this point is reached draw one pixel: */ XDrawPoint (aux1SP->guiSP->displaySP, aux1SP->guiSP->main_hidden_pixmapID, aux1SP->guiSP->theGCA[1], screen_x, screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = 2; curr_pixelSP->last_refreshI = aux1SP->refreshI; curr_pixelSP->mol_complexI = aux1SP->mol_complexI; curr_pixelSP->atomI = aux1SP->atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = atomic_z; curr_pixelSP->colorID = aux1SP->colorIDA[1]; /* Update the number of pixels drawn: */ pixels_drawnN++; /* End of single pass loop: */ } while (0); /* Check is at least one pixel drawn: */ if (pixels_drawnN > 0) return 1; /* If this point is reached, nothing is drawn: */ return 0; } /*===========================================================================*/ garlic-1.6/realloc_pdb.c0000644000076500007650000000517707415613006015535 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2002 Damir Zucic */ /*============================================================================= realloc_pdb.c Purpose: Check is there enough memory left for PDB atomic data. If not, reallocate memory. If reallocation fails, print error message and return negative value. Input: (1) Pointer to pointer to AtomS structure. Its value points to the first element in an array of AtomS structures. (2) Pointer to pointer to AtomS structure. Its value points to the next free (unused) element of the same array. (3) Pointer to maximal number of atoms. (4) Current number of atoms. Output: (1) Memory may be reallocated, pointer to the first element may be changed. (2) Pointer to the next free (unused) element updated. (3) Maximal number of atoms updated. (4) Return value. Return value: (1) Zero if there is enough memory (no reallocation). (2) Positive if memory successfully reallocated. (3) Negative if memory reallocation failed. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ void ErrorMessage_ (char *, char *, char *, char *, char *, char *, char *); /*======reallocate memory for PDB atomic data:===============================*/ int ReallocPDBMemory_ (AtomS **first_atomSPP, AtomS **next_atomSPP, size_t *max_atomsNP, size_t curr_atomsN) { size_t new_memory_size; static AtomS *new_first_atomSP; /* If there is enough space for at least 100 atoms, do nothing: */ if (*max_atomsNP - curr_atomsN > 100) return 0; /* If this point is reached, reallocation is necessary: */ *max_atomsNP += ATOMS_IN_CHUNK; new_memory_size = *max_atomsNP * sizeof (AtomS); new_first_atomSP = realloc (*first_atomSPP, new_memory_size); /* If reallocation fails: */ if (new_first_atomSP == NULL) { ErrorMessage_ ("garlic", "ReallocPDBMemory_", "", "Failed to reallocate memory for PDB atomic data!\n", "", "", ""); /** Free the original memory block and reset pointer: **/ /** (hope that realloc left the original block untouched) **/ free (*first_atomSPP); *first_atomSPP = NULL; return -1; } /* If reallocation was successful, update pointer values: */ *first_atomSPP = new_first_atomSP; *next_atomSPP = new_first_atomSP + curr_atomsN; /* Return positive value if reallocation successfully done: */ return 1; } /*===========================================================================*/ garlic-1.6/ENVIRONMENT0000644000076500007650000000407607237517463014663 0ustar zuciczucic00000000000000 Environment Varible MOL_PATH ------------------------------------------------------------------------ The environment varible MOL_PATH may be used to define the list of directories which should be searched when you are trying to load certain PDB file. It is not mandatory to define this environment variable, but it is very practical. The exact procedure which should be used to define the environment variable MOL_PATH depends on the shell you use. The procedure is described here for some commonly used shells. If you don't know what is you shell, execute these commands: echo $shell echo $SHELL ------------------------------------------------------------------------ Bourne Shell If you are using the Bourne shell (sh) or the GNU clone called Bourne-again shell (bash), use the example bellow to create your own MOL_PATH variable. Use colon ( : ) to separate directories. It is important to export the variable! You should define this variable through your .bash_profile or .bashrc resource file in your home directory. Don't forget to replace the user name and directories. MOL_PATH="/home/zucic/pdb:/home/zucic/glob:/home/zucic/memb" export MOL_PATH ------------------------------------------------------------------------ C Shell If you are using the C shell (csh) or it's clone tcsh, use the command setenv to define the environment variable MOL_PATH. Use colon ( : ) to separate directories. You should define this variable through your .cshrc, .tcshrc or .login resource file in your home directory. The user name and directories should be replaced, of course. setenv MOL_PATH /home/zucic/pdb:/home/zucic/glob:/home/zucic/memb ------------------------------------------------------------------------ Other Shells For other shells, read the manual page to learn how to define the environment variable MOL_PATH. In most cases, the method is similar to one of the methods described above. ------------------------------------------------------------------------ garlic-1.6/edit_bond.c0000644000076500007650000002144007747301716015217 0ustar zuciczucic00000000000000/* Copyright (C) 2001-2003 Damir Zucic */ /*============================================================================= edit_bond.c Purpose: Edit (rotate) the specified bond. The array indices of two atoms which form the bond are used to specify the bond. Input: (1) Pointer to MolComplexS structure, pointing to default complex. element. (2) The index (3) Pointer to RuntimeS structure. (4) Pointer to ConfigS structure. (5) Rotation angle. Output: (1) Part of the chosen residue rotated about the specified bond. (2) Return value. Return value: (1) Positive on success. (2) Negative on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int RotateAtom_ (AtomS *, VectorS *, VectorS *, double); int DihedralAngles_ (MolComplexS *, ConfigS *); /*======edit (rotate) the specified bond:====================================*/ int EditBond_ (MolComplexS *curr_mol_complexSP, int mol_complexI, RuntimeS *runtimeSP, ConfigS *configSP, double rotation_angle) { size_t atomsN; size_t atom1_arrayI, atom2_arrayI; int residueI; int start_atomI, end_atomI, atomI; AtomS *curr_atomSP; int stepI, previous_stepI; int atoms_in_residueN; int propagationF; int atom_reachedF; int bondI; TrueBondS *curr_bondSP; AtomS *curr_neighborSP; char *atom_nameP; int CA_foundF; VectorS atom1_vectorS, atom2_vectorS; /*------prepare required indices:--------------------------------------------*/ /* Prepare and check the number of atoms: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) return -1; /* Copy the array indices of two atoms which define the chosen bond: */ atom1_arrayI = runtimeSP->atom1_arrayI; atom2_arrayI = runtimeSP->atom2_arrayI; /* Two atoms which specify the bond should belong to the same residue: */ residueI = (curr_mol_complexSP->atomSP + atom1_arrayI)->residue_arrayI; if ((int) (curr_mol_complexSP->atomSP + atom2_arrayI)->residue_arrayI != residueI) { return -2; } /* Prepare and check the atomic array indices which */ /* define the residue to which both atoms belong. */ start_atomI = (curr_mol_complexSP->residueSP + residueI)->residue_startI; end_atomI = (curr_mol_complexSP->residueSP + residueI)->residue_endI; if (((int) atom1_arrayI < start_atomI) || ((int) atom1_arrayI > end_atomI)) { return -3; } if (((int) atom2_arrayI < start_atomI) || ((int) atom2_arrayI > end_atomI)) { return -4; } /*------reset auxiliaryI for each atom of a chosen residue:------------------*/ /* Scan the chosen residue, atom by atom: */ for (atomI = start_atomI; atomI <= end_atomI; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Reset the auxiliaryI: */ curr_atomSP->auxiliaryI = 0; } /*------try to find the CA atom:---------------------------------------------*/ /* Only the atoms which are opposite to the main chain with */ /* respect to the specified bond should be rotated. To find */ /* these atoms, a shock wave is send from the first atom to */ /* the second atom and further. If this wave will reach the */ /* CA atom, the atoms which should be rotated are on the */ /* opposite side of the specified bond. Otherwise, the CA */ /* atom is either missing or placed on the opposite side. */ /* Initialize the step index: */ stepI = 1; /* Associate the first step index with the first atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atom1_arrayI; curr_atomSP->auxiliaryI = 1; /* Associate the second step index with the second atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atom2_arrayI; curr_atomSP->auxiliaryI = 2; /* Now scan the residue repeatedly. The number of scans should not */ /* exceed the number of atoms in the residue, because the length */ /* of the fully extended residue is equal to number_of_atoms - 1. */ atoms_in_residueN = end_atomI - start_atomI + 1; /* Initialize the index of the previous step: */ previous_stepI = 2; /* Initialize the flag which says that CA atom is found: */ CA_foundF = 0; /* The loop which counts steps should start from the third step: */ for (stepI = 3; stepI < atoms_in_residueN; stepI++) { /* Reset the wave propagation flag: */ propagationF = 0; /* In each step, scan the entire residue, atom by atom: */ for (atomI = start_atomI; atomI <= end_atomI; atomI++) { /* In the third step, the first atom of */ /* the specified bond should be skipped: */ if ((stepI == 3) && (atomI == (int) atom1_arrayI)) continue; /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* If the current atom was reached */ /* in the previous step, skip it: */ if (curr_atomSP->auxiliaryI == previous_stepI) continue; /* Reset the flag which says that the */ /* atom is reached by the shock wave: */ atom_reachedF = 0; /* Scan all bonds of the current atom: */ for (bondI = 0; bondI < curr_atomSP->bondsN; bondI++) { /* Pointer to the current bond: */ curr_bondSP = curr_atomSP->true_bondSA + bondI; /* Only the covalent bonds are taken into account. */ /* Hydrogen, disulfide and pseudo-bonds are ignored. */ if (curr_bondSP->bond_typeI != 1) continue; /* Bonds formed with atoms from another */ /* macromolecular complex are ignored: */ if (curr_bondSP->neighbor_mol_complexI != mol_complexI) { continue; } /* If the bond partner was reached by the shock */ /* wave in the previous step, the current atom */ /* is reached by the shock wave in this step: */ curr_neighborSP = curr_mol_complexSP->atomSP + curr_bondSP->neighbor_arrayI; if (curr_neighborSP->auxiliaryI == previous_stepI) { /* Set the flag which says that the */ /* shock wave continues propagation: */ propagationF = 1; /* Set the flag which says that this */ /* atom is reached by the shock wave: */ atom_reachedF = 1; /* Do not check the remaining */ /* bonds, it is not necessary: */ break; } } /* If the current atom is reached in this step: */ if (atom_reachedF) { /* If the current atom is the CA atom, set the flag: */ atom_nameP = curr_atomSP->raw_atomS.pure_atom_nameA; if (strcmp (atom_nameP, "CA") == 0) CA_foundF = 1; /* If the shock wave reached the current atom */ /* for the first time, store the step index: */ if (curr_atomSP->auxiliaryI == 0) { curr_atomSP->auxiliaryI = stepI; } } } /* If the shock wave is not propagating any more, break: */ if (!propagationF) break; /* Update the value of the previous step index: */ previous_stepI = stepI; } /* If the CA atom was reached by the shock wave, the atoms which should */ /* be rotated about the specified bond are on the opposite side of this */ /* bond, and for that reason all auxiliaryI values should be changed. */ /* Zeros should be replaced by values different from zero and vice versa. */ if (CA_foundF) { /* Scan the chosen residue, atom by atom: */ for (atomI = start_atomI; atomI <= end_atomI; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Revert the auxiliaryI: */ if (curr_atomSP->auxiliaryI) curr_atomSP->auxiliaryI = 0; else curr_atomSP->auxiliaryI = 1; } } /*------rotate atoms:--------------------------------------------------------*/ /* Prepare the coordinates of two atoms which define the rotation axis: */ /* The position of the first atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atom1_arrayI; atom1_vectorS.x = curr_atomSP->raw_atomS.x[0]; atom1_vectorS.y = curr_atomSP->raw_atomS.y; atom1_vectorS.z = curr_atomSP->raw_atomS.z[0]; /* The position of the second atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atom2_arrayI; atom2_vectorS.x = curr_atomSP->raw_atomS.x[0]; atom2_vectorS.y = curr_atomSP->raw_atomS.y; atom2_vectorS.z = curr_atomSP->raw_atomS.z[0]; /* Rotate all atoms after the current residue about CA-C bond: */ for (atomI = start_atomI + 1; atomI <= end_atomI; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* If this atom is not in the outer portion of the side chain */ /* (with respect to the specified bond), do not rotate it: */ if (curr_atomSP->auxiliaryI == 0) continue; /* Rotate atom: */ RotateAtom_ (curr_atomSP, &atom1_vectorS, &atom2_vectorS, rotation_angle); } /*---------------------------------------------------------------------------*/ /* Update dihedral angles and cis-trans flags: */ DihedralAngles_ (curr_mol_complexSP, configSP); /* Return positive value (trivial): */ return 1; } /*===========================================================================*/ garlic-1.6/fileformat.c0000644000076500007650000000200307065471116015405 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= fileformat.c Purpose: Try to recognize input file format. Input: (1) File name. Output: (1) Return value. Return value: (1) File format identifier on success (see defines.h for values). (3) Negative on failure. ========includes:============================================================*/ #include #include "defines.h" /*======function prototypes:=================================================*/ void ErrorMessage_ (char *, char *, char *, char *, char *, char *, char *); int IsPDB_ (char *); /*======recognize file format:===============================================*/ int RecogFileFormat_ (char *file_nameP) { int n; /* Check is it PDB file: */ n = IsPDB_ (file_nameP); if (n >= 0) return n; /* If this point is reached, file format recognition failed: */ return -1; } /*===========================================================================*/ garlic-1.6/edit_chi1.c0000644000076500007650000000703107415612566015121 0ustar zuciczucic00000000000000/* Copyright (C) 2001, 2002 Damir Zucic */ /*============================================================================= edit_chi1.c Purpose: Edit the chi1 angle for every selected residue in the specified macromolecular complex. A residue is treated as selected if the first atom of this residue is selected. For proteins, this is typically the N atom (nitrogen). Input: (1) Pointer to MolComplexS structure. (2) Pointer to RuntimeS structure. (3) Pointer to ConfigS structure. (4) Rotation angle. Output: (1) The angle chi1 changed for every selected residue. (2) Return value. Return value: (1) Positive always (trivial). ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int ExtractCACB_ (VectorS *, VectorS *, AtomS *, size_t, size_t); int RotateAtom_ (AtomS *, VectorS *, VectorS *, double); int DihedralAngles_ (MolComplexS *, ConfigS *); /*======change chi1 angle for selected residues:=============================*/ int EditChi1_ (MolComplexS *mol_complexSP, RuntimeS *runtimeSP, ConfigS *configSP, double delta_chi1) { int residuesN, residueI; size_t atomsN; ResidueS *residueSP; size_t atom_startI, atom_endI, atomI; AtomS *atomSP; char *residue_nameP; int n; char *atom_nameP; static VectorS CA_vectorS, CB_vectorS; /* Copy the number of residues in the current complex: */ residuesN = mol_complexSP->residuesN; /* Copy the number of atoms in the current complex: */ atomsN = mol_complexSP->atomsN; /* Scan residues: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Pointer to the current residue: */ residueSP = mol_complexSP->residueSP + residueI; /* Prepare the atomic index range: */ atom_startI = residueSP->residue_startI; atom_endI = residueSP->residue_endI; /* Pointer to the first atom: */ atomSP = mol_complexSP->atomSP + atom_startI; /* Skip proline: */ residue_nameP = atomSP->raw_atomS.pure_residue_nameA; if (strcmp (residue_nameP, "PRO") == 0) continue; /* Edit chi1 angle if the current residue is selected. */ /* If the first atom of the current residue is */ /* not selected, the residue is not selected: */ if (atomSP->selectedF == 0) continue; /* Extract CA and CB coordinates: */ n = ExtractCACB_ (&CA_vectorS, &CB_vectorS, mol_complexSP->atomSP, atom_startI, atom_endI); if (n < 2) continue; /* Change the chi1 angle: */ for (atomI = atom_startI; atomI <= atom_endI; atomI++) { /* Pointer to the current atom: */ atomSP = mol_complexSP->atomSP + atomI; /* Pointer to the purified atom name: */ atom_nameP = atomSP->raw_atomS.pure_atom_nameA; /* Do not rotate H, N, CA, HA, C, O and CB: */ if (!strcmp (atom_nameP, "H" )) continue; if (!strcmp (atom_nameP, "N" )) continue; if (!strcmp (atom_nameP, "CA")) continue; if (!strcmp (atom_nameP, "HA")) continue; if (!strcmp (atom_nameP, "C" )) continue; if (!strcmp (atom_nameP, "O" )) continue; if (!strcmp (atom_nameP, "CB")) continue; /* Rotate the current atom about CA-CB bond: */ RotateAtom_ (atomSP, &CA_vectorS, &CB_vectorS, delta_chi1); } } /* Update dihedral angles and cis-trans flags: */ DihedralAngles_ (mol_complexSP, configSP); /* Return positive value (trivial): */ return 1; } /*===========================================================================*/ garlic-1.6/edit_chi2.c0000644000076500007650000000761007415612577015127 0ustar zuciczucic00000000000000/* Copyright (C) 2001, 2002 Damir Zucic */ /*============================================================================= edit_chi2.c Purpose: Edit the chi2 angle for every selected residue in the specified macromolecular complex. A residue is treated as selected if the first atom of this residue is selected. For proteins, this is typically the N atom (nitrogen). In this function the symbol XG stands for CG, CG1, OG, OG1 or SG. The CG atom appears in PRO, LEU, MET, PHE, TRP, ASN, GLN, TYR, ASP, GLU, LYS, ARG and HIS. The CG1 atom appears in ILE, OG in SER, OG1 in THR and SG in CYS. This function is not able to handle non-standard residues. Input: (1) Pointer to MolComplexS structure. (2) Pointer to RuntimeS structure. (3) Pointer to ConfigS structure. (4) Rotation angle. Output: (1) Chi2 angle changed for every selected residue. (2) Return value. Return value: (1) Positive always (trivial). ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int ExtractCBXG_ (VectorS *, VectorS *, AtomS *, size_t, size_t); int RotateAtom_ (AtomS *, VectorS *, VectorS *, double); int DihedralAngles_ (MolComplexS *, ConfigS *); /*======change chi2 angle for selected residues:=============================*/ int EditChi2_ (MolComplexS *mol_complexSP, RuntimeS *runtimeSP, ConfigS *configSP, double delta_chi2) { int residuesN, residueI; size_t atomsN; ResidueS *residueSP; size_t atom_startI, atom_endI, atomI; AtomS *atomSP; char *residue_nameP; int n; char *atom_nameP; static VectorS CB_vectorS, XG_vectorS; /* Copy the number of residues in the current complex: */ residuesN = mol_complexSP->residuesN; /* Copy the number of atoms in the current complex: */ atomsN = mol_complexSP->atomsN; /* Scan residues: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Pointer to the current residue: */ residueSP = mol_complexSP->residueSP + residueI; /* Prepare the atomic index range: */ atom_startI = residueSP->residue_startI; atom_endI = residueSP->residue_endI; /* Pointer to the first atom: */ atomSP = mol_complexSP->atomSP + atom_startI; /* Skip proline: */ residue_nameP = atomSP->raw_atomS.pure_residue_nameA; if (strcmp (residue_nameP, "PRO") == 0) continue; /* Edit chi2 angle if the current residue is selected. */ /* If the first atom of the current residue is */ /* not selected, the residue is not selected: */ if (atomSP->selectedF == 0) continue; /* Extract CB and XG coordinates: */ n = ExtractCBXG_ (&CB_vectorS, &XG_vectorS, mol_complexSP->atomSP, atom_startI, atom_endI); if (n < 2) continue; /* Change the chi2 angle: */ for (atomI = atom_startI; atomI <= atom_endI; atomI++) { /* Pointer to the current atom: */ atomSP = mol_complexSP->atomSP + atomI; /* Pointer to the purified atom name: */ atom_nameP = atomSP->raw_atomS.pure_atom_nameA; /* Do not rotate H, N, CA, HA, C, O, CB and HB: */ if (strcmp (atom_nameP, "H" ) == 0) continue; if (strcmp (atom_nameP, "N" ) == 0) continue; if (strcmp (atom_nameP, "CA") == 0) continue; if (strcmp (atom_nameP, "HA") == 0) continue; if (strcmp (atom_nameP, "C" ) == 0) continue; if (strcmp (atom_nameP, "O" ) == 0) continue; if (strcmp (atom_nameP, "CB") == 0) continue; if (strcmp (atom_nameP, "HB") == 0) continue; /* Rotate the current atom about CB-XG bond: */ RotateAtom_ (atomSP, &CB_vectorS, &XG_vectorS, delta_chi2); } } /* Update dihedral angles and cis-trans flags: */ DihedralAngles_ (mol_complexSP, configSP); /* Return positive value (trivial): */ return 1; } /*===========================================================================*/ garlic-1.6/foreground.c0000644000076500007650000000531107065471150015432 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= foreground.c Purpose: Execute foreground command: change the main window foreground color. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) The number of macromolecular complexes. (3) Pointer to RuntimeS structure, with some runtime data. (4) Pointer to ConfigS structure, with configuration data. (5) Pointer to GUIS structure, with GUI data. (6) Pointer to NearestAtomS structure. (7) The number of pixels in the main window free area. (8) Pointer to refreshI. Output: (1) Log file created. (2) Return value. Return value: (1) Positive (command) code on success. (2) Negative (error) code on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "commands.h" #include "typedefs.h" /*======function prototypes:=================================================*/ char *ExtractToken_ (char *, int, char *, char *); int ParseColor_ (RGBS *, unsigned long *, GUIS *, char *, char *); size_t MainRefresh_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); /*======execute fg command:==================================================*/ int Foreground_ (MolComplexS *mol_complexSP, int mol_complexesN, RuntimeS *runtimeSP, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int *refreshIP) { char *remainderP; char tokenA[STRINGSIZE]; /* Skip the first token: */ remainderP = ExtractToken_ (tokenA, STRINGSIZE, runtimeSP->curr_commandA, " \t\n"); if (!remainderP) return ERROR_FOREGROUND; /* The second token should contain the color: */ remainderP = ExtractToken_ (tokenA, STRINGSIZE, remainderP, " \t\n"); if (!remainderP) { strcpy (runtimeSP->messageA, "Main window foreground color missing!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_NO_COLOR; } /* Prepare the main window foreground color: */ strncpy (configSP->fg_colorA, tokenA, SHORTSTRINGSIZE - 1); configSP->fg_colorA[SHORTSTRINGSIZE - 1] = '\0'; ParseColor_ (&guiSP->main_winS.fg_rgbS, &guiSP->main_winS.fg_colorID, guiSP, configSP->fg_colorA, "white"); /* Refresh the main window: */ (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); /* Return positive value on success: */ return COMMAND_FOREGROUND; } /*===========================================================================*/ garlic-1.6/font.c0000644000076500007650000001445010357044217014230 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2006 Damir Zucic */ /*============================================================================= font.c Purpose: Execute font command: change font. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Pointer to the number of macromolecular complexes. (3) Pointer to RuntimeS structure, with some runtime data. (4) Pointer to ConfigS structure, with configuration data. (5) Pointer to GUIS structure, with GUI data. (6) Pointer to pointer to NearestAtomS structure. (7) Pointer to the number of pixels in the main window free area. (8) Pointer to refreshI. Output: (1) Font changed. (2) Return value. Return value: (1) Positive (command) code on success. (2) Negative (error) code on failure. Notes: (1) The original command string should be used. ========includes:============================================================*/ #include #include #include #include #include #include #include #include "defines.h" #include "commands.h" #include "typedefs.h" /*======function prototypes:=================================================*/ char *ExtractToken_ (char *, int, char *, char *); int CalculateParameters_ (ConfigS *, GUIS *); NearestAtomS *AllocateNearest_ (size_t *, GUIS *); void InitNearest_ (NearestAtomS *, size_t); /*======execute font command:================================================*/ int Font_ (MolComplexS *mol_complexSP, int mol_complexesN, RuntimeS *runtimeSP, ConfigS *configSP, GUIS *guiSP, NearestAtomS **nearest_atomSPP, size_t *pixelsNP, unsigned int *refreshIP) { char *remainderP; char tokenA[STRINGSIZE]; static XFontStruct *fontSP; int n; int old_input_win_height, new_input_win_height; int delta_height; int mol_complexI; /* Skip the first token: */ remainderP = ExtractToken_ (tokenA, STRINGSIZE, runtimeSP->curr_commandA, " \t\n"); if (!remainderP) return ERROR_FONT; /* The second token should contain the font name: */ remainderP = ExtractToken_ (tokenA, STRINGSIZE, remainderP, " \t\n"); if (!remainderP) { strcpy (runtimeSP->messageA, "Missing font name!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_NO_FONT_NAME; } /* Try to load the requested font: */ fontSP = XLoadQueryFont (guiSP->displaySP, tokenA); if (fontSP == NULL) { sprintf (runtimeSP->messageA, "Font %s is not available!", tokenA); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_FONT; } /* If this point is reached, copy the font to GUIS structure: */ guiSP->main_winS.fontSP = fontSP; /* Set this font to all GC's: */ XSetFont(guiSP->displaySP, guiSP->theGCA[0], guiSP->main_winS.fontSP->fid); XSetFont(guiSP->displaySP, guiSP->theGCA[1], guiSP->main_winS.fontSP->fid); XSetFont(guiSP->displaySP, guiSP->theGCA[2], guiSP->main_winS.fontSP->fid); XSetFont(guiSP->displaySP, guiSP->theGCA[3], guiSP->main_winS.fontSP->fid); XSetFont(guiSP->displaySP, guiSP->theGCA[4], guiSP->main_winS.fontSP->fid); XSetFont(guiSP->displaySP, guiSP->theGCA[5], guiSP->main_winS.fontSP->fid); XSetFont(guiSP->displaySP, guiSP->theGCA[6], guiSP->main_winS.fontSP->fid); XSetFont(guiSP->displaySP, guiSP->theGCA[7], guiSP->main_winS.fontSP->fid); XSetFont(guiSP->displaySP, guiSP->theGCA[8], guiSP->main_winS.fontSP->fid); XSetFont(guiSP->displaySP, guiSP->theGCA[9], guiSP->main_winS.fontSP->fid); /* Initialize font heights: */ n = guiSP->main_winS.fontSP->ascent + guiSP->main_winS.fontSP->descent; /** Main window: **/ guiSP->main_winS.quarter_font_height = (n + 3) / 4; guiSP->main_winS.half_font_height = (n + 1) / 2; guiSP->main_winS.font_height = n; guiSP->main_winS.text_line_height = guiSP->main_winS.font_height + guiSP->main_winS.quarter_font_height; /** Output window: **/ guiSP->output_winS.quarter_font_height = guiSP->main_winS.quarter_font_height; guiSP->output_winS.half_font_height = guiSP->main_winS.half_font_height; guiSP->output_winS.font_height = guiSP->main_winS.font_height; guiSP->output_winS.text_line_height = guiSP->main_winS.text_line_height; /** Input window: **/ guiSP->input_winS.quarter_font_height = guiSP->main_winS.quarter_font_height; guiSP->input_winS.half_font_height = guiSP->main_winS.half_font_height; guiSP->input_winS.font_height = guiSP->main_winS.font_height; guiSP->input_winS.text_line_height = guiSP->main_winS.text_line_height; /* Change input window height and position: */ old_input_win_height = guiSP->input_winS.height; new_input_win_height = 2 * guiSP->input_winS.text_line_height + guiSP->input_winS.quarter_font_height; delta_height = new_input_win_height - old_input_win_height; guiSP->input_winS.height = (unsigned int) new_input_win_height; n = (int) guiSP->input_winS.y0 - delta_height; if (n < 0) n = 0; guiSP->input_winS.y0 = n; /* Change the main window free area height: */ n = (int) guiSP->main_win_free_area_height - delta_height; if (n < 0) n = 0; guiSP->main_win_free_area_height = (unsigned int) n; /* Refresh calculated parameters: */ if (CalculateParameters_ (configSP, guiSP) < 0) return ERROR_FONT; /* Resize and move the input window: */ XResizeWindow (guiSP->displaySP, guiSP->input_winS.ID, guiSP->input_winS.width, guiSP->input_winS.height); XMoveWindow (guiSP->displaySP, guiSP->input_winS.ID, guiSP->input_winS.x0, guiSP->input_winS.y0); /* Resize the main hidden pixmap: */ if ((guiSP->main_hidden_pixmapF) && (guiSP->main_win_free_area_height > 0)) { XFreePixmap (guiSP->displaySP, guiSP->main_hidden_pixmapID); guiSP->main_hidden_pixmapID = XCreatePixmap ( guiSP->displaySP, DefaultRootWindow (guiSP->displaySP), guiSP->main_win_free_area_width, guiSP->main_win_free_area_height, guiSP->depth); } /* Resize the NearestAtomS array: */ if (*nearest_atomSPP) { free (*nearest_atomSPP); *nearest_atomSPP = AllocateNearest_ (pixelsNP, guiSP); InitNearest_ (*nearest_atomSPP, *pixelsNP); } /* Set the position_changedF flag for each macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { (mol_complexSP + mol_complexI)->position_changedF = 1; } /* Return positive value on success: */ return COMMAND_FONT; } /*===========================================================================*/ garlic-1.6/comm_rotate.c0000644000076500007650000000745307362641754015613 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= comm_rotate.c Purpose: Execute rotate command. Rotate all caught macromolecular complexes for a given angle around a given axis. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) The number of macromolecular complexes. (3) Pointer to RuntimeS structure, with some runtime data. (4) Pointer to ConfigS structure, with configuration data. (5) Pointer to GUIS structure, with GUI data. (6) Pointer to NearestAtomS structure. (7) The number of pixels in the main window free area. (8) Pointer to refreshI. (9) String which contains the rotation axis name and the rotation angle. Output: (1) Atoms rotated. (2) Return value. Return value: (1) Positive (command) code on success. (2) Negative (error) code on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "commands.h" #include "typedefs.h" /*======function prototypes:=================================================*/ char *ExtractToken_ (char *, int, char *, char *); int Rotate_ (MolComplexS *, int, RuntimeS *, ConfigS *, double, int); size_t MainRefresh_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); int ControlRefresh_ (MolComplexS *, ConfigS *, GUIS *); int DockingRefresh_ (RuntimeS *, GUIS *); /*======execute rotate command:==============================================*/ int CommandRotate_ (MolComplexS *mol_complexSP, int mol_complexesN, RuntimeS *runtimeSP, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int *refreshIP, char *stringP) { char *remainderP; char tokenA[STRINGSIZE]; int axisID; double rotation_angle; /* Extract axis name: */ remainderP = ExtractToken_ (tokenA, STRINGSIZE, stringP, " \t\n"); if (!remainderP) { strcpy (runtimeSP->messageA, "Axis specification missing!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_NO_AXIS; } /* Identify the axis: */ if (strcmp (tokenA, "X") == 0) axisID = 1; else if (strcmp (tokenA, "Y") == 0) axisID = 2; else if (strcmp (tokenA, "Z") == 0) axisID = 3; else { strcpy (runtimeSP->messageA, "Bad axis (only x, y and z are available)!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_BAD_AXIS; } /* Extract the token which contains the rotation angle: */ remainderP = ExtractToken_ (tokenA, STRINGSIZE, remainderP, " \t\n"); if (!remainderP) { strcpy (runtimeSP->messageA, "Rotation angle missing!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_NO_ANGLE; } /* Extract the rotation angle: */ if (sscanf (tokenA, "%lf", &rotation_angle) != 1) { strcpy (runtimeSP->messageA, "Rotation angle specification is bad!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_NO_ANGLE; } /* Convert degrees to radians: */ rotation_angle *= DEG_TO_RAD; /* Rotate all caught macromolecular complexes: */ Rotate_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, rotation_angle, axisID); /* Refresh the main window: */ (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); /* Refresh the control window: */ ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); /* Refresh docking window, if docking is switched on: */ if (guiSP->dockingF) DockingRefresh_ (runtimeSP, guiSP); /* Return positive value on success: */ return COMMAND_ROTATE; } /*===========================================================================*/ garlic-1.6/color_weighted.c0000644000076500007650000002046610445760276016274 0ustar zuciczucic00000000000000/* Copyright (C) 2004-2006 Damir Zucic */ /*============================================================================= color_weighted.c Purpose: Weighted color scheme: colors are assigned according to weighted hydrophobicity. The array of weights may be seen below. The absolute weighted hydrophobicity values are used. The residue which has the minimal absolute weighted hydrophobicity value will be colored blue and the residue which has the maximal value of the absolute weighted hydrophobicity will be colored red. Almost the entire spectrum of "rainbow" colors is used, except magenta: blue, cyan, green, yellow, orange and red. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. (3) Pointer to GUIS structure, with GUI data. (4) Pointer to ColorSchemeS structure. Output: (1) Return value. Return value: (1) Positive on success. (2) Zero on failure. Notes: (1) Indentation is exceptionally four spaces. (2) The minimal and maximal value are calculated separately for each macromolecular complex. =============================================================================*/ #include #include #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ void ErrorMessage_ (char *, char *, char *, char *, char *, char *, char *); int MixColors_ (AtomS *, ColorSchemeS *, ColorSchemeS *, double, GUIS *); /*======weighted color scheme:===============================================*/ int ColorWeighted_ (MolComplexS *mol_complexSP, int mol_complexesN, GUIS *guiSP, ColorSchemeS *color_schemeSP) { size_t rgb_struct_size; ColorSchemeS *blue_schemeSP, *cyan_schemeSP, *green_schemeSP, *yellow_schemeSP, *orange_schemeSP, *red_schemeSP; int max_residuesN; int mol_complexI; MolComplexS *curr_mol_complexSP; int residuesN; static double *weightedP; int residueI; double min_abs_value, max_abs_value; double weighted; int windowI, combinedI; ResidueS *curr_residueSP; int first_atomI, last_atomI, atomI; AtomS *first_atomSP; double hydrophobicity; static double weightA[11] = { 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, -1.0, -1.0, -1.0, -1.0, -1.0}; double abs_value; double range, inverse_range; double delta_range, inverse_delta_range; int rangeI; double scale_factor; AtomS *curr_atomSP; /*------auxiliary parameters and pointers:-----------------------------------*/ /* The size of RGBS structure: */ rgb_struct_size = sizeof (RGBS); /* Pointer to color schemes: */ blue_schemeSP = color_schemeSP + 2; cyan_schemeSP = color_schemeSP + 4; green_schemeSP = color_schemeSP + 1; yellow_schemeSP = color_schemeSP + 3; orange_schemeSP = color_schemeSP + 12; red_schemeSP = color_schemeSP + 0; /*------find the maximal number of residues:---------------------------------*/ /* Initialize the maximal number of residues: */ max_residuesN = 0; /* Scan every macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check is the current macromolecular complex caught: */ if (curr_mol_complexSP->catchF == 0) continue; /* Check the number of residues: */ residuesN = curr_mol_complexSP->residuesN; if (residuesN > max_residuesN) max_residuesN = residuesN; } /* Check was there anything at all: */ if (max_residuesN == 0) { ErrorMessage_ ("garlic", "ColorSchemes_", "", "No residues found!\n", "", "", ""); return -1; } /*------allocate the storage for weighted hydrophobicity:--------------------*/ weightedP = (double *) calloc (max_residuesN, sizeof (double)); if (weightedP == NULL) { ErrorMessage_ ("garlic", "ColorSchemes_", "", "Failed to allocate memory!\n", "", "", ""); return -2; } /*------calculate the absolute weighted hydrophobicity values:---------------*/ /* Scan every macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check is the current macromolecular complex caught: */ if (curr_mol_complexSP->catchF == 0) continue; /* Copy the number of residues: */ residuesN = curr_mol_complexSP->residuesN; if (residuesN == 0) continue; /* Reset the extreme absolute values of weighted hydrophobicity: */ min_abs_value = +999999.0; max_abs_value = -999999.0; /* Scan all residues: */ for (residueI = 5; residueI < residuesN - 5; residueI++) { /* Reset the weighted hydrophobicity: */ weighted = 0.0; /* Scan the window of 15 residues: */ for (windowI = 0; windowI < 11; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI - 5; if (combinedI < 0) continue; if (combinedI >= residuesN) continue; /* Pointer to the current residue: */ curr_residueSP = curr_mol_complexSP->residueSP + combinedI; /* Pointer to the first atom of this residue: */ first_atomI = curr_residueSP->residue_startI; first_atomSP = (curr_mol_complexSP->atomSP + first_atomI); /* Copy the hydrophobicity associated with this residue: */ hydrophobicity = first_atomSP->raw_atomS.hydrophobicity; /* Update the weighted hydrophobicity: */ weighted += hydrophobicity * weightA[windowI]; } /* Store the absolute value of weighted hydrophobicity: */ abs_value = fabs (weighted); *(weightedP + residueI) = abs_value; /* Check is this the minimal or the maximal */ /* value for this macromolecular complex: */ if (abs_value < min_abs_value) min_abs_value = abs_value; if (abs_value > max_abs_value) max_abs_value = abs_value; } /* Prepare and check two auxiliary parameters required for color mixing: */ range = max_abs_value - min_abs_value; if (range <= 0.0) continue; inverse_range = 1.0 / range; /* The first parameter */ delta_range = range / 5.0; inverse_delta_range = 1.0 / delta_range; /* The second parameter */ /* Scan the current macromolecular complex again, residue by residue: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Pointer to the current residue: */ curr_residueSP = curr_mol_complexSP->residueSP + residueI; /* The indices of the first and the */ /* last atom of the current residue: */ first_atomI = curr_residueSP->residue_startI; last_atomI = curr_residueSP->residue_endI; /* The absolute weighted hydrophobicity assigned to this residue: */ abs_value = *(weightedP + residueI); /* Range index (between zero and four): */ rangeI = (abs_value - min_abs_value) * inverse_delta_range; /* The scale factor, required for color mixing (the */ /* value of scale factor must be between 0 and 1). */ scale_factor = (abs_value - (double) rangeI * delta_range) * inverse_delta_range; /* Scan the residue, atom by atom: */ for (atomI = first_atomI; atomI <= last_atomI; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Mix colors: */ if (rangeI == 0) { MixColors_ (curr_atomSP, blue_schemeSP, cyan_schemeSP, scale_factor, guiSP); } else if (rangeI == 1) { MixColors_ (curr_atomSP, cyan_schemeSP, green_schemeSP, scale_factor, guiSP); } else if (rangeI == 2) { MixColors_ (curr_atomSP, green_schemeSP, yellow_schemeSP, scale_factor, guiSP); } else if (rangeI == 3) { MixColors_ (curr_atomSP, yellow_schemeSP, orange_schemeSP, scale_factor, guiSP); } else { MixColors_ (curr_atomSP, orange_schemeSP, red_schemeSP, scale_factor, guiSP); } } } /* Reset the position_changedF: */ curr_mol_complexSP->position_changedF = 1; } /*------free storage:--------------------------------------------------------*/ free (weightedP); /*---------------------------------------------------------------------------*/ /* Return positive value on success: */ return 1; } /*===========================================================================*/ garlic-1.6/many-proteins.script0000644000076500007650000000545607577174602017173 0ustar zuciczucic00000000000000load 100d.pdb hyb dis all load 153l.pdb hyb dis all load 1APL.pdb hyb dis all load 1AV5.pdb hyb dis all load 1aaj.pdb hyb dis all load 1aaz.pdb hyb dis all load 1aba.pdb hyb dis all load 1acf.pdb hyb dis all load 1acx.pdb hyb dis all load 1adl.pdb hyb dis all load 1aiz.pdb hyb dis all load 1alc.pdb hyb dis all load 1ald.pdb hyb dis all load 1alk.pdb hyb dis all load 1amp.pdb hyb dis all load 1aoz.pdb hyb dis all load 1apb.pdb hyb dis all load 1apm.pdb hyb dis all load 1apt.pdb hyb dis all load 1arb.pdb hyb dis all load 1arp.pdb hyb dis all load 1ast.pdb hyb dis all load 1ava.pdb hyb dis all load 1aya.pdb hyb dis all load 1b9p.pdb hyb dis all load 1bab.pdb hyb dis all load 1bam.pdb hyb dis all load 1bbh.pdb hyb dis all load 1bbp.pdb hyb dis all load 1bcx.pdb hyb dis all load 1bgc.pdb hyb dis all load 1bmd.pdb hyb dis all load 1bpq.pdb hyb dis all load 1brs.pdb hyb dis all load 1bse.pdb hyb dis all load 1bsr.pdb hyb dis all load 1btc.pdb hyb dis all load 1btl.pdb hyb dis all load 1cbs.pdb hyb dis all load 1cdg.pdb hyb dis all load 1cdm.pdb hyb dis all load 1cel.pdb hyb dis all load 1cew.pdb hyb dis all load 1cfb.pdb hyb dis all load 1chm.pdb hyb dis all load 1cmb.pdb hyb dis all load 1cob.pdb hyb dis all load 1con.pdb hyb dis all load 1cot.pdb hyb dis all load 1cp4.pdb hyb dis all load 1cpc.pdb hyb dis all load 1cse.pdb hyb dis all load 1cus.pdb hyb dis all load 1cyo.pdb hyb dis all load 1dbs.pdb hyb dis all load 1ddt.pdb hyb dis all load 1dhi.pdb hyb dis all load 1dmb.pdb hyb dis all load 1dob.pdb hyb dis all load 1drf.pdb hyb dis all load 1drk.pdb hyb dis all load 1dsb.pdb hyb dis all load 1eas.pdb hyb dis all load 1eca.pdb hyb dis all load 1edb.pdb hyb dis all load 1ejg.pdb hyb dis all load 1enj.pdb hyb dis all load 1ept.pdb hyb dis all load 1esl.pdb hyb dis all load 1ezm.pdb hyb dis all load 1flp.pdb hyb dis all load 1fus.pdb hyb dis all load 1hbg.pdb hyb dis all load 1hfc.pdb hyb dis all load 1hmr.pdb hyb dis all load 1icm.pdb hyb dis all load 1lzb.pdb hyb dis all load 1mbc.pdb hyb dis all load 1noa.pdb hyb dis all load 1pmy.pdb hyb dis all load 1poa.pdb hyb dis all load 1rat.pdb hyb dis all load 1rcf.pdb hyb dis all load 1sha.pdb hyb dis all load 1stf.pdb hyb dis all load 1tca.pdb hyb dis all load 1thm.pdb hyb dis all load 1tld.pdb hyb dis all load 1vqb.pdb hyb dis all load 1xnb.pdb hyb dis all load 2ACT.pdb hyb dis all load 2abk.pdb hyb dis all load 2c2c.pdb hyb dis all load 2cba.pdb hyb dis all load 2ctb.pdb hyb dis all load 2end.pdb hyb dis all load 2pia.pdb hyb dis all load 2pkc.pdb hyb dis all load 2plt.pdb hyb dis all load 2rn2.pdb hyb dis all load 2sga.pdb hyb dis all load 2sns.pdb hyb dis all load 3b5c.pdb hyb dis all load 3grs.pdb hyb dis all load 3sdh.pdb hyb dis all load 4gcr.pdb hyb dis all load 5cyt.pdb hyb dis all load 5pal.pdb hyb dis all load 8abp.pdb hyb dis all load 9PAP.pdb hyb dis all garlic-1.6/color_schemes.c0000644000076500007650000002517110142642257016111 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2004 Damir Zucic */ /*============================================================================= color_schemes.c Purpose: This function handles the simple color schemes. The first call to this function prepares color specifications. Later calls to this function may be used to: - Assign required color scheme to selected atoms. - Define default color scheme for molecular surfaces. - Assign required color scheme to the active surface. The active surface belongs to default macromolecular complex. The index of the active surface is kept in RuntimeS structure. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. (3) Pointer to ConfigS, where surface colors will be stored on request (if mode index is equal to one). (4) Pointer to GUIS structure, with GUI data. (5) Color scheme name. (6) The mode index: 0 = assign colors to atoms. 1 = initialize default colors for the outer side of molecular surfaces. The colors should be stored to ConfigS. 2 = initialize default colors for the inner side of molecular surfaces. The colors should be stored to ConfigS. 3 = set the outer surface colors for the active surface of default macromolecular complexes. 4 = set the inner surface colors for the active surface of default macromolecular complexes. Output: (1) Return value. Return value: (1) Positive on success. (2) Zero, if this function is called for the first time. (2) Negative on failure (scheme not recognized). Notes: (1) Simple color schemes are hard-coded in the program. (2) The active surface index is stored to RuntimeS structure. =============================================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int InitializeColors_ (ColorSchemeS *, GUIS *); int CPK_ (MolComplexS *, int, GUIS *, ColorSchemeS *); int Zebra_ (MolComplexS *, int, GUIS *, ColorSchemeS *); int Chain_ (MolComplexS *, int, GUIS *, ColorSchemeS *); int ColorHyphob_ (MolComplexS *, int, GUIS *, ColorSchemeS *); int ColorModel_ (MolComplexS *, int, GUIS *, ColorSchemeS *); int ColorSize_ (MolComplexS *, int, GUIS *, ColorSchemeS *); int ColorWeighted_ (MolComplexS *, int, GUIS *, ColorSchemeS *); /*======simple color schemes:================================================*/ int ColorSchemes_ (MolComplexS *mol_complexSP, int mol_complexesN, ConfigS *configSP, GUIS *guiSP, char *scheme_nameP, int modeI) { static int called_beforeF; static ColorSchemeS color_schemeSA[COLORSCHEMES]; static char scheme_nameAA[COLORSCHEMES][SHORTSTRINGSIZE] = {"RED", "GREEN", "BLUE", "YELLOW", "CYAN", "MAGENTA", "WHITE", "YELLOW-GREEN", "CYAN-GREEN", "CYAN-BLUE", "MAGENTA-BLUE", "MAGENTA-RED", "ORANGE", "HOT", "COLD", "MONOCHROME", "CPK", "ZEBRA", "CHAIN", "HYPHOB", "MODEL", "ORANGE-YELLOW", "ORANGE-RED", "SKIN", "SIZE", "WEIGHTED"}; int schemeI = -1; ColorSchemeS *color_schemeSP; int i; int surfaceI, surfacesN; int mol_complexI; MolComplexS *curr_mol_complexSP; size_t atomsN, atomI; AtomS *curr_atomSP; size_t rgb_struct_size; /* The size of RGBS structure: */ rgb_struct_size = sizeof (RGBS); /* If this function is called for the first time, initialize colors: */ if (called_beforeF == 0) { InitializeColors_ (color_schemeSA, guiSP); called_beforeF = 1; return 0; } /* Recognize the scheme name: */ for (i = 0; i < COLORSCHEMES; i++) { if (strcmp (scheme_nameAA[i], scheme_nameP) == 0) { schemeI = i; break; } } /* If scheme name was not recognized, return negative value: */ if (schemeI == -1) return -1; /*---------------------------------------------------------------------------*/ /* If the mode index is equal to one, initialize default */ /* colors for the outer sides of the molecular surfaces. */ if (modeI == 1) { switch (schemeI) { /* The following color schemes are suitable for surfaces: */ case 0: /* RED */ case 1: /* GREEN */ case 2: /* BLUE */ case 3: /* YELLOW */ case 4: /* CYAN */ case 5: /* MAGENTA */ case 6: /* WHITE */ case 7: /* YELLOW-GREEN */ case 8: /* CYAN-GREEN */ case 9: /* CYAN-BLUE */ case 10: /* MAGENTA-BLUE */ case 11: /* MAGENTA-RED */ case 12: /* ORANGE */ case 21: /* ORANGE-YELLOW */ case 22: /* ORANGE-RED */ case 23: /* SKIN */ /* Pointer to the color scheme: */ color_schemeSP = color_schemeSA + schemeI; /* Six colors for the outer side of the */ /* surface (3 near colors, 3 far colors): */ memcpy (&configSP->out_left_near_rgbS, color_schemeSP->left_rgbSA, rgb_struct_size); memcpy (&configSP->out_middle_near_rgbS, color_schemeSP->middle_rgbSA, rgb_struct_size); memcpy (&configSP->out_right_near_rgbS, color_schemeSP->right_rgbSA, rgb_struct_size); memcpy (&configSP->out_left_far_rgbS, color_schemeSP->left_rgbSA + 1, rgb_struct_size); memcpy (&configSP->out_middle_far_rgbS, color_schemeSP->middle_rgbSA + 1, rgb_struct_size); memcpy (&configSP->out_right_far_rgbS, color_schemeSP->right_rgbSA + 1, rgb_struct_size); /* Return the positive value after */ /* setting the surface outer color: */ return 1; break; /* If color scheme is not suitable for */ /* surfaces, return negative value: */ default: return -2; } } /*---------------------------------------------------------------------------*/ /* If the mode index is equal to two, initialize default */ /* colors for the inner sides of the molecular surfaces. */ if (modeI == 2) { switch (schemeI) { /* The following color schemes are suitable for surfaces: */ case 0: /* RED */ case 1: /* GREEN */ case 2: /* BLUE */ case 3: /* YELLOW */ case 4: /* CYAN */ case 5: /* MAGENTA */ case 6: /* WHITE */ case 7: /* YELLOW-GREEN */ case 8: /* CYAN-GREEN */ case 9: /* CYAN-BLUE */ case 10: /* MAGENTA-BLUE */ case 11: /* MAGENTA-RED */ case 12: /* ORANGE */ case 21: /* ORANGE-YELLOW */ case 22: /* ORANGE-RED */ case 23: /* SKIN */ /* Pointer to the color scheme: */ color_schemeSP = color_schemeSA + schemeI; /* Six colors for the inner side of the */ /* surface (3 near colors, 3 far colors): */ memcpy (&configSP->in_left_near_rgbS, color_schemeSP->left_rgbSA, rgb_struct_size); memcpy (&configSP->in_middle_near_rgbS, color_schemeSP->middle_rgbSA, rgb_struct_size); memcpy (&configSP->in_right_near_rgbS, color_schemeSP->right_rgbSA, rgb_struct_size); memcpy (&configSP->in_left_far_rgbS, color_schemeSP->left_rgbSA + 1, rgb_struct_size); memcpy (&configSP->in_middle_far_rgbS, color_schemeSP->middle_rgbSA + 1, rgb_struct_size); memcpy (&configSP->in_right_far_rgbS, color_schemeSP->right_rgbSA + 1, rgb_struct_size); /* Return the positive value after */ /* setting the surface inner color: */ return 2; break; /* If color scheme is not suitable for */ /* surfaces, return negative value: */ default: return -3; } } /*---------------------------------------------------------------------------*/ /* If this point is reached, the mode index is zero; assign colors to atoms! */ /*......CPK:.................................................................*/ if (schemeI == 16) { return CPK_ (mol_complexSP, mol_complexesN, guiSP, color_schemeSA); } /*......ZEBRA:...............................................................*/ else if (schemeI == 17) { return Zebra_ (mol_complexSP, mol_complexesN, guiSP, color_schemeSA); } /*......CHAIN:...............................................................*/ else if (schemeI == 18) { return Chain_ (mol_complexSP, mol_complexesN, guiSP, color_schemeSA); } /*......HYPHOB:..............................................................*/ else if (schemeI == 19) { return ColorHyphob_ (mol_complexSP, mol_complexesN, guiSP, color_schemeSA); } /*......MODEL:...............................................................*/ else if (schemeI == 20) { return ColorModel_ (mol_complexSP, mol_complexesN, guiSP, color_schemeSA); } /*......SIZE:...............................................................*/ else if (schemeI == 24) { return ColorSize_ (mol_complexSP, mol_complexesN, guiSP, color_schemeSA); } /*......WEIGHTED:............................................................*/ else if (schemeI == 25) { return ColorWeighted_ (mol_complexSP, mol_complexesN, guiSP, color_schemeSA); } /*......other schemes:.......................................................*/ /* The number of color surfaces: */ surfacesN = color_schemeSA[schemeI].surfacesN; /* Pointer to the color scheme: */ color_schemeSP = color_schemeSA + schemeI; /* Scan every macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check is the current macromolecular complex caught: */ if (curr_mol_complexSP->catchF == 0) continue; /* Number of atoms in a macromolecular complex: */ atomsN = curr_mol_complexSP->atomsN; /* Scan all atoms in the current complex: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Check is atom selected: */ if (curr_atomSP->selectedF == 0) continue; /* Set the number of color surfaces: */ curr_atomSP->surfacesN = surfacesN; /* Copy the color specifications: */ for (surfaceI = 0; surfaceI < surfacesN; surfaceI++) { /* Left color: */ memcpy (curr_atomSP->left_rgbSA + surfaceI, color_schemeSP->left_rgbSA + surfaceI, rgb_struct_size); /* Middle color: */ memcpy (curr_atomSP->middle_rgbSA + surfaceI, color_schemeSP->middle_rgbSA + surfaceI, rgb_struct_size); /* Right color: */ memcpy (curr_atomSP->right_rgbSA + surfaceI, color_schemeSP->right_rgbSA + surfaceI, rgb_struct_size); } } /* Reset the position_changedF: */ curr_mol_complexSP->position_changedF = 1; } /*---------------------------------------------------------------------------*/ /* Return positive value on success: */ return 5; } /*===========================================================================*/ garlic-1.6/test.script0000644000076500007650000000011107642000744015310 0ustar zuciczucic00000000000000sel het hide sel com bac 2 color cold sel phe,trp,tyr color yellow show garlic-1.6/color_hyphob.c0000644000076500007650000000771407762724720015770 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2003 Damir Zucic */ /*============================================================================= color_hyphob.c Purpose: Hyphob color scheme: colors are assigned according to hydrophobicity. Residues with hydrophobicity close to threshold value will be white, hydrophobic residues will be red and hydrophilic residues will be blue. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. (3) Pointer to GUIS structure, with GUI data. (4) Pointer to ColorSchemeS structure. Output: (1) Return value. Return value: (1) Positive always. =============================================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int MixColors_ (AtomS *, ColorSchemeS *, ColorSchemeS *, double, GUIS *); /*======hyphob color scheme:=================================================*/ int ColorHyphob_ (MolComplexS *mol_complexSP, int mol_complexesN, GUIS *guiSP, ColorSchemeS *color_schemeSP) { size_t rgb_struct_size; ColorSchemeS *blue_schemeSP, *white_schemeSP, *red_schemeSP; int mol_complexI; MolComplexS *curr_mol_complexSP; size_t atomsN, atomI; AtomS *curr_atomSP; double min_hyphob, threshold_hyphob, max_hyphob; double delta_hyphob1, delta_hyphob2; double inverse_range1, inverse_range2; double hyphob; double scale_factor; /* The size of RGBS structure: */ rgb_struct_size = sizeof (RGBS); /* Red scheme pointer: */ red_schemeSP = color_schemeSP + 0; /* White scheme pointer: */ white_schemeSP = color_schemeSP + 6; /* Blue scheme pointer: */ blue_schemeSP = color_schemeSP + 2; /* Scan every macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check is the current macromolecular complex caught: */ if (curr_mol_complexSP->catchF == 0) continue; /* Minimal, maximal and threshold hydrophob. for current complex: */ min_hyphob = (double) curr_mol_complexSP->min_hydrophobicity; max_hyphob = (double) curr_mol_complexSP->max_hydrophobicity; threshold_hyphob = (double) curr_mol_complexSP->threshold_hydrophobicity; /* Inverse hydrophobicity ranges: */ delta_hyphob1 = max_hyphob - threshold_hyphob; if (delta_hyphob1 != 0.0) inverse_range1 = 1.0 / delta_hyphob1; else inverse_range1 = 0.0; delta_hyphob2 = threshold_hyphob - min_hyphob; if (delta_hyphob2 != 0.0) inverse_range2 = 1.0 / delta_hyphob2; else inverse_range2 = 0.0; /* Number of atoms in a macromolecular complex: */ atomsN = curr_mol_complexSP->atomsN; /* Scan all atoms in the current complex: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Check is atom selected: */ if (curr_atomSP->selectedF == 0) continue; /* Set the number of color surfaces: */ curr_atomSP->surfacesN = 2; /* Hydrophobicity of the current atom: */ hyphob = (double) curr_atomSP->raw_atomS.hydrophobicity; /* If hydrophobicity is below threshold value: */ if (hyphob <= threshold_hyphob) { scale_factor = (threshold_hyphob - hyphob) * inverse_range2; MixColors_ (curr_atomSP, white_schemeSP, blue_schemeSP, scale_factor, guiSP); } /* If hydrophobicity is above threshold value: */ else { scale_factor = (hyphob - threshold_hyphob) * inverse_range1; MixColors_ (curr_atomSP, white_schemeSP, red_schemeSP, scale_factor, guiSP); } } /* Reset the position_changedF: */ curr_mol_complexSP->position_changedF = 1; } /* Return positive value: */ return 1; } /*===========================================================================*/ garlic-1.6/create_log_file.c0000644000076500007650000000401110000274230016336 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2004 Damir Zucic */ /*============================================================================= create_log_file.c Purpose: Try to create a new log file, opened for writting. First try to create log file in the current working directory. If this attempt fails, try to create the log file in the users home directory. Input: (1) Input file name. (2) The content of environment variable HOME may be used. Output: Return value. Return value: (1) File pointer, on success. (2) NULL on failure. Notes: (1) No error messages. ========includes:============================================================*/ #include #include #include #include "defines.h" /*======try to create log file:==============================================*/ FILE *CreateLogFile_ (char *log_file_nameP) { static FILE *fileP; static char *env_valueP; char path_nameA[STRINGSIZE]; int n; /* The first attempt: */ if ((fileP = fopen (log_file_nameP, "w")) != NULL) return fileP; /* If this point is reached, the first attempt failed! */ /* Prepare the file name pointer. If the first character is slash, skip it! */ if (*log_file_nameP == '/') log_file_nameP++; /* The second attempt (using environment variable HOME): */ if ((env_valueP = getenv ("HOME")) != NULL) { /* Copy the value of the environment variable HOME: */ strncpy (path_nameA, env_valueP, STRINGSIZE - 1); path_nameA[STRINGSIZE - 1] = '\0'; /* The last character should be slash: */ n = (int) strlen (path_nameA) - 1; if (path_nameA[n] != '/') strcat (path_nameA, "/"); /* Concatename the file name to directory name: */ n = STRINGSIZE - (int) strlen (path_nameA) - 1; strncat (path_nameA, log_file_nameP, n); path_nameA[STRINGSIZE - 1] = '\0'; /* The second attempt to open file: */ if ((fileP = fopen (path_nameA, "w")) != NULL) return fileP; } /* If this point is reached, both attempts failed; return NULL: */ return NULL; } /*===========================================================================*/ garlic-1.6/hybonds.c0000644000076500007650000001200007540351253014716 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2002 Damir Zucic */ /*============================================================================= hybonds.c Purpose: Execute hybonds command. Generate and show (or hide) hydrogen bonds. If hydrogen bonds were generated before, check is it necessary to refresh the information about hydrogen bonds. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) The number of macromolecular complexes. (3) Pointer to RuntimeS structure, with some runtime data. (4) Pointer to ConfigS structure, with configuration data. (5) Pointer to GUIS structure, with GUI data. (6) Pointer to NearestAtomS structure. (7) The number of pixels in the main window free area. (8) Pointer to refreshI. (9) Pointer to the remainder of the command string. It is either empty or contains the keyword OFF. Output: (1) Hydrogen bonds should be either visible or hidden. (2) Return value. Return value: (1) Positive (command) code on success. (2) Negative (error) code on failure. Notes: (1) Nice style is not available for hydrogen bonds. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "commands.h" #include "typedefs.h" /*======function prototypes:=================================================*/ char *ExtractToken_ (char *, int, char *, char *); void InformUser_ (GUIS *, char *); unsigned long GenerateHyBonds_ (MolComplexS *, int, ConfigS *, int); size_t MainRefresh_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); int ControlRefresh_ (MolComplexS *, ConfigS *, GUIS *); /*======execute hybonds command:=============================================*/ int HydrogenBonds_ (MolComplexS *mol_complexSP, int mol_complexesN, RuntimeS *runtimeSP, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int *refreshIP, char *stringP) { char *remainderP; char tokenA[STRINGSIZE]; int styleI; int mol_complexI; MolComplexS *curr_mol_complexSP; long l; /* Initialize the styleI: */ styleI = 1; /* Extract the first token: */ remainderP = ExtractToken_ (tokenA, STRINGSIZE, stringP, " \t\n"); /* If available, the first token should contain the bond drawing style: */ if (remainderP) { /** Extract the bond drawing style: **/ if (strstr (tokenA, "OFF") == tokenA) styleI = -1; else if (strcmp (tokenA, "0") == 0) styleI = 0; else if (strcmp (tokenA, "1") == 0) styleI = 1; else if (strcmp (tokenA, "2") == 0) styleI = 2; else if (strcmp (tokenA, "3") == 0) styleI = 3; else if (strcmp (tokenA, "4") == 0) styleI = 4; else if (strcmp (tokenA, "5") == 0) styleI = 5; else { sprintf (runtimeSP->messageA, "Hydrogen bond drawing style \"%s\" not available!", tokenA); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_HYBONDS; } } /* If the first token was keyword OFF: */ if (styleI == -1) { /** Hide hydrogen bonds in every caught complex: **/ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /*** Pointer to the current macromolecular complex: ***/ curr_mol_complexSP = mol_complexSP + mol_complexI; /*** Check is the current macromol. complex caught: ***/ if (curr_mol_complexSP->catchF == 0) continue; /*** Hide hydrogen bonds: ***/ curr_mol_complexSP->hydrogen_bonds_hiddenF = 1; } /** Refresh the main window: **/ (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); /** Refresh the control window: **/ ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); /** Return to caller: **/ return COMMAND_HYBONDS; } /* If this point is reached, make hydrogen bonds visible: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /** Pointer to the current macromolecular complex: **/ curr_mol_complexSP = mol_complexSP + mol_complexI; /** Check is the current macromol. complex caught: **/ if (curr_mol_complexSP->catchF == 0) continue; /** Make hydrogen bonds visible (unhide): **/ curr_mol_complexSP->hydrogen_bonds_hiddenF = 0; } /* Inform user that this function may take some time to execute: */ InformUser_ (guiSP, "This may take some time, please be patient!"); /* Generate hydrogen bonds, or just update the bond drawing style: */ l = GenerateHyBonds_ (mol_complexSP, mol_complexesN, configSP, styleI); /* Refresh the main window: */ (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); /* Refresh the control window: */ ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); /* Return positive value on success: */ return COMMAND_HYBONDS; } /*===========================================================================*/ garlic-1.6/print_version.c0000644000076500007650000000235610364506523016166 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2006 Damir Zucic */ /*============================================================================= print_version.c Purpose: Print version information. Input: No input. Output: Version info printed to stdout. Return value: No return value. ========includes:============================================================*/ #include /*======print version info:==================================================*/ void PrintVersion_ (void) { fprintf (stdout, "\n"); fprintf (stdout, "==================================\n"); fprintf (stdout, "garlic version 1.6\n"); fprintf (stdout, "Release date: 2006/X/X\n"); fprintf (stdout, "==================================\n"); fprintf (stdout, "\n"); fprintf (stdout, "Compliant with PDB version 2.1"); fprintf (stdout, " (draft, October 25, 1996).\n"); fprintf (stdout, "Copyright (C) 2000-2006 Damir Zucic (zucic@garlic.mefos.hr).\n"); fprintf (stdout, "Source code, documentation and binaries:\n"); fprintf (stdout, "\n=====================================\n"); fprintf (stdout, " http://garlic.mefos.hr/garlic-1.6\n"); fprintf (stdout, "=====================================\n\n"); } /*===========================================================================*/ garlic-1.6/hide.c0000644000076500007650000000610007076564025014174 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= hide.c Purpose: Execute hide command: hide the selected atoms, i.e. set hiddenF to one for selected atoms. Only the caught complexes are treated. For atoms which are not selected visibility status is not changed. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) The number of macromolecular complexes. (3) Pointer to RuntimeS structure, with some runtime data. (4) Pointer to ConfigS structure, with configuration data. (5) Pointer to GUIS structure, with GUI data. (6) Pointer to NearestAtomS structure. (7) The number of pixels in the main window free area. (8) Pointer to refreshI. Output: (1) The hiddenF set for each atom in each caught complex. (2) Return value. Return value: (1) The command code. ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "commands.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int HideBackbone_ (MolComplexS *, int); size_t MainRefresh_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); int ControlRefresh_ (MolComplexS *, ConfigS *, GUIS *); /*======execute hide command:================================================*/ int Hide_ (MolComplexS *mol_complexSP, int mol_complexesN, RuntimeS *runtimeSP, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int *refreshIP) { int mol_complexI; MolComplexS *curr_mol_complexSP; size_t atomsN, atomI; AtomS *curr_atomSP; /* Check every macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /** Pointer to the current macromolecular complex: **/ curr_mol_complexSP = mol_complexSP + mol_complexI; /** Check is the current macromolecular complex caught: **/ if (curr_mol_complexSP->catchF == 0) continue; /** Number of atoms in a macromolecular complex: **/ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /** Scan all atoms in the current complex: **/ for (atomI = 0; atomI < atomsN; atomI++) { /** Pointer to the current atom: **/ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /** Check the selection flag; hide selected atoms: **/ if (curr_atomSP->selectedF) curr_atomSP->hiddenF = 1; } } /* Hide backbone (update hiddenF for each selected CA atom): */ HideBackbone_ (mol_complexSP, mol_complexesN); /* Refresh the main window: */ (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); /* Refresh the control window: */ ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); /* Return the command code: */ return COMMAND_HIDE; } /*===========================================================================*/ garlic-1.6/flip_vector.c0000644000076500007650000000172707373234014015601 0ustar zuciczucic00000000000000/* Copyright (C) 2000, 2001 Damir Zucic */ /*============================================================================= flip_vector.c Purpose: Copy vector multiplied by -1. Input: (1) Pointer to VectorS structure, where output vector will be stored. (2) Pointer to VectorS structure, with input vector. Output: (1) Output vector (equal to -1 * input_vector) prepared. Return value: No return value. ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======flip vector (multiply by -1):========================================*/ void FlipVector_ (VectorS *out_vectorS, VectorS *in_vectorS) { out_vectorS->x = - in_vectorS->x; out_vectorS->y = - in_vectorS->y; out_vectorS->z = - in_vectorS->z; } /*===========================================================================*/ garlic-1.6/prepare_color.c0000644000076500007650000000350307065474335016125 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= prepare_color.c Purpose: Prepare the color by mixing two colors, using the proper weighting. Input: (1) Pointer to RGBS structure, with the first color. (2) Pointer to RGBS structure, with the second color. (3) Scale factor (double). (4) Pointer to GUIS structure. Output: (1) Return value. Return value: The pixel value for the new color. =============================================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ unsigned long PixelFromRGBS_ (RGBS *, GUIS *); /*======mix two colors:======================================================*/ unsigned long PrepareColor_ (RGBS *rgb1SP, RGBS *rgb2SP, double scale_factor, GUIS *guiSP) { unsigned long colorID; double color1, delta_color, color; RGBS rgbS; /* Red: */ color1 = (double) rgb1SP->red; delta_color = (double) rgb2SP->red - (double) rgb1SP->red; color = color1 + scale_factor * delta_color; rgbS.red = (unsigned short) color; /* Green: */ color1 = (double) rgb1SP->green; delta_color = (double) rgb2SP->green - (double) rgb1SP->green; color = color1 + scale_factor * delta_color; rgbS.green = (unsigned short) color; /* Blue: */ color1 = (double) rgb1SP->blue; delta_color = (double) rgb2SP->blue - (double) rgb1SP->blue; color = color1 + scale_factor * delta_color; rgbS.blue = (unsigned short) color; /* Pixel value: */ colorID = PixelFromRGBS_ (&rgbS, guiSP); /* Return the pixel value: */ return colorID; } /*===========================================================================*/ garlic-1.6/control.xpm0000644000076500007650000015071107303426266015332 0ustar zuciczucic00000000000000/* XPM */ static char *control_xpm[] = { /* width height num_colors chars_per_pixel */ " 131 396 8 1", /* colors */ ". c black", "# c blue", "a c DarkSlateGray", "b c DarkRed", "c c gray", "d c red", "e c yellow", "f c white", /* pixels */ "...................................................................................................................................", ".ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa.", ".fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffaa.", ".ffcccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccaa.", ".ffcccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccaa.", ".ffcccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccaa.", ".ffcccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccaa.", ".ffccccccccccccc..ccc..c..ccc..c...ccc...c......c......cc..cc.....cccccccc..cc..c......c..cc..c......ccc...ccc......ccccccccccccaa.", ".ffccccccccccccc..ccc..c..ccc..c...ccc...c..ccccc..ccc..c..c..ccc..ccccccc..c..cc..ccccc..cc..c..ccc..cc...ccc..ccc..cccccccccccaa.", ".ffccccccccccccc...cc..c..ccc..c....c....c..ccccc..ccc..c..c..cccccccccccc....ccc..ccccc......c..ccc..c..c..cc..ccc..cccccccccccaa.", ".ffccccccccccccc....c..c..ccc..c....c....c.....cc......cc..c..cccccccccccc...cccc.....ccc....cc......cc..c..cc..ccc..cccccccccccaa.", ".ffccccccccccccc..c....c..ccc..c..c...c..c..ccccc..ccc..c..c..cccccccccccc....ccc..ccccccc..ccc..cccccc.....cc..ccc..cccccccccccaa.", ".ffccccccccccccc..cc...c..ccc..c..c...c..c..ccccc..ccc..c..c..ccc..ccccccc..c..cc..ccccccc..ccc..ccccc..ccc..c..ccc..cccccccccccaa.", ".ffccccccccccccc..ccc..cc.....cc..ccccc..c......c..ccc..c..cc.....cccccccc..cc..c......ccc..ccc..ccccc..ccc..c......ccccccccccccaa.", ".ffcccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccaa.", ".ffcccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccaa.", ".ffcccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccaa.", ".ffaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.", ".ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa.", ".ffcccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccaa.", ".ffccccccccccccccccccccccccccccccccccccccccccccccccccccccccc..ccccccccccccccccccccccccccccc..cccccccccccccccccccccccccccccccccccaa.", ".ffccccccccccccc......c.....cccc..ccc...c..cc...ccccccccccc..cc.....ccc....c......cccccccc..cc...cc..ccccc..ccc.....ccccccccccccaa.", ".ffccccccccccccccc..ccc..cc..ccc..ccc...c..c..c..ccccccccc..ccc..cc..c..cc..cc..ccccccccc..cc..c..c..ccccc..ccc..cc..cccccccccccaa.", ".ffccccccccccccccc..ccc..cc..cc....cc......cc..cccccccccc..cccc..cc..c..cc..cc..cccccccc..cccc..ccc..cccc....cc.....ccccccccccccaa.", ".ffccccccccccccccc..ccc.....ccc....cc......ccc..cccccccc..ccccc.....cc..cc..cc..ccccccc..cccccc..cc..cccc....cc..cc..cccccccccccaa.", ".ffccccccccccccccc..ccc..cc..c..cc..c..c...c..c..c..ccc..cccccc..cc..c..cc..cc..c..ccc..ccccc..c..c..ccc..cc..c..cc..cccccccccccaa.", ".ffccccccccccccccc..ccc..cc..c..cc..c..c...cc...cc..cc..ccccccc..cc..cc....ccc..c..cc..ccccccc...cc....c..cc..c.....ccccccccccccaa.", ".ffcccccccccccccccccccccccccccccccccccccccccccccccccc..ccccccccccccccccccccccccccccc..ccccccccccccccccccccccccccccccccccccccccccaa.", ".ffcccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccaa.", ".ffaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.", ".faaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.", "...................................................................................................................................", ".ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd.", ".d...............................d...............................d...............................d...............................d.", ".d.cfcfcfcfcfcfcfcfcfcfcfcfcfcfc.d.cfcfcfcfcfcfcfcfcfcfcfcfcfcfc.d.cfcfcfcfcfcfcfcfcfcfcfcfcfcfc.d.cfcfcfcfcfcfcfcfcfcfcfcfcfcfc.d.", ".d.fcfcfcfcfcfcfcfcfcfcfcfcfcfca.d.fcfcfcfcfcfcfcfcfcfcfcfcfcfca.d.fcfcfcfcfcfcfcfcfcfcfcfcfcfca.d.fcfcfcfcfcfcfcfcfcfcfcfcfcfca.d.", ".d.cfcfc...................cfcaa.d.cfcfc...................cfcaa.d.cfcfc...................cfcaa.d.cfcfc...................cfcaa.d.", ".d.fcfc.ccccccccccccccccccc.caaa.d.fcfc.ccccccccccccccccccc.caaa.d.fcfc.ccccccccccccccccccc.caaa.d.fcfc.ccccccccccccccccccc.caaa.d.", ".d.cfc.ccccccccccccccccccccc.aaa.d.cfc.ccccccccccccccccccccc.aaa.d.cfc.ccccccccccccccccccccc.aaa.d.cfc.ccccccccccccccccccccc.aaa.d.", ".d.fc.ccccccccccccccccccccccc.aa.d.fc.ccccccccccccccccccccccc.aa.d.fc.ccccccccccccccccccccccc.aa.d.fc.ccccccccccccccccccccccc.aa.d.", ".d.cf.ccccccccccccccccccccccc.aa.d.cf.cccccccccf.cccccccccccc.aa.d.cf.ccccccccccccf.ccccccccc.aa.d.cf.cccccccccccfccccccccccc.aa.d.", ".d.fc.ccccccccccccccccccccccc.aa.d.fc.ccccccccf#.cccccccccccc.aa.d.fc.ccccccccccccf#.cccccccc.aa.d.fc.ccccccccccf#.cccccccccc.aa.d.", ".d.cf.ccccccccccccccccccccccc.aa.d.cf.cccccccf##.cccccccccccc.aa.d.cf.ccccccccccccf##.ccccccc.aa.d.cf.cccccccccf###.ccccccccc.aa.d.", ".d.fc.ccccccccccccccccccccccc.aa.d.fc.ccccccf###.cccccccccccc.aa.d.fc.ccccccccccccf###.cccccc.aa.d.fc.ccccccccf#####.cccccccc.aa.d.", ".d.cf.c..cc..cccccccccccccccc.aa.d.cf.cccccf####fffffffff.ccc.aa.d.cf.cccffffffffff####.ccccc.aa.d.cf.cccccccf#######.ccccccc.aa.d.", ".d.fc.c..cc..cccccccccccccccc.aa.d.fc.ccccf##############.ccc.aa.d.fc.cccf##############.cccc.aa.d.fc.ccccccf#########.cccccc.aa.d.", ".d.cf.c...c..c..c..c.......cc.aa.d.cf.cccf###############.ccc.aa.d.cf.cccf###############.ccc.aa.d.cf.cccccf###########.ccccc.aa.d.", ".d.fc.c......c..c..c..c..c..c.aa.d.fc.ccf################.ccc.aa.d.fc.cccf################.cc.aa.d.fc.ccccf#############.cccc.aa.d.", ".d.cf.c..c...c..c..c..c..c..c.aa.d.cf.ccc.###############.ccc.aa.d.cf.cccf###############.ccc.aa.d.cf.cccc.....#####.....cccc.aa.d.", ".d.fc.c..cc..c..c..c..c..c..c.aa.d.fc.cccc.##############.ccc.aa.d.fc.cccf##############.cccc.aa.d.fc.ccccccccf#####.cccccccc.aa.d.", ".d.cf.c..cc..cc....c..c..c..c.aa.d.cf.ccccc.####..........ccc.aa.d.cf.cccf.........####.ccccc.aa.d.cf.ccccccccf#####.cccccccc.aa.d.", ".d.fc.ccccccccccccccccccccccc.aa.d.fc.cccccc.###.cccccccccccc.aa.d.fc.ccccccccccccf###.cccccc.aa.d.fc.ccccccccf#####.cccccccc.aa.d.", ".d.cf.ccccccccccccccccccccccc.aa.d.cf.ccccccc.##.cccccccccccc.aa.d.cf.ccccccccccccf##.ccccccc.aa.d.cf.ccccccccf#####.cccccccc.aa.d.", ".d.fc.ccccccccccccccccccccccc.aa.d.fc.cccccccc.#.cccccccccccc.aa.d.fc.ccccccccccccf#.cccccccc.aa.d.fc.ccccccccf#####.cccccccc.aa.d.", ".d.cf.ccccccccccccccccccccccc.aa.d.cf.ccccccccc..cccccccccccc.aa.d.cf.ccccccccccccf.ccccccccc.aa.d.cf.ccccccccf......cccccccc.aa.d.", ".d.fc.ccccccccccccccccccccccc.aa.d.fc.ccccccccccccccccccccccc.aa.d.fc.ccccccccccccccccccccccc.aa.d.fc.ccccccccccccccccccccccc.aa.d.", ".d.cfc.ccccccccccccccccccccc.aaa.d.cfc.ccccccccccccccccccccc.aaa.d.cfc.ccccccccccccccccccccc.aaa.d.cfc.ccccccccccccccccccccc.aaa.d.", ".d.fcac.ccccccccccccccccccc.aaaa.d.fcac.ccccccccccccccccccc.aaaa.d.fcac.ccccccccccccccccccc.aaaa.d.fcac.ccccccccccccccccccc.aaaa.d.", ".d.cacaa...................aaaaa.d.cacaa...................aaaaa.d.cacaa...................aaaaa.d.cacaa...................aaaaa.d.", ".d.acaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.acaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.acaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.acaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.", ".d.caaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.caaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.caaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.caaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.", ".d.aaaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.aaaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.aaaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.aaaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.", ".d.aaaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.aaaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.aaaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.aaaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.", ".d...............................d...............................d...............................d...............................d.", ".ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd.", ".d...............................d...............................d...............................d...............................d.", ".d.cfcfcfcfcfcfcfcfcfcfcfcfcfcfc.d.cfcfcfcfcfcfcfcfcfcfcfcfcfcfc.d.cfcfcfcfcfcfcfcfcfcfcfcfcfcfc.d.cfcfcfcfcfcfcfcfcfcfcfcfcfcfc.d.", ".d.fcfcfcfcfcfcfcfcfcfcfcfcfcfca.d.fcfcfcfcfcfcfcfcfcfcfcfcfcfca.d.fcfcfcfcfcfcfcfcfcfcfcfcfcfca.d.fcfcfcfcfcfcfcfcfcfcfcfcfcfca.d.", ".d.cfcfc...................cfcaa.d.cfcfc...................cfcaa.d.cfcfc...................cfcaa.d.cfcfc...................cfcaa.d.", ".d.fcfc.ccccccccccccccccccc.caaa.d.fcfc.ccccccccccccccccccc.caaa.d.fcfc.ccccccccccccccccccc.caaa.d.fcfc.ccccccccccccccccccc.caaa.d.", ".d.cfc.ccccccccccccccccccccc.aaa.d.cfc.ccccccccccccfcccccccc.aaa.d.cfc.ccccccccccccccccccccc.aaa.d.cfc.ccccccccccccccccccccc.aaa.d.", ".d.fc.ccccccccc.......ccccccc.aa.d.fc.ccccccccccccf#.cccccccc.aa.d.fc.cccccccc........ccccccc.aa.d.fc.ccccccccccccccccccccccc.aa.d.", ".d.cf.cc...ccc.##..c.b..ccccc.aa.d.cf.cccccccccccf###.ccccccc.aa.d.cf.c...ccc.##.cc.b..cccccc.aa.d.cf.ccccccccccccccccccccccc.aa.d.", ".d.fc.cc.ee.c.##.cccc.bb.cccc.aa.d.fc.ccccccccccf#####.cccccc.aa.d.fc.c.ee...##.cccc.bb.ccccc.aa.d.fc.ccccccccccccccccccccccc.aa.d.", ".d.cf.ccc.ee.###.ccccc.b.cccc.aa.d.cf.ccf.....cf#######.ccccc.aa.d.cf.cc.ee.###.ccccc.b.ccccc.aa.d.cf.ccccccccccccccccccccccc.aa.d.", ".d.fc.cccc..###.cccccc.bb.ccc.aa.d.fc.ccfbbbb.f#########.cccc.aa.d.fc.ccc..###..ccccc.bb.cccc.aa.d.fc.ccccccccccccccccccccccc.aa.d.", ".d.cf.ccccc.###..cccccc.b.ccc.aa.d.cf.ccfbbbbf###########.ccc.aa.d.cf.cccc.##.ee..cccc.b.cccc.aa.d.cf.ccccccccccccccccccccccc.aa.d.", ".d.fc.cccc.###.ee..cccc.bb.cc.aa.d.fc.ccfbbbf#############.cc.aa.d.fc.ccc.###.eeee..cc.bb.ccc.aa.d.fc.ccccccccccccccccccccccc.aa.d.", ".d.cf.cccc.###.eee...cc.bb.cc.aa.d.cf.ccfbbbfffff#####.....cc.aa.d.cf.ccc.###..eeee....bb.ccc.aa.d.cf.ccccccccccccccccccccccc.aa.d.", ".d.fc.cccc.###.ee..e..c.bb.cc.aa.d.fc.ccfbbbb.ccf#####.cccccc.aa.d.fc.ccc.###.c.ee..e..bb.ccc.aa.d.fc.ccccccccccccccccccccccc.aa.d.", ".d.cf.c....###..e.eee.c.bb.cc.aa.d.cf.cc........f#####.....cc.aa.d.cf.ccc.###.cc.e.eee.bb.ccc.aa.d.cf.ccccccccccccccccccccccc.aa.d.", ".d.fc.cc.#.###.c..eee.c.bb.cc.aa.d.fc.c.e.eeeeeef#####.eeee.c.aa.d.fc.ccc.###.ccc..eee.bb.ccc.aa.d.fc.ccccccccccccccccccccccc.aa.d.", ".d.cf.cc.#####.cc..e..c.bb.cc.aa.d.cf.c.e.eeeeeef#####.eeee.c.aa.d.cf.ccc.###.cccc..e..bb...c.aa.d.cf.ccccccccccccccccccccccc.aa.d.", ".d.fc.ccc.####..cc...c.bbb.cc.aa.d.fc.cc........f#####.....cc.aa.d.fc.ccc.###.ccccc...bbbbb.c.aa.d.fc.ccccccccccccccccccccccc.aa.d.", ".d.cf.ccc.######..cccc.bb..cc.aa.d.cf.ccfbbbb.cf#####.ccccccc.aa.d.cf.ccc.####.ccccccc.bb..cc.aa.d.cf.ccccccccccccccccccccccc.aa.d.", ".d.fc.cccc.######..ccc..b.ccc.aa.d.fc.cccfbbbb.f#####.ccccccc.aa.d.fc.cccc.###.ccccccc.b.cccc.aa.d.fc.ccccccccfffffffcccccccc.aa.d.", ".d.cf.cccc.####..ccccccc..ccc.aa.d.cf.cccfbbbbf#####.cccccccc.aa.d.cf.cccc...##.ccccccc.ccccc.aa.d.cf.ccccccccf#####.cccccccc.aa.d.", ".d.fc.ccccc.#..cccccccccccccc.aa.d.fc.ccccffff#####.ccccccccc.aa.d.fc.ccccccc...ccccccccccccc.aa.d.fc.ccccccccf#####.cccccccc.aa.d.", ".d.cfc.cccc..ccccccccccccccc.aaa.d.cfc.ccccccccccccccccccccc.aaa.d.cfc.ccccccccccccccccccccc.aaa.d.cf.ccccccccf#####.cccccccc.aa.d.", ".d.fcac.ccccccccccccccccccc.aaaa.d.fcac.ccccccccccccccccccc.aaaa.d.fcac.ccccccccccccccccccc.aaaa.d.fc.ccccccccf#####.cccccccc.aa.d.", ".d.cacaa...................aaaaa.d.cacaa...................aaaaa.d.cacaa...................aaaaa.d.cf.ccccccccf#####.cccccccc.aa.d.", ".d.acaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.acaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.acaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.fc.ccccccccf#####.cccccccc.aa.d.", ".d.caaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.caaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.caaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.cf.ccccccccf#####.cccccccc.aa.d.", ".d.aaaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.aaaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.aaaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.fc.ccccccccf#####.cccccccc.aa.d.", ".d.aaaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.aaaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.aaaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.cf.ccccccccf#####.cccccccc.aa.d.", ".d...............................d...............................d...............................d.ff.ccccccccf#####.cccccccc.aa.d.", ".ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd.fc.ccccccccf#####.cccccccc.aa.d.", ".d...............................d...............................d...............................d.cf.ccccccccf#####.cccccccc.aa.d.", ".d.cfcfcfcfcfcfcfcfcfcfcfcfcfcfc.d.cfcfcfcfcfcfcfcfcfcfcfcfcfcfc.d.afcfcfcfcfcfcfcfcfcfcfcfcfcfc.d.fc.ccccfffff#####.ffffcccc.aa.d.", ".d.fcfcfcfcfcfcfcfcfcfcfcfcfcfca.d.fcfcfcfcfcfcfcfcfcfcfcfcfcfca.d.fcfcfcfcfcfcfcfcfcfcfcfcfcfca.d.cf.cccc.#############.cccc.aa.d.", ".d.cfcfc...................cfcaa.d.cfcfc...................cfcaa.d.cfcfc...................cfcaa.d.fc.ccccc.###########.ccccc.aa.d.", ".d.fcfc.ccccccccccccccccccc.caaa.d.fcfc.ccccccccccccccccccc.caaa.d.fcfc.ccccccccccccccccccc.caaa.d.cf.cccccc.#########.cccccc.aa.d.", ".d.cfc.ccccccccccc..cccccccc.aaa.d.cfc.ccccccccccccccccccccc.aaa.d.cfc.cccccccc..ccccccccccc.aaa.d.fc.ccccccc.#######.ccccccc.aa.d.", ".d.fc.cccccffffff.ee.ffcccccc.aa.d.fc.ccccccccccf..cccccccccc.aa.d.fc.ccccccff.ee.ffffffccccc.aa.d.cf.cccccccc.#####.cccccccc.aa.d.", ".d.cf.ccccc.bbbbb....bbfffccc.aa.d.cf.ccccccccf#####.cccccccc.aa.d.cf.cccfffbb....bbbbb.ccccc.aa.d.fc.ccccccccc.###.ccccccccc.aa.d.", ".d.fc.ccccc.bbbbb.ee.bbbbbfcc.aa.d.fc.ccccccf#########.cccccc.aa.d.fc.ccfbbbbb.ee.bbbbb.ccccc.aa.d.cf.cccccccccc.#.cccccccccc.aa.d.", ".d.cf.ccccc.bbf.b.ee.bbbbbfcc.aa.d.cf.ccccf#############.cccc.aa.d.cf.ccfbbbbb.ee.bf.bb.ccccc.aa.d.fc.ccccccccccc.ccccccccccc.aa.d.", ".d.fc.ccccc.bf#.b.ee.bbbbbfcc.aa.d.fc.ccc......#####......ccc.aa.d.fc.ccfbbbbb.ee.bf#.b.ccccc.aa.d.cf.ccccccccccccccccccccccc.aa.d.", ".d.cf.ccccc.f##...ee..bbff#cc.aa.d.cf.ccccccccf#####.cccccccc.aa.d.cf.cc#ffbb..ee..f##..ccccc.aa.d.fc.ccccccccccccccccccccccc.aa.d.", ".d.fc.cccccf###.c.ee.fff###cc.aa.d.fc.cccccccf#######.ccccccc.aa.d.fc.cc###fff.ee.cf###.ccccc.aa.d.cf.ccccccccccccccccccccccc.aa.d.", ".d.cf.ccccf####ffffff######cc.aa.d.cf.cccccccf#######.ccccccc.aa.d.cf.cc######ffffff####.cccc.aa.d.fc.ccccccccccccccccccccccc.aa.d.", ".d.fc.cccf#################cc.aa.d.fc.ccccccf##f#f##f#.cccccc.aa.d.fc.cc#################.ccc.aa.d.cf.ccccccccccccccccccccccc.aa.d.", ".d.cf.ccf##################cc.aa.d.cf.ccccccf##f#f##f#.cccccc.aa.d.cf.cc##################.cc.aa.d.fc.ccccccccccccccccccccccc.aa.d.", ".d.fc.cf##################.cc.aa.d.fc.cccccf###f#ff#f##.ccccc.aa.d.fc.cc.##################.c.aa.d.cf.ccccccccccccccccccccccc.aa.d.", ".d.cf.cc.###############..ccc.aa.d.cf.cccccf###f#f#ff##.ccccc.aa.d.cf.ccc..###############.cc.aa.d.fc.ccccccccccccccccccccccc.aa.d.", ".d.fc.ccc.###########...ccccc.aa.d.fc.ccccf####f#f##f###.cccc.aa.d.fc.ccccc...###########.ccc.aa.d.cf.ccccccccccccccccccccccc.aa.d.", ".d.cf.cccc.####......cccccccc.aa.d.cf.cccc...............cccc.aa.d.cf.cccccccc......####.cccc.aa.d.fc.ccccccccccccccccccccccc.aa.d.", ".d.fc.ccccc.###.c.ee.cccccccc.aa.d.fc.cccc...............cccc.aa.d.fc.cccccccc.ee.cf###.ccccc.aa.d.cf.ccccccccccccccccccccccc.aa.d.", ".d.cf.cccccc.##.c.ee.cccccccc.aa.d.cf.cccc...............cccc.aa.d.cf.cccccccc.ee.cf##.cccccc.aa.d.fc.ccccccccccccccccccccccc.aa.d.", ".d.fc.ccccccc.#.c.ee.cccccccc.aa.d.fc.ccccccccccccccccccccccc.aa.d.fc.cccccccc.ee.cf#.ccccccc.aa.d.cf.ccccccccccccccccccccccc.aa.d.", ".d.cfc.ccccccc..cc..cccccccc.aaa.d.cfc.ccccccccccccccccccccc.aaa.d.cfc.cccccccc..ccf.ccccccc.aaa.d.fcf.ccccccccccccccccccccc.aaa.d.", ".d.fcac.ccccccccccccccccccc.aaaa.d.fcac.ccccccccccccccccccc.aaaa.d.fcac.ccccccccccccccccccc.aaaa.d.cfac.ccccccccccccccccccc.aaaa.d.", ".d.cacaa...................aaaaa.d.cacaa...................aaaaa.d.cacaa...................aaaaa.d.facaa...................aaaaa.d.", ".d.acaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.acaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.acaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.acaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.", ".d.caaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.caaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.caaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.caaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.", ".d.aaaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.aaaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.aaaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.aaaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.", ".d.aaaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.aaaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.aaaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.aaaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.", ".d...............................d...............................d...............................d...............................d.", ".ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd.", ".d...............................d...............................d...............................d...............................d.", ".d.cfcfcfcfcfcfcfcfcfcfcfcfcfcfc.d.cfcfcfcfcfcfcfcfcfcfcfcfcfcfc.d.cfcfcfcfcfcfcfcfcfcfcfcfcfcfc.d.cfcfcfcfcfcfcfcfcfcfcfcfcfcfc.d.", ".d.fcfcfcfcfcfcfcfcfcfcfcfcfcfca.d.fcfcfcfcfcfcfcfcfcfcfcfcfcfca.d.fcfcfcfcfcfcfcfcfcfcfcfcfcfca.d.fcfcfcfcfcfcfcfcfcfcfcfcfcfca.d.", ".d.cfcfc...................cfcaa.d.cfcfc...................cfcaa.d.cfcfc...................cfcaa.d.cfcfc...................cfcaa.d.", ".d.fcfc.ccccccccccccccccccc.caaa.d.fcfc.ccccccccccccccccccc.caaa.d.fcfc.ccccccccccccccccccc.caaa.d.fcfc.ccccccccccccccccccc.caaa.d.", ".d.cfc.ccccccccccccccccccccc.aaa.d.cfc.ccccccccccccccccccccc.aaa.d.cfc.ccccccccccccccccccccc.aaa.d.cfc.ccccccccccccccccccccc.aaa.d.", ".d.fc.ccccccccccccccccccccccc.aa.d.fc.ccccffff#####.ccccccccc.aa.d.fc.ccccccccccccccccccccccc.aa.d.fc.ccccccccccccccccccccccc.aa.d.", ".d.cf.cccccccccccccc.eddd.ccc.aa.d.cf.cccfbbbbf#####.cccccccc.aa.d.cf.cccccccccccccc.eddd.ccc.aa.d.cf.ccccccccccccccccccccccc.aa.d.", ".d.fc.cccccccccccccc.eddd.ccc.aa.d.fc.cccfbbbb.f#####.ccccccc.aa.d.fc.cccccccccccccc.eddd.ccc.aa.d.fc.ccccccccccccccccccccccc.aa.d.", ".d.cf.ccccccc.cccccc.eddd.ccc.aa.d.cf.ccfbbbb.cf#####.ccccccc.aa.d.cf.cccccccc.ccccc.eddd.ccc.aa.d.cf.ccccccccccccccccccccccc.aa.d.", ".d.fc.cccccc..cccccc.eddd.ccc.aa.d.fc.cc........f#####.....cc.aa.d.fc.cccccccc..cccc.eddd.ccc.aa.d.fc.ccccccccccccccccccccccc.aa.d.", ".d.cf.ccccc.e.cccccc.eddd.ccc.aa.d.cf.c.e.eeeeeef#####.eeee.c.aa.d.cf.cccccccc.e.ccc.eddd.ccc.aa.d.cf.ccccccccccccccccccccccc.aa.d.", ".d.fc.cccc.ee........eddd.ccc.aa.d.fc.c.e.eeeeeef#####.eeee.c.aa.d.fc.cc.......ee.cc.eddd.ccc.aa.d.fc.ccccccccccccccccccccccc.aa.d.", ".d.cf.ccc.eeeeeeeeee.eddd.ccc.aa.d.cf.cc........f#####.....cc.aa.d.cf.cc.eeeeeeeee.c.eddd.ccc.aa.d.cf.ccccccccccccccccccccccc.aa.d.", ".d.fc.cc.eeeeeeeeeee.eddd.ccc.aa.d.fc.ccfbbbb.ccf#####.cccccc.aa.d.fc.cc.eeeeeeeeee..eddd.ccc.aa.d.fc.ccccccccccccccccccccccc.aa.d.", ".d.cf.ccc.eeeeeeeeee.eddd.ccc.aa.d.cf.ccfbbbfffff#####.ffffcc.aa.d.cf.cc.eeeeeeeee.c.eddd.ccc.aa.d.cf.ccccccccccccccccccccccc.aa.d.", ".d.fc.cccc.ee........eddd.ccc.aa.d.fc.ccfbbb.#############.cc.aa.d.fc.cc.......ee.cc.eddd.ccc.aa.d.fc.ccccccccccccccccccccccc.aa.d.", ".d.cf.ccccc.e.cccccc.eddd.ccc.aa.d.cf.ccfbbbb.###########.ccc.aa.d.cf.cccccccc.e.ccc.eddd.ccc.aa.d.cf.ccccccccccccccccccccccc.aa.d.", ".d.fc.cccccc..cccccc.eddd.ccc.aa.d.fc.ccfbbbb..#########.cccc.aa.d.fc.cccccccc..cccc.eddd.ccc.aa.d.fc.ccccccccccccccccccccccc.aa.d.", ".d.cf.ccccccc.cccccc.eddd.ccc.aa.d.cf.ccf.....c.#######.ccccc.aa.d.cf.cccccccc.ccccc.eddd.ccc.aa.d.cf.ccccccccccccccccccccccc.aa.d.", ".d.fc.cccccccccccccc.eddd.ccc.aa.d.fc.cccccccccc.#####.cccccc.aa.d.fc.cccccccccccccc.eddd.ccc.aa.d.fc.ccccccccccccccccccccccc.aa.d.", ".d.cf.cccccccccccccc.eddd.ccc.aa.d.cf.ccccccccccc.###.ccccccc.aa.d.cf.cccccccccccccc.eddd.ccc.aa.d.cf.ccc.ddde.cccccccccccccc.aa.d.", ".d.fc.ccccccccccccccccccccccc.aa.d.fc.cccccccccccc.#.cccccccc.aa.d.fc.ccccccccccccccccccccccc.aa.d.fc.ccc.ddde.cccccccccccccc.aa.d.", ".d.cfc.ccccccccccccccccccccc.aaa.d.cfc.cccccccccccc.cccccccc.aaa.d.cfc.ccccccccccccccccccccc.aaa.d.cf.ccc.ddde.cccccc.ccccccc.aa.d.", ".d.fcac.ccccccccccccccccccc.aaaa.d.fcac.ccccccccccccccccccc.aaaa.d.fcac.ccccccccccccccccccc.aaaa.d.fc.ccc.ddde.cccccc..cccccc.aa.d.", ".d.cacaa...................aaaaa.d.cacaa...................aaaaa.d.cacaa...................aaaaa.d.cf.ccc.ddde.cccccc.e.ccccc.aa.d.", ".d.acaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.acaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.acaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.fc.ccc.ddde........ee.cccc.aa.d.", ".d.caaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.caaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.caaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.cf.ccc.ddde.eeeeeeeeee.ccc.aa.d.", ".d.aaaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.aaaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.aaaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.fc.ccc.ddde.eeeeeeeeeee.cc.aa.d.", ".d.aaaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.aaaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.aaaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.cf.ccc.ddde.eeeeeeeeee.ccc.aa.d.", ".d...............................d...............................d...............................d.fc.ccc.ddde........ee.cccc.aa.d.", ".ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd.fc.ccc.ddde.cccccc.e.ccccc.aa.d.", ".d...............................................................d...............................d.cf.ccc.ddde.cccccc..cccccc.aa.d.", ".d.cfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfc.d.cfcfcfcfcfcfcfcfcfcfcfcfcfcfc.d.fc.ccc.ddde.cccccc.ccccccc.aa.d.", ".d.fcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfca.d.fcfcfcfcfcfcfcfcfcfcfcfcfcfca.d.cf.ccc.ddde.cccccccccccccc.aa.d.", ".d.cfcfc...................................................cfcaa.d.cfcfc...................cfcaa.d.fc.ccc.ddde.cccccccccccccc.aa.d.", ".d.fcfc.ccccccccccccccccccccccccccccccccccccccccccccccccccc.caaa.d.fcfc.ccccccccccccccccccc.caaa.d.cf.ccccccccccccccccccccccc.aa.d.", ".d.cfc.ccccccccccccccccccccccccccccccccccccccccccccccccccccc.aaa.d.cfc.ccccccccccccccccccccc.aaa.d.fc.ccccccccccccccccccccccc.aa.d.", ".d.fc.ccccccccccccccccccccccf#########.cccccccccccccccccccccc.aa.d.fc.ccccccccccccccccccccccc.aa.d.cf.ccccccccccccccccccccccc.aa.d.", ".d.cf.cccccccccccccccccccccf###########.ccccccccccccccccccccc.aa.d.cf.ccc.ddde.cccccccccccccc.aa.d.fc.ccccccccccccccccccccccc.aa.d.", ".d.fc.cccccccccccccccccccccf###########.ccccccccccccccccccccc.aa.d.fc.ccc.ddde.cccccccccccccc.aa.d.cf.ccccccccccccccccccccccc.aa.d.", ".d.cf.ccccccccccccccccccccf#############.cccccccccccccccccccc.aa.d.cf.ccc.ddde.ccccc.cccccccc.aa.d.fc.ccccccccccccccccccccccc.aa.d.", ".d.fc.ccccccccccccccccccccf#############.cccccccccccccccccccc.aa.d.fc.ccc.ddde.cccc..cccccccc.aa.d.cf.ccccccccccccccccccccccc.aa.d.", ".d.cf.cccccccccccccccccccf###############.ccccccccccccccccccc.aa.d.cf.ccc.ddde.ccc.e.cccccccc.aa.d.fc.ccccccccccccccccccccccc.aa.d.", ".d.fc.ccccccccc..###########ff##f##f#fff#.#######..cccccccccc.aa.d.fc.ccc.ddde.cc.ee.......cc.aa.d.cf.ccccccccccccccccccccccc.aa.d.", ".d.cf.ccccccccc.....#######f##f#f##f##f#######.....cccccccccc.aa.d.cf.ccc.ddde.c.eeeeeeeee.cc.aa.d.fc.ccccccccccccccccccccccc.aa.d.", ".d.fc.ccccccccc.......#####f##f#f##f##f#####.......cccccccccc.aa.d.fc.ccc.ddde..eeeeeeeeee.cc.aa.d.cf.ccccccccccccccccccccccc.aa.d.", ".d.cf.ccccccccccc.......###f##f#f##f##f###.......cccccccccccc.aa.d.cf.ccc.ddde.c.eeeeeeeee.cc.aa.d.fc.ccccccccccccccccccccccc.aa.d.", ".d.fc.ccccccccccccc.......##ff###ff###f#.......cccccccccccccc.aa.d.fc.ccc.ddde.cc.ee.......cc.aa.d.cf.ccccccccccccccccccccccc.aa.d.", ".d.cf.ccccccccccccccc.......##########.......cccccccccccccccc.aa.d.cf.ccc.ddde.ccc.e.cccccccc.aa.d.fc.ccccccccccccccccccccccc.aa.d.", ".d.fc.ccccccccccccccccc.......######.......cccccccccccccccccc.aa.d.fc.ccc.ddde.cccc..cccccccc.aa.d.cf.ccccccccccccccccccccccc.aa.d.", ".d.cf.ccccccccccccccccccc................cccccccccccccccccccc.aa.d.cf.ccc.ddde.ccccc.cccccccc.aa.d.fc.ccccccccccccccccccccccc.aa.d.", ".d.fc.ccccccccccccccccccccc............cccccccccccccccccccccc.aa.d.fc.ccc.ddde.cccccccccccccc.aa.d.cf.ccccccccccccccccccccccc.aa.d.", ".d.cf.ccccccccccccccccccccccc........cccccccccccccccccccccccc.aa.d.cf.ccc.ddde.cccccccccccccc.aa.d.fc.ccccccccccccccccccccccc.aa.d.", ".d.fc.ccccccccccccccccccccccccc....cccccccccccccccccccccccccc.aa.d.fc.ccccccccccccccccccccccc.aa.d.cf.ccccccccccccccccccccccc.aa.d.", ".d.cfc.ccccccccccccccccccccccccccccccccccccccccccccccccccccc.aaa.d.cfc.ccccccccccccccccccccc.aaa.d.fcf.ccccccccccccccccccccc.aaa.d.", ".d.fcac.ccccccccccccccccccccccccccccccccccccccccccccccccccc.aaaa.d.fcac.ccccccccccccccccccc.aaaa.d.cfac.ccccccccccccccccccc.aaaa.d.", ".d.cacaa...................................................aaaaa.d.cacaa...................aaaaa.d.facaa...................aaaaa.d.", ".d.acaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.acaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.acaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.", ".d.caaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.caaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.caaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.", ".d.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.aaaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.aaaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.", ".d.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.aaaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.aaaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.", ".d...............................................................d...............................d...............................d.", ".ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd.", ".d...............................................................................................................................d.", ".d.ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa.d.", ".d.fccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccca.d.", ".d.fcccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc..ccccccccccccccccccccccccccccccccccccccccca.d.", ".d.fccc...cc..ccccc...ccc.....cccc....ccc....ccc...cc..c......c..cc....cc..cc..cccc....cccc..cccccc..c..c.....cc......c..c..ccca.d.", ".d.fcc..c..c..ccccc...ccc..cc..ccc..c..c..cc..c..c..c..ccc..ccc..c..cc..c..cc..cccc..c.cccc..cc..cc..c..c..cc..ccc..ccc..c..ccca.d.", ".d.fccc..ccc..cccc..c..cc.....cccc..c..c..cc..cc..ccc..ccc..ccc..c..cc..c...c..ccccc..cc.ccc..c..c..cc..c..cc..ccc..ccc.....ccca.d.", ".d.fcccc..cc..cccc.....cc..cc..ccc....cc..cc..ccc..cc..ccc..ccc..c..cc..c......ccc...c...ccc..c..c..cc..c..cc..ccc..ccc..c..ccca.d.", ".d.fcc..c..c..ccc..ccc..c..cc..ccc..cccc..cc..c..c..c..ccc..ccc..c..cc..c..c...ccc..cc..ccccc......ccc..c..cc..ccc..ccc..c..ccca.d.", ".d.fccc...cc....c..ccc..c.....cccc..ccccc....ccc...cc..ccc..ccc..cc....cc..cc..cccc....c..ccc..cc..ccc..c.....cccc..ccc..c..ccca.d.", ".d.fccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccca.d.", ".d.fccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccca.d.", ".d.fcaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaca.d.", ".d.fca.......................................................................................................................fca.d.", ".d.fca.......................................................................................................................fca.d.", ".d.fca.......................................................................................................................fca.d.", ".d.fca.......................................................................................................................fca.d.", ".d.fca.......................................................................................................................fca.d.", ".d.fca.......................................................................................................................fca.d.", ".d.fca.......................................................................................................................fca.d.", ".d.fca.......................................................................................................................fca.d.", ".d.fca.......................................................................................................................fca.d.", ".d.fca.......................................................................................................................fca.d.", ".d.fca.......................................................................................................................fca.d.", ".d.fca.......................................................................................................................fca.d.", ".d.fca.......................................................................................................................fca.d.", ".d.fca.......................................................................................................................fca.d.", ".d.fca.......................................................................................................................fca.d.", ".d.fca.......................................................................................................................fca.d.", ".d.fca.......................................................................................................................fca.d.", ".d.fca.......................................................................................................................fca.d.", ".d.fca.......................................................................................................................fca.d.", ".d.fca.......................................................................................................................fca.d.", ".d.fca.......................................................................................................................fca.d.", ".d.fca.......................................................................................................................fca.d.", ".d.fca.......................................................................................................................fca.d.", ".d.fca.............................................................................................................ee..ee....fca.d.", ".d.fca..............................................................................................................eeee.....fca.d.", ".d.fca...............................................................................................................ee......fca.d.", ".d.fca...............................................................................................................ee......fca.d.", ".d.fca..............................................................................................................eeee.....fca.d.", ".d.fca.............................................................................................................ee..ee....fca.d.", ".d.fca.......................................................................................................................fca.d.", ".d.fca.......................................................................................................................fca.d.", ".d.fca...............................................................................................................e.......fca.d.", ".d.fca...............................................................................................................e.......fca.d.", ".d.fca...............................................................................................................e.......fca.d.", ".d.fca..............................................................................................................eee......fca.d.", ".d.fca..............................................................................................................eee......fca.d.", ".d.fca..............................................................................................................eee......fca.d.", ".d.fca.............................................................................................................eeeee.....fca.d.", ".d.fca.............................................................................................................eeeee.....fca.d.", ".d.fca...............................................................................................................e.......fca.d.", ".d.fca...............................................................................................................e.......fca.d.", ".d.fca...............................................................................................................e.......fca.d.", ".d.fca.....................................................................................................ee..ee....e.......fca.d.", ".d.fca......................................................................................................eeee.....e.......fca.d.", ".d.fca.......................................................................................................ee......e.......fca.d.", ".d.fca.......................................................................................................ee......e.......fca.d.", ".d.fca.......................................................................................................ee....eeeee.....fca.d.", ".d.fca.......................................................................................................ee...e.....e....fca.d.", ".d.fca...........................................................................................................ee.....ee...fca.d.", ".d.fca....................................................................................eeeee........ee.......e..e...e..e..fca.d.", ".d.fca.......................................................................................ee.....eeeee.......e...e.e...e..fca.d.", ".d.fca......................................................................................ee...eeeeeeeeeeeeeeee....e....e..fca.d.", ".d.fca.....................................................................................ee.......eeeee.......e...e.e...e..fca.d.", ".d.fca....................................................................................ee...........ee.......e..e...e..e..fca.d.", ".d.fca....................................................................................eeeee..................ee.....ee...fca.d.", ".d.fca............................................................................................................e.....e....fca.d.", ".d.fca.............................................................................................................eeeee.....fca.d.", ".d.fca.......................................................................................................................fca.d.", ".d.fca.......................................................................................................................fca.d.", ".d.fcfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffca.d.", ".d.fccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccca.d.", ".d.faaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.", ".d...............................................................................................................................d.", ".ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd.", "...................................................................................................................................", ".ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa.", ".fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffaa.", ".ffcccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccaa.", ".ffcccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccaa.", ".ffcccccccccccccccccccccccccccc....ccc....cc..cccc....cc.....ccccc.....cc...ccc.....cc..c..cc..cc....cccccccccccccccccccccccccccaa.", ".ffccccccccccccccccccccccccccc..cc..c..cc..c..ccc..cc..c..cc..cccc..ccccc...ccc..cc..c..c..cc..c..cc..ccccccccccccccccccccccccccaa.", ".ffccccccccccccccccccccccccccc..ccccc..cc..c..ccc..cc..c..cc..cccc....cc..c..cc..cc..c..c...c..c..ccccccccccccccccccccccccccccccaa.", ".ffccccccccccccccccccccccccccc..ccccc..cc..c..ccc..cc..c.....ccccc..cccc.....cc..cc..c..c......c..c...ccccccccccccccccccccccccccaa.", ".ffccccccccccccccccccccccccccc..cc..c..cc..c..ccc..cc..c..cc..cccc..ccc..ccc..c..cc..c..c..c...c..cc..ccccccccccccccccccccccccccaa.", ".ffcccccccccccccccccccccccccccc....ccc....cc....cc....cc..cc..cccc..ccc..ccc..c.....cc..c..cc..cc.....ccccccccccccccccccccccccccaa.", ".ffcccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccaa.", ".ffcccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccaa.", ".ffaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.", ".faaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.", "...................................................................................................................................", ".ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd.", ".d...............................d...............................d...............................d...............................d.", ".d.cfcfcfcfcfcfcfcfcfcfcfcfcfcfc.d.cfcfcfcfcfcfcfcfcfcfcfcfcfcfc.d.cfcfcfcfcfcfcfcfcfcfcfcfcfcfc.d.cfcfcfcfcfcfcfcfcfcfcfcfcfcfc.d.", ".d.fcfcfcfcfcfcfcfcfcfcfcfcfcfca.d.fcfcfcfcfcfcfcfcfcfcfcfcfcfca.d.fcfcfcfcfcfcfcfcfcfcfcfcfcfca.d.fcfcfcfcfcfcfcfcfcfcfcfcfcfca.d.", ".d.cfcfc...................cfcaa.d.cfcfc...................cfcaa.d.cfcfc...................cfcaa.d.cfcfc...................cfcaa.d.", ".d.fcfc.ccccccccccccccccccc.caaa.d.fcfc.ccccccccccccccccccc.caaa.d.fcfc.ccccccccccccccccccc.caaa.d.fcfc.ccccccccccccccccccc.caaa.d.", ".d.cfc.ccccccccccccccccccccc.aaa.d.cfc.ccccccccccccccccccccc.aaa.d.cfc.ccccccccccccccccccccc.aaa.d.cfc.ccccccccccccccccccccc.aaa.d.", ".d.fc.ccccc......cccc...ccccc.aa.d.fc.ccccc......ccc....ccccc.aa.d.fc.cccc......ccc....cccccc.aa.d.fc.cccc......ccccc...ccccc.aa.d.", ".d.cf.ccccc......ccc....ccccc.aa.d.cf.ccccc......cc......cccc.aa.d.cf.cccc......cc......ccccc.aa.d.cf.cccc......cccc....ccccc.aa.d.", ".d.fc.ccccc...ccccc.....ccccc.aa.d.fc.ccccc...ccccc......cccc.aa.d.fc.cccc...cccccccc...ccccc.aa.d.fc.cccc...cccccc.....ccccc.aa.d.", ".d.cf.ccccc.....ccc.....ccccc.aa.d.cf.ccccc.....cccccc...cccc.aa.d.cf.cccc.....ccccc...cccccc.aa.d.cf.cccc.....ccc......ccccc.aa.d.", ".d.fc.ccccc.....ccccc...ccccc.aa.d.fc.ccccc.....ccccc...ccccc.aa.d.fc.cccc.....cccccc...ccccc.aa.d.fc.cccc.....cc...c...ccccc.aa.d.", ".d.cf.ccccc...ccccccc...ccccc.aa.d.cf.ccccc...cccccc...cccccc.aa.d.cf.cccc...ccccc......ccccc.aa.d.cf.cccc...cccc........cccc.aa.d.", ".d.fc.ccccc...ccccccc...ccccc.aa.d.fc.ccccc...ccccc......cccc.aa.d.fc.cccc...ccccc......ccccc.aa.d.fc.cccc...cccc........cccc.aa.d.", ".d.cf.ccccc...ccccccc...ccccc.aa.d.cf.ccccc...ccccc......cccc.aa.d.cf.cccc...cccccc....cccccc.aa.d.cf.cccc...cccccccc...ccccc.aa.d.", ".d.fc.ccccccccccccccccccccccc.aa.d.fc.ccccccccccccccccccccccc.aa.d.fc.ccccccccccccccccccccccc.aa.d.fc.ccccccccccccccccccccccc.aa.d.", ".d.cf.ccccccccccccccccccccccc.aa.d.cf.ccccccccccccccccccccccc.aa.d.cf.ccccccccccccccccccccccc.aa.d.cf.ccccccccccccccccccccccc.aa.d.", ".d.fc.cccccccccccccc.b.bbddcc.aa.d.fc.cccccccccccccc.b.bbddcc.aa.d.fc.cc.b.bbddcccccccccccccc.aa.d.fc.cc.b.bbddcccccccccccccc.aa.d.", ".d.cf.cccccccccccccc..bbdbdcc.aa.d.cf.cccccccccccccc..bbdbdcc.aa.d.cf.cc..bbdbdcccccccccccccc.aa.d.cf.cc..bbdbdcccccccccccccc.aa.d.", ".d.fc.ccccccc.cccccc.b.bbddcc.aa.d.fc.cccccccc.ccccc.b.bbddcc.aa.d.fc.cc.b.bbddccccc.cccccccc.aa.d.fc.cc.b.bbddcccccc.ccccccc.aa.d.", ".d.cf.cccccc..cccccc..bbdbdcc.aa.d.cf.cccccccc..cccc..bbdbdcc.aa.d.cf.cc..bbdbdcccc..cccccccc.aa.d.cf.cc..bbdbdcccccc..cccccc.aa.d.", ".d.fc.ccccc.e.cccccc.b.bbddcc.aa.d.fc.cccccccc.e.ccc.b.bbddcc.aa.d.fc.cc.b.bbddccc.e.cccccccc.aa.d.fc.cc.b.bbddcccccc.e.ccccc.aa.d.", ".d.cf.cccc.ee.........bbdbdcc.aa.d.cf.cc.......ee.cc..bbdbdcc.aa.d.cf.cc..bbdbdcc.ee.......cc.aa.d.cf.cc..bbdbd.......ee.cccc.aa.d.", ".d.fc.ccc.eeeeeeeeee.b.bbddcc.aa.d.fc.cc.eeeeeeeee.c.b.bbddcc.aa.d.fc.cc.b.bbddc.eeeeeeeee.cc.aa.d.fc.cc.b.bbddeeeeeeeeee.ccc.aa.d.", ".d.cf.cc.eeeeeeeeeee..bbdbdcc.aa.d.cf.cc.eeeeeeeeee...bbdbdcc.aa.d.cf.cc..bbdbd.eeeeeeeeee.cc.aa.d.cf.cc..bbdbdeeeeeeeeeee.cc.aa.d.", ".d.fc.ccc.eeeeeeeeee.b.bbddcc.aa.d.fc.cc.eeeeeeeee.c.b.bbddcc.aa.d.fc.cc.b.bbddc.eeeeeeeee.cc.aa.d.fc.cc.b.bbddeeeeeeeeee.ccc.aa.d.", ".d.cf.cccc.ee.........bbdbdcc.aa.d.cf.cc.......ee.cc..bbdbdcc.aa.d.cf.cc..bbdbdcc.ee.......cc.aa.d.cf.cc..bbdbd.......ee.cccc.aa.d.", ".d.fc.ccccc.e.cccccc.b.bbddcc.aa.d.fc.cccccccc.e.ccc.b.bbddcc.aa.d.fc.cc.b.bbddccc.e.cccccccc.aa.d.fc.cc.b.bbddcccccc.e.ccccc.aa.d.", ".d.cf.cccccc..cccccc..bbdbdcc.aa.d.cf.cccccccc..cccc..bbdbdcc.aa.d.cf.cc..bbdbdcccc..cccccccc.aa.d.cf.cc..bbdbdcccccc..cccccc.aa.d.", ".d.fc.ccccccc.cccccc.b.bbddcc.aa.d.fc.cccccccc.ccccc.b.bbddcc.aa.d.fc.cc.b.bbddccccc.cccccccc.aa.d.fc.cc.b.bbddcccccc.ccccccc.aa.d.", ".d.cf.cccccccccccccc..bbdbdcc.aa.d.cf.cccccccccccccc..bbdbdcc.aa.d.cf.cc..bbdbdcccccccccccccc.aa.d.cf.cc..bbdbdcccccccccccccc.aa.d.", ".d.fc.cccccccccccccc.b.bbddcc.aa.d.fc.cccccccccccccc.b.bbddcc.aa.d.fc.cc.b.bbddcccccccccccccc.aa.d.fc.cc.b.bbddcccccccccccccc.aa.d.", ".d.cfc.ccccccccccccccccccccc.aaa.d.cfc.ccccccccccccccccccccc.aaa.d.cfc.ccccccccccccccccccccc.aaa.d.cfc.ccccccccccccccccccccc.aaa.d.", ".d.fcac.ccccccccccccccccccc.aaaa.d.fcac.ccccccccccccccccccc.aaaa.d.fcac.ccccccccccccccccccc.aaaa.d.fcac.ccccccccccccccccccc.aaaa.d.", ".d.cacaa...................aaaaa.d.cacaa...................aaaaa.d.cacaa...................aaaaa.d.cacaa...................aaaaa.d.", ".d.acaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.acaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.acaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.acaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.", ".d.caaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.caaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.caaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.caaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.", ".d.aaaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.aaaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.aaaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.aaaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.", ".d.aaaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.aaaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.aaaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.aaaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.", ".d...............................d...............................d...............................d...............................d.", ".ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd.", ".d...............................................................................................................................d.", ".d.ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa.d.", ".d.fccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccca.d.", ".d.fcaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaca.d.", ".d.fca.......................................................................................................................fca.d.", ".d.fca.......................................................................................................................fca.d.", ".d.fca.......................................................................................................................fca.d.", ".d.fca.......................................................................................................................fca.d.", ".d.fca.......................................................................................................................fca.d.", ".d.fca.......................................................................................................................fca.d.", ".d.fca.......................................................................................................................fca.d.", ".d.fca.......................................................................................................................fca.d.", ".d.fca.......................................................................................................................fca.d.", ".d.fca.......................................................................................................................fca.d.", ".d.fca.......................................................................................................................fca.d.", ".d.fca.......................................................................................................................fca.d.", ".d.fca.......................................................................................................................fca.d.", ".d.fca.......................................................................................................................fca.d.", ".d.fca.......................................................................................................................fca.d.", ".d.fca.......................................................................................................................fca.d.", ".d.fca.......................................................................................................................fca.d.", ".d.fca.......................................................................................................................fca.d.", ".d.fca.......................................................................................................................fca.d.", ".d.fca.......................................................................................................................fca.d.", ".d.fca.......................................................................................................................fca.d.", ".d.fca.......................................................................................................................fca.d.", ".d.fca.......................................................................................................................fca.d.", ".d.fca.............................................................................................................ee..ee....fca.d.", ".d.fca..............................................................................................................eeee.....fca.d.", ".d.fca...............................................................................................................ee......fca.d.", ".d.fca...............................................................................................................ee......fca.d.", ".d.fca..............................................................................................................eeee.....fca.d.", ".d.fca.............................................................................................................ee..ee....fca.d.", ".d.fca.......................................................................................................................fca.d.", ".d.fca.......................................................................................................................fca.d.", ".d.fca...............................................................................................................e.......fca.d.", ".d.fca...............................................................................................................e.......fca.d.", ".d.fca...............................................................................................................e.......fca.d.", ".d.fca..............................................................................................................eee......fca.d.", ".d.fca..............................................................................................................eee......fca.d.", ".d.fca..............................................................................................................eee......fca.d.", ".d.fca.............................................................................................................eeeee.....fca.d.", ".d.fca.............................................................................................................eeeee.....fca.d.", ".d.fca...............................................................................................................e.......fca.d.", ".d.fca...............................................................................................................e.......fca.d.", ".d.fca...............................................................................................................e.......fca.d.", ".d.fca.....................................................................................................ee..ee....e.......fca.d.", ".d.fca......................................................................................................eeee.....e.......fca.d.", ".d.fca.......................................................................................................ee......e.......fca.d.", ".d.fca.......................................................................................................ee......e.......fca.d.", ".d.fca.......................................................................................................ee....eeeee.....fca.d.", ".d.fca.......................................................................................................ee...e.....e....fca.d.", ".d.fca...........................................................................................................ee.....ee...fca.d.", ".d.fca....................................................................................eeeee........ee.......e..e...e..e..fca.d.", ".d.fca.......................................................................................ee.....eeeee.......e...e.e...e..fca.d.", ".d.fca......................................................................................ee...eeeeeeeeeeeeeeee....e....e..fca.d.", ".d.fca.....................................................................................ee.......eeeee.......e...e.e...e..fca.d.", ".d.fca....................................................................................ee...........ee.......e..e...e..e..fca.d.", ".d.fca....................................................................................eeeee..................ee.....ee...fca.d.", ".d.fca............................................................................................................e.....e....fca.d.", ".d.fca.............................................................................................................eeeee.....fca.d.", ".d.fca.......................................................................................................................fca.d.", ".d.fca.......................................................................................................................fca.d.", ".d.fcfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffca.d.", ".d.fccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccca.d.", ".d.faaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.d.", ".d...............................................................................................................................d.", ".ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd.", "..................................................................................................................................." }; garlic-1.6/include.c0000644000076500007650000000626410124233335014702 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2004 Damir Zucic */ /*============================================================================= include.c Purpose: Identify chains, residue ranges, residue names and atom names which have to be included into selection. Input: (1) Pointer to SelectS structure, where data will be stored. (2) Pointer to the selection string. Output: (1) SelectS structure filled with data. (2) Return value. Return value: (1) Positive on success. (2) Negative on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ char *ExtractToken_ (char *, int, char *, char *); int ExtractChains_ (SelectS *, char *); int ExtractResidueRanges_ (SelectS *, char *); int ExtractResidueNames_ (SelectS *, char *); int ExtractAtomNames_ (SelectS *, char *); /*======identify included ranges and names:==================================*/ int Include_ (SelectS *include_selectSP, char *stringP) { char string_copyA[STRINGSIZE]; char *remainderP; char tokenA[STRINGSIZE]; char *exceptP; /* Copy the input string to preserve it: */ strncpy (string_copyA, stringP, STRINGSIZE - 1); string_copyA[STRINGSIZE - 1] = '\0'; /* Pointer to the remainder of the string */ /* initially points to the whole string: */ remainderP = stringP; /* The first token should contain chain identifiers: */ remainderP = ExtractToken_ (tokenA, STRINGSIZE, remainderP, "/"); if (remainderP == NULL) return -1; /* Remove the exc (exclude, except) keyword and everything after it: */ if ((exceptP = strstr (tokenA, "EXC")) != NULL) *exceptP = '\0'; /* Extract chain identifiers: */ if (ExtractChains_ (include_selectSP, tokenA) < 0) return -2; /* The second token should contain residue ranges: */ remainderP = ExtractToken_ (tokenA, STRINGSIZE, remainderP, "/"); if (remainderP == NULL) return -3; /* Remove the exc (exclude, except) keyword and everything after it: */ if ((exceptP = strstr (tokenA, "EXC")) != NULL) *exceptP = '\0'; /* Extract residue ranges: */ if (ExtractResidueRanges_ (include_selectSP, tokenA) < 0) return -4; /* The third token should contain residue names: */ remainderP = ExtractToken_ (tokenA, STRINGSIZE, remainderP, "/"); if (remainderP == NULL) return -5; /* Remove the exc (exclude, except) keyword and everything after it: */ if ((exceptP = strstr (tokenA, "EXC")) != NULL) *exceptP = '\0'; /* Extract residue names: */ if (ExtractResidueNames_ (include_selectSP, tokenA) < 0) return -6; /* The fourth (the last) token should contain atom names: */ remainderP = ExtractToken_ (tokenA, STRINGSIZE, remainderP, "/"); if (remainderP == NULL) return -7; /* Remove the exc (exclude, except) keyword and everything after it: */ if ((exceptP = strstr (tokenA, "EXC")) != NULL) *exceptP = '\0'; /* Extract atom names: */ if (ExtractAtomNames_ (include_selectSP, tokenA) < 0) return -8; /* Return positive value on success: */ return 1; } /*===========================================================================*/ garlic-1.6/free_memory.c0000644000076500007650000000724710157077034015602 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= free_memory.c Purpose: Free storage used for pixmaps and other data. Input: (1) Pointer to GUIS structure. (2) Pointer to the array of MolComplexS structures. (3) Number of molecular complexes stored in dynamically allocated memory. (4) Pointer to the array of NearestAtomS structures. (5) Pointer to the number of pixels. Output: No output (well, some memory may be freed, but this does not count). Return value: No return value. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======free data storage:===================================================*/ void FreeMemory_ (GUIS *guiSP, MolComplexS *mol_complexSP, int mol_complexesN, NearestAtomS *nearest_atomSP, size_t *pixelsNP) { int i; /* Free pixmaps: */ if (guiSP->icon_winS.pixmapF) XFreePixmap (guiSP->displaySP, guiSP->icon_winS.pixmapID); if (guiSP->control_winS.pixmapF) XFreePixmap (guiSP->displaySP, guiSP->control_winS.pixmapID); if (guiSP->main_hidden_pixmapF) XFreePixmap (guiSP->displaySP, guiSP->main_hidden_pixmapID); if (guiSP->small_arrows_pixmapF) XFreePixmap (guiSP->displaySP, guiSP->small_arrows_pixmapID); /* Free cursors: */ if (guiSP->main_winS.cursorF) XFreeCursor (guiSP->displaySP, guiSP->main_winS.cursorID); if (guiSP->control_winS.cursorF) XFreeCursor (guiSP->displaySP, guiSP->control_winS.cursorID); if (guiSP->input_winS.cursorF) XFreeCursor (guiSP->displaySP, guiSP->input_winS.cursorID); if (guiSP->output_winS.cursorF) XFreeCursor (guiSP->displaySP, guiSP->output_winS.cursorID); /* Free font: */ if (guiSP->main_winS.fontF) XFreeFont (guiSP->displaySP, guiSP->main_winS.fontSP); /* Free GC's (graphics contexts): */ if (guiSP->gca_createdF) { XFreeGC (guiSP->displaySP, guiSP->theGCA[0]); XFreeGC (guiSP->displaySP, guiSP->theGCA[1]); XFreeGC (guiSP->displaySP, guiSP->theGCA[2]); XFreeGC (guiSP->displaySP, guiSP->theGCA[3]); XFreeGC (guiSP->displaySP, guiSP->theGCA[4]); XFreeGC (guiSP->displaySP, guiSP->theGCA[5]); XFreeGC (guiSP->displaySP, guiSP->theGCA[6]); XFreeGC (guiSP->displaySP, guiSP->theGCA[7]); XFreeGC (guiSP->displaySP, guiSP->theGCA[8]); XFreeGC (guiSP->displaySP, guiSP->theGCA[9]); } /* Free memory used to store header, atomic data, backbone and sequence: */ for (i = 0; i < mol_complexesN; i++) { if ((mol_complexSP + i)->headerS.dataP) { free ((mol_complexSP + i)->headerS.dataP); (mol_complexSP + i)->headerS.dataP = NULL; } if ((mol_complexSP + i)->atomSP) { free ((mol_complexSP + i)->atomSP); (mol_complexSP + i)->atomSP = NULL; (mol_complexSP + i)->atomsN = 0; (mol_complexSP + i)->max_atomsN = 0; } if ((mol_complexSP + i)->backboneSP) { free ((mol_complexSP + i)->backboneSP); (mol_complexSP + i)->backboneSP = NULL; (mol_complexSP + i)->c_alphaN = 0; } if ((mol_complexSP + i)->residueSP) { free ((mol_complexSP + i)->residueSP); (mol_complexSP + i)->residueSP = NULL; (mol_complexSP + i)->residuesN = 0; } if ((mol_complexSP + i)->secondary_structureP) { free ((mol_complexSP + i)->secondary_structureP); (mol_complexSP + i)->secondary_structureP = NULL; } } /* Free memory used by NearestAtomS array: */ if (nearest_atomSP != NULL) { free (nearest_atomSP); nearest_atomSP = NULL; *pixelsNP = 0; } } /*===========================================================================*/ garlic-1.6/print_config.c0000644000076500007650000003715007606131402015741 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2003 Damir Zucic */ /*============================================================================= print_config.c Purpose: Print configuration data (for debugging purpose). Input: (1) Pointer to ConfigS structure, with configuration data. (2) Pointer to GUIS structure, with GUI data. Output: Configuration data and part of GUI data written to stdout. Return value: No return value. ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======print configuration data:============================================*/ void PrintConfig_ (ConfigS *configSP, GUIS *guiSP) { int n; printf ("========================\n"); /* Main window geometry: */ printf ("main window geometry: <%s>\n", configSP->geometryA); /* Font name and cursor name: */ printf ("font name: <%s>\n", configSP->font_nameA); printf ("cursor name: <%s>\n", configSP->cursor_nameA); /* Coordinate system flag: */ printf ("coordinate system flag: %d\n", (int) configSP->show_coord_systemF); /* Control window flag: */ printf ("control window flag: %d\n", (int) configSP->show_control_windowF); /* Sequence neighborhood flag: */ printf ("sequence neighborhood flag: %d\n", (int) configSP->show_sequence_neighborhoodF); /** Stereo flag: **/ printf ("stereo flag: %d\n", (int) configSP->stereoF); /** Light source theta angle: **/ printf ("light source theta angle: %f\n", configSP->light_theta); /** Light source phi angle: **/ printf ("light source phi angle: %f\n", configSP->light_phi); /** Default slab mode flag: */ printf ("default slab mode: %d\n", (int) configSP->default_slab_modeI); /** Default color fading mode: **/ printf ("default color fading mode: %d\n", (int) configSP->default_fading_modeI); /** Strings specifying default colors for all windows: **/ printf ("window background color: <%s>\n", configSP->bg_colorA); printf ("window foreground color: <%s>\n", configSP->fg_colorA); printf ("text background color: <%s>\n", configSP->text_bg_colorA); printf ("text foreground color: <%s>\n", configSP->text_fg_colorA); printf ("Number of fading surfaces: %d\n", configSP->default_surfacesN); /** Strings specifying default basic colors for atoms and bonds: **/ for (n = 0; n < MAXCOLORSURFACES; n++) { printf ("Fading surface %d:\n", n); printf ("Left color: <%s>\n", configSP->left_colorAA[n]); printf ("Left color RGB values: %d %d %d\n", (int) configSP->left_rgbSA[n].red, (int) configSP->left_rgbSA[n].green, (int) configSP->left_rgbSA[n].blue); printf ("Middle color: <%s>\n", configSP->middle_colorAA[n]); printf ("Middle color RGB values: %d %d %d\n", (int) configSP->middle_rgbSA[n].red, (int) configSP->middle_rgbSA[n].green, (int) configSP->middle_rgbSA[n].blue); printf ("Right color: <%s>\n", configSP->right_colorAA[n]); printf ("Right color RGB values: %d %d %d\n", (int) configSP->right_rgbSA[n].red, (int) configSP->right_rgbSA[n].green, (int) configSP->right_rgbSA[n].blue); } /** Default color scheme for the outer side of molecular surfaces: **/ printf ("default surface color scheme (outer side): <%s>\n", configSP->surface_outer_color_schemeA); /** Default color scheme for the inner side of molecular surfaces: **/ printf ("default surface color scheme (inner side): <%s>\n", configSP->surface_inner_color_schemeA); /** Default drawing style for atoms, bonds and backbone: **/ printf ("default atom drawing style: %d\n", configSP->default_atom_styleI); printf ("default bond drawing style: %d\n", configSP->default_bond_styleI); printf ("default backbone drawing style: %d\n", configSP->default_backbone_styleI); /** Bond parameters: **/ printf ("maximal bond length: %f\n", configSP->max_bond_length); printf ("minimal C-C bond length: %f\n", configSP->C_C_bond_length_min); printf ("maximal C-C bond length: %f\n", configSP->C_C_bond_length_max); printf ("minimal C-N bond length: %f\n", configSP->C_N_bond_length_min); printf ("maximal C-N bond length: %f\n", configSP->C_N_bond_length_max); printf ("minimal C-O bond length: %f\n", configSP->C_O_bond_length_min); printf ("maximal C-O bond length: %f\n", configSP->C_O_bond_length_max); printf ("minimal C-S bond length: %f\n", configSP->C_S_bond_length_min); printf ("maximal C-S bond length: %f\n", configSP->C_S_bond_length_max); printf ("minimal C-H bond length: %f\n", configSP->C_H_bond_length_min); printf ("maximal C-H bond length: %f\n", configSP->C_H_bond_length_max); printf ("minimal N-O bond length: %f\n", configSP->N_O_bond_length_min); printf ("maximal N-O bond length: %f\n", configSP->N_O_bond_length_max); printf ("minimal N-H bond length: %f\n", configSP->N_H_bond_length_min); printf ("maximal N-H bond length: %f\n", configSP->N_H_bond_length_max); printf ("minimal O-H bond length: %f\n", configSP->O_H_bond_length_min); printf ("maximal O-H bond length: %f\n", configSP->O_H_bond_length_max); printf ("minimal S-H bond length: %f\n", configSP->S_H_bond_length_min); printf ("maximal S-H bond length: %f\n", configSP->S_H_bond_length_max); printf ("minimal O-P bond length: %f\n", configSP->O_P_bond_length_min); printf ("maximal O-P bond length: %f\n", configSP->O_P_bond_length_max); printf ("minimal S-S bond length: %f\n", configSP->S_S_bond_length_min); printf ("maximal S-S bond length: %f\n", configSP->S_S_bond_length_max); printf ("minimal generic bond length: %f\n", configSP->generic_bond_length_min); printf ("maximal generic bond length: %f\n", configSP->generic_bond_length_max); printf ("minimal hydrogen bond length: %f\n", configSP->hydro_bond_length_min); printf ("maximal hydrogen bond length: %f\n", configSP->hydro_bond_length_max); printf ("minimal C-O...N angle (radians): %f\n", configSP->hydro_bond_angle_min); printf ("maximal C-O...N angle (radians): %f\n", configSP->hydro_bond_angle_max); /** The calculated (practical) bond parameters: **/ printf ("minimal C-C bond length squared: %f\n", configSP->C_C_min_squared); printf ("maximal C-C bond length squared: %f\n", configSP->C_C_max_squared); printf ("minimal C-N bond length squared: %f\n", configSP->C_N_min_squared); printf ("maximal C-N bond length squared: %f\n", configSP->C_N_max_squared); printf ("minimal C-O bond length squared: %f\n", configSP->C_O_min_squared); printf ("maximal C-O bond length squared: %f\n", configSP->C_O_max_squared); printf ("minimal C-S bond length squared: %f\n", configSP->C_S_min_squared); printf ("maximal C-S bond length squared: %f\n", configSP->C_S_max_squared); printf ("minimal C-H bond length squared: %f\n", configSP->C_H_min_squared); printf ("maximal C-H bond length squared: %f\n", configSP->C_H_max_squared); printf ("minimal N-O bond length squared: %f\n", configSP->N_O_min_squared); printf ("maximal N-O bond length squared: %f\n", configSP->N_O_max_squared); printf ("minimal N-H bond length squared: %f\n", configSP->N_H_min_squared); printf ("maximal N-H bond length squared: %f\n", configSP->N_H_max_squared); printf ("minimal O-H bond length squared: %f\n", configSP->O_H_min_squared); printf ("maximal O-H bond length squared: %f\n", configSP->O_H_max_squared); printf ("minimal S-H bond length squared: %f\n", configSP->S_H_min_squared); printf ("maximal S-H bond length squared: %f\n", configSP->S_H_max_squared); printf ("minimal O-P bond length squared: %f\n", configSP->O_P_min_squared); printf ("maximal O-P bond length squared: %f\n", configSP->O_P_max_squared); printf ("minimal S-S bond length squared: %f\n", configSP->S_S_min_squared); printf ("maximal S-S bond length squared: %f\n", configSP->S_S_max_squared); printf ("minimal generic bond length squared: %f\n", configSP->generic_min_squared); printf ("maximal generic bond length squared: %f\n", configSP->generic_max_squared); printf ("minimal hydrogen bond length squared: %f\n", configSP->hydro_min_squared); printf ("maximal hydrogen length squared: %f\n", configSP->hydro_max_squared); /** Backbone CA-CA distance: **/ printf ("maximal CA-CA distance: %f\n", configSP->CA_CA_dist_max); printf ("maximal CA-CA distance squared: %f\n", configSP->CA_CA_dist_max_squared); /** Atomic radii: **/ printf ("radius of H atom: %f\n", configSP->H_radius); printf ("radius of C atom: %f\n", configSP->C_radius); printf ("radius of N atom: %f\n", configSP->N_radius); printf ("radius of O atom: %f\n", configSP->O_radius); printf ("radius of S atom: %f\n", configSP->S_radius); printf ("radius of P atom: %f\n", configSP->P_radius); printf ("generic radius: %f\n", configSP->generic_radius); /** Covalent radii: **/ printf ("covalent radius of H atom: %f\n", configSP->H_covalent_radius); printf ("covalent radius of C atom: %f\n", configSP->C_covalent_radius); printf ("covalent radius of N atom: %f\n", configSP->N_covalent_radius); printf ("covalent radius of O atom: %f\n", configSP->O_covalent_radius); printf ("covalent radius of S atom: %f\n", configSP->S_covalent_radius); printf ("covalent radius of P atom: %f\n", configSP->P_covalent_radius); printf ("generic covalent radius: %f\n", configSP->generic_covalent_radius); /** Small radii: **/ printf ("small radius of H atom: %f\n", configSP->H_small_radius); printf ("small radius of C atom: %f\n", configSP->C_small_radius); printf ("small radius of N atom: %f\n", configSP->N_small_radius); printf ("small radius of O atom: %f\n", configSP->O_small_radius); printf ("small radius of S atom: %f\n", configSP->S_small_radius); printf ("small radius of P atom: %f\n", configSP->P_small_radius); printf ("generic small radius: %f\n", configSP->generic_small_radius); /** Van der Waals radii: **/ printf ("van der Waals radius of H atom: %f\n", configSP->H_van_der_Waals_radius); printf ("van der Waals radius of C atom: %f\n", configSP->C_van_der_Waals_radius); printf ("van der Waals radius of N atom: %f\n", configSP->N_van_der_Waals_radius); printf ("van der Waals radius of O atom: %f\n", configSP->O_van_der_Waals_radius); printf ("van der Waals radius of S atom: %f\n", configSP->S_van_der_Waals_radius); printf ("van der Waals radius of P atom: %f\n", configSP->P_van_der_Waals_radius); printf ("generic van der Waals radius: %f\n", configSP->generic_van_der_Waals_radius); /** Ball radius: **/ printf ("default ball radius (used to draw balls and sticks): %f\n", configSP->default_ball_radius); /** Default bond probe radius: **/ printf ("default bond probe radius (used to draw nice bonds): %f\n", configSP->default_bond_probe_radius); /** Default stick radius: **/ printf ("default stick radius (used to draw bonds as sticks): %f\n", configSP->default_stick_radius); /** Number of neighbors which should be checked as bond candidates: **/ printf ("number of bond candidates (backward): %d\n", configSP->bond_candidates_backward); printf ("number of bond candidates (forward): %d\n", configSP->bond_candidates_forward); /** Blur rectangle default width and height: **/ printf ("Blur rectangle default width: %d\n", configSP->blur_default_width); printf ("Blur rectangle default height: %d\n", configSP->blur_default_height); /** Miscelaneous geometric parameters, related to drawing: **/ printf ("main window left margin: %d\n", configSP->main_margin_left); printf ("main window right margin: %d\n", configSP->main_margin_right); printf ("main window top margin: %d\n", configSP->main_margin_top); printf ("main window bottom margin: %d\n", configSP->main_margin_bottom); printf ("maximal main window width: %d\n", configSP->max_main_win_width); printf ("maximal main window height: %d\n", configSP->max_main_win_height); printf ("the nearest line thickness: %d\n", configSP->nearest_line_thickness); printf ("screen width (physical): %f\n", configSP->screen_real_width); printf ("screen height (physical): %f\n", configSP->screen_real_height); printf ("user to screen distance (physical): %f\n", configSP->user_screen_real_distance); printf ("screen width (atomic): %f\n", configSP->screen_atomic_width); printf ("user position (atomic): %f\n", configSP->user_atomic_position); printf ("stereo margin (screen): %d\n", configSP->stereo_screen_margin); printf ("stereo angle (degrees): %f\n", configSP->stereo_angle * RAD_TO_DEG); printf ("rotation steps (degrees): %7.3f %7.3f %7.3f %7.3f %7.3f\n", configSP->rotation_stepA[0], configSP->rotation_stepA[1], configSP->rotation_stepA[2], configSP->rotation_stepA[3], configSP->rotation_stepA[4]); printf ("translation steps (angstroms): %7.3f %7.3f %7.3f %7.3f %7.3f\n", configSP->translation_stepA[0], configSP->translation_stepA[1], configSP->translation_stepA[2], configSP->translation_stepA[3], configSP->translation_stepA[4]); printf ("slab steps (angstroms): %7.3f %7.3f %7.3f %7.3f %7.3f\n", configSP->slab_stepA[0], configSP->slab_stepA[1], configSP->slab_stepA[2], configSP->slab_stepA[3], configSP->slab_stepA[4]); printf ("fading steps (angstroms): %7.3f %7.3f %7.3f %7.3f %7.3f\n", configSP->fading_stepA[0], configSP->fading_stepA[1], configSP->fading_stepA[2], configSP->fading_stepA[3], configSP->fading_stepA[4]); printf ("------------------------\n"); /** Parameters calculated from geometric data. **/ printf ("user to screen distance (atomic): %f\n", configSP->user_screen_atomic_distance); printf ("screen height (atomic): %f\n", configSP->screen_atomic_height); printf ("screen z coordinate (atomic): %f\n", configSP->screen_atomic_z); printf ("atomic to screen scale factor (x): %f\n", configSP->atomic_to_screen_scale_x); printf ("atomic to screen scale factor (y): %f\n", configSP->atomic_to_screen_scale_y); printf ("screen to atomic scale factor (x): %f\n", configSP->screen_to_atomic_scale_x); printf ("window free width (atomic): %f\n", configSP->win_atomic_free_width); printf ("window free height (atomic): %f\n", configSP->win_atomic_free_height); printf ("window left edge position (atomic): %f\n", configSP->win_atomic_x0); printf ("window top edge position (atomic): %f\n", configSP->win_atomic_y0); printf ("window z coordinate (atomic): %f\n", configSP->win_atomic_z0); printf ("window right edge position (atomic): %f\n", configSP->win_atomic_x1); printf ("window bottom edge position (atomic): %f\n", configSP->win_atomic_y1); printf ("rationalized x0: %f\n", configSP->rationalized_x0); printf ("rationalized y0: %f\n", configSP->rationalized_y0); printf ("rationalized x1: %f\n", configSP->rationalized_x1); printf ("rationalized y1: %f\n", configSP->rationalized_y1); printf ("stereo margin (atomic): %f\n", configSP->stereo_atomic_margin); printf ("left image center x (screen): %d\n", configSP->center_screen_x[0]); printf ("right image center x (screen): %d\n", configSP->center_screen_x[1]); printf ("both images center y (screen): %d\n", configSP->center_screen_y); printf ("left image left edge x (screen): %d\n", configSP->image_screen_x0[0]); printf ("left image right edge x (screen): %d\n", configSP->image_screen_x1[0]); printf ("right image left edge x (screen): %d\n", configSP->image_screen_x0[1]); printf ("right image right edge x (screen): %d\n", configSP->image_screen_x1[1]); printf ("both images top edge y (screen): %d\n", configSP->image_screen_y0); printf ("both images bottom edge y (screen): %d\n", configSP->image_screen_y1); printf ("-----some GUI data:-----\n"); printf ("screen width (pixels): %u\n", guiSP->screen_width); printf ("screen height (pixels): %u\n", guiSP->screen_height); printf ("control window x0 (pixels): %u\n", guiSP->control_winS.x0); printf ("input window y0 (pixels): %u\n", guiSP->input_winS.y0); printf ("main window free area width: %u\n", guiSP->main_win_free_area_width); printf ("main window free area height: %u\n", guiSP->main_win_free_area_height); /* Flush it: */ fflush (stdout); } /*===========================================================================*/ garlic-1.6/spacefill2.c0000644000076500007650000003140107747301456015313 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2003 Damir Zucic */ /*============================================================================= spacefill2.c Purpose: Draw atoms as spheres, version 2 (spacefill style 2). Input: (1) Pointer to MolComplexS structure. (2) Number of macromolecular complexes. (3) Pointer to ConfigS structure, with configuration data. (4) Pointer to GUIS structure. (5) Pointer to NearestAtomS structure, with information about the atom occupying the given pixel. (6) The number of pixels in the main window free area. (7) The refreshI, used to check the NearestAtomS associated with a given pixel. Output: (1) Spheres drawn to the hidden pixmap. (2) Return value. Return value: (1) Positive always (trivial). Notes: (1) Indentation is exceptionally 4 spaces. =============================================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ unsigned long Sp2Color_ (AtomS *, GUIS *, double); /*======draw atoms as spheres, version 2:====================================*/ int DrawSpacefill2_ (MolComplexS *mol_complexSP, int mol_complexesN, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int refreshI) { int imageI, imagesN; double scale_factor, user_atomic_position; int left_edge[2], right_edge[2]; int mol_complexI; MolComplexS *curr_mol_complexSP; size_t atomsN, atomI; AtomS *curr_atomSP; int screen_x0, screen_y0; double radius, radius_squared; double denominator, reciprocal_denominator; int screen_radius; long screen_radius_squared; int screen_x1, screen_y1, screen_x2, screen_y2; int screen_x, screen_y; long delta_x, delta_y, distance_squared; double z0, front_z, delta_z, z; size_t pixelI; NearestAtomS *curr_pixelSP; double denominator2, reciprocal_denominator2; double rho_squared; VectorS vectorS; double abs_value, abs_value_squared; double scalar_product, cos_angle; unsigned long colorID; int bondI; /* Initialize the bond index. The negative value means that pixels */ /* filled in this function are not a part of any chemical bond. */ bondI = -1; /* Number of images: */ if (configSP->stereoF) imagesN = 2; else imagesN = 1; /* The auxiliary scale factor: */ scale_factor = configSP->user_screen_atomic_distance * configSP->atomic_to_screen_scale_x; /* Prepare the user position in atomic coordinates: */ user_atomic_position = configSP->user_atomic_position; /* Left and right image edge (in stereo mode there are two images): */ left_edge[0] = configSP->image_screen_x0[0]; right_edge[0] = configSP->image_screen_x1[0]; left_edge[1] = configSP->image_screen_x0[1]; right_edge[1] = configSP->image_screen_x1[1]; /*------first pass - fill NearestAtomS array with planar atoms:--------------*/ /* Draw each macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Prepare and check the number of atoms: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Draw atoms which have the given style: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Check style: */ if (curr_atomSP->raw_atomS.atom_styleI != SPACEFILL2) continue; /* Check is atom hidden: */ if (curr_atomSP->hiddenF) continue; /* Check is atom inside slab: */ if (!curr_atomSP->inside_slabF) continue; /* Check is atom inside window: */ if (!curr_atomSP->inside_windowF) continue; /* Atomic radius, in atomic units: */ radius = curr_atomSP->raw_atomS.radius; /* The y coordinate of atomic center, in screen units: */ screen_y0 = curr_atomSP->raw_atomS.screen_y; /* Prepare one image (mono) or two images (stereo): */ for (imageI = 0; imageI < imagesN; imageI++) { /* The z coordinate of atomic center, in atomic units: */ z0 = curr_atomSP->raw_atomS.z[imageI]; /* Prepare the factor required for projection of atomic radius: */ denominator = z0 - user_atomic_position; if (denominator == 0.0) continue; reciprocal_denominator = 1.0 / denominator; /* Atomic radius in screen units: */ screen_radius = (int) (radius * scale_factor * reciprocal_denominator + 0.5); /* Screen radius squared (used to improve speed): */ screen_radius_squared = (long) screen_radius * (long) screen_radius; /* The x coordinate of atomic center, in screen units: */ screen_x0 = curr_atomSP->raw_atomS.screen_x[imageI]; /* Define the bounding rectangle: */ screen_x1 = screen_x0 - screen_radius; screen_y1 = screen_y0 - screen_radius; screen_x2 = screen_x0 + screen_radius; screen_y2 = screen_y0 + screen_radius; /* Horizontal scan: */ for (screen_x = screen_x1; screen_x <= screen_x2; screen_x++) { /* Check horizontal position: */ if (screen_x < left_edge[imageI]) continue; if (screen_x >= right_edge[imageI]) continue; /* Vertical scan: */ for (screen_y = screen_y1; screen_y <= screen_y2; screen_y++) { /* Check vertical position: */ if (screen_y < 0) continue; if (screen_y >= (int) guiSP->main_win_free_area_height) { continue; } /* Check distance from the circle center: */ delta_x = (long) (screen_x - screen_x0); delta_y = (long) (screen_y - screen_y0); distance_squared = delta_x * delta_x + delta_y * delta_y; if (distance_squared > screen_radius_squared) continue; /* Prepare index to the array */ /* of NearestAtomS structures: */ pixelI = guiSP->main_win_free_area_width * screen_y + screen_x; /* Check the pixel index: */ if (pixelI >= pixelsN) continue; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = nearest_atomSP + pixelI; /* Check was this pixel used already in */ /* this drawing step; if it was, compare */ /* the z value of the current atom with z */ /* value previously stored to this pixel: */ if (refreshI == curr_pixelSP->last_refreshI) { if (z0 > curr_pixelSP->z) continue; } /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = SPACEFILL2; curr_pixelSP->last_refreshI = refreshI; curr_pixelSP->mol_complexI = mol_complexI; curr_pixelSP->atomI = atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = z0; } } } /* imageI loop */ } /* atomI loop */ } /* mol_complexI loop */ /*------second pass - draw spherical atoms:----------------------------------*/ /* Draw each macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Prepare and check the number of atoms: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Draw atoms which have the given style: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Check style: */ if (curr_atomSP->raw_atomS.atom_styleI != SPACEFILL2) continue; /* Check is atom hidden: */ if (curr_atomSP->hiddenF) continue; /* Check is atom inside slab: */ if (!curr_atomSP->inside_slabF) continue; /* Check is atom inside window: */ if (!curr_atomSP->inside_windowF) continue; /* Atomic radius, in atomic units: */ radius = curr_atomSP->raw_atomS.radius; /* Squared atomic radius: */ radius_squared = radius * radius; /* The y coordinate of atomic center, in screen units: */ screen_y0 = curr_atomSP->raw_atomS.screen_y; /* Prepare one image (mono) or two images (stereo): */ for (imageI = 0; imageI < imagesN; imageI++) { /* The z coordinate of atomic center, in atomic units: */ z0 = curr_atomSP->raw_atomS.z[imageI]; /* The z coordinate of the nearest */ /* point of a given atom (sphere): */ front_z = z0 - radius; /* Prepare the factor required for projection of atomic radius: */ denominator = z0 - user_atomic_position; if (denominator == 0.0) continue; reciprocal_denominator = 1.0 / denominator; /* Atomic radius in screen units: */ screen_radius = (int) (radius * scale_factor * reciprocal_denominator + 0.5); /* Square of the atomic radius (in screen units): */ screen_radius_squared = (long) screen_radius * (long) screen_radius; /* Reciprocal value will be used to improve performance: */ denominator2 = (double) screen_radius_squared; if (denominator2 == 0.0) continue; reciprocal_denominator2 = 1.0 / denominator2; /* The x coordinate of atomic center, in screen units: */ screen_x0 = curr_atomSP->raw_atomS.screen_x[imageI]; /* Define the bounding rectangle: */ screen_x1 = screen_x0 - screen_radius; screen_y1 = screen_y0 - screen_radius; screen_x2 = screen_x0 + screen_radius; screen_y2 = screen_y0 + screen_radius; /* Horizontal scan: */ for (screen_x = screen_x1; screen_x <= screen_x2; screen_x++) { /* Check horizontal position: */ if (screen_x < left_edge[imageI]) continue; if (screen_x > right_edge[imageI]) continue; /* Vertical scan: */ for (screen_y = screen_y1; screen_y <= screen_y2; screen_y++) { /* Check vertical position: */ if (screen_y < 0) continue; if (screen_y >= (int) guiSP->main_win_free_area_height) { continue; } /* Check distance from the circle center: */ delta_x = (long) (screen_x - screen_x0); delta_y = (long) (screen_y - screen_y0); distance_squared = delta_x * delta_x + delta_y * delta_y; if (distance_squared > screen_radius_squared) continue; /* Prepare index to the array */ /* of NearestAtomS structures: */ pixelI = guiSP->main_win_free_area_width * screen_y + screen_x; /* Check the pixel index: */ if (pixelI >= pixelsN) continue; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = nearest_atomSP + pixelI; /* Check z value (this is just a quick check): */ if (refreshI == curr_pixelSP->last_refreshI) { if (front_z > curr_pixelSP->z) continue; } /* Calculate the accurate z value: */ rho_squared = radius_squared * (double) distance_squared * reciprocal_denominator2; delta_z = sqrt (fabs (radius_squared - rho_squared)); z = z0 - delta_z; /* Check z value (precise check): */ if (refreshI == curr_pixelSP->last_refreshI) { if (z > curr_pixelSP->z) continue; } /* The vector from sphere center to the current pixel: */ vectorS.x = (double) delta_x; vectorS.y = (double) delta_y; vectorS.z = - sqrt (fabs (screen_radius_squared - vectorS.x * vectorS.x - vectorS.y * vectorS.y)); abs_value_squared = vectorS.x * vectorS.x + vectorS.y * vectorS.y + vectorS.z * vectorS.z; abs_value = sqrt (abs_value_squared); /* The scalar product between this */ /* vector and light source vector: */ scalar_product = vectorS.x * configSP->light_vectorS.x + vectorS.y * configSP->light_vectorS.y + vectorS.z * configSP->light_vectorS.z; /* Cosine of the angle between the vector to the */ /* current pixel and the light source unit vector: */ if (abs_value == 0.0) cos_angle = 0.0; else cos_angle = scalar_product / abs_value; /* Prepare color: */ colorID = Sp2Color_ (curr_atomSP, guiSP, cos_angle); XSetForeground (guiSP->displaySP, guiSP->theGCA[0], colorID); XDrawPoint (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x, screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = SPACEFILL2; curr_pixelSP->last_refreshI = refreshI; curr_pixelSP->mol_complexI = mol_complexI; curr_pixelSP->atomI = atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = z; curr_pixelSP->colorID = colorID; } } } /* imageI loop */ } /* atomI loop */ } /* mol_complexI loop */ /*---------------------------------------------------------------------------*/ /* Return positive value (trivial): */ return 1; } /*===========================================================================*/ garlic-1.6/sec_structure_from.c0000644000076500007650000001073607262271656017214 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= sec_structure_from.c Purpose: Copy the secondary structure from the specified macromolecular complex to the secondary structure buffer. Only the structure for selected range(s) is copied. A given residue is treated as selected if the first atom of this residue is selected. For proteins, this is typically N. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) The number of macromolecular complexes. (3) Pointer to RuntimeS structure. (4) Pointer to the string which contains the macromol. complex identifier. Output: (1) Secondary structure from the specified complex is copied to the secondary structure buffer. (2) Return value. Return value: (1) Positive (command) code on success. (2) Negative (error) code on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "commands.h" #include "typedefs.h" /*======function prototypes:=================================================*/ char *ExtractToken_ (char *, int, char *, char *); /*======copy secondary structure from complex to sec. str. buffer:===========*/ int SecondaryStructureFrom_ (MolComplexS *mol_complexSP, int mol_complexesN, RuntimeS *runtimeSP, char *stringP) { char *remainderP; char tokenA[SHORTSTRINGSIZE]; int complexID; int mol_complexI; static MolComplexS *curr_mol_complexSP; int job_doneF = 0; size_t residueI, residuesN; size_t selected_residueI = 0; ResidueS *curr_residueSP; AtomS *first_atomSP; /* At least one macromolecular complex should be available: */ if (mol_complexesN == 0) { strcpy (runtimeSP->messageA, "No structure loaded!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return -1; } /* Take the first token; it should be present: */ remainderP = ExtractToken_ (tokenA, SHORTSTRINGSIZE, stringP, " \t\n"); if (!remainderP) { strcpy (runtimeSP->messageA, "Complex identifier missing!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return -2; } /* Extract the macromolecular complex identifier: */ if (sscanf (tokenA, "%d", &complexID) != 1) { strcpy (runtimeSP->messageA, "Bad macromolecular complex identifier!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return -3; } /* Check is the requested complex available at all: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /** Prepare the pointer to the current macromolecular complex: **/ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check the number of atoms; for bad */ /* and discarded complexes it is zero: */ if (curr_mol_complexSP->atomsN == 0) continue; /* If macromol. complex is recognized, set the catch flag to one: */ if (curr_mol_complexSP->mol_complexID == complexID) { job_doneF = 1; break; } } /* If the requested complex is not available, return negative value: */ if (job_doneF == 0) { strcpy (runtimeSP->messageA, "The requested complex is not available!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return -4; } /* Prepare the number of residues: */ residuesN = curr_mol_complexSP->residuesN; /* Copy the secondary structure (for selected residues only): */ residuesN = curr_mol_complexSP->residuesN; for (residueI = 0; residueI < residuesN; residueI++) { /* Pointer to the current residue: */ curr_residueSP = curr_mol_complexSP->residueSP + residueI; /* Pointer to the first atom: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* If the first atom is not selected, do not copy the residue name: */ if (first_atomSP->selectedF == 0) continue; /* Copy the secondary structure code: */ *(runtimeSP->sec_structureP + selected_residueI) = *(curr_mol_complexSP->secondary_structureP + residueI); /* Update the selected residue index: */ selected_residueI++; /* Check the number of selected residues: */ if (selected_residueI >= MAXRESIDUES) { strcpy (runtimeSP->messageA, "Secondary structure too long!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return -5; } } /*@@*/ /* This function should be tested with a real structure! */ /* Return positive value on success: */ return 1; } /*===========================================================================*/ garlic-1.6/atom_names.c0000644000076500007650000000351407065456134015413 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= atom_names.c Purpose: Extract atom names from the list. Input: (1) Pointer to SelectS structure, where data will be stored. (2) Pointer to the string with list of atom names. Output: (1) Some data added to SelectS structure. (2) Return value. Return value: (1) Positive on success. (2) Negative on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======extract atom names:==================================================*/ int ExtractAtomNames_ (SelectS *selectSP, char *stringP) { char *P, *tokenP; int nameI; /* Check the string length: */ if (strlen (stringP) == 0) return -1; /* Initialize all_atom_namesF (1 = select all atom names): */ selectSP->all_atom_namesF = 0; /* Initialize the number of atom names: */ selectSP->atom_namesN = 0; /* If wildcard is present, set all_atom_namesF to one and return: */ if (strstr (stringP, "*")) { selectSP->all_atom_namesF = 1; return 1; } /* Parse the list of atom names: */ P = stringP; while ((tokenP = strtok (P, " \t,;")) != NULL) { /** Ensure the proper operation of strtok: **/ P = NULL; /** Copy the token and update the count: **/ nameI = selectSP->atom_namesN; strncpy (selectSP->atom_nameAA[nameI], tokenP, ATOMNAMESIZE - 1); selectSP->atom_nameAA[nameI][ATOMNAMESIZE - 1] = '\0'; /** Update and check the count: **/ selectSP->atom_namesN++; if (selectSP->atom_namesN >= MAXFIELDS) break; } /* Return positive value on success: */ return 1; } /*===========================================================================*/ garlic-1.6/patterns2.script0000644000076500007650000000053207647465600016275 0ustar zuciczucic00000000000000# This example is just a variation of patters.script; read description there. # 2003/04/17 pattern = phe trp tyr ile leu val met / * / asn asp gln glu arg lys / * / asn asp gln glu arg lys select pattern color yellow pattern = asn asp gln glu arg lys / * / asn asp gln glu arg lys / * / phe trp tyr ile leu val met select pattern color green garlic-1.6/cylin_slab.c0000644000076500007650000000542607065470164015412 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= cylin_slab.c Purpose: Check which atoms are inside the cylindrical slab. Cylindrical slab is defined by two concentric cylinders. A given atom is inside the slab if it is outside the inner and inside the outer cylinder. Use this slab type to hide the inner part (the "cork") of a porin-like protein. The y axis is a symmetry axis. Input: (1) Pointer to MolComplexS structure. Output: (1) Slab flag set for each atom. The value one is assigned to atoms inside the slab, zero to the rest. (2) Return value. Return value: The number of atoms inside the slab. ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======cylindrical slab:====================================================*/ size_t CylinSlab_ (MolComplexS *curr_mol_complexSP) { size_t atoms_inside_slabN = 0; size_t atomsN, atomI; AtomS *curr_atomSP; double x0, z0, rho0_squared, rho1_squared; double x, z, rho_squared; /* The number of atoms in a complex: */ atomsN = curr_mol_complexSP->atomsN; /* Copy the slab center coordinates: */ x0 = curr_mol_complexSP->slab_center_vectorS.x; z0 = curr_mol_complexSP->slab_center_vectorS.z; rho0_squared = curr_mol_complexSP->slab_back_relative_position; rho0_squared *= rho0_squared; rho1_squared = curr_mol_complexSP->slab_front_relative_position; rho1_squared *= rho1_squared; /* Set the slab flag for each atom: */ for (atomI = 0; atomI < atomsN; atomI++) { /** Pointer to the current atom: **/ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /** Set the initial values of slab flags to one; this **/ /** will be changed later for atoms outside the slab: **/ curr_atomSP->inside_slabF = 1; curr_atomSP->inside_projected_slabF = 1; /** Distance between the current atom and the cylinder axis: **/ x = curr_atomSP->raw_atomS.x[0] - x0; z = curr_atomSP->raw_atomS.z[0] - z0; rho_squared = x * x + z * z; /** If atom is inside the inner cylinder, set **/ /** slab flag to zero and check the next atom: **/ if (rho_squared < rho0_squared) { curr_atomSP->inside_slabF = 0; curr_atomSP->inside_projected_slabF = 0; continue; } /** If atom is outside the outer slab cylinder: **/ if (rho_squared > rho1_squared) { curr_atomSP->inside_slabF = 0; curr_atomSP->inside_projected_slabF = 0; continue; } /** If this points is reached, current atom is inside the slab: **/ atoms_inside_slabN++; } /* Return the number of atoms inside the slab: */ return atoms_inside_slabN; } /*===========================================================================*/ garlic-1.6/parse_sequence.c0000644000076500007650000000526707747154474016312 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2003 Damir Zucic */ /*============================================================================= parse_sequence.c Purpose: Parse the sequence string. Input: (1) Pointer to RuntimeS structure. (2) Pointer to the string which contains the sequence. Output: (1) Sequence stored to the sequence buffer. (2) Return value. Return value: (1) Positive on success. (2) Negative on failure. Notes: (1) The sequence is expected in three letters code. One letter code may be missinterpreted as valid three letters code. (2) Space, comma, tab and semicolon may be used as separators. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "commands.h" #include "typedefs.h" /*======function prototypes:=================================================*/ char *ExtractToken_ (char *, int, char *, char *); void InitHyphob_ (RuntimeS *); /*======parse sequence string:===============================================*/ int ParseSequence_ (RuntimeS *runtimeSP, char *stringP) { int max_length, i; char *remainderP; char tokenA[SHORTSTRINGSIZE]; char *P; size_t residueI = 0; /* The maximal residue name length: */ max_length = RESNAMESIZE - 1; /* Reset the number of residues in sequence: */ runtimeSP->residuesN = 0; /* Zero initialize the sequence buffer: */ for (i = 0; i < (int) runtimeSP->sequence_buffer_size; i++) { *(runtimeSP->sequenceP + i) = '\0'; } /* Parse the string: */ remainderP = stringP; while ((remainderP = ExtractToken_ (tokenA, SHORTSTRINGSIZE, remainderP, " ,;\t\n")) != NULL) { /* Check the residue name size: */ if ((int) strlen (tokenA) > max_length) { sprintf (runtimeSP->messageA, "Residue name %s too long!", tokenA); runtimeSP->message_length = strlen (runtimeSP->messageA); return -1; } /* Copy the residue name to the sequence buffer: */ P = runtimeSP->sequenceP + max_length * residueI; strcpy (P, tokenA); /* Update the residue index: */ residueI++; } /* Store the number of residues: */ runtimeSP->residuesN = residueI; /* Reinitialize serial numbers: */ for (residueI = 0; residueI < runtimeSP->residuesN; residueI++) { *(runtimeSP->serialIP + residueI) = residueI + 1; } /* Reinitialize disulfide flags: */ for (residueI = 0; residueI < runtimeSP->residuesN; residueI++) { *(runtimeSP->disulfideFP + residueI) = 0; } /* Initialize hydrophobicity values: */ InitHyphob_ (runtimeSP); /* Return positive value on success: */ return 1; } /*===========================================================================*/ garlic-1.6/draw_edit_symbol.c0000644000076500007650000000717707363354274016633 0ustar zuciczucic00000000000000/* Copyright (C) 2001 Damir Zucic */ /*============================================================================= draw_edit_symbol.c Purpose: Draw the edit symbol: squid or seahorse. The squid is drawn at the position of the first selected atom of default macromolecular complex. The seahorse is drawn in the middle of the first bond from the set of bonds which have to be rotated. If editing phi angle, the seahorse will be drawn in the middle of N-CA bond. If editing psi, it will be drawn in the middle of CA-C bond. In all other cases only one bond is selected for editing. The seahorse will be drawn in the middle of this bond. There is no symbol for default editing mode (0 = no editing). Input: (1) Pointer to MolComplexS structure. (2) Number of macromolecular complexes. (3) Pointer to RuntimeS structure. (4) Pointer to ConfigS structure. (5) Pointer to GUIS structure. (6) Pointer to NearestAtomS structure. (7) The number of pixels in the main window free area. (8) The refreshI, used to check the NearestAtomS associated with a given pixel. Output: (1) The edit symbol drawn. (2) Return value. Return value: (1) Zero if editing is off. (2) Negative if there are no atoms or no atom is selected. (3) Positive in all other cases. =============================================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int DrawSquid_ (AtomS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); int DrawSeahorse_ (MolComplexS *, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); /*======draw edit symbol:====================================================*/ int DrawEditSymbol_ (MolComplexS *mol_complexSP, int mol_complexesN, RuntimeS *runtimeSP, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int refreshI) { MolComplexS *default_mol_complexSP; size_t atomsN, atomI; int something_is_selectedF; static AtomS *curr_atomSP; /* Check editing mode: */ if (runtimeSP->edit_modeI == 0) return 0; /* Prepare the pointer to default macromolecular complex: */ default_mol_complexSP = mol_complexSP + runtimeSP->default_complexI; /* Check are there any atoms at all: */ atomsN = default_mol_complexSP->atomsN; if (atomsN == 0) return -1; /* Draw the proper symbol: */ switch (runtimeSP->edit_modeI) { /* Draw squid if editing atom or dimensions: */ case 1: case 101: /* Check is there anything selected at all: */ something_is_selectedF = 0; for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = default_mol_complexSP->atomSP + atomI; /* If the current atom is selected, set */ /* the flag and break from the loop: */ if (curr_atomSP->selectedF) { something_is_selectedF = 1; break; } } if (!something_is_selectedF) return -2; /* Draw squid at the position of the first selected atom: */ DrawSquid_ (curr_atomSP, configSP, guiSP, nearest_atomSP, pixelsN, refreshI); break; /* Editing phi, psi, omega, bond, main chain or side chain: */ case 2: case 3: case 4: case 5: case 6: case 7: DrawSeahorse_ (mol_complexSP, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, refreshI); break; /* Unsupported editing modes: */ default: ; } /* Return positive value on success: */ return 1; } /*===========================================================================*/ garlic-1.6/cylin_fading.c0000644000076500007650000001337107066751535015724 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= cylin_fading.c Purpose: Prepare the left, middle and right color for each atom in a complex. The color fading is cylindrical. The cylinder axis is parallel to y axis (vertical). Input: (1) Pointer to MolComplexS structure. (2) Pointer to GUIS structure. Output: (1) left_colorID, middle_colorID and right_colorID members of AtomS structure initialized for each atom in macromolecular complex. (2) Return value. Return value: (1) On success, the number of atoms which have colors different from near and far color. These atoms are located in the area between the front and back surface. (2) Zero on failure. Notes: (1) Do not skip hidden atoms, the color of these atoms may be used for backbone drawing! =============================================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ unsigned long PixelFromRGBS_ (RGBS *, GUIS *); unsigned long PrepareColor_ (RGBS *, RGBS *, double, GUIS *); /*======cylindrical fading:==================================================*/ size_t CylinFading_ (MolComplexS *curr_mol_complexSP, GUIS *guiSP) { size_t atoms_between_surfacesN = 0; size_t atomsN, atomI; AtomS *curr_atomSP; int surfacesN, surfaceI, inner_surfaceI, outer_surfaceI; double rho_out, rho_out_squared, rho_in, rho_in_squared; double x0, z0; double overall_range, internal_range; double inverse_internal_range; double x, z, rho_squared, rho, delta_rho, scale_factor; int near_surfaceI, far_surfaceI; /* The radius of the front (outer) surface: */ rho_out = curr_mol_complexSP->fading_front_relative_position; rho_out_squared = rho_out * rho_out; /* The radius of the back (inner) surface: */ rho_in = curr_mol_complexSP->fading_back_relative_position; rho_in_squared = rho_in * rho_in; /* Check: */ if (rho_in >= rho_out) return 0; /* The overall range: */ overall_range = rho_out - rho_in; /* Fading center coordinates: */ x0 = curr_mol_complexSP->fading_center_vectorS.x; z0 = curr_mol_complexSP->fading_center_vectorS.z; /* The number of atoms in a complex: */ atomsN = curr_mol_complexSP->atomsN; /* Assign three colors to each atom: */ for (atomI = 0; atomI < atomsN; atomI++) { /** Pointer to the current atom: **/ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /** Is atom out of slab? **/ if (!curr_atomSP->inside_slabF) continue; /** Check the number of color fading surfaces: **/ surfacesN = curr_atomSP->surfacesN; /*** If there is only one, there is no fading: ***/ if (surfacesN == 1) { curr_atomSP->left_colorID = PixelFromRGBS_ (curr_atomSP->left_rgbSA, guiSP); curr_atomSP->middle_colorID = PixelFromRGBS_ (curr_atomSP->middle_rgbSA, guiSP); curr_atomSP->right_colorID = PixelFromRGBS_ (curr_atomSP->right_rgbSA, guiSP); continue; } /** Distance between the current atom and the fading axis: **/ x = curr_atomSP->raw_atomS.x[0] - x0; z = curr_atomSP->raw_atomS.z[0] - z0; rho_squared = x * x + z * z; /** Atoms which are too far from the fading **/ /** axis should be treated as near atoms: **/ if (rho_squared >= rho_out_squared) { curr_atomSP->left_colorID = PixelFromRGBS_ (curr_atomSP->left_rgbSA, guiSP); curr_atomSP->middle_colorID = PixelFromRGBS_ (curr_atomSP->middle_rgbSA, guiSP); curr_atomSP->right_colorID = PixelFromRGBS_ (curr_atomSP->right_rgbSA, guiSP); continue; } /** Atoms which are to close to the fading **/ /** axis should be treated as far atoms: **/ if (rho_squared <= rho_in_squared) { surfaceI = surfacesN - 1; curr_atomSP->left_colorID = PixelFromRGBS_ (curr_atomSP->left_rgbSA + surfaceI, guiSP); curr_atomSP->middle_colorID = PixelFromRGBS_ (curr_atomSP->middle_rgbSA + surfaceI, guiSP); curr_atomSP->right_colorID = PixelFromRGBS_ (curr_atomSP->right_rgbSA + surfaceI, guiSP); continue; } /** If this point is reached, current atom is in **/ /** the area between two surfaces; colors should **/ /** be calculated weighting near and far colors: **/ /** Prepare auxiliary variables: **/ if (surfacesN > 1) { rho = sqrt (rho_squared); internal_range = overall_range / (double) (surfacesN - 1); inverse_internal_range = 1.0 / internal_range; inner_surfaceI = (int) floor ((rho - rho_in) * inverse_internal_range); outer_surfaceI = inner_surfaceI + 1; delta_rho = outer_surfaceI * internal_range + rho_in - rho; scale_factor = delta_rho * inverse_internal_range; far_surfaceI = surfacesN - inner_surfaceI - 1; near_surfaceI = far_surfaceI - 1; } else { scale_factor = 0.0; far_surfaceI = 0; near_surfaceI = 0; } /** Left color: **/ curr_atomSP->left_colorID = PrepareColor_ (curr_atomSP->left_rgbSA + near_surfaceI, curr_atomSP->left_rgbSA + far_surfaceI, scale_factor, guiSP); /** Middle color: **/ curr_atomSP->middle_colorID = PrepareColor_ (curr_atomSP->middle_rgbSA + near_surfaceI, curr_atomSP->middle_rgbSA + far_surfaceI, scale_factor, guiSP); /** Right color: **/ curr_atomSP->right_colorID = PrepareColor_ (curr_atomSP->right_rgbSA + near_surfaceI, curr_atomSP->right_rgbSA + far_surfaceI, scale_factor, guiSP); /** Update the number of atoms in the area between two surfaces: **/ atoms_between_surfacesN++; } /* Return the number of atoms which have */ /* colors different from near and far colors: */ return atoms_between_surfacesN; } /*===========================================================================*/ garlic-1.6/extract_ncaco.c0000644000076500007650000000606707272236321016105 0ustar zuciczucic00000000000000/* Copyright (C) 2000, 2001 Damir Zucic */ /*============================================================================= extract_ncaco.c Purpose: Extract N, CA, C and O coordinates for a given residue. Input: (1) Pointer to VectorS structure, where N coord. will be stored. (2) Pointer to VectorS structure, where CA coord. will be stored. (3) Pointer to VectorS structure, where C coord. will be stored. (4) Pointer to VectorS structure, where O coord. will be stored. (5) Pointer to AtomS structure, pointing to the first element of the atomic array. (6) Index of the first atom of a given residue. (7) Index of the last atom of a given residue. Output: (1) VectorS structures filled with data. (2) Return value. Return value: (1) The number of successfully extracted vectors (at least zero, at most four). Notes: (1) Some files contain more than one entry for some atoms. Garlic uses only the first entry and discards other entries for the same atom. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======extract N, CA, C and O coordinates:==================================*/ int ExtractNCACO_ (VectorS *N_vectorSP, VectorS *CA_vectorSP, VectorS *C_vectorSP, VectorS *O_vectorSP, AtomS *atomSP, size_t atom_startI, size_t atom_endI) { int vectors_extractedN = 0; size_t atomI; AtomS *curr_atomSP; int N_foundF = 0, CA_foundF = 0, C_foundF = 0, O_foundF = 0; /* Scan the given residue: */ for (atomI = atom_startI; atomI <= atom_endI; atomI++) { /* Pointer to the current atom: */ curr_atomSP = atomSP + atomI; /* N: */ if (strcmp (curr_atomSP->raw_atomS.pure_atom_nameA, "N") == 0) { if (N_foundF) continue; N_vectorSP->x = curr_atomSP->raw_atomS.x[0]; N_vectorSP->y = curr_atomSP->raw_atomS.y; N_vectorSP->z = curr_atomSP->raw_atomS.z[0]; vectors_extractedN++; N_foundF = 1; } /* CA: */ else if (strcmp (curr_atomSP->raw_atomS.pure_atom_nameA, "CA") == 0) { if (CA_foundF) continue; CA_vectorSP->x = curr_atomSP->raw_atomS.x[0]; CA_vectorSP->y = curr_atomSP->raw_atomS.y; CA_vectorSP->z = curr_atomSP->raw_atomS.z[0]; vectors_extractedN++; CA_foundF = 1; } /* C: */ else if (strcmp (curr_atomSP->raw_atomS.pure_atom_nameA, "C") == 0) { if (C_foundF) continue; C_vectorSP->x = curr_atomSP->raw_atomS.x[0]; C_vectorSP->y = curr_atomSP->raw_atomS.y; C_vectorSP->z = curr_atomSP->raw_atomS.z[0]; vectors_extractedN++; C_foundF = 1; } /* O: */ else if (strcmp (curr_atomSP->raw_atomS.pure_atom_nameA, "O") == 0) { if (O_foundF) continue; O_vectorSP->x = curr_atomSP->raw_atomS.x[0]; O_vectorSP->y = curr_atomSP->raw_atomS.y; O_vectorSP->z = curr_atomSP->raw_atomS.z[0]; vectors_extractedN++; O_foundF = 1; } } /* Return the number of extracted vectors: */ return vectors_extractedN; } /*===========================================================================*/ garlic-1.6/change_slab.c0000644000076500007650000000351307465733424015521 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2002 Damir Zucic */ /*============================================================================= change_slab.c Purpose: Change slab mode for each caught macromolecular complex. Input: (1) Pointer to MolComplexS structure. (2) Number of macromolecular complexes. (3) Slab mode index. Output: (1) Slab mode changed for each caught macromolecular complex. (2) Return value. Return value: (1) The number of complexes for which the slab mode was changed. ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ void InitSlab_ (MolComplexS *); /*======change slab mode:====================================================*/ int ChangeSlab_ (MolComplexS *mol_complexSP, int mol_complexesN, int slab_modeI) { int changesN = 0; int mol_complexI; MolComplexS *curr_mol_complexSP; /* Check every macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /** Pointer to the current macromolecular complex: **/ curr_mol_complexSP = mol_complexSP + mol_complexI; /** Do not apply slab if position has not changed: **/ if (curr_mol_complexSP->catchF== 0) continue; /** Change the slab mode: **/ curr_mol_complexSP->slab_modeI = slab_modeI; /** Initialize slab: **/ InitSlab_ (curr_mol_complexSP); /** Change the position_changedF: **/ curr_mol_complexSP->position_changedF = 1; /** Increase the count: **/ changesN++; } /* Return the number of m. complexes for */ /* for which the slab mode was changed: */ return changesN; } /*===========================================================================*/ garlic-1.6/trp.pdb0000644000076500007650000000421307065415526014415 0ustar zuciczucic00000000000000ATOM 1 C 1 -2.257 -0.302 0.846 1.00 0.00 ATOM 2 C 1 -0.944 0.146 1.487 1.00 0.00 ATOM 3 C 1 0.214 -0.502 0.765 1.00 0.00 ATOM 4 C 1 1.098 0.133 -0.115 1.00 0.00 ATOM 5 C 1 2.017 -0.826 -0.559 1.00 0.00 ATOM 6 N 1 1.701 -2.032 0.041 1.00 0.00 ATOM 7 C 1 0.598 -1.845 0.854 1.00 0.00 ATOM 8 C 1 3.027 -0.466 -1.458 1.00 0.00 ATOM 9 C 1 3.119 0.855 -1.915 1.00 0.00 ATOM 10 C 1 2.201 1.814 -1.472 1.00 0.00 ATOM 11 C 1 1.191 1.453 -0.572 1.00 0.00 ATOM 12 N 1 -2.332 0.219 -0.553 1.00 0.00 ATOM 13 C 1 -3.417 0.238 1.647 1.00 0.00 ATOM 14 O 1 -4.219 -0.529 2.155 1.00 0.00 ATOM 15 O 1 -3.558 1.492 1.794 1.00 0.00 ATOM 16 H 1 0.116 -2.603 1.453 1.00 0.00 ATOM 17 H 1 2.194 -2.903 -0.093 1.00 0.00 ATOM 18 H 1 3.899 1.133 -2.609 1.00 0.00 ATOM 19 H 1 2.272 2.833 -1.824 1.00 0.00 ATOM 20 H 1 0.482 2.194 -0.230 1.00 0.00 ATOM 21 H 1 3.736 -1.205 -1.799 1.00 0.00 ATOM 22 H 1 -0.856 1.228 1.417 1.00 0.00 ATOM 23 H 1 -0.931 -0.153 2.533 1.00 0.00 ATOM 24 H 1 -2.302 -1.389 0.832 1.00 0.00 ATOM 25 H 1 -3.222 -0.084 -0.987 1.00 0.00 ATOM 26 H 1 -1.537 -0.152 -1.102 1.00 0.00 ATOM 27 H 1 -2.290 1.253 -0.539 1.00 0.00 garlic-1.6/size_hints.c0000644000076500007650000000416110402377243015436 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2006 Damir Zucic */ /*============================================================================= size_hints.c Purpose: Set size hints for main window. Part of this job could be done before. This function just copies data from one reserved storage to another. Input: (1) Pointer to GUIS structure, where input data will be read from and output data will be stored. (2) Pointer to ConfigS structure, with some input data. Output: (1) Some data stored to GUIS structure. Return value: No return value. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======set size hints for the main window:==================================*/ void SetSizeHints_ (GUIS *guiSP, ConfigS *configSP) { /* Set main window size hints (obsolete parameters are not initialized): */ guiSP->main_winS.size_hintsS.flags = PAllHints; guiSP->main_winS.size_hintsS.min_width = 300; guiSP->main_winS.size_hintsS.min_height = 200; if ((int) guiSP->screen_width <= configSP->max_main_win_width) { guiSP->main_winS.size_hintsS.max_width = guiSP->screen_width; } else guiSP->main_winS.size_hintsS.max_width = configSP->max_main_win_width; if ((int) guiSP->screen_height <= configSP->max_main_win_height) { guiSP->main_winS.size_hintsS.max_height = guiSP->screen_height; } else guiSP->main_winS.size_hintsS.max_height = configSP->max_main_win_height; guiSP->main_winS.size_hintsS.width_inc = 1; guiSP->main_winS.size_hintsS.height_inc = 1; guiSP->main_winS.size_hintsS.min_aspect.x = 1; guiSP->main_winS.size_hintsS.min_aspect.y = 4; guiSP->main_winS.size_hintsS.max_aspect.x = 4; guiSP->main_winS.size_hintsS.max_aspect.y = 1; guiSP->main_winS.size_hintsS.base_width = guiSP->main_winS.width; guiSP->main_winS.size_hintsS.base_height = guiSP->main_winS.height; guiSP->main_winS.size_hintsS.win_gravity = NorthWestGravity; } /*===========================================================================*/ garlic-1.6/hide_control.c0000644000076500007650000000243107065471444015737 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= hide_control.c Purpose: Hide control and resize output window. Input: (1) Pointer to GUIS structure. Output: (1) Control window hidden. Return value: No return value. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======hide control and resize output window:===============================*/ void HideControlWindow_ (GUIS *guiSP) { int border_width = 1; /* Hide the control window: */ XUnmapWindow (guiSP->displaySP, guiSP->control_winS.ID); /* Move the output window to the new position: */ guiSP->output_winS.y0 = guiSP->control_winS.y0; XMoveWindow (guiSP->displaySP, guiSP->output_winS.ID, guiSP->output_winS.x0, guiSP->output_winS.y0); /* Resize the output window: */ guiSP->output_winS.height = guiSP->main_winS.height - 2 * border_width - 2; XResizeWindow (guiSP->displaySP, guiSP->output_winS.ID, guiSP->output_winS.width, guiSP->output_winS.height); } /*===========================================================================*/ garlic-1.6/HISTORY0000644000076500007650000000136607642261111014201 0ustar zuciczucic00000000000000 GARLIC HISTORY Garlic was born September 30, 1998. At that time I needed a good molecular visualization program and almost the only thing at hand was RasMol. I had some hard time with RasMol so I tryed to adapt it to my needs. However, I realized that it is very hard to read and change RasMol source code, so I decided to write my own molecular visualization program. Further, I decided to learn programming for the X window system, and this is my first serious program written for X11. Since 1997 I use GNU/Linux software, so I concluded that it would be fair to add something useful and modern to the existing collection of free software because this software significantly improved my working conditions. Damir Zucic, Osijek, April 01, 2003. garlic-1.6/resize_complex.c0000644000076500007650000001104207463432567016321 0ustar zuciczucic00000000000000/* Copyright (C) 2001, 2002 Damir Zucic */ /*============================================================================= resize_complex.c Purpose: Resize the selected portion of the macromolecular complex. This operation is not suitable for real molecular structures. It is suitable for special objects, i.e. the objects which are build from imaginary atoms (quarkonium and jellium). The operation will affect only one of three dimensions of the object. If the size should be proportionaly changed, three consecutive operations (in three different directions) are required. Input: (1) Pointer to MolComplexS structure, with macromolecular data to be modified. (2) Translation shift (will be replaced by three scale factors). (3) Axis identifier (1 = x, 2 = y, 3 = z). (4) Pointer to ConfigS structure. Output: (1) The structure will be resized. Return value: No return value. Notes: (1) The shift is replaced by three scale factors. Two of these factors are equal to one. (2) This function will not update the geometric center and some other geometric data. Use the command CEN (CENTER) to refresh these parameters. ========includes:============================================================*/ #include #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int PrepareStereoData_ (MolComplexS *, ConfigS *); /*======resize macromolecular complex:=======================================*/ void ResizeComplex_ (MolComplexS *mol_complexSP, double shift, int axisID, ConfigS *configSP) { double abs_shift; double scale_factor_x = 1.0; double scale_factor_y = 1.0; double scale_factor_z = 1.0; double x0, y0, z0; size_t atomI; AtomS *curr_atomSP; double delta_x, delta_y, delta_z; /* Prepare the absolute value of the translation shift: */ abs_shift = fabs (shift); /* Replace the translation shift with three scale factors: */ if (fabs (abs_shift - configSP->translation_stepA[0]) < 0.0001) { scale_factor_x = 1.01; scale_factor_y = 1.01; scale_factor_z = 1.01; } else if (fabs (abs_shift - configSP->translation_stepA[1]) < 0.0001) { scale_factor_x = 1.05; scale_factor_y = 1.05; scale_factor_z = 1.05; } else if (fabs (abs_shift - configSP->translation_stepA[2]) < 0.0001) { scale_factor_x = 1.15; scale_factor_y = 1.15; scale_factor_z = 1.15; } else if (fabs (abs_shift - configSP->translation_stepA[3]) < 0.0001) { scale_factor_x = 1.50; scale_factor_y = 1.50; scale_factor_z = 1.50; } else if (fabs (abs_shift - configSP->translation_stepA[4]) < 0.0001) { scale_factor_x = 2.00; scale_factor_y = 2.00; scale_factor_z = 2.00; } /* The scale factors should be used to reduce the */ /* size of the object if the shift is negative: */ if (shift < 0.0) { scale_factor_x = 1.0 / scale_factor_x; scale_factor_y = 1.0 / scale_factor_y; scale_factor_z = 1.0 / scale_factor_z; } /* Reset two scale factors: */ if (axisID == 1) { scale_factor_y = 1.0; scale_factor_z = 1.0; } else if (axisID == 2) { scale_factor_x = 1.0; scale_factor_z = 1.0; } else if (axisID == 3) { scale_factor_x = 1.0; scale_factor_y = 1.0; } /* Prepare the coordinates of the geometric center: */ x0 = mol_complexSP->geometric_center_vectorS.x; y0 = mol_complexSP->geometric_center_vectorS.y; z0 = mol_complexSP->geometric_center_vectorS.z; /* Scan the macromolecular complex, atom by atom: */ for (atomI = 0; atomI < mol_complexSP->atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = mol_complexSP->atomSP + atomI; /* If this atom is not selected, skip it: */ if (curr_atomSP->selectedF == 0) continue; /* The distance from the current atom to the geometric center: */ delta_x = curr_atomSP->raw_atomS.x[0] - x0; delta_y = curr_atomSP->raw_atomS.y - y0; delta_z = curr_atomSP->raw_atomS.z[0] - z0; /* Scale this distance: */ delta_x = scale_factor_x * delta_x; delta_y = scale_factor_y * delta_y; delta_z = scale_factor_z * delta_z; /* Update the position of the current atom: */ curr_atomSP->raw_atomS.x[0] = x0 + delta_x; curr_atomSP->raw_atomS.y = y0 + delta_y; curr_atomSP->raw_atomS.z[0] = z0 + delta_z; } /* Update stereo data, if required: */ if (configSP->stereoF) PrepareStereoData_ (mol_complexSP, configSP); /* Update the position_changedF flag: */ mol_complexSP->position_changedF = 1; } /*===========================================================================*/ garlic-1.6/pdb_id.c0000644000076500007650000000435107104006760014477 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= pdb_id.c Purpose: If the input line contains the keyword HEADER, extract the unique PDB identifier. HEADER line should be the first line of the PDB entry, but be careful - if your file is stored in HTML format, the keyword HEADER may be pushed from the first position in the first nonempty line. The unique PDB identifier may be extracted from characters 63-66 in the HEADER line, if the first character is indexed with index one. In the C language, this means that characters 62-65 should be copied. Input: (1) Pointer to MolComplexS structure. (2) Input line. Output: (1) If the line is identified as HEADER line, the unique PDB identifier may be found and copied to MolComplexS structure. data about C-alpha atoms. (2) Return value. Return value: (1) Positive on success. (2) Negative on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ void ErrorMessage_ (char *, char *, char *, char *, char *, char *, char *); /*======try to extract the unique PDB identifier:============================*/ int PDBIdentifier_ (MolComplexS *mol_complexSP, char *stringP) { char *P; int record_length; int first_char_pos = 62, last_char_pos = 65; static char codeA[PDBCODESIZE] = "????"; /* If line does not contain keyword HEADER, return negative value: */ P = strstr (stringP, "HEADER"); if (P == NULL) return -1; /* Check the length of the line, counting from */ /* the first character of the keyword HEADER: */ record_length = strlen (P); if (record_length < last_char_pos + 1) return -2; /* Extract the unique PDB identifier: */ strncpy (codeA, P + first_char_pos, PDBCODESIZE - 1); codeA[PDBCODESIZE - 1] = '\0'; strcpy (mol_complexSP->unique_PDB_codeA, codeA); /* Return positive value on success: */ return 1; } /*===========================================================================*/ garlic-1.6/atoms.script0000644000076500007650000000275707540357627015512 0ustar zuciczucic00000000000000# Show all drawing styles used to draw atoms. Bonds are hidden! # This script requires garlic version 1.2! # Atom style 0: load trp.pdb pos -24 -15 0 ato 0 bon 0 tag "0" # Now inform user that refreshing is off: title 1 50 50 "Please be patient ..." # Switch refreshing off: refresh off # Atom style 1: load trp.pdb pos -12 -15 0 ato 1 bon 0 tag "1" # Atom style 2: load trp.pdb pos 0 -15 0 ato 2 bon 0 tag "2" # Atom style 3: load trp.pdb pos 12 -15 0 ato 3 bon 0 tag "3" # Atom style 4: load trp.pdb pos 24 -15 0 ato 4 bon 0 tag "4" # Atom style 5: load trp.pdb pos -24 -5 0 ato 5 bon 0 tag "5" # Atom style 6: load trp.pdb pos -12 -5 0 ato 6 bon 0 tag "6" # Atom style 7: load trp.pdb pos 0 -5 0 ato 7 bon 0 tag "7" # Atom style bal: load trp.pdb pos 12 -5 0 ato bal bon 0 tag "bal (ball)" # Atom style ba2: load trp.pdb pos 24 -5 0 ato ba2 bon 0 tag "ba2" #Atom style small: load trp.pdb pos -24 5 0 ato sma bon 0 tag "sma (small)" # Atom style sm2: load trp.pdb pos -12 5 0 ato sm2 bon 0 tag "sm2" # Atom style covalent: load trp.pdb pos 0 5 0 ato cov bon 0 tag "cov (covalent)" #Atom style co2: load trp.pdb pos 12 5 0 ato co2 bon 0 tag "co2" #Atom style spacefill: load trp.pdb pos -24 15 0 ato spa bon 0 tag "spa (spacefill)" #Atom style sp2: load trp.pdb pos -12 15 0 ato sp2 bon 0 tag "sp2" #Atom style big: load trp.pdb pos 0 15 0 ato big bon 0 tag "big" #Atom style bi2: load trp.pdb pos 12 15 0 ato bi2 bon 0 tag "bi2" # Hide the title: title 1 off # Switch refreshing on: refresh garlic-1.6/load.c0000644000076500007650000001237707611254505014211 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2003 Damir Zucic */ /*============================================================================= load.c Purpose: Execute load command: load the specified macromolecular complex from file. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Pointer to the number of macromolecular complexes. (3) Pointer to the next macromolecular complex identifier. (4) Pointer to RuntimeS structure, with some runtime data. (5) Pointer to ConfigS structure, with configuration data. (6) Pointer to GUIS structure, with GUI data. (7) Pointer to NearestAtomS structure. (8) The number of pixels in the main window free area. (9) Pointer to refreshI. Output: (1) New macromolecular complex loaded into memory. (2) The number of complexes updated. (3) The next macromolecular complex identifier updated. (4) Return value. Return value: (1) Positive (command) code on success. (2) Negative (error) code on failure. Notes: (1) The value of refreshI (*refreshIP) may be changed in this function or in some function called by this function. It is checked in EventLoop_ (see event_loop.c). It is assumed that refreshI is updated no more than once in each event handling function. If this is not the case, the care should be taken to avoid refreshI overflow. (2) This functions resets the edit mode index. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "commands.h" #include "typedefs.h" /*======function prototypes:=================================================*/ char *ExtractToken_ (char *, int, char *, char *); int LoadComplex_ (int *, MolComplexS *, int *, int *, char *, ConfigS *, GUIS *); size_t MainRefresh_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); int ControlRefresh_ (MolComplexS *, ConfigS *, GUIS *); /*======execute load command:================================================*/ int Load_ (MolComplexS *mol_complexSP, int *mol_complexesNP, int *next_mol_complexIDP, RuntimeS *runtimeSP, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int *refreshIP) { char *remainderP; char tokenA[STRINGSIZE]; static char messageA[SHORTSTRINGSIZE] = "Loading file ..."; int message_length, text_width; int frame_width, frame_height, screen_x0, screen_y0; int n; /* Skip the first token: */ remainderP = ExtractToken_ (tokenA, STRINGSIZE, runtimeSP->curr_commandA, " \t\n"); if (!remainderP) return ERROR_LOAD; /* The second token should contain the file name: */ remainderP = ExtractToken_ (tokenA, STRINGSIZE, remainderP, " \t\n"); if (!remainderP) { strcpy (runtimeSP->messageA, "Missing input file name!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_NO_FILE_NAME; } /* Inform user that loading may take some time: */ message_length = strlen (messageA); text_width = XTextWidth (guiSP->main_winS.fontSP, messageA, message_length); frame_width = text_width + 50; frame_height = 4 * guiSP->main_winS.text_line_height; screen_x0 = (guiSP->main_win_free_area_width - frame_width) / 2; screen_y0 = (guiSP->main_win_free_area_height - frame_height) / 2; XSetForeground (guiSP->displaySP, guiSP->theGCA[0], guiSP->dark_red_colorID); XFillRectangle (guiSP->displaySP, guiSP->main_winS.ID, guiSP->theGCA[0], screen_x0, screen_y0, frame_width, frame_height); XSetForeground (guiSP->displaySP, guiSP->theGCA[0], guiSP->yellow_colorID); screen_x0 = (guiSP->main_win_free_area_width - text_width) / 2; screen_y0 = (guiSP->main_win_free_area_height + guiSP->main_winS.text_line_height) / 2; XDrawString (guiSP->displaySP, guiSP->main_winS.ID, guiSP->theGCA[0], screen_x0, screen_y0, messageA, message_length); XFlush (guiSP->displaySP); /* Try to read file: */ n = LoadComplex_ (&runtimeSP->groupF, mol_complexSP, mol_complexesNP, next_mol_complexIDP, tokenA, configSP, guiSP); if (n < 0) { sprintf (runtimeSP->messageA, "Unable to open file %s!", tokenA); runtimeSP->message_length = strlen (runtimeSP->messageA); (*refreshIP)++; MainRefresh_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); return ERROR_OPEN_FAILURE; } /* The new complex will be a new default caught complex: */ if (*mol_complexesNP > 0) { runtimeSP->default_complexI = *mol_complexesNP - 1; } /* Reset the editing mode index: */ runtimeSP->edit_modeI = 0; /* Reset the edit_single_modeF flag: */ runtimeSP->edit_single_bondF = 0; /* Reset the main window mode index: */ guiSP->main_window_modeI = 0; /* Refresh the main window: */ (*refreshIP)++; MainRefresh_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); /* Refresh the control window: */ ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); /* Return positive value on success: */ return COMMAND_LOAD; } /*===========================================================================*/ garlic-1.6/chi5_from_cdnecznh1.c0000644000076500007650000000731507342225452017076 0ustar zuciczucic00000000000000/* Copyright (C) 2001 Damir Zucic */ /*============================================================================= chi5_from_cdnecznh1.c Purpose: Calculate dihedral angle chi5, using CD, NE, CZ and NH1 coordinates. Input: (1) Pointer to AtomS structure, pointing to the first atom of the current macromolecular complex. (2) Index of the first atom of the current residue. (3) Index of the last atom of the currrent residue. Output: Return value. Return value: (1) Dihedral angle chi5, on success. (2) BADDIHEDANGLE on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int ExtractFourAtoms_ (VectorS *, VectorS *, VectorS *, VectorS *, char *, char *, char *, char *, AtomS *, size_t, size_t); void VectorProduct_ (VectorS *, VectorS *, VectorS *); double AbsoluteValue_ (VectorS *); double ScalarProduct_ (VectorS *, VectorS *); /*======calculate chi5 from CD, NE, CZ and NH1:===============================*/ double Chi5FromCDNECZNH1_ (AtomS *atomSP, size_t atom_startI, size_t atom_endI) { static VectorS CD_vectorS, NE_vectorS, CZ_vectorS, NH1_vectorS; int n; VectorS NE_CD_vectorS, NE_CZ_vectorS; VectorS CZ_NE_vectorS, CZ_NH1_vectorS; VectorS u1S, u2S; VectorS v1S, v2S; double denom, ratio, alpha; double chi5; /* Extract CD, NE, CZ and NH1 coordinates: */ n = ExtractFourAtoms_ (&CD_vectorS, &NE_vectorS, &CZ_vectorS, &NH1_vectorS, "CD", "NE", "CZ", "NH1", atomSP, atom_startI, atom_endI); /* All four atoms are required to calculate the angle chi5: */ if (n < 4) return BADDIHEDANGLE; /* The first pair of auxiliary vectors: */ NE_CD_vectorS.x = CD_vectorS.x - NE_vectorS.x; NE_CD_vectorS.y = CD_vectorS.y - NE_vectorS.y; NE_CD_vectorS.z = CD_vectorS.z - NE_vectorS.z; NE_CZ_vectorS.x = CZ_vectorS.x - NE_vectorS.x; NE_CZ_vectorS.y = CZ_vectorS.y - NE_vectorS.y; NE_CZ_vectorS.z = CZ_vectorS.z - NE_vectorS.z; /* The second pair of auxiliary vectors: */ CZ_NE_vectorS.x = NE_vectorS.x - CZ_vectorS.x; CZ_NE_vectorS.y = NE_vectorS.y - CZ_vectorS.y; CZ_NE_vectorS.z = NE_vectorS.z - CZ_vectorS.z; CZ_NH1_vectorS.x = NH1_vectorS.x - CZ_vectorS.x; CZ_NH1_vectorS.y = NH1_vectorS.y - CZ_vectorS.y; CZ_NH1_vectorS.z = NH1_vectorS.z - CZ_vectorS.z; /* Two vectors perpendicular to NE_CZ_vectorS, mutually orthogonal, */ /* the second in the plane defined by NE_CD_vectorS and NE_CZ_vectorS: */ VectorProduct_ (&u1S, &NE_CD_vectorS, &NE_CZ_vectorS); VectorProduct_ (&u2S, &u1S, &NE_CZ_vectorS); /* Two vectors perpendicular to CZ_NE_vectorS, mutually orthogonal, */ /* the second in the plane defined by CZ_NE_vectorS and CZ_NH1_vectorS: */ VectorProduct_ (&v1S, &CZ_NE_vectorS, &CZ_NH1_vectorS); VectorProduct_ (&v2S, &CZ_NE_vectorS, &v1S); /* Calculate the angle alpha, which will be used to calculate chi5: */ /* Avoid division by zero: */ denom = AbsoluteValue_ (&u1S) * AbsoluteValue_ (&v1S); if (denom == 0.0) return BADDIHEDANGLE; /* Use the scalar product to calculate the cosine of the angle: */ ratio = ScalarProduct_ (&u1S, &v1S) / denom; /* Arc cosine is very sensitive to floating point errors: */ if (ratio <= -1.0) alpha = 3.1415927; else if (ratio >= 1.0) alpha = 0.0; else alpha = acos (ratio); /* There are two possible solutions; the right one is resolved here: */ if (ScalarProduct_ (&v2S, &u1S) >= 0) chi5 = alpha; else chi5 = -alpha; /* Return the angle (in radians): */ return chi5; } /*===========================================================================*/ garlic-1.6/borneol.pdb0000644000076500007650000000763307626372475015271 0ustar zuciczucic00000000000000HEADER FLAVOR: CARDAMOM, GINGER COMPND BORNEOL AUTHOR GLACTONE HETATM 1 C -0.841 -1.240 1.182 HETATM 2 C 0.400 -0.335 1.353 HETATM 3 C 1.478 -0.875 0.387 HETATM 4 C 0.948 -0.416 -0.977 HETATM 5 C -1.391 -0.790 -0.185 HETATM 6 C -0.374 0.294 -0.623 HETATM 7 C -0.031 1.006 0.713 HETATM 9 O 0.752 -1.519 -1.862 HETATM 10 C 1.094 2.059 0.642 HETATM 11 C -1.211 1.694 1.430 HETATM 12 C -0.897 1.188 -1.747 HETATM 23 H -1.579 -1.074 2.000 HETATM 24 H -0.580 -2.322 1.200 HETATM 29 H 0.748 -0.260 2.406 HETATM 25 H 1.598 -1.978 0.463 HETATM 26 H 2.474 -0.431 0.610 HETATM 8 H 1.661 0.270 -1.487 HETATM 27 H -2.417 -0.367 -0.091 HETATM 28 H -1.474 -1.629 -0.910 HETATM 13 H 1.603 -1.793 -2.160 HETATM 14 H 2.023 1.731 0.134 HETATM 15 H 1.397 2.372 1.667 HETATM 16 H 0.751 2.969 0.100 HETATM 17 H -2.120 1.074 1.556 HETATM 18 H -1.533 2.606 0.878 HETATM 19 H -0.910 2.011 2.455 HETATM 20 H -0.152 1.966 -2.026 HETATM 21 H -1.835 1.707 -1.448 HETATM 22 H -1.117 0.584 -2.656 CONECT 1 2 5 23 24 CONECT 2 1 3 7 29 CONECT 3 2 4 25 26 CONECT 4 3 6 9 8 CONECT 5 1 6 27 28 CONECT 6 4 5 7 12 CONECT 7 2 6 10 11 CONECT 9 4 13 CONECT 10 7 14 15 16 CONECT 11 7 17 18 19 CONECT 12 6 20 21 22 CONECT 23 1 CONECT 24 1 CONECT 29 2 CONECT 25 3 CONECT 26 3 CONECT 8 4 CONECT 27 5 CONECT 28 5 CONECT 13 9 CONECT 14 10 CONECT 15 10 CONECT 16 10 CONECT 17 11 CONECT 18 11 CONECT 19 11 CONECT 20 12 CONECT 21 12 CONECT 22 12 END garlic-1.6/draw_titles.c0000644000076500007650000000342607611073715015610 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= draw titles.c Purpose: Draw titles. Input: (1) Pointer to RuntimeS structure. (2) Pointer to GUIS structure. Output: (1) Titles drawn to the hidden pixmap. (2) Return value. Return value: The number of titles drawn. =============================================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======draw titles:=========================================================*/ int DrawTitles_ (RuntimeS *runtimeSP, GUIS *guiSP) { int titles_drawnN = 0; int titleI; char *curr_titleP; int curr_title_length; int screen_x, screen_y; /* Prepare the text color: */ XSetForeground (guiSP->displaySP, guiSP->theGCA[0], guiSP->main_winS.fg_colorID); /* Scan the set of titles: */ for (titleI = 0; titleI < MAXTITLES; titleI++) { /** Do not draw hidden titles: **/ if (runtimeSP->title_hiddenF[titleI] != 0) continue; /** Pointer to the current title: **/ curr_titleP = runtimeSP->titlesP + titleI * TITLESTRINGSIZE; /** Do not draw empty titles: **/ curr_title_length = strlen (curr_titleP); if (curr_title_length == 0) continue; /** String position: **/ screen_x = runtimeSP->title_screen_x[titleI]; screen_y = runtimeSP->title_screen_y[titleI]; /** Draw the string: **/ XDrawString (guiSP->displaySP, guiSP->main_winS.ID, guiSP->theGCA[0], screen_x, screen_y, curr_titleP, curr_title_length); } /* Return the number of titles that were drawn: */ return titles_drawnN; } /*===========================================================================*/ garlic-1.6/planar_slab.c0000644000076500007650000000477207065474267015564 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= planar_slab.c Purpose: Check which atoms of a given macromolecular complex are inside the planar slab. Planar slab is defined by two parallel planes. It is always perpendicular to z axis. If you need different planar slab orientation, write a new function. Input: (1) Pointer to MolComplexS structure. Output: (1) Slab flag set for each atom. The value one is assigned to atoms inside the slab, zero to the rest. (2) Return value. Return value: The number of atoms inside the slab. ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======apply planar slab:===================================================*/ size_t PlanarSlab_ (MolComplexS *curr_mol_complexSP) { size_t atoms_inside_slabN = 0; size_t atomsN, atomI; AtomS *curr_atomSP; double z0, z1; /* The number of atoms in a complex: */ atomsN = curr_mol_complexSP->atomsN; /* The z coordinate of the front (near) surface: */ z0 = curr_mol_complexSP->slab_front_relative_position + curr_mol_complexSP->slab_center_vectorS.z; /* The z coordinate of the back (far) surface: */ z1 = curr_mol_complexSP->slab_back_relative_position + curr_mol_complexSP->slab_center_vectorS.z; /* Set the slab flag for each atom: */ for (atomI = 0; atomI < atomsN; atomI++) { /** Pointer to the current atom: **/ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /** Set the initial values of slab flags to one; this **/ /** will be changed later for atoms outside the slab: **/ curr_atomSP->inside_slabF = 1; curr_atomSP->inside_projected_slabF = 1; /** If current atom is closer to the observer than the front **/ /** slab plane, set flag to zero and check the next atom: **/ if (curr_atomSP->raw_atomS.z[0] < z0) { curr_atomSP->inside_slabF = 0; curr_atomSP->inside_projected_slabF = 0; continue; } /** If atom is behind the back plane: **/ if (curr_atomSP->raw_atomS.z[0] > z1) { curr_atomSP->inside_slabF = 0; curr_atomSP->inside_projected_slabF = 0; continue; } /** If this points is reached, current atom is inside the slab: **/ atoms_inside_slabN++; } /* Return the number of atoms inside the slab: */ return atoms_inside_slabN; } /*===========================================================================*/ garlic-1.6/mono.c0000644000076500007650000000435207070337700014232 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= mono.c Purpose: Execute mono command. Input: (1) Pointer to MolComplexS structure. (2) The number of macromolecular complexes. (3) Pointer to RuntimeS structure. (4) Pointer to ConfigS structure. (5) Pointer to GUIS structure. (6) Pointer to NearestAtomS structure. (7) The number of pixels in the main window free area. (8) Pointer to refreshI. Output: (1) Stereo flag set. (2) Return value. Return value: (1) Positive (command) code on success. (2) Negative (error) code on failure. ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "commands.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int CalculateParameters_ (ConfigS *, GUIS *); size_t MainRefresh_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); int ControlRefresh_ (MolComplexS *, ConfigS *, GUIS *); /*======execute mono command:================================================*/ int CommandMono_ (MolComplexS *mol_complexSP, int mol_complexesN, RuntimeS *runtimeSP, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int *refreshIP) { int mol_complexI; /* Set mono mode: */ configSP->stereoF = 0; /* Refresh calculated parameters: */ if (CalculateParameters_ (configSP, guiSP) < 0) return ERROR_MONO; /* Set the position_changedF flag for each macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { (mol_complexSP + mol_complexI)->position_changedF = 1; } /* Refresh the main window: */ (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); /* Refresh the control window: */ ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); /* Return the command code: */ return COMMAND_MONO; } /*===========================================================================*/ garlic-1.6/typedefs.h0000644000076500007650000012504010445762033015111 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2006 Damir Zucic */ /* Structures used in garlic program. */ /* Color RGB specifications; this structure is slightly smaller than XColor: */ typedef struct /* RGBS */ { unsigned short red; unsigned short green; unsigned short blue; } RGBS; /* The structure used to store color schemes: */ typedef struct /* ColorSchemeS */ { int surfacesN; RGBS left_rgbSA[MAXCOLORSURFACES]; RGBS middle_rgbSA[MAXCOLORSURFACES]; RGBS right_rgbSA[MAXCOLORSURFACES]; } ColorSchemeS; /* Three dimensional vector structure: */ typedef struct /* VectorS */ { double x; double y; double z; } VectorS; /* Configuration data from $HOME/.garlicrc , or - if this file */ /* does not exist - from /usr/local/lib/garlic/.garlicrc file: */ /*----------------------------------*/ /* _atomic_ = atomic world units */ /* _real_ = real world units */ /* _screen_ = screen units (pixels) */ /*----------------------------------*/ /* Slab and fading modes: */ /*-------------------------*/ /* 0 = off (not used) */ /* 1 = planar (default) */ /* 2 = spherical */ /* 3 = half-sphere */ /* 4 = cylindrical */ /* 5 = half-cylinder */ /*-------------------------*/ typedef struct /* ConfigS */ { /* Log file name, flag and pointer: */ char log_file_nameA[STRINGSIZE]; int log_fileF; FILE *log_fileP; /* Main window geometry: */ char geometryA[SHORTSTRINGSIZE]; /* Font name and cursor name: */ char font_nameA[SHORTSTRINGSIZE]; char cursor_nameA[SHORTSTRINGSIZE]; /* Coordinate system flag (0 = hidden, 1 = visible): */ int show_coord_systemF; /* Control window flag (0 = hidden, 1 = visible): */ int show_control_windowF; /* Sequence neighborhood flag (0 = hide, 1 = show residue names, */ /* 2 = show residue names, serial numbers and chain identifiers): */ int show_sequence_neighborhoodF; /* Stereo flag (0 = draw mono image, 1 = draw stereo image): */ int stereoF; /* Default slab mode flag (see the list above for possible values): */ int default_slab_modeI; /* Default color fading mode (see above for possible modes): */ int default_fading_modeI; /* If print_configF is 1, print configuration data to stdout: */ int print_configF; /* If print_cursor_namesF is 1, print cursor names and exit: */ int print_cursor_namesF; /* Light source position may be defined using two angles. */ /* The angle light_theta is defined relative to z axis, */ /* while light_phi is defined relative to x axis. Positive */ /* values of light_phi are defined according to right-hand */ /* rule if positive z axis is rotation axis. Ranges are: */ /* light_theta from 0 to PI, light_phi from 0 to 2 * PI. */ double light_theta; double light_phi; /* Light source unit vector: */ VectorS light_vectorS; /* Strings specifying default colors for all windows: */ char bg_colorA[SHORTSTRINGSIZE]; char fg_colorA[SHORTSTRINGSIZE]; char text_bg_colorA[SHORTSTRINGSIZE]; char text_fg_colorA[SHORTSTRINGSIZE]; /* Default number of color fading surfaces: */ int default_surfacesN; /* Strings specifying default basic colors for atoms and bonds: */ char left_colorAA[MAXCOLORSURFACES][SHORTSTRINGSIZE]; char middle_colorAA[MAXCOLORSURFACES][SHORTSTRINGSIZE]; char right_colorAA[MAXCOLORSURFACES][SHORTSTRINGSIZE]; /* Default basic colors (color structures) for atoms and bonds: */ RGBS left_rgbSA[MAXCOLORSURFACES]; RGBS middle_rgbSA[MAXCOLORSURFACES]; RGBS right_rgbSA[MAXCOLORSURFACES]; /* Default surface color schemes: */ char surface_outer_color_schemeA[SHORTSTRINGSIZE]; char surface_inner_color_schemeA[SHORTSTRINGSIZE]; /* Six default colors for the outer side of the surface: */ RGBS out_left_near_rgbS; RGBS out_middle_near_rgbS; RGBS out_right_near_rgbS; RGBS out_left_far_rgbS; RGBS out_middle_far_rgbS; RGBS out_right_far_rgbS; /* Six default colors for the inner side of the surface: */ RGBS in_left_near_rgbS; RGBS in_middle_near_rgbS; RGBS in_right_near_rgbS; RGBS in_left_far_rgbS; RGBS in_middle_far_rgbS; RGBS in_right_far_rgbS; /* Default drawing styles for atoms, bonds and backbone: */ int default_atom_styleI; int default_bond_styleI; int default_backbone_styleI; /* Bond length parameters: */ double max_bond_length; /* In angstroms */ double C_C_bond_length_min; /* carbon-carbon */ double C_C_bond_length_max; double C_N_bond_length_min; /* carbon-nitrogen */ double C_N_bond_length_max; double C_O_bond_length_min; /* carbon-oxygen */ double C_O_bond_length_max; double C_S_bond_length_min; /* carbon-sulfur */ double C_S_bond_length_max; double C_H_bond_length_min; /* carbon-hydrogen */ double C_H_bond_length_max; double N_O_bond_length_min; /* nitrogen-oxygen */ double N_O_bond_length_max; double N_H_bond_length_min; /* nitrogen-hydrogen */ double N_H_bond_length_max; double O_H_bond_length_min; /* oxygen-hydrogen */ double O_H_bond_length_max; double S_H_bond_length_min; /* sulfur-hydrogen */ double S_H_bond_length_max; double O_P_bond_length_min; /* oxygen-phosphorus */ double O_P_bond_length_max; double S_S_bond_length_min; /* sulfur-sulfur (disulf.) */ double S_S_bond_length_max; double generic_bond_length_min; /* unrecognized bond */ double generic_bond_length_max; double hydro_bond_length_min; /* hydrogen bond */ double hydro_bond_length_max; double hydro_bond_angle_min; double hydro_bond_angle_max; /* The calculated (practical) bond length parameters: */ double C_C_min_squared; double C_C_max_squared; double C_N_min_squared; double C_N_max_squared; double C_O_min_squared; double C_O_max_squared; double C_S_min_squared; double C_S_max_squared; double C_H_min_squared; double C_H_max_squared; double N_O_min_squared; double N_O_max_squared; double N_H_min_squared; double N_H_max_squared; double O_H_min_squared; double O_H_max_squared; double S_H_min_squared; double S_H_max_squared; double O_P_min_squared; double O_P_max_squared; double S_S_min_squared; double S_S_max_squared; double generic_min_squared; double generic_max_squared; double hydro_min_squared; double hydro_max_squared; /* The maximal CA-CA distance, for two neighbouring residues: */ double CA_CA_dist_max; double CA_CA_dist_max_squared; /* Atomic radii (in angstroms): */ double H_radius; double C_radius; double N_radius; double O_radius; double S_radius; double P_radius; double generic_radius; /* Covalent radii (in angstroms): */ double H_covalent_radius; double C_covalent_radius; double N_covalent_radius; double O_covalent_radius; double S_covalent_radius; double P_covalent_radius; double generic_covalent_radius; /* Small radii (in angstroms): */ double H_small_radius; double C_small_radius; double N_small_radius; double O_small_radius; double S_small_radius; double P_small_radius; double generic_small_radius; /* van der Waals radii (in angstroms): */ double H_van_der_Waals_radius; double C_van_der_Waals_radius; double N_van_der_Waals_radius; double O_van_der_Waals_radius; double S_van_der_Waals_radius; double P_van_der_Waals_radius; double generic_van_der_Waals_radius; /* Ball radius (used to draw balls and sticks): */ double default_ball_radius; /* Default bond probe radius (used to draw nice bonds): */ double default_bond_probe_radius; /* Default stick radius (used to draw bonds as sticks): */ double default_stick_radius; /* Number of neighbors which should be checked as */ /* bond candidates; both values should be positive: */ int bond_candidates_backward; int bond_candidates_forward; /* Miscelaneous geometric parameters, related to drawing: */ int main_margin_left; int main_margin_right; int main_margin_top; int main_margin_bottom; int max_main_win_width; int max_main_win_height; int nearest_line_thickness; double screen_real_width; double screen_real_height; double user_screen_real_distance; double screen_atomic_width; double user_atomic_position; int stereo_screen_margin; /* Screen units */ double stereo_angle; /* radians, not degrees */ double rotation_stepA[5]; double translation_stepA[5]; double slab_stepA[5]; double fading_stepA[5]; /* Parameters calculated from geometric data. Used */ /* to reduce the number of mathematical operations */ /* required to project raw coordinates to screen. */ /* The rationalized_x0 and other rationalized data */ /* are used to identify atoms which are invisible */ /* and whose bonds are invisible (out of window). */ double user_screen_atomic_distance; double screen_atomic_height; double screen_atomic_z; double atomic_to_screen_scale_x; double atomic_to_screen_scale_y; double screen_to_atomic_scale_x; double win_atomic_free_width; double win_atomic_free_height; double win_atomic_x0; /* Window left edge (mono) */ double win_atomic_y0; /* Top edge */ double win_atomic_z0; /* Screen and window z value */ double win_atomic_x1; /* Right edge */ double win_atomic_y1; /* Bottom edge */ double rationalized_x0; double rationalized_y0; double rationalized_x1; double rationalized_y1; double stereo_atomic_margin; int center_screen_x[2]; /* ..._x[0] is the left one */ int center_screen_y; int image_screen_x0[2]; /* Image extent */ int image_screen_x1[2]; int image_screen_y0; int image_screen_y1; /* Blur rectangle default width and height: */ int blur_default_width; int blur_default_height; } ConfigS; /* Structure with the most important window data: */ typedef struct /* WindowS */ { Window ID; int x0; int y0; unsigned int width; unsigned int height; int border_width; XSizeHints size_hintsS; unsigned int colorsN; RGBS bg_rgbS; unsigned long bg_colorID; RGBS fg_rgbS; unsigned long fg_colorID; int pixmapF; /* 0 = created, 1 = not created */ Pixmap pixmapID; int fontF; /* 0 = not loaded, 1 = loaded */ int font_height; int half_font_height; int quarter_font_height; int text_line_height; XFontStruct *fontSP; int cursorF; /* 0 = not created, 1 = created */ Cursor cursorID; } WindowS; /* Structure needed to store GUI data: */ typedef struct /* GUIS */ { /* Main window refresh flag (0 = do not refresh, 1 = refresh): */ int main_window_refreshF; /*-----------------------------------*/ /* Main window drawing mode index: */ /*-----------------------------------*/ /* 0 structure */ /* 1 Ramachandran plot */ /* 2 helical wheel */ /* 3 Venn diagram */ /* 4 plots (hydrophob.) */ /* 5 sequence comparison */ /*-----------------------------------*/ int main_window_modeI; /* Docking flag (0 = docking mode off, 1 = docking mode on) */ int dockingF; /* Display data: */ char *display_nameP; char display_nameA[STRINGSIZE]; Display *displaySP; /* Screen data: */ int screenID; unsigned int screen_width; unsigned int screen_height; /* Flags reserved for keyboard modifiers (0 = not pressed): */ int shift_pressedF; int control_pressedF; int alt_pressedF; /* Data describing display color capabilities: */ int depth; XVisualInfo visual_infoS; Visual *visualSP; Colormap colormapID; /* Data for fast TrueColor color allocation: */ int red_right_shift; int red_left_shift; int green_right_shift; int green_left_shift; int blue_right_shift; int blue_left_shift; /* The main hidden pixmap. Drawing is done to a hidden pixmap */ /* which resides on the server side. Another approach will be */ /* to use an XImage on the client side. An experiment was made */ /* to compare two approaches, using XFree86 implementation of */ /* X11 window system. The XImage-based method was twice faster */ /* if both client and server run on the same machine. However, */ /* the hidden pixmap method was choosen because it offers much */ /* larger set of drawing routines (rectangles, arcs etc.). */ int main_hidden_pixmapF; Pixmap main_hidden_pixmapID; /* The hidden pixmap with small blue arrows. These arrows are used */ /* to show the main chain direction, projected to the XY plane. */ int small_arrows_pixmapF; unsigned int small_arrows_width; unsigned int small_arrows_height; Pixmap small_arrows_pixmapID; /* Array of graphics contexts: */ GC theGCA[10]; int gca_createdF; /* Window manager hints: */ XWMHints wm_hintsS; /* Main window data: */ WindowS main_winS; unsigned int main_win_free_area_width; unsigned int main_win_free_area_height; /* Icon data: */ WindowS icon_winS; /* Data required for control window: */ WindowS control_winS; /* Data required for text input window: */ WindowS input_winS; /* Data required for text output window: */ WindowS output_winS; /* Data required for docking window: */ int docking_window_createdF; int docking_window_mappedF; WindowS docking_winS; /* Data required for docking icon window: */ WindowS docking_icon_winS; /* Atoms related to window manager: */ Atom delete_window_atom; Atom protocols_atom; /* Eighteen auxiliary colors: */ unsigned long black_colorID; unsigned long gray_colorID; unsigned long dark_gray_colorID; unsigned long white_colorID; unsigned long red_colorID; unsigned long dark_red_colorID; unsigned long green_colorID; unsigned long dark_green_colorID; unsigned long blue_colorID; unsigned long dark_blue_colorID; unsigned long yellow_colorID; unsigned long dark_yellow_colorID; unsigned long cyan_colorID; unsigned long dark_cyan_colorID; unsigned long magenta_colorID; unsigned long dark_magenta_colorID; unsigned long orange_colorID; unsigned long dark_orange_colorID; } GUIS; /* Raw atomic data structure: it stores atomic data read from PDB file. */ /* Each molecular complex is a set of atoms; the atomic information */ /* is the most important information about molecular complex. Residue */ /* information is not considered to be of such importance to group all */ /* atoms beloging to the same residue into a special structure, though */ /* this approach is also possible. As amino acids, residues, nucleic */ /* bases, detergents and other molecules (commonly called residues) are */ /* quite different in size (number of atoms), grouping AtomS structures */ /* into residue structures will lead to inefficient usage of the memory. */ typedef struct /* RawAtomS */ { /* Hetero-flag (0 = ATOM, 1 = HETATM): */ int heteroF; /* Data contained in PDB ATOM and HETATM records: */ int serialI; char atom_nameA[ATOMNAMESIZE]; /* With spaces */ char pure_atom_nameA[ATOMNAMESIZE]; /* Without spaces */ char chemical_symbolA[SYMBOLSIZE]; /* Right justified */ char remoteness_indicator; /* Alphabetic */ char branch_designator; /* Numeric */ char alt_location; char residue_nameA[RESNAMESIZE]; /* With spaces */ char pure_residue_nameA[RESNAMESIZE]; /* Without s. */ char chainID; int residue_sequenceI; char residue_insertion_code; double x[2]; /* Stereo: x[0] left, x[1] right */ double y; /* x[0] is read from PDB file */ double z[2]; /* x[1] is calculated from x[0] */ int screen_x[2]; /* Projection to the screen */ int screen_y; double occupancy; double temperature_factor; /* Be careful with the remaining fields: older PDB files */ /* contain some other data after the temperature factor: */ char segmentA[SEGNAMESIZE]; char elementA[ELEMNAMESIZE]; /* With spaces */ char pure_elementA[ELEMNAMESIZE]; /* Without spaces */ char chargeA[CHARGESIZE]; /* SIGATM, ANISOU and SIGUIJ fields not implemented at present! */ /* Maybe some time later ... */ /* Model identifier (important for NMR structures): */ int model_serialI; /* Data below this line are not covered by PDB: */ /* Style index: */ int atom_styleI; /* Atomic radius: */ double radius; /* Covalent radius: */ double covalent_radius; /* Small radius: */ double small_radius; /* van der Waals radius: */ double van_der_Waals_radius; /* Ball radius, used to draw atoms as balls. */ double ball_radius; /* Additional data: */ double hydrophobicity; double special_value; /* Since version 1.2 */ } RawAtomS; /* True bond structure; it contains data about real chemical */ /* bond. Atomic pair ID's may be found in check_dist.c file. */ typedef struct /* TrueBondS */ { /* Style index (0 = nothing to draw): */ int bond_styleI; /* Bond ID (see check_dist.c for detailed information): */ int pairID; /* Bond type: */ /* 1 = covalent */ /* 0 = hydrogen */ /* 2 = disulfide */ /* 11 = pseudo */ int bond_typeI; /* Neighboring atom specification: */ int neighbor_mol_complexI; size_t neighbor_arrayI; /* Bond length: */ double bond_length; } TrueBondS; /* Atomic data structure; it contains raw atomic data and data */ /* about bonds. The same basic colors are used both for given */ /* atom and all bonds associated with this atom. If one or */ /* more bonds should be colored differently, try some special */ /* tricks. For example, it may be interesting to color bonds */ /* according to bond length (red too close, blue too far). */ /* Normally, hydrogen bonds should be drawn using the same */ /* basic colors and the same drawing style for all hydrogen */ /* bonds. These colors should be stored elsewhere, not here. */ /*-------------------------------------------------------------*/ /* Flags: */ /*-------------------------------------------------------------*/ /* selectedF Equal to 1 if atom is currently selected. */ /* hiddenF Equal to 1 if atom is hideen, 0 otherwise. */ /* inside_slabF Depends on slab: visible atoms are inside. */ /* in_windowF Some atoms may fall outside main window. */ /*-------------------------------------------------------------*/ typedef struct /* AtomS */ { /* Selection flag (current and previous): */ int selectedF; int previous_selectedF; /* Visibility flags (read Note 4 in main_expose.c): */ int hiddenF; int inside_slabF; int inside_windowF; /* Additional visibility flag, used only in ControlRefresh_ (): */ int inside_projected_slabF; /* Label flag (1 = write label): */ int labelF; /* Auxiliary index (used to recognize rings, for example). */ /* Do not forget to reset this index before every use! */ int auxiliaryI; /* The number of color fading surfaces: */ int surfacesN; /* Basic colors, used both for atom and its bonds. */ /* Used to prepare the atom_colorID for drawing. */ RGBS left_rgbSA[MAXCOLORSURFACES]; RGBS middle_rgbSA[MAXCOLORSURFACES]; RGBS right_rgbSA[MAXCOLORSURFACES]; /* Atom color ID's (used for drawing): */ unsigned long left_colorID; unsigned long middle_colorID; unsigned long right_colorID; /* Array index of the residue to which this atom belongs: */ size_t residue_arrayI; /* Raw atomic data (atom without bonds): */ RawAtomS raw_atomS; /* Bonds: */ int bondsN; TrueBondS true_bondSA[MAXBONDS]; } AtomS; /* Structure for macromolecular complex header data (text). */ /* Header is divided into six subsets: header, title, compnd, */ /* source, expdta, author. Each subset is defined by offset */ /* and number of lines. A total number of lines is stored too. */ typedef struct /* HeaderS */ { char *dataP; int total_linesN; int header_linesN; int header_offset; int title_linesN; int title_offset; int compnd_linesN; int compnd_offset; int source_linesN; int source_offset; int expdta_linesN; int expdta_offset; int author_linesN; int author_offset; } HeaderS; /* Backbone structure, used to store information about CA atoms. */ typedef struct /* BackboneS */ { int hiddenF; size_t c_alphaI; int backbone_styleI; int previous_c_alphaF; size_t previous_c_alphaI; int next_c_alphaF; size_t next_c_alphaI; } BackboneS; /* Residue structure, used to store sequence */ /* info, dihedral angles and cis-trans flag. */ typedef struct /* ResidueS */ { size_t residue_startI; size_t residue_endI; double phi; double psi; double omega; int cis_transF; /* 0 = bad/undefined, 1 = trans, 2 = cis */ double chi1; double chi2; double chi3; double chi4; double chi5; } ResidueS; /* Plane structure defines the plane associated with a given macromol. */ /* complex. The plane is represented by a circle and defined by plane */ /* center, normal vector and circle radius. Projected to the screen, */ /* plane looks like a tilted ellipse. The angle normal_phi is the angle */ /* between x axis and the projection of the normal vector to xy plane. */ /* It is equal to zero if the projection is parallel to x axis. Positive */ /* direction is clockwise. The angle normal_theta is the angle between */ /* the normal vector and z axis. The value is zero if they are parallel. */ /* Half axis a and b are given in screen units but stored as doubles. */ typedef struct /* PlaneS */ { int hiddenF; /* 0 = visible, 1 = unvisible */ int visible_sideI[2]; /* 0 = top, 1 = bottom */ double center_x[2]; /* Atomic units */ double center_y; double center_z[2]; int center_screen_x[2]; int center_screen_y; double normal_x[2]; double normal_y; double normal_z[2]; double circle_radius; /* Circle radius in atomic units */ double screen_a; /* Large half-axis of the ellipse */ double screen_b[2]; /* Small half-axis of the ellipse */ double normal_theta[2]; /* See definition above. */ double normal_phi[2]; /* See definition above. */ RGBS top_near_rgbS; /* Top side near color */ RGBS top_far_rgbS; /* Top side far color */ RGBS bottom_near_rgbS; /* Bottom s. near color */ RGBS bottom_far_rgbS; /* Bottom s. far color */ unsigned long top_near_colorID; unsigned long top_far_colorID; unsigned long bottom_near_colorID; unsigned long bottom_far_colorID; double transparency; /* 0.0 = opaque, 1.0 = transparent */ } PlaneS; /* Membrane structure defines the membrane associated with a given */ /* macromolecular complex. Due to the thermal motion, it is not */ /* possible to define the inner and the outer edge of the membrane. */ /* However, the representation which uses two planes to define the */ /* membrane is very popular. Do not forget that this is a bad idea. */ typedef struct /* MembraneS */ { int definedF; /* 0 = missing, 1 = defined */ int hiddenF; /* 0 = visible, 1 = unvisible */ double center_x; /* Atomic units */ double center_y; double center_z; double thickness; /* In angstroms. */ PlaneS plane1S; PlaneS plane2S; } MembraneS; /* Dot structure is used to define the surface. The surfaces are */ /* treated as sets of dots, with some common properties. A single */ /* dot on a given surface is defined by the radius vector, the */ /* unit (normal) vector, two flags and a set of twelve colors. Six */ /* outside colors are used if the projection of the normal vector */ /* to z axis is negative, i.e. if the outer side of the surface at */ /* the given point is on observer's side. Six inside (rear) colors */ /* are used if the normal vector has a positive z component, i.e. */ /* if the observer sees the inner side of the surface. A single */ /* transparency value is used for all dots at the same surface. */ typedef struct /* DotS */ { /* Radius vector and unit vector normal to the surface: */ VectorS radius_vectorS; VectorS normal_vectorS; /* Six colors for the outer side of the surface: */ RGBS out_left_near_rgbS; RGBS out_middle_near_rgbS; RGBS out_right_near_rgbS; RGBS out_left_far_rgbS; RGBS out_middle_far_rgbS; RGBS out_right_far_rgbS; /* Six colors for the inner side of the surface: */ RGBS in_left_near_rgbS; RGBS in_middle_near_rgbS; RGBS in_right_near_rgbS; RGBS in_left_far_rgbS; RGBS in_middle_far_rgbS; RGBS in_right_far_rgbS; /* Selection flag (0 = dot is not selected, 1 = dot is selected): */ char selectedF; /* Hide flag (0 = dot is visible, 1 = dot is hidden): */ char hiddenF; /* The array index of the macromolecular complex and the */ /* array index of the atom to which this dot belongs (These */ /* data are required if using CPK color scheme for dots): */ int mol_complexI; size_t atomI; } DotS; /* Surface structure is used to define the molecular surface. It is */ /* possible to associate more than one surface with a given molec. */ /* structure (the maximal number is MAXMOLSURFACES, see defines.h). */ /* Each surface is a finite set of dots (see DotS structure above), */ /* with a number of common properties, like transparency and color. */ /* If the number of dots for a given surface (dotsN) is zero, the */ /* surface is not defined (used) and the storage is not allocated. */ /* Take care about dotsN and storage when discarding some surface! */ typedef struct /* SurfaceS */ { /* Number of dots and pointer to the storage: */ int dotsN; DotS *dotSP; int hiddenF; /* 0 = visible, 1 = hidden; this flag */ /* overrides flags of individual dots */ /* Surface transparency mode index. */ /*-----------------------------------------*/ /* 0 = Default mode (uniform transparency) */ /* 1 = Transparency depends on the angle */ /* between the unit vector and z axis */ /*-----------------------------------------*/ int transparency_modeI; /* Surface transparency value: */ double transparency; /* The surface probe radius. This probe radius is used */ /* to generate the surface. Do not confuse it with */ /* the probe radius which is used to draw nice bonds! */ double surface_probe_radius; } SurfaceS; /* Structure which contains molecular complex data (proteins, DNA). */ /* Each molecular complex is a set of atoms. The fact that each */ /* molecular complex is made of building blocks called residues is */ /* not very important for this program, as atoms are considered to */ /* be the basic building blocks. Atomic data are stored into */ /* dynamically allocated memory. Reallocation mechanism must be */ /* ensured as the molecular complex size is not known in advance */ /* and large insertions into the structure are allowed at runtime. */ typedef struct /* MolComplexS */ { /* Macromolecular complex identifier: */ int mol_complexID; /* Unique PDB identifier: */ char unique_PDB_codeA[PDBCODESIZE]; /* Tag associated with the complex: */ int tagF; char tagA[TAGSIZE]; /* File name: */ char file_nameA[STRINGSIZE]; /* Catch flag; if equal to one, the movement, slab and */ /* fading controls affect the macromolecular complex: */ int catchF; /* Move bits; structure, plane and */ /* envelope may be moved separately. */ /* By default, everything is moved. */ /*-----------------------------------*/ /* Bit: If set to one: */ /*-----------------------------------*/ /* 1 (LSB) Move structure */ /* 2 Move plane */ /* 3 Move membrane */ /* 4 Move envelope */ /*-----------------------------------*/ int move_bits; /* Slab mode flag (each macromol. complex has its own): */ int slab_modeI; /* Color fading mode flag (each complex has its own): */ int fading_modeI; /* Flag used to signal that position or orientation changed: */ int position_changedF; /* Geometric center position and spacial extent of the object. */ /* Note: spacial extent is very approximate, calculated at the */ /* very beginning. It is used to set the initial slab width. */ VectorS geometric_center_vectorS; VectorS left_top_near_vectorS; VectorS right_bottom_far_vectorS; /* The maximal extent (the largest dimension): */ double max_extent; /* Rotation center position: */ VectorS rotation_center_vectorS; /* The storage which is used to backup the rotation */ /* center position if the macromolecular complex is */ /* taking part in a group of complexes. The stored */ /* value is copied back when the group is dismissed. */ VectorS backup_vectorS; /* Slab center position. It is used as the reference point for */ /* planar slab, cylindrical slab and spherical slab. The sym- */ /* metry axis of the cylindrical slab is parallel to y-axis. */ VectorS slab_center_vectorS; /* Parameters which define the relative positions */ /* of slab surfaces with respect to slab center. */ double slab_front_relative_position; double slab_back_relative_position; /* Color fading center. Used in a similar way as slab center. */ VectorS fading_center_vectorS; /* Parameters which define the relative positions of */ /* color fading surfaces with respect to fading center. */ double fading_front_relative_position; double fading_back_relative_position; /* Hydrophobicity scale index and reference */ /* hydrophobicity values for a given scale: */ int hydrophobicity_scaleI; double min_hydrophobicity; /* Extreme values for current */ double max_hydrophobicity; /* scale, not for the complex */ double average_hydrophobicity; double threshold_hydrophobicity; /* Information header: */ HeaderS headerS; /* Contains pointer to alloc. storage! */ /* Atoms: */ size_t atomsN; /* Number of atoms in a complex */ size_t max_atomsN; AtomS *atomSP; /* Backbone: */ size_t c_alphaN; BackboneS *backboneSP; /* Sequence, dihedral angles, cis-trans */ /* flags and sec. structure information: */ size_t residuesN; ResidueS *residueSP; char *secondary_structureP; /* Plane: */ PlaneS planeS; /* Membrane: */ MembraneS membraneS; /* A number of surfaces associated with the structure: */ SurfaceS surfaceSA[MAXMOLSURFACES]; /* Two flags related to hydrogen bonds. The first flag gives the */ /* status of hydrogen bonds (0 = missing or obsolete, 1 = valid). */ /* The second flag is equal to zero if hydrogen bonds are visible. */ int hydrogen_bondsF; int hydrogen_bonds_hiddenF; /* Bond probe radius. Each structure has its own probe radius. */ /* Do not confuse this probe with the probe used for the surface. */ double bond_probe_radius; /* Stick radius, used to draw bonds as sticks. Each structure has */ /* its own stick radius. A single radius is used for all bonds. */ double stick_radius; /* Group member flag. Zero for independent structures, */ /* one for all structures which are forming the group. */ int group_memberF; } MolComplexS; /* NearestAtomS is used to store data about the nearest atom for a given */ /* pixel of the main window (excluding control, input and output win.). */ /* Each time the macromolecular complexes are drawn to the main window, */ /* the fact that some atoms are closer to the observer than other atoms */ /* must be taken into account. Both complex array index and atom serial */ /* number are stored. If some atoms are inserted or deleted in one or */ /* more macromolecular complexes, NearestAtomS has to be reinitialized. */ /* Unvisible atoms are not taken into account while comparing distances. */ /* Because NearestAtomS is used, there is no need to sort atoms by dist. */ /* The value of the refreshI must be in range between 1 and MAXREFRESHI. */ /* If maximal value is exceeded, reinitialize the NearestAtomS array. */ /* The size of NearestAtomS should be checked after the main window is */ /* resized. The array should be reallocated if main window is enlarged. */ /* Always check the column and row index of a given pixel, as well as */ /* the combined (array) index before using NearestAtomS array elements. */ /* In addition, the NearestAtomS is also used for sequence comparison. */ /* The member bondI is zero or positive if the specified pixel is filled */ /* by certain true bond and negative if it is filled by something else. */ typedef struct /* NearestAtomS */ { unsigned int last_refreshI; int mol_complexI; size_t atomI; int bondI; double z; int styleI; unsigned long colorID; int auxiliaryI; } NearestAtomS; /* Aux1S structure, used to store some data and pointers required to */ /* draw simple bonds. Bond drawing functions require many parameters. */ /* Aux1S is used to reduce the number of arguments in function calls. */ typedef struct /* Aux1S */ { int imageI; int screen_x0; int screen_x1; int screen_delta_x; int screen_y0; int screen_y1; int screen_delta_y; double atomic_z0; double atomic_z1; double atomic_delta_z; ConfigS *configSP; GUIS *guiSP; NearestAtomS *nearest_atomSP; size_t pixelsN; unsigned int refreshI; int mol_complexI; size_t atomI; unsigned long colorIDA[10]; } Aux1S; /* Aux2S structure, used to store some data and */ /* pointers required to draw nice (curved) bonds. */ typedef struct /* Aux2S */ { int imageI; int mol_complexI; size_t atomI; int bondI; ConfigS *configSP; GUIS *guiSP; NearestAtomS *nearest_atomSP; size_t pixelsN; unsigned int refreshI; AtomS *atom1SP; AtomS *atom2SP; TrueBondS *curr_bondSP; double bond_probe_radius; double stick_radius; } Aux2S; /* ExposedResidueS structure, with data about exposed polar residue. */ /* If excludedF is equal to one the exposed residue should be ignored. */ typedef struct /* ExposedResidueS */ { int excludedF; int donorI; /* 0 = acceptor, 1 = donor, 2 = both */ size_t representative_atomI; char pure_residue_nameA[RESNAMESIZE]; char chainID; int residue_sequenceI; char residue_insertion_code; } ExposedResidueS; /* BetaCellS structure, used to find the proper membrane position */ /* and orientation with respect to a given beta barrel protein. */ typedef struct /* BetaCellS */ { int cell_usedF; double distance; double hydrophobicity; int cells_usedN; int average_calculatedF; double average_hydrophobicity; } BetaCellS; /*---------------------------------------------------*/ /* RuntimeS structure: a lot of run-time data. */ /*---------------------------------------------------*/ /* click_modeI: */ /*---------------------------------------------------*/ /* 0 = use clicks for distances and angles. */ /* 1 = use clicks to pick bond for editing. */ /*---------------------------------------------------*/ /* edit_modeI: */ /*---------------------------------------------------*/ /* 0 = default mode (no editing). */ /* 1 = edit atom(s). */ /* 2 = edit phi. */ /* 3 = edit psi. */ /* 4 = edit omega. */ /* 5 = edit main chain (edit phi and psi). */ /* 6 = edit bond. */ /* 7 = edit side chain (chi1 and chi2). */ /* 101 = edit dimensions of selected portion. */ /*---------------------------------------------------*/ /* rama_selectionF: */ /*---------------------------------------------------*/ /* 0 = draw Ramachandran plot for all residues. */ /* 1 = draw Ramachandran plot for selected residues. */ /*---------------------------------------------------*/ /* *disulfideFP: */ /*---------------------------------------------------*/ /* 0 = not involved in disulfide bond. */ /* 1 = involved in disulfide bond. */ /*---------------------------------------------------*/ /* wheel_clockwiseF: */ /*---------------------------------------------------*/ /* 0 = draw helical wheel anticlockwise (top view). */ /* 1 = draw helical wheel clockwise (bottom view). */ /*---------------------------------------------------*/ /* groupF: */ /*---------------------------------------------------*/ /* 0 = only 1 struct. is caught, there is no group. */ /* 1 = one, two or more structures are grouped. */ /*---------------------------------------------------*/ typedef struct /* RuntimeS */ { int click_modeI; int edit_modeI; int edit_single_bondF; int default_complexI; int scriptF; int pauseF; int rama_selectionF; int wheel_clockwiseF; int groupF; char *commandsP; /* History buffer */ int next_commandI; int old_commandI; int highest_commandI; char curr_commandA[COMMSTRINGSIZE]; int command_length; int carriage_position; int left_part_widthA[COMMSTRINGSIZE]; char messageA[COMMSTRINGSIZE]; int message_length; int title_hiddenF[MAXTITLES]; int title_screen_x[MAXTITLES]; int title_screen_y[MAXTITLES]; char *titlesP; /* Buffer for titles */ int atom1_serialI; /* Serial numbers of two */ int atom2_serialI; /* atoms which form bond */ size_t atom1_arrayI; /* Array indices of */ size_t atom2_arrayI; /* these two atoms */ int hydrophobicity_scaleI; double helix_step_angle; /* degrees */ double arc_angle; /* degrees */ double sphere_radius; /* angstroms */ int sliding_window_width; /* residues */ int average_hydrophobicityF; /* Average hydrophobicity */ int weighted_hydrophobicityF; /* Weighted hydrophobicity */ int hydrophobic_momentF; /* Hydrophobic moment */ int sided_hydrophobicityF; /* Two sided-h. functions */ int function1F; /* 1 = draw function F1 */ int function2F; /* 1 = draw function F2 */ int function3F; /* 1 = draw function F3 */ int function4F; /* 1 = draw function F4 */ int function5F; /* 1 = draw function F5 */ int function6F; /* 1 = draw function F6 */ int function7F; /* 1 = draw function F7 */ size_t sequence_buffer_size; /* Size of seq. buffer */ size_t residuesN; /* Sequence length */ char *sequenceP; /* Main sequence buffer */ char *sec_structureP; /* Secondary structure */ int sec_structure_length; /* Number of codes */ int *disulfideFP; /* S-S bond flags */ int *serialIP; /* Serial numbers */ int *residue_codeIP; /* Numeric residue codes */ double *hydrophobicityP; /* Hydrophobicity values */ double *weighted_hydrophobicityP; /* Weighted hyd. values */ double *average_hydrophobicityP; /* For given win. width */ double *hydrophobic_momentP; /* Absolute value */ double *larger_sided_hyphobP; /* Sided h., upper line */ double *smaller_sided_hyphobP; /* Sided h., bottom line */ double *function1P; /* Hydroph. function F1 */ double *function2P; /* Hydroph. function F2 */ double *function3P; /* Hydroph. function F3 */ double *function4P; /* Hydroph. function F4 */ double *function5P; /* Hydroph. function F5 */ double *function6P; /* Hydroph. function F6 */ double *function7P; /* Hydroph. function F7 */ int *auxiliaryIP; /* Aux. integer storage */ double *aux_doubleP; /* Aux. double storage */ size_t reference_residuesN; /* Reference seq. length */ char *reference_sequenceP; /* Reference seq. buffer */ char *reference_sec_structureP; /* Refer. sec. structure */ int reference_sec_str_length; /* Number of codes */ int *reference_serialIP; /* Ref. seq. ser. number */ int *reference_residue_codeIP; /* Numeric residue codes */ double *reference_hydrophobicityP; /* Hydrophobicity values */ int zoom_factor; /* Zoom factor: 1, 2 ... */ int sequence_offset; /* Sequence offset */ int reference_offset; /* Reference seq. offset */ int segment_width; /* Use to compare 2 seq. */ int minimal_score; /* Use to compare 2 seq. */ int range_startI; /* Residue range start */ int range_endI; /* Residue range end */ size_t pattern_buffer_size; /* Size of pattern buffer */ size_t pattern_length; /* Number of positions */ char *patternP; /* Pattern buffer */ int namesNA[MAX_PATT_LENGTH]; /* Residue names per pos. */ int residues_in_patternN; /* Total number of resid. */ int pattern_tolerance; /* Numb. of allowed errors */ MolComplexS *mol_complex1SP; /* Involved in docking */ MolComplexS *mol_complex2SP; /* Involved in docking */ double docking_area_width; /* angstroms */ double docking_cell_width; /* angstroms */ int docking_matrix_width; /* Cells across width */ int *exposed_atom1IP; /* Involved in docking */ int *exposed_atom2IP; /* Involved in docking */ ExposedResidueS *exposed_polar1SP; /* Exposed polar, bottom */ int exposed_polar1N; /* Number of e.p.r. bottom */ ExposedResidueS *exposed_polar2SP; /* Exposed polar, top */ int exposed_polar2N; /* Number of e.p.r. top */ int template_atomsN; /* Numb. of template atoms */ int max_template_atomsN; /* Max. n. of template at. */ AtomS *template_atomSP; /* Used to create peptides */ size_t template_residuesN; /* N. of template residues */ ResidueS *template_residueSP; /* Information about res. */ int blurF; /* 0 = blur off, 1 = on */ int blur_width; /* Width of blur rectangle */ int blur_height; /* Height of blur rect. */ int beta_cellsN; /* Auxiliary cells used to */ BetaCellS *beta_cellSP; /* find membrane position */ /* relative to beta barrel */ int active_surfaceI; /* For default m. complex */ } RuntimeS; /* SelectS structure, with the selection criteria. */ typedef struct /* SelectS */ { int all_chainsF; int chainsN; char chainIDA[MAXFIELDS]; int all_residue_serialF; int residue_serial_rangesN; int residue_serial_start[MAXFIELDS]; int residue_serial_end[MAXFIELDS]; int all_residue_namesF; int residue_namesN; char residue_nameAA[MAXFIELDS][RESNAMESIZE]; int all_atom_namesF; int atom_namesN; char atom_nameAA[MAXFIELDS][ATOMNAMESIZE]; } SelectS; /* ButtonS structure, defines positions */ /* of dummy buttons in control window. */ typedef struct /* ButtonS */ { int left_edge; int right_edge; int top_edge; int bottom_edge; } ButtonS; /* DockingS contains data required for docking. */ typedef struct /* DockingS */ { MolComplexS *mol_complex1SP; MolComplexS *mol_complex2SP; double docking_area_width; } DockingS; /* That's all! */ garlic-1.6/omega_from_cacnca.c0000644000076500007650000001012607316071077016666 0ustar zuciczucic00000000000000/* Copyright (C) 2001 Damir Zucic */ /*============================================================================= omega_from_cacnca.c Purpose: Calculate the dihedral angle omega, using CA and C atom from the previous residue and N and C atom from the current residue. The peptide bond formed by the residues I and I + 1 is assigned to the residue I + 1 and not to the residue I. The same applies to Input: (1) Pointer to VectorS structure, with CA atom coordinates from the previous residue. (2) Pointer to VectorS structure, with C atom coordinates from the previous residue. (3) Pointer to VectorS structure, with N atom coordinates. (4) Pointer to VectorS structure, with CA atom coordinates. (5) Pointer to ConfigS structure. Output: Return value. Return value: (1) Dihedral angle omega, on success. (2) BADDIHEDANGLE on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ void VectorProduct_ (VectorS *, VectorS *, VectorS *); double ScalarProduct_ (VectorS *, VectorS *); double AbsoluteValue_ (VectorS *); /*======calculate the omega angle:===========================================*/ double OmegaFromCACNCA_ (VectorS *prevCA_vectorSP, VectorS *prevC_vectorSP, VectorS *N_vectorSP, VectorS *CA_vectorSP, ConfigS *configSP) { VectorS prevC_N_vectorS, prevC_prevCA_vectorS; double bond_length_squared; VectorS N_prevC_vectorS, N_CA_vectorS; VectorS u1S, u2S; VectorS v1S, v2S; double denom, ratio; double alpha, omega; /* The first pair of auxiliary vectors: */ prevC_N_vectorS.x = N_vectorSP->x - prevC_vectorSP->x; prevC_N_vectorS.y = N_vectorSP->y - prevC_vectorSP->y; prevC_N_vectorS.z = N_vectorSP->z - prevC_vectorSP->z; prevC_prevCA_vectorS.x = prevCA_vectorSP->x - prevC_vectorSP->x; prevC_prevCA_vectorS.y = prevCA_vectorSP->y - prevC_vectorSP->y; prevC_prevCA_vectorS.z = prevCA_vectorSP->z - prevC_vectorSP->z; bond_length_squared = prevC_N_vectorS.x * prevC_N_vectorS.x + prevC_N_vectorS.y * prevC_N_vectorS.y + prevC_N_vectorS.z * prevC_N_vectorS.z; if (bond_length_squared < configSP->C_N_min_squared) return BADDIHEDANGLE; if (bond_length_squared > configSP->C_N_max_squared) return BADDIHEDANGLE; /* The second pair of auxiliary vectors: */ N_prevC_vectorS.x = prevC_vectorSP->x - N_vectorSP->x; N_prevC_vectorS.y = prevC_vectorSP->y - N_vectorSP->y; N_prevC_vectorS.z = prevC_vectorSP->z - N_vectorSP->z; N_CA_vectorS.x = CA_vectorSP->x - N_vectorSP->x; N_CA_vectorS.y = CA_vectorSP->y - N_vectorSP->y; N_CA_vectorS.z = CA_vectorSP->z - N_vectorSP->z; /* Two vectors perpendicular to prevC_N_vectorS, mutually orthogonal, the */ /* second in the plane defined by prevC_N_vectorS and prevC_prevCA_vectorS: */ VectorProduct_ (&u1S, &prevC_N_vectorS, &prevC_prevCA_vectorS); VectorProduct_ (&u2S, &u1S, &prevC_N_vectorS); /* Two vectors perpendicular to N_prevC_vectorS, mutually orthogonal, */ /* the second in the plane defined by N_prevC_vectorS and N_CA_vectorS: */ VectorProduct_ (&v1S, &N_CA_vectorS, &N_prevC_vectorS); VectorProduct_ (&v2S, &N_prevC_vectorS, &v1S); /* Calculate the angle alpha, which will be used to calculate omega: */ /* Avoid division by zero: */ denom = AbsoluteValue_ (&u1S) * AbsoluteValue_ (&v1S); if (denom == 0.0) return BADDIHEDANGLE; /* Use the scalar product to calculate the cosine of the angle: */ ratio = ScalarProduct_ (&u1S, &v1S) / denom; /* Arc cosine is very sensitive to floating point errors: */ if (ratio <= -1.0) alpha = 3.1415927; else if (ratio >= 1.0) alpha = 0.0; else alpha = acos (ratio); /* There are two possible solutions; the right one is resolved here: */ if (ScalarProduct_ (&v2S, &u1S) >= 0) omega = alpha; else omega = -alpha; /* Return the angle (in radians): */ return omega; } /*===========================================================================*/ garlic-1.6/draw_seahorse.c0000644000076500007650000001720007612772063016113 0ustar zuciczucic00000000000000/* Copyright (C) 2001-2003 Damir Zucic */ /*============================================================================= draw_seahorse.c Purpose: Draw the seahorse in the middle of the representative bond. Write a small hint to the top right corner of the main window. Input: (1) Pointer to MolComplexS structure. (2) Pointer to RuntimeS structure. (3) Pointer to ConfigS structure. (4) Pointer to GUIS structure. (5) Pointer to NearestAtomS structure. (6) The number of pixels in the main window free area. (7) The refreshI index. Output: (1) Seahorse drawn to the main pixmap. (2) Return value. Return value: (1) Positive on success. (2) Negative on failure. =============================================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" #include "seahorse.xpm" /*======function prototypes:=================================================*/ int ParseColor_ (RGBS *, unsigned long *, GUIS *, char *, char *); /*======draw seahorse:=======================================================*/ int DrawSeahorse_ (MolComplexS *mol_complexSP, RuntimeS *runtimeSP, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int refreshI) { static int called_beforeF; int imageI, imagesN; int left_edge[2], right_edge[2]; int colorsN = 10, colorI; int stringI; MolComplexS *default_mol_complexSP; char *color_stringP; static RGBS rgbS; static unsigned long colorIDA[10]; size_t atomsN, atom1I, atom2I; AtomS *atom1SP, *atom2SP; int screen_x0, screen_y0, screen_x, screen_y; double z; int width = 80, height = 143, columnI, rowI; int current_char; size_t pixelI; NearestAtomS *curr_pixelSP; int edit_modeI; char stringA[SHORTSTRINGSIZE]; int text_width; unsigned int hint_width, hint_height; /*------draw the seahorse:---------------------------------------------------*/ /* Number of images: */ if (configSP->stereoF) imagesN = 2; else imagesN = 1; /* Left and right image edge (in stereo mode there are two images): */ left_edge[0] = configSP->image_screen_x0[0]; right_edge[0] = configSP->image_screen_x1[0]; left_edge[1] = configSP->image_screen_x0[1]; right_edge[1] = configSP->image_screen_x1[1]; /* Prepare colors if this function is called for the first time: */ if (!called_beforeF) { for (colorI = 0; colorI < colorsN; colorI++) { /* The third string specifies the first */ /* color. The index of this string is two: */ stringI = colorI + 2; /* The color string follows the substring "c ": */ color_stringP = strstr (seahorse_xpm[stringI], "c ") + 2; /* Parse color: */ ParseColor_ (&rgbS, &colorIDA[colorI], guiSP, color_stringP, "white"); } } /* Set the flag which signals that this function was used at least once: */ called_beforeF = 1; /* Copy colors to GC's: */ for (colorI = 0; colorI < colorsN; colorI++) { XSetForeground (guiSP->displaySP, guiSP->theGCA[colorI], colorIDA[colorI]); } /* Pointer to default macromolecular complex: */ default_mol_complexSP = mol_complexSP + runtimeSP->default_complexI; /* Check the array indices of the representative atoms: */ atomsN = default_mol_complexSP->atomsN; atom1I = runtimeSP->atom1_arrayI; atom2I = runtimeSP->atom2_arrayI; if (atom1I >= atomsN) return -1; if (atom2I >= atomsN) return -2; if (atom1I == atom2I) return -3; /* Prepare the pointers to representative atoms: */ atom1SP = default_mol_complexSP->atomSP + atom1I; atom2SP = default_mol_complexSP->atomSP + atom2I; /* Draw one (mono) or two pixels (stereo): */ for (imageI = 0; imageI < imagesN; imageI++) { /* Prepare the screen coordinates for the seahorse: */ screen_x0 = (atom1SP->raw_atomS.screen_x[imageI] + atom2SP->raw_atomS.screen_x[imageI]) / 2; screen_y0 = (atom1SP->raw_atomS.screen_y + atom2SP->raw_atomS.screen_y) / 2; /* Prepare the z coordinate: */ z = (atom1SP->raw_atomS.z[imageI] + atom2SP->raw_atomS.z[imageI]) / 2; /* Now scan the pixmap. */ /* Vertical scan (top to bottom): */ for (rowI = 0; rowI < height; rowI++) { /* Prepare the string index: */ stringI = rowI + 12; /* Horizontal scan (left to right): */ for (columnI = 0; columnI < width; columnI++) { /* Prepare the current character: */ current_char = seahorse_xpm[stringI][columnI]; /* Check is it this pixel transparent: */ if (current_char == ' ') continue; /* Prepare the color index: */ switch (current_char) { case '.': colorI = 0; break; case '+': colorI = 1; break; case '@': colorI = 2; break; case '#': colorI = 3; break; case '$': colorI = 4; break; case '%': colorI = 5; break; case '&': colorI = 6; break; case '*': colorI = 7; break; case '=': colorI = 8; break; case '-': colorI = 9; break; default: ; } /* Prepare and check the screen coordinates: */ screen_x = screen_x0 + columnI - 11; screen_y = screen_y0 + rowI - 143; if (screen_x < left_edge[imageI]) break; if (screen_x >= right_edge[imageI]) break; /* Prepare index to the array */ /* of NearestAtomS structures: */ pixelI = guiSP->main_win_free_area_width * screen_y + screen_x; /* Check the pixel index: */ if (pixelI >= pixelsN) break; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = nearest_atomSP + pixelI; /* Check was this pixel used already in */ /* this drawing step; if it was, compare */ /* the z value of the current atom with z */ /* value previously stored to this pixel: */ if (refreshI == curr_pixelSP->last_refreshI) { if (z >= curr_pixelSP->z) continue; } /* Draw this pixel: */ XDrawPoint (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[colorI], screen_x, screen_y); } } } /* imageI loop */ /*------draw the hint:-------------------------------------------------------*/ /* Copy the edit mode index: */ edit_modeI = runtimeSP->edit_modeI; /* If editing PHI, PSI, OMEGA or BOND: */ if ((edit_modeI == 2) || (edit_modeI == 3) || (edit_modeI == 4) || (edit_modeI == 6)) { strcpy (stringA, "Use keys 7 and 9 on numeric keypad"); } /* If editing MAIN or SIDE chain: */ else if ((edit_modeI == 5) || (edit_modeI == 7)) { strcpy (stringA, "Use 2, 4, 6 and 8 on numeric keypad"); } /* Draw the red filled rectangle and the yellow text inside this rectangle: */ text_width = XTextWidth (guiSP->main_winS.fontSP, stringA, strlen (stringA)); screen_x0 = guiSP->main_win_free_area_width - text_width - guiSP->main_winS.half_font_height - 2 * guiSP->main_winS.border_width; screen_y0 = guiSP->main_winS.font_height + 9; hint_width = text_width + guiSP->main_winS.half_font_height; hint_height = guiSP->main_winS.font_height + 4; XSetForeground (guiSP->displaySP, guiSP->theGCA[0], guiSP->red_colorID); XFillRectangle (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0, screen_y0, hint_width, hint_height); XSetForeground (guiSP->displaySP, guiSP->theGCA[0], guiSP->yellow_colorID); screen_x0 += guiSP->main_winS.quarter_font_height; screen_y0 += guiSP->main_winS.font_height - 2; XDrawString (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, strlen (stringA)); /*---------------------------------------------------------------------------*/ /* Return positive value on success: */ return 1; } /*===========================================================================*/ garlic-1.6/execute_command1.c0000644000076500007650000007152510116016405016500 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2003 Damir Zucic */ /*============================================================================= execute_command1.c Purpose: Parse and execute command. Refresh the message (reset or fill with a new content). This function is capable to execute garlic scripts. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Pointer to the number of macromolecular complexes. (3) Pointer to the next macromolecular complex identifier. (4) Pointer to RuntimeS structure, with some runtime data. (5) Pointer to ConfigS structure, with configuration data. (6) Pointer to GUIS structure, with GUI data. (7) Pointer to pointer to NearestAtomS structure. (8) Pointer to the number of pixels in the main win. free area. (9) Pointer to refreshI. Output: (1) The latest command executed. (2) Return value. Return value: (1) Positive on success (command code). (2) Zero, if command string is empty. (3) Negative on failure. Notes: (1) The value of refreshI (*refreshIP) may be changed in this function or in some function called by this function. It is checked in EventLoop_ (see event_loop.c). It is assumed that refreshI is updated no more than once in each event handling function. If this is not the case, the care should be taken to avoid refreshI overflow. (2) The command string is converted to uppercase. Do not forget that file names are case sensitive. Use the copy of the original command string to prepare the proper file name. ========includes:============================================================*/ #include #include #include #include #include #include #include #include "defines.h" #include "commands.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int ExecuteScript_ (MolComplexS *, int *, int *, RuntimeS *, ConfigS *, GUIS *, NearestAtomS **, size_t *, unsigned int *); char *ExtractToken_ (char *, int, char *, char *); int Load_ (MolComplexS *, int *, int *, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *); int Discard_ (MolComplexS *, int *, int *, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *, char *); int Catch_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *, char *); int Select_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *, char *, int); int Show_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *); int Hide_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *); int Color_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *, char *); int Atoms_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *, char *); int Bonds_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *, char *); int CommandRotate_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *, char *); int CommandTranslate_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *, char *); int CommandSlab_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *, char *); int CommandFading_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *, char *); int Log_ (ConfigS *, RuntimeS *); int Foreground_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *); int Background_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *); int TextBackground_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *); int TextForeground_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *); int Font_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS **, size_t *, unsigned int *); int CommandBackbone_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *, char *); int HydrogenBonds_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *, char *); int CommandStereo_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *, char *); int CommandMono_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *); int CommandPosition_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *, char *); int Title_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *); int Labels_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *, char *); int Register_ (void); int Center_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *); int Save_ (MolComplexS *, int, RuntimeS *); int Tag_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *); int Sequence_ (MolComplexS *, int, RuntimeS *, char *); int Ramachandran_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *, char *); int Wheel_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *, char *); int Angle_ (RuntimeS *, char *); int Radius_ (RuntimeS *, char *); int Venn_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *, char *); int SSB_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *, char *); int Window_ (RuntimeS *); int Plot_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *, char *); int CommandMove_ (MolComplexS *, int, RuntimeS *, char *); int Plane_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *, char *); int Scale_ (MolComplexS *, int, RuntimeS *, char *); int Pattern_ (MolComplexS *, int, RuntimeS *, char *); int Dock_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *, char *); int Compare_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *, char *); int Neighborhood_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *, char *); int Structure_ (MolComplexS *, int, RuntimeS *, char *); int Create_ (MolComplexS *, int *, int *, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *); int Replace_ (MolComplexS *, int, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *); int Edit_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *, char *); int Membrane_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *, char *); int Set_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *, char *); int Probe_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *, char *); int CommandRefresh_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *, char *); int Sticks_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *, char *); int Balls_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *, char *); int Blur_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *, char *); int Group_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *, char *); int Dump_ (MolComplexS *, int, RuntimeS *, char *); /*======execute command (1):=================================================*/ int ExecuteCommand1_ (MolComplexS *mol_complexSP, int *mol_complexesNP, int *next_mol_complexIDP, RuntimeS *runtimeSP, ConfigS *configSP, GUIS *guiSP, NearestAtomS **nearest_atomSPP, size_t *pixelsNP, unsigned int *refreshIP) { char commandA[STRINGSIZE]; int command_length; int i; char *remainderP; char tokenA[STRINGSIZE]; /* If the previous command was PAUSE, take a special care: */ if (runtimeSP->pauseF == 1) { /* Script mode: */ if (runtimeSP->scriptF) { return ExecuteScript_ (mol_complexSP, mol_complexesNP, next_mol_complexIDP, runtimeSP, configSP, guiSP, nearest_atomSPP, pixelsNP, refreshIP); } /* Interactive mode: */ else { runtimeSP->pauseF = 0; runtimeSP->messageA[0] = '\0'; runtimeSP->message_length = 0; return COMMAND_CONTINUE; } } /* Copy both command length and command string: */ command_length = runtimeSP->command_length; strncpy (commandA, runtimeSP->curr_commandA, runtimeSP->command_length); commandA[command_length] = '\0'; /* Convert the command string to uppercase: */ for (i = 0; i < command_length; i++) commandA[i] = toupper (commandA[i]); /* Truncate the message and reset the message length: */ runtimeSP->messageA[0] = '\0'; runtimeSP->message_length = 0; /* Take the first token - it should be the command word: */ remainderP = ExtractToken_ (tokenA, STRINGSIZE, commandA, " \t\n"); /* If there is nothing, return zero - the command string is empty: */ if (remainderP == NULL) return 0; /* Parse and execute the command: */ /*------quit, exit:----------------------------------------------------------*/ if ((strstr (tokenA, "QUI") == tokenA) || (strstr (tokenA, "EXI") == tokenA)) { return COMMAND_QUIT; } /*------pause:---------------------------------------------------------------*/ else if (strstr (tokenA, "PAU") == tokenA) { runtimeSP->pauseF = 1; strcpy (runtimeSP->messageA, "Press enter to continue!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return COMMAND_PAUSE; } /*------ignore:--------------------------------------------------------------*/ /* This command does nothing - it is added for debugging purpose! */ else if (strstr (tokenA, "IGN") == tokenA) { return COMMAND_IGNORE; } /*------select:--------------------------------------------------------------*/ /* Overwrite the previous selection: */ else if (strstr (tokenA, "SEL") == tokenA) { return Select_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP, remainderP, 0); } /*------restrict:------------------------------------------------------------*/ /* Restrict the previous selection: */ else if (strstr (tokenA, "RES") == tokenA) { return Select_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP, remainderP, 1); } /*------add:-----------------------------------------------------------------*/ /* Expand (add to) the previous selection: */ else if ((strstr (tokenA, "ADD") == tokenA) || (strstr (tokenA, "EXP") == tokenA)) { return Select_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP, remainderP, 2); } /*------load, read:----------------------------------------------------------*/ else if ((strstr (tokenA, "LOA") == tokenA) || (strstr (tokenA, "REA") == tokenA)) { /* The original command string should be used */ /* because the copy was converted to uppercase: */ return Load_ (mol_complexSP, mol_complexesNP, next_mol_complexIDP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP); } /*------discard:-------------------------------------------------------------*/ else if (strstr (tokenA, "DIS") == tokenA) { return Discard_ (mol_complexSP, mol_complexesNP, next_mol_complexIDP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP, remainderP); } /*------catch, take:---------------------------------------------------------*/ else if ((strstr (tokenA, "CAT") == tokenA) || (strstr (tokenA, "TAK") == tokenA)) { return Catch_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP, remainderP); } /*------show:----------------------------------------------------------------*/ else if (strstr (tokenA, "SHO") == tokenA) { return Show_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP); } /*------hide:----------------------------------------------------------------*/ else if (strstr (tokenA, "HID") == tokenA) { return Hide_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP); } /*------color:---------------------------------------------------------------*/ else if (strstr (tokenA, "COL") == tokenA) { return Color_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP, remainderP); } /*------atoms:---------------------------------------------------------------*/ else if (strstr (tokenA, "ATO") == tokenA) { return Atoms_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP, remainderP); } /*------bonds:---------------------------------------------------------------*/ else if (strstr (tokenA, "BON") == tokenA) { return Bonds_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP, remainderP); } /*------rotate:--------------------------------------------------------------*/ else if (strstr (tokenA, "ROT") == tokenA) { return CommandRotate_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP, remainderP); } /*------translate:-----------------------------------------------------------*/ else if (strstr (tokenA, "TRA") == tokenA) { return CommandTranslate_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP, remainderP); } /*------slab:----------------------------------------------------------------*/ else if (strstr (tokenA, "SLA") == tokenA) { return CommandSlab_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP, remainderP); } /*------fading:--------------------------------------------------------------*/ else if (strstr (tokenA, "FAD") == tokenA) { return CommandFading_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP, remainderP); } /*------log:-----------------------------------------------------------------*/ else if (strstr (tokenA, "LOG") == tokenA) { /* The original command string should be used */ /* because the copy was converted to uppercase: */ return Log_ (configSP, runtimeSP); } /*------fg:------------------------------------------------------------------*/ else if ((strcmp (tokenA, "FG") == 0) || (strstr (tokenA, "FOREG") == tokenA)) { /* The original command string should be used */ /* because the copy was converted to uppercase: */ return Foreground_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP); } /*------bg:------------------------------------------------------------------*/ else if ((strcmp (tokenA, "BG") == 0) || (strstr (tokenA, "BACKG") == tokenA)) { /* The original command string should be used */ /* because the copy was converted to uppercase: */ return Background_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP); } /*------tbg:-----------------------------------------------------------------*/ else if (strcmp (tokenA, "TBG") == 0) { /* The original command string should be used */ /* because the copy was converted to uppercase: */ return TextBackground_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP); } /*------tfg:-----------------------------------------------------------------*/ else if (strcmp (tokenA, "TFG") == 0) { /* The original command string should be used */ /* because the copy was converted to uppercase: */ return TextForeground_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP); } /*------font:----------------------------------------------------------------*/ else if (strstr (tokenA, "FON") == tokenA) { /* The original command string should be used */ /* because the copy was converted to uppercase: */ return Font_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, nearest_atomSPP, pixelsNP, refreshIP); } /*------backbone:------------------------------------------------------------*/ else if (strstr (tokenA, "BAC") == tokenA) { return CommandBackbone_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP, remainderP); } /*------hybonds:-------------------------------------------------------------*/ else if (strstr (tokenA, "HYB") == tokenA) { return HydrogenBonds_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP, remainderP); } /*------stereo:--------------------------------------------------------------*/ else if (strstr (tokenA, "STE") == tokenA) { return CommandStereo_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP, remainderP); } /*------mono:----------------------------------------------------------------*/ else if (strstr (tokenA, "MON") == tokenA) { return CommandMono_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP); } /*------position:------------------------------------------------------------*/ else if (strstr (tokenA, "POS") == tokenA) { return CommandPosition_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP, remainderP); } /*------title:---------------------------------------------------------------*/ else if (strstr (tokenA, "TIT") == tokenA) { /* The original command string should be used */ /* because the copy was converted to uppercase: */ return Title_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP); } /*------labels:--------------------------------------------------------------*/ else if (strstr (tokenA, "LAB") == tokenA) { return Labels_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP, remainderP); } /*------register:------------------------------------------------------------*/ else if (strstr (tokenA, "REG") == tokenA) { strcpy (runtimeSP->messageA, "A short e-mail message was send to the author."); runtimeSP->message_length = strlen (runtimeSP->messageA); Register_ (); return COMMAND_REGISTER; } /*------center:--------------------------------------------------------------*/ else if (strstr (tokenA, "CEN") == tokenA) { return Center_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP); } /*------save:----------------------------------------------------------------*/ else if (strstr (tokenA, "SAV") == tokenA) { /* The original command string should be used */ /* because the copy was converted to uppercase: */ return Save_ (mol_complexSP, *mol_complexesNP, runtimeSP); } /*------tag:-----------------------------------------------------------------*/ else if (strstr (tokenA, "TAG") == tokenA) { /* The original command string should be used */ /* because the copy was converted to uppercase: */ return Tag_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP); } /*------sequence:------------------------------------------------------------*/ else if (strstr (tokenA, "SEQ") == tokenA) { return Sequence_ (mol_complexSP, *mol_complexesNP, runtimeSP, remainderP); } /*------ramachandran:--------------------------------------------------------*/ else if (strstr (tokenA, "RAM") == tokenA) { return Ramachandran_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP, remainderP); } /*------wheel:---------------------------------------------------------------*/ else if (strstr (tokenA, "WHE") == tokenA) { return Wheel_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP, remainderP); } /*------angle:---------------------------------------------------------------*/ else if (strstr (tokenA, "ANG") == tokenA) { return Angle_ (runtimeSP, remainderP); } /*------radius:--------------------------------------------------------------*/ else if (strstr (tokenA, "RAD") == tokenA) { return Radius_ (runtimeSP, remainderP); } /*------venn:----------------------------------------------------------------*/ else if (strstr (tokenA, "VEN") == tokenA) { return Venn_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP, remainderP); } /*------ssb:-----------------------------------------------------------------*/ else if (strstr (tokenA, "SSB") == tokenA) { return SSB_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP, remainderP); } /*------window:--------------------------------------------------------------*/ else if (strstr (tokenA, "WIN") == tokenA) { return Window_ (runtimeSP); } /*------plot:----------------------------------------------------------------*/ else if (strstr (tokenA, "PLO") == tokenA) { return Plot_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP, remainderP); } /*------move:----------------------------------------------------------------*/ else if (strstr (tokenA, "MOV") == tokenA) { return CommandMove_ (mol_complexSP, *mol_complexesNP, runtimeSP, remainderP); } /*------plane:---------------------------------------------------------------*/ else if (strstr (tokenA, "PLA") == tokenA) { return Plane_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP, remainderP); } /*------scale:---------------------------------------------------------------*/ else if (strstr (tokenA, "SCA") == tokenA) { return Scale_ (mol_complexSP, *mol_complexesNP, runtimeSP, remainderP); } /*------pattern:-------------------------------------------------------------*/ else if (strstr (tokenA, "PAT") == tokenA) { return Pattern_ (mol_complexSP, *mol_complexesNP, runtimeSP, remainderP); } /*------dock:----------------------------------------------------------------*/ else if (strstr (tokenA, "DOC") == tokenA) { return Dock_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP, remainderP); } /*------compare:-------------------------------------------------------------*/ else if (strstr (tokenA, "COM") == tokenA) { return Compare_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP, remainderP); } /*------neighborhood:--------------------------------------------------------*/ else if (strstr (tokenA, "NEI") == tokenA) { return Neighborhood_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP, remainderP); } /*------structure:-----------------------------------------------------------*/ else if (strstr (tokenA, "STR") == tokenA) { return Structure_ (mol_complexSP, *mol_complexesNP, runtimeSP, remainderP); } /*------create:--------------------------------------------------------------*/ else if (strstr (tokenA, "CRE") == tokenA) { return Create_ (mol_complexSP, mol_complexesNP, next_mol_complexIDP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP); } /*------replace:-------------------------------------------------------------*/ else if (strstr (tokenA, "REP") == tokenA) { return Replace_ (mol_complexSP, *mol_complexesNP, *next_mol_complexIDP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP); } /*------edit:----------------------------------------------------------------*/ else if (strstr (tokenA, "EDI") == tokenA) { return Edit_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP, remainderP); } /*------membrane:------------------------------------------------------------*/ else if (strstr (tokenA, "MEM") == tokenA) { return Membrane_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP, remainderP); } /*------set:-----------------------------------------------------------------*/ else if (strstr (tokenA, "SET") == tokenA) { return Set_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP, remainderP); } /*------probe:---------------------------------------------------------------*/ else if (strstr (tokenA, "PRO") == tokenA) { return Probe_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP, remainderP); } /*------refresh:-------------------------------------------------------------*/ else if (strstr (tokenA, "REF") == tokenA) { return CommandRefresh_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP, remainderP); } /*------sticks:--------------------------------------------------------------*/ else if (strstr (tokenA, "STI") == tokenA) { return Sticks_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP, remainderP); } /*------balls:---------------------------------------------------------------*/ else if (strstr (tokenA, "BAL") == tokenA) { return Balls_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP, remainderP); } /*------blur:----------------------------------------------------------------*/ else if (strstr (tokenA, "BLU") == tokenA) { return Blur_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP, remainderP); } /*------group:---------------------------------------------------------------*/ else if (strstr (tokenA, "GRO") == tokenA) { return Group_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP, remainderP); } /*------dump:----------------------------------------------------------------*/ else if (strstr (tokenA, "DUM") == tokenA) { return Dump_ (mol_complexSP, *mol_complexesNP, runtimeSP, remainderP); } /*------execute:-------------------------------------------------------------*/ else if (strstr (tokenA, "EXE") == tokenA) { /* The original command string should be used */ /* because the copy was converted to uppercase: */ return ExecuteScript_ (mol_complexSP, mol_complexesNP, next_mol_complexIDP, runtimeSP, configSP, guiSP, nearest_atomSPP, pixelsNP, refreshIP); } /*------end of command recognition section.----------------------------------*/ /* If this point is reached, the command was not recognized! */ /* Prepare error message: */ strcpy (runtimeSP->messageA, "Command not recognized!"); runtimeSP->message_length = strlen (runtimeSP->messageA); /* Return the error code: */ return ERROR_UNREC_COMM; } /*===========================================================================*/ garlic-1.6/execute_command2.c0000644000076500007650000006751210116021523016477 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2003 Damir Zucic */ /*============================================================================= execute_command2.c Purpose: Parse and execute command. Refresh the message (reset or fill with a new content). This function is not capable to execute scripts. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Pointer to the number of macromolecular complexes. (3) Pointer to the next macromolecular complex identifier. (4) Pointer to RuntimeS structure, with some runtime data. (5) Pointer to ConfigS structure, with configuration data. (6) Pointer to GUIS structure, with GUI data. (7) Pointer to pointer to NearestAtomS structure. (8) Pointer to the number of pixels in the main win. free area. (9) Pointer to refreshI. Output: (1) The latest command executed. (2) Return value. Return value: (1) Positive on success (command code). (2) Zero, if command string is empty. (3) Negative on failure. Notes: (1) The value of refreshI (*refreshIP) may be changed in this function or in some function called by this function. It is checked in EventLoop_ (see event_loop.c). It is assumed that refreshI is updated no more than once in each event handling function. If this is not the case, the care should be taken to avoid refreshI overflow. (2) The command string is converted to uppercase. Do not forget that file names and some other things are case sensitive. Use the copy of the original command string to prepare the proper file name. ========includes:============================================================*/ #include #include #include #include #include #include #include #include "defines.h" #include "commands.h" #include "typedefs.h" /*======function prototypes:=================================================*/ char *ExtractToken_ (char *, int, char *, char *); int Load_ (MolComplexS *, int *, int *, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *); int Discard_ (MolComplexS *, int *, int *, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *, char *); int Catch_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *, char *); int Select_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *, char *, int); int Show_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *); int Hide_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *); int Color_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *, char *); int Atoms_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *, char *); int Bonds_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *, char *); int CommandRotate_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *, char *); int CommandTranslate_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *, char *); int CommandSlab_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *, char *); int CommandFading_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *, char *); int Log_ (ConfigS *, RuntimeS *); int Foreground_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *); int Background_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *); int TextBackground_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *); int TextForeground_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *); int Font_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS **, size_t *, unsigned int *); int CommandBackbone_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *, char *); int HydrogenBonds_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *, char *); int CommandStereo_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *, char *); int CommandMono_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *); int CommandPosition_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *, char *); int Title_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *); int Labels_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *, char *); int Register_ (void); int Center_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *); int Save_ (MolComplexS *, int, RuntimeS *); int Tag_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *); int Sequence_ (MolComplexS *, int, RuntimeS *, char *); int Ramachandran_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *, char *); int Wheel_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *, char *); int Angle_ (RuntimeS *, char *); int Radius_ (RuntimeS *, char *); int Venn_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *, char *); int SSB_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *, char *); int Window_ (RuntimeS *); int Plot_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *, char *); int CommandMove_ (MolComplexS *, int, RuntimeS *, char *); int Plane_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *, char *); int Scale_ (MolComplexS *, int, RuntimeS *, char *); int Pattern_ (MolComplexS *, int, RuntimeS *, char *); int Dock_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *, char *); int Compare_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *, char *); int Neighborhood_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *, char *); int Structure_ (MolComplexS *, int, RuntimeS *, char *); int Create_ (MolComplexS *, int *, int *, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *); int Replace_ (MolComplexS *, int, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *); int Edit_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *, char *); int Membrane_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *, char *); int Set_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *, char *); int Probe_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *, char *); int CommandRefresh_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *, char *); int Sticks_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *, char *); int Balls_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *, char *); int Blur_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *, char *); int Group_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int *, char *); int Dump_ (MolComplexS *, int, RuntimeS *, char *); /*======execute command (2):=================================================*/ int ExecuteCommand2_ (MolComplexS *mol_complexSP, int *mol_complexesNP, int *next_mol_complexIDP, RuntimeS *runtimeSP, ConfigS *configSP, GUIS *guiSP, NearestAtomS **nearest_atomSPP, size_t *pixelsNP, unsigned int *refreshIP) { char commandA[STRINGSIZE]; int command_length; int i; char *remainderP; char tokenA[STRINGSIZE]; /* Copy both command length and command string: */ command_length = runtimeSP->command_length; strncpy (commandA, runtimeSP->curr_commandA, runtimeSP->command_length); commandA[command_length] = '\0'; /* Convert the command string to uppercase: */ for (i = 0; i < command_length; i++) commandA[i] = toupper (commandA[i]); /* Truncate the message and reset the message length: */ runtimeSP->messageA[0] = '\0'; runtimeSP->message_length = 0; /* Take the first token - it should be the command word: */ remainderP = ExtractToken_ (tokenA, STRINGSIZE, commandA, " \t\n"); /* If there is nothing, return zero - the command string is empty: */ if (remainderP == NULL) return 0; /* Parse and execute the command: */ /*------quit, exit:----------------------------------------------------------*/ if ((strstr (tokenA, "QUI") == tokenA) || (strstr (tokenA, "EXI") == tokenA)) { return COMMAND_QUIT; } /*------pause:---------------------------------------------------------------*/ else if (strstr (tokenA, "PAU") == tokenA) { runtimeSP->pauseF = 1; strcpy (runtimeSP->messageA, "Press enter to continue!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return COMMAND_PAUSE; } /*------ignore:--------------------------------------------------------------*/ /* This command does nothing - it is added for debugging purpose! */ else if (strstr (tokenA, "IGN") == tokenA) { return COMMAND_IGNORE; } /*------select:--------------------------------------------------------------*/ /* Overwrite the previous selection: */ else if (strstr (tokenA, "SEL") == tokenA) { return Select_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP, remainderP, 0); } /*------restrict:------------------------------------------------------------*/ /* Restrict the previous selection: */ else if (strstr (tokenA, "RES") == tokenA) { return Select_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP, remainderP, 1); } /*------add:-----------------------------------------------------------------*/ /* Expand (add to) the previous selection: */ else if ((strstr (tokenA, "ADD") == tokenA) || (strstr (tokenA, "EXP") == tokenA)) { return Select_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP, remainderP, 2); } /*------load, read:----------------------------------------------------------*/ else if ((strstr (tokenA, "LOA") == tokenA) || (strstr (tokenA, "REA") == tokenA)) { /* The original command string should be used */ /* because the copy was converted to uppercase: */ return Load_ (mol_complexSP, mol_complexesNP, next_mol_complexIDP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP); } /*------discard:-------------------------------------------------------------*/ else if (strstr (tokenA, "DIS") == tokenA) { return Discard_ (mol_complexSP, mol_complexesNP, next_mol_complexIDP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP, remainderP); } /*------catch, take:---------------------------------------------------------*/ else if ((strstr (tokenA, "CAT") == tokenA) || (strstr (tokenA, "TAK") == tokenA)) { return Catch_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP, remainderP); } /*------show:----------------------------------------------------------------*/ else if (strstr (tokenA, "SHO") == tokenA) { return Show_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP); } /*------hide:----------------------------------------------------------------*/ else if (strstr (tokenA, "HID") == tokenA) { return Hide_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP); } /*------color:---------------------------------------------------------------*/ else if (strstr (tokenA, "COL") == tokenA) { return Color_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP, remainderP); } /*------atoms:---------------------------------------------------------------*/ else if (strstr (tokenA, "ATO") == tokenA) { return Atoms_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP, remainderP); } /*------bonds:---------------------------------------------------------------*/ else if (strstr (tokenA, "BON") == tokenA) { return Bonds_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP, remainderP); } /*------rotate:--------------------------------------------------------------*/ else if (strstr (tokenA, "ROT") == tokenA) { return CommandRotate_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP, remainderP); } /*------translate:-----------------------------------------------------------*/ else if (strstr (tokenA, "TRA") == tokenA) { return CommandTranslate_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP, remainderP); } /*------slab:----------------------------------------------------------------*/ else if (strstr (tokenA, "SLA") == tokenA) { return CommandSlab_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP, remainderP); } /*------fading:--------------------------------------------------------------*/ else if (strstr (tokenA, "FAD") == tokenA) { return CommandFading_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP, remainderP); } /*------log:-----------------------------------------------------------------*/ else if (strstr (tokenA, "LOG") == tokenA) { /* The original command string should be used */ /* because the copy was converted to uppercase: */ return Log_ (configSP, runtimeSP); } /*------fg:------------------------------------------------------------------*/ else if ((strcmp (tokenA, "FG") == 0) || (strstr (tokenA, "FOREG") == tokenA)) { /* The original command string should be used */ /* because the copy was converted to uppercase: */ return Foreground_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP); } /*------bg:------------------------------------------------------------------*/ else if ((strcmp (tokenA, "BG") == 0) || (strstr (tokenA, "BACKG") == tokenA)) { /* The original command string should be used */ /* because the copy was converted to uppercase: */ return Background_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP); } /*------tbg:-----------------------------------------------------------------*/ else if (strcmp (tokenA, "TBG") == 0) { /* The original command string should be used */ /* because the copy was converted to uppercase: */ return TextBackground_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP); } /*------tfg:-----------------------------------------------------------------*/ else if (strcmp (tokenA, "TFG") == 0) { /* The original command string should be used */ /* because the copy was converted to uppercase: */ return TextForeground_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP); } /*------font:----------------------------------------------------------------*/ else if (strstr (tokenA, "FON") == tokenA) { /* The original command string should be used */ /* because the copy was converted to uppercase: */ return Font_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, nearest_atomSPP, pixelsNP, refreshIP); } /*------backbone:------------------------------------------------------------*/ else if (strstr (tokenA, "BAC") == tokenA) { return CommandBackbone_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP, remainderP); } /*------hybonds:-------------------------------------------------------------*/ else if (strstr (tokenA, "HYB") == tokenA) { return HydrogenBonds_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP, remainderP); } /*------stereo:--------------------------------------------------------------*/ else if (strstr (tokenA, "STE") == tokenA) { return CommandStereo_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP, remainderP); } /*------mono:----------------------------------------------------------------*/ else if (strstr (tokenA, "MON") == tokenA) { return CommandMono_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP); } /*------position:------------------------------------------------------------*/ else if (strstr (tokenA, "POS") == tokenA) { return CommandPosition_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP, remainderP); } /*------title:---------------------------------------------------------------*/ else if (strstr (tokenA, "TIT") == tokenA) { /* The original command string should be used */ /* because the copy was converted to uppercase: */ return Title_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP); } /*------labels:--------------------------------------------------------------*/ else if (strstr (tokenA, "LAB") == tokenA) { return Labels_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP, remainderP); } /*------register:------------------------------------------------------------*/ else if (strstr (tokenA, "REG") == tokenA) { strcpy (runtimeSP->messageA, "A short e-mail message was send to the author."); runtimeSP->message_length = strlen (runtimeSP->messageA); Register_ (); return COMMAND_REGISTER; } /*------center:--------------------------------------------------------------*/ else if (strstr (tokenA, "CEN") == tokenA) { return Center_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP); } /*------save:----------------------------------------------------------------*/ else if (strstr (tokenA, "SAV") == tokenA) { /* The original command string should be used */ /* because the copy was converted to uppercase: */ return Save_ (mol_complexSP, *mol_complexesNP, runtimeSP); } /*------tag:-----------------------------------------------------------------*/ else if (strstr (tokenA, "TAG") == tokenA) { /* The original command string should be used */ /* because the copy was converted to uppercase: */ return Tag_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP); } /*------sequence:------------------------------------------------------------*/ else if (strstr (tokenA, "SEQ") == tokenA) { return Sequence_ (mol_complexSP, *mol_complexesNP, runtimeSP, remainderP); } /*------ramachandran:--------------------------------------------------------*/ else if (strstr (tokenA, "RAM") == tokenA) { return Ramachandran_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP, remainderP); } /*------wheel:---------------------------------------------------------------*/ else if (strstr (tokenA, "WHE") == tokenA) { return Wheel_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP, remainderP); } /*------angle:---------------------------------------------------------------*/ else if (strstr (tokenA, "ANG") == tokenA) { return Angle_ (runtimeSP, remainderP); } /*------radius:--------------------------------------------------------------*/ else if (strstr (tokenA, "RAD") == tokenA) { return Radius_ (runtimeSP, remainderP); } /*------venn:----------------------------------------------------------------*/ else if (strstr (tokenA, "VEN") == tokenA) { return Venn_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP, remainderP); } /*------ssb:-----------------------------------------------------------------*/ else if (strstr (tokenA, "SSB") == tokenA) { return SSB_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP, remainderP); } /*------window:--------------------------------------------------------------*/ else if (strstr (tokenA, "WIN") == tokenA) { return Window_ (runtimeSP); } /*------plot:----------------------------------------------------------------*/ else if (strstr (tokenA, "PLO") == tokenA) { return Plot_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP, remainderP); } /*------move:----------------------------------------------------------------*/ else if (strstr (tokenA, "MOV") == tokenA) { return CommandMove_ (mol_complexSP, *mol_complexesNP, runtimeSP, remainderP); } /*------plane:---------------------------------------------------------------*/ else if (strstr (tokenA, "PLA") == tokenA) { return Plane_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP, remainderP); } /*------scale:---------------------------------------------------------------*/ else if (strstr (tokenA, "SCA") == tokenA) { return Scale_ (mol_complexSP, *mol_complexesNP, runtimeSP, remainderP); } /*------pattern:-------------------------------------------------------------*/ else if (strstr (tokenA, "PAT") == tokenA) { return Pattern_ (mol_complexSP, *mol_complexesNP, runtimeSP, remainderP); } /*------dock:----------------------------------------------------------------*/ else if (strstr (tokenA, "DOC") == tokenA) { return Dock_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP, remainderP); } /*------compare:-------------------------------------------------------------*/ else if (strstr (tokenA, "COM") == tokenA) { return Compare_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP, remainderP); } /*------neighborhood:--------------------------------------------------------*/ else if (strstr (tokenA, "NEI") == tokenA) { return Neighborhood_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP, remainderP); } /*------structure:-----------------------------------------------------------*/ else if (strstr (tokenA, "STR") == tokenA) { return Structure_ (mol_complexSP, *mol_complexesNP, runtimeSP, remainderP); } /*------create:--------------------------------------------------------------*/ else if (strstr (tokenA, "CRE") == tokenA) { return Create_ (mol_complexSP, mol_complexesNP, next_mol_complexIDP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP); } /*------replace:-------------------------------------------------------------*/ else if (strstr (tokenA, "REP") == tokenA) { return Replace_ (mol_complexSP, *mol_complexesNP, *next_mol_complexIDP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP); } /*------edit:----------------------------------------------------------------*/ else if (strstr (tokenA, "EDI") == tokenA) { return Edit_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP, remainderP); } /*------membrane:------------------------------------------------------------*/ else if (strstr (tokenA, "MEM") == tokenA) { return Membrane_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP, remainderP); } /*------set:-----------------------------------------------------------------*/ else if (strstr (tokenA, "SET") == tokenA) { return Set_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP, remainderP); } /*------probe:---------------------------------------------------------------*/ else if (strstr (tokenA, "PRO") == tokenA) { return Probe_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP, remainderP); } /*------refresh:-------------------------------------------------------------*/ else if (strstr (tokenA, "REF") == tokenA) { return CommandRefresh_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP, remainderP); } /*------sticks:--------------------------------------------------------------*/ else if (strstr (tokenA, "STI") == tokenA) { return Sticks_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP, remainderP); } /*------balls:---------------------------------------------------------------*/ else if (strstr (tokenA, "BAL") == tokenA) { return Balls_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP, remainderP); } /*------blur:----------------------------------------------------------------*/ else if (strstr (tokenA, "BLU") == tokenA) { return Blur_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP, remainderP); } /*------group:---------------------------------------------------------------*/ else if (strstr (tokenA, "GRO") == tokenA) { return Group_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, *nearest_atomSPP, *pixelsNP, refreshIP, remainderP); } /*------dump:----------------------------------------------------------------*/ else if (strstr (tokenA, "DUM") == tokenA) { return Dump_ (mol_complexSP, *mol_complexesNP, runtimeSP, remainderP); } /*------end of command recognition section.----------------------------------*/ /* If this point is reached, the command was not recognized! */ /* Prepare error message: */ strcpy (runtimeSP->messageA, "Command not recognized!"); runtimeSP->message_length = strlen (runtimeSP->messageA); /* Return the error code: */ return ERROR_UNREC_COMM; } /*===========================================================================*/ garlic-1.6/add_bond.c0000644000076500007650000000513707461743130015020 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2002 Damir Zucic */ /*============================================================================= add_bond.c Purpose: Add one bond to the structure associated with a given atom. Add atomic pair ID, the array index of the complex to which the neighboring atom belongs, the array index of neighboring atom and bond length (the inter-atomic distance). Input: (1) Pointer to AtomS structure with data about the atom to which the bond belongs. (2) Atomic pair ID (see check_dist.c). (3) Bond type (0 covalent, 1 hydrogen, 2 disulfide, 11 pseudo). (3) Array index of the macromolecular complex to which neighbor belongs. (4) The array index of the neighbor. (5) Inter-atomic distance. (6) Default bond drawing style. Output: (1) One bond added to AtomS structure associated with a given atom. (2) Return value. Return value: (1) The updated number of bonds (positive, non-zero) on success. (2) Negative if the maximal number of bonds was reached before. Notes: (1) Zero is reserved as pair identifier of hydrogen bonds. (2) This function checks the total number of bonds. It will not allow the array overflow error. ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======add one bond to the atom:============================================*/ int AddBond_ (AtomS *atomSP, int pairID, int bond_typeI, int neighbor_mol_complexI, size_t neighbor_arrayI, double distance, int default_styleI) { int bondI; /* Prepare and check the bond index (equal to the previous number of bonds): */ bondI = atomSP->bondsN; if (bondI >= MAXBONDS) return -1; /* The number of bonds per atom is limited */ /* Update the number of bonds: */ atomSP->bondsN++; /* Initialize the bond drawing style: */ atomSP->true_bondSA[bondI].bond_styleI = default_styleI; /* PairID: */ atomSP->true_bondSA[bondI].pairID = pairID; /* Bond type: */ atomSP->true_bondSA[bondI].bond_typeI = bond_typeI; /* The array index of the complex to which neighbor belongs: */ atomSP->true_bondSA[bondI].neighbor_mol_complexI = neighbor_mol_complexI; /* Index number of the neighboring atom: */ atomSP->true_bondSA[bondI].neighbor_arrayI = neighbor_arrayI; /* Interatomic distance i.e. bond length: */ atomSP->true_bondSA[bondI].bond_length = distance; /* Return the updated number of bonds: */ return atomSP->bondsN; } /*===========================================================================*/ garlic-1.6/add_char.c0000644000076500007650000000523707307133206015010 0ustar zuciczucic00000000000000/* Copyright (C) 2000, 2001 Damir Zucic */ /*============================================================================= add_char.c Purpose: Add one character to the command string; copy the string to the history buffer. Input: (1) Pointer to RuntimeS structure. (2) Pointer to GUIS structure. (2) The new character. Output: (1) One character added to the input string. (2) Return value. Return value: (1) Positive on success. (2) Negative on failure. Notes: (1) Only insert mode is available: it is not possible to overwrite characters. (2) Input overflow is not allowed. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======add one character to command string:=================================*/ int AddCharToCommand_ (RuntimeS *runtimeSP, GUIS *guiSP, int new_char) { int comm_length, old_comm_length, carriage_pos; char stringA[COMMSTRINGSIZE]; char *currP; /* Copy the command string length and carriage (keyboard cursor) position: */ comm_length = runtimeSP->command_length; old_comm_length = comm_length; carriage_pos = runtimeSP->carriage_position; /* Check the command string length: */ if (comm_length >= COMMSTRINGSIZE - 2) return -1; /* Append the character to the end of command */ /* string, if carriage is at the end of string: */ if (carriage_pos == comm_length) { runtimeSP->curr_commandA[comm_length] = new_char; runtimeSP->curr_commandA[comm_length + 1] = '\0'; } /* Insert character, if carriage is not at the end of command string: */ else { strncpy (stringA, runtimeSP->curr_commandA, carriage_pos); stringA[carriage_pos] = new_char; stringA[carriage_pos + 1] = '\0'; strncat (stringA, runtimeSP->curr_commandA + carriage_pos, comm_length - carriage_pos); stringA[comm_length + 1] = '\0'; strcpy (runtimeSP->curr_commandA, stringA); } /* Update the command length and carriage position: */ comm_length++; runtimeSP->command_length = comm_length; carriage_pos++; runtimeSP->carriage_position = carriage_pos; /* Copy the command string to the history buffer: */ currP = runtimeSP->commandsP + runtimeSP->next_commandI * COMMSTRINGSIZE; strcpy (currP, runtimeSP->curr_commandA); /* Find and store the command string width: */ runtimeSP->left_part_widthA[old_comm_length] = XTextWidth (guiSP->main_winS.fontSP, runtimeSP->curr_commandA, runtimeSP->carriage_position); /* Return positive value (success): */ return 1; } /*===========================================================================*/ garlic-1.6/move_back_fading.c0000644000076500007650000000526307070337736016533 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= move_back_fading.c Purpose: Change the position of the back fading surface for each caught macromolecular complex. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. (3) Pointer to ConfigS structure. (4) Translation shift. Output: (1) The back fading surface moved. Return value: No return value. Notes: (1) Indentation is exceptionally 4 spaces. ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======move the back fading surface:========================================*/ void MoveBackFading_ (MolComplexS *mol_complexSP, int mol_complexesN, ConfigS *configSP, double shift) { int mol_complexI; MolComplexS *curr_mol_complexSP; for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check is the current macromolecular complex caught: */ if (curr_mol_complexSP->catchF == 0) continue; /* Move back fading surface: */ switch (curr_mol_complexSP->fading_modeI) { /* Planar fading: */ case 1: /* Prepare the new position: */ curr_mol_complexSP->fading_back_relative_position += shift; /* Check it: */ if (curr_mol_complexSP->fading_back_relative_position < curr_mol_complexSP->fading_front_relative_position + MINFADINGSPACING) { curr_mol_complexSP->fading_back_relative_position = curr_mol_complexSP->fading_front_relative_position + MINFADINGSPACING; } break; /* Spherical, semi-spher., cylindrical and semi-cyl. fading: */ case 2: case 3: case 4: case 5: /* Prepare the new position: */ curr_mol_complexSP->fading_back_relative_position -= shift; /* Check it: */ if (curr_mol_complexSP->fading_back_relative_position > curr_mol_complexSP->fading_front_relative_position - MINFADINGSPACING) { curr_mol_complexSP->fading_back_relative_position = curr_mol_complexSP->fading_front_relative_position - MINFADINGSPACING; } if (curr_mol_complexSP->fading_back_relative_position < 0) { curr_mol_complexSP->fading_back_relative_position = 0.0; } break; /* Ignore all other cases: */ default: ; } /* Set the position_changedF: */ curr_mol_complexSP->position_changedF = 1; } } /*===========================================================================*/ garlic-1.6/extract_token.c0000644000076500007650000000525207104006746016135 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= extract_token.c Purpose: Extract token (substring) from string. Up to max_length - 1 characters are copied. Input: (1) Pointer to the buffer where token will be stored. (2) The maximal length of the token (counting '\0'). (2) Pointer to the input string. (3) Pointer to the list (string) of separators. Output: (1) Token extracted and copied. (2) Return value. Return value: (1) Pointer to the next token, on success. (2) NULL on failure. Notes: (1) Input overflow is not allowed in this function. (2) The output token is always terminated properly. ========includes:============================================================*/ #include /*======extract token:=======================================================*/ char *ExtractToken_ (char *tokenP, int max_length, char *stringP, char *separatorsP) { int current_char, current_separator; int separator_foundF, token_foundF; char *P; int token_length = 0; /* Initialize the output string: */ *tokenP = '\0'; /* Check the input string pointer: */ if (stringP == NULL) return NULL; /* Skip leading separators: */ token_foundF = 0; while ((current_char = *stringP++) != '\0') { /** Search the set of separators: **/ P = separatorsP; separator_foundF = 0; while ((current_separator = *P++) != '\0') { if (current_char == current_separator) { separator_foundF = 1; break; } } /** If the current character does not belong to **/ /** the set of separators, the token is reached: **/ if (!separator_foundF) { token_foundF = 1; break; } } /* Pointer to the last character; this is either */ /* zero or the first character of the token: */ stringP--; /* If token was not reached at all, return NULL: */ if (*stringP == '\0') return NULL; /* Copy the token: */ while ((current_char = *stringP++) != '\0') { /** Search the set of separators: **/ P = separatorsP; separator_foundF = 0; while ((current_separator = *P++) != '\0') { if (current_char == current_separator) { separator_foundF = 1; break; } } /** If the current character belongs to the set **/ /** of separators, the end of token is reached: **/ if (separator_foundF) break; /** If end of token is not reached, copy the current character: **/ *tokenP++ = current_char; /** Update and check the token length: **/ token_length++; if (token_length >= max_length - 1) break; } /* Terminate the token: */ *tokenP = '\0'; /* Return the pointer to the remainder of the string: */ return --stringP; } /*===========================================================================*/ garlic-1.6/backup-hyd.script0000755000076500007650000000115610435553307016377 0ustar zuciczucic00000000000000# Back up some hydrophobic functions. cp hyphob_function1.c /home/zucic/research/porins/$(timestring)-hyphob_function1.c cp hyphob_function2.c /home/zucic/research/porins/$(timestring)-hyphob_function2.c cp hyphob_function3.c /home/zucic/research/porins/$(timestring)-hyphob_function3.c cp hyphob_function4.c /home/zucic/research/porins/$(timestring)-hyphob_function4.c cp hyphob_function5.c /home/zucic/research/porins/$(timestring)-hyphob_function5.c cp hyphob_function6.c /home/zucic/research/porins/$(timestring)-hyphob_function6.c cp hyphob_function7.c /home/zucic/research/porins/$(timestring)-hyphob_function7.c garlic-1.6/residue_ranges.c0000644000076500007650000000432307065474643016273 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= residue_ranges.c Purpose: Extract residue ranges (serial numbers) from the list. Input: (1) Pointer to SelectS structure, where data will be stored. (2) Pointer to the string with list of ranges. Output: (1) Some data added to SelectS structure. (2) Return value. Return value: (1) Positive on success. (2) Negative on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ char *ExtractToken_ (char *, int, char *, char *); int ExtractSerials_ (int *, int *, char *); /*======extract residue ranges:==============================================*/ int ExtractResidueRanges_ (SelectS *selectSP, char *stringP) { char *remainderP; char tokenA[SHORTSTRINGSIZE]; int max; int n1, n2; int rangeI; /* Check the string length: */ if (strlen (stringP) == 0) return -1; /* Initialize all_residue_serialF (1 = select all serial numbers): */ selectSP->all_residue_serialF = 0; /* Initialize the number of ranges: */ selectSP->residue_serial_rangesN = 0; /* If wildcard (asterisk) is present, set */ /* all_residue_serialF to one and return: */ if (strstr (stringP, "*")) { selectSP->all_residue_serialF = 1; return 1; } /* Parse the list of ranges: */ remainderP = stringP; max = SHORTSTRINGSIZE; while ((remainderP = ExtractToken_ (tokenA, max, remainderP, " \t,;")) != NULL) { /** Extract serial numbers: **/ if (ExtractSerials_ (&n1, &n2, tokenA) < 0) return -2; /** Copy serial numbers: **/ rangeI = selectSP->residue_serial_rangesN; selectSP->residue_serial_start[rangeI] = n1; selectSP->residue_serial_end[rangeI] = n2; /** Increase and check the number of ranges: **/ selectSP->residue_serial_rangesN++; if (selectSP->residue_serial_rangesN >= MAXFIELDS) break; } /* Return positive value on success: */ return 1; } /*===========================================================================*/ garlic-1.6/color_shifts.c0000644000076500007650000001320607065467633015773 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= color_shifts.c Purpose: Prepare left and right color shift for RGB color components. Each color component (red, green and blue) must be shifted properly to prepare the pixel value for a given RGB triplet. Every component should be shifted first to the right, to remove unused bits, then to the left, to put the remaining bits into the proper position. This function prepares the shifts for all three RGB components. Shifts are used later to prepare colors for drawing. Masks from XVisualInfo structure (part of GUIS structure) are used as input. Input: (1) Pointer to GUIS structure. Input data are there; output data will be stored to the same structure. Output: (1) Data added to GUIS structure. (2) Return value. Return value: (1) Positive on success. (2) Negative on failure. =============================================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ void ErrorMessage_ (char *, char *, char *, char *, char *, char *, char *); /*======prepare color shifts:================================================*/ int PrepareColorShifts_ (GUIS *guiSP) { XColor colorS; int color_component_size, pixel_value_size; unsigned long mask, lowest_bit_mask = 1; int lowest_bit_position, highest_bit_position, bitsN; int i; /* Prepare the color component size int bits (16 expected): */ color_component_size = 8 * sizeof (colorS.red); /* Prepare the pixel value size in bits (32 expected): */ pixel_value_size = 8 * sizeof (colorS.pixel); /*---------------------------------------------------------------------------*/ /* Find the shifts for red color component: */ /** Check the red mask: **/ if (guiSP->visual_infoS.red_mask == 0) { ErrorMessage_ ("garlic", "PrepareColorShifts_", "", "Red mask equal to zero!\n", "", "", ""); return -1; } /** The least significant bit position: **/ mask = guiSP->visual_infoS.red_mask; lowest_bit_position = -1; for (i = 0; i < pixel_value_size; i++) { if ((mask >> i) & lowest_bit_mask) { lowest_bit_position = i; break; } } /** Check was it found at all: **/ if (lowest_bit_position < 0) { ErrorMessage_ ("garlic", "PrepareColorShifts_", "", "Unable to find the lowest bit position", " in the red mask!\n", "", ""); return -2; } /** The most significant bit position: **/ mask = guiSP->visual_infoS.red_mask; highest_bit_position = lowest_bit_position; for (i = lowest_bit_position; i < pixel_value_size; i++) { if (!((mask >> i) & lowest_bit_mask)) break; highest_bit_position = i; } /** Prepare the shifts: **/ bitsN = highest_bit_position - lowest_bit_position + 1; guiSP->red_right_shift = color_component_size - bitsN; guiSP->red_left_shift = lowest_bit_position; /*---------------------------------------------------------------------------*/ /* Find the shifts for green color component: */ /** Check the green mask: **/ if (guiSP->visual_infoS.green_mask == 0) { ErrorMessage_ ("garlic", "PrepareColorShifts_", "", "Green mask equal to zero!\n", "", "", ""); return -3; } /** The least significant bit position: **/ mask = guiSP->visual_infoS.green_mask; lowest_bit_position = -1; for (i = 0; i < pixel_value_size; i++) { if ((mask >> i) & lowest_bit_mask) { lowest_bit_position = i; break; } } /** Check was it found at all: **/ if (lowest_bit_position < 0) { ErrorMessage_ ("garlic", "PrepareColorShifts_", "", "Unable to find the lowest bit position", " in the green mask!\n", "", ""); return -4; } /** The most significant bit position: **/ mask = guiSP->visual_infoS.green_mask; highest_bit_position = lowest_bit_position; for (i = lowest_bit_position; i < pixel_value_size; i++) { if (!((mask >> i) & lowest_bit_mask)) break; highest_bit_position = i; } /** Prepare the shifts: **/ bitsN = highest_bit_position - lowest_bit_position + 1; guiSP->green_right_shift = color_component_size - bitsN; guiSP->green_left_shift = lowest_bit_position; /*---------------------------------------------------------------------------*/ /* Find the shifts for blue color component: */ /** Check the blue mask: **/ if (guiSP->visual_infoS.blue_mask == 0) { ErrorMessage_ ("garlic", "PrepareColorShifts_", "", "Blue mask equal to zero!\n", "", "", ""); return -5; } /** The least significant bit position: **/ mask = guiSP->visual_infoS.blue_mask; lowest_bit_position = -1; for (i = 0; i < pixel_value_size; i++) { if ((mask >> i) & lowest_bit_mask) { lowest_bit_position = i; break; } } /** Check was it found at all: **/ if (lowest_bit_position < 0) { ErrorMessage_ ("garlic", "PrepareColorShifts_", "", "Unable to find the lowest bit position", " in the blue mask!\n", "", ""); return -6; } /** The most significant bit position: **/ mask = guiSP->visual_infoS.blue_mask; highest_bit_position = lowest_bit_position; for (i = lowest_bit_position; i < pixel_value_size; i++) { if (!((mask >> i) & lowest_bit_mask)) break; highest_bit_position = i; } /** Prepare the shifts: **/ bitsN = highest_bit_position - lowest_bit_position + 1; guiSP->blue_right_shift = color_component_size - bitsN; guiSP->blue_left_shift = lowest_bit_position; /*---------------------------------------------------------------------------*/ /* Return positive value on success: */ return 1; } /*===========================================================================*/ garlic-1.6/edit_phi.c0000644000076500007650000001023007370732516015046 0ustar zuciczucic00000000000000/* Copyright (C) 2001 Damir Zucic */ /*============================================================================= edit_phi.c Purpose: Edit phi angle. If edit_single_bondF is zero, edit phi for every selected residue in the specified macromolecular complex. If the flag edit_single_bondF is different from zero, edit only the phi angle for the bond specified by the given atomic array indices. A residue is treated as selected if the first atom of this residue is selected. For protein residues, this is typically N atom (nitrogen). Input: (1) Pointer to MolComplexS structure. (2) Pointer to RuntimeS structure. (3) Pointer to ConfigS structure. (4) Rotation angle. Output: (1) Phi angle changed for chosen residue(s). (2) Return value. Return value: (1) Positive always (trivial). ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int ExtractNCA_ (VectorS *, VectorS *, AtomS *, size_t, size_t); int RotateAtom_ (AtomS *, VectorS *, VectorS *, double); int DihedralAngles_ (MolComplexS *, ConfigS *); /*======change phi angle for selected residues:==============================*/ int EditPhi_ (MolComplexS *mol_complexSP, RuntimeS *runtimeSP, ConfigS *configSP, double delta_phi) { int residuesN, residueI; size_t atomsN; ResidueS *residueSP; size_t atom_startI, atom_endI, atomI; AtomS *atomSP; int n; static VectorS N_vectorS, CA_vectorS; /* Copy the number of residues in the current complex: */ residuesN = mol_complexSP->residuesN; /* Copy the number of atoms in the current complex: */ atomsN = mol_complexSP->atomsN; /* Scan residues: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Pointer to the current residue: */ residueSP = mol_complexSP->residueSP + residueI; /* Prepare the atomic index range: */ atom_startI = residueSP->residue_startI; atom_endI = residueSP->residue_endI; /* Pointer to the first atom: */ atomSP = mol_complexSP->atomSP + atom_startI; /* Check the edit_single_bondF flag. If this flag is equal */ /* to zero, the current selection should be taken into */ /* account. Otherwise, the selection should be ignored. */ /* Editing of a single phi angle requested: */ if (runtimeSP->edit_single_bondF) { /* Check the array indices of N and CA: */ if ((runtimeSP->atom1_arrayI < atom_startI) || (runtimeSP->atom1_arrayI > atom_endI) || (runtimeSP->atom2_arrayI < atom_startI) || (runtimeSP->atom2_arrayI > atom_endI)) { continue; } } /* Editing of phi angles for all selected residues requested: */ else { /* If the first atom of the current residue is */ /* not selected, the residue is not selected: */ if (atomSP->selectedF == 0) continue; } /* Extract N and CA coordinates: */ n = ExtractNCA_ (&N_vectorS, &CA_vectorS, mol_complexSP->atomSP, atom_startI, atom_endI); if (n < 2) continue; /* Change the phi angle: */ for (atomI = atom_startI; atomI <= atom_endI; atomI++) { /* Pointer to the current atom: */ atomSP = mol_complexSP->atomSP + atomI; /* Do not rotate H, N and CA: */ if ((strcmp (atomSP->raw_atomS.pure_atom_nameA, "H") == 0) || (strcmp (atomSP->raw_atomS.pure_atom_nameA, "N") == 0) || (strcmp (atomSP->raw_atomS.pure_atom_nameA, "CA") == 0)) { continue; } /* Rotate the current atom about N-CA bond: */ RotateAtom_ (atomSP, &N_vectorS, &CA_vectorS, delta_phi); } /* Rotate all atoms after the current residue about N-CA bond: */ for (atomI = atom_endI + 1; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ atomSP = mol_complexSP->atomSP + atomI; /* Rotate atom: */ RotateAtom_ (atomSP, &N_vectorS, &CA_vectorS, delta_phi); } } /* Update dihedral angles and cis-trans flags: */ DihedralAngles_ (mol_complexSP, configSP); /* Return positive value (trivial): */ return 1; } /*===========================================================================*/ garlic-1.6/rotate.c0000644000076500007650000002054307415612537014567 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2002 Damir Zucic */ /*============================================================================= rotate.c Purpose: Rotate all caught macromolecular complexes or edit default complex. Input: (1) Pointer to MolComplexS structure, with macromolecular complexes. (2) Number of macromolecular complexes. (3) Pointer to RuntimeS structure. (4) Pointer to ConfigS structure. (5) Rotation angle. (6) Rotation axis identifier (1 = x, 2 = y, 3 = z). Output: (1) Atoms rotated in all caught macromolecular complexes. Return value: (1) Edit mode index (positive or zero) on success. (2) Negative on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int EditPhi_ (MolComplexS *, RuntimeS *, ConfigS *, double); int EditPsi_ (MolComplexS *, RuntimeS *, ConfigS *, double); int EditOmega_ (MolComplexS *, RuntimeS *, ConfigS *, double); int EditBond_ (MolComplexS *, int, RuntimeS *, ConfigS *, double); int EditChi1_ (MolComplexS *, RuntimeS *, ConfigS *, double); int EditChi2_ (MolComplexS *, RuntimeS *, ConfigS *, double); int PrepareStereoData_ (MolComplexS *, ConfigS *); void RotatePlane_ (MolComplexS *, ConfigS *, double, int); void RotateMembrane_ (MolComplexS *, ConfigS *, double, int); /*======rotate all caught macromol. complexes:===============================*/ int Rotate_ (MolComplexS *mol_complexSP, int mol_complexesN, RuntimeS *runtimeSP, ConfigS *configSP, double rotation_angle, int axisID) { MolComplexS *curr_mol_complexSP; int edit_modeI; int mol_complexI; double cos_angle, sin_angle; size_t atomsN, atomI; AtomS *curr_atomSP; double x0, y0, z0, x, y, z, x_new = 0.0, y_new = 0.0, z_new = 0.0; /* Pointer to default macromolecular complex: */ curr_mol_complexSP = mol_complexSP + runtimeSP->default_complexI; /* Copy the edit mode index: */ edit_modeI = runtimeSP->edit_modeI; /* Check the axis identifier and edit mode index. */ /* If axisID is three and edit_modeI is two, three, four or */ /* six, edit phi, psi, omega or selected side chain bond: */ if ((axisID == 3) && ((edit_modeI == 2) || (edit_modeI == 3) || (edit_modeI == 4) || (edit_modeI == 6))) { /* Edit phi: */ if (edit_modeI == 2) { EditPhi_ (curr_mol_complexSP, runtimeSP, configSP, rotation_angle); } /* Edit psi: */ else if (edit_modeI == 3) { EditPsi_ (curr_mol_complexSP, runtimeSP, configSP, rotation_angle); } /* Edit omega: */ else if (edit_modeI == 4) { EditOmega_ (curr_mol_complexSP, runtimeSP, configSP, rotation_angle); } /* Edit some other bond (side chain): */ else if (edit_modeI == 6) { EditBond_ (curr_mol_complexSP, runtimeSP->default_complexI, runtimeSP, configSP, rotation_angle); } /* Prepare the stereo data, update one */ /* flag and return the edit mode index: */ /* Prepare stereo data, if required: */ if (configSP->stereoF) { PrepareStereoData_ (curr_mol_complexSP, configSP); } /* Set the position_changedF: */ curr_mol_complexSP->position_changedF = 1; /* Return the edit mode index: */ return edit_modeI; } /* If axis identifier is two and edit_modeI is five, edit phi: */ else if ((axisID == 2) && (edit_modeI == 5)) { /* Edit phi: */ rotation_angle *= -1; EditPhi_ (curr_mol_complexSP, runtimeSP, configSP, rotation_angle); /* Prepare the stereo data, update one */ /* flag and return the edit mode index: */ /* Prepare stereo data, if required: */ if (configSP->stereoF) { PrepareStereoData_ (curr_mol_complexSP, configSP); } /* Set the position_changedF: */ curr_mol_complexSP->position_changedF = 1; /* Return the edit mode index: */ return edit_modeI; } /* If axis identifier is two and edit_modeI is seven, edit chi1: */ else if ((axisID == 2) && (edit_modeI == 7)) { /* Edit chi1: */ rotation_angle *= -1; EditChi1_ (curr_mol_complexSP, runtimeSP, configSP, rotation_angle); /* Prepare the stereo data, update one */ /* flag and return the edit mode index: */ /* Prepare stereo data, if required: */ if (configSP->stereoF) { PrepareStereoData_ (curr_mol_complexSP, configSP); } /* Set the position_changedF: */ curr_mol_complexSP->position_changedF = 1; /* Return the edit mode index: */ return edit_modeI; } /* If axis identifier is one and edit_modeI is five, edit psi: */ else if ((axisID == 1) && (edit_modeI == 5)) { /* Edit psi: */ rotation_angle *= -1; EditPsi_ (curr_mol_complexSP, runtimeSP, configSP, rotation_angle); /* Prepare the stereo data, update one */ /* flag and return the edit mode index: */ /* Prepare stereo data, if required: */ if (configSP->stereoF) { PrepareStereoData_ (curr_mol_complexSP, configSP); } /* Set the position_changedF: */ curr_mol_complexSP->position_changedF = 1; /* Return the edit mode index: */ return edit_modeI; } /* If axis identifier is one and edit_modeI is seven, edit chi2: */ else if ((axisID == 1) && (edit_modeI == 7)) { /* Edit chi2: */ rotation_angle *= -1; EditChi2_ (curr_mol_complexSP, runtimeSP, configSP, rotation_angle); /* Prepare the stereo data, update one */ /* flag and return the edit mode index: */ /* Prepare stereo data, if required: */ if (configSP->stereoF) { PrepareStereoData_ (curr_mol_complexSP, configSP); } /* Set the position_changedF: */ curr_mol_complexSP->position_changedF = 1; /* Return the edit mode index: */ return edit_modeI; } /* If this point is reached, the entire structure should be rotated. */ /* Calculate cosine and sine of the rotation angle: */ cos_angle = cos (rotation_angle); sin_angle = sin (rotation_angle); /* If working in default mode, rotate the entire structure: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check is the current macromolecular complex caught: */ if (curr_mol_complexSP->catchF == 0) continue; /* Check is it necessary to rotate the plane: */ if (curr_mol_complexSP->move_bits & PLANE_MASK) { RotatePlane_ (curr_mol_complexSP, configSP, rotation_angle, axisID); } /* Check is it necessary to rotate the membrane: */ if (curr_mol_complexSP->move_bits & MEMBRANE_MASK) { RotateMembrane_ (curr_mol_complexSP, configSP, rotation_angle, axisID); } /* Check is it necessary to rotate the structure at all: */ if (!(curr_mol_complexSP->move_bits & STRUCTURE_MASK)) continue; /* Copy the rotation center coordinates: */ x0 = curr_mol_complexSP->rotation_center_vectorS.x; y0 = curr_mol_complexSP->rotation_center_vectorS.y; z0 = curr_mol_complexSP->rotation_center_vectorS.z; /* Number of atoms in a macromolecular complex: */ atomsN = curr_mol_complexSP->atomsN; /* Scan all atoms in the current complex: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Coordinates relative to the rotation center: */ x = curr_atomSP->raw_atomS.x[0] - x0; y = curr_atomSP->raw_atomS.y - y0; z = curr_atomSP->raw_atomS.z[0] - z0; /* Rotate these coordinates: */ switch (axisID) { /* Rotate around x: */ case 1: x_new = x; y_new = y * cos_angle - z * sin_angle; z_new = y * sin_angle + z * cos_angle; break; /* Rotate around y: */ case 2: x_new = x * cos_angle + z * sin_angle; y_new = y; z_new = -x * sin_angle + z * cos_angle; break; /* Rotate around z: */ case 3: x_new = x * cos_angle - y * sin_angle; y_new = x * sin_angle + y * cos_angle; z_new = z; break; /* The impossible case: */ default: ; break; } /* Translate and store new coordinates: */ curr_atomSP->raw_atomS.x[0] = x_new + x0; curr_atomSP->raw_atomS.y = y_new + y0; curr_atomSP->raw_atomS.z[0] = z_new + z0; } /* Prepare stereo data, if required: */ if (configSP->stereoF) { PrepareStereoData_ (curr_mol_complexSP, configSP); } /* Set the position_changedF: */ curr_mol_complexSP->position_changedF = 1; } /* Return edit mode index: */ return edit_modeI; } /*===========================================================================*/ garlic-1.6/edit_psi.c0000644000076500007650000001002207370732552015060 0ustar zuciczucic00000000000000/* Copyright (C) 2001 Damir Zucic */ /*============================================================================= edit_psi.c Purpose: Edit psi angle. If edit_single_bondF is zero, edit psi for every selected residue in the specified macromolecular complex. If the flag edit_single_bondF is different from zero, edit only the psi angle for the bond specified by the given atomic array indices. A residue is treated as selected if the first atom of this residue is selected. For protein residues, this is typically N atom (nitrogen). Input: (1) Pointer to MolComplexS structure. (2) Pointer to RuntimeS structure. (3) Pointer to ConfigS structure. (4) Rotation angle. Output: (1) Psi angle changed for chosen residue(s). (2) Return value. Return value: (1) Positive always (trivial). ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int ExtractCAC_ (VectorS *, VectorS *, AtomS *, size_t, size_t); int RotateAtom_ (AtomS *, VectorS *, VectorS *, double); int DihedralAngles_ (MolComplexS *, ConfigS *); /*======change psi angle for selected residues:==============================*/ int EditPsi_ (MolComplexS *mol_complexSP, RuntimeS *runtimeSP, ConfigS *configSP, double delta_psi) { int residuesN, residueI; size_t atomsN; ResidueS *residueSP; size_t atom_startI, atom_endI, atomI; AtomS *atomSP; int n; static VectorS CA_vectorS, C_vectorS; /* Copy the number of residues in the current complex: */ residuesN = mol_complexSP->residuesN; /* Copy the number of atoms in the current complex: */ atomsN = mol_complexSP->atomsN; /* Scan residues: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Pointer to the current residue: */ residueSP = mol_complexSP->residueSP + residueI; /* Prepare the atomic index range: */ atom_startI = residueSP->residue_startI; atom_endI = residueSP->residue_endI; /* Pointer to the first atom: */ atomSP = mol_complexSP->atomSP + atom_startI; /* Check the edit_single_bondF flag. If this flag is equal */ /* to zero, the current selection should be taken into */ /* account. Otherwise, the selection should be ignored. */ /* Editing of a single psi angle requested: */ if (runtimeSP->edit_single_bondF) { /* Check the array indices of CA and C: */ if ((runtimeSP->atom1_arrayI < atom_startI) || (runtimeSP->atom1_arrayI > atom_endI) || (runtimeSP->atom2_arrayI < atom_startI) || (runtimeSP->atom2_arrayI > atom_endI)) { continue; } } /* Editing of psi angles for all selected residues requested: */ else { /* If the first atom of the current residue is */ /* not selected, the residue is not selected: */ if (atomSP->selectedF == 0) continue; } /* Extract CA and C coordinates: */ n = ExtractCAC_ (&CA_vectorS, &C_vectorS, mol_complexSP->atomSP, atom_startI, atom_endI); if (n < 2) continue; /* Change the psi angle: */ for (atomI = atom_startI; atomI <= atom_endI; atomI++) { /* Pointer to the current atom: */ atomSP = mol_complexSP->atomSP + atomI; /* Rotate only the O atom: */ if (strcmp (atomSP->raw_atomS.pure_atom_nameA, "O") != 0) { continue; } /* If this point is reached, rotate O atom about CA-C bond: */ RotateAtom_ (atomSP, &CA_vectorS, &C_vectorS, delta_psi); } /* Rotate all atoms after the current residue about CA-C bond: */ for (atomI = atom_endI + 1; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ atomSP = mol_complexSP->atomSP + atomI; /* Rotate atom: */ RotateAtom_ (atomSP, &CA_vectorS, &C_vectorS, delta_psi); } } /* Update dihedral angles and cis-trans flags: */ DihedralAngles_ (mol_complexSP, configSP); /* Return positive value (trivial): */ return 1; } /*===========================================================================*/ garlic-1.6/spacefill_color.c0000644000076500007650000000661507572731265016441 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2002 Damir Zucic */ /*============================================================================= spacefill_color.c Purpose: Prepare the color for a single pixel which is on the atomic sphere surface. Input: (1) Pointer to AtomS structure. (2) Pointer to GUIS structure. (3) Cosine of the angle between the vector from sphere center and the current pixel and the light source unit vector. Output: (1) Return value. Return value: The pixel (color) value. Notes: (1) This function uses left, right and black color. Note that the middle color is not used here! (2) This function may be quite slow (a lot of math). =============================================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======spacefill color:=====================================================*/ unsigned long SpacefillColor_ (AtomS *curr_atomSP, GUIS *guiSP, double cos_angle) { static long double w1, w2; static unsigned long colorID; static unsigned long red_mask, green_mask, blue_mask; static unsigned long red1, red2, red; static unsigned long green1, green2, green; static unsigned long blue1, blue2, blue; static long double r1, r2, g1, g2, b1, b2; static long double r, g, b; /* Factors which are used to weight colors: */ w1 = cos_angle * cos_angle; w2 = 1 - w1; /* Copy masks: */ red_mask = guiSP->visual_infoS.red_mask; green_mask = guiSP->visual_infoS.green_mask; blue_mask = guiSP->visual_infoS.blue_mask; /* Bright side (cos_angle between zero and one): */ if (cos_angle >= 0.0) { /* Extract input color components: */ red1 = curr_atomSP->left_colorID & red_mask; red2 = curr_atomSP->right_colorID & red_mask; green1 = curr_atomSP->left_colorID & green_mask; green2 = curr_atomSP->right_colorID & green_mask; blue1 = curr_atomSP->left_colorID & blue_mask; blue2 = curr_atomSP->right_colorID & blue_mask; /* Convert to doubles: */ r1 = (double) red1; r2 = (double) red2; g1 = (double) green1; g2 = (double) green2; b1 = (double) blue1; b2 = (double) blue2; /* Calculate new color components: */ r = w1 * r1 + w2 * r2; g = w1 * g1 + w2 * g2; b = w1 * b1 + w2 * b2; } /* Dark side (cos_angle between minus one and zero): */ else { /* Extract input color components: */ red1 = curr_atomSP->right_colorID & red_mask; red2 = guiSP->black_colorID & red_mask; green1 = curr_atomSP->right_colorID & green_mask; green2 = guiSP->black_colorID & green_mask; blue1 = curr_atomSP->right_colorID & blue_mask; blue2 = guiSP->black_colorID & blue_mask; /* Convert to doubles: */ r1 = (double) red1; r2 = (double) red2; g1 = (double) green1; g2 = (double) green2; b1 = (double) blue1; b2 = (double) blue2; /* Calculate new color components: */ r = w2 * r1 + w1 * r2; g = w2 * g1 + w1 * g2; b = w2 * b1 + w1 * b2; } /* Check new color components: */ if (r < 0.0) r = 0.0; if (g < 0.0) g = 0.0; if (b < 0.0) b = 0.0; /* Convert new color components: */ red = ((unsigned long) r) & red_mask; green = ((unsigned long) g) & green_mask; blue = ((unsigned long) b) & blue_mask; /* Combine new color components: */ colorID = red | green | blue; /* Return the pixel value: */ return colorID; } /*===========================================================================*/ garlic-1.6/init_colors.c0000644000076500007650000005027507762176050015622 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2003 Damir Zucic */ /*============================================================================= init_colors.c Purpose: Initialize the predefined (hard-coded) color schemes. Input: (1) Pointer to ColorSchemeS structure. (2) Pointer to GUIS structure. Output: (1) Predefined color schemes initialized. (2) Return value. Return value: (1) Positive always (trivial). =============================================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int ParseColor_ (RGBS *, unsigned long *, GUIS *, char *, char *); /*======predefined color schemes:============================================*/ int InitializeColors_ (ColorSchemeS *color_schemeSP, GUIS *guiSP) { size_t rgb_struct_size; RGBS rgbS; unsigned long dummyID; /* The size of RGBS structure: */ rgb_struct_size = sizeof (RGBS); /*------RED (0):-------------------------------------------------------------*/ (color_schemeSP + 0)->surfacesN = 2; /* Surface 0: */ ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:FFFF/8888/8888", "white"); memcpy ((color_schemeSP + 0)->left_rgbSA, &rgbS, rgb_struct_size); ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:FFFF/0000/0000", "white"); memcpy ((color_schemeSP + 0)->middle_rgbSA, &rgbS, rgb_struct_size); ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:8888/0000/0000", "white"); memcpy ((color_schemeSP + 0)->right_rgbSA, &rgbS, rgb_struct_size); /* Surface 1: */ ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:6666/0000/0000", "white"); memcpy ((color_schemeSP + 0)->left_rgbSA + 1, &rgbS, rgb_struct_size); ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:4444/0000/0000", "white"); memcpy ((color_schemeSP + 0)->middle_rgbSA + 1, &rgbS, rgb_struct_size); ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:2222/0000/0000", "white"); memcpy ((color_schemeSP + 0)->right_rgbSA + 1, &rgbS, rgb_struct_size); /*------GREEN (1):-----------------------------------------------------------*/ (color_schemeSP + 1)->surfacesN = 2; /* Surface 0: */ ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:8888/FFFF/8888", "white"); memcpy ((color_schemeSP + 1)->left_rgbSA, &rgbS, rgb_struct_size); ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:0000/FFFF/0000", "white"); memcpy ((color_schemeSP + 1)->middle_rgbSA, &rgbS, rgb_struct_size); ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:0000/8888/0000", "white"); memcpy ((color_schemeSP + 1)->right_rgbSA, &rgbS, rgb_struct_size); /* Surface 1: */ ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:0000/6666/0000", "white"); memcpy ((color_schemeSP + 1)->left_rgbSA + 1, &rgbS, rgb_struct_size); ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:0000/4444/0000", "white"); memcpy ((color_schemeSP + 1)->middle_rgbSA + 1, &rgbS, rgb_struct_size); ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:0000/2222/0000", "white"); memcpy ((color_schemeSP + 1)->right_rgbSA + 1, &rgbS, rgb_struct_size); /*------BLUE (2):------------------------------------------------------------*/ (color_schemeSP + 2)->surfacesN = 2; /* Surface 0: */ ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:8888/8888/FFFF", "white"); memcpy ((color_schemeSP + 2)->left_rgbSA, &rgbS, rgb_struct_size); ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:0000/0000/FFFF", "white"); memcpy ((color_schemeSP + 2)->middle_rgbSA, &rgbS, rgb_struct_size); ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:0000/0000/8888", "white"); memcpy ((color_schemeSP + 2)->right_rgbSA, &rgbS, rgb_struct_size); /* Surface 1: */ ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:0000/0000/6666", "white"); memcpy ((color_schemeSP + 2)->left_rgbSA + 1, &rgbS, rgb_struct_size); ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:0000/0000/4444", "white"); memcpy ((color_schemeSP + 2)->middle_rgbSA + 1, &rgbS, rgb_struct_size); ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:0000/0000/2222", "white"); memcpy ((color_schemeSP + 2)->right_rgbSA + 1, &rgbS, rgb_struct_size); /*------YELLOW (3):----------------------------------------------------------*/ (color_schemeSP + 3)->surfacesN = 2; /* Surface 0: */ ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:FFFF/FFFF/8888", "white"); memcpy ((color_schemeSP + 3)->left_rgbSA, &rgbS, rgb_struct_size); ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:FFFF/FFFF/0000", "white"); memcpy ((color_schemeSP + 3)->middle_rgbSA, &rgbS, rgb_struct_size); ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:8888/8888/0000", "white"); memcpy ((color_schemeSP + 3)->right_rgbSA, &rgbS, rgb_struct_size); /* Surface 1: */ ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:3333/3333/0000", "white"); memcpy ((color_schemeSP + 3)->left_rgbSA + 1, &rgbS, rgb_struct_size); ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:2222/2222/0000", "white"); memcpy ((color_schemeSP + 3)->middle_rgbSA + 1, &rgbS, rgb_struct_size); ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:1111/1111/0000", "white"); memcpy ((color_schemeSP + 3)->right_rgbSA + 1, &rgbS, rgb_struct_size); /*------CYAN (4):------------------------------------------------------------*/ (color_schemeSP + 4)->surfacesN = 2; /* Surface 0: */ ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:DDDD/FFFF/FFFF", "white"); memcpy ((color_schemeSP + 4)->left_rgbSA, &rgbS, rgb_struct_size); ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:0000/FFFF/FFFF", "white"); memcpy ((color_schemeSP + 4)->middle_rgbSA, &rgbS, rgb_struct_size); ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:0000/8888/8888", "white"); memcpy ((color_schemeSP + 4)->right_rgbSA, &rgbS, rgb_struct_size); /* Surface 1: */ ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:0000/3333/3333", "white"); memcpy ((color_schemeSP + 4)->left_rgbSA + 1, &rgbS, rgb_struct_size); ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:0000/2222/2222", "white"); memcpy ((color_schemeSP + 4)->middle_rgbSA + 1, &rgbS, rgb_struct_size); ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:0000/1111/1111", "white"); memcpy ((color_schemeSP + 4)->right_rgbSA + 1, &rgbS, rgb_struct_size); /*------MAGENTA (5):---------------------------------------------------------*/ (color_schemeSP + 5)->surfacesN = 2; /* Surface 0: */ ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:FFFF/9999/FFFF", "white"); memcpy ((color_schemeSP + 5)->left_rgbSA, &rgbS, rgb_struct_size); ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:EEEE/4444/EEEE", "white"); memcpy ((color_schemeSP + 5)->middle_rgbSA, &rgbS, rgb_struct_size); ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:8888/0000/8888", "white"); memcpy ((color_schemeSP + 5)->right_rgbSA, &rgbS, rgb_struct_size); /* Surface 1: */ ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:3333/0000/3333", "white"); memcpy ((color_schemeSP + 5)->left_rgbSA + 1, &rgbS, rgb_struct_size); ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:2222/0000/2222", "white"); memcpy ((color_schemeSP + 5)->middle_rgbSA + 1, &rgbS, rgb_struct_size); ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:1111/0000/1111", "white"); memcpy ((color_schemeSP + 5)->right_rgbSA + 1, &rgbS, rgb_struct_size); /*------WHITE (6):-----------------------------------------------------------*/ (color_schemeSP + 6)->surfacesN = 2; /* Surface 0: */ ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:DDDD/DDDD/DDDD", "white"); memcpy ((color_schemeSP + 6)->left_rgbSA, &rgbS, rgb_struct_size); ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:AAAA/AAAA/AAAA", "white"); memcpy ((color_schemeSP + 6)->middle_rgbSA, &rgbS, rgb_struct_size); ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:5555/5555/5555", "white"); memcpy ((color_schemeSP + 6)->right_rgbSA, &rgbS, rgb_struct_size); /* Surface 1: */ ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:3333/3333/3333", "white"); memcpy ((color_schemeSP + 6)->left_rgbSA + 1, &rgbS, rgb_struct_size); ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:2222/2222/2222", "white"); memcpy ((color_schemeSP + 6)->middle_rgbSA + 1, &rgbS, rgb_struct_size); ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:1111/1111/1111", "white"); memcpy ((color_schemeSP + 6)->right_rgbSA + 1, &rgbS, rgb_struct_size); /*------YELLOW-GREEN (7):----------------------------------------------------*/ (color_schemeSP + 7)->surfacesN = 2; /* Surface 0: */ ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:DDDD/FFFF/8888", "white"); memcpy ((color_schemeSP + 7)->left_rgbSA, &rgbS, rgb_struct_size); ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:8888/FFFF/0000", "white"); memcpy ((color_schemeSP + 7)->middle_rgbSA, &rgbS, rgb_struct_size); ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:4444/8888/0000", "white"); memcpy ((color_schemeSP + 7)->right_rgbSA, &rgbS, rgb_struct_size); /* Surface 1: */ ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:2222/4444/0000", "white"); memcpy ((color_schemeSP + 7)->left_rgbSA + 1, &rgbS, rgb_struct_size); ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:2222/3333/0000", "white"); memcpy ((color_schemeSP + 7)->middle_rgbSA + 1, &rgbS, rgb_struct_size); ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:1111/2222/0000", "white"); memcpy ((color_schemeSP + 7)->right_rgbSA + 1, &rgbS, rgb_struct_size); /*-------CYAN-GREEN (8):-----------------------------------------------------*/ (color_schemeSP + 8)->surfacesN = 2; /* Surface 0: */ ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:8888/FFFF/DDDD", "white"); memcpy ((color_schemeSP + 8)->left_rgbSA, &rgbS, rgb_struct_size); ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:0000/FFFF/8888", "white"); memcpy ((color_schemeSP + 8)->middle_rgbSA, &rgbS, rgb_struct_size); ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:0000/8888/4444", "white"); memcpy ((color_schemeSP + 8)->right_rgbSA, &rgbS, rgb_struct_size); /* Surface 1: */ ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:0000/4444/2222", "white"); memcpy ((color_schemeSP + 8)->left_rgbSA + 1, &rgbS, rgb_struct_size); ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:0000/3333/2222", "white"); memcpy ((color_schemeSP + 8)->middle_rgbSA + 1, &rgbS, rgb_struct_size); ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:0000/2222/1111", "white"); memcpy ((color_schemeSP + 8)->right_rgbSA + 1, &rgbS, rgb_struct_size); /*-------CYAN-BLUE (9):-----------------------------------------------------*/ (color_schemeSP + 9)->surfacesN = 2; /* Surface 0: */ ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:8888/DDDD/FFFF", "white"); memcpy ((color_schemeSP + 9)->left_rgbSA, &rgbS, rgb_struct_size); ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:0000/8888/FFFF", "white"); memcpy ((color_schemeSP + 9)->middle_rgbSA, &rgbS, rgb_struct_size); ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:0000/4444/8888", "white"); memcpy ((color_schemeSP + 9)->right_rgbSA, &rgbS, rgb_struct_size); /* Surface 1: */ ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:0000/2222/4444", "white"); memcpy ((color_schemeSP + 9)->left_rgbSA + 1, &rgbS, rgb_struct_size); ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:0000/2222/3333", "white"); memcpy ((color_schemeSP + 9)->middle_rgbSA + 1, &rgbS, rgb_struct_size); ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:0000/1111/2222", "white"); memcpy ((color_schemeSP + 9)->right_rgbSA + 1, &rgbS, rgb_struct_size); /*-------MAGENTA-BLUE (10):--------------------------------------------------*/ (color_schemeSP + 10)->surfacesN = 2; /* Surface 0: */ ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:DDDD/8888/FFFF", "white"); memcpy ((color_schemeSP + 10)->left_rgbSA, &rgbS, rgb_struct_size); ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:8888/0000/FFFF", "white"); memcpy ((color_schemeSP + 10)->middle_rgbSA, &rgbS, rgb_struct_size); ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:4444/0000/8888", "white"); memcpy ((color_schemeSP + 10)->right_rgbSA, &rgbS, rgb_struct_size); /* Surface 1: */ ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:2222/0000/4444", "white"); memcpy ((color_schemeSP + 10)->left_rgbSA + 1, &rgbS, rgb_struct_size); ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:2222/0000/3333", "white"); memcpy ((color_schemeSP + 10)->middle_rgbSA + 1, &rgbS, rgb_struct_size); ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:1111/0000/2222", "white"); memcpy ((color_schemeSP + 10)->right_rgbSA + 1, &rgbS, rgb_struct_size); /*-------MAGENTA-RED (11):---------------------------------------------------*/ (color_schemeSP + 11)->surfacesN = 2; /* Surface 0: */ ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:FFFF/8888/DDDD", "white"); memcpy ((color_schemeSP + 11)->left_rgbSA, &rgbS, rgb_struct_size); ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:FFFF/0000/8888", "white"); memcpy ((color_schemeSP + 11)->middle_rgbSA, &rgbS, rgb_struct_size); ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:8888/0000/4444", "white"); memcpy ((color_schemeSP + 11)->right_rgbSA, &rgbS, rgb_struct_size); /* Surface 1: */ ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:4444/0000/2222", "white"); memcpy ((color_schemeSP + 11)->left_rgbSA + 1, &rgbS, rgb_struct_size); ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:3333/0000/2222", "white"); memcpy ((color_schemeSP + 11)->middle_rgbSA + 1, &rgbS, rgb_struct_size); ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:2222/0000/1111", "white"); memcpy ((color_schemeSP + 11)->right_rgbSA + 1, &rgbS, rgb_struct_size); /*------ORANGE (12):---------------------------------------------------------*/ (color_schemeSP + 12)->surfacesN = 2; /* Surface 0: */ ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:FFFF/9999/7777", "white"); memcpy ((color_schemeSP + 12)->left_rgbSA, &rgbS, rgb_struct_size); ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:FFFF/8888/0000", "white"); memcpy ((color_schemeSP + 12)->middle_rgbSA, &rgbS, rgb_struct_size); ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:8888/4444/0000", "white"); memcpy ((color_schemeSP + 12)->right_rgbSA, &rgbS, rgb_struct_size); /* Surface 1: */ ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:6666/3333/0000", "white"); memcpy ((color_schemeSP + 12)->left_rgbSA + 1, &rgbS, rgb_struct_size); ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:4444/2222/0000", "white"); memcpy ((color_schemeSP + 12)->middle_rgbSA + 1, &rgbS, rgb_struct_size); ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:2222/1111/0000", "white"); memcpy ((color_schemeSP + 12)->right_rgbSA + 1, &rgbS, rgb_struct_size); /*------HOT (13):------------------------------------------------------------*/ (color_schemeSP + 13)->surfacesN = 3; /* Surface 0: */ ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:FFFF/FFFF/4444", "white"); memcpy ((color_schemeSP + 13)->left_rgbSA, &rgbS, rgb_struct_size); ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:FFFF/DDDD/0000", "white"); memcpy ((color_schemeSP + 13)->middle_rgbSA, &rgbS, rgb_struct_size); ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:8888/5555/0000", "white"); memcpy ((color_schemeSP + 13)->right_rgbSA, &rgbS, rgb_struct_size); /* Surface 1: */ ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:FFFF/8888/0000", "white"); memcpy ((color_schemeSP + 13)->left_rgbSA + 1, &rgbS, rgb_struct_size); ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:FFFF/0000/0000", "white"); memcpy ((color_schemeSP + 13)->middle_rgbSA + 1, &rgbS, rgb_struct_size); ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:8888/0000/0000", "white"); memcpy ((color_schemeSP + 13)->right_rgbSA + 1, &rgbS, rgb_struct_size); /* Surface 2: */ ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:8888/0000/0000", "white"); memcpy ((color_schemeSP + 13)->left_rgbSA + 2, &rgbS, rgb_struct_size); ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:4444/0000/0000", "white"); memcpy ((color_schemeSP + 13)->middle_rgbSA + 2, &rgbS, rgb_struct_size); ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:2222/0000/0000", "white"); memcpy ((color_schemeSP + 13)->right_rgbSA + 2, &rgbS, rgb_struct_size); /*------COLD (14):-----------------------------------------------------------*/ (color_schemeSP + 14)->surfacesN = 3; /* Surface 0: */ ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:DDDD/FFFF/FFFF", "white"); memcpy ((color_schemeSP + 14)->left_rgbSA, &rgbS, rgb_struct_size); ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:0000/FFFF/FFFF", "white"); memcpy ((color_schemeSP + 14)->middle_rgbSA, &rgbS, rgb_struct_size); ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:0000/8888/FFFF", "white"); memcpy ((color_schemeSP + 14)->right_rgbSA, &rgbS, rgb_struct_size); /* Surface 1: */ ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:0000/8888/FFFF", "white"); memcpy ((color_schemeSP + 14)->left_rgbSA + 1, &rgbS, rgb_struct_size); ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:0000/0000/FFFF", "white"); memcpy ((color_schemeSP + 14)->middle_rgbSA + 1, &rgbS, rgb_struct_size); ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:0000/0000/8888", "white"); memcpy ((color_schemeSP + 14)->right_rgbSA + 1, &rgbS, rgb_struct_size); /* Surface 2: */ ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:0000/0000/8888", "white"); memcpy ((color_schemeSP + 14)->left_rgbSA + 2, &rgbS, rgb_struct_size); ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:0000/0000/4444", "white"); memcpy ((color_schemeSP + 14)->middle_rgbSA + 2, &rgbS, rgb_struct_size); ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:0000/0000/2222", "white"); memcpy ((color_schemeSP + 14)->right_rgbSA + 2, &rgbS, rgb_struct_size); /*------MONOCHROME (15):-----------------------------------------------------*/ (color_schemeSP + 15)->surfacesN = 1; /* Surface 0: */ ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:0000/0000/0000", "white"); memcpy ((color_schemeSP + 15)->left_rgbSA, &rgbS, rgb_struct_size); ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:FFFF/FFFF/FFFF", "white"); memcpy ((color_schemeSP + 15)->middle_rgbSA, &rgbS, rgb_struct_size); ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:0000/0000/0000", "white"); memcpy ((color_schemeSP + 15)->right_rgbSA, &rgbS, rgb_struct_size); /*------ORANGE-YELLOW (21):--------------------------------------------------*/ (color_schemeSP + 21)->surfacesN = 2; /* Surface 0: */ ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:FFFF/DDDD/7777", "white"); memcpy ((color_schemeSP + 21)->left_rgbSA, &rgbS, rgb_struct_size); ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:FFFF/AAAA/0000", "white"); memcpy ((color_schemeSP + 21)->middle_rgbSA, &rgbS, rgb_struct_size); ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:8888/6666/0000", "white"); memcpy ((color_schemeSP + 21)->right_rgbSA, &rgbS, rgb_struct_size); /* Surface 1: */ ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:5555/4444/0000", "white"); memcpy ((color_schemeSP + 21)->left_rgbSA + 1, &rgbS, rgb_struct_size); ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:3333/2222/0000", "white"); memcpy ((color_schemeSP + 21)->middle_rgbSA + 1, &rgbS, rgb_struct_size); ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:2222/1111/0000", "white"); memcpy ((color_schemeSP + 21)->right_rgbSA + 1, &rgbS, rgb_struct_size); /*------ORANGE-RED (22):-----------------------------------------------------*/ (color_schemeSP + 22)->surfacesN = 2; /* Surface 0: */ ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:FFFF/8888/6666", "white"); memcpy ((color_schemeSP + 22)->left_rgbSA, &rgbS, rgb_struct_size); ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:FFFF/6666/0000", "white"); memcpy ((color_schemeSP + 22)->middle_rgbSA, &rgbS, rgb_struct_size); ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:8888/2222/0000", "white"); memcpy ((color_schemeSP + 22)->right_rgbSA, &rgbS, rgb_struct_size); /* Surface 1: */ ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:6666/2222/0000", "white"); memcpy ((color_schemeSP + 22)->left_rgbSA + 1, &rgbS, rgb_struct_size); ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:4444/1111/0000", "white"); memcpy ((color_schemeSP + 22)->middle_rgbSA + 1, &rgbS, rgb_struct_size); ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:2222/1111/0000", "white"); memcpy ((color_schemeSP + 22)->right_rgbSA + 1, &rgbS, rgb_struct_size); /*------SKIN (23):-----------------------------------------------------------*/ (color_schemeSP + 23)->surfacesN = 2; /* Surface 0: */ ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:EDED/C5C5/9494", "white"); memcpy ((color_schemeSP + 23)->left_rgbSA, &rgbS, rgb_struct_size); ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:BCBC/8585/5C5C", "white"); memcpy ((color_schemeSP + 23)->middle_rgbSA, &rgbS, rgb_struct_size); ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:8A8A/5757/3A3A", "white"); memcpy ((color_schemeSP + 23)->right_rgbSA, &rgbS, rgb_struct_size); /* Surface 1: */ ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:8585/5555/3535", "white"); memcpy ((color_schemeSP + 23)->left_rgbSA + 1, &rgbS, rgb_struct_size); ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:6565/4040/3030", "white"); memcpy ((color_schemeSP + 23)->middle_rgbSA + 1, &rgbS, rgb_struct_size); ParseColor_ (&rgbS, &dummyID, guiSP, "RGB:2D2D/1F1F/1C1C", "white"); memcpy ((color_schemeSP + 23)->right_rgbSA + 1, &rgbS, rgb_struct_size); /*---------------------------------------------------------------------------*/ /* Return positive value on success: */ return 1; } /*===========================================================================*/ garlic-1.6/parse_sec_structure.c0000644000076500007650000000443307273765710017361 0ustar zuciczucic00000000000000/* Copyright (C) 2001 Damir Zucic */ /*============================================================================= parse_sec_structure.c Purpose: Parse the string with secondary structure. Input: (1) Pointer to RuntimeS structure. (2) Pointer to the string which contains the secondary structure. Output: (1) Secondary structure stored to the secondary structure buffer. (2) Return value. Return value: (1) Positive on success. (2) Negative on failure. Notes: (1) Use one letter codes to define the secondary structure: C = coil, E = strand, G = 3-10 helix, H = alpha helix, T = turn. (2) Space, comma and tab may be used as separators. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "commands.h" #include "typedefs.h" /*======parse string with secondary structure:===============================*/ int ParseSecondaryStructure_ (RuntimeS *runtimeSP, char *stringP) { int i; int code; char *P; int codeI = 0; /* Initialize the secondary structure buffer */ /* (use the code for extended conformation): */ runtimeSP->sec_structure_length = 0; for (i = 0; i < MAXRESIDUES; i++) *(runtimeSP->sec_structureP + i) = 'E'; /* Parse input string, character by character: */ while ((code = *stringP++) != '\0') { /* Check the current code: */ switch (code) { /* Valid codes: */ case 'C': case 'E': case 'G': case 'H': case 'T': break; /* Separators: */ case ' ': case ',': case '\t': continue; break; /* Bad codes: */ default: sprintf (runtimeSP->messageA, "Bad code!"); strcat (runtimeSP->messageA, " Valid codes: C E G H T;"); strcat (runtimeSP->messageA, " separators: space, comma and tab."); runtimeSP->message_length = strlen (runtimeSP->messageA); return -1; } /* Store the secondary structure code: */ P = runtimeSP->sec_structureP + codeI; *P = code; /* Increment the counter: */ codeI++; } /* Store the number of codes: */ runtimeSP->sec_structure_length = codeI; /* Return positive value on success: */ return 1; } /*===========================================================================*/ garlic-1.6/text_background.c0000644000076500007650000000670607307254672016463 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= text_background.c Purpose: Execute tbg command: change the background color for input and output window. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) The number of macromolecular complexes. (3) Pointer to RuntimeS structure, with some runtime data. (4) Pointer to ConfigS structure, with configuration data. (5) Pointer to GUIS structure, with GUI data. (6) Pointer to NearestAtomS structure. (7) The number of pixels in the main window free area. (8) Pointer to refreshI. Output: (1) Log file created. (2) Return value. Return value: (1) Positive (command) code on success. (2) Negative (error) code on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "commands.h" #include "typedefs.h" /*======function prototypes:=================================================*/ char *ExtractToken_ (char *, int, char *, char *); int ParseColor_ (RGBS *, unsigned long *, GUIS *, char *, char *); size_t MainRefresh_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); /*======execute tbg command:=================================================*/ int TextBackground_ (MolComplexS *mol_complexSP, int mol_complexesN, RuntimeS *runtimeSP, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int *refreshIP) { char *remainderP; char tokenA[STRINGSIZE]; size_t rgb_struct_size; /* Skip the first token: */ remainderP = ExtractToken_ (tokenA, STRINGSIZE, runtimeSP->curr_commandA, " \t\n"); if (!remainderP) return ERROR_TBG; /* The second token should contain the color: */ remainderP = ExtractToken_ (tokenA, STRINGSIZE, remainderP, " \t\n"); if (!remainderP) { strcpy (runtimeSP->messageA, "Text background color missing!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_NO_COLOR; } /* Prepare the text background color: */ strncpy (configSP->text_bg_colorA, tokenA, SHORTSTRINGSIZE - 1); configSP->text_bg_colorA[SHORTSTRINGSIZE - 1] = '\0'; ParseColor_ (&guiSP->input_winS.bg_rgbS, &guiSP->input_winS.bg_colorID, guiSP, configSP->text_bg_colorA, "black"); /* Don't forget the output window, it uses the same background color: */ rgb_struct_size = sizeof (RGBS); memcpy (&guiSP->output_winS.bg_rgbS, &guiSP->input_winS.bg_rgbS, rgb_struct_size); guiSP->output_winS.bg_colorID = guiSP->input_winS.bg_colorID; XSetWindowBackground (guiSP->displaySP, guiSP->input_winS.ID, guiSP->input_winS.bg_colorID); XSetWindowBackground (guiSP->displaySP, guiSP->output_winS.ID, guiSP->output_winS.bg_colorID); /* Refresh the output window: */ XSetForeground (guiSP->displaySP, guiSP->theGCA[0], guiSP->output_winS.bg_colorID); XFillRectangle (guiSP->displaySP, guiSP->output_winS.ID, guiSP->theGCA[0], 0, 0, guiSP->output_winS.width, guiSP->output_winS.height); /* Refresh the main window: */ (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); /* Return positive value on success: */ return COMMAND_TBG; } /*===========================================================================*/ garlic-1.6/covalent.c0000644000076500007650000003140207747301765015106 0ustar zuciczucic00000000000000/* Copyright (C) 2002-2003 Damir Zucic */ /*============================================================================= covalent.c Purpose: Draw atoms as spheres (covalent style). Input: (1) Pointer to MolComplexS structure. (2) Number of macromolecular complexes. (3) Pointer to ConfigS structure, with configuration data. (4) Pointer to GUIS structure. (5) Pointer to NearestAtomS structure, with information about the atom occupying the given pixel. (6) The number of pixels in the main window free area. (7) The refreshI, used to check the NearestAtomS associated with a given pixel. Output: (1) Spheres drawn to the hidden pixmap. (2) Return value. Return value: (1) Positive always (trivial). Notes: (1) Indentation is exceptionally 4 spaces. =============================================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ unsigned long SpacefillColor_ (AtomS *, GUIS *, double); /*======draw atoms as spheres, covalent style:===============================*/ int DrawCovalent_ (MolComplexS *mol_complexSP, int mol_complexesN, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int refreshI) { int imageI, imagesN; double scale_factor, user_atomic_position; int left_edge[2], right_edge[2]; int mol_complexI; MolComplexS *curr_mol_complexSP; size_t atomsN, atomI; AtomS *curr_atomSP; int screen_x0, screen_y0; double radius, radius_squared; double denominator, reciprocal_denominator; int screen_radius; long screen_radius_squared; int screen_x1, screen_y1, screen_x2, screen_y2; int screen_x, screen_y; long delta_x, delta_y, distance_squared; double z0, front_z, delta_z, z; size_t pixelI; NearestAtomS *curr_pixelSP; double denominator2, reciprocal_denominator2; double rho_squared; VectorS vectorS; double abs_value, abs_value_squared; double scalar_product, cos_angle; unsigned long colorID; int bondI; /* Initialize the bond index. The negative value means that pixels */ /* filled in this function are not a part of any chemical bond. */ bondI = -1; /* Number of images: */ if (configSP->stereoF) imagesN = 2; else imagesN = 1; /* The auxiliary scale factor: */ scale_factor = configSP->user_screen_atomic_distance * configSP->atomic_to_screen_scale_x; /* Prepare the user position in atomic coordinates: */ user_atomic_position = configSP->user_atomic_position; /* Left and right image edge (in stereo mode there are two images): */ left_edge[0] = configSP->image_screen_x0[0]; right_edge[0] = configSP->image_screen_x1[0]; left_edge[1] = configSP->image_screen_x0[1]; right_edge[1] = configSP->image_screen_x1[1]; /*------first pass - fill NearestAtomS array with planar atoms:--------------*/ /* Draw each macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Prepare and check the number of atoms: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Draw atoms which have the given style: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Check style: */ if (curr_atomSP->raw_atomS.atom_styleI != COVALENT) continue; /* Check is atom hidden: */ if (curr_atomSP->hiddenF) continue; /* Check is atom inside slab: */ if (!curr_atomSP->inside_slabF) continue; /* Check is atom inside window: */ if (!curr_atomSP->inside_windowF) continue; /* Covalent radius, in atomic units: */ radius = curr_atomSP->raw_atomS.covalent_radius; /* The y coordinate of atomic center, in screen units: */ screen_y0 = curr_atomSP->raw_atomS.screen_y; /* Prepare one image (mono) or two images (stereo): */ for (imageI = 0; imageI < imagesN; imageI++) { /* The z coordinate of atomic center, in atomic units: */ z0 = curr_atomSP->raw_atomS.z[imageI]; /* Prepare the factor required for the projection of radius: */ denominator = z0 - user_atomic_position; if (denominator == 0.0) continue; reciprocal_denominator = 1.0 / denominator; /* Covalent radius in screen units: */ screen_radius = (int) (radius * scale_factor * reciprocal_denominator + 0.5); /* Screen radius squared (used to improve speed): */ screen_radius_squared = (long) screen_radius * (long) screen_radius; /* The x coordinate of atomic center, in screen units: */ screen_x0 = curr_atomSP->raw_atomS.screen_x[imageI]; /* Define the bounding rectangle: */ screen_x1 = screen_x0 - screen_radius; screen_y1 = screen_y0 - screen_radius; screen_x2 = screen_x0 + screen_radius; screen_y2 = screen_y0 + screen_radius; /* Horizontal scan: */ for (screen_x = screen_x1; screen_x <= screen_x2; screen_x++) { /* Check horizontal position: */ if (screen_x < left_edge[imageI]) continue; if (screen_x >= right_edge[imageI]) continue; /* Vertical scan: */ for (screen_y = screen_y1; screen_y <= screen_y2; screen_y++) { /* Check vertical position: */ if (screen_y < 0) continue; if (screen_y >= (int) guiSP->main_win_free_area_height) { continue; } /* Check distance from the circle center: */ delta_x = (long) (screen_x - screen_x0); delta_y = (long) (screen_y - screen_y0); distance_squared = delta_x * delta_x + delta_y * delta_y; if (distance_squared > screen_radius_squared) continue; /* Prepare index to the array */ /* of NearestAtomS structures: */ pixelI = guiSP->main_win_free_area_width * screen_y + screen_x; /* Check the pixel index: */ if (pixelI >= pixelsN) continue; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = nearest_atomSP + pixelI; /* Check was this pixel used already in */ /* this drawing step; if it was, compare */ /* the z value of the current atom with z */ /* value previously stored to this pixel: */ if (refreshI == curr_pixelSP->last_refreshI) { if (z0 > curr_pixelSP->z) continue; } /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = COVALENT; curr_pixelSP->last_refreshI = refreshI; curr_pixelSP->mol_complexI = mol_complexI; curr_pixelSP->atomI = atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = z0; } } } /* imageI loop */ } /* atomI loop */ } /* mol_complexI loop */ /*------second pass - draw spherical atoms:----------------------------------*/ /* Draw each macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Prepare and check the number of atoms: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Draw atoms which have the given style: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Check style: */ if (curr_atomSP->raw_atomS.atom_styleI != COVALENT) continue; /* Check is atom hidden: */ if (curr_atomSP->hiddenF) continue; /* Check is atom inside slab: */ if (!curr_atomSP->inside_slabF) continue; /* Check is atom inside window: */ if (!curr_atomSP->inside_windowF) continue; /* Covalent radius, in atomic units: */ radius = curr_atomSP->raw_atomS.covalent_radius; /* Squared covalent radius: */ radius_squared = radius * radius; /* The y coordinate of atomic center, in screen units: */ screen_y0 = curr_atomSP->raw_atomS.screen_y; /* Prepare one image (mono) or two images (stereo): */ for (imageI = 0; imageI < imagesN; imageI++) { /* The z coordinate of atomic center, in atomic units: */ z0 = curr_atomSP->raw_atomS.z[imageI]; /* The z coordinate of the nearest */ /* point of a given atom (sphere): */ front_z = z0 - radius; /* Prepare the factor required for the projection of radius: */ denominator = z0 - user_atomic_position; if (denominator == 0.0) continue; reciprocal_denominator = 1.0 / denominator; /* Covalent radius in screen units: */ screen_radius = (int) (radius * scale_factor * reciprocal_denominator + 0.5); /* Square of the covalent radius (in screen units): */ screen_radius_squared = (long) screen_radius * (long) screen_radius; /* Reciprocal value will be used to improve performance: */ denominator2 = (double) screen_radius_squared; if (denominator2 == 0.0) continue; reciprocal_denominator2 = 1.0 / denominator2; /* The x coordinate of atomic center, in screen units: */ screen_x0 = curr_atomSP->raw_atomS.screen_x[imageI]; /* Define the bounding rectangle: */ screen_x1 = screen_x0 - screen_radius; screen_y1 = screen_y0 - screen_radius; screen_x2 = screen_x0 + screen_radius; screen_y2 = screen_y0 + screen_radius; /* Horizontal scan: */ for (screen_x = screen_x1; screen_x <= screen_x2; screen_x++) { /* Check horizontal position: */ if (screen_x < left_edge[imageI]) continue; if (screen_x > right_edge[imageI]) continue; /* Vertical scan: */ for (screen_y = screen_y1; screen_y <= screen_y2; screen_y++) { /* Check vertical position: */ if (screen_y < 0) continue; if (screen_y >= (int) guiSP->main_win_free_area_height) { continue; } /* Check distance from the circle center: */ delta_x = (long) (screen_x - screen_x0); delta_y = (long) (screen_y - screen_y0); distance_squared = delta_x * delta_x + delta_y * delta_y; if (distance_squared > screen_radius_squared) continue; /* Prepare index to the array */ /* of NearestAtomS structures: */ pixelI = guiSP->main_win_free_area_width * screen_y + screen_x; /* Check the pixel index: */ if (pixelI >= pixelsN) continue; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = nearest_atomSP + pixelI; /* Check z value (this is just a quick check): */ if (refreshI == curr_pixelSP->last_refreshI) { if (front_z > curr_pixelSP->z) continue; } /* Calculate the accurate z value: */ rho_squared = radius_squared * (double) distance_squared * reciprocal_denominator2; delta_z = sqrt (fabs (radius_squared - rho_squared)); z = z0 - delta_z; /* Check z value (precise check): */ if (refreshI == curr_pixelSP->last_refreshI) { if (z > curr_pixelSP->z) continue; } /* The vector from sphere center to the current pixel: */ vectorS.x = (double) delta_x; vectorS.y = (double) delta_y; vectorS.z = - sqrt (fabs (screen_radius_squared - vectorS.x * vectorS.x - vectorS.y * vectorS.y)); abs_value_squared = vectorS.x * vectorS.x + vectorS.y * vectorS.y + vectorS.z * vectorS.z; abs_value = sqrt (abs_value_squared); /* The scalar product between this */ /* vector and light source vector: */ scalar_product = vectorS.x * configSP->light_vectorS.x + vectorS.y * configSP->light_vectorS.y + vectorS.z * configSP->light_vectorS.z; /* Cosine of the angle between the vector to the */ /* current pixel and the light source unit vector: */ if (abs_value == 0.0) cos_angle = 0.0; else cos_angle = scalar_product / abs_value; /* Prepare color: */ colorID = SpacefillColor_ (curr_atomSP, guiSP, cos_angle); XSetForeground (guiSP->displaySP, guiSP->theGCA[0], colorID); XDrawPoint (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x, screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = COVALENT; curr_pixelSP->last_refreshI = refreshI; curr_pixelSP->mol_complexI = mol_complexI; curr_pixelSP->atomI = atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = z; curr_pixelSP->colorID = colorID; } } } /* imageI loop */ } /* atomI loop */ } /* mol_complexI loop */ /*---------------------------------------------------------------------------*/ /* Return positive value (trivial): */ return 1; } /*===========================================================================*/ garlic-1.6/free_runtime.c0000644000076500007650000000642710445771114015754 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2006 Damir Zucic */ /*============================================================================= free_runtime.c Purpose: Free memory used to store some runtime data. Input: (1) Pointer to RuntimeS structure. Output: (1) Memory used to store some runtime data freed. (2) Return value. Return value: Positive always (trivial). ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======initialize runtime parameters:=======================================*/ int FreeRuntime_ (RuntimeS *runtimeSP) { /* Free memory used for command strings (the history buffer): */ if (runtimeSP->commandsP) free (runtimeSP->commandsP); if (runtimeSP->titlesP) free (runtimeSP->titlesP); if (runtimeSP->sequenceP) free (runtimeSP->sequenceP); if (runtimeSP->patternP) free (runtimeSP->patternP); if (runtimeSP->sec_structureP) free (runtimeSP->sec_structureP); if (runtimeSP->disulfideFP) free (runtimeSP->disulfideFP); if (runtimeSP->serialIP) free (runtimeSP->serialIP); if (runtimeSP->residue_codeIP) free (runtimeSP->residue_codeIP); if (runtimeSP->hydrophobicityP) free (runtimeSP->hydrophobicityP); if (runtimeSP->average_hydrophobicityP) free (runtimeSP->average_hydrophobicityP); if (runtimeSP->weighted_hydrophobicityP) free (runtimeSP->weighted_hydrophobicityP); if (runtimeSP->hydrophobic_momentP) free (runtimeSP->hydrophobic_momentP); if (runtimeSP->larger_sided_hyphobP) free (runtimeSP->larger_sided_hyphobP); if (runtimeSP->smaller_sided_hyphobP) free (runtimeSP->smaller_sided_hyphobP); if (runtimeSP->function1P) free (runtimeSP->function1P); if (runtimeSP->function2P) free (runtimeSP->function2P); if (runtimeSP->function3P) free (runtimeSP->function3P); if (runtimeSP->function4P) free (runtimeSP->function4P); if (runtimeSP->function5P) free (runtimeSP->function5P); if (runtimeSP->function6P) free (runtimeSP->function6P); if (runtimeSP->function7P) free (runtimeSP->function7P); if (runtimeSP->auxiliaryIP) free (runtimeSP->auxiliaryIP); if (runtimeSP->aux_doubleP) free (runtimeSP->aux_doubleP); if (runtimeSP->reference_sequenceP) free (runtimeSP->reference_sequenceP); if (runtimeSP->reference_sec_structureP) free (runtimeSP->reference_sec_structureP); if (runtimeSP->reference_serialIP) free (runtimeSP->reference_serialIP); if (runtimeSP->reference_residue_codeIP) free (runtimeSP->reference_residue_codeIP); if (runtimeSP->reference_hydrophobicityP) free (runtimeSP->reference_hydrophobicityP); if (runtimeSP->exposed_atom1IP) free (runtimeSP->exposed_atom1IP); if (runtimeSP->exposed_atom2IP) free (runtimeSP->exposed_atom2IP); if (runtimeSP->exposed_polar1SP) free (runtimeSP->exposed_polar1SP); if (runtimeSP->exposed_polar2SP) free (runtimeSP->exposed_polar2SP); if (runtimeSP->template_atomSP) free (runtimeSP->template_atomSP); if (runtimeSP->template_residueSP) free (runtimeSP->template_residueSP); if (runtimeSP->beta_cellSP) free (runtimeSP->beta_cellSP); /* Return positive value (trivial): */ return 1; } /*===========================================================================*/ garlic-1.6/bond_style4_quad1.c0000644000076500007650000001770207461726667016630 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2002 Damir Zucic */ /*============================================================================= bond_style4_quad1.c Purpose: Draw bond which fits into quadrant 1 using style 4. See the file file bonds_style4.c for description of quadrants. Input: (1) Pointer to Aux1S structure, which contains required data. (2) Bond index. Output: (1) A single bond drawn. (2) Return value. Return value: (1) One if at least one pixel is drawn. (2) Zero otherwise. =============================================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======draw bond in quadrant 1 using style 4:===============================*/ int BondStyle4Quadrant1_ (Aux1S *aux1SP, int bondI) { long pixels_drawnN = 0; double recip_denom, x_to_y_scale, x_to_z_scale; int screen_x, screen_x1, delta_x, screen_y, line_screen_y; double d, atomic_z; int lineI; size_t pixelI; NearestAtomS *curr_pixelSP; int edge_y, columnI; static int edge_maskAA[5][2] = {{1, 0}, {1, 1}, {1, 1}, {1, 1}, {1, 0}}; /* Scale factor required to calculate screen_y from screen_x: */ if (aux1SP->screen_delta_x != 0) recip_denom = 1.0 / aux1SP->screen_delta_x; else recip_denom = 0.0; x_to_y_scale = aux1SP->screen_delta_y * recip_denom; /* Scale factor required to calculate z (in atomic units) from screen_x: */ x_to_z_scale = aux1SP->atomic_delta_z * recip_denom; /* Horizontal scan, from left to right: */ screen_x1 = (aux1SP->screen_x0 + aux1SP->screen_x1) / 2; for (screen_x = aux1SP->screen_x0; screen_x <= screen_x1; screen_x++) { /* Check is this pixel inside the area reserved for the */ /* current image (there are two images in stereo mode): */ if (screen_x < aux1SP->configSP->image_screen_x0[aux1SP->imageI]) { continue; } if (screen_x > aux1SP->configSP->image_screen_x1[aux1SP->imageI]) { continue; } /* Relative position: */ delta_x = screen_x - aux1SP->screen_x0; /* Find the corresponding screen_y: */ d = aux1SP->screen_y0 + x_to_y_scale * delta_x; screen_y = (int) (d + 0.5); /* z value (in atomic units): */ atomic_z = aux1SP->atomic_z0 + x_to_z_scale * delta_x; /* Loop which draws lines (vertical scan): */ for (lineI = 0; lineI <= 6; lineI++) { /* Pixel position: */ line_screen_y = screen_y +lineI - 3; /* Check is this pixel inside the area reserved for the */ /* current image (there are two images in stereo mode): */ if (line_screen_y < aux1SP->configSP->image_screen_y0) { continue; } if (line_screen_y > aux1SP->configSP->image_screen_y1) { continue; } /* Current pixel index: */ pixelI = aux1SP->guiSP->main_win_free_area_width * line_screen_y + screen_x; /* Check pixel index: */ if (pixelI >= aux1SP->pixelsN) break; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = aux1SP->nearest_atomSP + pixelI; /* Check was this pixel used already in */ /* this drawing step; if it was, compare */ /* the z value of the current atom with z */ /* value previously stored to this pixel: */ if (aux1SP->refreshI == curr_pixelSP->last_refreshI) { if (atomic_z >= curr_pixelSP->z) continue; } /* If this point is reached draw one pixel: */ XDrawPoint (aux1SP->guiSP->displaySP, aux1SP->guiSP->main_hidden_pixmapID, aux1SP->guiSP->theGCA[lineI], screen_x, line_screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = 4; curr_pixelSP->last_refreshI = aux1SP->refreshI; curr_pixelSP->mol_complexI = aux1SP->mol_complexI; curr_pixelSP->atomI = aux1SP->atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = atomic_z; curr_pixelSP->colorID = aux1SP->colorIDA[lineI]; /* Update the number of pixels drawn: */ pixels_drawnN++; } } /* Rounding the left end: */ edge_y = aux1SP->screen_y0; atomic_z = aux1SP->atomic_z0; for (columnI = 0; columnI <= 1; columnI++) { /* Prepare and check screen_x: */ screen_x = aux1SP->screen_x0 - columnI - 1; if (screen_x < aux1SP->configSP->image_screen_x0[aux1SP->imageI]) continue; if (screen_x > aux1SP->configSP->image_screen_x1[aux1SP->imageI]) continue; /* Vertical scan: */ for (lineI = 0; lineI <= 4; lineI++) { /* Pixel y coordinate: */ line_screen_y = edge_y + lineI - 2; /* Check line_screen_y: */ if (line_screen_y < aux1SP->configSP->image_screen_y0) continue; if (line_screen_y > aux1SP->configSP->image_screen_y1) continue; /* Check the mask: */ if (!edge_maskAA[lineI][columnI]) continue; /* Current pixel index: */ pixelI = aux1SP->guiSP->main_win_free_area_width * line_screen_y + screen_x; /* Check pixel index: */ if (pixelI >= aux1SP->pixelsN) break; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = aux1SP->nearest_atomSP + pixelI; /* Check was this pixel used already in this drawing step : */ if (aux1SP->refreshI == curr_pixelSP->last_refreshI) { if (atomic_z >= curr_pixelSP->z) continue; } /* If this point is reached draw one pixel: */ XDrawPoint (aux1SP->guiSP->displaySP, aux1SP->guiSP->main_hidden_pixmapID, aux1SP->guiSP->theGCA[lineI + 1], screen_x, line_screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = 4; curr_pixelSP->last_refreshI = aux1SP->refreshI; curr_pixelSP->mol_complexI = aux1SP->mol_complexI; curr_pixelSP->atomI = aux1SP->atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = atomic_z; curr_pixelSP->colorID = aux1SP->colorIDA[lineI + 1]; /* Update the number of pixels drawn: */ pixels_drawnN++; } } /* Rounding the right end: */ delta_x = screen_x1 - aux1SP->screen_x0; d = (double) aux1SP->screen_y0 + x_to_y_scale * (double) delta_x; edge_y = (int) (d + 0.5); atomic_z = aux1SP->atomic_z0 + x_to_z_scale * (double) delta_x; for (columnI = 0; columnI <= 1; columnI++) { /* Prepare and check screen_x: */ screen_x = screen_x1 + columnI + 1; if (screen_x < aux1SP->configSP->image_screen_x0[aux1SP->imageI]) continue; if (screen_x > aux1SP->configSP->image_screen_x1[aux1SP->imageI]) continue; /* Vertical scan: */ for (lineI = 0; lineI <= 4; lineI++) { /* Pixel y coordinate: */ line_screen_y = edge_y + lineI - 2; /* Check line_screen_y: */ if (line_screen_y < aux1SP->configSP->image_screen_y0) continue; if (line_screen_y > aux1SP->configSP->image_screen_y1) continue; /* Check the mask: */ if (!edge_maskAA[lineI][columnI]) continue; /* Current pixel index: */ pixelI = aux1SP->guiSP->main_win_free_area_width * line_screen_y + screen_x; /* Check pixel index: */ if (pixelI >= aux1SP->pixelsN) break; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = aux1SP->nearest_atomSP + pixelI; /* Check was this pixel used already in this drawing step : */ if (aux1SP->refreshI == curr_pixelSP->last_refreshI) { if (atomic_z >= curr_pixelSP->z) continue; } /* If this point is reached draw one pixel: */ XDrawPoint (aux1SP->guiSP->displaySP, aux1SP->guiSP->main_hidden_pixmapID, aux1SP->guiSP->theGCA[lineI + 1], screen_x, line_screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = 4; curr_pixelSP->last_refreshI = aux1SP->refreshI; curr_pixelSP->mol_complexI = aux1SP->mol_complexI; curr_pixelSP->atomI = aux1SP->atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = atomic_z; curr_pixelSP->colorID = aux1SP->colorIDA[lineI + 1]; /* Update the number of pixels drawn: */ pixels_drawnN++; } } /* Check is at least one pixel drawn: */ if (pixels_drawnN > 0) return 1; /* If this point is reached, nothing is drawn: */ return 0; } /*===========================================================================*/ garlic-1.6/bond_style4_quad2.c0000644000076500007650000001771107461726702016617 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2002 Damir Zucic */ /*============================================================================= bond_style4_quad2.c Purpose: Draw bond which fits into quadrant 2 using style 4. See the file file bonds_style4.c for description of quadrants. Input: (1) Pointer to Aux1S structure, which contains required data. (2) Bond index. Output: (1) A single bond drawn. (2) Return value. Return value: (1) One if at least one pixel is drawn. (2) Zero otherwise. =============================================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======draw bond in quadrant 2 using style 4:===============================*/ int BondStyle4Quadrant2_ (Aux1S *aux1SP, int bondI) { long pixels_drawnN = 0; double recip_denom, y_to_x_scale, y_to_z_scale; int screen_x, line_screen_x, screen_y, screen_y1, delta_y; double d, atomic_z; int lineI; size_t pixelI; NearestAtomS *curr_pixelSP; int edge_x, rowI; static int edge_maskAA[5][2] = {{1, 0}, {1, 1}, {1, 1}, {1, 1}, {1, 0}}; /* Scale factor required to calculate screen_x from screen_y: */ if (aux1SP->screen_delta_y != 0) recip_denom = 1.0 / aux1SP->screen_delta_y; else recip_denom = 0.0; y_to_x_scale = aux1SP->screen_delta_x * recip_denom; /* Scale factor required to calculate z (in atomic units) from screen_y: */ y_to_z_scale = aux1SP->atomic_delta_z * recip_denom; /* Vertical scan (top to bottom): */ screen_y1 = (aux1SP->screen_y0 + aux1SP->screen_y1) / 2; for (screen_y = aux1SP->screen_y0; screen_y <= screen_y1; screen_y++) { /* Check is this pixel inside the area reserved for the */ /* current image (there are two images in stereo mode): */ if (screen_y < aux1SP->configSP->image_screen_y0) continue; if (screen_y > aux1SP->configSP->image_screen_y1) continue; /* Relative position: */ delta_y = screen_y - aux1SP->screen_y0; /* Find the corresponding screen_x: */ d = aux1SP->screen_x0 + y_to_x_scale * delta_y; screen_x = (int) (d + 0.5); /* z value (in atomic units): */ atomic_z = aux1SP->atomic_z0 + y_to_z_scale * delta_y; /* Loop which draws lines (horizontal scan): */ for (lineI = 0; lineI <= 6; lineI++) { /* Pixel position: */ line_screen_x = screen_x +lineI - 3; /* Check is this pixel inside the area reserved for the */ /* current image (there are two images in stereo mode): */ if (line_screen_x < aux1SP->configSP->image_screen_x0[aux1SP->imageI]) { continue; } if (line_screen_x > aux1SP->configSP->image_screen_x1[aux1SP->imageI]) { continue; } /* Current pixel index: */ pixelI = aux1SP->guiSP->main_win_free_area_width * screen_y + line_screen_x; /* Check pixel index: */ if (pixelI >= aux1SP->pixelsN) break; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = aux1SP->nearest_atomSP + pixelI; /* Check was this pixel used already in */ /* this drawing step; if it was, compare */ /* the z value of the current atom with z */ /* value previously stored to this pixel: */ if (aux1SP->refreshI == curr_pixelSP->last_refreshI) { if (atomic_z >= curr_pixelSP->z) continue; } /* If this point is reached draw pixel: */ XDrawPoint (aux1SP->guiSP->displaySP, aux1SP->guiSP->main_hidden_pixmapID, aux1SP->guiSP->theGCA[lineI], line_screen_x, screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = 4; curr_pixelSP->last_refreshI = aux1SP->refreshI; curr_pixelSP->mol_complexI = aux1SP->mol_complexI; curr_pixelSP->atomI = aux1SP->atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = atomic_z; curr_pixelSP->colorID = aux1SP->colorIDA[lineI]; /* Update the number of pixels drawn: */ pixels_drawnN++; } } /* Rounding the top end: */ edge_x = aux1SP->screen_x0; atomic_z = aux1SP->atomic_z0; for (rowI = 0; rowI <= 1; rowI++) { /* Prepare and check screen_y: */ screen_y = aux1SP->screen_y0 - rowI - 1; if (screen_y < aux1SP->configSP->image_screen_y0) continue; if (screen_y > aux1SP->configSP->image_screen_y1) continue; /* Vertical scan: */ for (lineI = 0; lineI <= 4; lineI++) { /* Pixel x coordinate: */ line_screen_x = edge_x + lineI - 2; /* Check line_screen_x: */ if (line_screen_x < aux1SP->configSP->image_screen_x0[aux1SP->imageI]) { continue; } if (line_screen_x > aux1SP->configSP->image_screen_x1[aux1SP->imageI]) { continue; } /* Check the mask: */ if (!edge_maskAA[lineI][rowI]) continue; /* Current pixel index: */ pixelI = aux1SP->guiSP->main_win_free_area_width * screen_y + line_screen_x; /* Check pixel index: */ if (pixelI >= aux1SP->pixelsN) break; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = aux1SP->nearest_atomSP + pixelI; /* Check was this pixel used already in this drawing step : */ if (aux1SP->refreshI == curr_pixelSP->last_refreshI) { if (atomic_z >= curr_pixelSP->z) continue; } /* If this point is reached draw one pixel: */ XDrawPoint (aux1SP->guiSP->displaySP, aux1SP->guiSP->main_hidden_pixmapID, aux1SP->guiSP->theGCA[lineI + 1], line_screen_x, screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = 4; curr_pixelSP->last_refreshI = aux1SP->refreshI; curr_pixelSP->mol_complexI = aux1SP->mol_complexI; curr_pixelSP->atomI = aux1SP->atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = atomic_z; curr_pixelSP->colorID = aux1SP->colorIDA[lineI + 1]; /* Update the number of pixels drawn: */ pixels_drawnN++; } } /* Rounding the bottom end: */ delta_y = screen_y1 - aux1SP->screen_y0; d = (double) aux1SP->screen_x0 + y_to_x_scale * (double) delta_y; edge_x = (int) (d + 0.5); atomic_z = aux1SP->atomic_z0 + y_to_z_scale * (double) delta_y; for (rowI = 0; rowI <= 1; rowI++) { /* Prepare and check screen_y: */ screen_y = screen_y1 + rowI + 1; if (screen_y < aux1SP->configSP->image_screen_y0) continue; if (screen_y > aux1SP->configSP->image_screen_y1) continue; /* Vertical scan: */ for (lineI = 0; lineI <= 4; lineI++) { /* Pixel x coordinate: */ line_screen_x = edge_x + lineI - 2; /* Check line_screen_x: */ if (line_screen_x < aux1SP->configSP->image_screen_x0[aux1SP->imageI]) { continue; } if (line_screen_x > aux1SP->configSP->image_screen_x1[aux1SP->imageI]) { continue; } /* Check the mask: */ if (!edge_maskAA[lineI][rowI]) continue; /* Current pixel index: */ pixelI = aux1SP->guiSP->main_win_free_area_width * screen_y + line_screen_x; /* Check pixel index: */ if (pixelI >= aux1SP->pixelsN) break; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = aux1SP->nearest_atomSP + pixelI; /* Check was this pixel used already in this drawing step : */ if (aux1SP->refreshI == curr_pixelSP->last_refreshI) { if (atomic_z >= curr_pixelSP->z) continue; } /* If this point is reached draw one pixel: */ XDrawPoint (aux1SP->guiSP->displaySP, aux1SP->guiSP->main_hidden_pixmapID, aux1SP->guiSP->theGCA[lineI + 1], line_screen_x, screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = 4; curr_pixelSP->last_refreshI = aux1SP->refreshI; curr_pixelSP->mol_complexI = aux1SP->mol_complexI; curr_pixelSP->atomI = aux1SP->atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = atomic_z; curr_pixelSP->colorID = aux1SP->colorIDA[lineI + 1]; /* Update the number of pixels drawn: */ pixels_drawnN++; } } /* Check is at least one pixel drawn: */ if (pixels_drawnN > 0) return 1; /* If this point is reached, nothing is drawn: */ return 0; } /*===========================================================================*/ garlic-1.6/bond_style4_quad3.c0000644000076500007650000001767707461726711016633 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2002 Damir Zucic */ /*============================================================================= bond_style4_quad3.c Purpose: Draw bond which fits into quadrant 3 using style 4. See the file file bonds_style4.c for description of quadrants. Input: (1) Pointer to Aux1S structure, which contains required data. (2) Bond index. Output: (1) A single bond drawn. (2) Return value. Return value: (1) One if at least one pixel is drawn. (2) Zero otherwise. =============================================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======draw bond in quadrant 3 using style 4:===============================*/ int BondStyle4Quadrant3_ (Aux1S *aux1SP, int bondI) { long pixels_drawnN = 0; double recip_denom, x_to_y_scale, x_to_z_scale; int screen_x, screen_x1, delta_x, screen_y, line_screen_y; double d, atomic_z; int lineI; size_t pixelI; NearestAtomS *curr_pixelSP; int edge_y, columnI; static int edge_maskAA[5][2] = {{1, 0}, {1, 1}, {1, 1}, {1, 1}, {1, 0}}; /* Scale factor required to calculate screen_y from screen_x: */ if (aux1SP->screen_delta_x != 0) recip_denom = 1.0 / aux1SP->screen_delta_x; else recip_denom = 0.0; x_to_y_scale = aux1SP->screen_delta_y * recip_denom; /* Scale factor required to calculate z (in atomic units) from screen_x: */ x_to_z_scale = aux1SP->atomic_delta_z * recip_denom; /* Horizontal scan, from right to left: */ screen_x1 = (aux1SP->screen_x0 + aux1SP->screen_x1) / 2; for (screen_x = aux1SP->screen_x0; screen_x >= screen_x1; screen_x--) { /* Check is this pixel inside the area reserved for the */ /* current image (there are two images in stereo mode): */ if (screen_x < aux1SP->configSP->image_screen_x0[aux1SP->imageI]) { continue; } if (screen_x > aux1SP->configSP->image_screen_x1[aux1SP->imageI]) { continue; } /* Relative position: */ delta_x = screen_x - aux1SP->screen_x0; /* Find the corresponding screen_y: */ d = aux1SP->screen_y0 + x_to_y_scale * delta_x; screen_y = (int) (d + 0.5); /* z value (in atomic units): */ atomic_z = aux1SP->atomic_z0 + x_to_z_scale * delta_x; /* Loop which draws lines (vertical scan): */ for (lineI = 0; lineI <= 6; lineI++) { /* Pixel position: */ line_screen_y = screen_y +lineI - 3; /* Check is this pixel inside the area reserved for the */ /* current image (there are two images in stereo mode): */ if (line_screen_y < aux1SP->configSP->image_screen_y0) { continue; } if (line_screen_y > aux1SP->configSP->image_screen_y1) { continue; } /* Current pixel index: */ pixelI = aux1SP->guiSP->main_win_free_area_width * line_screen_y + screen_x; /* Check pixel index: */ if (pixelI >= aux1SP->pixelsN) break; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = aux1SP->nearest_atomSP + pixelI; /* Check was this pixel used already in */ /* this drawing step; if it was, compare */ /* the z value of the current atom with z */ /* value previously stored to this pixel: */ if (aux1SP->refreshI == curr_pixelSP->last_refreshI) { if (atomic_z >= curr_pixelSP->z) continue; } /* If this point is reached draw pixel: */ XDrawPoint (aux1SP->guiSP->displaySP, aux1SP->guiSP->main_hidden_pixmapID, aux1SP->guiSP->theGCA[lineI], screen_x, line_screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = 4; curr_pixelSP->last_refreshI = aux1SP->refreshI; curr_pixelSP->mol_complexI = aux1SP->mol_complexI; curr_pixelSP->atomI = aux1SP->atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = atomic_z; curr_pixelSP->colorID = aux1SP->colorIDA[lineI]; /* Update the number of pixels drawn: */ pixels_drawnN++; } } /* Rounding the right end: */ edge_y = aux1SP->screen_y0; atomic_z = aux1SP->atomic_z0; for (columnI = 0; columnI <= 1; columnI++) { /* Prepare and check screen_x: */ screen_x = aux1SP->screen_x0 + columnI + 1; if (screen_x < aux1SP->configSP->image_screen_x0[aux1SP->imageI]) continue; if (screen_x > aux1SP->configSP->image_screen_x1[aux1SP->imageI]) continue; /* Vertical scan: */ for (lineI = 0; lineI <= 4; lineI++) { /* Pixel y coordinate: */ line_screen_y = edge_y + lineI - 2; /* Check line_screen_y: */ if (line_screen_y < aux1SP->configSP->image_screen_y0) continue; if (line_screen_y > aux1SP->configSP->image_screen_y1) continue; /* Check the mask: */ if (!edge_maskAA[lineI][columnI]) continue; /* Current pixel index: */ pixelI = aux1SP->guiSP->main_win_free_area_width * line_screen_y + screen_x; /* Check pixel index: */ if (pixelI >= aux1SP->pixelsN) break; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = aux1SP->nearest_atomSP + pixelI; /* Check was this pixel used already in this drawing step : */ if (aux1SP->refreshI == curr_pixelSP->last_refreshI) { if (atomic_z >= curr_pixelSP->z) continue; } /* If this point is reached draw one pixel: */ XDrawPoint (aux1SP->guiSP->displaySP, aux1SP->guiSP->main_hidden_pixmapID, aux1SP->guiSP->theGCA[lineI + 1], screen_x, line_screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = 4; curr_pixelSP->last_refreshI = aux1SP->refreshI; curr_pixelSP->mol_complexI = aux1SP->mol_complexI; curr_pixelSP->atomI = aux1SP->atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = atomic_z; curr_pixelSP->colorID = aux1SP->colorIDA[lineI + 1]; /* Update the number of pixels drawn: */ pixels_drawnN++; } } /* Rounding the right end: */ delta_x = screen_x1 - aux1SP->screen_x0; d = (double) aux1SP->screen_y0 + x_to_y_scale * (double) delta_x; edge_y = (int) (d + 0.5); atomic_z = aux1SP->atomic_z0 + x_to_z_scale * (double) delta_x; for (columnI = 0; columnI <= 1; columnI++) { /* Prepare and check screen_x: */ screen_x = screen_x1 - columnI - 1; if (screen_x < aux1SP->configSP->image_screen_x0[aux1SP->imageI]) continue; if (screen_x > aux1SP->configSP->image_screen_x1[aux1SP->imageI]) continue; /* Vertical scan: */ for (lineI = 0; lineI <= 4; lineI++) { /* Pixel y coordinate: */ line_screen_y = edge_y + lineI - 2; /* Check line_screen_y: */ if (line_screen_y < aux1SP->configSP->image_screen_y0) continue; if (line_screen_y > aux1SP->configSP->image_screen_y1) continue; /* Check the mask: */ if (!edge_maskAA[lineI][columnI]) continue; /* Current pixel index: */ pixelI = aux1SP->guiSP->main_win_free_area_width * line_screen_y + screen_x; /* Check pixel index: */ if (pixelI >= aux1SP->pixelsN) break; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = aux1SP->nearest_atomSP + pixelI; /* Check was this pixel used already in this drawing step : */ if (aux1SP->refreshI == curr_pixelSP->last_refreshI) { if (atomic_z >= curr_pixelSP->z) continue; } /* If this point is reached draw one pixel: */ XDrawPoint (aux1SP->guiSP->displaySP, aux1SP->guiSP->main_hidden_pixmapID, aux1SP->guiSP->theGCA[lineI + 1], screen_x, line_screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = 4; curr_pixelSP->last_refreshI = aux1SP->refreshI; curr_pixelSP->mol_complexI = aux1SP->mol_complexI; curr_pixelSP->atomI = aux1SP->atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = atomic_z; curr_pixelSP->colorID = aux1SP->colorIDA[lineI + 1]; /* Update the number of pixels drawn: */ pixels_drawnN++; } } /* Check is at least one pixel drawn: */ if (pixels_drawnN > 0) return 1; /* If this point is reached, nothing is drawn: */ return 0; } /*===========================================================================*/ garlic-1.6/bond_style4_quad4.c0000644000076500007650000001771007461726717016626 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2002 Damir Zucic */ /*============================================================================= bond_style4_quad4.c Purpose: Draw bond which fits into quadrant 4 using style 4. See the file file bonds_style4.c for description of quadrants. Input: (1) Pointer to Aux1S structure, which contains required data. (2) Bond index. Output: (1) A single bond drawn. (2) Return value. Return value: (1) One if at least one pixel is drawn. (2) Zero otherwise. =============================================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======draw bond in quadrant 4 using style 4:===============================*/ int BondStyle4Quadrant4_ (Aux1S *aux1SP, int bondI) { long pixels_drawnN = 0; double recip_denom, y_to_x_scale, y_to_z_scale; int screen_x, line_screen_x, screen_y, screen_y1, delta_y; double d, atomic_z; int lineI; size_t pixelI; NearestAtomS *curr_pixelSP; int edge_x, rowI; static int edge_maskAA[5][2] = {{1, 0}, {1, 1}, {1, 1}, {1, 1}, {1, 0}}; /* Scale factor required to calculate screen_x from screen_y: */ if (aux1SP->screen_delta_y != 0) recip_denom = 1.0 / aux1SP->screen_delta_y; else recip_denom = 0.0; y_to_x_scale = aux1SP->screen_delta_x * recip_denom; /* Scale factor required to calculate z (in atomic units) from screen_y: */ y_to_z_scale = aux1SP->atomic_delta_z * recip_denom; /* Vertical scan (bottom to top): */ screen_y1 = (aux1SP->screen_y0 + aux1SP->screen_y1) / 2; for (screen_y = aux1SP->screen_y0; screen_y >= screen_y1; screen_y--) { /* Check is this pixel inside the area reserved for the */ /* current image (there are two images in stereo mode): */ if (screen_y < aux1SP->configSP->image_screen_y0) continue; if (screen_y > aux1SP->configSP->image_screen_y1) continue; /* Relative position: */ delta_y = screen_y - aux1SP->screen_y0; /* Find the corresponding screen_x: */ d = aux1SP->screen_x0 + y_to_x_scale * delta_y; screen_x = (int) (d + 0.5); /* z value (in atomic units): */ atomic_z = aux1SP->atomic_z0 + y_to_z_scale * delta_y; /* Loop which draws lines (horizontal scan): */ for (lineI = 0; lineI <= 6; lineI++) { /* Pixel position: */ line_screen_x = screen_x +lineI - 3; /* Check is this pixel inside the area reserved for the */ /* current image (there are two images in stereo mode): */ if (line_screen_x < aux1SP->configSP->image_screen_x0[aux1SP->imageI]) { continue; } if (line_screen_x > aux1SP->configSP->image_screen_x1[aux1SP->imageI]) { continue; } /* Current pixel index: */ pixelI = aux1SP->guiSP->main_win_free_area_width * screen_y + line_screen_x; /* Check pixel index: */ if (pixelI >= aux1SP->pixelsN) break; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = aux1SP->nearest_atomSP + pixelI; /* Check was this pixel used already in */ /* this drawing step; if it was, compare */ /* the z value of the current atom with z */ /* value previously stored to this pixel: */ if (aux1SP->refreshI == curr_pixelSP->last_refreshI) { if (atomic_z >= curr_pixelSP->z) continue; } /* If this point is reached draw pixel: */ XDrawPoint (aux1SP->guiSP->displaySP, aux1SP->guiSP->main_hidden_pixmapID, aux1SP->guiSP->theGCA[lineI], line_screen_x, screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = 4; curr_pixelSP->last_refreshI = aux1SP->refreshI; curr_pixelSP->mol_complexI = aux1SP->mol_complexI; curr_pixelSP->atomI = aux1SP->atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = atomic_z; curr_pixelSP->colorID = aux1SP->colorIDA[lineI]; /* Update the number of pixels drawn: */ pixels_drawnN++; } } /* Rounding the bottom end: */ edge_x = aux1SP->screen_x0; atomic_z = aux1SP->atomic_z0; for (rowI = 0; rowI <= 1; rowI++) { /* Prepare and check screen_y: */ screen_y = aux1SP->screen_y0 + rowI + 1; if (screen_y < aux1SP->configSP->image_screen_y0) continue; if (screen_y > aux1SP->configSP->image_screen_y1) continue; /* Vertical scan: */ for (lineI = 0; lineI <= 4; lineI++) { /* Pixel x coordinate: */ line_screen_x = edge_x + lineI - 2; /* Check line_screen_x: */ if (line_screen_x < aux1SP->configSP->image_screen_x0[aux1SP->imageI]) { continue; } if (line_screen_x > aux1SP->configSP->image_screen_x1[aux1SP->imageI]) { continue; } /* Check the mask: */ if (!edge_maskAA[lineI][rowI]) continue; /* Current pixel index: */ pixelI = aux1SP->guiSP->main_win_free_area_width * screen_y + line_screen_x; /* Check pixel index: */ if (pixelI >= aux1SP->pixelsN) break; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = aux1SP->nearest_atomSP + pixelI; /* Check was this pixel used already in this drawing step : */ if (aux1SP->refreshI == curr_pixelSP->last_refreshI) { if (atomic_z >= curr_pixelSP->z) continue; } /* If this point is reached draw one pixel: */ XDrawPoint (aux1SP->guiSP->displaySP, aux1SP->guiSP->main_hidden_pixmapID, aux1SP->guiSP->theGCA[lineI + 1], line_screen_x, screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = 4; curr_pixelSP->last_refreshI = aux1SP->refreshI; curr_pixelSP->mol_complexI = aux1SP->mol_complexI; curr_pixelSP->atomI = aux1SP->atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = atomic_z; curr_pixelSP->colorID = aux1SP->colorIDA[lineI + 1]; /* Update the number of pixels drawn: */ pixels_drawnN++; } } /* Rounding the top end: */ delta_y = screen_y1 - aux1SP->screen_y0; d = (double) aux1SP->screen_x0 + y_to_x_scale * (double) delta_y; edge_x = (int) (d + 0.5); atomic_z = aux1SP->atomic_z0 + y_to_z_scale * (double) delta_y; for (rowI = 0; rowI <= 1; rowI++) { /* Prepare and check screen_y: */ screen_y = screen_y1 - rowI - 1; if (screen_y < aux1SP->configSP->image_screen_y0) continue; if (screen_y > aux1SP->configSP->image_screen_y1) continue; /* Vertical scan: */ for (lineI = 0; lineI <= 4; lineI++) { /* Pixel x coordinate: */ line_screen_x = edge_x + lineI - 2; /* Check line_screen_x: */ if (line_screen_x < aux1SP->configSP->image_screen_x0[aux1SP->imageI]) { continue; } if (line_screen_x > aux1SP->configSP->image_screen_x1[aux1SP->imageI]) { continue; } /* Check the mask: */ if (!edge_maskAA[lineI][rowI]) continue; /* Current pixel index: */ pixelI = aux1SP->guiSP->main_win_free_area_width * screen_y + line_screen_x; /* Check pixel index: */ if (pixelI >= aux1SP->pixelsN) break; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = aux1SP->nearest_atomSP + pixelI; /* Check was this pixel used already in this drawing step : */ if (aux1SP->refreshI == curr_pixelSP->last_refreshI) { if (atomic_z >= curr_pixelSP->z) continue; } /* If this point is reached draw one pixel: */ XDrawPoint (aux1SP->guiSP->displaySP, aux1SP->guiSP->main_hidden_pixmapID, aux1SP->guiSP->theGCA[lineI + 1], line_screen_x, screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = 4; curr_pixelSP->last_refreshI = aux1SP->refreshI; curr_pixelSP->mol_complexI = aux1SP->mol_complexI; curr_pixelSP->atomI = aux1SP->atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = atomic_z; curr_pixelSP->colorID = aux1SP->colorIDA[lineI + 1]; /* Update the number of pixels drawn: */ pixels_drawnN++; } } /* Check is at least one pixel drawn: */ if (pixels_drawnN > 0) return 1; /* If this point is reached, nothing is drawn: */ return 0; } /*===========================================================================*/ garlic-1.6/rotate_plane.c0000644000076500007650000001037107154277717015753 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= rotate_plane.c Purpose: Rotate the plane associated with the given macromolecular complex. Input: (1) Pointer to MolComplexS structure. (2) Pointer to ConfigS structure. (3) Rotation angle. (4) Rotation axis identifier (1 = x, 2 = y, 3 = z). Output: (1) Plane rotated, stereo data updated. Return value: No return value. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======rotate plane:========================================================*/ void RotatePlane_ (MolComplexS *curr_mol_complexSP, ConfigS *configSP, double rotation_angle, int axisID) { double cos_angle, sin_angle; double cos_stereo_angle, sin_stereo_angle; PlaneS *curr_planeSP; double x0, y0, z0; double x, y, z; static double x_new, y_new, z_new; /* Calculate cosine and sine of the rotation angle: */ cos_angle = cos (rotation_angle); sin_angle = sin (rotation_angle); /* Calculate cosine and sine of the stereo angle: */ cos_stereo_angle = cos (configSP->stereo_angle); sin_stereo_angle = sin (configSP->stereo_angle); /* Pointer to the current plane: */ curr_planeSP = &curr_mol_complexSP->planeS; /* If plane is moved together with the structure, rotate the plane center: */ if (curr_mol_complexSP->move_bits & STRUCTURE_MASK) { /* Copy the rotation center coordinates: */ x0 = curr_mol_complexSP->rotation_center_vectorS.x; y0 = curr_mol_complexSP->rotation_center_vectorS.y; z0 = curr_mol_complexSP->rotation_center_vectorS.z; /* Position of the plane center relative to the rotation center: */ x = curr_planeSP->center_x[0] - x0; y = curr_planeSP->center_y - y0; z = curr_planeSP->center_z[0] - z0; /* Rotate these coordinates: */ switch (axisID) { /* Rotate around x: */ case 1: x_new = x; y_new = y * cos_angle - z * sin_angle; z_new = y * sin_angle + z * cos_angle; break; /* Rotate around y: */ case 2: x_new = x * cos_angle + z * sin_angle; y_new = y; z_new = -x * sin_angle + z * cos_angle; break; /* Rotate around z: */ case 3: x_new = x * cos_angle - y * sin_angle; y_new = x * sin_angle + y * cos_angle; z_new = z; break; /* The impossible case: */ default: ; break; } /* Translate and store new coordinates: */ curr_planeSP->center_x[0] = x_new + x0; curr_planeSP->center_y = y_new + y0; curr_planeSP->center_z[0] = z_new + z0; /* Prepare stereo data: */ x0 = curr_mol_complexSP->geometric_center_vectorS.x; z0 = curr_mol_complexSP->geometric_center_vectorS.z; x = curr_planeSP->center_x[0] - x0; z = curr_planeSP->center_z[0] - z0; x_new = x * cos_stereo_angle + z * sin_stereo_angle; z_new = -x * sin_stereo_angle + z * cos_stereo_angle; curr_planeSP->center_x[1] = x_new + x0; curr_planeSP->center_z[1] = z_new + z0; } /* Copy the normal vector components: */ x = curr_planeSP->normal_x[0]; y = curr_planeSP->normal_y; z = curr_planeSP->normal_z[0]; /* Rotate the normal vector: */ switch (axisID) { /* Rotate around x: */ case 1: x_new = x; y_new = y * cos_angle - z * sin_angle; z_new = y * sin_angle + z * cos_angle; break; /* Rotate around y: */ case 2: x_new = x * cos_angle + z * sin_angle; y_new = y; z_new = -x * sin_angle + z * cos_angle; break; /* Rotate around z: */ case 3: x_new = x * cos_angle - y * sin_angle; y_new = x * sin_angle + y * cos_angle; z_new = z; break; /* The impossible case: */ default: ; break; } /* Store the rotated vector: */ curr_planeSP->normal_x[0] = x_new; curr_planeSP->normal_y = y_new; curr_planeSP->normal_z[0] = z_new; /* Prepare stereo data for normal vector: */ curr_planeSP->normal_x[1] = curr_planeSP->normal_x[0] * cos_stereo_angle + curr_planeSP->normal_z[0] * sin_stereo_angle; curr_planeSP->normal_z[1] = -curr_planeSP->normal_x[0] * sin_stereo_angle + curr_planeSP->normal_z[0] * cos_stereo_angle; /* Set the position_changedF: */ curr_mol_complexSP->position_changedF = 1; } /*===========================================================================*/ garlic-1.6/draw_bottom.c0000644000076500007650000001536507230077636015620 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= draw_bottom.c Purpose: Draw the exposed polar residues at the surface of the bottom complex. This complex is colored red. Hydrogen bond donors are shown as crosses, acceptors as circles and residues which may be both donors and acceptors are shown as combined crosses and circles. Input: (1) Pointer to GUIS structure. (2) Pointer to RuntimeS structure. Output: (1) Symbols (crosses and circles) drawn to docking window. (2) Return value. Return value: The number of symbols. ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======draw exposed polar residues of the bottom complex:===================*/ int DrawBottom_ (GUIS *guiSP, RuntimeS *runtimeSP) { int symbolsN = 0; int exposed_polarN, exposed_polarI; MolComplexS *curr_mol_complexSP; int *exposed_atomIP; ExposedResidueS *exposed_polarSP; int geom_returnF; Window root_windowID; int x0, y0; unsigned int width, height, border_width, bpp; int square_width, half_square_width; int screen_center_x0, screen_center_y0; int screen_x0, screen_y0, screen_x1, screen_y1; int screen_delta_x, screen_delta_y; double docking_area_width; double scale_factor; int atom_screen_radius; double plane_center_x, plane_center_z; ExposedResidueS *curr_exposedSP; AtomS *curr_atomSP; double x, z; double relative_x, relative_z; double d; int screen_x, screen_y; double donorI; /* Copy pointers: */ exposed_polarN = runtimeSP->exposed_polar1N; curr_mol_complexSP = runtimeSP->mol_complex1SP; exposed_atomIP = runtimeSP->exposed_atom1IP; exposed_polarSP = runtimeSP->exposed_polar1SP; /* Docking window geometry: */ geom_returnF = XGetGeometry(guiSP->displaySP, guiSP->docking_winS.ID, &root_windowID, &x0, &y0, &width, &height, &border_width, &bpp); /* Refresh docking window: */ XSetForeground (guiSP->displaySP, guiSP->theGCA[0], guiSP->black_colorID); XFillRectangle (guiSP->displaySP, guiSP->docking_winS.ID, guiSP->theGCA[0], 0, 0, width, height); /* Prepare some geometric parameters: */ square_width = (int) width - 8 * (int) guiSP->docking_winS.border_width; if (height < width) square_width = (int) height - 8 * (int) guiSP->docking_winS.border_width; half_square_width = square_width / 2; screen_center_x0 = width / 2; screen_center_y0 = height / 2; screen_x0 = screen_center_x0 - half_square_width; screen_y0 = screen_center_y0 - half_square_width; screen_x1 = screen_center_x0 + half_square_width; screen_y1 = screen_center_y0 + half_square_width; screen_delta_x = screen_x1 - screen_x0; screen_delta_y = screen_y1 - screen_y0; docking_area_width = runtimeSP->docking_area_width; if (docking_area_width != 0.0) { scale_factor = square_width / docking_area_width; } else scale_factor = 0.0; atom_screen_radius = (int) (scale_factor * 2.0); /* Draw bounding rectangle (white): */ XSetForeground (guiSP->displaySP, guiSP->theGCA[0], guiSP->white_colorID); XDrawRectangle (guiSP->displaySP, guiSP->docking_winS.ID, guiSP->theGCA[0], screen_x0, screen_y0, (unsigned int) screen_delta_x, (unsigned int) screen_delta_y); /* Copy the plane center position (plane belongs to bottom complex): */ plane_center_x = runtimeSP->mol_complex1SP->planeS.center_x[0]; plane_center_z = runtimeSP->mol_complex1SP->planeS.center_z[0]; /* Prepare cyan color: */ XSetForeground (guiSP->displaySP, guiSP->theGCA[0], guiSP->cyan_colorID); /* Scan the list of exposed polar residues: */ for (exposed_polarI = 0; exposed_polarI < exposed_polarN; exposed_polarI++) { /* Pointer to the current exposed polar residue: */ curr_exposedSP = exposed_polarSP + exposed_polarI; /* If this residue is excluded check the next one: */ if (curr_exposedSP->excludedF) continue; /* Pointer to the representative atom: */ curr_atomSP = curr_mol_complexSP->atomSP + curr_exposedSP->representative_atomI; /* Copy the atomic coordinates: */ x = curr_atomSP->raw_atomS.x[0]; z = curr_atomSP->raw_atomS.z[0]; /* Position of the atom relative to the plane center: */ relative_x = x - plane_center_x; relative_z = z - plane_center_z; /* Atomic coordinates in screen units: */ d = scale_factor * relative_z + screen_center_x0; screen_x = (int) d; d = scale_factor * relative_x + screen_center_y0; screen_y = (int) d; /* Check the screen coordinates: */ if ((screen_x < screen_x0) || (screen_x > screen_x1)) continue; if ((screen_y < screen_y0) || (screen_y > screen_y1)) continue; /* Prepare the color index: */ donorI = (int) curr_exposedSP->donorI; /* If the current residue is hydrogen bond donor, draw cross: */ if ((donorI == 1) || (donorI == 2)) { XDrawLine (guiSP->displaySP, guiSP->docking_winS.ID, guiSP->theGCA[0], screen_x, screen_y + atom_screen_radius, screen_x, screen_y - atom_screen_radius); XDrawLine (guiSP->displaySP, guiSP->docking_winS.ID, guiSP->theGCA[0], screen_x - 1, screen_y + atom_screen_radius, screen_x - 1, screen_y - atom_screen_radius); XDrawLine (guiSP->displaySP, guiSP->docking_winS.ID, guiSP->theGCA[0], screen_x + 1, screen_y + atom_screen_radius, screen_x + 1, screen_y - atom_screen_radius); XDrawLine (guiSP->displaySP, guiSP->docking_winS.ID, guiSP->theGCA[0], screen_x - atom_screen_radius, screen_y, screen_x + atom_screen_radius, screen_y); XDrawLine (guiSP->displaySP, guiSP->docking_winS.ID, guiSP->theGCA[0], screen_x - atom_screen_radius, screen_y - 1, screen_x + atom_screen_radius, screen_y - 1); XDrawLine (guiSP->displaySP, guiSP->docking_winS.ID, guiSP->theGCA[0], screen_x - atom_screen_radius, screen_y + 1, screen_x + atom_screen_radius, screen_y + 1); } /* If the current residue is hydrogen bond acceptor, draw circle: */ if ((donorI == 0) || (donorI == 2)) { XDrawArc (guiSP->displaySP, guiSP->docking_winS.ID, guiSP->theGCA[0], screen_x - atom_screen_radius, screen_y - atom_screen_radius, (unsigned int) (2 * atom_screen_radius), (unsigned int) (2 * atom_screen_radius), 0, 23040); XDrawArc (guiSP->displaySP, guiSP->docking_winS.ID, guiSP->theGCA[0], screen_x - atom_screen_radius - 1, screen_y - atom_screen_radius - 1, (unsigned int) (2 * atom_screen_radius + 2), (unsigned int) (2 * atom_screen_radius + 2), 0, 23040); } /* Increment the counter: */ symbolsN++; } /* Return the number of symbols drawn: */ return symbolsN; } /*===========================================================================*/ garlic-1.6/display_init.c0000644000076500007650000000503307520467075015760 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2002 Damir Zucic */ /*============================================================================= display_init.c Purpose: Display initializations: connect to X server, get default screen ID and screen size. In addition, prepare the three graphics contexts. Input: (1) Pointer to GUIS structure (with GUI data). Output: (1) Data stored to GUIS structure. (2) Return value. Return value: (1) Positive on success. (2) Negative on failure (if attempt to connect to X server fails). =============================================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======initialize display:==================================================*/ int DisplayInit_ (GUIS *guiSP) { /* Connect to X server: */ if ((guiSP->displaySP = XOpenDisplay (guiSP->display_nameP)) == NULL) { return -1; } /* Default screen for given display: */ guiSP->screenID = DefaultScreen (guiSP->displaySP); /* Default screen size: */ guiSP->screen_width = DisplayWidth (guiSP->displaySP, guiSP->screenID); guiSP->screen_height = DisplayHeight (guiSP->displaySP, guiSP->screenID); /* Ten graphics contexts: */ guiSP->theGCA[0] = XCreateGC (guiSP->displaySP, DefaultRootWindow (guiSP->displaySP), 0, NULL); guiSP->theGCA[1] = XCreateGC (guiSP->displaySP, DefaultRootWindow (guiSP->displaySP), 0, NULL); guiSP->theGCA[2] = XCreateGC (guiSP->displaySP, DefaultRootWindow (guiSP->displaySP), 0, NULL); guiSP->theGCA[3] = XCreateGC (guiSP->displaySP, DefaultRootWindow (guiSP->displaySP), 0, NULL); guiSP->theGCA[4] = XCreateGC (guiSP->displaySP, DefaultRootWindow (guiSP->displaySP), 0, NULL); guiSP->theGCA[5] = XCreateGC (guiSP->displaySP, DefaultRootWindow (guiSP->displaySP), 0, NULL); guiSP->theGCA[6] = XCreateGC (guiSP->displaySP, DefaultRootWindow (guiSP->displaySP), 0, NULL); guiSP->theGCA[7] = XCreateGC (guiSP->displaySP, DefaultRootWindow (guiSP->displaySP), 0, NULL); guiSP->theGCA[8] = XCreateGC (guiSP->displaySP, DefaultRootWindow (guiSP->displaySP), 0, NULL); guiSP->theGCA[9] = XCreateGC (guiSP->displaySP, DefaultRootWindow (guiSP->displaySP), 0, NULL); guiSP->gca_createdF = 1; /* Return positive value on success: */ return 1; } /*===========================================================================*/ garlic-1.6/plot.c0000644000076500007650000002510510445775002014240 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2006 Damir Zucic */ /*============================================================================= plot.c Purpose: Execute plot command: plot requested functions. The command plot may be followed by a list of keywords. If keyword OFF is present, the main window drawing mode will be changed to default mode. Otherwise, for all recognized keywords the corresponding flags in RuntimeS structure will be set to one. Other keywords: HYD (HYDROPHOBICITY) - average hydrophobicity; WEI (WEIGHTED) - weigthed hydrophobicity; MOM (MOMENT) - hydrophobic moment; SID (SIDED) - sided hydrophobicity (porins). F1 - hydrophobicity function F1; F2 - hydrophobicity function F2. F3 - hydrophobicity function F3. F4 - hydrophobicity function F4. F5 - hydrophobicity function F5. F6 - hydrophobicity function F6. F7 - hydrophobicity function F7. Input: (1) Pointer to MolComplexS structure. (2) The number of macromolecular complexes. (3) Pointer to RuntimeS structure. (4) Pointer to ConfigS structure. (5) Pointer to GUIS structure. (6) Pointer to NearestAtomS structure. (7) The number of pixels in the main window free area. (8) Pointer to refreshI. (9) Pointer to the remainder of the command string. This command may be given with a list of keywords or with keyword OFF. Output: (1) The main window mode changed to 4 (default is zero). (2) Return value. Return value: (1) Positive (command) code on success. (2) Negative (error) code on failure. Notes: (1) This command reinitializes the NearestAtomS array, except if at least one of additional keywords is not recognized. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "commands.h" #include "typedefs.h" /*======function prototypes:=================================================*/ void InitNearest_ (NearestAtomS *, size_t); int ExtractTwoIntegers_ (int *, int *, char *); size_t MainRefresh_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); int ControlRefresh_ (MolComplexS *, ConfigS *, GUIS *); /*======execute plot command:================================================*/ int Plot_ (MolComplexS *mol_complexSP, int mol_complexesN, RuntimeS *runtimeSP, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int *refreshIP, char *stringP) { char *P; int n; int residue1I, residue2I; /* Reset flags: */ runtimeSP->average_hydrophobicityF = 0; runtimeSP->weighted_hydrophobicityF = 0; runtimeSP->hydrophobic_momentF = 0; runtimeSP->sided_hydrophobicityF = 0; runtimeSP->function1F = 0; runtimeSP->function2F = 0; runtimeSP->function3F = 0; runtimeSP->function4F = 0; runtimeSP->function5F = 0; runtimeSP->function6F = 0; runtimeSP->function7F = 0; /* If keyword OFF is present, switch to default drawing mode: */ if (strstr (stringP, "OFF")) { /* Reset drawing mode index: */ guiSP->main_window_modeI = 0; /* Reinitialize the NearestAtomS array: */ InitNearest_ (nearest_atomSP, pixelsN); *refreshIP = 1; /* Refresh the main window: */ (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); /* Refresh the control window: */ ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); /* Return the command code: */ return COMMAND_PLOT; } /* The sequence buffer should be filled with something: */ if ((int) runtimeSP->residuesN == 0) { strcpy (runtimeSP->messageA, "The sequence buffer is empty!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_PLOT; } /* The sliding window should not be wider than the sequence: */ if (runtimeSP->sliding_window_width > (int) runtimeSP->residuesN) { strcpy (runtimeSP->messageA, "The sliding window is wider than the sequence!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_PLOT; } /* If keyword HYD (short for HYDROPHOBICITY) is present, set the */ /* flag which signals that average hydrophobicity should be drawn: */ if (strstr (stringP, "HYD")) { runtimeSP->average_hydrophobicityF = 1; } /* If keyword WEI (short for WEIGHTED) is present, set the flag */ /* which signals that weighted hydrophobicity should be drawn: */ if (strstr (stringP, "WEI")) { runtimeSP->weighted_hydrophobicityF = 1; } /* If keyword MOM (short for MOMENT) is present, set the flag */ /* which signals that hydrophobic moment should be drawn: */ if (strstr (stringP, "MOM")) { runtimeSP->hydrophobic_momentF = 1; } /* If keyword SID (short for SIDED_HYDROPHOBICITY) is present, set the flag */ /* which says that sided hydrophobicity should be calculated (two lines): */ if (strstr (stringP, "SID")) { runtimeSP->sided_hydrophobicityF = 1; } /* If keyword F1 is present, draw the function F1. Do not forget */ /* to remove the substring "F1" from the string, because it may */ /* confuse the parser which retrieves the residue array indices! */ if (strstr (stringP, "F1")) { /* Set flag: */ runtimeSP->function1F = 1; /* Replace the substring "F1": */ P = strstr (stringP, "F1"); if (P) { *P = ' '; *(P + 1) = ' '; } } /* If keyword F2 is present, draw the function F2. Do not forget */ /* to remove the substring "F2" from the string, because it may */ /* confuse the parser which retrieves the residue array indices! */ if (strstr (stringP, "F2")) { /* Set flag: */ runtimeSP->function2F = 1; /* Replace the substring "F2": */ P = strstr (stringP, "F2"); if (P) { *P = ' '; *(P + 1) = ' '; } } /* If keyword F3 is present, draw the function F3. Do not forget */ /* to remove the substring "F3" from the string, because it may */ /* confuse the parser which retrieves the residue array indices! */ if (strstr (stringP, "F3")) { /* Set flag: */ runtimeSP->function3F = 1; /* Replace the substring "F3": */ P = strstr (stringP, "F3"); if (P) { *P = ' '; *(P + 1) = ' '; } } /* If keyword F4 is present, draw the function F4. Do not forget */ /* to remove the substring "F4" from the string, because it may */ /* confuse the parser which retrieves the residue array indices! */ if (strstr (stringP, "F4")) { /* Set flag: */ runtimeSP->function4F = 1; /* Replace the substring "F4": */ P = strstr (stringP, "F4"); if (P) { *P = ' '; *(P + 1) = ' '; } } /* If keyword F5 is present, draw the function F5. Do not forget */ /* to remove the substring "F5" from the string, because it may */ /* confuse the parser which retrieves the residue array indices! */ if (strstr (stringP, "F5")) { /* Set flag: */ runtimeSP->function5F = 1; /* Replace the substring "F5": */ P = strstr (stringP, "F5"); if (P) { *P = ' '; *(P + 1) = ' '; } } /* If keyword F6 is present, draw the function F6. Do not forget */ /* to remove the substring "F6" from the string, because it may */ /* confuse the parser which retrieves the residue array indices! */ if (strstr (stringP, "F6")) { /* Set flag: */ runtimeSP->function6F = 1; /* Replace the substring "F6": */ P = strstr (stringP, "F6"); if (P) { *P = ' '; *(P + 1) = ' '; } } /* If keyword F7 is present, draw the function F7. Do not forget */ /* to remove the substring "F7" from the string, because it may */ /* confuse the parser which retrieves the residue array indices! */ if (strstr (stringP, "F7")) { /* Set flag: */ runtimeSP->function7F = 1; /* Replace the substring "F7": */ P = strstr (stringP, "F7"); if (P) { *P = ' '; *(P + 1) = ' '; } } /* At least one flag should be set to one: */ if ((runtimeSP->average_hydrophobicityF == 0) && (runtimeSP->weighted_hydrophobicityF == 0) && (runtimeSP->hydrophobic_momentF == 0) && (runtimeSP->sided_hydrophobicityF == 0) && (runtimeSP->function1F == 0) && (runtimeSP->function2F == 0) && (runtimeSP->function3F == 0) && (runtimeSP->function4F == 0) && (runtimeSP->function5F == 0) && (runtimeSP->function6F == 0) && (runtimeSP->function7F == 0)) { strcpy (runtimeSP->messageA, "Failed to recognize what should be drawn!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_PLOT; } /* If you want sided hydrophobicity, the sliding */ /* window should contain at least two residues: */ if ((runtimeSP->sided_hydrophobicityF == 1) && (runtimeSP->sliding_window_width < 2)) { strcpy (runtimeSP->messageA, "For sided hyd. plot, the sliding window"); strcat (runtimeSP->messageA, " should contain at least two residues!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_PLOT; } /* Replace each minus and colon in the input string with space: */ P = stringP; while ((n = *P++) != '\0') { if (n == '-') *(P - 1) = ' '; else if (n == ':') *(P - 1) = ' '; } /* Try to extract two indices: */ residue1I = 0; residue2I = 0; if (ExtractTwoIntegers_ (&residue1I, &residue2I, stringP) > 0) { /* Check indices: */ if ((residue1I < 1) || (residue2I < residue1I)) { strcpy (runtimeSP->messageA, "Bad range (check indices)!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_PLOT; } if (residue1I <= 0) residue1I = 1; if (residue2I <= 0) residue2I = 1; /* Store the extracted indices: */ runtimeSP->range_startI = residue1I - 1; runtimeSP->range_endI = residue2I - 1; } /* If failed to extract indices, use default values: */ else { runtimeSP->range_startI = 0; if (runtimeSP->residuesN >= 1) { runtimeSP->range_endI = (int) runtimeSP->residuesN - 1; } else { runtimeSP->range_endI = 0; } } /* Set the main window drawing mode index: */ guiSP->main_window_modeI = 4; /* Reinitialize the NearestAtomS array and refresh index: */ InitNearest_ (nearest_atomSP, pixelsN); *refreshIP = 1; /* Refresh the main window: */ (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); /* Refresh the control window: */ ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); /* Return the command code: */ return COMMAND_PLOT; } /*===========================================================================*/ garlic-1.6/compare_sequences.c0000644000076500007650000000644007374046452016773 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= compare_sequences.c Purpose: Compare sequence fragment from the current macromolecular complex with the sequence from the sequence buffer. The leading residues from both sequences were compared before, so it is not necessary to compare these residues again. Input: (1) Pointer to MolComplexS structure, with data about the current macromolecular complex, including the sequence fragment which should be compared with sequence from the sequence buffer. (2) The index of the first residue in the sequence fragment which is currently checked. (3) Number of residues in the sequence which is associated with the current macromolecular complex. The fragment mentioned above belongs to this sequence. (4) Pointer to the first residue in the sequence buffer. (5) Number of residues in the sequence buffer. Output: Return value. Return value: (1) Positive, if two sequences match. (2) Negative, if two sequences do not match. Notes: (1) Don't forget to check are there enough residues in the seq. fragment which is compared with the sequence buffer. If this is not checked, a memory overflow may occur. (2) Use strncmp to compare residue names because residue names in the sequence buffer are not zero terminated! ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======compare sequences:===================================================*/ int CompareSequences_ (MolComplexS *curr_mol_complexSP, size_t start1I, size_t residues1N, char *first_name2P, size_t residues2N) { int max_length; size_t residue1I, residue2I; ResidueS *curr_residue1SP; AtomS *atom1SP; char *name1P; char *name2P; /* If there is only one residue in the sequence buffer, the sequences match: */ if (residues2N == 1) return 1; /* Check is the sequence fragment long enough to be */ /* compared with sequence from the sequence buffer: */ if (start1I + residues2N > residues1N) return -1; /* The maximal residue name length: */ max_length = RESNAMESIZE - 1; /* Scan the sequence fragment: */ residue2I = 1; for (residue1I = start1I + 1; residue1I < start1I + residues2N; residue1I++) { /* Pointer to the current residue: */ curr_residue1SP = curr_mol_complexSP->residueSP + residue1I; /* Pointer to the first atom of the current residue: */ atom1SP = curr_mol_complexSP->atomSP + curr_residue1SP->residue_startI; /* Pointer to the name of the current residue: */ name1P = atom1SP->raw_atomS.pure_residue_nameA; /* Pointer to the name of the corresponding residue in the buffer: */ name2P = first_name2P + residue2I * max_length; /* Compare residue names; if they do */ /* not match, return negative value: */ if (strncmp (name1P, name2P, max_length) != 0) return -1; /* Update the residue index which is scanning the sequence buffer: */ residue2I++; } /* If this point is reached, two sequences match! */ /* Return positive value on success: */ return 1; } /*===========================================================================*/ garlic-1.6/2por.script0000644000076500007650000000033210140117630015206 0ustar zuciczucic00000000000000# Playing with 2por: extracellular loops load 2por.pdb backbone 3 color white select hetero select complement sequence from 1 scale octanol sel 15-20 46-60 73-118 135-149 168-183 202-231 252-262 282-290 color blue garlic-1.6/window.c0000644000076500007650000000367707224716625014612 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= window.c Purpose: Execute window command: set the sliding window width. The hard-coded default is 11. The minimal value is 1. Input: (1) Pointer to RuntimeS structure. Output: (1) The sliding window width set. (2) Return value. Return value: (1) Positive (command) code on success. (2) Negative (error) code on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include #include "defines.h" #include "commands.h" #include "typedefs.h" /*======execute window command:==============================================*/ int Window_ (RuntimeS *runtimeSP) { char string_copyA[STRINGSIZE]; char *P; int n; int value; /* Copy the original command string: */ strncpy (string_copyA, runtimeSP->curr_commandA, STRINGSIZE - 1); string_copyA[STRINGSIZE - 1] = '\0'; /* Replace each non-numeric character (except */ /* minus sign and decimal point) with space: */ P = string_copyA; while ((n = *P++) != '\0') { if (!isdigit (n) && (n != '-') && (n != '.')) *(P - 1) = ' '; } /* Try to extract the sliding window width: */ if (sscanf (string_copyA, "%d", &value) != 1) { strcpy (runtimeSP->messageA, "Failed to extract the sliding window width!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_WINDOW; } /* Check the value: */ if (value < 1) { strcpy (runtimeSP->messageA, "Positive value expected!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_WINDOW; } /* On success, copy the extracted value to RuntimeS structure: */ runtimeSP->sliding_window_width = value; /* Return the command code: */ return COMMAND_WINDOW; } /*===========================================================================*/ garlic-1.6/select.c0000644000076500007650000001156607317143321014544 0ustar zuciczucic00000000000000/* Copyright (C) 2000, 2001 Damir Zucic */ /*============================================================================= select.c Purpose: Execute select command. Select the specified atoms in all caught macromolecular complexes. Three selection modes are available: 0 = overwrite, 1 = restrict, 2 = expand previous selection. Input: (1) Pointer to MolComplexS structure. (2) Number of macromolecular complexes. (3) Pointer to RuntimeS structure. (4) Pointer to ConfigS structure. (5) Pointer to GUIS structure. (6) Pointer to NearestAtomS structure. (7) The number of pixels in the main window free area. (8) Pointer to refreshI. (9) The selection string. (10) Selection mode index. Output: (1) Selection flag changed for some or all atoms. (2) Return value. Return value: (1) Positive (command) code on success. (2) Negative (error) code on failure. Notes: (1) This function resets the edit mode index. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "commands.h" #include "typedefs.h" /*======function prototypes:=================================================*/ char *ExtractToken_ (char *, int, char *, char *); long FullSelect_ (MolComplexS *, int, char *, int); long SelectElement_ (MolComplexS *, int, char *, int); long SelectAtoms_ (MolComplexS *, int, RuntimeS *, char *, int); long SpecialSelect_ (MolComplexS *, int, RuntimeS *, char *, int); long QuickSelect_ (MolComplexS *, int, char *, int); size_t MainRefresh_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); int ControlRefresh_ (MolComplexS *, ConfigS *, GUIS *); /*======execute select command:==============================================*/ int Select_ (MolComplexS *mol_complexSP, int mol_complexesN, RuntimeS *runtimeSP, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int *refreshIP, char *stringP, int selection_modeI) { char *remainderP; char tokenA[STRINGSIZE]; long selected_atomsN; /* The second token should contain the selection */ /* criteria; it is called "the selection string": */ remainderP = ExtractToken_ (tokenA, STRINGSIZE, stringP, "\n\0"); if (!remainderP) { strcpy (runtimeSP->messageA, "Selection criteria missing!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_SELECT; } /* First try with the function which expects precise selection */ /* criteria; the string is expected to contain three slashes: */ selected_atomsN = FullSelect_ (mol_complexSP, mol_complexesN, tokenA, selection_modeI); /* If the first attempt failed, try to intepret the command */ /* as the request to select the specified chemical element: */ if (selected_atomsN == -1) { selected_atomsN = SelectElement_ (mol_complexSP, mol_complexesN, tokenA, selection_modeI); } /* Try to interpret the command as the request to select */ /* the atom which has the specified serial number: */ if (selected_atomsN == -1) { selected_atomsN = SelectAtoms_ (mol_complexSP, mol_complexesN, runtimeSP, tokenA, selection_modeI); } /* If all previous functions were unable to interpret the */ /* selection string try with the special selection function: */ if (selected_atomsN == -1) { selected_atomsN = SpecialSelect_ (mol_complexSP, mol_complexesN, runtimeSP, tokenA, selection_modeI); } /* The last attempt - try with the "quick" selection: */ if (selected_atomsN == -1) { selected_atomsN = QuickSelect_ (mol_complexSP, mol_complexesN, tokenA, selection_modeI); } /* Write the number of selected atoms to the input window: */ if (selected_atomsN >= 0) { sprintf (runtimeSP->messageA, "%ld atom(s) selected", selected_atomsN); runtimeSP->message_length = strlen (runtimeSP->messageA); } /* If all selection functions failed, prepare error message: */ else { strcpy (runtimeSP->messageA, "Selection failed!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_SELECT; } /* Default editing mode (0, no editing) does not */ /* require redrawing. Other modes require it: */ if (runtimeSP->edit_modeI != 0) { /* Reset edit mode index: */ runtimeSP->edit_modeI = 0; /* Reset edit_single_bondF flag: */ runtimeSP->edit_single_bondF = 0; /* Refresh the main window: */ (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); /* Refresh the control window: */ ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); } /* If this point is reached, everything worked fine: */ return COMMAND_SELECT; } /*===========================================================================*/ garlic-1.6/draw_squid.c0000644000076500007650000001470507612772131015432 0ustar zuciczucic00000000000000/* Copyright (C) 2001-2003 Damir Zucic */ /*============================================================================= draw_squid.c Purpose: Draw the squid at the position of the first selected atom. Write a small hint to the top right corner of the main window. Input: (1) Pointer to AtomS structure. (2) Pointer to ConfigS structure. (3) Pointer to GUIS structure. (4) Pointer to NearestAtomS structure. (5) The number of pixels in the main window free area. (6) The refreshI index. Output: (1) Squid drawn to the main pixmap. (2) Return value. Return value: (1) Positive on success. (2) Negative on failure. =============================================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" #include "squid.xpm" /*======function prototypes:=================================================*/ int ParseColor_ (RGBS *, unsigned long *, GUIS *, char *, char *); /*======draw squid:==========================================================*/ int DrawSquid_ (AtomS *selected_atomSP, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int refreshI) { static int called_beforeF; int imageI, imagesN; int left_edge[2], right_edge[2]; int colorsN = 10, colorI; int stringI; char *color_stringP; RGBS rgbS; static unsigned long colorIDA[10]; int screen_x0, screen_y0, screen_x, screen_y; double z; int width = 211, height = 43, columnI, rowI; int current_char; size_t pixelI; NearestAtomS *curr_pixelSP; char stringA[SHORTSTRINGSIZE]; int text_width; unsigned int hint_width, hint_height; /*------draw the squid:------------------------------------------------------*/ /* Number of images: */ if (configSP->stereoF) imagesN = 2; else imagesN = 1; /* Left and right image edge (in stereo mode there are two images): */ left_edge[0] = configSP->image_screen_x0[0]; right_edge[0] = configSP->image_screen_x1[0]; left_edge[1] = configSP->image_screen_x0[1]; right_edge[1] = configSP->image_screen_x1[1]; /* Prepare colors if this function is called for the first time: */ if (!called_beforeF) { for (colorI = 0; colorI < colorsN; colorI++) { /* The third string specifies the first */ /* color. The index of this string is two: */ stringI = colorI + 2; /* The color string follows the substring "c ": */ color_stringP = strstr (squid_xpm[stringI], "c ") + 2; /* Parse color: */ ParseColor_ (&rgbS, &colorIDA[colorI], guiSP, color_stringP, "white"); } } /* Set the flag which signals that this function was used at least once: */ called_beforeF = 1; /* Copy colors to GC's: */ for (colorI = 0; colorI < colorsN; colorI++) { XSetForeground (guiSP->displaySP, guiSP->theGCA[colorI], colorIDA[colorI]); } /* Draw one (mono) or two pixels (stereo): */ for (imageI = 0; imageI < imagesN; imageI++) { /* Screen coordinates of the selected atom: */ screen_x0 = selected_atomSP->raw_atomS.screen_x[imageI]; screen_y0 = selected_atomSP->raw_atomS.screen_y; /* z coordinate: */ z = selected_atomSP->raw_atomS.z[imageI]; /* Now scan the pixmap. */ /* Vertical scan (top to bottom): */ for (rowI = 0; rowI < height; rowI++) { /* Prepare the string index: */ stringI = rowI + 12; /* Horizontal scan (left to right): */ for (columnI = 0; columnI < width; columnI++) { /* Prepare the current character: */ current_char = squid_xpm[stringI][columnI]; /* Check is it this pixel transparent: */ if (current_char == ' ') continue; /* Prepare the color index: */ switch (current_char) { case '.': colorI = 0; break; case '+': colorI = 1; break; case '@': colorI = 2; break; case '#': colorI = 3; break; case '$': colorI = 4; break; case '%': colorI = 5; break; case '&': colorI = 6; break; case '*': colorI = 7; break; case '=': colorI = 8; break; case '-': colorI = 9; break; default: ; } /* Prepare and check the screen coordinates: */ screen_x = screen_x0 + columnI - 1; screen_y = screen_y0 + rowI - 28; if (screen_x < left_edge[imageI]) break; if (screen_x >= right_edge[imageI]) break; /* Prepare index to the array */ /* of NearestAtomS structures: */ pixelI = guiSP->main_win_free_area_width * screen_y + screen_x; /* Check the pixel index: */ if (pixelI >= pixelsN) break; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = nearest_atomSP + pixelI; /* Check was this pixel used already in */ /* this drawing step; if it was, compare */ /* the z value of the current atom with z */ /* value previously stored to this pixel: */ if (refreshI == curr_pixelSP->last_refreshI) { if (z >= curr_pixelSP->z) continue; } /* Draw this pixel: */ XDrawPoint (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[colorI], screen_x, screen_y); } } } /* imageI loop */ /*------draw the hint:-------------------------------------------------------*/ /* Prepare the text: */ strcpy (stringA, "Use 0, 5, /, *, + and - on numeric keypad"); /* Draw the red filled rectangle and the yellow text inside this rectangle: */ text_width = XTextWidth (guiSP->main_winS.fontSP, stringA, strlen (stringA)); screen_x0 = guiSP->main_win_free_area_width - text_width - guiSP->main_winS.half_font_height - 2 * guiSP->main_winS.border_width; screen_y0 = guiSP->main_winS.font_height + 9; hint_width = text_width + guiSP->main_winS.half_font_height; hint_height = guiSP->main_winS.font_height + 4; XSetForeground (guiSP->displaySP, guiSP->theGCA[0], guiSP->red_colorID); XFillRectangle (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0, screen_y0, hint_width, hint_height); XSetForeground (guiSP->displaySP, guiSP->theGCA[0], guiSP->yellow_colorID); screen_x0 += guiSP->main_winS.quarter_font_height; screen_y0 += guiSP->main_winS.font_height - 2; XDrawString (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, strlen (stringA)); /*---------------------------------------------------------------------------*/ /* Return positive value on success: */ return 1; } /*===========================================================================*/ garlic-1.6/22porins.script0000644000076500007650000000463610414506153016023 0ustar zuciczucic00000000000000# Loading and displaying 18 porins. # All structures will be displayed as cyan-blue backbones. # Turn refreshing off, for better performance (don't forget # to switch the refreshing on at the end of this script!): refresh off #============================================================================== # (1) 2POR: load 2por.pdb backbone 2 color cyan-blue position -150 -105 700 # (2) 1OPF: load 1opf.pdb backbone 2 color cyan-blue position -90 -105 700 # (3) 1PRN: load 1prn.pdb backbone 2 color cyan-blue position -30 -105 700 # (4) 1OSM: load 1osm.pdb backbone 2 color cyan-blue position 30 -105 700 # (5) 1E54: load 1e54.pdb backbone 2 color cyan-blue position 90 -105 700 # (6) 1MAL: load 1mal.pdb backbone 2 color cyan-blue position 150 -105 700 #============================================================================== # (7) 1A0S: load 1a0s.pdb backbone 2 color cyan-blue position -150 -35 700 # (8) 1BXW: load 1bxw.pdb backbone 2 color cyan-blue position -90 -35 700 # (9) 1QJ8: load 1qj8.pdb backbone 2 color cyan-blue position -30 -35 700 # (10) 2FCP: load 2fcp.pdb backbone 2 color cyan-blue position 30 -35 700 # (11) 1FEP: load 1fep.pdb backbone 2 color cyan-blue position 90 -35 700 # (12) 1KMO: load 1kmo.pdb backbone 2 color cyan-blue position 150 -35 700 #============================================================================== # (13) 1I78: load 1i78.pdb backbone 2 color cyan-blue position -150 35 700 # (14) 1QD5: load 1qd5.pdb backbone 2 color cyan-blue position -90 35 700 # (15) 1K24: load 1k24.pdb backbone 2 color cyan-blue position -30 35 700 # (16) 1NQE: load 1nqe.pdb backbone 2 color cyan-blue position 30 35 700 # (17) 1TLZ: load 1tlz.pdb backbone 2 color cyan-blue position 90 35 700 # (18) 1T16: load 1t16.pdb backbone 2 color cyan-blue position 150 35 700 #============================================================================== # (19) 1THQ: load 1thq.pdb backbone 2 color cyan-blue position -150 105 700 # (20) 1XKH: load 1xkh.pdb backbone 2 color cyan-blue position -90 105 700 # (21) 1UYN: load 1uyn.pdb backbone 2 color cyan-blue position -30 105 700 # (22) 1WP1 (truncated file, bottom part deleted): load 1wp1-truncated.pdb backbone 2 color cyan-blue position 30 105 700 #============================================================================== # Switch refreshing on: refresh on # Group all structures: group all garlic-1.6/exclude_distant.c0000644000076500007650000000655107157240535016451 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= exclude_distant.c Purpose: Exclude exposed polar residues which are below the plane. Input: (1) Pointer to RuntimeS structure. (2) The complex index (1 = bottom, 2 = top). Output: (1) Some exposed polar residues excluded from the list. (2) Return value. Return value: (1) Positive on success. (2) Negative on failure. ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ void ErrorMessage_ (char *, char *, char *, char *, char *, char *, char *); double ScalarProduct_ (VectorS *, VectorS *); /*======exclude distant residues from the list:==============================*/ int ExcludeDistant_ (RuntimeS *runtimeSP, int docking_complexI) { int exposed_polarN, exposed_polarI; MolComplexS *curr_mol_complexSP; int *exposed_atomIP; ExposedResidueS *exposed_polarSP; double plane_center_x, plane_center_y, plane_center_z; VectorS normal_vectorS; ExposedResidueS *curr_exposedSP; AtomS *curr_atomSP; double x, y, z; VectorS curr_vectorS; /* Check the complex index and prepare the pointers: */ if (docking_complexI == 1) { exposed_polarN = runtimeSP->exposed_polar1N; curr_mol_complexSP = runtimeSP->mol_complex1SP; exposed_atomIP = runtimeSP->exposed_atom1IP; exposed_polarSP = runtimeSP->exposed_polar1SP; } else if (docking_complexI == 2) { exposed_polarN = runtimeSP->exposed_polar2N; curr_mol_complexSP = runtimeSP->mol_complex2SP; exposed_atomIP = runtimeSP->exposed_atom2IP; exposed_polarSP = runtimeSP->exposed_polar2SP; } else { ErrorMessage_ ("garlic", "RepresentativeAtoms_", "", "Bad macromolecular complex index!\n", "", "", ""); return -1; } /* Copy the plane center position (plane belongs to bottom complex): */ plane_center_x = curr_mol_complexSP->planeS.center_x[0]; plane_center_y = curr_mol_complexSP->planeS.center_y; plane_center_z = curr_mol_complexSP->planeS.center_z[0]; /* Copy the normal vector (plane belongs to bottom complex): */ normal_vectorS.x = curr_mol_complexSP->planeS.normal_x[0]; normal_vectorS.y = curr_mol_complexSP->planeS.normal_y; normal_vectorS.z = curr_mol_complexSP->planeS.normal_z[0]; /* Scan the list: */ for (exposed_polarI = 0; exposed_polarI < exposed_polarN; exposed_polarI++) { /* Pointer to the current exposed polar residue: */ curr_exposedSP = exposed_polarSP + exposed_polarI; /* Pointer to the representative atom: */ curr_atomSP = curr_mol_complexSP->atomSP + curr_exposedSP->representative_atomI; /* Copy the atomic coordinates: */ x = curr_atomSP->raw_atomS.x[0]; y = curr_atomSP->raw_atomS.y; z = curr_atomSP->raw_atomS.z[0]; /* Position of the atom relative to the plane center: */ curr_vectorS.x = x - plane_center_x; curr_vectorS.y = y - plane_center_y; curr_vectorS.z = z - plane_center_z; /* Check the sign of the scalar product: */ if (ScalarProduct_ (&curr_vectorS, &normal_vectorS) < 0) { curr_exposedSP->excludedF = 1; } } /* Return positive value on success: */ return 1; } /*===========================================================================*/ garlic-1.6/dance.script0000644000076500007650000000073307063372010015410 0ustar zuciczucic00000000000000load trp.pdb pos 0 0 1000 tra z -50 rot y 20 tra z -50 rot y -20 tra z -50 rot y 20 tra z -50 rot y -20 tra z -50 rot y 20 tra z -50 rot y -20 tra z -50 rot y 20 tra z -50 rot y -20 tra z -50 rot y 20 tra z -50 rot y -20 tra z -50 rot y 20 tra z -50 rot y -20 tra z -50 rot y 20 tra z -50 rot y -20 tra z -50 rot y 20 tra z -50 rot y -20 tra z -50 rot y 20 tra z -50 rot y -20 tra z -50 rot y 20 tra z -50 rot y -20 tra z -50 rot y 20 tra z -50 rot y -20 tra z -50 rot y 20 garlic-1.6/save.c0000644000076500007650000000674207612762023014227 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2003 Damir Zucic */ /*============================================================================= save.c Purpose: Execute save command: save the atomic coordinates to a specified file. PDB format is used. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) The number of macromolecular complexes. (3) Pointer to RuntimeS structure. Output: (1) Atomic coordinates written to file, on success. (2) Return value. Return value: (1) Positive (command) code on success. (2) Negative (error) code on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include #include "defines.h" #include "commands.h" #include "typedefs.h" /*======function prototypes:=================================================*/ char *ExtractToken_ (char *, int, char *, char *); int WriteLine_ (FILE *, RawAtomS *); /*======execute save command:================================================*/ int Save_ (MolComplexS *mol_complexSP, int mol_complexesN, RuntimeS *runtimeSP) { char *remainderP; char tokenA[STRINGSIZE]; FILE *fileP; char token_copyA[STRINGSIZE]; char *P; int n; int selectionF = 0; MolComplexS *curr_mol_complexSP; size_t atomsN, atomI; AtomS *curr_atomSP; /* Skip the first token: */ remainderP = ExtractToken_ (tokenA, STRINGSIZE, runtimeSP->curr_commandA, " \t\n"); if (!remainderP) return ERROR_SAVE; /* The second token should contain the file name: */ remainderP = ExtractToken_ (tokenA, STRINGSIZE, remainderP, " \t\n"); if (!remainderP) { strcpy (runtimeSP->messageA, "Missing the output file name!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_NO_FILE_NAME; } /* Try to open the output file: */ if ((fileP = fopen (tokenA, "w")) == NULL) { strcpy (runtimeSP->messageA, "Failed to open output file!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_OPEN_FAILURE; } /* If third token is present, it should contain the keyword SEL: */ remainderP = ExtractToken_ (tokenA, STRINGSIZE, remainderP, " \t\n"); if (remainderP) { /** Convert token to uppercase: **/ strncpy (token_copyA, tokenA, STRINGSIZE - 1); P = token_copyA; while ((n = *P++) != '\0') *(P - 1) = toupper (n); /** If this token contains the keyword SEL, set selectionF: **/ if (strstr (token_copyA, "SEL") == token_copyA) selectionF = 1; } /* Prepare the pointer to default caught complex: */ curr_mol_complexSP = mol_complexSP + runtimeSP->default_complexI; /** Number of atoms in a macromolecular complex: **/ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) { strcpy (runtimeSP->messageA, "Catch the complex which is not empty!"); runtimeSP->message_length = strlen (runtimeSP->messageA); fclose (fileP); return ERROR_SAVE; } /* Scan all atoms in the current complex: */ for (atomI = 0; atomI < atomsN; atomI++) { /** Pointer to the current atom: **/ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /** If only selected atoms should be **/ /** saved, check is this atom selected: **/ if (selectionF) { if (curr_atomSP->selectedF == 0) continue; } /** Write data to output file: **/ WriteLine_ (fileP, &curr_atomSP->raw_atomS); } /* Close the output file: */ fclose (fileP); /* Return the command code: */ return COMMAND_SAVE; } /*===========================================================================*/ garlic-1.6/geomcenter.c0000644000076500007650000000274207065471277015427 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= geomcenter.c Purpose: Find geometric center position. Add it to MolComplexS structure. Input: (1) Pointer to MolComplexS structure (macromolecular complex). Output: (1) Geometric center vector stored to MolComplexS structure. (2) Return value. Return value: (1) Positive if there are some atoms. (2) Zero if there are no atoms at all. ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======find geometric center position:======================================*/ int GeometricCenter_ (MolComplexS *mol_complexSP) { size_t atomsN, i; AtomS *curr_atomSP; double x = 0.0, y = 0.0, z = 0.0, denom; atomsN = mol_complexSP->atomsN; if (atomsN <= 0) return 0; curr_atomSP = mol_complexSP->atomSP; for (i = 0; i < atomsN; i++) { x += curr_atomSP->raw_atomS.x[0]; y += curr_atomSP->raw_atomS.y; z += curr_atomSP->raw_atomS.z[0]; curr_atomSP++; } denom = 1.0 / (double) atomsN; /* This is safe: atomsN is checked above! */ mol_complexSP->geometric_center_vectorS.x = x * denom; mol_complexSP->geometric_center_vectorS.y = y * denom; mol_complexSP->geometric_center_vectorS.z = z * denom; return 1; } /*===========================================================================*/ garlic-1.6/load_sequence.c0000644000076500007650000001223007747301400016062 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2003 Damir Zucic */ /*============================================================================= load_sequence.c Purpose: Load sequence from file. Input: (1) Pointer to RuntimeS structure. Output: (1) Sequence stored to the sequence buffer. (2) Return value. Return value: (1) Positive on success. (2) Negative on failure. Notes: (1) The sequence is expected in three letters code or in FASTA format (one letter code, but the first character in title line is '>'). If not in FASTA format, one letter code may be missinterpreted as valid three letters code. File format is free, but the maximal input line should not exceed STRINGSIZE. (2) Space, comma, tab, semicolon and newline are interpreted as separators. Lines beginning with # (numbersign) are treated as comments. Empty lines are ignored. This applies to both three letters code and to FASTA format. (3) The original command string is used because the copy was converted to uppercase. ========includes:============================================================*/ #include #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ char *ExtractToken_ (char *, int, char *, char *); int ReadFasta_ (RuntimeS *, char *); FILE *OpenFileForReading_ (char *); void InitHyphob_ (RuntimeS *); /*======load sequence from file:=============================================*/ int LoadSequence_ (RuntimeS *runtimeSP) { int max_length, i; char lineA[STRINGSIZE]; char *remainderP; char tokenA[STRINGSIZE]; FILE *fileP; char *P; int n; size_t residueI = 0; int token_length; int numberF; size_t offset; /* The maximal residue name length: */ max_length = RESNAMESIZE - 1; /* Zero initialize the sequence buffer: */ runtimeSP->residuesN = 0; for (i = 0; i < (int) runtimeSP->sequence_buffer_size; i++) { *(runtimeSP->sequenceP + i) = '\0'; } /* Copy the original command string: */ strncpy (lineA, runtimeSP->curr_commandA, STRINGSIZE - 1); lineA[STRINGSIZE - 1] = '\0'; /* Skip two tokens: */ remainderP = ExtractToken_ (tokenA, STRINGSIZE, lineA, " \t\n"); if (!remainderP) return -1; remainderP = ExtractToken_ (tokenA, STRINGSIZE, remainderP, " \t\n"); if (!remainderP) return -2; /* The third token should contain the file name: */ remainderP = ExtractToken_ (tokenA, STRINGSIZE, remainderP, " \t\n"); if (!remainderP) { strcpy (runtimeSP->messageA, "File name missing!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return -3; } /* Try to interpret file as FASTA (one letter code): */ if (ReadFasta_ (runtimeSP, tokenA) > 0) return 1; /* If this point is reached, the input file was not in FASTA format. */ /* Try to open file: */ fileP = OpenFileForReading_ (tokenA); if (fileP == NULL) { strcpy (runtimeSP->messageA, "Failed to open file!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return -4; } /* Read file, line by line: */ while (fgets (lineA, STRINGSIZE, fileP)) { /* Lines beginning with # are treated as comments: */ if (lineA[0] == '#') continue; /* Convert to uppercase: */ P = lineA; while ((n = *P++) != '\0') *(P - 1) = toupper (n); /* Parse line: */ remainderP = lineA; while ((remainderP = ExtractToken_ (tokenA, STRINGSIZE, remainderP, " ,;\t\n")) != NULL) { /* Check the token length - it should */ /* not contain more than max_length characters: */ token_length = strlen (tokenA); if (token_length > max_length) { sprintf (runtimeSP->messageA, "Bad residue name: %s", tokenA); runtimeSP->message_length = strlen (runtimeSP->messageA); fclose (fileP); return -5; } /* If this token contains nothing but digits, ignore it: */ numberF = 1; for (i = 0; i < token_length; i++) { if ((isdigit (tokenA[i]) == 0) && (tokenA[i] != '-') && (tokenA[i] != '+')) { numberF = 0; break; } } if (numberF) continue; /* Check is there enough space left in the buffer: */ offset = max_length * residueI; if (offset > runtimeSP->sequence_buffer_size - 10 * max_length) { strcpy (runtimeSP->messageA, "Sequence too long!"); runtimeSP->message_length = strlen (runtimeSP->messageA); fclose (fileP); return -6; } /* Copy the residue name to the sequence buffer: */ P = runtimeSP->sequenceP + offset; strncpy (P, tokenA, max_length); /* Update the residue index: */ residueI++; } } /* Close file: */ fclose (fileP); /* Store the number of residues: */ runtimeSP->residuesN = residueI; /* Initialize serial numbers: */ for (residueI = 0; residueI < runtimeSP->residuesN; residueI++) { *(runtimeSP->serialIP + residueI) = residueI + 1; } /* Initialize disulfide flags: */ for (residueI = 0; residueI < runtimeSP->residuesN; residueI++) { *(runtimeSP->disulfideFP + residueI) = 0; } /* Initialize hydrophobicity values: */ InitHyphob_ (runtimeSP); /* Return positive value on success: */ return 2; } /*===========================================================================*/ garlic-1.6/labels.c0000644000076500007650000000713407465734470014542 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= labels.c Purpose: Execute labels command. Input: (1) Pointer to MolComplexS structure. (2) The number of macromolecular complexes. (3) Pointer to RuntimeS structure. (4) Pointer to ConfigS structure. (5) Pointer to GUIS structure. (6) Pointer to NearestAtomS structure. (7) The number of pixels in the main window free area. (8) Pointer to refreshI. (9) Pointer to the remainder of the command string. It is either empty or contains the keyword OFF. Output: (1) Label flag set for each atom in each caught macromol. complex. (2) Return value. Return value: (1) Positive (command) code on success. (2) Negative (error) code on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "commands.h" #include "typedefs.h" /*======function prototypes:=================================================*/ char *ExtractToken_ (char *, int, char *, char *); size_t MainRefresh_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); int ControlRefresh_ (MolComplexS *, ConfigS *, GUIS *); /*======execute labels command:==============================================*/ int Labels_ (MolComplexS *mol_complexSP, int mol_complexesN, RuntimeS *runtimeSP, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int *refreshIP, char *stringP) { char *remainderP; char tokenA[STRINGSIZE]; int labelF; int mol_complexI; MolComplexS *curr_mol_complexSP; size_t atomsN, atomI; AtomS *curr_atomSP; /* Initialize the labelF: */ labelF = 1; /* Extract the first token: */ remainderP = ExtractToken_ (tokenA, STRINGSIZE, stringP, " \t\n"); /* If available, the first token should contain the keyword OFF: */ if (remainderP) { if (strstr (tokenA, "OFF") == tokenA) labelF = 0; else { sprintf (runtimeSP->messageA, "Keyword %s not recognized!", tokenA); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_LABELS; } } /* Check every macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /** Pointer to the current macromolecular complex: **/ curr_mol_complexSP = mol_complexSP + mol_complexI; /** Check is the current macromolecular complex caught: **/ if (curr_mol_complexSP->catchF == 0) continue; /** Number of atoms in a macromolecular complex: **/ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /** Scan all atoms in the current complex: **/ for (atomI = 0; atomI < atomsN; atomI++) { /** Pointer to the current atom: **/ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /** Check the selection flag; set the labelF: **/ if (curr_atomSP->selectedF) curr_atomSP->labelF = labelF; } } /* Set the position_changedF flag: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /** Set flag: **/ (mol_complexSP + mol_complexI)->position_changedF = 1; } /* Refresh the main window: */ (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); /* Refresh the control window: */ ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); /* Return the command code: */ return COMMAND_LABELS; } /*===========================================================================*/ garlic-1.6/select_below.c0000644000076500007650000000715007465734760015747 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2002 Damir Zucic */ /*============================================================================= select_below.c Purpose: Select atoms below the plane. The normal vector defines what is up and what is down. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. (3) Selection mode index (0 = overwrite, 1 = restrict, 2 = expand previous selection). Output: (1) The flag selectedF set to one for selected atoms in every caught macromolecular complex. (2) Return value. Return value: (1) The number of selected atoms (zero or positive value). ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ double ScalarProduct_ (VectorS *, VectorS *); /*======select atoms below the plane:========================================*/ long SelectBelow_ (MolComplexS *mol_complexSP, int mol_complexesN, int selection_modeI) { long selected_atomsN = 0; int mol_complexI; MolComplexS *curr_mol_complexSP; size_t atomsN, atomI; VectorS normal_vectorS; double plane_center_x, plane_center_y, plane_center_z; AtomS *curr_atomSP; double x, y, z; VectorS curr_vectorS; int belowF; /* Select all atoms below the plane: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check is the current macromolecular complex caught: */ if (curr_mol_complexSP->catchF == 0) continue; /* Number of atoms in a macromolecular complex: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* The normal vector: */ normal_vectorS.x = curr_mol_complexSP->planeS.normal_x[0]; normal_vectorS.y = curr_mol_complexSP->planeS.normal_y; normal_vectorS.z = curr_mol_complexSP->planeS.normal_z[0]; /* Position of the plane center: */ plane_center_x = curr_mol_complexSP->planeS.center_x[0]; plane_center_y = curr_mol_complexSP->planeS.center_y; plane_center_z = curr_mol_complexSP->planeS.center_z[0]; /* Scan all atoms in the current complex: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Copy the coordinates: */ x = curr_atomSP->raw_atomS.x[0]; y = curr_atomSP->raw_atomS.y; z = curr_atomSP->raw_atomS.z[0]; /* Position of the atom relative to the plane center: */ curr_vectorS.x = x - plane_center_x; curr_vectorS.y = y - plane_center_y; curr_vectorS.z = z - plane_center_z; /* Reset the flag: */ belowF = 0; /* Check the sign of the scalar product: */ if (ScalarProduct_ (&curr_vectorS, &normal_vectorS) < 0) { belowF = 1; } /* Set the selection flag for the current atom: */ switch (selection_modeI) { /* Overwrite the previous selection: */ case 0: curr_atomSP->selectedF = belowF; break; /* Restrict the previous selection: */ case 1: curr_atomSP->selectedF &= belowF; break; /* Expand the previous selection: */ case 2: curr_atomSP->selectedF |= belowF; break; default: ; } /* Check the selection flag; increase */ /* the count if flag is equal to one: */ if (curr_atomSP->selectedF) selected_atomsN++; } } /* Return the number of selected atoms: */ return selected_atomsN; } /*===========================================================================*/ garlic-1.6/wmhints.c0000644000076500007650000000220107155376045014753 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= wmhints.c Purpose: Set window manager hints: icon information, the initial state of the window etc. Input: Pointer to GUIS structure. Output: (1) Some data stored to GUIS structure. Return value: No return value. Notes: (1) The function XSetWMHints is not called here (as it was done in versions 1.x and 1.0). This function is obsolete (X11R3). ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======set window manager hints:============================================*/ void SetWMHints_ (GUIS *guiSP) { guiSP->wm_hintsS.flags = InputHint | StateHint | IconWindowHint; guiSP->wm_hintsS.input = True; guiSP->wm_hintsS.initial_state = NormalState; guiSP->wm_hintsS.icon_window = guiSP->icon_winS.ID; } /*===========================================================================*/ garlic-1.6/show.c0000644000076500007650000000606207076564017014253 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= show.c Purpose: Execute show command: show the selected atoms, i.e. set hiddenF to zero for selected atoms. Only the caught complexes are treated. For atoms which are not selected visibility status is not changed. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) The number of macromolecular complexes. (3) Pointer to RuntimeS structure, with some runtime data. (4) Pointer to ConfigS structure, with configuration data. (5) Pointer to GUIS structure, with GUI data. (6) Pointer to NearestAtomS structure. (7) The number of pixels in the main window free area. (8) Pointer to refreshI. Output: (1) The hiddenF set for each atom in each caught complex. (2) Return value. Return value: (1) The command code. ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "commands.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int ShowBackbone_ (MolComplexS *, int); size_t MainRefresh_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); int ControlRefresh_ (MolComplexS *, ConfigS *, GUIS *); /*======execute show command:================================================*/ int Show_ (MolComplexS *mol_complexSP, int mol_complexesN, RuntimeS *runtimeSP, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int *refreshIP) { int mol_complexI; MolComplexS *curr_mol_complexSP; size_t atomsN, atomI; AtomS *curr_atomSP; /* Check every macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /** Pointer to the current macromolecular complex: **/ curr_mol_complexSP = mol_complexSP + mol_complexI; /** Check is the current macromolecular complex caught: **/ if (curr_mol_complexSP->catchF == 0) continue; /** Number of atoms in a macromolecular complex: **/ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /** Scan all atoms in the current complex: **/ for (atomI = 0; atomI < atomsN; atomI++) { /** Pointer to the current atom: **/ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /** Check the selection flag; show selected atoms: **/ if (curr_atomSP->selectedF) curr_atomSP->hiddenF = 0; } } /* Show backbone (update hiddenF for each selected CA atom): */ ShowBackbone_ (mol_complexSP, mol_complexesN); /* Refresh the main window: */ (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); /* Refresh the control window: */ ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); /* Return the command code: */ return COMMAND_SHOW; } /*===========================================================================*/ garlic-1.6/slab.c0000644000076500007650000000522307065475116014211 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= slab.c Purpose: For each macromolecular complex, check which atoms are inside slab. If slab mode is not recognized, do nothing. The slab flags will be left intact in this case. Each macromolecular complex may have its own slab mode. Input: (1) Pointer to MolComplexS structure. (2) Number of macromolecular complexes. Output: (1) Slab flag set for each atom in each macromolecular complex. The value zero is assigned to all atoms outside the slab and value one to all atoms inside the slab. (2) Return value. Return value: The number of atoms inside slab (zero or positive). Notes: (1) For each slab mode a separate function is prepared. ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ size_t NoSlab_ (MolComplexS *); size_t PlanarSlab_ (MolComplexS *); size_t SphereSlab_ (MolComplexS *); size_t HalfSphereSlab_ (MolComplexS *); size_t CylinSlab_ (MolComplexS *); size_t HalfCylinSlab_ (MolComplexS *); /*======cut the slab:========================================================*/ size_t Slab_ (MolComplexS *mol_complexSP, int mol_complexesN) { int mol_complexI; MolComplexS *curr_mol_complexSP; /* Check every macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /** Pointer to the current macromolecular complex: **/ curr_mol_complexSP = mol_complexSP + mol_complexI; /** Do not apply slab if position has not changed: **/ if (curr_mol_complexSP->position_changedF == 0) continue; /** Apply the proper slab: **/ switch (curr_mol_complexSP->slab_modeI) { /*** Slab not used: ***/ case 0: return NoSlab_ (curr_mol_complexSP); break; /*** Planar: ***/ case 1: return PlanarSlab_ (curr_mol_complexSP); break; /*** Spherical: ***/ case 2: return SphereSlab_ (curr_mol_complexSP); break; /*** Semi-spherical: ***/ case 3: return HalfSphereSlab_ (curr_mol_complexSP); break; /*** Cylindrical: ***/ case 4: return CylinSlab_ (curr_mol_complexSP); break; /*** Semi-cylindrical: ***/ case 5: return HalfCylinSlab_ (curr_mol_complexSP); break; /*** Unknown slab mode: ***/ default: ; } } /* If this point is reached, slab mode was not recognized: */ return 0; } /*===========================================================================*/ garlic-1.6/group.c0000644000076500007650000004511210404014272014404 0ustar zuciczucic00000000000000/* Copyright (C) 2003-2006 Damir Zucic */ /*============================================================================= group.c Purpose: Execute group command: catch a set of macromolecular complexes, releasing some others. A single rotation center will be prepared for the entire group, except if grouping was done using keyword ALL. In that case, each macromolecular center will have its own rotation center (the old one). All atoms, including the atoms which are not selected, will be taken into account. To break the group, use the command CATCH. If keyword ALL is not used, then two or more complex identifiers should be specified as command arguments. The keyword SAVE may be used to save the whole group, where each structure will be treated as a single chain. The keyword SSC may be used to save the structure as a single chain, with no chain identifier. If any structure consist of two or more chains, the original chain identifiers will be lost. The keyword ALL may be used to group all loaded structures, where each of these structures will retain its own rotation center. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. (3) Pointer to RuntimeS structure, with some runtime data. (4) Pointer to ConfigS structure, with configuration data. (5) Pointer to GUIS structure, with GUI data. (6) Pointer to NearestAtomS structure. (7) The number of pixels in the main window free area. (8) Pointer to refreshI. (9) The string which contains one or more the macromol. complex identifiers. Output: (1) The catch flag (catchF) set for each macromolecular complex. (2) The edit mode index will be reset to zero. (3) The group flag in RuntimeS structure will be set to one. (4) Return value. Return value: (1) Positive (command) code on success. (2) Negative (error) code on failure. Notes: (1) This command takes one of more arguments. To catch only one macromolecular complex, use the command catch. (2) This function resets the edit mode index. ========includes:============================================================*/ #include #include #include #include #include #include #include #include "defines.h" #include "commands.h" #include "typedefs.h" /*======function prototypes:=================================================*/ char *ExtractToken_ (char *, int, char *, char *); int WriteLine_ (FILE *, RawAtomS *); int ExtractIndex_ (char *); size_t MainRefresh_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); int ControlRefresh_ (MolComplexS *, ConfigS *, GUIS *); /*======execute group command:===============================================*/ int Group_ (MolComplexS *mol_complexSP, int mol_complexesN, RuntimeS *runtimeSP, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int *refreshIP, char *stringP) { size_t raw_atom_struct_size; int max; char *remainderP; char tokenA[SHORTSTRINGSIZE]; FILE *fileP; int chainI = 0; static char chainIDA[30] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; char chainID; int complexID; int mol_complexI; MolComplexS *curr_mol_complexSP; int curr_mol_complexID; size_t atomI; AtomS *curr_atomSP; RawAtomS *raw_atomSP; RawAtomS copy_raw_atomS; int new_atomI = 0; int residue_sequenceI, old_residue_sequenceI = 0; char insertion_code, old_insertion_code = '\0'; int new_residueI = 0; int arrayI = 0; int mol_complexIDA[MAX_GROUP_SIZE]; int structures_in_groupN; int job_doneF = 0; double center_x = 0.0, center_y = 0.0, center_z = 0.0; size_t total_atomsN = 0; double reciprocal_total_atomsN; /* The size of RawAtomS structure: */ raw_atom_struct_size = sizeof (RawAtomS); /* Check the input string, there should be something: */ max = SHORTSTRINGSIZE; if ((remainderP = ExtractToken_ (tokenA, max, stringP, " \t,;")) == NULL) { strcpy (runtimeSP->messageA, "Some additional parameters were expected!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_NO_ID; } /*---------------------------------------------------------------------------*/ /* Check for keyword SAVE: */ if (strstr (tokenA, "SAV") == tokenA) { /* If there is no group at all, there is nothing to save: */ if (runtimeSP->groupF == 0) { strcpy (runtimeSP->messageA, "The group is not defined!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_GROUP; } /* Now parse the original command line because the */ /* copy of this line was converted to uppercase. */ /* Skip the first and the second token: */ remainderP = ExtractToken_ (tokenA, STRINGSIZE, runtimeSP->curr_commandA, " \t\n"); if (!remainderP) return ERROR_GROUP; remainderP = ExtractToken_ (tokenA, STRINGSIZE, remainderP, " \t\n"); if (!remainderP) return ERROR_GROUP; /* The second token should be the name of the output file: */ remainderP = ExtractToken_ (tokenA, STRINGSIZE, remainderP, " \t\n"); if (!remainderP) { strcpy (runtimeSP->messageA, "Missing the output file name!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_NO_FILE_NAME; } /* Try to open the output file: */ if ((fileP = fopen (tokenA, "w")) == NULL) { strcpy (runtimeSP->messageA, "Failed to open output file!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_OPEN_FAILURE; } /* If this point is reached, save the entire group to the same */ /* PDB file. The output file will not contain any header. The */ /* structures forming the group will be treated as chains. */ /* Scan each macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Prepare the pointer to the current macromol. complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check the number of atoms; for bad */ /* and discarded complexes it is zero: */ if (curr_mol_complexSP->atomsN == 0) continue; /* Prepare the chain identifier: */ chainI %= 26; chainID = chainIDA[chainI]; /* Increment the chain index: */ chainI++; /* Atomic loop: */ for (atomI = 0; atomI < curr_mol_complexSP->atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Pointer to raw atomic data: */ raw_atomSP = &curr_atomSP->raw_atomS; /* Copy the raw atomic data: */ memcpy (©_raw_atomS, raw_atomSP, raw_atom_struct_size); /* Replace the chain identifier: */ copy_raw_atomS.chainID = chainID; /* Replace the atomic serial index: */ copy_raw_atomS.serialI = new_atomI + 1; /* Update the new atomic index: */ new_atomI++; /* Now take care about the residue serial number. */ /* Copy the residue data associated with this atom: */ residue_sequenceI = raw_atomSP->residue_sequenceI; insertion_code = raw_atomSP->residue_insertion_code; /* If this is the first atom from this */ /* structure, copy the residue sequence */ /* index and residue insertion code: */ if (atomI == 0) { old_residue_sequenceI = residue_sequenceI; old_insertion_code = insertion_code; } /* If this atom does not belong to the */ /* same residue as the previous atom, */ /* update the new residue serial index: */ if ((residue_sequenceI != old_residue_sequenceI) || (insertion_code != old_insertion_code)) { /* Update index: */ new_residueI++; /* Update the residue sequence */ /* index and insertion code: */ old_residue_sequenceI = residue_sequenceI; old_insertion_code = insertion_code; } /* Replace the residue index: */ copy_raw_atomS.residue_sequenceI = new_residueI + 1; /* Replace the residue insertion code: */ copy_raw_atomS.residue_insertion_code = ' '; /* Write the output line: */ WriteLine_ (fileP, ©_raw_atomS); } } /* Close the output file: */ fclose (fileP); /* Return to the caller, redrawing is not required: */ return COMMAND_GROUP; } /*---------------------------------------------------------------------------*/ /* Check for keyword SSC: */ else if (strstr (tokenA, "SSC") == tokenA) { /* If there is no group at all, there is nothing to save: */ if (runtimeSP->groupF == 0) { strcpy (runtimeSP->messageA, "The group is not defined!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_GROUP; } /* Now parse the original command line because the */ /* copy of this line was converted to uppercase. */ /* Skip the first and the second token: */ remainderP = ExtractToken_ (tokenA, STRINGSIZE, runtimeSP->curr_commandA, " \t\n"); if (!remainderP) return ERROR_GROUP; remainderP = ExtractToken_ (tokenA, STRINGSIZE, remainderP, " \t\n"); if (!remainderP) return ERROR_GROUP; /* The second token should be the name of the output file: */ remainderP = ExtractToken_ (tokenA, STRINGSIZE, remainderP, " \t\n"); if (!remainderP) { strcpy (runtimeSP->messageA, "Missing the output file name!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_NO_FILE_NAME; } /* Try to open the output file: */ if ((fileP = fopen (tokenA, "w")) == NULL) { strcpy (runtimeSP->messageA, "Failed to open output file!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_OPEN_FAILURE; } /* If this point is reached, save the entire group to the same */ /* PDB file. The output file will not contain any header. The */ /* structures forming the group will be treated as chains. */ /* Scan each macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Prepare the pointer to the current macromol. complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check the number of atoms; for bad */ /* and discarded complexes it is zero: */ if (curr_mol_complexSP->atomsN == 0) continue; /* Prepare the chain identifier (space, for all structures): */ chainID = ' '; /* Atomic loop: */ for (atomI = 0; atomI < curr_mol_complexSP->atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Pointer to raw atomic data: */ raw_atomSP = &curr_atomSP->raw_atomS; /* Copy the raw atomic data: */ memcpy (©_raw_atomS, raw_atomSP, raw_atom_struct_size); /* Replace the chain identifier: */ copy_raw_atomS.chainID = chainID; /* Replace the atomic serial index: */ copy_raw_atomS.serialI = new_atomI + 1; /* Update the new atomic index: */ new_atomI++; /* Now take care about the residue serial number. */ /* Copy the residue data associated with this atom: */ residue_sequenceI = raw_atomSP->residue_sequenceI; insertion_code = raw_atomSP->residue_insertion_code; /* If this is the first atom from this */ /* structure, copy the residue sequence */ /* index and residue insertion code: */ if (atomI == 0) { old_residue_sequenceI = residue_sequenceI; old_insertion_code = insertion_code; } /* If this atom does not belong to the */ /* same residue as the previous atom, */ /* update the new residue serial index: */ if ((residue_sequenceI != old_residue_sequenceI) || (insertion_code != old_insertion_code)) { new_residueI++; } /* Replace the residue index: */ copy_raw_atomS.residue_sequenceI = new_residueI + 1; /* Replace the residue insertion code: */ copy_raw_atomS.residue_insertion_code = ' '; /* Write the output line: */ WriteLine_ (fileP, ©_raw_atomS); } } /* Close the output file: */ fclose (fileP); /* Return to the caller, redrawing is not required: */ return COMMAND_GROUP; } /*---------------------------------------------------------------------------*/ /* Check for keyword ALL: */ else if (strstr (tokenA, "ALL") == tokenA) { /* Set the catch flag to one for each macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Prepare the pointer to the current macromol. complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check the number of atoms; for bad */ /* and discarded complexes it is zero: */ if (curr_mol_complexSP->atomsN == 0) continue; /* Set the catch flag to one: */ curr_mol_complexSP->catchF = 1; /* Mark this macromolecular complex as group member: */ curr_mol_complexSP->group_memberF = 1; } /* Each macromolecular complex retains its own rotation center! */ /* Return to the caller, redrawing is not required: */ return COMMAND_GROUP; } /*---------------------------------------------------------------------------*/ /* If this point is reached, keywords SAVE, SSC and ALL were */ /* not found. Check are there any identifiers (integers). */ /* Parse the list of macromolecular identifiers: */ max = SHORTSTRINGSIZE; remainderP = stringP; while ((remainderP = ExtractToken_ (tokenA, max, remainderP, " \t,;")) != NULL) { /* Extract the macromolecular complex identifier */ /* (an integer larger than zero is expected): */ if ((complexID = ExtractIndex_ (tokenA)) <= 0) { strcpy (runtimeSP->messageA, "Failed to extract the macromolecular complex"); strcat (runtimeSP->messageA, " identifier!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_NO_ID; } /* Store the macromolecular complex identifier: */ mol_complexIDA[arrayI] = complexID; /* Increment and check the array index: */ arrayI++; if (arrayI >= MAX_GROUP_SIZE) break; } /* Copy the number of structures in a group: */ structures_in_groupN = arrayI; /* If no identifiers were found, return: */ if (structures_in_groupN <= 0) { strcpy (runtimeSP->messageA, "Some additional parameters were expected!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_NO_ID; } /* If at least one identifier was found, reset all catch flags */ /* to zero (this will be changed later for some complexes): */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Prepare the pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* For all other complexes, set the catch flag to zero: */ curr_mol_complexSP->catchF = 0; } /* Set the catch flag for macromolecular */ /* complexes which belong to the group: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Prepare the pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check the number of atoms; for bad */ /* and discarded complexes it is zero: */ if (curr_mol_complexSP->atomsN == 0) continue; /* Copy the current macromolecular complex identifier: */ curr_mol_complexID = curr_mol_complexSP->mol_complexID; /* Scan the group: */ for (arrayI = 0; arrayI < structures_in_groupN; arrayI++) { /* If the current macromolecular complex is recognized: */ if (curr_mol_complexID == mol_complexIDA[arrayI]) { /* Set the catch flag to one: */ curr_mol_complexSP->catchF = 1; /* Mark this macromolecular complex as group member: */ curr_mol_complexSP->group_memberF = 1; /* Set the flag which says that group is */ /* formed and break from the inner loop: */ job_doneF = 1; break; } } } /* If no complex was found, return negative value: */ if (job_doneF == 0) { strcpy (runtimeSP->messageA, "All complex identifiers are bad!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_BAD_ID; } /* Calculate the position of the rotation center. This rotation */ /* center will be common for all structures which form the group. */ /* The geometric center will be calculated for all atoms and for */ /* all complexes, including the atoms which are not selected. */ /* Scan each macromolecular complex and take each atom into account: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Prepare the pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check the number of atoms; for bad */ /* and discarded complexes it is zero: */ if (curr_mol_complexSP->atomsN == 0) continue; /* Atomic loop: */ for (atomI = 0; atomI < curr_mol_complexSP->atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Add x, y and z to the totals: */ center_x += curr_atomSP->raw_atomS.x[0]; center_y += curr_atomSP->raw_atomS.y; center_z += curr_atomSP->raw_atomS.z[0]; /* Increment the total number of atoms: */ total_atomsN++; } } /* Check the total number of atoms: */ if (total_atomsN == 0) { strcpy (runtimeSP->messageA, "There are no atoms in this group!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_GROUP; } /* Calculate the coordinates of the rotation center: */ reciprocal_total_atomsN = 1.0 / (double) total_atomsN; center_x *= reciprocal_total_atomsN; center_y *= reciprocal_total_atomsN; center_z *= reciprocal_total_atomsN; /* Replace the original rotation center vector with the group's center: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Prepare the pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check is this complex a group member: */ if (curr_mol_complexSP->group_memberF == 0) continue; /* If this point is reached, the current complex is a group member. */ /* Backup the original rotation center vector: */ curr_mol_complexSP->backup_vectorS.x = curr_mol_complexSP->rotation_center_vectorS.x; curr_mol_complexSP->backup_vectorS.y = curr_mol_complexSP->rotation_center_vectorS.y; curr_mol_complexSP->backup_vectorS.z = curr_mol_complexSP->rotation_center_vectorS.z; /* Replace the original coordinates: */ curr_mol_complexSP->rotation_center_vectorS.x = center_x; curr_mol_complexSP->rotation_center_vectorS.y = center_y; curr_mol_complexSP->rotation_center_vectorS.z = center_z; } /* Set the group flag in the RuntimeS structure: */ runtimeSP->groupF = 1; /* Default editing mode (0, no editing) does not */ /* require redrawing. Other modes require it: */ if (runtimeSP->edit_modeI != 0) { /* Reset the edit mode index: */ runtimeSP->edit_modeI = 0; /* Refresh the main window: */ (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); /* Refresh the control window: */ ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); } /* Return positive value on success: */ return COMMAND_GROUP; } /*===========================================================================*/ garlic-1.6/half_cylin_fading.c0000644000076500007650000001447407066751723016722 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= half_cylin_fading.c Purpose: Prepare the left, middle and right color for each atom in a complex. The color fading is semi-cylindrical. The cylinder axis is parallel to y axis. The plane is parallel to x-y plane, passing through the fading center. Input: (1) Pointer to MolComplexS structure. (2) Pointer to GUIS structure. Output: (1) left_colorID, middle_colorID and right_colorID members of AtomS structure initialized for each atom in macromolecular complex. (2) Return value. Return value: (1) On success, the number of atoms which have colors different from near and far color. These atoms are located in the area between the front and back surface. (2) Zero on failure. Notes: (1) Do not skip hidden atoms, the color of these atoms may be used for backbone drawing! =============================================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ unsigned long PixelFromRGBS_ (RGBS *, GUIS *); unsigned long PrepareColor_ (RGBS *, RGBS *, double, GUIS *); /*======semi-cylindrical fading:=============================================*/ size_t HalfCylinFading_ (MolComplexS *curr_mol_complexSP, GUIS *guiSP) { size_t atoms_between_surfacesN = 0; size_t atomsN, atomI; AtomS *curr_atomSP; int surfacesN, surfaceI, inner_surfaceI, outer_surfaceI; double rho_out, rho_out_squared, rho_in, rho_in_squared; double x0, z0; double overall_range, internal_range; double inverse_internal_range; double x, z, rho_squared, rho, delta_rho, scale_factor; int near_surfaceI, far_surfaceI; /* The radius of the front (outer) surface: */ rho_out = curr_mol_complexSP->fading_front_relative_position; rho_out_squared = rho_out * rho_out; /* The radius of the back (inner) surface: */ rho_in = curr_mol_complexSP->fading_back_relative_position; rho_in_squared = rho_in * rho_in; /* Check: */ if (rho_in >= rho_out) return 0; /* The overall range: */ overall_range = rho_out - rho_in; /* Fading center coordinates: */ x0 = curr_mol_complexSP->fading_center_vectorS.x; z0 = curr_mol_complexSP->fading_center_vectorS.z; /* The number of atoms in a complex: */ atomsN = curr_mol_complexSP->atomsN; /* Assign three colors to each atom: */ for (atomI = 0; atomI < atomsN; atomI++) { /** Pointer to the current atom: **/ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /** Is atom out of slab? **/ if (!curr_atomSP->inside_slabF) continue; /** Check the number of color fading surfaces: **/ surfacesN = curr_atomSP->surfacesN; /*** If there is only one, there is no fading: ***/ if (surfacesN == 1) { curr_atomSP->left_colorID = PixelFromRGBS_ (curr_atomSP->left_rgbSA, guiSP); curr_atomSP->middle_colorID = PixelFromRGBS_ (curr_atomSP->middle_rgbSA, guiSP); curr_atomSP->right_colorID = PixelFromRGBS_ (curr_atomSP->right_rgbSA, guiSP); continue; } /** Atomic coordinates (relative to the fading center): **/ x = curr_atomSP->raw_atomS.x[0] - x0; z = curr_atomSP->raw_atomS.z[0] - z0; /** Check is atom behind the plane; if it is, treat it as far atom: **/ if (z > 0.0) { surfaceI = surfacesN - 1; curr_atomSP->left_colorID = PixelFromRGBS_ (curr_atomSP->left_rgbSA + surfaceI, guiSP); curr_atomSP->middle_colorID = PixelFromRGBS_ (curr_atomSP->middle_rgbSA + surfaceI, guiSP); curr_atomSP->right_colorID = PixelFromRGBS_ (curr_atomSP->right_rgbSA + surfaceI, guiSP); continue; } /** Distance between the current atom and the fading axis: **/ rho_squared = x * x + z * z; /** Atoms which are too far from the fading **/ /** axis should be treated as near atoms: **/ if (rho_squared >= rho_out_squared) { curr_atomSP->left_colorID = PixelFromRGBS_ (curr_atomSP->left_rgbSA, guiSP); curr_atomSP->middle_colorID = PixelFromRGBS_ (curr_atomSP->middle_rgbSA, guiSP); curr_atomSP->right_colorID = PixelFromRGBS_ (curr_atomSP->right_rgbSA, guiSP); continue; } /** Atoms which are to close to the fading **/ /** axis should be treated as far atoms: **/ if (rho_squared <= rho_in_squared) { surfaceI = surfacesN - 1; curr_atomSP->left_colorID = PixelFromRGBS_ (curr_atomSP->left_rgbSA + surfaceI, guiSP); curr_atomSP->middle_colorID = PixelFromRGBS_ (curr_atomSP->middle_rgbSA + surfaceI, guiSP); curr_atomSP->right_colorID = PixelFromRGBS_ (curr_atomSP->right_rgbSA + surfaceI, guiSP); continue; } /** If this point is reached, current atom is in **/ /** the area between two surfaces; colors should **/ /** be calculated weighting near and far colors: **/ /** Prepare auxiliary variables: **/ if (surfacesN > 1) { rho = sqrt (rho_squared); internal_range = overall_range / (double) (surfacesN - 1); inverse_internal_range = 1.0 / internal_range; inner_surfaceI = (int) floor ((rho - rho_in) * inverse_internal_range); outer_surfaceI = inner_surfaceI + 1; delta_rho = outer_surfaceI * internal_range + rho_in - rho; scale_factor = delta_rho * inverse_internal_range; far_surfaceI = surfacesN - inner_surfaceI - 1; near_surfaceI = far_surfaceI - 1; } else { scale_factor = 0.0; far_surfaceI = 0; near_surfaceI = 0; } /** Left color: **/ curr_atomSP->left_colorID = PrepareColor_ (curr_atomSP->left_rgbSA + near_surfaceI, curr_atomSP->left_rgbSA + far_surfaceI, scale_factor, guiSP); /** Middle color: **/ curr_atomSP->middle_colorID = PrepareColor_ (curr_atomSP->middle_rgbSA + near_surfaceI, curr_atomSP->middle_rgbSA + far_surfaceI, scale_factor, guiSP); /** Right color: **/ curr_atomSP->right_colorID = PrepareColor_ (curr_atomSP->right_rgbSA + near_surfaceI, curr_atomSP->right_rgbSA + far_surfaceI, scale_factor, guiSP); /** Update the number of atoms in the area between two surfaces: **/ atoms_between_surfacesN++; } /* Return the number of atoms which have */ /* colors different from near and far colors: */ return atoms_between_surfacesN; } /*===========================================================================*/ garlic-1.6/build_chain.c0000644000076500007650000003041107633055560015524 0ustar zuciczucic00000000000000/* Copyright (C) 2001-2003 Damir Zucic */ /*============================================================================= build_chain.c Purpose: Build the extended polypeptide chain. Moving of a single residue consists of three steps: (1) Translate the chain to bring N atom to the correct position. (2) Rotate the new residue to bring CA atom to correct position. (3) Rotate the residue about N-CA bond, to fix C atom position. Input: (1) Pointer to MolComplexS structure, with macromolecular data. Output: (1) The extended chain formed. (2) Return value. Return value: (1) Positive on success. (2) Negative on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int ExtractNCAC_ (VectorS *, VectorS *, VectorS *, AtomS *, size_t, size_t); double AbsoluteValue_ (VectorS *); void VectorProduct_ (VectorS *, VectorS *, VectorS *); void TranslateRange_ (AtomS *, size_t, size_t, double, double, double); double ScalarProduct_ (VectorS *, VectorS *); void RotateRange_ (AtomS *, size_t, size_t, VectorS *, VectorS *, double); int ParallelPart_ (VectorS *, VectorS *, VectorS *); /*======move residues to build extended chain:===============================*/ int BuildChain_ (MolComplexS *mol_complexSP) { size_t vector_struct_size; double angle; double cn1, cn2, nca1, nca2, cac1, cac2; int residuesN; int residueI; ResidueS *curr_residueSP; size_t atom_startI, atom_endI; int n; static VectorS N_old_vectorS, CA_old_vectorS, C_old_vectorS; static VectorS N_vectorS, CA_vectorS, C_vectorS; VectorS vector1S, vector2S; double abs_value, reciprocal_abs_value; VectorS unit_vector1S, unit_vector2S, unit_vector3S; double x, y, z; double delta_x, delta_y, delta_z; double denominator, ratio; VectorS axis_vectorS; VectorS parallel_vectorS, perpendicular_vectorS; /* The size of VectorS structure: */ vector_struct_size = sizeof (VectorS); /* Prepare the auxilliary parameters: */ angle = DEG_TO_RAD * (180.0 - CACN_ANGLE); cn1 = CN_BOND_LENGTH * cos (angle); cn2 = CN_BOND_LENGTH * sin (angle); angle = DEG_TO_RAD * (180.0 - CNCA_ANGLE); nca1 = NCA_BOND_LENGTH * cos (angle); nca2 = NCA_BOND_LENGTH * sin (angle); angle = DEG_TO_RAD * (180.0 - NCAC_ANGLE); cac1 = CAC_BOND_LENGTH * cos (angle); cac2 = CAC_BOND_LENGTH * sin (angle); /* Prepare the number of residues: */ residuesN = mol_complexSP->residuesN; /* If there is only one residue (or less), return: */ if (residuesN <= 1) return 1; /* Prepare N, CA and C coordinates for the first residue: */ atom_startI = mol_complexSP->residueSP->residue_startI; atom_endI = mol_complexSP->residueSP->residue_endI; n = ExtractNCAC_ (&N_old_vectorS, &CA_old_vectorS, &C_old_vectorS, mol_complexSP->atomSP, atom_startI, atom_endI); /* All three atomic positions are required to properly initiate the chain: */ if (n < 3) return -1; /* Scan residues, skipping the first one: */ for (residueI = 1; residueI < residuesN; residueI++) { /* Pointer to the current residue: */ curr_residueSP = mol_complexSP->residueSP + residueI; /* Prepare the atomic index range: */ atom_startI = curr_residueSP->residue_startI; atom_endI = curr_residueSP->residue_endI; /*------translation:-------------------------------------------------*/ /* Extract N, CA and C coordinates: */ n = ExtractNCAC_ (&N_vectorS, &CA_vectorS, &C_vectorS, mol_complexSP->atomSP, atom_startI, atom_endI); /* Three atoms are required to properly place the current residue: */ if (n < 3) continue; /* Prepare the vector parallel to CA-C bond of the previous residue: */ vector1S.x = C_old_vectorS.x - CA_old_vectorS.x; vector1S.y = C_old_vectorS.y - CA_old_vectorS.y; vector1S.z = C_old_vectorS.z - CA_old_vectorS.z; /* Prepare the first unit vector, required to place the N atom: */ abs_value = AbsoluteValue_ (&vector1S); if (abs_value == 0.0) continue; reciprocal_abs_value = 1.0 / abs_value; unit_vector1S.x = reciprocal_abs_value * vector1S.x; unit_vector1S.y = reciprocal_abs_value * vector1S.y; unit_vector1S.z = reciprocal_abs_value * vector1S.z; /* Prepare the vector parallel to CA-N bond of the previous residue: */ vector1S.x = N_old_vectorS.x - CA_old_vectorS.x; vector1S.y = N_old_vectorS.y - CA_old_vectorS.y; vector1S.z = N_old_vectorS.z - CA_old_vectorS.z; /* Prepare the vector perpendicular to the first unit */ /* vector and to the CA-N bond of the previous residue: */ VectorProduct_ (&vector2S, &unit_vector1S, &vector1S); /* Prepare the vector in the N-CA-C plane of the previous residue: */ VectorProduct_ (&vector1S, &unit_vector1S, &vector2S); /* Prepare the second unit vector, required to set N atom: */ abs_value = AbsoluteValue_ (&vector1S); if (abs_value == 0.0) continue; reciprocal_abs_value = 1.0 / abs_value; unit_vector2S.x = reciprocal_abs_value * vector1S.x; unit_vector2S.y = reciprocal_abs_value * vector1S.y; unit_vector2S.z = reciprocal_abs_value * vector1S.z; /* Prepare the position where N atom should be moved: */ x = cn1 * unit_vector1S.x + cn2 * unit_vector2S.x + C_old_vectorS.x; y = cn1 * unit_vector1S.y + cn2 * unit_vector2S.y + C_old_vectorS.y; z = cn1 * unit_vector1S.z + cn2 * unit_vector2S.z + C_old_vectorS.z; /* Prepare the shift for the entire residue: */ delta_x = x - N_vectorS.x; delta_y = y - N_vectorS.y; delta_z = z - N_vectorS.z; /* Translate all atoms which belong to the current residue: */ TranslateRange_ (mol_complexSP->atomSP, atom_startI, atom_endI, delta_x, delta_y, delta_z); /*------the first rotation:------------------------------------------*/ /* Extract new N, CA and C coordinates: */ n = ExtractNCAC_ (&N_vectorS, &CA_vectorS, &C_vectorS, mol_complexSP->atomSP, atom_startI, atom_endI); /* Three atoms are required to properly rotate the current residue: */ if (n < 3) continue; /* Prepare the vector parallel to C-N bond (the C atom */ /* which belongs to the previous residue should be used): */ vector1S.x = N_vectorS.x - C_old_vectorS.x; vector1S.y = N_vectorS.y - C_old_vectorS.y; vector1S.z = N_vectorS.z - C_old_vectorS.z; /* Prepare the first unit vector, required to place the CA atom: */ abs_value = AbsoluteValue_ (&vector1S); if (abs_value == 0.0) continue; reciprocal_abs_value = 1.0 / abs_value; unit_vector1S.x = reciprocal_abs_value * vector1S.x; unit_vector1S.y = reciprocal_abs_value * vector1S.y; unit_vector1S.z = reciprocal_abs_value * vector1S.z; /* Prepare the vector parallel to C-CA bond of the previous residue: */ vector1S.x = CA_old_vectorS.x - C_old_vectorS.x; vector1S.y = CA_old_vectorS.y - C_old_vectorS.y; vector1S.z = CA_old_vectorS.z - C_old_vectorS.z; /* Prepare the vector perpendicular to the first unit */ /* vector and to the C-CA bond of the previous residue: */ VectorProduct_ (&vector2S, &unit_vector1S, &vector1S); /* Prepare the vector in the peptide unit plane: */ VectorProduct_ (&vector1S, &unit_vector1S, &vector2S); /* Prepare the second unit vector, */ /* required to calculate CA position: */ abs_value = AbsoluteValue_ (&vector1S); if (abs_value == 0.0) continue; reciprocal_abs_value = 1.0 / abs_value; unit_vector2S.x = reciprocal_abs_value * vector1S.x; unit_vector2S.y = reciprocal_abs_value * vector1S.y; unit_vector2S.z = reciprocal_abs_value * vector1S.z; /* Prepare the position where CA atom should be moved: */ x = nca1 * unit_vector1S.x + nca2 * unit_vector2S.x + N_vectorS.x; y = nca1 * unit_vector1S.y + nca2 * unit_vector2S.y + N_vectorS.y; z = nca1 * unit_vector1S.z + nca2 * unit_vector2S.z + N_vectorS.z; /* The vector parallel to the current (bad) N-CA bond: */ vector1S.x = CA_vectorS.x - N_vectorS.x; vector1S.y = CA_vectorS.y - N_vectorS.y; vector1S.z = CA_vectorS.z - N_vectorS.z; /* The vector parallel to the future (correct) N-CA bond: */ vector2S.x = x - N_vectorS.x; vector2S.y = y - N_vectorS.y; vector2S.z = z - N_vectorS.z; /* The vector which defines the rotation axis: */ VectorProduct_ (&axis_vectorS, &vector1S, &vector2S); /* Calculate the rotation angle, but remember that arc */ /* cosine is very sensitive to floating point errors: */ denominator = AbsoluteValue_ (&vector1S) * AbsoluteValue_ (&vector2S); if (denominator == 0.0) continue; ratio = ScalarProduct_ (&vector1S, &vector2S) / denominator; if (ratio <= -1.0) angle = 3.1415927; else if (ratio >= 1.0) angle = 0.0; else angle = acos (ratio); /* Rotate all atoms which belong to the current residue: */ RotateRange_ (mol_complexSP->atomSP, atom_startI, atom_endI, &N_vectorS, &axis_vectorS, angle); /*------the second rotation:-----------------------------------------*/ /* Extract new N, CA and C coordinates: */ n = ExtractNCAC_ (&N_vectorS, &CA_vectorS, &C_vectorS, mol_complexSP->atomSP, atom_startI, atom_endI); /* Three atoms are required to properly rotate the current residue: */ if (n < 3) continue; /* Prepare the rotation axis vector (parallel to N-CA bond): */ axis_vectorS.x = CA_vectorS.x - N_vectorS.x; axis_vectorS.y = CA_vectorS.y - N_vectorS.y; axis_vectorS.z = CA_vectorS.z - N_vectorS.z; /* Prepare the first unit vector, required to place the C atom: */ abs_value = AbsoluteValue_ (&axis_vectorS); if (abs_value == 0.0) continue; reciprocal_abs_value = 1.0 / abs_value; unit_vector1S.x = reciprocal_abs_value * axis_vectorS.x; unit_vector1S.y = reciprocal_abs_value * axis_vectorS.y; unit_vector1S.z = reciprocal_abs_value * axis_vectorS.z; /* Prepare the vector parallel to N-C bond (the C atom */ /* which belongs to the previous residue should be used): */ vector1S.x = C_old_vectorS.x - N_vectorS.x; vector1S.y = C_old_vectorS.y - N_vectorS.y; vector1S.z = C_old_vectorS.z - N_vectorS.z; /* Prepare the vector perpendicular to the */ /* first unit vector and to the N-C bond: */ VectorProduct_ (&vector2S, &unit_vector1S, &vector1S); /* Prepare the vector in the peptide unit plane: */ VectorProduct_ (&vector1S, &unit_vector1S, &vector2S); /* Prepare the second unit vector, */ /* required to calculate C position: */ abs_value = AbsoluteValue_ (&vector1S); if (abs_value == 0.0) continue; reciprocal_abs_value = 1.0 / abs_value; unit_vector2S.x = reciprocal_abs_value * vector1S.x; unit_vector2S.y = reciprocal_abs_value * vector1S.y; unit_vector2S.z = reciprocal_abs_value * vector1S.z; /* Prepare the third unit vector, required to */ /* calculate the sign of the rotation angle: */ VectorProduct_ (&unit_vector3S, &unit_vector1S, &unit_vector2S); /* The current (bad) CA-C vector: */ vector1S.x = C_vectorS.x - CA_vectorS.x; vector1S.y = C_vectorS.y - CA_vectorS.y; vector1S.z = C_vectorS.z - CA_vectorS.z; /* The parallel part of CA-C vector: */ n = ParallelPart_ (¶llel_vectorS, &axis_vectorS, &vector1S); if (n < 0) continue; /* The perpendicular part of CA-C vector: */ perpendicular_vectorS.x = vector1S.x - parallel_vectorS.x; perpendicular_vectorS.y = vector1S.y - parallel_vectorS.y; perpendicular_vectorS.z = vector1S.z - parallel_vectorS.z; /* Calculate the rotation angle, but remember that arc */ /* cosine is very sensitive to floating point errors: */ denominator = AbsoluteValue_ (&perpendicular_vectorS); if (denominator == 0.0) continue; ratio = ScalarProduct_ (&perpendicular_vectorS, &unit_vector2S) / denominator; if (ratio < -1.0) angle = 3.1415927; else if (ratio > 1.0) angle = 0.0; else angle = acos (ratio); if (ScalarProduct_ (&perpendicular_vectorS, &unit_vector3S) > 0.0) { angle *= -1; } /* Rotate all atoms which belong to the current residue: */ RotateRange_ (mol_complexSP->atomSP, atom_startI, atom_endI, &CA_vectorS, &axis_vectorS, angle); /*------copy N, CA and C coordinates:--------------------------------*/ /* Copy the N, CA and C coordinates for later use. If it */ /* worked eighty lines above, it should work again here. */ /* Therefore, I believe it is not necessary to check n. */ n = ExtractNCAC_ (&N_old_vectorS, &CA_old_vectorS, &C_old_vectorS, mol_complexSP->atomSP, atom_startI, atom_endI); } /* Return positive value on success: */ return 2; } /*===========================================================================*/ garlic-1.6/draw_membranes.c0000644000076500007650000003342207407646765016272 0ustar zuciczucic00000000000000/* Copyright (C) 2001 Damir Zucic */ /*============================================================================= draw_membranes.c Purpose: For each macromolecular complex, draw the membrane, if visible. Input: (1) Pointer to MolComplexS structure. (2) Number of macromolecular complexes. (3) Pointer to ConfigS structure, with configuration data. (4) Pointer to GUIS structure. (5) Pointer to NearestAtomS structure, with information about the atom occupying the given pixel. (6) The number of pixels in the main window free area. (7) The refreshI, used to check the NearestAtomS associated with a given pixel. Output: (1) Membrane drawn for each macromolecular complex, if visible. (2) Return value. Return value: (1) Positive always (trivial). Notes: (1) Indentation is exceptionally 4 spaces. (2) First draw the first plane, then the second plane. =============================================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ void PlaneExtent_ (int *, int *, int *, int *, PlaneS *, ConfigS *, int); unsigned long WeightColors_ (unsigned long, unsigned long, double, GUIS *); /*======draw membranes:======================================================*/ int DrawMembranes_ (MolComplexS *mol_complexSP, int mol_complexesN, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int refreshI) { int imagesN, imageI; int mol_complexI; MolComplexS *curr_mol_complexSP; size_t atomsN; PlaneS *plane1SP, *plane2SP; int center_screen_x, center_screen_y; double angle, sin_angle, cos_angle; double reciprocal_a, reciprocal_b; double reciprocal_diameter; double coeff; int screen_x_min, screen_x_max, screen_y_min, screen_y_max; int screen_x, screen_y; double x_relative, y_relative, x_rotated, y_rotated; double ratio_x, ratio_y, d; double plane_delta_z, plane_z; size_t pixelI; NearestAtomS *curr_pixelSP; double scale_factor; unsigned long plane_colorID, old_colorID, colorID; /* Number of images: */ if (configSP->stereoF) imagesN = 2; else imagesN = 1; /* Draw the membrane (two planes), if it is defined */ /* and visible, for each macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check is the membrane defined: */ if (curr_mol_complexSP->membraneS.definedF == 0) continue; /* Check is the membrane visible: */ if (curr_mol_complexSP->membraneS.hiddenF) continue; /* Prepare and check the number of atoms: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Pointers to planes: */ plane1SP = &curr_mol_complexSP->membraneS.plane1S; plane2SP = &curr_mol_complexSP->membraneS.plane2S; /*------draw the first plane:--------------------------------------------*/ /* Draw one image (mono) or two images (stereo): */ for (imageI = 0; imageI < imagesN; imageI++) { /* Plane center position: */ center_screen_x = plane1SP->center_screen_x[imageI]; center_screen_y = plane1SP->center_screen_y; /* The shifted phi angle, used to rotate */ /* the rectangle bounding the ellipsa : */ angle = plane1SP->normal_phi[imageI] - 4.712389; /* Sine and cosine of this angle: */ sin_angle = sin (angle); cos_angle = cos (angle); /* Reciprocal values of half axes: */ if (plane1SP->screen_a == 0.0) reciprocal_a = 0.0; else reciprocal_a = 1.0 / plane1SP->screen_a; if (plane1SP->screen_b[imageI] == 0.0) reciprocal_b = 0.0; else reciprocal_b = 1.0 / plane1SP->screen_b[imageI]; /* Reciprocal diameter (required for color fading effect): */ if (plane1SP->circle_radius == 0.0) reciprocal_diameter = 0.0; else reciprocal_diameter = 0.5 / plane1SP->circle_radius; /* The coefficient used to calculate z value for a given pixel: */ if (plane1SP->screen_b[imageI] == 0.0) coeff = 0.0; else { coeff = plane1SP->circle_radius * sin (plane1SP->normal_theta[imageI]) / plane1SP->screen_b[imageI]; if (plane1SP->normal_theta[imageI] >= 1.5707963) coeff *= -1; } /* Find the plane extent: */ PlaneExtent_ (&screen_x_min, &screen_x_max, &screen_y_min, &screen_y_max, plane1SP, configSP, imageI); /* Scan the rectangle bounding ellipse: */ for (screen_x = screen_x_min; screen_x <= screen_x_max; screen_x++) { for (screen_y = screen_y_min; screen_y <= screen_y_max; screen_y++) { /* Pixel position relative to the plane center position: */ x_relative = screen_x - center_screen_x; y_relative = screen_y - center_screen_y; /* Rotated pixel position (rotation is anticlockwise here): */ x_rotated = x_relative * cos_angle + y_relative * sin_angle; y_rotated = -x_relative * sin_angle + y_relative * cos_angle; /* Check is it inside bounding ellipse: */ ratio_x = x_rotated * reciprocal_a; ratio_y = y_rotated * reciprocal_b; d = ratio_x * ratio_x + ratio_y * ratio_y; if (d > 1.0) continue; /* Calculate the z value for this pixel: */ plane_delta_z = coeff * y_rotated; plane_z = plane1SP->center_z[imageI] + plane_delta_z; /* The current pixel index: */ pixelI = guiSP->main_win_free_area_width * screen_y + screen_x; /* Check pixel index: */ if (pixelI >= pixelsN) continue; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = nearest_atomSP + pixelI; /* If something was drawn to the current */ /* pixel in this step, compare z values: */ if (curr_pixelSP->last_refreshI == refreshI) { /* If the point drawn before is closer to the */ /* observer than plane, do not draw anything: */ if (curr_pixelSP->z < plane_z) { continue; } /* If the plane is closer than the */ /* point drawn before, mix colors: */ else { /* The plane color: */ scale_factor = (plane_delta_z + plane1SP->circle_radius) * reciprocal_diameter; if (scale_factor < 0.0) scale_factor = 0.0; if (scale_factor > 1.0) scale_factor = 1.0; if (plane1SP->visible_sideI[imageI] == 0) { plane_colorID = WeightColors_ ( plane1SP->top_near_colorID, plane1SP->top_far_colorID, scale_factor, guiSP); } else { plane_colorID = WeightColors_ ( plane1SP->bottom_near_colorID, plane1SP->bottom_far_colorID, scale_factor, guiSP); } /* The color of the object which was */ /* drawn before the current plane: */ old_colorID = curr_pixelSP->colorID; /* The weighting factor which should be used */ /* to mix the plane color and the old color: */ scale_factor = plane1SP->transparency; /* Mix the plane color and the old color: */ colorID = WeightColors_ (plane_colorID, old_colorID, scale_factor, guiSP); } } /* If nothing was drawn to the current pixel */ /* in this drawing step, prepare the color: */ else { /* Prepare the scale factor used to weight (mix) colors: */ scale_factor = (plane_delta_z + plane1SP->circle_radius) * reciprocal_diameter; if (scale_factor < 0.0) scale_factor = 0.0; if (scale_factor > 1.0) scale_factor = 1.0; /* Prepare the color by weighting */ /* (mixing) near and far color: */ if (plane1SP->visible_sideI[imageI] == 0) { colorID = WeightColors_ ( plane1SP->top_near_colorID, plane1SP->top_far_colorID, scale_factor, guiSP); } else { colorID = WeightColors_ ( plane1SP->bottom_near_colorID, plane1SP->bottom_far_colorID, scale_factor, guiSP); } /* Set the style index associated with the current pixel */ /* to signal that only plane was drawn to this pixel: */ curr_pixelSP->styleI = PLANE_STYLE; } /* Draw point: */ XSetForeground (guiSP->displaySP, guiSP->theGCA[0], colorID); XDrawPoint (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x, screen_y); /* Update refresh index, z value and */ /* color value for the current pixel: */ curr_pixelSP->last_refreshI = refreshI; curr_pixelSP->z = plane_z; curr_pixelSP->colorID = colorID; } } } /*------draw the second plane:-------------------------------------------*/ /* Draw one image (mono) or two images (stereo): */ for (imageI = 0; imageI < imagesN; imageI++) { /* Plane center position: */ center_screen_x = plane2SP->center_screen_x[imageI]; center_screen_y = plane2SP->center_screen_y; /* The shifted phi angle, used to rotate */ /* the rectangle bounding the ellipsa : */ angle = plane2SP->normal_phi[imageI] - 4.712389; /* Sine and cosine of this angle: */ sin_angle = sin (angle); cos_angle = cos (angle); /* Reciprocal values of half axes: */ if (plane2SP->screen_a == 0.0) reciprocal_a = 0.0; else reciprocal_a = 1.0 / plane2SP->screen_a; if (plane2SP->screen_b[imageI] == 0.0) reciprocal_b = 0.0; else reciprocal_b = 1.0 / plane2SP->screen_b[imageI]; /* Reciprocal diameter (required for color fading effect): */ if (plane2SP->circle_radius == 0.0) reciprocal_diameter = 0.0; else reciprocal_diameter = 0.5 / plane2SP->circle_radius; /* The coefficient used to calculate z value for a given pixel: */ if (plane2SP->screen_b[imageI] == 0.0) coeff = 0.0; else { coeff = plane2SP->circle_radius * sin (plane2SP->normal_theta[imageI]) / plane2SP->screen_b[imageI]; if (plane2SP->normal_theta[imageI] >= 1.5707963) coeff *= -1; } /* Find the plane extent: */ PlaneExtent_ (&screen_x_min, &screen_x_max, &screen_y_min, &screen_y_max, plane2SP, configSP, imageI); /* Scan the rectangle bounding ellipse: */ for (screen_x = screen_x_min; screen_x <= screen_x_max; screen_x++) { for (screen_y = screen_y_min; screen_y <= screen_y_max; screen_y++) { /* Pixel position relative to the plane center position: */ x_relative = screen_x - center_screen_x; y_relative = screen_y - center_screen_y; /* Rotated pixel position (rotation is anticlockwise here): */ x_rotated = x_relative * cos_angle + y_relative * sin_angle; y_rotated = -x_relative * sin_angle + y_relative * cos_angle; /* Check is it inside bounding ellipse: */ ratio_x = x_rotated * reciprocal_a; ratio_y = y_rotated * reciprocal_b; d = ratio_x * ratio_x + ratio_y * ratio_y; if (d > 1.0) continue; /* Calculate the z value for this pixel: */ plane_delta_z = coeff * y_rotated; plane_z = plane2SP->center_z[imageI] + plane_delta_z; /* The current pixel index: */ pixelI = guiSP->main_win_free_area_width * screen_y + screen_x; /* Check pixel index: */ if (pixelI >= pixelsN) continue; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = nearest_atomSP + pixelI; /* If something was drawn to the current */ /* pixel in this step, compare z values: */ if (curr_pixelSP->last_refreshI == refreshI) { /* If the point drawn before is closer to the */ /* observer than plane, do not draw anything: */ if (curr_pixelSP->z < plane_z) { continue; } /* If the plane is closer than the */ /* point drawn before, mix colors: */ else { /* The plane color: */ scale_factor = (plane_delta_z + plane2SP->circle_radius) * reciprocal_diameter; if (scale_factor < 0.0) scale_factor = 0.0; if (scale_factor > 1.0) scale_factor = 1.0; if (plane2SP->visible_sideI[imageI] == 0) { plane_colorID = WeightColors_ ( plane2SP->top_near_colorID, plane2SP->top_far_colorID, scale_factor, guiSP); } else { plane_colorID = WeightColors_ ( plane2SP->bottom_near_colorID, plane2SP->bottom_far_colorID, scale_factor, guiSP); } /* The color of the object which was */ /* drawn before the current plane: */ old_colorID = curr_pixelSP->colorID; /* The weighting factor which should be used */ /* to mix the plane color and the old color: */ scale_factor = plane2SP->transparency; /* Mix the plane color and the old color: */ colorID = WeightColors_ (plane_colorID, old_colorID, scale_factor, guiSP); } } /* If nothing was drawn to the current pixel */ /* in this drawing step, prepare the color: */ else { /* Prepare the scale factor used to weight (mix) colors: */ scale_factor = (plane_delta_z + plane2SP->circle_radius) * reciprocal_diameter; if (scale_factor < 0.0) scale_factor = 0.0; if (scale_factor > 1.0) scale_factor = 1.0; /* Prepare the color by weighting */ /* (mixing) near and far color: */ if (plane2SP->visible_sideI[imageI] == 0) { colorID = WeightColors_ ( plane2SP->top_near_colorID, plane2SP->top_far_colorID, scale_factor, guiSP); } else { colorID = WeightColors_ ( plane2SP->bottom_near_colorID, plane2SP->bottom_far_colorID, scale_factor, guiSP); } /* Set the style index associated with the current pixel */ /* to signal that only plane was drawn to this pixel: */ curr_pixelSP->styleI = PLANE_STYLE; } /* Draw point: */ XSetForeground (guiSP->displaySP, guiSP->theGCA[0], colorID); XDrawPoint (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x, screen_y); /* Update refresh index, z value and */ /* color value for the current pixel: */ curr_pixelSP->last_refreshI = refreshI; curr_pixelSP->z = plane_z; curr_pixelSP->colorID = colorID; } } } } /* Return positive value (trivial): */ return 1; } /*===========================================================================*/ garlic-1.6/draw_ramachandran.c0000644000076500007650000004205607311424326016720 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= draw_ramachandran.c Purpose: Draw Ramachandran plot. This function is used if the main window drawing mode is equal to one. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. (3) Pointer to RuntimeS structure, with some runtime data. (4) Pointer to ConfigS structure, with configuration data. (5) Pointer to GUIS structure, with GUI data. (6) Pointer to NearestAtomS structure, with information about the atom occupying the given pixel. (7) The number of pixels in the main window free area. (8) The refreshI, used to check the NearestAtomS associated with a given pixel. It is currently unused in this function. Output: (1) Ramachadran plot drawn to the main window. (2) Return value. Return value: (1) The number of residues used to prepare Ramachandran plot. Notes: (1) Indentation is exceptionally 4 spaces. (2) The initial drawing destination is the hidden pixmap, and the content of this pixmap is copied later to the main window. (3) The second index of indexAA is treated as row index. This is somewhat unusual, but more practical in this function. ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int RefreshPixmap_ (Display *, Pixmap, GC, unsigned int, unsigned int, unsigned long); void RamaFrame_ (GUIS *); int ParseColor_ (RGBS *, unsigned long *, GUIS *, char *, char *); int DrawTitles_ (RuntimeS *, GUIS *); /*======draw Ramachandran plot:==============================================*/ size_t DrawRamachandran_ (MolComplexS *mol_complexSP, int mol_complexesN, RuntimeS *runtimeSP, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int refreshI) { size_t residues_drawnN = 0; int free_width, free_height; int frame_screen_x0, frame_screen_y0; int frame_screen_x1, frame_screen_y1; int frame_screen_width, frame_screen_height; double scale_x, scale_y; RGBS rgbS; unsigned long symbol_color1ID, symbol_color2ID, symbol_color3ID; int mol_complexI; MolComplexS *curr_mol_complexSP; size_t residuesN, residueI; ResidueS *curr_residueSP; AtomS *first_atomSP; double delta_x, delta_y, phi, psi; int screen_phi, screen_psi; int i, j, screen_x, screen_y; static int circle_maskAA[9][9] = {{0, 0, 0, 1, 1, 1, 0, 0, 0}, {0, 1, 1, 1, 1, 1, 1, 1, 0}, {0, 1, 1, 1, 1, 1, 1, 1, 0}, {1, 1, 1, 1, 1, 1, 1, 1, 1}, /* Be sure to */ {1, 1, 1, 1, 1, 1, 1, 1, 1}, /* read Note 3! */ {1, 1, 1, 1, 1, 1, 1, 1, 1}, {0, 1, 1, 1, 1, 1, 1, 1, 0}, {0, 1, 1, 1, 1, 1, 1, 1, 0}, {0, 0, 0, 1, 1, 1, 0, 0, 0}}; size_t pixelI; NearestAtomS *curr_pixelSP; static int indexAA[9][9] = {{0, 0, 0, 2, 2, 2, 0, 0, 0}, {0, 2, 0, 0, 1, 1, 2, 2, 0}, {0, 0, 0, 0, 0, 1, 1, 2, 0}, {2, 0, 0, 0, 0, 1, 1, 2, 2}, /* Be sure to */ {2, 1, 0, 0, 1, 1, 1, 2, 2}, /* read Note 3! */ {2, 1, 1, 1, 1, 1, 1, 2, 2}, {0, 2, 1, 1, 1, 1, 2, 2, 0}, {0, 2, 2, 2, 2, 2, 2, 2, 0}, {0, 0, 0, 2, 2, 2, 0, 0, 0}}; int cis_transF; /*------refresh hidden pixmap:-----------------------------------------------*/ /* Refresh the hidden pixmap, where drawing will be done: */ RefreshPixmap_ (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], guiSP->control_winS.x0, guiSP->input_winS.y0, guiSP->main_winS.bg_colorID); /*------draw frame:----------------------------------------------------------*/ /* Draw frame, including labels: */ RamaFrame_ (guiSP); /*------prepare geometric parameters:----------------------------------------*/ /* Prepare screen parameters: */ free_width = (int) guiSP->main_win_free_area_width; free_height = (int) guiSP->main_win_free_area_height; frame_screen_x0 = guiSP->main_winS.text_line_height + 2; frame_screen_y0 = frame_screen_x0; frame_screen_x1 = free_width - frame_screen_x0; frame_screen_y1 = free_height - frame_screen_y0; frame_screen_width = frame_screen_x1 - frame_screen_x0 + 1; frame_screen_height = frame_screen_y1 - frame_screen_y0 + 1; /* Prepare scale factors: */ scale_x = (double) frame_screen_width / 6.2831853; scale_y = (double) frame_screen_height / 6.2831853; /*------draw trans residues:-------------------------------------------------*/ /* Prepare three colors: */ ParseColor_ (&rgbS, &symbol_color1ID, guiSP, "RGB:8888/DDDD/FFFF", "white"); ParseColor_ (&rgbS, &symbol_color2ID, guiSP, "RGB:0000/8888/FFFF", "white"); ParseColor_ (&rgbS, &symbol_color3ID, guiSP, "RGB:0000/4444/8888", "black"); XSetForeground (guiSP->displaySP, guiSP->theGCA[0], symbol_color1ID); XSetForeground (guiSP->displaySP, guiSP->theGCA[1], symbol_color2ID); XSetForeground (guiSP->displaySP, guiSP->theGCA[2], symbol_color3ID); /* Scan all macromolecular complexes: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ /* Pointer to current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check are there any atoms: */ if (curr_mol_complexSP->atomsN == 0) continue; /* Check is the current macromolecular complex caught: */ if (curr_mol_complexSP->catchF == 0) continue; /* Scan all residues: */ residuesN = curr_mol_complexSP->residuesN; for (residueI = 0; residueI < residuesN; residueI++) { /* Pointer to the current residue: */ curr_residueSP = curr_mol_complexSP->residueSP + residueI; /* If only selected residues should be visible: */ if (runtimeSP->rama_selectionF) { /* Pointer to the first atom of this residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Check the selection flag: */ if (first_atomSP->selectedF == 0) continue; } /* Extract dihedral angles: */ phi = curr_residueSP->phi; psi = curr_residueSP->psi; /* Check angles; both should be in the range (-180, 180): */ if (phi < -180) continue; if (phi > 180) continue; if (psi < -180) continue; if (psi > 180) continue; /* Project phi and psi: */ delta_x = scale_x * (phi + 3.1415927); delta_y = scale_y * (psi + 3.1415927); screen_phi = frame_screen_x0 + (int) delta_x; screen_psi = frame_screen_y1 - (int) delta_y; /* Check cis-trans flag; draw only trans residues in this step: */ cis_transF = (int) curr_residueSP->cis_transF; if (cis_transF != 1) continue; /* Draw symbol: */ /* Horizontal scan of the neighbourhood: */ for (i = 0; i < 9; i++) { /* Vertical scan of the neighbourhood: */ for (j = 0; j < 9; j++) { /* Current pixel coordinates: */ screen_x = screen_phi + i - 4; screen_y = screen_psi + j - 4; /* Check the circle mask: */ if (circle_maskAA[j][i] == 0) continue; /* Prepare index to the array */ /* of NearestAtomS structures: */ pixelI = guiSP->main_win_free_area_width * screen_y + screen_x; /* Check the pixel index: */ if (pixelI >= pixelsN) continue; /* Draw the pixel: */ XDrawPoint (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[indexAA[j][i]], screen_x, screen_y); /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = nearest_atomSP + pixelI; /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->last_refreshI = refreshI; curr_pixelSP->mol_complexI = mol_complexI; curr_pixelSP->atomI = curr_residueSP->residue_startI; } } /* Increase count of residues: */ residues_drawnN++; } } /* Add symbol for trans residues to the legend: */ /* Position of symbol center: */ screen_phi = frame_screen_x0; screen_psi = frame_screen_y1 + guiSP->main_winS.text_line_height - guiSP->main_winS.text_line_height / 5 - 5; /* Horizontal scan of the neighbourhood: */ for (i = 0; i < 9; i++) { /* Vertical scan of the neighbourhood: */ for (j = 0; j < 9; j++) { /* Current pixel coordinates: */ screen_x = screen_phi + i - 4; screen_y = screen_psi + j - 4; /* Check the circle mask: */ if (circle_maskAA[j][i] == 0) continue; /* Draw the pixel: */ XDrawPoint (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[indexAA[j][i]], screen_x, screen_y); } } /*------draw cis residues:---------------------------------------------------*/ /* Prepare three colors: */ ParseColor_ (&rgbS, &symbol_color1ID, guiSP, "RGB:FFFF/9999/FFFF", "white"); ParseColor_ (&rgbS, &symbol_color2ID, guiSP, "RGB:FFFF/0000/FFFF", "white"); ParseColor_ (&rgbS, &symbol_color3ID, guiSP, "RGB:8888/0000/8888", "black"); XSetForeground (guiSP->displaySP, guiSP->theGCA[0], symbol_color1ID); XSetForeground (guiSP->displaySP, guiSP->theGCA[1], symbol_color2ID); XSetForeground (guiSP->displaySP, guiSP->theGCA[2], symbol_color3ID); /* Scan all macromolecular complexes: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ /* Pointer to current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check are there any atoms: */ if (curr_mol_complexSP->atomsN == 0) continue; /* Check is the current macromolecular complex caught: */ if (curr_mol_complexSP->catchF == 0) continue; /* Scan all residues: */ residuesN = curr_mol_complexSP->residuesN; for (residueI = 0; residueI < residuesN; residueI++) { /* Pointer to the current residue: */ curr_residueSP = curr_mol_complexSP->residueSP + residueI; /* If only selected residues should be visible: */ if (runtimeSP->rama_selectionF) { /* Pointer to the first atom of this residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Check the selection flag: */ if (first_atomSP->selectedF == 0) continue; } /* Extract dihedral angles: */ phi = curr_residueSP->phi; psi = curr_residueSP->psi; /* Check angles; both should be in the range (-180, 180): */ if (phi < -180) continue; if (phi > 180) continue; if (psi < -180) continue; if (psi > 180) continue; /* Project phi and psi: */ delta_x = scale_x * (phi + 3.1415927); delta_y = scale_y * (psi + 3.1415927); screen_phi = frame_screen_x0 + (int) delta_x; screen_psi = frame_screen_y1 - (int) delta_y; /* Check cis-trans flag; draw only cis residues in this step: */ cis_transF = (int) curr_residueSP->cis_transF; if (cis_transF != 2) continue; /* Draw symbol: */ /* Horizontal scan of the neighbourhood: */ for (i = 0; i < 9; i++) { /* Vertical scan of the neighbourhood: */ for (j = 0; j < 9; j++) { /* Current pixel coordinates: */ screen_x = screen_phi + i - 4; screen_y = screen_psi + j - 4; /* Check the circle mask: */ if (circle_maskAA[j][i] == 0) continue; /* Prepare index to the array */ /* of NearestAtomS structures: */ pixelI = guiSP->main_win_free_area_width * screen_y + screen_x; /* Check the pixel index: */ if (pixelI >= pixelsN) continue; /* Draw the pixel: */ XDrawPoint (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[indexAA[j][i]], screen_x, screen_y); /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = nearest_atomSP + pixelI; /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->last_refreshI = refreshI; curr_pixelSP->mol_complexI = mol_complexI; curr_pixelSP->atomI = curr_residueSP->residue_startI; } } /* Increase count of residues: */ residues_drawnN++; } } /* Add symbol for cis residues to the legend: */ /* Position of symbol center: */ screen_phi = frame_screen_x0 + (frame_screen_x1 - frame_screen_x0) / 4; screen_psi = frame_screen_y1 + guiSP->main_winS.text_line_height - guiSP->main_winS.text_line_height / 5 - 5; /* Horizontal scan of the neighbourhood: */ for (i = 0; i < 9; i++) { /* Vertical scan of the neighbourhood: */ for (j = 0; j < 9; j++) { /* Current pixel coordinates: */ screen_x = screen_phi + i - 4; screen_y = screen_psi + j - 4; /* Check the circle mask: */ if (circle_maskAA[j][i] == 0) continue; /* Draw the pixel: */ XDrawPoint (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[indexAA[j][i]], screen_x, screen_y); } } /*------draw bad residues:---------------------------------------------------*/ /* Prepare three colors: */ ParseColor_ (&rgbS, &symbol_color1ID, guiSP, "RGB:FFFF/8888/8888", "white"); ParseColor_ (&rgbS, &symbol_color2ID, guiSP, "RGB:FFFF/0000/0000", "white"); ParseColor_ (&rgbS, &symbol_color3ID, guiSP, "RGB:8888/0000/0000", "black"); XSetForeground (guiSP->displaySP, guiSP->theGCA[0], symbol_color1ID); XSetForeground (guiSP->displaySP, guiSP->theGCA[1], symbol_color2ID); XSetForeground (guiSP->displaySP, guiSP->theGCA[2], symbol_color3ID); /* Scan all macromolecular complexes: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ /* Pointer to current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check are there any atoms: */ if (curr_mol_complexSP->atomsN == 0) continue; /* Check is the current macromolecular complex caught: */ if (curr_mol_complexSP->catchF == 0) continue; /* Scan all residues: */ residuesN = curr_mol_complexSP->residuesN; for (residueI = 0; residueI < residuesN; residueI++) { /* Pointer to the current residue: */ curr_residueSP = curr_mol_complexSP->residueSP + residueI; /* If only selected residues should be visible: */ if (runtimeSP->rama_selectionF) { /* Pointer to the first atom of this residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Check the selection flag: */ if (first_atomSP->selectedF == 0) continue; } /* Extract dihedral angles: */ phi = curr_residueSP->phi; psi = curr_residueSP->psi; /* Check angles; both should be in the range (-180, 180): */ if (phi < -180) continue; if (phi > 180) continue; if (psi < -180) continue; if (psi > 180) continue; /* Project phi and psi: */ delta_x = scale_x * (phi + 3.1415927); delta_y = scale_y * (psi + 3.1415927); screen_phi = frame_screen_x0 + (int) delta_x; screen_psi = frame_screen_y1 - (int) delta_y; /* Check cis-trans flag; draw only bad residues in this step: */ cis_transF = (int) curr_residueSP->cis_transF; if (cis_transF != 0) continue; /* Draw symbol: */ /* Horizontal scan of the neighbourhood: */ for (i = 0; i < 9; i++) { /* Vertical scan of the neighbourhood: */ for (j = 0; j < 9; j++) { /* Current pixel coordinates: */ screen_x = screen_phi + i - 4; screen_y = screen_psi + j - 4; /* Check the circle mask: */ if (circle_maskAA[j][i] == 0) continue; /* Prepare index to the array */ /* of NearestAtomS structures: */ pixelI = guiSP->main_win_free_area_width * screen_y + screen_x; /* Check the pixel index: */ if (pixelI >= pixelsN) continue; /* Draw the pixel: */ XDrawPoint (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[indexAA[j][i]], screen_x, screen_y); /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = nearest_atomSP + pixelI; /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->last_refreshI = refreshI; curr_pixelSP->mol_complexI = mol_complexI; curr_pixelSP->atomI = curr_residueSP->residue_startI; } } /* Increase count of residues: */ residues_drawnN++; } } /* Add symbol for bad residues to the legend: */ /* Position of symbol center: */ screen_phi = frame_screen_x0 + 2 * (frame_screen_x1 - frame_screen_x0) / 4; screen_psi = frame_screen_y1 + guiSP->main_winS.text_line_height - guiSP->main_winS.text_line_height / 5 - 5; /* Horizontal scan of the neighbourhood: */ for (i = 0; i < 9; i++) { /* Vertical scan of the neighbourhood: */ for (j = 0; j < 9; j++) { /* Current pixel coordinates: */ screen_x = screen_phi + i - 4; screen_y = screen_psi + j - 4; /* Check the circle mask: */ if (circle_maskAA[j][i] == 0) continue; /* Draw the pixel: */ XDrawPoint (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[indexAA[j][i]], screen_x, screen_y); } } /*------draw titles:---------------------------------------------------------*/ DrawTitles_ (runtimeSP, guiSP); /*------copy hidden pixmap to the main window:-------------------------------*/ XCopyArea (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->main_winS.ID, guiSP->theGCA[0], 0, 0, guiSP->main_win_free_area_width, guiSP->main_win_free_area_height, 0, 0); /*---------------------------------------------------------------------------*/ return residues_drawnN; } /*===========================================================================*/ garlic-1.6/copy_sequence.c0000644000076500007650000000363307747301561016134 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2003 Damir Zucic */ /*============================================================================= copy_sequence.c Purpose: Copy sequence from the general purpose buffer to the reference buffer. Input: (1) Pointer to RuntimeS structure. Output: (1) Sequence copyed to reference buffer. (2) Return value. Return value: (1) The number of residues in both buffers. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ void InitHyphob_ (RuntimeS *); /*======copy sequence to reference buffer:===================================*/ int CopySequence_ (RuntimeS *runtimeSP) { int max_length, i; size_t residuesN, residueI; char *sourceP, *destP; /* The maximal residue name length: */ max_length = RESNAMESIZE - 1; /* Copy the number of residues: */ residuesN = runtimeSP->residuesN; runtimeSP->reference_residuesN = residuesN; /* Zero initialize the reference buffer: */ for (i = 0; i < (int) runtimeSP->sequence_buffer_size; i++) { *(runtimeSP->reference_sequenceP + i) = '\0'; } /* Scan the source sequence: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Copy the residue name: */ sourceP = runtimeSP->sequenceP + residueI * max_length; destP = runtimeSP->reference_sequenceP + residueI * max_length; strncpy (destP, sourceP, max_length); /* Copy the residue serial number: */ *(runtimeSP->reference_serialIP + residueI) = *(runtimeSP->serialIP + residueI); } /* Initialize the hydrophobicity values: */ InitHyphob_ (runtimeSP); /* Return the number of residues in both buffers: */ return residuesN; } /*===========================================================================*/ garlic-1.6/translate_plane.c0000644000076500007650000000243207150602375016435 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= translate_plane.c Purpose: Translate the plane. Input: (1) Pointer to MolComplexS structure. (2) Pointer to VectorS structure, with shift vector. Output: (1) Plane translated. Return value: No return value. ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======translate plane:=====================================================*/ void TranslatePlane_ (MolComplexS *curr_mol_complexSP, VectorS *shift_vectorSP) { PlaneS *curr_planeSP; /* Pointer to the current plane: */ curr_planeSP = &curr_mol_complexSP->planeS; /* Translate the plane center: */ curr_planeSP->center_x[0] += shift_vectorSP->x; curr_planeSP->center_y += shift_vectorSP->y; curr_planeSP->center_z[0] += shift_vectorSP->z; /* Update stereo data: */ curr_planeSP->center_x[1] += shift_vectorSP->x; curr_planeSP->center_z[1] += shift_vectorSP->z; /* Set the position_changedF: */ curr_mol_complexSP->position_changedF = 1; } /*===========================================================================*/ garlic-1.6/alloc_gui.c0000644000076500007650000000253507463606707015235 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2002 Damir Zucic */ /*============================================================================= alloc_gui.c Purpose: Allocate memory for GUIS structure. The calloc function is used to zero-initialize all bytes. Input: No arguments. Output: (1) Memory for GUIS structure allocated. (2) Return value. Return value: (1) Pointer to allocated memory, on success. (2) NULL on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ void ErrorMessage_ (char *, char *, char *, char *, char *, char *, char *); /*======allocate memory for GUIS structure:==================================*/ GUIS *AllocateGUIS_ (void) { static GUIS *guiSP; /* Allocate zero-initialized memory: */ guiSP = (GUIS *) calloc (1, sizeof (GUIS)); if (guiSP == NULL) { ErrorMessage_ ("garlic", "AllocateGUIS_", "", "Failed to allocate memory for GUIS structure!\n", "", "", ""); } /* Return pointer to allocated memory (equal to NULL on failure): */ return guiSP; } /*===========================================================================*/ garlic-1.6/porins2.script0000644000076500007650000000074510043147203015731 0ustar zuciczucic00000000000000# Searching for sequence motifs characteristic for porins. # # 2004/04/26 # Hide water and other hetero atoms: select hetero hide # Draw just a backbone, using blue color: select complement show backbone 4 color cyan-blue # Select the first characteristic pattern: pattern = TYR TRP PHE / * / LEU VAL / * / LEU VAL ALA GLY select pattern color red # Select the second characteristic pattern: pattern = LEU VAL ALA GLY / * / LEU VAL / * / TYR TRP PHE select pattern color yellow garlic-1.6/comm_backbone.c0000644000076500007650000001324107461732071016042 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2002 Damir Zucic */ /*============================================================================= comm_backbone.c Purpose: Execute backbone command. Hide the selected atoms and make backbone visible. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) The number of macromolecular complexes. (3) Pointer to RuntimeS structure, with some runtime data. (4) Pointer to ConfigS structure, with configuration data. (5) Pointer to GUIS structure, with GUI data. (6) Pointer to NearestAtomS structure. (7) The number of pixels in the main window free area. (8) Pointer to refreshI. (9) Pointer to the remainder of the command string. It is either empty or contains the backbone thickness specification. Output: (1) Backbone drawn. (2) Return value. Return value: (1) Positive (command) code on success. (2) Negative (error) code on failure. Notes: (1) It is important to initialize the value of backbone_styleI with a value different from zero! (2) The backbone_styleI may be used in two roles: as the real style index and as the signal that backbone should be hidden and all selected atoms shown. In the later case, the value is set to -1. (3) The term "backbone element" refers to a pair of bonds assigned to the given CA atom. The entire backbone is a set of backbone elements. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "commands.h" #include "typedefs.h" /*======function prototypes:=================================================*/ char *ExtractToken_ (char *, int, char *, char *); int ShowNoRefresh_ (MolComplexS *, int); int HideBackbone_ (MolComplexS *, int); int HideNoRefresh_ (MolComplexS *, int); int ShowBackbone_ (MolComplexS *, int); size_t MainRefresh_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); int ControlRefresh_ (MolComplexS *, ConfigS *, GUIS *); /*======execute backbone command:============================================*/ int CommandBackbone_ (MolComplexS *mol_complexSP, int mol_complexesN, RuntimeS *runtimeSP, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int *refreshIP, char *stringP) { char *remainderP; char tokenA[STRINGSIZE]; int backbone_styleI; int mol_complexI; MolComplexS *curr_mol_complexSP; size_t c_alphaI, c_alphaN; BackboneS *curr_backboneSP; AtomS *curr_atomSP; /* Initialize the backbone_styleI: */ backbone_styleI = configSP->default_backbone_styleI; /* Extract the first token: */ remainderP = ExtractToken_ (tokenA, STRINGSIZE, stringP, " \t\n"); /* If available, the first token should contain the backbone drawing style: */ if (remainderP) { /** Extract the backbone drawing style: **/ if (strstr (tokenA, "OFF") == tokenA) backbone_styleI = -1; else if (strcmp (tokenA, "0") == 0) backbone_styleI = 0; else if (strcmp (tokenA, "1") == 0) backbone_styleI = 1; else if (strcmp (tokenA, "2") == 0) backbone_styleI = 2; else if (strcmp (tokenA, "3") == 0) backbone_styleI = 3; else if (strcmp (tokenA, "4") == 0) backbone_styleI = 4; else if (strcmp (tokenA, "5") == 0) backbone_styleI = 5; else { sprintf (runtimeSP->messageA, "Backbone drawing style \"%s\" not available!", tokenA); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_BACKBONE; } } /* Set the backbone drawing style for each */ /* selected CA atom in each cought complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /** Pointer to the current macromolecular complex: **/ curr_mol_complexSP = mol_complexSP + mol_complexI; /** Check is the current macromol. complex caught: **/ if (curr_mol_complexSP->catchF == 0) continue; /** Number of CA atoms in the current macromolecular complex: **/ c_alphaN = curr_mol_complexSP->c_alphaN; /** Set backbone drawing style: **/ for (c_alphaI = 0; c_alphaI < c_alphaN; c_alphaI++) { /*** Pointer to the current BackboneS structure: ***/ curr_backboneSP = curr_mol_complexSP->backboneSP + c_alphaI; /*** Pointer to the current CA atom: ***/ curr_atomSP = curr_mol_complexSP->atomSP + curr_backboneSP->c_alphaI; /*** If this CA atom is not selected, skip it: ***/ if (curr_atomSP->selectedF == 0) continue; /*** Copy style: ***/ curr_backboneSP->backbone_styleI = backbone_styleI; } } /* Hide backbone (if requested): */ if (backbone_styleI == -1) { /** Show all selected atoms but do not refresh graphics: **/ ShowNoRefresh_ (mol_complexSP, mol_complexesN); /** Hide backbone (update hiddenF for each backbone element): **/ HideBackbone_ (mol_complexSP, mol_complexesN); } /* Show backbone or change backbone style (if requested): */ else { /** Hide all selected atoms but do not refresh graphics: **/ HideNoRefresh_ (mol_complexSP, mol_complexesN); /** Show backbone (update hiddenF for each backbone element): **/ ShowBackbone_ (mol_complexSP, mol_complexesN); } /*---------------------------------------------------------------------------*/ /* Refresh the main window: */ (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); /* Refresh the control window: */ ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); /* Return positive value on success: */ return COMMAND_BACKBONE; } /*===========================================================================*/ garlic-1.6/arrow.pdb0000644000076500007650000000024207633642167014744 0ustar zuciczucic00000000000000ATOM 1 Q DUM 1 0.000 0.000 0.000 1.00 10.00 ARRW 1 ATOM 2 Q DUM 1 0.000 0.000 10.000 1.00 10.00 ARRW 2 garlic-1.6/venn.c0000644000076500007650000001126107664415611014234 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2003 Damir Zucic */ /*============================================================================= venn.c Purpose: Execute venn command: draw Venn diagram for the sequence which is kept in the sequence buffer. Input: (1) Pointer to MolComplexS structure. (2) The number of macromolecular complexes. (3) Pointer to RuntimeS structure. (4) Pointer to ConfigS structure. (5) Pointer to GUIS structure. (6) Pointer to NearestAtomS structure. (7) The number of pixels in the main window free area. (8) Pointer to refreshI. (9) Pointer to the remainder of the command string. This command may be given without any keyword, with the keyword OFF or with a range of residue serial indices. Output: (1) The main window mode changed to 3 (default is zero), i.e. the main window will be switched to Venn diagram. (2) Return value. Return value: (1) Positive (command) code on success. (2) Negative (error) code on failure. Notes: (1) This command reinitializes the NearestAtomS array, except if the additional keyword is not recognized. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "commands.h" #include "typedefs.h" /*======function prototypes:=================================================*/ char *ExtractToken_ (char *, int, char *, char *); int ExtractTwoIntegers_ (int *, int *, char *); void InitNearest_ (NearestAtomS *, size_t); size_t MainRefresh_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); int ControlRefresh_ (MolComplexS *, ConfigS *, GUIS *); /*======execute venn command:================================================*/ int Venn_ (MolComplexS *mol_complexSP, int mol_complexesN, RuntimeS *runtimeSP, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int *refreshIP, char *stringP) { char *remainderP; char tokenA[SHORTSTRINGSIZE]; char *P; int n; int residue1I, residue2I; /* Extract the first token: */ remainderP = ExtractToken_ (tokenA, STRINGSIZE, stringP, " \t\n"); /* If available, the first token should contain keyword OFF: */ if (remainderP) { /* If keyword OFF is present, switch to default drawing mode: */ if (strstr (tokenA, "OFF") == tokenA) { /* Reset drawing mode index: */ guiSP->main_window_modeI = 0; /* Reinitialize the NearestAtomS array: */ InitNearest_ (nearest_atomSP, pixelsN); *refreshIP = 1; /* Refresh the main window: */ (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); /* Refresh the control window: */ ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); /* Return the command code: */ return COMMAND_VENN; } /* If keyword OFF is not present, try to read two array indices: */ else { /* Replace each minus in the input string with space: */ P = stringP; while ((n = *P++) != '\0') { if (n == '-') *(P - 1) = ' '; } /* If reading fails: */ if (ExtractTwoIntegers_ (&residue1I, &residue2I, stringP) < 0) { strcpy (runtimeSP->messageA, "Command interpretation failed!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_VENN; } /* If array indices were successfully read, check them: */ if ((residue1I < 1) || (residue2I < residue1I)) { strcpy (runtimeSP->messageA, "Bad range (check indices)!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_VENN; } /* Store the extracted indices: */ runtimeSP->range_startI = residue1I - 1; runtimeSP->range_endI = residue2I - 1; } } /* If the first token is not available, initialize range indices: */ else { runtimeSP->range_startI = 0; if (runtimeSP->residuesN >= 1) { runtimeSP->range_endI = (int) runtimeSP->residuesN - 1; } else { runtimeSP->range_endI = 0; } } /* Set the main window drawing mode index: */ guiSP->main_window_modeI = 3; /* Reinitialize the NearestAtomS array and refresh index: */ InitNearest_ (nearest_atomSP, pixelsN); *refreshIP = 1; /* Refresh the main window: */ (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); /* Refresh the control window: */ ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); /* Return the command code: */ return COMMAND_VENN; } /*===========================================================================*/ garlic-1.6/defines.h0000644000076500007650000002250310357036544014706 0ustar zuciczucic00000000000000/* Copyright (C) 2001-2006 Damir Zucic */ /* Defines used in garlic program. */ /* Some general purpose symbols: */ #define STRINGSIZE 1024 #define SHORTSTRINGSIZE 80 #define MAXMESSAGES 100 /* Maximal number of error messages */ #define OPEN_FAILURE -999 /* Conversion factors for angular units: */ #define DEG_TO_RAD 0.017453293 #define RAD_TO_DEG 57.29578 /* The maximal size of the main window: */ /* Notes: */ /* (1) Normally, the size of NearestAtomS array is controled through */ /* .garlicrc file. If the corresponding entries are missing */ /* there, the values defined here are used. Check your .garlicrc! */ /* (2) Each pixel is associated with one NearestAtomS (defined in */ /* typedefs.h). This may require too much memory on some systems. */ /* (3) The size of NearestAtomS array is proportional to display */ /* resolution. See sizehints.c for max. size of the main window! */ #define MAXWINWIDTH 3000 #define MAXWINHEIGHT 3000 /* Array sizes used for protein data structures: */ #define PDBCODESIZE 5 #define TAGSIZE 128 #define ATOMNAMESIZE 5 #define SYMBOLSIZE 3 #define RESNAMESIZE 4 #define SEGNAMESIZE 5 #define ELEMNAMESIZE 3 #define CHARGESIZE 3 #define MAXCOMPLEXES 1000 #define ATOMS_IN_CHUNK 2500 /* Symbols related to PDB header: */ #define HEADERLINESIZE 81 #define MAXHEADERLINES 1 #define MAXTITLELINES 1 #define MAXCOMPNDLINES 5 #define MAXSOURCELINES 5 #define MAXEXPDTALINES 5 #define MAXAUTHORLINES 5 /* File format identifiers (see fileformat.c): */ #define PDB_FORMAT 1 /* Number of keywords in a standard format: */ #define PDB_KEYWORDS 52 /* The maximal value of refreshI: */ #define MAXREFRESHI 32000 /* The maximal number of color fading surfaces */ /* (do not confuse this with MAXMOLSURFACES!): */ #define MAXCOLORSURFACES 8 /* Default maximal number of lines: */ #define MAXLINES 7 /* The maximal bond drawing style index: */ #define MAXBONDSTYLEI 5 /* The identifier for nice bonds (one of bond drawing styles): */ #define NICE_BONDS 100 /* The identifier for sticks (one of bond drawing styles): */ #define STICK_BONDS 200 /* The identifier for the request to refresh bonds: */ #define REFRESH_BONDS 300 /* The maximal backbone drawing style index: */ #define MAXBONESTYLEI 5 /* The maximal atom drawing style index: */ #define MAXATOMSTYLEI 7 /* Spacefill style identifier: */ #define SPACEFILL 100 /* Spacefill (version 2) style identifier: */ #define SPACEFILL2 101 /* Ball style identifier: */ #define BALL 150 /* Ball (version 2) style identifier: */ #define BALL2 151 /* Big sphere style identifier: */ #define BIG_SPHERE 200 /* Big sphere (version 2) style identifier: */ #define BIG_SPHERE2 201 /* Covalent style identifier: */ #define COVALENT 250 /* Covalent style (version 2) identifier: */ #define COVALENT2 251 /* Small atom style identifier: */ #define SMALL_ATOM 300 /* Small atom (version 2) style identifier: */ #define SMALL_ATOM2 301 /* Plane style identifier: */ #define PLANE_STYLE 99 /* Default user and screen geometric parameters in real and atomic world: */ #define SCREEN_REAL_WX 270.0 #define SCREEN_REAL_WY 195.0 #define USER_SCREEN_REAL_DIST 700.0 #define SCREEN_ATOMIC_WX 0.5 #define USER_ATOMIC_Z -250.0 /* The shift along z axis (used to tilt bonds): */ #define Z_SHIFT 0.1 /* Stereo image parameters: */ #define STEREO_MARGIN 10 #define STEREO_ANGLE 5.0 /* Degrees */ /* Maximal number of bonds per atom (including hydrogen bonds): */ #define MAXBONDS 10 /* The number of known atomic pairs (recognized by this program). */ /* Both " C N" and " N C" are included in the list of known pairs, */ /* though they are equivalent. This is done for practical reasons. */ #define KNOWNPAIRS 22 /* The size of atomic pair array (string): */ #define PAIRSIZE 5 /* The number of hydrophobicity scales which are hard-coded in the program: */ #define SCALESN 6 /* The minimal spacing of slab surfaces: */ #define MINSLABSPACING 1.0 /* The minimal spacing of outer fading surfaces: */ #define MINFADINGSPACING 1.0 /* The maximal number of command strings: */ #define MAXCOMMSTRINGS 500 /* The maximal length of the command string: */ #define COMMSTRINGSIZE 1024 /* The text margin: */ #define TEXTMARGIN 1 /* The maximal number of chain ID's, residue ranges, */ /* residue names and atom names in selection cryteria: */ #define MAXFIELDS 100 /* Number of predefined (hard-coded) color schemes: */ #define COLORSCHEMES 26 /* The identifier used to identify H to H bond (must be negative!): */ #define H_TO_H_BOND -100 /* The identifier used to identify unrecognized atomic pairs: */ #define GENERICID 16348 /* The margin of the circle used to represent the plane: */ #define CIRCLEMARGIN 0.25 /* Circle tilt angle (from negative y axis toward observer), in degrees: */ #define CIRCLETILT 20 /* Default circle transparency (should be between 0.0 and 1.0): */ #define DEFAULT_TRANSP 0.40 /* The maximal number of titles (strings added to the main window): */ #define MAXTITLES 100 /* The maximal length of the title string: */ #define TITLESTRINGSIZE 1024 /* The maximal number of residues in the sequence buffer: */ #define MAXRESIDUES 20000 /* The maximal pattern length (the maximal number of sets in pattern): */ #define MAX_PATT_LENGTH 100 /* For each position in the pattern, more than one residue may be specified. */ /* The following symbol defines the maximal number of residues per position: */ #define MAX_NAMES_IN_SET 30 /* The maximal number of residues in the pattern buffer: */ #define MAX_RES_IN_PATT 3000 /* The value which signals that dihedral angle is missing (not calculated): */ #define BADDIHEDANGLE 999.0 /* The screen width of a single residue, in pixels (used for plots): */ #define RESIDUE_WIDTH 5 /* Bit masks for structure, plane and envelope: */ #define STRUCTURE_MASK 0x1 #define PLANE_MASK 0x2 #define MEMBRANE_MASK 0x4 #define ENVELOPE_MASK 0x8 /* The gap between two objects prepared for docking (in angstroms): */ #define DOCKING_GAP 4 /* The parameter used to define the width */ /* and height of docking area (angstroms): */ #define DOCKING_AREA_WIDTH 40.0 /* The projected surface of some structure is divided into small */ /* squares. This parameter defines the square size in angstroms: */ #define DOCKING_CELL_WIDTH 0.20 /* The atomic radius used for docking (in angstroms): */ #define DOCKING_ATOM_RADIUS 3.0 /* The maximal number of exposed residues: */ #define MAX_EXPOSED_RESIDUES 1000 /* The number of neighbours to be scanned while */ /* searching the representative atom for docking: */ #define DOCKING_SCAN_WIDTH 20 /* Sequence neighborhood half width: */ #define NEIGH_HALF_WIDTH 11 /* The omega angle tolerance (degrees). For a */ /* planar peptide, omega is 0 or 180 degrees. */ #define OMEGA_TOLERANCE 20 /* The segment width and the minimal score (used for sequence comparison): */ #define SEGMENT_WIDTH 5 #define MINIMAL_SCORE 5 /* The maximal number of template atoms: */ #define MAXTEMPLATEATOMS 1000 /* The angle between C-CA bond and C-N bond (degrees): */ #define CACN_ANGLE 116 /* The length of N-C bond: */ #define CN_BOND_LENGTH 1.325 /* The angle between N-C and N-CA bond (degrees): */ #define CNCA_ANGLE 122 /* The length of N-CA bond: */ #define NCA_BOND_LENGTH 1.455 /* The angle between CA-N and CA-C bond (degrees): */ #define NCAC_ANGLE 111 /* The length of CA-C bond: */ #define CAC_BOND_LENGTH 1.510 /* Default membrane thickness in angstroms: */ #define MEMBRANE_THICKNESS 30 /* The maximal number of molecular surfaces per */ /* structure (do not confuse with MAXSURFACES!): */ #define MAXMOLSURFACES 5 /* The maximal number of macromolecular complexes in a group: */ #define MAX_GROUP_SIZE 100 /* An auxiliary cylinder is used to find the proper position and */ /* orientation of membrane with respect to beta barrel protein. */ /* The following parameters define the maximal number of cells */ /* on the surface of this cylinder along the axis and in a ring */ /* which runs around the cylinder, perpendicular to the axis. */ #define BETA_CELLS_ALONG_AXIS 40 #define BETA_CELLS_IN_RING 20 /* The linear width of a single cell on the surface of auxiliary cylinder: */ #define BETA_CELL_LINEAR_WIDTH 3.0 /* The number of simple (ordinary) cells associated with the axis. These */ /* cells are used to count PHE, TRP and TYR residues projected to the axis. */ #define SIMPLE_CELLS_ALONG_AXIS 4000 /* The linear width of a single simple cell: */ #define SIMPLE_CELL_WIDTH 0.2 garlic-1.6/input_refresh.c0000644000076500007650000000756707070460570016154 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= input_refresh.c Purpose: Refresh the input window. Input: (1) Pointer to GUIS structure. (2) Pointer to RuntimeS structure, with command strings. Output: (1) Input window redrawn. (2) Return value. Return value: (1) Positive always. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======refresh the input window:============================================*/ int InputRefresh_ (GUIS *guiSP, RuntimeS *runtimeSP) { int comm_length, carriage_pos, the_rest; char left_partA[COMMSTRINGSIZE]; char right_partA[COMMSTRINGSIZE]; int full_left_part_width, left_part_width, max_width; int i; static char *left_partP; int left_part_length; int x0, y0, y1, y2; /* Refresh the input window: */ XSetForeground (guiSP->displaySP, guiSP->theGCA[0], guiSP->input_winS.bg_colorID); XFillRectangle (guiSP->displaySP, guiSP->input_winS.ID, guiSP->theGCA[0], 0, 0, guiSP->input_winS.width, guiSP->input_winS.height); /* Prepare the text color: */ XSetForeground (guiSP->displaySP, guiSP->theGCA[0], guiSP->output_winS.fg_colorID); /* Draw the current message (this is often empty): */ x0 = TEXTMARGIN; y0 = guiSP->input_winS.height - guiSP->input_winS.text_line_height - guiSP->input_winS.half_font_height; XDrawString (guiSP->displaySP, guiSP->input_winS.ID, guiSP->theGCA[0], x0, y0, runtimeSP->messageA, runtimeSP->message_length); /* Copy the command string length and carriage position: */ comm_length = runtimeSP->command_length; carriage_pos = runtimeSP->carriage_position; /* Prepare the left and right part of the command string: */ strncpy (left_partA, runtimeSP->curr_commandA, carriage_pos); left_partA[carriage_pos] = '\0'; the_rest = comm_length - carriage_pos; strncpy (right_partA, runtimeSP->curr_commandA + carriage_pos, the_rest); right_partA[the_rest] = '\0'; /* Prepare the left part width: */ full_left_part_width = XTextWidth (guiSP->main_winS.fontSP, left_partA, carriage_pos) + TEXTMARGIN; /* Initialize the pointer to the left part: */ left_partP = left_partA; /* The maximal allowed width of the left */ /* part (some space left for the cursor): */ max_width = (int) guiSP->input_winS.width - 3; /* If the left part is too wide, skip some characters: */ if (full_left_part_width > max_width) { for (i = 0; i < COMMSTRINGSIZE - 1; i++) { left_part_width = full_left_part_width - runtimeSP->left_part_widthA[i]; if (left_part_width <= max_width) { left_partP = left_partA + i + 1; break; } } } else left_part_width = full_left_part_width; /* The length of the remainder: */ left_part_length = strlen (left_partP); /* Draw the left part to the bottom of input window: */ y0 = guiSP->input_winS.height - guiSP->input_winS.half_font_height; XDrawString (guiSP->displaySP, guiSP->input_winS.ID, guiSP->theGCA[0], x0, y0, left_partP, left_part_length); /* Draw the keyboard cursor (showing the "carriage" position): */ x0 = left_part_width + 1; y1 = guiSP->input_winS.height - guiSP->input_winS.text_line_height - guiSP->input_winS.quarter_font_height; y2 = guiSP->input_winS.height - 2; XDrawLine (guiSP->displaySP, guiSP->input_winS.ID, guiSP->theGCA[0], x0, y1, x0, y2); XDrawLine (guiSP->displaySP, guiSP->input_winS.ID, guiSP->theGCA[0], x0 + 1, y1, x0 + 1, y2); /* Draw the right part of command string: */ x0 = left_part_width + 3; XDrawString (guiSP->displaySP, guiSP->input_winS.ID, guiSP->theGCA[0], x0, y0, right_partA, strlen (right_partA)); /* Return positive value on success: */ return 1; } /*===========================================================================*/ garlic-1.6/chi4_from_cgcdcenz.c0000644000076500007650000000727307342225133016777 0ustar zuciczucic00000000000000/* Copyright (C) 2001 Damir Zucic */ /*============================================================================= chi4_from_cgcdcenz.c Purpose: Calculate dihedral angle chi4, using CG, CD, CE and NZ coordinates. Input: (1) Pointer to AtomS structure, pointing to the first atom of the current macromolecular complex. (2) Index of the first atom of the current residue. (3) Index of the last atom of the currrent residue. Output: Return value. Return value: (1) Dihedral angle chi4, on success. (2) BADDIHEDANGLE on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int ExtractFourAtoms_ (VectorS *, VectorS *, VectorS *, VectorS *, char *, char *, char *, char *, AtomS *, size_t, size_t); void VectorProduct_ (VectorS *, VectorS *, VectorS *); double AbsoluteValue_ (VectorS *); double ScalarProduct_ (VectorS *, VectorS *); /*======calculate chi4 from CG, CD, CE and NZ:===============================*/ double Chi4FromCGCDCENZ_ (AtomS *atomSP, size_t atom_startI, size_t atom_endI) { static VectorS CG_vectorS, CD_vectorS, CE_vectorS, NZ_vectorS; int n; VectorS CD_CG_vectorS, CD_CE_vectorS; VectorS CE_CD_vectorS, CE_NZ_vectorS; VectorS u1S, u2S; VectorS v1S, v2S; double denom, ratio, alpha; double chi4; /* Extract CG, CD, CE and NZ coordinates: */ n = ExtractFourAtoms_ (&CG_vectorS, &CD_vectorS, &CE_vectorS, &NZ_vectorS, "CG", "CD", "CE", "NZ", atomSP, atom_startI, atom_endI); /* All four atoms are required to calculate the angle chi4: */ if (n < 4) return BADDIHEDANGLE; /* The first pair of auxiliary vectors: */ CD_CG_vectorS.x = CG_vectorS.x - CD_vectorS.x; CD_CG_vectorS.y = CG_vectorS.y - CD_vectorS.y; CD_CG_vectorS.z = CG_vectorS.z - CD_vectorS.z; CD_CE_vectorS.x = CE_vectorS.x - CD_vectorS.x; CD_CE_vectorS.y = CE_vectorS.y - CD_vectorS.y; CD_CE_vectorS.z = CE_vectorS.z - CD_vectorS.z; /* The second pair of auxiliary vectors: */ CE_CD_vectorS.x = CD_vectorS.x - CE_vectorS.x; CE_CD_vectorS.y = CD_vectorS.y - CE_vectorS.y; CE_CD_vectorS.z = CD_vectorS.z - CE_vectorS.z; CE_NZ_vectorS.x = NZ_vectorS.x - CE_vectorS.x; CE_NZ_vectorS.y = NZ_vectorS.y - CE_vectorS.y; CE_NZ_vectorS.z = NZ_vectorS.z - CE_vectorS.z; /* Two vectors perpendicular to CD_CE_vectorS, mutually orthogonal, */ /* the second in the plane defined by CD_CG_vectorS and CD_CE_vectorS: */ VectorProduct_ (&u1S, &CD_CG_vectorS, &CD_CE_vectorS); VectorProduct_ (&u2S, &u1S, &CD_CE_vectorS); /* Two vectors perpendicular to CE_CD_vectorS, mutually orthogonal, */ /* the second in the plane defined by CE_CD_vectorS and CE_NZ_vectorS: */ VectorProduct_ (&v1S, &CE_CD_vectorS, &CE_NZ_vectorS); VectorProduct_ (&v2S, &CE_CD_vectorS, &v1S); /* Calculate the angle alpha, which will be used to calculate chi4: */ /* Avoid division by zero: */ denom = AbsoluteValue_ (&u1S) * AbsoluteValue_ (&v1S); if (denom == 0.0) return BADDIHEDANGLE; /* Use the scalar product to calculate the cosine of the angle: */ ratio = ScalarProduct_ (&u1S, &v1S) / denom; /* Arc cosine is very sensitive to floating point errors: */ if (ratio <= -1.0) alpha = 3.1415927; else if (ratio >= 1.0) alpha = 0.0; else alpha = acos (ratio); /* There are two possible solutions; the right one is resolved here: */ if (ScalarProduct_ (&v2S, &u1S) >= 0) chi4 = alpha; else chi4 = -alpha; /* Return the angle (in radians): */ return chi4; } /*===========================================================================*/ garlic-1.6/balls.c0000644000076500007650000000627407604154377014376 0ustar zuciczucic00000000000000/* Copyright (C) 2002 Damir Zucic */ /*============================================================================= balls.c Purpose: Execute balls command: change the ball radius. This radius is used used to draw atoms as balls. Input: (1) Pointer to ConfigS structure. (2) Pointer to the remainder of the command string. Output: (1) The ball radius. (2) Return value. Return value: (1) Positive (command) code on success. (2) Negative (error) code on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include #include "defines.h" #include "commands.h" #include "typedefs.h" /*======function prototypes:=================================================*/ size_t MainRefresh_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); int ControlRefresh_ (MolComplexS *, ConfigS *, GUIS *); /*======execute balls command:===============================================*/ int Balls_ (MolComplexS *mol_complexSP, int mol_complexesN, RuntimeS *runtimeSP, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int *refreshIP, char *stringP) { char *P; int n; double value; int mol_complexI; MolComplexS *curr_mol_complexSP; size_t atomI; AtomS *curr_atomSP; /* Replace each non-numeric character (except */ /* minus sign and decimal point) with space: */ P = stringP; while ((n = *P++) != '\0') { if (!isdigit (n) && (n != '-') && (n != '.')) *(P - 1) = ' '; } /* Try to extract the ball radius: */ if (sscanf (stringP, "%lf", &value) != 1) { strcpy (runtimeSP->messageA, "Failed to extract the ball radius!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_BALLS; } /* Check the ball radius (must be positive): */ if (value < 0.0) { strcpy (runtimeSP->messageA, "Positive value expected!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_BALLS; } /* On success, set the ball radius for each */ /* selected atom in each caught complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* If this complex is not caught, skip it: */ if (curr_mol_complexSP->catchF == 0) continue; /* Scan all atoms: */ for (atomI = 0; atomI < curr_mol_complexSP->atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* If this atom is not selected, skip it: */ if (curr_atomSP->selectedF == 0) continue; /* Change the ball radius: */ curr_atomSP->raw_atomS.ball_radius = value; } } /* Refresh the main window: */ (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); /* Refresh the control window: */ ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); /* Return the command code: */ return COMMAND_BALLS; } /*===========================================================================*/ garlic-1.6/hydrophobicity.c0000644000076500007650000001263610376567502016336 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2006 Damir Zucic */ /*============================================================================= hydrophobicity.c Purpose: This function may be used to assign the hydrophobicity to the specified residue or to retrieve minimal, maximal, average or threshold hydrophobicity value. Input: (1) Pointer to residue name. (2) Hydrophobicity scale index. (3) Request index: 0 = return hydrophobicity, 1 = return min. value, 2 = return max. value, 3 = return average value and 4 = return threshold value. Output: Return value. Return value: (1) Hydrophobicity of the specified residue, extreme hydrophob. value, average hydrophobicity or threshold hydrophobicity. What will be returned is decided by the request index. Notes: (1) The average hydrophobicity is assigned to unknown residues. (2) Threshold hydrophobicy is used to distinguish hydrophobic and hydrophilic residues. Residue which has hydrophobicity value above the threshold should be treated as hydrophobic. For Kyte-Doolittle scale and White scales, positive values are assigned to hydrophobic residues and threshold value is equal to zero. For normalized Eisenberg scale, threshold is different from zero. This is caused by normalization. (3) References: =========================================================== | Scale(s) | Reference | =========================================================== | S. White group | Biochemistry 35 (1996), p. 5109. | | Kyte-Doolitle | J. Mol. Biol. 157 (1982), p. 105. | | Eisenberg | J. Mol. Biol. 179 (1984), p. 125. | =========================================================== (4) Check init_runtime.c for default hydrophobicity scale! (5) Twenty standard residues are used to calculate the average hydrophobicity value: ASX, GLX and UNK are not used. ========includes:============================================================*/ #include #include #include "defines.h" /*======return hydrophobicity or requested reference value:==================*/ double Hydrophobicity_ (char *residue_nameP, int scaleI, int requestI) { double hydrophobicity; static char amino_acidAA[23][4] = {"ALA","ARG","ASN","ASP","CYS","GLN","GLU","GLY","HIS","ILE", "LEU","LYS","MET","PHE","PRO","SER","THR","TRP","TYR","VAL", "ASX","GLX","UNK"}; static double hyphob_scaleAA[SCALESN][23] = /* 0: White & Wimley octanol scale, OCT (was WHI before): */ {{-0.50,-1.81,-0.85,-3.64, 0.02,-0.77,-3.63,-1.15,-0.11, 1.12, 1.25,-2.80, 0.67, 1.71,-0.14,-0.46,-0.25, 2.09, 0.71, 0.46, -2.25,-2.20,-0.40}, /* Note: HIS is neutral! */ /* 1: Kyte & Doolittle hydropathy scale, KD: */ { 1.80,-4.50,-3.50,-3.50, 2.50,-3.50,-3.50,-0.40,-3.20, 4.50, 3.80,-3.90, 1.90, 2.80,-1.60,-0.80,-0.70,-0.90,-1.30, 4.20, -3.50,-3.50,-0.49}, /* 2: Eisenberg normalized consensus scale, EIS: */ { 0.62,-2.53,-0.78,-0.90, 0.29,-0.85,-0.74, 0.48,-0.40, 1.38, 1.06,-1.50, 0.64, 1.19, 0.12,-0.18,-0.05, 0.81, 0.26, 1.08, -0.84,-0.80, 0.00}, /* 3: White & Wimley interface scale, HIS neutral, INT: */ {-0.17,-0.81,-0.42,-1.23, 0.24,-0.58,-2.02,-0.01,-0.17, 0.31, 0.56,-0.99, 0.23, 1.13,-0.45,-0.13,-0.14, 1.85, 0.94,-0.07, -0.83,-1.30,-0.10}, /* Note: HIS is neutral! */ /* 4: Interface scale, HIS, ASP and GLU neutral, IN2: */ {-0.17,-0.81,-0.42,-0.07,-0.24,-0.58, 0.01,-0.01,-0.17, 0.31, 0.56,-0.99, 0.23, 1.13,-0.45,-0.13,-0.14, 1.85, 0.94,-0.07, -0.25,-0.30, 0.04}, /* Note: HIS, ASP and GLU are neutral! */ /* 5: Differential scale, OCT-INT, HIS neutral, DIF: */ {-0.33,-1.00,-0.43,-2.41,-0.22,-0.19,-1.61,-1.14, 0.06, 0.81, 0.69,-1.81, 0.44, 0.58, 0.31,-0.33,-0.11, 0.24,-0.23, 0.53, -1.38,-0.90,-0.31}}; /*-----------------------------------*/ /* OCT KD EIS INT IN2 DIF */ /*-----------------------------------*/ /* 0 1 2 3 4 5 */ /*-----------------------------------*/ static double min_hyphobA[SCALESN] = {-3.64,-4.50,-2.53,-2.02,-0.99,-2.41}; static double max_hyphobA[SCALESN] = { 2.09, 4.50, 1.38, 1.85, 1.85, 0.81}; static double average_hyphobA[SCALESN] = {-0.40,-0.49, 0.00,-0.10, 0.04,-0.31}; static double threshold_hyphobA[SCALESN] = { 0.00, 0.00,-0.16, 0.00, 0.00, 0.00}; int i; /* Check scale index: */ if (scaleI >= SCALESN) return 0.0; /* If minimal hydrophobicity is requested: */ if (requestI == 1) return min_hyphobA[scaleI]; /* If maximal hydrophobicity is requiested: */ else if (requestI == 2) return max_hyphobA[scaleI]; /* If average hydrophobicity is requested: */ else if (requestI == 3) return average_hyphobA[scaleI]; /* If threshold hydrophobicity is requested: */ else if (requestI == 4) return threshold_hyphobA[scaleI]; /* If this point is reached, hydrophobicity */ /* of the specified residue is requested. */ /* Use average value as default; it will */ /* be returned if identification fails: */ hydrophobicity = average_hyphobA[scaleI]; /* Compare the purified residue name with 23 standard names: */ for (i = 0; i < 23; i++) { /* If amino acid is recognized: */ if (strcmp (residue_nameP, amino_acidAA[i]) == 0) { hydrophobicity = hyphob_scaleAA[scaleI][i]; break; } } /* Return hydrophobicity value: */ return hydrophobicity; } /*===========================================================================*/ garlic-1.6/select_atoms.c0000644000076500007650000001106107647334220015743 0ustar zuciczucic00000000000000/* Copyright (C) 2001-2003 Damir Zucic */ /*============================================================================= select_atoms.c Purpose: Try to interpret the selection string as the request to select one or more atoms. Atomic serial numbers are used to specify atoms. Selection modes: 0 = overwrite, 1 = restrict, 2 = expand the previous selection. This function expects that the second token in the command line is the keyword ATOM (short version is ATO). If it is not found, the function will return negative value. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. (3) Pointer to RuntimeS structure. (4) The selection string. (5) Selection mode index (0 = overwr., 1 = restrict, 2 = expand). Output: (1) The flag selectedF will be equal to one for selected atoms and equal to zero for all other atoms. (2) Return value. Return value: (1) The number of selected atoms, if selection is done in this function. (2) Negative value on failure. Notes: (1) If there are two atoms with the same serial number, both atoms will be selected. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "commands.h" #include "typedefs.h" /*======function prototypes:=================================================*/ char *ExtractToken_ (char *, int, char *, char *); int ExtractSerials_ (int *, int *, char *); /*======select atom(s) by serial number(s):==================================*/ long SelectAtoms_ (MolComplexS *mol_complexSP, int mol_complexesN, RuntimeS *runtimeSP, char *stringP, int selection_modeI) { long selected_atomsN = 0; char *remainderP; char tokenA[SHORTSTRINGSIZE]; int max; int n1, n2; int start_atomIA[MAXFIELDS], end_atomIA[MAXFIELDS]; int rangeI = 0, rangesN; int mol_complexI; MolComplexS *curr_mol_complexSP; size_t atomsN, atomI; AtomS *curr_atomSP; int serial_numberF; int serialI; int startI, endI; /* Extract the first token and check it (search for substring ATO): */ remainderP = ExtractToken_ (tokenA, STRINGSIZE, stringP, " \t\n"); if (!strstr (tokenA, "ATO")) return (long) -1; /* Parse the list of ranges: */ max = SHORTSTRINGSIZE; while ((remainderP = ExtractToken_ (tokenA, max, remainderP, " \t,;")) != NULL) { /* Extract serial numbers: */ if (ExtractSerials_ (&n1, &n2, tokenA) < 0) return (long) -2; /* Copy serial numbers: */ start_atomIA[rangeI] = n1; end_atomIA[rangeI] = n2; /* Increment and check the number of ranges: */ rangeI++; if (rangeI >= MAXFIELDS) break; } /* Store the number of ranges: */ rangesN = rangeI; /* Scan every macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check is the current macromolecular complex caught: */ if (curr_mol_complexSP->catchF == 0) continue; /* Number of atoms in a macromolecular complex: */ atomsN = curr_mol_complexSP->atomsN; /* Scan all atoms in the current complex: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Copy the serial number of the current atom: */ serialI = curr_atomSP->raw_atomS.serialI; /* Reset the flag: */ serial_numberF = 0; /* Scan all ranges and check the atomic serial number: */ for (rangeI = 0; rangeI < rangesN; rangeI++) { startI = start_atomIA[rangeI]; endI = end_atomIA[rangeI]; if ((serialI >= startI) && (serialI <= endI)) { serial_numberF = 1; break; } } /* Set the selection flag for the current atom: */ switch (selection_modeI) { /* Overwrite the previous selection: */ case 0: curr_atomSP->selectedF = serial_numberF; break; /* Restrict the previous selection: */ case 1: curr_atomSP->selectedF &= serial_numberF; break; /* Expand the previous selection: */ case 2: curr_atomSP->selectedF |= serial_numberF; break; default: ; } /* Check the selection flag; increase */ /* the count if flag is equal to one: */ if (curr_atomSP->selectedF) selected_atomsN++; } /* Update the position_changedF: */ curr_mol_complexSP->position_changedF = 1; } /* Return the number of selected atoms: */ return selected_atomsN; } /*===========================================================================*/ garlic-1.6/half_stick.c0000644000076500007650000005106207604152670015375 0ustar zuciczucic00000000000000/* Copyright (C) 2002 Damir Zucic */ /*============================================================================= half_stick.c Purpose: Draw half of a stick. Input: (1) Pointer to Aux2S structure, which contains required data. (2) Bond index. Output: (1) Half of a stick drawn. (2) Return value. Return value: (1) Positive on success. (2) Negative on failure. Notes: (1) The stick is drawn circle by circle. Only one half of each circle is drawn, because it is assumed that another side of the circle is invisible to the observer. The rear side of the stick is not drawn! (2) Indentation is exceptionally 4 spaces. =============================================================================*/ #include #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ double AbsoluteValue_ (VectorS *); double ScalarProduct_ (VectorS *, VectorS *); void VectorProduct_ (VectorS *, VectorS *, VectorS *); unsigned long SpacefillColor_ (AtomS *, GUIS *, double); unsigned long Sp2Color_ (AtomS *, GUIS *, double); unsigned long WeightColors_ (unsigned long, unsigned long, double, GUIS *); /*======draw half of a stick:================================================*/ int HalfStick_ (Aux2S *aux2SP, int bondI) { static int imageI; static int image_center_screen_x, image_center_screen_y; static int left_edge, right_edge, bottom_edge; static double screen_atomic_z; static double nominator_x, nominator_y; static RawAtomS *raw_atom1SP, *raw_atom2SP; static double user_screen_atomic_distance; static double atomic_to_screen_scale; static double user_atomic_position; static VectorS *light_vectorSP; static int atom1_styleI, atom2_styleI; double r1, r2; static AtomS *far_atomSP; static double far_radius, far_z; static double denominator, reciprocal_denominator; static double pixel_atomic_size; double d0, u0, u0min, u0max, stick_radius; double delta_x, delta_y, delta_z; VectorS start_vectorS, end_vectorS; static VectorS unit_vector0S, unit_vector1S, unit_vector2S; static VectorS aux_vector0S, aux_vector1S; static double abs_value, reciprocal_abs_value; static double linear_increment, double_linear_increment; static double angular_increment; static double reciprocal_delta_u0; static double scale_factor; static double circle_x0, circle_y0, circle_z0; static double projection_factor_x, projection_factor_y; static double rationalized_x, rationalized_y; static int circle_screen_x0, circle_screen_y0; double angle, cos_angle, sin_angle; static double surface_offset_1, surface_offset_2; static double surface_offset_x, surface_offset_y, surface_offset_z; static double surface_x, surface_y, surface_z; static int surface_screen_x, surface_screen_y; static size_t pixelI; static NearestAtomS *curr_pixelSP; static int drawF; static double shifted_z; static VectorS normal_vectorS; static double normal_abs_value; static double scalar_product; static double cos_light_angle; static unsigned long colorID; static int localI; static int pixel_screen_x, pixel_screen_y; static int pixel_shift_xA[4] = { 0, 1, 0, 1}; static int pixel_shift_yA[4] = { 0, 0, 1, 1}; /*---------------------------------------------------------------------------*/ /* Copy some data and prepare some parameters. */ /* Image index: */ imageI = aux2SP->imageI; /* Image center, in screen units: */ image_center_screen_x = aux2SP->configSP->center_screen_x[imageI]; image_center_screen_y = aux2SP->configSP->center_screen_y; /* Bounding rectangle: */ left_edge = aux2SP->configSP->image_screen_x0[imageI]; right_edge = aux2SP->configSP->image_screen_x1[imageI]; bottom_edge = (int) aux2SP->guiSP->main_win_free_area_height; /* Screen position, in atomic units: */ screen_atomic_z = aux2SP->configSP->screen_atomic_z; /* Prepare two factors which are required for scaling: */ nominator_x = aux2SP->configSP->user_screen_atomic_distance * aux2SP->configSP->atomic_to_screen_scale_x; nominator_y = aux2SP->configSP->user_screen_atomic_distance * aux2SP->configSP->atomic_to_screen_scale_y; /* Pointers to raw atomic data: */ raw_atom1SP = &aux2SP->atom1SP->raw_atomS; raw_atom2SP = &aux2SP->atom2SP->raw_atomS; /* Both atoms should be on the opposite side of */ /* the screen, with respect to the observer: */ if (raw_atom1SP->z[imageI] < screen_atomic_z) return -1; if (raw_atom2SP->z[imageI] < screen_atomic_z) return -2; /* Distance between user and screen, in atomic units: */ user_screen_atomic_distance = aux2SP->configSP->user_screen_atomic_distance; /* The scale factor required for conversion from atomic to */ /* screen units. There are originally two such factors. Use */ /* the larger one here because it goes to denominator. */ if (aux2SP->configSP->atomic_to_screen_scale_x > aux2SP->configSP->atomic_to_screen_scale_y) { atomic_to_screen_scale = aux2SP->configSP->atomic_to_screen_scale_x; } else atomic_to_screen_scale = aux2SP->configSP->atomic_to_screen_scale_y; /* User position in atomic units: */ user_atomic_position = aux2SP->configSP->user_atomic_position; /* Pointer to the light source vector: */ light_vectorSP = &aux2SP->configSP->light_vectorS; /* Copy the drawing style of the first atom: */ atom1_styleI = raw_atom1SP->atom_styleI; /* Copy the drawing style of the second atom: */ atom2_styleI = raw_atom2SP->atom_styleI; /* Copy and check the bond length: */ d0 = aux2SP->curr_bondSP->bond_length; if (d0 <= 0.001) return -9; /* The range of the variable u0, which scans half of the bond: */ u0min = 0.0; u0max = 0.5 * d0; /* Stick radius: */ stick_radius = aux2SP->stick_radius; /*---------------------------------------------------------------------------*/ /* Copy and check the atomic radii. Two atoms forming the bond */ /* should be drawn using some sort of spacefill drawing style. */ /* Radius of the first atom (the current bond belongs to this atom): */ if ((atom1_styleI == SPACEFILL) || (atom1_styleI == SPACEFILL2)) { r1 = raw_atom1SP->radius; } else if ((atom1_styleI == COVALENT) || (atom1_styleI == COVALENT2)) { r1 = raw_atom1SP->covalent_radius; } else if ((atom1_styleI == SMALL_ATOM) || (atom1_styleI == SMALL_ATOM2)) { r1 = raw_atom1SP->small_radius; } else if ((atom1_styleI == BIG_SPHERE) || (atom1_styleI == BIG_SPHERE2)) { r1 = raw_atom1SP->van_der_Waals_radius; } else if ((atom1_styleI == BALL) || (atom1_styleI == BALL2)) { r1 = raw_atom1SP->ball_radius; } else return -3; /* Radius of the second atom (the bond partner of the first atom): */ if ((atom2_styleI == SPACEFILL) || (atom2_styleI == SPACEFILL2)) { r2 = raw_atom2SP->radius; } else if ((atom2_styleI == COVALENT) || (atom2_styleI == COVALENT2)) { r2 = raw_atom2SP->covalent_radius; } else if ((atom2_styleI == SMALL_ATOM) || (atom2_styleI == SMALL_ATOM2)) { r2 = raw_atom2SP->small_radius; } else if ((atom2_styleI == BIG_SPHERE) || (atom2_styleI == BIG_SPHERE2)) { r2 = raw_atom2SP->van_der_Waals_radius; } else if ((atom2_styleI == BALL) || (atom2_styleI == BALL2)) { r2 = raw_atom2SP->ball_radius; } else return -4; /*---------------------------------------------------------------------------*/ /* Now estimate the size (in atomic units) of the pixel which */ /* represents the most distant point. This point belongs to */ /* the atom (i.e. sphere) which is farther from the observer. */ /* The atom with higher z value is treated as the farther one. */ /* Find which atom has higher z value (in most cases, but */ /* not always, this atom is farther from the observer): */ if (raw_atom2SP->z[imageI] > raw_atom1SP->z[imageI]) { far_atomSP = aux2SP->atom2SP; far_radius = r2; } else { far_atomSP = aux2SP->atom1SP; far_radius = r1; } /* Find the z coordinate of the most distant point: */ far_z = far_atomSP->raw_atomS.z[imageI] + far_radius; /* Check is this point on the opposite side of */ /* the screen, with respect to the observer. */ /* If it is, the entire bond will be invisible. */ if (far_z < screen_atomic_z) return -6; /* Prepare denominator required to calculate */ /* the atomic size of the most distant pixel: */ denominator = user_screen_atomic_distance * atomic_to_screen_scale; if (denominator <= 0.001) return -7; /* The size of the most distant pixel in atomic units: */ pixel_atomic_size = 1.0 * (far_z - user_atomic_position) / denominator; /*---------------------------------------------------------------------------*/ /* Find the start point and the end point, which define the bond axis. */ /* Distance between two atoms which form the bond (three components): */ delta_x = raw_atom2SP->x[imageI] - raw_atom1SP->x[imageI]; delta_y = raw_atom2SP->y - raw_atom1SP->y; delta_z = raw_atom2SP->z[imageI] - raw_atom1SP->z[imageI]; /* Prepare the start point: */ start_vectorS.x = raw_atom1SP->x[imageI]; start_vectorS.y = raw_atom1SP->y; start_vectorS.z = raw_atom1SP->z[imageI]; /* Prepare the end point: */ end_vectorS.x = 0.5 * (raw_atom1SP->x[imageI] + raw_atom2SP->x[imageI]); end_vectorS.y = 0.5 * (raw_atom1SP->y + raw_atom2SP->y); end_vectorS.z = 0.5 * (raw_atom1SP->z[imageI] + raw_atom2SP->z[imageI]); /* Both points should be on the opposite side */ /* of the screen, with respect to the observer: */ if (start_vectorS.z < screen_atomic_z) return -13; if ( end_vectorS.z < screen_atomic_z) return -14; /*---------------------------------------------------------------------------*/ /* Prepare three unit vectors, required for angular scan. These */ /* three vectors define the plane, required to define the circle. */ /* Prepare the unit vector pointing from the start point to the end point: */ unit_vector0S.x = end_vectorS.x - start_vectorS.x; unit_vector0S.y = end_vectorS.y - start_vectorS.y; unit_vector0S.z = end_vectorS.z - start_vectorS.z; abs_value = AbsoluteValue_ (&unit_vector0S); if (abs_value <= 0.001) return -15; reciprocal_abs_value = 1.0 / abs_value; unit_vector0S.x *= reciprocal_abs_value; unit_vector0S.y *= reciprocal_abs_value; unit_vector0S.z *= reciprocal_abs_value; /* Prepare the unit vector parallel to z axis: */ aux_vector0S.x = 0.0; aux_vector0S.y = 0.0; aux_vector0S.z = 1.0; /* Check the absolute value of the vector product between unit_vector0S */ /* and aux_vector0S; if the absolute value is too small, use aux_vector0S */ /* perpendicular to z axis (the vector parallel to x axis will be good): */ VectorProduct_ (&aux_vector1S, &unit_vector0S, &aux_vector0S); abs_value = AbsoluteValue_ (&aux_vector1S); if (abs_value < 0.001) { aux_vector0S.x = 1.0; aux_vector0S.y = 0.0; aux_vector0S.z = 0.0; } /* Prepare the unit vector perpendicular to unit_vector0S */ /* and to z axis. This is the first vector required to */ /* define the plane, which is used to define the circle. */ VectorProduct_ (&unit_vector1S, &unit_vector0S, &aux_vector0S); abs_value = AbsoluteValue_ (&unit_vector1S); reciprocal_abs_value = 1.0 / abs_value; unit_vector1S.x *= reciprocal_abs_value; unit_vector1S.y *= reciprocal_abs_value; unit_vector1S.z *= reciprocal_abs_value; /* Prepare the second unit vector required to define the plane: */ VectorProduct_ (&unit_vector2S, &unit_vector0S, &unit_vector1S); /*---------------------------------------------------------------------------*/ /* Prepare the linear increment. This variable should be used as */ /* the maximal translational step, to prevent holes in the surface. */ /* The linear increment should be smaller than pixel size: */ linear_increment = 0.70 * pixel_atomic_size; double_linear_increment = 2.0 * linear_increment; /* Check the distance between the start point and end point. */ /* The curved surface will be drawn only if this distance is */ /* at least three times larger than the linear increment. */ if (u0max - u0min < 3.0 * linear_increment) return -16; /*---------------------------------------------------------------------------*/ /* Prepare the angular increment. This variable should be used as */ /* the maximal angular step, to prevent holes in the surface. */ /* Calculate the angular increment, in radians: */ if (stick_radius <= 0.001) return -17; angular_increment = 0.70 * linear_increment / stick_radius; /* Be sure that the angular increment is not larger than PI/4: */ if (angular_increment > 0.78539816) angular_increment = 0.78539816; /*---------------------------------------------------------------------------*/ /* Draw half of the bond. */ /* Prepare some factors which are used to */ /* reduce the number of multiplications: */ delta_x = end_vectorS.x - start_vectorS.x; delta_y = end_vectorS.y - start_vectorS.y; delta_z = end_vectorS.z - start_vectorS.z; reciprocal_delta_u0 = 1.0 / (u0max - u0min); /* Loop which scans the variable u0 (see nice_bonds.c for definition): */ for (u0 = u0min; u0 <= u0max; u0 += linear_increment) { /* Calculate the position of the point on the axis, */ /* defined by u0. This point is the circle center. */ scale_factor = (u0 - u0min) * reciprocal_delta_u0; circle_x0 = start_vectorS.x + delta_x * scale_factor; circle_y0 = start_vectorS.y + delta_y * scale_factor; circle_z0 = start_vectorS.z + delta_z * scale_factor; /* Prepare the reciprocal denominator, used to */ /* reduce the number of mathematical operations: */ denominator = circle_z0 - user_atomic_position; if (denominator <= 0.001) continue; reciprocal_denominator = 1.0 / denominator; /* Prepare two factors required for projection: */ projection_factor_x = nominator_x * reciprocal_denominator; projection_factor_y = nominator_y * reciprocal_denominator; /* Project the position of the circle center. Note that */ /* two different projection factors are used here! */ rationalized_x = circle_x0 * projection_factor_x; rationalized_y = circle_y0 * projection_factor_y; circle_screen_x0 = (int) rationalized_x + image_center_screen_x; circle_screen_y0 = (int) rationalized_y + image_center_screen_y; /* The angular loop, required to create the rotational surface: */ for (angle = 0.0; angle <= 6.2831853; angle += angular_increment) { /* Cosine and sine of the angle: */ cos_angle = cos (angle); sin_angle = sin (angle); /* Relative position of the point at the */ /* surface with respect to the circle center: */ surface_offset_1 = stick_radius * cos_angle; surface_offset_2 = stick_radius * sin_angle; surface_offset_x = surface_offset_1 * unit_vector1S.x + surface_offset_2 * unit_vector2S.x; surface_offset_y = surface_offset_1 * unit_vector1S.y + surface_offset_2 * unit_vector2S.y; surface_offset_z = surface_offset_1 * unit_vector1S.z + surface_offset_2 * unit_vector2S.z; /* Calculate the coordinates of the point at bond surface: */ surface_x = circle_x0 + surface_offset_x; surface_y = circle_y0 + surface_offset_y; surface_z = circle_z0 + surface_offset_z; /* The vector from the point at the surface */ /* to the center of the spherical probe: */ normal_vectorS.x = surface_offset_x; normal_vectorS.y = surface_offset_y; normal_vectorS.z = surface_offset_z; /* If this vector has a positive z component, */ /* do not draw this point because it is not on */ /* the side which is visible for the observer: */ if (normal_vectorS.z >= 0.0) continue; /* Calculate the absolute value of this vector: */ normal_abs_value = AbsoluteValue_ (&normal_vectorS); /* Project the relative position of surface point. Note */ /* that projection_factor_x is used in both equations! */ rationalized_x = surface_offset_x * projection_factor_x; rationalized_y = surface_offset_y * projection_factor_x; /* Combine the projection of the circle */ /* center and projection of the relative */ /* position of the point at the surface: */ surface_screen_x = (int) rationalized_x + circle_screen_x0; surface_screen_y = (int) rationalized_y + circle_screen_y0; /* Prepare the color. */ /* The scalar product between the normal */ /* vector and the light source vector: */ scalar_product = ScalarProduct_ (&normal_vectorS, light_vectorSP); /* Cosine of the angle between the normal */ /* vector and the light source unit vector: */ if (normal_abs_value <= 0.001) cos_light_angle = 0.0; else cos_light_angle = scalar_product / normal_abs_value; /* Prepare color: */ switch (atom1_styleI) { case SPACEFILL: case COVALENT: case SMALL_ATOM: case BIG_SPHERE: case BALL: colorID = SpacefillColor_ (aux2SP->atom1SP, aux2SP->guiSP, cos_light_angle); break; case SPACEFILL2: case COVALENT2: case SMALL_ATOM2: case BIG_SPHERE2: case BALL2: colorID = Sp2Color_ (aux2SP->atom1SP, aux2SP->guiSP, cos_light_angle); break; default: colorID = aux2SP->guiSP->white_colorID; } /* Set color to GC: */ XSetForeground (aux2SP->guiSP->displaySP, aux2SP->guiSP->theGCA[0], colorID); /* Draw four pixels: */ for (localI = 0; localI < 4; localI++) { /* Prepare and check the pixel position: */ pixel_screen_x = surface_screen_x + pixel_shift_xA[localI]; pixel_screen_y = surface_screen_y + pixel_shift_yA[localI]; if (pixel_screen_x < 0) continue; if (pixel_screen_x < left_edge) continue; if (pixel_screen_x >= right_edge) continue; if (pixel_screen_y < 0) continue; if (pixel_screen_y >= bottom_edge) continue; /* Prepare and check the index for the */ /* array of NearestAtomS structures: */ pixelI = aux2SP->guiSP->main_win_free_area_width * pixel_screen_y + pixel_screen_x; if (pixelI >= aux2SP->pixelsN) continue; /* Pointer to NearestAtomS struct. */ /* assigned to the current pixel: */ curr_pixelSP = aux2SP->nearest_atomSP + pixelI; /*------------------------------------------------------------*/ /* There are three cases when this pixel should be drawn: */ /* (1) Nothing was drawn to this pixel in this drawing step. */ /* (2) Drawing was done but the point at the bond surface is */ /* closer to the observer than the point drawn before. */ /* (3) Drawing was done and the point at the bond surface is */ /* more distant than the point drawn before. However, the */ /* pixel belongs to the atom to which this bond belongs */ /* and the z coordinate of the point at the bond surface */ /* is just slightly larger than the stored z value. */ /*------------------------------------------------------------*/ /* Assume initially that drawing is not necessary: */ drawF = 0; /* Check for the cases when drawing is necessary: */ do { /* Case (1) - no drawing was done before: */ if (aux2SP->refreshI != curr_pixelSP->last_refreshI) { drawF = 1; break; } /* If this point is reached, drawing was done before. */ /* Case (2): drawing was done before, but the point at the */ /* bond surface is closer than the point drawn before. */ if (surface_z < curr_pixelSP->z) { drawF = 1; break; } /* Now check the conditions for the case (3): */ /* The pixel should belong to the surface of the atom: */ if (curr_pixelSP->bondI != -1) break; /* The pixel should belong to the */ /* same atom and macromol. complex: */ if (curr_pixelSP->mol_complexI != aux2SP->mol_complexI) break; if (curr_pixelSP->atomI != aux2SP->atomI) break; /* If z is too large, no drawing will be done: */ shifted_z = curr_pixelSP->z + 2.0 * pixel_atomic_size; if (surface_z > shifted_z) break; /* Case (3): all conditions were satisfied. */ drawF = 1; /* End of inner single pass loop: */ } while (0); /* Check is drawing necessary at all: */ if (drawF == 0) continue; /* Draw the current pixel: */ XDrawPoint (aux2SP->guiSP->displaySP, aux2SP->guiSP->main_hidden_pixmapID, aux2SP->guiSP->theGCA[0], pixel_screen_x, pixel_screen_y); /* Refresh the NearestAtomS structure */ /* associated with the current pixel: */ curr_pixelSP->styleI = atom1_styleI; curr_pixelSP->last_refreshI = aux2SP->refreshI; curr_pixelSP->mol_complexI = aux2SP->mol_complexI; curr_pixelSP->atomI = aux2SP->atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = surface_z; curr_pixelSP->colorID = colorID; } } } /*---------------------------------------------------------------------------*/ /* If this point is reached, the entire bond was drawn: */ return 1; } /*===========================================================================*/ garlic-1.6/patterns.script0000644000076500007650000000100207662361232016175 0ustar zuciczucic00000000000000# 2003/04/22 load 2por.pdb sel all backbone 2 color white pattern tolerance 0 pattern = asp glu asn gln arg lys / * / asp glu asn gln arg lys / * / tyr phe trp / * / * / * / tyr phe trp select pattern color red pattern = asp glu asn gln arg lys / * / asp glu asn gln arg lys / * / tyr phe tr p / * / * / * / * / * / tyr phe trp select pattern color green pattern = asp glu asn gln arg lys / * / asp glu asn gln arg lys / * / tyr phe tr p / * / * / * / * / * / * / * / tyr phe trp select pattern color blue garlic-1.6/covalent2.c0000644000076500007650000003141207747302001015151 0ustar zuciczucic00000000000000/* Copyright (C) 2002-2003 Damir Zucic */ /*============================================================================= covalent2.c Purpose: Draw atoms as spheres (covalent style, version 2). Input: (1) Pointer to MolComplexS structure. (2) Number of macromolecular complexes. (3) Pointer to ConfigS structure, with configuration data. (4) Pointer to GUIS structure. (5) Pointer to NearestAtomS structure, with information about the atom occupying the given pixel. (6) The number of pixels in the main window free area. (7) The refreshI, used to check the NearestAtomS associated with a given pixel. Output: (1) Spheres drawn to the hidden pixmap. (2) Return value. Return value: (1) Positive always (trivial). Notes: (1) Indentation is exceptionally 4 spaces. =============================================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ unsigned long Sp2Color_ (AtomS *, GUIS *, double); /*======draw atoms as spheres, covalent style version 2:=====================*/ int DrawCovalent2_ (MolComplexS *mol_complexSP, int mol_complexesN, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int refreshI) { int imageI, imagesN; double scale_factor, user_atomic_position; int left_edge[2], right_edge[2]; int mol_complexI; MolComplexS *curr_mol_complexSP; size_t atomsN, atomI; AtomS *curr_atomSP; int screen_x0, screen_y0; double radius, radius_squared; double denominator, reciprocal_denominator; int screen_radius; long screen_radius_squared; int screen_x1, screen_y1, screen_x2, screen_y2; int screen_x, screen_y; long delta_x, delta_y, distance_squared; double z0, front_z, delta_z, z; size_t pixelI; NearestAtomS *curr_pixelSP; double denominator2, reciprocal_denominator2; double rho_squared; VectorS vectorS; double abs_value, abs_value_squared; double scalar_product, cos_angle; unsigned long colorID; int bondI; /* Initialize the bond index. The negative value means that pixels */ /* filled in this function are not a part of any chemical bond. */ bondI = -1; /* Number of images: */ if (configSP->stereoF) imagesN = 2; else imagesN = 1; /* The auxiliary scale factor: */ scale_factor = configSP->user_screen_atomic_distance * configSP->atomic_to_screen_scale_x; /* Prepare the user position in atomic coordinates: */ user_atomic_position = configSP->user_atomic_position; /* Left and right image edge (in stereo mode there are two images): */ left_edge[0] = configSP->image_screen_x0[0]; right_edge[0] = configSP->image_screen_x1[0]; left_edge[1] = configSP->image_screen_x0[1]; right_edge[1] = configSP->image_screen_x1[1]; /*------first pass - fill NearestAtomS array with planar atoms:--------------*/ /* Draw each macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Prepare and check the number of atoms: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Draw atoms which have the given style: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Check style: */ if (curr_atomSP->raw_atomS.atom_styleI != COVALENT2) continue; /* Check is atom hidden: */ if (curr_atomSP->hiddenF) continue; /* Check is atom inside slab: */ if (!curr_atomSP->inside_slabF) continue; /* Check is atom inside window: */ if (!curr_atomSP->inside_windowF) continue; /* Covalent radius, in atomic units: */ radius = curr_atomSP->raw_atomS.covalent_radius; /* The y coordinate of atomic center, in screen units: */ screen_y0 = curr_atomSP->raw_atomS.screen_y; /* Prepare one image (mono) or two images (stereo): */ for (imageI = 0; imageI < imagesN; imageI++) { /* The z coordinate of atomic center, in atomic units: */ z0 = curr_atomSP->raw_atomS.z[imageI]; /* Prepare the factor required for the projection of radius: */ denominator = z0 - user_atomic_position; if (denominator == 0.0) continue; reciprocal_denominator = 1.0 / denominator; /* Covalent radius in screen units: */ screen_radius = (int) (radius * scale_factor * reciprocal_denominator + 0.5); /* Screen radius squared (used to improve speed): */ screen_radius_squared = (long) screen_radius * (long) screen_radius; /* The x coordinate of atomic center, in screen units: */ screen_x0 = curr_atomSP->raw_atomS.screen_x[imageI]; /* Define the bounding rectangle: */ screen_x1 = screen_x0 - screen_radius; screen_y1 = screen_y0 - screen_radius; screen_x2 = screen_x0 + screen_radius; screen_y2 = screen_y0 + screen_radius; /* Horizontal scan: */ for (screen_x = screen_x1; screen_x <= screen_x2; screen_x++) { /* Check horizontal position: */ if (screen_x < left_edge[imageI]) continue; if (screen_x >= right_edge[imageI]) continue; /* Vertical scan: */ for (screen_y = screen_y1; screen_y <= screen_y2; screen_y++) { /* Check vertical position: */ if (screen_y < 0) continue; if (screen_y >= (int) guiSP->main_win_free_area_height) { continue; } /* Check distance from the circle center: */ delta_x = (long) (screen_x - screen_x0); delta_y = (long) (screen_y - screen_y0); distance_squared = delta_x * delta_x + delta_y * delta_y; if (distance_squared > screen_radius_squared) continue; /* Prepare index to the array */ /* of NearestAtomS structures: */ pixelI = guiSP->main_win_free_area_width * screen_y + screen_x; /* Check the pixel index: */ if (pixelI >= pixelsN) continue; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = nearest_atomSP + pixelI; /* Check was this pixel used already in */ /* this drawing step; if it was, compare */ /* the z value of the current atom with z */ /* value previously stored to this pixel: */ if (refreshI == curr_pixelSP->last_refreshI) { if (z0 > curr_pixelSP->z) continue; } /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = COVALENT2; curr_pixelSP->last_refreshI = refreshI; curr_pixelSP->mol_complexI = mol_complexI; curr_pixelSP->atomI = atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = z0; } } } /* imageI loop */ } /* atomI loop */ } /* mol_complexI loop */ /*------second pass - draw spherical atoms:----------------------------------*/ /* Draw each macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Prepare and check the number of atoms: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Draw atoms which have the given style: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Check style: */ if (curr_atomSP->raw_atomS.atom_styleI != COVALENT2) continue; /* Check is atom hidden: */ if (curr_atomSP->hiddenF) continue; /* Check is atom inside slab: */ if (!curr_atomSP->inside_slabF) continue; /* Check is atom inside window: */ if (!curr_atomSP->inside_windowF) continue; /* Covalent radius, in atomic units: */ radius = curr_atomSP->raw_atomS.covalent_radius; /* Squared covalent radius: */ radius_squared = radius * radius; /* The y coordinate of atomic center, in screen units: */ screen_y0 = curr_atomSP->raw_atomS.screen_y; /* Prepare one image (mono) or two images (stereo): */ for (imageI = 0; imageI < imagesN; imageI++) { /* The z coordinate of atomic center, in atomic units: */ z0 = curr_atomSP->raw_atomS.z[imageI]; /* The z coordinate of the nearest */ /* point of a given atom (sphere): */ front_z = z0 - radius; /* Prepare the factor required for the projection of radius: */ denominator = z0 - user_atomic_position; if (denominator == 0.0) continue; reciprocal_denominator = 1.0 / denominator; /* Covalent radius in screen units: */ screen_radius = (int) (radius * scale_factor * reciprocal_denominator + 0.5); /* Square of the covalent radius (in screen units): */ screen_radius_squared = (long) screen_radius * (long) screen_radius; /* Reciprocal value will be used to improve performance: */ denominator2 = (double) screen_radius_squared; if (denominator2 == 0.0) continue; reciprocal_denominator2 = 1.0 / denominator2; /* The x coordinate of atomic center, in screen units: */ screen_x0 = curr_atomSP->raw_atomS.screen_x[imageI]; /* Define the bounding rectangle: */ screen_x1 = screen_x0 - screen_radius; screen_y1 = screen_y0 - screen_radius; screen_x2 = screen_x0 + screen_radius; screen_y2 = screen_y0 + screen_radius; /* Horizontal scan: */ for (screen_x = screen_x1; screen_x <= screen_x2; screen_x++) { /* Check horizontal position: */ if (screen_x < left_edge[imageI]) continue; if (screen_x > right_edge[imageI]) continue; /* Vertical scan: */ for (screen_y = screen_y1; screen_y <= screen_y2; screen_y++) { /* Check vertical position: */ if (screen_y < 0) continue; if (screen_y >= (int) guiSP->main_win_free_area_height) { continue; } /* Check distance from the circle center: */ delta_x = (long) (screen_x - screen_x0); delta_y = (long) (screen_y - screen_y0); distance_squared = delta_x * delta_x + delta_y * delta_y; if (distance_squared > screen_radius_squared) continue; /* Prepare index to the array */ /* of NearestAtomS structures: */ pixelI = guiSP->main_win_free_area_width * screen_y + screen_x; /* Check the pixel index: */ if (pixelI >= pixelsN) continue; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = nearest_atomSP + pixelI; /* Check z value (this is just a quick check): */ if (refreshI == curr_pixelSP->last_refreshI) { if (front_z > curr_pixelSP->z) continue; } /* Calculate the accurate z value: */ rho_squared = radius_squared * (double) distance_squared * reciprocal_denominator2; delta_z = sqrt (fabs (radius_squared - rho_squared)); z = z0 - delta_z; /* Check z value (precise check): */ if (refreshI == curr_pixelSP->last_refreshI) { if (z > curr_pixelSP->z) continue; } /* The vector from sphere center to the current pixel: */ vectorS.x = (double) delta_x; vectorS.y = (double) delta_y; vectorS.z = - sqrt (fabs (screen_radius_squared - vectorS.x * vectorS.x - vectorS.y * vectorS.y)); abs_value_squared = vectorS.x * vectorS.x + vectorS.y * vectorS.y + vectorS.z * vectorS.z; abs_value = sqrt (abs_value_squared); /* The scalar product between this */ /* vector and light source vector: */ scalar_product = vectorS.x * configSP->light_vectorS.x + vectorS.y * configSP->light_vectorS.y + vectorS.z * configSP->light_vectorS.z; /* Cosine of the angle between the vector to the */ /* current pixel and the light source unit vector: */ if (abs_value == 0.0) cos_angle = 0.0; else cos_angle = scalar_product / abs_value; /* Prepare color: */ colorID = Sp2Color_ (curr_atomSP, guiSP, cos_angle); XSetForeground (guiSP->displaySP, guiSP->theGCA[0], colorID); XDrawPoint (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x, screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = COVALENT2; curr_pixelSP->last_refreshI = refreshI; curr_pixelSP->mol_complexI = mol_complexI; curr_pixelSP->atomI = atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = z; curr_pixelSP->colorID = colorID; } } } /* imageI loop */ } /* atomI loop */ } /* mol_complexI loop */ /*---------------------------------------------------------------------------*/ /* Return positive value (trivial): */ return 1; } /*===========================================================================*/ garlic-1.6/create_windows.c0000644000076500007650000003455210364506421016302 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2006 Damir Zucic */ /*============================================================================= create_windows.c Purpose: Prepare pixmaps, hints, cursors and some other data. After that, create windows, select events and map all windows. Input: (1) Icon pixmap included as garlic.xpm file. (2) Control pixmap included as control.xpm file. (3) Pointer to GUIS structure. Some data will be used as input data, some other will be added. (4) Pointer to ConfigS structure (input only). (5) Number of command line arguments. (6) Command line arguments. Output: (1) Some data stored to GUIS structure. (2) Pixmaps created. (3) Main, icon and control window created. (4) Return value. Return value: (1) Positive on success. (2) Negative on failure. Notes: (1) The width and height of the main window free area are used in this function and in some other functions. To prepare the width, it is necessary to know the control window width. This width is available after the control pixmap is created. To prepare the height, it is necessary to know the input window height. (2) There are two functions which are used to make pixmap. The first function (MakePixmap_, the older version) may be to create and draw pixmap which is associated with some window and the second function (MakePixmap2_) is used to create hidden pixmap which is not associated with any window. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" #include "garlic.xpm" #include "control.xpm" #include "small_arrows.xpm" /*======function prototypes:=================================================*/ void ErrorMessage_ (char *, char *, char *, char *, char *, char *, char *); int MakePixmap_ (WindowS *, GUIS *, char **); int MakePixmap2_ (Pixmap *, unsigned int *, unsigned int *, GUIS *, char **); void SetSizeHints_ (GUIS *, ConfigS *); void SetWMHints_ (GUIS *); void SelectEvents_ (GUIS *); void HideControlWindow_ (GUIS *); /*======create windows (main, icon, control, input and output):==============*/ int CreateWindows_ (GUIS *guiSP, ConfigS *configSP, int argc, char **argv) { int n; XSetWindowAttributes main_attribS, icon_attribS, control_attribS, input_attribS, output_attribS; unsigned long main_value_mask, icon_value_mask, control_value_mask, input_value_mask, output_value_mask; int border_width = 1; /* For all windows! */ static char main_win_titleA[SHORTSTRINGSIZE]; static char icon_win_titleA[SHORTSTRINGSIZE] = "garlic"; char *main_win_titleP, *icon_win_titleP; XTextProperty main_win_titleS, icon_win_titleS; static char prog_nameA[SHORTSTRINGSIZE] = "garlic"; static char class_nameA[SHORTSTRINGSIZE] = "Garlic"; static XClassHint class_hintS; Window rootID; int geom_returnF; int x0, y0; static unsigned int main_wx, main_wy, main_bw, bpp; /*------prepare the main window title:---------------------------------------*/ strcpy (main_win_titleA, "GARLIC 1.6 - Copyright (C) 2000-2006 Damir Zucic"); /*------main window:---------------------------------------------------------*/ /* Set size hints for main window: */ SetSizeHints_ (guiSP, configSP); /* Set main window attributes: */ main_attribS.border_pixel = guiSP->main_winS.fg_colorID; main_attribS.background_pixel = guiSP->main_winS.bg_colorID; main_attribS.cursor = guiSP->main_winS.cursorID; main_attribS.colormap = guiSP->colormapID; main_value_mask = CWBorderPixel | CWBackPixel | CWCursor | CWColormap; /* Copy the border width: */ guiSP->main_winS.border_width = border_width; /* Create the main window (parent is root): */ guiSP->main_winS.ID = XCreateWindow ( guiSP->displaySP, DefaultRootWindow (guiSP->displaySP), guiSP->main_winS.x0, guiSP->main_winS.y0, guiSP->main_winS.width, guiSP->main_winS.height, border_width, guiSP->depth, InputOutput, guiSP->visualSP, main_value_mask, &main_attribS); /* Set the window colormap (is this really necessary?): */ XSetWindowColormap (guiSP->displaySP, guiSP->main_winS.ID, guiSP->colormapID); /*------enable "delete window" command:--------------------------------------*/ /* Enable this program to trap "delete window" command; */ /* this has something to do with win. manager properties. */ /* Try: strings window_manager_name | grep WM_ */ /* The window manager is adding decoration to the main */ /* window; the command "Delete" may be available in the */ /* small popup-window in the top left corner. The lines */ /* below should take care that this message is processed. */ guiSP->delete_window_atom = XInternAtom(guiSP->displaySP, "WM_DELETE_WINDOW", False); guiSP->protocols_atom = XInternAtom(guiSP->displaySP, "WM_PROTOCOLS", False); XChangeProperty(guiSP->displaySP, guiSP->main_winS.ID, guiSP->protocols_atom, XA_ATOM, 32, PropModeReplace, (unsigned char *) &guiSP->delete_window_atom, 1); /*------icon window:---------------------------------------------------------*/ /* Prepare icon pixmap: */ n = MakePixmap_ (&guiSP->icon_winS, guiSP, garlic_xpm); if (n < 0) return -1; /* Set icon window attributes: */ icon_attribS.border_pixel = BlackPixel (guiSP->displaySP, guiSP->screenID); icon_attribS.background_pixmap = guiSP->icon_winS.pixmapID; icon_attribS.colormap = guiSP->colormapID; icon_value_mask = CWBorderPixel | CWBackPixmap | CWColormap; guiSP->icon_winS.x0 = 500; guiSP->icon_winS.y0 = 50; guiSP->icon_winS.border_width = border_width; /* Create the icon window (parent is root here also): */ guiSP->icon_winS.ID = XCreateWindow ( guiSP->displaySP, DefaultRootWindow (guiSP->displaySP), guiSP->icon_winS.x0, guiSP->icon_winS.y0, guiSP->icon_winS.width, guiSP->icon_winS.height, border_width, guiSP->depth, InputOutput, guiSP->visualSP, icon_value_mask, &icon_attribS); /* Set the window colormap (is this necessary?): */ XSetWindowColormap (guiSP->displaySP, guiSP->icon_winS.ID, guiSP->colormapID); /*------control pixmap:------------------------------------------------------*/ /* Prepare control pixmap (from incl. data) and control window dimensions: */ n = MakePixmap_ (&guiSP->control_winS, guiSP, control_xpm); if (n < 0) return -2; /*------input window height:-------------------------------------------------*/ /* Set input window height: */ guiSP->input_winS.height = 2 * guiSP->input_winS.text_line_height + guiSP->input_winS.quarter_font_height; /*------main window free area width and height:------------------------------*/ /* Get the main window geometry: */ geom_returnF = XGetGeometry(guiSP->displaySP, guiSP->main_winS.ID, &rootID, &x0, &y0, &main_wx, &main_wy, &main_bw, &bpp); /* Prepare the main window free area width: */ if (geom_returnF) { n = (int) main_wx - (int) guiSP->control_winS.width - 2 * (int) main_bw - 1; } else { n = (int) guiSP->main_winS.width - (int) guiSP->control_winS.width - 2 * (int) main_bw - 1; } if (n > 0) guiSP->main_win_free_area_width = (unsigned int) n; else guiSP->main_win_free_area_width = 0; /* Prepare the main window free area height: */ if (geom_returnF) { n = (int) main_wy - (int) guiSP->input_winS.height - 2 * (int) main_bw - 1; } else { n = (int) guiSP->main_winS.height - (int) guiSP->input_winS.height - 2 * (int) main_bw - 1; } if (n > 0) guiSP->main_win_free_area_height = (unsigned int) n; else guiSP->main_win_free_area_height = 0; /*------control window:------------------------------------------------------*/ /* Set control window attributes: */ control_attribS.border_pixel = guiSP->control_winS.fg_colorID; control_attribS.background_pixmap = guiSP->control_winS.pixmapID; control_attribS.cursor = guiSP->control_winS.cursorID; control_attribS.win_gravity = NorthEastGravity; control_attribS.colormap = guiSP->colormapID; control_value_mask = CWBorderPixel | CWBackPixmap | CWCursor | CWWinGravity | CWColormap; /* Prepare the control window position: */ guiSP->control_winS.x0 = guiSP->main_win_free_area_width; guiSP->control_winS.y0 = 1; /* Copy the border width: */ guiSP->control_winS.border_width = border_width; /* Create control window: */ guiSP->control_winS.ID = XCreateWindow ( guiSP->displaySP, guiSP->main_winS.ID, guiSP->control_winS.x0, guiSP->control_winS.y0, guiSP->control_winS.width, guiSP->control_winS.height, border_width, CopyFromParent, InputOutput, guiSP->visualSP, control_value_mask, &control_attribS); /* Set the window colormap (is this necessary?): */ XSetWindowColormap (guiSP->displaySP, guiSP->control_winS.ID, guiSP->colormapID); /*------input window:--------------------------------------------------------*/ /* Set input window attributes: */ input_attribS.border_pixel = guiSP->input_winS.fg_colorID; input_attribS.background_pixel = guiSP->input_winS.bg_colorID; input_attribS.cursor = guiSP->input_winS.cursorID; input_attribS.win_gravity = SouthWestGravity; input_attribS.colormap = guiSP->colormapID; input_value_mask = CWBorderPixel | CWBackPixel | CWCursor | CWWinGravity | CWColormap; /* Input window width and position (see above for height): */ guiSP->input_winS.x0 = 1; n = (int) main_wx - (int) guiSP->control_winS.width - 4 * (int) main_bw - 2 * 1 - 2; if (guiSP->main_win_free_area_width >= 10) { guiSP->input_winS.width = guiSP->main_win_free_area_width - 2 * main_bw - 2; } else guiSP->input_winS.width = 10; guiSP->input_winS.y0 = guiSP->main_win_free_area_height; /* Copy the border width: */ guiSP->input_winS.border_width = border_width; /* Create input window: */ guiSP->input_winS.ID = XCreateWindow ( guiSP->displaySP, guiSP->main_winS.ID, guiSP->input_winS.x0, guiSP->input_winS.y0, guiSP->input_winS.width, guiSP->input_winS.height, border_width, CopyFromParent, InputOutput, guiSP->visualSP, input_value_mask, &input_attribS); /* Set the window colormap (is this necessary?): */ XSetWindowColormap (guiSP->displaySP, guiSP->input_winS.ID, guiSP->colormapID); /*------output window:-------------------------------------------------------*/ /* Set output window attributes: */ output_attribS.border_pixel = guiSP->output_winS.fg_colorID; output_attribS.background_pixel = guiSP->input_winS.bg_colorID; output_attribS.cursor = guiSP->output_winS.cursorID; output_attribS.win_gravity = NorthEastGravity; output_value_mask = CWBorderPixel | CWBackPixel | CWCursor | CWWinGravity; /* Output window size and position: */ guiSP->output_winS.width = guiSP->control_winS.width; guiSP->output_winS.x0 = guiSP->control_winS.x0; guiSP->output_winS.y0 = guiSP->control_winS.height + 2 * main_bw + 1 + 2; n = (int) main_wy - guiSP->control_winS.height - 4 * (int) main_bw - 4; if ((n > 0) && (n >= 100)) guiSP->output_winS.height = (unsigned int) n; else guiSP->output_winS.height = 100; /* Copy the border width: */ guiSP->output_winS.border_width = border_width; /* Create input window: */ guiSP->output_winS.ID = XCreateWindow ( guiSP->displaySP, guiSP->main_winS.ID, guiSP->output_winS.x0, guiSP->output_winS.y0, guiSP->output_winS.width, guiSP->output_winS.height, border_width, CopyFromParent, InputOutput, guiSP->visualSP, output_value_mask, &output_attribS); /* Set the window colormap (is this necessary?): */ XSetWindowColormap (guiSP->displaySP, guiSP->input_winS.ID, guiSP->colormapID); /*------additional settings:-------------------------------------------------*/ /* Set window manager hints: */ SetWMHints_ (guiSP); /* Set main window name: */ main_win_titleP = main_win_titleA; if (!XStringListToTextProperty (&main_win_titleP, 1, &main_win_titleS)) { ErrorMessage_ ("garlic", "CreateWindows_", "", "Failed to allocate storage for XTextProperty structure!\n", "", "", ""); return -3; } /* Set icon window name: */ icon_win_titleP = icon_win_titleA; if (!XStringListToTextProperty (&icon_win_titleP, 1, &icon_win_titleS)) { ErrorMessage_ ("garlic", "CreateWindows_", "", "Failed to allocate storage for XTextProperty structure!\n", "", "", ""); return -4; } /* Set class hints (just two char pointers and nothing else): */ class_hintS.res_name = prog_nameA; class_hintS.res_class = class_nameA; /* Inform window manager about application window properties: */ XSetWMProperties (guiSP->displaySP, guiSP->main_winS.ID, &main_win_titleS, &icon_win_titleS, argv, argc, &guiSP->main_winS.size_hintsS, &guiSP->wm_hintsS, &class_hintS); /* Select events: */ SelectEvents_ (guiSP); /* Map windows: */ /* The whole source code grew to about 59000 characters */ /* before I saw the garlic window for the first time! */ XMapSubwindows (guiSP->displaySP, guiSP->main_winS.ID); XMapWindow (guiSP->displaySP, guiSP->main_winS.ID); /* If control window should be hidden: */ if (!configSP->show_control_windowF) HideControlWindow_ (guiSP); /*------main pixmap ("hidden frame"):----------------------------------------*/ /* The main hidden pixmap. Drawing is done to a hidden pixmap */ /* which resides on the server side. Another approach will be */ /* to use an XImage on the client side. An experiment was made */ /* to compare two approaches, using XFree86 implementation of */ /* X11 window system. The XImage-based method was twice faster */ /* if both client and server ran on the same machine. However, */ /* the hidden pixmap method was chosen because it offers much */ /* larger set of drawing routines (rectangles, arcs etc.). */ /* The main hidden pixmap is the original drawing destination, */ /* and the content is copied to the main window after drawing. */ guiSP->main_hidden_pixmapID = XCreatePixmap ( guiSP->displaySP, DefaultRootWindow (guiSP->displaySP), guiSP->main_win_free_area_width, guiSP->main_win_free_area_height, guiSP->depth); guiSP->main_hidden_pixmapF = 1; /*------the hidden pixmap with small arrows:---------------------------------*/ /* The hidden pixmap with small arrows. It is used to show quickly the */ /* approximate direction of the main chain, projected to the XY plane. */ /* The appropriate arrow is drawn just under the sequence neighborhood. */ n = MakePixmap2_ (&guiSP->small_arrows_pixmapID, &guiSP->small_arrows_width, &guiSP->small_arrows_height, guiSP, small_arrows_xpm); if (n < 0) return -5; else (guiSP->small_arrows_pixmapF = 1); /*---------------------------------------------------------------------------*/ return 1; } /*===========================================================================*/ garlic-1.6/open_config_file.c0000644000076500007650000000603510357776246016565 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2006 Damir Zucic */ /*============================================================================= open_cfg_file.c Purpose: Open configuration file. Up to seven directories are searched. If all attempts fail, return NULL. Input: (1) Environment variable HOME used. Output: (1) Return value. Return value: (1) File pointer, if file found. (2) NULL, if all attempts to find file failed. Notes: (1) The following seven pathnames will be checked, if necessary: (1) ./.garlicrc (current working directory) (2) $HOME/.garlicrc (home directory) (3) $HOME/garlic/.garlicrc (4) /usr/share/garlic/.garlicrc (recomm. system-wide default!) (5) /etc/garlicrc (note: file name is garlicrc !) (6) /usr/local/lib/garlic/.garlicrc (7) /usr/lib/garlic/.garlicrc ========includes:============================================================*/ #include #include #include #include "defines.h" /*======try to find and open .garlicrc file:=================================*/ FILE *OpenConfigFile_ (void) { static FILE *fileP; static char tildaA[10] = "~"; char *home_dirP; int n; char config_file_nameA[STRINGSIZE]; /* The first attempt - try to find .garlicrc file in current directory: */ if ((fileP = fopen (".garlicrc", "r")) != NULL) { return fileP; } /* The second attempt - try to find .garlicrc file in users home directory: */ do { if ((home_dirP = getenv ("HOME")) != NULL) break; if ((home_dirP = getenv ("home")) != NULL) break; home_dirP = tildaA; } while (0); n = STRINGSIZE - 100; strncpy (config_file_nameA, home_dirP, n); config_file_nameA[n] = '\0'; strncat (config_file_nameA, "/.garlicrc", 11); config_file_nameA[STRINGSIZE - 1] = '\0'; if ((fileP = fopen (config_file_nameA, "r")) != NULL) { return fileP; } /* The third attempt - try to find personal file in $HOME/garlic directory: */ n = STRINGSIZE - 100; strncpy (config_file_nameA, home_dirP, n); config_file_nameA[n] = '\0'; strncat (config_file_nameA, "/garlic/.garlicrc", 18); config_file_nameA[STRINGSIZE - 1] = '\0'; if ((fileP = fopen (config_file_nameA, "r")) != NULL) { return fileP; } /* The fourth attempt - /usr/share/garlic/.garlicrc . */ /* This pathname is recommended as system-wide default! */ if ((fileP = fopen ("/usr/share/garlic/.garlicrc", "r")) != NULL) { return fileP; } /* The fifth attempt - /etc/garlicrc, default for */ /* Debian Linux (the file name is garlicrc !): */ if ((fileP = fopen ("/etc/garlicrc", "r")) != NULL) { return fileP; } /* The sixth attempt - /usr/local/lib/garlic directory: */ if ((fileP = fopen ("/usr/local/lib/garlic/.garlicrc", "r")) != NULL) { return fileP; } /* The seventh attempt - /usr/lib/garlic directory: */ if ((fileP = fopen ("/usr/lib/garlic/.garlicrc", "r")) != NULL) { return fileP; } /* If this point is reached, all attempts to */ /* open the configuration file have failed: */ return NULL; } /*===========================================================================*/ garlic-1.6/AUTHOR.README0000644000076500007650000000371110361461206014771 0ustar zuciczucic00000000000000Before releasing the new version of garlic, be sure to do a couple of things: =============================================================================== (1) Edit Makefile (enable -O3 optimizations and remove debugging options). (2) Replace the version number: it may be found in some source files, like print_version.c and in some html files (documentation). (3) Update the release date in print_version.c, .garlicrc and elsewhere. (4) Update the copyright notice in garlic.c . (5) Check is there any garbage left (dump, insert, files with ~ etc.) in the source directory. (6) Prepare garlic-*.tar.gz (* stands for version) and check the file size. (7) Check .garlicrc file. The system-wide configuration file should be in /usr/share/garlic directory, or /etc directory (Debian). The template residues (file residues.pdb) should be in /usr/share/garlic directory. Use "locate .garlicrc" and "locate garlicrc" to find the old versions. RESUME: (5.1) Recommended locations for .garlicrc: /usr/share/garlic (linux, system-wide file) /usr/local/lib/garlic (alternative location for older systems) /etc (special case: Debian and clones, system-wide file) $HOME (some users will prefer personal file) $HOME/garlic (alternative location for personal file) (5.2) Recommended locations for residues.pdb: /usr/share/garlic (linux, system-wide file) /usr/local/lib/garlic (alternative location for older systems) $HOME/garlic (some users will prefer personal file) (8) Update documentation (reference card, config/index.html, release date, version number etc.). (9) Update the screenshot gallery. (10) Update the main index.html file (release date, garlic news ...). (11) Update the list of Linux distributions and other sites with precompiled garlic packages. (12) Execute the script update-*.script, in the /var/www/html directory. garlic-1.6/small_atoms2.c0000644000076500007650000003135707747302027015671 0ustar zuciczucic00000000000000/* Copyright (C) 2002-2003 Damir Zucic */ /*============================================================================= small_atoms2.c Purpose: Draw small atoms (small style, version 2). Input: (1) Pointer to MolComplexS structure. (2) Number of macromolecular complexes. (3) Pointer to ConfigS structure, with configuration data. (4) Pointer to GUIS structure. (5) Pointer to NearestAtomS structure, with information about the atom occupying the given pixel. (6) The number of pixels in the main window free area. (7) The refreshI, used to check the NearestAtomS associated with a given pixel. Output: (1) Small spheres drawn to the hidden pixmap. (2) Return value. Return value: (1) Positive always (trivial). Notes: (1) Indentation is exceptionally 4 spaces. =============================================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ unsigned long Sp2Color_ (AtomS *, GUIS *, double); /*======draw atoms as spheres, small style version 2:========================*/ int DrawSmall2_ (MolComplexS *mol_complexSP, int mol_complexesN, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int refreshI) { int imageI, imagesN; double scale_factor, user_atomic_position; int left_edge[2], right_edge[2]; int mol_complexI; MolComplexS *curr_mol_complexSP; size_t atomsN, atomI; AtomS *curr_atomSP; int screen_x0, screen_y0; double radius, radius_squared; double denominator, reciprocal_denominator; int screen_radius; long screen_radius_squared; int screen_x1, screen_y1, screen_x2, screen_y2; int screen_x, screen_y; long delta_x, delta_y, distance_squared; double z0, front_z, delta_z, z; size_t pixelI; NearestAtomS *curr_pixelSP; double denominator2, reciprocal_denominator2; double rho_squared; VectorS vectorS; double abs_value, abs_value_squared; double scalar_product, cos_angle; unsigned long colorID; int bondI; /* Initialize the bond index. The negative value means that pixels */ /* filled in this function are not a part of any chemical bond. */ bondI = -1; /* Number of images: */ if (configSP->stereoF) imagesN = 2; else imagesN = 1; /* The auxiliary scale factor: */ scale_factor = configSP->user_screen_atomic_distance * configSP->atomic_to_screen_scale_x; /* Prepare the user position in atomic coordinates: */ user_atomic_position = configSP->user_atomic_position; /* Left and right image edge (in stereo mode there are two images): */ left_edge[0] = configSP->image_screen_x0[0]; right_edge[0] = configSP->image_screen_x1[0]; left_edge[1] = configSP->image_screen_x0[1]; right_edge[1] = configSP->image_screen_x1[1]; /*------first pass - fill NearestAtomS array with planar atoms:--------------*/ /* Draw each macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Prepare and check the number of atoms: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Draw atoms which have the given style: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Check style: */ if (curr_atomSP->raw_atomS.atom_styleI != SMALL_ATOM2) continue; /* Check is atom hidden: */ if (curr_atomSP->hiddenF) continue; /* Check is atom inside slab: */ if (!curr_atomSP->inside_slabF) continue; /* Check is atom inside window: */ if (!curr_atomSP->inside_windowF) continue; /* Small radius, in atomic units: */ radius = curr_atomSP->raw_atomS.small_radius; /* The y coordinate of atomic center, in screen units: */ screen_y0 = curr_atomSP->raw_atomS.screen_y; /* Prepare one image (mono) or two images (stereo): */ for (imageI = 0; imageI < imagesN; imageI++) { /* The z coordinate of atomic center, in atomic units: */ z0 = curr_atomSP->raw_atomS.z[imageI]; /* Prepare the factor required for the projection of radius: */ denominator = z0 - user_atomic_position; if (denominator == 0.0) continue; reciprocal_denominator = 1.0 / denominator; /* Small radius in screen units: */ screen_radius = (int) (radius * scale_factor * reciprocal_denominator + 0.5); /* Screen radius squared (used to improve speed): */ screen_radius_squared = (long) screen_radius * (long) screen_radius; /* The x coordinate of atomic center, in screen units: */ screen_x0 = curr_atomSP->raw_atomS.screen_x[imageI]; /* Define the bounding rectangle: */ screen_x1 = screen_x0 - screen_radius; screen_y1 = screen_y0 - screen_radius; screen_x2 = screen_x0 + screen_radius; screen_y2 = screen_y0 + screen_radius; /* Horizontal scan: */ for (screen_x = screen_x1; screen_x <= screen_x2; screen_x++) { /* Check horizontal position: */ if (screen_x < left_edge[imageI]) continue; if (screen_x >= right_edge[imageI]) continue; /* Vertical scan: */ for (screen_y = screen_y1; screen_y <= screen_y2; screen_y++) { /* Check vertical position: */ if (screen_y < 0) continue; if (screen_y >= (int) guiSP->main_win_free_area_height) { continue; } /* Check distance from the circle center: */ delta_x = (long) (screen_x - screen_x0); delta_y = (long) (screen_y - screen_y0); distance_squared = delta_x * delta_x + delta_y * delta_y; if (distance_squared > screen_radius_squared) continue; /* Prepare index to the array */ /* of NearestAtomS structures: */ pixelI = guiSP->main_win_free_area_width * screen_y + screen_x; /* Check the pixel index: */ if (pixelI >= pixelsN) continue; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = nearest_atomSP + pixelI; /* Check was this pixel used already in */ /* this drawing step; if it was, compare */ /* the z value of the current atom with z */ /* value previously stored to this pixel: */ if (refreshI == curr_pixelSP->last_refreshI) { if (z0 > curr_pixelSP->z) continue; } /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = SMALL_ATOM2; curr_pixelSP->last_refreshI = refreshI; curr_pixelSP->mol_complexI = mol_complexI; curr_pixelSP->atomI = atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = z0; } } } /* imageI loop */ } /* atomI loop */ } /* mol_complexI loop */ /*------second pass - draw spherical atoms:----------------------------------*/ /* Draw each macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Prepare and check the number of atoms: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Draw atoms which have the given style: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Check style: */ if (curr_atomSP->raw_atomS.atom_styleI != SMALL_ATOM2) continue; /* Check is atom hidden: */ if (curr_atomSP->hiddenF) continue; /* Check is atom inside slab: */ if (!curr_atomSP->inside_slabF) continue; /* Check is atom inside window: */ if (!curr_atomSP->inside_windowF) continue; /* Small radius, in atomic units: */ radius = curr_atomSP->raw_atomS.small_radius; /* Squared small radius: */ radius_squared = radius * radius; /* The y coordinate of atomic center, in screen units: */ screen_y0 = curr_atomSP->raw_atomS.screen_y; /* Prepare one image (mono) or two images (stereo): */ for (imageI = 0; imageI < imagesN; imageI++) { /* The z coordinate of atomic center, in atomic units: */ z0 = curr_atomSP->raw_atomS.z[imageI]; /* The z coordinate of the nearest */ /* point of a given atom (sphere): */ front_z = z0 - radius; /* Prepare the factor required for the projection of radius: */ denominator = z0 - user_atomic_position; if (denominator == 0.0) continue; reciprocal_denominator = 1.0 / denominator; /* Small radius in screen units: */ screen_radius = (int) (radius * scale_factor * reciprocal_denominator + 0.5); /* Square of the small radius (in screen units): */ screen_radius_squared = (long) screen_radius * (long) screen_radius; /* Reciprocal value will be used to improve performance: */ denominator2 = (double) screen_radius_squared; if (denominator2 == 0.0) continue; reciprocal_denominator2 = 1.0 / denominator2; /* The x coordinate of atomic center, in screen units: */ screen_x0 = curr_atomSP->raw_atomS.screen_x[imageI]; /* Define the bounding rectangle: */ screen_x1 = screen_x0 - screen_radius; screen_y1 = screen_y0 - screen_radius; screen_x2 = screen_x0 + screen_radius; screen_y2 = screen_y0 + screen_radius; /* Horizontal scan: */ for (screen_x = screen_x1; screen_x <= screen_x2; screen_x++) { /* Check horizontal position: */ if (screen_x < left_edge[imageI]) continue; if (screen_x > right_edge[imageI]) continue; /* Vertical scan: */ for (screen_y = screen_y1; screen_y <= screen_y2; screen_y++) { /* Check vertical position: */ if (screen_y < 0) continue; if (screen_y >= (int) guiSP->main_win_free_area_height) { continue; } /* Check distance from the circle center: */ delta_x = (long) (screen_x - screen_x0); delta_y = (long) (screen_y - screen_y0); distance_squared = delta_x * delta_x + delta_y * delta_y; if (distance_squared > screen_radius_squared) continue; /* Prepare index to the array */ /* of NearestAtomS structures: */ pixelI = guiSP->main_win_free_area_width * screen_y + screen_x; /* Check the pixel index: */ if (pixelI >= pixelsN) continue; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = nearest_atomSP + pixelI; /* Check z value (this is just a quick check): */ if (refreshI == curr_pixelSP->last_refreshI) { if (front_z > curr_pixelSP->z) continue; } /* Calculate the accurate z value: */ rho_squared = radius_squared * (double) distance_squared * reciprocal_denominator2; delta_z = sqrt (fabs (radius_squared - rho_squared)); z = z0 - delta_z; /* Check z value (precise check): */ if (refreshI == curr_pixelSP->last_refreshI) { if (z > curr_pixelSP->z) continue; } /* The vector from sphere center to the current pixel: */ vectorS.x = (double) delta_x; vectorS.y = (double) delta_y; vectorS.z = - sqrt (fabs (screen_radius_squared - vectorS.x * vectorS.x - vectorS.y * vectorS.y)); abs_value_squared = vectorS.x * vectorS.x + vectorS.y * vectorS.y + vectorS.z * vectorS.z; abs_value = sqrt (abs_value_squared); /* The scalar product between this */ /* vector and light source vector: */ scalar_product = vectorS.x * configSP->light_vectorS.x + vectorS.y * configSP->light_vectorS.y + vectorS.z * configSP->light_vectorS.z; /* Cosine of the angle between the vector to the */ /* current pixel and the light source unit vector: */ if (abs_value == 0.0) cos_angle = 0.0; else cos_angle = scalar_product / abs_value; /* Prepare color: */ colorID = Sp2Color_ (curr_atomSP, guiSP, cos_angle); XSetForeground (guiSP->displaySP, guiSP->theGCA[0], colorID); XDrawPoint (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x, screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = SMALL_ATOM2; curr_pixelSP->last_refreshI = refreshI; curr_pixelSP->mol_complexI = mol_complexI; curr_pixelSP->atomI = atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = z; curr_pixelSP->colorID = colorID; } } } /* imageI loop */ } /* atomI loop */ } /* mol_complexI loop */ /*---------------------------------------------------------------------------*/ /* Return positive value (trivial): */ return 1; } /*===========================================================================*/ garlic-1.6/angle.c0000644000076500007650000000314307125464340014347 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= angle.c Purpose: Execute angle command: define the angle separating neighboring residues along the axis of an alpha helix. The input angle should be specified in degrees. Default hard-coded value is 100 degrees (see init_runtime.c). Input: (1) Pointer to RuntimeS structure. (2) Pointer to the remainder of the command string. Output: (1) The helix step angle value changed. (2) Return value. Return value: (1) Positive (command) code on success. (2) Negative (error) code on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include #include "defines.h" #include "commands.h" #include "typedefs.h" /*======execute angle command:===============================================*/ int Angle_ (RuntimeS *runtimeSP, char *stringP) { char *P; int n; double value; /* Replace each non-numeric character (except */ /* minus sign and decimal point) with space: */ P = stringP; while ((n = *P++) != '\0') { if (!isdigit (n) && (n != '-') && (n != '.')) *(P - 1) = ' '; } /* Try to extract the angle: */ if (sscanf (stringP, "%lf", &value) != 1) return ERROR_ANGLE; /* On success, copy the extracted angle to RuntimeS structure: */ runtimeSP->helix_step_angle = value; /* Return the command code: */ return COMMAND_ANGLE; } /*===========================================================================*/ garlic-1.6/sequence_from.c0000644000076500007650000001425307465735213016127 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2002 Damir Zucic */ /*============================================================================= sequence_from.c Purpose: Copy the sequence from the specified macromolecular complex to the sequence buffer. Only the sequence for selected range(s) is copied. A residue is treated as selected if the first atom of this residue is selected. For proteins, this is typically N. The original residue sequence indices are copyed. Insertion codes are, however, ignored, so it is possible that some res. serial indices appear more than once in the buffer. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) The number of macromolecular complexes. (3) Pointer to RuntimeS structure. (4) Pointer to the string which contains the macromol. complex identifier. Output: (1) Sequence from the specified complex copied to the sequence buffer. (2) Return value. Return value: (1) Positive (command) code on success. (2) Negative (error) code on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "commands.h" #include "typedefs.h" /*======function prototypes:=================================================*/ char *ExtractToken_ (char *, int, char *, char *); void InitHyphob_ (RuntimeS *); /*======copy sequence from complex to sequence buffer:=======================*/ int SequenceFrom_ (MolComplexS *mol_complexSP, int mol_complexesN, RuntimeS *runtimeSP, char *stringP) { int max_length; char *remainderP; char tokenA[SHORTSTRINGSIZE]; int complexID; int mol_complexI; static MolComplexS *curr_mol_complexSP; int job_doneF = 0; size_t residue1I, residues1N; ResidueS *curr_residueSP; AtomS *first_atomSP; AtomS *last_atomSP; AtomS *curr_atomSP; size_t offset; char *sourceP, *destP; size_t residue2I = 0; int bondsN, bondI; TrueBondS *curr_bondSP; int disulfideF; int *curr_disulfideFP; /* The maximal residue name length: */ max_length = RESNAMESIZE - 1; /* At least one macromolecular complex should be available: */ if (mol_complexesN == 0) { strcpy (runtimeSP->messageA, "No structure loaded!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return -1; } /* Take the first token; it should be present: */ remainderP = ExtractToken_ (tokenA, SHORTSTRINGSIZE, stringP, " \t\n"); if (!remainderP) { strcpy (runtimeSP->messageA, "Complex identifier missing!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return -2; } /* Extract the macromolecular complex identifier: */ if (sscanf (tokenA, "%d", &complexID) != 1) { strcpy (runtimeSP->messageA, "Bad macromolecular complex identifier!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return -3; } /* Check is the requested complex available at all: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /** Prepare the pointer to the current macromolecular complex: **/ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check the number of atoms; for bad */ /* and discarded complexes it is zero: */ if (curr_mol_complexSP->atomsN == 0) continue; /* If macromol. complex is recognized, set the catch flag to one: */ if (curr_mol_complexSP->mol_complexID == complexID) { job_doneF = 1; break; } } /* If the requested complex is not available, return negative value: */ if (job_doneF == 0) { strcpy (runtimeSP->messageA, "The requested complex is not available!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return -4; } /* Copy the sequence: */ residues1N = curr_mol_complexSP->residuesN; for (residue1I = 0; residue1I < residues1N; residue1I++) { /* Pointer to the current residue: */ curr_residueSP = curr_mol_complexSP->residueSP + residue1I; /* Pointer to the first atom: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Pointer to the last atom: */ last_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_endI; /* If this atom is not selected, do not copy the residue name: */ if (first_atomSP->selectedF == 0) continue; /* Pointer to the residue name associated with this atom: */ sourceP = first_atomSP->raw_atomS.pure_residue_nameA; /* Prepare and check the position in seq. */ /* buffer where this name will be copied: */ offset = max_length * residue2I; if (offset > runtimeSP->sequence_buffer_size - 10 * max_length) { strcpy (runtimeSP->messageA, "Sequence too long!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return -5; } /* Copy the residue name: */ destP = runtimeSP->sequenceP + offset; strncpy (destP, sourceP, max_length); /* Copy the residue serial index: */ *(runtimeSP->serialIP + residue2I) = first_atomSP->raw_atomS.residue_sequenceI; /* Now it is time to set disulfide flag for the current residue. */ /* Pointer to disulfide flag for the current residue: */ curr_disulfideFP = runtimeSP->disulfideFP + residue2I; /* Reset disulfide flag: */ *curr_disulfideFP = 0; /* Reset the flag: */ disulfideF = 0; /* Check is this residue involved in disulfide bond: */ for (curr_atomSP = first_atomSP; curr_atomSP <= last_atomSP; curr_atomSP++) { /* The number of bonds: */ bondsN = curr_atomSP->bondsN; /* Check is disulfide bond present: */ for (bondI = 0; bondI < bondsN; bondI++) { /* Pointer to the current bond: */ curr_bondSP = curr_atomSP->true_bondSA + bondI; /* If this bond is disulfide */ /* bond, set flag and break: */ if (curr_bondSP->bond_typeI == 2) { disulfideF = 1; break; } } /* If at least one disulfide bond is found, break from loop: */ if (disulfideF != 0) break; } /* Update disulfide flag: */ if (disulfideF) *curr_disulfideFP = 1; /* Update the output residue index: */ residue2I++; } /* Set the number of residues: */ runtimeSP->residuesN = residue2I; /* Initialize hydrophobicity values: */ InitHyphob_ (runtimeSP); /* Return positive value on success: */ return 1; } /*===========================================================================*/ garlic-1.6/blur_main_window.c0000644000076500007650000001522207747233151016625 0ustar zuciczucic00000000000000/* Copyright (C) 2003 Damir Zucic */ /*============================================================================= blur_main_window.c Purpose: Blur the main window free area. The pixels from the rectangular area defined by blur_width and blur_height are used to calculate the average RGB values, to replace the color of the pixel which is in the center of the rectangular area. Input: (1) Pointer to RuntimeS structure. (2) Pointer to GUIS structure. (3) Pointer to NearestAtomS structure. (4) The number of pixels in the main window free area. Output: (1) The image in the main window free are will be modified. (2) Return value. Return value: (1) Positive on success. (2) Negative on failure. Notes: (1) Indentation is exceptionally four spaces. (2) Blur will not affect labels, tags, titles and the small coordinate system in the top left corner. ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======blur the main window free area:======================================*/ size_t BlurMainWindow_ (RuntimeS *runtimeSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN) { static unsigned long ulong_red_mask, ulong_green_mask, ulong_blue_mask; int free_area_width, free_area_height; int blur_width, blur_half_width; int blur_height, blur_half_height; int row_startI, row_endI, column_startI, column_endI; int screen_x0, screen_y0; static long double ldouble_new_red, ldouble_new_green, ldouble_new_blue; int mixed_pixelsN; int rowI, columnI; int screen_x1, screen_y1; int pixelI; NearestAtomS *curr_pixelSP; unsigned long old_colorID; static unsigned long ulong_old_red, ulong_old_green, ulong_old_blue; static long double ldouble_old_red, ldouble_old_green, ldouble_old_blue; long double reciprocal_mixed_pixelsN; static unsigned long ulong_new_red, ulong_new_green, ulong_new_blue; unsigned long new_colorID; /* Copy the color masks: */ ulong_red_mask = guiSP->visual_infoS.red_mask; ulong_green_mask = guiSP->visual_infoS.green_mask; ulong_blue_mask = guiSP->visual_infoS.blue_mask; /* Copy the width and height of the main window free area: */ free_area_width = (int) guiSP->main_win_free_area_width; free_area_height = (int) guiSP->main_win_free_area_height; /* Copy and check the width and height of the blur rectangle: */ blur_width = runtimeSP->blur_width; if (blur_width <= 0) return -1; blur_half_width = (blur_width - 1) / 2; blur_height = runtimeSP->blur_height; if (blur_height <= 0) return -2; blur_half_height = (blur_height - 1) / 2; /* Prepare start and end indices required to scan blur rectangle: */ row_startI = -blur_half_width; row_endI = row_startI + blur_width - 1; column_startI = -blur_half_height; column_endI = column_startI + blur_height - 1; /* Vertical scan of the main window free area: */ for (screen_x0 = 0; screen_x0 < free_area_width; screen_x0++) { /* Horizontal scan of the main window free area: */ for (screen_y0 = 0; screen_y0 < free_area_height; screen_y0++) { /* Reset the variables which store the */ /* new color components as long doubles: */ ldouble_new_red = 0.0; ldouble_new_green = 0.0; ldouble_new_blue = 0.0; /* Reset the counter which counts the pixels */ /* used to calculate the new color components: */ mixed_pixelsN = 0; /* Vertical scan of the blur rectangle: */ for (rowI = row_startI; rowI <= row_endI; rowI++) { /* Prepare and check the vertical position of the current pixel: */ screen_y1 = screen_y0 + rowI; if (screen_y1 < 0) continue; if (screen_y1 >= free_area_height) continue; /* Horizontal scan of the blur rectangle: */ for (columnI = column_startI; columnI <= column_endI; columnI++) { /* Prepare and check the horizontal */ /* position of the current pixel: */ screen_x1 = screen_x0 + columnI; if (screen_x1 < 0) continue; if (screen_x1 >= free_area_width) continue; /* Prepare and check the pixel index: */ pixelI = free_area_width * screen_y1 + screen_x1; if (pixelI >= (int) pixelsN) continue; /* Prepare the pointer to the current pixel: */ curr_pixelSP = nearest_atomSP + pixelI; /* Copy the color ID of the current pixel: */ old_colorID = curr_pixelSP->colorID; /* Extract the old color components: */ ulong_old_red = old_colorID & ulong_red_mask; ulong_old_green = old_colorID & ulong_green_mask; ulong_old_blue = old_colorID & ulong_blue_mask; /* Convert unsigned long values to long double values: */ ldouble_old_red = (long double) ulong_old_red; ldouble_old_green = (long double) ulong_old_green; ldouble_old_blue = (long double) ulong_old_blue; /* Add these values to the corresponding totals: */ ldouble_new_red += ldouble_old_red; ldouble_new_green += ldouble_old_green; ldouble_new_blue += ldouble_old_blue; /* Update the pixel counter: */ mixed_pixelsN++; } } /* Check the number of pixels which were mixed and */ /* calculate the reciprocal value if appropriate: */ if (mixed_pixelsN <= 0) continue; reciprocal_mixed_pixelsN = 1.0 / (long double) mixed_pixelsN; /* Prepare and check the index of the pixel */ /* in the middle of the blur rectangle: */ pixelI = free_area_width * screen_y0 + screen_x0; if (pixelI >= (int) pixelsN) continue; /* Prepare the pointer to the pixel in */ /* the middle of the blur rectangle: */ curr_pixelSP = nearest_atomSP + pixelI; /* Calculate the average values of color componets: */ ldouble_new_red *= reciprocal_mixed_pixelsN; ldouble_new_green *= reciprocal_mixed_pixelsN; ldouble_new_blue *= reciprocal_mixed_pixelsN; /* Convert the long double values to unsigned long values: */ ulong_new_red = (unsigned long) ldouble_new_red; ulong_new_green = (unsigned long) ldouble_new_green; ulong_new_blue = (unsigned long) ldouble_new_blue; /* Combine the unsigned long values with color masks: */ ulong_new_red &= ulong_red_mask; ulong_new_green &= ulong_green_mask; ulong_new_blue &= ulong_blue_mask; /* Combine the color components into a single color ID: */ new_colorID = ulong_new_red | ulong_new_green | ulong_new_blue; /* Store the new color ID to the NearestAtomS */ /* structure associated with the central pixel: */ curr_pixelSP->colorID = new_colorID; /* Redraw the current pixel: */ XSetForeground (guiSP->displaySP, guiSP->theGCA[0], new_colorID); XDrawPoint (guiSP->displaySP, guiSP->main_winS.ID, guiSP->theGCA[0], screen_x0, screen_y0); } } /* Return positive value on success: */ return 1; } /*===========================================================================*/ garlic-1.6/load_complex.c0000644000076500007650000002213207632075701015730 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2003 Damir Zucic */ /*============================================================================= load_complex.c Purpose: Load the specified macromolecular complex. Read the specified file and do some additional operations. Input: (1) Pointer to the storage where the group flag might be stored. The group flag is a member of RuntimeS structure. The pointer used here should point either to this flag or to some dummy integer. (2) Pointer to MolComplexS structure (macromolecular complexes). (3) Pointer to the number of macromolecular complexes. (4) Pointer to the next macromolecular complex identifier. (5) Input file name (pointer). (6) Pointer to ConfigS structure, with configuration data. (7) Pointer to GUIS structure, with GUI data. Output: (1) One macromolecular complex loaded. (2) Number of macromolecular complexes updated. (3) Return value. Return value: (1) The updated number of macromolecular complexes, on success. (2) Negative on failure. Notes: (1) Default hydrophobicity scale is the Eisenberg scale published in the article: Eisenberg, D., Schwarz, E., Komaromy, M. and Wall, R. (1984). J. Mol. Biol. 179, p. 125. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int ReadFile_ (MolComplexS *, char *, ConfigS *); int GeometricCenter_ (MolComplexS *); void FlipVector_ (VectorS *, VectorS *); void TranslateComplex_ (MolComplexS *, VectorS *, ConfigS *, int); int ComplexExtent_ (MolComplexS *); void InitSlab_ (MolComplexS *); void InitFading_ (MolComplexS *); int PrepareStereoData_ (MolComplexS *, ConfigS *); size_t StrongBonds_ (MolComplexS *, int, ConfigS *); size_t PseudoBonds_ (MolComplexS *, int, ConfigS *); size_t DisulfideBonds_ (MolComplexS *, int, ConfigS *); int PrepareBackbone_ (MolComplexS *, ConfigS *); int AssignRadii_ (MolComplexS *, ConfigS *); int AssignHydrophobicity_ (MolComplexS *, int); int ExtractSequence_ (MolComplexS *); int DihedralAngles_ (MolComplexS *, ConfigS *); int AllocSecondaryStructure_ (MolComplexS *); /*@@*/ /* Generate the secondary structure */ int GeneratePlane_ (MolComplexS *, ConfigS *, GUIS *); int InitializeMembrane_ (MolComplexS *, ConfigS *, GUIS *); /*======read file, do some initializations:==================================*/ int LoadComplex_ (int *groupFP, MolComplexS *mol_complexSP, int *mol_complexesNP, int *next_mol_complexIDP, char *mol_file_nameP, ConfigS *configSP, GUIS *guiSP) { int new_mol_complexI; MolComplexS *new_mol_complexSP; int new_mol_complexID; VectorS shift_vectorS; /* Shift to geometric center */ int default_hyphob_scaleI = 2; int mol_complexI; MolComplexS *curr_mol_complexSP; /* Check is there any space left in the array of MolComplexS structures: */ if (*mol_complexesNP >= MAXCOMPLEXES) return -1; /* Prepare the index of the new macromolecular complex: */ new_mol_complexI = *mol_complexesNP; /* Prepare the pointer to macromolecular complex: */ new_mol_complexSP = mol_complexSP + new_mol_complexI; /* Read file (if 0 returned, file is not specified): */ if (ReadFile_ (new_mol_complexSP, mol_file_nameP, configSP) <= 0) return -2; /* Store the file name: */ strncpy (new_mol_complexSP->file_nameA, mol_file_nameP, STRINGSIZE - 1); new_mol_complexSP->file_nameA[STRINGSIZE - 1] = '\0'; /* Set the unique macromolecular complex identifier. */ /* This ID wouldn't change even if some macromolecular */ /* complexes are loaded or discarded. The array index */ /* of a given complex may change after something is */ /* discarded so it should not be used as identifier. */ /* The first mol. complex ID is equal to 1 (garlic.c). */ new_mol_complexID = *next_mol_complexIDP; new_mol_complexSP->mol_complexID = new_mol_complexID; /* Update the next macromol. complex identifier: */ (*next_mol_complexIDP)++; /* Update the number of macromolecular complexes: */ (*mol_complexesNP)++; /* Initialize the move bits: */ new_mol_complexSP->move_bits = STRUCTURE_MASK | PLANE_MASK | MEMBRANE_MASK | ENVELOPE_MASK; /* Find geometric center: */ GeometricCenter_ (new_mol_complexSP); /* Flip vector (multiply by -1): */ FlipVector_ (&shift_vectorS, &new_mol_complexSP->geometric_center_vectorS); /* Translate geometric center of the complex to */ /* the origin of the absolute coordinate system: */ TranslateComplex_ (new_mol_complexSP, &shift_vectorS, configSP, 0); /* Initial rotation center position: */ new_mol_complexSP->rotation_center_vectorS.x = 0.0; new_mol_complexSP->rotation_center_vectorS.y = 0.0; new_mol_complexSP->rotation_center_vectorS.z = 0.0; /* Spatial extend of the whole macromolecular complex: */ ComplexExtent_ (new_mol_complexSP); /* Initialize the slab mode (use the current default slab mode): */ new_mol_complexSP->slab_modeI = configSP->default_slab_modeI; /* Initialize slab: */ InitSlab_ (new_mol_complexSP); /* Initialize the color fading mode (use the current default fading mode): */ new_mol_complexSP->fading_modeI = configSP->default_fading_modeI; /* Initialize color fading parameters: */ InitFading_ (new_mol_complexSP); /* Prepare the stereo data (coordinates for the right image): */ if (configSP->stereoF) PrepareStereoData_ (new_mol_complexSP, configSP); /* Prepare bonds; use inter-atomic */ /* distances for identification: */ StrongBonds_ (new_mol_complexSP, new_mol_complexI, configSP); /* Generate pseudo-bonds (bonds formed by imaginary Q atoms): */ PseudoBonds_ (new_mol_complexSP, new_mol_complexI, configSP); /* Prepare disulfide bonds: */ DisulfideBonds_ (new_mol_complexSP, new_mol_complexI, configSP); /* Prepare backbone data - allocate and */ /* fill the array of BackboneS structures: */ PrepareBackbone_ (new_mol_complexSP, configSP); /* Assign radius to each atom: */ AssignRadii_ (new_mol_complexSP, configSP); /* Assign default hydrophobicity to each atom: */ AssignHydrophobicity_ (new_mol_complexSP, default_hyphob_scaleI); /* Extract sequence information: */ ExtractSequence_ (new_mol_complexSP); /* Calculate dihedral angles and cis_trans flags: */ DihedralAngles_ (new_mol_complexSP, configSP); /* Allocate and initialize the storage for the secondary structure: */ if (AllocSecondaryStructure_ (new_mol_complexSP) < 0) return -3; /*@@*/ /* Generate the secondary structure information: */ /* Generate the plane (represented by an ellipse): */ GeneratePlane_ (new_mol_complexSP, configSP, guiSP); /* Initialize data required to draw the membrane: */ InitializeMembrane_ (new_mol_complexSP, configSP, guiSP); /* Initialize the flag reserved for hydrogen bonds: if value */ /* is equal to zero, hydrogen bonds are missing or obsolete. */ new_mol_complexSP->hydrogen_bondsF = 0; /* The hydrogen bonds are initially invisible: */ new_mol_complexSP->hydrogen_bonds_hiddenF = 1; /* The membrane is initially undefined: */ new_mol_complexSP->membraneS.definedF = 0; /* Set the probe radius (copy default value): */ new_mol_complexSP->bond_probe_radius = configSP->default_bond_probe_radius; /* Set the stick radius (used to draw bonds as sticks; copy default value): */ new_mol_complexSP->stick_radius = configSP->default_stick_radius; /* Set the group_memberF to zero: */ new_mol_complexSP->group_memberF = 0; /* If a group of structures was formed before, break it: */ *groupFP = 0; /* If some structures were involved in a formation of a */ /* group, restore the original rotation center vectors: */ for (mol_complexI = 0; mol_complexI < *mol_complexesNP; mol_complexI++) { /* Prepare the pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check was this complex a group member: */ if (curr_mol_complexSP->group_memberF == 0) continue; /* If this point is reached, the current complex was a group member. */ /* Restore the original rotation center vector: */ curr_mol_complexSP->rotation_center_vectorS.x = curr_mol_complexSP->backup_vectorS.x; curr_mol_complexSP->rotation_center_vectorS.y = curr_mol_complexSP->backup_vectorS.y; curr_mol_complexSP->rotation_center_vectorS.z = curr_mol_complexSP->backup_vectorS.z; /* Reset the group_memberF: */ curr_mol_complexSP->group_memberF = 0; } /* Set the catch flag to indicate that the new */ /* complex is the only one which is caught, i.e. */ /* affected by movement, slab and fading controls: */ for (mol_complexI = 0; mol_complexI < *mol_complexesNP; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* The catch flag for the new complex should be set to one: */ if (curr_mol_complexSP->mol_complexID == new_mol_complexID) { curr_mol_complexSP->catchF = 1; } /* All other catch flags should be set to zero: */ else curr_mol_complexSP->catchF = 0; } /* Return the updated number of macromolecular complexes on success: */ return *mol_complexesNP; } /*===========================================================================*/ garlic-1.6/representative_atoms.c0000644000076500007650000001212207374046720017525 0ustar zuciczucic00000000000000/* Copyright (C) 2000, 2001 Damir Zucic */ /*============================================================================= representative_atoms.c Purpose: Find representative atoms for a set of exposed polar residues. For side chains which have only one polar atom this atom is taken as representative. For side chains which have two polar atoms, the atom which is bound to both of these atoms is used, if it exists. Input: (1) Pointer to RuntimeS structure. (2) The complex index (1 = bottom, 2 = top). Output: (1) The information about representative atom will be asigned to each exposed polar residue. (2) Return value. Return value: (1) Positive on success. (2) Negative on failure. Notes: (1) Note that atomic index (atomI) is of the type int. Some related indices are also of the type int. The size_t type is not safe, because it is (at least on some systems) unsigned. As such, it is not suitable for subtraction. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ void ErrorMessage_ (char *, char *, char *, char *, char *, char *, char *); /*======find representative atoms:===========================================*/ int RepresentativeAtoms_ (RuntimeS *runtimeSP, int docking_complexI) { int exposed_polarN, exposed_polarI; MolComplexS *curr_mol_complexSP; int *exposed_atomIP; ExposedResidueS *exposed_polarSP; int scan_half_width; static char polar_nameAA[13][4] = {"GLU", "GLN", "HIS", "LYS", "TYR", "TRP", "THR", "SER", "ASP", "ASN", "ARG", "ASX", "GLX"}; static char representative_atomAA[13][ATOMNAMESIZE] = {"CD", "CD", "ND1", "NZ", "OH", "NE1", "OG1", "OG", "CG", "CG", "CZ", "CG", "CD"}; ExposedResidueS *curr_exposedSP; int name_foundF; int listI; int atomsN, atom0I, atom1I, atomI; /* Do not use size_t! */ int atom_foundF; AtomS *curr_atomSP; /* Check the complex index and prepare the pointers: */ if (docking_complexI == 1) { exposed_polarN = runtimeSP->exposed_polar1N; curr_mol_complexSP = runtimeSP->mol_complex1SP; exposed_atomIP = runtimeSP->exposed_atom1IP; exposed_polarSP = runtimeSP->exposed_polar1SP; } else if (docking_complexI == 2) { exposed_polarN = runtimeSP->exposed_polar2N; curr_mol_complexSP = runtimeSP->mol_complex2SP; exposed_atomIP = runtimeSP->exposed_atom2IP; exposed_polarSP = runtimeSP->exposed_polar2SP; } else { ErrorMessage_ ("garlic", "RepresentativeAtoms_", "", "Bad macromolecular complex index!\n", "", "", ""); return -1; } /* Prepare docking half width: */ scan_half_width = DOCKING_SCAN_WIDTH / 2; /* Scan the list of exposed polar residues: */ for (exposed_polarI = 0; exposed_polarI < exposed_polarN; exposed_polarI++) { /* Prepare the pointer to the current exposed polar residue: */ curr_exposedSP = exposed_polarSP + exposed_polarI; /* Identify the residue: */ name_foundF = 0; for (listI = 0; listI < 13; listI++) { if (strcmp (curr_exposedSP->pure_residue_nameA, polar_nameAA[listI]) == 0) { name_foundF = 1; break; } } /* If residue identification failes, the residue should be excluded: */ if (!name_foundF) { curr_exposedSP->excludedF = 1; continue; } /* If the residue was successfully identifyed, */ /* find the index of the representative atom. */ /* Prepare the scan range: */ atomsN = curr_mol_complexSP->atomsN; atom0I = curr_exposedSP->representative_atomI - scan_half_width; if (atom0I < 0) atom0I = 0; atom1I = curr_exposedSP->representative_atomI + scan_half_width; if (atom1I >= atomsN) atom1I = atomsN - 1; /* Scan the neighbourhood of the temporary representative atom: */ atom_foundF = 0; for (atomI = atom0I; atomI <= atom1I; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* If the purified atom name corresponds to the */ /* representative name, check residue information: */ if (strcmp (curr_atomSP->raw_atomS.pure_atom_nameA, representative_atomAA[listI]) == 0) { /* Check residue sequence index: */ if (curr_atomSP->raw_atomS.residue_sequenceI != curr_exposedSP->residue_sequenceI) continue; /* Check the residue insertion code: */ if (curr_atomSP->raw_atomS.residue_insertion_code != curr_exposedSP->residue_insertion_code) continue; /* Check the chain identifier: */ if (curr_atomSP->raw_atomS.chainID != curr_exposedSP->chainID) continue; /* If this point is reached, this is the right atom: */ atom_foundF = 1; curr_exposedSP->representative_atomI = (size_t) atomI; break; } } /* If the proper representative atom */ /* is missing, exclude this residue: */ if (!atom_foundF) curr_exposedSP->excludedF = 1; } /* Return positive value on success: */ return 1; } /*===========================================================================*/ garlic-1.6/small_ramachandran.c0000644000076500007650000006727407612777177017127 0ustar zuciczucic00000000000000/* Copyright (C) 2001-2003 Damir Zucic */ /*============================================================================= small_ramachandran.c Purpose: Draw small Ramachandran plot if editing dihedral angles phi and/or psi. If edit_single_bondF is zero, draw it for the first selected residue. Otherwise, draw it for the residue to which the chosen dihedral angle belongs. A residue is treated as selected if the first atom of this residue is selected. There is a separate type of Ramachadran plot for: (1) glycine; (2) proline; (3) residue preceding proline; (4) any other residue except glycine, proline and pre-proline. Input: (1) Pointer to MolComplexS structure. (2) Pointer to RuntimeS structure. (3) Pointer to GUIS structure. Output: (1) Small Ramachandran plot drawn to hidden pixmap. (2) Return value. Return value: (1) Positive on success. (2) Negative on failure. =============================================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int ParseColor_ (RGBS *, unsigned long *, GUIS *, char *, char *); /*======draw small Ramachandran plot:========================================*/ int SmallRamachandran_ (MolComplexS *mol_complexSP, RuntimeS *runtimeSP, GUIS *guiSP) { int residuesN, residueI; int chosen_residue_foundF; static ResidueS *residueSP; size_t atom_startI, atom_endI; static AtomS *first_atomSP; char *residue_nameP; ResidueS *next_residueSP; AtomS *next_first_atomSP; char *next_residue_nameP; static char dummy_nameA[10] = "XXX"; int inner_width, inner_height, outer_width, outer_height; int screen_x0, screen_y0, screen_x1, screen_y1; RGBS rgbS; unsigned long colorID; static double gly1_xA[18] = {0.000, 0.000, 0.102, 0.201, 0.201, 0.155, 0.000, 0.000, 0.356, 0.314, 0.327, 0.380, 0.380, 0.274, 0.327, 0.360, 0.366, 0.323}; static double gly1_yA[18] = {0.000, 0.395, 0.446, 0.541, 0.598, 0.632, 0.615, 1.000, 1.000, 0.895, 0.818, 0.699, 0.561, 0.466, 0.253, 0.230, 0.030, 0.000}; static int gly1_pointsN = 18; static double gly2_xA[18] = {1.000, 0.640, 0.680, 0.667, 0.614, 0.614, 0.723, 0.667, 0.634, 0.627, 0.677, 1.000, 1.000, 0.891, 0.792, 0.792, 0.838, 1.000}; static double gly2_yA[18] = {0.000, 0.000, 0.105, 0.180, 0.297, 0.439, 0.534, 0.743, 0.767, 0.963, 1.000, 1.000, 0.605, 0.551, 0.459, 0.399, 0.368, 0.382}; static int gly2_pointsN = 18; static double gly3_xA[13] = {0.096, 0.116, 0.086, 0.043, 0.000, 0.000, 0.030, 0.221, 0.228, 0.251, 0.333, 0.333, 0.310}; static double gly3_yA[13] = {0.000, 0.047, 0.084, 0.108, 0.084, 0.372, 0.389, 0.389, 0.294, 0.264, 0.206, 0.020, 0.000}; static int gly3_pointsN = 13; static double gly4_xA[11] = {0.667, 0.693, 0.693, 0.660, 0.660, 0.756, 0.822, 0.964, 1.000, 1.000, 0.878}; static double gly4_yA[11] = {0.000, 0.078, 0.196, 0.260, 0.378, 0.385, 0.351, 0.351, 0.375, 0.098, 0.000}; static int gly4_pointsN = 11; static double gly5_xA[12] = {0.000, 0.000, 0.007, 0.112, 0.327, 0.300, 0.300, 0.333, 0.333, 0.238, 0.172, 0.030}; static double gly5_yA[12] = {0.632, 0.909, 0.909, 1.000, 1.000, 0.926, 0.811, 0.747, 0.628, 0.622, 0.655, 0.655}; static int gly5_pointsN = 12; static double gly6_xA[12] = {0.772, 0.766, 0.660, 0.660, 0.690, 0.901, 0.878, 0.914, 0.951, 1.000, 1.000, 0.964}; static double gly6_yA[12] = {0.608, 0.703, 0.791, 0.976, 1.000, 1.000, 0.949, 0.905, 0.889, 0.916, 0.625, 0.608}; static int gly6_pointsN = 12; static double pro1_xA[17] = {0.293, 0.286, 0.286, 0.286, 0.293, 0.299, 0.309, 0.319, 0.332, 0.345, 0.362, 0.372, 0.382, 0.388, 0.388, 0.385, 0.382}; static double pro1_yA[17] = {0.000, 0.047, 0.074, 0.121, 0.161, 0.195, 0.225, 0.238, 0.248, 0.245, 0.232, 0.205, 0.168, 0.131, 0.050, 0.017, 0.000}; static int pro1_pointsN = 17; static double pro2_xA[21] = {0.339, 0.329, 0.319, 0.312, 0.306, 0.299, 0.299, 0.303, 0.313, 0.326, 0.339, 0.355, 0.359, 0.365, 0.365, 0.368, 0.368, 0.365, 0.355, 0.349, 0.339}; static double pro2_yA[21] = {0.537, 0.537, 0.544, 0.554, 0.574, 0.607, 0.671, 0.701, 0.725, 0.742, 0.742, 0.725, 0.708, 0.691, 0.671, 0.671, 0.607, 0.587, 0.557, 0.544, 0.537}; static int pro2_pointsN = 21; static double pro3_xA[14] = {0.339, 0.332, 0.322, 0.313, 0.305, 0.302, 0.301, 0.371, 0.371, 0.368, 0.362, 0.355, 0.349, 0.339}; static double pro3_yA[14] = {0.926, 0.926, 0.933, 0.946, 0.973, 0.987, 1.000, 1.000, 0.987, 0.970, 0.956, 0.943, 0.933, 0.926}; static int pro3_pointsN = 14; static double pro4_xA[22] = {0.342, 0.332, 0.319, 0.316, 0.313, 0.309, 0.306, 0.306, 0.313, 0.316, 0.326, 0.329, 0.342, 0.355, 0.359, 0.365, 0.368, 0.368, 0.365, 0.362, 0.355, 0.345}; static double pro4_yA[22] = {0.013, 0.013, 0.023, 0.037, 0.050, 0.057, 0.074, 0.128, 0.161, 0.188, 0.201, 0.208, 0.208, 0.198, 0.181, 0.148, 0.138, 0.077, 0.054, 0.037, 0.023, 0.013}; static int pro4_pointsN = 22; static double pro5_xA[16] = {0.339, 0.329, 0.322, 0.322, 0.319, 0.319, 0.322, 0.326, 0.329, 0.339, 0.345, 0.345, 0.349, 0.349, 0.345, 0.339}; static double pro5_yA[16] = {0.597, 0.597, 0.607, 0.617, 0.621, 0.661, 0.664, 0.678, 0.685, 0.685, 0.675, 0.664, 0.661, 0.624, 0.607, 0.597}; static int pro5_pointsN = 16; static double prepro1_xA[11] = {0.000, 0.000, 0.165, 0.191, 0.284, 0.413, 0.432, 0.409, 0.396, 0.373, 0.274}; static double prepro1_yA[11] = {0.047, 0.327, 0.327, 0.293, 0.223, 0.230, 0.163, 0.143, 0.117, 0.053, 0.027}; static int prepro1_pointsN = 11; static double prepro2_xA[7] = {0.667, 0.667, 0.564, 0.591, 0.663, 0.729, 0.743}; static double prepro2_yA[7] = {0.037, 0.157, 0.280, 0.340, 0.340, 0.287, 0.067}; static int prepro2_pointsN = 7; static double prepro3_xA[6] = {1.003, 0.983, 0.944, 0.937, 0.937, 1.003}; static double prepro3_yA[6] = {0.047, 0.043, 0.070, 0.103, 0.277, 0.330}; static int prepro3_pointsN = 6; static double prepro4_xA[10] = {0.000, 0.033, 0.307, 0.360, 0.386, 0.380, 0.264, 0.155, 0.056, 0.000}; static double prepro4_yA[10] = {0.097, 0.077, 0.060, 0.083, 0.137, 0.183, 0.210, 0.293, 0.307, 0.263}; static int prepro4_pointsN = 10; static double prepro5_xA[5] = {0.677, 0.663, 0.644, 0.677, 0.690}; static double prepro5_yA[5] = {0.217, 0.223, 0.283, 0.277, 0.250}; static int prepro5_pointsN = 5; static double prepro6_xA[5] = {1.000, 0.990, 0.980, 0.980, 1.000}; static double prepro6_yA[5] = {0.100, 0.107, 0.123, 0.207, 0.257}; static int prepro6_pointsN = 5; static double other1_xA[25] = {0.000, 0.359, 0.382, 0.382, 0.316, 0.316, 0.313, 0.270, 0.270, 0.388, 0.388, 0.000, 0.000, 0.010, 0.046, 0.079, 0.082, 0.102, 0.135, 0.184, 0.194, 0.203, 0.178, 0.151, 0.000}; static double other1_yA[25] = {0.000, 0.000, 0.037, 0.214, 0.274, 0.314, 0.331, 0.418, 0.465, 0.585, 0.702, 0.702, 0.599, 0.599, 0.622, 0.625, 0.629, 0.629, 0.622, 0.605, 0.595, 0.562, 0.505, 0.485, 0.388}; static int other1_pointsN = 25; static double other2_xA[4] = {0.671, 0.671, 0.632, 0.632}; static double other2_yA[4] = {0.465, 0.231, 0.264, 0.425}; static int other2_pointsN = 4; static double other3_xA[10] = {0.000, 0.000, 0.362, 0.362, 0.355, 0.345, 0.336, 0.316, 0.303, 0.296}; static double other3_yA[10] = {0.957, 1.000, 1.000, 0.990, 0.980, 0.973, 0.970, 0.963, 0.960, 0.957}; static int other3_pointsN = 10; static double other4_xA[8] = {0.066, 0.303, 0.355, 0.355, 0.329, 0.118, 0.118, 0.066}; static double other4_yA[8] = {0.241, 0.241, 0.207, 0.043, 0.010, 0.010, 0.043, 0.114}; static int other4_pointsN = 8; static double other5_xA[6] = {0.059, 0.349, 0.349, 0.197, 0.164, 0.059}; static double other5_yA[6] = {0.676, 0.676, 0.615, 0.615, 0.649, 0.649}; static int other5_pointsN = 6; int pointI; double d; XPoint pointSA[30]; int phiI, psiI; /* Prepare and check the number of residues: */ residuesN = mol_complexSP->residuesN; if (residuesN <= 0) return -1; /* Find the residue to which the small Ramachandran plot will be assigned: */ chosen_residue_foundF = 0; for (residueI = 0; residueI < residuesN; residueI++) { /* Pointer to the current residue: */ residueSP = mol_complexSP->residueSP + residueI; /* Prepare the atomic index range: */ atom_startI = residueSP->residue_startI; atom_endI = residueSP->residue_endI; /* Pointer to the first atom of the current residue: */ first_atomSP = mol_complexSP->atomSP + atom_startI; /* Editing of a single dihedral angle or a */ /* single pair of dihedral angles requested: */ if (runtimeSP->edit_single_bondF) { /* Check the array indices of N and CA: */ if ((runtimeSP->atom1_arrayI >= atom_startI) && (runtimeSP->atom1_arrayI <= atom_endI) && (runtimeSP->atom2_arrayI >= atom_startI) && (runtimeSP->atom2_arrayI <= atom_endI)) { chosen_residue_foundF = 1; break; } } /* Editing of dihedral angle(s) for all selected residues requested: */ else { /* If the first atom of the current residue is */ /* selected, treat this residue as selected: */ if (first_atomSP->selectedF) { chosen_residue_foundF = 1; break; } } } /* Check was residue found at all: */ if (!chosen_residue_foundF) return -2; /* The name of the chosen residue: */ residue_nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Prepare the name of the next residue, if */ /* the chosen residue is not the last one: */ if (residueI < residuesN - 1) { next_residueSP = mol_complexSP->residueSP + residueI + 1; next_first_atomSP = mol_complexSP->atomSP + next_residueSP->residue_startI; next_residue_nameP = next_first_atomSP->raw_atomS.pure_residue_nameA; } else next_residue_nameP = dummy_nameA; /* The width of small Ramachandran plot should not */ /* exceed one third of the main window free area: */ inner_width = ((guiSP->main_win_free_area_width / 3) / 30) * 30; inner_height = ((guiSP->main_win_free_area_height / 3) / 30) * 30; if (inner_height < inner_width) inner_width = inner_height; else inner_height = inner_width; outer_width = inner_width + 8; outer_height = inner_height + 8; /* The top left corner of the background square: */ screen_x0 = guiSP->main_win_free_area_width - outer_width - 2; screen_y0 = guiSP->main_win_free_area_height - outer_height - 2; /* Draw the filled square. Use a shade of orange color: */ ParseColor_ (&rgbS, &colorID, guiSP, "RGB:D8D8/B7B7/9999", "white"); XSetForeground (guiSP->displaySP, guiSP->theGCA[0], colorID); XFillRectangle (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0, screen_y0, outer_width, outer_height); /* Draw the border, using the main window foreground color: */ XSetForeground (guiSP->displaySP, guiSP->theGCA[0], guiSP->main_winS.fg_colorID); XDrawRectangle (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0, screen_y0, outer_width, outer_height); /* Draw allowed regions. */ /* Prepare the first blue color (light): */ ParseColor_ (&rgbS, &colorID, guiSP, "RGB:5A5A/D5D5/FEFE", "white"); XSetForeground (guiSP->displaySP, guiSP->theGCA[0], colorID); /* Prepare the second blue color (dark): */ ParseColor_ (&rgbS, &colorID, guiSP, "RGB:2222/B8B8/EEEE", "white"); XSetForeground (guiSP->displaySP, guiSP->theGCA[1], colorID); /* Allowed regions for glycine: */ if (strcmp (residue_nameP, "GLY") == 0) { /* The XPoint structures for the first filled polygon: */ for (pointI = 0; pointI < gly1_pointsN; pointI++) { d = guiSP->main_win_free_area_width - outer_width + 2 + inner_width * gly1_xA[pointI]; pointSA[pointI].x = (short) d; d = guiSP->main_win_free_area_height - outer_height + 2 + inner_height * gly1_yA[pointI]; pointSA[pointI].y = (short) d; } /* Draw the first filled polygon: */ XFillPolygon (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], pointSA, gly1_pointsN, Nonconvex, CoordModeOrigin); /* The XPoint structures for the second filled polygon: */ for (pointI = 0; pointI < gly2_pointsN; pointI++) { d = guiSP->main_win_free_area_width - outer_width + 2 + inner_width * gly2_xA[pointI]; pointSA[pointI].x = (short) d; d = guiSP->main_win_free_area_height - outer_height + 2 + inner_height * gly2_yA[pointI]; pointSA[pointI].y = (short) d; } /* Draw the second filled polygon: */ XFillPolygon (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], pointSA, gly2_pointsN, Nonconvex, CoordModeOrigin); /* The XPoint structures for the third filled polygon: */ for (pointI = 0; pointI < gly3_pointsN; pointI++) { d = guiSP->main_win_free_area_width - outer_width + 2 + inner_width * gly3_xA[pointI]; pointSA[pointI].x = (short) d; d = guiSP->main_win_free_area_height - outer_height + 2 + inner_height * gly3_yA[pointI]; pointSA[pointI].y = (short) d; } /* Draw the third filled polygon: */ XFillPolygon (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], pointSA, gly3_pointsN, Nonconvex, CoordModeOrigin); /* The XPoint structures for the fourth filled polygon: */ for (pointI = 0; pointI < gly4_pointsN; pointI++) { d = guiSP->main_win_free_area_width - outer_width + 2 + inner_width * gly4_xA[pointI]; pointSA[pointI].x = (short) d; d = guiSP->main_win_free_area_height - outer_height + 2 + inner_height * gly4_yA[pointI]; pointSA[pointI].y = (short) d; } /* Draw the fourth filled polygon: */ XFillPolygon (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], pointSA, gly4_pointsN, Nonconvex, CoordModeOrigin); /* The XPoint structures for the fifth filled polygon: */ for (pointI = 0; pointI < gly5_pointsN; pointI++) { d = guiSP->main_win_free_area_width - outer_width + 2 + inner_width * gly5_xA[pointI]; pointSA[pointI].x = (short) d; d = guiSP->main_win_free_area_height - outer_height + 2 + inner_height * gly5_yA[pointI]; pointSA[pointI].y = (short) d; } /* Draw the fifth filled polygon: */ XFillPolygon (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], pointSA, gly5_pointsN, Nonconvex, CoordModeOrigin); /* The XPoint structures for the sixth filled polygon: */ for (pointI = 0; pointI < gly6_pointsN; pointI++) { d = guiSP->main_win_free_area_width - outer_width + 2 + inner_width * gly6_xA[pointI]; pointSA[pointI].x = (short) d; d = guiSP->main_win_free_area_height - outer_height + 2 + inner_height * gly6_yA[pointI]; pointSA[pointI].y = (short) d; } /* Draw the sixth filled polygon: */ XFillPolygon (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], pointSA, gly6_pointsN, Nonconvex, CoordModeOrigin); } /* Allowed regions for proline: */ else if (strcmp (residue_nameP, "PRO") == 0) { /* The XPoint structures for the first filled polygon: */ for (pointI = 0; pointI < pro1_pointsN; pointI++) { d = guiSP->main_win_free_area_width - outer_width + 2 + inner_width * pro1_xA[pointI]; pointSA[pointI].x = (short) d; d = guiSP->main_win_free_area_height - outer_height + 2 + inner_height * pro1_yA[pointI]; pointSA[pointI].y = (short) d; } /* Draw the first filled polygon: */ XFillPolygon (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], pointSA, pro1_pointsN, Nonconvex, CoordModeOrigin); /* The XPoint structures for the second filled polygon: */ for (pointI = 0; pointI < pro2_pointsN; pointI++) { d = guiSP->main_win_free_area_width - outer_width + 2 + inner_width * pro2_xA[pointI]; pointSA[pointI].x = (short) d; d = guiSP->main_win_free_area_height - outer_height + 2 + inner_height * pro2_yA[pointI]; pointSA[pointI].y = (short) d; } /* Draw the second filled polygon: */ XFillPolygon (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], pointSA, pro2_pointsN, Nonconvex, CoordModeOrigin); /* The XPoint structures for the third filled polygon: */ for (pointI = 0; pointI < pro3_pointsN; pointI++) { d = guiSP->main_win_free_area_width - outer_width + 2 + inner_width * pro3_xA[pointI]; pointSA[pointI].x = (short) d; d = guiSP->main_win_free_area_height - outer_height + 2 + inner_height * pro3_yA[pointI]; pointSA[pointI].y = (short) d; } /* Draw the third filled polygon: */ XFillPolygon (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], pointSA, pro3_pointsN, Nonconvex, CoordModeOrigin); /* The XPoint structures for the fourth filled polygon: */ for (pointI = 0; pointI < pro4_pointsN; pointI++) { d = guiSP->main_win_free_area_width - outer_width + 2 + inner_width * pro4_xA[pointI]; pointSA[pointI].x = (short) d; d = guiSP->main_win_free_area_height - outer_height + 2 + inner_height * pro4_yA[pointI]; pointSA[pointI].y = (short) d; } /* Draw the fourth filled polygon: */ XFillPolygon (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], pointSA, pro4_pointsN, Nonconvex, CoordModeOrigin); /* The XPoint structures for the fifth filled polygon: */ for (pointI = 0; pointI < pro5_pointsN; pointI++) { d = guiSP->main_win_free_area_width - outer_width + 2 + inner_width * pro5_xA[pointI]; pointSA[pointI].x = (short) d; d = guiSP->main_win_free_area_height - outer_height + 2 + inner_height * pro5_yA[pointI]; pointSA[pointI].y = (short) d; } /* Draw the fifth filled polygon: */ XFillPolygon (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], pointSA, pro5_pointsN, Nonconvex, CoordModeOrigin); } /* Allowed regions for residues preceding proline: */ else if (strcmp (next_residue_nameP, "PRO") == 0) { /* The XPoint structures for the first filled polygon: */ for (pointI = 0; pointI < prepro1_pointsN; pointI++) { d = guiSP->main_win_free_area_width - outer_width + 2 + inner_width * prepro1_xA[pointI]; pointSA[pointI].x = (short) d; d = guiSP->main_win_free_area_height - outer_height + 2 + inner_height * prepro1_yA[pointI]; pointSA[pointI].y = (short) d; } /* Draw the first filled polygon: */ XFillPolygon (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], pointSA, prepro1_pointsN, Nonconvex, CoordModeOrigin); /* The XPoint structures for the second filled polygon: */ for (pointI = 0; pointI < prepro2_pointsN; pointI++) { d = guiSP->main_win_free_area_width - outer_width + 2 + inner_width * prepro2_xA[pointI]; pointSA[pointI].x = (short) d; d = guiSP->main_win_free_area_height - outer_height + 2 + inner_height * prepro2_yA[pointI]; pointSA[pointI].y = (short) d; } /* Draw the second filled polygon: */ XFillPolygon (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], pointSA, prepro2_pointsN, Nonconvex, CoordModeOrigin); /* The XPoint structures for the third filled polygon: */ for (pointI = 0; pointI < prepro3_pointsN; pointI++) { d = guiSP->main_win_free_area_width - outer_width + 2 + inner_width * prepro3_xA[pointI]; pointSA[pointI].x = (short) d; d = guiSP->main_win_free_area_height - outer_height + 2 + inner_height * prepro3_yA[pointI]; pointSA[pointI].y = (short) d; } /* Draw the third filled polygon: */ XFillPolygon (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], pointSA, prepro3_pointsN, Nonconvex, CoordModeOrigin); /* The XPoint structures for the fourth filled polygon: */ for (pointI = 0; pointI < prepro4_pointsN; pointI++) { d = guiSP->main_win_free_area_width - outer_width + 2 + inner_width * prepro4_xA[pointI]; pointSA[pointI].x = (short) d; d = guiSP->main_win_free_area_height - outer_height + 2 + inner_height * prepro4_yA[pointI]; pointSA[pointI].y = (short) d; } /* Draw the fourth filled polygon: */ XFillPolygon (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], pointSA, prepro4_pointsN, Nonconvex, CoordModeOrigin); /* The XPoint structures for the fifth filled polygon: */ for (pointI = 0; pointI < prepro5_pointsN; pointI++) { d = guiSP->main_win_free_area_width - outer_width + 2 + inner_width * prepro5_xA[pointI]; pointSA[pointI].x = (short) d; d = guiSP->main_win_free_area_height - outer_height + 2 + inner_height * prepro5_yA[pointI]; pointSA[pointI].y = (short) d; } /* Draw the fifth filled polygon: */ XFillPolygon (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], pointSA, prepro5_pointsN, Nonconvex, CoordModeOrigin); /* The XPoint structures for the sixth filled polygon: */ for (pointI = 0; pointI < prepro6_pointsN; pointI++) { d = guiSP->main_win_free_area_width - outer_width + 2 + inner_width * prepro6_xA[pointI]; pointSA[pointI].x = (short) d; d = guiSP->main_win_free_area_height - outer_height + 2 + inner_height * prepro6_yA[pointI]; pointSA[pointI].y = (short) d; } /* Draw the sixth filled polygon: */ XFillPolygon (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], pointSA, prepro6_pointsN, Nonconvex, CoordModeOrigin); } /* Allowed regions for all other residues: */ else { /* The XPoint structures for the first filled polygon: */ for (pointI = 0; pointI < other1_pointsN; pointI++) { d = guiSP->main_win_free_area_width - outer_width + 2 + inner_width * other1_xA[pointI]; pointSA[pointI].x = (short) d; d = guiSP->main_win_free_area_height - outer_height + 2 + inner_height * other1_yA[pointI]; pointSA[pointI].y = (short) d; } /* Draw the first filled polygon: */ XFillPolygon (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], pointSA, other1_pointsN, Nonconvex, CoordModeOrigin); /* The XPoint structures for the second filled polygon: */ for (pointI = 0; pointI < other2_pointsN; pointI++) { d = guiSP->main_win_free_area_width - outer_width + 2 + inner_width * other2_xA[pointI]; pointSA[pointI].x = (short) d; d = guiSP->main_win_free_area_height - outer_height + 2 + inner_height * other2_yA[pointI]; pointSA[pointI].y = (short) d; } /* Draw the second filled polygon: */ XFillPolygon (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], pointSA, other2_pointsN, Nonconvex, CoordModeOrigin); /* The XPoint structures for the third filled polygon: */ for (pointI = 0; pointI < other3_pointsN; pointI++) { d = guiSP->main_win_free_area_width - outer_width + 2 + inner_width * other3_xA[pointI]; pointSA[pointI].x = (short) d; d = guiSP->main_win_free_area_height - outer_height + 2 + inner_height * other3_yA[pointI]; pointSA[pointI].y = (short) d; } /* Draw the third filled polygon: */ XFillPolygon (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], pointSA, other3_pointsN, Nonconvex, CoordModeOrigin); /* The XPoint structures for the fourth filled polygon: */ for (pointI = 0; pointI < other4_pointsN; pointI++) { d = guiSP->main_win_free_area_width - outer_width + 2 + inner_width * other4_xA[pointI]; pointSA[pointI].x = (short) d; d = guiSP->main_win_free_area_height - outer_height + 2 + inner_height * other4_yA[pointI]; pointSA[pointI].y = (short) d; } /* Draw the fourth filled polygon: */ XFillPolygon (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], pointSA, other4_pointsN, Nonconvex, CoordModeOrigin); /* The XPoint structures for the fifth filled polygon: */ for (pointI = 0; pointI < other5_pointsN; pointI++) { d = guiSP->main_win_free_area_width - outer_width + 2 + inner_width * other5_xA[pointI]; pointSA[pointI].x = (short) d; d = guiSP->main_win_free_area_height - outer_height + 2 + inner_height * other5_yA[pointI]; pointSA[pointI].y = (short) d; } /* Draw the fifth filled polygon: */ XFillPolygon (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], pointSA, other5_pointsN, Nonconvex, CoordModeOrigin); } /* Draw small blue squares at the positions of alpha helix and beta sheet. */ /* Prepare the blue color: */ XSetForeground (guiSP->displaySP, guiSP->theGCA[0], guiSP->blue_colorID); /* Draw square at the position of alpha helix: */ d = 0.342 * (double) inner_width; screen_x0 = guiSP->main_win_free_area_width - outer_width + 2 + (int) d; d = 0.631 * (double) inner_height; screen_y0 = guiSP->main_win_free_area_height - outer_height + 2 + (int) d; XFillRectangle (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0 - 4, screen_y0 - 4, 9, 9); /* Draw square at the position of beta sheet: */ d = 0.114 * (double) inner_width; screen_x0 = guiSP->main_win_free_area_width - outer_width + 2 + (int) d; d = 0.124 * (double) inner_height; screen_y0 = guiSP->main_win_free_area_height - outer_height + 2 + (int) d; XFillRectangle (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0 - 4, screen_y0 - 4, 9, 9); /* Prepare black color for grid: */ XSetForeground (guiSP->displaySP, guiSP->theGCA[0], guiSP->black_colorID); /* Draw vertical grid using the spacing of 90 degrees: */ screen_x0 = guiSP->main_win_free_area_width - outer_width + 2; screen_y0 = guiSP->main_win_free_area_height - outer_height + 2; screen_y1 = screen_y0 + inner_height; for (phiI = 0; phiI <= 5; phiI++) { d = (double) inner_width * ((double) phiI * 0.25) + 0.5; screen_x1 = screen_x0 + (int) d; XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x1, screen_y0, screen_x1, screen_y1); } /* Draw horizontal grid, using the spacing of 90 degrees: */ screen_x0 = guiSP->main_win_free_area_width - outer_width + 2; screen_x1 = screen_x0 + inner_width; screen_y0 = guiSP->main_win_free_area_height - outer_height + 2; for (psiI = 0; psiI <= 5; psiI++) { d = (double) inner_height * ((double) psiI * 0.25) + 0.5; screen_y1 = screen_y0 + (int) d; XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0, screen_y1, screen_x1, screen_y1); } /* Draw the symbol at the position defined */ /* by phi and psi for the current residue. */ /* Prepare the symbol position: */ d = (double) inner_width * (residueSP->phi + 3.1415927) * 0.15915494; screen_x0 = guiSP->main_win_free_area_width - outer_width + 2 + (int) d; d = (double) inner_height * (residueSP->psi + 3.1415927) * 0.15915494; screen_y0 = guiSP->main_win_free_area_height - 6 - (int) d; /* Draw the outer part of the symbol (red): */ XSetForeground (guiSP->displaySP, guiSP->theGCA[0], guiSP->red_colorID); XDrawRectangle (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0 - 3, screen_y0 - 3, 6, 6); /* Draw the inner part of the symbol (yellow): */ XSetForeground (guiSP->displaySP, guiSP->theGCA[0], guiSP->yellow_colorID); XFillRectangle (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0 - 2, screen_y0 - 2, 5, 5); /* Return positive value on success: */ return 1; } /*===========================================================================*/ garlic-1.6/commands.h0000644000076500007650000001063310346113355015065 0ustar zuciczucic00000000000000/* Copyright (C) 2001-2005 Damir Zucic */ /* Command codes - return values from ExecuteCommand_ () function. */ /* Positive (success) codes: */ #define COMMAND_QUIT 1 #define COMMAND_IGNORE 2 #define COMMAND_LOAD 3 #define COMMAND_DISCARD 4 #define COMMAND_CATCH 5 #define COMMAND_SELECT 6 #define COMMAND_SHOW 7 #define COMMAND_HIDE 8 #define COMMAND_COLOR 9 #define COMMAND_ATOMS 10 #define COMMAND_BONDS 11 #define COMMAND_CONTINUE 12 #define COMMAND_PAUSE 13 #define COMMAND_EXECUTE 14 #define COMMAND_ROTATE 15 #define COMMAND_TRANSLATE 16 #define COMMAND_SLAB 17 #define COMMAND_FADING 18 #define COMMAND_LOG 19 #define COMMAND_FOREGROUND 20 #define COMMAND_BACKGROUND 21 #define COMMAND_TBG 22 #define COMMAND_TFG 23 #define COMMAND_FONT 24 #define COMMAND_BACKBONE 25 #define COMMAND_HYBONDS 26 #define COMMAND_STEREO 27 #define COMMAND_MONO 28 #define COMMAND_POSITION 29 #define COMMAND_TITLE 30 #define COMMAND_LABELS 31 #define COMMAND_REGISTER 32 #define COMMAND_CENTER 33 #define COMMAND_SAVE 34 #define COMMAND_TAG 35 #define COMMAND_SEQUENCE 36 #define COMMAND_RAMACHANDRAN 37 #define COMMAND_WHEEL 38 #define COMMAND_ANGLE 39 #define COMMAND_RADIUS 40 #define COMMAND_VENN 41 #define COMMAND_DISULFIDE 42 #define COMMAND_WINDOW 43 #define COMMAND_PLOT 44 #define COMMAND_MOVE 45 #define COMMAND_PLANE 46 #define COMMAND_SCALE 47 #define COMMAND_PATTERN 48 #define COMMAND_DOCK 49 #define COMMAND_COMPARE 50 #define COMMAND_NEIGHBORHOOD 51 #define COMMAND_STRUCTURE 52 #define COMMAND_CREATE 53 #define COMMAND_REPLACE 54 #define COMMAND_EDIT 55 #define COMMAND_MEMBRANE 56 #define COMMAND_SET 57 #define COMMAND_PROBE 58 #define COMMAND_REFRESH 59 #define COMMAND_STICKS 60 #define COMMAND_BALLS 61 #define COMMAND_BLUR 62 #define COMMAND_GROUP 63 #define COMMAND_DUMP 64 /* Negative (error) codes: */ #define ERROR_UNREC_COMM -1 #define ERROR_LOAD -2 #define ERROR_NO_FILE_NAME -3 #define ERROR_OPEN_FAILURE -4 #define ERROR_NO_ID -5 #define ERROR_BAD_ID -6 #define ERROR_SELECT -7 #define ERROR_NO_SCHEME -8 #define ERROR_BAD_SCHEME -9 #define ERROR_NO_ATOM_STYLE -10 #define ERROR_ATOM_STYLE -11 #define ERROR_NO_BOND_STYLE -12 #define ERROR_BOND_STYLE -13 #define ERROR_EXECUTE -14 #define ERROR_NO_AXIS -15 #define ERROR_BAD_AXIS -16 #define ERROR_NO_ANGLE -17 #define ERROR_NO_SHIFT -18 #define ERROR_BAD_SURFACE -19 #define ERROR_SLAB -20 #define ERROR_FADING -21 #define ERROR_LOG -22 #define ERROR_FOREGROUND -23 #define ERROR_BACKGROUND -24 #define ERROR_NO_COLOR -25 #define ERROR_TBG -26 #define ERROR_TFG -27 #define ERROR_FONT -28 #define ERROR_NO_FONT_NAME -29 #define ERROR_BACKBONE -30 #define ERROR_HYBONDS -31 #define ERROR_STEREO -32 #define ERROR_MONO -33 #define ERROR_POSITION -34 #define ERROR_TITLE -35 #define ERROR_LABELS -36 #define ERROR_CENTER -37 #define ERROR_SAVE -38 #define ERROR_TAG -39 #define ERROR_SEQUENCE -40 #define ERROR_RAMACHANDRAN -41 #define ERROR_WHEEL -42 #define ERROR_ANGLE -43 #define ERROR_RADIUS -44 #define ERROR_VENN -45 #define ERROR_WINDOW -46 #define ERROR_PLOT -47 #define ERROR_MOVE -48 #define ERROR_PLANE -49 #define ERROR_SCALE -50 #define ERROR_PATTERN -51 #define ERROR_DOCK -52 #define ERROR_COMPARE -53 #define ERROR_NEIGHBORHOOD -54 #define ERROR_STRUCTURE -55 #define ERROR_CREATE -56 #define ERROR_REPLACE -57 #define ERROR_EDIT -58 #define ERROR_MEMBRANE -59 #define ERROR_SET -60 #define ERROR_PROBE -61 #define ERROR_REFRESH -62 #define ERROR_STICKS -63 #define ERROR_BALLS -64 #define ERROR_BLUR -65 #define ERROR_GROUP -66 #define ERROR_DUMP -67 garlic-1.6/select_cis_trans.c0000644000076500007650000000701007465735020016605 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2002 Damir Zucic */ /*============================================================================= select_cis_trans.c Purpose: Select cis, trans or bad/undefined peptide groups. More precisely, only residues which contribute N and CA atom to peptide unit are selected, though the peptide group belongs to two residues. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. (3) Selection mode index (0 = overwrite, 1 = restrict, 2 = expand previous selection). (4) Peptide unit conformation index (0 = bad, 1 = trans, 2 = cis). Output: (1) The flag selectedF set for atoms belonging to residues which have the specified conformation of the peptide unit. More precisely, for atoms which belong to residues whose CA and N atoms are involved in a formation of a peptide unit having the specified type of conformation. (2) Return value. Return value: (1) The number of selected atoms (zero or positive value). Notes: (1) The position_changedF is updated, because some atoms may not have the proper color. ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======select cis, trans or bad residues:===================================*/ long SelectCisTrans_ (MolComplexS *mol_complexSP, int mol_complexesN, int selection_modeI, int input_cis_transF) { long selected_atomsN = 0; int mol_complexI; MolComplexS *curr_mol_complexSP; size_t atomsN, atomI; AtomS *curr_atomSP; ResidueS *curr_residueSP; int curr_cis_transF; int conformationF; /* Check every macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /** Pointer to the current macromolecular complex: **/ curr_mol_complexSP = mol_complexSP + mol_complexI; /** Check is the current macromolecular complex caught: **/ if (curr_mol_complexSP->catchF == 0) continue; /** Number of atoms in a macromolecular complex: **/ atomsN = curr_mol_complexSP->atomsN; /** Scan all atoms in the current complex: **/ for (atomI = 0; atomI < atomsN; atomI++) { /** Pointer to the current atom: **/ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /** Pointer to the current residue: **/ curr_residueSP = mol_complexSP->residueSP + curr_atomSP->residue_arrayI; /** Prepare the cis_transF: **/ curr_cis_transF = curr_residueSP->cis_transF; /** Prepare the conformation flag: **/ conformationF = 0; if (curr_cis_transF == input_cis_transF) conformationF = 1; /** Set the selection flag for the current atom: **/ switch (selection_modeI) { /*** Overwrite the previous selection: ***/ case 0: curr_atomSP->selectedF = conformationF; break; /*** Restrict the previous selection: ***/ case 1: curr_atomSP->selectedF &= conformationF; break; /*** Expand the previous selection: ***/ case 2: curr_atomSP->selectedF |= conformationF; break; default: ; } /** Check the selection flag; increase **/ /** the count if flag is equal to one: **/ if (curr_atomSP->selectedF) selected_atomsN++; } /** Update the position_changedF (some atoms may have bad color): **/ curr_mol_complexSP->position_changedF = 1; } /* Return the number of selected atoms: */ return selected_atomsN; } /*===========================================================================*/ garlic-1.6/big_spheres.c0000644000076500007650000003172207747301334015562 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2003 Damir Zucic */ /*============================================================================= big_spheres.c Purpose: Draw atoms as big spheres. Input: (1) Pointer to MolComplexS structure. (2) Number of macromolecular complexes. (3) Pointer to ConfigS structure, with configuration data. (4) Pointer to GUIS structure. (5) Pointer to NearestAtomS structure, with information about the atom occupying the given pixel. (6) The number of pixels in the main window free area. (7) The refreshI, used to check the NearestAtomS associated with a given pixel. Output: (1) Spheres drawn to the hidden pixmap. (2) Return value. Return value: (1) Positive always (trivial). Notes: (1) Indentation is exceptionally 4 spaces. (2) The atomic radii used in this function are based on the radii used in spacefill drawing function (spacefill.c). The values used here are 50% larger. =============================================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ unsigned long SpacefillColor_ (AtomS *, GUIS *, double); /*======draw atoms as big spheres:===========================================*/ int DrawBigSpheres_ (MolComplexS *mol_complexSP, int mol_complexesN, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int refreshI) { int imageI, imagesN; double scale_factor, user_atomic_position; int left_edge[2], right_edge[2]; int mol_complexI; MolComplexS *curr_mol_complexSP; size_t atomsN, atomI; AtomS *curr_atomSP; int screen_x0, screen_y0; double radius, radius_squared; double denominator, reciprocal_denominator; int screen_radius; long screen_radius_squared; int screen_x1, screen_y1, screen_x2, screen_y2; int screen_x, screen_y; long delta_x, delta_y, distance_squared; double z0, front_z, delta_z, z; size_t pixelI; NearestAtomS *curr_pixelSP; double denominator2, reciprocal_denominator2; double rho_squared; VectorS vectorS; double abs_value, abs_value_squared; double scalar_product, cos_angle; unsigned long colorID; int bondI; /* Initialize the bond index. The negative value means that pixels */ /* filled in this function are not a part of any chemical bond. */ bondI = -1; /* Number of images: */ if (configSP->stereoF) imagesN = 2; else imagesN = 1; scale_factor = configSP->user_screen_atomic_distance * configSP->atomic_to_screen_scale_x; /* Prepare the user position in atomic coordinates: */ user_atomic_position = configSP->user_atomic_position; /* Left and right image edge (in stereo mode there are two images): */ left_edge[0] = configSP->image_screen_x0[0]; right_edge[0] = configSP->image_screen_x1[0]; left_edge[1] = configSP->image_screen_x0[1]; right_edge[1] = configSP->image_screen_x1[1]; /*------first pass - fill NearestAtomS array with planar atoms:--------------*/ /* Draw each macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Prepare and check the number of atoms: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Draw atoms which have the given style: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Check style: */ if (curr_atomSP->raw_atomS.atom_styleI != BIG_SPHERE) continue; /* Check is atom hidden: */ if (curr_atomSP->hiddenF) continue; /* Check is atom inside slab: */ if (!curr_atomSP->inside_slabF) continue; /* Check is atom inside window: */ if (!curr_atomSP->inside_windowF) continue; /* Atomic radius, in atomic units: */ radius = curr_atomSP->raw_atomS.van_der_Waals_radius; /* Squared atomic radius: */ radius_squared = radius * radius; /* The y coordinate of atomic center, in screen units: */ screen_y0 = curr_atomSP->raw_atomS.screen_y; /* Prepare one image (mono) or two images (stereo): */ for (imageI = 0; imageI < imagesN; imageI++) { /* The z coordinate of atomic center, in atomic units: */ z0 = curr_atomSP->raw_atomS.z[imageI]; /* Prepare the factor required for projection of atomic radius: */ denominator = z0 - user_atomic_position; if (denominator == 0.0) continue; reciprocal_denominator = 1.0 / denominator; /* Atomic radius in screen units: */ screen_radius = (int) (radius * scale_factor * reciprocal_denominator + 0.5); /* Screen radius squared (used to improve speed): */ screen_radius_squared = (long) screen_radius * (long) screen_radius; /* The x coordinate of atomic center, in screen units: */ screen_x0 = curr_atomSP->raw_atomS.screen_x[imageI]; /* Define the bounding rectangle: */ screen_x1 = screen_x0 - screen_radius; screen_y1 = screen_y0 - screen_radius; screen_x2 = screen_x0 + screen_radius; screen_y2 = screen_y0 + screen_radius; /* Horizontal scan: */ for (screen_x = screen_x1; screen_x <= screen_x2; screen_x++) { /* Check horizontal position: */ if (screen_x < left_edge[imageI]) continue; if (screen_x >= right_edge[imageI]) continue; /* Vertical scan: */ for (screen_y = screen_y1; screen_y <= screen_y2; screen_y++) { /* Check vertical position: */ if (screen_y < 0) continue; if (screen_y >= (int) guiSP->main_win_free_area_height) { continue; } /* Check distance from the circle center: */ delta_x = (long) (screen_x - screen_x0); delta_y = (long) (screen_y - screen_y0); distance_squared = delta_x * delta_x + delta_y * delta_y; if (distance_squared > screen_radius_squared) continue; /* Prepare index to the array */ /* of NearestAtomS structures: */ pixelI = guiSP->main_win_free_area_width * screen_y + screen_x; /* Check the pixel index: */ if (pixelI >= pixelsN) continue; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = nearest_atomSP + pixelI; /* Check was this pixel used already in */ /* this drawing step; if it was, compare */ /* the z value of the current atom with z */ /* value previously stored to this pixel: */ if (refreshI == curr_pixelSP->last_refreshI) { if (z0 > curr_pixelSP->z) continue; } /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = BIG_SPHERE; curr_pixelSP->last_refreshI = refreshI; curr_pixelSP->mol_complexI = mol_complexI; curr_pixelSP->atomI = atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = z0; } } } /* imageI loop */ } /* atomI loop */ } /* mol_complexI loop */ /*------second pass - draw spherical atoms:----------------------------------*/ /* Draw each macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Prepare and check the number of atoms: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Draw atoms which have the given style: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Check style: */ if (curr_atomSP->raw_atomS.atom_styleI != BIG_SPHERE) continue; /* Check is atom hidden: */ if (curr_atomSP->hiddenF) continue; /* Check is atom inside slab: */ if (!curr_atomSP->inside_slabF) continue; /* Check is atom inside window: */ if (!curr_atomSP->inside_windowF) continue; /* Atomic radius, in atomic units: */ radius = curr_atomSP->raw_atomS.van_der_Waals_radius; /* Squared atomic radius: */ radius_squared = radius * radius; /* The y coordinate of atomic center, in screen units: */ screen_y0 = curr_atomSP->raw_atomS.screen_y; /* Prepare one image (mono) or two images (stereo): */ for (imageI = 0; imageI < imagesN; imageI++) { /* The z coordinate of atomic center, in atomic units: */ z0 = curr_atomSP->raw_atomS.z[imageI]; /* The z coordinate of the nearest */ /* point of a given atom (sphere): */ front_z = z0 - radius; /* Prepare the factor required for projection of atomic radius: */ denominator = z0 - user_atomic_position; if (denominator == 0.0) continue; reciprocal_denominator = 1.0 / denominator; /* Atomic radius in screen units: */ screen_radius = (int) (radius * scale_factor * reciprocal_denominator + 0.5); /* Square of the atomic radius (in screen units): */ screen_radius_squared = (long) screen_radius * (long) screen_radius; /* Reciprocal value will be used to improve performance: */ denominator2 = (double) screen_radius_squared; if (denominator2 == 0.0) continue; reciprocal_denominator2 = 1.0 / denominator2; /* The x coordinate of atomic center, in screen units: */ screen_x0 = curr_atomSP->raw_atomS.screen_x[imageI]; /* Define the bounding rectangle: */ screen_x1 = screen_x0 - screen_radius; screen_y1 = screen_y0 - screen_radius; screen_x2 = screen_x0 + screen_radius; screen_y2 = screen_y0 + screen_radius; /* Horizontal scan: */ for (screen_x = screen_x1; screen_x <= screen_x2; screen_x++) { /* Check horizontal position: */ if (screen_x < left_edge[imageI]) continue; if (screen_x > right_edge[imageI]) continue; /* Vertical scan: */ for (screen_y = screen_y1; screen_y <= screen_y2; screen_y++) { /* Check vertical position: */ if (screen_y < 0) continue; if (screen_y >= (int) guiSP->main_win_free_area_height) { continue; } /* Check distance from the circle center: */ delta_x = (long) (screen_x - screen_x0); delta_y = (long) (screen_y - screen_y0); distance_squared = delta_x * delta_x + delta_y * delta_y; if (distance_squared > screen_radius_squared) continue; /* Prepare index to the array */ /* of NearestAtomS structures: */ pixelI = guiSP->main_win_free_area_width * screen_y + screen_x; /* Check the pixel index: */ if (pixelI >= pixelsN) continue; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = nearest_atomSP + pixelI; /* Check z value (this is just a quick check): */ if (refreshI == curr_pixelSP->last_refreshI) { if (front_z > curr_pixelSP->z) continue; } /* Calculate the accurate z value: */ rho_squared = radius_squared * (double) distance_squared * reciprocal_denominator2; delta_z = sqrt (fabs (radius_squared - rho_squared)); z = z0 - delta_z; /* Check z value (precise check): */ if (refreshI == curr_pixelSP->last_refreshI) { if (z > curr_pixelSP->z) continue; } /* The vector from sphere center to the current pixel: */ vectorS.x = (double) delta_x; vectorS.y = (double) delta_y; vectorS.z = - sqrt (fabs (screen_radius_squared - vectorS.x * vectorS.x - vectorS.y * vectorS.y)); abs_value_squared = vectorS.x * vectorS.x + vectorS.y * vectorS.y + vectorS.z * vectorS.z; abs_value = sqrt (abs_value_squared); /* The scalar product between this */ /* vector and light source vector: */ scalar_product = vectorS.x * configSP->light_vectorS.x + vectorS.y * configSP->light_vectorS.y + vectorS.z * configSP->light_vectorS.z; /* Cosine of the angle between the vector to the */ /* current pixel and the light source unit vector: */ if (abs_value == 0.0) cos_angle = 0.0; else cos_angle = scalar_product / abs_value; /* Prepare color: */ colorID = SpacefillColor_ (curr_atomSP, guiSP, cos_angle); XSetForeground (guiSP->displaySP, guiSP->theGCA[0], colorID); XDrawPoint (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x, screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = BIG_SPHERE; curr_pixelSP->last_refreshI = refreshI; curr_pixelSP->mol_complexI = mol_complexI; curr_pixelSP->atomI = atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = z; curr_pixelSP->colorID = colorID; } } } /* imageI loop */ } /* atomI loop */ } /* mol_complexI loop */ /*---------------------------------------------------------------------------*/ /* Return positive value (trivial): */ return 1; } /*===========================================================================*/ garlic-1.6/sample.script0000644000076500007650000000052207045617035015624 0ustar zuciczucic00000000000000load 2por.pdb select side hide select hetero hide select 73-113, 206-222 hide rotate x 90 translate y 5 select backbone bonds 2 atoms 0 color orange select 1-15, 59-72, 148-170, 228-253, 290-301 color red sel */* exc 73-113, 206-222/phe, tyr, trp, met, leu, ile/* exc c, n, o show color cyan bonds 5 atoms 0 slab back -35 fading back -35 garlic-1.6/prepare_cursor.c0000644000076500007650000001316107466232752016325 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2002 Damir Zucic */ /*============================================================================= prepare_cursor.c Purpose: Prepare cursor. Use either default garlic cursor, or one of X11 predefined cursors. If cursor name is not recognized, replace with "crosshair". Input: (1) Pointer to GUIS structure. (2) Cursor name (based on /usr/include/X11/cursorfont.h). Output: Return value. Return value: Cursor ID. ========includes:============================================================*/ #include #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======defines:=============================================================*/ #define NAMESNUM 78 /*======prepare the main window cursor:======================================*/ Cursor PrepareCursor_ (GUIS *guiSP, char *nameP) { static unsigned int cursor_shape_width = 16, cursor_shape_height = 16; static unsigned char cursor_shape_bits[32] = {0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00}; Pixmap shape_pixmapID; static unsigned int cursor_mask_width = 16, cursor_mask_height = 16; static unsigned char cursor_mask_bits[32] = {0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0x80, 0x00, 0x1f, 0x7c, 0x3f, 0x7e, 0x1f, 0x7c, 0x80, 0x00, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0x00, 0x00}; Pixmap mask_pixmapID; XColor fg_colorS, bg_colorS; Cursor cursorID; int i; struct CursorNameS { char nameA[20]; unsigned cursorID; }; struct CursorNameS cnSA[NAMESNUM] = { {"X_cursor", 0}, {"arrow", 2}, {"based_arrow_down", 4}, {"based_arrow_up", 6}, {"boat", 8}, {"bogosity", 10}, {"bottom_left_corner", 12}, {"bottom_right_corner", 14}, {"bottom_side", 16}, {"bottom_tee", 18}, {"box_spiral", 20}, {"center_ptr", 22}, {"circle", 24}, {"clock", 26}, {"coffee_mug", 28}, {"cross", 30}, {"cross_reverse", 32}, {"crosshair", 34}, {"diamond_cross", 36}, {"dot", 38}, {"dotbox", 40}, {"double_arrow", 42}, {"draft_large", 44}, {"draft_small", 46}, {"draped_box", 48}, {"exchange", 50}, {"fleur", 52}, {"gobbler", 54}, {"gumby", 56}, {"hand1", 58}, {"hand2", 60}, {"heart", 62}, {"icon", 64}, {"iron_cross", 66}, {"left_ptr", 68}, {"left_side", 70}, {"left_tee", 72}, {"leftbutton", 72}, {"ll_angle", 76}, {"lr_angle", 78}, {"man", 80}, {"middlebutton", 82}, {"mouse", 84}, {"pencil", 86}, {"pirate", 88}, {"plus", 90}, {"question_arrow", 92}, {"right_ptr", 94}, {"right_side", 96}, {"right_tee", 98}, {"rightbutton", 100}, {"rtl_logo", 102}, {"sailboat", 104}, {"sb_down_arrow", 106}, {"sb_h_double_arrow", 108}, {"sb_left_arrow", 110}, {"sb_right_arrow", 112}, {"sb_up_arrow", 114}, {"sb_v_double_arrow", 116}, {"shuttle", 118}, {"sizing", 120}, {"spider", 122}, {"spraycan", 124}, {"star", 126}, {"target", 128}, {"tcross", 130}, {"top_left_arrow", 132}, {"top_left_corner", 134}, {"top_right_corner", 136}, {"top_side", 138}, {"top_tee", 140}, {"trek", 142}, {"ul_angle", 144}, {"umbrella", 146}, {"ur_angle", 148}, {"watch", 150}, {"xterm", 152}, {"num_glyphs", 154}}; /* Check is default cursor required: */ if (strcmp (nameP, "default") == 0) { /** Prepare the shape pixmap: **/ shape_pixmapID = XCreatePixmapFromBitmapData ( guiSP->displaySP, RootWindow (guiSP->displaySP, guiSP->screenID), (char *) cursor_shape_bits, cursor_shape_width, cursor_shape_height, 1, 0, 1); /** Prepare the mask pixmap: **/ mask_pixmapID = XCreatePixmapFromBitmapData ( guiSP->displaySP, RootWindow (guiSP->displaySP, guiSP->screenID), (char *) cursor_mask_bits, cursor_mask_width, cursor_mask_height, 1, 0, 1); /** Prepare colors: **/ XParseColor (guiSP->displaySP, guiSP->colormapID, "black", &fg_colorS); XParseColor (guiSP->displaySP, guiSP->colormapID, "white", &bg_colorS); /** Create the main window cursor: **/ cursorID = XCreatePixmapCursor (guiSP->displaySP, shape_pixmapID, mask_pixmapID, &fg_colorS, &bg_colorS, 7, 7); /** Return the cursor ID: **/ return cursorID; } /* Default garlic cursor not required; compare */ /* the specified cursor name with X11 cursors: */ if (strlen (nameP) > 0) { /* Try to recognize cursor name; create cursor and return ID: */ for (i = 0; i < NAMESNUM; i++) { if (strcmp (nameP, cnSA[i].nameA) == 0) { return XCreateFontCursor (guiSP->displaySP, cnSA[i].cursorID); } } } /* Return default (crosshair) cursor ID if cursor name not recognized: */ return XCreateFontCursor (guiSP->displaySP, XC_crosshair); } /*===========================================================================*/ garlic-1.6/squid.xpm0000644000076500007650000002250307303426361014770 0ustar zuciczucic00000000000000/* XPM */ static char *squid_xpm[] = { /* width height num_colors chars_per_pixel */ "211 43 11 1", /* Colors: */ " c None", ". c #160C02", "+ c #536A87", "@ c #02FEFA", "# c #90A2A9", "$ c #D93D09", "% c #2ECECE", "& c #2C4434", "* c #EEE9D3", "= c #CAA677", "- c #A8642B", /* Pixels: */ " ", " ....... ", " ..####*##... ", " .##*******=*#.. ", " .###***********#. ", " .#+**************=. ", " .#+##=#-#=-****#****. ", " ..+#*#-+$#-+#-+=#****=#... ", " ............#+=#+-&$.$$..##*********=#... ", " ......... ... .... .........###=#*#=#=#--#-+$..$.$.=#*************###......... ", " ....#++$-+++#...... ...###........##*#.... ........#*#**=*****************---$.$..#=****************=*########... ", " ..#.-$$$$--$$$$$$$-+#..... ....###*##=+#####+*******=..............#=##==******************************=-#*****#=#=+###==#**=*********=##. ", " ...+.$.$$$$$-=$-$------$$-+##....###-*#%###*##*=-.********************=****************=*===--=-========-=*=#****#=+=#=---+-+$.-++-==*********#. ", " ...#&.$$$$-$$-$-=----.$----$-----#-=-=*=%+%%%=*+****.+***--=---+=---=-----------$-$$$$$$$$$$$$-$-$$------====-#=*+##&#-#-+-+&$$.$&.$..$.+#=#******#. ", " .+&&.-$+-#-####-==*====----$$.$$#=*====*##%****%##***+.*=$$.$$$$$$$$$$$$$$$$$$$$$$$$-$$$$-$$-$===-====*===**-#=*++-&-+&&+&.+$.&&..$.$.$..$.&+###****=. ", " ....--#-#==#+#&&.&&.&&&#===-+-$$-$-$$-=*#=*+%%*+&&#*=#**##.-=$$$$$$$$$$$$$$$$$$-$$$-$---=-===-=====*=*=******#-#*=##-+-+$$.$-+$-+-.-$--&-+$.......-#*#**=#. ", " ..#+###=+=##%.....+-+&&...&-$--$--===#=*===*##%*+&...#*+%**#.+*-$$$$$$$$$$$$-$-----==-==-*====*=*=*********=##-**####&$#-#-$=#-#--++-+&+++&&&-+&$$--#$+#####. ", " ..+$$&.+&#==+.. ..#=#-$$-----#-++&++&&#=*=*=+%*+....-*++*==&.*=$$$$$-$---=-=-=========*=*****************##*****=#-==-=-#-=---++-++&&.&.&.&.$$--==+#-+###.. ", " .####+##++.$+. ...+++-+-==-=-+&&&++&+&+.&+#***+%*&...&$*+++=-$.=*------=-===========*=********************#*****=#-=#-=#--=--+$$&.&.&$.$...$$-#==###....... ", " ...%*####+-+#... ..#==#-#--#-&++&&&.&....$==******+%*+&..&*%&&##=+.=*-=-========*=*==**=****************************-==-==-=-$$$.$.$........$$-===###... ", " ...###*#%+##.... ..#-#+&&.&.&.&&&...&.-=*****=###**=&#*&&&*%&&$-$$$.**=====*=**=**********************************=-*=-===---$&.&$......&.$$-===###... ", " ...###%##++&#.. ..#==#==$+$ .&.$$-===***==+&$.&$-#=#+.+***%&.&-$&$&.****=*=*=**********************************=*=*====-=$-.$.$.......$$-=*=####... ", " ..##*##%+++#... ..####...$. ..==****=#=-+.==-#$*****#=&&&&....$+$.$.$***=*=***********************************=**===#-=&$&...&..$.$.$-==*=#+##... ", " ........... ....=%#%+&##... ..=+=#..$ ..=-=---$$.$$.$=-$-****==#=++&&&.&.-.$.$.&***==#*==*=****************************=*====-==-$$$.$&.$.$$--==*=*####... ", " ..##+=##$####.. ...#=%*#+#=... ..###=.. ..+$$$--$$.$$$=---*=*=*#+++++&&&..&-$$&.$&.&=#*==-=====*=*********************=*=-=-*===--$$$+$.$.$---==*=*#-###... ", " ..##*#-&++#*##+##.. ....##%*=++#... ...$=#.. .....#=#-===#...$-$-=-*==+++++&...+$#...+-&+-&$&...#=#*=*-#=+-##-=#********=====-====-=-=$$#-$+-$-----=*==*=####..... ", " .++%%#+&&-+&##-#=$##....###*###&#... ....#-#=. ..+$$+----$=$.. ..$-+*=+=#.&&+-###.... .##-+##. ..##+#*===*=*===-=-=-*-=#--===#-$=-=-#-=--====*=*===#####.... ", " .. ..&+&&&&&+&&%&+%&&#+%###%++&+... ...$#==#=$. ..-$........... .=-*+==-#-=##...... ...... .....*=+#==*=****==*=============*=*=******=#.......... ", ".++... .&&&.%...%.%&&&&&+&++&&&... .&#+#=-#&.. .#-.. ..-$#==**=#.... ........=#==*#=*=***=*==*=====#=#=*#.... ", ".++&##.. ..&..&%.%.&..&..&&++... ..##+=+#+.. .#.. .....++*-#...... .......*#############....... ", " .$+#***. ..+#.&.&.&&&+..... .##*##-... ... .......&+$#+-=... .............. ", " .+..*#*=. ........... ...*#=#&&. ..=+$.$&.&=.. ", " .##.+&**. ..#*=#+&#.. ......... ", " .*.&+&#*. ...#####&... ", " .+&.+&#*. ..+####&++. ", " ...&&&==. ...@##+++&*.. ", " .+#&&&#.. ......#&#+++#&#.. ", " ..+#-+&+.........####+++++&#.... ", " ..+&&+&+#%&##+%+#+%&+#+&.. ", " ...&&&+++++&++&+###... ", " ...++#&+#+...... ", " ....... ", " "}; garlic-1.6/stereo.c0000644000076500007650000000622707107756413014575 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= stereo.c Purpose: Execute stereo command. Input: (1) Pointer to MolComplexS structure. (2) The number of macromolecular complexes. (3) Pointer to RuntimeS structure. (4) Pointer to ConfigS structure. (5) Pointer to GUIS structure. (6) Pointer to NearestAtomS structure. (7) The number of pixels in the main window free area. (8) Pointer to refreshI. (9) Pointer to the remainder of the command string. It is either empty or contains the keyword OFF. Output: (1) Stereo flag set. (2) Return value. Return value: (1) Positive (command) code on success. (2) Negative (error) code on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "commands.h" #include "typedefs.h" /*======function prototypes:=================================================*/ char *ExtractToken_ (char *, int, char *, char *); int CalculateParameters_ (ConfigS *, GUIS *); int PrepareStereoData_ (MolComplexS *, ConfigS *); size_t MainRefresh_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); int ControlRefresh_ (MolComplexS *, ConfigS *, GUIS *); /*======execute stereo command:==============================================*/ int CommandStereo_ (MolComplexS *mol_complexSP, int mol_complexesN, RuntimeS *runtimeSP, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int *refreshIP, char *stringP) { char *remainderP; char tokenA[STRINGSIZE]; int mol_complexI; /* Initialize the stereo flag: */ configSP->stereoF = 1; /* Extract the first token: */ remainderP = ExtractToken_ (tokenA, STRINGSIZE, stringP, " \t\n"); /* If available, the first token should contain the keyword OFF: */ if (remainderP) { if (strstr (tokenA, "OFF") == tokenA) configSP->stereoF = 0; else { sprintf (runtimeSP->messageA, "Keyword %s not recognized!", tokenA); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_STEREO; } } /* Refresh calculated parameters: */ if (CalculateParameters_ (configSP, guiSP) < 0) return ERROR_STEREO; /* Set the position_changedF flag and update stereo data: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /** Set flag: **/ (mol_complexSP + mol_complexI)->position_changedF = 1; /** Update stereo data: **/ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { PrepareStereoData_ (mol_complexSP + mol_complexI, configSP); } } /* Refresh the main window: */ (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); /* Refresh the control window: */ ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); /* Return the command code: */ return COMMAND_STEREO; } /*===========================================================================*/ garlic-1.6/select_sequence.c0000644000076500007650000001463307647334110016436 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2003 Damir Zucic */ /*============================================================================= select_sequence.c Purpose: Select residue ranges which are matching the sequence from the sequence buffer. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. (3) Pointer to RuntimeS structure (sequence buffer is there). (4) Selection mode index (0 = overwrite, 1 = restrict, 2 = expand previous selection). Output: (1) The flag selectedF set to one for selected atoms in every caught macromolecular complex. (2) Return value. Return value: (1) The number of selected atoms (zero or positive value). Notes: (1) The sequence associated with the current macromol. complex is treated as the sequence number 1, while the sequence from the sequence buffer is treated as the sequence number 2. (2) Most users are likely to store just a short sequence fragment into the sequence buffer before using the command SEL SEQ. (3) The position_changedF is updated. (4) Use strncmp to compare residue names because residue names in the sequence buffer are not zero terminated! ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int CompareSequences_ (MolComplexS *, size_t, size_t, char *, size_t); /*======select sequence:=====================================================*/ long SelectSequence_ (MolComplexS *mol_complexSP, int mol_complexesN, RuntimeS *runtimeSP, int selection_modeI) { long selected_atomsN = 0; size_t residues2N; int max_length; char *first_name2P; int mol_complexI; MolComplexS *curr_mol_complexSP; size_t atomsN, atomI; AtomS *curr_atomSP; size_t residues1N, residue1I; ResidueS *first_residue1SP; char *first_name1P; int n; ResidueS *last_residue1SP; size_t atom_startI, atom_endI; int selectedF = 1; /* Check is there anything in the sequence buffer: */ residues2N = runtimeSP->residuesN; if (residues2N == 0) return (long) 0; /* The maximal residue name length: */ max_length = RESNAMESIZE - 1; /* Prepare the pointer to the name of the first residue from the sequence */ /* buffer. Warning: this string is not zero terminated! Be very careful! */ first_name2P = runtimeSP->sequenceP; /* Check every macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check is the current macromolecular complex caught: */ if (curr_mol_complexSP->catchF == 0) continue; /* Prepare and check the number of atoms in the current complex: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Compare the number of residues in the current */ /* macromolecular complex with the length of the */ /* sequence which is stored to the sequence buffer: */ if (curr_mol_complexSP->residuesN < runtimeSP->residuesN) continue; /* Backup the current selection if selection mode is restrict: */ else if (selection_modeI == 1) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Copy the selection flag: */ curr_atomSP->previous_selectedF = curr_atomSP->selectedF; } } /* Unselect everything if selection mode is overwrite or restrict: */ if ((selection_modeI == 0) || (selection_modeI == 1)) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Unselect the current atom: */ curr_atomSP->selectedF = 0; } } /* Scan the sequence associated with the current macromol. complex: */ residues1N = curr_mol_complexSP->residuesN; for (residue1I = 0; residue1I < residues1N; residue1I++) { /* Pointer to the leading residue: */ first_residue1SP = curr_mol_complexSP->residueSP + residue1I; /* Pointer to the first atom of the current residue: */ curr_atomSP = curr_mol_complexSP->atomSP + first_residue1SP->residue_startI; /* Pointer to the name of the leading residue: */ first_name1P = curr_atomSP->raw_atomS.pure_residue_nameA; /* Compare the residue names: */ if (strncmp (first_name1P, first_name2P, max_length) != 0) { continue; } /* If this point is reached, the residue names */ /* from two sequences match; compare the rest: */ n = CompareSequences_ (curr_mol_complexSP, residue1I, residues1N, first_name2P, residues2N); if (n < 0) continue; /* If this point is reached, the current seq. fragment */ /* is equal to the sequence from the sequence buffer. */ /* Prepare the pointer to the last residue in the fragment: */ last_residue1SP = curr_mol_complexSP->residueSP + residue1I + residues2N; last_residue1SP--; /* Prepare the atomic start and end index: */ atom_startI = first_residue1SP->residue_startI; atom_endI = last_residue1SP->residue_endI; /* Apply selection to the atoms in */ /* the current sequence fragment: */ for (atomI = atom_startI; atomI <= atom_endI; atomI++) { /* Check the atomic index: */ if (atomI >= atomsN) break; /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Set the selection flag for the current atom: */ curr_atomSP->selectedF = selectedF; /* Check the selection flag; increase the count of */ /* selected residues if this flag is equal to one: */ if (curr_atomSP->selectedF) selected_atomsN++; } } /* Combine the current selection with the */ /* previous, if selection mode is restrict: */ if (selection_modeI == 1) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Combine the old and the new selection flag: */ curr_atomSP->selectedF *= curr_atomSP->previous_selectedF; } } /* Update the position_changedF (some atoms may have bad color): */ curr_mol_complexSP->position_changedF = 1; } /* Return the number of selected atoms: */ return selected_atomsN; } /*===========================================================================*/ garlic-1.6/quick_select.c0000644000076500007650000001034707647334433015750 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2003 Damir Zucic */ /*============================================================================= quick_select.c Purpose: Execute select command (the quick version): try to interpret the selection string as short selection string. Three selections modes are available: 0 = overwrite, 1 = restrict, 2 = expand previous selection. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. (3) The selection string. (4) Selection mode index (0 = overwr., 1 = restrict, 2 = expand). Output: (1) The flag selectedF will be equal to one for selected atoms and equal to zero for all other atoms. (2) Return value. Return value: (1) The number of selected atoms, if selection is done in this function. (2) Negative value on failure. Notes: (1) This function will try to interpret the selection string as the set of residue ranges or as the set of residue names. The decision will be based on the string content: if it appears to consist of printable characters which are not alphabetic, it will be interpreted as the set of residue ranges. Otherwise, it will be interpreted as the set of residue names. If the string contains keyword EXCEPT (EXC), it may be interpreted as a set of residue ranges though it contains alphabetic chars. (2) There is no way to specify the chain identifiers and atomic names using the "quick" selection syntax. Only residue ranges and residue names may be specified. (3) The return value -1 has no special meaning, except that the selection job was not done properly. ========includes:============================================================*/ #include #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int Include_ (SelectS *, char *); int Exclude_ (SelectS *, char *); long ApplySelection_ (MolComplexS *, int, SelectS *, SelectS *, int); /*======execute select command (quick selection string):=====================*/ long QuickSelect_ (MolComplexS *mol_complexSP, int mol_complexesN, char *stringP, int selection_modeI) { long selected_atomsN; char copyA[STRINGSIZE]; int rangesF; char *P; int n; char full_stringA[STRINGSIZE]; SelectS include_selectS, exclude_selectS; /* The short (quick) selection string should not contain any slashes: */ if (strstr (stringP, "/") != NULL) return (long) -1; /* Make a copy of the string, to allow some modifications before check: */ strncpy (copyA, stringP, STRINGSIZE - 1); copyA[STRINGSIZE - 1] = '\0'; /* If keyword EXC is present, replace all */ /* alphabetic characters after E with blanks: */ if ((P = strstr (copyA, "EXC")) != NULL) { while ((n = *P++) != '\0') { if (!isalpha (n)) break; else *(P - 1) = ' '; } } /* Try to recognize the string type. The rangesF will be */ /* equal to one if the specifyed string was recognized */ /* as the set of residue ranges and to zero otherwise. */ rangesF = 1; P = copyA; while ((n = *P++) != '\0') { if (isalpha (n)) { rangesF = 0; break; } } /* Prepare the full selection string: */ /** If string was recognized as the set of residue ranges: **/ if (rangesF) sprintf (full_stringA, "*/%s/*/*", stringP); /** If string was not recognized as the set of residue ranges, **/ /** assume it can be interpreted as the set of residue names: **/ else sprintf (full_stringA, "*/*/%s/*", stringP); /* Identify chains, residue ranges, residue */ /* names and atoms which have to be included: */ if (Include_ (&include_selectS, full_stringA) < 0) return (long) -2; /* Identify chains, residue ranges, residue */ /* names and atoms which have to be excluded: */ if (Exclude_ (&exclude_selectS, full_stringA) < 0) return (long) -3; /* Do the selection: */ selected_atomsN = ApplySelection_ (mol_complexSP, mol_complexesN, &include_selectS, &exclude_selectS, selection_modeI); /* Return the number of selected atoms: */ return selected_atomsN; } /*===========================================================================*/ garlic-1.6/donor_dipole.c0000644000076500007650000002662007571177535015757 0ustar zuciczucic00000000000000/* Copyright (C) 2002 Damir Zucic */ /*============================================================================= donor_dipole.c Purpose: Prepare two vectors which define the hydrogen bond donor dipole. The first vector is the position of the dipole center. The second vector is the unit vector which defines the dipole direction. If the donor atom is an oxygen, try to find the hydrogen atom bound to oxygen. If it is nitrogen, try to find one or two carbon atoms bound to this nitrogen atom (see the table below for details). Input: (1) Pointer to VectorS structure, where the position of the dipole center will be stored. (2) Pointer to VectorS, where the unit vector which defines the direction of dipole will be stored. (3) The expected number of carbon atoms bound to the hydrogen bond donor atom. This number is positive if the hydrogen bond donor is nitrogen and negative if hydrogen bond donor is oxygen. The value of -1 is assigned to OG atom from SER, -2 to OG1 atom from THR and -3 to OH atom from TYR. (4) Half of N-H bond length, in angstroms. (5) Pointer to AtomS structure, with data about the hydrogen bond donor. (6) Pointer to MolComplexS structure, which contains the data about the macromolecular complex to which the hydrogen bond donor belongs. (7) The array index of the macromolecular complex to which the hydrogen bond donor belongs. Output: (1) The vector which defines the dipole center. (2) The unit vector which defines the dipole direction. (3) Return value. Return value: (1) Positive on success. (2) Negative on failure. Notes: (1) Here is the list of hydrogen bond donors for twenty standard residues. For most of these atoms, the donor dipole may be constructed without the coordinates of hydrogen atom. The exceptions are OG from SER, OG1 from THR and OH from TYR. o---------o------o-------------------------------------------o | RESIDUE | ATOM | Number of carbon atoms bound to this atom | |---------|------|-------------------------------------------| | every | N | 2 (the main chain nitrogen atom) | | ARG | NE | 2 | | ARG | NH1 | 1 | | ARG | NH2 | 1 | | ASN | ND2 | 1 | | GLN | NE2 | 1 | | HIS | ND1 | 2 | | LYS | NZ | 1 | | SER | OG | 1 (the coordinates of H atom required) | | THR | OG1 | 1 (the coordinates of H atom required) | | TRP | NE1 | 2 | | TYR | OH | 1 (the coordinates of H atom required) | |_________|______|___________________________________________| ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ double AbsoluteValue_ (VectorS *); /*======prepare vectors which define the donor dipole:=======================*/ int DonorDipole_ (VectorS *center_vectorSP, VectorS *unit_vectorSP, int expected_bound_carbonsN, double half_NH_bond_length, AtomS *donor_atomSP, MolComplexS *current_mol_complexSP, int mol_complexI) { ResidueS *current_residueSP; size_t first_atomI, last_atomI; char hydrogen_nameA[10]; int bondI; TrueBondS *current_bondSP; char alt_location; AtomS *partner_atomSP; double x1, y1, z1, x2, y2, z2; double absolute_value, reciprocal_abs_value; double carbon_x, carbon_y, carbon_z; int bound_carbonsN; /* Prepare the pointer to the residue to which the hydrogen */ /* bond donor belongs. Only this residue should be scanned: */ current_residueSP = current_mol_complexSP->residueSP + donor_atomSP->residue_arrayI; /* The range of atomic array indices which define this residue: */ first_atomI = current_residueSP->residue_startI; last_atomI = current_residueSP->residue_endI; /*---------------------------------------------------------------------------*/ /* If the hydrogen bond donor is an oxygen atom, it is not possible */ /* to reconstruct the position of the hydrogen atom using only the */ /* coordinates of this oxygen atom and of the carbon atoms bound to */ /* the oxygen. Thus, try to find the hydrogen atom, if available. */ if (expected_bound_carbonsN < 0) { /* OG atom from SER: */ if (expected_bound_carbonsN == -1) strcpy (hydrogen_nameA, "HG"); /* OG1 atom from THR: */ else if (expected_bound_carbonsN == -2) strcpy (hydrogen_nameA, "HG1"); /* OH atom from TYR: */ else if (expected_bound_carbonsN == -3) strcpy (hydrogen_nameA, "HH"); /* Check all bonds of the donor atom to find the hydrogen atom: */ for (bondI = 0; bondI < donor_atomSP->bondsN; bondI++) { /* Pointer to the current bond: */ current_bondSP = donor_atomSP->true_bondSA + bondI; /* Only covalently bound partners are valid candidates: */ if (current_bondSP->bond_typeI != 1) continue; /* The bond partner should belong to the same complex: */ if (current_bondSP->neighbor_mol_complexI != mol_complexI) { continue; } /* The bond partner should belong to the same residue: */ if (current_bondSP->neighbor_arrayI < first_atomI) continue; if (current_bondSP->neighbor_arrayI > last_atomI) continue; /* The bond partner should be the hydrogen */ /* atom (see check_dist.c for pair ID's): */ if (current_bondSP->pairID != 8) continue; /* Prepare the pointer to the bond partner (carbon atom): */ partner_atomSP = current_mol_complexSP->atomSP + current_bondSP->neighbor_arrayI; /* Ignore atoms at alternate positions: */ alt_location = partner_atomSP->raw_atomS.alt_location; if ((alt_location != ' ') && (alt_location != 'A')) continue; /* If this point is reached, the hydrogen */ /* atom bound to the oxygen atom is found. */ /* Copy atomic coordinates: */ x1 = donor_atomSP->raw_atomS.x[0]; y1 = donor_atomSP->raw_atomS.y; z1 = donor_atomSP->raw_atomS.z[0]; x2 = partner_atomSP->raw_atomS.x[0]; y2 = partner_atomSP->raw_atomS.y; z2 = partner_atomSP->raw_atomS.z[0]; /* Prepare and store the position of dipole center: */ center_vectorSP->x = 0.5 * (x1 + x2); center_vectorSP->y = 0.5 * (y1 + y2); center_vectorSP->z = 0.5 * (z1 + z2); /* Prepare and store the unit vector */ /* pointing from oxygen to hydrogen */ /* atom (don't forget normalization!): */ unit_vectorSP->x = x2 - x1; unit_vectorSP->y = y2 - y1; unit_vectorSP->z = z2 - z1; absolute_value = AbsoluteValue_ (unit_vectorSP); if (absolute_value <= 0.0) return -1; reciprocal_abs_value = 1.0 / absolute_value; unit_vectorSP->x *= reciprocal_abs_value; unit_vectorSP->y *= reciprocal_abs_value; unit_vectorSP->z *= reciprocal_abs_value; /* Return the success indicator: */ return 1; } /* If this point is reached, the hydrogen atom */ /* was not found. Return the failure indicator: */ return -2; } /*---------------------------------------------------------------------------*/ /* If the hydrogen bond donor is a nitrogen atom, find and use the */ /* coordinates of carbon atoms bound to this nitrogen to construct */ /* the position of hydrogen atom. If the hydrogen atoms bound to */ /* nitrogen are present in PDB file, they will be ignored anyway. */ else if ((expected_bound_carbonsN == 1) || (expected_bound_carbonsN == 2)) { /* If there is only one carbon atom bound to nitrogen, */ /* initialize the position of this carbon atom. If there */ /* are two carbon atoms bound to nitrogen, initialize the */ /* position which lays between these two carbon atoms. */ carbon_x = 0.0; carbon_y = 0.0; carbon_z = 0.0; /* Initialize the number of carbon atoms bound to nitrogen: */ bound_carbonsN = 0; /* Check all bonds of the acceptor atom to find one or */ /* two partners which form the dipole with the acceptor: */ for (bondI = 0; bondI < donor_atomSP->bondsN; bondI++) { /* Pointer to the current bond: */ current_bondSP = donor_atomSP->true_bondSA + bondI; /* Only covalently bound partners are valid candidates: */ if (current_bondSP->bond_typeI != 1) continue; /* The bond partner should belong to the same complex: */ if (current_bondSP->neighbor_mol_complexI != mol_complexI) { continue; } /* Note: one of two carbon atoms which are usually bound to */ /* the nitrogen atom does not belong to the same residue! */ /* The bond partner should be the carbon */ /* atom (see check_dist.c for pair ID's): */ if (current_bondSP->pairID != 2) continue; /* Prepare the pointer to the bond partner (carbon atom): */ partner_atomSP = current_mol_complexSP->atomSP + current_bondSP->neighbor_arrayI; /* Ignore atoms at alternate positions: */ alt_location = partner_atomSP->raw_atomS.alt_location; if ((alt_location != ' ') && (alt_location != 'A')) continue; /* If this point is reached, one of the carbon */ /* atoms bound to the nitrogen atom is found. */ /* Add the coordinates of this carbon atom */ /* to the coordinates of the point which lays */ /* in the middle between two carbon atoms: */ carbon_x += partner_atomSP->raw_atomS.x[0]; carbon_y += partner_atomSP->raw_atomS.y; carbon_z += partner_atomSP->raw_atomS.z[0]; /* Increment the counter which counts the */ /* carbon atoms bound to the nitrogen atom: */ bound_carbonsN++; } /* The true number of carbon atoms bound to */ /* nitrogen should match the expected number: */ if (bound_carbonsN != expected_bound_carbonsN) return -3; /* If there are two carbon atoms bound to donor nitrogen, */ /* fix the position of the point between these two atoms: */ if (bound_carbonsN == 2) { carbon_x *= 0.5; carbon_y *= 0.5; carbon_z *= 0.5; } /* Copy the coordinates of the nitrogen atom: */ x1 = donor_atomSP->raw_atomS.x[0]; y1 = donor_atomSP->raw_atomS.y; z1 = donor_atomSP->raw_atomS.z[0]; /* Prepare the unit vector pointing from the carbon */ /* position (or from the combined position obtained for */ /* two carbons) to the nitrogen atom. This vector will */ /* be used as the vector pointing from nitrogen to */ /* hydrogen. Don't forget to normalize this vector! */ unit_vectorSP->x = x1 - carbon_x; unit_vectorSP->y = y1 - carbon_y; unit_vectorSP->z = z1 - carbon_z; absolute_value = AbsoluteValue_ (unit_vectorSP); if (absolute_value <= 0.0) return -4; reciprocal_abs_value = 1.0 / absolute_value; unit_vectorSP->x *= reciprocal_abs_value; unit_vectorSP->y *= reciprocal_abs_value; unit_vectorSP->z *= reciprocal_abs_value; /* Prepare and store the position of dipole center: */ center_vectorSP->x = x1 + half_NH_bond_length * unit_vectorSP->x; center_vectorSP->y = y1 + half_NH_bond_length * unit_vectorSP->y; center_vectorSP->z = z1 + half_NH_bond_length * unit_vectorSP->z; /* Return the success indicator: */ return 2; } /*---------------------------------------------------------------------------*/ /* If this point is reached, the donor atom was */ /* not recognized - return the failure indicator: */ return -5; } /*===========================================================================*/ garlic-1.6/eat_left_char.c0000644000076500007650000000404107307133224016033 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= eat_left_char.c Purpose: Eat left character. Copy the command line to the history buffer. Input: (1) Pointer to RuntimeS structure. Output: (1) One character removed. (2) Return value. Return value: (1) Positive on success. (2) Negative on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======eat left character:==================================================*/ int EatLeftChar_ (RuntimeS *runtimeSP) { int comm_length, carriage_pos, old_carriage_pos; char stringA[COMMSTRINGSIZE]; char *currP; /* Copy the command string length and carriage (keyboard cursor) position: */ comm_length = runtimeSP->command_length; carriage_pos = runtimeSP->carriage_position; old_carriage_pos = carriage_pos; /* Move carriage to the left: */ carriage_pos--; /* Check the carriage position: */ if (carriage_pos < 0) return -1; /* Update the command length: */ comm_length--; /* Copy the left part: */ strncpy (stringA, runtimeSP->curr_commandA, carriage_pos); stringA[carriage_pos] = '\0'; /* Copy the right part, but skip the first character: */ strncat (stringA, runtimeSP->curr_commandA + old_carriage_pos, comm_length - carriage_pos); /* Ensure the proper termination: */ stringA[comm_length] = '\0'; /* Copy the command string: */ strcpy (runtimeSP->curr_commandA, stringA); /* Set the command length and carriage position: */ runtimeSP->command_length = comm_length; runtimeSP->carriage_position = carriage_pos; /* Copy the command string to the output buffer: */ currP = runtimeSP->commandsP + runtimeSP->next_commandI * COMMSTRINGSIZE; strcpy (currP, runtimeSP->curr_commandA); /* Return positive value (success): */ return 1; } /*===========================================================================*/ garlic-1.6/apply_structure.c0000644000076500007650000001213407311516203016517 0ustar zuciczucic00000000000000/* Copyright (C) 2001 Damir Zucic */ /*============================================================================= apply_structure.c Purpose: Apply the specified secondary structure. Use the secondary structure stored to the main secondary structure buffer. Generate and set dihedral angles. This function assumes that all phi angles were set to -180 degrees and all psi angles were set to +180 degrees in two functions: ResetPhi_ () and ResetPsi_ (). Input: (1) Pointer to MolComplexS structure. (2) Pointer to RuntimeS structure (secondary structure is there). Output: (1) The secondary structure set. (2) Return value. Return value: (1) Positive always (trivial). ========includes:============================================================*/ #include #include #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int ExtractNCA_ (VectorS *, VectorS *, AtomS *, size_t, size_t); int GeneratePhiAndPsi_ (double *, double *, int); int RotateAtom_ (AtomS *, VectorS *, VectorS *, double); int ExtractC_ (VectorS *, AtomS *, size_t, size_t); /*======apply the specified secondary structure:=============================*/ int ApplyStructure_ (MolComplexS *mol_complexSP, RuntimeS *runtimeSP) { int residuesN; size_t atomsN; time_t elapsed_time; unsigned long long_time, short_time; static unsigned int random_seed; int residueI; ResidueS *curr_residueSP; size_t atom_startI, atom_endI, atomI; int n; static VectorS N_vectorS, CA_vectorS, C_vectorS; int sec_structure_code; double phi, psi; double delta_phi, delta_psi; AtomS *atomSP; /* Copy the number of residues: */ residuesN = mol_complexSP->residuesN; /* Copy the number of atoms: */ atomsN = mol_complexSP->atomsN; /* Generate the pseudo-random seed using the time since */ /* 00:00:00 UTC, January 1, 1970, measured in seconds: */ elapsed_time = time (NULL); long_time = (unsigned long) elapsed_time; short_time = long_time % 30000; random_seed = (unsigned int) short_time; srand (random_seed); /* Scan the structure: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Pointer to the current residue: */ curr_residueSP = mol_complexSP->residueSP + residueI; /* Prepare the atomic index range: */ atom_startI = curr_residueSP->residue_startI; atom_endI = curr_residueSP->residue_endI; /* Extract N and CA coordinates: */ n = ExtractNCA_ (&N_vectorS, &CA_vectorS, mol_complexSP->atomSP, atom_startI, atom_endI); if (n < 2) continue; /* The secondary structure code associated with this residue: */ sec_structure_code = *(runtimeSP->sec_structureP + residueI); /* Generate dihedral angles: */ GeneratePhiAndPsi_ (&phi, &psi, sec_structure_code); /* Set phi angle for the current residue; rotate */ /* all atoms except H, N and CA about N-CA bond. */ /* Rotation angle (the old phi value should be equal to -3.1415927: */ delta_phi = phi + 3.1415927; /* Scan all atoms of the current residue: */ for (atomI = atom_startI; atomI <= atom_endI; atomI++) { /* Pointer to the current atom: */ atomSP = mol_complexSP->atomSP + atomI; /* Do not rotate H, N and CA: */ if ((strcmp (atomSP->raw_atomS.pure_atom_nameA, "H") == 0) || (strcmp (atomSP->raw_atomS.pure_atom_nameA, "N") == 0) || (strcmp (atomSP->raw_atomS.pure_atom_nameA, "CA") == 0)) { continue; } /* Rotate the current atom about N-CA bond: */ RotateAtom_ (atomSP, &N_vectorS, &CA_vectorS, delta_phi); } /* Rotate all atoms after the current residue about N-CA bond: */ for (atomI = atom_endI + 1; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ atomSP = mol_complexSP->atomSP + atomI; /* Rotate atom: */ RotateAtom_ (atomSP, &N_vectorS, &CA_vectorS, delta_phi); } /* Now extract the new C coordinate; it is required to set psi: */ n = ExtractC_ (&C_vectorS, mol_complexSP->atomSP, atom_startI, atom_endI); if (n < 1) continue; /* Set psi angle for the current residue, */ /* i.e. rotate the O atom about CA-C bond. */ /* Rotation angle (the old psi value should be equal to 3.1415927): */ delta_psi = psi - 3.1415927; /* Scan all atoms of the current residue: */ for (atomI = atom_startI; atomI <= atom_endI; atomI++) { /* Pointer to the current atom: */ atomSP = mol_complexSP->atomSP + atomI; /* Rotate only the O atom: */ if (strcmp (atomSP->raw_atomS.pure_atom_nameA, "O") != 0) { continue; } /* If this point is reached, rotate O atom about CA-C bond: */ RotateAtom_ (atomSP, &CA_vectorS, &C_vectorS, delta_psi); } /* Rotate all atoms after the current residue about CA-C bond: */ for (atomI = atom_endI + 1; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ atomSP = mol_complexSP->atomSP + atomI; /* Rotate atom: */ RotateAtom_ (atomSP, &CA_vectorS, &C_vectorS, delta_psi); } } /* Return positive value on success: */ return 1; } /*===========================================================================*/ garlic-1.6/IMPORTANT_FILES.README0000644000076500007650000000641410361455422016274 0ustar zuciczucic00000000000000 GARLIC CONFIGURATION FILE, TEMPLATE RESIDUES AND DOCUMENTATION Garlic will try to open two files at startup: the system-wide configuration file (.garlicrc) and PDB file with template residues (residues.pdb). Garlic documentation package may be added to /usr/share/doc directory or some HTML directory or to some HTML directory. ============================================================================ (1) CONFIGURATION FILE: Up to seven attempts to open the configuration file will be made. Only the first available file is used. If all seven attempts fail, default parameters will be used. Default parameters are hard-coded in the file read_config.c. File name: .garlicrc (or garlicrc, but only for one directory!). C source file: open_config_file.c ---------------------------------------------------------------------------- (1.1) ./.garlicrc (the current working directory) (1.2) $HOME/.garlicrc (the home directory, $HOME or $home) (1.3) $HOME/garlic/.garlicrc (1.4) /usr/share/garlic/.garlicrc (recommended as system-wide default!) (1.5) /etc/garlicrc (note that file name is garlicrc !) (1.6) /usr/local/lib/garlic/.garlicrc (1.7) /usr/lib/garlic/.garlicrc ============================================================================ ============================================================================ (2) TEMPLATE RESIDUES (building blocks for proteins etc.): Up to six (6) attempts to open the file with template residues will be made. Only the first available file is used. If not available at all, the template residues will not be available. The commands CREATE and REPLACE will be useless, but the program will work (with limited capabilities). File name: residues.pdb C source file: open_template_file.c ---------------------------------------------------------------------------- (1.1) ./residues.pdb (the current working directory) (1.2) $HOME/residues.pdb (the home directory, $HOME or $home) (1.3) $HOME/garlic/residues.pdb (1.4) /usr/share/garlic/residues.pdb (recommended as system-wide default!) (1.5) /usr/local/lib/garlic/residues.pdb (1.6) /usr/lib/garlic/residues.pdb ============================================================================ ============================================================================ RESUME: The suggested pathnames (see below) should be useful for most Linux and Unix distributions. If you accept these paths and pathnames, please note that the configuration file should be called .garlicrc and not garlicrc! Both files (.garlicrc and residues.pdb) may be found in the original source package. If you don't like the suggestions, please edit open_config_file.c and/or open_template_file.c ! ---------------------------------------------------------------------------- System-wide configuration file: /usr/share/garlic/.garlicrc System-wide file with template residues: /usr/share/garlic/residues.pdb Garlic documentation directory: /usr/share/doc/garlic/ or /var/www/html/garlic/ or some_other_html_directory ! ============================================================================ garlic-1.6/control_refresh.c0000644000076500007650000005654207115472467016502 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= control_refresh.c Purpose: Refresh the control window content. This function draws two small projections, showing current positions of outer slab and fading surfaces. Input: (1) Pointer to MolComplexS structure, with macromol. complex. (2) Pointer to ConfigS structure, with configuration data. (3) Pointer to GUIS structure, with GUI data. Output: (1) Two small projections drawn to the bottom of control window. (2) Return value. Return value: (1) Positive if something useful drawn. (2) Zero if there are no atoms. Notes: (1) Default caught complex is the only complex projected in this function. (2) Drawing is done on a hidden pixmap. This was not absolutely necessary. (3) If nothing is loaded, or if maximal extent is equal to zero, do nothing! (4) Only atoms which are not hidden will be drawn. ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======refresh the control window:==========================================*/ int ControlRefresh_ (MolComplexS *curr_mol_complexSP, ConfigS *configSP, GUIS *guiSP) { static double extra_scale = 0.8; static int screen_slab_x0 = 6, screen_slab_y0 = 206; static int screen_fading_x0 = 6, screen_fading_y0 = 331; int screen_delta_x = 84, screen_delta_y = 58, screen_center_x = 42, screen_center_y = 29; size_t atomsN, atomI; double max_extent, scale_factor; AtomS *curr_atomSP; double x0, z0, x, z, front, back; int screen_x0, screen_y0, screen_x1; int n, half_width; double d; unsigned int width, height; size_t c_alphaI, c_alphaN; BackboneS *curr_backboneSP; /* Prepare and check the number of atoms: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) { XSetForeground (guiSP->displaySP, guiSP->theGCA[0], guiSP->black_colorID); width = (unsigned int) screen_delta_x; height = (unsigned int) screen_delta_y; XFillRectangle (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], 0, 0, width, height); XCopyArea (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->control_winS.ID, guiSP->theGCA[0], 1, 1, screen_delta_x - 2, screen_delta_y - 2, screen_slab_x0 + 1, screen_slab_y0 + 1); XCopyArea (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->control_winS.ID, guiSP->theGCA[0], 1, 1, screen_delta_x - 2, screen_delta_y - 2, screen_fading_x0 + 1, screen_fading_y0 + 1); return 0; } /* Prepare and check the maximal extent: */ max_extent = curr_mol_complexSP->max_extent; if (max_extent == 0.0) { XSetForeground (guiSP->displaySP, guiSP->theGCA[0], guiSP->black_colorID); width = (unsigned int) screen_delta_x; height = (unsigned int) screen_delta_y; XFillRectangle (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], 0, 0, width, height); XCopyArea (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->control_winS.ID, guiSP->theGCA[0], 1, 1, screen_delta_x - 2, screen_delta_y - 2, screen_slab_x0 + 1, screen_slab_y0 + 1); XCopyArea (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->control_winS.ID, guiSP->theGCA[0], 1, 1, screen_delta_x - 2, screen_delta_y - 2, screen_fading_x0 + 1, screen_fading_y0 + 1); return 0; } /* Prepare the scale factor: */ scale_factor = extra_scale * (double) screen_delta_y / max_extent; /* Atomic coordinates of slab center: */ x0 = curr_mol_complexSP->slab_center_vectorS.x; z0 = curr_mol_complexSP->slab_center_vectorS.z; /*------slab:----------------------------------------------------------------*/ /* Refresh part of the main hidden pixmap: */ XSetForeground (guiSP->displaySP, guiSP->theGCA[0], guiSP->black_colorID); width = (unsigned int) screen_delta_x; height = (unsigned int) screen_delta_y; XFillRectangle (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], 0, 0, width, height); /* Prepare two GUI's with different colors: */ XSetForeground (guiSP->displaySP, guiSP->theGCA[0], guiSP->dark_cyan_colorID); XSetForeground (guiSP->displaySP, guiSP->theGCA[1], guiSP->red_colorID); /* Draw all atoms which belong to the currently caught macromol. complex: */ for (atomI = 0; atomI < atomsN; atomI ++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* This atom may be hidden: */ if (curr_atomSP->hiddenF) continue; /* Atomic coordinates: */ x = curr_atomSP->raw_atomS.x[0] - x0; z = curr_atomSP->raw_atomS.z[0] - z0; /* Screen coordinates (atomic coordinates projected to the screen): */ screen_x0 = screen_center_x - scale_factor * z; screen_y0 = screen_center_y - scale_factor * x; /* Draw atom: */ if (curr_atomSP->inside_projected_slabF) /* red */ { XDrawPoint (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], screen_x0, screen_y0); /* If there fewer than 100 atoms, draw 4 additional pixels: */ if (atomsN < 100) { XDrawPoint (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], screen_x0 - 1, screen_y0); XDrawPoint (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], screen_x0 + 1, screen_y0); XDrawPoint (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], screen_x0, screen_y0 - 1); XDrawPoint (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], screen_x0, screen_y0 + 1); } } else /* green */ { XDrawPoint (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0, screen_y0); /* If there fewer than 100 atoms, draw 4 additional pixels: */ if (atomsN < 100) { XDrawPoint (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0 - 1, screen_y0); XDrawPoint (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0 + 1, screen_y0); XDrawPoint (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0, screen_y0 - 1); XDrawPoint (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0, screen_y0 + 1); } } } /* Draw backbone atoms: */ c_alphaN = curr_mol_complexSP->c_alphaN; for (c_alphaI = 0; c_alphaI < c_alphaN; c_alphaI++) { /* Pointer to the current BackboneS structure: */ curr_backboneSP = curr_mol_complexSP->backboneSP + c_alphaI; curr_atomSP = curr_mol_complexSP->atomSP + curr_backboneSP->c_alphaI; /* The current backbone element may be hidden: */ if (curr_backboneSP->hiddenF) continue; /* Atomic coordinates: */ x = curr_atomSP->raw_atomS.x[0] - x0; z = curr_atomSP->raw_atomS.z[0] - z0; /* Screen coordinates (atomic coordinates projected to the screen): */ screen_x0 = screen_center_x - scale_factor * z; screen_y0 = screen_center_y - scale_factor * x; /* Draw atom: */ if (curr_atomSP->inside_projected_slabF) /* red */ { XDrawPoint (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], screen_x0, screen_y0); /* If there fewer than 100 atoms, draw 4 additional pixels: */ if (atomsN < 100) { XDrawPoint (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], screen_x0 - 1, screen_y0); XDrawPoint (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], screen_x0 + 1, screen_y0); XDrawPoint (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], screen_x0, screen_y0 - 1); XDrawPoint (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], screen_x0, screen_y0 + 1); } } else /* green */ { XDrawPoint (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0, screen_y0); /* If there fewer than 100 atoms, draw 4 additional pixels: */ if (atomsN < 100) { XDrawPoint (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0 - 1, screen_y0); XDrawPoint (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0 + 1, screen_y0); XDrawPoint (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0, screen_y0 - 1); XDrawPoint (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0, screen_y0 + 1); } } } /* Atomic coordinates of slab surfaces: */ front = curr_mol_complexSP->slab_front_relative_position; back = curr_mol_complexSP->slab_back_relative_position; /* Draw two outermost slab surfaces (but not the area between them): */ XSetForeground (guiSP->displaySP, guiSP->theGCA[2], guiSP->yellow_colorID); switch (curr_mol_complexSP->slab_modeI) { /* Fading not used: */ case 0: break; /* Planar slab: */ case 1: d = (double) screen_center_x - scale_factor * back; screen_x0 = (int) d; d = (double) screen_center_x - scale_factor * front; screen_x1 = (int) d; if (screen_x0 >= screen_x1) { screen_x0 = screen_x1 - 1; } if (screen_x0 < 1) screen_x0 = 1; if (screen_x1 < 1) screen_x1 = 1; n = screen_delta_x - 3; if (screen_x1 > n) screen_x1 = n; n = screen_x1 - screen_x0 + 1; if (n >= 2) width = n; else width = 2; height = screen_delta_y; XDrawRectangle (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], screen_x0, 0, width, height); XDrawRectangle (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], screen_x0 + 1, 0, width - 2, height); break; /* Spherical and cylindrical slab: */ case 2: case 4: /* Outer surface (yellow): */ d = scale_factor * front; half_width = (int) d; screen_x0 = screen_center_x - half_width; if (screen_x0 < 1) screen_x0 = 1; screen_x1 = screen_center_x + half_width; n = screen_delta_x - 3; if (screen_x1 > n) { half_width = n / 2; screen_x0 = screen_center_x - half_width; screen_x1 = n; } screen_y0 = screen_center_y - half_width; n = screen_x1 - screen_x0 + 1; if (n > 0) width = n; else width = 0; height = width; XDrawArc (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], screen_x0, screen_y0, width, height, 0, 23040); XDrawArc (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], screen_x0 - 1, screen_y0 - 1, width + 2, height + 2, 0, 23040); /* Inner surface (yellow): */ d = scale_factor * back; half_width = (int) d; screen_x0 = screen_center_x - half_width; if (screen_x0 < 0) screen_x0 = 0; screen_x1 = screen_center_x + half_width; n = screen_delta_x - 3; if (screen_x1 > n) { half_width = n / 2; screen_x0 = screen_center_x - half_width; screen_x1 = n; } screen_y0 = screen_center_y - half_width; n = screen_x1 - screen_x0 + 1; if (n > 0) width = n; else width = 0; height = width; XDrawArc (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], screen_x0, screen_y0, width, height, 0, 23040); XDrawArc (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], screen_x0 - 1, screen_y0 - 1, width + 2, height + 2, 0, 23040); break; /* Semi-spherical and semi-cylindrical slab: */ case 3: case 5: /* Outer surface (yellow): */ d = scale_factor * front; half_width = (int) d; screen_x0 = screen_center_x - half_width; if (screen_x0 < 1) screen_x0 = 1; screen_x1 = screen_center_x + half_width; n = screen_delta_x - 3; if (screen_x1 > n) { half_width = n / 2; screen_x0 = screen_center_x - half_width; screen_x1 = n; } screen_y0 = screen_center_y - half_width; n = screen_x1 - screen_x0 + 1; if (n > 0) width = n; else width = 0; height = width; XDrawArc (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], screen_x0, screen_y0, width, height, 0, 5760); XDrawArc (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], screen_x0 - 1, screen_y0 - 1, width + 2, height + 2, 0, 5760); XDrawArc (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], screen_x0, screen_y0, width, height, 0, -5760); XDrawArc (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], screen_x0 - 1, screen_y0 - 1, width + 2, height + 2, 0, -5760); /* Inner surface (yellow): */ d = scale_factor * back; half_width = (int) d; screen_x0 = screen_center_x - half_width; if (screen_x0 < 1) screen_x0 = 1; screen_x1 = screen_center_x + half_width; n = screen_delta_x - 3; if (screen_x1 > n) { half_width = n / 2; screen_x0 = screen_center_x - half_width; screen_x1 = n; } screen_y0 = screen_center_y - half_width; n = screen_x1 - screen_x0 + 1; if (n > 0) width = n; else width = 0; height = width; XDrawArc (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], screen_x0, screen_y0, width, height, 0, 5760); XDrawArc (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], screen_x0 - 1, screen_y0 - 1, width + 2, height + 2, 0, 5760); XDrawArc (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], screen_x0, screen_y0, width, height, 0, -5760); XDrawArc (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], screen_x0 - 1, screen_y0 - 1, width + 2, height + 2, 0, -5760); /* Two vertical lines (yellow): */ XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], screen_center_x, 1, screen_center_x, screen_delta_y - 1); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], screen_center_x - 1, 1, screen_center_x - 1, screen_delta_y - 1); break; /* Unknown slab: */ default: ; } /* Copy part of the main hidden pixmap to control window: */ XCopyArea (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->control_winS.ID, guiSP->theGCA[0], 1, 1, screen_delta_x - 2, screen_delta_y - 2, screen_slab_x0 + 1, screen_slab_y0 + 1); /*------fading:--------------------------------------------------------------*/ /* Refresh part of the main hidden pixmap: */ XSetForeground (guiSP->displaySP, guiSP->theGCA[0], guiSP->black_colorID); width = screen_delta_x; height = screen_delta_y; XFillRectangle (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], 0, 0, width, height); /* Prepare GUI: */ XSetForeground (guiSP->displaySP, guiSP->theGCA[1], guiSP->red_colorID); /* Draw all atoms which belong to the currently caught macromol. complex: */ for (atomI = 0; atomI < atomsN; atomI ++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* This atom may be hidden: */ if (curr_atomSP->hiddenF) continue; /* Atomic coordinates: */ x = curr_atomSP->raw_atomS.x[0] - x0; z = curr_atomSP->raw_atomS.z[0] - z0; /* Screen coordinates (atomic coordinates projected to the screen): */ screen_x0 = screen_center_x - scale_factor * z; screen_y0 = screen_center_y - scale_factor * x; /* Draw atom (a single pixel): */ XDrawPoint (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], screen_x0, screen_y0); /* If there fewer than 100 atoms, draw 4 additional pixels: */ if (atomsN < 100) { XDrawPoint (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], screen_x0 - 1, screen_y0); XDrawPoint (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], screen_x0 + 1, screen_y0); XDrawPoint (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], screen_x0, screen_y0 - 1); XDrawPoint (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], screen_x0, screen_y0 + 1); } } /* Draw backbone atoms: */ c_alphaN = curr_mol_complexSP->c_alphaN; for (c_alphaI = 0; c_alphaI < c_alphaN; c_alphaI++) { /* Pointer to the current BackboneS structure: */ curr_backboneSP = curr_mol_complexSP->backboneSP + c_alphaI; curr_atomSP = curr_mol_complexSP->atomSP + curr_backboneSP->c_alphaI; /* The current backbone element may be hidden: */ if (curr_backboneSP->hiddenF) continue; /* Atomic coordinates: */ x = curr_atomSP->raw_atomS.x[0] - x0; z = curr_atomSP->raw_atomS.z[0] - z0; /* Screen coordinates (atomic coordinates projected to the screen): */ screen_x0 = screen_center_x - scale_factor * z; screen_y0 = screen_center_y - scale_factor * x; /* Draw atom (a single pixel): */ XDrawPoint (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], screen_x0, screen_y0); /* If there fewer than 100 atoms, draw 4 additional pixels: */ if (atomsN < 100) { XDrawPoint (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], screen_x0 - 1, screen_y0); XDrawPoint (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], screen_x0 + 1, screen_y0); XDrawPoint (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], screen_x0, screen_y0 - 1); XDrawPoint (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], screen_x0, screen_y0 + 1); } } /* Atomic coordinates of fading surfaces: */ front = curr_mol_complexSP->fading_front_relative_position; back = curr_mol_complexSP->fading_back_relative_position; /* Draw two outermost fading surfaces (but not the area between them): */ XSetForeground (guiSP->displaySP, guiSP->theGCA[2], guiSP->yellow_colorID); switch (curr_mol_complexSP->fading_modeI) { /* Fading not used: */ case 0: break; /* Planar fading: */ case 1: d = (double) screen_center_x - scale_factor * back; screen_x0 = (int) d; d = (double) screen_center_x - scale_factor * front; screen_x1 = (int) d; if (screen_x0 >= screen_x1) { screen_x0 = screen_x1 - 1; } if (screen_x0 < 1) screen_x0 = 1; if (screen_x1 < 1) screen_x1 = 1; n = screen_delta_x - 3; if (screen_x1 > n) screen_x1 = n; n = screen_x1 - screen_x0 + 1; if (n >= 2) width = n; else width = 2; height = screen_delta_y; XDrawRectangle (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], screen_x0, 0, width, height); XDrawRectangle (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], screen_x0 + 1, 0, width - 2, height); break; /* Spherical and cylindrical fading: */ case 2: case 4: /* Outer surface (yellow): */ d = scale_factor * front; half_width = (int) d; screen_x0 = screen_center_x - half_width; if (screen_x0 < 1) screen_x0 = 1; screen_x1 = screen_center_x + half_width; n = screen_delta_x - 3; if (screen_x1 > n) { half_width = n / 2; screen_x0 = screen_center_x - half_width; screen_x1 = n; } screen_y0 = screen_center_y - half_width; n = screen_x1 - screen_x0 + 1; if (n > 0) width = n; else width = 0; height = width; XDrawArc (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], screen_x0, screen_y0, width, height, 0, 23040); XDrawArc (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], screen_x0 - 1, screen_y0 - 1, width + 2, height + 2, 0, 23040); /* Inner surface (yellow): */ d = scale_factor * back; half_width = (int) d; screen_x0 = screen_center_x - half_width; if (screen_x0 < 0) screen_x0 = 0; screen_x1 = screen_center_x + half_width; n = screen_delta_x - 3; if (screen_x1 > n) { half_width = n / 2; screen_x0 = screen_center_x - half_width; screen_x1 = n; } screen_y0 = screen_center_y - half_width; n = screen_x1 - screen_x0 + 1; if (n > 0) width = n; else width = 0; height = width; XDrawArc (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], screen_x0, screen_y0, width, height, 0, 23040); XDrawArc (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], screen_x0 - 1, screen_y0 - 1, width + 2, height + 2, 0, 23040); break; /* Semi-spherical and semi-cylindrical fading: */ case 3: case 5: /* Outer surface (yellow): */ d = scale_factor * front; half_width = (int) d; screen_x0 = screen_center_x - half_width; if (screen_x0 < 1) screen_x0 = 1; screen_x1 = screen_center_x + half_width; n = screen_delta_x - 3; if (screen_x1 > n) { half_width = n / 2; screen_x0 = screen_center_x - half_width; screen_x1 = n; } screen_y0 = screen_center_y - half_width; n = screen_x1 - screen_x0 + 1; if (n > 0) width = n; else width = 0; height = width; XDrawArc (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], screen_x0, screen_y0, width, height, 0, 5760); XDrawArc (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], screen_x0 - 1, screen_y0 - 1, width + 2, height + 2, 0, 5760); XDrawArc (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], screen_x0, screen_y0, width, height, 0, -5760); XDrawArc (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], screen_x0 - 1, screen_y0 - 1, width + 2, height + 2, 0, -5760); /* Inner surface (yellow): */ d = scale_factor * back; half_width = (int) d; screen_x0 = screen_center_x - half_width; if (screen_x0 < 1) screen_x0 = 1; screen_x1 = screen_center_x + half_width; n = screen_delta_x - 3; if (screen_x1 > n) { half_width = n / 2; screen_x0 = screen_center_x - half_width; screen_x1 = n; } screen_y0 = screen_center_y - half_width; n = screen_x1 - screen_x0 + 1; if (n > 0) width = n; else width = 0; height = width; XDrawArc (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], screen_x0, screen_y0, width, height, 0, 5760); XDrawArc (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], screen_x0 - 1, screen_y0 - 1, width + 2, height + 2, 0, 5760); XDrawArc (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], screen_x0, screen_y0, width, height, 0, -5760); XDrawArc (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], screen_x0 - 1, screen_y0 - 1, width + 2, height + 2, 0, -5760); /* Two vertical lines (yellow): */ XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], screen_center_x, 1, screen_center_x, screen_delta_y - 1); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], screen_center_x - 1, 1, screen_center_x - 1, screen_delta_y - 1); break; /* Unknown fading: */ default: ; } /* Copy part of the main hidden pixmap to control window: */ XCopyArea (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->control_winS.ID, guiSP->theGCA[0], 1, 1, screen_delta_x - 2, screen_delta_y - 2, screen_fading_x0 + 1, screen_fading_y0 + 1); /*---------------------------------------------------------------------------*/ /* Return positive value on success: */ return 1; } /*===========================================================================*/ garlic-1.6/rama_frame.c0000644000076500007650000002566407311424463015366 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= rama_frame.c Purpose: Draw frame for Ramachandran plot, including labels. Input: (1) Pointer to GUIS structure, with GUI data. Output: (1) A rectangular frame drawn to the main window. Return value: No return value. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int ParseColor_ (RGBS *, unsigned long *, GUIS *, char *, char *); /*======draw frame for Ramachandran plot:====================================*/ void RamaFrame_ (GUIS *guiSP) { int free_width, free_height; int frame_screen_x0, frame_screen_y0; int frame_screen_x1, frame_screen_y1; int frame_screen_width, frame_screen_height; RGBS rgbS; unsigned long frame_color1ID, frame_color2ID, frame_color3ID; int i; int screen_x0, screen_y0; char stringA[SHORTSTRINGSIZE]; int string_length; /* Prepare geometric parameters: */ free_width = (int) guiSP->main_win_free_area_width; free_height = (int) guiSP->main_win_free_area_height; frame_screen_x0 = guiSP->main_winS.text_line_height + 2; frame_screen_y0 = frame_screen_x0; frame_screen_x1 = free_width - frame_screen_x0; if (frame_screen_x1 < frame_screen_x0) frame_screen_x1 = frame_screen_x0; frame_screen_y1 = free_height - frame_screen_y0; if (frame_screen_y1 < frame_screen_y0) frame_screen_y1 = frame_screen_y0; frame_screen_width = frame_screen_x1 - frame_screen_x0 + 1; frame_screen_height = frame_screen_y1 - frame_screen_y0 + 1; /* Prepare frame colors: */ ParseColor_ (&rgbS, &frame_color1ID, guiSP, "RGB:EEEE/EEEE/EEEE", "white"); ParseColor_ (&rgbS, &frame_color2ID, guiSP, "RGB:9999/9999/9999", "white"); ParseColor_ (&rgbS, &frame_color3ID, guiSP, "RGB:4444/4444/4444", "black"); XSetForeground (guiSP->displaySP, guiSP->theGCA[1], frame_color1ID); XSetForeground (guiSP->displaySP, guiSP->theGCA[2], frame_color2ID); XSetForeground (guiSP->displaySP, guiSP->theGCA[3], frame_color3ID); /* Thin lines: */ for (i = 1; i < 12; i++) { if (i == 6) continue; screen_x0 = frame_screen_x0 + i * frame_screen_width / 12; if ((i % 3) == 0) { XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], screen_x0 - 1, frame_screen_y0, screen_x0 - 1, frame_screen_y1); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], screen_x0, frame_screen_y0, screen_x0, frame_screen_y1); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[3], screen_x0 + 1, frame_screen_y0, screen_x0 + 1, frame_screen_y1); } else { XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], screen_x0, frame_screen_y0, screen_x0, frame_screen_y1); } } for (i = 1; i < 12; i++) { if (i == 6) continue; screen_y0 = frame_screen_y0 + i * frame_screen_height / 12; if ((i % 3) == 0) { XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], frame_screen_x0, screen_y0 - 1, frame_screen_x1, screen_y0 - 1); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], frame_screen_x0, screen_y0, frame_screen_x1, screen_y0); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[3], frame_screen_x0, screen_y0 + 1, frame_screen_x1, screen_y0 + 1); } else { XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], frame_screen_x0, screen_y0, frame_screen_x1, screen_y0); } } /* Thick outer frame: */ XDrawRectangle (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], frame_screen_x0, frame_screen_y0, (unsigned int) (frame_screen_width - 1), (unsigned int) (frame_screen_height - 1)); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], frame_screen_x0 - 1, frame_screen_y0 - 1, frame_screen_x0 - 1, frame_screen_y1 + 1); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], frame_screen_x0 - 1, frame_screen_y0 - 1, frame_screen_x1 + 1, frame_screen_y0 - 1); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], frame_screen_x1 - 1, frame_screen_y0 + 1, frame_screen_x1 - 1, frame_screen_y1 - 1); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], frame_screen_x0 + 1, frame_screen_y1 - 1, frame_screen_x1 - 1, frame_screen_y1 - 1); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[3], frame_screen_x0 + 1, frame_screen_y0 + 1, frame_screen_x0 + 1, frame_screen_y1 - 1); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[3], frame_screen_x0 + 1, frame_screen_y0 + 1, frame_screen_x1 - 1, frame_screen_y0 + 1); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[3], frame_screen_x1 + 1, frame_screen_y0 - 1, frame_screen_x1 + 1, frame_screen_y1 + 1); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[3], frame_screen_x0 - 1, frame_screen_y1 + 1, frame_screen_x1 + 1, frame_screen_y1 + 1); /* Thick inner frame: */ screen_x0 = (frame_screen_x0 + frame_screen_x1) / 2; XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], screen_x0, frame_screen_y0, screen_x0, frame_screen_y1); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], screen_x0 - 1, frame_screen_y0 + 1, screen_x0 - 1, frame_screen_y1 - 1); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[3], screen_x0 + 1, frame_screen_y0 + 1, screen_x0 + 1, frame_screen_y1 - 1); screen_y0 = (frame_screen_y0 + frame_screen_y1) / 2; XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], frame_screen_x0, screen_y0, frame_screen_x1, screen_y0); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], frame_screen_x0 + 1, screen_y0 - 1, frame_screen_x1 - 1, screen_y0 - 1); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[3], frame_screen_x0 + 1, screen_y0 + 1, frame_screen_x1 - 1, screen_y0 + 1); XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], screen_x0, screen_y0 - 1, screen_x0, screen_y0 + 1); /* Draw labels: */ XSetForeground (guiSP->displaySP, guiSP->theGCA[0], guiSP->main_winS.fg_colorID); strcpy (stringA, "abscisa: phi ordinate: psi"); string_length = strlen (stringA); screen_x0 = (frame_screen_x0 + frame_screen_x1) / 2 - XTextWidth (guiSP->main_winS.fontSP, stringA, string_length) / 2; screen_y0 = frame_screen_y0 - guiSP->main_winS.fontSP->descent - 1; XDrawString (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, string_length); screen_y0 = frame_screen_y1 + guiSP->main_winS.text_line_height - guiSP->main_winS.text_line_height / 5; screen_x0 = frame_screen_x0 + 10; strcpy (stringA, "trans"); string_length = strlen (stringA); XDrawString (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, string_length); screen_x0 = frame_screen_x0 + (frame_screen_x1 - frame_screen_x0) / 4 + 10; strcpy (stringA, "cis"); string_length = strlen (stringA); XDrawString (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, string_length); screen_x0 = frame_screen_x0 + 2 * (frame_screen_x1 - frame_screen_x0) / 4 + 10; strcpy (stringA, "bad / amino terminus"); string_length = strlen (stringA); XDrawString (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, string_length); strcpy (stringA, "0"); string_length = strlen (stringA); screen_x0 = (frame_screen_x0 + frame_screen_x1) / 2 + 3; screen_y0 = (frame_screen_y0 + frame_screen_y1) / 2 - 3; XDrawString (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, string_length); strcpy (stringA, "-180"); string_length = strlen (stringA); screen_x0 = frame_screen_x0 + 3; screen_y0 = (frame_screen_y0 + frame_screen_y1) / 2 - 3; XDrawString (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, string_length); screen_x0 = (frame_screen_x0 + frame_screen_x1) / 2 + 3; screen_y0 = frame_screen_y1 - 3; XDrawString (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, string_length); strcpy (stringA, "-90"); string_length = strlen (stringA); screen_x0 = frame_screen_x0 + (frame_screen_x1 - frame_screen_x0) / 4 + 3; screen_y0 = (frame_screen_y0 + frame_screen_y1) / 2 - 3; XDrawString (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, string_length); screen_x0 = (frame_screen_x0 + frame_screen_x1) / 2 + 3; screen_y0 = frame_screen_y0 + 3 * (frame_screen_y1 - frame_screen_y0) / 4 - 3; XDrawString (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, string_length); strcpy (stringA, "90"); string_length = strlen (stringA); screen_x0 = frame_screen_x0 + 3 * (frame_screen_x1 - frame_screen_x0) / 4 + 3; screen_y0 = (frame_screen_y0 + frame_screen_y1) / 2 - 3; XDrawString (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, string_length); screen_x0 = (frame_screen_x0 + frame_screen_x1) / 2 + 3; screen_y0 = frame_screen_y0 + (frame_screen_y1 - frame_screen_y0) / 4 - 3; XDrawString (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, string_length); strcpy (stringA, "180"); string_length = strlen (stringA); screen_x0 = frame_screen_x1 - XTextWidth (guiSP->main_winS.fontSP, stringA, string_length) - 3; screen_y0 = (frame_screen_y0 + frame_screen_y1) / 2 - 3; XDrawString (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, string_length); screen_x0 = (frame_screen_x0 + frame_screen_x1) / 2 + 3; screen_y0 = frame_screen_y0 + guiSP->main_winS.text_line_height - guiSP->main_winS.text_line_height / 5; XDrawString (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, string_length); } /*===========================================================================*/ garlic-1.6/disulfide_bonds.c0000644000076500007650000000717407612776404016436 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2003 Damir Zucic */ /*============================================================================= disulfide_bonds.c Purpose: Prepare disulfide bonds. Only the distance between two sulfur atoms is checked; the angle between two methylene groups is not checked. Input: (1) Pointer to MolComplexS structure, with macromolecular data. (2) The array index of a given macromolecular complex. (3) Pointer to ConfigS structure, with configuration data. Output: (1) Information about dusulfide bonds added. (2) Return value. Return value: (1) The total number of bonds on success. (2) Zero if there are no atoms. (3) Negative, if there are some atoms but there are no bonds. Notes: (1) If some atoms are deleted or inserted, all bonds have to be updated. Note that array indices are shifted after addition or deletion of atoms; that's the most important reason for thorough revision of bonds. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int CheckDistance_ (double *, AtomS *, AtomS *, ConfigS *); int AddBond_ (AtomS *, int, int, int, size_t, double, int); /*======prepare disulfide bonds:=============================================*/ size_t DisulfideBonds_ (MolComplexS *mol_complexSP, int mol_complexI, ConfigS *configSP) { size_t total_bondsN = 0; int styleI; size_t atomsN, atom1I, atom2I; /* Use signed int to store the following indices: */ AtomS *atom1SP, *atom2SP; int pairID; int bond_typeI; double distance; char alt_location1, alt_location2; /* Initialize the styleI: */ styleI = 1; /* Return zero if there are no atoms: */ atomsN = mol_complexSP->atomsN; if (atomsN == 0) return 0; /* Disulfide bonds are treated as type 2: */ bond_typeI = 2; /* The outer atomic loop: */ for (atom1I = 0; atom1I < atomsN; atom1I++) { /* Pointer to atom 1: */ atom1SP = mol_complexSP->atomSP + atom1I; /* Check is this sulfur: */ if (strcmp (atom1SP->raw_atomS.chemical_symbolA, " S") != 0) continue; /* The inner atomic loop: */ for (atom2I = 0; atom2I < atomsN; atom2I++) { /* Atom is not bound to itself: */ if (atom2I == atom1I) continue; /* Pointer to atom 2: */ atom2SP = mol_complexSP->atomSP + atom2I; /* Both atoms should be sulfur atoms: */ if (strcmp (atom1SP->raw_atomS.chemical_symbolA, " S") != 0) continue; if (strcmp (atom2SP->raw_atomS.chemical_symbolA, " S") != 0) continue; /* Check is there a chemical bond: */ pairID = CheckDistance_ (&distance, atom1SP, atom2SP, configSP); /* If bond is bad, check the next atom 2: */ if (pairID <= 0) continue; /* Compare the alternate location indicators; */ /* if both indicators are different from ' ' */ /* and mutually different, the bond is bad! */ alt_location1 = atom1SP->raw_atomS.alt_location; alt_location2 = atom2SP->raw_atomS.alt_location; if ((alt_location1 != alt_location2) && (alt_location1 != ' ') && (alt_location2 != ' ')) { continue; } /* If this point is reached, the bond does exist! */ /* Add bond to atom 1: */ AddBond_ (atom1SP, pairID, bond_typeI, mol_complexI, atom2I, distance, styleI); /* Update the number of bonds in a macromolecular complex: */ total_bondsN++; } } /* If this point is reached, return the total number of bonds: */ return total_bondsN; } /*===========================================================================*/ garlic-1.6/skip_keyword.c0000644000076500007650000000334307072062316015773 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= skip_keyword.c Purpose: Skip keyword: find the pointer which points to the first character which belongs to the set of separators. Used to skip keyword and reach the content following the keyword. This function is required because some keywords may be abbreviated. Input: (1) Pointer to the string which has a keyword at the beginning. (2) Pointer to the list (string) of separators. Output: (1) Return value. Return value: (1) Pointer to the remainder of the string, following the keyword. (2) NULL on failure. ========includes:============================================================*/ #include /*======skip keyword:========================================================*/ char *SkipKeyword_ (char *stringP, char *separatorsP) { int current_char, current_separator; int separator_foundF = 0; char *P; /* Check the input string pointer: */ if (stringP == NULL) return NULL; /* Find the first separator: */ while ((current_char = *stringP++) != '\0') { /** Search the set of separators: **/ P = separatorsP; separator_foundF = 0; while ((current_separator = *P++) != '\0') { if (current_char == current_separator) { separator_foundF = 1; break; } } /** If the current character belongs to **/ /** the set of separators, job is done: **/ if (separator_foundF) break; } /* If end of string is reached but separator was */ /* not found, there is nothing after the keyword: */ if (!separator_foundF) return NULL; /* Return the pointer to the remainder of the string: */ return --stringP; } /*===========================================================================*/ garlic-1.6/rama_mouse.c0000644000076500007650000001401307315467507015420 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= rama_mouse.c Purpose: Handle MotionNotify events if the main window contains Ramachandran plot. Input: (1) Pointer to MolComplexS structure, with macromolecular complexes. (2) Number of macromolecular complexes. (3) Pointer to ConfigS structure, with configuration data. (4) Pointer to GUIS structure, with GUI data. (5) Pointer to NearestAtomS structure. (6) The number of pixels in the main window free area. (7) Pointer to refreshI. (8) Pointer to XMotionEvent structure. Output: (1) Some data related to the residue under the pointer written to output window. (2) Return value. Return value: (1) Positive on success. (2) Zero if event is ignored. (3) Negative on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======handle MotionNotify events for Ramachandran plot:====================*/ int RamaMouse_ (MolComplexS *mol_complexSP, int mol_complexesN, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int refreshI, XMotionEvent *motion_eventSP) { size_t pixelI; NearestAtomS *pixelSP; MolComplexS *curr_mol_complexSP; AtomS *curr_atomSP; RawAtomS *raw_atomSP; static char stringA[SHORTSTRINGSIZE]; int line_height; int screen_x0, screen_y0; ResidueS *curr_residueSP; double phi, psi, omega; /* If the event came from child window, return zero: */ if (motion_eventSP->subwindow != None) return 0; /* Pixel index: */ pixelI = guiSP->main_win_free_area_width * motion_eventSP->y + motion_eventSP->x; /* Check the pixel index: */ if (pixelI >= pixelsN) return -1; /* Pointer to NearestAtomS structure assigned with this pixel: */ pixelSP = nearest_atomSP + pixelI; /* Check the refreshI associated with this pixel: */ if (pixelSP->last_refreshI != refreshI) return 0; /* Refresh the output window: */ XSetForeground (guiSP->displaySP, guiSP->theGCA[0], guiSP->output_winS.bg_colorID); XFillRectangle (guiSP->displaySP, guiSP->output_winS.ID, guiSP->theGCA[0], 0, 0, guiSP->output_winS.width, guiSP->output_winS.height); /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + pixelSP->mol_complexI; /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + pixelSP->atomI; /* Pointer to raw atomic data: */ raw_atomSP = &curr_atomSP->raw_atomS; /* Pointer to the current residue: */ curr_residueSP = curr_mol_complexSP->residueSP + curr_atomSP->residue_arrayI; /* Prepare the text foreground color: */ XSetForeground (guiSP->displaySP, guiSP->theGCA[0], guiSP->output_winS.fg_colorID); /* Text line height: */ line_height = guiSP->output_winS.text_line_height; /* The initial drawing position: */ screen_x0 = TEXTMARGIN; screen_y0 = guiSP->output_winS.font_height + 5; /* Draw the unique PDB identifier: */ sprintf (stringA, "(%d) %s", curr_mol_complexSP->mol_complexID, curr_mol_complexSP->unique_PDB_codeA); stringA[SHORTSTRINGSIZE - 1] = '\0'; XDrawString (guiSP->displaySP, guiSP->output_winS.ID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, strlen (stringA)); /* Draw residue data: */ screen_y0 += line_height; sprintf (stringA, "%s %d %c", raw_atomSP->residue_nameA, raw_atomSP->residue_sequenceI, raw_atomSP->chainID); stringA[SHORTSTRINGSIZE - 1] = '\0'; XDrawString (guiSP->displaySP, guiSP->output_winS.ID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, strlen (stringA)); /* The peptide group conformation: */ screen_y0 += line_height; if (curr_residueSP->cis_transF == 1) { strcpy (stringA, "trans"); XDrawString (guiSP->displaySP, guiSP->output_winS.ID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, strlen (stringA)); } else if (curr_residueSP->cis_transF == 2) { strcpy (stringA, "cis"); XDrawString (guiSP->displaySP, guiSP->output_winS.ID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, strlen (stringA)); } else { strcpy (stringA, "bad/undef."); XDrawString (guiSP->displaySP, guiSP->output_winS.ID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, strlen (stringA)); } /* The angle phi (see dihedral_angles.c for definition): */ screen_y0 += line_height; phi = curr_residueSP->phi; if (phi == BADDIHEDANGLE) { strcpy (stringA, "phi: missing"); XDrawString (guiSP->displaySP, guiSP->output_winS.ID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, strlen (stringA)); } else { phi *= RAD_TO_DEG; sprintf (stringA, "phi: %7.2f", phi); stringA[SHORTSTRINGSIZE - 1] = '\0'; XDrawString (guiSP->displaySP, guiSP->output_winS.ID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, strlen (stringA)); } /* The angle psi (see dihedral_angles.c for definition): */ screen_y0 += line_height; psi = curr_residueSP->psi; if (psi == BADDIHEDANGLE) { strcpy (stringA, "psi: missing"); XDrawString (guiSP->displaySP, guiSP->output_winS.ID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, strlen (stringA)); } else { psi *= RAD_TO_DEG; sprintf (stringA, "psi: %7.2f", psi); stringA[SHORTSTRINGSIZE - 1] = '\0'; XDrawString (guiSP->displaySP, guiSP->output_winS.ID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, strlen (stringA)); } /* The angle omega psi (see dihedral_angles.c for definition): */ screen_y0 += line_height; omega = curr_residueSP->omega; if (omega == BADDIHEDANGLE) { strcpy (stringA, "omeg: missing"); XDrawString (guiSP->displaySP, guiSP->output_winS.ID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, strlen (stringA)); } else { omega *= RAD_TO_DEG; sprintf (stringA, "omeg:%7.2f", omega); stringA[SHORTSTRINGSIZE - 1] = '\0'; XDrawString (guiSP->displaySP, guiSP->output_winS.ID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, strlen (stringA)); } /* Return positive value: */ return 1; } /*===========================================================================*/ garlic-1.6/read_config.c0000644000076500007650000010514607646776702015547 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2003 Damir Zucic */ /*============================================================================= read_config.c Purpose: Read configuration data. Configuration file is .garlicrc and up to six directories are searched for this file. The only exception is /etc directory: if the configuration file is stored there it should be called garlicrc (without the leading period). If all attempts fail, default (hard-coded) parameters are used. Input: (1) Pointer to ConfigS structure, where some data will be stored. Output: (1) Some data stored to ConfigS structure. (2) Return value. Return value: (1) Positive if configuration read from file. (2) Zero if default values used for initialization. Notes: (1) This function is quite fast: on a 233 MHz Pentium MMX, it will take few milliseconds to execute. Therefore do not be surprised that if's are not optimized here. ========includes:============================================================*/ #include #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ FILE *OpenConfigFile_ (void); int ExtractInteger_ (char *); int ExtractTwoIntegers_ (int *, int *, char *); int ExtractPhrase_ (char *, char *); double ExtractDouble_ (char *); int ExtractTwoDoubles_ (double *, double *, char *); int ExtractIndex_ (char *); int ExtractRotationSteps_ (ConfigS *, char *); int ExtractTranslationSteps_ (ConfigS *, char *); int ExtractSlabSteps_ (ConfigS *, char *); int ExtractFadingSteps_ (ConfigS *, char *); /*======read configuration data (.garlicrc file):============================*/ int ReadConfig_ (ConfigS *configSP) { FILE *fileP; char s[STRINGSIZE]; int line_size; char phraseA[SHORTSTRINGSIZE]; int n, n1, n2; double d, d1, d2; int surfaceI; /* Default values; used if all attempts to find .garlicrc (or garlicrc) */ /* fail or if the corresponding entry does not exist in .garlicrc file: */ /* Main window geometry: */ strcpy (configSP->geometryA, "default"); /* Font name and cursor name: */ strcpy (configSP->font_nameA, "10x20"); strcpy (configSP->cursor_nameA, "default"); /* Coordinate system in the top left corner is visible by default: */ configSP->show_coord_systemF = 1; /* Control window in the top right corner is visible by default: */ configSP->show_control_windowF = 1; /* The sequence neighborhood of the residue under */ /* the pointer is visible and verbose by default: */ configSP->show_sequence_neighborhoodF = 2; /* Stereo flag (default is mono): */ configSP->stereoF = 0; /* Light source theta angle (with respect to z): */ configSP->light_theta = 150.0 * DEG_TO_RAD; /* Light source phi angle (with respect to x): */ configSP->light_phi = 225.0 * DEG_TO_RAD; /* Window colors: */ strcpy (configSP->bg_colorA, "black"); strcpy (configSP->fg_colorA, "white"); strcpy (configSP->text_bg_colorA, "black"); strcpy (configSP->text_fg_colorA, "white"); /* Slab mode index (default is planar): */ configSP->default_slab_modeI = 1; /* Color fading mode index (default is planar): */ configSP->default_fading_modeI = 1; /* Default number of color fading surfaces (up to MAXCOLORSURFACES): */ configSP->default_surfacesN = 3; /* Default colors for atoms and bonds: */ strcpy (configSP->left_colorAA[0], "RGB:FFFF/FFFF/0000"); strcpy (configSP->middle_colorAA[0], "RGB:FFFF/AAAA/0000"); strcpy (configSP->right_colorAA[0], "RGB:FFFF/5555/0000"); strcpy (configSP->left_colorAA[1], "RGB:FFFF/8888/0000"); strcpy (configSP->middle_colorAA[1], "RGB:FFFF/0000/0000"); strcpy (configSP->right_colorAA[1], "RGB:AAAA/0000/0000"); strcpy (configSP->left_colorAA[2], "RGB:7777/0000/0000"); strcpy (configSP->middle_colorAA[2], "RGB:5555/0000/0000"); strcpy (configSP->right_colorAA[2], "RGB:4444/0000/0000"); for (n = 3; n < MAXCOLORSURFACES; n++) { strcpy (configSP->left_colorAA[n], "white"); strcpy (configSP->middle_colorAA[n], "gray"); strcpy (configSP->right_colorAA[n], "DarkGray"); } /* Default color schemes for surfaces: */ strcpy (configSP->surface_outer_color_schemeA, "magenta"); strcpy (configSP->surface_inner_color_schemeA, "blue"); /* Drawing styles for atoms, bonds and backbone: */ configSP->default_atom_styleI = 2; configSP->default_bond_styleI = 3; configSP->default_backbone_styleI = 5; /* Bond lengths (angstroms): */ configSP->max_bond_length = 2.3; configSP->C_C_bond_length_min = 1.40; configSP->C_C_bond_length_max = 1.70; configSP->C_N_bond_length_min = 1.10; configSP->C_N_bond_length_max = 1.60; configSP->C_O_bond_length_min = 1.10; configSP->C_O_bond_length_max = 1.40; configSP->C_S_bond_length_min = 1.60; configSP->C_S_bond_length_max = 2.00; configSP->C_H_bond_length_min = 0.80; configSP->C_H_bond_length_max = 1.20; configSP->N_O_bond_length_min = 1.20; configSP->N_O_bond_length_max = 1.70; configSP->N_H_bond_length_min = 0.90; configSP->N_H_bond_length_max = 1.30; configSP->O_H_bond_length_min = 0.70; configSP->O_H_bond_length_max = 1.30; configSP->S_H_bond_length_min = 0.90; configSP->S_H_bond_length_max = 1.60; configSP->O_P_bond_length_min = 1.20; configSP->O_P_bond_length_max = 1.80; configSP->S_S_bond_length_min = 1.80; configSP->S_S_bond_length_max = 2.30; configSP->generic_bond_length_min = 0.8; configSP->generic_bond_length_max = 2.0; configSP->hydro_bond_length_min = 2.0; configSP->hydro_bond_length_max = 5.0; /* These two bond parameters are obsolete since version 1.3: */ configSP->hydro_bond_angle_min = (double) 125 * DEG_TO_RAD; configSP->hydro_bond_angle_max = (double) 180 * DEG_TO_RAD; /* The maximal CA_CA distance for two neighbouring residues (angstroms): */ configSP->CA_CA_dist_max = 4.1; /* Atomic radii (in angstroms): */ configSP->H_radius = 0.70; configSP->C_radius = 1.20; configSP->N_radius = 1.05; configSP->O_radius = 1.00; configSP->S_radius = 1.25; configSP->P_radius = 1.25; configSP->generic_radius = 1.40; /* Atomic covalent radii (in angstroms): */ configSP->H_covalent_radius = 0.70; configSP->C_covalent_radius = 1.20; configSP->N_covalent_radius = 1.05; configSP->O_covalent_radius = 1.00; configSP->S_covalent_radius = 1.25; configSP->P_covalent_radius = 1.25; configSP->generic_covalent_radius = 1.40; /* Atomic small radii (in angstroms): */ configSP->H_small_radius = 0.21; configSP->C_small_radius = 0.54; configSP->N_small_radius = 0.49; configSP->O_small_radius = 0.46; configSP->S_small_radius = 0.73; configSP->P_small_radius = 0.77; configSP->generic_small_radius = 0.84; /* van der Waals radii (in angstroms): */ configSP->H_van_der_Waals_radius = 1.00; configSP->C_van_der_Waals_radius = 1.70; configSP->N_van_der_Waals_radius = 1.50; configSP->O_van_der_Waals_radius = 1.40; configSP->S_van_der_Waals_radius = 1.80; configSP->P_van_der_Waals_radius = 1.80; configSP->generic_van_der_Waals_radius = 2.00; /* Default ball radius (used to draw atoms as balls of equal size): */ configSP->default_ball_radius = 0.40; /* Default bond probe radius (used to draw nice bonds with curved surfaces): */ configSP->default_bond_probe_radius = 0.80; /* Default stick radius (used to draw bonds as sticks): */ configSP->default_stick_radius = 0.15; /* Number of neighbors to be checked as bond candidates: */ configSP->bond_candidates_backward = 50; configSP->bond_candidates_forward = 50; /* Geometric parameters: */ configSP->main_margin_left = 30; configSP->main_margin_right = 30; configSP->main_margin_top = 60; configSP->main_margin_bottom = 30; configSP->max_main_win_width = MAXWINWIDTH; configSP->max_main_win_height = MAXWINHEIGHT; configSP->nearest_line_thickness = MAXLINES; configSP->screen_real_width = SCREEN_REAL_WX; configSP->screen_real_height = SCREEN_REAL_WY; configSP->user_screen_real_distance = USER_SCREEN_REAL_DIST; configSP->screen_atomic_width = SCREEN_ATOMIC_WX; configSP->user_atomic_position = USER_ATOMIC_Z; configSP->stereo_screen_margin = STEREO_MARGIN; configSP->stereo_angle = STEREO_ANGLE * DEG_TO_RAD; configSP->rotation_stepA[0] = 0.2 * DEG_TO_RAD; configSP->rotation_stepA[1] = 1.0 * DEG_TO_RAD; configSP->rotation_stepA[2] = 5.0 * DEG_TO_RAD; configSP->rotation_stepA[3] = 30.0 * DEG_TO_RAD; configSP->rotation_stepA[4] = 90.0 * DEG_TO_RAD; configSP->translation_stepA[0] = 0.2; configSP->translation_stepA[1] = 1.0; configSP->translation_stepA[2] = 5.0; configSP->translation_stepA[3] = 25.0; configSP->translation_stepA[4] = 100.0; configSP->slab_stepA[0] = 0.2; configSP->slab_stepA[1] = 1.0; configSP->slab_stepA[2] = 5.0; configSP->slab_stepA[3] = 20.0; configSP->slab_stepA[4] = 80.0; configSP->fading_stepA[0] = 0.2; configSP->fading_stepA[1] = 1.0; configSP->fading_stepA[2] = 5.0; configSP->fading_stepA[3] = 20.0; configSP->fading_stepA[4] = 80.0; /* Try to find the personal or public configuration file: */ if ((fileP = OpenConfigFile_ ()) == NULL) return 0; /* If this point is reached, file is available - read and parse all lines: */ line_size = sizeof (s); while (fgets (s, line_size, fileP)) { /* Skip comments: */ if (strstr (s, "#") == s) continue; /* Skip very short lines: */ if (strlen (s) <= 5) continue; /* Main window geometry: */ if (strstr (s, "main") && strstr (s, "window") && strstr (s, "geometry")) { if (ExtractPhrase_ (phraseA, s) > 0) { strncpy (configSP->geometryA, phraseA, SHORTSTRINGSIZE - 1); configSP->geometryA[SHORTSTRINGSIZE - 1] = '\0'; } continue; } /* Main font name: */ if (strstr (s, "main") && strstr (s, "font")) { if (ExtractPhrase_ (phraseA, s) > 0) { strncpy (configSP->font_nameA, phraseA, SHORTSTRINGSIZE - 1); configSP->font_nameA[SHORTSTRINGSIZE - 1] = '\0'; } continue; } /* Main window cursor: */ if (strstr (s, "main") && strstr (s, "window") && strstr (s, "cursor")) { if (ExtractPhrase_ (phraseA, s) > 0) { strncpy (configSP->cursor_nameA, phraseA, SHORTSTRINGSIZE - 1); configSP->cursor_nameA[SHORTSTRINGSIZE - 1] = '\0'; } continue; } /* Coordinate system in the top left corner (yes or no): */ if (strstr (s, "show") && strstr (s, "coordinate") && strstr (s, "system")) { if (ExtractPhrase_ (phraseA, s) > 0) { if (strstr (phraseA, "no")) { configSP->show_coord_systemF = 0; } } continue; } /* Control window in the top right corner: */ if (strstr (s, "show") && strstr (s, "control") && strstr (s, "window")) { if (ExtractPhrase_ (phraseA, s) > 0) { if (strstr (phraseA, "no")) { configSP->show_control_windowF = 0; } } continue; } /* Sequence neighborhood of the residue under the pointer: */ if (strstr (s, "show") && strstr (s, "sequence") && strstr (s, "neighborhood")) { if (ExtractPhrase_ (phraseA, s) > 0) { if (strstr (phraseA, "no")) { configSP->show_sequence_neighborhoodF = 0; } else if (strstr (phraseA, "yes")) { configSP->show_sequence_neighborhoodF = 1; } else if (strstr (phraseA, "verbose")) { configSP->show_sequence_neighborhoodF = 2; } } continue; } /* Stereo flag (0 = mono, 1 = stereo): */ if (strstr (s, "display") && strstr (s, "stereo") && strstr (s, "image")) { if (ExtractPhrase_ (phraseA, s) > 0) { if (strstr (phraseA, "yes")) configSP->stereoF = 1; } continue; } /* Default slab mode index (see typedefs.h for available modes): */ if (strstr (s, "default") && strstr (s, "slab") && strstr (s, "mode")) { if (ExtractPhrase_ (phraseA, s) > 0) { if (strncmp (phraseA, "off", 50) == 0) configSP->default_slab_modeI = 0; else if (strncmp (phraseA, "planar", 50) == 0) configSP->default_slab_modeI = 1; else if (strncmp (phraseA, "sphere", 50) == 0) configSP->default_slab_modeI = 2; else if (strncmp (phraseA, "half-sphere", 50) == 0) configSP->default_slab_modeI = 3; else if (strncmp (phraseA, "cylinder", 50) == 0) configSP->default_slab_modeI = 4; else if (strncmp (phraseA, "half-cylinder", 50) == 0) configSP->default_slab_modeI = 5; else configSP->default_slab_modeI = 1; /* Default */ } continue; } /* Default fading mode index (see typedefs.h for available modes): */ if (strstr (s, "default") && strstr (s, "fading") && strstr (s, "mode")) { if (ExtractPhrase_ (phraseA, s) > 0) { if (strncmp (phraseA, "off", 50) == 0) configSP->default_fading_modeI = 0; else if (strncmp (phraseA, "planar", 50) == 0) configSP->default_fading_modeI = 1; else if (strncmp (phraseA, "sphere", 50) == 0) configSP->default_fading_modeI = 2; else if (strncmp (phraseA, "half-sphere", 50) == 0) configSP->default_fading_modeI = 3; else if (strncmp (phraseA, "cylinder", 50) == 0) configSP->default_fading_modeI = 4; else if (strncmp (phraseA, "half-cylinder", 50) == 0) configSP->default_fading_modeI = 5; else configSP->default_fading_modeI = 1; /* Default */ } continue; } /* Main window left margin: */ if (strstr (s, "main") && strstr (s, "window") && strstr (s, "left") && strstr (s, "margin")) { n = ExtractInteger_ (s); if (n >= 0) configSP->main_margin_left = n; continue; } /* Main window right margin: */ if (strstr (s, "main") && strstr (s, "window") && strstr (s, "right") && strstr (s, "margin")) { n = ExtractInteger_ (s); if (n >= 0) configSP->main_margin_right = n; continue; } /* Main window top margin: */ if (strstr (s, "main") && strstr (s, "window") && strstr (s, "top") && strstr (s, "margin")) { n = ExtractInteger_ (s); if (n >= 0) configSP->main_margin_top = n; continue; } /* Main window bottom margin: */ if (strstr (s, "main") && strstr (s, "window") && strstr (s, "bottom") && strstr (s, "margin")) { n = ExtractInteger_ (s); if (n >= 0) configSP->main_margin_bottom = n; continue; } /* Background color specification: */ if (strstr (s, "main") && strstr (s, "window") && strstr (s, "background") && strstr (s, "color")) { if (ExtractPhrase_ (phraseA, s) > 0) { strncpy (configSP->bg_colorA, phraseA, SHORTSTRINGSIZE - 1); configSP->bg_colorA[SHORTSTRINGSIZE - 1] = '\0'; } continue; } /* Foreground color specification: */ if (strstr (s, "main") && strstr (s, "window") && strstr (s, "foreground") && strstr (s, "color")) { if (ExtractPhrase_ (phraseA, s) > 0) { strncpy (configSP->fg_colorA, phraseA, SHORTSTRINGSIZE - 1); configSP->fg_colorA[SHORTSTRINGSIZE - 1] = '\0'; } continue; } /* Text background color: */ if (strstr (s, "text") && strstr (s, "background") && strstr (s, "color")) { if (ExtractPhrase_ (phraseA, s) > 0) { strncpy (configSP->text_bg_colorA, phraseA, SHORTSTRINGSIZE - 1); configSP->text_bg_colorA[SHORTSTRINGSIZE - 1] = '\0'; } continue; } /* Text foreground color: */ if (strstr (s, "text") && strstr (s, "foreground") && strstr (s, "color")) { if (ExtractPhrase_ (phraseA, s) > 0) { strncpy (configSP->text_fg_colorA, phraseA, SHORTSTRINGSIZE - 1); configSP->text_fg_colorA[SHORTSTRINGSIZE - 1] = '\0'; } continue; } /* Default number of color fading surfaces: */ if (strstr (s, "number") && strstr (s, "color") && strstr (s, "surfaces")) { n = ExtractInteger_ (s); if ((n > 0) && (n <= MAXCOLORSURFACES)) { configSP->default_surfacesN = n; } continue; } /* Left color: */ if (strstr (s, "left") && strstr (s, "color")) { surfaceI = ExtractIndex_ (s); if ((surfaceI < 0) || (surfaceI >= MAXCOLORSURFACES)) continue; if (ExtractPhrase_ (phraseA, s) > 0) { strncpy (configSP->left_colorAA[surfaceI], phraseA, SHORTSTRINGSIZE - 1); n = SHORTSTRINGSIZE - 1; configSP->left_colorAA[surfaceI][n] = '\0'; } continue; } /* Middle color: */ if (strstr (s, "middle") && strstr (s, "color")) { surfaceI = ExtractIndex_ (s); if ((surfaceI < 0) || (surfaceI >= MAXCOLORSURFACES)) continue; if (ExtractPhrase_ (phraseA, s) > 0) { strncpy (configSP->middle_colorAA[surfaceI], phraseA, SHORTSTRINGSIZE - 1); n = SHORTSTRINGSIZE - 1; configSP->middle_colorAA[surfaceI][n] = '\0'; } continue; } /* Right color: */ if (strstr (s, "right") && strstr (s, "color")) { surfaceI = ExtractIndex_ (s); if ((surfaceI < 0) || (surfaceI >= MAXCOLORSURFACES)) continue; if (ExtractPhrase_ (phraseA, s) > 0) { strncpy (configSP->right_colorAA[surfaceI], phraseA, SHORTSTRINGSIZE - 1); n = SHORTSTRINGSIZE - 1; configSP->right_colorAA[surfaceI][n] = '\0'; } continue; } /* Default color scheme for the outer side of molecular surfaces: */ if (strstr (s, "surface") && strstr (s, "outer") && strstr (s, "color") && strstr (s, "scheme")) { if (ExtractPhrase_ (phraseA, s) > 0) { strncpy (configSP->surface_outer_color_schemeA, phraseA, SHORTSTRINGSIZE - 1); n = SHORTSTRINGSIZE - 1; configSP->surface_outer_color_schemeA[n] = '\0'; } continue; } /* Default color scheme for the inner side of molecular surfaces: */ if (strstr (s, "surface") && strstr (s, "inner") && strstr (s, "color") && strstr (s, "scheme")) { if (ExtractPhrase_ (phraseA, s) > 0) { strncpy (configSP->surface_inner_color_schemeA, phraseA, SHORTSTRINGSIZE - 1); n = SHORTSTRINGSIZE - 1; configSP->surface_inner_color_schemeA[n] = '\0'; } continue; } /* Default drawing style for atoms: */ if (strstr (s, "default") && strstr (s, "atom") && strstr (s, "drawing") && strstr (s, "style")) { n = ExtractInteger_ (s); if ((n >= 0) && (n <= MAXATOMSTYLEI)) { configSP->default_atom_styleI = n; } continue; } /* Default drawing style for bonds: */ if (strstr (s, "default") && strstr (s, "bond") && strstr (s, "drawing") && strstr (s, "style")) { n = ExtractInteger_ (s); if ((n >= 0) && (n <= MAXBONDSTYLEI)) { configSP->default_bond_styleI = n; } continue; } /* Default backbone drawing style: */ if (strstr (s, "default") && strstr (s, "backbone") && strstr (s, "drawing") && strstr (s, "style")) { n = ExtractInteger_ (s); if ((n >= 0) && (n <= MAXBONESTYLEI)) { configSP->default_backbone_styleI = n; } continue; } /* Maximal main window width: */ if (strstr (s, "maximal") && strstr (s, "window") && strstr (s, "width")) { n = ExtractInteger_ (s); if (n >= 0) configSP->max_main_win_width = n; continue; } /* Maximal main window height: */ if (strstr (s, "maximal") && strstr (s, "window") && strstr (s, "height")) { n = ExtractInteger_ (s); if (n >= 0) configSP->max_main_win_height = n; continue; } /* The nearest line (i.e. the nearest bond) thickness. */ /* Used only if line thickness is used for perspective! */ if (strstr (s, "nearest") && strstr (s, "line") && strstr (s, "thickness")) { n = ExtractInteger_ (s); if (n >= 0) configSP->nearest_line_thickness = n; continue; } /* Screen width in real world: */ if (strstr (s, "screen") && strstr (s, "real") && strstr (s, "width")) { d = ExtractDouble_ (s); if (d > 0.0) configSP->screen_real_width = d; continue; } /* Screen height in real world: */ if (strstr (s, "screen") && strstr (s, "real") && strstr (s, "height")) { d = ExtractDouble_ (s); if (d > 0.0) configSP->screen_real_height = d; continue; } /* Distance between user and screen in real world: */ if (strstr (s, "distance") && strstr (s, "user") && strstr (s, "screen") && strstr (s, "real")) { d = ExtractDouble_ (s); if (d > 0.0) configSP->user_screen_real_distance = d; continue; } /* Screen width in atomic world: */ if (strstr (s, "screen") && strstr (s, "width") && strstr (s, "atomic")) { d = ExtractDouble_ (s); if (d > 0.0) configSP->screen_atomic_width = d; continue; } /* User z coordinate in atomic world (must be negative!): */ if (strstr (s, "user") && strstr (s, "position") && strstr (s, "atomic")) { d = ExtractDouble_ (s); if (d < 0) configSP->user_atomic_position = d; /* Negative! */ continue; } /* Stereo internal margin (separating left and right image): */ if (strstr (s, "stereo") && strstr (s, "internal") && strstr (s, "margin")) { n = ExtractInteger_ (s); if (n > 0) configSP->stereo_screen_margin = n; continue; } /* Stereo angle. The right image is rotated around y axis for that */ /* angle (right-handed rotation). Degrees read, radians stored: */ if (strstr (s, "stereo") && strstr (s, "angle")) { d = ExtractDouble_ (s); configSP->stereo_angle = d * DEG_TO_RAD; continue; } /* Light source theta angle: */ if (strstr (s, "light") && strstr (s, "source") && strstr (s, "theta") && strstr (s, "angle")) { d = ExtractDouble_ (s); configSP->light_theta = d * DEG_TO_RAD; continue; } /* Light source phi angle: */ if (strstr (s, "light") && strstr (s, "source") && strstr (s, "phi") && strstr (s, "angle")) { d = ExtractDouble_ (s); configSP->light_phi = d * DEG_TO_RAD; continue; } /* Rotation steps (very small, small, normal, large, very large): */ if (strstr (s, "rotation") && strstr (s, "steps")) { ExtractRotationSteps_ (configSP, s); continue; } /* Translation steps (very small, small, normal, large, very large): */ if (strstr (s, "translation") && strstr (s, "steps")) { ExtractTranslationSteps_ (configSP, s); continue; } /* Slab steps (very small, small, normal, large, very large): */ if (strstr (s, "slab") && strstr (s, "steps")) { ExtractSlabSteps_ (configSP, s); continue; } /* Fading steps (very small, small, normal, large, very large): */ if (strstr (s, "fading") && strstr (s, "steps")) { ExtractFadingSteps_ (configSP, s); continue; } /* Maximal bond length, used to check */ /* which atoms and bonds are invisible: */ if (strstr (s, "maximal") && strstr (s, "bond") && strstr (s, "length")) { d = ExtractDouble_ (s); if (d > 0.0) configSP->max_bond_length = d; continue; } /* Crude bond length limits for C-C bond: */ if (strstr (s, "approx") && strstr (s, "C-C") && strstr (s, "bond") && strstr (s, "length")) { if (ExtractTwoDoubles_ (&d1, &d2, s) > 0) { if ((d1 > 0) && (d2 > d1)) { configSP->C_C_bond_length_min = d1; configSP->C_C_bond_length_max = d2; } } continue; } /* Crude bond length limits for C-N bond: */ if (strstr (s, "approx") && strstr (s, "C-N") && strstr (s, "bond") && strstr (s, "length")) { if (ExtractTwoDoubles_ (&d1, &d2, s) > 0) { if ((d1 > 0) && (d2 > d1)) { configSP->C_N_bond_length_min = d1; configSP->C_N_bond_length_max = d2; } } continue; } /* Crude bond length limits for C-O bond: */ if (strstr (s, "approx") && strstr (s, "C-O") && strstr (s, "bond") && strstr (s, "length")) { if (ExtractTwoDoubles_ (&d1, &d2, s) > 0) { if ((d1 > 0) && (d2 > d1)) { configSP->C_O_bond_length_min = d1; configSP->C_O_bond_length_max = d2; } } continue; } /* Crude bond length limits for C-S bond: */ if (strstr (s, "approximate") && strstr (s, "C-S") && strstr (s, "bond") && strstr (s, "length")) { if (ExtractTwoDoubles_ (&d1, &d2, s) > 0) { if ((d1 > 0) && (d2 > d1)) { configSP->C_S_bond_length_min = d1; configSP->C_S_bond_length_max = d2; } } continue; } /* Crude bond length limits for C-H bond: */ if (strstr (s, "approximate") && strstr (s, "C-H") && strstr (s, "bond") && strstr (s, "length")) { if (ExtractTwoDoubles_ (&d1, &d2, s) > 0) { if ((d1 > 0) && (d2 > d1)) { configSP->C_H_bond_length_min = d1; configSP->C_H_bond_length_max = d2; } } continue; } /* Crude bond length limits for N-O bond: */ if (strstr (s, "approximate") && strstr (s, "N-O") && strstr (s, "bond") && strstr (s, "length")) { if (ExtractTwoDoubles_ (&d1, &d2, s) > 0) { if ((d1 > 0) && (d2 > d1)) { configSP->N_O_bond_length_min = d1; configSP->N_O_bond_length_max = d2; } } continue; } /* Crude bond length limits for N-H bond: */ if (strstr (s, "approximate") && strstr (s, "N-H") && strstr (s, "bond") && strstr (s, "length")) { if (ExtractTwoDoubles_ (&d1, &d2, s) > 0) { if ((d1 > 0) && (d2 > d1)) { configSP->N_H_bond_length_min = d1; configSP->N_H_bond_length_max = d2; } } continue; } /* Crude bond length limits for O-H bond: */ if (strstr (s, "approximate") && strstr (s, "O-H") && strstr (s, "bond") && strstr (s, "length")) { if (ExtractTwoDoubles_ (&d1, &d2, s) > 0) { if ((d1 > 0) && (d2 > d1)) { configSP->O_H_bond_length_min = d1; configSP->O_H_bond_length_max = d2; } } continue; } /* Crude bond length limits for S-H bond: */ if (strstr (s, "approximate") && strstr (s, "S-H") && strstr (s, "bond") && strstr (s, "length")) { if (ExtractTwoDoubles_ (&d1, &d2, s) > 0) { if ((d1 > 0) && (d2 > d1)) { configSP->S_H_bond_length_min = d1; configSP->S_H_bond_length_max = d2; } } continue; } /* Crude bond length limits for O-P bond: */ if (strstr (s, "approximate") && strstr (s, "O-P") && strstr (s, "bond") && strstr (s, "length")) { if (ExtractTwoDoubles_ (&d1, &d2, s) > 0) { if ((d1 > 0) && (d2 > d1)) { configSP->O_P_bond_length_min = d1; configSP->O_P_bond_length_max = d2; } } continue; } /* Crude bond length limits for S-S bond: */ if (strstr (s, "approximate") && strstr (s, "S-S") && strstr (s, "bond") && strstr (s, "length")) { if (ExtractTwoDoubles_ (&d1, &d2, s) > 0) { if ((d1 > 0) && (d2 > d1)) { configSP->S_S_bond_length_min = d1; configSP->S_S_bond_length_max = d2; } } continue; } /* Bond length limits for unrecognized atomic pairs: */ if (strstr (s, "generic") && strstr (s, "bond") && strstr (s, "length")) { if (ExtractTwoDoubles_ (&d1, &d2, s) > 0) { if ((d1 > 0) && (d2 > d1)) { configSP->generic_bond_length_min = d1; configSP->generic_bond_length_max = d2; } } continue; } /* Hydrogen bond length range: */ if (strstr (s, "hydrogen") && strstr (s, "bond") && strstr (s, "length")) { if (ExtractTwoDoubles_ (&d1, &d2, s) > 0) { if ((d1 > 0) && (d2 > d1)) { configSP->hydro_bond_length_min = d1; configSP->hydro_bond_length_max = d2; } } continue; } /* Hydrogen bond angular range (obsolete since version 1.3!): */ if (strstr (s, "hydrogen") && strstr (s, "bond") && strstr (s, "angle")) { if (ExtractTwoDoubles_ (&d1, &d2, s) > 0) { if ((d1 >= 0.0) && (d1 <= 180.0) && (d2 > d1) && (d2 <= 180)) { configSP->hydro_bond_angle_min = d1 * DEG_TO_RAD; configSP->hydro_bond_angle_max = d2 * DEG_TO_RAD; } } continue; } /* The maximal CA-CA distance for two neighbouring residues: */ if (strstr (s, "maximal") && strstr (s, "CA-CA") && strstr (s, "distance")) { d = ExtractDouble_ (s); if (d > 0.0) configSP->CA_CA_dist_max = d; continue; } /* Radius of hydrogen atom: */ if (strstr (s, "radius") && strstr (s, "hydrogen") && !strstr (s, "Waals") && !strstr (s, "covalent") && !strstr (s, "small")) { d = ExtractDouble_ (s); if (d > 0.0) configSP->H_radius = d; continue; } /* Radius of carbon atom: */ if (strstr (s, "radius") && strstr (s, "carbon") && !strstr (s, "Waals") && !strstr (s, "covalent") && !strstr (s, "small")) { d = ExtractDouble_ (s); if (d > 0.0) configSP->C_radius = d; continue; } /* Radius of nitrogen atom: */ if (strstr (s, "radius") && strstr (s, "nitrogen") && !strstr (s, "Waals") && !strstr (s, "covalent") && !strstr (s, "small")) { d = ExtractDouble_ (s); if (d > 0.0) configSP->N_radius = d; continue; } /* Radius of oxygen atom: */ if (strstr (s, "radius") && strstr (s, "oxygen") && !strstr (s, "Waals") && !strstr (s, "covalent") && !strstr (s, "small")) { d = ExtractDouble_ (s); if (d > 0.0) configSP->O_radius = d; continue; } /* Radius of sulfur atom: */ if (strstr (s, "radius") && strstr (s, "sulfur") && !strstr (s, "Waals") && !strstr (s, "covalent") && !strstr (s, "small")) { d = ExtractDouble_ (s); if (d > 0.0) configSP->S_radius = d; continue; } /* Radius of phosphorus atom: */ if (strstr (s, "radius") && strstr (s, "phosphorus") && !strstr (s, "Waals") && !strstr (s, "covalent") && !strstr (s, "small")) { d = ExtractDouble_ (s); if (d > 0.0) configSP->P_radius = d; continue; } /* Radius of unknown atom (generic radius): */ if (strstr (s, "generic") && strstr (s, "radius") && !strstr (s, "Waals") && !strstr (s, "covalent") && !strstr (s, "small")) { d = ExtractDouble_ (s); if (d > 0.0) configSP->generic_radius = d; continue; } /* Covalent radius of hydrogen atom: */ if (strstr (s, "hydrogen") && strstr (s, "covalent")) { d = ExtractDouble_ (s); if (d > 0.0) configSP->H_covalent_radius = d; continue; } /* Covalent radius of carbon atom: */ if (strstr (s, "carbon") && strstr (s, "covalent")) { d = ExtractDouble_ (s); if (d > 0.0) configSP->C_covalent_radius = d; continue; } /* Covalent radius of nitrogen atom: */ if (strstr (s, "nitrogen") && strstr (s, "covalent")) { d = ExtractDouble_ (s); if (d > 0.0) configSP->N_covalent_radius = d; continue; } /* Covalent radius of oxygen atom: */ if (strstr (s, "oxygen") && strstr (s, "covalent")) { d = ExtractDouble_ (s); if (d > 0.0) configSP->O_covalent_radius = d; continue; } /* Covalent radius of sulfur atom: */ if (strstr (s, "sulfur") && strstr (s, "covalent")) { d = ExtractDouble_ (s); if (d > 0.0) configSP->S_covalent_radius = d; continue; } /* Covalent radius of phosphorus atom: */ if (strstr (s, "phosphorus") && strstr (s, "covalent")) { d = ExtractDouble_ (s); if (d > 0.0) configSP->P_covalent_radius = d; continue; } /* Covalent radius of unknown atom (generic radius): */ if (strstr (s, "generic") && strstr (s, "covalent")) { d = ExtractDouble_ (s); if (d > 0.0) configSP->generic_covalent_radius = d; continue; } /* Small radius of hydrogen atom: */ if (strstr (s, "hydrogen") && strstr (s, "small")) { d = ExtractDouble_ (s); if (d > 0.0) configSP->H_small_radius = d; continue; } /* Small radius of carbon atom: */ if (strstr (s, "carbon") && strstr (s, "small")) { d = ExtractDouble_ (s); if (d > 0.0) configSP->C_small_radius = d; continue; } /* Small radius of nitrogen atom: */ if (strstr (s, "nitrogen") && strstr (s, "small")) { d = ExtractDouble_ (s); if (d > 0.0) configSP->N_small_radius = d; continue; } /* Small radius of oxygen atom: */ if (strstr (s, "oxygen") && strstr (s, "small")) { d = ExtractDouble_ (s); if (d > 0.0) configSP->O_small_radius = d; continue; } /* Small radius of sulfur atom: */ if (strstr (s, "sulfur") && strstr (s, "small")) { d = ExtractDouble_ (s); if (d > 0.0) configSP->S_small_radius = d; continue; } /* Small radius of phosphorus atom: */ if (strstr (s, "phosphorus") && strstr (s, "small")) { d = ExtractDouble_ (s); if (d > 0.0) configSP->P_small_radius = d; continue; } /* Small radius of unknown atom (generic radius): */ if (strstr (s, "generic") && strstr (s, "small")) { d = ExtractDouble_ (s); if (d > 0.0) configSP->generic_small_radius = d; continue; } /* Van der Waals radius of hydrogen: */ if (strstr (s, "hydrogen") && strstr (s, "Waals")) { d = ExtractDouble_ (s); if (d > 0.0) configSP->H_van_der_Waals_radius = d; continue; } /* Van der Waals radius of carbon: */ if (strstr (s, "carbon") && strstr (s, "Waals")) { d = ExtractDouble_ (s); if (d > 0.0) configSP->C_van_der_Waals_radius = d; continue; } /* Van der Waals radius of nitrogen: */ if (strstr (s, "nitrogen") && strstr (s, "Waals")) { d = ExtractDouble_ (s); if (d > 0.0) configSP->N_van_der_Waals_radius = d; continue; } /* Van der Waals radius of oxygen: */ if (strstr (s, "oxygen") && strstr (s, "Waals")) { d = ExtractDouble_ (s); if (d > 0.0) configSP->O_van_der_Waals_radius = d; continue; } /* Van der Waals radius of sulfur: */ if (strstr (s, "sulfur") && strstr (s, "Waals")) { d = ExtractDouble_ (s); if (d > 0.0) configSP->S_van_der_Waals_radius = d; continue; } /* Van der Waals radius of phosphorus: */ if (strstr (s, "phosphorus") && strstr (s, "Waals")) { d = ExtractDouble_ (s); if (d > 0.0) configSP->P_van_der_Waals_radius = d; continue; } /* Van der Waals radius of unknown atom (generic radius): */ if (strstr (s, "generic") && strstr (s, "Waals")) { d = ExtractDouble_ (s); if (d > 0.0) configSP->generic_van_der_Waals_radius = d; continue; } /* Ball radius (used to draw balls and sticks): */ if (strstr (s, "default") && strstr (s, "ball") && strstr (s, "radius")) { d = ExtractDouble_ (s); if (d > 0.0) configSP->default_ball_radius = d; continue; } /* Default bond probe radius (used to draw nice bonds): */ if (strstr (s, "bond") && strstr (s, "probe") && strstr (s, "radius")) { d = ExtractDouble_ (s); if (d > 0.0) configSP->default_bond_probe_radius = d; continue; } /* Default stick radius (used to draw bonds as sticks): */ if (strstr (s, "default") && strstr (s, "stick") && strstr (s, "radius")) { d = ExtractDouble_ (s); if (d > 0.0) configSP->default_stick_radius = d; continue; } /* The number of neighboring atoms which should be checked */ /* as bond candidates, in each direction of AtomS array: */ if (strstr (s, "number") && strstr (s, "bond") && strstr (s, "candidates")) { if (ExtractTwoIntegers_ (&n1, &n2, s) > 0) { if (n1 > 0) configSP->bond_candidates_backward = n1; if (n2 > 0) configSP->bond_candidates_forward = n2; } continue; } /* Blur rectangle default width (positive integer expected): */ if (strstr (s, "blur") && strstr (s, "rectangle") && strstr (s, "width")) { n = ExtractInteger_ (s); if (n >= 0) configSP->blur_default_width = n; continue; } /* Blur rectangle default height (positive integer expected): */ if (strstr (s, "blur") && strstr (s, "rectangle") && strstr (s, "height")) { n = ExtractInteger_ (s); if (n >= 0) configSP->blur_default_height = n; continue; } } /* Close file: */ fclose (fileP); return 1; } /*===========================================================================*/ garlic-1.6/probes.script0000644000076500007650000000224507542443050015635 0ustar zuciczucic00000000000000# Show the combinations of different drawing styles and probes. # This script requires garlic version 1.2! load trp.pdb pos -15 -12 -50 ato sm2 probe 0.25 bon nice # Now inform user that refreshing is off: title 1 50 50 "Please be patient ..." # Switch refreshing off: refresh off load trp.pdb pos -5 -12 -50 ato sm2 probe 0.50 bon nice load trp.pdb pos 5 -12 -50 ato sm2 probe 1.00 bon nice load trp.pdb pos 15 -12 -50 ato sm2 probe 2.00 bon nice load trp.pdb pos -15 -4 -50 ato co2 probe 0.25 bon nice load trp.pdb pos -5 -4 -50 ato co2 probe 0.50 bon nice load trp.pdb pos 5 -4 -50 ato co2 probe 1.00 bon nice load trp.pdb pos 15 -4 -50 ato co2 probe 2.00 bon nice load trp.pdb pos -15 4 -50 ato sp2 probe 0.25 bon nice load trp.pdb pos -5 4 -50 ato sp2 probe 0.50 bon nice load trp.pdb pos 5 4 -50 ato sp2 probe 1.00 bon nice load trp.pdb pos 15 4 -50 ato sp2 probe 2.00 bon nice load trp.pdb pos -15 12 -50 ato bi2 probe 0.25 bon nice load trp.pdb pos -5 12 -50 ato bi2 probe 0.50 bon nice load trp.pdb pos 5 12 -50 ato bi2 probe 1.00 bon nice load trp.pdb pos 15 12 -50 ato bi2 probe 2.00 bon nice # Hide the title: title 1 off # Switch refreshing on: refresh garlic-1.6/is_polar.c0000644000076500007650000000255107375761007015102 0ustar zuciczucic00000000000000/* Copyright (C) 2001 Damir Zucic */ /*============================================================================= is_polar.c Purpose: Check is the specified residue polar. Check also is it hydrogen bond donor or acceptor. Input: (1) Residue name (purified, i.e. without spaces). Output: (1) Return value. Return value: (1) Negative, if residue is apolar. (2) Zero, if residue is polar and hydrogen bond acceptor. (3) One, if residue is polar and hydrogen bond donor. (4) Two, if residue is both donor and acceptor or ASX or GLX. ========includes:============================================================*/ #include #include /*======check is the specified residue polar:================================*/ int IsPolar_ (char *pure_residue_nameP) { static char polar_nameAA[13][4] = {"GLU", "GLN", "HIS", "LYS", "TYR", "TRP", "THR", "SER", "ASP", "ASN", "ARG", "ASX", "GLX"}; static int donorI[13] = { 0, 2, 1, 1, 1, 1, 0, 0, 0, 2, 1, 2, 2}; int i; /* Compare only the first three characters: */ for (i = 0; i < 13; i++) { if (!strcmp (polar_nameAA[i], pure_residue_nameP)) return donorI[i]; } /* If this point is reached, the specified residue is apolar: */ return -1; } /*===========================================================================*/ garlic-1.6/INSTALL0000644000076500007650000001151510364507237014152 0ustar zuciczucic00000000000000 Garlic Installation Garlic is the most portable molecular viewer/editor in the unix world, because the only libraries required by this program are the standard C library (libc), the standard math library (libm) and the standard X library (libX11). All other molecular visualization programs require some additional libraries. Before starting the installation, you might be interested to check the technical requirements. Most contemporary unix and unix-like systems (like linux) meet these requirements without need to change the configuration, so you can skip this text if you are impatient. If you have Apple McIntosh running Xtools from Tenon, please read the hints contributed by Chris from Macinchem: http://garlic.mefos.hr/garlic-1.6/install/macosx.html To compile and install garlic, follow these instructions: (1) Put garlic package (garlic-1.6.tar.gz) into some empty directory. (2) Uncompress and unpack the package: gzip -d garlic-1.6.tar.gz tar xf garlic-1.6.tar (3) Change your working directory: cd garlic-1.6 (4) Check which C compiler is available on your system. If you don't know how to find this information, try this: man -k compiler to obtain the list of available compilers. (5) If gcc (GNU C) compiler is not available on your system, use your favorite editor to edit Makefile. Replace gcc in: CC = gcc line with the name of your compiler (this may be cc, for example). If gcc is available on your system, do not change the CC line. (6) Find a directory which contains the Xlib library. Try this: cd / find . -name libX11\* Check where is the file libX11.so (sharable library - prefered) or libX11.a (static library - reserve option). If your directory is different from /usr/X11R6/lib, modify the line: LIBPATH = -L/usr/X11R6/lib in Makefile. For example, if libX11.so is stored in /usr/shlib directory on your system, the LIBPATH should be changed to: LIBPATH = -L/usr/shlib (7) Compile the package - just type: make and wait, it will take some time. (8) If everything worked fine, copy the executable to a choosen directory. /usr/local/bin may be a good choice. This job should be done by root (system administrator): cp garlic /usr/local/bin If you don't have root privileges, ask your local administrator to install garlic, or just leave it in one of your directories. (9) Now the .garlicrc configuration file and the file residues.pdb, which contains the template residues should be copied to a directory where these files will be accessible to everyone. If this is not done, garlic will work anyway, using hard-coded default configuration, but you will be unable to replace residues and to create peptides. The recommended directory is /usr/share/garlic but if /usr/share directory does not exist on your system, /usr/local/lib/garlic may be used. This should be done by root (system administrator): mkdir /usr/share/garlic cp .garlicrc /usr/share/garlic cp residues.pdb /usr/share/garlic (10) It may be good idea to copy the configuration file to your home directory or to the subdirectory garlic of your home directory. The same may be done with the file residues.pdb. If you do this, you will be able to personalize your garlic sessions, because your private files will override the system-wide defaults. Of course, you don't need root privileges to do this: cp .garlicrc $HOME cp residues.pdb $HOME or: mkdir $HOME/garlic cp .garlicrc $HOME/garlic cp residues.pdb $HOME/garlic (11) It is recommended to set the environment variable MOL_PATH, so garlic will search all directories listed in this variable to find the specified file. Detailed instructions may be found at: http://garlic.mefos.hr/garlic-1.6/install/mol_path.html (12) Clean up the mess (sources and .o files). Be sure to leave all .pdb files for later practice. Leave also the files with the extension .script, these are some garlic tutorial scripts. If garlic refuses to work because it fails to get the TrueColor visual, try to execute xdpyinfo and xwininfo (click into the root window); check the list of supported visuals and the current color depth. Choose the color depth for which the TrueColor visual is available. If you have the SGI Octane workstation, please read the text, contributed by Randal R. Ketchem: http://garlic.mefos.hr/garlic-1.6/install/octane.html If you have IBM RS6000 with AIX, read the hint, contributed by Nicolas Ferre: http://garlic.mefos.hr/garlic-1.6/install/rs6000.html The list of sites with proteins, nucleic acids and hetero compounds may be found at: http://garlic.mefos.hr/garlic-1.6/data/index.html If you can't compile, install or run garlic, write to me (Damir Zucic), my address is zucic@mefos.hr . garlic-1.6/draw_tags.c0000644000076500007650000000655207611073666015252 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2003 Damir Zucic */ /*============================================================================= draw_tags.c Purpose: Draw tags for all caught complexes. Input: (1) Pointer to MolComplexS structure. (2) Number of macromolecular complexes. (3) Pointer to ConfigS structure. (4) Pointer to GUIS structure. Output: (1) Tags drawn to hidden pixmap. (2) Return value. Return value: The number of tags drawn. =============================================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int TagPosition_ (int *, int *, int *, MolComplexS *, int); /*======draw tags:===========================================================*/ int DrawTags_ (MolComplexS *mol_complexSP, int mol_complexesN, ConfigS *configSP, GUIS *guiSP) { int tags_drawnN = 0; int imageI, imagesN; int left_edge[2], right_edge[2]; int mol_complexI; MolComplexS *curr_mol_complexSP; size_t atomsN; int screen_left_x, screen_right_x, screen_x, screen_y; int tag_length, text_width; /* Number of images: */ if (configSP->stereoF) imagesN = 2; else imagesN = 1; /* Left and right image edge (in stereo mode there are two images): */ left_edge[0] = configSP->image_screen_x0[0]; right_edge[0] = configSP->image_screen_x1[0]; left_edge[1] = configSP->image_screen_x0[1]; right_edge[1] = configSP->image_screen_x1[1]; /* Prepare the text color: */ XSetForeground (guiSP->displaySP, guiSP->theGCA[0], guiSP->main_winS.fg_colorID); /* Check every macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /** Pointer to current macromolecular complex: **/ curr_mol_complexSP = mol_complexSP + mol_complexI; /** Prepare and check the number of atoms: **/ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /** Check is tag hidden or visible: **/ if (curr_mol_complexSP->tagF == 0) continue; /** Draw one (mono) or two tags (stereo): **/ for (imageI = 0; imageI < imagesN; imageI++) { /*** Prepare the screen coordinates: ***/ TagPosition_ (&screen_left_x, &screen_right_x, &screen_y, curr_mol_complexSP, imagesN); if (imageI == 0) screen_x = screen_left_x; else screen_x = screen_right_x; /** Check is this tag really visible: */ if (screen_x < left_edge[imageI]) continue; if (screen_x >= right_edge[imageI]) continue; /** Do not allow tag to overlap with the structure: **/ screen_y -= guiSP->main_winS.text_line_height + 1; /*** Tag length (the number of characters): ***/ tag_length = strlen (curr_mol_complexSP->tagA); /*** Prepare the tag size in pixels: ***/ text_width = XTextWidth (guiSP->main_winS.fontSP, curr_mol_complexSP->tagA, tag_length); /*** Draw tag: ***/ XDrawString (guiSP->displaySP, guiSP->main_winS.ID, guiSP->theGCA[0], screen_x - text_width / 2, screen_y, curr_mol_complexSP->tagA, tag_length); /*** Update the counter: ***/ tags_drawnN++; } /* imageI loop */ } /* mol_complexI loop */ /* Return the number of tags which were drawn: */ return tags_drawnN; } /*===========================================================================*/ garlic-1.6/apply_selection.c0000644000076500007650000001454307070335635016464 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= apply_selection.c Purpose: Apply the selection criteria. Cancel the previous selection and apply the new one. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. (3) Pointer to SelectS structure, with inclusion criteria. (4) Pointer to SelectS structure, with exclusion criteria. (5) Selection mode index (0 = overwrite, 1 = restrict, 2 = expand previous selection). Output: (1) The flag selectedF set for all atoms in all currently caught macromolecular complexes. (2) Return value. Return value: (1) The number of selected atoms (zero or positive value). Notes: (1) Indentation is exceptionally four spaces. (2) The position_changedF is updated, because some atoms may not have the proper color. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======apply selection criteria:============================================*/ long ApplySelection_ (MolComplexS *mol_complexSP, int mol_complexesN, SelectS *include_selectSP, SelectS *exclude_selectSP, int selection_modeI) { long selected_atomsN = 0; int mol_complexI; MolComplexS *curr_mol_complexSP; size_t atomsN, atomI; AtomS *curr_atomSP; int i, serialI, startI, endI; int chainF, residue_serialF, residue_nameF, atom_nameF, combinedF; /* Check every macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /** Pointer to the current macromolecular complex: **/ curr_mol_complexSP = mol_complexSP + mol_complexI; /** Check is the current macromolecular complex caught: **/ if (curr_mol_complexSP->catchF == 0) continue; /** Number of atoms in a macromolecular complex: **/ atomsN = curr_mol_complexSP->atomsN; /** Scan all atoms in the current complex: **/ for (atomI = 0; atomI < atomsN; atomI++) { /** Pointer to the current atom: **/ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /*---------------------------------------------------------------------------*/ /** Apply the inclusion criteria: **/ /*** Check chain ID: ***/ chainF = 0; if (include_selectSP->all_chainsF) chainF = 1; else { for (i = 0; i < include_selectSP->chainsN; i++) { if (curr_atomSP->raw_atomS.chainID == include_selectSP->chainIDA[i]) { chainF = 1; break; } } } /*** Check the residue serial number: ***/ residue_serialF = 0; if (include_selectSP->all_residue_serialF) residue_serialF = 1; else { for (i = 0; i < include_selectSP->residue_serial_rangesN; i++) { serialI = curr_atomSP->raw_atomS.residue_sequenceI; startI = include_selectSP->residue_serial_start[i]; endI = include_selectSP->residue_serial_end[i]; if ((serialI >= startI) && (serialI <= endI)) { residue_serialF = 1; break; } } } /*** Check residue name: ***/ residue_nameF = 0; if (include_selectSP->all_residue_namesF) residue_nameF = 1; else { for (i = 0; i < include_selectSP->residue_namesN; i++) { if (strcmp (curr_atomSP->raw_atomS.pure_residue_nameA, include_selectSP->residue_nameAA[i]) == 0) { residue_nameF = 1; break; } } } /*** Check atom name: ***/ atom_nameF = 0; if (include_selectSP->all_atom_namesF) atom_nameF = 1; else { for (i = 0; i < include_selectSP->atom_namesN; i++) { if (strcmp (curr_atomSP->raw_atomS.pure_atom_nameA, include_selectSP->atom_nameAA[i]) == 0) { atom_nameF = 1; break; } } } /*---------------------------------------------------------------------------*/ /** Apply the exclusion criteria: **/ /*** Check chain ID: ***/ if (exclude_selectSP->all_chainsF) chainF = 0; else { for (i = 0; i < exclude_selectSP->chainsN; i++) { if (curr_atomSP->raw_atomS.chainID == exclude_selectSP->chainIDA[i]) { chainF = 0; break; } } } /*** Check the residue serial number: ***/ if (exclude_selectSP->all_residue_serialF) residue_serialF = 0; else { for (i = 0; i < exclude_selectSP->residue_serial_rangesN; i++) { serialI = curr_atomSP->raw_atomS.residue_sequenceI; startI = exclude_selectSP->residue_serial_start[i]; endI = exclude_selectSP->residue_serial_end[i]; if ((serialI >= startI) && (serialI <= endI)) { residue_serialF = 0; break; } } } /*** Check residue name: ***/ if (exclude_selectSP->all_residue_namesF) residue_nameF = 0; else { for (i = 0; i < exclude_selectSP->residue_namesN; i++) { if (strcmp (curr_atomSP->raw_atomS.pure_residue_nameA, exclude_selectSP->residue_nameAA[i]) == 0) { residue_nameF = 0; break; } } } /*** Check atom name: ***/ if (exclude_selectSP->all_atom_namesF) atom_nameF = 0; else { for (i = 0; i < exclude_selectSP->atom_namesN; i++) { if (strcmp (curr_atomSP->raw_atomS.pure_atom_nameA, exclude_selectSP->atom_nameAA[i]) == 0) { atom_nameF = 0; break; } } } /*---------------------------------------------------------------------------*/ /** Combine all flags to calculate the selection flag: **/ combinedF = chainF * residue_serialF * residue_nameF * atom_nameF; /** Set the selection flag for the current atom: **/ switch (selection_modeI) { /*** Overwrite the previous selection: ***/ case 0: curr_atomSP->selectedF = combinedF; break; /*** Restrict the previous selection: ***/ case 1: curr_atomSP->selectedF &= combinedF; break; /*** Expand the previous selection: ***/ case 2: curr_atomSP->selectedF |= combinedF; break; default: ; } /** Check the selection flag; increase **/ /** the count if flag is equal to one: **/ if (curr_atomSP->selectedF) selected_atomsN++; } /** Update the position_changedF (some atoms may have bad color): **/ curr_mol_complexSP->position_changedF = 1; } /* Return the number of selected atoms: */ return selected_atomsN; } /*===========================================================================*/ garlic-1.6/bonds.script0000644000076500007650000000150607622025770015453 0ustar zuciczucic00000000000000# Show all drawing styles used to draw bonds. Atoms are hidden! # This script will work if you use default .garlicrc script. # This script requires garlic version 1.2! # Bond style 1: load trp.pdb pos -15 -5 -50 ato 0 bon 1 tag "1" # Now inform user that refreshing is off: title 1 50 50 "Please be patient ..." # Switch refreshing off: refresh off # Bond style 2: load trp.pdb pos -5 -5 -50 ato 0 bon 2 tag "2" # Bond style 3: load trp.pdb pos 5 -5 -50 ato 0 bon 3 tag "3" # Bond style 4: load trp.pdb pos 15 -5 -50 ato 0 bon 4 tag "4" # Bond style 5: load trp.pdb pos -15 5 -50 ato 0 bon 5 tag "5" # Bond style nice: load trp.pdb pos -5 5 -50 ato co2 bon nice tag "nic (nice)" # Bond style sticks: load trp.pdb pos 5 5 -50 ato ba2 bon sticks tag "sti (sticks)" # Hide the title: title 1 off # Switch refreshing on: refresh garlic-1.6/rotate_range.c0000644000076500007650000001102307272365503015733 0ustar zuciczucic00000000000000/* Copyright (C) 2001 Damir Zucic */ /*============================================================================= rotate_range.c Purpose: Rotate the specified range of atoms. The rotation is done about the specified axis. The axis is specified by one point and by one unit vector. Input: (1) Pointer to AtomS structure, pointing to the first element of the atomic array. (2) Index of the first atom in the range. (3) Index of the last atom in the range. (4) Pointer to VectorS structure, which defines the point in space. (5) Pointer to VectorS structure, which defines the unit vector. (6) The rotation angle. Output: (1) The specified range of atoms translated. (2) Return value. Return value: No return value. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int ParallelPart_ (VectorS *, VectorS *, VectorS *); double AbsoluteValue_ (VectorS *); void VectorProduct_ (VectorS *, VectorS *, VectorS *); double ScalarProduct_ (VectorS *, VectorS *); /*======rotate the range of atoms:===========================================*/ void RotateRange_ (AtomS *atomSP, size_t atom_startI, size_t atom_endI, VectorS *origin_vectorSP, VectorS *axis_vectorSP, double angle) { double cos_angle, sin_angle; size_t atomI; AtomS *curr_atomSP; VectorS radius_vectorS; VectorS parallel_vectorS; VectorS perpendicular_vectorS; double perpendicular_part; double abs_value; double reciprocal_abs_value; VectorS unit_vector1S, unit_vector2S; double p1_new, p2_new; /* Prepare the cosine and sine of the angle: */ cos_angle = cos (angle); sin_angle = sin (angle); /* Scan the range of atoms: */ for (atomI = atom_startI; atomI <= atom_endI; atomI++) { /* Pointer to the current atom: */ curr_atomSP = atomSP + atomI; /* Prepare the radius vector of the given atom: */ radius_vectorS.x = curr_atomSP->raw_atomS.x[0] - origin_vectorSP->x; radius_vectorS.y = curr_atomSP->raw_atomS.y - origin_vectorSP->y; radius_vectorS.z = curr_atomSP->raw_atomS.z[0] - origin_vectorSP->z; /* Find the part of the radius vector */ /* which is parallel to the rot. axis. */ ParallelPart_ (¶llel_vectorS, axis_vectorSP, &radius_vectorS); /* Find the part of the radius vector which */ /* is perpendicular to the rotation axis: */ perpendicular_vectorS.x = radius_vectorS.x - parallel_vectorS.x; perpendicular_vectorS.y = radius_vectorS.y - parallel_vectorS.y; perpendicular_vectorS.z = radius_vectorS.z - parallel_vectorS.z; /* Prepare and check the absolute value of the perpendicular part: */ perpendicular_part = AbsoluteValue_ (&perpendicular_vectorS); if (perpendicular_part <= 0.0) continue; /* Prepare the first unit vector, required for rotation: */ reciprocal_abs_value = 1.0 / perpendicular_part; unit_vector1S.x = reciprocal_abs_value * perpendicular_vectorS.x; unit_vector1S.y = reciprocal_abs_value * perpendicular_vectorS.y; unit_vector1S.z = reciprocal_abs_value * perpendicular_vectorS.z; /* Prepare and check the second unit vector: */ VectorProduct_ (&unit_vector2S, axis_vectorSP, &unit_vector1S); abs_value = AbsoluteValue_ (&unit_vector2S); if (abs_value <= 0.0) continue; reciprocal_abs_value = 1.0 / abs_value; unit_vector2S.x = unit_vector2S.x * reciprocal_abs_value; unit_vector2S.y = unit_vector2S.y * reciprocal_abs_value; unit_vector2S.z = unit_vector2S.z * reciprocal_abs_value; /* Rotate the perpendicular vector: */ p1_new = perpendicular_part * cos_angle; p2_new = perpendicular_part * sin_angle; perpendicular_vectorS.x = p1_new * unit_vector1S.x + p2_new * unit_vector2S.x; perpendicular_vectorS.y = p1_new * unit_vector1S.y + p2_new * unit_vector2S.y; perpendicular_vectorS.z = p1_new * unit_vector1S.z + p2_new * unit_vector2S.z; /* Update the radius vector: */ radius_vectorS.x = parallel_vectorS.x + perpendicular_vectorS.x; radius_vectorS.y = parallel_vectorS.y + perpendicular_vectorS.y; radius_vectorS.z = parallel_vectorS.z + perpendicular_vectorS.z; /* Update the atomic coordinates: */ curr_atomSP->raw_atomS.x[0] = radius_vectorS.x + origin_vectorSP->x; curr_atomSP->raw_atomS.y = radius_vectorS.y + origin_vectorSP->y; curr_atomSP->raw_atomS.z[0] = radius_vectorS.z + origin_vectorSP->z; } } /*===========================================================================*/ garlic-1.6/copypur.c0000644000076500007650000000134507065470011014757 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= copypur.c Purpose: Copy string, omitting spaces. Input: (1) Output string pointer. (2) Input string pointer. Output: (1) Output string. Return value: No return value. ========includes:============================================================*/ #include /*======copy purified string:================================================*/ void CopyPurified_ (char *output_stringP, char *input_stringP) { int n; while ((n = *input_stringP++) != '\0') if (n != ' ') *output_stringP++ = n; *output_stringP = '\0'; } /*===========================================================================*/ garlic-1.6/translate.c0000644000076500007650000000667607470135606015277 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2002 Damir Zucic */ /*============================================================================= translate.c Purpose: In default editing mode (no editing), translate atoms in macromol. complexes which are caught. TranslateComplex_ function takes care for stereo data and for position_changedF. If editing atoms (mode index equal to 1), translate only the selected atoms. If edit mode index is equal to 101, resize the selected portion of one or more objects. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. (3) Pointer to RuntimeS structure. (4) Pointer to ConfigS structure. (5) Translation shift. (6) Translation direction (axis) identifier (1 = x, 2 = y, 3 = z). Output: (1) Atoms translated in all caught macromolecular complexes. Return value: No return value. ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ void TranslatePlane_ (MolComplexS *, VectorS *); void TranslateMembrane_ (MolComplexS *, VectorS *); void ResizeComplex_ (MolComplexS *, double, int, ConfigS *); void TranslateComplex_ (MolComplexS *, VectorS *, ConfigS *, int); /*======translate all caught macromol. complexes:============================*/ void Translate_ (MolComplexS *mol_complexSP, int mol_complexesN, RuntimeS *runtimeSP, ConfigS *configSP, double shift, int axisID) { int edit_modeI; VectorS shift_vectorS; int mol_complexI; MolComplexS *curr_mol_complexSP; /* Copy the editing mode: */ edit_modeI = runtimeSP->edit_modeI; /* Prepare the shift vector: */ switch (axisID) { case 1: shift_vectorS.x = shift; shift_vectorS.y = 0.0; shift_vectorS.z = 0.0; break; case 2: shift_vectorS.x = 0.0; shift_vectorS.y = shift; shift_vectorS.z = 0.0; break; case 3: shift_vectorS.x = 0.0; shift_vectorS.y = 0.0; shift_vectorS.z = shift; break; default: ; break; } for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check is the current macromolecular complex caught: */ if (curr_mol_complexSP->catchF == 0) continue; /* Check is it necessary to translate the plane: */ if ((curr_mol_complexSP->move_bits & PLANE_MASK) && (edit_modeI != 1) && (edit_modeI != 101)) { TranslatePlane_ (curr_mol_complexSP, &shift_vectorS); } /* Check is it necessary to translate the membrane: */ if ((curr_mol_complexSP->move_bits & MEMBRANE_MASK) && (edit_modeI != 1) && (edit_modeI != 101)) { TranslateMembrane_ (curr_mol_complexSP, &shift_vectorS); } /* Check is it necessary to translate the structure at all: */ if (!(curr_mol_complexSP->move_bits & STRUCTURE_MASK)) continue; /* If resizing is required: */ if (edit_modeI == 101) { /* Resize the selected portion of the complex: */ ResizeComplex_ (curr_mol_complexSP, shift, axisID, configSP); /* Do not translate this complex: */ continue; } /* Translate or resize the complex (stereo data updated too): */ TranslateComplex_ (curr_mol_complexSP, &shift_vectorS, configSP, edit_modeI); } } /*===========================================================================*/ garlic-1.6/generate_plane.c0000644000076500007650000000744607562026324016245 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2002 Damir Zucic */ /*============================================================================= generate_plane.c Purpose: Generate the plane for a given macromolecular complex. The plane is defined by the plane center, normal vector and plane radius. It may be partially transparent or opaque. Stereo data should be prepared. Each plane is initially tilted toward observer, so that the top surface is visible. Input: (1) Pointer to MolComplexS structure, with macromolecular data. (2) Pointer to ConfigS structure, with configuration data. (3) Pointer to GUIS structure, with GUI data. Output: (1) Plane generated for a given macromolecular complex. (2) Return value. Return value: (1) Positive on success. (2) Zero, if complex contains no atoms (no geometric center). ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int ParseColor_ (RGBS *, unsigned long *, GUIS *, char *, char *); /*======generate plane:======================================================*/ int GeneratePlane_ (MolComplexS *mol_complexSP, ConfigS *configSP, GUIS *guiSP) { size_t atomsN; double tilt_angle; double sin_angle, cos_angle; /* Return zero if there are no atoms: */ atomsN = mol_complexSP->atomsN; if (atomsN == 0) return 0; /* The plane is initially hidden: */ mol_complexSP->planeS.hiddenF = 1; /* The plane center: */ mol_complexSP->planeS.center_x[0] = mol_complexSP->geometric_center_vectorS.x; mol_complexSP->planeS.center_x[1] = mol_complexSP->planeS.center_x[0]; mol_complexSP->planeS.center_y = mol_complexSP->geometric_center_vectorS.y; mol_complexSP->planeS.center_z[0] = mol_complexSP->geometric_center_vectorS.z; mol_complexSP->planeS.center_z[1] = mol_complexSP->planeS.center_z[0]; /* Circle radius: */ mol_complexSP->planeS.circle_radius = (0.5 + CIRCLEMARGIN) * mol_complexSP->max_extent; /* The plane tilt angle, in radians: */ tilt_angle = CIRCLETILT * DEG_TO_RAD; /* The normal vector (perpendicular to x axis): */ mol_complexSP->planeS.normal_x[0] = 0; mol_complexSP->planeS.normal_y = -cos (tilt_angle); mol_complexSP->planeS.normal_z[0] = -sin (tilt_angle); /* Prepare the sine and cosine of the stereo angle: */ sin_angle = sin (configSP->stereo_angle); cos_angle = cos (configSP->stereo_angle); /* Prepare stereo data for the normal vector: */ mol_complexSP->planeS.normal_x[1] = mol_complexSP->planeS.normal_x[0] * cos_angle + mol_complexSP->planeS.normal_z[0] * sin_angle; mol_complexSP->planeS.normal_z[1] = -mol_complexSP->planeS.normal_x[0] * sin_angle + mol_complexSP->planeS.normal_z[0] * cos_angle; /* Define colors. */ /* Top side near color: */ ParseColor_ (&mol_complexSP->planeS.top_near_rgbS, &mol_complexSP->planeS.top_near_colorID, guiSP, "RGB:0000/8888/FFFF", "white"); /* Top side far color: */ ParseColor_ (&mol_complexSP->planeS.top_far_rgbS, &mol_complexSP->planeS.top_far_colorID, guiSP, "RGB:0000/2222/4444", "black"); /* Bottom side near color: */ ParseColor_ (&mol_complexSP->planeS.bottom_near_rgbS, &mol_complexSP->planeS.bottom_near_colorID, guiSP, "RGB:DDDD/8888/8888", "white"); /* Bottom side far color: */ ParseColor_ (&mol_complexSP->planeS.bottom_far_rgbS, &mol_complexSP->planeS.bottom_far_colorID, guiSP, "RGB:3333/2222/2222", "black"); /* Initialize transparency: */ mol_complexSP->planeS.transparency = DEFAULT_TRANSP; /* If this point is reached, return positive value (success indicator): */ return 1; } /*===========================================================================*/ garlic-1.6/assign_hyphob.c0000644000076500007650000000515607761147043016130 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2003 Damir Zucic */ /*============================================================================= assign_hyphob.c Purpose: Assign hydrophobicity to each atom in a macromolecular complex. Use the scale specified by the last argument. If zero is the last argument, use default scale. Input: (1) Pointer to MolComplexS structure, with macromolecular data. (2) Hydrophobicity scale index. Output: (1) Hydrophobicity information assigned to each atom. (2) Return value. Return value: (1) Positive on success (scale is available). (2) Zero, if complex contains no atoms. (3) Negative on failure (scale not available). Notes: (1) The average hydrophobicity is assigned to all atoms which belong to unknown (unidentifyed) residues. (2) Check init_runtime.c for default hydrophobicity scale! ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ double Hydrophobicity_ (char *, int, int); /*======assign hydrophobicity to each atom in a given complex:===============*/ int AssignHydrophobicity_ (MolComplexS *mol_complexSP, int scaleI) { size_t atomsN, atomI; RawAtomS *raw_atomSP; char *nameP; /* Return negative value if scale is not available: */ if (scaleI >= SCALESN) return -1; /* Copy the scale index to the MolComplexS structure: */ mol_complexSP->hydrophobicity_scaleI = scaleI; /* Store extreme values of hydrophobicity for the given scale: */ mol_complexSP->min_hydrophobicity = Hydrophobicity_ ("", scaleI, 1); mol_complexSP->max_hydrophobicity = Hydrophobicity_ ("", scaleI, 2); /* Store average hydrophobicity: */ mol_complexSP->average_hydrophobicity = Hydrophobicity_ ("", scaleI, 3); /* Store threshold hydrophobicity: */ mol_complexSP->threshold_hydrophobicity = Hydrophobicity_ ("", scaleI, 4); /* Return zero if there are no atoms: */ atomsN = mol_complexSP->atomsN; if (atomsN == 0) return 0; /* Scan all atoms: */ for (atomI = 0; atomI < atomsN; atomI++) { /** Pointer to raw atomic data: **/ raw_atomSP = &(mol_complexSP->atomSP + atomI)->raw_atomS; /** Pointer to residue name: **/ nameP = raw_atomSP->pure_residue_nameA; /** Assign hydrophobicity: **/ raw_atomSP->hydrophobicity = Hydrophobicity_ (nameP, scaleI, 0); } /* If this point is reached, return positive value (success indicator): */ return 1; } /*===========================================================================*/ garlic-1.6/refresh_pixmap.c0000644000076500007650000000225707072414264016303 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= refresh_pixmap.c Purpose: Refresh pixmap (fill with given color). Input: (1) Display structure pointer. (2) Pixmap ID. (3) Graphics context (GC). (4) Width of the area to be refreshed (left justified). (5) Height of the area to be refreshed (top justified). (6) Color ID. Output: (1) Pixmap refreshed (filled with uniform color). (2) Return value. Return value: (1) Always positive (trivial). =============================================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======refresh pixmap (fill with given color):==============================*/ int RefreshPixmap_ (Display *displaySP, Pixmap pixmapID, GC theGC, unsigned int width, unsigned int height, unsigned long colorID) { XSetForeground (displaySP, theGC, colorID); XFillRectangle (displaySP, pixmapID, theGC, 0, 0, width, height); return 1; } /*===========================================================================*/ garlic-1.6/docking_resize.c0000644000076500007650000000245407155645254016274 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= docking_resize.c Purpose: Handle ConfigureNotify event for docking window. Input: (1) Pointer to RuntimeS structure. (2) Pointer to GUIS structure. (3) Pointer to XConfigureEvent structure. Output: (1) Two geometric parameters updated. (2) Return value. Return value: (1) Positive if geometric parameters are updated. (2) Zero if nothing should be done. ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======handle ConfigureNotify event for docking window:=====================*/ int DockingResize_ (RuntimeS *runtimeSP, GUIS *guiSP, XConfigureEvent *configure_eventSP) { /* If this event was not generated for docking window, do nothing: */ if (configure_eventSP->window != guiSP->docking_winS.ID) return 0; /* New width and height of docking window: */ guiSP->docking_winS.width = configure_eventSP->width; guiSP->docking_winS.height = configure_eventSP->height; /* Return positive value: */ return 1; } /*===========================================================================*/ garlic-1.6/text_foreground.c0000644000076500007650000000656607065475326016524 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= text_foreground.c Purpose: Execute tfg command: change the foreground color for input and output window. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) The number of macromolecular complexes. (3) Pointer to RuntimeS structure, with some runtime data. (4) Pointer to ConfigS structure, with configuration data. (5) Pointer to GUIS structure, with GUI data. (6) Pointer to NearestAtomS structure. (7) The number of pixels in the main window free area. (8) Pointer to refreshI. Output: (1) Log file created. (2) Return value. Return value: (1) Positive (command) code on success. (2) Negative (error) code on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "commands.h" #include "typedefs.h" /*======function prototypes:=================================================*/ char *ExtractToken_ (char *, int, char *, char *); int ParseColor_ (RGBS *, unsigned long *, GUIS *, char *, char *); size_t MainRefresh_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); /*======execute tfg command:=================================================*/ int TextForeground_ (MolComplexS *mol_complexSP, int mol_complexesN, RuntimeS *runtimeSP, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int *refreshIP) { char *remainderP; char tokenA[STRINGSIZE]; size_t rgb_struct_size; /* Skip the first token: */ remainderP = ExtractToken_ (tokenA, STRINGSIZE, runtimeSP->curr_commandA, " \t\n"); if (!remainderP) return ERROR_TFG; /* The second token should contain the color: */ remainderP = ExtractToken_ (tokenA, STRINGSIZE, remainderP, " \t\n"); if (!remainderP) { strcpy (runtimeSP->messageA, "Text foreground color missing!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_NO_COLOR; } /* Prepare the text foreground color: */ strncpy (configSP->text_fg_colorA, tokenA, SHORTSTRINGSIZE - 1); configSP->text_fg_colorA[SHORTSTRINGSIZE - 1] = '\0'; ParseColor_ (&guiSP->input_winS.fg_rgbS, &guiSP->input_winS.fg_colorID, guiSP, configSP->text_fg_colorA, "yellow"); /* Don't forget output window and control window: */ rgb_struct_size = sizeof (RGBS); memcpy (&guiSP->output_winS.fg_rgbS, &guiSP->input_winS.fg_rgbS, rgb_struct_size); guiSP->output_winS.fg_colorID = guiSP->input_winS.fg_colorID; memcpy (&guiSP->control_winS.fg_rgbS, &guiSP->input_winS.fg_rgbS, rgb_struct_size); guiSP->control_winS.fg_colorID = guiSP->input_winS.fg_colorID; /* Input and output window should have new foreground color: */ XSetWindowBorder (guiSP->displaySP, guiSP->input_winS.ID, guiSP->input_winS.fg_colorID); XSetWindowBorder (guiSP->displaySP, guiSP->output_winS.ID, guiSP->output_winS.fg_colorID); /* Refresh the main window: */ (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); /* Return positive value on success: */ return COMMAND_TFG; } /*===========================================================================*/ garlic-1.6/sticks.c0000644000076500007650000000542707604150463014570 0ustar zuciczucic00000000000000/* Copyright (C) 2002 Damir Zucic */ /*============================================================================= sticks.c Purpose: Execute sticks command: change the radius of sticks. This radius is used used to draw bonds as sticks. Input: (1) Pointer to ConfigS structure. (2) Pointer to the remainder of the command string. Output: (1) The radius of sticks changed. (2) Return value. Return value: (1) Positive (command) code on success. (2) Negative (error) code on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include #include "defines.h" #include "commands.h" #include "typedefs.h" /*======function prototypes:=================================================*/ size_t MainRefresh_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); int ControlRefresh_ (MolComplexS *, ConfigS *, GUIS *); /*======execute sticks command:==============================================*/ int Sticks_ (MolComplexS *mol_complexSP, int mol_complexesN, RuntimeS *runtimeSP, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int *refreshIP, char *stringP) { char *P; int n; double value; int mol_complexI; MolComplexS *curr_mol_complexSP; /* Replace each non-numeric character (except */ /* minus sign and decimal point) with space: */ P = stringP; while ((n = *P++) != '\0') { if (!isdigit (n) && (n != '-') && (n != '.')) *(P - 1) = ' '; } /* Try to extract the radius of sticks: */ if (sscanf (stringP, "%lf", &value) != 1) { strcpy (runtimeSP->messageA, "Failed to extract the stick radius!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_STICKS; } /* Check the radius of sticks (must be positive): */ if (value < 0.0) { strcpy (runtimeSP->messageA, "Positive value expected!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_STICKS; } /* On success, set the radius of sticks for each caught complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { curr_mol_complexSP = mol_complexSP + mol_complexI; if (curr_mol_complexSP->catchF == 0) continue; curr_mol_complexSP->stick_radius = value; } /* Refresh the main window: */ (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); /* Refresh the control window: */ ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); /* Return the command code: */ return COMMAND_STICKS; } /*===========================================================================*/ garlic-1.6/create.c0000644000076500007650000001613007474652016014532 0ustar zuciczucic00000000000000/* Copyright (C) 2001, 2002 Damir Zucic */ /*============================================================================= create.c Purpose: Execute create command: create the atomic structure using the sequence from the main sequence buffer and the secondary structure from the main secondary structure buffer. This function does some checks and preparations. The actual creation of the structure is done by the function CreateStructure_ (). This function works only for protein sequences. Input: (1) Pointer to MolComplexS structure. (2) Pointer to the number of macromolecular complexes. (3) Pointer to the next macromolecular complex identifier. (4) Pointer to RuntimeS structure. (5) Pointer to ConfigS structure. (6) Pointer to GUIS structure. (7) Pointer to NearestAtomS structure. (8) The number of pixels in the main window free area. (9) Pointer to refreshI. Output: (1) A new macromolecular complex (structure) created. (2) Return value. Return value: (1) Positive (command) code on success. (2) Negative (error) code on failure. Notes: (1) The template residues, which consist of the template atoms and are used to generate the new structure, should be written to the file called residues.pdb and stored to at least one of the following five directories: (1) The current working directory. (2) Home directory. (3) $HOME/garlic . (4) /usr/local/lib/garlic (recommended location). (5) /usr/lib/garlic . These directories will be searched in the specified order. It is recommended to mantain a single template file in directory /usr/local/lib/garlic . In that case, the users will not need to have their own template files. (2) CREATE is not the only command using the template atoms. The storage for template residues (atoms) is allocated at the beginning of garlic session, in the function InitRuntime_ (). The template file is read in the same function. If the reading fails, the number of template atoms (template_atomsN) will be equal to zero. Do not forget to check this number! (3) This function resets the edit mode index. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "commands.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int CreateStructure_ (MolComplexS *, int *, int *, RuntimeS *, int, ConfigS *, GUIS *); size_t MainRefresh_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); int ControlRefresh_ (MolComplexS *, ConfigS *, GUIS *); /*======execute command create:==============================================*/ int Create_ (MolComplexS *mol_complexSP, int *mol_complexesNP, int *next_mol_complexIDP, RuntimeS *runtimeSP, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int *refreshIP) { int max_length; int residuesN, residueI; int residue_recognizedF; char *curr_residue_nameP; int template_residuesN, template_residueI; ResidueS *template_residueSP; AtomS *first_atomSP; char *curr_template_nameP; char bad_residue_nameA[10]; int n; /* The maximal residue name length: */ max_length = RESNAMESIZE - 1; /* Check the number of residues in the main sequence buffer: */ if (runtimeSP->residuesN == 0) { strcpy (runtimeSP->messageA, "The sequence buffer is empty!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_CREATE; } /* Check the number of codes in the main secondary structure buffer: */ if (runtimeSP->sec_structure_length == 0) { strcpy (runtimeSP->messageA, "The secondary structure buffer is empty!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_CREATE; } /* Prepare the number of residues for the new atomic structure: */ residuesN = runtimeSP->residuesN; if (runtimeSP->sec_structure_length < residuesN) { residuesN = runtimeSP->sec_structure_length; } /* Copy the number of template residues: */ template_residuesN = runtimeSP->template_residuesN; /* Check the sequence: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Prepare the pointer to the current residue name: */ curr_residue_nameP = runtimeSP->sequenceP + residueI * max_length; /* If the current residue is recognized, this flag will be set to */ /* one; if recognition failes, the value will remain unchanged: */ residue_recognizedF = 0; /* Scan the list of template residues: */ for (template_residueI = 0; template_residueI < template_residuesN; template_residueI++) { /* Pointer to the current template residue: */ template_residueSP = runtimeSP->template_residueSP + template_residueI; /* Pointer to the first atom of */ /* the current template residue: */ first_atomSP = runtimeSP->template_atomSP + template_residueSP->residue_startI; /* Pointer to the current template residue name: */ curr_template_nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Compare the current residue name */ /* with the template residue name: */ if (strncmp (curr_residue_nameP, curr_template_nameP, max_length) == 0) { residue_recognizedF = 1; break; } } /* If residue recognition failed, the */ /* atomic structure cannot be created: */ if (!residue_recognizedF) { strncpy (bad_residue_nameA, curr_residue_nameP, 3); bad_residue_nameA[3] = '\0'; sprintf (runtimeSP->messageA, "Residue not recognized: %s", bad_residue_nameA); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_CREATE; } } /* Check is there any space left in the array of MolComplexS structures: */ if (*mol_complexesNP >= MAXCOMPLEXES) { strcpy (runtimeSP->messageA, "Too many structures in use!\n"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_CREATE; } /* Create the macromolecular complex: */ n = CreateStructure_ (mol_complexSP, mol_complexesNP, next_mol_complexIDP, runtimeSP, residuesN, configSP, guiSP); if (n < 0) { sprintf (runtimeSP->messageA, "Unable to create structure! Error code: %d!", n); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_CREATE; } /* The new complex will be a new default caught complex: */ if (*mol_complexesNP > 0) { runtimeSP->default_complexI = *mol_complexesNP - 1; } /* Reset the editing mode index: */ runtimeSP->edit_modeI = 0; /* Reset the edit_single_bondF flag: */ runtimeSP->edit_single_bondF = 0; /* Reset the main window mode index: */ guiSP->main_window_modeI = 0; /* Refresh the main window: */ (*refreshIP)++; MainRefresh_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); /* Refresh the control window: */ ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); /* Return the command code: */ return COMMAND_CREATE; } /*===========================================================================*/ garlic-1.6/alpha_membrane_center.c0000644000076500007650000002253207631102443017552 0ustar zuciczucic00000000000000/* Copyright (C) 2001-2003 Damir Zucic */ /*============================================================================= alpha_membrane_center.c Purpose: Refine the position of the membrane center. This version is suitable for helix bundle proteins. Input: (1) Pointer to MolComplexS structure, with the chosen structure. (2) Pointer to VectorS structure, with the vector which is perpend. to the membrane. Output: (1) The position of the membrane center will be updated on success. (2) Return value. Return value: (1) Positive on success. (2) Negative on failure. Notes: (1) The method used here is described in alpha_membrane.c. Read the Note 1 and pay a special attention to the second step. (2) On every failure, remember to free the allocated storage before returning to the caller. (3) The CA is used as the representative atom because there are some structures which contain only CA atoms. (4) Use calloc to initialize all array elements with zero values. (5) The cell width should be similar to the covalent bond length. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ double AbsoluteValue_ (VectorS *); int ExtractCA_ (VectorS *, AtomS *, size_t, size_t); double ScalarProduct_ (VectorS *, VectorS *); /*======refine the membrane center (helix bundle version):===================*/ int AlphaMembraneCenter_ (MolComplexS *mol_complexSP, VectorS *normal_vectorSP) { int residuesN, residueI; size_t double_size, int_size; int cellsN = 10000; static double *hydrophobicityP; static int *projectionsNP; static int *cells_usedNP; double abs_value, reciprocal_denominator; VectorS unit_vectorS; VectorS center_vectorS; int centralI; double cell_width = 1.0, half_cell_width; double reciprocal_cell_width; ResidueS *curr_residueSP; int first_atomI, last_atomI; int n; AtomS *first_atomSP; double hydrophobicity; VectorS CA_vectorS; VectorS radius_vectorS; double projection; int cellI; int used_cellsN; double average; int first_cellI, last_cellI; int half_window_width, windowI, combinedI; double max_average; int peak_cellI; double shift; /* Copy the number of residues: */ residuesN = mol_complexSP->residuesN; /* Double and int size: */ double_size = sizeof (double); int_size = sizeof (int); /* Allocate memory for the array of hydrophobicity values: */ hydrophobicityP = (double *) calloc (cellsN, double_size); if (!hydrophobicityP) { return -1; } /* Allocate the memory required to store the number of projections per cell: */ projectionsNP = (int *) calloc (cellsN, int_size); if (!projectionsNP) { free (hydrophobicityP); return -2; } /* Allocate the memory for the total number of used cells: */ cells_usedNP = (int *) calloc (cellsN, int_size); if (!cells_usedNP) { free (hydrophobicityP); free (projectionsNP); return -3; } /* Prepare the unit vector required to project CA atoms to the axis: */ abs_value = AbsoluteValue_ (normal_vectorSP); if (abs_value == 0.0) { free (hydrophobicityP); free (projectionsNP); free (cells_usedNP); return -4; } reciprocal_denominator = 1.0 / abs_value; unit_vectorS.x = reciprocal_denominator * normal_vectorSP->x; unit_vectorS.y = reciprocal_denominator * normal_vectorSP->y; unit_vectorS.z = reciprocal_denominator * normal_vectorSP->z; /* Prepare the vector which defines the membrane center: */ center_vectorS.x = mol_complexSP->membraneS.center_x; center_vectorS.y = mol_complexSP->membraneS.center_y; center_vectorS.z = mol_complexSP->membraneS.center_z; /* Prepare the central index, half of the */ /* cell width and the reciprocal cell width: */ centralI = cellsN / 2; if (cell_width == 0.0) { free (hydrophobicityP); free (projectionsNP); free (cells_usedNP); return -4; } half_cell_width = 0.5 * cell_width; reciprocal_cell_width = 1.0 / cell_width; /* Now project the hydrophobicities of all residues to the reference axis */ /* defined by the current membrane center and by the normal vector. The */ /* axis is divided into cells. The width of a single cell is cell_width. */ /* Scan all residues and project CA atoms to the reference axis: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Pointer to the current residue: */ curr_residueSP = mol_complexSP->residueSP + residueI; /* Copy the indices of the first and of the last atom: */ first_atomI = curr_residueSP->residue_startI; last_atomI = curr_residueSP->residue_endI; /* Extract the position of CA atom. */ n = ExtractCA_ (&CA_vectorS, mol_complexSP->atomSP, first_atomI, last_atomI); if (n != 1) continue; /* Copy the hydrophobicity associated with this residue: */ first_atomSP = (mol_complexSP->atomSP + first_atomI); hydrophobicity = first_atomSP->raw_atomS.hydrophobicity; /* Prepare the vector from the membrane center to the CA atom: */ radius_vectorS.x = CA_vectorS.x - center_vectorS.x; radius_vectorS.y = CA_vectorS.y - center_vectorS.y; radius_vectorS.z = CA_vectorS.z - center_vectorS.z; /* Project this vector: */ projection = ScalarProduct_ (&radius_vectorS, &unit_vectorS); /* Prepare and check the cell index: */ cellI = centralI + reciprocal_cell_width * (projection - half_cell_width); if (cellI < 0) continue; if (cellI >= cellsN) continue; /* Update the total hydrophobicity stored */ /* to the cell with the given cell index. */ /* Update the number of CA atoms projected to the given cell: */ (*(projectionsNP + cellI))++; /* Update the total hydrophobicity: */ *(hydrophobicityP + cellI) += hydrophobicity; } /* Find the range of cells which covers the entire macromolecular complex. */ /* Find the first cell which is not empty (search from bottom to top): */ first_cellI = 0; for (cellI = 0; cellI < cellsN; cellI++) { if (*(projectionsNP + cellI) != 0) { first_cellI = cellI; break; } } /* Find the last cell which is not empty (search from top to bottom): */ last_cellI = cellsN - 1; for (cellI = cellsN - 1; cellI >= 0; cellI--) { if (*(projectionsNP + cellI) != 0) { last_cellI = cellI; break; } } /* Prepare the sliding window which is required for the averaging of */ /* total hydrophobicities. In this step the total hydrophobicities will */ /* be averaged over the specified number of adjacent cells. The width */ /* of the sliding window should be slightly larger than the membrane */ /* thickness. The minimal half-width is 1 and the min. full width is 3. */ half_window_width = (int) (mol_complexSP->membraneS.thickness / cell_width); half_window_width /= 2; half_window_width += 1; /* Average the total hydrophobicities over */ /* the specified number of adjacent cells: */ for (cellI = first_cellI; cellI <= last_cellI; cellI++) { /* Reset the number of cells in a window and the average value: */ used_cellsN = 0; average = 0.0; /* Scan the sliding window: */ for (windowI = -half_window_width; windowI <= half_window_width; windowI++) { /* Prepare and check the combined index: */ combinedI = cellI + windowI; if (combinedI < 0) continue; else if (combinedI >= cellsN) continue; /* Skip empty cells: */ if (*(projectionsNP + combinedI) == 0) continue; /* Update the number of used cells and */ /* the sum of total hydrophobicities: */ used_cellsN++; average += *(hydrophobicityP + combinedI); } /* Calculate the average value and store it. In addition, store the */ /* number of cells which were used to calculate the average value. */ if (used_cellsN != 0) { *(hydrophobicityP + cellI) = average / (double) used_cellsN; *(cells_usedNP + cellI) = used_cellsN; } } /* After averaging the total projected hydrophobicities, find the */ /* index of the cell with the highest peak. In this loop, use only */ /* the average values which were calculated from a significant */ /* number of cells (at least half of the entire sliding window). */ /* Be sure to skip the cells close to the edge of the structure. */ max_average = -999999.0; peak_cellI = -1; for (cellI = first_cellI + half_window_width; cellI <= last_cellI - half_window_width; cellI++) { /* Skip the cells for which the average value */ /* was calculated from a small number of cells: */ if (*(cells_usedNP + cellI) < half_window_width) continue; /* Copy the average value stored to the current cell: */ average = *(hydrophobicityP + cellI); /* Check is this value the maximum: */ if (average > max_average) { peak_cellI = cellI; max_average = average; } } /* Check the index of the cell with the highest peak: */ if (peak_cellI == -1) { free (hydrophobicityP); free (projectionsNP); free (cells_usedNP); return -5; } /* Calculate the shift along the axis defined by the normal vector: */ shift = (double) (peak_cellI - centralI) * cell_width; /* Calculate the new position of the membrane center: */ mol_complexSP->membraneS.center_x += shift * unit_vectorS.x; mol_complexSP->membraneS.center_y += shift * unit_vectorS.y; mol_complexSP->membraneS.center_z += shift * unit_vectorS.z; /* Free storage: */ free (hydrophobicityP); free (projectionsNP); free (cells_usedNP); /* Return positive value on success: */ return 1; } /*===========================================================================*/ garlic-1.6/ex_trans_steps.c0000644000076500007650000000317207612772302016325 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2003 Damir Zucic */ /*============================================================================= ex_trans_steps.c Purpose: Extract translation steps (five doubles) from a string. Input: (1) Pointer to ConfigS structure, where values will be stored. (2) Input string pointer. Output: Return value. Return value: (1) Positive on success. (2) Negative on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======extract translation steps from a string:=============================*/ int ExtractTranslationSteps_ (ConfigS *configSP, char *sP) { char *P0, *P1; int n; double d1, d2, d3, d4, d5; /* Colon should be separator: */ if ((P0 = strstr (sP, ":")) == NULL) P0 = sP; /* Replace each non-numeric character (except */ /* minus sign and decimal point) with space: */ P1 = P0; while ((n = *P1++) != '\0') { if (!isdigit (n) && (n != '-') && (n != '.')) *(P1 - 1) = ' '; } /* Try to read five doubles: */ if (sscanf (P0, "%lf %lf %lf %lf %lf", &d1, &d2, &d3, &d4, &d5) != 5) { return -1; } /* Copy translation steps to ConfigS: */ configSP->translation_stepA[0] = d1; configSP->translation_stepA[1] = d2; configSP->translation_stepA[2] = d3; configSP->translation_stepA[3] = d4; configSP->translation_stepA[4] = d5; /* If everything worked fine, return positive number: */ return 1; } /*===========================================================================*/ garlic-1.6/gallery.script0000644000076500007650000000213307643247615016011 0ustar zuciczucic00000000000000# Gallery of membrane proteins. load 1prc.pdb bac 2 pos 0 0 500 pause dis all load 1kme.pdb bac 2 pos 0 0 500 pause dis all load 1kzu.pdb bac 2 pos 0 0 500 pause dis all load 1occ.pdb bac 2 pos 0 0 500 pause dis all load 1qrc.pdb bac 2 pos 0 0 500 pause dis all load 1fum.pdb bac 2 pos 0 0 500 pause dis all load 1bl8.pdb bac 2 pos 0 0 500 pause dis all load 1msl.pdb bac 2 pos 0 0 500 pause dis all load 1mxm.pdb bac 2 pos 0 0 500 pause dis all load 1f88.pdb bac 2 pos 0 0 500 pause dis all load 1eul.pdb bac 2 pos 0 0 500 pause dis all load 1fqy.pdb bac 2 pos 0 0 500 pause dis all load 1kpk.pdb bac 2 pos 0 0 500 pause dis all load 1kqf.pdb bac 2 pos 0 0 500 pause dis all load 1l7v.pdb bac 2 pos 0 0 500 pause dis all load 1iwg.pdb bac 2 pos 0 0 500 pause dis all load 1bxw.pdb bac 2 pos 0 0 500 pause dis all load 1i78.pdb bac 2 pos 0 0 500 pause dis all load 1qd5.pdb bac 2 pos 0 0 500 pause dis all load 7ahl.pdb bac 2 pos 0 0 500 pause dis all load 2por.pdb bac 2 pos 0 0 500 pause dis all load 1mal.pdb bac 2 pos 0 0 500 pause dis all load 1fcp.pdb bac 2 pos 0 0 500 pause dis all garlic-1.6/is_standard.c0000644000076500007650000000315307320024263015546 0ustar zuciczucic00000000000000/* Copyright (C) 2001 Damir Zucic */ /*============================================================================= is_standard.c Purpose: If the specified residue belongs to the set of 20 standard residues, return positive value or zero. Otherwise, return negative value. This function contains the list of standard residue names. If the specified residue name matches one of the names from the list, this function will return the array index. Input: (1) Residue name. Output: (1) Return value. Return value: (1) Positive or zero, if residue name was found in the list. (2) Negative otherwise. ========includes:============================================================*/ #include #include /*======check residue name:==================================================*/ int IsStandard_ (char *residue_nameP) { int nameI; static char residue_nameAA[20][4] = {"ALA", "ARG", "ASN", "ASP", "CYS", /* 0 1 2 3 4 */ "GLN", "GLU", "GLY", "HIS", "ILE", /* 5 6 7 8 9 */ "LEU", "LYS", "MET", "PHE", "PRO", /* 10 11 12 13 14 */ "SER", "THR", "TRP", "TYR", "VAL"}; /* 15 16 17 18 19 */ /* Scan the list of standard residue names: */ for (nameI = 0; nameI < 20; nameI++) { if (strcmp (residue_nameP, residue_nameAA[nameI]) == 0) return nameI; } /* If this point is reached, residue name was */ /* not found in the list of 20 standard names: */ return -1; } /*===========================================================================*/ garlic-1.6/interface.scale0000644000076500007650000000056207775121556016102 0ustar zuciczucic00000000000000# Stephen White (et al.) interface hydrophobicity scale (INT). # See http://blanco.biomol.uci.edu/hydrophobicity_scales.html for details. ALA -0.17 ARG -0.81 ASN -0.42 ASP -1.23 CYS -0.24 GLN -0.58 GLU -2.02 GLY -0.01 HIS -0.17 ILE 0.31 LEU 0.56 LYS -0.99 MET 0.23 PHE 1.13 PRO -0.45 SER -0.13 THR -0.14 TRP 1.85 TYR 0.94 VAL -0.07 ASX -0.83 GLX -1.30 UNK -0.12 garlic-1.6/replace_command.c0000644000076500007650000000624407307133272016376 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= replace_command.c Purpose: Replace the current command with the one from the history buffer. If there is nothing in the history buffer, return negative value. The history buffer is empty if the highest_commandI is equal to minus one. Input: (1) Pointer to RuntimeS structure. (2) The relative index (index difference). (3) Pointer to GUIS structure. Output: (1) The current command may be replaced with the old one. (2) Return value. Return value: (1) Positive on success. (2) Negative on failure. Notes: (1) After the highest index value is reached, the current command will be replaced by the first one. After the lowest index is reached (zero), the current command will be replaced by the the command which is specified by the highest_commandI index. The current command string is replaced immediately after the arrow key "Up" or "Down" is pressed. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======replace command:=====================================================*/ int ReplaceCommand_ (RuntimeS *runtimeSP, int deltaI, GUIS *guiSP) { char *oldP, *newP; int text_width, max_width; /* Check is there anything in the history buffer. */ /* The initial value of the highest_commandI is -1. */ if (runtimeSP->highest_commandI < 0) return -1; /* If this point is reached, there is at */ /* least one command in the history buffer. */ /* Prepare and check the index of the old (previously used) command: */ runtimeSP->old_commandI += deltaI; if (runtimeSP->old_commandI < 0) /* Read note 2! */ runtimeSP->old_commandI = runtimeSP->highest_commandI; if (runtimeSP->old_commandI > runtimeSP->highest_commandI) runtimeSP->old_commandI = 0; /* Copy the old command: */ oldP = runtimeSP->commandsP + runtimeSP->old_commandI * COMMSTRINGSIZE; strncpy (runtimeSP->curr_commandA, oldP, COMMSTRINGSIZE - 1); runtimeSP->curr_commandA[COMMSTRINGSIZE - 1] = '\0'; newP = runtimeSP->commandsP + runtimeSP->next_commandI * COMMSTRINGSIZE; strncpy (newP, oldP, COMMSTRINGSIZE - 1); *(newP + COMMSTRINGSIZE - 1) = '\0'; /* Update the current command length and carriage position: */ runtimeSP->command_length = strlen (runtimeSP->curr_commandA); runtimeSP->carriage_position = runtimeSP->command_length; /* Prepare, check and store the width (in pixels) of the command string: */ /** Prepare the width: **/ text_width = XTextWidth (guiSP->main_winS.fontSP, runtimeSP->curr_commandA, runtimeSP->carriage_position); /** Check is it larger than output window: **/ max_width = (int) guiSP->input_winS.width - 3; if (text_width > max_width) { text_width = 0; runtimeSP->carriage_position = 0; text_width = 0; } /** Store the width: **/ runtimeSP->left_part_widthA[runtimeSP->carriage_position] = text_width; /* Return positive value: */ return 1; } /*===========================================================================*/ garlic-1.6/draw_venn.c0000644000076500007650000007134210114572045015244 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2004 Damir Zucic */ /*============================================================================= draw_venn.c Purpose: Draw Venn diagram. This function is used if the main win. drawing mode is equal to three. The sequence stored to the sequence buffer is used to prepare the Venn diagram. Input: (1) Pointer to RuntimeS structure, with some runtime data. (2) Pointer to GUIS structure, with GUI data. (3) Pointer to NearestAtomS structure, with information about the atom occupying the given pixel. (4) The number of pixels in the main window free area. (5) The refreshI, used to check the NearestAtomS associated with a given pixel. It is currently unused in this function. Output: (1) Venn diagram drawn to the main window. (2) Return value. Return value: (1) The number of residues used to prepare the Venn diagram. Notes: (1) The initial drawing destination is the hidden pixmap, and the content of this pixmap is copied later to the main window. (2) Cysteine is treated in a special way: cysteine which is not involved in a disulfide bond should be treated as polar, while cysteine which takes part in disulfide bond formation is not polar. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int RefreshPixmap_ (Display *, Pixmap, GC, unsigned int, unsigned int, unsigned long); /*======draw Venn diagram:===================================================*/ size_t DrawVenn_ (RuntimeS *runtimeSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int refreshI) { int max_length; size_t residuesN, residueI; char *residue_nameP; char residue_nameA[RESNAMESIZE]; int range_startI, range_endI, residues_in_vennN = 0; size_t vennI = 0; int alaN = 0, argN = 0, asnN = 0, aspN = 0, cysN = 0; int glnN = 0, gluN = 0, glyN = 0, hisN = 0, ileN = 0; int leuN = 0, lysN = 0, metN = 0, pheN = 0, proN = 0; int serN = 0, thrN = 0, trpN = 0, tyrN = 0, valN = 0; int unkN = 0; int S_S_cysN = 0, S_H_cysN = 0; int hydrophobicN, polarN, smallN; int aromaticN, aliphaticN, tinyN, chargedN; int positiveN, negativeN; int screen_margin_x, screen_margin_y; int screen_delta_x, screen_delta_y; int screen_x0, screen_y0, screen_x; unsigned int screen_width, screen_height; double d; int text_width, text_height; char stringA[SHORTSTRINGSIZE]; /* The number of residues in sequence buffer: */ residuesN = runtimeSP->residuesN; if (residuesN == 0) { strcpy (runtimeSP->messageA, "The sequence buffer is empty!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return 0; } /* The maximal residue name length: */ max_length = RESNAMESIZE - 1; /* Residue array index range: */ range_startI = runtimeSP->range_startI; range_endI = runtimeSP->range_endI; /* Count the number of residues in the specified range: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Check is the residue array index inside the range: */ if (((int) residueI < range_startI) || ((int) residueI > range_endI)) { continue; } /* Increase the count of residues if current */ /* residue belongs to the specified range: */ residues_in_vennN++; } /* Check the number of residues in Venn diagram: */ if (residues_in_vennN == 0) { strcpy (runtimeSP->messageA, "The specified range is empty!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return 0; } /* Refresh the hidden pixmap, where drawing will be done: */ RefreshPixmap_ (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], guiSP->control_winS.x0, guiSP->input_winS.y0, guiSP->main_winS.bg_colorID); /*------auxilliary parameters:-----------------------------------------------*/ /* Text line height: */ text_height = guiSP->main_winS.font_height; /* Prepare margins and useful area width and height: */ screen_margin_x = guiSP->main_win_free_area_width / 20; if (screen_margin_x < 2) screen_margin_x = 2; screen_margin_y = guiSP->main_win_free_area_height / 20; if (screen_margin_y < 2) screen_margin_y = 2; screen_delta_x = guiSP->main_win_free_area_width - 2 * screen_margin_x; if (screen_delta_x < 0) screen_delta_x = 0; screen_delta_y = guiSP->main_win_free_area_height - 2 * screen_margin_y; if (screen_delta_y < 0) screen_delta_y = 0; /*------scan the sequence and count residues by type:------------------------*/ /* Count residues by type: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Check is the residue array index inside the range: */ if (((int) residueI < range_startI) || ((int) residueI > range_endI)) { continue; } /* Pointer to the current residue name: */ residue_nameP = runtimeSP->sequenceP + residueI * max_length; /* Copy the residue name: */ strncpy (residue_nameA, residue_nameP, max_length); residue_nameA[max_length] = '\0'; /* Check the residue name: */ if (strcmp (residue_nameA, "ALA") == 0) alaN++; else if (strcmp (residue_nameA, "ARG") == 0) argN++; else if (strcmp (residue_nameA, "ASN") == 0) asnN++; else if (strcmp (residue_nameA, "ASP") == 0) aspN++; else if (strcmp (residue_nameA, "CYS") == 0) { /* Update the total number of cysteines: */ cysN++; /* Check disulfide flag: */ if (*(runtimeSP->disulfideFP + residueI)) S_S_cysN++; else S_H_cysN++; } else if (strcmp (residue_nameA, "GLN") == 0) glnN++; else if (strcmp (residue_nameA, "GLU") == 0) gluN++; else if (strcmp (residue_nameA, "GLY") == 0) glyN++; else if (strcmp (residue_nameA, "HIS") == 0) hisN++; else if (strcmp (residue_nameA, "ILE") == 0) ileN++; else if (strcmp (residue_nameA, "LEU") == 0) leuN++; else if (strcmp (residue_nameA, "LYS") == 0) lysN++; else if (strcmp (residue_nameA, "MET") == 0) metN++; else if (strcmp (residue_nameA, "PHE") == 0) pheN++; else if (strcmp (residue_nameA, "PRO") == 0) proN++; else if (strcmp (residue_nameA, "SER") == 0) serN++; else if (strcmp (residue_nameA, "THR") == 0) thrN++; else if (strcmp (residue_nameA, "TRP") == 0) trpN++; else if (strcmp (residue_nameA, "TYR") == 0) tyrN++; else if (strcmp (residue_nameA, "VAL") == 0) valN++; else unkN++; /* Update the Venn diagram index: */ vennI++; } /* Prepare the combined counts: */ hydrophobicN = pheN + tyrN + trpN + hisN + metN + ileN + leuN + valN + alaN + glyN + cysN; polarN = tyrN + trpN + hisN + lysN + argN + gluN + glnN + aspN + asnN + thrN + serN + S_H_cysN; smallN = glyN + alaN + serN + proN + valN + thrN + aspN + asnN + cysN; chargedN = argN + lysN + hisN + gluN + aspN; aromaticN = trpN + tyrN + pheN + hisN; aliphaticN = valN + leuN + ileN; tinyN = glyN + alaN + serN + S_H_cysN; positiveN = argN + lysN + hisN; negativeN = gluN + aspN; /*------draw polar, hydrophobic and small rectangle:-------------------------*/ /* Polar rectangle: */ screen_x0 = screen_margin_x; d = 0.075 * (double) screen_delta_y; screen_y0 = screen_margin_y + (unsigned int) d; d = 0.666 * (double) screen_delta_x; if (d < 1.0) d = 1.0; screen_width = (unsigned int) d; d = 0.765 * (double) screen_delta_y; if (d < 1.0) d = 1.0; screen_height = (unsigned int) d; XSetForeground (guiSP->displaySP, guiSP->theGCA[0], guiSP->blue_colorID); XDrawRectangle (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0, screen_y0, screen_width, screen_height); XDrawRectangle (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0 - 1, screen_y0 - 1, screen_width + 2, screen_height + 2); XDrawRectangle (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0 - 2, screen_y0 - 2, screen_width + 4, screen_height + 4); XDrawRectangle (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0 - 3, screen_y0 - 3, screen_width + 6, screen_height + 6); /* Hydrophobic rectangle: */ d = 0.333 * (double) screen_delta_x; screen_x0 = screen_margin_x + (unsigned int) d; screen_y0 = screen_margin_y; d = 0.666 * (double) screen_delta_x; if (d < 1.0) d = 1.0; screen_width = (unsigned int) d; d = 0.824 * (double) screen_delta_y; if (d < 1.0) d = 1.0; screen_height = (unsigned int) d; XSetForeground (guiSP->displaySP, guiSP->theGCA[1], guiSP->red_colorID); XDrawRectangle (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], screen_x0, screen_y0, screen_width, screen_height); XDrawRectangle (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], screen_x0 - 1, screen_y0 - 1, screen_width + 2, screen_height + 2); XDrawRectangle (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], screen_x0 - 2, screen_y0 - 2, screen_width + 4, screen_height + 4); XDrawRectangle (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], screen_x0 - 3, screen_y0 - 3, screen_width + 6, screen_height + 6); /* Small rectangle (small refers to small residues, not to the rectangle): */ d = 0.012 * (double) screen_delta_x; screen_x0 = screen_margin_x + (unsigned int) d; d = 0.534 * (double) screen_delta_y; screen_y0 = screen_margin_y + (unsigned int) d; d = 0.967 * (double) screen_delta_x; if (d < 1.0) d = 1.0; screen_width = (unsigned int) d; d = 0.470 * (double) screen_delta_y; if (d < 1.0) d = 1.0; screen_height = (unsigned int) d; XSetForeground (guiSP->displaySP, guiSP->theGCA[2], guiSP->green_colorID); XDrawRectangle (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], screen_x0, screen_y0, screen_width, screen_height); XDrawRectangle (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], screen_x0 - 1, screen_y0 - 1, screen_width + 2, screen_height + 2); XDrawRectangle (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], screen_x0 - 2, screen_y0 - 2, screen_width + 4, screen_height + 4); XDrawRectangle (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], screen_x0 - 3, screen_y0 - 3, screen_width + 6, screen_height + 6); /*------draw charged, aromatic, aliphatic and tiny rectangle:----------------*/ /* Charged rectangle: */ d = 0.023 * (double) screen_delta_x; screen_x0 = screen_margin_x + (unsigned int) d; d = 0.200 * (double) screen_delta_y; screen_y0 = screen_margin_y + (unsigned int) d; d = 0.635 * (double) screen_delta_x; if (d < 1.0) d = 1.0; screen_width = (unsigned int) d; d = 0.430 * (double) screen_delta_y; if (d < 1.0) d = 1.0; screen_height = (unsigned int) d; XSetForeground (guiSP->displaySP, guiSP->theGCA[0], guiSP->blue_colorID); XDrawRectangle (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0, screen_y0, screen_width, screen_height); XDrawRectangle (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0 - 1, screen_y0 - 1, screen_width + 2, screen_height + 2); XDrawRectangle (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0 - 2, screen_y0 - 2, screen_width + 4, screen_height + 4); /* Aromatic rectangle: */ d = 0.342 * (double) screen_delta_x; screen_x0 = screen_margin_x + (unsigned int) d; d = 0.088 * (double) screen_delta_y; screen_y0 = screen_margin_y + (unsigned int) d; d = 0.648 * (double) screen_delta_x; if (d < 1.0) d = 1.0; screen_width = (unsigned int) d; d = 0.255 * (double) screen_delta_y; if (d < 1.0) d = 1.0; screen_height = (unsigned int) d; XSetForeground (guiSP->displaySP, guiSP->theGCA[1], guiSP->red_colorID); XDrawRectangle (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], screen_x0, screen_y0, screen_width, screen_height); XDrawRectangle (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], screen_x0 - 1, screen_y0 - 1, screen_width + 2, screen_height + 2); XDrawRectangle (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], screen_x0 - 2, screen_y0 - 2, screen_width + 4, screen_height + 4); /* Aliphatic rectangle: */ d = 0.679 * (double) screen_delta_x; screen_x0 = screen_margin_x + (unsigned int) d; d = 0.372 * (double) screen_delta_y; screen_y0 = screen_margin_y + (unsigned int) d; d = 0.311 * (double) screen_delta_x; if (d < 1.0) d = 1.0; screen_width = (unsigned int) d; d = 0.257 * (double) screen_delta_y; if (d < 1.0) d = 1.0; screen_height = (unsigned int) d; XSetForeground (guiSP->displaySP, guiSP->theGCA[1], guiSP->red_colorID); XDrawRectangle (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], screen_x0, screen_y0, screen_width, screen_height); XDrawRectangle (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], screen_x0 - 1, screen_y0 - 1, screen_width + 2, screen_height + 2); XDrawRectangle (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[1], screen_x0 - 2, screen_y0 - 2, screen_width + 4, screen_height + 4); /* Tiny rectangle: */ d = 0.023 * (double) screen_delta_x; screen_x0 = screen_margin_x + (unsigned int) d; d = 0.730 * (double) screen_delta_y; screen_y0 = screen_margin_y + (unsigned int) d; d = 0.948 * (double) screen_delta_x; if (d < 1.0) d = 1.0; screen_width = (unsigned int) d; d = 0.190 * (double) screen_delta_y; if (d < 1.0) d = 1.0; screen_height = (unsigned int) d; XSetForeground (guiSP->displaySP, guiSP->theGCA[2], guiSP->green_colorID); XDrawRectangle (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], screen_x0, screen_y0, screen_width, screen_height); XDrawRectangle (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], screen_x0 - 1, screen_y0 - 1, screen_width + 2, screen_height + 2); XDrawRectangle (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[2], screen_x0 - 2, screen_y0 - 2, screen_width + 4, screen_height + 4); /*------positive and negative rectangle:-------------------------------------*/ /* Positive rectangle: */ d = 0.030 * (double) screen_delta_x; screen_x0 = screen_margin_x + (unsigned int) d; d = 0.270 * (double) screen_delta_y; screen_y0 = screen_margin_y + (unsigned int) d; d = 0.618 * (double) screen_delta_x; if (d < 1.0) d = 1.0; screen_width = (unsigned int) d; d = 0.150 * (double) screen_delta_y; if (d < 1.0) d = 1.0; screen_height = (unsigned int) d; XSetForeground (guiSP->displaySP, guiSP->theGCA[0], guiSP->blue_colorID); XDrawRectangle (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0, screen_y0, screen_width, screen_height); XDrawRectangle (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0 - 1, screen_y0 - 1, screen_width + 2, screen_height + 2); /* Negative rectangle: */ d = 0.030 * (double) screen_delta_x; screen_x0 = screen_margin_x + (unsigned int) d; d = 0.430 * (double) screen_delta_y; screen_y0 = screen_margin_y + (unsigned int) d; d = 0.292 * (double) screen_delta_x; if (d < 1.0) d = 1.0; screen_width = (unsigned int) d; d = 0.190 * (double) screen_delta_y; if (d < 1.0) d = 1.0; screen_height = (unsigned int) d; XSetForeground (guiSP->displaySP, guiSP->theGCA[0], guiSP->blue_colorID); XDrawRectangle (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0, screen_y0, screen_width, screen_height); XDrawRectangle (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0 - 1, screen_y0 - 1, screen_width + 2, screen_height + 2); /*------draw text:-----------------------------------------------------------*/ XSetForeground (guiSP->displaySP, guiSP->theGCA[0], guiSP->main_winS.fg_colorID); /* TOTAL NUMBER OF RESIDUES: */ screen_x0 = screen_margin_x; screen_y0 = screen_margin_y + text_height - 1; sprintf (stringA, "TOTAL: %d", residuesN); XDrawString (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, strlen (stringA)); /* POLAR: */ screen_x0 = screen_margin_x + 5; d = 0.075 * (double) screen_delta_y; screen_y0 = screen_margin_y + (int) d + text_height - 1; sprintf (stringA, "POLAR: %d", polarN); XDrawString (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, strlen (stringA)); /* HYDROPHOBIC: */ d = 0.333 * (double) screen_delta_x; screen_x0 = screen_margin_x + (int) d + 5; screen_y0 = screen_margin_y + text_height - 1; sprintf (stringA, "HYDROPHOBIC: %d", hydrophobicN); XDrawString (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, strlen (stringA)); /* SMALL: */ d = 0.012 * (double) screen_delta_x; screen_x0 = screen_margin_x + (int) d + 5; d = 0.985 * (double) screen_delta_y; screen_y0 = screen_margin_y + (int) d + guiSP->main_winS.fontSP->descent + 1; sprintf (stringA, "SMALL: %d", smallN); XDrawString (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, strlen (stringA)); /* CHARGED: */ d = 0.023 * (double) screen_delta_x; screen_x0 = screen_margin_x + (int) d + 5; d = 0.200 * (double) screen_delta_y + text_height; screen_y0 = screen_margin_y + (int) d - 1; sprintf (stringA, "CHARGED: %d", chargedN); XDrawString (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, strlen (stringA)); /* AROMATIC: */ d = 0.670 * (double) screen_delta_x; screen_x0 = screen_margin_x + (int) d + 5; d = 0.088 * (double) screen_delta_y; screen_y0 = screen_margin_y + (int) d + text_height - 1; sprintf (stringA, "AROMATIC: %d", aromaticN); XDrawString (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, strlen (stringA)); /* ALIPHATIC: */ d = 0.679 * (double) screen_delta_x; screen_x0 = screen_margin_x + (int) d + 5; d = 0.372 * (double) screen_delta_y; screen_y0 = screen_margin_y + (int) d + text_height - 1; sprintf (stringA, "ALIPHATIC: %d", aliphaticN); XDrawString (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, strlen (stringA)); /* TINY: */ d = 0.023 * (double) screen_delta_x; screen_x0 = screen_margin_x + (int) d + 5; d = 0.905 * (double) screen_delta_y; screen_y0 = screen_margin_y + (unsigned int) d + guiSP->main_winS.fontSP->descent + 1; sprintf (stringA, "TINY: %d", tinyN); XDrawString (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, strlen (stringA)); /* POSITIVE: */ d = 0.030 * (double) screen_delta_x; screen_x0 = screen_margin_x + (int) d + 5; d = 0.270 * (double) screen_delta_y; screen_y0 = screen_margin_y + (int) d + text_height - 1; sprintf (stringA, "POSITIVE: %d", positiveN); XDrawString (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, strlen (stringA)); /* NEGATIVE: */ d = 0.030 * (double) screen_delta_x; screen_x0 = screen_margin_x + (int) d + 5; d = 0.428 * (double) screen_delta_y; screen_y0 = screen_margin_y + (int) d + text_height - 1; sprintf (stringA, "NEGATIVE: %d", negativeN); XDrawString (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, strlen (stringA)); /* The first five strings will be placed at the same screen_x: */ d = 0.167 * screen_delta_x; screen_x = screen_margin_x + (int) d; /* GLN: */ sprintf (stringA, "GLN: %d", glnN); text_width = XTextWidth (guiSP->main_winS.fontSP, stringA, strlen (stringA)); screen_x0 = screen_x - text_width / 2; d = 0.138 * (double) screen_delta_y; screen_y0 = screen_margin_y + (int) d + text_height / 2; XDrawString (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, strlen (stringA)); /* ARG: */ sprintf (stringA, "ARG: %d", argN); text_width = XTextWidth (guiSP->main_winS.fontSP, stringA, strlen (stringA)); screen_x0 = screen_x - text_width / 2; d = 0.340 * (double) screen_delta_y; screen_y0 = screen_margin_y + (int) d + text_height / 2; XDrawString (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, strlen (stringA)); /* LYS: */ sprintf (stringA, "LYS: %d", lysN); text_width = XTextWidth (guiSP->main_winS.fontSP, stringA, strlen (stringA)); screen_x0 = screen_x - text_width / 2; d = 0.380 * (double) screen_delta_y; screen_y0 = screen_margin_y + (int) d + text_height / 2; XDrawString (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, strlen (stringA)); /* GLU: */ sprintf (stringA, "GLU: %d", gluN); text_width = XTextWidth (guiSP->main_winS.fontSP, stringA, strlen (stringA)); screen_x0 = screen_x - text_width / 2; d = 0.515 * (double) screen_delta_y; screen_y0 = screen_margin_y + (int) d; XDrawString (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, strlen (stringA)); /* ASP: */ sprintf (stringA, "ASP: %d", aspN); text_width = XTextWidth (guiSP->main_winS.fontSP, stringA, strlen (stringA)); screen_x0 = screen_x - text_width / 2; d = 0.570 * (double) screen_delta_y; screen_y0 = screen_margin_y + (int) d + text_height / 2; XDrawString (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, strlen (stringA)); /* SER: */ sprintf (stringA, "SER: %d", serN); text_width = XTextWidth (guiSP->main_winS.fontSP, stringA, strlen (stringA)); screen_x0 = screen_x - text_width / 2; d = 0.780 * screen_delta_y; screen_y0 = screen_margin_y + (int) d + text_height / 2; XDrawString (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, strlen (stringA)); /* The next two strings are not aligned vertically with the previous five: */ /* ASN: */ sprintf (stringA, "ASN: %d", asnN); text_width = XTextWidth (guiSP->main_winS.fontSP, stringA, strlen (stringA)); d = 0.092 * screen_delta_x; screen_x0 = screen_margin_x + (int) d - text_width / 2; d = 0.675 * screen_delta_y; screen_y0 = screen_margin_y + (int) d + text_height / 2; XDrawString (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, strlen (stringA)); /* THR: */ sprintf (stringA, "THR: %d", thrN); text_width = XTextWidth (guiSP->main_winS.fontSP, stringA, strlen (stringA)); d = 0.253 * screen_delta_x; screen_x0 = screen_margin_x + (int) d - text_width / 2; d = 0.675 * screen_delta_y; screen_y0 = screen_margin_y + (int) d + text_height / 2; XDrawString (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, strlen (stringA)); /* The next five strings are placed at the same screen_x: */ d = 0.500 * screen_delta_x; screen_x = screen_margin_x + (int) d; /* HIS: */ sprintf (stringA, "HIS: %d", hisN); text_width = XTextWidth (guiSP->main_winS.fontSP, stringA, strlen (stringA)); screen_x0 = screen_x - text_width / 2; d = 0.307 * (double) screen_delta_y; screen_y0 = screen_margin_y + (int) d + text_height / 2; XDrawString (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, strlen (stringA)); /* CYS (S-S): */ sprintf (stringA, "CYS (S-S): %d", S_S_cysN); text_width = XTextWidth (guiSP->main_winS.fontSP, stringA, strlen (stringA)); screen_x0 = screen_x - text_width / 2; d = 0.675 * screen_delta_y; screen_y0 = screen_margin_y + (int) d + text_height / 2; XDrawString (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, strlen (stringA)); /* CYS (S-H): */ sprintf (stringA, "CYS (S-H): %d", S_H_cysN); text_width = XTextWidth (guiSP->main_winS.fontSP, stringA, strlen (stringA)); screen_x0 = screen_x - text_width / 2; d = 0.780 * screen_delta_y; screen_y0 = screen_margin_y + (int) d + text_height / 2; XDrawString (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, strlen (stringA)); /* PRO: */ sprintf (stringA, "PRO: %d", proN); text_width = XTextWidth (guiSP->main_winS.fontSP, stringA, strlen (stringA)); screen_x0 = screen_x - text_width / 2; d = 0.960 * screen_delta_y; screen_y0 = screen_margin_y + (int) d + text_height / 2; XDrawString (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, strlen (stringA)); /* The next two strings are not aligned vertically with the previous five: */ /* TYR: */ sprintf (stringA, "TYR: %d", tyrN); text_width = XTextWidth (guiSP->main_winS.fontSP, stringA, strlen (stringA)); d = 0.423 * screen_delta_x; screen_x0 = screen_margin_x + (int) d - text_width / 2; d = 0.138 * screen_delta_y; screen_y0 = screen_margin_y + (int) d + text_height / 2; XDrawString (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, strlen (stringA)); /* TRP: */ sprintf (stringA, "TRP: %d", trpN); text_width = XTextWidth (guiSP->main_winS.fontSP, stringA, strlen (stringA)); d = 0.585 * screen_delta_x; screen_x0 = screen_margin_x + (int) d - text_width / 2; d = 0.138 * screen_delta_y; screen_y0 = screen_margin_y + (int) d + text_height / 2; XDrawString (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, strlen (stringA)); /* The next three strings are placed at the same screen_x: */ d = 0.825 * screen_delta_x; screen_x = screen_margin_x + (int) d; /* MET: */ sprintf (stringA, "MET: %d", metN); text_width = XTextWidth (guiSP->main_winS.fontSP, stringA, strlen (stringA)); screen_x0 = screen_x - text_width / 2; d = 0.044 * (double) screen_delta_y; screen_y0 = screen_margin_y + (int) d + text_height / 2; XDrawString (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, strlen (stringA)); /* PHE: */ sprintf (stringA, "PHE: %d", pheN); text_width = XTextWidth (guiSP->main_winS.fontSP, stringA, strlen (stringA)); screen_x0 = screen_x - text_width / 2; d = 0.216 * (double) screen_delta_y; screen_y0 = screen_margin_y + (int) d + text_height / 2; XDrawString (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, strlen (stringA)); /* VAL: */ sprintf (stringA, "VAL: %d", valN); text_width = XTextWidth (guiSP->main_winS.fontSP, stringA, strlen (stringA)); screen_x = screen_x0 - text_width / 2; d = 0.570 * (double) screen_delta_y; screen_y0 = screen_margin_y + (int) d + text_height / 2; XDrawString (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, strlen (stringA)); /* The next four strings are not aligned with the previous three: */ /* LEU: */ sprintf (stringA, "LEU: %d", leuN); text_width = XTextWidth (guiSP->main_winS.fontSP, stringA, strlen (stringA)); d = 0.757 * screen_delta_x; screen_x0 = screen_margin_x + (int) d - text_width / 2; d = 0.470 * screen_delta_y; screen_y0 = screen_margin_y + (int) d; XDrawString (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, strlen (stringA)); /* ILE: */ sprintf (stringA, "ILE: %d", ileN); text_width = XTextWidth (guiSP->main_winS.fontSP, stringA, strlen (stringA)); d = 0.912 * screen_delta_x; screen_x0 = screen_margin_x + (int) d - text_width / 2; d = 0.470 * screen_delta_y; screen_y0 = screen_margin_y + (int) d; XDrawString (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, strlen (stringA)); /* ALA: */ sprintf (stringA, "ALA: %d", alaN); text_width = XTextWidth (guiSP->main_winS.fontSP, stringA, strlen (stringA)); d = 0.745 * screen_delta_x; screen_x0 = screen_margin_x + (int) d - text_width / 2; d = 0.780 * screen_delta_y; screen_y0 = screen_margin_y + (int) d; XDrawString (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, strlen (stringA)); /* GLY: */ sprintf (stringA, "GLY: %d", glyN); text_width = XTextWidth (guiSP->main_winS.fontSP, stringA, strlen (stringA)); d = 0.890 * screen_delta_x; screen_x0 = screen_margin_x + (int) d - text_width / 2; d = 0.780 * screen_delta_y; screen_y0 = screen_margin_y + (int) d; XDrawString (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0, screen_y0, stringA, strlen (stringA)); /*------copy the prepared image to the main window:--------------------------*/ /* Copy hidden pixmap to the main window: */ XCopyArea (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->main_winS.ID, guiSP->theGCA[0], 0, 0, guiSP->main_win_free_area_width, guiSP->main_win_free_area_height, 0, 0); return residuesN; } /*===========================================================================*/ garlic-1.6/alloc_mol_complex.c0000644000076500007650000000301107463606734016755 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2002 Damir Zucic */ /*============================================================================= alloc_mol_complex.c Purpose: Allocate memory for an array of MolComplexS structures. The calloc function is used to zero-initialize all bytes. Input: No arguments. Output: (1) Memory for an array of MolComplexS structures allocated. (2) Return value. Return value: (1) Pointer to allocated memory, on success. (2) NULL on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ void ErrorMessage_ (char *, char *, char *, char *, char *, char *, char *); /*======allocate memory for array of MolComplexS structures:=================*/ MolComplexS *AllocateMolComplexSA_ (size_t max_complexes) { static MolComplexS *mol_complexSP; /* Allocate zero-initialized memory: */ mol_complexSP = (MolComplexS *) calloc (max_complexes, sizeof (MolComplexS)); if (mol_complexSP == NULL) { ErrorMessage_ ("garlic", "AllocateMolComplexSA_", "", "Failed to allocate memory for an array", " of MolComplexS structures!\n", "", ""); } /* Return pointer to allocated memory (equal to NULL on failure): */ return mol_complexSP; } /*===========================================================================*/ garlic-1.6/garlic.xpm0000644000076500007650000000546107303426325015110 0ustar zuciczucic00000000000000/* XPM */ static char *garlic_xpm[] = { /* width height num_colors chars_per_pixel */ "48 48 16 1", /* Colors: */ " c None", ". c #64220E", "+ c #AE5031", "@ c #331922", "# c #C78771", "$ c #AC320D", "% c #AF7A78", "& c #DEA8B6", "* c #A2270E", "= c #E2C4CA", "- c #CCA6A0", "; c #603C3C", "> c #F0C4CA", ", c #FDF5FC", "' c #FFFFFF", ") c #661001", /* Pixels: */ " ", " ", " ", " ", " ", " .+ ", " @+# ", " @+. ", " @$+% ", " @.&.#. @ ", " @#++#. @% ", " @.*+##+* @+= ", " @.+++#@+*.@#= ", " @.-%.+#.+$.#+# ", " %--%%%%%;.+$%+%*.+#+#.+.&= ", " %%----%%%+%%%#%#*$+#+#.+@#= ", " @%---------####&&&&;#+#.+#+= ", " @%%-&--%-#-&&&&&=&==#+%.+#%= ", " +%#==---%--&&===>===&#$%#+%= ", " ;%%-==-----====>>=>===&#++%= ", " ;%--==-%--=>>>>>>>=>&&&=#+& ", " @%%-=>=--%==>,,,,>>>=-===&+ ", " @;%%->>=---=>>,,,,,>==-&==-#+ ", " @;%-=>>--%-=>>,'',>=&&-&&&&-& ", " @;%%=>>=%%-=>,',,>>=&=&--=-&-- ", " @%%-=>>=-%-&>,,,>=>===&------= ", " @;%%=>>-%%-=>,>=-=>>>>==--#--- ", " @;%%-=>>-%%#>>>=-&=>>,,>=&&#%#- ", " @%;;--==#++%=>=%#=>,,,,,>&-#--- ", " @%+;+%+-%+*#--%+%&>,''',,=--#-- ", " @+%+;;++++@++++%#->,'''',--#%#% ", " @+%++**** $*.+;+%#>,''''>=----# ", " @%++*..)**@*$++;+#=>,',,=----% ", " @;+++$)*$.**..+++%&=>>=>=%#--- ", " ;%#&+)+*)*@).;+$+%->==------ ", " @%>=+*$*.))@).;;+%---#%%-&&- ", " %>#$).))).))..;;;+%;%---&- ", " @;.)))).))).)*.@;;++%#%#- ", " @.).)$)@)))*++*.;+%%%%%& ", " &.;.).)*)*$++#-%%%++%#& ", " &%&%*$++#++$;.+%%%%%+ ", " #&#&#&#%#%+%+%% ", " #%+%+%+%%% ", " ", " ", " ", " ", " "}; garlic-1.6/pick_bond.c0000644000076500007650000001666207501462164015223 0ustar zuciczucic00000000000000/* Copyright (C) 2001-2002 Damir Zucic */ /*============================================================================= pick_bond.c Purpose: Pick bond for editing. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. (3) Pointer to RuntimeS structure. (4) Pointer to ConfigS structure, with configuration data. (5) Pointer to GUIS structure, with GUI data. (6) Pointer to NearestAtomS structure. (7) The number of pixels in the main window free area. (8) Pointer to refreshI. (9) Pointer to NearestAtomS structure, which contains data about the choosen pixel in the main window working area. Output: (1) The edit mode index may be changed. Some members of RuntimeS structure may be set. (2) Return value. Return value: (1) Positive on success. (2) Negative on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int IsPartOfRing_ (MolComplexS *, int, size_t, size_t); int InputRefresh_ (GUIS *, RuntimeS *); size_t MainRefresh_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); int ControlRefresh_ (MolComplexS *, ConfigS *, GUIS *); /*======handle ButtonPress events:===========================================*/ int PickBond_ (MolComplexS *mol_complexSP, int mol_complexesN, RuntimeS *runtimeSP, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int *refreshIP, NearestAtomS *curr_pixelSP) { int mol_complexI; MolComplexS *curr_mol_complexSP; size_t atomsN; size_t atom1_arrayI, atom2_arrayI; int bondI; AtomS *atom1SP, *atom2SP; TrueBondS *curr_bondSP; int atom1_serialI, atom2_serialI; int n; char *atom1_pure_nameP, *atom2_pure_nameP; /* Check the main window drawing mode index (it */ /* was checked in the caller, but I am paranoic): */ if (guiSP->main_window_modeI != 0) return -1; /* Copy and check the index of the macromolecular complex: */ mol_complexI = curr_pixelSP->mol_complexI; if ((mol_complexI < 0) || (mol_complexI >= mol_complexesN)) return -2; /* Prepare the pointer to the choosen macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Copy and check the number of atoms in the choosen macromolecular complex: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN <= 0) return -3; /* Copy and check the array index of the first atom: */ atom1_arrayI = curr_pixelSP->atomI; if (atom1_arrayI >= atomsN) return -4; /* Copy and check the bond index: */ bondI = curr_pixelSP->bondI; if ((bondI < 0) || (bondI >= MAXBONDS)) return -5; /* Prepare the pointer to the first atom: */ atom1SP = curr_mol_complexSP->atomSP + atom1_arrayI; /* Prepare the pointer to the choosen bond: */ curr_bondSP = atom1SP->true_bondSA + bondI; /* If this is not a covalent bond, ignore the click: */ if (curr_bondSP->bond_typeI != 1) { strcpy (runtimeSP->messageA, "This is not an ordinary covalent bond!"); runtimeSP->message_length = strlen (runtimeSP->messageA); InputRefresh_ (guiSP, runtimeSP); return -6; } /* The second atom should belong to the same complex: */ if (curr_bondSP->neighbor_mol_complexI != mol_complexI) return -7; /* Copy and check the array index of the second atom: */ atom2_arrayI = curr_bondSP->neighbor_arrayI; if (atom2_arrayI >= atomsN) return -8; /* Prepare the pointer to the second atom: */ atom2SP = curr_mol_complexSP->atomSP + atom2_arrayI; /* Copy and compare the serial numbers of both atoms: */ atom1_serialI = atom1SP->raw_atomS.serialI; atom2_serialI = atom2SP->raw_atomS.serialI; if (atom1_serialI == atom2_serialI) return -9; /* Check is it possible to rotate the specified bond. It */ /* is not possible to edit the bond which is part of a */ /* ring or some other closed structural element. If bond */ /* belongs to a ring the return value will be positive. */ n = IsPartOfRing_ (curr_mol_complexSP, mol_complexI, atom1_arrayI, atom2_arrayI); if (n > 0) { strcpy (runtimeSP->messageA, "This bond belongs to a ring!"); runtimeSP->message_length = strlen (runtimeSP->messageA); InputRefresh_ (guiSP, runtimeSP); return -10; } /* Store the serial numbers and the array indices: */ runtimeSP->atom1_serialI = atom1_serialI; runtimeSP->atom2_serialI = atom2_serialI; runtimeSP->atom1_arrayI = atom1_arrayI; runtimeSP->atom2_arrayI = atom2_arrayI; /* Prepare the purified names for two given atoms: */ atom1SP = curr_mol_complexSP->atomSP + atom1_arrayI; atom2SP = curr_mol_complexSP->atomSP + atom2_arrayI; atom1_pure_nameP = atom1SP->raw_atomS.pure_atom_nameA; atom2_pure_nameP = atom2SP->raw_atomS.pure_atom_nameA; /* If two atoms form the N-CA bond, the current command */ /* is equivalent to EDIT PHI. If they form the CA-C bond, */ /* the command is equivalent to EDIT PSI. If they form */ /* the C-N bond, the command is equivalent to EDIT OMEGA. */ /* The first combination equivalent to EDIT PHI: */ if ((strcmp (atom1_pure_nameP, "N" ) == 0) && (strcmp (atom2_pure_nameP, "CA") == 0)) { runtimeSP->edit_modeI = 2; runtimeSP->edit_single_bondF = 1; } /* The second combination equivalent to EDIT PHI: */ else if ((strcmp (atom1_pure_nameP, "CA") == 0) && (strcmp (atom2_pure_nameP, "N" ) == 0)) { runtimeSP->edit_modeI = 2; runtimeSP->edit_single_bondF = 1; } /* The first combination equivalent to EDIT PSI: */ else if ((strcmp (atom1_pure_nameP, "CA") == 0) && (strcmp (atom2_pure_nameP, "C" ) == 0)) { runtimeSP->edit_modeI = 3; runtimeSP->edit_single_bondF = 1; } /* The second combination equivalent to EDIT PSI: */ else if ((strcmp (atom1_pure_nameP, "C" ) == 0) && (strcmp (atom2_pure_nameP, "CA") == 0)) { runtimeSP->edit_modeI = 3; runtimeSP->edit_single_bondF = 1; } /* The first combination equivalent to EDIT OMEGA: */ else if ((strcmp (atom1_pure_nameP, "C") == 0) && (strcmp (atom2_pure_nameP, "N") == 0)) { runtimeSP->edit_modeI = 4; runtimeSP->edit_single_bondF = 1; } /* The second combination equivalent to EDIT OMEGA: */ else if ((strcmp (atom1_pure_nameP, "N") == 0) && (strcmp (atom2_pure_nameP, "C") == 0)) { runtimeSP->edit_modeI = 4; runtimeSP->edit_single_bondF = 1; /* Swap the array and serial indices. The second array */ /* index will be used in small_omega.c to recognize */ /* the residue to which the nitrogen atom belongs: */ runtimeSP->atom2_arrayI = atom1_arrayI; runtimeSP->atom1_arrayI = atom2_arrayI; runtimeSP->atom1_serialI = atom2_serialI; runtimeSP->atom2_serialI = atom1_serialI; } /* All other combinations are not equivalent to */ /* special cases EDIT PHI, EDIT PSI and EDIT OMEGA: */ else { runtimeSP->edit_modeI = 6; runtimeSP->edit_single_bondF = 1; } /* Refresh the input window: */ strcpy (runtimeSP->messageA, ""); runtimeSP->message_length = strlen (runtimeSP->messageA); InputRefresh_ (guiSP, runtimeSP); /* Refresh the main window: */ (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); /* Refresh the control window: */ ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); /* Return positive value on success: */ return 1; } /*===========================================================================*/ garlic-1.6/atoms.c0000644000076500007650000001137007467660753014424 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2002 Damir Zucic */ /*============================================================================= atoms.c Purpose: Execute atoms command: change the atom drawing style for selected atoms. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) The number of macromolecular complexes. (3) Pointer to RuntimeS structure, with some runtime data. (4) Pointer to ConfigS structure, with configuration data. (5) Pointer to GUIS structure, with GUI data. (6) Pointer to NearestAtomS structure. (7) The number of pixels in the main window free area. (8) Pointer to refreshI. (9) String which contains the atom drawing style name. Output: (1) Drawing style for atoms changed. (2) Return value. Return value: (1) Positive (command) code on success. (2) Negative (error) code on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "commands.h" #include "typedefs.h" /*======function prototypes:=================================================*/ char *ExtractToken_ (char *, int, char *, char *); size_t MainRefresh_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); int ControlRefresh_ (MolComplexS *, ConfigS *, GUIS *); /*======execute atoms command:===============================================*/ int Atoms_ (MolComplexS *mol_complexSP, int mol_complexesN, RuntimeS *runtimeSP, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int *refreshIP, char *stringP) { char *remainderP; char tokenA[SHORTSTRINGSIZE]; int atom_styleI; int mol_complexI; MolComplexS *curr_mol_complexSP; size_t atomsN, atomI; AtomS *curr_atomSP; /* Extract the atom style name: */ remainderP = ExtractToken_ (tokenA, SHORTSTRINGSIZE, stringP, " \t\n"); if (!remainderP) { strcpy (runtimeSP->messageA, "Atom drawing style specification missing!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_NO_ATOM_STYLE; } /* Try to recognize the requested style: */ if (strcmp (tokenA, "0") == 0) atom_styleI = 0; else if (strcmp (tokenA, "1") == 0) atom_styleI = 1; else if (strcmp (tokenA, "2") == 0) atom_styleI = 2; else if (strcmp (tokenA, "3") == 0) atom_styleI = 3; else if (strcmp (tokenA, "4") == 0) atom_styleI = 4; else if (strcmp (tokenA, "5") == 0) atom_styleI = 5; else if (strcmp (tokenA, "6") == 0) atom_styleI = 6; else if (strcmp (tokenA, "7") == 0) atom_styleI = 7; else if (strstr (tokenA, "SPA") == tokenA) atom_styleI = SPACEFILL; else if (strstr (tokenA, "SP2") == tokenA) atom_styleI = SPACEFILL2; else if (strstr (tokenA, "COV") == tokenA) atom_styleI = COVALENT; else if (strstr (tokenA, "CO2") == tokenA) atom_styleI = COVALENT2; else if (strstr (tokenA, "SMA") == tokenA) atom_styleI = SMALL_ATOM; else if (strstr (tokenA, "SM2") == tokenA) atom_styleI = SMALL_ATOM2; else if (strstr (tokenA, "BAL") == tokenA) atom_styleI = BALL; else if (strstr (tokenA, "BA2") == tokenA) atom_styleI = BALL2; else if (strstr (tokenA, "BIG") == tokenA) atom_styleI = BIG_SPHERE; else if (strstr (tokenA, "BI2") == tokenA) atom_styleI = BIG_SPHERE2; else { sprintf (runtimeSP->messageA, "Atom drawing style \"%s\" not available!", tokenA); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_ATOM_STYLE; } /* Scan every macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /** Pointer to the current macromolecular complex: **/ curr_mol_complexSP = mol_complexSP + mol_complexI; /** Check is the current macromolecular complex caught: **/ if (curr_mol_complexSP->catchF == 0) continue; /** Number of atoms in a macromolecular complex: **/ atomsN = curr_mol_complexSP->atomsN; /** Scan all atoms in the current complex: **/ for (atomI = 0; atomI < atomsN; atomI++) { /** Pointer to the current atom: **/ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /** Check is atom selected: **/ if (curr_atomSP->selectedF == 0) continue; /** Change the atom drawing style: **/ curr_atomSP->raw_atomS.atom_styleI = atom_styleI; } /* Reset the position_changedF: */ curr_mol_complexSP->position_changedF = 1; } /* Refresh the main window: */ (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); /* Refresh the control window: */ ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); /* Return positive value on success: */ return COMMAND_ATOMS; } /*===========================================================================*/ garlic-1.6/inform_user.c0000644000076500007650000000356707520464403015622 0ustar zuciczucic00000000000000/* Copyright (C) 2001-2002 Damir Zucic */ /*============================================================================= inform_user.c Purpose: Write some message to the main window. Input: (1) Pointer to GUIS structure, with GUI data. (2) Pointer to the string which contains the message. Output: (1) Short message written to the main window. Return value: No return value. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======inform user about something:=========================================*/ void InformUser_ (GUIS *guiSP, char *messageP) { int message_length, text_width; int frame_width, frame_height; int screen_x0, screen_y0; /* Inform user about something: */ message_length = strlen (messageP); text_width = XTextWidth (guiSP->main_winS.fontSP, messageP, message_length); frame_width = text_width + 50; frame_height = 4 * guiSP->main_winS.text_line_height; screen_x0 = (guiSP->main_win_free_area_width - frame_width) / 2; screen_y0 = (guiSP->main_win_free_area_height - frame_height) / 2; XSetForeground (guiSP->displaySP, guiSP->theGCA[0], guiSP->dark_red_colorID); XFillRectangle (guiSP->displaySP, guiSP->main_winS.ID, guiSP->theGCA[0], screen_x0, screen_y0, frame_width, frame_height); XSetForeground (guiSP->displaySP, guiSP->theGCA[0], guiSP->yellow_colorID); screen_x0 = (guiSP->main_win_free_area_width - text_width) / 2; screen_y0 = (guiSP->main_win_free_area_height + guiSP->main_winS.text_line_height) / 2; XDrawString (guiSP->displaySP, guiSP->main_winS.ID, guiSP->theGCA[0], screen_x0, screen_y0, messageP, message_length); XFlush (guiSP->displaySP); } /*===========================================================================*/ garlic-1.6/extract_hncac.c0000644000076500007650000000612707272236235016077 0ustar zuciczucic00000000000000/* Copyright (C) 2001 Damir Zucic */ /*============================================================================= extract_hncac.c Purpose: Extract H, N, CA and C coordinates for a given residue. Input: (1) Pointer to VectorS structure, where H coord. will be stored. (2) Pointer to VectorS structure, where N coord. will be stored. (3) Pointer to VectorS structure, where CA coord. will be stored. (4) Pointer to VectorS structure, where C coord. will be stored. (5) Pointer to AtomS structure, pointing to the first element of the atomic array. (6) Index of the first atom of a given residue. (7) Index of the last atom of a given residue. Output: (1) VectorS structures filled with data. (2) Return value. Return value: (1) The number of successfully extracted vectors (at least zero, at most four). Notes: (1) Some files contain more than one entry for some atoms. Garlic uses only the first entry and discards other entries for the same atom. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======extract H, N, CA and C coordinates:==================================*/ int ExtractHNCAC_ (VectorS *H_vectorSP, VectorS *N_vectorSP, VectorS *CA_vectorSP, VectorS *C_vectorSP, AtomS *atomSP, size_t atom_startI, size_t atom_endI) { int vectors_extractedN = 0; size_t atomI; AtomS *curr_atomSP; int H_foundF = 0, N_foundF = 0, CA_foundF = 0, C_foundF = 0; /* Scan the given residue: */ for (atomI = atom_startI; atomI <= atom_endI; atomI++) { /* Pointer to the current atom: */ curr_atomSP = atomSP + atomI; /* H: */ if (strcmp (curr_atomSP->raw_atomS.pure_atom_nameA, "H") == 0) { if (H_foundF) continue; H_vectorSP->x = curr_atomSP->raw_atomS.x[0]; H_vectorSP->y = curr_atomSP->raw_atomS.y; H_vectorSP->z = curr_atomSP->raw_atomS.z[0]; vectors_extractedN++; H_foundF = 1; } /* N: */ if (strcmp (curr_atomSP->raw_atomS.pure_atom_nameA, "N") == 0) { if (N_foundF) continue; N_vectorSP->x = curr_atomSP->raw_atomS.x[0]; N_vectorSP->y = curr_atomSP->raw_atomS.y; N_vectorSP->z = curr_atomSP->raw_atomS.z[0]; vectors_extractedN++; N_foundF = 1; } /* CA: */ else if (strcmp (curr_atomSP->raw_atomS.pure_atom_nameA, "CA") == 0) { if (CA_foundF) continue; CA_vectorSP->x = curr_atomSP->raw_atomS.x[0]; CA_vectorSP->y = curr_atomSP->raw_atomS.y; CA_vectorSP->z = curr_atomSP->raw_atomS.z[0]; vectors_extractedN++; CA_foundF = 1; } /* C: */ else if (strcmp (curr_atomSP->raw_atomS.pure_atom_nameA, "C") == 0) { if (C_foundF) continue; C_vectorSP->x = curr_atomSP->raw_atomS.x[0]; C_vectorSP->y = curr_atomSP->raw_atomS.y; C_vectorSP->z = curr_atomSP->raw_atomS.z[0]; vectors_extractedN++; C_foundF = 1; } } /* Return the number of extracted vectors: */ return vectors_extractedN; } /*===========================================================================*/ garlic-1.6/vector_product.c0000644000076500007650000000233007301167516016321 0ustar zuciczucic00000000000000/* Copyright (C) 2000, 2001 Damir Zucic */ /*============================================================================= vector_product.c Purpose: Calculate the vector product of two vectors (v3 = v1 x v2). Input: (1) Pointer to VectorS structure, where the result will be stored. (2) Pointer to VectorS structure, with the first vector. (3) Pointer to VectorS structure, with the second vector. Output: (1) The vector product calculated and stored into VectorS structure. Return value: No return value. ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======calculate vector product of two vectors:=============================*/ void VectorProduct_ (VectorS *vector3SP, VectorS *vector1SP, VectorS *vector2SP) { vector3SP->x = vector1SP->y * vector2SP->z - vector1SP->z * vector2SP->y; vector3SP->y = vector1SP->z * vector2SP->x - vector1SP->x * vector2SP->z; vector3SP->z = vector1SP->x * vector2SP->y - vector1SP->y * vector2SP->x; } /*===========================================================================*/ garlic-1.6/open_template_file.c0000644000076500007650000000603610357762607017130 0ustar zuciczucic00000000000000/* Copyright (C) 2001-2006 Damir Zucic */ /*============================================================================= open_template_file.c Purpose: Open the template file. This is the file with template atoms. These atoms are used to create new peptides, to replace or insert residues and for similar operations. Up to six directories are searched. If all attempts fail, this function will return NULL. Input: (1) Environment variable HOME used. Output: (1) Return value. Return value: (1) File pointer, if file is found. (2) NULL, if all attempts to find file fail. Notes: (1) The following six pathnames in the given order will be checked, if necessary: (1) residues.pdb (current working directory) (2) $HOME/residues.pdb (home directory) (3) $HOME/garlic/residues.pdb (4) /usr/share/garlic/residues.pdb (recom. system-wide default!) (5) /usr/local/lib/garlic/residues.pdb (6) /usr/lib/garlic/residues.pdb ========includes:============================================================*/ #include #include #include #include "defines.h" /*======try to find and open residues.pdb file:==============================*/ FILE *OpenTemplateFile_ (void) { static FILE *fileP; static char tildaA[10] = "~"; char *home_dirP; int n; char template_file_nameA[STRINGSIZE]; /* The first attempt: try to find the file in the current working directory: */ if ((fileP = fopen ("residues.pdb", "r")) != NULL) { return fileP; } /* The second attempt - try to find residues.pdb file in the home directory: */ do { if ((home_dirP = getenv ("HOME")) != NULL) break; if ((home_dirP = getenv ("home")) != NULL) break; home_dirP = tildaA; } while (0); n = STRINGSIZE - 100; strncpy (template_file_nameA, home_dirP, n); template_file_nameA[n] = '\0'; strncat (template_file_nameA, "/residues.pdb", 13); template_file_nameA[STRINGSIZE - 1] = '\0'; if ((fileP = fopen (template_file_nameA, "r")) != NULL) { return fileP; } /* The third attempt - try to find personal file in $HOME/garlic directory: */ n = STRINGSIZE - 100; strncpy (template_file_nameA, home_dirP, n); template_file_nameA[n] = '\0'; strncat (template_file_nameA, "/garlic/residues.pdb", 20); template_file_nameA[STRINGSIZE - 1] = '\0'; if ((fileP = fopen (template_file_nameA, "r")) != NULL) { return fileP; } /* The fourth attempt - /usr/share/garlic directory. */ /* This pathname is recommended as system-wide default! */ if ((fileP = fopen ("/usr/share/garlic/residues.pdb", "r")) != NULL) { return fileP; } /* The fifth attempt - /usr/local/lib/garlic directory: */ if ((fileP = fopen ("/usr/local/lib/garlic/residues.pdb", "r")) != NULL) { return fileP; } /* The sixth attempt - /usr/lib/garlic directory: */ if ((fileP = fopen ("/usr/lib/garlic/residues.pdb", "r")) != NULL) { return fileP; } /* If this point is reached, all attempts have failed: */ return NULL; } /*===========================================================================*/ garlic-1.6/phe.pdb0000644000076500007650000000236107247142305014360 0ustar zuciczucic00000000000000ATOM 1 C 1 1.723 -0.606 0.553 ATOM 2 C 1 0.938 0.493 1.268 ATOM 3 C 1 -0.416 0.648 0.618 ATOM 4 C 1 -1.504 -0.103 1.077 ATOM 5 C 1 -2.760 0.041 0.475 ATOM 6 C 1 -2.927 0.938 -0.588 ATOM 7 C 1 -1.839 1.689 -1.047 ATOM 8 C 1 -0.584 1.545 -0.444 ATOM 9 N 1 0.973 -1.896 0.647 ATOM 10 C 1 3.076 -0.762 1.203 ATOM 11 O 1 4.091 -0.587 0.548 ATOM 12 O 1 3.159 -1.076 2.431 ATOM 13 H 1 -3.895 1.049 -1.052 ATOM 14 H 1 -1.968 2.381 -1.867 ATOM 15 H 1 0.255 2.125 -0.799 ATOM 16 H 1 -1.375 -0.795 1.897 ATOM 17 H 1 -3.599 -0.539 0.829 ATOM 18 H 1 0.809 0.224 2.314 ATOM 19 H 1 1.483 1.431 1.199 ATOM 20 H 1 1.851 -0.337 -0.494 ATOM 21 H 1 1.505 -2.640 0.163 ATOM 22 H 1 0.045 -1.789 0.202 ATOM 23 H 1 0.850 -2.152 1.642 garlic-1.6/parse_pattern.c0000644000076500007650000001142007747233212016127 0ustar zuciczucic00000000000000/* Copyright (C) 2003 Damir Zucic */ /*============================================================================= parse_pattern.c Purpose: Parse the pattern. Pattern consists of residue name sets; each set contains a number of residue names. Input: (1) Pointer to RuntimeS structure. (2) Pointer to the string which contains the pattern. Output: (1) Sequence stored to the pattern buffer. (2) Return value. Return value: (1) Positive on success. (2) Negative on failure. Notes: (1) The pattern is expected in three letters code. One letter code may be missinterpreted as valid three letters code. To each position a set of residues is assigned. Use slash to separate sets. (2) Space, comma, tab and semicolon may be used as separators. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "commands.h" #include "typedefs.h" /*======function prototypes:=================================================*/ char *ExtractToken_ (char *, int, char *, char *); /*======parse pattern:=======================================================*/ int ParsePattern_ (RuntimeS *runtimeSP, char *stringP) { int max_length, i; char *remaining_stringP; char tokenA[STRINGSIZE]; int setI = 0; int residue_names_in_setN = 0; int global_residueI = 0; char *P; char *remaining_substringP; char subtokenA[SHORTSTRINGSIZE]; /* The maximal residue name length: */ max_length = RESNAMESIZE - 1; /* Reset the pattern length: */ runtimeSP->pattern_length = 0; /* Zero initialize the pattern buffer: */ for (i = 0; i < (int) runtimeSP->pattern_buffer_size; i++) { *(runtimeSP->patternP + i) = '\0'; } /* Reset the array with the number of residues per set: */ for (i = 0; i < MAX_PATT_LENGTH; i++) { runtimeSP->namesNA[i] = 0; } /* Reset the total number of residues in pattern: */ runtimeSP->residues_in_patternN = 0; /* Extract the tokens separated by slash, newline and */ /* end of line. These tokens are called residue sets. */ remaining_stringP = stringP; while ((remaining_stringP = ExtractToken_ (tokenA, STRINGSIZE, remaining_stringP, "/\n")) != NULL) { /* If this token contains wildcard, treat this set */ /* as the set which contains only one element: */ if (strstr (tokenA, "*") != NULL) { /* Copy the residue name to the pattern buffer: */ P = runtimeSP->patternP + max_length * global_residueI; *P = '*'; /* This set contains only one residue name: */ runtimeSP->namesNA[setI] = 1; } /* Reset the local number of residue names in set: */ residue_names_in_setN = 0; /* Parse the token to subtokens, separated by space, comma, */ /* semicolon, tab, newline and end of line. These subtokens */ /* should contain valid residue names (three letters code). */ remaining_substringP = tokenA; while ((remaining_substringP = ExtractToken_ (subtokenA, SHORTSTRINGSIZE, remaining_substringP, " ,;\t\n")) != NULL) { /* Check the residue name size: */ if ((int) strlen (subtokenA) > max_length) { sprintf (runtimeSP->messageA, "Residue name %s too long!", subtokenA); runtimeSP->message_length = strlen (runtimeSP->messageA); return -1; } /* Copy the residue name to the pattern buffer: */ P = runtimeSP->patternP + max_length * global_residueI; strcpy (P, subtokenA); /* Increment the local number of residue names in set: */ residue_names_in_setN++; /* Do not allow too many residue names in this set: */ if (residue_names_in_setN >= MAX_NAMES_IN_SET) { sprintf (runtimeSP->messageA, "Too many residues in set!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return -2; } /* Increment the global (cumulative) residue index: */ global_residueI++; /* Do not allow array overflow: */ if (global_residueI >= MAX_RES_IN_PATT) { sprintf (runtimeSP->messageA, "Too many residues!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return -3; } } /* Store the number of residues in this set: */ runtimeSP->namesNA[setI] = residue_names_in_setN; /* Increment the residue set index: */ setI++; /* Do not allow array overflow: */ if (setI >= MAX_PATT_LENGTH) { sprintf (runtimeSP->messageA, "Pattern is too long!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return -4; } } /* Store the total number of sets (the pattern length): */ runtimeSP->pattern_length = setI; /* Store the total number of residues in pattern: */ runtimeSP->residues_in_patternN = global_residueI; /* Return positive value on success: */ return 1; } /*===========================================================================*/ garlic-1.6/sequence.c0000644000076500007650000001112307257453471015077 0ustar zuciczucic00000000000000/* Copyright (C) 2000, 2001 Damir Zucic */ /*============================================================================= sequence.c Purpose: Execute sequence command. This command may be used to define or copy the sequence. The sequence is stored to the sequence buffer. The pointer to this buffer is a member of RuntimeS structure. The sequence command always requires at least one keyword. Keywords: RESET, =, FROM, LOAD (READ) and SAVE. All commands (except =) may be abbreviated to three characters. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) The number of macromolecular complexes. (3) Pointer to RuntimeS structure. (4) Pointer to the string with command parameters. Output: (1) Sequence stored to the sequence buffer. (2) Return value. Return value: (1) Positive (command) code on success. (2) Negative (error) code on failure. Notes: (1) The sequence is expected in three letters code. One letter code may be missinterpreted as valid three letters code. ========includes:============================================================*/ #include #include #include #include #include #include #include #include "defines.h" #include "commands.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int ParseSequence_ (RuntimeS *, char *); char *ExtractToken_ (char *, int, char *, char *); int SequenceFrom_ (MolComplexS *, int, RuntimeS *, char *); int CopySequence_ (RuntimeS *); int LoadSequence_ (RuntimeS *); int SaveSequence_ (RuntimeS *); int SaveSequenceWithNumbers_ (RuntimeS *); /*======execute sequence command:============================================*/ int Sequence_ (MolComplexS *mol_complexSP, int mol_complexesN, RuntimeS *runtimeSP, char *stringP) { char string_copyA[STRINGSIZE]; char *P; char *sequenceP; int n; char *remainderP; char tokenA[SHORTSTRINGSIZE]; /* Copy the original command string: */ strncpy (string_copyA, runtimeSP->curr_commandA, STRINGSIZE - 1); string_copyA[STRINGSIZE - 1] = '\0'; /* Check is the equality sign present in the original command string: */ if ((P = strstr (string_copyA, "=")) != NULL) { /* Prepare the pointer to the sequence string: */ sequenceP = P + 1; /* Convert sequence to uppercase: */ P = sequenceP; while ((n = *P++) != '\0') *(P - 1) = toupper (n); /* Parse and store the sequence: */ n = ParseSequence_ (runtimeSP, sequenceP); if (n > 0) return COMMAND_SEQUENCE; else return ERROR_SEQUENCE; } /* If this point is reached, the equality sign was not found */ /* in the original command string. Check for other keywords. */ /* Take the first token; it should be present: */ remainderP = ExtractToken_ (tokenA, SHORTSTRINGSIZE, stringP, " \t\n"); if (!remainderP) { strcpy (runtimeSP->messageA, "Command parameter(s) missing!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_SEQUENCE; } /* Reset sequence, if requested by keyword RES (RESET): */ if (strstr (tokenA, "RES") == tokenA) { runtimeSP->residuesN = 0; return COMMAND_SEQUENCE; } /* Copy sequence from structure, if requested by keyword FRO (FROM): */ else if (strstr (tokenA, "FRO") == tokenA) { n = SequenceFrom_ (mol_complexSP, mol_complexesN, runtimeSP, remainderP); if (n > 0) return COMMAND_SEQUENCE; else return ERROR_SEQUENCE; } /* Copy the sequence from the main sequence buffer to the reference buffer: */ else if (strstr (tokenA, "COP") == tokenA) { CopySequence_ (runtimeSP); return COMMAND_SEQUENCE; } /* Load seq. from file, if requested by keyword LOA (LOAD) or REA (READ): */ else if ((strstr (tokenA, "LOA") == tokenA) || (strstr (tokenA, "REA") == tokenA)) { n = LoadSequence_ (runtimeSP); if (n > 0) return COMMAND_SEQUENCE; else return ERROR_SEQUENCE; } /* Save sequence as three letter code, if requested by keyword SAV: */ else if (strstr (tokenA, "SAV") == tokenA) { n = SaveSequence_ (runtimeSP); if (n > 0) return COMMAND_SEQUENCE; else return ERROR_SEQUENCE; } /* Save sequence as three letter code, with serial numbers: */ else if (strstr (tokenA, "SWN") == tokenA) { n = SaveSequenceWithNumbers_ (runtimeSP); if (n > 0) return COMMAND_SEQUENCE; else return ERROR_SEQUENCE; } /* If keyword recognition failed: */ else { strcpy (runtimeSP->messageA, "Keyword not recognized!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_SEQUENCE; } /* Return the command code: */ return COMMAND_SEQUENCE; } /*===========================================================================*/ garlic-1.6/assign_radii.c0000644000076500007650000001004407604153310015705 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2002 Damir Zucic */ /*============================================================================= assign_radii.c Purpose: Assign atomic, covalent and van der Waals radius to each atom. Assign generic radii to unrecognized atoms. Input: (1) Pointer to MolComplexS structure. (2) Pointer to ConfigS structure. Output: (1) Atomic radius, covalent radius and van der Waals radius assigned to each atom. (2) Return value. Return value: (1) Positive if there are some atoms. (2) Zero if there are no atoms. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======assign two radii to each atom:=======================================*/ int AssignRadii_ (MolComplexS *mol_complexSP, ConfigS *configSP) { size_t atomI, atomsN; AtomS *curr_atomSP; /* Return zero if there are no atoms in this macromolecular complex: */ atomsN = mol_complexSP->atomsN; if (atomsN == 0) return 0; /* Scan the macromolecular complex: */ for (atomI = 0; atomI < atomsN; atomI++) { /** Pointer to the current atom: **/ curr_atomSP = mol_complexSP->atomSP + atomI; /** Assign default ball radius to all atoms: **/ curr_atomSP->raw_atomS.ball_radius = configSP->default_ball_radius; /** Check the chemical symbol and assign four additional radii: **/ if (strcmp (curr_atomSP->raw_atomS.chemical_symbolA, " H") == 0) { curr_atomSP->raw_atomS.radius = configSP->H_radius; curr_atomSP->raw_atomS.covalent_radius = configSP->H_covalent_radius; curr_atomSP->raw_atomS.small_radius = configSP->H_small_radius; curr_atomSP->raw_atomS.van_der_Waals_radius = configSP->H_van_der_Waals_radius; } else if (strcmp (curr_atomSP->raw_atomS.chemical_symbolA, " C") == 0) { curr_atomSP->raw_atomS.radius = configSP->C_radius; curr_atomSP->raw_atomS.covalent_radius = configSP->C_covalent_radius; curr_atomSP->raw_atomS.small_radius = configSP->C_small_radius; curr_atomSP->raw_atomS.van_der_Waals_radius = configSP->C_van_der_Waals_radius; } else if (strcmp (curr_atomSP->raw_atomS.chemical_symbolA, " N") == 0) { curr_atomSP->raw_atomS.radius = configSP->N_radius; curr_atomSP->raw_atomS.covalent_radius = configSP->N_covalent_radius; curr_atomSP->raw_atomS.small_radius = configSP->N_small_radius; curr_atomSP->raw_atomS.van_der_Waals_radius = configSP->N_van_der_Waals_radius; } else if (strcmp (curr_atomSP->raw_atomS.chemical_symbolA, " O") == 0) { curr_atomSP->raw_atomS.radius = configSP->O_radius; curr_atomSP->raw_atomS.covalent_radius = configSP->O_covalent_radius; curr_atomSP->raw_atomS.small_radius = configSP->O_small_radius; curr_atomSP->raw_atomS.van_der_Waals_radius = configSP->O_van_der_Waals_radius; } else if (strcmp (curr_atomSP->raw_atomS.chemical_symbolA, " S") == 0) { curr_atomSP->raw_atomS.radius = configSP->S_radius; curr_atomSP->raw_atomS.covalent_radius = configSP->S_covalent_radius; curr_atomSP->raw_atomS.small_radius = configSP->S_small_radius; curr_atomSP->raw_atomS.van_der_Waals_radius = configSP->S_van_der_Waals_radius; } else if (strcmp (curr_atomSP->raw_atomS.chemical_symbolA, " P") == 0) { curr_atomSP->raw_atomS.radius = configSP->P_radius; curr_atomSP->raw_atomS.covalent_radius = configSP->P_covalent_radius; curr_atomSP->raw_atomS.small_radius = configSP->P_small_radius; curr_atomSP->raw_atomS.van_der_Waals_radius = configSP->P_van_der_Waals_radius; } else { curr_atomSP->raw_atomS.radius = configSP->generic_radius; curr_atomSP->raw_atomS.covalent_radius = configSP->generic_covalent_radius; curr_atomSP->raw_atomS.small_radius = configSP->generic_small_radius; curr_atomSP->raw_atomS.van_der_Waals_radius = configSP->generic_van_der_Waals_radius; } } /* Return positive value if this point is reached: */ return 1; } /*===========================================================================*/ garlic-1.6/required_atoms.c0000644000076500007650000000506007305424337016306 0ustar zuciczucic00000000000000/* Copyright (C) 2001 Damir Zucic */ /*============================================================================= required_atoms.c Purpose: Count the number of atoms required for the new structure. This is done before creating the structure, to calculate the required storage. Input: (1) Pointer to RuntimeS structure, with template atoms. (2) The number of residues in the new structure. Output: (1) Return value. Return value: (1) The number of atoms required for the new structure. ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======number of atoms required for the new structure:=====================*/ int CountRequiredAtoms_ (RuntimeS *runtimeSP, int residuesN) { int total_atomsN = 0; int max_length; int residueI; char *curr_residue_nameP; int template_residuesN, template_residueI; ResidueS *template_residueSP; AtomS *first_atomSP; char *curr_template_nameP; int atomsN; /* The maximal residue name length: */ max_length = RESNAMESIZE - 1; /* The number of template residues: */ template_residuesN = runtimeSP->template_residuesN; /* Scan the sequence: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Prepare the pointer to the current residue name: */ curr_residue_nameP = runtimeSP->sequenceP + residueI * max_length; /* Scan the list of template residues: */ for (template_residueI = 0; template_residueI < template_residuesN; template_residueI++) { /* Pointer to the current template residue: */ template_residueSP = runtimeSP->template_residueSP + template_residueI; /* Pointer to the first atom of */ /* the current template residue: */ first_atomSP = runtimeSP->template_atomSP + template_residueSP->residue_startI; /* Pointer to the current template residue name: */ curr_template_nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Compare the current residue name */ /* with the template residue name; */ /* if they match, prepare the number */ /* of atoms and add it to the total. */ if (strncmp (curr_residue_nameP, curr_template_nameP, max_length) == 0) { atomsN = (int) template_residueSP->residue_endI - (int) template_residueSP->residue_startI + 1; total_atomsN += atomsN; break; } } } /* Return the total number of atoms: */ return total_atomsN; } /*===========================================================================*/ garlic-1.6/docking_project.c0000644000076500007650000001555007463436321016435 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= docking_project.c Purpose: Prepare orthogonal projection of the specified complex. There are two complexes: bottom (1) and top (2). The purpose of this function is to find the exposed candidates for hydrogen bonds. Atomic positions are taken relative to the plane center of the first complex and projected to xz plane. Input: (1) Pointer to RuntimeS structure. (2) The index of the complex which should be projected. Do not confuse this index with the actual macromol. complex index! The values allowed here are 1 (bottom) and 2 (top). Output: (1) The array of indices, which are listing exposed atoms, will be prepared. (2) Return value. Return value: (1) Positive on success. (2) Negative on failure. Notes: (1) The index of exposed atom is of the type int, though size_t is used elsewhere. The reason is that int may have negative value, while size_t is unsigned on many systems. Negative values are used to signal that data stored to a given cell are obsolete. (2) Indentation is exceptionally 4 spaces. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ void ErrorMessage_ (char *, char *, char *, char *, char *, char *, char *); /*======prepare orthogonal projection of the specified complex:==============*/ int DockingProject_ (RuntimeS *runtimeSP, int docking_complexI) { MolComplexS *curr_mol_complexSP; int *exposed_atomIP; ExposedResidueS *exposed_polarSP; double x0, z0; size_t atomsN, atomI; double reciprocal_denominator; int matrix_width, elementsN, matrixI; int exposed_polarI; int atom_half_width; AtomS *curr_atomSP; double x, y, z; double relative_x, relative_z; double d; int central_rowI, central_columnI; int row0I, row1I, column0I, column1I; int rowI, columnI, combinedI; int *curr_cellP; int prev_atomI; double old_y; /* Check the complex index and prepare the pointers: */ if (docking_complexI == 1) { curr_mol_complexSP = runtimeSP->mol_complex1SP; exposed_atomIP = runtimeSP->exposed_atom1IP; exposed_polarSP = runtimeSP->exposed_polar1SP; } else if (docking_complexI == 2) { curr_mol_complexSP = runtimeSP->mol_complex2SP; exposed_atomIP = runtimeSP->exposed_atom2IP; exposed_polarSP = runtimeSP->exposed_polar2SP; } else { ErrorMessage_ ("garlic", "DockingProject_", "", "Bad macromolecular complex index!\n", "", "", ""); return -1; } /* The reference (central) point is the center of the */ /* plane associated with the first (bottom) complex. */ /* Here it is shifted for half of docking area width: */ x0 = runtimeSP->mol_complex1SP->planeS.center_x[0] - runtimeSP->docking_area_width / 2; z0 = runtimeSP->mol_complex1SP->planeS.center_z[0] - runtimeSP->docking_area_width / 2; /* Prepare and check the number of atoms: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) return -2; /* Initialize the matrix of indices; negative value in some cell */ /* is used to signal that no atom was projected to this cell: */ matrix_width = runtimeSP->docking_matrix_width; elementsN = matrix_width * matrix_width; for (matrixI = 0; matrixI < elementsN; matrixI++) { *(exposed_atomIP + matrixI) = -1; } /* Reset excludedF flags: */ for (exposed_polarI = 0; exposed_polarI < MAX_EXPOSED_RESIDUES; exposed_polarI++) { (exposed_polarSP + exposed_polarI)->excludedF = 0; } /* Atom radius in cells: */ if (runtimeSP->docking_cell_width != 0.0) { d = DOCKING_ATOM_RADIUS / runtimeSP->docking_cell_width; atom_half_width = (int) d; } else atom_half_width = 0; /* Auxilliary variable: */ if (runtimeSP->docking_cell_width != 0.0) { reciprocal_denominator = 1.0 / runtimeSP->docking_cell_width; } else reciprocal_denominator = 0.0; /* Scan the macromolecular complex: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* x and z coordinate of the current atom: */ x = curr_atomSP->raw_atomS.x[0]; z = curr_atomSP->raw_atomS.z[0]; /* y coordinate of the current atom: */ y = curr_atomSP->raw_atomS.y; /* Coordinates relative to the upper left corner */ /* of the area which is covered by docking matrix: */ relative_x = x - x0; relative_z = z - z0; /* Matrix indices of the central point: row index depends on */ /* relative_x and column index depends on relative_z value: */ d = floor (relative_x * reciprocal_denominator); central_rowI = (int) d; d = floor (relative_z * reciprocal_denominator); central_columnI = (int) d; /* Scan the neighbourhood: */ row0I = central_rowI - atom_half_width; row1I = central_rowI + atom_half_width; column0I = central_columnI - atom_half_width; column1I = central_columnI + atom_half_width; for (rowI = row0I; rowI <= row1I; rowI++) { /* The allowed range is from 0 to matrix_width: */ if ((rowI < 0) || (rowI >= matrix_width)) continue; for (columnI = column0I; columnI <= column1I; columnI++) { /* The allowed range is from 0 to matrix_width: */ if ((columnI < 0) || (columnI >= matrix_width)) continue; /* Prepare the combined array index (the matrix is */ /* stored in the form of one-dimensional array): */ combinedI = rowI * matrix_width + columnI; /* Prepare the pointer to the current cell: */ curr_cellP = exposed_atomIP + combinedI; /* The index of the atom reffered by the stored atomic index: */ prev_atomI = *curr_cellP; /* If some atomic index was stored to the cell defined by */ /* rowI and columnI, compare y coordinates of the atom */ /* reffered by this index and the current atom. For the */ /* bottom complex, the obscured atom has higher y, while */ /* for the top complex the obscured atom has lower y. */ if (prev_atomI >= 0) { /* The y coordinate of the atom reffered by stored index: */ old_y = (curr_mol_complexSP->atomSP + prev_atomI)->raw_atomS.y; /* If projecting bottom complex: */ if (docking_complexI == 1) { if (old_y < y) continue; } /* If projecting top complex: */ else { if (old_y > y) continue; } } /* If this point is reached, the current atom is not obscured. */ /* Store the index of the current atom to the matrix: */ *curr_cellP = atomI; } } } /* Return positive value on success: */ return 1; } /*===========================================================================*/ garlic-1.6/bond_partners.c0000644000076500007650000000561707304700417016126 0ustar zuciczucic00000000000000/* Copyright (C) 2001 Damir Zucic */ /*============================================================================= bond_partners.c Purpose: Extract serial numbers and array indices of two atoms which both should belong to the specified residue. Input: (1) Pointer to RuntimeS structure. (2) Pointer to MolComplexS structure. (3) Pointer to ResidueS structure. (4) The purified name of the first atom. (5) The purified name of the second atom. Output: (1) Serial numbers and array indices stored to RuntimeS structure. (2) Return value. Return value: (1) Positive on success. (2) Negative on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "commands.h" #include "typedefs.h" /*======extract serial numbers and array indices for two atoms:==============*/ int BondPartners_ (RuntimeS *runtimeSP, MolComplexS *mol_complexSP, ResidueS *residueSP, char *atom1_nameP, char *atom2_nameP) { int atom_foundF; size_t atom_startI, atom_endI, atomI; AtomS *curr_atomSP; static int atom1_serialI, atom2_serialI; static size_t atom1_arrayI, atom2_arrayI; /* The range for atomic index: */ atom_startI = residueSP->residue_startI; atom_endI = residueSP->residue_endI; /* Try to find the atom specified by the first name: */ atom_foundF = 0; for (atomI = atom_startI; atomI <= atom_endI; atomI++) { /* Pointer to the current atom: */ curr_atomSP = mol_complexSP->atomSP + atomI; /* Check the purified name of this atom: */ if (strcmp (curr_atomSP->raw_atomS.pure_atom_nameA, atom1_nameP) == 0) { atom1_serialI = curr_atomSP->raw_atomS.serialI; atom1_arrayI = atomI; atom_foundF = 1; break; } } /* If atom is not present in this residue: */ if (!atom_foundF) return -1; /* Try to find the atom specified by the second name: */ atom_foundF = 0; for (atomI = atom_startI; atomI <= atom_endI; atomI++) { /* Pointer to the current atom: */ curr_atomSP = mol_complexSP->atomSP + atomI; /* Check the purified name of this atom: */ if (strcmp (curr_atomSP->raw_atomS.pure_atom_nameA, atom2_nameP) == 0) { atom2_serialI = curr_atomSP->raw_atomS.serialI; atom2_arrayI = atomI; atom_foundF = 1; break; } } /* If atom is not present in this residue: */ if (!atom_foundF) return -2; /* If this point is reached, both atoms were found. */ /* Store the serial numbers and the array indices: */ runtimeSP->atom1_serialI = atom1_serialI; runtimeSP->atom2_serialI = atom2_serialI; runtimeSP->atom1_arrayI = atom1_arrayI; runtimeSP->atom2_arrayI = atom2_arrayI; /* Return positive value on success: */ return 1; } /*===========================================================================*/ garlic-1.6/translate_range.c0000644000076500007650000000276107272361013016433 0ustar zuciczucic00000000000000/* Copyright (C) 2001 Damir Zucic */ /*============================================================================= translate_range.c Purpose: Translate the specified range of atoms. This function is used to translate the residues, in fact. Input: (1) Pointer to AtomS structure, pointing to the first element of the atomic array. (2) Index of the first atom in the range. (3) Index of the last atom in the range. (4) Shift along x axis. (5) Shift along y axis. (6) Shift along z axis. Output: (1) The specified range of atoms translated. (2) Return value. Return value: No return value. ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======translate the range of atoms:========================================*/ void TranslateRange_ (AtomS *atomSP, size_t atom_startI, size_t atom_endI, double delta_x, double delta_y, double delta_z) { size_t atomI; AtomS *curr_atomSP; /* Scan the range of atoms: */ for (atomI = atom_startI; atomI <= atom_endI; atomI++) { /* Pointer to the current atom: */ curr_atomSP = atomSP + atomI; /* Update the position of the current atom: */ curr_atomSP->raw_atomS.x[0] += delta_x; curr_atomSP->raw_atomS.y += delta_y; curr_atomSP->raw_atomS.z[0] += delta_z; } } /*===========================================================================*/ garlic-1.6/write_hints.c0000644000076500007650000001212010364507317015614 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2006 Damir Zucic */ /*============================================================================= write_hints.c Purpose: Write some hints to the hidden pixmap. Input: (1) Pointer to GUIS structure, with GUI data. Output: (1) Some hints (textual information) written to hidden pixmap. (2) Return value. Return value: (1) Positive always (trivial). ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======write some hints to the hidden pixmap:===============================*/ int WriteHints_ (GUIS *guiSP) { int screen_x, screen_y, delta_y; char stringA[STRINGSIZE]; /* Prepare the text color (orange): */ XSetForeground (guiSP->displaySP, guiSP->theGCA[0], guiSP->orange_colorID); /* Draw hints: */ delta_y = guiSP->input_winS.text_line_height; screen_x = 10; screen_y = 60 + 2 * delta_y; strcpy (stringA, "Home page (HTML documentation and GNU GPL license is there):"); XDrawString (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x, screen_y, stringA, strlen (stringA)); screen_x = 40; screen_y += delta_y; strcpy (stringA, "http://garlic.mefos.hr/garlic-1.6"); XDrawString (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x, screen_y, stringA, strlen (stringA)); screen_x = 10; screen_y += 2 * delta_y; strcpy (stringA, "Author: http://garlic.mefos.hr/zucic"); XDrawString (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x, screen_y, stringA, strlen (stringA)); /* Change the text color (yellow): */ XSetForeground (guiSP->displaySP, guiSP->theGCA[0], guiSP->yellow_colorID); screen_x = 10; screen_y += 2 * delta_y; strcpy (stringA, "References:"); XDrawString (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x, screen_y, stringA, strlen (stringA)); screen_x = 40; screen_y += delta_y; strcpy (stringA, "Damir Zucic and Davor Juretic,"); XDrawString (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x, screen_y, stringA, strlen (stringA)); screen_y += delta_y; strcpy (stringA, "Precise Annotation of Transmembrane Segments"); XDrawString (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x, screen_y, stringA, strlen (stringA)); screen_y += delta_y; strcpy (stringA, "with Garlic - a Free Molecular Visualization Program,"); XDrawString (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x, screen_y, stringA, strlen (stringA)); screen_y += delta_y; strcpy (stringA, "Croatica Chemica Acta Vol. 77, No. 1-2, pp. 397-401 (2004)."); XDrawString (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x, screen_y, stringA, strlen (stringA)); screen_y += delta_y; strcpy (stringA, "Free PDF:"); XDrawString (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x, screen_y, stringA, strlen (stringA)); screen_y += delta_y; strcpy (stringA, "http://public.carnet.hr/ccacaa/CCA-PDF/cca2004/v77-n1_n2/CCA_77_2004_397-401_zucic.pdf"); XDrawString (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x, screen_y, stringA, strlen (stringA)); screen_y += 2.0 * delta_y; strcpy (stringA, "Damir Zucic,"); XDrawString (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x, screen_y, stringA, strlen (stringA)); screen_y += delta_y; strcpy (stringA, "Annotation of Transmembrane Segments of Experimentally"); XDrawString (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x, screen_y, stringA, strlen (stringA)); screen_y += delta_y; strcpy (stringA, "Solved Bacterial Porins and Adhesins,"); XDrawString (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x, screen_y, stringA, strlen (stringA)); screen_y += delta_y; strcpy (stringA, "Croatica Chemica Acta Vol. 78, No. 2, pp. 151-158 (2005)."); XDrawString (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x, screen_y, stringA, strlen (stringA)); screen_y += delta_y; strcpy (stringA, "Free PDF:"); XDrawString (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x, screen_y, stringA, strlen (stringA)); screen_y += delta_y; strcpy (stringA, "http://jagor.srce.hr/ccacaa/CCA-PDF/cca2005/v78-n2/CCA_78_2005_151-158_Zucic.pdf"); XDrawString (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x, screen_y, stringA, strlen (stringA)); /* Restore the text color (orange): */ XSetForeground (guiSP->displaySP, guiSP->theGCA[0], guiSP->orange_colorID); screen_x = 10; screen_y += 2 * delta_y; strcpy (stringA, "Encourage garlic development - type reg to register!"); XDrawString (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x, screen_y, stringA, strlen (stringA)); /* Return positive value (trivial): */ return 1; } /*===========================================================================*/ garlic-1.6/hide_no_refresh.c0000644000076500007650000000342407076166747016425 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= hide_no_refresh.c Purpose: Hide selected atoms but do not refresh graphics. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) The number of macromolecular complexes. Output: (1) The hiddenF set for each atom in each caught complex. (2) Return value. Return value: (1) Always positive (trivial). ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======hide selected atoms:=================================================*/ int HideNoRefresh_ (MolComplexS *mol_complexSP, int mol_complexesN) { int mol_complexI; MolComplexS *curr_mol_complexSP; size_t atomsN, atomI; AtomS *curr_atomSP; /* Check every macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /** Pointer to the current macromolecular complex: **/ curr_mol_complexSP = mol_complexSP + mol_complexI; /** Check is the current macromolecular complex caught: **/ if (curr_mol_complexSP->catchF == 0) continue; /** Number of atoms in a macromolecular complex: **/ atomsN = curr_mol_complexSP->atomsN; /** Scan all atoms in the current complex: **/ for (atomI = 0; atomI < atomsN; atomI++) { /** Pointer to the current atom: **/ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /** Check the selection flag; hide selected atoms: **/ if (curr_atomSP->selectedF) curr_atomSP->hiddenF = 1; } } /* Return positive value (trivial): */ return 1; } /*===========================================================================*/ garlic-1.6/wheel.c0000644000076500007650000001215307664415537014402 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2003 Damir Zucic */ /*============================================================================= wheel.c Purpose: Execute wheel command: draw helical wheel for the sequence which is kept in the sequence buffer. Input: (1) Pointer to MolComplexS structure. (2) The number of macromolecular complexes. (3) Pointer to RuntimeS structure. (4) Pointer to ConfigS structure. (5) Pointer to GUIS structure. (6) Pointer to NearestAtomS structure. (7) The number of pixels in the main window free area. (8) Pointer to refreshI. (9) Pointer to the remainder of the command string. This command may be given without any keyword, with keyword OFF or with two residue serial numbers. Output: (1) The main window mode changed to 2 (default is zero), i.e. the main window will be switched to helical wheel plot. (2) Return value. Return value: (1) Positive (command) code on success. (2) Negative (error) code on failure. Notes: (1) This command reinitializes the NearestAtomS array, except if the additional keyword is not recognized. (2) Helical wheel is drawn for the sequence which is currently in the sequence buffer. This sequence will be typically short. ========includes:============================================================*/ #include #include #include #include #include #include #include #include "defines.h" #include "commands.h" #include "typedefs.h" /*======function prototypes:=================================================*/ char *ExtractToken_ (char *, int, char *, char *); int ExtractTwoIntegers_ (int *, int *, char *); void InitNearest_ (NearestAtomS *, size_t); size_t MainRefresh_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); int ControlRefresh_ (MolComplexS *, ConfigS *, GUIS *); /*======execute wheel command:===============================================*/ int Wheel_ (MolComplexS *mol_complexSP, int mol_complexesN, RuntimeS *runtimeSP, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int *refreshIP, char *stringP) { char *P; int n; int residue1I, residue2I; int digit_foundF; /* Reset the clockwise flag: */ runtimeSP->wheel_clockwiseF = 0; /* If the string contans the substring " OFF", switch off */ /* the helical wheel plot and return to default drawing mode: */ if (strstr (stringP, " OFF")) { /* Reset drawing mode index: */ guiSP->main_window_modeI = 0; /* Reinitialize the NearestAtomS array: */ InitNearest_ (nearest_atomSP, pixelsN); *refreshIP = 1; /* Refresh the main window: */ (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); /* Refresh the control window: */ ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); /* Return the command code: */ return COMMAND_WHEEL; } /* If the string contains the substring " CLO", the helical wheel should be */ /* drawn clockwise (this gives the bottom view of the corresponding helix). */ if (strstr (stringP, " CLO")) runtimeSP->wheel_clockwiseF = 1; /* Initialize the range of residue array indices: */ runtimeSP->range_startI = 0; if (runtimeSP->residuesN >= 1) { runtimeSP->range_endI = (int) runtimeSP->residuesN - 1; } else { runtimeSP->range_endI = 0; } /* Scan the string for digits; if it contains at least one */ /* digit, try to extract two integers (the range indices): */ P = stringP; digit_foundF = 0; while ((n = *P++) != '\0') { if (isdigit (n)) { digit_foundF = 1; break; } } /* If at least one digit was found, try to extract two integers: */ if (digit_foundF) { /* Replace each minus in the input string with space: */ P = stringP; while ((n = *P++) != '\0') { if (n == '-') *(P - 1) = ' '; } /* If reading fails: */ if (ExtractTwoIntegers_ (&residue1I, &residue2I, stringP) < 0) { strcpy (runtimeSP->messageA, "Command interpretation failed!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_WHEEL; } /* If indices were successfully read, check them: */ if ((residue1I < 1) || (residue2I < residue1I)) { strcpy (runtimeSP->messageA, "Bad range (check indices)!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_WHEEL; } /* Store the extracted indices: */ runtimeSP->range_startI = residue1I - 1; runtimeSP->range_endI = residue2I - 1; } /* Set the main window drawing mode index: */ guiSP->main_window_modeI = 2; /* Reinitialize the NearestAtomS array and refresh index: */ InitNearest_ (nearest_atomSP, pixelsN); *refreshIP = 1; /* Refresh the main window: */ (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); /* Refresh the control window: */ ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); /* Return the command code: */ return COMMAND_WHEEL; } /*===========================================================================*/ garlic-1.6/chi4_from_cgcdnecz.c0000644000076500007650000000727307342224664017007 0ustar zuciczucic00000000000000/* Copyright (C) 2001 Damir Zucic */ /*============================================================================= chi4_from_cgcdnecz.c Purpose: Calculate dihedral angle chi4, using CG, CD, NE and CZ coordinates. Input: (1) Pointer to AtomS structure, pointing to the first atom of the current macromolecular complex. (2) Index of the first atom of the current residue. (3) Index of the last atom of the currrent residue. Output: Return value. Return value: (1) Dihedral angle chi4, on success. (2) BADDIHEDANGLE on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int ExtractFourAtoms_ (VectorS *, VectorS *, VectorS *, VectorS *, char *, char *, char *, char *, AtomS *, size_t, size_t); void VectorProduct_ (VectorS *, VectorS *, VectorS *); double AbsoluteValue_ (VectorS *); double ScalarProduct_ (VectorS *, VectorS *); /*======calculate chi4 from CG, CD, NE and CZ:===============================*/ double Chi4FromCGCDNECZ_ (AtomS *atomSP, size_t atom_startI, size_t atom_endI) { static VectorS CG_vectorS, CD_vectorS, NE_vectorS, CZ_vectorS; int n; VectorS CD_CG_vectorS, CD_NE_vectorS; VectorS NE_CD_vectorS, NE_CZ_vectorS; VectorS u1S, u2S; VectorS v1S, v2S; double denom, ratio, alpha; double chi4; /* Extract CG, CD, NE and CZ coordinates: */ n = ExtractFourAtoms_ (&CG_vectorS, &CD_vectorS, &NE_vectorS, &CZ_vectorS, "CG", "CD", "NE", "CZ", atomSP, atom_startI, atom_endI); /* All four atoms are required to calculate the angle chi4: */ if (n < 4) return BADDIHEDANGLE; /* The first pair of auxiliary vectors: */ CD_CG_vectorS.x = CG_vectorS.x - CD_vectorS.x; CD_CG_vectorS.y = CG_vectorS.y - CD_vectorS.y; CD_CG_vectorS.z = CG_vectorS.z - CD_vectorS.z; CD_NE_vectorS.x = NE_vectorS.x - CD_vectorS.x; CD_NE_vectorS.y = NE_vectorS.y - CD_vectorS.y; CD_NE_vectorS.z = NE_vectorS.z - CD_vectorS.z; /* The second pair of auxiliary vectors: */ NE_CD_vectorS.x = CD_vectorS.x - NE_vectorS.x; NE_CD_vectorS.y = CD_vectorS.y - NE_vectorS.y; NE_CD_vectorS.z = CD_vectorS.z - NE_vectorS.z; NE_CZ_vectorS.x = CZ_vectorS.x - NE_vectorS.x; NE_CZ_vectorS.y = CZ_vectorS.y - NE_vectorS.y; NE_CZ_vectorS.z = CZ_vectorS.z - NE_vectorS.z; /* Two vectors perpendicular to CD_NE_vectorS, mutually orthogonal, */ /* the second in the plane defined by CD_CG_vectorS and CD_NE_vectorS: */ VectorProduct_ (&u1S, &CD_CG_vectorS, &CD_NE_vectorS); VectorProduct_ (&u2S, &u1S, &CD_NE_vectorS); /* Two vectors perpendicular to NE_CD_vectorS, mutually orthogonal, */ /* the second in the plane defined by NE_CD_vectorS and NE_CZ_vectorS: */ VectorProduct_ (&v1S, &NE_CD_vectorS, &NE_CZ_vectorS); VectorProduct_ (&v2S, &NE_CD_vectorS, &v1S); /* Calculate the angle alpha, which will be used to calculate chi4: */ /* Avoid division by zero: */ denom = AbsoluteValue_ (&u1S) * AbsoluteValue_ (&v1S); if (denom == 0.0) return BADDIHEDANGLE; /* Use the scalar product to calculate the cosine of the angle: */ ratio = ScalarProduct_ (&u1S, &v1S) / denom; /* Arc cosine is very sensitive to floating point errors: */ if (ratio <= -1.0) alpha = 3.1415927; else if (ratio >= 1.0) alpha = 0.0; else alpha = acos (ratio); /* There are two possible solutions; the right one is resolved here: */ if (ScalarProduct_ (&v2S, &u1S) >= 0) chi4 = alpha; else chi4 = -alpha; /* Return the angle (in radians): */ return chi4; } /*===========================================================================*/ garlic-1.6/acceptor_dipole.c0000644000076500007650000002204607571175562016432 0ustar zuciczucic00000000000000/* Copyright (C) 2002 Damir Zucic */ /*============================================================================= acceptor_dipole.c Purpose: Prepare two vectors which define the hydrogen bond acceptor dipole. The first vector is the position of the dipole center. The second vector is the unit vector which defines the dipole direction. Two types of acceptor dipoles are recognized by garlic: C-O dipole and C-N-C dipole (which involves the NE2 atom of HIS side chain). Input: (1) Pointer to VectorS structure, where the position of the dipole center will be stored. (2) Pointer to VectorS, where the unit vector which defines the direction of dipole will be stored. (3) Pointer to AtomS structure, with data about the hydrogen bond acceptor. (4) Pointer to MolComplexS structure, which contains the data about the macromolecular complex to which the hydrogen bond acceptor belongs. (5) The array index of the macromolecular complex to which the hydrogen bond acceptor belongs. Output: (1) The vector which defines the dipole center. (2) The unit vector which defines the dipole direction. (3) Return value. Return value: (1) Positive on success. (2) Negative on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ double AbsoluteValue_ (VectorS *); /*======prepare vectors which define the acceptor dipole:====================*/ int AcceptorDipole_ (VectorS *center_vectorSP, VectorS *unit_vectorSP, AtomS *acceptor_atomSP, MolComplexS *current_mol_complexSP, int mol_complexI) { ResidueS *current_residueSP; size_t first_atomI, last_atomI; RawAtomS *acceptor_raw_atomSP; int bondI; TrueBondS *current_bondSP; char alt_location; AtomS *partner_atomSP; double x1, y1, z1, x2, y2, z2; double absolute_value, reciprocal_abs_value; int carbon_atomsN; /* Prepare the pointer to the residue to which the hydrogen */ /* bond acceptor belongs. Only this residue should be scanned: */ current_residueSP = current_mol_complexSP->residueSP + acceptor_atomSP->residue_arrayI; /* The range of atomic array indices which define this residue: */ first_atomI = current_residueSP->residue_startI; last_atomI = current_residueSP->residue_endI; /* Prepare the pointer to raw atomic data about the acceptor atom: */ acceptor_raw_atomSP = &acceptor_atomSP->raw_atomS; /*---------------------------------------------------------------------------*/ /* If the acceptor atom is the oxygen atom, find the only */ /* carbon bound to this oxygen. It is assumed that there */ /* is only one carbon atom bound to the given oxygen atom. */ /* This should be true for standard amino acid residues. */ if (strcmp (acceptor_raw_atomSP->chemical_symbolA, " O") == 0) { /* Check all bonds of the acceptor atom to find the */ /* partner which forms the dipole with the acceptor: */ for (bondI = 0; bondI < acceptor_atomSP->bondsN; bondI++) { /* Pointer to the current bond: */ current_bondSP = acceptor_atomSP->true_bondSA + bondI; /* Only covalently bound partners are valid candidates: */ if (current_bondSP->bond_typeI != 1) continue; /* The bond partner should belong to the same complex: */ if (current_bondSP->neighbor_mol_complexI != mol_complexI) { continue; } /* The bond partner should belong to the same residue: */ if (current_bondSP->neighbor_arrayI < first_atomI) continue; if (current_bondSP->neighbor_arrayI > last_atomI) continue; /* The bond partner should be the carbon */ /* atom (see check_dist.c for pair ID's): */ if (current_bondSP->pairID != 3) continue; /* Prepare the pointer to the bond partner (carbon atom): */ partner_atomSP = current_mol_complexSP->atomSP + current_bondSP->neighbor_arrayI; /* Ignore atoms at alternate positions: */ alt_location = partner_atomSP->raw_atomS.alt_location; if ((alt_location != ' ') && (alt_location != 'A')) continue; /* If this point is reached, the carbon */ /* atom bound to the oxygen atom is found. */ /* Copy atomic coordinates: */ x1 = partner_atomSP->raw_atomS.x[0]; y1 = partner_atomSP->raw_atomS.y; z1 = partner_atomSP->raw_atomS.z[0]; x2 = acceptor_atomSP->raw_atomS.x[0]; y2 = acceptor_atomSP->raw_atomS.y; z2 = acceptor_atomSP->raw_atomS.z[0]; /* Prepare and store the position of dipole center: */ center_vectorSP->x = 0.5 * (x1 + x2); center_vectorSP->y = 0.5 * (y1 + y2); center_vectorSP->z = 0.5 * (z1 + z2); /* Prepare and store the unit vector, */ /* pointing from oxygen to carbon atom */ /* (don't forget the normalization!): */ unit_vectorSP->x = x1 - x2; unit_vectorSP->y = y1 - y2; unit_vectorSP->z = z1 - z2; absolute_value = AbsoluteValue_ (unit_vectorSP); if (absolute_value <= 0.0) return -1; reciprocal_abs_value = 1.0 / absolute_value; unit_vectorSP->x *= reciprocal_abs_value; unit_vectorSP->y *= reciprocal_abs_value; unit_vectorSP->z *= reciprocal_abs_value; /* Return the success indicator: */ return 1; } /* If this point is reached, all bond partners were checked */ /* but no carbon atom was found. Return the failure indicator: */ return -2; } /*---------------------------------------------------------------------------*/ /* If the acceptor atom is NE2 (HIS side chain), two carbon atoms */ /* bound to the nitrogen should be found. The point in the middle */ /* of these two atoms will be combined with nitrogen coordinates */ /* to prepare the position of dipole center and the unit vector. */ /* It is expected that there are two carbon atoms bound to the */ /* nitrogen atom. This should be true for standard HIS residue. */ else if (strcmp (acceptor_raw_atomSP->pure_atom_nameA, "NE2") == 0) { /* Initialize the position of the point */ /* which lays between two carbon atoms: */ x1 = 0.0; y1 = 0.0; z1 = 0.0; /* Initialize the number of carbon atoms bound to nitrogen: */ carbon_atomsN = 0; /* Check all bonds of the acceptor atom to find two */ /* partners which form the dipole with the acceptor: */ for (bondI = 0; bondI < acceptor_atomSP->bondsN; bondI++) { /* Pointer to the current bond: */ current_bondSP = acceptor_atomSP->true_bondSA + bondI; /* Only covalently bound partners are valid candidates: */ if (current_bondSP->bond_typeI != 1) continue; /* The bond partner should belong to the same complex: */ if (current_bondSP->neighbor_mol_complexI != mol_complexI) { continue; } /* The bond partner should belong to the same residue: */ if (current_bondSP->neighbor_arrayI < first_atomI) continue; if (current_bondSP->neighbor_arrayI > last_atomI) continue; /* The bond partner should be the carbon */ /* atom (see check_dist.c for pair ID's): */ if (current_bondSP->pairID != 2) continue; /* Prepare the pointer to the bond partner (carbon atom): */ partner_atomSP = current_mol_complexSP->atomSP + current_bondSP->neighbor_arrayI; /* Ignore atoms at alternate positions: */ alt_location = partner_atomSP->raw_atomS.alt_location; if ((alt_location != ' ') && (alt_location != 'A')) continue; /* If this point is reached, one of the carbon */ /* atoms bound to the nitrogen atom is found. */ /* Add the coordinates of this carbon atom */ /* to the coordinates of the point which lays */ /* in the middle between two carbon atoms: */ x1 += partner_atomSP->raw_atomS.x[0]; y1 += partner_atomSP->raw_atomS.y; z1 += partner_atomSP->raw_atomS.z[0]; /* Increment the counter which counts the */ /* carbon atoms bound to the nitrogen atom: */ carbon_atomsN++; } /* There should be two carbon atoms bound to the nitrogen atom: */ if (carbon_atomsN != 2) return -3; /* Fix the position of the first point: */ x1 *= 0.5; y1 *= 0.5; z1 *= 0.5; /* Copy the coordinates of the second point: */ x2 = acceptor_atomSP->raw_atomS.x[0]; y2 = acceptor_atomSP->raw_atomS.y; z2 = acceptor_atomSP->raw_atomS.z[0]; /* Prepare and store the position of dipole center: */ center_vectorSP->x = 0.5 * (x1 + x2); center_vectorSP->y = 0.5 * (y1 + y2); center_vectorSP->z = 0.5 * (z1 + z2); /* Prepare and store the unit vector */ /* pointing from carbon to oxygen atom */ /* (don't forget the normalization!): */ unit_vectorSP->x = x2 - x1; unit_vectorSP->y = y2 - y1; unit_vectorSP->z = z2 - z1; absolute_value = AbsoluteValue_ (unit_vectorSP); if (absolute_value <= 0.0) return -4; reciprocal_abs_value = 1.0 / absolute_value; unit_vectorSP->x *= reciprocal_abs_value; unit_vectorSP->y *= reciprocal_abs_value; unit_vectorSP->z *= reciprocal_abs_value; /* Return the success indicator: */ return 2; } /*---------------------------------------------------------------------------*/ /* If this point is reached, the acceptor atom was */ /* not recognized - return the failure indicator: */ return -5; } /*===========================================================================*/ garlic-1.6/alpha_normal.c0000644000076500007650000003337207633610023015720 0ustar zuciczucic00000000000000/* Copyright (C) 2001-2003 Damir Zucic */ /*============================================================================= alpha_normal.c Purpose: Refine the normal vector which is required to define the membrane for alpha helix bundle protein. The normal vector is declined from its original direction and a set of alternative positions is scanned. For each trial, calculate the average hydrophobicity associated with the cell which is nearest to the reference point. The sliding window width should be similar to the membrane thickness (slightly larger, in fact). The best normal vector is the one which gives the highest average hydrophobicity at the reference point. Input: (1) Pointer to VectorS structure, with the normal vector. The components of this vector will be updated. (2) Pointer to MolComplexS structure, with the chosen structure. (3) The tilt step, used to decline the normal vector from its original direction. Output: (1) On success, the normal vector will be refined. (2) Return value. Return value: (1) Positive on success. (2) Negative on failure. Notes: (1) Indentation is exceptionally four spaces. (2) On failure, remember to free the allocated storage before returning to the caller. (3) If the tilt_step is set equal to 0.05, the maximal deviation of the normal vector from its original direction will be about 31 degree in each direction, about each of two axis. (4) On success, this function will normalize the normal vector. ========includes:============================================================*/ #include #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ double AbsoluteValue_ (VectorS *); double ScalarProduct_ (VectorS *, VectorS *); void VectorProduct_ (VectorS *, VectorS *, VectorS *); int ExtractCA_ (VectorS *, AtomS *, size_t, size_t); /*======refine the normal vector (helix bundle version):=====================*/ int AlphaNormalVector_ (VectorS *normal_vectorSP, MolComplexS *mol_complexSP, double tilt_step) { int residuesN, residueI; size_t double_size, int_size; int cellsN = 10000; static double *hydrophobicityP; static int *projectionsNP; static int *cells_usedNP; VectorS center_vectorS; int centralI; double cell_width = 1.0, half_cell_width; double reciprocal_cell_width; int half_window_width; double abs_value, reciprocal_abs_value; VectorS unit_vector1S, unit_vector2S, unit_vector3S; VectorS aux_vectorS; double best_average; int best_i, best_j; int i, j, k; double d1, d2; ResidueS *curr_residueSP; int first_atomI, last_atomI; int n; VectorS CA_vectorS; AtomS *first_atomSP; double hydrophobicity; VectorS radius_vectorS; double reciprocal_denominator; double projection; int cellI; int used_cellsN; double average; int windowI, combinedI; /* Copy the number of residues: */ residuesN = mol_complexSP->residuesN; /* Double and int size: */ double_size = sizeof (double); int_size = sizeof (int); /* Allocate the memory for the array of hydrophobicity values: */ hydrophobicityP = (double *) calloc (cellsN, double_size); if (!hydrophobicityP) { return -1; } /* Allocate the memory required to store the number of projections per cell: */ projectionsNP = (int *) calloc (cellsN, int_size); if (!projectionsNP) { free (hydrophobicityP); return -2; } /* Allocate the memory for the total number of used cells: */ cells_usedNP = (int *) calloc (cellsN, int_size); if (!cells_usedNP) { free (hydrophobicityP); free (projectionsNP); return -3; } /* Copy the vector which defines the membrane center: */ center_vectorS.x = mol_complexSP->membraneS.center_x; center_vectorS.y = mol_complexSP->membraneS.center_y; center_vectorS.z = mol_complexSP->membraneS.center_z; /* Prepare the central index, half of the */ /* cell width and the reciprocal cell width: */ centralI = cellsN / 2; if (cell_width == 0.0) { free (hydrophobicityP); free (projectionsNP); free (cells_usedNP); return -4; } half_cell_width = 0.5 * cell_width; reciprocal_cell_width = 1.0 / cell_width; /* Prepare the half of the window width. The window is used for */ /* the averaging of total hydrophobicities. The width of this */ /* window should be slightly larger than the membrane thickness. */ /* The minimal half-width is 1 and the minimal full width is 3. */ half_window_width = (int) (mol_complexSP->membraneS.thickness / cell_width); half_window_width /= 2; half_window_width += 1; /* Prepare the first unit vector. This vector */ /* will be collinear with the normal vector: */ abs_value = AbsoluteValue_ (normal_vectorSP); if (abs_value == 0.0) { free (hydrophobicityP); free (projectionsNP); free (cells_usedNP); return -5; } reciprocal_abs_value = 1.0 / abs_value; unit_vector1S.x = reciprocal_abs_value * normal_vectorSP->x; unit_vector1S.y = reciprocal_abs_value * normal_vectorSP->y; unit_vector1S.z = reciprocal_abs_value * normal_vectorSP->z; /* Now prepare the second unit vector. It will */ /* be perpendicular to the first unit vector. */ /* Prepare one auxiliary vector which is not */ /* collinear with the first unit vector. For each */ /* unit vector, the absolute value of at least one */ /* component is larger than or equal to 0.577350. */ if (fabs (unit_vector1S.x) >= 0.5) { aux_vectorS.x = 0.0; aux_vectorS.y = unit_vector1S.y + 4.0; aux_vectorS.z = unit_vector1S.z + 4.0; } else if (fabs (unit_vector1S.y) >= 0.5) { aux_vectorS.x = unit_vector1S.x + 4.0; aux_vectorS.y = 0.0; aux_vectorS.z = unit_vector1S.z + 4.0; } else { aux_vectorS.x = unit_vector1S.x + 4.0; aux_vectorS.y = unit_vector1S.y + 4.0; aux_vectorS.z = 0.0; } /* Check the scalar product between the auxialiary */ /* vector and the first unit vector (I am paranoic): */ if (ScalarProduct_ (&aux_vectorS, &unit_vector1S) == 0.0) { free (hydrophobicityP); free (projectionsNP); free (cells_usedNP); return -6; } /* Now prepare the second unit vector. It will */ /* be perpendicular to the first unit vector: */ VectorProduct_ (&unit_vector2S, &unit_vector1S, &aux_vectorS); /* Check and normalize the second unit vector: */ abs_value = AbsoluteValue_ (&unit_vector2S); if (abs_value == 0.0) { free (hydrophobicityP); free (projectionsNP); free (cells_usedNP); return -7; } reciprocal_abs_value = 1.0 / abs_value; unit_vector2S.x *= reciprocal_abs_value; unit_vector2S.y *= reciprocal_abs_value; unit_vector2S.z *= reciprocal_abs_value; /* Prepare the third unit vector: */ VectorProduct_ (&unit_vector3S, &unit_vector1S, &unit_vector2S); /*--------------------------------------------------*/ /* */ /* Prepare 25 x 25 = 625 vectors. For each of these */ /* vectors, a number of operations should be done: */ /* */ /*---------------------------------------------------------------------*/ /* */ /* (1) Project all residues to the axis defined by the given vector */ /* and by the reference point (this point is the membrane center). */ /* */ /* (2) Divide the axis into a number of cells and for each cell */ /* calculate the total hydrophobicity for residues which project */ /* to this cell. */ /* */ /* (3) Average the total hydrophobicities for all cells in the */ /* neighborhood of the central cell. Take the window which covers */ /* the entire thickness of the membrane. The central cell should */ /* be in the middle of this window, of course. */ /* */ /* (4) Take the vector for which the average total hydrophobicity */ /* assigned to the central cell has the highest value. Copy this */ /* vector to the normal vector. */ /* */ /*---------------------------------------------------------------------*/ best_average = -999999.0; best_i = 999; best_j = 999; /* Check 25 x 25 vectors: */ for (i = -12; i <= 12; i++) { d1 = i * tilt_step; for (j = -12; j <= 12; j++) { /* Prepare the auxiliary vector: */ d2 = j * tilt_step; aux_vectorS.x = unit_vector1S.x + unit_vector2S.x * d1 + unit_vector3S.x * d2; aux_vectorS.y = unit_vector1S.y + unit_vector2S.y * d1 + unit_vector3S.y * d2; aux_vectorS.z = unit_vector1S.z + unit_vector2S.z * d1 + unit_vector3S.z * d2; /* Normalize the auxiliary vector: */ abs_value = AbsoluteValue_ (&aux_vectorS); if (abs_value == 0.0) { free (hydrophobicityP); free (projectionsNP); free (cells_usedNP); return -8; } reciprocal_denominator = 1.0 / abs_value; aux_vectorS.x *= reciprocal_denominator; aux_vectorS.y *= reciprocal_denominator; aux_vectorS.z *= reciprocal_denominator; /* Reset three arrays which are used in residueI loop: */ for (k = 0; k < cellsN; k++) { *(hydrophobicityP + k) = 0.0; *(projectionsNP + k) = 0; *(cells_usedNP + k) = 0; } /* Now project the hydrophobicities of all residues to */ /* the reference axis defined by the current membrane */ /* center and by the normal vector. The axis is divided */ /* into cells. The width of a single cell is cell_width. */ /* Scan all residues and project CA atoms to the reference axis: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Pointer to the current residue: */ curr_residueSP = mol_complexSP->residueSP + residueI; /* Copy the indices of the first and of the last atom: */ first_atomI = curr_residueSP->residue_startI; last_atomI = curr_residueSP->residue_endI; /* Extract the position of CA atom. */ n = ExtractCA_ (&CA_vectorS, mol_complexSP->atomSP, first_atomI, last_atomI); if (n != 1) continue; /* Copy the hydrophobicity associated with this residue: */ first_atomSP = (mol_complexSP->atomSP + first_atomI); hydrophobicity = first_atomSP->raw_atomS.hydrophobicity; /* Prepare the vector from the membrane center to the CA atom: */ radius_vectorS.x = CA_vectorS.x - center_vectorS.x; radius_vectorS.y = CA_vectorS.y - center_vectorS.y; radius_vectorS.z = CA_vectorS.z - center_vectorS.z; /* Project the radius vector: */ projection = ScalarProduct_ (&radius_vectorS, &aux_vectorS); /* Prepare and check the cell index: */ cellI = centralI + reciprocal_cell_width * (projection - half_cell_width); if (cellI < 0) continue; if (cellI >= cellsN) continue; /* Update the total hydrophobicity stored */ /* to the cell with the given cell index. */ /* Update the total hydrophobicity stored */ /* to the cell with the given cell index. */ /* Update the number of CA atoms projected to the given cell: */ (*(projectionsNP + cellI))++; /* Update the total hydrophobicity: */ *(hydrophobicityP + cellI) += hydrophobicity; } /* Average the total hydrophobicities over cells. */ /* The cell which is associated with the membrane */ /* center should be in the middle of the window. */ /* Reset the number of cells in a window and the average value: */ used_cellsN = 0; average = 0.0; /* Scan the window: */ for (windowI = -half_window_width; windowI <= half_window_width; windowI++) { /* Prepare the combined index: */ combinedI = centralI + windowI; /* Skip empty cells: */ if (*(projectionsNP + combinedI) == 0) continue; /* Update the number of used cells and */ /* the sum of total hydrophobicities: */ used_cellsN++; average += *(hydrophobicityP + combinedI); } /* Calculate the average value: */ if (used_cellsN != 0) average /= (double) used_cellsN; else average = -999999.0; /* Check is it the best overall average: */ if (average > best_average) { best_average = average; best_i = i; best_j = j; } } } /* If the best average value was not found (rather strange */ /* outcome, but I am paranoic), return negative value: */ if ((best_i == 999) || (best_j == 999)) { free (hydrophobicityP); free (projectionsNP); free (cells_usedNP); return -9; } /* If this point is reached, the best average */ /* value was found. Update the normal vector: */ d1 = best_i * tilt_step; d2 = best_j * tilt_step; normal_vectorSP->x = unit_vector1S.x + unit_vector2S.x * d1 + unit_vector3S.x * d2; normal_vectorSP->y = unit_vector1S.y + unit_vector2S.y * d1 + unit_vector3S.y * d2; normal_vectorSP->z = unit_vector1S.z + unit_vector2S.z * d1 + unit_vector3S.z * d2; /* Make sure that the absolute value of the normal vector is equal to one: */ abs_value = AbsoluteValue_ (normal_vectorSP); if (abs_value == 0.0) { free (hydrophobicityP); free (projectionsNP); free (cells_usedNP); return -10; } reciprocal_denominator = 1.0 / abs_value; normal_vectorSP->x *= reciprocal_denominator; normal_vectorSP->y *= reciprocal_denominator; normal_vectorSP->z *= reciprocal_denominator; /* Free storage: */ free (hydrophobicityP); free (projectionsNP); free (cells_usedNP); /* Return positive value on success: */ return 1; } /*===========================================================================*/ garlic-1.6/singlebond.pdb0000644000076500007650000000024207443226725015733 0ustar zuciczucic00000000000000ATOM 1 N GLU 1 0.013 -0.727-100.024 1.00 27.59 2POR 190 ATOM 2 CA GLU 1 -0.013 0.727 -99.976 1.00 36.06 2POR 191 garlic-1.6/comparison_mouse.c0000644000076500007650000002000207747301627016644 0ustar zuciczucic00000000000000/* Copyright (C) 2001-2003 Damir Zucic */ /*============================================================================= comparison_mouse.c Purpose: Handle MotionNotify events if the main window contains the comparison of two sequences. Input: (1) Pointer to RuntimeS structure, with runtime data. (2) Pointer to GUIS structure, with GUI data. (3) Pointer to NearestAtomS structure. (4) The number of pixels in the main window free area. (5) Pointer to XMotionEvent structure. Output: (1) The information about the sequence segment covered by the mouse pointer (and its neighborhood) written to the output window. (2) Return value. Return value: (1) Positive on success. (2) Zero if event is ignored. (3) Negative on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======handle MotionNotify events for sequence comparison:==================*/ int ComparisonMouse_ (RuntimeS *runtimeSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, XMotionEvent *motion_eventSP) { int name_length; int square_width, square_height; int max_screen_x, max_screen_y; int ref_startI, startI; int screen_x, screen_y; int ref_residuesN, residuesN; int first_ref_residueI, first_residueI; int minimal_score; int line_height; int screen_x0, screen_y0; int ref_residueI, residueI; char stringA[SHORTSTRINGSIZE]; int string_width; int localI; size_t pixelI; NearestAtomS *curr_pixelSP; int colorI; int serialI; char *nameP; char nameA[RESNAMESIZE]; /* Residue name length: */ name_length = RESNAMESIZE - 1; /* Initialize square_width and square_height: */ square_width = runtimeSP->zoom_factor; if (square_width < 1) square_width = 1; square_height = runtimeSP->zoom_factor; /* Initialize the width and height of the usable area: */ max_screen_x = guiSP->main_win_free_area_width - 1; max_screen_y = guiSP->main_win_free_area_height - 1; /* Prepare start (offset) indices: */ ref_startI = runtimeSP->reference_offset; startI = runtimeSP->sequence_offset; /* Copy screen coordinates of the mouse pointer: */ screen_x = motion_eventSP->x; screen_y = motion_eventSP->y; /* Numbers of residues: */ ref_residuesN = runtimeSP->reference_residuesN; residuesN = runtimeSP->residuesN; /* Calculate and check the residue indices: */ first_ref_residueI = screen_x / square_width + ref_startI; if (first_ref_residueI < 0) return -1; if (first_ref_residueI >= ref_residuesN) return -2; first_residueI = screen_y / square_height + startI; if (first_residueI < 0) return -3; if (first_residueI >= residuesN) return -4; /* The score associated with the current pair should be found. */ /* The minimal score: */ minimal_score = runtimeSP->minimal_score; /* Prepare and check the pixel index: */ screen_x = square_width * (first_ref_residueI - ref_startI); if ((screen_x < 0) || (screen_x > max_screen_x)) return -5; screen_y = square_height * (first_residueI - startI); if ((screen_y < 0) || (screen_y > max_screen_y)) return -6; pixelI = guiSP->main_win_free_area_width * screen_y + screen_x; if (pixelI >= pixelsN) return -7; /* Pointer to NearestAtomS structure */ /* associated with the current pair: */ curr_pixelSP = nearest_atomSP + pixelI; /* No drawing for pairs with low score: */ /* (score was stored as mol_complexI!) */ if (curr_pixelSP->mol_complexI < minimal_score) return 0; /* Refresh the output window: */ XSetForeground (guiSP->displaySP, guiSP->theGCA[0], guiSP->black_colorID); XFillRectangle (guiSP->displaySP, guiSP->output_winS.ID, guiSP->theGCA[0], 0, 0, guiSP->output_winS.width, guiSP->output_winS.height); /* Prepare three colors for the text: */ /* 0 = red = mismatch */ /* 1 = magenta = acceptable replacement */ /* 2 = yellow = exact match */ XSetForeground (guiSP->displaySP, guiSP->theGCA[0], guiSP->red_colorID); XSetForeground (guiSP->displaySP, guiSP->theGCA[1], guiSP->magenta_colorID); XSetForeground (guiSP->displaySP, guiSP->theGCA[2], guiSP->yellow_colorID); /* Prepare white color for header and lines: */ XSetForeground (guiSP->displaySP, guiSP->theGCA[3], guiSP->white_colorID); /* Text line height: */ line_height = guiSP->output_winS.text_line_height; /* Initialize the string position: */ screen_x0 = guiSP->output_winS.width / 2; screen_y0 = guiSP->output_winS.font_height + 5; /* Draw title: */ strcpy (stringA, "HORIZ."); string_width = XTextWidth (guiSP->main_winS.fontSP, stringA, strlen (stringA)); XDrawString (guiSP->displaySP, guiSP->output_winS.ID, guiSP->theGCA[3], screen_x0 - string_width - 2, screen_y0, stringA, strlen (stringA)); strcpy (stringA, "VERT."); XDrawString (guiSP->displaySP, guiSP->output_winS.ID, guiSP->theGCA[3], screen_x0 + 2, screen_y0, stringA, strlen (stringA)); /* Draw vertical line which divides the output window in two parts: */ XDrawLine (guiSP->displaySP, guiSP->output_winS.ID, guiSP->theGCA[3], screen_x0, 0, screen_x0, guiSP->output_winS.height); /* Draw horizontal line (under the title): */ screen_y0 += 2; XDrawLine (guiSP->displaySP, guiSP->output_winS.ID, guiSP->theGCA[3], 0, screen_y0, guiSP->output_winS.width, screen_y0); /* Scan twenty residues starting from the */ /* first residue; do this for both sequences: */ for (localI = 0; localI < 20; localI++) { /* Update screen_y0: */ screen_y0 += line_height; /* Do not draw text if it falls outside the output window: */ if (screen_y0 > (int) guiSP->output_winS.height + line_height) { continue; } /* Prepare and check local indices for both sequences: */ ref_residueI = first_ref_residueI + localI; if ((ref_residueI < 0) || (ref_residueI >= ref_residuesN)) continue; residueI = first_residueI + localI; if ((residueI < 0) || (residueI >= residuesN)) continue; /* If this point is reached, the current residue pair is available. */ /* Prepare and check the screen */ /* position of the current pair: */ screen_x = (int) square_width * (ref_residueI - ref_startI); if ((screen_x < 0) || (screen_x > max_screen_x)) continue; screen_y = (int) square_height * (residueI - startI); if ((screen_y < 0) || (screen_y > max_screen_y)) continue; /* Prepare and check the pixel index: */ pixelI = guiSP->main_win_free_area_width * screen_y + screen_x; if (pixelI >= pixelsN) continue; /* Pointer to NearestAtomS structure */ /* associated with the current pair: */ curr_pixelSP = nearest_atomSP + pixelI; /* Prepare and check the color index: */ colorI = curr_pixelSP->styleI; if ((colorI != 0) && (colorI != 1) && (colorI != 2)) continue; /* Prepare the reference residue serial number: */ serialI = *(runtimeSP->reference_serialIP + ref_residueI); /* Prepare the reference residue name: */ nameP = runtimeSP->reference_sequenceP + ref_residueI * name_length; strncpy (nameA, nameP, name_length); nameA[name_length] = '\0'; /* The left string contains residue name */ /* and serial number for ref. sequence: */ sprintf (stringA, "%d%s", serialI, nameA); /* Draw the left string: */ string_width = XTextWidth (guiSP->main_winS.fontSP, stringA, strlen (stringA)); XDrawString (guiSP->displaySP, guiSP->output_winS.ID, guiSP->theGCA[colorI], screen_x0 - string_width - 2, screen_y0, stringA, strlen (stringA)); /* Prepare the residue serial number (main sequence): */ serialI = *(runtimeSP->serialIP + residueI); /* Prepare the residue name: */ nameP = runtimeSP->sequenceP + residueI * name_length; strncpy (nameA, nameP, name_length); nameA[name_length] = '\0'; /* The right string contains residue name */ /* and serial number for refer. sequence: */ sprintf (stringA, "%s%d", nameA, serialI); /* Draw the right string: */ XDrawString (guiSP->displaySP, guiSP->output_winS.ID, guiSP->theGCA[colorI], screen_x0 + 2, screen_y0, stringA, strlen (stringA)); } /* Return positive value: */ return 1; } /*===========================================================================*/ garlic-1.6/catch.c0000644000076500007650000001366107612766466014370 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2003 Damir Zucic */ /*============================================================================= catch.c Purpose: Execute catch (take) command: catch the specified macromolecular complex and release all others. Set the new default caught ID and refresh the control window. Reset the group flag (RuntimeS). Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. (3) Pointer to RuntimeS structure, with some runtime data. (4) Pointer to ConfigS structure, with configuration data. (5) Pointer to GUIS structure, with GUI data. (6) Pointer to NearestAtomS structure. (7) The number of pixels in the main window free area. (8) Pointer to refreshI. (9) The string which contains the macromol. complex identifier. Output: (1) The catch flag (catchF) set for each macromolecular complex. (2) Return value. Return value: (1) Positive (command) code on success. (2) Negative (error) code on failure. Notes: (1) This command takes only one argument. If you want to catch more than one macromolecular complex, use command group. (2) This function resets the edit mode index. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "commands.h" #include "typedefs.h" /*======function prototypes:=================================================*/ char *ExtractToken_ (char *, int, char *, char *); size_t MainRefresh_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); int ControlRefresh_ (MolComplexS *, ConfigS *, GUIS *); /*======execute catch command:===============================================*/ int Catch_ (MolComplexS *mol_complexSP, int mol_complexesN, RuntimeS *runtimeSP, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int *refreshIP, char *stringP) { char *remainderP; char tokenA[SHORTSTRINGSIZE]; int complexID; int mol_complexI; MolComplexS *curr_mol_complexSP; int job_doneF = 0; /* Extract the macromolecular complex identifier: */ remainderP = ExtractToken_ (tokenA, SHORTSTRINGSIZE, stringP, " \t\n"); if (!remainderP) { strcpy (runtimeSP->messageA, "Complex identifier missing!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_NO_ID; } /* Read the identifier (integer expected): */ if (sscanf (tokenA, "%d", &complexID) != 1) { strcpy (runtimeSP->messageA, "Bad macromolecular complex identifier!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_BAD_ID; } /* Set the catchF and the group_memberF for the specified complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /** Prepare the pointer to the current macromolecular complex: **/ curr_mol_complexSP = mol_complexSP + mol_complexI; /** Check the number of atoms; for bad **/ /** and discarded complexes it is zero: **/ if (curr_mol_complexSP->atomsN == 0) continue; /** If macromolecular complex is recognized: **/ if (curr_mol_complexSP->mol_complexID == complexID) { /* Set the catchF to one: */ curr_mol_complexSP->catchF = 1; /* Set the group_memberF to zero: */ curr_mol_complexSP->group_memberF = 0; /* Set the flag which says that the complex was found: */ job_doneF = 1; } } /* If complex was not found, return negative value: */ if (job_doneF == 0) { strcpy (runtimeSP->messageA, "Bad complex identifier (out of range)!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_BAD_ID; } /* If complex was found, set all other catch flags to zero: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /** Prepare the pointer to the current macromolecular complex: **/ curr_mol_complexSP = mol_complexSP + mol_complexI; /** For the specified complex, do not reset the catch flag, but **/ /** use the complex index as the index of default caught complex: **/ if (curr_mol_complexSP->mol_complexID == complexID) { runtimeSP->default_complexI = mol_complexI; continue; } /** For all other complexes, set the catch flag to zero: **/ curr_mol_complexSP->catchF = 0; } /* Default editing mode (0, no editing) does not */ /* require redrawing. Other modes require it: */ if (runtimeSP->edit_modeI != 0) { /* Reset the edit mode index: */ runtimeSP->edit_modeI = 0; /* Refresh the main window: */ (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); /* Refresh the control window: */ ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); } /* Don't forget to reset the group flag to zero. If some structures */ /* were grouped before, the command CATCH should break the group: */ runtimeSP->groupF = 0; /* If some structures were involved in a formation of a */ /* group, restore the original rotation center vectors: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Prepare the pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check was this complex a group member: */ if (curr_mol_complexSP->group_memberF == 0) continue; /* If this point is reached, the current complex was a group member. */ /* Restore the original rotation center vector: */ curr_mol_complexSP->rotation_center_vectorS.x = curr_mol_complexSP->backup_vectorS.x; curr_mol_complexSP->rotation_center_vectorS.y = curr_mol_complexSP->backup_vectorS.y; curr_mol_complexSP->rotation_center_vectorS.z = curr_mol_complexSP->backup_vectorS.z; /* Reset the group_memberF: */ curr_mol_complexSP->group_memberF = 0; } /* Return positive value on success: */ return COMMAND_CATCH; } /*===========================================================================*/ garlic-1.6/spacefill.c0000644000076500007650000003137107747301300015223 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2003 Damir Zucic */ /*============================================================================= spacefill.c Purpose: Draw atoms as spheres (spacefill style). Input: (1) Pointer to MolComplexS structure. (2) Number of macromolecular complexes. (3) Pointer to ConfigS structure, with configuration data. (4) Pointer to GUIS structure. (5) Pointer to NearestAtomS structure, with information about the atom occupying the given pixel. (6) The number of pixels in the main window free area. (7) The refreshI, used to check the NearestAtomS associated with a given pixel. Output: (1) Spheres drawn to the hidden pixmap. (2) Return value. Return value: (1) Positive always (trivial). Notes: (1) Indentation is exceptionally 4 spaces. =============================================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ unsigned long SpacefillColor_ (AtomS *, GUIS *, double); /*======draw atoms as spheres:===============================================*/ int DrawSpacefill_ (MolComplexS *mol_complexSP, int mol_complexesN, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int refreshI) { int imageI, imagesN; double scale_factor, user_atomic_position; int left_edge[2], right_edge[2]; int mol_complexI; MolComplexS *curr_mol_complexSP; size_t atomsN, atomI; AtomS *curr_atomSP; int screen_x0, screen_y0; double radius, radius_squared; double denominator, reciprocal_denominator; int screen_radius; long screen_radius_squared; int screen_x1, screen_y1, screen_x2, screen_y2; int screen_x, screen_y; long delta_x, delta_y, distance_squared; double z0, front_z, delta_z, z; size_t pixelI; NearestAtomS *curr_pixelSP; double denominator2, reciprocal_denominator2; double rho_squared; VectorS vectorS; double abs_value, abs_value_squared; double scalar_product, cos_angle; unsigned long colorID; int bondI; /* Initialize the bond index. The negative value means that pixels */ /* filled in this function are not a part of any chemical bond. */ bondI = -1; /* Number of images: */ if (configSP->stereoF) imagesN = 2; else imagesN = 1; /* The auxiliary scale factor: */ scale_factor = configSP->user_screen_atomic_distance * configSP->atomic_to_screen_scale_x; /* Prepare the user position in atomic coordinates: */ user_atomic_position = configSP->user_atomic_position; /* Left and right image edge (in stereo mode there are two images): */ left_edge[0] = configSP->image_screen_x0[0]; right_edge[0] = configSP->image_screen_x1[0]; left_edge[1] = configSP->image_screen_x0[1]; right_edge[1] = configSP->image_screen_x1[1]; /*------first pass - fill NearestAtomS array with planar atoms:--------------*/ /* Draw each macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Prepare and check the number of atoms: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Draw atoms which have the given style: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Check style: */ if (curr_atomSP->raw_atomS.atom_styleI != SPACEFILL) continue; /* Check is atom hidden: */ if (curr_atomSP->hiddenF) continue; /* Check is atom inside slab: */ if (!curr_atomSP->inside_slabF) continue; /* Check is atom inside window: */ if (!curr_atomSP->inside_windowF) continue; /* Atomic radius, in atomic units: */ radius = curr_atomSP->raw_atomS.radius; /* The y coordinate of atomic center, in screen units: */ screen_y0 = curr_atomSP->raw_atomS.screen_y; /* Prepare one image (mono) or two images (stereo): */ for (imageI = 0; imageI < imagesN; imageI++) { /* The z coordinate of atomic center, in atomic units: */ z0 = curr_atomSP->raw_atomS.z[imageI]; /* Prepare the factor required for projection of atomic radius: */ denominator = z0 - user_atomic_position; if (denominator == 0.0) continue; reciprocal_denominator = 1.0 / denominator; /* Atomic radius in screen units: */ screen_radius = (int) (radius * scale_factor * reciprocal_denominator + 0.5); /* Screen radius squared (used to improve speed): */ screen_radius_squared = (long) screen_radius * (long) screen_radius; /* The x coordinate of atomic center, in screen units: */ screen_x0 = curr_atomSP->raw_atomS.screen_x[imageI]; /* Define the bounding rectangle: */ screen_x1 = screen_x0 - screen_radius; screen_y1 = screen_y0 - screen_radius; screen_x2 = screen_x0 + screen_radius; screen_y2 = screen_y0 + screen_radius; /* Horizontal scan: */ for (screen_x = screen_x1; screen_x <= screen_x2; screen_x++) { /* Check horizontal position: */ if (screen_x < left_edge[imageI]) continue; if (screen_x >= right_edge[imageI]) continue; /* Vertical scan: */ for (screen_y = screen_y1; screen_y <= screen_y2; screen_y++) { /* Check vertical position: */ if (screen_y < 0) continue; if (screen_y >= (int) guiSP->main_win_free_area_height) { continue; } /* Check distance from the circle center: */ delta_x = (long) (screen_x - screen_x0); delta_y = (long) (screen_y - screen_y0); distance_squared = delta_x * delta_x + delta_y * delta_y; if (distance_squared > screen_radius_squared) continue; /* Prepare index to the array */ /* of NearestAtomS structures: */ pixelI = guiSP->main_win_free_area_width * screen_y + screen_x; /* Check the pixel index: */ if (pixelI >= pixelsN) continue; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = nearest_atomSP + pixelI; /* Check was this pixel used already in */ /* this drawing step; if it was, compare */ /* the z value of the current atom with z */ /* value previously stored to this pixel: */ if (refreshI == curr_pixelSP->last_refreshI) { if (z0 > curr_pixelSP->z) continue; } /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = SPACEFILL; curr_pixelSP->last_refreshI = refreshI; curr_pixelSP->mol_complexI = mol_complexI; curr_pixelSP->atomI = atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = z0; } } } /* imageI loop */ } /* atomI loop */ } /* mol_complexI loop */ /*------second pass - draw spherical atoms:----------------------------------*/ /* Draw each macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Prepare and check the number of atoms: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Draw atoms which have the given style: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Check style: */ if (curr_atomSP->raw_atomS.atom_styleI != SPACEFILL) continue; /* Check is atom hidden: */ if (curr_atomSP->hiddenF) continue; /* Check is atom inside slab: */ if (!curr_atomSP->inside_slabF) continue; /* Check is atom inside window: */ if (!curr_atomSP->inside_windowF) continue; /* Atomic radius, in atomic units: */ radius = curr_atomSP->raw_atomS.radius; /* Squared atomic radius: */ radius_squared = radius * radius; /* The y coordinate of atomic center, in screen units: */ screen_y0 = curr_atomSP->raw_atomS.screen_y; /* Prepare one image (mono) or two images (stereo): */ for (imageI = 0; imageI < imagesN; imageI++) { /* The z coordinate of atomic center, in atomic units: */ z0 = curr_atomSP->raw_atomS.z[imageI]; /* The z coordinate of the nearest */ /* point of a given atom (sphere): */ front_z = z0 - radius; /* Prepare the factor required for projection of atomic radius: */ denominator = z0 - user_atomic_position; if (denominator == 0.0) continue; reciprocal_denominator = 1.0 / denominator; /* Atomic radius in screen units: */ screen_radius = (int) (radius * scale_factor * reciprocal_denominator + 0.5); /* Square of the atomic radius (in screen units): */ screen_radius_squared = (long) screen_radius * (long) screen_radius; /* Reciprocal value will be used to improve performance: */ denominator2 = (double) screen_radius_squared; if (denominator2 == 0.0) continue; reciprocal_denominator2 = 1.0 / denominator2; /* The x coordinate of atomic center, in screen units: */ screen_x0 = curr_atomSP->raw_atomS.screen_x[imageI]; /* Define the bounding rectangle: */ screen_x1 = screen_x0 - screen_radius; screen_y1 = screen_y0 - screen_radius; screen_x2 = screen_x0 + screen_radius; screen_y2 = screen_y0 + screen_radius; /* Horizontal scan: */ for (screen_x = screen_x1; screen_x <= screen_x2; screen_x++) { /* Check horizontal position: */ if (screen_x < left_edge[imageI]) continue; if (screen_x > right_edge[imageI]) continue; /* Vertical scan: */ for (screen_y = screen_y1; screen_y <= screen_y2; screen_y++) { /* Check vertical position: */ if (screen_y < 0) continue; if (screen_y >= (int) guiSP->main_win_free_area_height) { continue; } /* Check distance from the circle center: */ delta_x = (long) (screen_x - screen_x0); delta_y = (long) (screen_y - screen_y0); distance_squared = delta_x * delta_x + delta_y * delta_y; if (distance_squared > screen_radius_squared) continue; /* Prepare index to the array */ /* of NearestAtomS structures: */ pixelI = guiSP->main_win_free_area_width * screen_y + screen_x; /* Check the pixel index: */ if (pixelI >= pixelsN) continue; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = nearest_atomSP + pixelI; /* Check z value (this is just a quick check): */ if (refreshI == curr_pixelSP->last_refreshI) { if (front_z > curr_pixelSP->z) continue; } /* Calculate the accurate z value: */ rho_squared = radius_squared * (double) distance_squared * reciprocal_denominator2; delta_z = sqrt (fabs (radius_squared - rho_squared)); z = z0 - delta_z; /* Check z value (precise check): */ if (refreshI == curr_pixelSP->last_refreshI) { if (z > curr_pixelSP->z) continue; } /* The vector from sphere center to the current pixel: */ vectorS.x = (double) delta_x; vectorS.y = (double) delta_y; vectorS.z = - sqrt (fabs (screen_radius_squared - vectorS.x * vectorS.x - vectorS.y * vectorS.y)); abs_value_squared = vectorS.x * vectorS.x + vectorS.y * vectorS.y + vectorS.z * vectorS.z; abs_value = sqrt (abs_value_squared); /* The scalar product between this */ /* vector and light source vector: */ scalar_product = vectorS.x * configSP->light_vectorS.x + vectorS.y * configSP->light_vectorS.y + vectorS.z * configSP->light_vectorS.z; /* Cosine of the angle between the vector to the */ /* current pixel and the light source unit vector: */ if (abs_value == 0.0) cos_angle = 0.0; else cos_angle = scalar_product / abs_value; /* Prepare color: */ colorID = SpacefillColor_ (curr_atomSP, guiSP, cos_angle); XSetForeground (guiSP->displaySP, guiSP->theGCA[0], colorID); XDrawPoint (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x, screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = SPACEFILL; curr_pixelSP->last_refreshI = refreshI; curr_pixelSP->mol_complexI = mol_complexI; curr_pixelSP->atomI = atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = z; curr_pixelSP->colorID = colorID; } } } /* imageI loop */ } /* atomI loop */ } /* mol_complexI loop */ /*---------------------------------------------------------------------------*/ /* Return positive value (trivial): */ return 1; } /*===========================================================================*/ garlic-1.6/rotate_atom.c0000644000076500007650000001106607311513312015571 0ustar zuciczucic00000000000000/* Copyright (C) 2001 Damir Zucic */ /*============================================================================= rotate_atom.c Purpose: Rotate the given atom about the given axis. The axis is defined by two points (vectors). The vector from the first point to the second point defines the axis direction. The right-handed rotation is positive and the left-handed rotation is negative. Input: (1) Pointer to AtomS structure. (2) Pointer to VectorS structure (the first point). (3) Pointer to VectorS structure (the second point). (4) The rotation angle. Output: (1) Atom position changed. (2) Return value. Return value: (1) Positive on success. (2) Negative on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ double AbsoluteValue_ (VectorS *); int ParallelPart_ (VectorS *, VectorS *, VectorS *); void VectorProduct_ (VectorS *, VectorS *, VectorS *); double ScalarProduct_ (VectorS *, VectorS *); /*======rotate atom about given axis:========================================*/ int RotateAtom_ (AtomS *atomSP, VectorS *vector1SP, VectorS *vector2SP, double angle) { VectorS rot_axis_vectorS; double abs_value; VectorS radius_vectorS; VectorS parallel_vectorS; VectorS perpendicular_vectorS; double perpendicular_part; double reciprocal_abs_value; VectorS unit_vector1S, unit_vector2S; double cos_angle, sin_angle; double p1_new, p2_new; /* Prepare the vector which defines the rotation axis: */ rot_axis_vectorS.x = vector2SP->x - vector1SP->x; rot_axis_vectorS.y = vector2SP->y - vector1SP->y; rot_axis_vectorS.z = vector2SP->z - vector1SP->z; /* Check the absolute value of the rotation axis vector: */ abs_value = AbsoluteValue_ (&rot_axis_vectorS); if (abs_value <= 0.0) return -1; /* Prepare the radius vector of the given atom: */ radius_vectorS.x = atomSP->raw_atomS.x[0] - vector1SP->x; radius_vectorS.y = atomSP->raw_atomS.y - vector1SP->y; radius_vectorS.z = atomSP->raw_atomS.z[0] - vector1SP->z; /* Find the part of the radius vector which is parallel to the rotation */ /* axis. Note that we need the vector, not just the absolute value! */ ParallelPart_ (¶llel_vectorS, &rot_axis_vectorS, &radius_vectorS); /* Find the part of the radius vector which */ /* is perpendicular to the rotation axis: */ perpendicular_vectorS.x = radius_vectorS.x - parallel_vectorS.x; perpendicular_vectorS.y = radius_vectorS.y - parallel_vectorS.y; perpendicular_vectorS.z = radius_vectorS.z - parallel_vectorS.z; /* Prepare and check the absolute value of the perpendicular part: */ perpendicular_part = AbsoluteValue_ (&perpendicular_vectorS); if (perpendicular_part <= 0.0) return -2; /* Prepare the first unit vector, required for rotation: */ reciprocal_abs_value = 1.0 / perpendicular_part; unit_vector1S.x = reciprocal_abs_value * perpendicular_vectorS.x; unit_vector1S.y = reciprocal_abs_value * perpendicular_vectorS.y; unit_vector1S.z = reciprocal_abs_value * perpendicular_vectorS.z; /* Prepare and check the second unit vector: */ VectorProduct_ (&unit_vector2S, &rot_axis_vectorS, &unit_vector1S); abs_value = AbsoluteValue_ (&unit_vector2S); if (abs_value <= 0.0) return -3; reciprocal_abs_value = 1.0 / abs_value; unit_vector2S.x = reciprocal_abs_value * unit_vector2S.x; unit_vector2S.y = reciprocal_abs_value * unit_vector2S.y; unit_vector2S.z = reciprocal_abs_value * unit_vector2S.z; /* Rotate the perpendicular vector: */ cos_angle = cos (angle); sin_angle = sin (angle); p1_new = perpendicular_part * cos_angle; p2_new = perpendicular_part * sin_angle; perpendicular_vectorS.x = p1_new * unit_vector1S.x + p2_new * unit_vector2S.x; perpendicular_vectorS.y = p1_new * unit_vector1S.y + p2_new * unit_vector2S.y; perpendicular_vectorS.z = p1_new * unit_vector1S.z + p2_new * unit_vector2S.z; /* Update the radius vector: */ radius_vectorS.x = parallel_vectorS.x + perpendicular_vectorS.x; radius_vectorS.y = parallel_vectorS.y + perpendicular_vectorS.y; radius_vectorS.z = parallel_vectorS.z + perpendicular_vectorS.z; /* Update the atomic coordinates: */ atomSP->raw_atomS.x[0] = radius_vectorS.x + vector1SP->x; atomSP->raw_atomS.y = radius_vectorS.y + vector1SP->y; atomSP->raw_atomS.z[0] = radius_vectorS.z + vector1SP->z; /* Return positive value (success indicator): */ return 1; } /*===========================================================================*/ garlic-1.6/ex_template_residues.c0000644000076500007650000001165107264302164017475 0ustar zuciczucic00000000000000/* Copyright (C) 2001 Damir Zucic */ /*============================================================================= ex_template_residues.c Purpose: Extract template residues. Remove whitespace from residue names. In addition, add residue array index to each atom. Input: (1) Pointer to RuntimeS structure, which should contain template atoms. Output: (1) An array of ResidueS structures allocated and initialized. (2) Return value. Return value: (1) The number of template residues (positive or zero). (2) Negative on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int CountTemplateResidues_ (RuntimeS *); void ErrorMessage_ (char *, char *, char *, char *, char *, char *, char *); /*======extract template residues:===========================================*/ int ExtractTemplateResidues_ (RuntimeS *runtimeSP) { int template_atomsN, template_atomI; int template_residuesN, template_residueI = 0; size_t struct_size, elementsN; AtomS *curr_atomSP; int previous_residueI, current_residueI; int previous_insertion_code, current_insertion_code; ResidueS *current_residueSP; ResidueS *previous_residueSP; /* Initialize the number of template residues: */ runtimeSP->template_residuesN = 0; /* Check the number of template atoms: */ template_atomsN = runtimeSP->template_atomsN; if (template_atomsN == 0) return 0; /* Count the template residues; return negative if there are no residues: */ template_residuesN = CountTemplateResidues_ (runtimeSP); if (template_residuesN == 0) return -1; /* Store the number of template residues: */ runtimeSP->template_residuesN = template_residuesN; /* Allocate the storage for template residues: */ struct_size = sizeof (ResidueS); elementsN = template_residuesN + 10; runtimeSP->template_residueSP = (ResidueS *) calloc (elementsN, struct_size); if (runtimeSP->template_residueSP == NULL) { ErrorMessage_ ("garlic", "ExtractTemplateResidues_", "", "Failed to allocate memory for template residues!\n", "", "", ""); return -2; } /* The first atom has a special treatment: */ curr_atomSP = runtimeSP->template_atomSP; curr_atomSP->residue_arrayI = 0; previous_residueI = curr_atomSP->raw_atomS.residue_sequenceI; previous_insertion_code = curr_atomSP->raw_atomS.residue_insertion_code; /* Extract residue information, but skip the first atom: */ for (template_atomI = 1; template_atomI < template_atomsN; template_atomI++) { /* Pointer to raw atomic data: */ curr_atomSP = runtimeSP->template_atomSP + template_atomI; /* Copy the residue sequence number and residue insertion code: */ current_residueI = curr_atomSP->raw_atomS.residue_sequenceI; current_insertion_code = curr_atomSP->raw_atomS.residue_insertion_code; /* Compare the current residue sequence number with the old one */ /* and the current residue insertion code with the old code. */ /* If this atom belongs to the same residue as the previous */ /* one, set the residue array index and take the next atom: */ if ((current_residueI == previous_residueI) && (current_insertion_code == previous_insertion_code)) { curr_atomSP->residue_arrayI = template_residueI; continue; } /* If this atom does not belong to the same residue as */ /* the previous one, increment the residue array index */ /* by one and assign the incremented value to this atom: */ else { template_residueI++; curr_atomSP->residue_arrayI = template_residueI; } /* If this point is reached, a new residue is found. */ /* Prepare the pointer to the current residue: */ current_residueSP = runtimeSP->template_residueSP + template_residueI; /* The residue start index for the current residue: */ current_residueSP->residue_startI = template_atomI; /* The initial (dummy) residue end index for the current residue: */ current_residueSP->residue_endI = template_atomI; /* The residue end index for the previous residue: */ if (template_residueI != 0) { previous_residueSP = runtimeSP->template_residueSP + template_residueI - 1; if (template_atomI != 0) { previous_residueSP->residue_endI = template_atomI - 1; } } /* Copy the residue sequence index and residue insertion code: */ previous_residueI = current_residueI; previous_insertion_code = current_insertion_code; } /* The residue end index for the last residue: */ if (template_residueI != 0) { previous_residueSP = runtimeSP->template_residueSP + template_residueI; if (template_atomI != 0) { previous_residueSP->residue_endI = template_atomI - 1; } } /* If this point is reached, return the number of template residues: */ return template_residuesN; } /*===========================================================================*/ garlic-1.6/barrel.script0000644000076500007650000000022310120035425015571 0ustar zuciczucic00000000000000# Playing with porin. # please load some porin structure before executing this script! bac 4 color cyan-blue sel het sel com seq from 1 sca oct garlic-1.6/control_click.c0000644000076500007650000002760307305722767016127 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= control_click.c Purpose: Handle ButtonPress event which came from control window. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. (3) Pointer to RuntimeS structure. (4) Pointer to ConfigS structure, with configuration data. (5) Pointer to GUIS structure, with GUI data. (6) Pointer to NearestAtomS structure. (7) The number of pixels in the main window free area. (8) Pointer to refreshI. (9) Pointer to XButtonEvent structure. Output: (1) The click may cause rotation, translation, slab change or fading change. (2) Return value. Return value: (1) Positive if some transformation is done. (2) Zero if click is ignored (no button pressed). Notes: (1) Indices are assigned as follows: 0 = KP_0 1 = KP_1 2 = KP_2 3 = KP_3 4 = KP_4 5 = KP_5 6 = KP_6 7 = KP_7 8 = KP_8 9 = KP_9 10 = KP_Decimal 11 = KP_Enter 12 = KP_Add 13 = KP_Subtract 14 = KP_Multiply 15 = KP_Divide 16 = F1 17 = F2 18 = F3 19 = F4 ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int IdentifyButton_ (XButtonEvent *, GUIS *); size_t MainRefresh_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); int ControlRefresh_ (MolComplexS *, ConfigS *, GUIS *); int DockingRefresh_ (RuntimeS *, GUIS *); double TranslationShift_ (ConfigS *, GUIS *, double); void Translate_ (MolComplexS *, int, RuntimeS *, ConfigS *, double, int); double RotationAngle_ (ConfigS *, GUIS *, double); int Rotate_ (MolComplexS *, int, RuntimeS *, ConfigS *, double, int); double SlabShift_ (ConfigS *, GUIS *, double); void MoveBackSlab_ (MolComplexS *, int, ConfigS *, double); void MoveFrontSlab_ (MolComplexS *, int, ConfigS *, double); double FadingShift_ (ConfigS *, GUIS *, double); void MoveBackFading_ (MolComplexS *, int, ConfigS *, double); void MoveFrontFading_ (MolComplexS *, int, ConfigS *, double); /*======handle ButtonPress from control window:==============================*/ int ControlClick_ (MolComplexS *mol_complexSP, int mol_complexesN, RuntimeS *runtimeSP, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int *refreshIP, XButtonEvent *button_eventSP) { int buttonI; double shift; double rotation_angle; /* Identify dummy button which was pressed: */ buttonI = IdentifyButton_ (button_eventSP, guiSP); /* Hit or miss: */ if (buttonI < 0) return 0; /* Apply the requested transformation: */ switch (buttonI) { /* Translation along z, negative shift: */ case 0: (*refreshIP)++; shift = TranslationShift_ (configSP, guiSP, -1.0); Translate_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, shift, 3); MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); if (guiSP->dockingF) DockingRefresh_ (runtimeSP, guiSP); break; /* Move back slab surface along z, positive shift: */ case 1: (*refreshIP)++; shift = SlabShift_ (configSP, guiSP, 1.0); MoveBackSlab_ (mol_complexSP, mol_complexesN, configSP, shift); MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); break; /* Positive rotation around x: */ case 2: (*refreshIP)++; rotation_angle = RotationAngle_ (configSP, guiSP, 1.0); Rotate_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, rotation_angle, 1); MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); if (guiSP->dockingF) DockingRefresh_ (runtimeSP, guiSP); break; /* Move back slab surface along z, negative shift: */ case 3: (*refreshIP)++; shift = SlabShift_ (configSP, guiSP, -1.0); MoveBackSlab_ (mol_complexSP, mol_complexesN, configSP, shift); MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); break; /* Positive rotation around y: */ case 4: (*refreshIP)++; rotation_angle = RotationAngle_ (configSP, guiSP, +1.0); Rotate_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, rotation_angle, 2); MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); if (guiSP->dockingF) DockingRefresh_ (runtimeSP, guiSP); break; /* Translation along z, positive shift: */ case 5: (*refreshIP)++; shift = TranslationShift_ (configSP, guiSP, +1.0); Translate_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, shift, 3); MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); if (guiSP->dockingF) DockingRefresh_ (runtimeSP, guiSP); break; /* Negative rotation around y: */ case 6: (*refreshIP)++; rotation_angle = RotationAngle_ (configSP, guiSP, -1.0); Rotate_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, rotation_angle, 2); MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); if (guiSP->dockingF) DockingRefresh_ (runtimeSP, guiSP); break; /* Negative rotation around z: */ case 7: (*refreshIP)++; rotation_angle = RotationAngle_ (configSP, guiSP, -1.0); Rotate_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, rotation_angle, 3); MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); if (guiSP->dockingF) DockingRefresh_ (runtimeSP, guiSP); break; /* Negative rotation aroung x: */ case 8: (*refreshIP)++; rotation_angle = RotationAngle_ (configSP, guiSP, -1.0); Rotate_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, rotation_angle, 1); MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); if (guiSP->dockingF) DockingRefresh_ (runtimeSP, guiSP); break; /* Positive rotation around z: */ case 9: (*refreshIP)++; rotation_angle = RotationAngle_ (configSP, guiSP, +1.0); Rotate_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, rotation_angle, 3); MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); if (guiSP->dockingF) DockingRefresh_ (runtimeSP, guiSP); break; /* Move front slab surface along z, positive shift: */ case 10: (*refreshIP)++; shift = SlabShift_ (configSP, guiSP, 1.0); MoveFrontSlab_ (mol_complexSP, mol_complexesN, configSP, shift); MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); break; /* Move front slab surface along z, negative shift: */ case 11: (*refreshIP)++; shift = SlabShift_ (configSP, guiSP, -1.0); MoveFrontSlab_ (mol_complexSP, mol_complexesN, configSP, shift); MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); break; /* Translation along y, positive shift: */ case 12: (*refreshIP)++; shift = TranslationShift_ (configSP, guiSP, +1.0); Translate_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, shift, 2); MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); if (guiSP->dockingF) DockingRefresh_ (runtimeSP, guiSP); break; /* Translation along y, negative shift: */ case 13: (*refreshIP)++; shift = TranslationShift_ (configSP, guiSP, -1.0); Translate_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, shift, 2); MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); if (guiSP->dockingF) DockingRefresh_ (runtimeSP, guiSP); break; /* Translation along x, positive shift: */ case 14: (*refreshIP)++; shift = TranslationShift_ (configSP, guiSP, +1.0); Translate_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, shift, 1); MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); if (guiSP->dockingF) DockingRefresh_ (runtimeSP, guiSP); break; /* Translation along x, negative shift: */ case 15: (*refreshIP)++; shift = TranslationShift_ (configSP, guiSP, -1.0); Translate_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, shift, 1); MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); if (guiSP->dockingF) DockingRefresh_ (runtimeSP, guiSP); break; /* Move back fading surface, positive shift: */ case 16: (*refreshIP)++; shift = FadingShift_ (configSP, guiSP, 1.0); MoveBackFading_ (mol_complexSP, mol_complexesN, configSP, shift); MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); break; /* Move back fading surface, negative shift: */ case 17: (*refreshIP)++; shift = FadingShift_ (configSP, guiSP, -1.0); MoveBackFading_ (mol_complexSP, mol_complexesN, configSP, shift); MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); break; /* Move front fading surface, positive shift: */ case 18: (*refreshIP)++; shift = FadingShift_ (configSP, guiSP, 1.0); MoveFrontFading_ (mol_complexSP, mol_complexesN, configSP, shift); MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); break; /* Move front fading surface, negative shift: */ case 19: (*refreshIP)++; shift = FadingShift_ (configSP, guiSP, -1.0); MoveFrontFading_ (mol_complexSP, mol_complexesN, configSP, shift); MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); break; /* Unresolved: */ default: ; } /* Return positive value: */ return 1; } /*===========================================================================*/ garlic-1.6/translate_complex.c0000644000076500007650000000731607363357073017023 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= translate_complex.c Purpose: In default editing mode (0 = no editing), translate the macromol. complex and update the geometric, slab and color fading center. If editing atoms (editing mode 1), translate only the selected atoms and leave the geometric parameters unchanged. Input: (1) Pointer to MolComplexS structure, with macromolecular data to be modified. (2) Pointer to VectorS structure, with shift vector. (3) Pointer to ConfigS structure (stereo flag used). (4) Editing mode index (0 = no editing, 1 = editing atoms etc.). Output: (1) The structure will be translated. Return value: No return value. ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======translate macromolecular complex:====================================*/ void TranslateComplex_ (MolComplexS *mol_complexSP, VectorS *shift_vectorSP, ConfigS *configSP, int edit_modeI) { size_t i; AtomS *curr_atomSP; /* Translate all atoms: */ for (i = 0; i < mol_complexSP->atomsN; i++) { /* Pointer to the current atom: */ curr_atomSP = mol_complexSP->atomSP + i; /* If editing atoms, do not translate */ /* this atom if it is not selected: */ if (edit_modeI == 1) { if (curr_atomSP->selectedF == 0) continue; } /* Translate atom: */ curr_atomSP->raw_atomS.x[0] += shift_vectorSP->x; curr_atomSP->raw_atomS.y += shift_vectorSP->y; curr_atomSP->raw_atomS.z[0] += shift_vectorSP->z; } if (configSP->stereoF) { for (i = 0; i < mol_complexSP->atomsN; i++) { /* Pointer to the current atom: */ curr_atomSP = mol_complexSP->atomSP + i; /* If editing atoms, do not translate */ /* this atom if it is not selected: */ if (edit_modeI == 1) { if (curr_atomSP->selectedF == 0) continue; } /* Translate atom: */ curr_atomSP->raw_atomS.x[1] += shift_vectorSP->x; curr_atomSP->raw_atomS.z[1] += shift_vectorSP->z; } } /* If not editing atoms, update geometric center and some other data: */ if (edit_modeI != 1) { /* Update the geometric center: */ mol_complexSP->geometric_center_vectorS.x += shift_vectorSP->x; mol_complexSP->geometric_center_vectorS.y += shift_vectorSP->y; mol_complexSP->geometric_center_vectorS.z += shift_vectorSP->z; /* Update the extent vectors: */ mol_complexSP->left_top_near_vectorS.x += shift_vectorSP->x; mol_complexSP->left_top_near_vectorS.y += shift_vectorSP->y; mol_complexSP->left_top_near_vectorS.z += shift_vectorSP->z; mol_complexSP->right_bottom_far_vectorS.x += shift_vectorSP->x; mol_complexSP->right_bottom_far_vectorS.y += shift_vectorSP->y; mol_complexSP->right_bottom_far_vectorS.z += shift_vectorSP->z; /* Update the rotation center: */ mol_complexSP->rotation_center_vectorS.x += shift_vectorSP->x; mol_complexSP->rotation_center_vectorS.y += shift_vectorSP->y; mol_complexSP->rotation_center_vectorS.z += shift_vectorSP->z; /* Update the slab center: */ mol_complexSP->slab_center_vectorS.x += shift_vectorSP->x; mol_complexSP->slab_center_vectorS.y += shift_vectorSP->y; mol_complexSP->slab_center_vectorS.z += shift_vectorSP->z; /* Update the color fading center: */ mol_complexSP->fading_center_vectorS.x += shift_vectorSP->x; mol_complexSP->fading_center_vectorS.y += shift_vectorSP->y; mol_complexSP->fading_center_vectorS.z += shift_vectorSP->z; } /* Update the position_changedF flag: */ mol_complexSP->position_changedF = 1; } /*===========================================================================*/ garlic-1.6/select_2cz3.c0000644000076500007650000001546710153564241015411 0ustar zuciczucic00000000000000/* Copyright (C) 2004 Damir Zucic */ /*============================================================================= select_2cz3.c Purpose: Select the sequence fragment which contains two or more charged or zwitterionic residues in a window of three residues. ASP, GLU, ASN, GLN, ARG, LYS and HIS are taken into account. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. (3) Selection mode index (0 = overwrite, 1 = restrict, 2 = expand previous selection). Output: (1) The flag selectedF set to one for selected atoms in every caught macromolecular complex. (2) Return value. Return value: (1) The number of selected atoms (zero or positive value). ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======select two or more charged or zwitterionic residues:=================*/ long Select2CZ3_ (MolComplexS *mol_complexSP, int mol_complexesN, int selection_modeI) { long selected_atomsN = 0; int mol_complexI; MolComplexS *curr_mol_complexSP; int atomsN, atomI; AtomS *curr_atomSP; int residuesN, residueI, windowI, combinedI; ResidueS *curr_residueSP; AtomS *first_atomSP; char *nameP; int very_polarN; int first_atomI, last_atomI; /* Check every macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check is the current macromolecular complex caught: */ if (curr_mol_complexSP->catchF == 0) continue; /* Prepare and check the number of atoms in the current complex: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Copy the number of residues in the current macromol. complex: */ residuesN = curr_mol_complexSP->residuesN; if (residuesN == 0) continue; /* Backup the current selection if selection mode is restrict: */ if (selection_modeI == 1) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Copy the selection flag: */ curr_atomSP->previous_selectedF = curr_atomSP->selectedF; } } /* Unselect everything if selection mode is overwrite or restrict: */ if ((selection_modeI == 0) || (selection_modeI == 1)) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Unselect the current atom: */ curr_atomSP->selectedF = 0; } } /* Scan the residues of the current macromolecular complex: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Reset the counter which counts very polar residues: */ very_polarN = 0; /* Scan the window of four residues, */ /* starting from the current residue: */ for (windowI = 0; windowI < 3; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI >= residuesN) break; /* Residue associated with the combined index: */ curr_residueSP = curr_mol_complexSP->residueSP + combinedI; /* Pointer to the first atom of current residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Pointer to the name of the current residue: */ nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Check is this residue very polar: */ if ((strcmp (nameP, "ASP") == 0) || (strcmp (nameP, "GLU") == 0) || (strcmp (nameP, "ASN") == 0) || (strcmp (nameP, "GLN") == 0) || (strcmp (nameP, "ARG") == 0) || (strcmp (nameP, "LYS") == 0) || (strcmp (nameP, "HIS") == 0)) very_polarN++; } /* If there were two or more very polar residues in */ /* a window of three residues, the dublet is found. */ /* If there was one or less, take the next residue. */ if (very_polarN < 2) continue; /* If this point is reached, scan the window of four */ /* residues again and select very polar residues. */ /* Scan the window of four residues, */ /* starting from the current residue: */ for (windowI = 0; windowI < 3; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI >= residuesN) break; /* Residue associated with the combined index: */ curr_residueSP = curr_mol_complexSP->residueSP + combinedI; /* Pointer to the first atom of current residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Pointer to the name of the current residue: */ nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Check is this residue very polar: */ if ((strcmp (nameP, "ASP") != 0) && (strcmp (nameP, "GLU") != 0) && (strcmp (nameP, "ASN") != 0) && (strcmp (nameP, "GLN") != 0) && (strcmp (nameP, "ARG") != 0) && (strcmp (nameP, "LYS") != 0) && (strcmp (nameP, "HIS") != 0)) continue; /* If this point is reached, select */ /* all atoms of the current residue. */ /* The indices of the first and the */ /* last atom of the current residue: */ first_atomI = curr_residueSP->residue_startI; last_atomI = curr_residueSP->residue_endI; /* Select all atoms of the current residue: */ for (atomI = first_atomI; atomI <= last_atomI; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Select the current atom: */ curr_atomSP->selectedF = 1; /* Update the counter of selected atoms: */ selected_atomsN++; } } /* End of residueI loop: */ } /* Combine the current selection with the */ /* previous, if selection mode is restrict: */ if (selection_modeI == 1) { /* Reset the counter of selected atoms. The */ /* selected atoms should be counted again. */ selected_atomsN = 0; /* Combine the old and the new selection flag: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Combine selection flags: */ curr_atomSP->selectedF *= curr_atomSP->previous_selectedF; /* Check the selection flag; increase */ /* the count of selected residues if */ /* the selection flag is equal to one: */ if (curr_atomSP->selectedF) selected_atomsN++; } } /* Update the position_changedF (some atoms may have bad color): */ curr_mol_complexSP->position_changedF = 1; /* End of mol_complexI loop: */ } /* Return the number of selected atoms: */ return selected_atomsN; } /*===========================================================================*/ garlic-1.6/draw_comparison.c0000644000076500007650000003344207461732023016454 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2002 Damir Zucic */ /*============================================================================= draw_comparison.c Purpose: Draw sequence comparison. Input: (1) Pointer to RuntimeS structure, with some runtime data. (2) Pointer to GUIS structure, with GUI data. (3) Pointer to NearestAtomS structure, with information about the atom occupying the given pixel. (4) The number of pixels in the main window free area. (5) The refreshI, used to check the NearestAtomS associated with a given pixel. Output: (1) Sequence comparison should be drawn to the main window. (2) Return value. Return value: (1) The number of dots drawn. Notes: (1) The initial drawing destination is the hidden pixmap, and the content of this pixmap is copied later to the main window. (2) The x axis is used for the reference sequence and the y axis is used for the sequence from the general purpose buffer. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int RefreshPixmap_ (Display *, Pixmap, GC, unsigned int, unsigned int, unsigned long); /*======draw sequence comparison:============================================*/ size_t DrawComparison_ (RuntimeS *runtimeSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int refreshI) { size_t dots_drawnN = 0; int max_length; unsigned int square_width, square_height; int max_screen_x0, max_screen_y0; int ref_residueI, ref_startI, ref_endI, ref_residuesN; int residueI, startI, endI, residuesN; char *ref_residue_nameP; char *residue_nameP; int *reference_codeIP, *codeIP; int nameI, namesN = 23; static char nameAA[23][4] = {"ALA","ASX","CYS","ASP","GLU","PHE","GLY","HIS","ILE","LYS", "LEU","MET","ASN","PRO","GLN","ARG","SER","THR","VAL","TRP", "TYR","GLX","UNK"}; static int replacement_matrixAA[23][23] = {{1,0,0,0,0, 0,1,0,0,0, 0,0,0,1,0, 0,1,1,0,0, 0,0,0}, {0,1,0,1,1, 0,0,1,0,1, 0,0,1,0,1, 0,0,0,0,0, 0,1,0}, {0,0,1,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0}, {0,1,0,1,1, 0,1,1,0,0, 0,0,1,0,1, 0,0,0,0,0, 0,1,0}, {0,1,0,1,1, 0,0,1,0,0, 0,0,1,0,1, 0,0,0,0,0, 0,1,0}, {0,0,0,0,0, 1,0,0,1,0, 1,0,0,0,0, 0,0,0,0,0, 1,0,0}, {1,0,0,1,0, 0,1,0,0,0, 0,0,0,0,0, 0,1,0,0,0, 0,0,0}, {0,1,0,1,1, 0,0,1,0,0, 0,0,1,0,1, 1,0,0,0,0, 0,1,0}, {0,0,0,0,0, 1,0,0,1,0, 1,1,0,0,0, 0,0,0,1,0, 0,0,0}, {0,1,0,0,0, 0,0,0,0,1, 0,0,1,0,1, 1,0,0,0,0, 0,0,0}, {0,0,0,0,0, 1,0,0,1,0, 1,1,0,0,0, 0,0,0,1,0, 0,0,0}, {0,0,0,0,0, 0,0,0,1,0, 1,1,0,0,0, 0,0,0,1,0, 0,0,0}, {0,1,0,1,1, 0,0,1,0,1, 0,0,1,0,1, 0,1,0,0,0, 0,1,0}, {1,0,0,0,0, 0,0,0,0,0, 0,0,0,1,0, 0,1,0,0,0, 0,0,0}, {0,1,0,1,1, 0,0,1,0,1, 0,0,1,0,1, 1,0,0,0,0, 0,1,0}, {0,0,0,0,0, 0,0,1,0,1, 0,0,0,0,1, 1,0,0,0,1, 0,0,0}, {1,0,0,0,0, 0,1,0,0,0, 0,0,1,1,0, 0,1,1,0,0, 0,0,0}, {1,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,1,1,0,0, 0,0,0}, {0,0,0,0,0, 0,0,0,1,0, 1,1,0,0,0, 0,0,0,1,0, 0,0,0}, {0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 1,0,0,0,1, 0,0,0}, {0,0,0,0,0, 1,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 1,0,0}, {0,1,0,1,1, 0,0,1,0,0, 0,0,1,0,1, 0,0,0,0,0, 0,1,0}, {0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0}}; size_t pixelI; NearestAtomS *curr_pixelSP; int segmentI, segment_width, minimal_score; int shifted_ref_residueI, shifted_residueI; int score; int rowI, columnI; int screen_x0, screen_y0, screen_x1, screen_y1; int colorI; /*------prepare some parameters:---------------------------------------------*/ max_length = RESNAMESIZE - 1; square_width = (unsigned int) runtimeSP->zoom_factor; if (square_width < 1) square_width = 1; square_height = square_width; max_screen_x0 = guiSP->main_win_free_area_width - 1; max_screen_y0 = guiSP->main_win_free_area_height - 1; ref_residuesN = (int) runtimeSP->reference_residuesN; residuesN = (int) runtimeSP->residuesN; segment_width = runtimeSP->segment_width; minimal_score = runtimeSP->minimal_score; /*------initialize code arrays:----------------------------------------------*/ /* Reference sequence: */ for (ref_residueI = 0; ref_residueI < ref_residuesN; ref_residueI++) { /* Pointer to reference residue name: */ ref_residue_nameP = runtimeSP->reference_sequenceP + ref_residueI * max_length; /* Pointer to reference residue code: */ reference_codeIP = runtimeSP->reference_residue_codeIP + ref_residueI; /* Initialize code with default value (22, unknown residue): */ *reference_codeIP = 22; /* Scan the set of standard residue names: */ for (nameI = 0; nameI < namesN; nameI++) { /* Compare the current reference residue */ /* name with the current standard name: */ if (strncmp (ref_residue_nameP, nameAA[nameI], 3) == 0) { *reference_codeIP = nameI; break; } } } /* The current working sequence (stored to the main sequence buffer): */ for (residueI = 0; residueI < residuesN; residueI++) { /* Pointer to residue name: */ residue_nameP = runtimeSP->sequenceP + residueI * max_length; /* Pointer to residue code: */ codeIP = runtimeSP->residue_codeIP + residueI; /* Initialize code with default value (22, unknown residue): */ *codeIP = 22; /* Scan the set of standard residue names: */ for (nameI = 0; nameI < namesN; nameI++) { /* Compare the current reference residue */ /* name with the current standard name: */ if (strncmp (residue_nameP, nameAA[nameI], 3) == 0) { *codeIP = nameI; break; } } } /*------refresh the hidden pixmap:-------------------------------------------*/ /* Refresh the hidden pixmap, where drawing */ /* will be done (background must be black): */ RefreshPixmap_ (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], guiSP->control_winS.x0, guiSP->input_winS.y0, guiSP->black_colorID); /*------initialize mol_complexI and styleI in each NearestAtomS:-------------*/ /* The mol_complexI is used to store score: */ for (pixelI = 0; pixelI < pixelsN; pixelI++) { curr_pixelSP = nearest_atomSP + pixelI; curr_pixelSP->mol_complexI = 0; curr_pixelSP->styleI = 0; } /*------prepare ranges for serial indices:-----------------------------------*/ /* Index range for the reference sequence: */ ref_startI = runtimeSP->reference_offset; ref_endI = (int) guiSP->main_win_free_area_width / square_width + ref_startI; if (ref_endI >= ref_residuesN) ref_endI = ref_residuesN - 1; /* Index range for the current working sequence: */ startI = runtimeSP->sequence_offset; endI = (int) guiSP->main_win_free_area_height / square_height + startI; if (endI >= residuesN) endI = residuesN - 1; /*------scan sequences and prepare scores:-----------------------------------*/ /* Scan the reference sequence (horizontal scan): */ for (ref_residueI = ref_startI; ref_residueI <= ref_endI; ref_residueI++) { /* Scan the current working sequence (vertical scan): */ for (residueI = startI; residueI <= endI; residueI++) { /* Reset score (the number of matching */ /* residues in the current segment): */ score = 0; /* Scan the current segment: */ for (segmentI = 0; segmentI < segment_width; segmentI++) { /* Prepare and check shifted indices: */ shifted_ref_residueI = ref_residueI + segmentI; if (shifted_ref_residueI > ref_endI) continue; shifted_residueI = residueI + segmentI; if (shifted_residueI > endI) continue; /* Prepare row and column index: */ rowI = *(runtimeSP->residue_codeIP + shifted_residueI); columnI = *(runtimeSP->reference_residue_codeIP + shifted_ref_residueI); /* Compare codes: */ if (!replacement_matrixAA[rowI][columnI]) continue; /* If this point is reached, increment score: */ score++; } /* If the current score is lower than */ /* the minimal score, do not use it: */ if (score < minimal_score) continue; /* If this point is reached, the current score is larger or */ /* equal to the minimal score. Compare new scores with old */ /* scores associated with residues in the current segment. */ /* The NearestAtomS array is used as the buffer for scores. */ for (segmentI = 0; segmentI < segment_width; segmentI++) { /* Prepare and check the screen */ /* position of the current pair: */ screen_x0 = (int) square_width * (ref_residueI + segmentI - ref_startI); if (screen_x0 > max_screen_x0) continue; screen_y0 = (int) square_height * (residueI + segmentI - startI); if (screen_y0 > max_screen_y0) continue; /* Prepare and check the pixel index: */ pixelI = guiSP->main_win_free_area_width * screen_y0 + screen_x0; if (pixelI >= pixelsN) continue; /* Pointer to NearestAtomS structure */ /* associated with the current pair: */ curr_pixelSP = nearest_atomSP + pixelI; /* Compare scores: */ if (curr_pixelSP->mol_complexI >= score) continue; /* If the new score is better than */ /* the old one it should be stored: */ curr_pixelSP->mol_complexI = score; } } } /*------compare residues again and set styleI:-------------------------------*/ /* styleI values: */ /* 0 = mismatch (bad substit.) */ /* 1 = exact match */ /* 2 = acceptable substitution */ /* Scan the reference sequence (horizontal scan): */ for (ref_residueI = ref_startI; ref_residueI <= ref_endI; ref_residueI++) { /* Prepare and check the column index: */ columnI = *(runtimeSP->reference_residue_codeIP + ref_residueI); /* Prepare and check screen_x0: */ screen_x0 = (int) square_width * (ref_residueI - ref_startI); if (screen_x0 > max_screen_x0) continue; /* Scan the current working sequence (vertical scan): */ for (residueI = startI; residueI <= endI; residueI++) { /* Prepare the row index: */ rowI = *(runtimeSP->residue_codeIP + residueI); /* Prepare and check screen_y0: */ screen_y0 = (int) square_height * (residueI - startI); if (screen_y0 > max_screen_y0) continue; /* Prepare and check the pixel index: */ pixelI = guiSP->main_win_free_area_width * screen_y0 + screen_x0; if (pixelI >= pixelsN) continue; /* Pointer to NearestAtomS structure */ /* associated with the current pair: */ curr_pixelSP = nearest_atomSP + pixelI; /* If these indices are equal, the residues are equal: */ if (rowI == columnI) { curr_pixelSP->styleI = 2; continue; } /* If indices are different, compare residue codes: */ if (replacement_matrixAA[rowI][columnI]) { curr_pixelSP->styleI = 1; } } } /*------prepare yellow and magenta color:------------------------------------*/ /* Yellow is used for exact matches: */ XSetForeground (guiSP->displaySP, guiSP->theGCA[2], guiSP->yellow_colorID); /* Magenta is used for acceptable substitutions: */ XSetForeground (guiSP->displaySP, guiSP->theGCA[1], guiSP->magenta_colorID); /*------draw comparison to hidden pixmap:------------------------------------*/ /* Scan the reference sequence (horizontal scan): */ for (ref_residueI = ref_startI; ref_residueI <= ref_endI; ref_residueI++) { /* Horizontal position: */ screen_x0 = (int) square_width * (ref_residueI - ref_startI); if (screen_x0 > max_screen_x0) continue; /* Column index: */ columnI = *(runtimeSP->reference_residue_codeIP + ref_residueI); /* Scan the current working sequence (vertical scan): */ for (residueI = startI; residueI <= endI; residueI++) { /* Vertical position: */ screen_y0 = (int) square_height * (residueI - startI); if (screen_y0 > max_screen_y0) continue; /* Row index: */ rowI = *(runtimeSP->residue_codeIP + residueI); /* Compare codes: */ if (!replacement_matrixAA[rowI][columnI]) continue; /* Prepare and check the pixel index: */ pixelI = guiSP->main_win_free_area_width * screen_y0 + screen_x0; if (pixelI >= pixelsN) continue; /* Pointer to NearestAtomS structure */ /* associated with the current pair: */ curr_pixelSP = nearest_atomSP + pixelI; /* Compare the current score with the minimal score: */ if (curr_pixelSP->mol_complexI < minimal_score) continue; /* The styleI will be used as the color index */ /* (0 = mismatch, 1 = subst., 2 = exact match): */ colorI = curr_pixelSP->styleI; if (colorI == 0) continue; if ((colorI != 1) && (colorI != 2)) continue; /* If this point is reached, the current */ /* score is good enough; draw the square: */ XFillRectangle (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[colorI], screen_x0, screen_y0, square_width, square_height); /* Update the "dots counter": */ dots_drawnN++; } } /*------draw lines at the right and bottom edge:-----------------------------*/ /* Prepare edge coordinates: */ screen_x0 = (int) square_width * (ref_endI - ref_startI + 1); if (screen_x0 <= max_screen_x0) screen_x1 = screen_x0; else screen_x1 = max_screen_x0; screen_y0 = (int) square_height * (endI - startI + 1); if (screen_y0 <= max_screen_y0) screen_y1 = screen_y0; else screen_y1 = max_screen_y0; /* Use cyan color for bounding rectangle: */ XSetForeground (guiSP->displaySP, guiSP->theGCA[0], guiSP->cyan_colorID); /* Draw the right edge: */ if (screen_x0 <= max_screen_x0) { XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0, 0, screen_x0, screen_y1); } /* Draw the bottom edge: */ if (screen_y0 <= max_screen_y0) { XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], 0, screen_y0, screen_x1, screen_y0); } /*------copy the prepared image to the main window:--------------------------*/ /* Copy hidden pixmap to the main window: */ XCopyArea (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->main_winS.ID, guiSP->theGCA[0], 0, 0, guiSP->main_win_free_area_width, guiSP->main_win_free_area_height, 0, 0); return (size_t) dots_drawnN; } /*===========================================================================*/ garlic-1.6/porins4.script0000644000076500007650000000165210043152601015727 0ustar zuciczucic00000000000000# Searching for sequence motifs characteristic for porins. # This script covers the following patterns: # # aromatic-anything-aliphatic # charged-anything-TYR-anything-hydrophobic # # 2004/04/26 # Hide water and other hetero atoms: select hetero hide # Draw just a backbone, using blue color: select complement show backbone 4 color cyan-blue # Select the first characteristic pattern: pattern = ARG LYS HIS ASP GLU ASN GLN SER THR / * / ARG LYS HIS ASP GLU ASN GLN SER THR / * / TYR TRP PHE LEU VAL ILE ALA / * / LEU VAL TYR PHE ALA GLY ILE / * / LEU VAL TYR PHE ALA GLY ILE / * / LEU VAL TYR PHE ALA GLY ILE select pattern color red # Select the second characteristic pattern: pattern = LEU VAL TYR PHE ALA GLY ILE / * / LEU VAL TYR PHE ALA GLY ILE / * / LEU VAL TYR PHE ALA GLY ILE / * / TYR TRP PHE LEU VAL ILE ALA / * / ARG LYS HIS ASP GLU ASN GLN SER THR / * / ARG LYS HIS ASP GLU ASN GLN SER THR select pattern color yellow garlic-1.6/plane.c0000644000076500007650000001437007400132036014352 0ustar zuciczucic00000000000000/* Copyright (C) 2000, 2001 Damir Zucic */ /*============================================================================= plane.c Purpose: Execute plane command. Input: (1) Pointer to MolComplexS structure. (2) The number of macromolecular complexes. (3) Pointer to RuntimeS structure. (4) Pointer to ConfigS structure. (5) Pointer to GUIS structure. (6) Pointer to NearestAtomS structure. (7) The number of pixels in the main window free area. (8) Pointer to refreshI. (9) Pointer to the remainder of the command string. It may be empty or it may contain the keyword OFF, TRA (TRANSPARENCY) or RAD (RADIUS). Output: (1) Plane flag set, transparency changed or radius set for each caught macromolecular complex. (2) Return value. Return value: (1) Positive (command) code on success. (2) Negative (error) code on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include #include "defines.h" #include "commands.h" #include "typedefs.h" /*======function prototypes:=================================================*/ char *ExtractToken_ (char *, int, char *, char *); size_t MainRefresh_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); int ControlRefresh_ (MolComplexS *, ConfigS *, GUIS *); /*======execute plane command:===============================================*/ int Plane_ (MolComplexS *mol_complexSP, int mol_complexesN, RuntimeS *runtimeSP, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int *refreshIP, char *stringP) { char *remainderP; char tokenA[STRINGSIZE]; int mol_complexI; MolComplexS *curr_mol_complexSP; char *P; int n; double value; /* Extract the first token, if present: */ remainderP = ExtractToken_ (tokenA, STRINGSIZE, stringP, " \t\n"); /* If there are no tokens in the remainder of */ /* the command string, make plane(s) visible: */ if (!remainderP) { /* For each caught macromolecular complex, make the plane visible: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check is the current macromolecular complex caught: */ if (curr_mol_complexSP->catchF == 0) continue; /* Make plane visible (set flag): */ curr_mol_complexSP->planeS.hiddenF = 0; } } /* If keyword OFF is present, hide plane(s): */ else if (strstr (tokenA, "OFF") == tokenA) { /* For each caught macromolecular complex, hide the plane: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check is the current macromolecular complex caught: */ if (curr_mol_complexSP->catchF == 0) continue; /* Hide plane (set flag): */ curr_mol_complexSP->planeS.hiddenF = 1; } } /* If keyword TRA (TRANSPARENCY) is present, change the plane transparency: */ else if (strstr (tokenA, "TRA") == tokenA) { /* Replace each non-numeric character (except */ /* minus sign and decimal point) with space: */ P = stringP; while ((n = *P++) != '\0') { if (!isdigit (n) && (n != '-') && (n != '.')) *(P - 1) = ' '; } /* Try to extract the plane transparency: */ if (sscanf (stringP, "%lf", &value) != 1) { strcpy (runtimeSP->messageA, "Failed to extract the plane transparency!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_PLANE; } /* Check the value; it should be between 0 and 1: */ if ((value < 0.0) || (value > 1.0)) { strcpy (runtimeSP->messageA, "The value should be between 0 and 1!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_PLANE; } /* If this point is reached, the plane transparency is good: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check is the current macromolecular complex caught: */ if (curr_mol_complexSP->catchF == 0) continue; /* Set the transparency: */ curr_mol_complexSP->planeS.transparency = value; } } /* If keyword RAD (RADIUS) is present, change the circle radius: */ else if (strstr (tokenA, "RAD") == tokenA) { /* Replace each non-numeric character (except */ /* minus sign and decimal point) with space: */ P = stringP; while ((n = *P++) != '\0') { if (!isdigit (n) && (n != '-') && (n != '.')) *(P - 1) = ' '; } /* Try to extract the circle radius: */ if (sscanf (stringP, "%lf", &value) != 1) { strcpy (runtimeSP->messageA, "Failed to extract the plane radius!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_PLANE; } /* Check the value; it should be positive: */ if (value < 0.0) { strcpy (runtimeSP->messageA, "The value should be positive!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_PLANE; } /* If this point is reached, the plane radius is good: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check is the current macromolecular complex caught: */ if (curr_mol_complexSP->catchF == 0) continue; /* Set the plane radius: */ curr_mol_complexSP->planeS.circle_radius = value; /* Set the position_changedF, to force projection: */ curr_mol_complexSP->position_changedF = 1; } } /* Keyword not recognized: */ else { strcpy (runtimeSP->messageA, "Keyword not recognized!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_PLANE; } /* Refresh the main window: */ (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); /* Refresh the control window: */ ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); /* Return the command code: */ return COMMAND_PLANE; } /*===========================================================================*/ garlic-1.6/stereo_data.c0000644000076500007650000000542607154665214015566 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= stereo_data.c Purpose: Prepare the stereo data. The right x and z coordinate have to be calculated. Rotation axis is y; the angle is given in ConfigS structure. If this angle is positive, rotation is right-handed. The original data are used for the left image and this function prepares data for the right image. Input: (1) Pointer to MolComplexS structure, with macromolecular data. (2) Pointer to ConfigS structure, with configuration data, including the rotation angle. Output: (1) Data added to the array of MolComplexS structures. (2) Return value. Return value: (1) Positive, if macromolecular complex contains at least one atom. (2) Zero, if there are no atoms. Notes: (1) Positive angle is suitable for "relaxed eyes". Negative angle is suitable for "crossed eyes". (2) This function does not prepare stereo data for the normal vector, which defines the plane associated with the complex. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======prepare stereo data:=================================================*/ int PrepareStereoData_ (MolComplexS *curr_mol_complexSP, ConfigS *configSP) { size_t atomI, atomsN; double sin_angle, cos_angle; double x0, z0; double x, z; static double x_new, z_new; AtomS *curr_atomSP; /* Return zero if there are no atoms: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) return 0; /* Prepare the sine and cosine of the rotation angle: */ sin_angle = sin (configSP->stereo_angle); cos_angle = cos (configSP->stereo_angle); /* Copy the geometric center coordinates: */ x0 = curr_mol_complexSP->geometric_center_vectorS.x; z0 = curr_mol_complexSP->geometric_center_vectorS.z; /* Scan the whole complex; calculate right_x and right_z: */ for (atomI = 0; atomI < atomsN; atomI++) { /** Current AtomS pointer: **/ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /** Coordinates relative to the geometric center: **/ x = curr_atomSP->raw_atomS.x[0] - x0; z = curr_atomSP->raw_atomS.z[0] - z0; /** Rotate around y: **/ x_new = x * cos_angle + z * sin_angle; z_new = -x * sin_angle + z * cos_angle; /** New coordinates (used for the right image): **/ curr_atomSP->raw_atomS.x[1] = x_new + x0; curr_atomSP->raw_atomS.z[1] = z_new + z0; } /* Force the projection: */ curr_mol_complexSP->position_changedF = 1; /* Return positive value if complex contains at least one atom: */ return 1; } /*===========================================================================*/ garlic-1.6/copy_template_atoms.c0000644000076500007650000000557507612775537017362 0ustar zuciczucic00000000000000/* Copyright (C) 2001-2003 Damir Zucic */ /*============================================================================= copy_template_atoms.c Purpose: Copy all atoms from the specified template residue to the new structure. Update the atomic serial numbers, residue sequence numbers and other data specific for the new structure. Update the number of atoms in the new structure. Input: (1) Pointer to MolComplexS structure. (2) Pointer to RuntimeS structure. (3) Pointer to the current template residue. (4) Residue serial index. Output: (1) Return value. Return value: (1) The number of atoms in the specified template residue. Notes: (1) This function does not check the amount of storage left for atomic data. (2) The number of atoms is updated in this function. ========includes:============================================================*/ #include #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======copy atoms from template residue to new structure:===================*/ int CopyTemplateAtoms_ (MolComplexS *mol_complexSP, RuntimeS *runtimeSP, ResidueS *template_residueSP, int residueI) { int atoms_copiedN = 0; int atom_struct_size; int first_template_atomI, last_template_atomI, template_atomI; int atomI; AtomS *curr_template_atomSP; AtomS *curr_atomSP; /* Size of AtomS structure: */ atom_struct_size = sizeof (AtomS); /* Prepare the indices of the first and the last template atom: */ first_template_atomI = template_residueSP->residue_startI; last_template_atomI = template_residueSP->residue_endI; /* Prepare the index of the next atom in the new structure: */ atomI = mol_complexSP->atomsN; /* Scan the template residue: */ for (template_atomI = first_template_atomI; template_atomI <= last_template_atomI; template_atomI++) { /* Pointer to the current template atom: */ curr_template_atomSP = runtimeSP->template_atomSP + template_atomI; /* Pointer to the current atom: */ curr_atomSP = mol_complexSP->atomSP + atomI; /* Copy the complete atomic data from the */ /* current template atom to the current atom: */ memcpy (curr_atomSP, curr_template_atomSP, atom_struct_size); /* Fix atom serial number: */ curr_atomSP->raw_atomS.serialI = atomI + 1; /* Fix residue sequence number: */ curr_atomSP->raw_atomS.residue_sequenceI = residueI + 1; /* Fix residue insertion code: */ curr_atomSP->raw_atomS.residue_insertion_code = ' '; /* Fix residue array index: */ curr_atomSP->residue_arrayI = residueI; /* Update the atomic index: */ atomI++; } /* Update the number of atoms in the new structure: */ mol_complexSP->atomsN = atomI; /* Return the number of atoms which were copied: */ return atoms_copiedN; } /*===========================================================================*/ garlic-1.6/comm_move.c0000644000076500007650000000474107400137674015252 0ustar zuciczucic00000000000000/* Copyright (C) 2000, 2001 Damir Zucic */ /*============================================================================= comm_move.c Purpose: Execute move command: set bits for objects which should be moved. More keywords may be specified simultaneously. The keywords are: ALL, STR (STRUCTURE), PLA (PLANE) and MEM (MEMBRANE). Input: (1) Pointer to MolComplexS structure. (2) The number of macromolecular complexes. (3) Pointer to RuntimeS structure. (4) Pointer to the remainder of the command string. This command may be given with a list of keywords. Output: (1) Bits set for specified objects. (2) Return value. Return value: (1) Positive (command) code on success. (2) Negative (error) code on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "commands.h" #include "typedefs.h" /*======execute move command:================================================*/ int CommandMove_ (MolComplexS *mol_complexSP, int mol_complexesN, RuntimeS *runtimeSP, char *stringP) { int move_bits = 0; int mol_complexI; MolComplexS *curr_mol_complexSP; /* If keyword ALL is present, set all bits: */ if (strstr (stringP, "ALL")) { move_bits = STRUCTURE_MASK | PLANE_MASK | MEMBRANE_MASK; } /* If keyword STR (STRUCTURE) is present: */ if (strstr (stringP, "STR")) move_bits = STRUCTURE_MASK; /* If keyword PLA (PLANE) is present: */ if (strstr (stringP, "PLA")) move_bits = PLANE_MASK; /* If keyword MEM (MEMBRANE) is present: */ if (strstr (stringP, "MEM")) move_bits = MEMBRANE_MASK; /* If move_bits are unchanged, keyword recognition failed: */ if (move_bits == 0) { strcpy (runtimeSP->messageA, "Failed to recognize keyword(s)!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_MOVE; } /* Sets bits for every caught macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check is the current macromolecular complex caught: */ if (curr_mol_complexSP->catchF == 0) continue; /* Copy movement bits: */ curr_mol_complexSP->move_bits = move_bits; } /* Return the command code on success: */ return COMMAND_MOVE; } /*===========================================================================*/ garlic-1.6/chi1_from_ncacbcg1.c0000644000076500007650000000730707341017646016662 0ustar zuciczucic00000000000000/* Copyright (C) 2001 Damir Zucic */ /*============================================================================= chi1_from_ncacbcg1.c Purpose: Calculate dihedral angle chi1, using N, CA, CB and CG1 coordinates. Input: (1) Pointer to AtomS structure, pointing to the first atom of the current macromolecular complex. (2) Index of the first atom of the current residue. (3) Index of the last atom of the currrent residue. Output: Return value. Return value: (1) Dihedral angle chi1, on success. (2) BADDIHEDANGLE on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int ExtractFourAtoms_ (VectorS *, VectorS *, VectorS *, VectorS *, char *, char *, char *, char *, AtomS *, size_t, size_t); void VectorProduct_ (VectorS *, VectorS *, VectorS *); double AbsoluteValue_ (VectorS *); double ScalarProduct_ (VectorS *, VectorS *); /*======calculate chi1 from N, CA, CB and CG1:===============================*/ double Chi1FromNCACBCG1_ (AtomS *atomSP, size_t atom_startI, size_t atom_endI) { static VectorS N_vectorS, CA_vectorS, CB_vectorS, CG1_vectorS; int n; VectorS CA_N_vectorS, CA_CB_vectorS; VectorS CB_CA_vectorS, CB_CG1_vectorS; VectorS u1S, u2S; VectorS v1S, v2S; double denom, ratio, alpha; double chi1; /* Extract N, CA, CB and CG1 coordinates: */ n = ExtractFourAtoms_ (&N_vectorS, &CA_vectorS, &CB_vectorS, &CG1_vectorS, "N", "CA", "CB", "CG1", atomSP, atom_startI, atom_endI); /* All four atoms are required to calculate the angle chi1: */ if (n < 4) return BADDIHEDANGLE; /* The first pair of auxiliary vectors: */ CA_N_vectorS.x = N_vectorS.x - CA_vectorS.x; CA_N_vectorS.y = N_vectorS.y - CA_vectorS.y; CA_N_vectorS.z = N_vectorS.z - CA_vectorS.z; CA_CB_vectorS.x = CB_vectorS.x - CA_vectorS.x; CA_CB_vectorS.y = CB_vectorS.y - CA_vectorS.y; CA_CB_vectorS.z = CB_vectorS.z - CA_vectorS.z; /* The second pair of auxiliary vectors: */ CB_CA_vectorS.x = CA_vectorS.x - CB_vectorS.x; CB_CA_vectorS.y = CA_vectorS.y - CB_vectorS.y; CB_CA_vectorS.z = CA_vectorS.z - CB_vectorS.z; CB_CG1_vectorS.x = CG1_vectorS.x - CB_vectorS.x; CB_CG1_vectorS.y = CG1_vectorS.y - CB_vectorS.y; CB_CG1_vectorS.z = CG1_vectorS.z - CB_vectorS.z; /* Two vectors perpendicular to CA_CB_vectorS, mutually orthogonal, */ /* the second in the plane defined by CA_N_vectorS and CA_CB_vectorS: */ VectorProduct_ (&u1S, &CA_N_vectorS, &CA_CB_vectorS); VectorProduct_ (&u2S, &u1S, &CA_CB_vectorS); /* Two vectors perpendicular to CB_CA_vectorS, mutually orthogonal, */ /* the second in the plane defined by CB_CA_vectorS and CB_CG1_vectorS: */ VectorProduct_ (&v1S, &CB_CA_vectorS, &CB_CG1_vectorS); VectorProduct_ (&v2S, &CB_CA_vectorS, &v1S); /* Calculate the angle alpha, which will be used to calculate chi1: */ /* Avoid division by zero: */ denom = AbsoluteValue_ (&u1S) * AbsoluteValue_ (&v1S); if (denom == 0.0) return BADDIHEDANGLE; /* Use the scalar product to calculate the cosine of the angle: */ ratio = ScalarProduct_ (&u1S, &v1S) / denom; /* Arc cosine is very sensitive to floating point errors: */ if (ratio <= -1.0) alpha = 3.1415927; else if (ratio >= 1.0) alpha = 0.0; else alpha = acos (ratio); /* There are two possible solutions; the right one is resolved here: */ if (ScalarProduct_ (&v2S, &u1S) >= 0) chi1 = alpha; else chi1 = -alpha; /* Return the angle (in radians): */ return chi1; } /*===========================================================================*/ garlic-1.6/hide_backbone.c0000644000076500007650000000377607070337335016034 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= hide_backbone.c Purpose: Hide backbone for selected atoms: set hiddenF in each BackboneS structure. Input: (1) Pointer to MolComplexS structure. (2) The number of macromolecular complexes. Output: (1) The hiddenF set to one for selected atoms. (2) Return value. Return value: Positive always. ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======hide backbone:=======================================================*/ int HideBackbone_ (MolComplexS *mol_complexSP, int mol_complexesN) { int mol_complexI; MolComplexS *curr_mol_complexSP; size_t c_alphaI, c_alphaN; BackboneS *curr_backboneSP; AtomS *curr_atomSP; /* Scan every macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /** Pointer to the current macromolecular complex: **/ curr_mol_complexSP = mol_complexSP + mol_complexI; /** Check is the current macromolecular complex caught: **/ if (curr_mol_complexSP->catchF == 0) continue; /** The number of CA atoms in the current complex: **/ c_alphaN = curr_mol_complexSP->c_alphaN; /** Scan the array of BackboneS structures: **/ for (c_alphaI = 0; c_alphaI < c_alphaN; c_alphaI++) { /*** Pointer to the current CA atom: ***/ curr_backboneSP = curr_mol_complexSP->backboneSP + c_alphaI; curr_atomSP = curr_mol_complexSP->atomSP + curr_backboneSP->c_alphaI; /*** Check is the current CA atom selected and set ***/ /*** hiddenF. If the current CA atom is selected, ***/ /*** the backbone element should be unvisible. ***/ if (curr_atomSP->selectedF) curr_backboneSP->hiddenF = 1; } } /* Return positive value (trivial): */ return 1; } /*===========================================================================*/ garlic-1.6/select_2nz3.c0000644000076500007650000001521410403045134015403 0ustar zuciczucic00000000000000/* Copyright (C) 2006 Damir Zucic */ /*============================================================================= select_2nz3.c Purpose: Select the sequence fragment which contains two or more negative or zwitterionic residues in a window of three residues. ASP, GLU, ASN and GLN are taken into account. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. (3) Selection mode index (0 = overwrite, 1 = restrict, 2 = expand previous selection). Output: (1) The flag selectedF set to one for selected atoms in every caught macromolecular complex. (2) Return value. Return value: (1) The number of selected atoms (zero or positive value). ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======select two or more negative or zwitterionic residues:================*/ long Select2NZ3_ (MolComplexS *mol_complexSP, int mol_complexesN, int selection_modeI) { long selected_atomsN = 0; int mol_complexI; MolComplexS *curr_mol_complexSP; int atomsN, atomI; AtomS *curr_atomSP; int residuesN, residueI, windowI, combinedI; ResidueS *curr_residueSP; AtomS *first_atomSP; char *nameP; int negative_zwitterN; int first_atomI, last_atomI; /* Check every macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check is the current macromolecular complex caught: */ if (curr_mol_complexSP->catchF == 0) continue; /* Prepare and check the number of atoms in the current complex: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Copy the number of residues in the current macromol. complex: */ residuesN = curr_mol_complexSP->residuesN; if (residuesN == 0) continue; /* Backup the current selection if selection mode is restrict: */ if (selection_modeI == 1) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Copy the selection flag: */ curr_atomSP->previous_selectedF = curr_atomSP->selectedF; } } /* Unselect everything if selection mode is overwrite or restrict: */ if ((selection_modeI == 0) || (selection_modeI == 1)) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Unselect the current atom: */ curr_atomSP->selectedF = 0; } } /* Scan the residues of the current macromolecular complex: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Reset the number of negative and zwitterionic residues: */ negative_zwitterN = 0; /* Scan the window of three residues, */ /* starting from the current residue: */ for (windowI = 0; windowI < 3; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI >= residuesN) break; /* Residue associated with the combined index: */ curr_residueSP = curr_mol_complexSP->residueSP + combinedI; /* Pointer to the first atom of current residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Pointer to the name of the current residue: */ nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Check is this residue negative or zwitterionic: */ if ((strcmp (nameP, "ASP") == 0) || (strcmp (nameP, "GLU") == 0) || (strcmp (nameP, "ASN") == 0) || (strcmp (nameP, "GLN") == 0)) negative_zwitterN++; } /* If there were two or more negative and zwitterionic */ /* residues in a window of three residues, the doublet is */ /* found. If there was one or less, take the next resid. */ if (negative_zwitterN < 2) continue; /* If this point is reached, rescan the window of three */ /* residues and select negative and zwitterionic resid. */ /* Scan the window of three residues, */ /* starting from the current residue: */ for (windowI = 0; windowI < 3; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI >= residuesN) break; /* Residue associated with the combined index: */ curr_residueSP = curr_mol_complexSP->residueSP + combinedI; /* Pointer to the first atom of current residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Pointer to the name of the current residue: */ nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Check is this residue negative or zwitterionic: */ if ((strcmp (nameP, "ASP") != 0) && (strcmp (nameP, "GLU") != 0) && (strcmp (nameP, "ASN") != 0) && (strcmp (nameP, "GLN") != 0)) continue; /* If this point is reached, select */ /* all atoms of the current residue. */ /* The indices of the first and the */ /* last atom of the current residue: */ first_atomI = curr_residueSP->residue_startI; last_atomI = curr_residueSP->residue_endI; /* Select all atoms of the current residue: */ for (atomI = first_atomI; atomI <= last_atomI; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Select the current atom: */ curr_atomSP->selectedF = 1; /* Update the counter of selected atoms: */ selected_atomsN++; } } /* End of residueI loop: */ } /* Combine the current selection with the */ /* previous, if selection mode is restrict: */ if (selection_modeI == 1) { /* Reset the counter of selected atoms. The */ /* selected atoms should be counted again. */ selected_atomsN = 0; /* Combine the old and the new selection flag: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Combine selection flags: */ curr_atomSP->selectedF *= curr_atomSP->previous_selectedF; /* Check the selection flag; increase */ /* the count of selected residues if */ /* the selection flag is equal to one: */ if (curr_atomSP->selectedF) selected_atomsN++; } } /* Update the position_changedF (some atoms may have bad color): */ curr_mol_complexSP->position_changedF = 1; /* End of mol_complexI loop: */ } /* Return the number of selected atoms: */ return selected_atomsN; } /*===========================================================================*/ garlic-1.6/select_3cz4.c0000644000076500007650000001547310153564322015410 0ustar zuciczucic00000000000000/* Copyright (C) 2004 Damir Zucic */ /*============================================================================= select_3cz4.c Purpose: Select the sequence fragment which contains three or more charged or zwitterionic residues in a window of four residues. ASP, GLU, ASN, GLN, ARG, LYS and HIS are taken into account. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. (3) Selection mode index (0 = overwrite, 1 = restrict, 2 = expand previous selection). Output: (1) The flag selectedF set to one for selected atoms in every caught macromolecular complex. (2) Return value. Return value: (1) The number of selected atoms (zero or positive value). ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======select three or more charged or zwitterionic residues:===============*/ long Select3CZ4_ (MolComplexS *mol_complexSP, int mol_complexesN, int selection_modeI) { long selected_atomsN = 0; int mol_complexI; MolComplexS *curr_mol_complexSP; int atomsN, atomI; AtomS *curr_atomSP; int residuesN, residueI, windowI, combinedI; ResidueS *curr_residueSP; AtomS *first_atomSP; char *nameP; int very_polarN; int first_atomI, last_atomI; /* Check every macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check is the current macromolecular complex caught: */ if (curr_mol_complexSP->catchF == 0) continue; /* Prepare and check the number of atoms in the current complex: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Copy the number of residues in the current macromol. complex: */ residuesN = curr_mol_complexSP->residuesN; if (residuesN == 0) continue; /* Backup the current selection if selection mode is restrict: */ if (selection_modeI == 1) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Copy the selection flag: */ curr_atomSP->previous_selectedF = curr_atomSP->selectedF; } } /* Unselect everything if selection mode is overwrite or restrict: */ if ((selection_modeI == 0) || (selection_modeI == 1)) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Unselect the current atom: */ curr_atomSP->selectedF = 0; } } /* Scan the residues of the current macromolecular complex: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Reset the counter which counts very polar residues: */ very_polarN = 0; /* Scan the window of four residues, */ /* starting from the current residue: */ for (windowI = 0; windowI < 4; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI >= residuesN) break; /* Residue associated with the combined index: */ curr_residueSP = curr_mol_complexSP->residueSP + combinedI; /* Pointer to the first atom of current residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Pointer to the name of the current residue: */ nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Check is this residue very polar: */ if ((strcmp (nameP, "ASP") == 0) || (strcmp (nameP, "GLU") == 0) || (strcmp (nameP, "ASN") == 0) || (strcmp (nameP, "GLN") == 0) || (strcmp (nameP, "ARG") == 0) || (strcmp (nameP, "LYS") == 0) || (strcmp (nameP, "HIS") == 0)) very_polarN++; } /* If there were three or more very polar residues in */ /* a window of four residues, the triplet is found. */ /* If there were two or less, take the next residue. */ if (very_polarN < 3) continue; /* If this point is reached, scan the window of four */ /* residues again and select very polar residues. */ /* Scan the window of four residues, */ /* starting from the current residue: */ for (windowI = 0; windowI < 4; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI >= residuesN) break; /* Residue associated with the combined index: */ curr_residueSP = curr_mol_complexSP->residueSP + combinedI; /* Pointer to the first atom of current residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Pointer to the name of the current residue: */ nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Check is this residue very polar: */ if ((strcmp (nameP, "ASP") != 0) && (strcmp (nameP, "GLU") != 0) && (strcmp (nameP, "ASN") != 0) && (strcmp (nameP, "GLN") != 0) && (strcmp (nameP, "ARG") != 0) && (strcmp (nameP, "LYS") != 0) && (strcmp (nameP, "HIS") != 0)) continue; /* If this point is reached, select */ /* all atoms of the current residue. */ /* The indices of the first and the */ /* last atom of the current residue: */ first_atomI = curr_residueSP->residue_startI; last_atomI = curr_residueSP->residue_endI; /* Select all atoms of the current residue: */ for (atomI = first_atomI; atomI <= last_atomI; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Select the current atom: */ curr_atomSP->selectedF = 1; /* Update the counter of selected atoms: */ selected_atomsN++; } } /* End of residueI loop: */ } /* Combine the current selection with the */ /* previous, if selection mode is restrict: */ if (selection_modeI == 1) { /* Reset the counter of selected atoms. The */ /* selected atoms should be counted again. */ selected_atomsN = 0; /* Combine the old and the new selection flag: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Combine selection flags: */ curr_atomSP->selectedF *= curr_atomSP->previous_selectedF; /* Check the selection flag; increase */ /* the count of selected residues if */ /* the selection flag is equal to one: */ if (curr_atomSP->selectedF) selected_atomsN++; } } /* Update the position_changedF (some atoms may have bad color): */ curr_mol_complexSP->position_changedF = 1; /* End of mol_complexI loop: */ } /* Return the number of selected atoms: */ return selected_atomsN; } /*===========================================================================*/ garlic-1.6/select_3cz5.c0000644000076500007650000001547310153564353015415 0ustar zuciczucic00000000000000/* Copyright (C) 2004 Damir Zucic */ /*============================================================================= select_3cz5.c Purpose: Select the sequence fragment which contains three or more charged or zwitterionic residues in a window of five residues. ASP, GLU, ASN, GLN, ARG, LYS and HIS are taken into account. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. (3) Selection mode index (0 = overwrite, 1 = restrict, 2 = expand previous selection). Output: (1) The flag selectedF set to one for selected atoms in every caught macromolecular complex. (2) Return value. Return value: (1) The number of selected atoms (zero or positive value). ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======select three or more charged or zwitterionic residues:===============*/ long Select3CZ5_ (MolComplexS *mol_complexSP, int mol_complexesN, int selection_modeI) { long selected_atomsN = 0; int mol_complexI; MolComplexS *curr_mol_complexSP; int atomsN, atomI; AtomS *curr_atomSP; int residuesN, residueI, windowI, combinedI; ResidueS *curr_residueSP; AtomS *first_atomSP; char *nameP; int very_polarN; int first_atomI, last_atomI; /* Check every macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check is the current macromolecular complex caught: */ if (curr_mol_complexSP->catchF == 0) continue; /* Prepare and check the number of atoms in the current complex: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Copy the number of residues in the current macromol. complex: */ residuesN = curr_mol_complexSP->residuesN; if (residuesN == 0) continue; /* Backup the current selection if selection mode is restrict: */ if (selection_modeI == 1) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Copy the selection flag: */ curr_atomSP->previous_selectedF = curr_atomSP->selectedF; } } /* Unselect everything if selection mode is overwrite or restrict: */ if ((selection_modeI == 0) || (selection_modeI == 1)) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Unselect the current atom: */ curr_atomSP->selectedF = 0; } } /* Scan the residues of the current macromolecular complex: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Reset the counter which counts very polar residues: */ very_polarN = 0; /* Scan the window of five residues, */ /* starting from the current residue: */ for (windowI = 0; windowI < 5; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI >= residuesN) break; /* Residue associated with the combined index: */ curr_residueSP = curr_mol_complexSP->residueSP + combinedI; /* Pointer to the first atom of current residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Pointer to the name of the current residue: */ nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Check is this residue very polar: */ if ((strcmp (nameP, "ASP") == 0) || (strcmp (nameP, "GLU") == 0) || (strcmp (nameP, "ASN") == 0) || (strcmp (nameP, "GLN") == 0) || (strcmp (nameP, "ARG") == 0) || (strcmp (nameP, "LYS") == 0) || (strcmp (nameP, "HIS") == 0)) very_polarN++; } /* If there were three or more very polar residues in */ /* a window of five residues, the triplet is found. */ /* If there were two or less, take the next residue. */ if (very_polarN < 3) continue; /* If this point is reached, scan the window of five */ /* residues again and select very polar residues. */ /* Scan the window of five residues, */ /* starting from the current residue: */ for (windowI = 0; windowI < 5; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI >= residuesN) break; /* Residue associated with the combined index: */ curr_residueSP = curr_mol_complexSP->residueSP + combinedI; /* Pointer to the first atom of current residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Pointer to the name of the current residue: */ nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Check is this residue very polar: */ if ((strcmp (nameP, "ASP") != 0) && (strcmp (nameP, "GLU") != 0) && (strcmp (nameP, "ASN") != 0) && (strcmp (nameP, "GLN") != 0) && (strcmp (nameP, "ARG") != 0) && (strcmp (nameP, "LYS") != 0) && (strcmp (nameP, "HIS") != 0)) continue; /* If this point is reached, select */ /* all atoms of the current residue. */ /* The indices of the first and the */ /* last atom of the current residue: */ first_atomI = curr_residueSP->residue_startI; last_atomI = curr_residueSP->residue_endI; /* Select all atoms of the current residue: */ for (atomI = first_atomI; atomI <= last_atomI; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Select the current atom: */ curr_atomSP->selectedF = 1; /* Update the counter of selected atoms: */ selected_atomsN++; } } /* End of residueI loop: */ } /* Combine the current selection with the */ /* previous, if selection mode is restrict: */ if (selection_modeI == 1) { /* Reset the counter of selected atoms. The */ /* selected atoms should be counted again. */ selected_atomsN = 0; /* Combine the old and the new selection flag: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Combine selection flags: */ curr_atomSP->selectedF *= curr_atomSP->previous_selectedF; /* Check the selection flag; increase */ /* the count of selected residues if */ /* the selection flag is equal to one: */ if (curr_atomSP->selectedF) selected_atomsN++; } } /* Update the position_changedF (some atoms may have bad color): */ curr_mol_complexSP->position_changedF = 1; /* End of mol_complexI loop: */ } /* Return the number of selected atoms: */ return selected_atomsN; } /*===========================================================================*/ garlic-1.6/select_3cz6.c0000644000076500007650000001547110153564471015415 0ustar zuciczucic00000000000000/* Copyright (C) 2004 Damir Zucic */ /*============================================================================= select_3cz6.c Purpose: Select the sequence fragment which contains three or more charged or zwitterionic residues in a window of six residues. ASP, GLU, ASN, GLN, ARG, LYS and HIS are taken into account. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. (3) Selection mode index (0 = overwrite, 1 = restrict, 2 = expand previous selection). Output: (1) The flag selectedF set to one for selected atoms in every caught macromolecular complex. (2) Return value. Return value: (1) The number of selected atoms (zero or positive value). ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======select three or more charged or zwitterionic residues:===============*/ long Select3CZ6_ (MolComplexS *mol_complexSP, int mol_complexesN, int selection_modeI) { long selected_atomsN = 0; int mol_complexI; MolComplexS *curr_mol_complexSP; int atomsN, atomI; AtomS *curr_atomSP; int residuesN, residueI, windowI, combinedI; ResidueS *curr_residueSP; AtomS *first_atomSP; char *nameP; int very_polarN; int first_atomI, last_atomI; /* Check every macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check is the current macromolecular complex caught: */ if (curr_mol_complexSP->catchF == 0) continue; /* Prepare and check the number of atoms in the current complex: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Copy the number of residues in the current macromol. complex: */ residuesN = curr_mol_complexSP->residuesN; if (residuesN == 0) continue; /* Backup the current selection if selection mode is restrict: */ if (selection_modeI == 1) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Copy the selection flag: */ curr_atomSP->previous_selectedF = curr_atomSP->selectedF; } } /* Unselect everything if selection mode is overwrite or restrict: */ if ((selection_modeI == 0) || (selection_modeI == 1)) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Unselect the current atom: */ curr_atomSP->selectedF = 0; } } /* Scan the residues of the current macromolecular complex: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Reset the counter which counts very polar residues: */ very_polarN = 0; /* Scan the window of six residues, */ /* starting from the current residue: */ for (windowI = 0; windowI < 6; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI >= residuesN) break; /* Residue associated with the combined index: */ curr_residueSP = curr_mol_complexSP->residueSP + combinedI; /* Pointer to the first atom of current residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Pointer to the name of the current residue: */ nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Check is this residue very polar: */ if ((strcmp (nameP, "ASP") == 0) || (strcmp (nameP, "GLU") == 0) || (strcmp (nameP, "ASN") == 0) || (strcmp (nameP, "GLN") == 0) || (strcmp (nameP, "ARG") == 0) || (strcmp (nameP, "LYS") == 0) || (strcmp (nameP, "HIS") == 0)) very_polarN++; } /* If there were three or more very polar residues in */ /* a window of six residues, the triplet is found. */ /* If there were two or less, take the next residue. */ if (very_polarN < 3) continue; /* If this point is reached, scan the window of six */ /* residues again and select very polar residues. */ /* Scan the window of six residues, */ /* starting from the current residue: */ for (windowI = 0; windowI < 6; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI >= residuesN) break; /* Residue associated with the combined index: */ curr_residueSP = curr_mol_complexSP->residueSP + combinedI; /* Pointer to the first atom of current residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Pointer to the name of the current residue: */ nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Check is this residue very polar: */ if ((strcmp (nameP, "ASP") != 0) && (strcmp (nameP, "GLU") != 0) && (strcmp (nameP, "ASN") != 0) && (strcmp (nameP, "GLN") != 0) && (strcmp (nameP, "ARG") != 0) && (strcmp (nameP, "LYS") != 0) && (strcmp (nameP, "HIS") != 0)) continue; /* If this point is reached, select */ /* all atoms of the current residue. */ /* The indices of the first and the */ /* last atom of the current residue: */ first_atomI = curr_residueSP->residue_startI; last_atomI = curr_residueSP->residue_endI; /* Select all atoms of the current residue: */ for (atomI = first_atomI; atomI <= last_atomI; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Select the current atom: */ curr_atomSP->selectedF = 1; /* Update the counter of selected atoms: */ selected_atomsN++; } } /* End of residueI loop: */ } /* Combine the current selection with the */ /* previous, if selection mode is restrict: */ if (selection_modeI == 1) { /* Reset the counter of selected atoms. The */ /* selected atoms should be counted again. */ selected_atomsN = 0; /* Combine the old and the new selection flag: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Combine selection flags: */ curr_atomSP->selectedF *= curr_atomSP->previous_selectedF; /* Check the selection flag; increase */ /* the count of selected residues if */ /* the selection flag is equal to one: */ if (curr_atomSP->selectedF) selected_atomsN++; } } /* Update the position_changedF (some atoms may have bad color): */ curr_mol_complexSP->position_changedF = 1; /* End of mol_complexI loop: */ } /* Return the number of selected atoms: */ return selected_atomsN; } /*===========================================================================*/ garlic-1.6/garlic.c0000644000076500007650000002676510357777445014557 0ustar zuciczucic00000000000000/* o-------------------------------------------------------------------o | | | Copyright (C) 2000-2006 Damir Zucic | | | | This program is free software; you can redistribute it and/or | | modify it under the terms of the GNU General Public License | | as published by the Free Software Foundation, version 2. | | | | This program is distributed in the hope that it will be useful, | | but WITHOUT ANY WARRANTY; without even the implied warranty of | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | | GNU General Public License for more details. | | | | You should have received a copy of the GNU General Public License | | along with this program; if not, write to the | | Free Software Foundation, Inc., | | 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | | | o-------------------------------------------------------------------o */ /*============================================================================= garlic.c Molecular visualization and analyzing tool General description: Garlic is molecular visualization program written for investigation of membrane proteins. It may be used to visualize other proteins, as well as some geometric objects. This version is capable to recognize the PDB format version 2.1; check pdb_atom.c for details about this format. Author: Damir Zucic (zucic@garlic.mefos.hr), University of Osijek, Croatia. ------------------------------------------------------------------------------- Naming conventions: (1) xxx_yyy Simple variable; lowercase, underline separates adjacent words. (2) xxx_yyyI Index (array index usually). (3) xxx_yyyN Number of array elements. (4) xxx_yyyID Identifier (integer or long integer). (5) xxx_yyyF Flag (usually integer, value 0 or 1). (6) XxxYyyS New data type (typedef struct XxxYyyS). (7) xxx_yyyS Structure (type: XxxYyyS). (8) xxx_yyyP Pointer. (9) xxx_yyySP Pointer to structure. (10) xxx_yyyA[] Array; no space before left bracket. (11) xxx_yyyAA[][] Two dimensional array. (12) xxx_yyySA[] Array of structures. (13) xxx_yyyPA[] Array of pointers. (14) XXXYYYZZZ Symbol (#define). (15) XxxYyy_ () Function; the first character in each word is in uppercase; the last character is underline; one space (exactly one!) used to separate underline and left parenthesis; underline is not used to separate words. (16) xxx_yyyGC Graphics context (pointer to _XGC structure). Programming style: When this project was started RAM and hard disk became quite cheap. Thus: (1) Whenever choosing between brute force and intelligence, chose force: it is cheaper, simpler and more reliable. Of course, use brain if there is no other choice. (2) Comment everything, including trivial things, so that hackers find this program disgusting. (3) Never put two functions in the same file, even if it seems to be reasonable. (4) Use verbose function and variable names. (5) Indentation is one tab (eight characters), except in functions which draw atoms and bonds (four characters). (6) Each brace should be placed in a separate line. (7) Avoid global scope data. (8) Use auxiliary structures when some function requires a lot of input data. Pass pointer to the structure to this function, instead of a large number of arguments. Portability: Garlic should be ANSI C and/or POSIX compliant. All functions fit into one of these standards: (1) ANSI C programming language. (2) Xlib, X Window System (X11R6). From /usr/games/fortunes/fortunes file (Linux Slackware 3.4): "What garlic is to food, insanity is to art." ------------------------------------------------------------------------------- Purpose of this file: The main function is in this file. The real job is done by called functions. Return value / exit status: (1) EXIT_SUCCESS on success. (2) EXIT_FAILURE on failure. (3) EXIT_SUCCESS if help, version info or registr. is required. ========includes:============================================================*/ #include #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======defines:=============================================================*/ /* See defines.h for all other symbols! */ /*======function prototypes:=================================================*/ void PrintUsage_ (void); void PrintHelp_ (void); void PrintVersion_ (void); int Register_ (void); void ErrorMessage_ (char *, char *, char *, char *, char *, char *, char *); void WarningMessage_ (char *, char *, char *, char *, char *, char *, char *); GUIS *AllocateGUIS_ (void); ConfigS *AllocateConfigS_ (void); MolComplexS *AllocateMolComplexSA_ (size_t); void FreeMemory_ (GUIS *, MolComplexS *, int, NearestAtomS *, size_t *); int ReadConfig_ (ConfigS *); int ExtractArgs_ (ConfigS *, GUIS *, char *, int, char **); void PrintCursorNames_ (void); int DisplayInit_ (GUIS *); int DisplayColorCapabilities_ (GUIS *); int ParseOptions_ (GUIS *, ConfigS *); int CreateWindows_ (GUIS *, ConfigS *, int, char **); int CalculateParameters_ (ConfigS *, GUIS *); void PrintConfig_ (ConfigS *, GUIS *); int LoadComplex_ (int *, MolComplexS *, int *, int *, char *, ConfigS *, GUIS *); NearestAtomS *AllocateNearest_ (size_t *, GUIS *); void InitNearest_ (NearestAtomS *, size_t); int ColorSchemes_ (MolComplexS *, int, ConfigS *, GUIS *, char *, int); int IdentifyButton_ (XButtonEvent *, GUIS *); int EventLoop_ (MolComplexS *, int *, int *, NearestAtomS **, size_t *, ConfigS *, GUIS *); /*======main:================================================================*/ int main (int argc, char *argv[]) { int mainI = 0; /* Positive on success */ int n; /* Auxiliary integer */ static GUIS *guiSP; /* See typedefs.h */ static ConfigS *configSP; /* Read from .garlicrc */ static char mol_file_nameA[STRINGSIZE]; /* Input file name */ static MolComplexS *mol_complexSP; /* Macromolecular data */ int mol_complexesN = 0; /* Number of mol. complexes */ int next_mol_complexID = 1; /* Initial value should be 1 */ static NearestAtomS *nearest_atomSP; /* Replaces depth sorting */ size_t pixelsN; /* The number of pixels */ int dummy_groupF; /* Has no special meaning */ /* Write brief introduction - if requested - and exit: */ for (n = 0; n < argc; n++) { if ((strcmp (argv[n], "-h") == 0) || (strcmp (argv[n], "--help") == 0) || (strcmp (argv[n], "-help") == 0)) { PrintHelp_ (); exit (EXIT_SUCCESS); } } /* Print version information - if requested - and exit: */ for (n = 0; n < argc; n++) { if ((strcmp (argv[n], "-v") == 0) || (strcmp (argv[n], "--version") == 0)) { PrintVersion_ (); exit (EXIT_SUCCESS); } } /* Register user (send e-mail to the author) - if requested - and exit: */ for (n = 0; n < argc; n++) { if ((strcmp (argv[n], "-r") == 0) || (strcmp (argv[n], "--register") == 0)) { Register_ (); fprintf (stdout, "A short e-mail message with registration"); fprintf (stdout, " was send to the author.\n"); exit (EXIT_SUCCESS); } } /* Formal, single pass loop (many things happen here): */ do { /* Allocate memory for GUI data: */ mainI--; guiSP = AllocateGUIS_ (); if (guiSP == NULL) break; /* Initialize the main window refreshing flag: */ mainI--; guiSP->main_window_refreshF = 1; /* Initialize the main window drawing mode index: */ mainI--; guiSP->main_window_modeI = 0; /* Allocate memory for configuration data: */ mainI--; configSP = AllocateConfigS_ (); if (configSP == NULL) break; /* Allocate memory for macromolecular data: */ mainI--; mol_complexSP = AllocateMolComplexSA_ (MAXCOMPLEXES); if (mol_complexSP == NULL) break; /* Read configuration from $HOME.garlicrc file: */ mainI--; n = ReadConfig_ (configSP); /* Extract command line arguments: */ mainI--; n = ExtractArgs_ (configSP, guiSP, mol_file_nameA, argc, argv); if (n < 0) break; /* Print cursor names and exit on request: */ mainI--; if (configSP->print_cursor_namesF) { PrintCursorNames_ (); break; } /* Display related initializations: */ mainI--; n = DisplayInit_ (guiSP); if (n < 0) { PrintUsage_ (); fprintf (stderr, "\nUnable to connect to X server,"); fprintf (stderr, " exiting ...\n"); break; } /* Display color properties: */ mainI--; n = DisplayColorCapabilities_ (guiSP); if (n < 0) break; /* Parse options which require connection to X server: */ mainI--; n = ParseOptions_ (guiSP, configSP); if (n < 0) break; /* Create windows: */ mainI--; n = CreateWindows_ (guiSP, configSP, argc, argv); if (n < 0) break; /* Calculate the remaining parameters: */ mainI--; n = CalculateParameters_ (configSP, guiSP); if (n < 0) break; /* Load macromolecular complex if input file name is specified: */ mainI--; LoadComplex_ (&dummy_groupF, mol_complexSP, &mol_complexesN, &next_mol_complexID, mol_file_nameA, configSP, guiSP); /* Print configuration data, if requested: */ mainI--; if (configSP->print_configF) { PrintConfig_ (configSP, guiSP); mainI *= -1; break; } /* Allocate the array of NeareastAtomS structures: */ mainI--; nearest_atomSP = AllocateNearest_ (&pixelsN, guiSP); if (nearest_atomSP == NULL) break; /* Initialize the array of NearestAtomS structures: */ InitNearest_ (nearest_atomSP, pixelsN); /* Prepare the simple color schemes: */ mainI--; ColorSchemes_ (mol_complexSP, mol_complexesN, configSP, guiSP, "dummy", 0); /* Initialize default colors for molecular surfaces: */ mainI--; ColorSchemes_ (mol_complexSP, mol_complexesN, configSP, guiSP, configSP->surface_outer_color_schemeA, 1); ColorSchemes_ (mol_complexSP, mol_complexesN, configSP, guiSP, configSP->surface_inner_color_schemeA, 2); /* Define dummy buttons in control window: */ mainI--; IdentifyButton_ ((XButtonEvent *) NULL, guiSP); /* Take and process events: */ mainI--; n = EventLoop_ (mol_complexSP, &mol_complexesN, &next_mol_complexID, &nearest_atomSP, &pixelsN, configSP, guiSP); if (n < 0) break; /* If this point is reached, everything worked */ /* fine; change the sign of mainI to positive: */ mainI *= -1; } while (0); /* Free storage used for pixmaps and other data: */ FreeMemory_ (guiSP, mol_complexSP, mol_complexesN, nearest_atomSP, &pixelsN); /* Close connection to X server: */ if (guiSP->displaySP) XCloseDisplay (guiSP->displaySP); /* Free the array of MolComplexS structures: */ if (mol_complexSP) free (mol_complexSP); /* Close log file if used at all: */ if (configSP->log_fileF != 0) fclose (configSP->log_fileP); /* Free ConfigS structure: */ if (configSP) free (configSP); /* Free GUIS structure: */ if (guiSP) free (guiSP); /* Return on failure: */ if (mainI < 0) return EXIT_FAILURE; /* Return on success: */ return EXIT_SUCCESS; } /*===========================================================================*/ garlic-1.6/discard.c0000644000076500007650000002451007612772020014671 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2003 Damir Zucic */ /*============================================================================= discard.c Purpose: Execute discard command: discard the specified macromolecular complex. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Pointer to the number of macromolecular complexes. (3) Pointer to the next macromolecular complex identifier. (4) Pointer to RuntimeS structure, with some runtime data. (5) Pointer to ConfigS structure, with configuration data. (6) Pointer to GUIS structure, with GUI data. (7) Pointer to NearestAtomS structure. (8) The number of pixels in the main window free area. (9) Pointer to refreshI. (10) The string which contains macromol. complex identifier. Output: (1) The specified macromolecular complex discarded. (2) The number of complexes updated. (3) The next macromolecular complex identifier updated. (4) Return value. Return value: (1) Positive (command) code on success. (2) Negative (error) code on failure. Notes: (1) The value of refreshI (*refreshIP) may be changed in this function or in some function called by this function. It is checked in EventLoop_ (see event_loop.c). It is assumed that refreshI is updated no more than once in each event handling function. If this is not the case, the care should be taken to avoid refreshI overflow. (2) The number of macromolecular complexes is not changed. It should not be used as the actual number of macromolecular complexes. It should be used in loops as the value which is defines the highest value of the array index. (3) If the currently caught macromol. complex is discarded, it may happen that nothing is caught. This may be fixed by catch (take) command. The ID of some complex which was not discarded should be specified as argument to catch. (4) This functions resets the edit mode index and some flags. ========includes:============================================================*/ #include #include #include #include #include #include #include #include "defines.h" #include "commands.h" #include "typedefs.h" /*======function prototypes:=================================================*/ char *ExtractToken_ (char *, int, char *, char *); size_t MainRefresh_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); int ControlRefresh_ (MolComplexS *, ConfigS *, GUIS *); /*======execute discard command:=============================================*/ int Discard_ (MolComplexS *mol_complexSP, int *mol_complexesNP, int *next_mol_complexIDP, RuntimeS *runtimeSP, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int *refreshIP, char *stringP) { char *remainderP; char tokenA[SHORTSTRINGSIZE]; int complexID; int mol_complexI; MolComplexS *curr_mol_complexSP; int job_doneF = 0; /* Extract the macromolecular complex identifier: */ remainderP = ExtractToken_ (tokenA, SHORTSTRINGSIZE, stringP, " \t\n"); if (!remainderP) { strcpy (runtimeSP->messageA, "Complex identifier missing!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_NO_ID; } /* If the second token contains the keyword ALL or *, */ /* discard all macromolecular complexes and return: */ if ((strstr (tokenA, "ALL") == tokenA) || (strstr (tokenA, "*"))) { for (mol_complexI = 0; mol_complexI < *mol_complexesNP; mol_complexI++) { /* Prepare the pointer to the current macromol. complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Discard the complex and reinitialize associated data: */ /* Reset counters: */ curr_mol_complexSP->atomsN = 0; curr_mol_complexSP->max_atomsN = 0; /* Atomic array: */ if (curr_mol_complexSP->atomSP) { free (curr_mol_complexSP->atomSP); curr_mol_complexSP->atomSP = NULL; } /* Header: */ if (curr_mol_complexSP->headerS.dataP) { free (curr_mol_complexSP->headerS.dataP); curr_mol_complexSP->headerS.dataP = NULL; } /* Backbone data: */ if (curr_mol_complexSP->backboneSP) { free (curr_mol_complexSP->backboneSP); curr_mol_complexSP->backboneSP = NULL; } curr_mol_complexSP->c_alphaN = 0; /* Sequence information: */ if (curr_mol_complexSP->residueSP) { free (curr_mol_complexSP->residueSP); curr_mol_complexSP->residueSP = NULL; } curr_mol_complexSP->residuesN = 0; /* Secondary structure: */ if (curr_mol_complexSP->secondary_structureP) { free (curr_mol_complexSP->secondary_structureP); curr_mol_complexSP->secondary_structureP = NULL; } /* Catch flag, tag flag, plane */ /* flag and two membrane flags: */ curr_mol_complexSP->catchF = 0; curr_mol_complexSP->tagF = 0; curr_mol_complexSP->planeS.hiddenF = 1; curr_mol_complexSP->membraneS.definedF = 0; curr_mol_complexSP->membraneS.hiddenF = 1; } /* Reset default_complexI: */ runtimeSP->default_complexI = 0; /* Reset the edit mode index: */ runtimeSP->edit_modeI = 0; /* Reset the edit_single_bondF flag: */ runtimeSP->edit_single_bondF = 0; /* If some structures were grouped, reset the group flag: */ runtimeSP->groupF = 0; /* If some structures were involved in a formation of a */ /* group, restore the original rotation center vectors: */ for (mol_complexI = 0; mol_complexI < *mol_complexesNP; mol_complexI++) { /* The pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check was this complex a group member: */ if (curr_mol_complexSP->group_memberF == 0) continue; /* If this point is reached, this */ /* complex was a group member. */ /* Restore the original rotation center vector: */ curr_mol_complexSP->rotation_center_vectorS.x = curr_mol_complexSP->backup_vectorS.x; curr_mol_complexSP->rotation_center_vectorS.y = curr_mol_complexSP->backup_vectorS.y; curr_mol_complexSP->rotation_center_vectorS.z = curr_mol_complexSP->backup_vectorS.z; /* Reset the group_memberF: */ curr_mol_complexSP->group_memberF = 0; } /* Reinitialize the number of macromol. complexes */ /* and the next macromolecular complex identifier: */ *mol_complexesNP = 0; *next_mol_complexIDP = 1; /* Refresh the main window: */ (*refreshIP)++; MainRefresh_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); /* Refresh the control window: */ ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); /* Return positive value on success: */ return COMMAND_DISCARD; } /* If this point is reached, a single macromolecular complex should */ /* be discarded. Read the complex identifier (integer expected): */ if (sscanf (tokenA, "%d", &complexID) != 1) { strcpy (runtimeSP->messageA, "Bad macromolecular complex identifier!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_BAD_ID; } /* Find and discard the specified macromolecular complex: */ for (mol_complexI = 0; mol_complexI < *mol_complexesNP; mol_complexI++) { /* Prepare the pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* If macromolecular complex is recognized */ /* discard it and set the flag job_doneF: */ if (curr_mol_complexSP->mol_complexID == complexID) { /* Reset counters: */ curr_mol_complexSP->atomsN = 0; curr_mol_complexSP->max_atomsN = 0; /* Free storage: */ if (curr_mol_complexSP->atomSP) { free (curr_mol_complexSP->atomSP); curr_mol_complexSP->atomSP = NULL; } if (curr_mol_complexSP->headerS.dataP) { free (curr_mol_complexSP->headerS.dataP); curr_mol_complexSP->headerS.dataP = NULL; } if (curr_mol_complexSP->backboneSP) { free (curr_mol_complexSP->backboneSP); curr_mol_complexSP->backboneSP = NULL; } if (curr_mol_complexSP->residueSP) { free (curr_mol_complexSP->residueSP); curr_mol_complexSP->residueSP = NULL; } if (curr_mol_complexSP->secondary_structureP) { free (curr_mol_complexSP->secondary_structureP); curr_mol_complexSP->secondary_structureP = NULL; } /* Catch flag, tag flag, plane flag, two */ /* membrane flags and group member flag: */ curr_mol_complexSP->catchF = 0; curr_mol_complexSP->tagF = 0; curr_mol_complexSP->planeS.hiddenF = 1; curr_mol_complexSP->membraneS.definedF = 0; curr_mol_complexSP->membraneS.hiddenF = 1; curr_mol_complexSP->group_memberF = 0; /* Flag which says that job was done: */ job_doneF = 1; } } /* If complex was not found, return the error code: */ if (job_doneF == 0) { strcpy (runtimeSP->messageA, "Bad complex identifier (out of range)!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_BAD_ID; } /* Reset the edit mode index: */ runtimeSP->edit_modeI = 0; /* Reset the edit_single_bondF flag: */ runtimeSP->edit_single_bondF = 0; /* If some structures were grouped, reset the group flag: */ runtimeSP->groupF = 0; /* If some structures were involved in a formation of a */ /* group, restore the original rotation center vectors: */ for (mol_complexI = 0; mol_complexI < *mol_complexesNP; mol_complexI++) { /* Prepare the pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check was this complex a group member: */ if (curr_mol_complexSP->group_memberF == 0) continue; /* If this point is reached, the current complex was a group member. */ /* Restore the original rotation center vector: */ curr_mol_complexSP->rotation_center_vectorS.x = curr_mol_complexSP->backup_vectorS.x; curr_mol_complexSP->rotation_center_vectorS.y = curr_mol_complexSP->backup_vectorS.y; curr_mol_complexSP->rotation_center_vectorS.z = curr_mol_complexSP->backup_vectorS.z; } /* Refresh the main window: */ (*refreshIP)++; MainRefresh_ (mol_complexSP, *mol_complexesNP, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); /* Refresh the control window: */ ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); /* Return positive value on success: */ return COMMAND_DISCARD; } /*===========================================================================*/ garlic-1.6/show_backbone.c0000644000076500007650000000377707070340402016071 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= show_backbone.c Purpose: Show backbone for selected atoms: set hiddenF in each BackboneS structure. Input: (1) Pointer to MolComplexS structure. (2) The number of macromolecular complexes. Output: (1) The hiddenF set to zero for selected atoms. (2) Return value. Return value: Positive always. ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======show backbone:=======================================================*/ int ShowBackbone_ (MolComplexS *mol_complexSP, int mol_complexesN) { int mol_complexI; MolComplexS *curr_mol_complexSP; size_t c_alphaI, c_alphaN; BackboneS *curr_backboneSP; AtomS *curr_atomSP; /* Scan every macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /** Pointer to the current macromolecular complex: **/ curr_mol_complexSP = mol_complexSP + mol_complexI; /** Check is the current macromolecular complex caught: **/ if (curr_mol_complexSP->catchF == 0) continue; /** The number of CA atoms in the current complex: **/ c_alphaN = curr_mol_complexSP->c_alphaN; /** Scan the array of BackboneS structures: **/ for (c_alphaI = 0; c_alphaI < c_alphaN; c_alphaI++) { /*** Pointer to the current CA atom: ***/ curr_backboneSP = curr_mol_complexSP->backboneSP + c_alphaI; curr_atomSP = curr_mol_complexSP->atomSP + curr_backboneSP->c_alphaI; /*** Check is the current CA atom selected and set ***/ /*** hiddenF. If the current CA atom is selected, ***/ /*** the backbone element should be made visible. ***/ if (curr_atomSP->selectedF) curr_backboneSP->hiddenF = 0; } } /* Return positive value (trivial): */ return 1; } /*===========================================================================*/ garlic-1.6/extract_args.c0000644000076500007650000004505007572477431015765 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2002 Damir Zucic */ /*============================================================================= extract_args.c Purpose: Extract command line arguments. Xlib resource manager could be used, but I prefer my own function. Parsing will be done after connecting to X server, because color specifications cannot be parsed before connection. Geometry could be parsed now, but it is left for later. Input: (1) Pointer to ConfigS structure, where config. data will be stored. (2) Pointer to GUIS structure, where display name will be stored. (3) Pointer to the input molecular file name. (4) Number of command line arguments. (5) Command line arguments. Output: (1) Some data stored to ConfigS structure. (2) Display name stored to GUIS structure. (3) Input molecular file name stored. (4) Return value. Return value: (1) Number of arguments on success (zero or positive). (2) Negative on failure (one or more arguments not recognized). ========includes:============================================================*/ #include #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ void ErrorMessage_ (char *, char *, char *, char *, char *, char *, char *); int ExtractInteger_ (char *); FILE *OpenFileForReading_ (char *); int ExtractIndex_ (char *); /*======extract command line arguments:======================================*/ int ExtractArgs_ (ConfigS *configSP, GUIS *guiSP, char *mol_file_nameP, int argc, char **argv) { int args_foundN = 0; int i = 1, j, n; FILE *fileP; int surfaceI; /* Initialize the input file name: */ *mol_file_nameP = '\0'; /* Initialize the log file name, flag and pointer: */ configSP->log_file_nameA[0] = '\0'; configSP->log_fileF = 0; configSP->log_fileP = NULL; /* Set the initial pointer to display name: */ guiSP->display_nameP = NULL; /* Initialize the print_configF: */ configSP->print_configF = 0; /* Initialize print_cursor_namesF: */ configSP->print_cursor_namesF = 0; /* Scan all command line arguments and extract options: */ while ((j = i++) < argc) { /*......options specific for garlic:.........................................*/ /* Log file name: */ if (strcmp (*(argv + j), "-log") == 0) { /*** Enough arguments? ***/ if (i >= argc) { ErrorMessage_ ("garlic", "ExtractArgs_", "", "Log file name missing!\n", "", "", ""); return -1; } /*** Copy log file name: ***/ n = sizeof (configSP->log_file_nameA) - 1; strncpy (configSP->log_file_nameA, argv[i], n); *(configSP->log_file_nameA + n) = '\0'; /*** Set flag to indicate that log file should be used: ***/ configSP->log_fileF = 1; /*** Update index and number of arguments: ***/ i++; args_foundN++; continue; } /** Stereo flag (display stereo or mono image): **/ if (strcmp (*(argv + j), "-stereo") == 0) { configSP->stereoF = 1; /*** Update the number of arguments; do not update i: ***/ args_foundN++; continue; } /** Slab mode index (see typedefs.h for available modes): **/ if (strcmp (*(argv + j), "-slab") == 0) { /*** Enough arguments? ***/ if (i >= argc) { ErrorMessage_ ("garlic", "ExtractArgs_", "", "Slab mode specification missing!\n", "", "", ""); return -2; } /*** Recognize the mode: ***/ if (strncmp (argv[i], "off", 20) == 0) configSP->default_slab_modeI = 0; else if (strncmp (argv[i], "planar", 20) == 0) configSP->default_slab_modeI = 1; else if (strncmp (argv[i], "sphere", 20) == 0) configSP->default_slab_modeI = 2; else if (strncmp (argv[i], "half-sphere", 20) == 0) configSP->default_slab_modeI = 3; else if (strncmp (argv[i], "cylinder", 20) == 0) configSP->default_slab_modeI = 4; else if (strncmp (argv[i], "half-cylinder", 20) == 0) configSP->default_slab_modeI = 5; else { ErrorMessage_ ("garlic", "ExtractArgs_", "", "Slab mode \"", argv[i], "\" not supported.\n", ""); return -3; } /*** Update index and the number of arguments: ***/ i++; args_foundN++; continue; } /** Color fading mode index (see typedefs.h for available modes): **/ if (strcmp (*(argv + j), "-fading") == 0) { /*** Enough arguments? ***/ if (i >= argc) { ErrorMessage_ ("garlic", "ExtractArgs_", "", "Fading mode specification missing!\n", "", "", ""); return -4; } /*** Recognize the mode: ***/ if (strncmp (argv[i], "off", 20) == 0) configSP->default_fading_modeI = 0; else if (strncmp (argv[i], "planar", 20) == 0) configSP->default_fading_modeI = 1; else if (strncmp (argv[i], "sphere", 20) == 0) configSP->default_fading_modeI = 2; else if (strncmp (argv[i], "half-sphere", 20) == 0) configSP->default_fading_modeI = 3; else if (strncmp (argv[i], "cylinder", 20) == 0) configSP->default_fading_modeI = 4; else if (strncmp (argv[i], "half-cylinder", 20) == 0) configSP->default_fading_modeI = 5; else { ErrorMessage_ ("garlic", "ExtractArgs_", "", "Fading mode \"", argv[i], "\" not supported.\n", ""); return -5; } /*** Update index and the number of arguments: ***/ i++; args_foundN++; continue; } /** Default atom drawing style: **/ if (strcmp (*(argv + j), "-as") == 0) { /*** Enough arguments? ***/ if (i >= argc) { ErrorMessage_ ("garlic", "ExtractArgs_", "", "Atom style specification missing!\n", "", "", ""); return -6; } /*** Extract atom style index: ***/ n = ExtractInteger_ (argv[i]); /*** Check it: ***/ if ((n < 0) || (n > MAXATOMSTYLEI)) { ErrorMessage_ ("garlic", "ExtractArgs_", "", "Bad atom style index!\n", "", "", ""); return -7; } /*** Copy the value: ***/ configSP->default_atom_styleI = n; /*** Update index and number of arguments: ***/ i++; args_foundN++; continue; } /** Default bond drawing style: **/ if (strcmp (*(argv + j), "-bs") == 0) { /*** Enough arguments? ***/ if (i >= argc) { ErrorMessage_ ("garlic", "ExtractArgs_", "", "Bond style specification missing!\n", "", "", ""); return -8; } /*** Extract bond style index: ***/ n = ExtractInteger_ (argv[i]); /*** Check it: ***/ if ((n < 0) || (n > MAXBONDSTYLEI)) { ErrorMessage_ ("garlic", "ExtractArgs_", "", "Bad bond style index!\n", "", "", ""); return -9; } /*** Copy the value: ***/ configSP->default_bond_styleI = n; /*** Update index and number of arguments: ***/ i++; args_foundN++; continue; } /** Coordinate system flag: **/ if (strcmp (*(argv + j), "-nosys") == 0) { configSP->show_coord_systemF = 0; /*** Update the number of arguments; do not update i: ***/ args_foundN++; continue; } /** Control window flag: **/ if (strcmp (*(argv + j), "-no-control") == 0) { configSP->show_control_windowF = 0; /*** Update the number of arguments; do no update i: ***/ args_foundN++; continue; } /** Print (dump) configuration flag: **/ if ((strcmp (*(argv + j), "-pc") == 0) || (strcmp (*(argv + j), "-print-config") == 0)) { configSP->print_configF = 1; /*** Update the number of arguments; do not update i: ***/ args_foundN++; continue; } /* Default number of color fading surfaces: */ if (strcmp (*(argv + j), "-fs") == 0) { /*** Enough arguments? ***/ if (i >= argc) { ErrorMessage_ ("garlic", "ExtractArgs_", "", "Number of fading surfaces missing!\n", "", "", ""); return -10; } /*** Extract bond style index: ***/ n = ExtractInteger_ (argv[i]); /*** Check it: ***/ if ((n <= 0) || (n > MAXCOLORSURFACES)) { ErrorMessage_ ("garlic", "ExtractArgs_", "", "Bad number of fading surfaces!\n", "", "", ""); return -11; } /*** Copy the value: ***/ configSP->default_surfacesN = n; /*** Update index and number of arguments: ***/ i++; args_foundN++; continue; } /** Left color for a given surface: **/ if (strstr (*(argv + j), "-lc") == *(argv + j)) { /*** Enough arguments? ***/ if (i >= argc) { ErrorMessage_ ("garlic", "ExtractArgs_", "", "Left color specification missing!\n", "", "", ""); return -12; } /*** Extract and check the surface index: ***/ /*** (Note that leading minus is skipped!) ***/ surfaceI = ExtractIndex_ (argv[j] + 1); if ((surfaceI < 0) || (surfaceI >= MAXCOLORSURFACES)) { ErrorMessage_ ("garlic", "ExtractArgs_", "", "Bad fading surface index!\n", "", "", ""); return -13; } /*** Copy left color specification: ***/ n = SHORTSTRINGSIZE - 1; strncpy (configSP->left_colorAA[surfaceI], argv[i], n); configSP->left_colorAA[surfaceI][n] = '\0'; /*** Update index and number of arguments: ***/ i++; args_foundN++; continue; } /** Middle color for a given surface: **/ if (strstr (*(argv + j), "-mc") == *(argv + j)) { /*** Enough arguments? ***/ if (i >= argc) { ErrorMessage_ ("garlic", "ExtractArgs_", "", "Middle color specification missing!\n", "", "", ""); return -14; } /*** Extract and check the surface index: ***/ /*** (Note that leading minus is skipped!) ***/ surfaceI = ExtractIndex_ (argv[j] + 1); if ((surfaceI < 0) || (surfaceI >= MAXCOLORSURFACES)) { ErrorMessage_ ("garlic", "ExtractArgs_", "", "Bad fading surface index!\n", "", "", ""); return -15; } /*** Copy middle color specification: ***/ n = SHORTSTRINGSIZE - 1; strncpy (configSP->middle_colorAA[surfaceI], argv[i], n); configSP->middle_colorAA[surfaceI][n] = '\0'; /*** Update index and number of arguments: ***/ i++; args_foundN++; continue; } /** Right color for a given surface: **/ if (strstr (*(argv + j), "-rc") == *(argv + j)) { /*** Enough arguments? ***/ if (i >= argc) { ErrorMessage_ ("garlic", "ExtractArgs_", "", "Right color specification missing!\n", "", "", ""); return -16; } /*** Extract and check the surface index: ***/ /*** (Note that leading minus is skipped!) ***/ surfaceI = ExtractIndex_ (argv[j] + 1); if ((surfaceI < 0) || (surfaceI >= MAXCOLORSURFACES)) { ErrorMessage_ ("garlic", "ExtractArgs_", "", "Bad fading surface index!\n", "", "", ""); return -17; } /*** Copy right color specification: ***/ n = SHORTSTRINGSIZE - 1; strncpy (configSP->right_colorAA[surfaceI], argv[i], n); configSP->right_colorAA[surfaceI][n] = '\0'; /*** Update index and number of arguments: ***/ i++; args_foundN++; continue; } /*......X11 options:.........................................................*/ /** Display name: **/ if (strcmp (*(argv + j), "-display") == 0) { /*** Enough arguments? ***/ if (i >= argc) { ErrorMessage_ ("garlic", "ExtractArgs_", "", "Display name missing!\n", "", "", ""); return -18; } /*** Copy display name: ***/ n = sizeof (guiSP->display_nameA) - 1; strncpy (guiSP->display_nameA, argv[i], n); *(guiSP->display_nameA + n) = '\0'; /** Refresh display name pointer: **/ guiSP->display_nameP = guiSP->display_nameA; /*** Update index and the number of arguments: ***/ i++; args_foundN++; continue; } /** Geometry string: **/ if (strcmp (*(argv + j), "-geometry") == 0) { /*** Enough arguments? ***/ if (i >= argc) { ErrorMessage_ ("garlic", "ExtractArgs_", "", "Geometry string missing!\n", "", "", ""); return -19; } /*** Copy geometry string: ***/ n = sizeof (configSP->geometryA) - 1; strncpy (configSP->geometryA, argv[i], n); *(configSP->geometryA + n) = '\0'; /*** Update index and number of arguments: ***/ i++; args_foundN++; continue; } /** Main window background color: **/ if (strcmp (*(argv + j), "-bg") == 0) { /*** Enough arguments? ***/ if (i >= argc) { ErrorMessage_ ("garlic", "ExtractArgs_", "", "Background color specification missing!\n", "", "", ""); return -20; } /*** Copy background color specification: ***/ n = sizeof (configSP->bg_colorA) - 1; strncpy (configSP->bg_colorA, argv[i], n); *(configSP->bg_colorA + n) = '\0'; /*** Update index and number of arguments: ***/ i++; args_foundN++; continue; } /** Main window foreground color: **/ if (strcmp (*(argv + j), "-fg") == 0) { /*** Enough arguments? ***/ if (i >= argc) { ErrorMessage_ ("garlic", "ExtractArgs_", "", "Foreground color specification missing!\n", "", "", ""); return -21; } /*** Copy foreground color specification: ***/ n = sizeof (configSP->fg_colorA) - 1; strncpy (configSP->fg_colorA, argv[i], n); *(configSP->fg_colorA + n) = '\0'; /*** Update index and number of arguments: ***/ i++; args_foundN++; continue; } /** Font name: **/ if (strcmp (*(argv + j), "-fn") == 0) { /*** Enough arguments? ***/ if (i >= argc) { ErrorMessage_ ("garlic", "ExtractArgs_", "", "Font name missing!\n", "", "", ""); return -22; } /*** Copy font name: ***/ n = sizeof (configSP->font_nameA) - 1; strncpy (configSP->font_nameA, argv[i], n); *(configSP->font_nameA + n) = '\0'; /*** Update index and number of arguments: ***/ i++; args_foundN++; continue; } /** Input window background color: **/ if (strcmp (*(argv + j), "-tbg") == 0) { /*** Enough arguments? ***/ if (i >= argc) { ErrorMessage_ ("garlic", "ExtractArgs_", "", "Text background color specification", " missing!\n", "", ""); return -23; } /*** Copy text background color specification: ***/ n = sizeof (configSP->text_bg_colorA) - 1; strncpy (configSP->text_bg_colorA, argv[i], n); *(configSP->text_bg_colorA + n) = '\0'; /*** Update index and number of arguments: ***/ i++; args_foundN++; continue; } /** Text color: **/ if (strcmp (*(argv + j), "-tfg") == 0) { /*** Enough arguments? ***/ if (i >= argc) { ErrorMessage_ ("garlic", "ExtractArgs_", "", "Text color specification missing!\n", "", "", ""); return -24; } /*** Copy text color specification: ***/ n = sizeof (configSP->text_fg_colorA) - 1; strncpy (configSP->text_fg_colorA, argv[i], n); *(configSP->text_fg_colorA + n) = '\0'; /*** Update index and number of arguments: ***/ i++; args_foundN++; continue; } /* Cursor name: */ if (strcmp (*(argv + j), "-cursor") == 0) { /*** Enough arguments? ***/ if (i >= argc) { ErrorMessage_ ("garlic", "ExtractArgs_", "", "Cursor name missing!\n", "", "", ""); return -25; } /*** Copy cursor name: ***/ n = sizeof (configSP->cursor_nameA) - 1; strncpy (configSP->cursor_nameA, argv[i], n); *(configSP->cursor_nameA + n) = '\0'; /*** Update index and number of arguments: ***/ i++; args_foundN++; continue; } /** Print cursor names flag: **/ if (strcmp (*(argv + j), "-pcn") == 0) { configSP->print_cursor_namesF = 1; /*** Update the number of arguments; do not update i: ***/ args_foundN++; continue; } /*......file name:...........................................................*/ /* If argument was not recognized up to here, check is it file name: */ if ((fileP = OpenFileForReading_ (argv[j])) != NULL) { fclose (fileP); n = STRINGSIZE - 1; strncpy (mol_file_nameP, argv[j], n); args_foundN++; continue; } /*......argument not recognized:.............................................*/ /* If this point is reached, at least one argument is bad: */ ErrorMessage_ ("garlic", "ExtractArgs_", "", "Command line argument \"", argv[j], "\" not recognized, exiting ...\n", ""); return -26; } /*...........................................................................*/ return args_foundN; } /*===========================================================================*/ garlic-1.6/bonds.c0000644000076500007650000001510310357044151014360 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2006 Damir Zucic */ /*============================================================================= bonds.c Purpose: Execute bonds command: change the bond drawing style for selected atoms or refresh bonds. Do not change drawing style for hydrogen and disulfide bonds. Change it for pseudo-bonds. Refreshing is however done for ordinary, disulfide and pseudo-bonds. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) The number of macromolecular complexes. (3) Pointer to RuntimeS structure, with some runtime data. (4) Pointer to ConfigS structure, with configuration data. (5) Pointer to GUIS structure, with GUI data. (6) Pointer to NearestAtomS structure. (7) The number of pixels in the main window free area. (8) Pointer to refreshI. (9) String which contains the bond drawing style name. Output: (1) Drawing style for bonds changed. (2) Return value. Return value: (1) Positive (command) code on success. (2) Negative (error) code on failure. Notes: (1) Bonds sometimes should be refreshed after replacement of side chains, creation of a new structure and after moving atoms or groups of atoms. Move (rotate) badly placed side chains into a proper position (far from all neighbors) before refreshing. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "commands.h" #include "typedefs.h" /*======function prototypes:=================================================*/ char *ExtractToken_ (char *, int, char *, char *); size_t StrongBonds_ (MolComplexS *, int, ConfigS *); size_t PseudoBonds_ (MolComplexS *, int, ConfigS *); size_t DisulfideBonds_ (MolComplexS *, int, ConfigS *); int RefreshBackbone_ (MolComplexS *, ConfigS *); int DihedralAngles_ (MolComplexS *, ConfigS *); size_t MainRefresh_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); int ControlRefresh_ (MolComplexS *, ConfigS *, GUIS *); /*======execute bonds command:===============================================*/ int Bonds_ (MolComplexS *mol_complexSP, int mol_complexesN, RuntimeS *runtimeSP, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int *refreshIP, char *stringP) { char *remainderP; char tokenA[SHORTSTRINGSIZE]; int bond_styleI; int mol_complexI; MolComplexS *default_mol_complexSP; MolComplexS *curr_mol_complexSP; size_t atomsN, atomI; AtomS *curr_atomSP; int bondI, bondsN; int bond_typeI; /* Extract the bond style name: */ remainderP = ExtractToken_ (tokenA, SHORTSTRINGSIZE, stringP, " \t\n"); if (!remainderP) { strcpy (runtimeSP->messageA, "Bond drawing style specification missing!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_NO_ATOM_STYLE; } /* The tokenA should either define the new bond */ /* style or contain request to refresh bonds: */ if (strcmp (tokenA, "0") == 0) bond_styleI = 0; else if (strcmp (tokenA, "1") == 0) bond_styleI = 1; else if (strcmp (tokenA, "2") == 0) bond_styleI = 2; else if (strcmp (tokenA, "3") == 0) bond_styleI = 3; else if (strcmp (tokenA, "4") == 0) bond_styleI = 4; else if (strcmp (tokenA, "5") == 0) bond_styleI = 5; else if (strstr (tokenA, "NIC") == tokenA) bond_styleI = NICE_BONDS; else if (strstr (tokenA, "STI") == tokenA) bond_styleI = STICK_BONDS; else if (strstr (tokenA, "REF") == tokenA) bond_styleI = REFRESH_BONDS; else { sprintf (runtimeSP->messageA, "Bond drawing style \"%s\" not available!", tokenA); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_BOND_STYLE; } /* The special case - request to refresh bonds: */ if (bond_styleI == REFRESH_BONDS) { /* Prepare the pointer to default complex: */ default_mol_complexSP = mol_complexSP + runtimeSP->default_complexI; /* Update strong bonds: */ StrongBonds_ (default_mol_complexSP, runtimeSP->default_complexI, configSP); /* Update pseudo-bonds: */ PseudoBonds_ (default_mol_complexSP, runtimeSP->default_complexI, configSP); /* Prepare disulfide bonds: */ DisulfideBonds_ (default_mol_complexSP, runtimeSP->default_complexI, configSP); /* Refresh backbone data: */ RefreshBackbone_ (default_mol_complexSP, configSP); /* Calculate dihedral angles and cis-trans flags: */ DihedralAngles_ (default_mol_complexSP, configSP); /* Reset the position_changedF: */ default_mol_complexSP->position_changedF = 1; /* Refresh the main window: */ (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); /* Refresh the control window: */ ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); /* Return positive value on success: */ return COMMAND_BONDS; } /* Scan every macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /** Pointer to the current macromolecular complex: **/ curr_mol_complexSP = mol_complexSP + mol_complexI; /** Check is the current macromolecular complex caught: **/ if (curr_mol_complexSP->catchF == 0) continue; /** Number of bonds in a macromolecular complex: **/ atomsN = curr_mol_complexSP->atomsN; /** Scan all bonds in the current complex: **/ for (atomI = 0; atomI < atomsN; atomI++) { /** Pointer to the current bond: **/ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /** Check is atom selected: **/ if (curr_atomSP->selectedF == 0) continue; /** The number of bonds associated with a given atoms: **/ bondsN = curr_atomSP->bondsN; /** Scan all bonds: **/ for (bondI = 0; bondI < bondsN; bondI++) { /*** If this is hydrogen or ***/ /*** disulfide bond skip it: ***/ bond_typeI = curr_atomSP->true_bondSA[bondI].bond_typeI; if (bond_typeI == 0) continue; if (bond_typeI == 2) continue; /*** Change the bond drawing style: ***/ curr_atomSP->true_bondSA[bondI].bond_styleI = bond_styleI; } } /* Reset the position_changedF: */ curr_mol_complexSP->position_changedF = 1; } /* Refresh the main window: */ (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); /* Refresh the control window: */ ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); /* Return positive value on success: */ return COMMAND_BONDS; } /*===========================================================================*/ garlic-1.6/chi1_from_ncacbcg.c0000644000076500007650000000726007341017621016570 0ustar zuciczucic00000000000000/* Copyright (C) 2001 Damir Zucic */ /*============================================================================= chi1_from_ncacbcg.c Purpose: Calculate dihedral angle chi1, using N, CA, CB and CG coordinates. Input: (1) Pointer to AtomS structure, pointing to the first atom of the current macromolecular complex. (2) Index of the first atom of the current residue. (3) Index of the last atom of the currrent residue. Output: Return value. Return value: (1) Dihedral angle chi1, on success. (2) BADDIHEDANGLE on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int ExtractFourAtoms_ (VectorS *, VectorS *, VectorS *, VectorS *, char *, char *, char *, char *, AtomS *, size_t, size_t); void VectorProduct_ (VectorS *, VectorS *, VectorS *); double AbsoluteValue_ (VectorS *); double ScalarProduct_ (VectorS *, VectorS *); /*======calculate chi1 from N, CA, CB and CG:================================*/ double Chi1FromNCACBCG_ (AtomS *atomSP, size_t atom_startI, size_t atom_endI) { static VectorS N_vectorS, CA_vectorS, CB_vectorS, CG_vectorS; int n; VectorS CA_N_vectorS, CA_CB_vectorS; VectorS CB_CA_vectorS, CB_CG_vectorS; VectorS u1S, u2S; VectorS v1S, v2S; double denom, ratio, alpha; double chi1; /* Extract N, CA, CB and CG coordinates: */ n = ExtractFourAtoms_ (&N_vectorS, &CA_vectorS, &CB_vectorS, &CG_vectorS, "N", "CA", "CB", "CG", atomSP, atom_startI, atom_endI); /* All four atoms are required to calculate the angle chi1: */ if (n < 4) return BADDIHEDANGLE; /* The first pair of auxiliary vectors: */ CA_N_vectorS.x = N_vectorS.x - CA_vectorS.x; CA_N_vectorS.y = N_vectorS.y - CA_vectorS.y; CA_N_vectorS.z = N_vectorS.z - CA_vectorS.z; CA_CB_vectorS.x = CB_vectorS.x - CA_vectorS.x; CA_CB_vectorS.y = CB_vectorS.y - CA_vectorS.y; CA_CB_vectorS.z = CB_vectorS.z - CA_vectorS.z; /* The second pair of auxiliary vectors: */ CB_CA_vectorS.x = CA_vectorS.x - CB_vectorS.x; CB_CA_vectorS.y = CA_vectorS.y - CB_vectorS.y; CB_CA_vectorS.z = CA_vectorS.z - CB_vectorS.z; CB_CG_vectorS.x = CG_vectorS.x - CB_vectorS.x; CB_CG_vectorS.y = CG_vectorS.y - CB_vectorS.y; CB_CG_vectorS.z = CG_vectorS.z - CB_vectorS.z; /* Two vectors perpendicular to CA_CB_vectorS, mutually orthogonal, */ /* the second in the plane defined by CA_N_vectorS and CA_CB_vectorS: */ VectorProduct_ (&u1S, &CA_N_vectorS, &CA_CB_vectorS); VectorProduct_ (&u2S, &u1S, &CA_CB_vectorS); /* Two vectors perpendicular to CB_CA_vectorS, mutually orthogonal, */ /* the second in the plane defined by CB_CA_vectorS and CB_CG_vectorS: */ VectorProduct_ (&v1S, &CB_CA_vectorS, &CB_CG_vectorS); VectorProduct_ (&v2S, &CB_CA_vectorS, &v1S); /* Calculate the angle alpha, which will be used to calculate chi1: */ /* Avoid division by zero: */ denom = AbsoluteValue_ (&u1S) * AbsoluteValue_ (&v1S); if (denom == 0.0) return BADDIHEDANGLE; /* Use the scalar product to calculate the cosine of the angle: */ ratio = ScalarProduct_ (&u1S, &v1S) / denom; /* Arc cosine is very sensitive to floating point errors: */ if (ratio <= -1.0) alpha = 3.1415927; else if (ratio >= 1.0) alpha = 0.0; else alpha = acos (ratio); /* There are two possible solutions; the right one is resolved here: */ if (ScalarProduct_ (&v2S, &u1S) >= 0) chi1 = alpha; else chi1 = -alpha; /* Return the angle (in radians): */ return chi1; } /*===========================================================================*/ garlic-1.6/chi1_from_ncacbog.c0000644000076500007650000000726007341017632016606 0ustar zuciczucic00000000000000/* Copyright (C) 2001 Damir Zucic */ /*============================================================================= chi1_from_ncacbog.c Purpose: Calculate dihedral angle chi1, using N, CA, CB and OG coordinates. Input: (1) Pointer to AtomS structure, pointing to the first atom of the current macromolecular complex. (2) Index of the first atom of the current residue. (3) Index of the last atom of the currrent residue. Output: Return value. Return value: (1) Dihedral angle chi1, on success. (2) BADDIHEDANGLE on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int ExtractFourAtoms_ (VectorS *, VectorS *, VectorS *, VectorS *, char *, char *, char *, char *, AtomS *, size_t, size_t); void VectorProduct_ (VectorS *, VectorS *, VectorS *); double AbsoluteValue_ (VectorS *); double ScalarProduct_ (VectorS *, VectorS *); /*======calculate chi1 from N, CA, CB and OG:================================*/ double Chi1FromNCACBOG_ (AtomS *atomSP, size_t atom_startI, size_t atom_endI) { static VectorS N_vectorS, CA_vectorS, CB_vectorS, OG_vectorS; int n; VectorS CA_N_vectorS, CA_CB_vectorS; VectorS CB_CA_vectorS, CB_OG_vectorS; VectorS u1S, u2S; VectorS v1S, v2S; double denom, ratio, alpha; double chi1; /* Extract N, CA, CB and OG coordinates: */ n = ExtractFourAtoms_ (&N_vectorS, &CA_vectorS, &CB_vectorS, &OG_vectorS, "N", "CA", "CB", "OG", atomSP, atom_startI, atom_endI); /* All four atoms are required to calculate the angle chi1: */ if (n < 4) return BADDIHEDANGLE; /* The first pair of auxiliary vectors: */ CA_N_vectorS.x = N_vectorS.x - CA_vectorS.x; CA_N_vectorS.y = N_vectorS.y - CA_vectorS.y; CA_N_vectorS.z = N_vectorS.z - CA_vectorS.z; CA_CB_vectorS.x = CB_vectorS.x - CA_vectorS.x; CA_CB_vectorS.y = CB_vectorS.y - CA_vectorS.y; CA_CB_vectorS.z = CB_vectorS.z - CA_vectorS.z; /* The second pair of auxiliary vectors: */ CB_CA_vectorS.x = CA_vectorS.x - CB_vectorS.x; CB_CA_vectorS.y = CA_vectorS.y - CB_vectorS.y; CB_CA_vectorS.z = CA_vectorS.z - CB_vectorS.z; CB_OG_vectorS.x = OG_vectorS.x - CB_vectorS.x; CB_OG_vectorS.y = OG_vectorS.y - CB_vectorS.y; CB_OG_vectorS.z = OG_vectorS.z - CB_vectorS.z; /* Two vectors perpendicular to CA_CB_vectorS, mutually orthogonal, */ /* the second in the plane defined by CA_N_vectorS and CA_CB_vectorS: */ VectorProduct_ (&u1S, &CA_N_vectorS, &CA_CB_vectorS); VectorProduct_ (&u2S, &u1S, &CA_CB_vectorS); /* Two vectors perpendicular to CB_CA_vectorS, mutually orthogonal, */ /* the second in the plane defined by CB_CA_vectorS and CB_OG_vectorS: */ VectorProduct_ (&v1S, &CB_CA_vectorS, &CB_OG_vectorS); VectorProduct_ (&v2S, &CB_CA_vectorS, &v1S); /* Calculate the angle alpha, which will be used to calculate chi1: */ /* Avoid division by zero: */ denom = AbsoluteValue_ (&u1S) * AbsoluteValue_ (&v1S); if (denom == 0.0) return BADDIHEDANGLE; /* Use the scalar product to calculate the cosine of the angle: */ ratio = ScalarProduct_ (&u1S, &v1S) / denom; /* Arc cosine is very sensitive to floating point errors: */ if (ratio <= -1.0) alpha = 3.1415927; else if (ratio >= 1.0) alpha = 0.0; else alpha = acos (ratio); /* There are two possible solutions; the right one is resolved here: */ if (ScalarProduct_ (&v2S, &u1S) >= 0) chi1 = alpha; else chi1 = -alpha; /* Return the angle (in radians): */ return chi1; } /*===========================================================================*/ garlic-1.6/chi1_from_ncacbsg.c0000644000076500007650000000726007341017640016611 0ustar zuciczucic00000000000000/* Copyright (C) 2001 Damir Zucic */ /*============================================================================= chi1_from_ncacbsg.c Purpose: Calculate dihedral angle chi1, using N, CA, CB and SG coordinates. Input: (1) Pointer to AtomS structure, pointing to the first atom of the current macromolecular complex. (2) Index of the first atom of the current residue. (3) Index of the last atom of the currrent residue. Output: Return value. Return value: (1) Dihedral angle chi1, on success. (2) BADDIHEDANGLE on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int ExtractFourAtoms_ (VectorS *, VectorS *, VectorS *, VectorS *, char *, char *, char *, char *, AtomS *, size_t, size_t); void VectorProduct_ (VectorS *, VectorS *, VectorS *); double AbsoluteValue_ (VectorS *); double ScalarProduct_ (VectorS *, VectorS *); /*======calculate chi1 from N, CA, CB and SG:================================*/ double Chi1FromNCACBSG_ (AtomS *atomSP, size_t atom_startI, size_t atom_endI) { static VectorS N_vectorS, CA_vectorS, CB_vectorS, SG_vectorS; int n; VectorS CA_N_vectorS, CA_CB_vectorS; VectorS CB_CA_vectorS, CB_SG_vectorS; VectorS u1S, u2S; VectorS v1S, v2S; double denom, ratio, alpha; double chi1; /* Extract N, CA, CB and SG coordinates: */ n = ExtractFourAtoms_ (&N_vectorS, &CA_vectorS, &CB_vectorS, &SG_vectorS, "N", "CA", "CB", "SG", atomSP, atom_startI, atom_endI); /* All four atoms are required to calculate the angle chi1: */ if (n < 4) return BADDIHEDANGLE; /* The first pair of auxiliary vectors: */ CA_N_vectorS.x = N_vectorS.x - CA_vectorS.x; CA_N_vectorS.y = N_vectorS.y - CA_vectorS.y; CA_N_vectorS.z = N_vectorS.z - CA_vectorS.z; CA_CB_vectorS.x = CB_vectorS.x - CA_vectorS.x; CA_CB_vectorS.y = CB_vectorS.y - CA_vectorS.y; CA_CB_vectorS.z = CB_vectorS.z - CA_vectorS.z; /* The second pair of auxiliary vectors: */ CB_CA_vectorS.x = CA_vectorS.x - CB_vectorS.x; CB_CA_vectorS.y = CA_vectorS.y - CB_vectorS.y; CB_CA_vectorS.z = CA_vectorS.z - CB_vectorS.z; CB_SG_vectorS.x = SG_vectorS.x - CB_vectorS.x; CB_SG_vectorS.y = SG_vectorS.y - CB_vectorS.y; CB_SG_vectorS.z = SG_vectorS.z - CB_vectorS.z; /* Two vectors perpendicular to CA_CB_vectorS, mutually orthogonal, */ /* the second in the plane defined by CA_N_vectorS and CA_CB_vectorS: */ VectorProduct_ (&u1S, &CA_N_vectorS, &CA_CB_vectorS); VectorProduct_ (&u2S, &u1S, &CA_CB_vectorS); /* Two vectors perpendicular to CB_CA_vectorS, mutually orthogonal, */ /* the second in the plane defined by CB_CA_vectorS and CB_SG_vectorS: */ VectorProduct_ (&v1S, &CB_CA_vectorS, &CB_SG_vectorS); VectorProduct_ (&v2S, &CB_CA_vectorS, &v1S); /* Calculate the angle alpha, which will be used to calculate chi1: */ /* Avoid division by zero: */ denom = AbsoluteValue_ (&u1S) * AbsoluteValue_ (&v1S); if (denom == 0.0) return BADDIHEDANGLE; /* Use the scalar product to calculate the cosine of the angle: */ ratio = ScalarProduct_ (&u1S, &v1S) / denom; /* Arc cosine is very sensitive to floating point errors: */ if (ratio <= -1.0) alpha = 3.1415927; else if (ratio >= 1.0) alpha = 0.0; else alpha = acos (ratio); /* There are two possible solutions; the right one is resolved here: */ if (ScalarProduct_ (&v2S, &u1S) >= 0) chi1 = alpha; else chi1 = -alpha; /* Return the angle (in radians): */ return chi1; } /*===========================================================================*/ garlic-1.6/small_omega.c0000644000076500007650000002075507501462523015550 0ustar zuciczucic00000000000000/* Copyright (C) 2001-2002 Damir Zucic */ /*============================================================================= small_omega.c Purpose: Draw small plot showing the current omega angle with statistical distribution of omega values. This plot is used while editing the omega angle. The distribution was derived using a collection of high resolution X-ray structures (1.00 angstroms or better). The plot is placed to the bottom right corner. Input: (1) Pointer to MolComplexS structure. (2) Pointer to RuntimeS structure. (3) Pointer to GUIS structure. Output: (1) Small omega plot drawn to the hidden pixmap. (2) Return value. Return value: (1) Positive on success. (2) Negative on failure. =============================================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int ParseColor_ (RGBS *, unsigned long *, GUIS *, char *, char *); /*======draw small omega plot:===============================================*/ int SmallOmega_ (MolComplexS *mol_complexSP, RuntimeS *runtimeSP, GUIS *guiSP) { int residuesN, residueI; int chosen_residue_foundF; static ResidueS *residueSP; size_t atom_startI, atom_endI; static AtomS *first_atomSP; int inner_width, inner_height, outer_width, outer_height; int screen_x0, screen_y0, screen_x1, screen_y1; RGBS rgbS; unsigned long colorID; static double peak1_xA[19] = {0.000, 0.054, 0.045, 0.040, 0.036, 0.030, 0.026, 0.020, 0.017, 0.015, 0.014, 0.011, 0.010, 0.007, 0.006, 0.004, 0.002, 0.001, 0.001}; static double peak1_yA[19] = {1.000, 1.000, 0.920, 0.850, 0.810, 0.770, 0.700, 0.670, 0.613, 0.558, 0.482, 0.392, 0.302, 0.251, 0.231, 0.206, 0.186, 0.161, 1.000}; static int peak1_pointsN = 19; static double peak2_xA[6] = {0.521, 0.497, 0.474, 0.456, 0.432, 0.425}; static double peak2_yA[6] = {1.000, 0.980, 0.982, 0.982, 0.980, 1.000}; static int peak2_pointsN = 6; static double peak3_xA[20] = {1.000, 0.999, 0.996, 0.994, 0.991, 0.990, 0.989, 0.987, 0.987, 0.983, 0.980, 0.977, 0.973, 0.971, 0.965, 0.962, 0.958, 0.951, 0.945, 0.938}; static double peak3_yA[20] = {1.000, 0.106, 0.025, 0.015, 0.050, 0.080, 0.126, 0.251, 0.362, 0.467, 0.603, 0.729, 0.814, 0.859, 0.905, 0.935, 0.960, 0.975, 0.985, 1.000}; static int peak3_pointsN = 20; int pointI; XPoint pointSA[30]; double d; int omegaI; /* Prepare and check the number of residues: */ residuesN = mol_complexSP->residuesN; if (residuesN <= 0) return -1; /* Find the residue to which the omega plot will be assigned: */ chosen_residue_foundF = 0; for (residueI = 0; residueI < residuesN; residueI++) { /* Pointer to the current residue: */ residueSP = mol_complexSP->residueSP + residueI; /* Prepare the atomic index range: */ atom_startI = residueSP->residue_startI; atom_endI = residueSP->residue_endI; /* Pointer to the first atom of the current residue: */ first_atomSP = mol_complexSP->atomSP + atom_startI; /* Editing of a single omega angle requested: */ if (runtimeSP->edit_single_bondF) { /* Check the array index of N atom, it is assumed that */ /* it was stored as the second array index somewhere: */ if ((runtimeSP->atom2_arrayI >= atom_startI) && (runtimeSP->atom2_arrayI <= atom_endI)) { chosen_residue_foundF = 1; break; } } /* Editing of omega for all selected residues requested: */ else { /* If the first atom of the current residue is */ /* selected, treat this residue as selected: */ if (first_atomSP->selectedF) { chosen_residue_foundF = 1; break; } } } /* Check was residue found at all: */ if (!chosen_residue_foundF) return -2; /* The width and height of the omega plot: */ inner_width = (int) guiSP->main_win_free_area_width - 11; if (inner_width < 10) inner_width = 10; inner_height = (int) guiSP->main_win_free_area_height / 8; if (inner_height < 10) inner_height = 10; outer_width = inner_width + 8; outer_height = inner_height + 8; /* The top left corner of the background square: */ screen_x0 = 1; screen_y0 = guiSP->main_win_free_area_height - outer_height - 2; /* Draw the filled square. Use a shade of orange color: */ ParseColor_ (&rgbS, &colorID, guiSP, "RGB:D8D8/B7B7/9999", "white"); XSetForeground (guiSP->displaySP, guiSP->theGCA[0], colorID); XFillRectangle (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0, screen_y0, outer_width, outer_height); /* Draw the border, using the main window foreground color: */ XSetForeground (guiSP->displaySP, guiSP->theGCA[0], guiSP->main_winS.fg_colorID); XDrawRectangle (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0, screen_y0, outer_width, outer_height); /* Draw peaks. */ /* Prepare a shade of blue: */ ParseColor_ (&rgbS, &colorID, guiSP, "RGB:2222/5555/DDDD", "white"); XSetForeground (guiSP->displaySP, guiSP->theGCA[0], colorID); /* The XPoint structures for the first filled polygon: */ for (pointI = 0; pointI < peak1_pointsN; pointI++) { d = guiSP->main_win_free_area_width - outer_width + 2 + inner_width * peak1_xA[pointI]; pointSA[pointI].x = (short) d; d = guiSP->main_win_free_area_height - outer_height + 2 + inner_height * peak1_yA[pointI]; pointSA[pointI].y = (short) d; } /* Draw the first filled polygon: */ XFillPolygon (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], pointSA, peak1_pointsN, Nonconvex, CoordModeOrigin); /* The XPoint structures for the second filled polygon: */ for (pointI = 0; pointI < peak2_pointsN; pointI++) { d = guiSP->main_win_free_area_width - outer_width + 2 + inner_width * peak2_xA[pointI]; pointSA[pointI].x = (short) d; d = guiSP->main_win_free_area_height - outer_height + 2 + inner_height * peak2_yA[pointI]; pointSA[pointI].y = (short) d; } /* Draw the second filled polygon: */ XFillPolygon (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], pointSA, peak2_pointsN, Nonconvex, CoordModeOrigin); /* The XPoint structures for the third filled polygon: */ for (pointI = 0; pointI < peak3_pointsN; pointI++) { d = guiSP->main_win_free_area_width - outer_width + 2 + inner_width * peak3_xA[pointI]; pointSA[pointI].x = (short) d; d = guiSP->main_win_free_area_height - outer_height + 2 + inner_height * peak3_yA[pointI]; pointSA[pointI].y = (short) d; } /* Draw the third filled polygon: */ XFillPolygon (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], pointSA, peak3_pointsN, Nonconvex, CoordModeOrigin); /* Prepare black color: */ XSetForeground (guiSP->displaySP, guiSP->theGCA[0], guiSP->black_colorID); /* Draw bounding rectangle: */ screen_x0 = guiSP->main_win_free_area_width - outer_width + 2; screen_y0 = guiSP->main_win_free_area_height - outer_height + 2; XDrawRectangle (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0, screen_y0, inner_width, inner_height); /* Draw vertical grid using the spacing of 90 degrees: */ screen_x0 = guiSP->main_win_free_area_width - outer_width + 2; screen_y0 = guiSP->main_win_free_area_height - outer_height + 2; screen_y1 = screen_y0 + inner_height; for (omegaI = 0; omegaI <= 5; omegaI++) { d = (double) inner_width * ((double) omegaI * 0.25) + 0.5; screen_x1 = screen_x0 + (int) d; XDrawLine (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x1, screen_y0, screen_x1, screen_y1); } /* Draw the symbol at the position defined by the omega value. */ /* Prepare the symbol position: */ d = (double) inner_width * (residueSP->omega + 3.1415927) * 0.15915494; screen_x0 = guiSP->main_win_free_area_width - outer_width + 2 + (int) d; screen_y0 = guiSP->main_win_free_area_height - outer_height + 2; /* Draw the inner part of the symbol (yellow): */ XSetForeground (guiSP->displaySP, guiSP->theGCA[0], guiSP->yellow_colorID); XFillRectangle (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0 - 1, screen_y0, 1, inner_height); /* Draw the outer part of the symbol (red): */ XSetForeground (guiSP->displaySP, guiSP->theGCA[0], guiSP->red_colorID); XDrawRectangle (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x0 - 2, screen_y0, 2, inner_height); /* Return positive value on success: */ return 1; } /*===========================================================================*/ garlic-1.6/extract_cacb.c0000644000076500007650000000443107356622222015705 0ustar zuciczucic00000000000000/* Copyright (C) 2001 Damir Zucic */ /*============================================================================= extract_cacb.c Purpose: Extract CA and CB coordinates for a given residue. Input: (1) Pointer to VectorS structure, where CA coord. will be stored. (2) Pointer to VectorS structure, where CB coord. will be stored. (3) Pointer to AtomS structure, pointing to the first element of the atomic array. (4) Index of the first atom of a given residue. (5) Index of the last atom of a given residue. Output: (1) VectorS structures filled with data. (2) Return value. Return value: (1) The number of successfully extracted vectors (at least zero, at most two). Notes: (1) Some files contain more than one entry for some atoms. Garlic uses only the first entry and discards other entries for the same atom. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======extract CA and CB coordinates:=======================================*/ int ExtractCACB_ (VectorS *CA_vectorSP, VectorS *CB_vectorSP, AtomS *atomSP, size_t atom_startI, size_t atom_endI) { int vectors_extractedN = 0; size_t atomI; AtomS *curr_atomSP; int CA_foundF = 0, CB_foundF = 0; /* Scan the given residue: */ for (atomI = atom_startI; atomI <= atom_endI; atomI++) { /* Pointer to the current atom: */ curr_atomSP = atomSP + atomI; /* CA: */ if (strcmp (curr_atomSP->raw_atomS.pure_atom_nameA, "CA") == 0) { if (CA_foundF) continue; CA_vectorSP->x = curr_atomSP->raw_atomS.x[0]; CA_vectorSP->y = curr_atomSP->raw_atomS.y; CA_vectorSP->z = curr_atomSP->raw_atomS.z[0]; vectors_extractedN++; CA_foundF = 1; } /* CB: */ else if (strcmp (curr_atomSP->raw_atomS.pure_atom_nameA, "CB") == 0) { if (CB_foundF) continue; CB_vectorSP->x = curr_atomSP->raw_atomS.x[0]; CB_vectorSP->y = curr_atomSP->raw_atomS.y; CB_vectorSP->z = curr_atomSP->raw_atomS.z[0]; vectors_extractedN++; CB_foundF = 1; } } /* Return the number of extracted vectors: */ return vectors_extractedN; } /*===========================================================================*/ garlic-1.6/chi1_from_ncacbog1.c0000644000076500007650000000730107341017655016670 0ustar zuciczucic00000000000000/* Copyright (C) 2001 Damir Zucic */ /*============================================================================= chi1_from_ncacbog1.c Purpose: Calculate dihedral angle chi1, using N, CA, CB and OG1 coordinates. Input: (1) Pointer to AtomS structure, pointing to the first atom of the current macromolecular complex. (2) Index of the first atom of the current residue. (3) Index of the last atom of the currrent residue. Output: Return value. Return value: (1) Dihedral angle chi1, on success. (2) BADDIHEDANGLE on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int ExtractFourAtoms_ (VectorS *, VectorS *, VectorS *, VectorS *, char *, char *, char *, char *, AtomS *, size_t, size_t); void VectorProduct_ (VectorS *, VectorS *, VectorS *); double AbsoluteValue_ (VectorS *); double ScalarProduct_ (VectorS *, VectorS *); /*======calculate chi1 from N, CA, CB and OG1:================================*/ double Chi1FromNCACBOG1_ (AtomS *atomSP, size_t atom_startI, size_t atom_endI) { static VectorS N_vectorS, CA_vectorS, CB_vectorS, OG1_vectorS; int n; VectorS CA_N_vectorS, CA_CB_vectorS; VectorS CB_CA_vectorS, CB_OG1_vectorS; VectorS u1S, u2S; VectorS v1S, v2S; double denom, ratio, alpha; double chi1; /* Extract N, CA, CB and OG1 coordinates: */ n = ExtractFourAtoms_ (&N_vectorS, &CA_vectorS, &CB_vectorS, &OG1_vectorS, "N", "CA", "CB", "OG1", atomSP, atom_startI, atom_endI); /* All four atoms are required to calculate the angle chi1: */ if (n < 4) return BADDIHEDANGLE; /* The first pair of auxiliary vectors: */ CA_N_vectorS.x = N_vectorS.x - CA_vectorS.x; CA_N_vectorS.y = N_vectorS.y - CA_vectorS.y; CA_N_vectorS.z = N_vectorS.z - CA_vectorS.z; CA_CB_vectorS.x = CB_vectorS.x - CA_vectorS.x; CA_CB_vectorS.y = CB_vectorS.y - CA_vectorS.y; CA_CB_vectorS.z = CB_vectorS.z - CA_vectorS.z; /* The second pair of auxiliary vectors: */ CB_CA_vectorS.x = CA_vectorS.x - CB_vectorS.x; CB_CA_vectorS.y = CA_vectorS.y - CB_vectorS.y; CB_CA_vectorS.z = CA_vectorS.z - CB_vectorS.z; CB_OG1_vectorS.x = OG1_vectorS.x - CB_vectorS.x; CB_OG1_vectorS.y = OG1_vectorS.y - CB_vectorS.y; CB_OG1_vectorS.z = OG1_vectorS.z - CB_vectorS.z; /* Two vectors perpendicular to CA_CB_vectorS, mutually orthogonal, */ /* the second in the plane defined by CA_N_vectorS and CA_CB_vectorS: */ VectorProduct_ (&u1S, &CA_N_vectorS, &CA_CB_vectorS); VectorProduct_ (&u2S, &u1S, &CA_CB_vectorS); /* Two vectors perpendicular to CB_CA_vectorS, mutually orthogonal, */ /* the second in the plane defined by CB_CA_vectorS and CB_OG1_vectorS: */ VectorProduct_ (&v1S, &CB_CA_vectorS, &CB_OG1_vectorS); VectorProduct_ (&v2S, &CB_CA_vectorS, &v1S); /* Calculate the angle alpha, which will be used to calculate chi1: */ /* Avoid division by zero: */ denom = AbsoluteValue_ (&u1S) * AbsoluteValue_ (&v1S); if (denom == 0.0) return BADDIHEDANGLE; /* Use the scalar product to calculate the cosine of the angle: */ ratio = ScalarProduct_ (&u1S, &v1S) / denom; /* Arc cosine is very sensitive to floating point errors: */ if (ratio <= -1.0) alpha = 3.1415927; else if (ratio >= 1.0) alpha = 0.0; else alpha = acos (ratio); /* There are two possible solutions; the right one is resolved here: */ if (ScalarProduct_ (&v2S, &u1S) >= 0) chi1 = alpha; else chi1 = -alpha; /* Return the angle (in radians): */ return chi1; } /*===========================================================================*/ garlic-1.6/select_3nz4.c0000644000076500007650000001521410403044554015412 0ustar zuciczucic00000000000000/* Copyright (C) 2006 Damir Zucic */ /*============================================================================= select_3nz4.c Purpose: Select the sequence fragment which contains three or more neg. or zwitterionic residues in a window of four residues. ASP, GLU, ASN and GLN are taken into account. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. (3) Selection mode index (0 = overwrite, 1 = restrict, 2 = expand previous selection). Output: (1) The flag selectedF set to one for selected atoms in every caught macromolecular complex. (2) Return value. Return value: (1) The number of selected atoms (zero or positive value). ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======select three or more negative or zwitterionic residues:==============*/ long Select3NZ4_ (MolComplexS *mol_complexSP, int mol_complexesN, int selection_modeI) { long selected_atomsN = 0; int mol_complexI; MolComplexS *curr_mol_complexSP; int atomsN, atomI; AtomS *curr_atomSP; int residuesN, residueI, windowI, combinedI; ResidueS *curr_residueSP; AtomS *first_atomSP; char *nameP; int negative_zwitterN; int first_atomI, last_atomI; /* Check every macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check is the current macromolecular complex caught: */ if (curr_mol_complexSP->catchF == 0) continue; /* Prepare and check the number of atoms in the current complex: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Copy the number of residues in the current macromol. complex: */ residuesN = curr_mol_complexSP->residuesN; if (residuesN == 0) continue; /* Backup the current selection if selection mode is restrict: */ if (selection_modeI == 1) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Copy the selection flag: */ curr_atomSP->previous_selectedF = curr_atomSP->selectedF; } } /* Unselect everything if selection mode is overwrite or restrict: */ if ((selection_modeI == 0) || (selection_modeI == 1)) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Unselect the current atom: */ curr_atomSP->selectedF = 0; } } /* Scan the residues of the current macromolecular complex: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Reset the number of negative and zwitterionic residues: */ negative_zwitterN = 0; /* Scan the window of four residues, */ /* starting from the current residue: */ for (windowI = 0; windowI < 4; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI >= residuesN) break; /* Residue associated with the combined index: */ curr_residueSP = curr_mol_complexSP->residueSP + combinedI; /* Pointer to the first atom of current residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Pointer to the name of the current residue: */ nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Check is this residue negative or zwitterionic: */ if ((strcmp (nameP, "ASP") == 0) || (strcmp (nameP, "GLU") == 0) || (strcmp (nameP, "ASN") == 0) || (strcmp (nameP, "GLN") == 0)) negative_zwitterN++; } /* If there were three or more negative and zwitterionic */ /* residues in a window of four residues, the triplet is */ /* found. If there were two or less, take the next resid. */ if (negative_zwitterN < 3) continue; /* If this point is reached, rescan the window of four */ /* residues and select negative and zwitterionic resid. */ /* Scan the window of four residues, */ /* starting from the current residue: */ for (windowI = 0; windowI < 4; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI >= residuesN) break; /* Residue associated with the combined index: */ curr_residueSP = curr_mol_complexSP->residueSP + combinedI; /* Pointer to the first atom of current residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Pointer to the name of the current residue: */ nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Check is this residue negative or zwitterionic: */ if ((strcmp (nameP, "ASP") != 0) && (strcmp (nameP, "GLU") != 0) && (strcmp (nameP, "ASN") != 0) && (strcmp (nameP, "GLN") != 0)) continue; /* If this point is reached, select */ /* all atoms of the current residue. */ /* The indices of the first and the */ /* last atom of the current residue: */ first_atomI = curr_residueSP->residue_startI; last_atomI = curr_residueSP->residue_endI; /* Select all atoms of the current residue: */ for (atomI = first_atomI; atomI <= last_atomI; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Select the current atom: */ curr_atomSP->selectedF = 1; /* Update the counter of selected atoms: */ selected_atomsN++; } } /* End of residueI loop: */ } /* Combine the current selection with the */ /* previous, if selection mode is restrict: */ if (selection_modeI == 1) { /* Reset the counter of selected atoms. The */ /* selected atoms should be counted again. */ selected_atomsN = 0; /* Combine the old and the new selection flag: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Combine selection flags: */ curr_atomSP->selectedF *= curr_atomSP->previous_selectedF; /* Check the selection flag; increase */ /* the count of selected residues if */ /* the selection flag is equal to one: */ if (curr_atomSP->selectedF) selected_atomsN++; } } /* Update the position_changedF (some atoms may have bad color): */ curr_mol_complexSP->position_changedF = 1; /* End of mol_complexI loop: */ } /* Return the number of selected atoms: */ return selected_atomsN; } /*===========================================================================*/ garlic-1.6/select_4cz5.c0000644000076500007650000001547610153564424015420 0ustar zuciczucic00000000000000/* Copyright (C) 2004 Damir Zucic */ /*============================================================================= select_4cz5.c Purpose: Select the sequence fragment which contains four or more charged or zwitterionic residues in a window of five residues. ASP, GLU, ASN, GLN, ARG, LYS and HIS are taken into account. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. (3) Selection mode index (0 = overwrite, 1 = restrict, 2 = expand previous selection). Output: (1) The flag selectedF set to one for selected atoms in every caught macromolecular complex. (2) Return value. Return value: (1) The number of selected atoms (zero or positive value). ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======select four or more charged or zwitterionic residues:================*/ long Select4CZ5_ (MolComplexS *mol_complexSP, int mol_complexesN, int selection_modeI) { long selected_atomsN = 0; int mol_complexI; MolComplexS *curr_mol_complexSP; int atomsN, atomI; AtomS *curr_atomSP; int residuesN, residueI, windowI, combinedI; ResidueS *curr_residueSP; AtomS *first_atomSP; char *nameP; int very_polarN; int first_atomI, last_atomI; /* Check every macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check is the current macromolecular complex caught: */ if (curr_mol_complexSP->catchF == 0) continue; /* Prepare and check the number of atoms in the current complex: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Copy the number of residues in the current macromol. complex: */ residuesN = curr_mol_complexSP->residuesN; if (residuesN == 0) continue; /* Backup the current selection if selection mode is restrict: */ if (selection_modeI == 1) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Copy the selection flag: */ curr_atomSP->previous_selectedF = curr_atomSP->selectedF; } } /* Unselect everything if selection mode is overwrite or restrict: */ if ((selection_modeI == 0) || (selection_modeI == 1)) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Unselect the current atom: */ curr_atomSP->selectedF = 0; } } /* Scan the residues of the current macromolecular complex: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Reset the counter which counts very polar residues: */ very_polarN = 0; /* Scan the window of five residues, */ /* starting from the current residue: */ for (windowI = 0; windowI < 5; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI >= residuesN) break; /* Residue associated with the combined index: */ curr_residueSP = curr_mol_complexSP->residueSP + combinedI; /* Pointer to the first atom of current residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Pointer to the name of the current residue: */ nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Check is this residue very polar: */ if ((strcmp (nameP, "ASP") == 0) || (strcmp (nameP, "GLU") == 0) || (strcmp (nameP, "ASN") == 0) || (strcmp (nameP, "GLN") == 0) || (strcmp (nameP, "ARG") == 0) || (strcmp (nameP, "LYS") == 0) || (strcmp (nameP, "HIS") == 0)) very_polarN++; } /* If there were four or more very polar residues in */ /* a window of five residues, the quartet is found. */ /* If there were three or less, take the next residue. */ if (very_polarN < 4) continue; /* If this point is reached, scan the window of five */ /* residues again and select very polar residues. */ /* Scan the window of five residues, */ /* starting from the current residue: */ for (windowI = 0; windowI < 5; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI >= residuesN) break; /* Residue associated with the combined index: */ curr_residueSP = curr_mol_complexSP->residueSP + combinedI; /* Pointer to the first atom of current residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Pointer to the name of the current residue: */ nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Check is this residue very polar: */ if ((strcmp (nameP, "ASP") != 0) && (strcmp (nameP, "GLU") != 0) && (strcmp (nameP, "ASN") != 0) && (strcmp (nameP, "GLN") != 0) && (strcmp (nameP, "ARG") != 0) && (strcmp (nameP, "LYS") != 0) && (strcmp (nameP, "HIS") != 0)) continue; /* If this point is reached, select */ /* all atoms of the current residue. */ /* The indices of the first and the */ /* last atom of the current residue: */ first_atomI = curr_residueSP->residue_startI; last_atomI = curr_residueSP->residue_endI; /* Select all atoms of the current residue: */ for (atomI = first_atomI; atomI <= last_atomI; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Select the current atom: */ curr_atomSP->selectedF = 1; /* Update the counter of selected atoms: */ selected_atomsN++; } } /* End of residueI loop: */ } /* Combine the current selection with the */ /* previous, if selection mode is restrict: */ if (selection_modeI == 1) { /* Reset the counter of selected atoms. The */ /* selected atoms should be counted again. */ selected_atomsN = 0; /* Combine the old and the new selection flag: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Combine selection flags: */ curr_atomSP->selectedF *= curr_atomSP->previous_selectedF; /* Check the selection flag; increase */ /* the count of selected residues if */ /* the selection flag is equal to one: */ if (curr_atomSP->selectedF) selected_atomsN++; } } /* Update the position_changedF (some atoms may have bad color): */ curr_mol_complexSP->position_changedF = 1; /* End of mol_complexI loop: */ } /* Return the number of selected atoms: */ return selected_atomsN; } /*===========================================================================*/ garlic-1.6/select_3nz5.c0000644000076500007650000001521410403044411015403 0ustar zuciczucic00000000000000/* Copyright (C) 2006 Damir Zucic */ /*============================================================================= select_3nz5.c Purpose: Select the sequence fragment which contains three or more neg. or zwitterionic residues in a window of five residues. ASP, GLU, ASN and GLN are taken into account. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. (3) Selection mode index (0 = overwrite, 1 = restrict, 2 = expand previous selection). Output: (1) The flag selectedF set to one for selected atoms in every caught macromolecular complex. (2) Return value. Return value: (1) The number of selected atoms (zero or positive value). ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======select three or more negative or zwitterionic residues:==============*/ long Select3NZ5_ (MolComplexS *mol_complexSP, int mol_complexesN, int selection_modeI) { long selected_atomsN = 0; int mol_complexI; MolComplexS *curr_mol_complexSP; int atomsN, atomI; AtomS *curr_atomSP; int residuesN, residueI, windowI, combinedI; ResidueS *curr_residueSP; AtomS *first_atomSP; char *nameP; int negative_zwitterN; int first_atomI, last_atomI; /* Check every macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check is the current macromolecular complex caught: */ if (curr_mol_complexSP->catchF == 0) continue; /* Prepare and check the number of atoms in the current complex: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Copy the number of residues in the current macromol. complex: */ residuesN = curr_mol_complexSP->residuesN; if (residuesN == 0) continue; /* Backup the current selection if selection mode is restrict: */ if (selection_modeI == 1) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Copy the selection flag: */ curr_atomSP->previous_selectedF = curr_atomSP->selectedF; } } /* Unselect everything if selection mode is overwrite or restrict: */ if ((selection_modeI == 0) || (selection_modeI == 1)) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Unselect the current atom: */ curr_atomSP->selectedF = 0; } } /* Scan the residues of the current macromolecular complex: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Reset the number of negative and zwitterionic residues: */ negative_zwitterN = 0; /* Scan the window of five residues, */ /* starting from the current residue: */ for (windowI = 0; windowI < 5; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI >= residuesN) break; /* Residue associated with the combined index: */ curr_residueSP = curr_mol_complexSP->residueSP + combinedI; /* Pointer to the first atom of current residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Pointer to the name of the current residue: */ nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Check is this residue negative or zwitterionic: */ if ((strcmp (nameP, "ASP") == 0) || (strcmp (nameP, "GLU") == 0) || (strcmp (nameP, "ASN") == 0) || (strcmp (nameP, "GLN") == 0)) negative_zwitterN++; } /* If there were three or more negative and zwitterionic */ /* residues in a window of five residues, the triplet is */ /* found. If there were two or less, take the next resid. */ if (negative_zwitterN < 3) continue; /* If this point is reached, rescan the window of five */ /* residues and select negative and zwitterionic resid. */ /* Scan the window of five residues, */ /* starting from the current residue: */ for (windowI = 0; windowI < 5; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI >= residuesN) break; /* Residue associated with the combined index: */ curr_residueSP = curr_mol_complexSP->residueSP + combinedI; /* Pointer to the first atom of current residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Pointer to the name of the current residue: */ nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Check is this residue negative or zwitterionic: */ if ((strcmp (nameP, "ASP") != 0) && (strcmp (nameP, "GLU") != 0) && (strcmp (nameP, "ASN") != 0) && (strcmp (nameP, "GLN") != 0)) continue; /* If this point is reached, select */ /* all atoms of the current residue. */ /* The indices of the first and the */ /* last atom of the current residue: */ first_atomI = curr_residueSP->residue_startI; last_atomI = curr_residueSP->residue_endI; /* Select all atoms of the current residue: */ for (atomI = first_atomI; atomI <= last_atomI; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Select the current atom: */ curr_atomSP->selectedF = 1; /* Update the counter of selected atoms: */ selected_atomsN++; } } /* End of residueI loop: */ } /* Combine the current selection with the */ /* previous, if selection mode is restrict: */ if (selection_modeI == 1) { /* Reset the counter of selected atoms. The */ /* selected atoms should be counted again. */ selected_atomsN = 0; /* Combine the old and the new selection flag: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Combine selection flags: */ curr_atomSP->selectedF *= curr_atomSP->previous_selectedF; /* Check the selection flag; increase */ /* the count of selected residues if */ /* the selection flag is equal to one: */ if (curr_atomSP->selectedF) selected_atomsN++; } } /* Update the position_changedF (some atoms may have bad color): */ curr_mol_complexSP->position_changedF = 1; /* End of mol_complexI loop: */ } /* Return the number of selected atoms: */ return selected_atomsN; } /*===========================================================================*/ garlic-1.6/select_4cz6.c0000644000076500007650000001547110153564557015423 0ustar zuciczucic00000000000000/* Copyright (C) 2004 Damir Zucic */ /*============================================================================= select_4cz6.c Purpose: Select the sequence fragment which contains four or more charged or zwitterionic residues in a window of six residues. ASP, GLU, ASN, GLN, ARG, LYS and HIS are taken into account. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. (3) Selection mode index (0 = overwrite, 1 = restrict, 2 = expand previous selection). Output: (1) The flag selectedF set to one for selected atoms in every caught macromolecular complex. (2) Return value. Return value: (1) The number of selected atoms (zero or positive value). ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======select four or more charged or zwitterionic residues:================*/ long Select4CZ6_ (MolComplexS *mol_complexSP, int mol_complexesN, int selection_modeI) { long selected_atomsN = 0; int mol_complexI; MolComplexS *curr_mol_complexSP; int atomsN, atomI; AtomS *curr_atomSP; int residuesN, residueI, windowI, combinedI; ResidueS *curr_residueSP; AtomS *first_atomSP; char *nameP; int very_polarN; int first_atomI, last_atomI; /* Check every macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check is the current macromolecular complex caught: */ if (curr_mol_complexSP->catchF == 0) continue; /* Prepare and check the number of atoms in the current complex: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Copy the number of residues in the current macromol. complex: */ residuesN = curr_mol_complexSP->residuesN; if (residuesN == 0) continue; /* Backup the current selection if selection mode is restrict: */ if (selection_modeI == 1) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Copy the selection flag: */ curr_atomSP->previous_selectedF = curr_atomSP->selectedF; } } /* Unselect everything if selection mode is overwrite or restrict: */ if ((selection_modeI == 0) || (selection_modeI == 1)) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Unselect the current atom: */ curr_atomSP->selectedF = 0; } } /* Scan the residues of the current macromolecular complex: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Reset the counter which counts very polar residues: */ very_polarN = 0; /* Scan the window of six residues, */ /* starting from the current residue: */ for (windowI = 0; windowI < 6; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI >= residuesN) break; /* Residue associated with the combined index: */ curr_residueSP = curr_mol_complexSP->residueSP + combinedI; /* Pointer to the first atom of current residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Pointer to the name of the current residue: */ nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Check is this residue very polar: */ if ((strcmp (nameP, "ASP") == 0) || (strcmp (nameP, "GLU") == 0) || (strcmp (nameP, "ASN") == 0) || (strcmp (nameP, "GLN") == 0) || (strcmp (nameP, "ARG") == 0) || (strcmp (nameP, "LYS") == 0) || (strcmp (nameP, "HIS") == 0)) very_polarN++; } /* If there were four or more very polar residues in */ /* a window of six residues, the quartet is found. If */ /* there were three or less, take the next residue. */ if (very_polarN < 4) continue; /* If this point is reached, scan the window of six */ /* residues again and select very polar residues. */ /* Scan the window of six residues, */ /* starting from the current residue: */ for (windowI = 0; windowI < 6; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI >= residuesN) break; /* Residue associated with the combined index: */ curr_residueSP = curr_mol_complexSP->residueSP + combinedI; /* Pointer to the first atom of current residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Pointer to the name of the current residue: */ nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Check is this residue very polar: */ if ((strcmp (nameP, "ASP") != 0) && (strcmp (nameP, "GLU") != 0) && (strcmp (nameP, "ASN") != 0) && (strcmp (nameP, "GLN") != 0) && (strcmp (nameP, "ARG") != 0) && (strcmp (nameP, "LYS") != 0) && (strcmp (nameP, "HIS") != 0)) continue; /* If this point is reached, select */ /* all atoms of the current residue. */ /* The indices of the first and the */ /* last atom of the current residue: */ first_atomI = curr_residueSP->residue_startI; last_atomI = curr_residueSP->residue_endI; /* Select all atoms of the current residue: */ for (atomI = first_atomI; atomI <= last_atomI; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Select the current atom: */ curr_atomSP->selectedF = 1; /* Update the counter of selected atoms: */ selected_atomsN++; } } /* End of residueI loop: */ } /* Combine the current selection with the */ /* previous, if selection mode is restrict: */ if (selection_modeI == 1) { /* Reset the counter of selected atoms. The */ /* selected atoms should be counted again. */ selected_atomsN = 0; /* Combine the old and the new selection flag: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Combine selection flags: */ curr_atomSP->selectedF *= curr_atomSP->previous_selectedF; /* Check the selection flag; increase */ /* the count of selected residues if */ /* the selection flag is equal to one: */ if (curr_atomSP->selectedF) selected_atomsN++; } } /* Update the position_changedF (some atoms may have bad color): */ curr_mol_complexSP->position_changedF = 1; /* End of mol_complexI loop: */ } /* Return the number of selected atoms: */ return selected_atomsN; } /*===========================================================================*/ garlic-1.6/select_3nz6.c0000644000076500007650000001521010403044055015404 0ustar zuciczucic00000000000000/* Copyright (C) 2006 Damir Zucic */ /*============================================================================= select_3nz6.c Purpose: Select the sequence fragment which contains three or more neg. or zwitterionic residues in a window of six residues. ASP, GLU, ASN and GLN are taken into account. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. (3) Selection mode index (0 = overwrite, 1 = restrict, 2 = expand previous selection). Output: (1) The flag selectedF set to one for selected atoms in every caught macromolecular complex. (2) Return value. Return value: (1) The number of selected atoms (zero or positive value). ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======select three or more negative or zwitterionic residues:==============*/ long Select3NZ6_ (MolComplexS *mol_complexSP, int mol_complexesN, int selection_modeI) { long selected_atomsN = 0; int mol_complexI; MolComplexS *curr_mol_complexSP; int atomsN, atomI; AtomS *curr_atomSP; int residuesN, residueI, windowI, combinedI; ResidueS *curr_residueSP; AtomS *first_atomSP; char *nameP; int negative_zwitterN; int first_atomI, last_atomI; /* Check every macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check is the current macromolecular complex caught: */ if (curr_mol_complexSP->catchF == 0) continue; /* Prepare and check the number of atoms in the current complex: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Copy the number of residues in the current macromol. complex: */ residuesN = curr_mol_complexSP->residuesN; if (residuesN == 0) continue; /* Backup the current selection if selection mode is restrict: */ if (selection_modeI == 1) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Copy the selection flag: */ curr_atomSP->previous_selectedF = curr_atomSP->selectedF; } } /* Unselect everything if selection mode is overwrite or restrict: */ if ((selection_modeI == 0) || (selection_modeI == 1)) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Unselect the current atom: */ curr_atomSP->selectedF = 0; } } /* Scan the residues of the current macromolecular complex: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Reset the number of negative and zwitterionic residues: */ negative_zwitterN = 0; /* Scan the window of six residues, */ /* starting from the current residue: */ for (windowI = 0; windowI < 6; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI >= residuesN) break; /* Residue associated with the combined index: */ curr_residueSP = curr_mol_complexSP->residueSP + combinedI; /* Pointer to the first atom of current residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Pointer to the name of the current residue: */ nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Check is this residue negative or zwitterionic: */ if ((strcmp (nameP, "ASP") == 0) || (strcmp (nameP, "GLU") == 0) || (strcmp (nameP, "ASN") == 0) || (strcmp (nameP, "GLN") == 0)) negative_zwitterN++; } /* If there were three or more negative and zwitterionic */ /* residues in a window of six residues, the triplet is */ /* found. If there were two or less, take the next resid. */ if (negative_zwitterN < 3) continue; /* If this point is reached, rescan the window of six */ /* residues and select negative and zwitterionic res. */ /* Scan the window of six residues, */ /* starting from the current residue: */ for (windowI = 0; windowI < 6; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI >= residuesN) break; /* Residue associated with the combined index: */ curr_residueSP = curr_mol_complexSP->residueSP + combinedI; /* Pointer to the first atom of current residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Pointer to the name of the current residue: */ nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Check is this residue negative or zwitterionic: */ if ((strcmp (nameP, "ASP") != 0) && (strcmp (nameP, "GLU") != 0) && (strcmp (nameP, "ASN") != 0) && (strcmp (nameP, "GLN") != 0)) continue; /* If this point is reached, select */ /* all atoms of the current residue. */ /* The indices of the first and the */ /* last atom of the current residue: */ first_atomI = curr_residueSP->residue_startI; last_atomI = curr_residueSP->residue_endI; /* Select all atoms of the current residue: */ for (atomI = first_atomI; atomI <= last_atomI; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Select the current atom: */ curr_atomSP->selectedF = 1; /* Update the counter of selected atoms: */ selected_atomsN++; } } /* End of residueI loop: */ } /* Combine the current selection with the */ /* previous, if selection mode is restrict: */ if (selection_modeI == 1) { /* Reset the counter of selected atoms. The */ /* selected atoms should be counted again. */ selected_atomsN = 0; /* Combine the old and the new selection flag: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Combine selection flags: */ curr_atomSP->selectedF *= curr_atomSP->previous_selectedF; /* Check the selection flag; increase */ /* the count of selected residues if */ /* the selection flag is equal to one: */ if (curr_atomSP->selectedF) selected_atomsN++; } } /* Update the position_changedF (some atoms may have bad color): */ curr_mol_complexSP->position_changedF = 1; /* End of mol_complexI loop: */ } /* Return the number of selected atoms: */ return selected_atomsN; } /*===========================================================================*/ garlic-1.6/select_4cz7.c0000644000076500007650000001550010153564740015407 0ustar zuciczucic00000000000000/* Copyright (C) 2004 Damir Zucic */ /*============================================================================= select_4cz7.c Purpose: Select the sequence fragment which contains four or more charged or zwitterionic residues in a window of seven residues. ASP, GLU, ASN, GLN, ARG, LYS and HIS are taken into account. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. (3) Selection mode index (0 = overwrite, 1 = restrict, 2 = expand previous selection). Output: (1) The flag selectedF set to one for selected atoms in every caught macromolecular complex. (2) Return value. Return value: (1) The number of selected atoms (zero or positive value). ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======select four or more charged or zwitterionic residues:================*/ long Select4CZ7_ (MolComplexS *mol_complexSP, int mol_complexesN, int selection_modeI) { long selected_atomsN = 0; int mol_complexI; MolComplexS *curr_mol_complexSP; int atomsN, atomI; AtomS *curr_atomSP; int residuesN, residueI, windowI, combinedI; ResidueS *curr_residueSP; AtomS *first_atomSP; char *nameP; int very_polarN; int first_atomI, last_atomI; /* Check every macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check is the current macromolecular complex caught: */ if (curr_mol_complexSP->catchF == 0) continue; /* Prepare and check the number of atoms in the current complex: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Copy the number of residues in the current macromol. complex: */ residuesN = curr_mol_complexSP->residuesN; if (residuesN == 0) continue; /* Backup the current selection if selection mode is restrict: */ if (selection_modeI == 1) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Copy the selection flag: */ curr_atomSP->previous_selectedF = curr_atomSP->selectedF; } } /* Unselect everything if selection mode is overwrite or restrict: */ if ((selection_modeI == 0) || (selection_modeI == 1)) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Unselect the current atom: */ curr_atomSP->selectedF = 0; } } /* Scan the residues of the current macromolecular complex: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Reset the counter which counts very polar residues: */ very_polarN = 0; /* Scan the window of seven residues, */ /* starting from the current residue: */ for (windowI = 0; windowI < 7; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI >= residuesN) break; /* Residue associated with the combined index: */ curr_residueSP = curr_mol_complexSP->residueSP + combinedI; /* Pointer to the first atom of current residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Pointer to the name of the current residue: */ nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Check is this residue very polar: */ if ((strcmp (nameP, "ASP") == 0) || (strcmp (nameP, "GLU") == 0) || (strcmp (nameP, "ASN") == 0) || (strcmp (nameP, "GLN") == 0) || (strcmp (nameP, "ARG") == 0) || (strcmp (nameP, "LYS") == 0) || (strcmp (nameP, "HIS") == 0)) very_polarN++; } /* If there were four or more very polar residues in */ /* a window of seven residues, the quartet is found. */ /* If there were three or less, take the next residue. */ if (very_polarN < 4) continue; /* If this point is reached, scan the window of seven */ /* residues again and select very polar residues. */ /* Scan the window of seven residues, */ /* starting from the current residue: */ for (windowI = 0; windowI < 7; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI >= residuesN) break; /* Residue associated with the combined index: */ curr_residueSP = curr_mol_complexSP->residueSP + combinedI; /* Pointer to the first atom of current residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Pointer to the name of the current residue: */ nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Check is this residue very polar: */ if ((strcmp (nameP, "ASP") != 0) && (strcmp (nameP, "GLU") != 0) && (strcmp (nameP, "ASN") != 0) && (strcmp (nameP, "GLN") != 0) && (strcmp (nameP, "ARG") != 0) && (strcmp (nameP, "LYS") != 0) && (strcmp (nameP, "HIS") != 0)) continue; /* If this point is reached, select */ /* all atoms of the current residue. */ /* The indices of the first and the */ /* last atom of the current residue: */ first_atomI = curr_residueSP->residue_startI; last_atomI = curr_residueSP->residue_endI; /* Select all atoms of the current residue: */ for (atomI = first_atomI; atomI <= last_atomI; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Select the current atom: */ curr_atomSP->selectedF = 1; /* Update the counter of selected atoms: */ selected_atomsN++; } } /* End of residueI loop: */ } /* Combine the current selection with the */ /* previous, if selection mode is restrict: */ if (selection_modeI == 1) { /* Reset the counter of selected atoms. The */ /* selected atoms should be counted again. */ selected_atomsN = 0; /* Combine the old and the new selection flag: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Combine selection flags: */ curr_atomSP->selectedF *= curr_atomSP->previous_selectedF; /* Check the selection flag; increase */ /* the count of selected residues if */ /* the selection flag is equal to one: */ if (curr_atomSP->selectedF) selected_atomsN++; } } /* Update the position_changedF (some atoms may have bad color): */ curr_mol_complexSP->position_changedF = 1; /* End of mol_complexI loop: */ } /* Return the number of selected atoms: */ return selected_atomsN; } /*===========================================================================*/ garlic-1.6/select_4cz9.c0000644000076500007650000001547610402045350015411 0ustar zuciczucic00000000000000/* Copyright (C) 2006 Damir Zucic */ /*============================================================================= select_4cz9.c Purpose: Select the sequence fragment which contains four or more charged or zwitterionic residues in a window of nine residues. ASP, GLU, ASN, GLN, ARG, LYS and HIS are taken into account. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. (3) Selection mode index (0 = overwrite, 1 = restrict, 2 = expand previous selection). Output: (1) The flag selectedF set to one for selected atoms in every caught macromolecular complex. (2) Return value. Return value: (1) The number of selected atoms (zero or positive value). ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======select four or more charged or zwitterionic residues:================*/ long Select4CZ9_ (MolComplexS *mol_complexSP, int mol_complexesN, int selection_modeI) { long selected_atomsN = 0; int mol_complexI; MolComplexS *curr_mol_complexSP; int atomsN, atomI; AtomS *curr_atomSP; int residuesN, residueI, windowI, combinedI; ResidueS *curr_residueSP; AtomS *first_atomSP; char *nameP; int very_polarN; int first_atomI, last_atomI; /* Check every macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check is the current macromolecular complex caught: */ if (curr_mol_complexSP->catchF == 0) continue; /* Prepare and check the number of atoms in the current complex: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Copy the number of residues in the current macromol. complex: */ residuesN = curr_mol_complexSP->residuesN; if (residuesN == 0) continue; /* Backup the current selection if selection mode is restrict: */ if (selection_modeI == 1) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Copy the selection flag: */ curr_atomSP->previous_selectedF = curr_atomSP->selectedF; } } /* Unselect everything if selection mode is overwrite or restrict: */ if ((selection_modeI == 0) || (selection_modeI == 1)) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Unselect the current atom: */ curr_atomSP->selectedF = 0; } } /* Scan the residues of the current macromolecular complex: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Reset the counter which counts very polar residues: */ very_polarN = 0; /* Scan the window of nine residues, */ /* starting from the current residue: */ for (windowI = 0; windowI < 9; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI >= residuesN) break; /* Residue associated with the combined index: */ curr_residueSP = curr_mol_complexSP->residueSP + combinedI; /* Pointer to the first atom of current residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Pointer to the name of the current residue: */ nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Check is this residue very polar: */ if ((strcmp (nameP, "ASP") == 0) || (strcmp (nameP, "GLU") == 0) || (strcmp (nameP, "ASN") == 0) || (strcmp (nameP, "GLN") == 0) || (strcmp (nameP, "ARG") == 0) || (strcmp (nameP, "LYS") == 0) || (strcmp (nameP, "HIS") == 0)) very_polarN++; } /* If there were four or more very polar residues in */ /* a window of nine residues, the quartet is found. */ /* If there were three or less, take the next residue. */ if (very_polarN < 4) continue; /* If this point is reached, scan the window of nine */ /* residues again and select very polar residues. */ /* Scan the window of nine residues, */ /* starting from the current residue: */ for (windowI = 0; windowI < 9; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI >= residuesN) break; /* Residue associated with the combined index: */ curr_residueSP = curr_mol_complexSP->residueSP + combinedI; /* Pointer to the first atom of current residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Pointer to the name of the current residue: */ nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Check is this residue very polar: */ if ((strcmp (nameP, "ASP") != 0) && (strcmp (nameP, "GLU") != 0) && (strcmp (nameP, "ASN") != 0) && (strcmp (nameP, "GLN") != 0) && (strcmp (nameP, "ARG") != 0) && (strcmp (nameP, "LYS") != 0) && (strcmp (nameP, "HIS") != 0)) continue; /* If this point is reached, select */ /* all atoms of the current residue. */ /* The indices of the first and the */ /* last atom of the current residue: */ first_atomI = curr_residueSP->residue_startI; last_atomI = curr_residueSP->residue_endI; /* Select all atoms of the current residue: */ for (atomI = first_atomI; atomI <= last_atomI; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Select the current atom: */ curr_atomSP->selectedF = 1; /* Update the counter of selected atoms: */ selected_atomsN++; } } /* End of residueI loop: */ } /* Combine the current selection with the */ /* previous, if selection mode is restrict: */ if (selection_modeI == 1) { /* Reset the counter of selected atoms. The */ /* selected atoms should be counted again. */ selected_atomsN = 0; /* Combine the old and the new selection flag: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Combine selection flags: */ curr_atomSP->selectedF *= curr_atomSP->previous_selectedF; /* Check the selection flag; increase */ /* the count of selected residues if */ /* the selection flag is equal to one: */ if (curr_atomSP->selectedF) selected_atomsN++; } } /* Update the position_changedF (some atoms may have bad color): */ curr_mol_complexSP->position_changedF = 1; /* End of mol_complexI loop: */ } /* Return the number of selected atoms: */ return selected_atomsN; } /*===========================================================================*/ garlic-1.6/box.pdb0000644000076500007650000000537607605373713014414 0ustar zuciczucic00000000000000ATOM 1 Q BOX 1 -10.000 0.000 0.000 1.00 10.00 ATOM 2 Q BOX 2 10.000 0.000 0.000 1.00 10.00 ATOM 4 Q BOX 4 -10.000 -10.000 0.000 1.00 10.00 ATOM 5 Q BOX 5 10.000 -10.000 0.000 1.00 10.00 ATOM 7 Q BOX 7 -10.000 10.000 0.000 1.00 10.00 ATOM 8 Q BOX 8 10.000 10.000 0.000 1.00 10.00 ATOM 10 Q BOX 10 0.000 -10.000 0.000 1.00 10.00 ATOM 11 Q BOX 11 0.000 10.000 0.000 1.00 10.00 ATOM 13 Q BOX 13 -10.000 -10.000 0.000 1.00 10.00 ATOM 14 Q BOX 14 -10.000 10.000 0.000 1.00 10.00 ATOM 16 Q BOX 16 10.000 -10.000 0.000 1.00 10.00 ATOM 17 Q BOX 17 10.000 10.000 0.000 1.00 10.00 ATOM 19 Q BOX 19 -10.000 0.000 50.000 1.00 10.00 ATOM 20 Q BOX 20 10.000 0.000 50.000 1.00 10.00 ATOM 22 Q BOX 22 -10.000 -10.000 50.000 1.00 10.00 ATOM 23 Q BOX 23 10.000 -10.000 50.000 1.00 10.00 ATOM 25 Q BOX 25 -10.000 10.000 50.000 1.00 10.00 ATOM 26 Q BOX 26 10.000 10.000 50.000 1.00 10.00 ATOM 28 Q BOX 28 0.000 -10.000 50.000 1.00 10.00 ATOM 29 Q BOX 29 0.000 10.000 50.000 1.00 10.00 ATOM 31 Q BOX 31 -10.000 -10.000 50.000 1.00 10.00 ATOM 32 Q BOX 32 -10.000 10.000 50.000 1.00 10.00 ATOM 34 Q BOX 34 10.000 -10.000 50.000 1.00 10.00 ATOM 35 Q BOX 35 10.000 10.000 50.000 1.00 10.00 ATOM 37 Q BOX 37 -10.000 -10.000 0.000 1.00 10.00 ATOM 38 Q BOX 38 -10.000 -10.000 50.000 1.00 10.00 ATOM 40 Q BOX 40 -10.000 -10.000 0.000 1.00 10.00 ATOM 41 Q BOX 41 -10.000 -10.000 50.000 1.00 10.00 ATOM 43 Q BOX 43 10.000 -10.000 0.000 1.00 10.00 ATOM 44 Q BOX 44 10.000 -10.000 50.000 1.00 10.00 ATOM 46 Q BOX 46 -10.000 10.000 0.000 1.00 10.00 ATOM 47 Q BOX 47 -10.000 10.000 50.000 1.00 10.00 ATOM 49 Q BOX 49 10.000 10.000 0.000 1.00 10.00 ATOM 50 Q BOX 50 10.000 10.000 50.000 1.00 10.00 ATOM 52 Q BOX 52 11.000 1.000 0.000 1.00 10.00 ATOM 53 Q BOX 53 13.000 3.000 0.000 1.00 10.00 ATOM 55 Q BOX 55 11.000 3.000 0.000 1.00 10.00 ATOM 56 Q BOX 56 13.000 1.000 0.000 1.00 10.00 ATOM 58 Q BOX 58 1.000 11.000 0.000 1.00 10.00 ATOM 59 Q BOX 59 2.000 12.000 0.000 1.00 10.00 ATOM 61 Q BOX 61 1.000 13.000 0.000 1.00 10.00 ATOM 62 Q BOX 62 3.000 11.000 0.000 1.00 10.00 garlic-1.6/select_hetero.c0000644000076500007650000000545207465735075016130 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2002 Damir Zucic */ /*============================================================================= select_hetero.c Purpose: Select hetero atoms. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. (3) Selection mode index (0 = overwrite, 1 = restrict, 2 = expand previous selection). Output: (1) The flag selectedF set for all hetero atoms in all currently caught macromolecular complexes. (2) Return value. Return value: (1) The number of selected atoms (zero or positive value). Notes: (1) Indentation is exceptionally four spaces. (2) The position_changedF is updated, because some atoms may not have the proper color. ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======select hetero atoms:=================================================*/ long SelectHetero_ (MolComplexS *mol_complexSP, int mol_complexesN, int selection_modeI) { long selected_atomsN = 0; int mol_complexI; MolComplexS *curr_mol_complexSP; size_t atomsN, atomI; AtomS *curr_atomSP; int heteroF; /* Check every macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /** Pointer to the current macromolecular complex: **/ curr_mol_complexSP = mol_complexSP + mol_complexI; /** Check is the current macromolecular complex caught: **/ if (curr_mol_complexSP->catchF == 0) continue; /** Number of atoms in a macromolecular complex: **/ atomsN = curr_mol_complexSP->atomsN; /** Scan all atoms in the current complex: **/ for (atomI = 0; atomI < atomsN; atomI++) { /** Pointer to the current atom: **/ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /** Check the heteroF: **/ heteroF = curr_atomSP->raw_atomS.heteroF; /** Set the selection flag for the current atom: **/ switch (selection_modeI) { /*** Overwrite the previous selection: ***/ case 0: curr_atomSP->selectedF = heteroF; break; /*** Restrict the previous selection: ***/ case 1: curr_atomSP->selectedF &= heteroF; break; /*** Expand the previous selection: ***/ case 2: curr_atomSP->selectedF |= heteroF; break; default: ; } /** Check the selection flag; increase **/ /** the count if flag is equal to one: **/ if (curr_atomSP->selectedF) selected_atomsN++; } /** Update the position_changedF (some atoms may have bad color): **/ curr_mol_complexSP->position_changedF = 1; } /* Return the number of selected atoms: */ return selected_atomsN; } /*===========================================================================*/ garlic-1.6/extract_cbxg.c0000644000076500007650000000542607415612614015745 0ustar zuciczucic00000000000000/* Copyright (C) 2001, 2002 Damir Zucic */ /*============================================================================= extract_cbxg.c Purpose: Extract CB and XG coordinates for a given residue. The symbol XG stands for CG, CG1, OG, OG1 or SG. The CG atom appears in PRO, LEU, MET, PHE, TRP, ASN, GLN, TYR, ASP, GLU, LYS, ARG and HIS. The CG1 atom appears in ILE, OG in SER, OG1 in THR and SG in CYS. This function is not able to handle non-standard residues. Input: (1) Pointer to VectorS structure, for CB coordinates. (2) Pointer to VectorS structure, for XG coordinates. (3) Pointer to AtomS structure, pointing to the first element of the atomic array. (4) Index of the first atom of a given residue. (5) Index of the last atom of a given residue. Output: (1) VectorS structures filled with data. (2) Return value. Return value: (1) The number of successfully extracted vectors (at least zero, at most two). Notes: (1) Some files contain more than one entry for some atoms. Garlic uses only the first entry and discards other entries for the same atom. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======extract CB and XG coordinates:=======================================*/ int ExtractCBXG_ (VectorS *CB_vectorSP, VectorS *XG_vectorSP, AtomS *atomSP, size_t atom_startI, size_t atom_endI) { int vectors_extractedN = 0; size_t atomI; AtomS *curr_atomSP; char *atom_nameP; int CB_foundF = 0, XG_foundF = 0; /* Scan the given residue: */ for (atomI = atom_startI; atomI <= atom_endI; atomI++) { /* Pointer to the current atom: */ curr_atomSP = atomSP + atomI; /* Pointer to the purified atom name: */ atom_nameP = curr_atomSP->raw_atomS.pure_atom_nameA; /* CB: */ if (strcmp (atom_nameP, "CB") == 0) { if (CB_foundF) continue; CB_vectorSP->x = curr_atomSP->raw_atomS.x[0]; CB_vectorSP->y = curr_atomSP->raw_atomS.y; CB_vectorSP->z = curr_atomSP->raw_atomS.z[0]; vectors_extractedN++; CB_foundF = 1; } /* XG: */ else if ((strcmp (atom_nameP, "CG" ) == 0) || (strcmp (atom_nameP, "CG1") == 0) || (strcmp (atom_nameP, "OG" ) == 0) || (strcmp (atom_nameP, "OG1") == 0) || (strcmp (atom_nameP, "SG" ) == 0)) { if (XG_foundF) continue; XG_vectorSP->x = curr_atomSP->raw_atomS.x[0]; XG_vectorSP->y = curr_atomSP->raw_atomS.y; XG_vectorSP->z = curr_atomSP->raw_atomS.z[0]; vectors_extractedN++; XG_foundF = 1; } } /* Return the number of extracted vectors: */ return vectors_extractedN; } /*===========================================================================*/ garlic-1.6/ex_slab_steps.c0000644000076500007650000000310107612772257016120 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2003 Damir Zucic */ /*============================================================================= ex_slab_steps.c Purpose: Extract slab steps (five doubles) from a string. Input: (1) Pointer to ConfigS structure, where values will be stored. (2) Input string pointer. Output: Return value. Return value: (1) Positive on success. (2) Negative on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======extract slab steps from a string:====================================*/ int ExtractSlabSteps_ (ConfigS *configSP, char *sP) { char *P0, *P1; int n; double d1, d2, d3, d4, d5; /* Colon should be separator: */ if ((P0 = strstr (sP, ":")) == NULL) P0 = sP; /* Replace each non-numeric character (except */ /* minus sign and decimal point) with space: */ P1 = P0; while ((n = *P1++) != '\0') { if (!isdigit (n) && (n != '-') && (n != '.')) *(P1 - 1) = ' '; } /* Try to read five doubles: */ if (sscanf (P0, "%lf %lf %lf %lf %lf", &d1, &d2, &d3, &d4, &d5) != 5) { return -1; } /* Copy slab steps to ConfigS: */ configSP->slab_stepA[0] = d1; configSP->slab_stepA[1] = d2; configSP->slab_stepA[2] = d3; configSP->slab_stepA[3] = d4; configSP->slab_stepA[4] = d5; /* If everything worked fine, return positive number: */ return 1; } /*===========================================================================*/ garlic-1.6/extract_cdxe.c0000644000076500007650000000474707415612710015747 0ustar zuciczucic00000000000000/* Copyright (C) 2001, 2002 Damir Zucic */ /*============================================================================= extract_cdxe.c Purpose: Extract CD and XE coordinates for a given residue. The symbol XE stands for NE in ARG and for CE in LYS. This function is not able to handle non-standard residues. Input: (1) Pointer to VectorS structure, for CD coordinates. (2) Pointer to VectorS structure, for XE coordinates. (3) Pointer to AtomS structure, pointing to the first element of the atomic array. (4) Index of the first atom of a given residue. (5) Index of the last atom of a given residue. Output: (1) VectorS structures filled with data. (2) Return value. Return value: (1) The number of successfully extracted vectors (at least zero, at most two). Notes: (1) Some files contain more than one entry for some atoms. Garlic uses only the first entry and discards other entries for the same atom. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======extract CD and XE coordinates:=======================================*/ int ExtractCDXE_ (VectorS *CD_vectorSP, VectorS *XE_vectorSP, AtomS *atomSP, size_t atom_startI, size_t atom_endI) { int vectors_extractedN = 0; size_t atomI; AtomS *curr_atomSP; char *atom_nameP; int CD_foundF = 0, XE_foundF = 0; /* Scan the given residue: */ for (atomI = atom_startI; atomI <= atom_endI; atomI++) { /* Pointer to the current atom: */ curr_atomSP = atomSP + atomI; /* Pointer to the purified atom name: */ atom_nameP = curr_atomSP->raw_atomS.pure_atom_nameA; /* CD: */ if (strcmp (atom_nameP, "CD") == 0) { if (CD_foundF) continue; CD_vectorSP->x = curr_atomSP->raw_atomS.x[0]; CD_vectorSP->y = curr_atomSP->raw_atomS.y; CD_vectorSP->z = curr_atomSP->raw_atomS.z[0]; vectors_extractedN++; CD_foundF = 1; } /* XE: */ else if ((strcmp (atom_nameP, "NE") == 0) || (strcmp (atom_nameP, "CE") == 0)) { if (XE_foundF) continue; XE_vectorSP->x = curr_atomSP->raw_atomS.x[0]; XE_vectorSP->y = curr_atomSP->raw_atomS.y; XE_vectorSP->z = curr_atomSP->raw_atomS.z[0]; vectors_extractedN++; XE_foundF = 1; } } /* Return the number of extracted vectors: */ return vectors_extractedN; } /*===========================================================================*/ garlic-1.6/extract_cgxd.c0000644000076500007650000000477707415612726015763 0ustar zuciczucic00000000000000/* Copyright (C) 2001, 2002 Damir Zucic */ /*============================================================================= extract_cgxd.c Purpose: Extract CG and XD coordinates for a given residue. The symbol XD stands for CD in ARG, GLN, GLU and LYS and for SD in MET. This function is not able to handle non-standard residues. Input: (1) Pointer to VectorS structure, for CG coordinates. (2) Pointer to VectorS structure, for XD coordinates. (3) Pointer to AtomS structure, pointing to the first element of the atomic array. (4) Index of the first atom of a given residue. (5) Index of the last atom of a given residue. Output: (1) VectorS structures filled with data. (2) Return value. Return value: (1) The number of successfully extracted vectors (at least zero, at most two). Notes: (1) Some files contain more than one entry for some atoms. Garlic uses only the first entry and discards other entries for the same atom. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======extract CG and XD coordinates:=======================================*/ int ExtractCGXD_ (VectorS *CG_vectorSP, VectorS *XD_vectorSP, AtomS *atomSP, size_t atom_startI, size_t atom_endI) { int vectors_extractedN = 0; size_t atomI; AtomS *curr_atomSP; char *atom_nameP; int CG_foundF = 0, XD_foundF = 0; /* Scan the given residue: */ for (atomI = atom_startI; atomI <= atom_endI; atomI++) { /* Pointer to the current atom: */ curr_atomSP = atomSP + atomI; /* Pointer to the purified atom name: */ atom_nameP = curr_atomSP->raw_atomS.pure_atom_nameA; /* CG: */ if (strcmp (atom_nameP, "CG") == 0) { if (CG_foundF) continue; CG_vectorSP->x = curr_atomSP->raw_atomS.x[0]; CG_vectorSP->y = curr_atomSP->raw_atomS.y; CG_vectorSP->z = curr_atomSP->raw_atomS.z[0]; vectors_extractedN++; CG_foundF = 1; } /* XD: */ else if ((strcmp (atom_nameP, "CD") == 0) || (strcmp (atom_nameP, "SD") == 0)) { if (XD_foundF) continue; XD_vectorSP->x = curr_atomSP->raw_atomS.x[0]; XD_vectorSP->y = curr_atomSP->raw_atomS.y; XD_vectorSP->z = curr_atomSP->raw_atomS.z[0]; vectors_extractedN++; XD_foundF = 1; } } /* Return the number of extracted vectors: */ return vectors_extractedN; } /*===========================================================================*/ garlic-1.6/2omf.script0000644000076500007650000000020107050335215015171 0ustar zuciczucic00000000000000load 2omf.pdb select side hide select hetero hide select 102-132 hide rotate x 90 rotate y 180 select main_chain atoms 0 bonds 3 garlic-1.6/bond_style1_quad1.c0000644000076500007650000000740507461726553016616 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2002 Damir Zucic */ /*============================================================================= bond_style1_quad1.c Purpose: Draw bond which fits into quadrant 1 using style 1. See the file file bonds_style1.c for description of quadrants. Input: (1) Pointer to Aux1S structure, which contains required data. (2) Bond index. Output: (1) A single bond drawn. (2) Return value. Return value: (1) One if at least one pixel is drawn. (2) Zero otherwise. =============================================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======draw bond in quadrant 1 using style 1:===============================*/ int BondStyle1Quadrant1_ (Aux1S *aux1SP, int bondI) { long pixels_drawnN = 0; double recip_denom, x_to_y_scale, x_to_z_scale; int screen_x, screen_x1, delta_x, screen_y; double d, atomic_z; size_t pixelI; NearestAtomS *curr_pixelSP; /* Scale factor required to calculate screen_y from screen_x: */ if (aux1SP->screen_delta_x != 0) recip_denom = 1.0 / aux1SP->screen_delta_x; else recip_denom = 0.0; x_to_y_scale = aux1SP->screen_delta_y * recip_denom; /* Scale factor required to calculate z (in atomic units) from screen_x: */ x_to_z_scale = aux1SP->atomic_delta_z * recip_denom; /* Horizontal scan, from left to right: */ screen_x1 = aux1SP->screen_x0 + (aux1SP->screen_delta_x + 1) / 2; for (screen_x = aux1SP->screen_x0; screen_x <= screen_x1; screen_x++) { /* Check is this pixel inside the area reserved for the */ /* current image (there are two images in stereo mode): */ if (screen_x < aux1SP->configSP->image_screen_x0[aux1SP->imageI]) { continue; } if (screen_x > aux1SP->configSP->image_screen_x1[aux1SP->imageI]) { continue; } /* Relative position: */ delta_x = screen_x - aux1SP->screen_x0; /* Find the corresponding screen_y: */ d = aux1SP->screen_y0 + x_to_y_scale * delta_x; screen_y = (int) (d + 0.5); /* Check is this pixel inside the area reserved for the */ /* current image (there are two images in stereo mode): */ if (screen_y < aux1SP->configSP->image_screen_y0) continue; if (screen_y > aux1SP->configSP->image_screen_y1) continue; /* z value (in atomic units): */ atomic_z = aux1SP->atomic_z0 + x_to_z_scale * delta_x; /* Current pixel index: */ pixelI = aux1SP->guiSP->main_win_free_area_width * screen_y + screen_x; /* Check pixel index: */ if (pixelI >= aux1SP->pixelsN) break; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = aux1SP->nearest_atomSP + pixelI; /* Check was this pixel used already in */ /* this drawing step; if it was, compare */ /* the z value of the current atom with z */ /* value previously stored to this pixel: */ if (aux1SP->refreshI == curr_pixelSP->last_refreshI) { if (atomic_z >= curr_pixelSP->z) continue; } /* If this point is reached, draw the pixel: */ XDrawPoint (aux1SP->guiSP->displaySP, aux1SP->guiSP->main_hidden_pixmapID, aux1SP->guiSP->theGCA[0], screen_x, screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = 1; curr_pixelSP->last_refreshI = aux1SP->refreshI; curr_pixelSP->mol_complexI = aux1SP->mol_complexI; curr_pixelSP->atomI = aux1SP->atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = atomic_z; curr_pixelSP->colorID = aux1SP->colorIDA[0]; /* Update the number of pixels drawn: */ pixels_drawnN++; } /* Check is at least one pixel drawn: */ if (pixels_drawnN > 0) return 1; /* If this point is reached, nothing is drawn: */ return 0; } /*===========================================================================*/ garlic-1.6/bond_style1_quad2.c0000644000076500007650000000737707461726561016626 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2002 Damir Zucic */ /*============================================================================= bond_style1_quad2.c Purpose: Draw bond which fits into quadrant 2 using style 1. See the file file bonds_style1.c for description of quadrants. Input: (1) Pointer to Aux1S structure, which contains required data. (2) Bond index. Output: (1) A single bond drawn. (2) Return value. Return value: (1) One if at least one pixel is drawn. (2) Zero otherwise. =============================================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======draw bond in quadrant 2 using style 1:===============================*/ int BondStyle1Quadrant2_ (Aux1S *aux1SP, int bondI) { long pixels_drawnN = 0; double recip_denom, y_to_x_scale, y_to_z_scale; int screen_x, screen_y, screen_y1, delta_y; double d, atomic_z; size_t pixelI; NearestAtomS *curr_pixelSP; /* Scale factor required to calculate screen_x from screen_y: */ if (aux1SP->screen_delta_y != 0) recip_denom = 1.0 / aux1SP->screen_delta_y; else recip_denom = 0.0; y_to_x_scale = aux1SP->screen_delta_x * recip_denom; /* Scale factor required to calculate z (in atomic units) from screen_y: */ y_to_z_scale = aux1SP->atomic_delta_z * recip_denom; /* Vertical scan (top to bottom): */ screen_y1 = aux1SP->screen_y0 + (aux1SP->screen_delta_y + 1) / 2; for (screen_y = aux1SP->screen_y0; screen_y <= screen_y1; screen_y++) { /* Check is this pixel inside the area reserved for the */ /* current image (there are two images in stereo mode): */ if (screen_y < aux1SP->configSP->image_screen_y0) continue; if (screen_y > aux1SP->configSP->image_screen_y1) continue; /* Relative position: */ delta_y = screen_y - aux1SP->screen_y0; /* Find the corresponding screen_x: */ d = aux1SP->screen_x0 + y_to_x_scale * delta_y; screen_x = (int) (d + 0.5); /* Check is this pixel inside the area reserved for the */ /* current image (there are two images in stereo mode): */ if (screen_x < aux1SP->configSP->image_screen_x0[aux1SP->imageI]) { continue; } if (screen_x > aux1SP->configSP->image_screen_x1[aux1SP->imageI]) { continue; } /* z value (in atomic units): */ atomic_z = aux1SP->atomic_z0 + y_to_z_scale * delta_y; /* Current pixel index: */ pixelI = aux1SP->guiSP->main_win_free_area_width * screen_y + screen_x; /* Check pixel index: */ if (pixelI >= aux1SP->pixelsN) break; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = aux1SP->nearest_atomSP + pixelI; /* Check was this pixel used already in */ /* this drawing step; if it was, compare */ /* the z value of the current atom with z */ /* value previously stored to this pixel: */ if (aux1SP->refreshI == curr_pixelSP->last_refreshI) { if (atomic_z >= curr_pixelSP->z) continue; } /* If this point is reached, draw the pixel: */ XDrawPoint (aux1SP->guiSP->displaySP, aux1SP->guiSP->main_hidden_pixmapID, aux1SP->guiSP->theGCA[0], screen_x, screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = 1; curr_pixelSP->last_refreshI = aux1SP->refreshI; curr_pixelSP->mol_complexI = aux1SP->mol_complexI; curr_pixelSP->atomI = aux1SP->atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = atomic_z; curr_pixelSP->colorID = aux1SP->colorIDA[0]; /* Update the number of pixels drawn: */ pixels_drawnN++; } /* Check is at least one pixel drawn: */ if (pixels_drawnN > 0) return 1; /* If this point is reached, nothing is drawn: */ return 0; } /*===========================================================================*/ garlic-1.6/bond_style1_quad3.c0000644000076500007650000000740507461726566016624 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2002 Damir Zucic */ /*============================================================================= bond_style1_quad3.c Purpose: Draw bond which fits into quadrant 3 using style 1. See the file file bonds_style1.c for description of quadrants. Input: (1) Pointer to Aux1S structure, which contains required data. (2) Bond index. Output: (1) A single bond drawn. (2) Return value. Return value: (1) One if at least one pixel is drawn. (2) Zero otherwise. =============================================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======draw bond in quadrant 3 using style 1:===============================*/ int BondStyle1Quadrant3_ (Aux1S *aux1SP, int bondI) { long pixels_drawnN = 0; double recip_denom, x_to_y_scale, x_to_z_scale; int screen_x, screen_x1, delta_x, screen_y; double d, atomic_z; size_t pixelI; NearestAtomS *curr_pixelSP; /* Scale factor required to calculate screen_y from screen_x: */ if (aux1SP->screen_delta_x != 0) recip_denom = 1.0 / aux1SP->screen_delta_x; else recip_denom = 0.0; x_to_y_scale = aux1SP->screen_delta_y * recip_denom; /* Scale factor required to calculate z (in atomic units) from screen_x: */ x_to_z_scale = aux1SP->atomic_delta_z * recip_denom; /* Horizontal scan, from left to right: */ screen_x1 = aux1SP->screen_x0 + (aux1SP->screen_delta_x + 1) / 2; for (screen_x = aux1SP->screen_x0; screen_x >= screen_x1; screen_x--) { /* Check is this pixel inside the area reserved for the */ /* current image (there are two images in stereo mode): */ if (screen_x < aux1SP->configSP->image_screen_x0[aux1SP->imageI]) { continue; } if (screen_x > aux1SP->configSP->image_screen_x1[aux1SP->imageI]) { continue; } /* Relative position: */ delta_x = screen_x - aux1SP->screen_x0; /* Find the corresponding screen_y: */ d = aux1SP->screen_y0 + x_to_y_scale * delta_x; screen_y = (int) (d + 0.5); /* Check is this pixel inside the area reserved for the */ /* current image (there are two images in stereo mode): */ if (screen_y < aux1SP->configSP->image_screen_y0) continue; if (screen_y > aux1SP->configSP->image_screen_y1) continue; /* z value (in atomic units): */ atomic_z = aux1SP->atomic_z0 + x_to_z_scale * delta_x; /* Current pixel index: */ pixelI = aux1SP->guiSP->main_win_free_area_width * screen_y + screen_x; /* Check pixel index: */ if (pixelI >= aux1SP->pixelsN) break; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = aux1SP->nearest_atomSP + pixelI; /* Check was this pixel used already in */ /* this drawing step; if it was, compare */ /* the z value of the current atom with z */ /* value previously stored to this pixel: */ if (aux1SP->refreshI == curr_pixelSP->last_refreshI) { if (atomic_z >= curr_pixelSP->z) continue; } /* If this point is reached, draw the pixel: */ XDrawPoint (aux1SP->guiSP->displaySP, aux1SP->guiSP->main_hidden_pixmapID, aux1SP->guiSP->theGCA[0], screen_x, screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = 1; curr_pixelSP->last_refreshI = aux1SP->refreshI; curr_pixelSP->mol_complexI = aux1SP->mol_complexI; curr_pixelSP->atomI = aux1SP->atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = atomic_z; curr_pixelSP->colorID = aux1SP->colorIDA[0]; /* Update the number of pixels drawn: */ pixels_drawnN++; } /* Check is at least one pixel drawn: */ if (pixels_drawnN > 0) return 1; /* If this point is reached, nothing is drawn: */ return 0; } /*===========================================================================*/ garlic-1.6/bond_style1_quad4.c0000644000076500007650000000737707461726571016631 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2002 Damir Zucic */ /*============================================================================= bond_style1_quad4.c Purpose: Draw bond which fits into quadrant 4 using style 1. See the file file bonds_style1.c for description of quadrants. Input: (1) Pointer to Aux1S structure, which contains required data. (2) Bond index. Output: (1) A single bond drawn. (2) Return value. Return value: (1) One if at least one pixel is drawn. (2) Zero otherwise. =============================================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======draw bond in quadrant 4 using style 1:===============================*/ int BondStyle1Quadrant4_ (Aux1S *aux1SP, int bondI) { long pixels_drawnN = 0; double recip_denom, y_to_x_scale, y_to_z_scale; int screen_x, screen_y, screen_y1, delta_y; double d, atomic_z; size_t pixelI; NearestAtomS *curr_pixelSP; /* Scale factor required to calculate screen_x from screen_y: */ if (aux1SP->screen_delta_y != 0) recip_denom = 1.0 / aux1SP->screen_delta_y; else recip_denom = 0.0; y_to_x_scale = aux1SP->screen_delta_x * recip_denom; /* Scale factor required to calculate z (in atomic units) from screen_y: */ y_to_z_scale = aux1SP->atomic_delta_z * recip_denom; /* Vertical scan (bottom to top): */ screen_y1 = aux1SP->screen_y0 + (aux1SP->screen_delta_y + 1) / 2; for (screen_y = aux1SP->screen_y0; screen_y >= screen_y1; screen_y--) { /* Check is this pixel inside the area reserved for the */ /* current image (there are two images in stereo mode): */ if (screen_y < aux1SP->configSP->image_screen_y0) continue; if (screen_y > aux1SP->configSP->image_screen_y1) continue; /* Relative position: */ delta_y = screen_y - aux1SP->screen_y0; /* Find the corresponding screen_x: */ d = aux1SP->screen_x0 + y_to_x_scale * delta_y; screen_x = (int) (d + 0.5); /* Check is this pixel inside the area reserved for the */ /* current image (there are two images in stereo mode): */ if (screen_x < aux1SP->configSP->image_screen_x0[aux1SP->imageI]) { continue; } if (screen_x > aux1SP->configSP->image_screen_x1[aux1SP->imageI]) { continue; } /* z value (in atomic units): */ atomic_z = aux1SP->atomic_z0 + y_to_z_scale * delta_y; /* Current pixel index: */ pixelI = aux1SP->guiSP->main_win_free_area_width * screen_y + screen_x; /* Check pixel index: */ if (pixelI >= aux1SP->pixelsN) break; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = aux1SP->nearest_atomSP + pixelI; /* Check was this pixel used already in */ /* this drawing step; if it was, compare */ /* the z value of the current atom with z */ /* value previously stored to this pixel: */ if (aux1SP->refreshI == curr_pixelSP->last_refreshI) { if (atomic_z >= curr_pixelSP->z) continue; } /* If this point is reached, draw the pixel: */ XDrawPoint (aux1SP->guiSP->displaySP, aux1SP->guiSP->main_hidden_pixmapID, aux1SP->guiSP->theGCA[0], screen_x, screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = 1; curr_pixelSP->last_refreshI = aux1SP->refreshI; curr_pixelSP->mol_complexI = aux1SP->mol_complexI; curr_pixelSP->atomI = aux1SP->atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = atomic_z; curr_pixelSP->colorID = aux1SP->colorIDA[0]; /* Update the number of pixels drawn: */ pixels_drawnN++; } /* Check is at least one pixel drawn: */ if (pixels_drawnN > 0) return 1; /* If this point is reached, nothing is drawn: */ return 0; } /*===========================================================================*/ garlic-1.6/porins.script0000644000076500007650000000067010043150165015645 0ustar zuciczucic00000000000000# Searching for sequence motifs characteristic for porins. # # 2004/04/26 # Hide water and other hetero atoms: select hetero hide # Draw just a backbone, using blue color: select complement show backbone 4 color cyan-blue # Select the first characteristic pattern: pattern = TYR TRP PHE / * / LEU VAL select pattern color red # Select the second characteristic pattern: pattern = LEU VAL / * / TYR TRP PHE select pattern color yellow garlic-1.6/select_4nz5.c0000644000076500007650000001521410403044321015404 0ustar zuciczucic00000000000000/* Copyright (C) 2006 Damir Zucic */ /*============================================================================= select_4nz5.c Purpose: Select the sequence fragment which contains four or more negative or zwitterionic residues in a window of five residues. ASP, GLU, ASN and GLN are taken into account. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. (3) Selection mode index (0 = overwrite, 1 = restrict, 2 = expand previous selection). Output: (1) The flag selectedF set to one for selected atoms in every caught macromolecular complex. (2) Return value. Return value: (1) The number of selected atoms (zero or positive value). ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======select four or more negative or zwitterionic residues:===============*/ long Select4NZ5_ (MolComplexS *mol_complexSP, int mol_complexesN, int selection_modeI) { long selected_atomsN = 0; int mol_complexI; MolComplexS *curr_mol_complexSP; int atomsN, atomI; AtomS *curr_atomSP; int residuesN, residueI, windowI, combinedI; ResidueS *curr_residueSP; AtomS *first_atomSP; char *nameP; int negative_zwitterN; int first_atomI, last_atomI; /* Check every macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check is the current macromolecular complex caught: */ if (curr_mol_complexSP->catchF == 0) continue; /* Prepare and check the number of atoms in the current complex: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Copy the number of residues in the current macromol. complex: */ residuesN = curr_mol_complexSP->residuesN; if (residuesN == 0) continue; /* Backup the current selection if selection mode is restrict: */ if (selection_modeI == 1) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Copy the selection flag: */ curr_atomSP->previous_selectedF = curr_atomSP->selectedF; } } /* Unselect everything if selection mode is overwrite or restrict: */ if ((selection_modeI == 0) || (selection_modeI == 1)) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Unselect the current atom: */ curr_atomSP->selectedF = 0; } } /* Scan the residues of the current macromolecular complex: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Reset the number of negative and zwitterionic residues: */ negative_zwitterN = 0; /* Scan the window of five residues, */ /* starting from the current residue: */ for (windowI = 0; windowI < 5; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI >= residuesN) break; /* Residue associated with the combined index: */ curr_residueSP = curr_mol_complexSP->residueSP + combinedI; /* Pointer to the first atom of current residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Pointer to the name of the current residue: */ nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Check is this residue negative or zwitterionic: */ if ((strcmp (nameP, "ASP") == 0) || (strcmp (nameP, "GLU") == 0) || (strcmp (nameP, "ASN") == 0) || (strcmp (nameP, "GLN") == 0)) negative_zwitterN++; } /* If there were four or more negative and zwitterionic */ /* residues in a window of five residues, the quartet is */ /* found. If there were three or less, take the next res. */ if (negative_zwitterN < 4) continue; /* If this point is reached, rescan the window of five */ /* residues and select negative and zwitterionic resid. */ /* Scan the window of five residues, */ /* starting from the current residue: */ for (windowI = 0; windowI < 5; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI >= residuesN) break; /* Residue associated with the combined index: */ curr_residueSP = curr_mol_complexSP->residueSP + combinedI; /* Pointer to the first atom of current residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Pointer to the name of the current residue: */ nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Check is this residue negative or zwitterionic: */ if ((strcmp (nameP, "ASP") != 0) && (strcmp (nameP, "GLU") != 0) && (strcmp (nameP, "ASN") != 0) && (strcmp (nameP, "GLN") != 0)) continue; /* If this point is reached, select */ /* all atoms of the current residue. */ /* The indices of the first and the */ /* last atom of the current residue: */ first_atomI = curr_residueSP->residue_startI; last_atomI = curr_residueSP->residue_endI; /* Select all atoms of the current residue: */ for (atomI = first_atomI; atomI <= last_atomI; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Select the current atom: */ curr_atomSP->selectedF = 1; /* Update the counter of selected atoms: */ selected_atomsN++; } } /* End of residueI loop: */ } /* Combine the current selection with the */ /* previous, if selection mode is restrict: */ if (selection_modeI == 1) { /* Reset the counter of selected atoms. The */ /* selected atoms should be counted again. */ selected_atomsN = 0; /* Combine the old and the new selection flag: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Combine selection flags: */ curr_atomSP->selectedF *= curr_atomSP->previous_selectedF; /* Check the selection flag; increase */ /* the count of selected residues if */ /* the selection flag is equal to one: */ if (curr_atomSP->selectedF) selected_atomsN++; } } /* Update the position_changedF (some atoms may have bad color): */ curr_mol_complexSP->position_changedF = 1; /* End of mol_complexI loop: */ } /* Return the number of selected atoms: */ return selected_atomsN; } /*===========================================================================*/ garlic-1.6/select_5cz6.c0000644000076500007650000001547110153564657015425 0ustar zuciczucic00000000000000/* Copyright (C) 2004 Damir Zucic */ /*============================================================================= select_5cz6.c Purpose: Select the sequence fragment which contains five or more charged or zwitterionic residues in a window of six residues. ASP, GLU, ASN, GLN, ARG, LYS and HIS are taken into account. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. (3) Selection mode index (0 = overwrite, 1 = restrict, 2 = expand previous selection). Output: (1) The flag selectedF set to one for selected atoms in every caught macromolecular complex. (2) Return value. Return value: (1) The number of selected atoms (zero or positive value). ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======select five or more charged or zwitterionic residues:================*/ long Select5CZ6_ (MolComplexS *mol_complexSP, int mol_complexesN, int selection_modeI) { long selected_atomsN = 0; int mol_complexI; MolComplexS *curr_mol_complexSP; int atomsN, atomI; AtomS *curr_atomSP; int residuesN, residueI, windowI, combinedI; ResidueS *curr_residueSP; AtomS *first_atomSP; char *nameP; int very_polarN; int first_atomI, last_atomI; /* Check every macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check is the current macromolecular complex caught: */ if (curr_mol_complexSP->catchF == 0) continue; /* Prepare and check the number of atoms in the current complex: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Copy the number of residues in the current macromol. complex: */ residuesN = curr_mol_complexSP->residuesN; if (residuesN == 0) continue; /* Backup the current selection if selection mode is restrict: */ if (selection_modeI == 1) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Copy the selection flag: */ curr_atomSP->previous_selectedF = curr_atomSP->selectedF; } } /* Unselect everything if selection mode is overwrite or restrict: */ if ((selection_modeI == 0) || (selection_modeI == 1)) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Unselect the current atom: */ curr_atomSP->selectedF = 0; } } /* Scan the residues of the current macromolecular complex: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Reset the counter which counts very polar residues: */ very_polarN = 0; /* Scan the window of six residues, */ /* starting from the current residue: */ for (windowI = 0; windowI < 6; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI >= residuesN) break; /* Residue associated with the combined index: */ curr_residueSP = curr_mol_complexSP->residueSP + combinedI; /* Pointer to the first atom of current residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Pointer to the name of the current residue: */ nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Check is this residue very polar: */ if ((strcmp (nameP, "ASP") == 0) || (strcmp (nameP, "GLU") == 0) || (strcmp (nameP, "ASN") == 0) || (strcmp (nameP, "GLN") == 0) || (strcmp (nameP, "ARG") == 0) || (strcmp (nameP, "LYS") == 0) || (strcmp (nameP, "HIS") == 0)) very_polarN++; } /* If there were five or more very polar residues in */ /* a window of six residues, the quintet is found. If */ /* there were four or less, take the next residue. */ if (very_polarN < 5) continue; /* If this point is reached, scan the window of six */ /* residues again and select very polar residues. */ /* Scan the window of six residues, */ /* starting from the current residue: */ for (windowI = 0; windowI < 6; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI >= residuesN) break; /* Residue associated with the combined index: */ curr_residueSP = curr_mol_complexSP->residueSP + combinedI; /* Pointer to the first atom of current residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Pointer to the name of the current residue: */ nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Check is this residue very polar: */ if ((strcmp (nameP, "ASP") != 0) && (strcmp (nameP, "GLU") != 0) && (strcmp (nameP, "ASN") != 0) && (strcmp (nameP, "GLN") != 0) && (strcmp (nameP, "ARG") != 0) && (strcmp (nameP, "LYS") != 0) && (strcmp (nameP, "HIS") != 0)) continue; /* If this point is reached, select */ /* all atoms of the current residue. */ /* The indices of the first and the */ /* last atom of the current residue: */ first_atomI = curr_residueSP->residue_startI; last_atomI = curr_residueSP->residue_endI; /* Select all atoms of the current residue: */ for (atomI = first_atomI; atomI <= last_atomI; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Select the current atom: */ curr_atomSP->selectedF = 1; /* Update the counter of selected atoms: */ selected_atomsN++; } } /* End of residueI loop: */ } /* Combine the current selection with the */ /* previous, if selection mode is restrict: */ if (selection_modeI == 1) { /* Reset the counter of selected atoms. The */ /* selected atoms should be counted again. */ selected_atomsN = 0; /* Combine the old and the new selection flag: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Combine selection flags: */ curr_atomSP->selectedF *= curr_atomSP->previous_selectedF; /* Check the selection flag; increase */ /* the count of selected residues if */ /* the selection flag is equal to one: */ if (curr_atomSP->selectedF) selected_atomsN++; } } /* Update the position_changedF (some atoms may have bad color): */ curr_mol_complexSP->position_changedF = 1; /* End of mol_complexI loop: */ } /* Return the number of selected atoms: */ return selected_atomsN; } /*===========================================================================*/ garlic-1.6/select_4nz6.c0000644000076500007650000001521010403043545015410 0ustar zuciczucic00000000000000/* Copyright (C) 2006 Damir Zucic */ /*============================================================================= select_4nz6.c Purpose: Select the sequence fragment which contains four or more negative or zwitterionic residues in a window of six residues. ASP, GLU, ASN and GLN are taken into account. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. (3) Selection mode index (0 = overwrite, 1 = restrict, 2 = expand previous selection). Output: (1) The flag selectedF set to one for selected atoms in every caught macromolecular complex. (2) Return value. Return value: (1) The number of selected atoms (zero or positive value). ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======select four or more negative or zwitterionic residues:===============*/ long Select4NZ6_ (MolComplexS *mol_complexSP, int mol_complexesN, int selection_modeI) { long selected_atomsN = 0; int mol_complexI; MolComplexS *curr_mol_complexSP; int atomsN, atomI; AtomS *curr_atomSP; int residuesN, residueI, windowI, combinedI; ResidueS *curr_residueSP; AtomS *first_atomSP; char *nameP; int negative_zwitterN; int first_atomI, last_atomI; /* Check every macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check is the current macromolecular complex caught: */ if (curr_mol_complexSP->catchF == 0) continue; /* Prepare and check the number of atoms in the current complex: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Copy the number of residues in the current macromol. complex: */ residuesN = curr_mol_complexSP->residuesN; if (residuesN == 0) continue; /* Backup the current selection if selection mode is restrict: */ if (selection_modeI == 1) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Copy the selection flag: */ curr_atomSP->previous_selectedF = curr_atomSP->selectedF; } } /* Unselect everything if selection mode is overwrite or restrict: */ if ((selection_modeI == 0) || (selection_modeI == 1)) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Unselect the current atom: */ curr_atomSP->selectedF = 0; } } /* Scan the residues of the current macromolecular complex: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Reset the number of negative and zwitterionic residues: */ negative_zwitterN = 0; /* Scan the window of six residues, */ /* starting from the current residue: */ for (windowI = 0; windowI < 6; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI >= residuesN) break; /* Residue associated with the combined index: */ curr_residueSP = curr_mol_complexSP->residueSP + combinedI; /* Pointer to the first atom of current residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Pointer to the name of the current residue: */ nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Check is this residue negative or zwitterionic: */ if ((strcmp (nameP, "ASP") == 0) || (strcmp (nameP, "GLU") == 0) || (strcmp (nameP, "ASN") == 0) || (strcmp (nameP, "GLN") == 0)) negative_zwitterN++; } /* If there were four or more negative and zwitterionic */ /* residues in a window of six residues, the quartet is */ /* found. If there were three or less, take the next res. */ if (negative_zwitterN < 4) continue; /* If this point is reached, rescan the window of six */ /* residues and select negative and zwitterionic res. */ /* Scan the window of six residues, */ /* starting from the current residue: */ for (windowI = 0; windowI < 6; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI >= residuesN) break; /* Residue associated with the combined index: */ curr_residueSP = curr_mol_complexSP->residueSP + combinedI; /* Pointer to the first atom of current residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Pointer to the name of the current residue: */ nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Check is this residue negative or zwitterionic: */ if ((strcmp (nameP, "ASP") != 0) && (strcmp (nameP, "GLU") != 0) && (strcmp (nameP, "ASN") != 0) && (strcmp (nameP, "GLN") != 0)) continue; /* If this point is reached, select */ /* all atoms of the current residue. */ /* The indices of the first and the */ /* last atom of the current residue: */ first_atomI = curr_residueSP->residue_startI; last_atomI = curr_residueSP->residue_endI; /* Select all atoms of the current residue: */ for (atomI = first_atomI; atomI <= last_atomI; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Select the current atom: */ curr_atomSP->selectedF = 1; /* Update the counter of selected atoms: */ selected_atomsN++; } } /* End of residueI loop: */ } /* Combine the current selection with the */ /* previous, if selection mode is restrict: */ if (selection_modeI == 1) { /* Reset the counter of selected atoms. The */ /* selected atoms should be counted again. */ selected_atomsN = 0; /* Combine the old and the new selection flag: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Combine selection flags: */ curr_atomSP->selectedF *= curr_atomSP->previous_selectedF; /* Check the selection flag; increase */ /* the count of selected residues if */ /* the selection flag is equal to one: */ if (curr_atomSP->selectedF) selected_atomsN++; } } /* Update the position_changedF (some atoms may have bad color): */ curr_mol_complexSP->position_changedF = 1; /* End of mol_complexI loop: */ } /* Return the number of selected atoms: */ return selected_atomsN; } /*===========================================================================*/ garlic-1.6/select_5cz7.c0000644000076500007650000001547510153564767015434 0ustar zuciczucic00000000000000/* Copyright (C) 2004 Damir Zucic */ /*============================================================================= select_5cz7.c Purpose: Select the sequence fragment which contains five or more charged or zwitterionic residues in a window of seven residues. ASP, GLU, ASN, GLN, ARG, LYS and HIS are taken into account. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. (3) Selection mode index (0 = overwrite, 1 = restrict, 2 = expand previous selection). Output: (1) The flag selectedF set to one for selected atoms in every caught macromolecular complex. (2) Return value. Return value: (1) The number of selected atoms (zero or positive value). ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======select five or more charged or zwitterionic residues:================*/ long Select5CZ7_ (MolComplexS *mol_complexSP, int mol_complexesN, int selection_modeI) { long selected_atomsN = 0; int mol_complexI; MolComplexS *curr_mol_complexSP; int atomsN, atomI; AtomS *curr_atomSP; int residuesN, residueI, windowI, combinedI; ResidueS *curr_residueSP; AtomS *first_atomSP; char *nameP; int very_polarN; int first_atomI, last_atomI; /* Check every macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check is the current macromolecular complex caught: */ if (curr_mol_complexSP->catchF == 0) continue; /* Prepare and check the number of atoms in the current complex: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Copy the number of residues in the current macromol. complex: */ residuesN = curr_mol_complexSP->residuesN; if (residuesN == 0) continue; /* Backup the current selection if selection mode is restrict: */ if (selection_modeI == 1) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Copy the selection flag: */ curr_atomSP->previous_selectedF = curr_atomSP->selectedF; } } /* Unselect everything if selection mode is overwrite or restrict: */ if ((selection_modeI == 0) || (selection_modeI == 1)) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Unselect the current atom: */ curr_atomSP->selectedF = 0; } } /* Scan the residues of the current macromolecular complex: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Reset the counter which counts very polar residues: */ very_polarN = 0; /* Scan the window of seven residues, */ /* starting from the current residue: */ for (windowI = 0; windowI < 7; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI >= residuesN) break; /* Residue associated with the combined index: */ curr_residueSP = curr_mol_complexSP->residueSP + combinedI; /* Pointer to the first atom of current residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Pointer to the name of the current residue: */ nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Check is this residue very polar: */ if ((strcmp (nameP, "ASP") == 0) || (strcmp (nameP, "GLU") == 0) || (strcmp (nameP, "ASN") == 0) || (strcmp (nameP, "GLN") == 0) || (strcmp (nameP, "ARG") == 0) || (strcmp (nameP, "LYS") == 0) || (strcmp (nameP, "HIS") == 0)) very_polarN++; } /* If there were five or more very polar residues in */ /* a window of seven residues, the quintet is found. */ /* If there were four or less, take the next residue. */ if (very_polarN < 5) continue; /* If this point is reached, scan the window of seven */ /* residues again and select very polar residues. */ /* Scan the window of seven residues, */ /* starting from the current residue: */ for (windowI = 0; windowI < 7; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI >= residuesN) break; /* Residue associated with the combined index: */ curr_residueSP = curr_mol_complexSP->residueSP + combinedI; /* Pointer to the first atom of current residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Pointer to the name of the current residue: */ nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Check is this residue very polar: */ if ((strcmp (nameP, "ASP") != 0) && (strcmp (nameP, "GLU") != 0) && (strcmp (nameP, "ASN") != 0) && (strcmp (nameP, "GLN") != 0) && (strcmp (nameP, "ARG") != 0) && (strcmp (nameP, "LYS") != 0) && (strcmp (nameP, "HIS") != 0)) continue; /* If this point is reached, select */ /* all atoms of the current residue. */ /* The indices of the first and the */ /* last atom of the current residue: */ first_atomI = curr_residueSP->residue_startI; last_atomI = curr_residueSP->residue_endI; /* Select all atoms of the current residue: */ for (atomI = first_atomI; atomI <= last_atomI; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Select the current atom: */ curr_atomSP->selectedF = 1; /* Update the counter of selected atoms: */ selected_atomsN++; } } /* End of residueI loop: */ } /* Combine the current selection with the */ /* previous, if selection mode is restrict: */ if (selection_modeI == 1) { /* Reset the counter of selected atoms. The */ /* selected atoms should be counted again. */ selected_atomsN = 0; /* Combine the old and the new selection flag: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Combine selection flags: */ curr_atomSP->selectedF *= curr_atomSP->previous_selectedF; /* Check the selection flag; increase */ /* the count of selected residues if */ /* the selection flag is equal to one: */ if (curr_atomSP->selectedF) selected_atomsN++; } } /* Update the position_changedF (some atoms may have bad color): */ curr_mol_complexSP->position_changedF = 1; /* End of mol_complexI loop: */ } /* Return the number of selected atoms: */ return selected_atomsN; } /*===========================================================================*/ garlic-1.6/select_4nz7.c0000644000076500007650000001522210402073452015413 0ustar zuciczucic00000000000000/* Copyright (C) 2006 Damir Zucic */ /*============================================================================= select_4nz7.c Purpose: Select the sequence fragment which contains four or more negative or zwitterionic residues in a window of seven residues. ASP, GLU, ASN and GLN are taken into account. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. (3) Selection mode index (0 = overwrite, 1 = restrict, 2 = expand previous selection). Output: (1) The flag selectedF set to one for selected atoms in every caught macromolecular complex. (2) Return value. Return value: (1) The number of selected atoms (zero or positive value). ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======select four or more negative or zwitterionic residues:===============*/ long Select4NZ7_ (MolComplexS *mol_complexSP, int mol_complexesN, int selection_modeI) { long selected_atomsN = 0; int mol_complexI; MolComplexS *curr_mol_complexSP; int atomsN, atomI; AtomS *curr_atomSP; int residuesN, residueI, windowI, combinedI; ResidueS *curr_residueSP; AtomS *first_atomSP; char *nameP; int negative_zwitterN; int first_atomI, last_atomI; /* Check every macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check is the current macromolecular complex caught: */ if (curr_mol_complexSP->catchF == 0) continue; /* Prepare and check the number of atoms in the current complex: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Copy the number of residues in the current macromol. complex: */ residuesN = curr_mol_complexSP->residuesN; if (residuesN == 0) continue; /* Backup the current selection if selection mode is restrict: */ if (selection_modeI == 1) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Copy the selection flag: */ curr_atomSP->previous_selectedF = curr_atomSP->selectedF; } } /* Unselect everything if selection mode is overwrite or restrict: */ if ((selection_modeI == 0) || (selection_modeI == 1)) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Unselect the current atom: */ curr_atomSP->selectedF = 0; } } /* Scan the residues of the current macromolecular complex: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Reset the number of negative and zwitterionic residues: */ negative_zwitterN = 0; /* Scan the window of seven residues, */ /* starting from the current residue: */ for (windowI = 0; windowI < 7; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI >= residuesN) break; /* Residue associated with the combined index: */ curr_residueSP = curr_mol_complexSP->residueSP + combinedI; /* Pointer to the first atom of current residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Pointer to the name of the current residue: */ nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Check is this residue negative or zwitterionic: */ if ((strcmp (nameP, "ASP") == 0) || (strcmp (nameP, "GLU") == 0) || (strcmp (nameP, "ASN") == 0) || (strcmp (nameP, "GLN") == 0)) negative_zwitterN++; } /* If there were four or more negative and zwitterionic */ /* residues in a window of seven residues, the quartet is */ /* found. If there were three or less, take the next res. */ if (negative_zwitterN < 4) continue; /* If this point is reached, rescan the window of seven */ /* residues and select negative and zwitterionic residues. */ /* Scan the window of seven residues, */ /* starting from the current residue: */ for (windowI = 0; windowI < 7; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI >= residuesN) break; /* Residue associated with the combined index: */ curr_residueSP = curr_mol_complexSP->residueSP + combinedI; /* Pointer to the first atom of current residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Pointer to the name of the current residue: */ nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Check is this residue negative or zwitterionic: */ if ((strcmp (nameP, "ASP") != 0) && (strcmp (nameP, "GLU") != 0) && (strcmp (nameP, "ASN") != 0) && (strcmp (nameP, "GLN") != 0)) continue; /* If this point is reached, select */ /* all atoms of the current residue. */ /* The indices of the first and the */ /* last atom of the current residue: */ first_atomI = curr_residueSP->residue_startI; last_atomI = curr_residueSP->residue_endI; /* Select all atoms of the current residue: */ for (atomI = first_atomI; atomI <= last_atomI; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Select the current atom: */ curr_atomSP->selectedF = 1; /* Update the counter of selected atoms: */ selected_atomsN++; } } /* End of residueI loop: */ } /* Combine the current selection with the */ /* previous, if selection mode is restrict: */ if (selection_modeI == 1) { /* Reset the counter of selected atoms. The */ /* selected atoms should be counted again. */ selected_atomsN = 0; /* Combine the old and the new selection flag: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Combine selection flags: */ curr_atomSP->selectedF *= curr_atomSP->previous_selectedF; /* Check the selection flag; increase */ /* the count of selected residues if */ /* the selection flag is equal to one: */ if (curr_atomSP->selectedF) selected_atomsN++; } } /* Update the position_changedF (some atoms may have bad color): */ curr_mol_complexSP->position_changedF = 1; /* End of mol_complexI loop: */ } /* Return the number of selected atoms: */ return selected_atomsN; } /*===========================================================================*/ garlic-1.6/select_5cz9.c0000644000076500007650000001547310153565026015421 0ustar zuciczucic00000000000000/* Copyright (C) 2004 Damir Zucic */ /*============================================================================= select_5cz9.c Purpose: Select the sequence fragment which contains five or more charged or zwitterionic residues in a window of nine residues. ASP, GLU, ASN, GLN, ARG, LYS and HIS are taken into account. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. (3) Selection mode index (0 = overwrite, 1 = restrict, 2 = expand previous selection). Output: (1) The flag selectedF set to one for selected atoms in every caught macromolecular complex. (2) Return value. Return value: (1) The number of selected atoms (zero or positive value). ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======select five or more charged or zwitterionic residues:================*/ long Select5CZ9_ (MolComplexS *mol_complexSP, int mol_complexesN, int selection_modeI) { long selected_atomsN = 0; int mol_complexI; MolComplexS *curr_mol_complexSP; int atomsN, atomI; AtomS *curr_atomSP; int residuesN, residueI, windowI, combinedI; ResidueS *curr_residueSP; AtomS *first_atomSP; char *nameP; int very_polarN; int first_atomI, last_atomI; /* Check every macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check is the current macromolecular complex caught: */ if (curr_mol_complexSP->catchF == 0) continue; /* Prepare and check the number of atoms in the current complex: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Copy the number of residues in the current macromol. complex: */ residuesN = curr_mol_complexSP->residuesN; if (residuesN == 0) continue; /* Backup the current selection if selection mode is restrict: */ if (selection_modeI == 1) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Copy the selection flag: */ curr_atomSP->previous_selectedF = curr_atomSP->selectedF; } } /* Unselect everything if selection mode is overwrite or restrict: */ if ((selection_modeI == 0) || (selection_modeI == 1)) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Unselect the current atom: */ curr_atomSP->selectedF = 0; } } /* Scan the residues of the current macromolecular complex: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Reset the counter which counts very polar residues: */ very_polarN = 0; /* Scan the window of nine residues, */ /* starting from the current residue: */ for (windowI = 0; windowI < 9; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI >= residuesN) break; /* Residue associated with the combined index: */ curr_residueSP = curr_mol_complexSP->residueSP + combinedI; /* Pointer to the first atom of current residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Pointer to the name of the current residue: */ nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Check is this residue very polar: */ if ((strcmp (nameP, "ASP") == 0) || (strcmp (nameP, "GLU") == 0) || (strcmp (nameP, "ASN") == 0) || (strcmp (nameP, "GLN") == 0) || (strcmp (nameP, "ARG") == 0) || (strcmp (nameP, "LYS") == 0) || (strcmp (nameP, "HIS") == 0)) very_polarN++; } /* If there were five or more very polar residues in */ /* a window of nine residues, the quintet is found. */ /* If there were four or less, take the next residue. */ if (very_polarN < 5) continue; /* If this point is reached, scan the window of nine */ /* residues again and select very polar residues. */ /* Scan the window of nine residues, */ /* starting from the current residue: */ for (windowI = 0; windowI < 9; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI >= residuesN) break; /* Residue associated with the combined index: */ curr_residueSP = curr_mol_complexSP->residueSP + combinedI; /* Pointer to the first atom of current residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Pointer to the name of the current residue: */ nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Check is this residue very polar: */ if ((strcmp (nameP, "ASP") != 0) && (strcmp (nameP, "GLU") != 0) && (strcmp (nameP, "ASN") != 0) && (strcmp (nameP, "GLN") != 0) && (strcmp (nameP, "ARG") != 0) && (strcmp (nameP, "LYS") != 0) && (strcmp (nameP, "HIS") != 0)) continue; /* If this point is reached, select */ /* all atoms of the current residue. */ /* The indices of the first and the */ /* last atom of the current residue: */ first_atomI = curr_residueSP->residue_startI; last_atomI = curr_residueSP->residue_endI; /* Select all atoms of the current residue: */ for (atomI = first_atomI; atomI <= last_atomI; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Select the current atom: */ curr_atomSP->selectedF = 1; /* Update the counter of selected atoms: */ selected_atomsN++; } } /* End of residueI loop: */ } /* Combine the current selection with the */ /* previous, if selection mode is restrict: */ if (selection_modeI == 1) { /* Reset the counter of selected atoms. The */ /* selected atoms should be counted again. */ selected_atomsN = 0; /* Combine the old and the new selection flag: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Combine selection flags: */ curr_atomSP->selectedF *= curr_atomSP->previous_selectedF; /* Check the selection flag; increase */ /* the count of selected residues if */ /* the selection flag is equal to one: */ if (curr_atomSP->selectedF) selected_atomsN++; } } /* Update the position_changedF (some atoms may have bad color): */ curr_mol_complexSP->position_changedF = 1; /* End of mol_complexI loop: */ } /* Return the number of selected atoms: */ return selected_atomsN; } /*===========================================================================*/ garlic-1.6/select_4nz9.c0000644000076500007650000001522210402046764015423 0ustar zuciczucic00000000000000/* Copyright (C) 2006 Damir Zucic */ /*============================================================================= select_4nz9.c Purpose: Select the sequence fragment which contains four or more negative or zwitterionic residues in a window of nine residues. ASP, GLU, ASN and GLN are taken into account. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. (3) Selection mode index (0 = overwrite, 1 = restrict, 2 = expand previous selection). Output: (1) The flag selectedF set to one for selected atoms in every caught macromolecular complex. (2) Return value. Return value: (1) The number of selected atoms (zero or positive value). ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======select four or more negative or zwitterionic residues:===============*/ long Select4NZ9_ (MolComplexS *mol_complexSP, int mol_complexesN, int selection_modeI) { long selected_atomsN = 0; int mol_complexI; MolComplexS *curr_mol_complexSP; int atomsN, atomI; AtomS *curr_atomSP; int residuesN, residueI, windowI, combinedI; ResidueS *curr_residueSP; AtomS *first_atomSP; char *nameP; int negative_zwitterN; int first_atomI, last_atomI; /* Check every macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check is the current macromolecular complex caught: */ if (curr_mol_complexSP->catchF == 0) continue; /* Prepare and check the number of atoms in the current complex: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Copy the number of residues in the current macromol. complex: */ residuesN = curr_mol_complexSP->residuesN; if (residuesN == 0) continue; /* Backup the current selection if selection mode is restrict: */ if (selection_modeI == 1) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Copy the selection flag: */ curr_atomSP->previous_selectedF = curr_atomSP->selectedF; } } /* Unselect everything if selection mode is overwrite or restrict: */ if ((selection_modeI == 0) || (selection_modeI == 1)) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Unselect the current atom: */ curr_atomSP->selectedF = 0; } } /* Scan the residues of the current macromolecular complex: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Reset the number of negative and zwitterionic residues: */ negative_zwitterN = 0; /* Scan the window of nine residues, */ /* starting from the current residue: */ for (windowI = 0; windowI < 9; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI >= residuesN) break; /* Residue associated with the combined index: */ curr_residueSP = curr_mol_complexSP->residueSP + combinedI; /* Pointer to the first atom of current residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Pointer to the name of the current residue: */ nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Check is this residue negative or zwitterionic: */ if ((strcmp (nameP, "ASP") == 0) || (strcmp (nameP, "GLU") == 0) || (strcmp (nameP, "ASN") == 0) || (strcmp (nameP, "GLN") == 0)) negative_zwitterN++; } /* If there were four or more negative and zwitterionic */ /* residues in a window of nine residues, the quartet is */ /* found. If there were three or less, take the next res. */ if (negative_zwitterN < 4) continue; /* If this point is reached, rescan the window of nine */ /* residues and select negative and zwitterionic residues. */ /* Scan the window of nine residues, */ /* starting from the current residue: */ for (windowI = 0; windowI < 9; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI >= residuesN) break; /* Residue associated with the combined index: */ curr_residueSP = curr_mol_complexSP->residueSP + combinedI; /* Pointer to the first atom of current residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Pointer to the name of the current residue: */ nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Check is this residue negative or zwitterionic: */ if ((strcmp (nameP, "ASP") != 0) && (strcmp (nameP, "GLU") != 0) && (strcmp (nameP, "ASN") != 0) && (strcmp (nameP, "GLN") != 0)) continue; /* If this point is reached, select */ /* all atoms of the current residue. */ /* The indices of the first and the */ /* last atom of the current residue: */ first_atomI = curr_residueSP->residue_startI; last_atomI = curr_residueSP->residue_endI; /* Select all atoms of the current residue: */ for (atomI = first_atomI; atomI <= last_atomI; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Select the current atom: */ curr_atomSP->selectedF = 1; /* Update the counter of selected atoms: */ selected_atomsN++; } } /* End of residueI loop: */ } /* Combine the current selection with the */ /* previous, if selection mode is restrict: */ if (selection_modeI == 1) { /* Reset the counter of selected atoms. The */ /* selected atoms should be counted again. */ selected_atomsN = 0; /* Combine the old and the new selection flag: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Combine selection flags: */ curr_atomSP->selectedF *= curr_atomSP->previous_selectedF; /* Check the selection flag; increase */ /* the count of selected residues if */ /* the selection flag is equal to one: */ if (curr_atomSP->selectedF) selected_atomsN++; } } /* Update the position_changedF (some atoms may have bad color): */ curr_mol_complexSP->position_changedF = 1; /* End of mol_complexI loop: */ } /* Return the number of selected atoms: */ return selected_atomsN; } /*===========================================================================*/ garlic-1.6/extract_sequence.c0000644000076500007650000001124407271017437016627 0ustar zuciczucic00000000000000/* Copyright (C) 2000, 2001 Damir Zucic */ /*============================================================================= extract_sequence.c Purpose: Extract sequence information: use pure residue names, i.e. ignore whitespace. Up to three characters are available in the PDB version 2.1 file format. In addition, add residue array index to each atom. Input: (1) Pointer to MolComplexS structure, with macromolecular data. Output: (1) An array of ResidueS structures allocated and initialized. (2) Return value. Return value: (1) Positive on success. (2) Zero, if complex contains no atoms. (3) Negative on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ size_t CountResidues_ (MolComplexS *); void ErrorMessage_ (char *, char *, char *, char *, char *, char *, char *); /*======extract sequence information:========================================*/ int ExtractSequence_ (MolComplexS *mol_complexSP) { size_t atomsN, atomI; size_t residuesN, residue_arrayI = 0; size_t struct_size, elementsN; AtomS *curr_atomSP; int previous_residueI, current_residueI; int previous_insertion_code, current_insertion_code; ResidueS *current_residueSP; ResidueS *previous_residueSP; /* Initialize the number of residues: */ mol_complexSP->residuesN = 0; /* Return zero if there are no atoms: */ atomsN = mol_complexSP->atomsN; if (atomsN == 0) return 0; /* Count residues; if there is nothing, return negative value: */ residuesN = CountResidues_ (mol_complexSP); if (residuesN == 0) return -1; /* Store the number of residues: */ mol_complexSP->residuesN = residuesN; /* Allocate memory for sequence information and other associated data: */ struct_size = sizeof (ResidueS); elementsN = residuesN + 100; mol_complexSP->residueSP = (ResidueS *) calloc (elementsN, struct_size); if (mol_complexSP->residueSP == NULL) { ErrorMessage_ ("garlic", "ExtractSequence_", "", "Failed to allocate memory for ResidueS array!\n", "", "", ""); return -2; } /* The first atom has special treatment: */ curr_atomSP = mol_complexSP->atomSP; curr_atomSP->residue_arrayI = 0; previous_residueI = curr_atomSP->raw_atomS.residue_sequenceI; previous_insertion_code = curr_atomSP->raw_atomS.residue_insertion_code; /* Extract residue information, but skip the first atom: */ for (atomI = 1; atomI < atomsN; atomI++) { /* Pointer to raw atomic data: */ curr_atomSP = mol_complexSP->atomSP + atomI; /* Copy the residue sequence number and residue insertion code: */ current_residueI = curr_atomSP->raw_atomS.residue_sequenceI; current_insertion_code = curr_atomSP->raw_atomS.residue_insertion_code; /* Compare the current residue sequence number with the old one */ /* and the current residue insertion code with the old code. */ /* If this atom belongs to the same residue as the previous */ /* one, set the residue array index and take the next atom: */ if ((current_residueI == previous_residueI) && (current_insertion_code == previous_insertion_code)) { curr_atomSP->residue_arrayI = residue_arrayI; continue; } /* If this atom does not belong to the same residue as */ /* the previous one, increment the residue array index */ /* by one and assign the incremented value to this atom: */ else { residue_arrayI++; curr_atomSP->residue_arrayI = residue_arrayI; } /* If this point is reached, a new residue is found. */ /* Prepare the pointer to the current residue: */ current_residueSP = mol_complexSP->residueSP + residue_arrayI; /* The residue start index for the current residue: */ current_residueSP->residue_startI = atomI; /* The initial (dummy) residue end index for the current residue: */ current_residueSP->residue_endI = atomI; /* The residue end index for the previous residue: */ if (residue_arrayI != 0) { previous_residueSP = mol_complexSP->residueSP + residue_arrayI - 1; if (atomI != 0) previous_residueSP->residue_endI = atomI - 1; } /* Copy the residue sequence index and residue insertion code: */ previous_residueI = current_residueI; previous_insertion_code = current_insertion_code; } /* The residue end index for the last residue: */ previous_residueSP = mol_complexSP->residueSP + residue_arrayI; if (atomI != 0) previous_residueSP->residue_endI = atomI - 1; /* If this point is reached, return positive value (success indicator): */ return 1; } /*===========================================================================*/ garlic-1.6/COPYING0000644000076500007650000004342007065421747014161 0ustar zuciczucic00000000000000 The GPL below is copyrighted by the Free Software Foundation, but the code that it refers to is copyrighted by Damir Zucic. ============================================================================== GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 675 Mass Ave, Cambridge, MA 02139, USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19yy name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. garlic-1.6/dihedral_angles.c0000644000076500007650000005364707477110560016406 0ustar zuciczucic00000000000000/* Copyright (C) 2000, 2001 Damir Zucic */ /*============================================================================= dihedral_angles.c Purpose: Calculate the angles phi, psi, omega, chi1, chi2, chi3 and chi4. Set the cis-trans flag (0 = bad/undefined, 1 = trans, 2 = cis). Phi is the angle of the right-handed rotation about N-CA bond. Phi is to zero if CA-C bond is cis to C-N bond, where the C atom involved in the C-N bond belongs to the previous residue. Psi is the angle of the right-handed rotation about CA-C bond. Psi is zero if C-N bond is cis to N-CA bond, where the N atom involved in the C-N bond belongs to the next residue. Omega is the angle of the right-handed rotation about C-N bond. Omega is zero if CA-C bond is cis to N-CA bond, where both the CA atom and the C atom involved in the CA-C bond belong to the previous residue. Chi1 is the angle of the right-handed rotation about CA-CB bond. Chi1 is zero if CG is cis to N-CA bond. Chi2 is the angle of the right-handed rotation about CB-CG bond, chi3 about CG-CD bond, chi4 about CD-CE or CD-NE bond and chi5 is the angle about NE-CZ bond. Input: (1) Pointer to MolComplexS structure. (2) Pointer to ConfigS structure. Output: (1) Dihedral angles calculated, cis-trans flag set. (2) Return value. Return value: (1) Positive on success. (2) Zero, if complex contains no atoms. (3) Negative on failure. Notes: (1) This should help you to understand phi and psi definitions: ........./................ | H * - * N | | \ phi1 = 180 | | * CA | residue 1 | / psi1 = 180 | | O * - * C | |........\...............| | N * - * H | | / phi2 = 180 | | CA * | residue 2 | \ psi2 = 180 | | C * - * O | |......../...............| (2) By default, the peptide group has undefined conformation. To define the peptide group, the coordinates of four atoms are required. (3) The peptide bond formed by residues I and I + 1 is assigned to the residue I + 1. Thus, the cis-trans flag assigned to the residue I refers to the peptide bond formed by the residues I - 1 and I. No peptide bond is assigned to the first residue. The omega angle for the first residue is not available (undefined). (4) This function tryes to calculate the phi angle without using the hydrogen atom coordinates. This means that C atom coord. of the previous residue are required. It also means that phi will be missing for the first residue in each chain. In the second passage, this function will look for hydrogen atoms in an attempt to calculate the phi angle. If hydrogen atoms are missing, some phi values may be missing. (5) The table below contains the list of atoms which are used to calculate the angles chi1, chi2, chi3, chi4 and chi5: +-----+-------------+--------------+--------------+-------------+--------------+ | res.| chi1 | chi2 | chi3 | chi4 | chi5 | |-----+-------------+--------------+--------------+-------------+--------------| | ALA | | | | | | | ARG | N-CA-CB-CG | CA-CB-CG-CD | CB-CG-CD-NE | CG-CD-NE-NZ | CD-NE-CZ-NH1 | | ASN | N-CA-CB-CG | CA-CB-CG-OD1 | | | | | ASP | N-CA-CB-CG | CA-CB-CG-OD1 | | | | | CYS | N-CA-CB-SG | | | | | | GLN | N-CA-CB-CG | CA-CB-CG-CD | CB-CG-CD-OE1 | | | | GLU | N-CA-CB-CG | CA-CB-CG-CD | CB-CG-CD-OE1 | | | | GLY | | | | | | | HIS | N-CA-CB-CG | CA-CB-CG-ND1 | | | | | ILE | N-CA-CB-CG1 | CA-CB-CG1-CD | | | | | LEU | N-CA-CB-CD | CA-CB-CG-CD1 | | | | | LYS | N-CA-CB-CG | CA-CB-CG-CD | CB-CG-CD-CE | CG-CD-CE-NZ | | | MET | N-CA-CB-CG | CA-CB-CG-SD | CB-CG-SD-CE | | | | PHE | N-CA-CB-CG | CA-CB-CG-CD1 | | | | | PRO | N-CA-CB-CG | CA-CB-CG-CD | | | | | SER | N-CA-CB-OG | | | | | | THR | N-CA-CB-OG1 | | | | | | TRP | N-CA-CB-CG | CA-CB-CG-CD1 | | | | | TYR | N-CA-CB-CG | CA-CB-CG-CD1 | | | | | VAL | N-CA-CB-CG1 | | | | | +-----+-------------+--------------+--------------+-------------+--------------+ ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int ExtractNCAC_ (VectorS *, VectorS *, VectorS *, AtomS *, size_t, size_t); int ExtractC_ (VectorS *, AtomS *, size_t, size_t); double PhiFromCNCAC_ (VectorS *, VectorS *, VectorS *, VectorS *, ConfigS *); int ExtractH_ (VectorS *, AtomS *, size_t, size_t); double PhiFromHNCAC_ (VectorS *, VectorS *, VectorS *, VectorS *); int ExtractN_ (VectorS *, AtomS *, size_t, size_t); double PsiFromNCACN_ (VectorS *, VectorS *, VectorS *, VectorS *, ConfigS *); int ExtractO_ (VectorS *, AtomS *, size_t, size_t); double PsiFromNCACO_ (VectorS *, VectorS *, VectorS *, VectorS *); int ExtractNCA_ (VectorS *, VectorS *, AtomS *, size_t, size_t); int ExtractCAC_ (VectorS *, VectorS *, AtomS *, size_t, size_t); double OmegaFromCACNCA_ (VectorS *, VectorS *, VectorS *, VectorS *, ConfigS *); int IsStandard_ (char *); double Chi1FromNCACBCG_ (AtomS *, size_t, size_t); double Chi1FromNCACBSG_ (AtomS *, size_t, size_t); double Chi1FromNCACBCG1_ (AtomS *, size_t, size_t); double Chi1FromNCACBOG_ (AtomS *, size_t, size_t); double Chi1FromNCACBOG1_ (AtomS *, size_t, size_t); double Chi2FromCACBCGCD_ (AtomS *, size_t, size_t); double Chi2FromCACBCGOD1_ (AtomS *, size_t, size_t); double Chi2FromCACBCGND1_ (AtomS *, size_t, size_t); double Chi2FromCACBCG1CD_ (AtomS *, size_t, size_t); double Chi2FromCACBCGCD1_ (AtomS *, size_t, size_t); double Chi2FromCACBCGSD_ (AtomS *, size_t, size_t); double Chi3FromCBCGCDNE_ (AtomS *, size_t, size_t); double Chi3FromCBCGCDOE1_ (AtomS *, size_t, size_t); double Chi3FromCBCGCDCE_ (AtomS *, size_t, size_t); double Chi3FromCBCGSDCE_ (AtomS *, size_t, size_t); double Chi4FromCGCDNECZ_ (AtomS *, size_t, size_t); double Chi4FromCGCDCENZ_ (AtomS *, size_t, size_t); double Chi5FromCDNECZNH1_ (AtomS *, size_t, size_t); /*======calculate dihedral angles and set the cis-trans flag:================*/ int DihedralAngles_ (MolComplexS *mol_complexSP, ConfigS *configSP) { int residuesN, residueI; size_t vector_struct_size; int n; ResidueS *current_residueSP; size_t current_startI, current_endI; static VectorS N_vectorS, CA_vectorS, C_vectorS; ResidueS *previous_residueSP; size_t previous_startI, previous_endI; static VectorS previousCA_vectorS, previousC_vectorS; static VectorS H_vectorS; ResidueS *next_residueSP; size_t next_startI, next_endI; static VectorS nextN_vectorS; static VectorS O_vectorS; double cis_abs_omega_max; double trans_abs_omega_min; double abs_omega; int cis_transF = 0; AtomS *first_atomSP; char *residue_nameP; int residue_typeI; /* Return zero if there are no atoms: */ if (mol_complexSP->atomsN == 0) return 0; /* Prepare and check the number of residues - at least one is required: */ residuesN = mol_complexSP->residuesN; if (residuesN < 1) return -1; /* The size of VectorS structure: */ vector_struct_size = sizeof (VectorS); /*---------------------------------------------------------------------------*/ /* The first passage: initialize dihedral angles and cis-trans flag. */ for (residueI = 0; residueI < residuesN; residueI++) { /* Pointer to the current residue: */ current_residueSP = mol_complexSP->residueSP + residueI; /* Initialize all dihedral angles: */ current_residueSP->phi = BADDIHEDANGLE; current_residueSP->psi = BADDIHEDANGLE; current_residueSP->omega = BADDIHEDANGLE; current_residueSP->chi1 = BADDIHEDANGLE; current_residueSP->chi2 = BADDIHEDANGLE; current_residueSP->chi3 = BADDIHEDANGLE; current_residueSP->chi4 = BADDIHEDANGLE; /* Initialize the cis-trans flag: */ current_residueSP->cis_transF = 0; } /*---------------------------------------------------------------------------*/ /* The second passage: calculate phi and psi. */ for (residueI = 0; residueI < residuesN; residueI++) { /* Pointer to the current residue: */ current_residueSP = mol_complexSP->residueSP + residueI; /* Prepare the atomic index range for the current residue: */ current_startI = current_residueSP->residue_startI; current_endI = current_residueSP->residue_endI; /* Try to extract N, CA and C coordinates for the current residue: */ n = ExtractNCAC_ (&N_vectorS, &CA_vectorS, &C_vectorS, mol_complexSP->atomSP, current_startI, current_endI); /* If the coordinates of any atom are missing, */ /* it is not possible to calculate phi and psi: */ if (n < 3) continue; /*------phi:---------------------------------------------------------*/ /* The first attempt - use the coordinates of the */ /* C atom from the previous residue, if available: */ do { /* Do nothing for the first residue: */ if (residueI < 1) break; /* Pointer to the previous residue: */ previous_residueSP = mol_complexSP->residueSP + residueI - 1; /* The atomic index range for the previous residue: */ previous_startI = previous_residueSP->residue_startI; previous_endI = previous_residueSP->residue_endI; /* Try to extract the C atom */ /* from the previous residue: */ n = ExtractC_ (&previousC_vectorS, mol_complexSP->atomSP, previous_startI, previous_endI); if (n < 1) break; /* If the C atom coordinates are available for */ /* the previous residue, try to calculate phi: */ current_residueSP->phi = PhiFromCNCAC_ (&previousC_vectorS, &N_vectorS, &CA_vectorS, &C_vectorS, configSP); } while (0); /* The second attempt - use the coordinates of the */ /* H atom from the current residue, if available: */ do { /* If phi was determined before, */ /* this attempt is not required: */ if (current_residueSP->phi != BADDIHEDANGLE) break; /* Try to extract the H atom coordinates: */ n = ExtractH_ (&H_vectorS, mol_complexSP->atomSP, current_startI, current_endI); if (n < 1) break; /* If the H atom coordinates are available for */ /* the current residue, try to calculate phi: */ current_residueSP->phi = PhiFromHNCAC_ (&H_vectorS, &N_vectorS, &CA_vectorS, &C_vectorS); } while (0); /*------psi:---------------------------------------------------------*/ /* The first attempt - use the coordinates of the */ /* N atom from the next residue, if available: */ do { /* Do nothing for the last residue: */ if (residueI >= residuesN - 1) break; /* Pointer to the next residue: */ next_residueSP = mol_complexSP->residueSP + residueI + 1; /* The atomic index range for the next residue: */ next_startI = next_residueSP->residue_startI; next_endI = next_residueSP->residue_endI; /* Try to extract the N atom */ /* from the next residue: */ n = ExtractN_ (&nextN_vectorS, mol_complexSP->atomSP, next_startI, next_endI); if (n < 1) break; /* If the N atom coordinates are available for */ /* the next residue, try to calculate psi: */ current_residueSP->psi = PsiFromNCACN_ (&N_vectorS, &CA_vectorS, &C_vectorS, &nextN_vectorS, configSP); } while (0); /* The second attempt - use the coordinates of the */ /* O atom from the current residue, if available: */ do { /* If psi was determined before, */ /* this attempt is not required: */ if (current_residueSP->psi != BADDIHEDANGLE) break; /* Try to extract the O atom coordinates: */ n = ExtractO_ (&O_vectorS, mol_complexSP->atomSP, current_startI, current_endI); if (n < 1) break; /* If the O atom coordinates are available for */ /* the current residue, try to calculate psi: */ current_residueSP->psi = PsiFromNCACO_ (&N_vectorS, &CA_vectorS, &C_vectorS, &O_vectorS); } while (0); } /*---------------------------------------------------------------------------*/ /* Initialize ranges for omega: */ /* Cis range: */ cis_abs_omega_max = DEG_TO_RAD * OMEGA_TOLERANCE; trans_abs_omega_min = DEG_TO_RAD * (180.0 - OMEGA_TOLERANCE); /* The third passage: calculate omega and */ /* cis-trans flag. Skip the first residue. */ for (residueI = 1; residueI < residuesN; residueI++) { /* Pointer to the current residue: */ current_residueSP = mol_complexSP->residueSP + residueI; /* Prepare the atomic index range for the current residue: */ current_startI = current_residueSP->residue_startI; current_endI = current_residueSP->residue_endI; /* Extract N and CA coordinates for the current residue: */ n = ExtractNCA_ (&N_vectorS, &CA_vectorS, mol_complexSP->atomSP, current_startI, current_endI); if (n < 2) continue; /* Pointer to the previous residue: */ previous_residueSP = mol_complexSP->residueSP + residueI - 1; /* The atomic index range from the previous residue: */ previous_startI = previous_residueSP->residue_startI; previous_endI = previous_residueSP->residue_endI; /* Extract CA and C coordinates from the previous residue: */ n = ExtractCAC_ (&previousCA_vectorS, &previousC_vectorS, mol_complexSP->atomSP, previous_startI, previous_endI); if (n < 2) continue; /* Try to calculate omega: */ current_residueSP->omega = OmegaFromCACNCA_ (&previousCA_vectorS, &previousC_vectorS, &N_vectorS, &CA_vectorS, configSP); /* Prepare the cis-trans flag: */ abs_omega = fabs (current_residueSP->omega); if (abs_omega < cis_abs_omega_max) cis_transF = 2; else if (abs_omega > trans_abs_omega_min) cis_transF = 1; else cis_transF = 0; current_residueSP->cis_transF = cis_transF; } /*---------------------------------------------------------------------------*/ /* The fourth passage: calculate side chain torsion angles (chi1 etc.). */ for (residueI = 0; residueI < residuesN; residueI++) { /* Pointer to the current residue: */ current_residueSP = mol_complexSP->residueSP + residueI; /* The atomic index range for the current residue: */ current_startI = current_residueSP->residue_startI; current_endI = current_residueSP->residue_endI; /* Pointer to the first atom of the current residue: */ first_atomSP = mol_complexSP->atomSP + current_startI; /* The name of the current residue: */ residue_nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Check is the current residue from */ /* the set of 20 standard residues: */ residue_typeI = IsStandard_ (residue_nameP); /*------chi1:--------------------------------------------------------*/ /* Calculate chi1: */ switch (residue_typeI) { /* Do nothing for ALA and GLY: */ case 0: /* ALA */ case 7: /* GLY */ break; /* Use N, CA, CB and CG for ARG, ASN, ASP, GLN, */ /* GLU, HIS, LEU, LYS, MET, PHE, PRO, TRP and TYR: */ case 1: /* ARG */ case 2: /* ASN */ case 3: /* ASP */ case 5: /* GLN */ case 6: /* GLU */ case 8: /* HIS */ case 10: /* LEU */ case 11: /* LYS */ case 12: /* MET */ case 13: /* PHE */ case 14: /* PRO */ case 17: /* TRP */ case 18: /* TYR */ current_residueSP->chi1 = Chi1FromNCACBCG_ (mol_complexSP->atomSP, current_startI, current_endI); break; /* Use N, CA, CB and SG for CYS: */ case 4: /* CYS */ current_residueSP->chi1 = Chi1FromNCACBSG_ (mol_complexSP->atomSP, current_startI, current_endI); break; /* Use N, CA, CB and CG1 for ILE and VAL: */ case 9: /* ILE */ case 19: /* VAL */ current_residueSP->chi1 = Chi1FromNCACBCG1_ (mol_complexSP->atomSP, current_startI, current_endI); break; /* Use N, CA, CB and OG for SER: */ case 15: /* SER */ current_residueSP->chi1 = Chi1FromNCACBOG_ (mol_complexSP->atomSP, current_startI, current_endI); break; /* Use N, CA, CB and OG1 for THR: */ case 16: /* THR */ current_residueSP->chi1 = Chi1FromNCACBOG1_ (mol_complexSP->atomSP, current_startI, current_endI); break; /* At present, chi1 is not calculated for exotic residues: */ default: ; } /*------chi2:--------------------------------------------------------*/ /* Calculate chi2: */ switch (residue_typeI) { /* Do nothing for ALA, CYS, GLY, SER, THR and VAL: */ case 0: /* ALA */ case 4: /* CYS */ case 7: /* GLY */ case 15: /* SER */ case 16: /* THR */ case 19: /* VAL */ break; /* Use CA, CB, CG and CD for ARG, GLN, GLU, LYS and PRO: */ case 1: /* ARG */ case 5: /* GLN */ case 6: /* GLU */ case 11: /* LYS */ case 14: /* PRO */ current_residueSP->chi2 = Chi2FromCACBCGCD_ (mol_complexSP->atomSP, current_startI, current_endI); break; /* Use CA, CB, CG and OD1 for ASN and ASP: */ case 2: /* ASN */ case 3: /* ASP */ current_residueSP->chi2 = Chi2FromCACBCGOD1_ (mol_complexSP->atomSP, current_startI, current_endI); break; /* Use CA, CB, CG and ND1 for HIS: */ case 8: /* HIS */ current_residueSP->chi2 = Chi2FromCACBCGND1_ (mol_complexSP->atomSP, current_startI, current_endI); break; /* Use CA, CB, CG1 and CD for ILE: */ case 9: /* ILE */ current_residueSP->chi2 = Chi2FromCACBCG1CD_ (mol_complexSP->atomSP, current_startI, current_endI); break; /* Use CA, CB, CG and CD1 for LEU, PHE, TRP and TYR: */ case 10: /* LEU */ case 13: /* PHE */ case 17: /* TRP */ case 18: /* TYR */ current_residueSP->chi2 = Chi2FromCACBCGCD1_ (mol_complexSP->atomSP, current_startI, current_endI); break; /* Use CA, CB, CG and SD for MET: */ case 12: /* MET */ current_residueSP->chi2 = Chi2FromCACBCGSD_ (mol_complexSP->atomSP, current_startI, current_endI); break; /* At present, chi2 is not calculated for exotic residues: */ default: ; } /*------chi3:--------------------------------------------------------*/ /* Calculate chi3: */ switch (residue_typeI) { /* Do nothing for ALA, ASN, ASP, CYS, GLY, HIS, */ /* ILE, LEU, PHE, PRO, SER THR, TRP, TYR and VAL: */ case 0: /* ALA */ case 2: /* ASN */ case 3: /* ASP */ case 4: /* CYS */ case 7: /* GLY */ case 8: /* HIS */ case 9: /* ILE */ case 10: /* LEU */ case 13: /* PHE */ case 14: /* PRO */ case 15: /* SER */ case 16: /* THR */ case 17: /* TRP */ case 18: /* TYR */ case 19: /* VAL */ break; /* Use CB, CG, CD and NE for ARG: */ case 1: /* ARG */ current_residueSP->chi3 = Chi3FromCBCGCDNE_ (mol_complexSP->atomSP, current_startI, current_endI); break; /* Use CB, CG, CD and OE1 for GLN and GLU: */ case 5: /* GLN */ case 6: /* GLU */ current_residueSP->chi3 = Chi3FromCBCGCDOE1_ (mol_complexSP->atomSP, current_startI, current_endI); break; /* Use CB, CG, CD and CE for LYS: */ case 11: /* LYS */ current_residueSP->chi3 = Chi3FromCBCGCDCE_ (mol_complexSP->atomSP, current_startI, current_endI); break; /* Use CB, CG, SD and CE for MET: */ case 12: /* MET */ current_residueSP->chi3 = Chi3FromCBCGSDCE_ (mol_complexSP->atomSP, current_startI, current_endI); break; /* At present, chi3 is not calculated for exotic residues: */ default: ; } /*------chi4:--------------------------------------------------------*/ /* Calculate chi4: */ switch (residue_typeI) { /* Do nothing for ALA, ASN, ASP, CYS, GLN, GLU, GLY, HIS, */ /* ILE, LEU, MET, PHE, PRO, SER, THR, TRP, TYR and VAL: */ case 0: case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9: case 10: case 12: case 13: case 14: case 15: case 16: case 17: case 18: case 19: break; /* Use CG, CD, NE and CZ for ARG: */ case 1: /* ARG */ current_residueSP->chi4 = Chi4FromCGCDNECZ_ (mol_complexSP->atomSP, current_startI, current_endI); break; /* Use CG, CD, NE and CZ for LYS: */ case 11: current_residueSP->chi4 = Chi4FromCGCDCENZ_ (mol_complexSP->atomSP, current_startI, current_endI); break; /* At present, chi4 is not calculated for exotic residues: */ default: ; } /*------chi5:--------------------------------------------------------*/ /* Calculate chi5: */ switch (residue_typeI) { /* Do nothing for ALA, ASN, ASP, CYS, GLN, GLU, GLY, HIS, */ /* ILE, LEU, LYS, MET, PHE, PRO, SER, THR, TRP, TYR and VAL: */ case 0: case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9: case 10: case 11: case 12: case 13: case 14: case 15: case 16: case 17: case 18: case 19: break; /* Use CD, NE, CZ and NH1 for ARG: */ case 1: /* ARG */ current_residueSP->chi5 = Chi5FromCDNECZNH1_ (mol_complexSP->atomSP, current_startI, current_endI); break; /* At present, chi5 is not calculated for exotic residues: */ default: ; } } /*---------------------------------------------------------------------------*/ /* If this point is reached, return the positive value (success indicator): */ return 1; } /*===========================================================================*/ garlic-1.6/print_help.c0000644000076500007650000003206110357776232015435 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2006 Damir Zucic */ /*============================================================================= print_help.c Purpose: Print brief help: short introduction and list of options. This is not the true (on-line) help for garlic! Input: No input. Output: Introductory information written to stdout. Return value: No return value. ========includes:============================================================*/ #include /*======print brief help:====================================================*/ void PrintHelp_ (void) { fprintf (stdout, "\n"); fprintf (stdout, "=========================================================================\n"); fprintf (stdout, " Garlic - free molecular viewer and editor\n"); fprintf (stdout, "=========================================================================\n"); fprintf (stdout, "\n"); fprintf (stdout, "Garlic was written by Damir Zucic (zucic@mefos.hr) as a complement to\n"); fprintf (stdout, "other molecular visualization programs, like rasmol (by Roger Sayle).\n"); fprintf (stdout, "It was written to simplify the analysis of membrane proteins, but it can\n"); fprintf (stdout, "be used as general purpose molecular visualization program, provided that\n"); fprintf (stdout, "molecular coordinates are available in PDB format, version 2.1 or older.\n"); fprintf (stdout, "Garlic may also be used to analyze protein sequences.\n"); fprintf (stdout, "\n"); fprintf (stdout, "Some of the features, which distinguish this program from others, are:\n"); fprintf (stdout, "(1) Coordinates, labels and other data are automatically displayed for\n"); fprintf (stdout, " the atom nearest to the current pointer (mouse) position.\n"); fprintf (stdout, "(2) Additional numeric data, like hydrophobicity, may be associated to\n"); fprintf (stdout, " each amino acid. The whole structure may be colored according to\n"); fprintf (stdout, " these values.\n"); fprintf (stdout, "(3) Selection mechanism is different.\n"); fprintf (stdout, "(4) Two bonds at different distance from observer have different colors.\n"); fprintf (stdout, "-------------------------------------------------------------------------\n"); fprintf (stdout, "Usage: garlic [true_garlic_options] [X11_options] [filename]\n"); fprintf (stdout, "-------------------------------------------------------------------------\n"); fprintf (stdout, "Command line options may be divided in two groups: true (specific) garlic\n"); fprintf (stdout, "options and X11 options. Options may be given in any order. All options\n"); fprintf (stdout, "and hard-coded default values are listed in the table below. For each\n"); fprintf (stdout, "parameter, the value defined through command line is used, if available.\n"); fprintf (stdout, "If not, the value defined in .garlicrc file is used. If .garlicrc file is\n"); fprintf (stdout, "not available, or there is no corresponding entry in this file, the\n"); fprintf (stdout, "hard-coded default value is used. The sample .garlicrc file included in\n"); fprintf (stdout, "the original package contains the values equal to hard-coded defaults.\n"); fprintf (stdout, "-------------------------------------------------------------------------\n"); fprintf (stdout, "garlic option: Description:\n"); fprintf (stdout, "-------------------------------------------------------------------------\n"); fprintf (stdout, "-h, --help Print help and exit.\n"); fprintf (stdout, "-v, --version Print version and exit.\n"); fprintf (stdout, "-r, --register Register garlic: inform author that your site has\n"); fprintf (stdout, " garlic installed and that someone is going to use\n"); fprintf (stdout, " this program. By registering, you are encouraging\n"); fprintf (stdout, " author to continue development of garlic. You can\n"); fprintf (stdout, " also help author to ensure support for further\n"); fprintf (stdout, " development. This option sends an e-mail message,\n"); fprintf (stdout, " containing only the e-mail message header and the\n"); fprintf (stdout, " word 'Hi!', to zucic@garlic.mefos.hr. Please type\n"); fprintf (stdout, " garlic -r if you are going to use this program.\n"); fprintf (stdout, " If your system is not connected to the Internet,\n"); fprintf (stdout, " you can send short e-mail from some other system.\n"); fprintf (stdout, "-nosys Hide the coordinate system icon (top left corner).\n"); fprintf (stdout, "-no-control Hide the control window (upper right corner).\n"); fprintf (stdout, "-stereo Display stereo image.\n"); fprintf (stdout, "-slab mode Default slab mode. Available slab modes are: off,\n"); fprintf (stdout, " planar (default), sphere, half-sphere, cylinder\n"); fprintf (stdout, " and half cylinder.\n"); fprintf (stdout, "-fading mode Default color fading mode. Available modes: off,\n"); fprintf (stdout, " planar (default), sphere, half-sphere, cylinder\n"); fprintf (stdout, " and half cylinder.\n"); fprintf (stdout, "-as number Default atom drawing style (hard-coded default: 2).\n"); fprintf (stdout, "-bs number Default bond drawing style (hard-coded default: 3).\n"); fprintf (stdout, "-fs number Default number of color fading surfaces. Parallel\n"); fprintf (stdout, " planes, concentric spheres or conc. cylinders may\n"); fprintf (stdout, " be used as fading surfaces. Three RGB triplets\n"); fprintf (stdout, " are assigned to each surface. Surfaces are evenly\n"); fprintf (stdout, " spaced; at least one and at most eight should be\n"); fprintf (stdout, " defined. At least three colors (left, middle and\n"); fprintf (stdout, " right) are assigned to each visible atom. These\n"); fprintf (stdout, " three colors are based on the position of a given\n"); fprintf (stdout, " atom relative to the nearest fading surface(s)\n"); fprintf (stdout, " and on colors assigned to these surfaces. Colors\n"); fprintf (stdout, " are combined using linear weighting.\n"); fprintf (stdout, "-lc color Left color at the i-th surface; i is between zero\n"); fprintf (stdout, " and seven. The color string should be compliant\n"); fprintf (stdout, " with X11R5. Blue, for example, may be specified\n"); fprintf (stdout, " as blue or as RGB:0000/0000/FFFF etc. For example\n"); fprintf (stdout, " -lc4 RGB:BBBB/8888/4444 defines the left color\n"); fprintf (stdout, " at the surface whose index is equal to four.\n"); fprintf (stdout, "-mc color Middle color at the i-th surface.\n"); fprintf (stdout, "-rc color Right color at the i-th surface.\n"); fprintf (stdout, "-pc, --print-config Print configuration data and exit.\n"); fprintf (stdout, "-pcn Print cursor names to stdout and exit.\n"); fprintf (stdout, "-log logfile Write commands and messages to log file. The file\n"); fprintf (stdout, " will be created in the current working directory.\n"); fprintf (stdout, " If this is not possible, log file will be created\n"); fprintf (stdout, " in users home directory.\n"); fprintf (stdout, "-------------------------------------------------------------------------\n"); fprintf (stdout, "X11 option: Description:\n"); fprintf (stdout, "-------------------------------------------------------------------------\n"); fprintf (stdout, "-display displayname X server to contact.\n"); fprintf (stdout, "-geometry geom Window geometry (default: almost the whole screen).\n"); fprintf (stdout, "-bg color Main window background color (default is black).\n"); fprintf (stdout, "-fg color Main window foreground color (default: white).\n"); fprintf (stdout, "-fn fontname Text font; (default is 10x20).\n"); fprintf (stdout, "-tbg color Text background color (default is black).\n"); fprintf (stdout, "-tfg color Text color (default is white).\n"); fprintf (stdout, "-cursor cursorname Cursor name; see /usr/include/X11/cursorfont.h for\n"); fprintf (stdout, " names; remove the XC_ prefix.\n"); fprintf (stdout, "-------------------------------------------------------------------------\n"); fprintf (stdout, "filename: The input file name. Full pathname may be used. If\n"); fprintf (stdout, " filename does not contain the path, garlic will try\n"); fprintf (stdout, " to find the specified file in the current working\n"); fprintf (stdout, " directory. If the first attempt to open the file\n"); fprintf (stdout, " fails, the filename is appended to the content of\n"); fprintf (stdout, " the environment variable MOL_DIR for the second\n"); fprintf (stdout, " attempt. If this fails too, garlic will search all\n"); fprintf (stdout, " directories specified in the environment variable\n"); fprintf (stdout, " MOL_PATH.\n"); fprintf (stdout, "-------------------------------------------------------------------------\n"); fprintf (stdout, "Personal initializations may be written to .garlicrc file. Normally, this\n"); fprintf (stdout, "file should be kept in users home directory. Note that this is not the\n"); fprintf (stdout, "first directory to be searched for .garlicrc file! Up to seven pathnames\n"); fprintf (stdout, "are tryed in the following order:\n"); fprintf (stdout, "\n"); fprintf (stdout, ".garlicrc .garlicrc in current working directory.\n"); fprintf (stdout, "$HOME/.garlicrc .garlicrc in home directory. This is the\n"); fprintf (stdout, " recommended location.\n"); fprintf (stdout, "$HOME/garlic/.garlicrc ./garlicrc, subdirectory garlic of users\n"); fprintf (stdout, " home directory.\n"); fprintf (stdout, "/usr/share/garlic/.garlicrc ./garlicrc in /usr/share/garlic (Linux).\n"); fprintf (stdout, "/etc/garlicrc garlicrc in /etc, Debian Linux; note that\n"); fprintf (stdout, " file name is garlicrc in this case!\n"); fprintf (stdout, "/usr/local/lib/garlic/.garlicrc .garlicrc in /usr/local/lib/garlic dir.\n"); fprintf (stdout, "/usr/lib/garlic/.garlicrc .garlicrc in /usr/lib/garlic; this is the\n"); fprintf (stdout, " last attempt; if it failes, hard-coded\n"); fprintf (stdout, " default values will be used.\n"); fprintf (stdout, "-------------------------------------------------------------------------\n"); fprintf (stdout, "Environment variables:\n"); fprintf (stdout, "-------------------------------------------------------------------------\n"); fprintf (stdout, "MOL_DIR Defines where to look for the specified file if not\n"); fprintf (stdout, " found in the current working directory.\n"); fprintf (stdout, "MOL_PATH The list of directories to be searched. It is used\n"); fprintf (stdout, " if attempt with MOL_DIR failes or if MOL_DIR is\n"); fprintf (stdout, " not defined. Use space or colon (:) to separate\n"); fprintf (stdout, " directory names. MOL_PATH is quite useful; it is\n"); fprintf (stdout, " recommended to define this environment variable\n"); fprintf (stdout, " through .login, .bashrc or some other script.\n"); fprintf (stdout, " MOL_PATH is more useful than MOL_DIR so it is\n"); fprintf (stdout, " recommended to define only MOL_PATH variable.\n"); fprintf (stdout, "DISPLAY X server to which the program should be connected.\n"); fprintf (stdout, "-------------------------------------------------------------------------\n"); fprintf (stdout, "garlic home page: http://garlic.mefos.hr/garlic\n"); fprintf (stdout, "Damir Zucic home page: http://garlic.mefos.hr/zucic\n"); fprintf (stdout, "E-mail: zucic@mefos.hr\n"); fprintf (stdout, "=========================================================================\n"); fprintf (stdout, "\n"); } /*===========================================================================*/ garlic-1.6/docking_refresh.c0000644000076500007650000000411107157356143016417 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= docking_refresh.c Purpose: Refresh the content of docking window. Input: (1) Pointer to RuntimeS structure. (2) Pointer to GUIS structure. Output: (1) The content of docking window refreshed. (2) Return value. Return value: (1) Positive always (trivial). Notes: (1) The index of exposed atom is of the type int, though size_t is used elsewhere. The reason is that int may have negative value, while size_t is unsigned on many systems. Negative values are used to signal that data stored to a given box are obsolete. ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int DockingProject_ (RuntimeS *, int); int ListExposedPolarResidues_ (RuntimeS *, int); int RepresentativeAtoms_ (RuntimeS *, int); int ExcludeDistant_ (RuntimeS *, int); int DrawBottom_ (GUIS *, RuntimeS *); int DrawTop_ (GUIS *, RuntimeS *); /*======refresh docking window:==============================================*/ int DockingRefresh_ (RuntimeS *runtimeSP, GUIS *guiSP) { /* Prepare orthogonal projections: */ DockingProject_ (runtimeSP, 1); DockingProject_ (runtimeSP, 2); /* Prepare two lists of exposed polar residues. Each */ /* residue may be found more than once in docking matrix: */ ListExposedPolarResidues_ (runtimeSP, 1); ListExposedPolarResidues_ (runtimeSP, 2); /* Find representative atoms: */ RepresentativeAtoms_ (runtimeSP, 1); RepresentativeAtoms_ (runtimeSP, 2); /* Exclude residues which are below the plane: */ ExcludeDistant_ (runtimeSP, 1); ExcludeDistant_ (runtimeSP, 2); /* Draw symbols: */ DrawBottom_ (guiSP, runtimeSP); DrawTop_ (guiSP, runtimeSP); /* Return positive value: */ return 1; } /*===========================================================================*/ garlic-1.6/parallel_part.c0000644000076500007650000000404507271260004016076 0ustar zuciczucic00000000000000/* Copyright (C) 2001 Damir Zucic */ /*============================================================================= parallel_part.c Purpose: Find the part of the vector which is parallel with the reference vector. Input: (1) Pointer to VectorS (where the result will be stored). (2) Pointer to VectorS structure (the reference vector). (3) Pointer to VectorS structure (the vector which should be projected). Output: (1) Parallel part of the specified vector. (2) Return value. Return value: (1) Positive on success. (2) Negative on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ double ScalarProduct_ (VectorS *, VectorS *); /*======find parallel part of input vector:==================================*/ int ParallelPart_ (VectorS *parallel_vectorSP, VectorS *reference_vectorSP, VectorS *input_vectorSP) { double abs_value_squared; double reciprocal_denominator; double scalar_product; double scale_factor; /* Check the squared absolute value of the reference vector: */ abs_value_squared = ScalarProduct_ (reference_vectorSP, reference_vectorSP); if (abs_value_squared == 0.0) return -1; /* Prepare the reciprocal denominator: */ reciprocal_denominator = 1.0 / abs_value_squared; /* Prepare the scalar product of two vectors: */ scalar_product = ScalarProduct_ (input_vectorSP, reference_vectorSP); /* Prepare the scale factor: */ scale_factor = scalar_product * reciprocal_denominator; /* Prepare the result: */ parallel_vectorSP->x = scale_factor * reference_vectorSP->x; parallel_vectorSP->y = scale_factor * reference_vectorSP->y; parallel_vectorSP->z = scale_factor * reference_vectorSP->z; /* Return positive value (success indicator): */ return 1; } /*===========================================================================*/ garlic-1.6/residue_names.c0000644000076500007650000000361707065474631016121 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= residue_names.c Purpose: Extract residue names from the list. Input: (1) Pointer to SelectS structure, where data will be stored. (2) Pointer to the string with list of residue names. Output: (1) Some data added to SelectS structure. (2) Return value. Return value: (1) Positive on success. (2) Negative on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======extract residue names:===============================================*/ int ExtractResidueNames_ (SelectS *selectSP, char *stringP) { char *P, *tokenP; int nameI; /* Check the string length: */ if (strlen (stringP) == 0) return -1; /* Initialize all_residue_namesF (1 = select all residue names): */ selectSP->all_residue_namesF = 0; /* Initialize the number of residue names: */ selectSP->residue_namesN = 0; /* If wildcard (asterisk) is present, set */ /* all_residue_namesF to one and return: */ if (strstr (stringP, "*")) { selectSP->all_residue_namesF = 1; return 1; } /* Parse the list of residue names: */ P = stringP; while ((tokenP = strtok (P, " \t,;")) != NULL) { /** Ensure the proper operation of strtok: **/ P = NULL; /** Copy the token and update the count: **/ nameI = selectSP->residue_namesN; strncpy (selectSP->residue_nameAA[nameI], tokenP, RESNAMESIZE - 1); selectSP->residue_nameAA[nameI][RESNAMESIZE - 1] = '\0'; /** Update and check the count: **/ selectSP->residue_namesN++; if (selectSP->residue_namesN >= MAXFIELDS) break; } /* Return positive value on success: */ return 1; } /*===========================================================================*/ garlic-1.6/chi3_from_cbcgcdoe1.c0000644000076500007650000000731507341276470017036 0ustar zuciczucic00000000000000/* Copyright (C) 2001 Damir Zucic */ /*============================================================================= chi3_from_cbcgcdoe1.c Purpose: Calculate dihedral angle chi3, using CB, CG, CD and OE1 coordinates. Input: (1) Pointer to AtomS structure, pointing to the first atom of the current macromolecular complex. (2) Index of the first atom of the current residue. (3) Index of the last atom of the currrent residue. Output: Return value. Return value: (1) Dihedral angle chi3, on success. (2) BADDIHEDANGLE on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int ExtractFourAtoms_ (VectorS *, VectorS *, VectorS *, VectorS *, char *, char *, char *, char *, AtomS *, size_t, size_t); void VectorProduct_ (VectorS *, VectorS *, VectorS *); double AbsoluteValue_ (VectorS *); double ScalarProduct_ (VectorS *, VectorS *); /*======calculate chi3 from CB, CG, CD and OE1:===============================*/ double Chi3FromCBCGCDOE1_ (AtomS *atomSP, size_t atom_startI, size_t atom_endI) { static VectorS CB_vectorS, CG_vectorS, CD_vectorS, OE1_vectorS; int n; VectorS CG_CB_vectorS, CG_CD_vectorS; VectorS CD_CG_vectorS, CD_OE1_vectorS; VectorS u1S, u2S; VectorS v1S, v2S; double denom, ratio, alpha; double chi3; /* Extract CB, CG, CD and OE1 coordinates: */ n = ExtractFourAtoms_ (&CB_vectorS, &CG_vectorS, &CD_vectorS, &OE1_vectorS, "CB", "CG", "CD", "OE1", atomSP, atom_startI, atom_endI); /* All four atoms are required to calculate the angle chi3: */ if (n < 4) return BADDIHEDANGLE; /* The first pair of auxiliary vectors: */ CG_CB_vectorS.x = CB_vectorS.x - CG_vectorS.x; CG_CB_vectorS.y = CB_vectorS.y - CG_vectorS.y; CG_CB_vectorS.z = CB_vectorS.z - CG_vectorS.z; CG_CD_vectorS.x = CD_vectorS.x - CG_vectorS.x; CG_CD_vectorS.y = CD_vectorS.y - CG_vectorS.y; CG_CD_vectorS.z = CD_vectorS.z - CG_vectorS.z; /* The second pair of auxiliary vectors: */ CD_CG_vectorS.x = CG_vectorS.x - CD_vectorS.x; CD_CG_vectorS.y = CG_vectorS.y - CD_vectorS.y; CD_CG_vectorS.z = CG_vectorS.z - CD_vectorS.z; CD_OE1_vectorS.x = OE1_vectorS.x - CD_vectorS.x; CD_OE1_vectorS.y = OE1_vectorS.y - CD_vectorS.y; CD_OE1_vectorS.z = OE1_vectorS.z - CD_vectorS.z; /* Two vectors perpendicular to CG_CD_vectorS, mutually orthogonal, */ /* the second in the plane defined by CG_CB_vectorS and CG_CD_vectorS: */ VectorProduct_ (&u1S, &CG_CB_vectorS, &CG_CD_vectorS); VectorProduct_ (&u2S, &u1S, &CG_CD_vectorS); /* Two vectors perpendicular to CD_CG_vectorS, mutually orthogonal, */ /* the second in the plane defined by CD_CG_vectorS and CD_OE1_vectorS: */ VectorProduct_ (&v1S, &CD_CG_vectorS, &CD_OE1_vectorS); VectorProduct_ (&v2S, &CD_CG_vectorS, &v1S); /* Calculate the angle alpha, which will be used to calculate chi3: */ /* Avoid division by zero: */ denom = AbsoluteValue_ (&u1S) * AbsoluteValue_ (&v1S); if (denom == 0.0) return BADDIHEDANGLE; /* Use the scalar product to calculate the cosine of the angle: */ ratio = ScalarProduct_ (&u1S, &v1S) / denom; /* Arc cosine is very sensitive to floating point errors: */ if (ratio <= -1.0) alpha = 3.1415927; else if (ratio >= 1.0) alpha = 0.0; else alpha = acos (ratio); /* There are two possible solutions; the right one is resolved here: */ if (ScalarProduct_ (&v2S, &u1S) >= 0) chi3 = alpha; else chi3 = -alpha; /* Return the angle (in radians): */ return chi3; } /*===========================================================================*/ garlic-1.6/select_alternate.c0000644000076500007650000000565307465734676016632 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2002 Damir Zucic */ /*============================================================================= select_alternate.c Purpose: Select atoms at alternate locations. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. (3) Selection mode index (0 = overwrite, 1 = restrict, 2 = expand previous selection). Output: (1) The flag selectedF set for all atoms at alternate positions, in all currently caught macromolecular complexes. (2) Return value. Return value: (1) The number of selected atoms (zero or positive value). Notes: (1) The position_changedF is updated, because some atoms may not have the proper color. ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======select atoms at alternate positions:=================================*/ long SelectAlternate_ (MolComplexS *mol_complexSP, int mol_complexesN, int selection_modeI) { long selected_atomsN = 0; int mol_complexI; MolComplexS *curr_mol_complexSP; size_t atomsN, atomI; AtomS *curr_atomSP; char alt_location; int alternateF; /* Check every macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /** Pointer to the current macromolecular complex: **/ curr_mol_complexSP = mol_complexSP + mol_complexI; /** Check is the current macromolecular complex caught: **/ if (curr_mol_complexSP->catchF == 0) continue; /** Number of atoms in a macromolecular complex: **/ atomsN = curr_mol_complexSP->atomsN; /** Scan all atoms in the current complex: **/ for (atomI = 0; atomI < atomsN; atomI++) { /** Pointer to the current atom: **/ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /** Check the alternate position indicator: **/ alt_location = curr_atomSP->raw_atomS.alt_location; alternateF = 0; if ((alt_location != ' ') && (alt_location != 'A')) { alternateF = 1; } /** Set the selection flag for the current atom: **/ switch (selection_modeI) { /*** Overwrite the previous selection: ***/ case 0: curr_atomSP->selectedF = alternateF; break; /*** Restrict the previous selection: ***/ case 1: curr_atomSP->selectedF &= alternateF; break; /*** Expand the previous selection: ***/ case 2: curr_atomSP->selectedF |= alternateF; break; default: ; } /** Check the selection flag; increase **/ /** the count if flag is equal to one: **/ if (curr_atomSP->selectedF) selected_atomsN++; } /** Update the position_changedF (some atoms may have bad color): **/ curr_mol_complexSP->position_changedF = 1; } /* Return the number of selected atoms: */ return selected_atomsN; } /*===========================================================================*/ garlic-1.6/eat_right_char.c0000644000076500007650000000371507307133241016224 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= eat_right_char.c Purpose: Eat right character. Copy the command line to the history buffer. Input: (1) Pointer to RuntimeS structure. Output: (1) One character removed. (2) Return value. Return value: (1) Positive on success. (2) Negative on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======eat right character:=================================================*/ int EatRightChar_ (RuntimeS *runtimeSP) { int comm_length, old_comm_length, carriage_pos; char stringA[COMMSTRINGSIZE]; char *currP; /* Copy the command string length and carriage (keyboard cursor) position: */ comm_length = runtimeSP->command_length; old_comm_length = comm_length; carriage_pos = runtimeSP->carriage_position; /* Check is there anything on the right side: */ if (carriage_pos >= comm_length) return -1; /* Reduce the command length: */ comm_length--; /* Copy the left part: */ strncpy (stringA, runtimeSP->curr_commandA, carriage_pos); stringA[carriage_pos] = '\0'; /* Copy the right part, but skip the first character: */ strncat (stringA, runtimeSP->curr_commandA + carriage_pos + 1, old_comm_length - carriage_pos - 1); /* Ensure the proper termination: */ stringA[comm_length] = '\0'; /* Copy the command string: */ strcpy (runtimeSP->curr_commandA, stringA); /* Set the command length: */ runtimeSP->command_length = comm_length; /* Copy the command string to the output buffer: */ currP = runtimeSP->commandsP + runtimeSP->next_commandI * COMMSTRINGSIZE; strcpy (currP, runtimeSP->curr_commandA); /* Return positive value (success): */ return 1; } /*===========================================================================*/ garlic-1.6/main_refresh.c0000644000076500007650000004062110360000676015716 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2006 Damir Zucic */ /*============================================================================= main_refresh.c Purpose: Refresh the main window content. This function does the most important job from the user's standpoint: draws something to the screen. This function calls the functions which are doing the most important job. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. (3) Pointer to RuntimeS structure, with some runtime data. (4) Pointer to ConfigS structure, with configuration data. (5) Pointer to GUIS structure, with GUI data. (6) Pointer to NearestAtomS structure, with information about the atom occupying the given pixel. (7) The number of pixels in the main window free area. (8) The refreshI, used to check the NearestAtomS associated with a given pixel. If refreshI is larger than the corresponding value stored in NearestAtomS, the structure does not contain fresh data, so the pixel may be redrawn without any checking. If values are equal, the check should be made to see which atom is closer to the observer: the one which is currently processed, or the one which already occupies the pixel. Output: (1) Image drawn to the main window. (2) Return value. Return value: (1) Depends on main window drawing mode index. If mode is zero the number of atoms which were drawn will be returned. Zero is returned if there are no visible atoms. Negative value is never returned, because the return type is size_t, so it is unsigned on most systems. Notes: (1) The initial drawing destination is the hidden pixmap, and the content of this pixmap is copied later to the main window. (2) The human eye may discriminate something like 25 images per second. Thus, if this function executes once in less than 40 milliseconds, refreshing will be smooth for the user. It will be quite smooth even if needs more time for one passage, because drawing is done on hidden pixmap ("hidden frame"). (3) In default mode (structure drawing mode), after the loaded objects are drawn, a small legend is placed to the top left corner (system.xpm). (4) A macromolecular object is visible and should be projected if if least one atom of this object is visible. The atom is visible if it is not hidden (user may decide to hide some atoms) and if it falls inside the slab. This does not mean that this atom will be truly visible in the main window: its projection may be outside the free area of the main window. Note that the term visible applyes both to the atoms which are actually visible and to the atoms which are projected outside of the main window free area! (5) Do not change the execution order of Slab_, ProjectAtoms_ and Fading_ ! (6) Note that atoms and bonds are drawn style by style. In the first step, only atoms which have style "1" are drawn. All other atoms are ignored in this step. In the next step, atoms which have style "2" are drawn etc. Another approach will be to draw atom by atom and bond by bond, choosing the proper style. This may require a larger number of function calls and repeated passing of certain parameters, reducing the speed of execution. (7) Planes are drawn after atoms and bonds are drawn. ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ void InformUser_ (GUIS *, char *); int RefreshPixmap_ (Display *, Pixmap, GC, unsigned int, unsigned int, unsigned long); size_t Slab_ (MolComplexS *, int); size_t ProjectAtoms_ (MolComplexS *, int, ConfigS *); void ProjectMembranes_ (MolComplexS *, int, ConfigS *); void ProjectPlanes_ (MolComplexS *, int, ConfigS *); size_t Fading_ (MolComplexS *, int, GUIS *); void ResetPositionFlag_ (MolComplexS *, int); size_t DrawAtomsStyle1_ (MolComplexS *, int, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); size_t DrawAtomsStyle2_ (MolComplexS *, int, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); size_t DrawAtomsStyle3_ (MolComplexS *, int, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); size_t DrawAtomsStyle4_ (MolComplexS *, int, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); size_t DrawAtomsStyle5_ (MolComplexS *, int, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); size_t DrawAtomsStyle6_ (MolComplexS *, int, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); size_t DrawAtomsStyle7_ (MolComplexS *, int, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); size_t DrawBondsStyle1_ (MolComplexS *, int, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); size_t DrawBondsStyle2_ (MolComplexS *, int, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); size_t DrawBondsStyle3_ (MolComplexS *, int, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); size_t DrawBondsStyle4_ (MolComplexS *, int, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); size_t DrawBondsStyle5_ (MolComplexS *, int, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); size_t DrawNiceBonds_ (MolComplexS *, int, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); size_t DrawSticks_ (MolComplexS *, int, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); size_t DrawBackbone_ (MolComplexS *, int, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); int DrawBalls_ (MolComplexS *, int, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); int DrawBalls2_ (MolComplexS *, int, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); int DrawBigSpheres_ (MolComplexS *, int, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); int DrawBigSpheres2_ (MolComplexS *, int, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); int DrawSpacefill_ (MolComplexS *, int, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); int DrawSpacefill2_ (MolComplexS *, int, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); int DrawCovalent_ (MolComplexS *, int, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); int DrawCovalent2_ (MolComplexS *, int, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); int DrawSmall_ (MolComplexS *, int, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); int DrawSmall2_ (MolComplexS *, int, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); int DrawEditSymbol_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); int DrawMembranes_ (MolComplexS *, int, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); int DrawPlanes_ (MolComplexS *, int, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); size_t DrawRamachandran_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); size_t WheelTopView_ (RuntimeS *, GUIS *, NearestAtomS *, size_t, unsigned int); size_t WheelBottomView_ (RuntimeS *, GUIS *, NearestAtomS *, size_t, unsigned int); size_t DrawVenn_ (RuntimeS *, GUIS *, NearestAtomS *, size_t, unsigned int); size_t DrawPlots_ (RuntimeS *, GUIS *, NearestAtomS *, size_t, unsigned int); size_t DrawComparison_ (RuntimeS *, GUIS *, NearestAtomS *, size_t, unsigned int); int SmallRamachandran_ (MolComplexS *, RuntimeS *, GUIS *); int SmallOmega_ (MolComplexS *, RuntimeS *, GUIS *); int BlurMainWindow_ (RuntimeS *, GUIS *, NearestAtomS *, size_t); size_t DrawLabels_ (MolComplexS *, int, ConfigS *, GUIS *); int DrawTags_ (MolComplexS *, int, ConfigS *, GUIS *); int DrawTitles_ (RuntimeS *, GUIS *); int DrawSystem_ (GUIS *); int WriteHints_ (GUIS *); /*======refresh the main window:=============================================*/ size_t MainRefresh_ (MolComplexS *mol_complexSP, int mol_complexesN, RuntimeS *runtimeSP, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int refreshI) { size_t atoms_drawnN = 0; size_t pixelI; NearestAtomS *curr_pixelSP; int edit_modeI; /* Check the main window refresh flag: if it is equal to zero, do not */ /* refresh the main window - just inform the user that refreshing is off: */ if (guiSP->main_window_refreshF == 0) { InformUser_ (guiSP, "Refreshing off!"); return 0; } /* Draw Ramachandran plot instead of structure, if requested: */ if (guiSP->main_window_modeI == 1) { return DrawRamachandran_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, refreshI); } /* Draw helical wheel instead of structure, if requested: */ else if (guiSP->main_window_modeI == 2) { /* Counterclockwise wheel: */ if (runtimeSP->wheel_clockwiseF == 0) { return WheelTopView_ (runtimeSP, guiSP, nearest_atomSP, pixelsN, refreshI); } else { return WheelBottomView_ (runtimeSP, guiSP, nearest_atomSP, pixelsN, refreshI); } } /* Draw Venn diagram instead of structure, if requested: */ else if (guiSP->main_window_modeI == 3) { return DrawVenn_ (runtimeSP, guiSP, nearest_atomSP, pixelsN, refreshI); } /* Draw hydrophobicity plots instead of structure, if requested: */ else if (guiSP->main_window_modeI == 4) { return DrawPlots_ (runtimeSP, guiSP, nearest_atomSP, pixelsN, refreshI); } /* Draw sequence comparison: */ else if (guiSP->main_window_modeI == 5) { return DrawComparison_ (runtimeSP, guiSP, nearest_atomSP, pixelsN, refreshI); } /* If this point is reached, structures should be drawn */ /* (default drawing mode, guiSP->main_window_modeI = 0). */ /*---------------------------------------------------------------------------*/ /* Refresh the hidden pixmap, where drawing will be done: */ RefreshPixmap_ (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], guiSP->control_winS.x0, guiSP->input_winS.y0, guiSP->main_winS.bg_colorID); /* If blur is on, fill the colorID element of each */ /* NearestAtomS structure with background color ID: */ if (runtimeSP->blurF) { for (pixelI = 0; pixelI < pixelsN; pixelI++) { curr_pixelSP = nearest_atomSP + pixelI; curr_pixelSP->colorID = guiSP->main_winS.bg_colorID; } } /*---------------------------------------------------------------------------*/ /* Check which atoms are inside slab: */ Slab_ (mol_complexSP, mol_complexesN); /* Project atoms: */ ProjectAtoms_ (mol_complexSP, mol_complexesN, configSP); /* Project all available membranes: */ ProjectMembranes_ (mol_complexSP, mol_complexesN, configSP); /* Project all planes (even if not visible): */ ProjectPlanes_ (mol_complexSP, mol_complexesN, configSP); /* Prepare the left, middle and right color for each atom. */ /* These are the only colors required by fast drawing styles. */ Fading_ (mol_complexSP, mol_complexesN, guiSP); /* Reset the position_changedF in each macromolecular complex: */ ResetPositionFlag_ (mol_complexSP, mol_complexesN); /*------draw atoms (simple styles):------------------------------------------*/ atoms_drawnN += DrawAtomsStyle1_ (mol_complexSP, mol_complexesN, configSP, guiSP, nearest_atomSP, pixelsN, refreshI); atoms_drawnN += DrawAtomsStyle2_ (mol_complexSP, mol_complexesN, configSP, guiSP, nearest_atomSP, pixelsN, refreshI); atoms_drawnN += DrawAtomsStyle3_ (mol_complexSP, mol_complexesN, configSP, guiSP, nearest_atomSP, pixelsN, refreshI); atoms_drawnN += DrawAtomsStyle4_ (mol_complexSP, mol_complexesN, configSP, guiSP, nearest_atomSP, pixelsN, refreshI); atoms_drawnN += DrawAtomsStyle5_ (mol_complexSP, mol_complexesN, configSP, guiSP, nearest_atomSP, pixelsN, refreshI); atoms_drawnN += DrawAtomsStyle6_ (mol_complexSP, mol_complexesN, configSP, guiSP, nearest_atomSP, pixelsN, refreshI); atoms_drawnN += DrawAtomsStyle7_ (mol_complexSP, mol_complexesN, configSP, guiSP, nearest_atomSP, pixelsN, refreshI); /*------draw bonds (simple styles):------------------------------------------*/ DrawBondsStyle1_ (mol_complexSP, mol_complexesN, configSP, guiSP, nearest_atomSP, pixelsN, refreshI); DrawBondsStyle2_ (mol_complexSP, mol_complexesN, configSP, guiSP, nearest_atomSP, pixelsN, refreshI); DrawBondsStyle3_ (mol_complexSP, mol_complexesN, configSP, guiSP, nearest_atomSP, pixelsN, refreshI); DrawBondsStyle4_ (mol_complexSP, mol_complexesN, configSP, guiSP, nearest_atomSP, pixelsN, refreshI); DrawBondsStyle5_ (mol_complexSP, mol_complexesN, configSP, guiSP, nearest_atomSP, pixelsN, refreshI); /*------special drawing functions:-------------------------------------------*/ DrawBackbone_ (mol_complexSP, mol_complexesN, configSP, guiSP, nearest_atomSP, pixelsN, refreshI); DrawBalls_ (mol_complexSP, mol_complexesN, configSP, guiSP, nearest_atomSP, pixelsN, refreshI); DrawBalls2_ (mol_complexSP, mol_complexesN, configSP, guiSP, nearest_atomSP, pixelsN, refreshI); DrawBigSpheres_ (mol_complexSP, mol_complexesN, configSP, guiSP, nearest_atomSP, pixelsN, refreshI); DrawBigSpheres2_ (mol_complexSP, mol_complexesN, configSP, guiSP, nearest_atomSP, pixelsN, refreshI); DrawSpacefill_ (mol_complexSP, mol_complexesN, configSP, guiSP, nearest_atomSP, pixelsN, refreshI); DrawSpacefill2_ (mol_complexSP, mol_complexesN, configSP, guiSP, nearest_atomSP, pixelsN, refreshI); DrawCovalent_ (mol_complexSP, mol_complexesN, configSP, guiSP, nearest_atomSP, pixelsN, refreshI); DrawCovalent2_ (mol_complexSP, mol_complexesN, configSP, guiSP, nearest_atomSP, pixelsN, refreshI); DrawSmall_ (mol_complexSP, mol_complexesN, configSP, guiSP, nearest_atomSP, pixelsN, refreshI); DrawSmall2_ (mol_complexSP, mol_complexesN, configSP, guiSP, nearest_atomSP, pixelsN, refreshI); DrawNiceBonds_ (mol_complexSP, mol_complexesN, configSP, guiSP, nearest_atomSP, pixelsN, refreshI); DrawSticks_ (mol_complexSP, mol_complexesN, configSP, guiSP, nearest_atomSP, pixelsN, refreshI); if (runtimeSP->edit_modeI != 0) { DrawEditSymbol_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, refreshI); } DrawMembranes_ (mol_complexSP, mol_complexesN, configSP, guiSP, nearest_atomSP, pixelsN, refreshI); DrawPlanes_ (mol_complexSP, mol_complexesN, configSP, guiSP, nearest_atomSP, pixelsN, refreshI); /*------auxiliary symbols and plots:-----------------------------------------*/ /* If editing dihedral angle phi or psi (or both), draw small Rama. */ /* plot for the first selected residue to the bottom right corner: */ edit_modeI = runtimeSP->edit_modeI; if ((edit_modeI == 2) || (edit_modeI == 3) || (edit_modeI == 5)) { SmallRamachandran_ (mol_complexSP + runtimeSP->default_complexI, runtimeSP, guiSP); } /* If editing the omega angle, draw small */ /* omega plot to the bottom right corner: */ else if (edit_modeI == 4) { SmallOmega_ (mol_complexSP + runtimeSP->default_complexI, runtimeSP, guiSP); } /* Write some hints if there are no macromolecular complexes loaded: */ if (mol_complexesN == 0) WriteHints_ (guiSP); /*---------------------------------------------------------------------------*/ /* Copy hidden pixmap to the main window: */ XCopyArea (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->main_winS.ID, guiSP->theGCA[0], 0, 0, guiSP->main_win_free_area_width, guiSP->main_win_free_area_height, 0, 0); /* Blur image if blur flag is equal to one: */ if (runtimeSP->blurF) { BlurMainWindow_ (runtimeSP, guiSP, nearest_atomSP, pixelsN); } /*------labels, tags, titles and coordinate system hint:---------------------*/ DrawLabels_ (mol_complexSP, mol_complexesN, configSP, guiSP); DrawTags_ (mol_complexSP, mol_complexesN, configSP, guiSP); DrawTitles_ (runtimeSP, guiSP); /* Put a small legend to the top left corner: */ /* (system.xpm, to explain the coord. system) */ if (configSP->show_coord_systemF) DrawSystem_ (guiSP); /*---------------------------------------------------------------------------*/ return atoms_drawnN; } /*===========================================================================*/ garlic-1.6/select_5nz6.c0000644000076500007650000001521010403043672015412 0ustar zuciczucic00000000000000/* Copyright (C) 2006 Damir Zucic */ /*============================================================================= select_5nz6.c Purpose: Select the sequence fragment which contains five or more negative or zwitterionic residues in a window of six residues. ASP, GLU, ASN and GLN are taken into account. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. (3) Selection mode index (0 = overwrite, 1 = restrict, 2 = expand previous selection). Output: (1) The flag selectedF set to one for selected atoms in every caught macromolecular complex. (2) Return value. Return value: (1) The number of selected atoms (zero or positive value). ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======select five or more negative or zwitterionic residues:===============*/ long Select5NZ6_ (MolComplexS *mol_complexSP, int mol_complexesN, int selection_modeI) { long selected_atomsN = 0; int mol_complexI; MolComplexS *curr_mol_complexSP; int atomsN, atomI; AtomS *curr_atomSP; int residuesN, residueI, windowI, combinedI; ResidueS *curr_residueSP; AtomS *first_atomSP; char *nameP; int negative_zwitterN; int first_atomI, last_atomI; /* Check every macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check is the current macromolecular complex caught: */ if (curr_mol_complexSP->catchF == 0) continue; /* Prepare and check the number of atoms in the current complex: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Copy the number of residues in the current macromol. complex: */ residuesN = curr_mol_complexSP->residuesN; if (residuesN == 0) continue; /* Backup the current selection if selection mode is restrict: */ if (selection_modeI == 1) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Copy the selection flag: */ curr_atomSP->previous_selectedF = curr_atomSP->selectedF; } } /* Unselect everything if selection mode is overwrite or restrict: */ if ((selection_modeI == 0) || (selection_modeI == 1)) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Unselect the current atom: */ curr_atomSP->selectedF = 0; } } /* Scan the residues of the current macromolecular complex: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Reset the number of negative and zwitterionic residues: */ negative_zwitterN = 0; /* Scan the window of six residues, */ /* starting from the current residue: */ for (windowI = 0; windowI < 6; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI >= residuesN) break; /* Residue associated with the combined index: */ curr_residueSP = curr_mol_complexSP->residueSP + combinedI; /* Pointer to the first atom of current residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Pointer to the name of the current residue: */ nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Check is this residue negative or zwitterionic: */ if ((strcmp (nameP, "ASP") == 0) || (strcmp (nameP, "GLU") == 0) || (strcmp (nameP, "ASN") == 0) || (strcmp (nameP, "GLN") == 0)) negative_zwitterN++; } /* If there were five or more negative and zwitterionic */ /* residues in a window of six residues, the quintet is */ /* found. If there were four or less, take the next res. */ if (negative_zwitterN < 5) continue; /* If this point is reached, rescan the window of six */ /* residues and select negative and zwitterionic res. */ /* Scan the window of six residues, */ /* starting from the current residue: */ for (windowI = 0; windowI < 6; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI >= residuesN) break; /* Residue associated with the combined index: */ curr_residueSP = curr_mol_complexSP->residueSP + combinedI; /* Pointer to the first atom of current residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Pointer to the name of the current residue: */ nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Check is this residue negative or zwitterionic: */ if ((strcmp (nameP, "ASP") != 0) && (strcmp (nameP, "GLU") != 0) && (strcmp (nameP, "ASN") != 0) && (strcmp (nameP, "GLN") != 0)) continue; /* If this point is reached, select */ /* all atoms of the current residue. */ /* The indices of the first and the */ /* last atom of the current residue: */ first_atomI = curr_residueSP->residue_startI; last_atomI = curr_residueSP->residue_endI; /* Select all atoms of the current residue: */ for (atomI = first_atomI; atomI <= last_atomI; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Select the current atom: */ curr_atomSP->selectedF = 1; /* Update the counter of selected atoms: */ selected_atomsN++; } } /* End of residueI loop: */ } /* Combine the current selection with the */ /* previous, if selection mode is restrict: */ if (selection_modeI == 1) { /* Reset the counter of selected atoms. The */ /* selected atoms should be counted again. */ selected_atomsN = 0; /* Combine the old and the new selection flag: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Combine selection flags: */ curr_atomSP->selectedF *= curr_atomSP->previous_selectedF; /* Check the selection flag; increase */ /* the count of selected residues if */ /* the selection flag is equal to one: */ if (curr_atomSP->selectedF) selected_atomsN++; } } /* Update the position_changedF (some atoms may have bad color): */ curr_mol_complexSP->position_changedF = 1; /* End of mol_complexI loop: */ } /* Return the number of selected atoms: */ return selected_atomsN; } /*===========================================================================*/ garlic-1.6/select_5nz7.c0000644000076500007650000001522210401550544015415 0ustar zuciczucic00000000000000/* Copyright (C) 2006 Damir Zucic */ /*============================================================================= select_5nz7.c Purpose: Select the sequence fragment which contains five or more negative or zwitterionic residues in a window of seven residues. ASP, GLU, ASN and GLN are taken into account. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. (3) Selection mode index (0 = overwrite, 1 = restrict, 2 = expand previous selection). Output: (1) The flag selectedF set to one for selected atoms in every caught macromolecular complex. (2) Return value. Return value: (1) The number of selected atoms (zero or positive value). ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======select five or more negative or zwitterionic residues:===============*/ long Select5NZ7_ (MolComplexS *mol_complexSP, int mol_complexesN, int selection_modeI) { long selected_atomsN = 0; int mol_complexI; MolComplexS *curr_mol_complexSP; int atomsN, atomI; AtomS *curr_atomSP; int residuesN, residueI, windowI, combinedI; ResidueS *curr_residueSP; AtomS *first_atomSP; char *nameP; int negative_zwitterN; int first_atomI, last_atomI; /* Check every macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check is the current macromolecular complex caught: */ if (curr_mol_complexSP->catchF == 0) continue; /* Prepare and check the number of atoms in the current complex: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Copy the number of residues in the current macromol. complex: */ residuesN = curr_mol_complexSP->residuesN; if (residuesN == 0) continue; /* Backup the current selection if selection mode is restrict: */ if (selection_modeI == 1) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Copy the selection flag: */ curr_atomSP->previous_selectedF = curr_atomSP->selectedF; } } /* Unselect everything if selection mode is overwrite or restrict: */ if ((selection_modeI == 0) || (selection_modeI == 1)) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Unselect the current atom: */ curr_atomSP->selectedF = 0; } } /* Scan the residues of the current macromolecular complex: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Reset the number of negative and zwitterionic residues: */ negative_zwitterN = 0; /* Scan the window of seven residues, */ /* starting from the current residue: */ for (windowI = 0; windowI < 7; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI >= residuesN) break; /* Residue associated with the combined index: */ curr_residueSP = curr_mol_complexSP->residueSP + combinedI; /* Pointer to the first atom of current residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Pointer to the name of the current residue: */ nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Check is this residue negative or zwitterionic: */ if ((strcmp (nameP, "ASP") == 0) || (strcmp (nameP, "GLU") == 0) || (strcmp (nameP, "ASN") == 0) || (strcmp (nameP, "GLN") == 0)) negative_zwitterN++; } /* If there were five or more negative and zwitterionic */ /* residues in a window of seven residues, the quintet is */ /* found. If there were four or less, take the next res. */ if (negative_zwitterN < 5) continue; /* If this point is reached, rescan the window of seven */ /* residues and select negative and zwitterionic residues. */ /* Scan the window of seven residues, */ /* starting from the current residue: */ for (windowI = 0; windowI < 7; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI >= residuesN) break; /* Residue associated with the combined index: */ curr_residueSP = curr_mol_complexSP->residueSP + combinedI; /* Pointer to the first atom of current residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Pointer to the name of the current residue: */ nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Check is this residue negative or zwitterionic: */ if ((strcmp (nameP, "ASP") != 0) && (strcmp (nameP, "GLU") != 0) && (strcmp (nameP, "ASN") != 0) && (strcmp (nameP, "GLN") != 0)) continue; /* If this point is reached, select */ /* all atoms of the current residue. */ /* The indices of the first and the */ /* last atom of the current residue: */ first_atomI = curr_residueSP->residue_startI; last_atomI = curr_residueSP->residue_endI; /* Select all atoms of the current residue: */ for (atomI = first_atomI; atomI <= last_atomI; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Select the current atom: */ curr_atomSP->selectedF = 1; /* Update the counter of selected atoms: */ selected_atomsN++; } } /* End of residueI loop: */ } /* Combine the current selection with the */ /* previous, if selection mode is restrict: */ if (selection_modeI == 1) { /* Reset the counter of selected atoms. The */ /* selected atoms should be counted again. */ selected_atomsN = 0; /* Combine the old and the new selection flag: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Combine selection flags: */ curr_atomSP->selectedF *= curr_atomSP->previous_selectedF; /* Check the selection flag; increase */ /* the count of selected residues if */ /* the selection flag is equal to one: */ if (curr_atomSP->selectedF) selected_atomsN++; } } /* Update the position_changedF (some atoms may have bad color): */ curr_mol_complexSP->position_changedF = 1; /* End of mol_complexI loop: */ } /* Return the number of selected atoms: */ return selected_atomsN; } /*===========================================================================*/ garlic-1.6/select_5nz9.c0000644000076500007650000001521710401324703015417 0ustar zuciczucic00000000000000/* Copyright (C) 2006 Damir Zucic */ /*============================================================================= select_5nz9.c Purpose: Select the sequence fragment which contains five or more negative or zwitterionic residues in a window of nine residues. ASP, GLU, ASN and GLN are taken into account. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. (3) Selection mode index (0 = overwrite, 1 = restrict, 2 = expand previous selection). Output: (1) The flag selectedF set to one for selected atoms in every caught macromolecular complex. (2) Return value. Return value: (1) The number of selected atoms (zero or positive value). ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======select five or more negative or zwitterionic residues:===============*/ long Select5NZ9_ (MolComplexS *mol_complexSP, int mol_complexesN, int selection_modeI) { long selected_atomsN = 0; int mol_complexI; MolComplexS *curr_mol_complexSP; int atomsN, atomI; AtomS *curr_atomSP; int residuesN, residueI, windowI, combinedI; ResidueS *curr_residueSP; AtomS *first_atomSP; char *nameP; int negative_zwitterN; int first_atomI, last_atomI; /* Check every macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check is the current macromolecular complex caught: */ if (curr_mol_complexSP->catchF == 0) continue; /* Prepare and check the number of atoms in the current complex: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Copy the number of residues in the current macromol. complex: */ residuesN = curr_mol_complexSP->residuesN; if (residuesN == 0) continue; /* Backup the current selection if selection mode is restrict: */ if (selection_modeI == 1) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Copy the selection flag: */ curr_atomSP->previous_selectedF = curr_atomSP->selectedF; } } /* Unselect everything if selection mode is overwrite or restrict: */ if ((selection_modeI == 0) || (selection_modeI == 1)) { for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Unselect the current atom: */ curr_atomSP->selectedF = 0; } } /* Scan the residues of the current macromolecular complex: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Reset the number of negative and zwitterionic residues: */ negative_zwitterN = 0; /* Scan the window of nine residues, */ /* starting from the current residue: */ for (windowI = 0; windowI < 9; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI >= residuesN) break; /* Residue associated with the combined index: */ curr_residueSP = curr_mol_complexSP->residueSP + combinedI; /* Pointer to the first atom of current residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Pointer to the name of the current residue: */ nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Check is this residue negative or zwitterionic: */ if ((strcmp (nameP, "ASP") == 0) || (strcmp (nameP, "GLU") == 0) || (strcmp (nameP, "ASN") == 0) || (strcmp (nameP, "GLN") == 0)) negative_zwitterN++; } /* If there were five or more negative and zwitterionic */ /* residues in a window of nine residues, the quintet is */ /* found. If there were four or less, take the next res. */ if (negative_zwitterN < 5) continue; /* If this point is reached, rescan the window of nine */ /* residues and select negative and zwitterionic residues. */ /* Scan the window of nine residues, */ /* starting from the current residue: */ for (windowI = 0; windowI < 9; windowI++) { /* Prepare and check the combined index: */ combinedI = residueI + windowI; if (combinedI >= residuesN) break; /* Residue associated with the combined index: */ curr_residueSP = curr_mol_complexSP->residueSP + combinedI; /* Pointer to the first atom of current residue: */ first_atomSP = curr_mol_complexSP->atomSP + curr_residueSP->residue_startI; /* Pointer to the name of the current residue: */ nameP = first_atomSP->raw_atomS.pure_residue_nameA; /* Check is this residue negative or zwitterionic: */ if ((strcmp (nameP, "ASP") != 0) && (strcmp (nameP, "GLU") != 0) && (strcmp (nameP, "ASN") != 0) && (strcmp (nameP, "GLN") != 0)) continue; /* If this point is reached, select */ /* all atoms of the current residue. */ /* The indices of the first and the */ /* last atom of the current residue: */ first_atomI = curr_residueSP->residue_startI; last_atomI = curr_residueSP->residue_endI; /* Select all atoms of the current residue: */ for (atomI = first_atomI; atomI <= last_atomI; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Select the current atom: */ curr_atomSP->selectedF = 1; /* Update the counter of selected atoms: */ selected_atomsN++; } } /* End of residueI loop: */ } /* Combine the current selection with the */ /* previous, if selection mode is restrict: */ if (selection_modeI == 1) { /* Reset the counter of selected atoms. The */ /* selected atoms should be counted again. */ selected_atomsN = 0; /* Combine the old and the new selection flag: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Combine selection flags: */ curr_atomSP->selectedF *= curr_atomSP->previous_selectedF; /* Check the selection flag; increase */ /* the count of selected residues if */ /* the selection flag is equal to one: */ if (curr_atomSP->selectedF) selected_atomsN++; } } /* Update the position_changedF (some atoms may have bad color): */ curr_mol_complexSP->position_changedF = 1; /* End of mol_complexI loop: */ } /* Return the number of selected atoms: */ return selected_atomsN; } /*===========================================================================*/ garlic-1.6/project_membranes.c0000644000076500007650000003155107377433775017005 0ustar zuciczucic00000000000000/* Copyright (C) 2001 Damir Zucic */ /*============================================================================= project_membranes.c Purpose: For each macromolecular complex, project membrane to the screen. The membrane is represented by two circles in space. Each circle is represented by an ellipse on the screen. This function will project each membrane always, even if it is not visible on the screen. The parameters prepared in this function are stored in two PlaneS structures, which are members of MembraneS structure. Some other parameters will be prepared in the function which draw the membrane to the screen. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) The number of macromolecular complexes. (3) Pointer to ConfigS structure, with configuration data. Output: (1) Parameters which define the membrane projection (i.e., the projections of two constituent planes) to the screen will be calculated for each macromolecular complex containing at least one atom. Return value: No return value. Notes: (1) If definedF is zero for a given membrane, the position and orientation of that membrane are not defined properly. ========includes:============================================================*/ #include #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======project membranes:===================================================*/ void ProjectMembranes_ (MolComplexS *mol_complexSP, int mol_complexesN, ConfigS *configSP) { int imagesN, imageI; double nominator_x, nominator_y, user_atomic_position; int center_screen_x[2], center_screen_y; double cos_stereo_angle, sin_stereo_angle; int mol_complexI; MolComplexS *curr_mol_complexSP; MembraneS *membraneSP; double half_thickness; PlaneS *plane1SP, *plane2SP; double x0, z0, x, z, x_new, z_new; double denominator, reciprocal_denominator; double normal_x, normal_y, normal_z; double rationalized_x, rationalized_y; double scalar_product, abs_value_squared, abs_value; double cos_theta, cos_phi, angle; double value1, value2; /* The number of images (1 for mono, 2 for stereo): */ if (configSP->stereoF == 1) imagesN = 2; else imagesN = 1; /* Prepare the factors which are used to */ /* reduce the number of multiplications: */ nominator_x = configSP->user_screen_atomic_distance * configSP->atomic_to_screen_scale_x; nominator_y = configSP->user_screen_atomic_distance * configSP->atomic_to_screen_scale_y; /* Prepare the user position in atomic coordinates: */ user_atomic_position = configSP->user_atomic_position; /* Position of the window free area center (stereo data): */ center_screen_x[0] = configSP->center_screen_x[0]; center_screen_x[1] = configSP->center_screen_x[1]; center_screen_y = configSP->center_screen_y; /* Calculate cosine and sine of the stereo angle: */ cos_stereo_angle = cos (configSP->stereo_angle); sin_stereo_angle = sin (configSP->stereo_angle); /* Project the membrane (two planes) for each macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* If this complex contains no atoms, ignore it: */ if (curr_mol_complexSP->atomsN == 0) continue; /* If the membrane associated with the current */ /* complex is not defined, skip this complex: */ if (curr_mol_complexSP->membraneS.definedF == 0) continue; /* Prepare the pointer to the membrane: */ membraneSP = &curr_mol_complexSP->membraneS; /* Half of the membrane thickness: */ half_thickness = membraneSP->thickness / 2.0; /*------refresh the members of the first PlaneS structure:-----------*/ /* Prepare the pointer to the first plane: */ plane1SP = &membraneSP->plane1S; /* The center of the first plane: */ plane1SP->center_x[0] = membraneSP->center_x + half_thickness * plane1SP->normal_x[0]; plane1SP->center_y = membraneSP->center_y + half_thickness * plane1SP->normal_y; plane1SP->center_z[0] = membraneSP->center_z + half_thickness * plane1SP->normal_z[0]; /* The stereo data associated with the center of the first plane: */ x0 = curr_mol_complexSP->geometric_center_vectorS.x; z0 = curr_mol_complexSP->geometric_center_vectorS.z; x = plane1SP->center_x[0] - x0; z = plane1SP->center_z[0] - z0; x_new = x * cos_stereo_angle + z * sin_stereo_angle; z_new = -x * sin_stereo_angle + z * cos_stereo_angle; plane1SP->center_x[1] = x_new + x0; plane1SP->center_z[1] = z_new + z0; /*------refresh the members of the second PlaneS structure:----------*/ /* Prepare the pointer to the second plane: */ plane2SP = &membraneSP->plane2S; /* The center of the second plane: */ plane2SP->center_x[0] = membraneSP->center_x + half_thickness * plane2SP->normal_x[0]; plane2SP->center_y = membraneSP->center_y + half_thickness * plane2SP->normal_y; plane2SP->center_z[0] = membraneSP->center_z + half_thickness * plane2SP->normal_z[0]; /* The stereo data associated with the center of the second plane: */ x0 = curr_mol_complexSP->geometric_center_vectorS.x; z0 = curr_mol_complexSP->geometric_center_vectorS.z; x = plane2SP->center_x[0] - x0; z = plane2SP->center_z[0] - z0; x_new = x * cos_stereo_angle + z * sin_stereo_angle; z_new = -x * sin_stereo_angle + z * cos_stereo_angle; plane2SP->center_x[1] = x_new + x0; plane2SP->center_z[1] = z_new + z0; /*------project the first plane:-------------------------------------*/ /* Project the first plane: */ /* Stereo data should be prepared: */ for (imageI = 0; imageI < imagesN; imageI++) { /*------prepare auxilliary parameters:-----------------------*/ denominator = plane1SP->center_z[imageI] - user_atomic_position; if (denominator == 0.0) reciprocal_denominator = 0.0; else reciprocal_denominator = 1.0 / denominator; normal_x = plane1SP->normal_x[imageI]; normal_y = plane1SP->normal_y; normal_z = plane1SP->normal_z[imageI]; /*------project plane center to the screen:------------------*/ /* Prepare rationalized coordinates: */ rationalized_x = plane1SP->center_x[imageI] * nominator_x * reciprocal_denominator; rationalized_y = plane1SP->center_y * nominator_y * reciprocal_denominator; /* Keep them in a reasonable range: */ if (rationalized_x > (double) INT_MAX / 4) rationalized_x = (double) INT_MAX / 4; else if (rationalized_x < (double) INT_MIN / 4) rationalized_x = (double) INT_MIN / 4; if (rationalized_y > (double) INT_MAX / 4) rationalized_y = (double) INT_MAX / 4; else if (rationalized_y < (double) INT_MIN / 4) rationalized_y = (double) INT_MIN / 4; /* Prepare screen coordinates of the plane center: */ plane1SP->center_screen_x[imageI] = (int) rationalized_x + center_screen_x[imageI]; plane1SP->center_screen_y = (int) rationalized_y + center_screen_y; /*------angle between normal vector and z axis:--------------*/ scalar_product = normal_z; abs_value_squared = normal_x * normal_x + normal_y * normal_y + normal_z * normal_z; abs_value = sqrt (abs_value_squared); if (abs_value == 0.0) { cos_theta = 0.0; plane1SP->normal_theta[imageI] = 1.5707963; } else { cos_theta = scalar_product / abs_value; if (cos_theta <= -1.0) angle = 3.1415927; else if (cos_theta >= 1.0) angle = 0.0; else angle = acos (cos_theta); plane1SP->normal_theta[imageI] = angle; } /*------visible side index (0 = top, 1 = bottom):------------*/ if (cos_theta <= 0.0) plane1SP->visible_sideI[imageI] = 0; else plane1SP->visible_sideI[imageI] = 1; /*------angle between x and project. of n. v. to xy plane:---*/ /* Prepare and check the cosine of normal_phi: */ abs_value = sqrt (normal_x * normal_x + normal_y * normal_y); cos_phi = normal_x / abs_value; if (cos_phi > 1.0) cos_phi = 1.0; if (cos_phi < -1.0) cos_phi = -1.0; /* The special case (undefined phi): */ if ((normal_x == 0.0) && (normal_y == 0.0)) { plane1SP->normal_phi[imageI] = 0.0; } /* If y component of the normal vector is positive: */ else if (normal_y >= 0.0) { if (cos_phi <= -1.0) angle = 3.1415927; else if (cos_phi >= 1.0) angle = 0.0; else angle = acos (cos_phi); plane1SP->normal_phi[imageI] = angle; } /* If y component of the normal vector is negative: */ else { if (cos_phi <= -1.0) angle = 3.1415927; else if (cos_phi >= 1.0) angle = 0.0; else angle = acos (cos_phi); plane1SP->normal_phi[imageI] = 6.2831853 - angle; } /*------large half axis of the ellipse in screen units:------*/ value1 = plane1SP->circle_radius * nominator_x * reciprocal_denominator; value2 = plane1SP->circle_radius * nominator_y * reciprocal_denominator; if (value1 > value2) plane1SP->screen_a = value1; else plane1SP->screen_a = value2; /*------small half axis of the ellipse (stereo data):--------*/ plane1SP->screen_b[imageI] = plane1SP->screen_a * fabs (cos_theta); /* The minimal value should be one: */ if (plane1SP->screen_b[imageI] < 1.0) plane1SP->screen_b[imageI] = 1.0; } /*------project the second plane:------------------------------------*/ /* Stereo data should be prepared: */ for (imageI = 0; imageI < imagesN; imageI++) { /*------prepare auxilliary parameters:-----------------------*/ denominator = plane2SP->center_z[imageI] - user_atomic_position; if (denominator == 0.0) reciprocal_denominator = 0.0; else reciprocal_denominator = 1.0 / denominator; normal_x = plane2SP->normal_x[imageI]; normal_y = plane2SP->normal_y; normal_z = plane2SP->normal_z[imageI]; /*------project plane center to the screen:------------------*/ /* Prepare rationalized coordinates: */ rationalized_x = plane2SP->center_x[imageI] * nominator_x * reciprocal_denominator; rationalized_y = plane2SP->center_y * nominator_y * reciprocal_denominator; /* Keep them in a reasonable range: */ if (rationalized_x > (double) INT_MAX / 4) rationalized_x = (double) INT_MAX / 4; else if (rationalized_x < (double) INT_MIN / 4) rationalized_x = (double) INT_MIN / 4; if (rationalized_y > (double) INT_MAX / 4) rationalized_y = (double) INT_MAX / 4; else if (rationalized_y < (double) INT_MIN / 4) rationalized_y = (double) INT_MIN / 4; /* Prepare screen coordinates of the plane center: */ plane2SP->center_screen_x[imageI] = (int) rationalized_x + center_screen_x[imageI]; plane2SP->center_screen_y = (int) rationalized_y + center_screen_y; /*------angle between normal vector and z axis:--------------*/ scalar_product = normal_z; abs_value_squared = normal_x * normal_x + normal_y * normal_y + normal_z * normal_z; abs_value = sqrt (abs_value_squared); if (abs_value == 0.0) { cos_theta = 0.0; plane2SP->normal_theta[imageI] = 1.5707963; } else { cos_theta = scalar_product / abs_value; if (cos_theta <= -1.0) angle = 3.1415927; else if (cos_theta >= 1.0) angle = 0.0; else angle = acos (cos_theta); plane2SP->normal_theta[imageI] = angle; } /*------visible side index (0 = top, 1 = bottom):------------*/ if (cos_theta <= 0.0) plane2SP->visible_sideI[imageI] = 0; else plane2SP->visible_sideI[imageI] = 1; /*------angle between x and project. of n. v. to xy plane:---*/ /* Prepare and check the cosine of normal_phi: */ abs_value = sqrt (normal_x * normal_x + normal_y * normal_y); cos_phi = normal_x / abs_value; if (cos_phi > 1.0) cos_phi = 1.0; if (cos_phi < -1.0) cos_phi = -1.0; /* The special case (undefined phi): */ if ((normal_x == 0.0) && (normal_y == 0.0)) { plane2SP->normal_phi[imageI] = 0.0; } /* If y component of the normal vector is positive: */ else if (normal_y >= 0.0) { if (cos_phi <= -1.0) angle = 3.1415927; else if (cos_phi >= 1.0) angle = 0.0; else angle = acos (cos_phi); plane2SP->normal_phi[imageI] = angle; } /* If y component of the normal vector is negative: */ else { if (cos_phi <= -1.0) angle = 3.1415927; else if (cos_phi >= 1.0) angle = 0.0; else angle = acos (cos_phi); plane2SP->normal_phi[imageI] = 6.2831853 - angle; } /*------large half axis of the ellipse in screen units:------*/ value1 = plane2SP->circle_radius * nominator_x * reciprocal_denominator; value2 = plane2SP->circle_radius * nominator_y * reciprocal_denominator; if (value1 > value2) plane2SP->screen_a = value1; else plane2SP->screen_a = value2; /*------small half axis of the ellipse (stereo data):--------*/ plane2SP->screen_b[imageI] = plane2SP->screen_a * fabs (cos_theta); /* The minimal value should be one: */ if (plane2SP->screen_b[imageI] < 1.0) plane2SP->screen_b[imageI] = 1.0; } } } /*===========================================================================*/ garlic-1.6/reset_phi.c0000644000076500007650000000661407311734423015250 0ustar zuciczucic00000000000000/* Copyright (C) 2001 Damir Zucic */ /*============================================================================= reset_phi.c Purpose: Reset the phi angle in each residue. Each phi angle will be changed to -180 degrees. The chain will be messed up! Please note that if you modify default angle you will also have to modify the function ApplyStructure_ (), because in that function it is assumed that you are using -180 degrees here. Input: (1) Pointer to MolComplexS structure, with macromolecular data. Output: (1) Phi angle changed to -180 degrees (in each residue). (2) Return value. Return value: (1) Positive on success. (2) Negative on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int ExtractHNCAC_ (VectorS *, VectorS *, VectorS *, VectorS *, AtomS *, size_t, size_t); double PhiFromHNCAC_ (VectorS *, VectorS *, VectorS *, VectorS *); int RotateAtom_ (AtomS *, VectorS *, VectorS *, double); /*======change phi angle to -180 degrees; do it for each residue:============*/ int ResetPhi_ (MolComplexS *mol_complexSP) { int residuesN; int residueI; ResidueS *curr_residueSP; size_t atom_startI, atom_endI, atomI; AtomS *atomSP; char *curr_residue_nameP; int n; static VectorS H_vectorS, N_vectorS, CA_vectorS, C_vectorS; double phi, delta_phi; /* Prepare the number of residues: */ residuesN = mol_complexSP->residuesN; /* Scan the macromolecular complex: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Pointer to the current residue: */ curr_residueSP = mol_complexSP->residueSP + residueI; /* Prepare the atomic index range: */ atom_startI = curr_residueSP->residue_startI; atom_endI = curr_residueSP->residue_endI; /* Skip proline: */ atomSP = mol_complexSP->atomSP + atom_startI; curr_residue_nameP = atomSP->raw_atomS.pure_residue_nameA; if (strcmp (curr_residue_nameP, "PRO") == 0) continue; /* Extract H, N, CA and C coordinates: */ n = ExtractHNCAC_ (&H_vectorS, &N_vectorS, &CA_vectorS, &C_vectorS, mol_complexSP->atomSP, atom_startI, atom_endI); /* All four atoms are required to reset the phi angle: */ if (n < 4) continue; /* If this point is reached, the coordinates */ /* of required four atoms were retrieved. */ /* Calculate the phi angle (radians), using the H atom coordinates: */ phi = PhiFromHNCAC_ (&H_vectorS, &N_vectorS, &CA_vectorS, &C_vectorS); /* Prepare the rotation angle: */ delta_phi = -3.1415927 - phi; /* Now rotate all atoms except H, N and CA about the N-CA bond: */ for (atomI = atom_startI; atomI <= atom_endI; atomI++) { /* Pointer to the current atom: */ atomSP = mol_complexSP->atomSP + atomI; /* Skip H, N and CA: */ if ((strcmp (atomSP->raw_atomS.pure_atom_nameA, "H") == 0) || (strcmp (atomSP->raw_atomS.pure_atom_nameA, "N") == 0) || (strcmp (atomSP->raw_atomS.pure_atom_nameA, "CA") == 0)) { continue; } /* Rotate the current atom about the N-CA bond: */ RotateAtom_ (atomSP, &N_vectorS, &CA_vectorS, delta_phi); } } /* Return positive value on success: */ return 1; } /*===========================================================================*/ garlic-1.6/reset_psi.c0000644000076500007650000000575307315156447015276 0ustar zuciczucic00000000000000/* Copyright (C) 2001 Damir Zucic */ /*============================================================================= reset_psi.c Purpose: Reset the psi angle in each residue. Each psi angle will be changed to +180 degrees. The chain will be messed up! Please note that if you modify default angle you will also have to modify the function ApplyStructure_ (), because it assumes that you are using +180 degrees here. Input: (1) Pointer to MolComplexS structure, with macromolecular data. Output: (1) Psi angle changed to -180 degrees (in each residue). (2) Return value. Return value: (1) Positive on success. (2) Negative on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int ExtractNCACO_ (VectorS *, VectorS *, VectorS *, VectorS *, AtomS *, size_t, size_t); double PsiFromNCACO_ (VectorS *, VectorS *, VectorS *, VectorS *); int RotateAtom_ (AtomS *, VectorS *, VectorS *, double); /*======change psi angle to +180 degrees; do it for each residue:============*/ int ResetPsi_ (MolComplexS *mol_complexSP) { int residuesN; int residueI; ResidueS *curr_residueSP; size_t atom_startI, atom_endI, atomI; AtomS *atomSP; int n; static VectorS N_vectorS, CA_vectorS, C_vectorS, O_vectorS; double psi, delta_psi; /* Prepare the number of residues: */ residuesN = mol_complexSP->residuesN; /* Scan the macromolecular complex: */ for (residueI = 0; residueI < residuesN; residueI++) { /* Pointer to the current residue: */ curr_residueSP = mol_complexSP->residueSP + residueI; /* Prepare the atomic index range: */ atom_startI = curr_residueSP->residue_startI; atom_endI = curr_residueSP->residue_endI; /* Extract N, CA, C and O coordinates: */ n = ExtractNCACO_ (&N_vectorS, &CA_vectorS, &C_vectorS, &O_vectorS, mol_complexSP->atomSP, atom_startI, atom_endI); /* All four atoms are required to reset the psi angle: */ if (n < 4) continue; /* If this point is reached, the coordinates */ /* for all four required atoms were retrieved. */ /* Calculate the psi angle (radians): */ psi = PsiFromNCACO_ (&N_vectorS, &CA_vectorS, &C_vectorS, &O_vectorS); /* Prepare the rotation angle: */ delta_psi = 3.1415927 - psi; /* Now rotate the O atom about the CA-C bond: */ for (atomI = atom_startI; atomI <= atom_endI; atomI++) { /* Pointer to the current atom: */ atomSP = mol_complexSP->atomSP + atomI; /* Check is it the O atom: */ if (strcmp (atomSP->raw_atomS.pure_atom_nameA, "O") != 0) { continue; } /* Rotate the O atom about CA-C bond: */ RotateAtom_ (atomSP, &CA_vectorS, &C_vectorS, delta_psi); } } /* Return positive value on success: */ return 1; } /*===========================================================================*/ garlic-1.6/chain.c0000644000076500007650000000612207072062702014340 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= chain.c Purpose: Chain color scheme: assign different colors to different chains. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) Number of macromolecular complexes. (3) Pointer to GUIS structure, with GUI data. (4) Pointer to ColorSchemeS structure. Output: (1) Return value. Return value: (1) Positive always. =============================================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======chain color scheme:==================================================*/ int Chain_ (MolComplexS *mol_complexSP, int mol_complexesN, GUIS *guiSP, ColorSchemeS *color_schemeSP) { int mol_complexI; MolComplexS *curr_mol_complexSP; size_t atomsN, atomI; AtomS *curr_atomSP; size_t rgb_struct_size; ColorSchemeS *schemeSP; int surfaceI; char old_chainID = '!'; int color_schemeI = -1; /* The size of RGBS structure: */ rgb_struct_size = sizeof (RGBS); /* Initialize the pointer to color scheme: */ schemeSP = color_schemeSP; /* Scan every macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to the current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Check is the current macromolecular complex caught: */ if (curr_mol_complexSP->catchF == 0) continue; /* Number of atoms in a macromolecular complex: */ atomsN = curr_mol_complexSP->atomsN; /* Scan all atoms in the current complex: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Check is atom selected: */ if (curr_atomSP->selectedF == 0) continue; /* Set the number of color surfaces: */ curr_atomSP->surfacesN = 2; /* Check the chain identifier: */ if (curr_atomSP->raw_atomS.chainID != old_chainID) { /* Store the chain ID: */ old_chainID = curr_atomSP->raw_atomS.chainID; /* Change color: */ color_schemeI++; /* Thirteen color schemes are used for chains: */ if (color_schemeI >= 13) color_schemeI = 0; /* Prepare the color scheme pointer: */ schemeSP = color_schemeSP + color_schemeI; } /* Copy the color specifications: */ for (surfaceI = 0; surfaceI < 2; surfaceI++) { /* Left color: */ memcpy (curr_atomSP->left_rgbSA + surfaceI, schemeSP->left_rgbSA + surfaceI, rgb_struct_size); /* Middle color: */ memcpy (curr_atomSP->middle_rgbSA + surfaceI, schemeSP->middle_rgbSA + surfaceI, rgb_struct_size); /* Right color: */ memcpy (curr_atomSP->right_rgbSA + surfaceI, schemeSP->right_rgbSA + surfaceI, rgb_struct_size); } } /* Reset the position_changedF: */ curr_mol_complexSP->position_changedF = 1; } /* Return positive value: */ return 1; } /*===========================================================================*/ garlic-1.6/make_pixmap.c0000644000076500007650000001135310157110133015541 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2004 Damir Zucic */ /*============================================================================= make_pixmap.c Purpose: Make pixmap from an array of strings. Array is obtained from the file which is included in calling function; MakePixmap_ receives pointer to char pointer. Xpm library is not used here. Xpm is quite good, but raw Xlib was chosen to make the whole garlic package as portable as possible. Though many systems have Xpm library, there are still some which don't. Pixmap should be hard-coded (included) in calling function. Input: (1) Pointer to WindowS structure, where some output data will be stored. (2) Pointer to GUIS structure. (3) Pointer to char pointer, with pixmap data. There are no special checks: if pixmap file is bad, core dump may be expected. Check each pixmap with a program like cxpm. Up to 256 color allowed. pixmap data. It has file scope. This file is not checked; if it is bad, core dump may be expected. If icon pixmap is changed it may be checked with cxpm program. Up to 256 colors allowed. Output: (1) Pixmap created. (2) Pixmap dimensions, number of colors and pixmap ID added to WindowDataS structure. Note that pixmap width and height are treated as window dimensions! Thus, window dimensions are set too in this function. (3) Pixmap flag set. (4) Return value. Return value: (1) Positive on success. (2) Negative on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ void ErrorMessage_ (char *, char *, char *, char *, char *, char *, char *); void RGBSFromXColor_ (RGBS *, XColor *); unsigned long PixelFromRGBS_ (RGBS *, GUIS *); /*======make pixmap from an array of strings, version 1:=====================*/ int MakePixmap_ (WindowS *winSP, GUIS *guiSP, char **dataPP) { unsigned int width, height, colorsN; Status status; XColor colorS; RGBS rgbS; unsigned long black_colorID; Pixmap pixmapID; int i, j; char line_copyA[STRINGSIZE]; int n; char *P, *P1; unsigned long pixel; unsigned long colorIDA[256]; int offset; /* Extract pixmap dimensions and number of colors: */ if (sscanf (*dataPP, "%u %u %u", &width, &height, &colorsN) != 3) { ErrorMessage_ ("garlic", "MakePixmap_", "", "Failed to extract data from pixmap header!\n", "", "", ""); return -1; } /* Check the number of colors: */ if (colorsN > 256) { ErrorMessage_ ("garlic", "MakePixmap_", "", "Number of colors in pixmap limited to 256!\n", "", "", ""); return -2; } /* Copy values: */ winSP->width = width; winSP->height = height; winSP->colorsN = colorsN; /* Prepare the black color (replacement for unrecognized colors): */ status = XParseColor (guiSP->displaySP, guiSP->colormapID, "black", &colorS); if (status) { RGBSFromXColor_ (&rgbS, &colorS); black_colorID = PixelFromRGBS_ (&rgbS, guiSP); } else { ErrorMessage_ ("garlic", "MakePixmap_", "", "Unable to parse black color!\n", "", "", ""); return -3; } /* Create pixmap: */ pixmapID = XCreatePixmap (guiSP->displaySP, DefaultRootWindow (guiSP->displaySP), width, height, guiSP->depth); winSP->pixmapID = pixmapID; winSP->pixmapF = 1; /* Parse colors: */ /* (Note: be sure that pixmap is good, no check is done here!) */ for (i = 1; i < (int) colorsN + 1; i++) { /** Copy the i-th line: **/ strncpy (line_copyA, *(dataPP + i), STRINGSIZE - 1); line_copyA[STRINGSIZE - 1] = '\0'; /** The first token is the color array index: **/ n = line_copyA[0]; /** Skip the first character and take one token; **/ /** it should be letter 'c' or 's' - ignore it: **/ P1 = line_copyA + 1; P = strtok (P1, " \t"); /** The next token is color specification; **/ P = strtok (NULL, " \t\""); /** This token is expected to specify some color; parse it: **/ status = XParseColor (guiSP->displaySP, guiSP->colormapID, P, &colorS); if (status) { RGBSFromXColor_ (&rgbS, &colorS); pixel = PixelFromRGBS_ (&rgbS, guiSP); } else pixel = black_colorID; colorIDA[n] = pixel; } /* Parse pixels and draw pixmap using default graphics context: */ offset = winSP->colorsN + 1; for (j = 0; j < (int) height; j++) { offset = j + colorsN + 1; for (i = 0; i < (int) width; i++) { P = *(dataPP + offset) + i; n = *P; XSetForeground (guiSP->displaySP, guiSP->theGCA[0], colorIDA[n]); XDrawPoint (guiSP->displaySP, pixmapID, guiSP->theGCA[0], i, j); } } return 1; } /*===========================================================================*/ garlic-1.6/openfile_r.c0000644000076500007650000001430207111177372015403 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= openfile_r.c Purpose: Try to open file for reading. First try with the specified file (path)name. If this doesn't work, check the content of the environment variable MOL_DIR. If this environment variable is defined, append the file name to the content of MOL_DIR and try again. If this attempt fails, check the content of MOL_PATH environment variable. If MOL_PATH is defined, parse the content to obtain the list of directories. Try with each of these directories if necessary. If all attempts fail, return NULL. Directories in MOL_PATH should be separated by space or colon. This function is capable to interpret tilde [~] and $HOME. Input: (1) Input file name (pointer to string). (2) The content of environment variable MOL_DIR may be used. (3) The content of environment variable MOL_PATH may be used. Output: Return value. Return value: (1) File pointer, on success. (2) NULL on failure. Notes: (1) No error messages. ========includes:============================================================*/ #include #include #include #include "defines.h" /*======try to open file:====================================================*/ FILE *OpenFileForReading_ (char *file_nameP) { static FILE *fileP; static char *env_valueP; char *currentP; char *tokenP; char copyA[STRINGSIZE]; char path_nameA[STRINGSIZE]; int n, i; /* If input file name contains the string $HOME: */ if (strstr (file_nameP, "$HOME") == file_nameP) { /* Get the value of environment variable HOME: */ if ((env_valueP = getenv ("HOME")) == NULL) return NULL; /* Copy this value: */ strncpy (path_nameA, env_valueP, STRINGSIZE - 1); path_nameA[STRINGSIZE - 1] = '\0'; /* The last character should be slash: */ n = (int) strlen (path_nameA) - 1; if (path_nameA[n] != '/') strcat (path_nameA, "/"); /* Concatenate the file name (without $HOME): */ n = STRINGSIZE - (int) strlen (path_nameA) - 1; strncat (path_nameA, file_nameP + 5, n); path_nameA[STRINGSIZE - 1] = '\0'; /* Try to open file: */ fileP = fopen (path_nameA, "r"); return fileP; } /* If input file name contains tilde [~]: */ else if (*file_nameP == '~') { /* Tilde alone defines no file: */ if (strlen (file_nameP) == 1) return NULL; /* If the second character is slash [/]: */ if (*(file_nameP + 1) == '/') { /* Get the value of environment variable HOME: */ if ((env_valueP = getenv ("HOME")) == NULL) return NULL; /* Copy this value: */ strncpy (path_nameA, env_valueP, STRINGSIZE - 1); path_nameA[STRINGSIZE - 1] = '\0'; /* The last character should be slash: */ n = (int) strlen (path_nameA) - 1; if (path_nameA[n] != '/') strcat (path_nameA, "/"); /* Concatenate the file name (without tilde): */ n = STRINGSIZE - (int) strlen (path_nameA) - 1; strncat (path_nameA, file_nameP + 1, n); path_nameA[STRINGSIZE - 1] = '\0'; /* Try to open file: */ fileP = fopen (path_nameA, "r"); return fileP; } /* If the second character is not slash, remove user name */ /* from $HOME and replace tilde with the resulting string: */ else { /* Get the value of environment variable HOME: */ if ((env_valueP = getenv ("HOME")) == NULL) return NULL; /* Copy this string, but reverted: */ n = strlen (env_valueP); if (n == 0) return NULL; for (i = 0; i < n; i++) { path_nameA[i] = *(env_valueP + n - 1 - i); } path_nameA[n] = '\0'; /* Replace all characters left from the first slash with \0: */ for (i = 0; i < n; i++) { if (path_nameA[i] == '/') break; else path_nameA[i] = '\0'; } /* Revert the string again: */ for (i = 0; i < n; i++) { copyA[i] = path_nameA[n - 1 - i]; } copyA[n] = '\0'; strncpy (path_nameA, copyA, n); /* Concatenate the file name (without tilde): */ n = STRINGSIZE - (int) strlen (path_nameA) - 1; strncat (path_nameA, file_nameP + 1, n); path_nameA[STRINGSIZE - 1] = '\0'; /* Try to open file: */ fileP = fopen (path_nameA, "r"); return fileP; } } /* If this point is reached, the input file name */ /* contains neither $HOME nor tilde. Try with the */ /* original file name and two environment variables. */ /* The first attempt to open file: */ if ((fileP = fopen (file_nameP, "r")) != NULL) return fileP; /* Prepare the file name pointer. If the first character is slash, skip it! */ if (*file_nameP == '/') file_nameP++; /* The second attempt (with MOL_DIR environment variable): */ if ((env_valueP = getenv ("MOL_DIR")) != NULL) { /* Copy the value of the MOL_DIR environment variable: */ strncpy (path_nameA, env_valueP, STRINGSIZE - 1); path_nameA[STRINGSIZE - 1] = '\0'; /* The last character should be slash: */ n = (int) strlen (path_nameA) - 1; if (path_nameA[n] != '/') strcat (path_nameA, "/"); /* Concatename the file name to directory name: */ n = STRINGSIZE - (int) strlen (path_nameA) - 1; strncat (path_nameA, file_nameP, n); path_nameA[STRINGSIZE - 1] = '\0'; /* The second attempt to open file: */ if ((fileP = fopen (path_nameA, "r")) != NULL) return fileP; } /* The third attempt (with MOL_PATH environment variable): */ if ((env_valueP = getenv ("MOL_PATH")) != NULL) { /* Copy the value of the MOL_PATH environment variable: */ strncpy (copyA, env_valueP, STRINGSIZE - 1); copyA[STRINGSIZE - 1] = '\0'; /* Try token by token: */ currentP = copyA; while ((tokenP = strtok (currentP, " :\n")) != NULL) { /* Prepare the argument for the next call of strtok: */ currentP = NULL; /* Copy the token: */ strncpy (path_nameA, tokenP, STRINGSIZE - 1); path_nameA[STRINGSIZE - 1] = '\0'; /* The last character should be slash (/): */ n = (int) strlen (path_nameA) - 1; if (path_nameA[n] != '/') strcat (path_nameA, "/"); /* Concatename the file name to directory name: */ n = STRINGSIZE - (int) strlen (path_nameA) - 1; strncat (path_nameA, file_nameP, n); path_nameA[STRINGSIZE - 1] = '\0'; /* Try to open file: */ if ((fileP = fopen (path_nameA, "r")) != NULL) return fileP; } } /* If this point is reached, all attempts failed; return NULL: */ return NULL; } /*===========================================================================*/ garlic-1.6/no_fading.c0000644000076500007650000000441307065474077015221 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= no_fading.c Purpose: Prepare the left, middle and right color for each atom in a complex. No fading in this function - near atom colors are used. White is used as a replacement color if color allocation fails. Input: (1) Pointer to MolComplexS structure. (2) Pointer to GUIS structure. Output: (1) left_colorID, middle_colorID and right_colorID members of AtomS structure initialized for each atom in macromolecular complex. (2) Return value. Return value: Zero always (trivial). Notes: (1) Do not skip hidden atoms, the color of these atoms may be used for backbone drawing! =============================================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ unsigned long PixelFromRGBS_ (RGBS *, GUIS *); /*======fading not used:=====================================================*/ size_t NoFading_ (MolComplexS *curr_mol_complexSP, GUIS *guiSP) { size_t atoms_between_surfacesN = 0; size_t atomsN, atomI; XColor colorS; AtomS *curr_atomSP; /* Prepare and check the number of atoms in a complex: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) return 0; /* Set DoRed, DoGreen and DoBlue flags in colorS: */ colorS.flags = DoRed | DoGreen | DoBlue; /* Assign the same set of three color ID's to each atom: */ for (atomI = 0; atomI < atomsN; atomI++) { /** Prepare the current atom pointer: **/ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /** Is atom out of slab? **/ if (!curr_atomSP->inside_slabF) continue; /** Prepare color ID's (use near atom colors): **/ curr_atomSP->left_colorID = PixelFromRGBS_ (curr_atomSP->left_rgbSA, guiSP); curr_atomSP->middle_colorID = PixelFromRGBS_ (curr_atomSP->middle_rgbSA, guiSP); curr_atomSP->right_colorID = PixelFromRGBS_ (curr_atomSP->right_rgbSA, guiSP); } /* Return the total number of allocated colors: */ return atoms_between_surfacesN; } /*===========================================================================*/ garlic-1.6/planar_fading.c0000644000076500007650000001315507157203531016050 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= planar_fading.c Purpose: Prepare the left, middle and right color for each atom in a complex. The color fading is planar (linear) in this function. Two planes, perpendicular to z axis, define the area of color fading. All atoms closer to the observer than the front plane will have the near atom color. All atoms behind the back surface will have the far atom color. RGB values are calculated from basic colors for each atom in the area between two planes. XAllocColor is not used, because it may work to slow. Input: (1) Pointer to MolComplexS structure. (2) Pointer to GUIS structure. Output: (1) left_colorID, middle_colorID and right_colorID members of AtomS structure initialized for each atom in macromolecular complex. (2) Return value. Return value: (1) On success, the number of atoms which have colors different from near and far color. These atoms are located in the area between the front and back surface. (2) Zero on failure. Notes: (1) Do not skip hidden atoms, the color of these atoms may be used for backbone drawing! =============================================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ unsigned long PixelFromRGBS_ (RGBS *, GUIS *); unsigned long PrepareColor_ (RGBS *, RGBS *, double, GUIS *); /*======planar fading:=======================================================*/ size_t PlanarFading_ (MolComplexS *curr_mol_complexSP, GUIS *guiSP) { size_t atoms_between_surfacesN = 0; size_t atomsN, atomI; AtomS *curr_atomSP; int surfacesN, surfaceI, near_surfaceI, far_surfaceI; double z0, z1, z; double overall_range, internal_range; double inverse_internal_range; double delta_z, scale_factor; /* The number of atoms in a complex: */ atomsN = curr_mol_complexSP->atomsN; /* The z coordinate of the front surface (plane): */ z0 = curr_mol_complexSP->fading_front_relative_position + curr_mol_complexSP->fading_center_vectorS.z; /* The z coordinate of the back surface (plane): */ z1 = curr_mol_complexSP->fading_back_relative_position + curr_mol_complexSP->fading_center_vectorS.z; /* Check: */ if (z0 >= z1) return 0; /* The overall range: */ overall_range = z1 - z0; /* Assign three colors to each atom: */ for (atomI = 0; atomI < atomsN; atomI++) { /** Pointer to the current atom: **/ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /** Is atom out of slab? **/ if (!curr_atomSP->inside_slabF) continue; /** Check the number of color fading surfaces: **/ surfacesN = curr_atomSP->surfacesN; /*** If there is only one, there is no fading: ***/ if (surfacesN == 1) { curr_atomSP->left_colorID = PixelFromRGBS_ (curr_atomSP->left_rgbSA, guiSP); curr_atomSP->middle_colorID = PixelFromRGBS_ (curr_atomSP->middle_rgbSA, guiSP); curr_atomSP->right_colorID = PixelFromRGBS_ (curr_atomSP->right_rgbSA, guiSP); continue; } /** The z coordinate of the current atom: **/ z = curr_atomSP->raw_atomS.z[0]; /** If current atom is closer to the observer than **/ /** the front surface, near colors should be used: **/ if (z <= z0) { curr_atomSP->left_colorID = PixelFromRGBS_ (curr_atomSP->left_rgbSA, guiSP); curr_atomSP->middle_colorID = PixelFromRGBS_ (curr_atomSP->middle_rgbSA, guiSP); curr_atomSP->right_colorID = PixelFromRGBS_ (curr_atomSP->right_rgbSA, guiSP); continue; } /** If current atom is behind the back **/ /** surface, far colors should be used: **/ else if (z >= z1) { surfaceI = surfacesN - 1; curr_atomSP->left_colorID = PixelFromRGBS_ (curr_atomSP->left_rgbSA + surfaceI, guiSP); curr_atomSP->middle_colorID = PixelFromRGBS_ (curr_atomSP->middle_rgbSA + surfaceI, guiSP); curr_atomSP->right_colorID = PixelFromRGBS_ (curr_atomSP->right_rgbSA + surfaceI, guiSP); continue; } /** If this point is reached, current atom is in **/ /** the area between two surfaces; colors should **/ /** be calculated weighting near and far colors: **/ /** Prepare auxiliary variables: **/ if (surfacesN > 1) { internal_range = overall_range / (double) (surfacesN - 1); inverse_internal_range = 1.0 / internal_range; near_surfaceI = (int) floor ((z - z0) * inverse_internal_range); far_surfaceI = near_surfaceI + 1; delta_z = z - near_surfaceI * internal_range - z0; scale_factor = delta_z * inverse_internal_range; } else { scale_factor = 0.0; far_surfaceI = 0; near_surfaceI = 0; } /** Left color: **/ curr_atomSP->left_colorID = PrepareColor_ (curr_atomSP->left_rgbSA + near_surfaceI, curr_atomSP->left_rgbSA + far_surfaceI, scale_factor, guiSP); /** Middle color: **/ curr_atomSP->middle_colorID = PrepareColor_ (curr_atomSP->middle_rgbSA + near_surfaceI, curr_atomSP->middle_rgbSA + far_surfaceI, scale_factor, guiSP); /** Right color: **/ curr_atomSP->right_colorID = PrepareColor_ (curr_atomSP->right_rgbSA + near_surfaceI, curr_atomSP->right_rgbSA + far_surfaceI, scale_factor, guiSP); /** Update the number of atoms in the area between two surfaces: **/ atoms_between_surfacesN++; } /* Return the number of atoms which have */ /* colors different from near and far colors: */ return atoms_between_surfacesN; } /*===========================================================================*/ garlic-1.6/nice_bonds.c0000644000076500007650000002222307603574156015374 0ustar zuciczucic00000000000000/* Copyright (C) 2002 Damir Zucic */ /*============================================================================= nice_bonds.c Purpose: Draw nice bonds (sort of spacefill style for bonds). Half of each bond is drawn and another half is assigned to the partner. Find the z value for each pixel. A bond is visible only if both atoms forming this bond are visible. Drawing direction: 1 -> 2. Input: (1) Pointer to MolComplexS structure. (2) Number of macromolecular complexes. (3) Pointer to ConfigS structure. (4) Pointer to GUIS structure. (5) Pointer to NearestAtomS structure, with information about the atom occupying the given pixel. (6) The number of pixels in the main window free area. (7) The refreshI, used to check the NearestAtomS associated with a given pixel. Output: (1) Bonds drawn to the hidden pixmap. (2) Return value. Return value: (1) The number of bonds drawn. Notes: (1) Indentation is exceptionally 4 spaces. (2) Some geometric parameters used to draw nice bonds are defined in the figure below: ++++++++ . +++ +++ |\ + + | \ + + + | \ + + .________+____________ | \ + + |\ r3 + | | \ + + /| \ + | | \ ++ +++ / | \ +++ | | \ ++ ooooo/++|+++\xxxxx rho0 | \ ++ ooo /ooo|xxxx\ xxxx | | ++++ oo / | | \ xx | |+++++++ |\ r1 + r3 o r2 / | | \ r1 x | | | \ o /______|___|___\_______x___|_ | | \ oo | | x | | \ ooo ooo| | xx | | \ ooooo |xxxx | xxxx | v0max | \ | | xxx|x rho0 | | \ | | | | | alpha1\ | |---a0--| |delta_u0| \ | | x________x_________\ |------d0------| | | | end_point start_point | | | |--------a0--------| (3) If alpha1 < PI/2, the parameters defined above are calculated from the following equations: r13 = r1 + r3; r23 = r2 + r3; alpha1 = acos ((r13 * r13 + d0 * d0 - r23 * r23) / (2 * d0 * r13)); rho0 = r13 * sin (alpha1); a0 = r13 * cos (alpha1); | | u0min = r1 * cos (alpha1); | | v0 u0max = r13 * cos (alpha1); | | u0min <= u0 <= u0max; | +--------------- v0max = r1 * sin (alpha1); u0max <-- u0min v0 = rho0 - sqrt (r3 * r3 - (a0 - u0) * (a0 - u0)); rho0 - r3 <= v0 <= v0max; (4) Sometimes it may happen that the angle alpha1 is larger than PI/2. It that case, the entire bond should be assigned to another atom. To identify such bond, the cosine of the angle alpha2 should be checked. The angle alpha2 is formed by r23 and d0 (the chemical bond). The problem described above may be experienced if one of two atoms is small and both another atom and the probe are large. Very large probe may also cause this kind of trouble. alpha2 = acos ((r23 * r23 + d0 * d0 - r13 * r13) / (2 * d0 * r23); (5) In the case that alpha2 > PI/2 the formula for u0max should be replaced by: u0max = d0 - r2 * cos (alpha2), where cos (alpha2) < 0, so that u0max will be larger than d0. the lower limit for v0 will be changed too, but this parameter is not required for drawing. Other formulas remain unchanged. (6) It is very important to reset the auxiliaryI member of each NearestAtomS structure before drawing nice bonds. This counter is used to signal that color correction was done and there is no need for further correction. The color correction (i.e. smoothing) is required to ensure nice connections of atoms and bonds. (7) Nice style is not allowed for hydrogen bonds. =============================================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int HalfNiceBond_ (Aux2S *, int); /*======draw bonds using the nice style:=====================================*/ size_t DrawNiceBonds_ (MolComplexS *mol_complexSP, int mol_complexesN, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int refreshI) { static size_t pixelI; static size_t bonds_drawnN = 0; static int imageI, imagesN; static int mol_complexI; static MolComplexS *curr_mol_complexSP, *partner_mol_complexSP; static size_t atomsN, atomI; static AtomS *curr_atomSP, *partner_atomSP; static int bondsN, bondI; static TrueBondS *curr_bondSP; static Aux2S aux2S; /* Return if there are no structures: */ if (mol_complexesN == 0) return 0; /* Reset the auxiliaryI member of each NearestAtomS structure. */ /* The zero value means that color correction is not done yet. */ for (pixelI = 0; pixelI < pixelsN; pixelI++) { (nearest_atomSP + pixelI)->auxiliaryI = 0; } /* Number of images: */ if (configSP->stereoF) imagesN = 2; else imagesN = 1; /* Copy some important pointers and parameters: */ aux2S.configSP = configSP; aux2S.guiSP = guiSP; aux2S.nearest_atomSP = nearest_atomSP; aux2S.pixelsN = pixelsN; aux2S.refreshI = refreshI; /* Draw each macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Prepare and check the number of atoms: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Copy the macromolecular complex index: */ aux2S.mol_complexI = mol_complexI; /* Copy the probe radius: */ aux2S.bond_probe_radius = curr_mol_complexSP->bond_probe_radius; /* Draw bonds which have the given style: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Check is atom hidden: */ if (curr_atomSP->hiddenF) continue; /* Check is atom inside slab: */ if (!curr_atomSP->inside_slabF) continue; /* Check is atom inside window: */ if (!curr_atomSP->inside_windowF) continue; /* Copy the pointer to the current atom: */ aux2S.atom1SP = curr_atomSP; /* Copy the atomic index: */ aux2S.atomI = atomI; /* Number of bonds: */ bondsN = curr_atomSP->bondsN; /* Bond loop: */ for (bondI = 0; bondI < bondsN; bondI++) { /* Pointer to the structure with data about current bond: */ curr_bondSP = curr_atomSP->true_bondSA + bondI; /* Check bond drawing style: */ if (curr_bondSP->bond_styleI != NICE_BONDS) continue; /* If the current bond is hydrogen bond, skip it: */ if (curr_bondSP->bond_typeI == 0) continue; /* The complex which contains the atom forming the bond: */ partner_mol_complexSP = mol_complexSP + curr_bondSP->neighbor_mol_complexI; /* Pointer to the bond partner: */ partner_atomSP = partner_mol_complexSP->atomSP + curr_bondSP->neighbor_arrayI; /* If partner is not visible, do not draw this bond: */ if (partner_atomSP->hiddenF) continue; /* Check is the partner inside the slab: */ if (!partner_atomSP->inside_slabF) continue; /* Check is the partner inside the window: */ if (!partner_atomSP->inside_windowF) continue; /* Copy the bond index: */ aux2S.bondI = bondI; /* Copy the pointer to the current bond: */ aux2S.curr_bondSP = curr_bondSP; /* Copy the pointer to the bond partner: */ aux2S.atom2SP = partner_atomSP; /* Draw one (mono) or two bonds (stereo): */ for (imageI = 0; imageI < imagesN; imageI++) { /* Copy the image index: */ aux2S.imageI = imageI; /* Draw half of a nice bond: */ HalfNiceBond_ (&aux2S, bondI); /* Update the counter: */ bonds_drawnN++; } /* imageI loop */ } /* bondI loop */ } /* atomI loop */ } /* mol_complexI loop */ /* Return the number of bonds which were drawn: */ return bonds_drawnN; } /*===========================================================================*/ garlic-1.6/draw_balls.c0000644000076500007650000003125507747301317015404 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2003 Damir Zucic */ /*============================================================================= draw_balls.c Purpose: Draw atoms as balls (ball style). Input: (1) Pointer to MolComplexS structure. (2) Number of macromolecular complexes. (3) Pointer to ConfigS structure, with configuration data. (4) Pointer to GUIS structure. (5) Pointer to NearestAtomS structure, with information about the atom occupying the given pixel. (6) The number of pixels in the main window free area. (7) The refreshI, used to check the NearestAtomS associated with a given pixel. Output: (1) Spheres drawn to the hidden pixmap. (2) Return value. Return value: (1) Positive always (trivial). Notes: (1) Indentation is exceptionally 4 spaces. =============================================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ unsigned long SpacefillColor_ (AtomS *, GUIS *, double); /*======draw atoms as balls:=================================================*/ int DrawBalls_ (MolComplexS *mol_complexSP, int mol_complexesN, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int refreshI) { int imageI, imagesN; double scale_factor, user_atomic_position; int left_edge[2], right_edge[2]; int mol_complexI; MolComplexS *curr_mol_complexSP; size_t atomsN, atomI; AtomS *curr_atomSP; int screen_x0, screen_y0; double radius, radius_squared; double denominator, reciprocal_denominator; int screen_radius; long screen_radius_squared; int screen_x1, screen_y1, screen_x2, screen_y2; int screen_x, screen_y; long delta_x, delta_y, distance_squared; double z0, front_z, delta_z, z; size_t pixelI; NearestAtomS *curr_pixelSP; double denominator2, reciprocal_denominator2; double rho_squared; VectorS vectorS; double abs_value, abs_value_squared; double scalar_product, cos_angle; unsigned long colorID; int bondI; /* Initialize the bond index. The negative value means that pixels */ /* filled in this function are not a part of any chemical bond. */ bondI = -1; /* Number of images: */ if (configSP->stereoF) imagesN = 2; else imagesN = 1; scale_factor = configSP->user_screen_atomic_distance * configSP->atomic_to_screen_scale_x; /* Prepare the user position in atomic coordinates: */ user_atomic_position = configSP->user_atomic_position; /* Left and right image edge (in stereo mode there are two images): */ left_edge[0] = configSP->image_screen_x0[0]; right_edge[0] = configSP->image_screen_x1[0]; left_edge[1] = configSP->image_screen_x0[1]; right_edge[1] = configSP->image_screen_x1[1]; /*------first pass - fill NearestAtomS array with planar atoms:--------------*/ /* Draw each macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Prepare and check the number of atoms: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Draw atoms which have the given style: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Check style: */ if (curr_atomSP->raw_atomS.atom_styleI != BALL) continue; /* Check is atom hidden: */ if (curr_atomSP->hiddenF) continue; /* Check is atom inside slab: */ if (!curr_atomSP->inside_slabF) continue; /* Check is atom inside window: */ if (!curr_atomSP->inside_windowF) continue; /* Copy the atomic radius: */ radius = curr_atomSP->raw_atomS.ball_radius; /* Squared atomic radius: */ radius_squared = radius * radius; /* The y coordinate of atomic center, in screen units: */ screen_y0 = curr_atomSP->raw_atomS.screen_y; /* Prepare one image (mono) or two images (stereo): */ for (imageI = 0; imageI < imagesN; imageI++) { /* The z coordinate of atomic center, in atomic units: */ z0 = curr_atomSP->raw_atomS.z[imageI]; /* Prepare the factor required for projection of atomic radius: */ denominator = z0 - user_atomic_position; if (denominator == 0.0) continue; reciprocal_denominator = 1.0 / denominator; /* Atomic radius in screen units: */ screen_radius = (int) (radius * scale_factor * reciprocal_denominator + 0.5); /* Screen radius squared (used to improve speed): */ screen_radius_squared = (long) screen_radius * (long) screen_radius; /* The x coordinate of atomic center, in screen units: */ screen_x0 = curr_atomSP->raw_atomS.screen_x[imageI]; /* Define the bounding rectangle: */ screen_x1 = screen_x0 - screen_radius; screen_y1 = screen_y0 - screen_radius; screen_x2 = screen_x0 + screen_radius; screen_y2 = screen_y0 + screen_radius; /* Horizontal scan: */ for (screen_x = screen_x1; screen_x <= screen_x2; screen_x++) { /* Check horizontal position: */ if (screen_x < left_edge[imageI]) continue; if (screen_x >= right_edge[imageI]) continue; /* Vertical scan: */ for (screen_y = screen_y1; screen_y <= screen_y2; screen_y++) { /* Check vertical position: */ if (screen_y < 0) continue; if (screen_y >= (int) guiSP->main_win_free_area_height) { continue; } /* Check distance from the circle center: */ delta_x = (long) (screen_x - screen_x0); delta_y = (long) (screen_y - screen_y0); distance_squared = delta_x * delta_x + delta_y * delta_y; if (distance_squared > screen_radius_squared) continue; /* Prepare index to the array */ /* of NearestAtomS structures: */ pixelI = guiSP->main_win_free_area_width * screen_y + screen_x; /* Check the pixel index: */ if (pixelI >= pixelsN) continue; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = nearest_atomSP + pixelI; /* Check was this pixel used already in */ /* this drawing step; if it was, compare */ /* the z value of the current atom with z */ /* value previously stored to this pixel: */ if (refreshI == curr_pixelSP->last_refreshI) { if (z0 > curr_pixelSP->z) continue; } /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = BALL; curr_pixelSP->last_refreshI = refreshI; curr_pixelSP->mol_complexI = mol_complexI; curr_pixelSP->atomI = atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = z0; } } } /* imageI loop */ } /* atomI loop */ } /* mol_complexI loop */ /*------second pass - draw spherical atoms:----------------------------------*/ /* Draw each macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Prepare and check the number of atoms: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Draw atoms which have the given style: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Check style: */ if (curr_atomSP->raw_atomS.atom_styleI != BALL) continue; /* Check is atom hidden: */ if (curr_atomSP->hiddenF) continue; /* Check is atom inside slab: */ if (!curr_atomSP->inside_slabF) continue; /* Check is atom inside window: */ if (!curr_atomSP->inside_windowF) continue; /* Copy the atomic radius: */ radius = curr_atomSP->raw_atomS.ball_radius; /* Squared atomic radius: */ radius_squared = radius * radius; /* The y coordinate of atomic center, in screen units: */ screen_y0 = curr_atomSP->raw_atomS.screen_y; /* Prepare one image (mono) or two images (stereo): */ for (imageI = 0; imageI < imagesN; imageI++) { /* The z coordinate of atomic center, in atomic units: */ z0 = curr_atomSP->raw_atomS.z[imageI]; /* The z coordinate of the nearest */ /* point of a given atom (sphere): */ front_z = z0 - radius; /* Prepare the factor required for projection of atomic radius: */ denominator = z0 - user_atomic_position; if (denominator == 0.0) continue; reciprocal_denominator = 1.0 / denominator; /* Atomic radius in screen units: */ screen_radius = (int) (radius * scale_factor * reciprocal_denominator + 0.5); /* Square of the atomic radius (in screen units): */ screen_radius_squared = (long) screen_radius * (long) screen_radius; /* Reciprocal value will be used to improve performance: */ denominator2 = (double) screen_radius_squared; if (denominator2 == 0.0) continue; reciprocal_denominator2 = 1.0 / denominator2; /* The x coordinate of atomic center, in screen units: */ screen_x0 = curr_atomSP->raw_atomS.screen_x[imageI]; /* Define the bounding rectangle: */ screen_x1 = screen_x0 - screen_radius; screen_y1 = screen_y0 - screen_radius; screen_x2 = screen_x0 + screen_radius; screen_y2 = screen_y0 + screen_radius; /* Horizontal scan: */ for (screen_x = screen_x1; screen_x <= screen_x2; screen_x++) { /* Check horizontal position: */ if (screen_x < left_edge[imageI]) continue; if (screen_x > right_edge[imageI]) continue; /* Vertical scan: */ for (screen_y = screen_y1; screen_y <= screen_y2; screen_y++) { /* Check vertical position: */ if (screen_y < 0) continue; if (screen_y >= (int) guiSP->main_win_free_area_height) { continue; } /* Check distance from the circle center: */ delta_x = (long) (screen_x - screen_x0); delta_y = (long) (screen_y - screen_y0); distance_squared = delta_x * delta_x + delta_y * delta_y; if (distance_squared > screen_radius_squared) continue; /* Prepare index to the array */ /* of NearestAtomS structures: */ pixelI = guiSP->main_win_free_area_width * screen_y + screen_x; /* Check the pixel index: */ if (pixelI >= pixelsN) continue; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = nearest_atomSP + pixelI; /* Check z value (this is just a quick check): */ if (refreshI == curr_pixelSP->last_refreshI) { if (front_z > curr_pixelSP->z) continue; } /* Calculate the accurate z value: */ rho_squared = radius_squared * (double) distance_squared * reciprocal_denominator2; delta_z = sqrt (fabs (radius_squared - rho_squared)); z = z0 - delta_z; /* Check z value (precise check): */ if (refreshI == curr_pixelSP->last_refreshI) { if (z > curr_pixelSP->z) continue; } /* The vector from sphere center to the current pixel: */ vectorS.x = (double) delta_x; vectorS.y = (double) delta_y; vectorS.z = -delta_z * scale_factor * reciprocal_denominator; abs_value_squared = vectorS.x * vectorS.x + vectorS.y * vectorS.y + vectorS.z * vectorS.z; abs_value = sqrt (abs_value_squared); /* The scalar product between this */ /* vector and light source vector: */ scalar_product = vectorS.x * configSP->light_vectorS.x + vectorS.y * configSP->light_vectorS.y + vectorS.z * configSP->light_vectorS.z; /* Cosine of the angle between the vector to the */ /* current pixel and the light source unit vector: */ if (abs_value == 0.0) cos_angle = 0.0; else cos_angle = scalar_product / abs_value; /* Prepare color: */ colorID = SpacefillColor_ (curr_atomSP, guiSP, cos_angle); XSetForeground (guiSP->displaySP, guiSP->theGCA[0], colorID); XDrawPoint (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x, screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = BALL; curr_pixelSP->last_refreshI = refreshI; curr_pixelSP->mol_complexI = mol_complexI; curr_pixelSP->atomI = atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = z; curr_pixelSP->colorID = colorID; } } } /* imageI loop */ } /* atomI loop */ } /* mol_complexI loop */ /*---------------------------------------------------------------------------*/ /* Return positive value (trivial): */ return 1; } /*===========================================================================*/ garlic-1.6/residues.pdb0000644000076500007650000006320407311734076015436 0ustar zuciczucic00000000000000ATOM 1 N ALA 1 -20.307 17.277 25.298 1.00 0.18 ATOM 2 CA ALA 1 -20.293 16.365 24.112 1.00 0.19 ATOM 3 C ALA 1 -18.873 16.278 23.541 1.00 0.20 ATOM 4 O ALA 1 -18.190 17.275 23.428 1.00 0.25 ATOM 5 CB ALA 1 -21.238 16.916 23.045 1.00 0.24 ATOM 6 H ALA 1 -19.804 18.120 25.278 1.00 0.19 ATOM 7 HA ALA 1 -20.622 15.383 24.409 1.00 0.18 ATOM 8 HB ALA 1 -21.767 17.771 23.437 1.00 1.03 ATOM 9 HB ALA 1 -20.670 17.215 22.176 1.00 1.00 ATOM 10 HB ALA 1 -21.949 16.156 22.760 1.00 1.09 ATOM 11 N ARG 2 -18.461 15.068 23.192 1.00 0.36 ATOM 12 CA ARG 2 -17.108 14.831 22.625 1.00 0.36 ATOM 13 C ARG 2 -17.200 13.824 21.484 1.00 0.30 ATOM 14 O ARG 2 -17.868 12.814 21.598 1.00 0.30 ATOM 15 CB ARG 2 -16.196 14.274 23.713 1.00 0.44 ATOM 16 CG ARG 2 -15.991 15.334 24.791 1.00 0.76 ATOM 17 CD ARG 2 -15.008 14.797 25.834 1.00 1.23 ATOM 18 NE ARG 2 -15.444 15.244 27.185 1.00 1.90 ATOM 19 CZ ARG 2 -14.847 14.759 28.240 1.00 2.72 ATOM 20 NH1 ARG 2 -13.673 14.207 28.102 1.00 3.38 ATOM 21 NH2 ARG 2 -15.449 14.840 29.395 1.00 3.41 ATOM 22 H ARG 2 -19.080 14.321 23.320 1.00 0.39 ATOM 23 HA ARG 2 -16.702 15.755 22.254 1.00 0.40 ATOM 24 HB ARG 2 -16.648 13.394 24.149 1.00 0.54 ATOM 25 HB ARG 2 -15.243 14.004 23.284 1.00 0.52 ATOM 26 HG ARG 2 -15.593 16.232 24.346 1.00 1.17 ATOM 27 HG ARG 2 -16.935 15.559 25.265 1.00 1.11 ATOM 28 HD ARG 2 -14.990 13.717 25.799 1.00 1.78 ATOM 29 HD ARG 2 -14.018 15.178 25.632 1.00 1.69 ATOM 30 HE ARG 2 -16.171 15.891 27.280 1.00 2.34 ATOM 31 HH1 ARG 2 -13.244 14.162 27.199 1.00 3.40 ATOM 32 HH1 ARG 2 -13.202 13.832 28.898 1.00 4.14 ATOM 33 HH2 ARG 2 -16.349 15.268 29.460 1.00 3.47 ATOM 34 HH2 ARG 2 -15.007 14.474 30.213 1.00 4.18 ATOM 35 N ASN 3 -16.516 14.122 20.389 1.00 0.23 ATOM 36 CA ASN 3 -16.511 13.242 19.206 1.00 0.22 ATOM 37 C ASN 3 -15.108 13.209 18.611 1.00 0.21 ATOM 38 O ASN 3 -14.478 14.235 18.461 1.00 0.29 ATOM 39 CB ASN 3 -17.499 13.783 18.172 1.00 0.25 ATOM 40 CG ASN 3 -18.879 13.944 18.814 1.00 0.28 ATOM 41 OD1 ASN 3 -19.878 13.516 18.270 1.00 1.09 ATOM 42 ND2 ASN 3 -18.984 14.560 19.961 1.00 1.16 ATOM 43 H ASN 3 -16.007 14.953 20.385 1.00 0.26 ATOM 44 HA ASN 3 -16.802 12.256 19.501 1.00 0.22 ATOM 45 HB ASN 3 -17.163 14.742 17.812 1.00 0.27 ATOM 46 HB ASN 3 -17.571 13.097 17.340 1.00 0.29 ATOM 47 HD2 ASN 3 -19.865 14.666 20.382 1.00 1.18 ATOM 48 HD2 ASN 3 -18.188 14.915 20.404 1.00 1.98 ATOM 49 N ASP 4 -14.646 12.011 18.281 1.00 0.22 ATOM 50 CA ASP 4 -13.290 11.823 17.688 1.00 0.23 ATOM 51 C ASP 4 -13.353 10.783 16.560 1.00 0.26 ATOM 52 O ASP 4 -13.923 9.723 16.723 1.00 0.37 ATOM 53 CB ASP 4 -12.317 11.360 18.770 1.00 0.24 ATOM 54 CG ASP 4 -12.487 9.860 19.000 1.00 0.34 ATOM 55 OD1 ASP 4 -13.592 9.399 18.774 1.00 0.30 ATOM 56 OD2 ASP 4 -11.499 9.262 19.390 1.00 0.57 ATOM 57 H ASP 4 -15.232 11.245 18.441 1.00 0.25 ATOM 58 HA ASP 4 -12.947 12.761 17.282 1.00 0.25 ATOM 59 HB ASP 4 -11.302 11.560 18.460 1.00 0.28 ATOM 60 HB ASP 4 -12.519 11.886 19.691 1.00 0.29 ATOM 61 N CYS 5 -12.755 11.118 15.426 1.00 0.19 ATOM 62 CA CYS 5 -12.735 10.212 14.247 1.00 0.18 ATOM 63 C CYS 5 -11.387 10.282 13.528 1.00 0.17 ATOM 64 O CYS 5 -10.854 11.350 13.300 1.00 0.22 ATOM 65 CB CYS 5 -13.830 10.645 13.279 1.00 0.21 ATOM 66 SG CYS 5 -13.702 12.314 12.591 1.00 0.48 ATOM 67 H CYS 5 -12.320 11.996 15.387 1.00 0.23 ATOM 68 HA CYS 5 -12.923 9.205 14.564 1.00 0.20 ATOM 69 HB CYS 5 -13.843 9.950 12.454 1.00 0.29 ATOM 70 HB CYS 5 -14.779 10.571 13.783 1.00 0.36 ATOM 71 HG CYS 5 -14.465 12.816 12.884 1.00 1.05 ATOM 72 N GLN 6 -10.853 9.121 13.180 1.00 0.36 ATOM 73 CA GLN 6 -9.537 9.034 12.469 1.00 0.44 ATOM 74 C GLN 6 -9.597 7.976 11.351 1.00 0.45 ATOM 75 O GLN 6 -10.108 6.893 11.547 1.00 0.58 ATOM 76 CB GLN 6 -8.455 8.664 13.479 1.00 0.54 ATOM 77 CG GLN 6 -7.073 8.995 12.898 1.00 0.74 ATOM 78 CD GLN 6 -6.557 10.290 13.531 1.00 1.23 ATOM 79 OE1 GLN 6 -6.781 11.372 13.028 1.00 1.93 ATOM 80 NE2 GLN 6 -5.860 10.221 14.633 1.00 1.76 ATOM 81 H GLN 6 -11.351 8.307 13.403 1.00 0.44 ATOM 82 HA GLN 6 -9.303 9.992 12.038 1.00 0.52 ATOM 83 HB GLN 6 -8.606 9.223 14.392 1.00 0.62 ATOM 84 HB GLN 6 -8.513 7.615 13.699 1.00 0.53 ATOM 85 HG GLN 6 -6.384 8.193 13.114 1.00 1.07 ATOM 86 HG GLN 6 -7.145 9.127 11.830 1.00 0.95 ATOM 87 HE2 GLN 6 -5.521 11.040 15.049 1.00 2.25 ATOM 88 HE2 GLN 6 -5.674 9.349 15.042 1.00 2.11 ATOM 89 N GLU 7 -9.064 8.328 10.190 1.00 0.29 ATOM 90 CA GLU 7 -9.049 7.403 9.010 1.00 0.28 ATOM 91 C GLU 7 -7.686 7.419 8.299 1.00 0.26 ATOM 92 O GLU 7 -7.148 8.467 8.000 1.00 0.35 ATOM 93 CB GLU 7 -10.129 7.836 8.034 1.00 0.35 ATOM 94 CG GLU 7 -11.459 7.206 8.446 1.00 0.41 ATOM 95 CD GLU 7 -12.574 7.746 7.549 1.00 0.87 ATOM 96 OE1 GLU 7 -12.323 8.763 6.924 1.00 1.57 ATOM 97 OE2 GLU 7 -13.617 7.109 7.538 1.00 1.56 ATOM 98 H GLU 7 -8.674 9.224 10.127 1.00 0.32 ATOM 99 HA GLU 7 -9.262 6.412 9.338 1.00 0.30 ATOM 100 HB GLU 7 -10.214 8.903 8.055 1.00 0.38 ATOM 101 HB GLU 7 -9.865 7.519 7.035 1.00 0.38 ATOM 102 HG GLU 7 -11.405 6.132 8.340 1.00 0.61 ATOM 103 HG GLU 7 -11.679 7.452 9.475 1.00 0.66 ATOM 104 N GLY 8 -7.151 6.234 8.041 1.00 0.56 ATOM 105 CA GLY 8 -5.835 6.094 7.357 1.00 0.58 ATOM 106 C GLY 8 -5.892 4.945 6.343 1.00 0.54 ATOM 107 O GLY 8 -6.415 3.885 6.628 1.00 0.51 ATOM 108 H GLY 8 -7.651 5.435 8.316 1.00 0.81 ATOM 109 HA GLY 8 -5.598 7.013 6.848 1.00 0.65 ATOM 110 HA GLY 8 -5.077 5.885 8.095 1.00 0.56 ATOM 111 N HIS 9 -5.343 5.186 5.162 1.00 0.28 ATOM 112 CA HIS 9 -5.323 4.163 4.075 1.00 0.29 ATOM 113 C HIS 9 -3.961 4.180 3.378 1.00 0.30 ATOM 114 O HIS 9 -3.437 5.233 3.066 1.00 0.50 ATOM 115 CB HIS 9 -6.415 4.486 3.051 1.00 0.34 ATOM 116 CG HIS 9 -7.790 4.408 3.717 1.00 0.36 ATOM 117 ND1 HIS 9 -8.354 5.354 4.314 1.00 0.43 ATOM 118 CD2 HIS 9 -8.677 3.349 3.788 1.00 0.46 ATOM 119 CE1 HIS 9 -9.496 5.008 4.752 1.00 0.50 ATOM 120 NE2 HIS 9 -9.788 3.742 4.463 1.00 0.50 ATOM 121 H HIS 9 -4.942 6.069 5.014 1.00 0.33 ATOM 122 HA HIS 9 -5.501 3.186 4.494 1.00 0.30 ATOM 123 HB HIS 9 -6.264 5.483 2.663 1.00 0.36 ATOM 124 HB HIS 9 -6.371 3.778 2.237 1.00 0.41 ATOM 125 HD1 HIS 9 -7.966 6.246 4.430 1.00 0.51 ATOM 126 HD2 HIS 9 -8.513 2.366 3.373 1.00 0.57 ATOM 127 HE1 HIS 9 -10.157 5.667 5.297 1.00 0.62 ATOM 128 N ILE 10 -3.412 2.996 3.147 1.00 0.20 ATOM 129 CA ILE 10 -2.084 2.856 2.475 1.00 0.22 ATOM 130 C ILE 10 -2.133 1.649 1.498 1.00 0.19 ATOM 131 O ILE 10 -2.638 0.603 1.845 1.00 0.19 ATOM 132 CB ILE 10 -1.018 2.598 3.544 1.00 0.28 ATOM 133 CG1 ILE 10 -0.940 3.822 4.469 1.00 0.30 ATOM 134 CG2 ILE 10 0.340 2.380 2.864 1.00 0.36 ATOM 135 CD1 ILE 10 0.029 3.539 5.629 1.00 1.04 ATOM 136 H ILE 10 -3.906 2.196 3.434 1.00 0.26 ATOM 137 HA ILE 10 -1.841 3.758 1.955 1.00 0.22 ATOM 138 HB ILE 10 -1.282 1.724 4.112 1.00 0.32 ATOM 139 HG1 ILE 10 -0.589 4.677 3.909 1.00 0.80 ATOM 140 HG1 ILE 10 -1.920 4.039 4.864 1.00 0.74 ATOM 141 HG2 ILE 10 0.263 2.610 1.812 1.00 0.89 ATOM 142 HG2 ILE 10 1.082 3.022 3.313 1.00 0.97 ATOM 143 HG2 ILE 10 0.644 1.352 2.980 1.00 1.01 ATOM 144 HD1 ILE 10 0.183 2.476 5.731 1.00 1.68 ATOM 145 HD1 ILE 10 0.977 4.018 5.436 1.00 1.64 ATOM 146 HD1 ILE 10 -0.382 3.927 6.549 1.00 1.58 ATOM 147 N LEU 11 -1.600 1.848 0.301 1.00 0.27 ATOM 148 CA LEU 11 -1.575 0.787 -0.735 1.00 0.30 ATOM 149 C LEU 11 -0.233 0.783 -1.459 1.00 0.24 ATOM 150 O LEU 11 0.238 1.809 -1.905 1.00 0.24 ATOM 151 CB LEU 11 -2.698 1.086 -1.726 1.00 0.39 ATOM 152 CG LEU 11 -3.390 -0.197 -2.223 1.00 0.46 ATOM 153 CD1 LEU 11 -4.099 -0.917 -1.040 1.00 1.23 ATOM 154 CD2 LEU 11 -4.415 0.243 -3.301 1.00 1.19 ATOM 155 H LEU 11 -1.216 2.733 0.120 1.00 0.31 ATOM 156 HA LEU 11 -1.737 -0.165 -0.277 1.00 0.33 ATOM 157 HB LEU 11 -3.430 1.722 -1.245 1.00 0.53 ATOM 158 HB LEU 11 -2.289 1.611 -2.571 1.00 0.41 ATOM 159 HG LEU 11 -2.660 -0.865 -2.671 1.00 0.73 ATOM 160 HD1 LEU 11 -4.377 -0.194 -0.287 1.00 1.69 ATOM 161 HD1 LEU 11 -4.981 -1.432 -1.378 1.00 1.82 ATOM 162 HD1 LEU 11 -3.429 -1.642 -0.603 1.00 1.73 ATOM 163 HD2 LEU 11 -4.595 1.304 -3.213 1.00 1.64 ATOM 164 HD2 LEU 11 -4.012 0.040 -4.277 1.00 1.87 ATOM 165 HD2 LEU 11 -5.348 -0.275 -3.188 1.00 1.68 ATOM 166 N LYS 12 0.367 -0.394 -1.564 1.00 0.32 ATOM 167 CA LYS 12 1.689 -0.552 -2.249 1.00 0.29 ATOM 168 C LYS 12 1.677 -1.816 -3.107 1.00 0.25 ATOM 169 O LYS 12 1.277 -2.870 -2.658 1.00 0.31 ATOM 170 CB LYS 12 2.797 -0.640 -1.216 1.00 0.30 ATOM 171 CG LYS 12 2.708 0.582 -0.296 1.00 0.47 ATOM 172 CD LYS 12 3.897 0.594 0.672 1.00 0.53 ATOM 173 CE LYS 12 3.927 -0.710 1.470 1.00 0.73 ATOM 174 NZ LYS 12 4.644 -0.514 2.761 1.00 1.37 ATOM 175 H LYS 12 -0.089 -1.166 -1.174 1.00 0.48 ATOM 176 HA LYS 12 1.862 0.302 -2.883 1.00 0.31 ATOM 177 HB LYS 12 2.681 -1.544 -0.648 1.00 0.37 ATOM 178 HB LYS 12 3.755 -0.654 -1.711 1.00 0.35 ATOM 179 HG LYS 12 2.722 1.481 -0.893 1.00 0.73 ATOM 180 HG LYS 12 1.789 0.548 0.259 1.00 0.64 ATOM 181 HD LYS 12 4.815 0.701 0.117 1.00 1.09 ATOM 182 HD LYS 12 3.798 1.427 1.352 1.00 1.00 ATOM 183 HE LYS 12 2.918 -1.036 1.670 1.00 1.30 ATOM 184 HE LYS 12 4.437 -1.473 0.898 1.00 1.42 ATOM 185 HZ LYS 12 4.882 0.493 2.876 1.00 1.79 ATOM 186 HZ LYS 12 4.031 -0.815 3.547 1.00 1.83 ATOM 187 HZ LYS 12 5.514 -1.079 2.765 1.00 2.00 ATOM 188 N MET 13 2.125 -1.681 -4.347 1.00 0.26 ATOM 189 CA MET 13 2.172 -2.830 -5.301 1.00 0.28 ATOM 190 C MET 13 3.485 -2.804 -6.097 1.00 0.30 ATOM 191 O MET 13 3.901 -1.774 -6.591 1.00 0.37 ATOM 192 CB MET 13 0.978 -2.757 -6.255 1.00 0.35 ATOM 193 CG MET 13 0.987 -1.419 -6.993 1.00 1.15 ATOM 194 SD MET 13 1.240 -1.464 -8.785 1.00 2.09 ATOM 195 CE MET 13 0.185 -0.054 -9.200 1.00 2.25 ATOM 196 H MET 13 2.429 -0.788 -4.624 1.00 0.28 ATOM 197 HA MET 13 2.121 -3.749 -4.747 1.00 0.28 ATOM 198 HB MET 13 1.038 -3.564 -6.970 1.00 0.94 ATOM 199 HB MET 13 0.061 -2.853 -5.692 1.00 0.92 ATOM 200 HG MET 13 0.043 -0.929 -6.809 1.00 1.89 ATOM 201 HG MET 13 1.765 -0.802 -6.569 1.00 1.80 ATOM 202 HE MET 13 1.045 0.456 -8.787 1.00 2.50 ATOM 203 HE MET 13 0.330 0.718 -9.941 1.00 2.60 ATOM 204 HE MET 13 0.101 -0.633 -10.106 1.00 2.53 ATOM 205 N PHE 14 4.121 -3.961 -6.207 1.00 0.19 ATOM 206 CA PHE 14 5.407 -4.089 -6.950 1.00 0.20 ATOM 207 C PHE 14 5.422 -5.373 -7.776 1.00 0.21 ATOM 208 O PHE 14 4.987 -6.413 -7.322 1.00 0.35 ATOM 209 CB PHE 14 6.569 -4.128 -5.957 1.00 0.22 ATOM 210 CG PHE 14 6.335 -3.110 -4.845 1.00 0.20 ATOM 211 CD1 PHE 14 5.580 -3.441 -3.732 1.00 0.18 ATOM 212 CD2 PHE 14 6.878 -1.848 -4.937 1.00 0.23 ATOM 213 CE1 PHE 14 5.371 -2.516 -2.732 1.00 0.17 ATOM 214 CE2 PHE 14 6.668 -0.922 -3.937 1.00 0.22 ATOM 215 CZ PHE 14 5.916 -1.255 -2.835 1.00 0.18 ATOM 216 H PHE 14 3.718 -4.745 -5.779 1.00 0.25 ATOM 217 HA PHE 14 5.527 -3.242 -7.606 1.00 0.21 ATOM 218 HB PHE 14 6.646 -5.107 -5.524 1.00 0.24 ATOM 219 HB PHE 14 7.493 -3.890 -6.465 1.00 0.26 ATOM 220 HD1 PHE 14 5.159 -4.431 -3.641 1.00 0.19 ATOM 221 HD2 PHE 14 7.479 -1.590 -5.792 1.00 0.27 ATOM 222 HE1 PHE 14 4.783 -2.782 -1.868 1.00 0.18 ATOM 223 HE2 PHE 14 7.096 0.067 -4.018 1.00 0.26 ATOM 224 HZ PHE 14 5.753 -0.532 -2.052 1.00 0.19 ATOM 225 N PRO 15 5.933 -5.274 -8.995 1.00 1.08 ATOM 226 CA PRO 15 6.013 -6.426 -9.902 1.00 1.04 ATOM 227 C PRO 15 7.369 -6.432 -10.606 1.00 0.87 ATOM 228 O PRO 15 7.811 -5.433 -11.141 1.00 1.05 ATOM 229 CB PRO 15 4.874 -6.214 -10.911 1.00 1.27 ATOM 230 CG PRO 15 4.304 -4.781 -10.660 1.00 1.32 ATOM 231 CD PRO 15 5.070 -4.187 -9.461 1.00 1.26 ATOM 232 HA PRO 15 5.866 -7.336 -9.362 1.00 1.16 ATOM 233 HB PRO 15 5.246 -6.289 -11.920 1.00 1.35 ATOM 234 HB PRO 15 4.101 -6.951 -10.754 1.00 1.44 ATOM 235 HG PRO 15 4.452 -4.166 -11.535 1.00 1.40 ATOM 236 HG PRO 15 3.251 -4.839 -10.433 1.00 1.46 ATOM 237 HD PRO 15 5.672 -3.346 -9.780 1.00 1.32 ATOM 238 HD PRO 15 4.391 -3.889 -8.685 1.00 1.45 ATOM 239 N SER 16 8.025 -7.583 -10.595 1.00 0.29 ATOM 240 CA SER 16 9.351 -7.738 -11.238 1.00 0.25 ATOM 241 C SER 16 9.398 -9.094 -11.925 1.00 0.26 ATOM 242 O SER 16 8.952 -10.084 -11.375 1.00 0.35 ATOM 243 CB SER 16 10.444 -7.648 -10.188 1.00 0.27 ATOM 244 OG SER 16 9.952 -6.700 -9.252 1.00 0.40 ATOM 245 H SER 16 7.599 -8.341 -10.141 1.00 0.33 ATOM 246 HA SER 16 9.488 -6.965 -11.965 1.00 0.24 ATOM 247 HB SER 16 10.589 -8.595 -9.717 1.00 0.39 ATOM 248 HB SER 16 11.367 -7.297 -10.625 1.00 0.35 ATOM 249 HG SER 16 9.508 -6.002 -9.741 1.00 0.91 ATOM 250 N THR 17 9.946 -9.116 -13.132 1.00 0.19 ATOM 251 CA THR 17 10.061 -10.373 -13.925 1.00 0.18 ATOM 252 C THR 17 11.385 -10.357 -14.678 1.00 0.17 ATOM 253 O THR 17 11.715 -9.370 -15.313 1.00 0.29 ATOM 254 CB THR 17 8.903 -10.454 -14.925 1.00 0.20 ATOM 255 OG1 THR 17 8.956 -9.225 -15.643 1.00 0.28 ATOM 256 CG2 THR 17 7.548 -10.450 -14.220 1.00 0.31 ATOM 257 H THR 17 10.280 -8.267 -13.498 1.00 0.23 ATOM 258 HA THR 17 10.030 -11.227 -13.265 1.00 0.19 ATOM 259 HB THR 17 8.997 -11.297 -15.585 1.00 0.28 ATOM 260 HG1 THR 17 8.383 -8.597 -15.200 1.00 0.90 ATOM 261 HG2 THR 17 7.694 -10.468 -13.151 1.00 1.06 ATOM 262 HG2 THR 17 7.002 -9.558 -14.491 1.00 1.00 ATOM 263 HG2 THR 17 6.981 -11.319 -14.517 1.00 1.09 ATOM 264 N TRP 18 12.117 -11.458 -14.590 1.00 0.22 ATOM 265 CA TRP 18 13.442 -11.587 -15.278 1.00 0.20 ATOM 266 C TRP 18 13.562 -12.996 -15.852 1.00 0.19 ATOM 267 O TRP 18 13.196 -13.958 -15.204 1.00 0.22 ATOM 268 CB TRP 18 14.571 -11.352 -14.277 1.00 0.19 ATOM 269 CG TRP 18 14.582 -9.877 -13.861 1.00 0.23 ATOM 270 CD1 TRP 18 13.809 -9.376 -12.906 1.00 0.27 ATOM 271 CD2 TRP 18 15.346 -8.932 -14.394 1.00 0.25 ATOM 272 NE1 TRP 18 14.132 -8.075 -12.880 1.00 0.30 ATOM 273 CE2 TRP 18 15.096 -7.710 -13.787 1.00 0.29 ATOM 274 CE3 TRP 18 16.298 -9.007 -15.404 1.00 0.27 ATOM 275 CZ2 TRP 18 15.785 -6.583 -14.183 1.00 0.33 ATOM 276 CZ3 TRP 18 16.983 -7.874 -15.795 1.00 0.32 ATOM 277 CH2 TRP 18 16.726 -6.665 -15.186 1.00 0.35 ATOM 278 H TRP 18 11.763 -12.202 -14.052 1.00 0.23 ATOM 279 HA TRP 18 13.512 -10.868 -16.075 1.00 0.21 ATOM 280 HB TRP 18 14.418 -11.963 -13.407 1.00 0.20 ATOM 281 HB TRP 18 15.515 -11.613 -14.724 1.00 0.18 ATOM 282 HD1 TRP 18 13.087 -9.894 -12.294 1.00 0.29 ATOM 283 HE1 TRP 18 13.720 -7.439 -12.260 1.00 0.33 ATOM 284 HE3 TRP 18 16.506 -9.945 -15.887 1.00 0.25 ATOM 285 HZ2 TRP 18 15.584 -5.634 -13.708 1.00 0.36 ATOM 286 HZ3 TRP 18 17.723 -7.937 -16.576 1.00 0.35 ATOM 287 HH2 TRP 18 17.264 -5.781 -15.494 1.00 0.39 ATOM 288 N TYR 19 14.078 -13.086 -17.069 1.00 0.41 ATOM 289 CA TYR 19 14.257 -14.399 -17.759 1.00 0.33 ATOM 290 C TYR 19 15.607 -14.436 -18.483 1.00 0.30 ATOM 291 O TYR 19 15.983 -13.486 -19.139 1.00 0.32 ATOM 292 CB TYR 19 13.133 -14.581 -18.781 1.00 0.36 ATOM 293 CG TYR 19 11.787 -14.282 -18.118 1.00 0.38 ATOM 294 CD1 TYR 19 11.205 -15.200 -17.268 1.00 0.34 ATOM 295 CD2 TYR 19 11.135 -13.089 -18.359 1.00 0.47 ATOM 296 CE1 TYR 19 9.991 -14.931 -16.671 1.00 0.39 ATOM 297 CE2 TYR 19 9.922 -12.821 -17.761 1.00 0.51 ATOM 298 CZ TYR 19 9.340 -13.739 -16.912 1.00 0.46 ATOM 299 OH TYR 19 8.125 -13.470 -16.313 1.00 0.53 ATOM 300 H TYR 19 14.344 -12.258 -17.512 1.00 0.45 ATOM 301 HA TYR 19 14.215 -15.196 -17.040 1.00 0.33 ATOM 302 HB TYR 19 13.280 -13.902 -19.610 1.00 0.43 ATOM 303 HB TYR 19 13.133 -15.597 -19.148 1.00 0.36 ATOM 304 HD1 TYR 19 11.704 -16.139 -17.071 1.00 0.32 ATOM 305 HD2 TYR 19 11.580 -12.360 -19.021 1.00 0.54 ATOM 306 HE1 TYR 19 9.547 -15.660 -16.009 1.00 0.40 ATOM 307 HE2 TYR 19 9.423 -11.882 -17.958 1.00 0.60 ATOM 308 HH TYR 19 7.495 -14.131 -16.609 1.00 1.09 ATOM 309 N VAL 20 16.310 -15.550 -18.343 1.00 0.68 ATOM 310 CA VAL 20 17.638 -15.729 -18.987 1.00 0.51 ATOM 311 C VAL 20 17.763 -17.141 -19.547 1.00 0.46 ATOM 312 O VAL 20 17.421 -18.106 -18.892 1.00 0.60 ATOM 313 CB VAL 20 18.726 -15.508 -17.933 1.00 0.46 ATOM 314 CG1 VAL 20 19.513 -14.248 -18.276 1.00 1.11 ATOM 315 CG2 VAL 20 18.076 -15.336 -16.557 1.00 1.12 ATOM 316 H VAL 20 15.933 -16.265 -17.799 1.00 0.81 ATOM 317 HA VAL 20 17.760 -15.015 -19.781 1.00 0.57 ATOM 318 HB VAL 20 19.388 -16.354 -17.912 1.00 0.67 ATOM 319 HG1 VAL 20 19.937 -14.338 -19.265 1.00 1.78 ATOM 320 HG1 VAL 20 18.857 -13.392 -18.246 1.00 1.49 ATOM 321 HG1 VAL 20 20.309 -14.115 -17.559 1.00 1.64 ATOM 322 HG2 VAL 20 17.459 -16.195 -16.333 1.00 1.59 ATOM 323 HG2 VAL 20 18.844 -15.246 -15.801 1.00 1.61 ATOM 324 HG2 VAL 20 17.465 -14.446 -16.548 1.00 1.71 garlic-1.6/register.c0000644000076500007650000000452507627655547015134 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= register.c Purpose: Register the user - try to send short e-mail message to the author. Input: No input. Output: (1) E-mail send to the author. (2) Return value. Return value: (1) Positive on success. (2) Negative on failure. Notes: (1) This function tryes to send mail, but it does not try too hard. ========includes:============================================================*/ #include #include #include #include "defines.h" /*======register:============================================================*/ int Register_ (void) { char outfile_nameA[SHORTSTRINGSIZE]; char command_stringA[STRINGSIZE]; FILE *outfileP; int n; /* Open the output (message) file: */ do { /** The first attempt: **/ strcpy (outfile_nameA, "garlic_reg.txt"); if ((outfileP = fopen (outfile_nameA, "w")) != NULL) break; /** The second attempt: **/ strcpy (outfile_nameA, "/tmp/garlic_reg.txt"); if ((outfileP = fopen (outfile_nameA, "w")) != NULL) break; /** If this point is reached, both attempts failed: **/ printf ("Unable to prepare the message file - registration failed!\n"); return -1; } while (0); /* Write the message: */ fprintf (outfileP, "Hi!\n"); /* Close the file: */ fclose (outfileP); /* Send the message: */ do { /** The first attempt (no path): **/ strcpy (command_stringA, "mailx zucic@garlic.mefos.hr < "); strcat (command_stringA, outfile_nameA); n = system (command_stringA); if (n >= 0) break; /** The second attempt (using Digital Unix mailx pathname): **/ strcpy (command_stringA, "/bin/mailx zucic@garlic.mefos.hr < "); strcat (command_stringA, outfile_nameA); n = system (command_stringA); if (n >= 0) break; /** The third attempt (using SunOS mailx pathname): **/ strcpy (command_stringA, "/usr/bin/mailx zucic@garlic.mefos.hr < "); strcat (command_stringA, outfile_nameA); n = system (command_stringA); if (n >= 0) break; /** If this point is reached, all attempts to send mail failed: **/ remove (outfile_nameA); return -2; } while (0); /* Remove (delete) the message file: */ remove (outfile_nameA); /* If this point is reached, registration might be successful: */ return 1; } /*===========================================================================*/ garlic-1.6/comm_slab.c0000644000076500007650000001404007465733616015227 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= comm_slab.c Purpose: Execute slab command. Change slab mode or change the position of front or back slab surface. Input: (1) Pointer to MolComplexS structure, with macromol. complexes. (2) The number of macromolecular complexes. (3) Pointer to RuntimeS structure, with some runtime data. (4) Pointer to ConfigS structure, with configuration data. (5) Pointer to GUIS structure, with GUI data. (6) Pointer to NearestAtomS structure. (7) The number of pixels in the main window free area. (8) Pointer to refreshI. (9) String which contains slab surface specification and slab shift. Output: (1) Slab surfaces moved. (2) Return value. Return value: (1) Positive (command) code on success. (2) Negative (error) code on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "commands.h" #include "typedefs.h" /*======function prototypes:=================================================*/ char *ExtractToken_ (char *, int, char *, char *); int ChangeSlab_ (MolComplexS *, int, int); void MoveBackSlab_ (MolComplexS *, int, ConfigS *, double); void MoveFrontSlab_ (MolComplexS *, int, ConfigS *, double); size_t MainRefresh_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); int ControlRefresh_ (MolComplexS *, ConfigS *, GUIS *); /*======execute slab command:================================================*/ int CommandSlab_ (MolComplexS *mol_complexSP, int mol_complexesN, RuntimeS *runtimeSP, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int *refreshIP, char *stringP) { char *remainderP; char tokenA[STRINGSIZE]; int surfaceID; double shift; /* Extract the first token: */ remainderP = ExtractToken_ (tokenA, STRINGSIZE, stringP, " \t\n"); if (!remainderP) { strcpy (runtimeSP->messageA, "Slab specification incomplete!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_SLAB; } /* Switch slab off: */ if (strstr (tokenA, "OFF") == tokenA) { ChangeSlab_ (mol_complexSP, mol_complexesN, 0); (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); return COMMAND_SLAB; } /* Change slab to planar: */ else if (strstr (tokenA, "PLA") == tokenA) { ChangeSlab_ (mol_complexSP, mol_complexesN, 1); (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); return COMMAND_SLAB; } /* Change slab to spherical: */ else if (strstr (tokenA, "SPH") == tokenA) { ChangeSlab_ (mol_complexSP, mol_complexesN, 2); (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); return COMMAND_SLAB; } /* Change slab to semi-spherical: */ else if ((strstr (tokenA, "HALF-SPH") == tokenA) || (strstr (tokenA, "HALF_SPH") == tokenA)) { ChangeSlab_ (mol_complexSP, mol_complexesN, 3); (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); return COMMAND_SLAB; } /* Change slab to cylindrical: */ else if (strstr (tokenA, "CYL") == tokenA) { ChangeSlab_ (mol_complexSP, mol_complexesN, 4); (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); return COMMAND_SLAB; } /* Change slab to semi-cylindrical: */ else if ((strstr (tokenA, "HALF-CYL") == tokenA) || (strstr (tokenA, "HALF_CYL") == tokenA)) { ChangeSlab_ (mol_complexSP, mol_complexesN, 5); (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); return COMMAND_SLAB; } /* Identify the surface: */ else if (strstr (tokenA, "FRO") == tokenA) surfaceID = 1; else if (strstr (tokenA, "BAC") == tokenA) surfaceID = 2; else { strcpy (runtimeSP->messageA, "Bad surface (valid keywords are front and back)!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_BAD_SURFACE; } /* Extract the token which contains the shift: */ remainderP = ExtractToken_ (tokenA, STRINGSIZE, remainderP, " \t\n"); if (!remainderP) { strcpy (runtimeSP->messageA, "Slab shift missing!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_NO_SHIFT; } /* Extract the shift: */ if (sscanf (tokenA, "%lf", &shift) != 1) { strcpy (runtimeSP->messageA, "Slab specification is bad (unknown keyword used)!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_NO_SHIFT; } /* Move the specified slab surface: */ if (surfaceID == 1) { MoveFrontSlab_ (mol_complexSP, mol_complexesN, configSP, shift); } else { MoveBackSlab_ (mol_complexSP, mol_complexesN, configSP, shift); } /* Refresh the main window: */ (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); /* Refresh the control window: */ ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); /* Return positive value on success: */ return COMMAND_SLAB; } /*===========================================================================*/ garlic-1.6/list_exposed_polar.c0000644000076500007650000001331207747301540017161 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2003 Damir Zucic */ /*============================================================================= list_exposed_polar.c Purpose: List all polar residues exposed at the surface. As each residue will (generally) occur more than once in docking matrix, it is necessary to remove the redundant data to minimize the number of symbols which should be drawn. This function ignores apolar residues as they are not involved in hydrogen bonds. Input: (1) Pointer to RuntimeS structure. (2) The complex index (1 = bottom, 2 = top). Output: (1) The list of exposed polar residues will be prepared. (2) Return value. Return value: (1) Positive on success. (2) Negative on failure. Notes: (1) The number of exposed polar residues should be reset at the beginning of this function. (2) Indentation is exceptionally 4 spaces. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ void ErrorMessage_ (char *, char *, char *, char *, char *, char *, char *); int IsPolar_ (char *); /*======list exposed polar residues:=========================================*/ int ListExposedPolarResidues_ (RuntimeS *runtimeSP, int docking_complexI) { MolComplexS *curr_mol_complexSP; int *exposed_atomIP; ExposedResidueS *exposed_polarSP; int exposed_polarN = 0; int matrix_width; int rowI, columnI, combinedI; int *curr_cellP; int atomI; AtomS *curr_atomSP; char pure_residue_nameA[RESNAMESIZE]; char chainID; int residue_sequenceI; char residue_insertion_code; int residue_foundF; int exposed_polarI; ExposedResidueS *curr_exposedSP; int int_return_value; /* Check the complex index and prepare the pointers: */ if (docking_complexI == 1) { curr_mol_complexSP = runtimeSP->mol_complex1SP; exposed_atomIP = runtimeSP->exposed_atom1IP; exposed_polarSP = runtimeSP->exposed_polar1SP; runtimeSP->exposed_polar1N = 0; } else if (docking_complexI == 2) { curr_mol_complexSP = runtimeSP->mol_complex2SP; exposed_atomIP = runtimeSP->exposed_atom2IP; exposed_polarSP = runtimeSP->exposed_polar2SP; runtimeSP->exposed_polar2N = 0; } else { ErrorMessage_ ("garlic", "ListExposedResidues_", "", "Bad macromolecular complex index!\n", "", "", ""); return -1; } /* Prepare the matrix width: */ matrix_width = runtimeSP->docking_matrix_width; /* Scan docking matrix: */ for (rowI = 0; rowI < matrix_width; rowI++) { for (columnI = 0; columnI < matrix_width; columnI++) { /* Prepare the combined index (the actual array index): */ combinedI = rowI * matrix_width + columnI; /* Prepare the pointer to the current cell (matrix element): */ curr_cellP = exposed_atomIP + combinedI; /* Prepare and check the atomic index: */ atomI = *curr_cellP; if (atomI < 0) continue; /* Check is that atom present at all in the current complex: */ if (atomI >= (int) curr_mol_complexSP->atomsN) continue; /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Copy the residue data associated with the current cell: */ strcpy (pure_residue_nameA, curr_atomSP->raw_atomS.pure_residue_nameA); chainID = curr_atomSP->raw_atomS.chainID; residue_sequenceI = curr_atomSP->raw_atomS.residue_sequenceI; residue_insertion_code = curr_atomSP->raw_atomS.residue_insertion_code; /* Scan the list of exposed polar residues; */ /* the current residue may be there already: */ residue_foundF = 0; for (exposed_polarI = 0; exposed_polarI < exposed_polarN; exposed_polarI++) { /* Pointer to the current exposed polar residue: */ curr_exposedSP = exposed_polarSP + exposed_polarI; if (curr_exposedSP->residue_sequenceI != residue_sequenceI) continue; /* Compare chain identifiers: */ if (curr_exposedSP->chainID != chainID) continue; /* Compare residue names: */ if (strcmp (curr_exposedSP->pure_residue_nameA, pure_residue_nameA) != 0) continue; /* Compare residue insertion codes: */ if (curr_exposedSP->residue_insertion_code != residue_insertion_code) continue; /* If this point is reached, residue is found: */ residue_foundF = 1; break; } /* If residue was found before, check the next cell: */ if (residue_foundF) continue; /* If this point is reached, the residue associated with */ /* the current cell was not found before. Check is it polar: */ if ((int_return_value = IsPolar_ (pure_residue_nameA)) < 0) continue; /* Well, if this point is reached, residue is polar and found */ /* for the first time in docking matrix. Add it to the list: */ curr_exposedSP = exposed_polarSP + exposed_polarN; strcpy (curr_exposedSP->pure_residue_nameA, pure_residue_nameA); curr_exposedSP->chainID = chainID; curr_exposedSP->residue_sequenceI = residue_sequenceI; curr_exposedSP->residue_insertion_code = residue_insertion_code; /* Initialize donorI: */ curr_exposedSP->donorI = int_return_value; /* Store the atomic index as the representative */ /* index. This is a temporary setting; the true */ /* representative atom will be identified later. */ curr_exposedSP->representative_atomI = atomI; /* Increase the counter: */ exposed_polarN++; } } /* Store the number of exposed residues: */ if (docking_complexI == 1) runtimeSP->exposed_polar1N = exposed_polarN; else runtimeSP->exposed_polar2N = exposed_polarN; /* Return positive value on success: */ return 1; } /*===========================================================================*/ garlic-1.6/extract_index.c0000644000076500007650000000234107162471166016126 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= extract_index.c Purpose: Extract index from string. Input: Input string pointer. Output: Return value. Return value: (1) Integer read from string, on success (positive or zero). (2) Negative on failure. ========includes:============================================================*/ #include #include #include #include "defines.h" /*======extract index from a string:=========================================*/ int ExtractIndex_ (char *input_stringP) { int index; char copyA[SHORTSTRINGSIZE]; char *P; int n; /* Copy the input string: */ strncpy (copyA, input_stringP, SHORTSTRINGSIZE - 1); copyA[SHORTSTRINGSIZE - 1] = '\0'; /* Replace each non-numeric character except minus sign with space: */ P = copyA; while ((n = *P++) != '\0') if (!isdigit (n) && (n != '-')) *(P - 1) = ' '; /* Try to read one integer: */ if (sscanf (copyA, "%d", &index) != 1) return -1; /* Check the sign: */ if (index < 0) return -2; /* If everything worked fine, return the extracted index: */ return index; } /*===========================================================================*/ garlic-1.6/mix_colors.c0000644000076500007650000001524707466710275015460 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2002 Damir Zucic */ /*============================================================================= mix_colors.c Purpose: Mix two color schemes to prepare colors for a given atom. Input: (1) Pointer to AtomS structure. (2) Pointer to ColorSchemeS structure, with the first color scheme. (3) Pointer to ColorSchemeS structure, with the second color scheme. (4) Scale factor (double). (5) Pointer to GUIS structure. Output: (1) RGBS data set in AtomS structure. (1) Return value. Return value: (1) Positive on success. (2) Negative on failure. Notes: (1) The input color schemes should contain enough data to define two color surfaces. =============================================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======mix (combine) two color schemes:=====================================*/ int MixColors_ (AtomS *curr_atomSP, ColorSchemeS *scheme1SP, ColorSchemeS *scheme2SP, double scale_factor, GUIS *guiSP) { static double color1, delta_color, color; /* Check color schemes - both should contain data for two color surfaces: */ if (scheme1SP->surfacesN < 2) return -1; if (scheme2SP->surfacesN < 2) return -2; /* Colors at the surface 0 (front surface): */ /** Left color: **/ /*** Red component: ***/ color1 = (double) scheme1SP->left_rgbSA[0].red; delta_color = (double) scheme2SP->left_rgbSA[0].red - (double) scheme1SP->left_rgbSA[0].red; color = color1 + scale_factor * delta_color; curr_atomSP->left_rgbSA[0].red = (unsigned short) color; /*** Green component: ***/ color1 = (double) scheme1SP->left_rgbSA[0].green; delta_color = (double) scheme2SP->left_rgbSA[0].green - (double) scheme1SP->left_rgbSA[0].green; color = color1 + scale_factor * delta_color; curr_atomSP->left_rgbSA[0].green = (unsigned short) color; /*** Blue component: ***/ color1 = (double) scheme1SP->left_rgbSA[0].blue; delta_color = (double) scheme2SP->left_rgbSA[0].blue - (double) scheme1SP->left_rgbSA[0].blue; color = color1 + scale_factor * delta_color; curr_atomSP->left_rgbSA[0].blue = (unsigned short) color; /** Middle color: **/ /*** Red component: ***/ color1 = (double) scheme1SP->middle_rgbSA[0].red; delta_color = (double) scheme2SP->middle_rgbSA[0].red - (double) scheme1SP->middle_rgbSA[0].red; color = color1 + scale_factor * delta_color; curr_atomSP->middle_rgbSA[0].red = (unsigned short) color; /*** Green component: ***/ color1 = (double) scheme1SP->middle_rgbSA[0].green; delta_color = (double) scheme2SP->middle_rgbSA[0].green - (double) scheme1SP->middle_rgbSA[0].green; color = color1 + scale_factor * delta_color; curr_atomSP->middle_rgbSA[0].green = (unsigned short) color; /*** Blue component: ***/ color1 = (double) scheme1SP->middle_rgbSA[0].blue; delta_color = (double) scheme2SP->middle_rgbSA[0].blue - (double) scheme1SP->middle_rgbSA[0].blue; color = color1 + scale_factor * delta_color; curr_atomSP->middle_rgbSA[0].blue = (unsigned short) color; /** Right color: **/ /*** Red component: ***/ color1 = (double) scheme1SP->right_rgbSA[0].red; delta_color = (double) scheme2SP->right_rgbSA[0].red - (double) scheme1SP->right_rgbSA[0].red; color = color1 + scale_factor * delta_color; curr_atomSP->right_rgbSA[0].red = (unsigned short) color; /*** Green component: ***/ color1 = (double) scheme1SP->right_rgbSA[0].green; delta_color = (double) scheme2SP->right_rgbSA[0].green - (double) scheme1SP->right_rgbSA[0].green; color = color1 + scale_factor * delta_color; curr_atomSP->right_rgbSA[0].green = (unsigned short) color; /*** Blue component: ***/ color1 = (double) scheme1SP->right_rgbSA[0].blue; delta_color = (double) scheme2SP->right_rgbSA[0].blue - (double) scheme1SP->right_rgbSA[0].blue; color = color1 + scale_factor * delta_color; curr_atomSP->right_rgbSA[0].blue = (unsigned short) color; /* Colors at the surface 1 (back surface): */ /** Left color: **/ /*** Red component: ***/ color1 = (double) scheme1SP->left_rgbSA[1].red; delta_color = (double) scheme2SP->left_rgbSA[1].red - (double) scheme1SP->left_rgbSA[1].red; color = color1 + scale_factor * delta_color; curr_atomSP->left_rgbSA[1].red = (unsigned short) color; /*** Green component: ***/ color1 = (double) scheme1SP->left_rgbSA[1].green; delta_color = (double) scheme2SP->left_rgbSA[1].green - (double) scheme1SP->left_rgbSA[1].green; color = color1 + scale_factor * delta_color; curr_atomSP->left_rgbSA[1].green = (unsigned short) color; /*** Blue component: ***/ color1 = (double) scheme1SP->left_rgbSA[1].blue; delta_color = (double) scheme2SP->left_rgbSA[1].blue - (double) scheme1SP->left_rgbSA[1].blue; color = color1 + scale_factor * delta_color; curr_atomSP->left_rgbSA[1].blue = (unsigned short) color; /** Middle color: **/ /*** Red component: ***/ color1 = (double) scheme1SP->middle_rgbSA[1].red; delta_color = (double) scheme2SP->middle_rgbSA[1].red - (double) scheme1SP->middle_rgbSA[1].red; color = color1 + scale_factor * delta_color; curr_atomSP->middle_rgbSA[1].red = (unsigned short) color; /*** Green component: ***/ color1 = (double) scheme1SP->middle_rgbSA[1].green; delta_color = (double) scheme2SP->middle_rgbSA[1].green - (double) scheme1SP->middle_rgbSA[1].green; color = color1 + scale_factor * delta_color; curr_atomSP->middle_rgbSA[1].green = (unsigned short) color; /*** Blue component: ***/ color1 = (double) scheme1SP->middle_rgbSA[1].blue; delta_color = (double) scheme2SP->middle_rgbSA[1].blue - (double) scheme1SP->middle_rgbSA[1].blue; color = color1 + scale_factor * delta_color; curr_atomSP->middle_rgbSA[1].blue = (unsigned short) color; /** Right color: **/ /*** Red component: ***/ color1 = (double) scheme1SP->right_rgbSA[1].red; delta_color = (double) scheme2SP->right_rgbSA[1].red - (double) scheme1SP->right_rgbSA[1].red; color = color1 + scale_factor * delta_color; curr_atomSP->right_rgbSA[1].red = (unsigned short) color; /*** Green component: ***/ color1 = (double) scheme1SP->right_rgbSA[1].green; delta_color = (double) scheme2SP->right_rgbSA[1].green - (double) scheme1SP->right_rgbSA[1].green; color = color1 + scale_factor * delta_color; curr_atomSP->right_rgbSA[1].green = (unsigned short) color; /*** Blue component: ***/ color1 = (double) scheme1SP->right_rgbSA[1].blue; delta_color = (double) scheme2SP->right_rgbSA[1].blue - (double) scheme1SP->right_rgbSA[1].blue; color = color1 + scale_factor * delta_color; curr_atomSP->right_rgbSA[1].blue = (unsigned short) color; /* Return positive value on success: */ return 1; } /*===========================================================================*/ garlic-1.6/small_atoms.c0000644000076500007650000003134707747302015015603 0ustar zuciczucic00000000000000/* Copyright (C) 2002-2003 Damir Zucic */ /*============================================================================= small_atoms.c Purpose: Draw small atoms (small style). Input: (1) Pointer to MolComplexS structure. (2) Number of macromolecular complexes. (3) Pointer to ConfigS structure, with configuration data. (4) Pointer to GUIS structure. (5) Pointer to NearestAtomS structure, with information about the atom occupying the given pixel. (6) The number of pixels in the main window free area. (7) The refreshI, used to check the NearestAtomS associated with a given pixel. Output: (1) Small spheres drawn to the hidden pixmap. (2) Return value. Return value: (1) Positive always (trivial). Notes: (1) Indentation is exceptionally 4 spaces. =============================================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ unsigned long SpacefillColor_ (AtomS *, GUIS *, double); /*======draw atoms as spheres, small style:==================================*/ int DrawSmall_ (MolComplexS *mol_complexSP, int mol_complexesN, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int refreshI) { int imageI, imagesN; double scale_factor, user_atomic_position; int left_edge[2], right_edge[2]; int mol_complexI; MolComplexS *curr_mol_complexSP; size_t atomsN, atomI; AtomS *curr_atomSP; int screen_x0, screen_y0; double radius, radius_squared; double denominator, reciprocal_denominator; int screen_radius; long screen_radius_squared; int screen_x1, screen_y1, screen_x2, screen_y2; int screen_x, screen_y; long delta_x, delta_y, distance_squared; double z0, front_z, delta_z, z; size_t pixelI; NearestAtomS *curr_pixelSP; double denominator2, reciprocal_denominator2; double rho_squared; VectorS vectorS; double abs_value, abs_value_squared; double scalar_product, cos_angle; unsigned long colorID; int bondI; /* Initialize the bond index. The negative value means that pixels */ /* filled in this function are not a part of any chemical bond. */ bondI = -1; /* Number of images: */ if (configSP->stereoF) imagesN = 2; else imagesN = 1; /* The auxiliary scale factor: */ scale_factor = configSP->user_screen_atomic_distance * configSP->atomic_to_screen_scale_x; /* Prepare the user position in atomic coordinates: */ user_atomic_position = configSP->user_atomic_position; /* Left and right image edge (in stereo mode there are two images): */ left_edge[0] = configSP->image_screen_x0[0]; right_edge[0] = configSP->image_screen_x1[0]; left_edge[1] = configSP->image_screen_x0[1]; right_edge[1] = configSP->image_screen_x1[1]; /*------first pass - fill NearestAtomS array with planar atoms:--------------*/ /* Draw each macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Prepare and check the number of atoms: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Draw atoms which have the given style: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Check style: */ if (curr_atomSP->raw_atomS.atom_styleI != SMALL_ATOM) continue; /* Check is atom hidden: */ if (curr_atomSP->hiddenF) continue; /* Check is atom inside slab: */ if (!curr_atomSP->inside_slabF) continue; /* Check is atom inside window: */ if (!curr_atomSP->inside_windowF) continue; /* Small radius, in atomic units: */ radius = curr_atomSP->raw_atomS.small_radius; /* The y coordinate of atomic center, in screen units: */ screen_y0 = curr_atomSP->raw_atomS.screen_y; /* Prepare one image (mono) or two images (stereo): */ for (imageI = 0; imageI < imagesN; imageI++) { /* The z coordinate of atomic center, in atomic units: */ z0 = curr_atomSP->raw_atomS.z[imageI]; /* Prepare the factor required for the projection of radius: */ denominator = z0 - user_atomic_position; if (denominator == 0.0) continue; reciprocal_denominator = 1.0 / denominator; /* Small radius in screen units: */ screen_radius = (int) (radius * scale_factor * reciprocal_denominator + 0.5); /* Screen radius squared (used to improve speed): */ screen_radius_squared = (long) screen_radius * (long) screen_radius; /* The x coordinate of atomic center, in screen units: */ screen_x0 = curr_atomSP->raw_atomS.screen_x[imageI]; /* Define the bounding rectangle: */ screen_x1 = screen_x0 - screen_radius; screen_y1 = screen_y0 - screen_radius; screen_x2 = screen_x0 + screen_radius; screen_y2 = screen_y0 + screen_radius; /* Horizontal scan: */ for (screen_x = screen_x1; screen_x <= screen_x2; screen_x++) { /* Check horizontal position: */ if (screen_x < left_edge[imageI]) continue; if (screen_x >= right_edge[imageI]) continue; /* Vertical scan: */ for (screen_y = screen_y1; screen_y <= screen_y2; screen_y++) { /* Check vertical position: */ if (screen_y < 0) continue; if (screen_y >= (int) guiSP->main_win_free_area_height) { continue; } /* Check distance from the circle center: */ delta_x = (long) (screen_x - screen_x0); delta_y = (long) (screen_y - screen_y0); distance_squared = delta_x * delta_x + delta_y * delta_y; if (distance_squared > screen_radius_squared) continue; /* Prepare index to the array */ /* of NearestAtomS structures: */ pixelI = guiSP->main_win_free_area_width * screen_y + screen_x; /* Check the pixel index: */ if (pixelI >= pixelsN) continue; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = nearest_atomSP + pixelI; /* Check was this pixel used already in */ /* this drawing step; if it was, compare */ /* the z value of the current atom with z */ /* value previously stored to this pixel: */ if (refreshI == curr_pixelSP->last_refreshI) { if (z0 > curr_pixelSP->z) continue; } /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = SMALL_ATOM; curr_pixelSP->last_refreshI = refreshI; curr_pixelSP->mol_complexI = mol_complexI; curr_pixelSP->atomI = atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = z0; } } } /* imageI loop */ } /* atomI loop */ } /* mol_complexI loop */ /*------second pass - draw spherical atoms:----------------------------------*/ /* Draw each macromolecular complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { /* Pointer to current macromolecular complex: */ curr_mol_complexSP = mol_complexSP + mol_complexI; /* Prepare and check the number of atoms: */ atomsN = curr_mol_complexSP->atomsN; if (atomsN == 0) continue; /* Draw atoms which have the given style: */ for (atomI = 0; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /* Check style: */ if (curr_atomSP->raw_atomS.atom_styleI != SMALL_ATOM) continue; /* Check is atom hidden: */ if (curr_atomSP->hiddenF) continue; /* Check is atom inside slab: */ if (!curr_atomSP->inside_slabF) continue; /* Check is atom inside window: */ if (!curr_atomSP->inside_windowF) continue; /* Small radius, in atomic units: */ radius = curr_atomSP->raw_atomS.small_radius; /* Squared small radius: */ radius_squared = radius * radius; /* The y coordinate of atomic center, in screen units: */ screen_y0 = curr_atomSP->raw_atomS.screen_y; /* Prepare one image (mono) or two images (stereo): */ for (imageI = 0; imageI < imagesN; imageI++) { /* The z coordinate of atomic center, in atomic units: */ z0 = curr_atomSP->raw_atomS.z[imageI]; /* The z coordinate of the nearest */ /* point of a given atom (sphere): */ front_z = z0 - radius; /* Prepare the factor required for the projection of radius: */ denominator = z0 - user_atomic_position; if (denominator == 0.0) continue; reciprocal_denominator = 1.0 / denominator; /* Small radius in screen units: */ screen_radius = (int) (radius * scale_factor * reciprocal_denominator + 0.5); /* Square of the small radius (in screen units): */ screen_radius_squared = (long) screen_radius * (long) screen_radius; /* Reciprocal value will be used to improve performance: */ denominator2 = (double) screen_radius_squared; if (denominator2 == 0.0) continue; reciprocal_denominator2 = 1.0 / denominator2; /* The x coordinate of atomic center, in screen units: */ screen_x0 = curr_atomSP->raw_atomS.screen_x[imageI]; /* Define the bounding rectangle: */ screen_x1 = screen_x0 - screen_radius; screen_y1 = screen_y0 - screen_radius; screen_x2 = screen_x0 + screen_radius; screen_y2 = screen_y0 + screen_radius; /* Horizontal scan: */ for (screen_x = screen_x1; screen_x <= screen_x2; screen_x++) { /* Check horizontal position: */ if (screen_x < left_edge[imageI]) continue; if (screen_x > right_edge[imageI]) continue; /* Vertical scan: */ for (screen_y = screen_y1; screen_y <= screen_y2; screen_y++) { /* Check vertical position: */ if (screen_y < 0) continue; if (screen_y >= (int) guiSP->main_win_free_area_height) { continue; } /* Check distance from the circle center: */ delta_x = (long) (screen_x - screen_x0); delta_y = (long) (screen_y - screen_y0); distance_squared = delta_x * delta_x + delta_y * delta_y; if (distance_squared > screen_radius_squared) continue; /* Prepare index to the array */ /* of NearestAtomS structures: */ pixelI = guiSP->main_win_free_area_width * screen_y + screen_x; /* Check the pixel index: */ if (pixelI >= pixelsN) continue; /* Pointer to NearestAtomS struct. */ /* assigned to current coordinates: */ curr_pixelSP = nearest_atomSP + pixelI; /* Check z value (this is just a quick check): */ if (refreshI == curr_pixelSP->last_refreshI) { if (front_z > curr_pixelSP->z) continue; } /* Calculate the accurate z value: */ rho_squared = radius_squared * (double) distance_squared * reciprocal_denominator2; delta_z = sqrt (fabs (radius_squared - rho_squared)); z = z0 - delta_z; /* Check z value (precise check): */ if (refreshI == curr_pixelSP->last_refreshI) { if (z > curr_pixelSP->z) continue; } /* The vector from sphere center to the current pixel: */ vectorS.x = (double) delta_x; vectorS.y = (double) delta_y; vectorS.z = - sqrt (fabs (screen_radius_squared - vectorS.x * vectorS.x - vectorS.y * vectorS.y)); abs_value_squared = vectorS.x * vectorS.x + vectorS.y * vectorS.y + vectorS.z * vectorS.z; abs_value = sqrt (abs_value_squared); /* The scalar product between this */ /* vector and light source vector: */ scalar_product = vectorS.x * configSP->light_vectorS.x + vectorS.y * configSP->light_vectorS.y + vectorS.z * configSP->light_vectorS.z; /* Cosine of the angle between the vector to the */ /* current pixel and the light source unit vector: */ if (abs_value == 0.0) cos_angle = 0.0; else cos_angle = scalar_product / abs_value; /* Prepare color: */ colorID = SpacefillColor_ (curr_atomSP, guiSP, cos_angle); XSetForeground (guiSP->displaySP, guiSP->theGCA[0], colorID); XDrawPoint (guiSP->displaySP, guiSP->main_hidden_pixmapID, guiSP->theGCA[0], screen_x, screen_y); /* Refresh the content of NearestAtomS */ /* array associated with this pixel: */ curr_pixelSP->styleI = SMALL_ATOM; curr_pixelSP->last_refreshI = refreshI; curr_pixelSP->mol_complexI = mol_complexI; curr_pixelSP->atomI = atomI; curr_pixelSP->bondI = bondI; curr_pixelSP->z = z; curr_pixelSP->colorID = colorID; } } } /* imageI loop */ } /* atomI loop */ } /* mol_complexI loop */ /*---------------------------------------------------------------------------*/ /* Return positive value (trivial): */ return 1; } /*===========================================================================*/ garlic-1.6/copy_sec_structure.c0000644000076500007650000000307707260557110017211 0ustar zuciczucic00000000000000/* Copyright (C) 2001 Damir Zucic */ /*============================================================================= copy_sec_structure.c Purpose: Copy the secondary structure from the general purpose (main) buffer to the reference buffer. Input: (1) Pointer to RuntimeS structure. Output: (1) Secondary structure copyed to the reference buffer. (2) Return value. Return value: (1) The number of residues in both buffers. ========includes:============================================================*/ #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======copy secondary structure to reference buffer:========================*/ int CopySecondaryStructure_ (RuntimeS *runtimeSP) { int sec_structure_length; int residueI; /* Copy the number of residues: */ sec_structure_length = runtimeSP->sec_structure_length; runtimeSP->reference_sec_str_length = sec_structure_length; /* Initialize the reference buffer (use the code for extended conformation): */ for (residueI = 0; residueI < MAXRESIDUES; residueI++) { *(runtimeSP->reference_sec_structureP + residueI) = 'E'; } /* Copy the secondary structure codes: */ for (residueI = 0; residueI < sec_structure_length; residueI++) { *(runtimeSP->reference_sec_structureP + residueI) = *(runtimeSP->sec_structureP + residueI); } /* Return the number of residues in both secondary structure buffers: */ return sec_structure_length; } /*===========================================================================*/ garlic-1.6/probe.c0000644000076500007650000000652607606137054014403 0ustar zuciczucic00000000000000/* Copyright (C) 2002-2003 Damir Zucic */ /*============================================================================= probe.c Purpose: Execute probe command: change the radius of the bond probe, for all caught complexes. Do not change default probe radius. This probe is used to draw nice bonds. It is not used to generate molecular surfaces: each surface has its own probe. Default (hard-coded) value is 0.80 angstroms. Each structure has its own probe. Input: (1) Pointer to MolComplexS structure. (2) The number of macromolecular complexes. (3) Pointer to RuntimeS structure. (4) Pointer to ConfigS structure. (5) Pointer to GUIS structure. (6) Pointer to NearestAtomS structure. (7) The number of pixels in the main window free area. (8) Pointer to refreshI. (9) Pointer to the remainder of the command string. Output: (1) The bond probe radius set. (2) Return value. Return value: (1) Positive (command) code on success. (2) Negative (error) code on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include #include "defines.h" #include "commands.h" #include "typedefs.h" /*======function prototypes:=================================================*/ size_t MainRefresh_ (MolComplexS *, int, RuntimeS *, ConfigS *, GUIS *, NearestAtomS *, size_t, unsigned int); int ControlRefresh_ (MolComplexS *, ConfigS *, GUIS *); /*======execute probe command:===============================================*/ int Probe_ (MolComplexS *mol_complexSP, int mol_complexesN, RuntimeS *runtimeSP, ConfigS *configSP, GUIS *guiSP, NearestAtomS *nearest_atomSP, size_t pixelsN, unsigned int *refreshIP, char *stringP) { char *P; int n; double value; int mol_complexI; MolComplexS *curr_mol_complexSP; /* Replace each non-numeric character (except */ /* minus sign and decimal point) with space: */ P = stringP; while ((n = *P++) != '\0') { if (!isdigit (n) && (n != '-') && (n != '.')) *(P - 1) = ' '; } /* Try to extract the bond probe radius: */ if (sscanf (stringP, "%lf", &value) != 1) { strcpy (runtimeSP->messageA, "Failed to extract the bond probe radius!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_PROBE; } /* Check the bond probe radius (must be positive): */ if (value < 0.0) { strcpy (runtimeSP->messageA, "Positive value expected!"); runtimeSP->message_length = strlen (runtimeSP->messageA); return ERROR_PROBE; } /* On success, set the bond probe radius for each caught complex: */ for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++) { curr_mol_complexSP = mol_complexSP + mol_complexI; if (curr_mol_complexSP->catchF == 0) continue; curr_mol_complexSP->bond_probe_radius = value; } /* Refresh the main window: */ (*refreshIP)++; MainRefresh_ (mol_complexSP, mol_complexesN, runtimeSP, configSP, guiSP, nearest_atomSP, pixelsN, *refreshIP); /* Refresh the control window: */ ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP); /* Return the command code: */ return COMMAND_PROBE; } /*===========================================================================*/ garlic-1.6/init_header.c0000644000076500007650000000224607065471577015554 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= init_header.c Purpose: Initialize offsets in HeaderS structure. Input: (1) Pointer to HeaderS structure. Output: (1) HeaderS structure initialized. Return value: No return value. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======initialize offsets in HeaderS structure:=============================*/ void InitializeHeader_ (HeaderS *hSP) { /* Set offsets: */ hSP->header_offset = 0; hSP->title_offset = hSP->header_offset + MAXHEADERLINES * HEADERLINESIZE; hSP->compnd_offset = hSP->title_offset + MAXTITLELINES * HEADERLINESIZE; hSP->source_offset = hSP->compnd_offset + MAXCOMPNDLINES * HEADERLINESIZE; hSP->expdta_offset = hSP->source_offset + MAXSOURCELINES * HEADERLINESIZE; hSP->author_offset = hSP->expdta_offset + MAXEXPDTALINES * HEADERLINESIZE; } /*===========================================================================*/ garlic-1.6/prepare_backbone.c0000644000076500007650000001266207747301256016557 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2003 Damir Zucic */ /*============================================================================= prepare_backbone.c Purpose: Prepare the array of BackboneS structures: extract data about CA atoms. Check distances between neighbouring CA atoms. Set flags. Input: (1) Pointer to MolComplexS structure. (2) Pointer to ConfigS structure. Output: (1) The array of BackboneS structures allocated and filled with data about C-alpha atoms. (2) Return value. Return value: (1) Positive on success. (2) Zero if there are no atoms. (3) Negative on failure (memory allocation may fail). ========includes:============================================================*/ #include #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ void ErrorMessage_ (char *, char *, char *, char *, char *, char *, char *); /*======prepare backbone data:===============================================*/ int PrepareBackbone_ (MolComplexS *mol_complexSP, ConfigS *configSP) { size_t atomI, atomsN; AtomS *curr_atomSP; int c_alphaN = 0; size_t elementsN; size_t struct_size; size_t mem_size; BackboneS *curr_backboneSP; int c_alphaI; size_t atom1I, atom2I; AtomS *atom0SP, *atom1SP, *atom2SP; double x0, y0, z0, x1, y1, z1, x2, y2, z2, delta_x, delta_y, delta_z; double d1_squared, d2_squared; double max_dist_squared; /* Initialize the number of CA atoms: */ mol_complexSP->c_alphaN = 0; /* Return zero if there are no atoms in this macromolecular complex: */ atomsN = mol_complexSP->atomsN; if (atomsN == 0) return 0; /* The maximal distance squared: */ max_dist_squared = configSP->CA_CA_dist_max_squared; /* Count CA atoms: */ for (atomI = 0; atomI < atomsN; atomI++) { /** Current AtomS pointer: **/ curr_atomSP = mol_complexSP->atomSP + atomI; /** Check the purified atom name: **/ if (strcmp (curr_atomSP->raw_atomS.pure_atom_nameA, "CA") == 0) { c_alphaN++; } } /* Allocate memory for the array of BackboneS structures: */ /** Add some extra space: **/ elementsN = c_alphaN + 100; struct_size = sizeof (BackboneS); mem_size = elementsN * struct_size; /** Allocate memory: **/ mol_complexSP->backboneSP = (BackboneS *) calloc (elementsN, struct_size); /** If something goes wrong, inform user and return negative value: **/ if (mol_complexSP->backboneSP == NULL) { ErrorMessage_ ("garlic", "PrepareBackbone_", "", "Failed to allocate memory for BackboneS array!\n", "", "", ""); mem_size = elementsN * struct_size; fprintf (stderr, "A total of %d bytes required.\n", mem_size); return -1; } /* Initialize the BackboneS pointer: */ curr_backboneSP = mol_complexSP->backboneSP; /* Scan the macromolecular complex again and extract required data: */ for (atomI = 0; atomI < atomsN; atomI++) { /** Pointer to the current atom: **/ curr_atomSP = mol_complexSP->atomSP + atomI; /** Check the purified atom name: **/ if (strcmp (curr_atomSP->raw_atomS.pure_atom_nameA, "CA") != 0) continue; /** Copy the index of the current atom: **/ curr_backboneSP->c_alphaI = atomI; /** Update the BackboneS pointer: */ curr_backboneSP++; } /* Copy the number of CA atoms: */ mol_complexSP->c_alphaN = c_alphaN; /* Check distances between neighbouring CA atoms: */ for (c_alphaI = 0; c_alphaI < c_alphaN; c_alphaI++) { /** Pointer to the current BackboneS: **/ curr_backboneSP = mol_complexSP->backboneSP + c_alphaI; /** Pointer to the current CA atom: **/ atom0SP = mol_complexSP->atomSP + curr_backboneSP->c_alphaI; /** Position of the current CA atom: **/ x0 = atom0SP->raw_atomS.x[0]; y0 = atom0SP->raw_atomS.y; z0 = atom0SP->raw_atomS.z[0]; /** Check distances between current CA, previous CA and next CA: **/ /*** For the first CA, the previous CA does not exist: ***/ if (c_alphaI > 0) { atom1I = (curr_backboneSP - 1)->c_alphaI; atom1SP = mol_complexSP->atomSP + atom1I; x1 = atom1SP->raw_atomS.x[0]; y1 = atom1SP->raw_atomS.y; z1 = atom1SP->raw_atomS.z[0]; delta_x = x1 - x0; delta_y = y1 - y0; delta_z = z1 - z0; d1_squared = delta_x * delta_x + delta_y * delta_y + delta_z * delta_z; if (d1_squared <= max_dist_squared) { curr_backboneSP->previous_c_alphaF = 1; curr_backboneSP->previous_c_alphaI = atom1I; } else curr_backboneSP->previous_c_alphaF = 0; } /*** For the last CA, the next CA does not exist: ***/ if (c_alphaI < c_alphaN - 1) { atom2I = (curr_backboneSP + 1)->c_alphaI; atom2SP = mol_complexSP->atomSP + atom2I; x2 = atom2SP->raw_atomS.x[0]; y2 = atom2SP->raw_atomS.y; z2 = atom2SP->raw_atomS.z[0]; delta_x = x2 - x0; delta_y = y2 - y0; delta_z = z2 - z0; d2_squared = delta_x * delta_x + delta_y * delta_y + delta_z * delta_z; if (d2_squared <= max_dist_squared) { curr_backboneSP->next_c_alphaF = 1; curr_backboneSP->next_c_alphaI = atom2I; } else curr_backboneSP->next_c_alphaF = 0; } } /* Initialize backbone drawing style and hide all backbone elements: */ for (c_alphaI = 0; c_alphaI < c_alphaN; c_alphaI++) { curr_backboneSP = mol_complexSP->backboneSP + c_alphaI; curr_backboneSP->backbone_styleI = -1; curr_backboneSP->hiddenF = 1; } /* Return positive value on success: */ return 1; } /*===========================================================================*/ garlic-1.6/alloc_config.c0000644000076500007650000000257507463606674015725 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2002 Damir Zucic */ /*============================================================================= alloc_config.c Purpose: Allocate memory for ConfigS structure. The calloc function is used to zero-initialize all bytes. Input: No arguments. Output: (1) Memory for ConfigS structure allocated. (2) Return value. Return value: (1) Pointer to allocated memory, on success. (2) NULL on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ void ErrorMessage_ (char *, char *, char *, char *, char *, char *, char *); /*======allocate memory for ConfigS structure:===============================*/ ConfigS *AllocateConfigS_ (void) { static ConfigS *configSP; /* Allocate zero-initialized memory: */ configSP = (ConfigS *) calloc (1, sizeof (ConfigS)); if (configSP == NULL) { ErrorMessage_ ("garlic", "AllocateConfigS_", "", "Failed to allocate memory for Config structure!\n", "", "", ""); } /* Return pointer to allocated memory (NULL on failure): */ return configSP; } /*===========================================================================*/ garlic-1.6/chi3_from_cbcgcdce.c0000644000076500007650000000727307341276674016752 0ustar zuciczucic00000000000000/* Copyright (C) 2001 Damir Zucic */ /*============================================================================= chi3_from_cbcgcdce.c Purpose: Calculate dihedral angle chi3, using CB, CG, CD and CE coordinates. Input: (1) Pointer to AtomS structure, pointing to the first atom of the current macromolecular complex. (2) Index of the first atom of the current residue. (3) Index of the last atom of the currrent residue. Output: Return value. Return value: (1) Dihedral angle chi3, on success. (2) BADDIHEDANGLE on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int ExtractFourAtoms_ (VectorS *, VectorS *, VectorS *, VectorS *, char *, char *, char *, char *, AtomS *, size_t, size_t); void VectorProduct_ (VectorS *, VectorS *, VectorS *); double AbsoluteValue_ (VectorS *); double ScalarProduct_ (VectorS *, VectorS *); /*======calculate chi3 from CB, CG, CD and CE:===============================*/ double Chi3FromCBCGCDCE_ (AtomS *atomSP, size_t atom_startI, size_t atom_endI) { static VectorS CB_vectorS, CG_vectorS, CD_vectorS, CE_vectorS; int n; VectorS CG_CB_vectorS, CG_CD_vectorS; VectorS CD_CG_vectorS, CD_CE_vectorS; VectorS u1S, u2S; VectorS v1S, v2S; double denom, ratio, alpha; double chi3; /* Extract CB, CG, CD and CE coordinates: */ n = ExtractFourAtoms_ (&CB_vectorS, &CG_vectorS, &CD_vectorS, &CE_vectorS, "CB", "CG", "CD", "CE", atomSP, atom_startI, atom_endI); /* All four atoms are required to calculate the angle chi3: */ if (n < 4) return BADDIHEDANGLE; /* The first pair of auxiliary vectors: */ CG_CB_vectorS.x = CB_vectorS.x - CG_vectorS.x; CG_CB_vectorS.y = CB_vectorS.y - CG_vectorS.y; CG_CB_vectorS.z = CB_vectorS.z - CG_vectorS.z; CG_CD_vectorS.x = CD_vectorS.x - CG_vectorS.x; CG_CD_vectorS.y = CD_vectorS.y - CG_vectorS.y; CG_CD_vectorS.z = CD_vectorS.z - CG_vectorS.z; /* The second pair of auxiliary vectors: */ CD_CG_vectorS.x = CG_vectorS.x - CD_vectorS.x; CD_CG_vectorS.y = CG_vectorS.y - CD_vectorS.y; CD_CG_vectorS.z = CG_vectorS.z - CD_vectorS.z; CD_CE_vectorS.x = CE_vectorS.x - CD_vectorS.x; CD_CE_vectorS.y = CE_vectorS.y - CD_vectorS.y; CD_CE_vectorS.z = CE_vectorS.z - CD_vectorS.z; /* Two vectors perpendicular to CG_CD_vectorS, mutually orthogonal, */ /* the second in the plane defined by CG_CB_vectorS and CG_CD_vectorS: */ VectorProduct_ (&u1S, &CG_CB_vectorS, &CG_CD_vectorS); VectorProduct_ (&u2S, &u1S, &CG_CD_vectorS); /* Two vectors perpendicular to CD_CG_vectorS, mutually orthogonal, */ /* the second in the plane defined by CD_CG_vectorS and CD_CE_vectorS: */ VectorProduct_ (&v1S, &CD_CG_vectorS, &CD_CE_vectorS); VectorProduct_ (&v2S, &CD_CG_vectorS, &v1S); /* Calculate the angle alpha, which will be used to calculate chi3: */ /* Avoid division by zero: */ denom = AbsoluteValue_ (&u1S) * AbsoluteValue_ (&v1S); if (denom == 0.0) return BADDIHEDANGLE; /* Use the scalar product to calculate the cosine of the angle: */ ratio = ScalarProduct_ (&u1S, &v1S) / denom; /* Arc cosine is very sensitive to floating point errors: */ if (ratio <= -1.0) alpha = 3.1415927; else if (ratio >= 1.0) alpha = 0.0; else alpha = acos (ratio); /* There are two possible solutions; the right one is resolved here: */ if (ScalarProduct_ (&v2S, &u1S) >= 0) chi3 = alpha; else chi3 = -alpha; /* Return the angle (in radians): */ return chi3; } /*===========================================================================*/ garlic-1.6/chi3_from_cbcgcdne.c0000644000076500007650000000727307341276344016757 0ustar zuciczucic00000000000000/* Copyright (C) 2001 Damir Zucic */ /*============================================================================= chi3_from_cbcgcdne.c Purpose: Calculate dihedral angle chi3, using CB, CG, CD and NE coordinates. Input: (1) Pointer to AtomS structure, pointing to the first atom of the current macromolecular complex. (2) Index of the first atom of the current residue. (3) Index of the last atom of the currrent residue. Output: Return value. Return value: (1) Dihedral angle chi3, on success. (2) BADDIHEDANGLE on failure. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int ExtractFourAtoms_ (VectorS *, VectorS *, VectorS *, VectorS *, char *, char *, char *, char *, AtomS *, size_t, size_t); void VectorProduct_ (VectorS *, VectorS *, VectorS *); double AbsoluteValue_ (VectorS *); double ScalarProduct_ (VectorS *, VectorS *); /*======calculate chi3 from CB, CG, CD and NE:===============================*/ double Chi3FromCBCGCDNE_ (AtomS *atomSP, size_t atom_startI, size_t atom_endI) { static VectorS CB_vectorS, CG_vectorS, CD_vectorS, NE_vectorS; int n; VectorS CG_CB_vectorS, CG_CD_vectorS; VectorS CD_CG_vectorS, CD_NE_vectorS; VectorS u1S, u2S; VectorS v1S, v2S; double denom, ratio, alpha; double chi3; /* Extract CB, CG, CD and NE coordinates: */ n = ExtractFourAtoms_ (&CB_vectorS, &CG_vectorS, &CD_vectorS, &NE_vectorS, "CB", "CG", "CD", "NE", atomSP, atom_startI, atom_endI); /* All four atoms are required to calculate the angle chi3: */ if (n < 4) return BADDIHEDANGLE; /* The first pair of auxiliary vectors: */ CG_CB_vectorS.x = CB_vectorS.x - CG_vectorS.x; CG_CB_vectorS.y = CB_vectorS.y - CG_vectorS.y; CG_CB_vectorS.z = CB_vectorS.z - CG_vectorS.z; CG_CD_vectorS.x = CD_vectorS.x - CG_vectorS.x; CG_CD_vectorS.y = CD_vectorS.y - CG_vectorS.y; CG_CD_vectorS.z = CD_vectorS.z - CG_vectorS.z; /* The second pair of auxiliary vectors: */ CD_CG_vectorS.x = CG_vectorS.x - CD_vectorS.x; CD_CG_vectorS.y = CG_vectorS.y - CD_vectorS.y; CD_CG_vectorS.z = CG_vectorS.z - CD_vectorS.z; CD_NE_vectorS.x = NE_vectorS.x - CD_vectorS.x; CD_NE_vectorS.y = NE_vectorS.y - CD_vectorS.y; CD_NE_vectorS.z = NE_vectorS.z - CD_vectorS.z; /* Two vectors perpendicular to CG_CD_vectorS, mutually orthogonal, */ /* the second in the plane defined by CG_CB_vectorS and CG_CD_vectorS: */ VectorProduct_ (&u1S, &CG_CB_vectorS, &CG_CD_vectorS); VectorProduct_ (&u2S, &u1S, &CG_CD_vectorS); /* Two vectors perpendicular to CD_CG_vectorS, mutually orthogonal, */ /* the second in the plane defined by CD_CG_vectorS and CD_NE_vectorS: */ VectorProduct_ (&v1S, &CD_CG_vectorS, &CD_NE_vectorS); VectorProduct_ (&v2S, &CD_CG_vectorS, &v1S); /* Calculate the angle alpha, which will be used to calculate chi3: */ /* Avoid division by zero: */ denom = AbsoluteValue_ (&u1S) * AbsoluteValue_ (&v1S); if (denom == 0.0) return BADDIHEDANGLE; /* Use the scalar product to calculate the cosine of the angle: */ ratio = ScalarProduct_ (&u1S, &v1S) / denom; /* Arc cosine is very sensitive to floating point errors: */ if (ratio <= -1.0) alpha = 3.1415927; else if (ratio >= 1.0) alpha = 0.0; else alpha = acos (ratio); /* There are two possible solutions; the right one is resolved here: */ if (ScalarProduct_ (&v2S, &u1S) >= 0) chi3 = alpha; else chi3 = -alpha; /* Return the angle (in radians): */ return chi3; } /*===========================================================================*/ garlic-1.6/set_omega.c0000644000076500007650000001064407633054443015233 0ustar zuciczucic00000000000000/* Copyright (C) 2001-2003 Damir Zucic */ /*============================================================================= set_omega.c Purpose: Set the omega angle for each selected residue in the given complex. A residue is treated as selected if the first atom of this residue is selected. For proteins, this is typically the N atom (nitrogen). Input: (1) Pointer to MolComplexS structure. (2) Pointer to ConfigS structure. (3) The omega angle in degrees. Output: (1) Omega angle set for each selected residue in each caught complex. (2) Return value. Return value: (1) Positive always (trivial). Notes: (1) This function uses the atoms N and CA of the current residue and and the atoms CA and C of the previous residue. ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ int ExtractNCA_ (VectorS *, VectorS *, AtomS *, size_t, size_t); int ExtractCAC_ (VectorS *, VectorS *, AtomS *, size_t, size_t); double OmegaFromCACNCA_ (VectorS *, VectorS *, VectorS *, VectorS *, ConfigS *); int RotateAtom_ (AtomS *, VectorS *, VectorS *, double); int DihedralAngles_ (MolComplexS *, ConfigS *); /*======set omega angle(s):==================================================*/ int SetOmega_ (MolComplexS *mol_complexSP, ConfigS *configSP, double omega_new) { int residuesN, residueI; size_t atomsN, atomI; ResidueS *current_residueSP; AtomS *first_atomSP; size_t current_startI, current_endI; int n; static VectorS N_vectorS, CA_vectorS; ResidueS *previous_residueSP; size_t previous_startI, previous_endI; static VectorS previousCA_vectorS, previousC_vectorS; double omega_old, delta_omega; AtomS *atomSP; /* Copy the number of residues in the specified complex: */ residuesN = mol_complexSP->residuesN; /* Copy the number of atoms in the specified complex: */ atomsN = mol_complexSP->atomsN; /* Scan residues, but skip the first one: */ for (residueI = 1; residueI < residuesN; residueI++) { /* Pointer to the current residue: */ current_residueSP = mol_complexSP->residueSP + residueI; /* Pointer to the first atom of this residue: */ first_atomSP = mol_complexSP->atomSP + current_residueSP->residue_startI; /* If the first atom of this residue is not */ /* selected, the residue is not selected: */ if (first_atomSP->selectedF == 0) continue; /* The range of atomic indices for the current residue: */ current_startI = current_residueSP->residue_startI; current_endI = current_residueSP->residue_endI; /* Try to extract N and CA coordinates for the current residue: */ n = ExtractNCA_ (&N_vectorS, &CA_vectorS, mol_complexSP->atomSP, current_startI, current_endI); if (n < 2) continue; /* The CA and C atoms of the previous residue are required. */ /* Pointer to the previous residue: */ previous_residueSP = mol_complexSP->residueSP + residueI - 1; /* The atomic index range for the previous residue: */ previous_startI = previous_residueSP->residue_startI; previous_endI = previous_residueSP->residue_endI; /* Extract CA and C coordinates from the previous residue: */ n = ExtractCAC_ (&previousCA_vectorS, &previousC_vectorS, mol_complexSP->atomSP, previous_startI, previous_endI); if (n < 2) continue; /* Calculate and check the old omega: */ omega_old = OmegaFromCACNCA_ (&previousCA_vectorS, &previousC_vectorS, &N_vectorS, &CA_vectorS, configSP); if (omega_old == BADDIHEDANGLE) continue; /* Calculate the difference: */ delta_omega = omega_new - omega_old; /* Rotate all atoms of the current residue and all */ /* atoms after the current residue about C-N bond: */ for (atomI = current_startI; atomI < atomsN; atomI++) { /* Pointer to the current atom: */ atomSP = mol_complexSP->atomSP + atomI; /* Rotate the current atom about N-CA bond: */ RotateAtom_ (atomSP, &previousC_vectorS, &N_vectorS, delta_omega); } } /* Update dihedral angles and cis-trans flags: */ DihedralAngles_ (mol_complexSP, configSP); /* Set the position_changedF: */ mol_complexSP->position_changedF = 1; /* Return positive value (trivial): */ return 1; } /*===========================================================================*/ garlic-1.6/sphere_fading.c0000644000076500007650000001344007066752034016064 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= sphere_fading.c Purpose: Prepare the left, middle and right color for each atom in a complex. The color fading is spherical. Input: (1) Pointer to MolComplexS structure. (2) Pointer to GUIS structure. Output: (1) left_colorID, middle_colorID and right_colorID members of AtomS structure initialized for each atom in macromolecular complex. (2) Return value. Return value: (1) On success, the number of atoms which have colors different from near and far color. These atoms are located in the area between the front and back surface. (2) Zero on failure. Notes: (1) Do not skip hidden atoms, the color of these atoms may be used for backbone drawing! =============================================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ unsigned long PixelFromRGBS_ (RGBS *, GUIS *); unsigned long PrepareColor_ (RGBS *, RGBS *, double, GUIS *); /*======spherical fading:====================================================*/ size_t SphereFading_ (MolComplexS *curr_mol_complexSP, GUIS *guiSP) { size_t atoms_between_surfacesN = 0; size_t atomsN, atomI; AtomS *curr_atomSP; int surfacesN, surfaceI, inner_surfaceI, outer_surfaceI; double r_out, r_out_squared, r_in, r_in_squared; double x0, y0, z0; double overall_range, internal_range; double inverse_internal_range; double x, y, z, r_squared, r, delta_r, scale_factor; int near_surfaceI, far_surfaceI; /* The radius of the front (outer) surface: */ r_out = curr_mol_complexSP->fading_front_relative_position; r_out_squared = r_out * r_out; /* The radius of the back (inner) surface: */ r_in = curr_mol_complexSP->fading_back_relative_position; r_in_squared = r_in * r_in; /* Check: */ if (r_in >= r_out) return 0; /* The overall range: */ overall_range = r_out - r_in; /* Fading center coordinates: */ x0 = curr_mol_complexSP->fading_center_vectorS.x; y0 = curr_mol_complexSP->fading_center_vectorS.y; z0 = curr_mol_complexSP->fading_center_vectorS.z; /* The number of atoms in a complex: */ atomsN = curr_mol_complexSP->atomsN; /* Assign three colors to each atom: */ for (atomI = 0; atomI < atomsN; atomI++) { /** Pointer to the current atom: **/ curr_atomSP = curr_mol_complexSP->atomSP + atomI; /** Is atom out of slab? **/ if (!curr_atomSP->inside_slabF) continue; /** Check the number of color fading surfaces: **/ surfacesN = curr_atomSP->surfacesN; /*** If there is only one, there is no fading: ***/ if (surfacesN == 1) { curr_atomSP->left_colorID = PixelFromRGBS_ (curr_atomSP->left_rgbSA, guiSP); curr_atomSP->middle_colorID = PixelFromRGBS_ (curr_atomSP->middle_rgbSA, guiSP); curr_atomSP->right_colorID = PixelFromRGBS_ (curr_atomSP->right_rgbSA, guiSP); continue; } /** Atomic coordinates (relative to fading center): **/ x = curr_atomSP->raw_atomS.x[0] - x0; y = curr_atomSP->raw_atomS.y - y0; z = curr_atomSP->raw_atomS.z[0] - z0; /** Distance between the current atom and the fading center: **/ r_squared = x * x + y * y + z * z; /** Atoms which are too far from the fading **/ /** center should be treated as near atoms: **/ if (r_squared >= r_out_squared) { curr_atomSP->left_colorID = PixelFromRGBS_ (curr_atomSP->left_rgbSA, guiSP); curr_atomSP->middle_colorID = PixelFromRGBS_ (curr_atomSP->middle_rgbSA, guiSP); curr_atomSP->right_colorID = PixelFromRGBS_ (curr_atomSP->right_rgbSA, guiSP); continue; } /** Atoms which are to close to the fading **/ /** center should be treated as far atoms: **/ if (r_squared <= r_in_squared) { surfaceI = surfacesN - 1; curr_atomSP->left_colorID = PixelFromRGBS_ (curr_atomSP->left_rgbSA + surfaceI, guiSP); curr_atomSP->middle_colorID = PixelFromRGBS_ (curr_atomSP->middle_rgbSA + surfaceI, guiSP); curr_atomSP->right_colorID = PixelFromRGBS_ (curr_atomSP->right_rgbSA + surfaceI, guiSP); continue; } /** If this point is reached, current atom is in **/ /** the area between two surfaces; colors should **/ /** be calculated weighting near and far colors: **/ /** Prepare auxiliary variables: **/ if (surfacesN > 1) { r = sqrt (r_squared); internal_range = overall_range / (double) (surfacesN - 1); inverse_internal_range = 1.0 / internal_range; inner_surfaceI = (int) floor ((r - r_in) * inverse_internal_range); outer_surfaceI = inner_surfaceI + 1; delta_r = outer_surfaceI * internal_range + r_in - r; scale_factor = delta_r * inverse_internal_range; far_surfaceI = surfacesN - inner_surfaceI - 1; near_surfaceI = far_surfaceI - 1; } else { scale_factor = 0.0; far_surfaceI = 0; near_surfaceI = 0; } /** Left color: **/ curr_atomSP->left_colorID = PrepareColor_ (curr_atomSP->left_rgbSA + near_surfaceI, curr_atomSP->left_rgbSA + far_surfaceI, scale_factor, guiSP); /** Middle color: **/ curr_atomSP->middle_colorID = PrepareColor_ (curr_atomSP->middle_rgbSA + near_surfaceI, curr_atomSP->middle_rgbSA + far_surfaceI, scale_factor, guiSP); /** Right color: **/ curr_atomSP->right_colorID = PrepareColor_ (curr_atomSP->right_rgbSA + near_surfaceI, curr_atomSP->right_rgbSA + far_surfaceI, scale_factor, guiSP); /** Update the number of atoms in the area between two surfaces: **/ atoms_between_surfacesN++; } /* Return the number of atoms which have */ /* colors different from near and far colors: */ return atoms_between_surfacesN; } /*===========================================================================*/ garlic-1.6/absolute_value.c0000644000076500007650000000160207457530601016273 0ustar zuciczucic00000000000000/* Copyright (C) 2000 Damir Zucic */ /*============================================================================= absolute_value.c Purpose: Calculate the absolute value of a given vector. Input: (1) Pointer to VectorS structure. Output: Return value. Return value: Absolute value (positive double value). ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======calculate absolute value of a vector:================================*/ double AbsoluteValue_ (VectorS *vectorSP) { return sqrt (vectorSP->x * vectorSP->x + vectorSP->y * vectorSP->y + vectorSP->z * vectorSP->z); } /*===========================================================================*/ garlic-1.6/phi_from_hncac.c0000644000076500007650000000741207315721736016231 0ustar zuciczucic00000000000000/* Copyright (C) 2001 Damir Zucic */ /*============================================================================= phi_from_hncac.c Purpose: Calculate dihedral angle phi, using H, N, CA and C atom coordinates for the given residue. Input: (1) Pointer to VectorS structure, with H atom coordinates. (2) Pointer to VectorS structure, with N atom coordinates. (3) Pointer to VectorS structure, with CA atom coordinates. (4) Pointer to VectorS structure, with C atom coordinates. Output: Return value. Return value: (1) Dihedral angle phi, on success. (2) BADDIHEDANGLE on failure. Notes: (1) This should help you to understand phi and psi definitions: ........./................ | H * - * N | | \ phi1 = 180 | | * CA | residue 1 | / psi1 = 180 | | O * - * C | |........\...............| | N * - * H | | / phi2 = 180 | | CA * | residue 2 | \ psi2 = 180 | | C * - * O | |......../...............| ========includes:============================================================*/ #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======function prototypes:=================================================*/ void VectorProduct_ (VectorS *, VectorS *, VectorS *); double AbsoluteValue_ (VectorS *); double ScalarProduct_ (VectorS *, VectorS *); /*======calculate phi from H[i], N[i], CA[i] and C[i]:=======================*/ double PhiFromHNCAC_ (VectorS *H_vectorSP, VectorS *N_vectorSP, VectorS *CA_vectorSP, VectorS *C_vectorSP) { VectorS N_CA_vectorS, N_H_vectorS; VectorS CA_N_vectorS, CA_C_vectorS; VectorS u1S, u2S; VectorS v1S, v2S; double denom, ratio; double alpha, phi; /* The first pair of auxiliary vectors: */ N_CA_vectorS.x = CA_vectorSP->x - N_vectorSP->x; N_CA_vectorS.y = CA_vectorSP->y - N_vectorSP->y; N_CA_vectorS.z = CA_vectorSP->z - N_vectorSP->z; N_H_vectorS.x = H_vectorSP->x - N_vectorSP->x; N_H_vectorS.y = H_vectorSP->y - N_vectorSP->y; N_H_vectorS.z = H_vectorSP->z - N_vectorSP->z; /* The second pair of auxiliary vectors: */ CA_N_vectorS.x = N_vectorSP->x - CA_vectorSP->x; CA_N_vectorS.y = N_vectorSP->y - CA_vectorSP->y; CA_N_vectorS.z = N_vectorSP->z - CA_vectorSP->z; CA_C_vectorS.x = C_vectorSP->x - CA_vectorSP->x; CA_C_vectorS.y = C_vectorSP->y - CA_vectorSP->y; CA_C_vectorS.z = C_vectorSP->z - CA_vectorSP->z; /* Two vectors perpendicular to N_CA_vectorS, mutually orthogonal, */ /* the second in the plane defined by N_H_vectorS and N_CA_vectorS: */ VectorProduct_ (&u1S, &N_CA_vectorS, &N_H_vectorS); VectorProduct_ (&u2S, &u1S, &N_CA_vectorS); /* Two vectors perpendicular to CA_N_vectorS, mutually orthogonal, */ /* the second in the plane defined by CA_N_vectorS and CA_C_vectorS: */ VectorProduct_ (&v1S, &CA_N_vectorS, &CA_C_vectorS); VectorProduct_ (&v2S, &CA_N_vectorS, &v1S); /* Calculate the angle alpha, which will be used to calculate phi: */ /* Avoid division by zero: */ denom = AbsoluteValue_ (&u1S) * AbsoluteValue_ (&v1S); if (denom == 0.0) return BADDIHEDANGLE; /* Use the scalar product to calculate the cosine of the angle: */ ratio = ScalarProduct_ (&u1S, &v1S) / denom; /* Arc cosine is very sensitive to floating point errors: */ if (ratio <= -1.0) alpha = 3.1415927; else if (ratio >= 1.0) alpha = 0.0; else alpha = acos (ratio); /* There are two possible solutions; the right one is resolved here: */ if (ScalarProduct_ (&v2S, &u1S) >= 0) phi = alpha; else phi = -alpha; /* Return the angle (in radians): */ return phi; } /*===========================================================================*/ garlic-1.6/check_dist.c0000644000076500007650000001355707612773207015401 0ustar zuciczucic00000000000000/* Copyright (C) 2000-2003 Damir Zucic */ /*============================================================================= check_dist.c Purpose: Try to recognize the atomic pair. If pair is recognized, check the distance between two atoms. If this distance fits into the bond length range which corresponds to given atomic pair, return positive value. Otherwise return negative value. See bellow for a list of pairs this routine recognizes. This array is called known_pairAA. Add more to the list, but don't forget to update the array size. Changes in PDB format may require the modification of this function. It is assumed that chemical symbol is right justified and that exactly two characters are used for representation. Pairs like " C N" and " N C" etc. are treated as equivalent and thus should have equal ID's. The array with pair ID's is called known_pairsIDA. Unrecognized pairs are also checked, using generic bond length limits. Input: (1) Pointer to inter-atomic distance. (2) Pointer to AtomS structure with data about one atom. (3) Pointer to AtomS structure with data about another atom. (4) Pointer to ConfigS structure, with configuration data, Output: (1) Bond length, if bond is recognized. (2) Return value. Return value: (1) If atomic pair is recognized and the distance corresponds to a valid bond length, atomic pair ID is returned. (2) Negative if inter-atomic distance is bad. Notes: (1) The pair identifier value of zero is reserved for hydrogen bonds. ========includes:============================================================*/ #include #include #include #include #include #include #include #include "defines.h" #include "typedefs.h" /*======check inter-atomic distance:=========================================*/ int CheckDistance_ (double *distanceP, AtomS *atom1SP, AtomS *atom2SP, ConfigS *configSP) { char atomic_pairA[40]; static char known_pairAA[KNOWNPAIRS][PAIRSIZE] = {" C C", " C C", " C N", " N C", " C O", " O C", " C S", " S C", " C H", " H C", " N O", " O N", " N H", " H N", " O H", " H O", " S H", " H S", " O P", " P O", " S S", " S S"}; static int known_pairIDA[KNOWNPAIRS] = {1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11}; int pair_string_len; int i; int pairID; double delta_x, delta_y, delta_z; double distance_squared; /* Auxiliary integer: */ pair_string_len = PAIRSIZE - 1; /* Prepare the string which will contain both chemical symbols: */ strcpy (atomic_pairA, atom1SP->raw_atomS.chemical_symbolA); strncat (atomic_pairA, atom2SP->raw_atomS.chemical_symbolA, 2); atomic_pairA[pair_string_len] = '\0'; /* Hydrogen to hydrogen bond is not allowed in garlic: */ /* (Note: H_TO_H_BOND must be negative, see defines.h!) */ if (strncmp (" H H", atomic_pairA, pair_string_len) == 0) return H_TO_H_BOND; /* Try to recognize the atomic pair: */ pairID = GENERICID; /* The initial value */ for (i = 0; i < KNOWNPAIRS; i++) { if (strncmp (known_pairAA[i], atomic_pairA, pair_string_len) == 0) { pairID = known_pairIDA[i]; break; } } /* Calculate the squared distance: */ delta_x = atom1SP->raw_atomS.x[0] - atom2SP->raw_atomS.x[0]; delta_y = atom1SP->raw_atomS.y - atom2SP->raw_atomS.y; delta_z = atom1SP->raw_atomS.z[0] - atom2SP->raw_atomS.z[0]; distance_squared = delta_x * delta_x + delta_y * delta_y + delta_z * delta_z; /* Check the squared distance: if it doesn't fit into */ /* the range for a given pair, return negative value: */ switch (pairID) { /* C-C: */ case 1: if (distance_squared > configSP->C_C_max_squared) return -1; if (distance_squared < configSP->C_C_min_squared) return -2; break; /* C-N: */ case 2: if (distance_squared > configSP->C_N_max_squared) return -3; if (distance_squared < configSP->C_N_min_squared) return -4; break; /* C-O: */ case 3: if (distance_squared > configSP->C_O_max_squared) return -5; if (distance_squared < configSP->C_O_min_squared) return -6; break; /* C-S: */ case 4: if (distance_squared > configSP->C_S_max_squared) return -7; if (distance_squared < configSP->C_S_min_squared) return -8; break; /* C-H: */ case 5: if (distance_squared > configSP->C_H_max_squared) return -9; if (distance_squared < configSP->C_H_min_squared) return -10; break; /* N-O: */ case 6: if (distance_squared > configSP->N_O_max_squared) return -11; if (distance_squared < configSP->N_O_min_squared) return -12; /* N-H: */ case 7: if (distance_squared > configSP->N_H_max_squared) return -13; if (distance_squared < configSP->N_H_min_squared) return -14; break; /* O-H: */ case 8: if (distance_squared > configSP->O_H_max_squared) return -15; if (distance_squared < configSP->O_H_min_squared) return -16; break; /* S-H: */ case 9: if (distance_squared > configSP->S_H_max_squared) return -17; if (distance_squared < configSP->S_H_min_squared) return -18; break; /* O-P: */ case 10: if (distance_squared > configSP->O_P_max_squared) return -19; if (distance_squared < configSP->O_P_min_squared) return -20; break; /* S-S (disulfide bond): */ case 11: if (distance_squared > configSP->S_S_max_squared) return -21; if (distance_squared < configSP->S_S_min_squared) return -22; break; /* If this happens, pair was not recognized: */ case GENERICID: if (distance_squared > configSP->generic_max_squared) return -23; if (distance_squared < configSP->generic_min_squared) return -24; break; /* The impossible option: */ default: return -9999; } /* If this point is reached, the bond fits */ /* into the range; calculate the distance: */ *distanceP = sqrt (distance_squared); /* Return pair ID on success: */ return pairID; } /*===========================================================================*/ garlic-1.6/vdac.fasta0000644000076500007650000000054407723640320015052 0ustar zuciczucic00000000000000>sp|P21796|POR1_HUMAN VDAC-1 (Outer mit. mem. porin 1) Homo sapiens. AVPPTYADLGKSARDVFTKGYGFGLIKLDLKTKSENGLEFTSSGSANTETTKVTGSLETK YRWTEYGLTFTEKWNTDNTLGTEITVEDQLARGLKLTFDSSFSPNTGKKNAKIKTGYKRE HINLGCDMDFDIAGPSIRGALVLGYEGWLAGYQMNFETAKSRVTQSNFAVGYKTDEFQLH TNVNDGTEFGGSIYQKVNKKLETAVNLAWTAGNSNTRFGIAAKYQIDPDACFSAKVNNSS LIGLGYTQTLKPGIKLTLSALLDGKNVNAGGHKLGLGLEFQA