From 16c600161b0c68157d54845e114b5c59a999c81d Mon Sep 17 00:00:00 2001 From: zerg Date: Wed, 29 Apr 2026 19:08:35 +0330 Subject: [PATCH 01/10] port font rendering to xftlib. --- makefile | 6 ++++-- src/v/x.c | 37 +++++++++++++++++++++---------------- src/v/x.h | 5 ++++- 3 files changed, 29 insertions(+), 19 deletions(-) diff --git a/makefile b/makefile index e134b76..beea043 100644 --- a/makefile +++ b/makefile @@ -45,8 +45,10 @@ else endif X11DIR= $(shell pkg-config --libs-only-L x11 xpm) # for macOS -CFLAGS= -c -std=gnu11 $(OPT) $(GPROF) $(W) $(GDB) -OFLAGS= -lm $(GPROF) -lX11 -lXpm $(X11DIR) +XFTLIB= $(shell pkg-config --libs xft) +XFTCFLAGS= $(shell pkg-config --cflags xft) +CFLAGS= -c -std=gnu11 $(OPT) $(GPROF) $(W) $(GDB) $(XFTCFLAGS) +OFLAGS= -lm $(GPROF) -lX11 -lXpm $(X11DIR) $(XFTLIB) SRCDIR=src OBJDIR=obj diff --git a/src/v/x.c b/src/v/x.c index 3e8ab90..dabd717 100644 --- a/src/v/x.c +++ b/src/v/x.c @@ -15,7 +15,10 @@ void close_x(void) { XDestroyWindow (world.dis, world.win); XFreePixmap (world.dis, world.px); if(world.fontInfo){ - XFreeFont (world.dis, world.fontInfo); + XftFontClose (world.dis, world.fontInfo); + } + if (world.xft_draw) { + XftDrawDestroy(world.xft_draw); } XCloseDisplay (world.dis); }; @@ -103,17 +106,17 @@ void init_x(const char * const capt, const colorscheme_t colorscheme){ return; }; -static void autosize_font(char * fontname){ +static void autosize_font(char * fontname, size_t size){ const int screen_sizes[] = {1200, 1080, 960, 900, 840, 768}; const int font_sizes[] = { 24, 20, 18, 16, 15, 14}; // font_size='ceil'(world.size) / 60 - int font_size = 13; + int font_size = 24; for(int i=0; iscreen_sizes[i]){ font_size = font_sizes[i]; break; } } - sprintf(fontname, "*x%d", font_size); + snprintf(fontname, size, "monospace:pixelsize=%d", font_size); return; } @@ -121,21 +124,20 @@ void init_font(char * fontname){ styp s; if(!fontname){ fontname = s; - autosize_font(fontname); - } - world.fontInfo = XLoadQueryFont(world.dis, fontname); - if(world.fontInfo){ - XSetFont (world.dis, world.gc_black, world.fontInfo->fid); - XSetFont (world.dis, world.gc_red, world.fontInfo->fid); + autosize_font(fontname, sizeof(s)); } - else{ + world.fontInfo = XftFontOpenName(world.dis, DefaultScreen(world.dis), fontname); + if(!world.fontInfo){ PRINT_WARN("cannot load font '%s'\n", fontname); + world.fontInfo = XftFontOpenName(world.dis, DefaultScreen(world.dis), "monospace:pixelsize=24"); } - XCharStruct _o; - int _d, font_ascent, font_descent; - XQueryTextExtents(world.dis, XGContextFromGC(world.gc_black), ".", 1, &_d, &font_ascent, &font_descent, &_o); - world.font_height = font_ascent + font_descent; + world.xft_draw = XftDrawCreate(world.dis, world.canv, DefaultVisual(world.dis, DefaultScreen(world.dis)), DefaultColormap(world.dis, DefaultScreen(world.dis))); + XRenderColor color = {0, 0, 0, 65535}; + XftColorAllocValue(world.dis, DefaultVisual(world.dis, DefaultScreen(world.dis)), DefaultColormap(world.dis, DefaultScreen(world.dis)), &color, &world.xft_color); + XGlyphInfo extents; + XftTextExtentsUtf8(world.dis, world.fontInfo, (const FcChar8 *)".", 1, &extents); + world.font_height = world.fontInfo->ascent + world.fontInfo->descent; return; } @@ -144,8 +146,11 @@ void put_text(const char * const lines[MAX_LINES], const int red[MAX_LINES]){ int hoffset = 10; for(int i=0; iascent; + XftDrawStringUtf8(world.xft_draw, &(world.xft_color), world.fontInfo, x, y, (const FcChar8 *)lines[i], strlen(lines[i])); } + voffset += world.fontInfo->height; } return; } diff --git a/src/v/x.h b/src/v/x.h index 792647c..364b69f 100644 --- a/src/v/x.h +++ b/src/v/x.h @@ -1,3 +1,4 @@ +#include #include #include #include @@ -16,7 +17,9 @@ typedef struct { GC gc_white, gc_black, gc_red, gc_dot[2], gcc[NCOLORS]; Pixmap px; Drawable canv; - XFontStruct * fontInfo; + XftFont * fontInfo; + XftDraw * xft_draw; + XftColor xft_color; int font_height; int W, H, size; } draw_world_t; From 6d9e5b2934415487b4122144394cbdf5803d1511 Mon Sep 17 00:00:00 2001 From: zerg Date: Wed, 29 Apr 2026 19:15:36 +0330 Subject: [PATCH 02/10] set coding format to GNU style --- .clang-format | 321 ++++++++++++ makefile | 3 + src/api.c | 165 +++--- src/math/3d.h | 19 +- src/math/jacobi.c | 151 +++--- src/math/matrix.c | 43 +- src/math/matrix.h | 27 +- src/math/mx_inv.c | 112 +++-- src/math/rot3d.c | 97 ++-- src/math/vec3.h | 196 +++++--- src/math/vecn.c | 56 ++- src/math/vecn.h | 14 +- src/math/zmat.c | 102 ++-- src/mol/common.h | 82 ++- src/mol/elements.h | 61 +-- src/mol/inertia.c | 150 +++--- src/mol/intcoord.c | 140 +++--- src/mol/masses.h | 63 +-- src/mol/mol.h | 37 +- src/mol/mytime.h | 11 +- src/mol/palette_cpk.h | 219 ++++---- src/mol/palette_v.h | 49 +- src/sym/pointgroup.c | 1120 +++++++++++++++++++++++------------------ src/sym/sym.h | 30 +- src/v.c | 184 ++++--- src/v/ac3_draw.c | 183 ++++--- src/v/ac3_print.c | 186 ++++--- src/v/ac3_read.c | 276 +++++----- src/v/ac3_read_in.c | 237 +++++---- src/v/ac3_read_out.c | 56 ++- src/v/ac3_read_xyz.c | 136 +++-- src/v/bonds.c | 339 +++++++------ src/v/cli.c | 389 ++++++++------ src/v/evr.c | 671 ++++++++++++++---------- src/v/evr.h | 118 ++--- src/v/get_atpar.c | 102 ++-- src/v/headless.c | 220 ++++---- src/v/load.c | 404 ++++++++------- src/v/loop.c | 313 +++++++----- src/v/man.c | 10 +- src/v/mode_read.c | 216 ++++---- src/v/pars.h | 158 +++--- src/v/redraw.c | 191 ++++--- src/v/scale.c | 64 ++- src/v/tools.c | 44 +- src/v/v.h | 158 +++--- src/v/x.c | 293 ++++++----- src/v/x.h | 33 +- src/v/xinput.c | 55 +- 49 files changed, 4894 insertions(+), 3410 deletions(-) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..e3f753c --- /dev/null +++ b/.clang-format @@ -0,0 +1,321 @@ +--- +Language: Cpp +AlignAfterOpenBracket: true +AccessModifierOffset: -2 +AlignArrayOfStructures: None +AlignConsecutiveAssignments: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionDeclarations: false + AlignFunctionPointers: false + PadOperators: true +AlignConsecutiveBitFields: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionDeclarations: false + AlignFunctionPointers: false + PadOperators: false +AlignConsecutiveDeclarations: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionDeclarations: true + AlignFunctionPointers: false + PadOperators: false +AlignConsecutiveMacros: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionDeclarations: false + AlignFunctionPointers: false + PadOperators: false +AlignConsecutiveShortCaseStatements: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCaseArrows: false + AlignCaseColons: false +AlignConsecutiveTableGenBreakingDAGArgColons: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionDeclarations: false + AlignFunctionPointers: false + PadOperators: false +AlignConsecutiveTableGenCondOperatorColons: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionDeclarations: false + AlignFunctionPointers: false + PadOperators: false +AlignConsecutiveTableGenDefinitionColons: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionDeclarations: false + AlignFunctionPointers: false + PadOperators: false +AlignEscapedNewlines: Right +AlignOperands: Align +AlignTrailingComments: + AlignPPAndNotPP: true + Kind: Always + OverEmptyLines: 0 +AllowAllArgumentsOnNextLine: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowBreakBeforeNoexceptSpecifier: Never +AllowBreakBeforeQtProperty: false +AllowShortBlocksOnASingleLine: Never +AllowShortCaseExpressionOnASingleLine: true +AllowShortCaseLabelsOnASingleLine: false +AllowShortCompoundRequirementOnASingleLine: true +AllowShortEnumsOnASingleLine: true +AllowShortFunctionsOnASingleLine: All +AllowShortIfStatementsOnASingleLine: Never +AllowShortLambdasOnASingleLine: All +AllowShortLoopsOnASingleLine: false +AllowShortNamespacesOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: All +AlwaysBreakBeforeMultilineStrings: false +AttributeMacros: + - __capability +BinPackArguments: true +BinPackLongBracedList: true +BinPackParameters: BinPack +BitFieldColonSpacing: Both +BracedInitializerIndentWidth: -1 +BraceWrapping: + AfterCaseLabel: true + AfterClass: true + AfterControlStatement: Always + AfterEnum: true + AfterExternBlock: true + AfterFunction: true + AfterNamespace: true + AfterObjCDeclaration: true + AfterStruct: true + AfterUnion: true + BeforeCatch: true + BeforeElse: true + BeforeLambdaBody: true + BeforeWhile: true + IndentBraces: true + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakAdjacentStringLiterals: true +BreakAfterAttributes: Leave +BreakAfterJavaFieldAnnotations: false +BreakAfterOpenBracketBracedList: false +BreakAfterOpenBracketFunction: false +BreakAfterOpenBracketIf: false +BreakAfterOpenBracketLoop: false +BreakAfterOpenBracketSwitch: false +BreakAfterReturnType: AllDefinitions +BreakArrays: true +BreakBeforeBinaryOperators: All +BreakBeforeCloseBracketBracedList: false +BreakBeforeCloseBracketFunction: false +BreakBeforeCloseBracketIf: false +BreakBeforeCloseBracketLoop: false +BreakBeforeCloseBracketSwitch: false +BreakBeforeConceptDeclarations: Always +BreakBeforeBraces: GNU +BreakBeforeInlineASMColon: OnlyMultiline +BreakBeforeTemplateCloser: false +BreakBeforeTernaryOperators: true +BreakBinaryOperations: Never +BreakConstructorInitializers: BeforeColon +BreakFunctionDefinitionParameters: false +BreakInheritanceList: BeforeColon +BreakStringLiterals: true +BreakTemplateDeclarations: MultiLine +ColumnLimit: 79 +CommentPragmas: '^ IWYU pragma:' +CompactNamespaces: false +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: Block +DerivePointerAlignment: false +DisableFormat: false +EmptyLineAfterAccessModifier: Never +EmptyLineBeforeAccessModifier: LogicalBlock +EnumTrailingComma: Leave +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: false +ForEachMacros: + - foreach + - Q_FOREACH + - BOOST_FOREACH +IfMacros: + - KJ_IF_MAYBE +IncludeBlocks: Preserve +IncludeCategories: + - Regex: '^"(llvm|llvm-c|clang|clang-c)/' + Priority: 2 + SortPriority: 0 + CaseSensitive: false + - Regex: '^(<|"(gtest|gmock|isl|json)/)' + Priority: 3 + SortPriority: 0 + CaseSensitive: false + - Regex: '.*' + Priority: 1 + SortPriority: 0 + CaseSensitive: false +IncludeIsMainRegex: '(Test)?$' +IncludeIsMainSourceRegex: '' +IndentAccessModifiers: false +IndentCaseBlocks: false +IndentCaseLabels: false +IndentExportBlock: true +IndentExternBlock: AfterExternBlock +IndentGotoLabels: true +IndentPPDirectives: None +IndentRequiresClause: true +IndentWidth: 2 +IndentWrappedFunctionNames: false +InsertBraces: false +InsertNewlineAtEOF: false +InsertTrailingCommas: None +IntegerLiteralSeparator: + Binary: 0 + BinaryMinDigitsInsert: 0 + BinaryMaxDigitsRemove: 0 + Decimal: 0 + DecimalMinDigitsInsert: 0 + DecimalMaxDigitsRemove: 0 + Hex: 0 + HexMinDigitsInsert: 0 + HexMaxDigitsRemove: 0 + BinaryMinDigits: 0 + DecimalMinDigits: 0 + HexMinDigits: 0 +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLines: + AtEndOfFile: false + AtStartOfBlock: true + AtStartOfFile: true +KeepFormFeed: true +LambdaBodyIndentation: Signature +LineEnding: DeriveLF +MacroBlockBegin: '' +MacroBlockEnd: '' +MainIncludeChar: Quote +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +NumericLiteralCase: + ExponentLetter: Leave + HexDigit: Leave + Prefix: Leave + Suffix: Leave +ObjCBinPackProtocolList: Auto +ObjCBlockIndentWidth: 2 +ObjCBreakBeforeNestedBlockParam: true +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +OneLineFormatOffRegex: '' +PackConstructorInitializers: BinPack +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakBeforeMemberAccess: 150 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakOpenParenthesis: 0 +PenaltyBreakScopeResolution: 500 +PenaltyBreakString: 1000 +PenaltyBreakTemplateDeclaration: 10 +PenaltyExcessCharacter: 1000000 +PenaltyIndentedWhitespace: 0 +PenaltyReturnTypeOnItsOwnLine: 60 +PointerAlignment: Right +PPIndentWidth: -1 +QualifierAlignment: Leave +ReferenceAlignment: Pointer +ReflowComments: Always +RemoveBracesLLVM: false +RemoveEmptyLinesInUnwrappedLines: false +RemoveParentheses: Leave +RemoveSemicolon: false +RequiresClausePosition: OwnLine +RequiresExpressionIndentation: OuterScope +SeparateDefinitionBlocks: Leave +ShortNamespaceLines: 1 +SkipMacroDefinitionBody: false +SortIncludes: + Enabled: true + IgnoreCase: false + IgnoreExtension: false +SortJavaStaticImport: Before +SortUsingDeclarations: LexicographicNumeric +SpaceAfterCStyleCast: false +SpaceAfterLogicalNot: false +SpaceAfterOperatorKeyword: false +SpaceAfterTemplateKeyword: true +SpaceAroundPointerQualifiers: Default +SpaceBeforeAssignmentOperators: true +SpaceBeforeCaseColon: false +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeJsonColon: false +SpaceBeforeParens: Always +SpaceBeforeParensOptions: + AfterControlStatements: false + AfterForeachMacros: false + AfterFunctionDefinitionName: false + AfterFunctionDeclarationName: false + AfterIfMacros: false + AfterNot: false + AfterOverloadedOperator: false + AfterPlacementOperator: true + AfterRequiresInClause: false + AfterRequiresInExpression: false + BeforeNonEmptyParentheses: false +SpaceBeforeRangeBasedForLoopColon: true +SpaceBeforeSquareBrackets: false +SpaceInEmptyBraces: Never +SpacesBeforeTrailingComments: 1 +SpacesInAngles: Never +SpacesInContainerLiterals: true +SpacesInLineCommentPrefix: + Minimum: 1 + Maximum: -1 +SpacesInParens: Never +SpacesInParensOptions: + ExceptDoubleParentheses: false + InCStyleCasts: false + InConditionalStatements: false + InEmptyParentheses: false + Other: false +SpacesInSquareBrackets: false +Standard: Latest +StatementAttributeLikeMacros: + - Q_EMIT +StatementMacros: + - Q_UNUSED + - QT_REQUIRE_VERSION +TableGenBreakInsideDAGArg: DontBreak +TabWidth: 8 +UseTab: Never +VerilogBreakBetweenInstancePorts: true +WhitespaceSensitiveMacros: + - BOOST_PP_STRINGIZE + - CF_SWIFT_NAME + - NS_SWIFT_NAME + - PP_STRINGIZE + - STRINGIZE +WrapNamespaceBodyWithEmptyLines: Leave +... + diff --git a/makefile b/makefile index beea043..2f785cc 100644 --- a/makefile +++ b/makefile @@ -98,3 +98,6 @@ include $(allmmd) cppcheck: cleancheck -.github/cppcheck.bash 2> errors.xml cppcheck-htmlreport --file=errors.xml --report-dir=cppcheck_html + +format: + git ls-files '*.c' '*.h' | xargs clang-format -i -style=file diff --git a/src/api.c b/src/api.c index da1cfab..07357f7 100644 --- a/src/api.c +++ b/src/api.c @@ -1,111 +1,136 @@ -#include #include "v.h" +#include -#define PRINTBUFLEN (1024*128) +#define PRINTBUFLEN (1024 * 128) -struct { - char * out_str; - mol * inp_mols; +struct +{ + char *out_str; + mol *inp_mols; vibr_t inp_vib; int n_inp_mols; } globals; -char * main_wrap_out(int argc, char * argv[], int * ret) { - globals.out_str = calloc(PRINTBUFLEN, 1); - if(!globals.out_str){ - *ret = -1; - return NULL; - } - *ret = main(argc, argv); +char * +main_wrap_out (int argc, char *argv[], int *ret) +{ + globals.out_str = calloc (PRINTBUFLEN, 1); + if (!globals.out_str) + { + *ret = -1; + return NULL; + } + *ret = main (argc, argv); return globals.out_str; } // cppcheck-suppress staticFunction -int main_wrap_in(int argc, char * argv[], int n_inp_mols, mol * inp_mols, vibr_t inp_vib) { +int +main_wrap_in (int argc, char *argv[], int n_inp_mols, mol *inp_mols, + vibr_t inp_vib) +{ globals.inp_mols = inp_mols; globals.n_inp_mols = n_inp_mols; globals.inp_vib = inp_vib; - int ret = main(argc, argv); + int ret = main (argc, argv); globals.inp_mols = NULL; globals.n_inp_mols = 0; return ret; } -char * main_wrap_in_out(int argc, char * argv[], - int n_inp_mols, mol * inp_mols, - vibr_t inp_vib, - int * ret){ - globals.out_str = calloc(PRINTBUFLEN, 1); - if(!globals.out_str){ - *ret = -1; - return NULL; - } - *ret = main_wrap_in(argc, argv, n_inp_mols, inp_mols, inp_vib); +char * +main_wrap_in_out (int argc, char *argv[], int n_inp_mols, mol *inp_mols, + vibr_t inp_vib, int *ret) +{ + globals.out_str = calloc (PRINTBUFLEN, 1); + if (!globals.out_str) + { + *ret = -1; + return NULL; + } + *ret = main_wrap_in (argc, argv, n_inp_mols, inp_mols, inp_vib); return globals.out_str; } -void free_out_str(void){ - FREE0(globals.out_str); - PRINTOUT(NULL, NULL); +void +free_out_str (void) +{ + FREE0 (globals.out_str); + PRINTOUT (NULL, NULL); } -void PRINTOUT(FILE * f, char * format, ...){ +void +PRINTOUT (FILE *f, char *format, ...) +{ va_list args; static size_t n = 0; static size_t N = PRINTBUFLEN; // call to reset n and N - if(!format){ - n = 0; - N = PRINTBUFLEN; - return; - } + if (!format) + { + n = 0; + N = PRINTBUFLEN; + return; + } - if(!globals.out_str){ - va_start(args, format); - vfprintf(f, format, args); - va_end(args); - } - else{ + if (!globals.out_str) + { + va_start (args, format); + vfprintf (f, format, args); + va_end (args); + } + else + { - va_start(args, format); - size_t size = N-n; - size_t m = vsnprintf(globals.out_str+n, size, format, args); - va_end(args); + va_start (args, format); + size_t size = N - n; + size_t m = vsnprintf (globals.out_str + n, size, format, args); + va_end (args); - if(m >= size){ - N = m < N ? N * 2 : N + 2*m; - char * tmp = realloc(globals.out_str, N); - if(!tmp){ - PRINT_ERR("cannot reallocate output buffer\n"); - abort(); - } - globals.out_str = tmp; - va_start(args, format); - vsnprintf(globals.out_str+n, N-n, format, args); - va_end(args); - } + if (m >= size) + { + N = m < N ? N * 2 : N + 2 * m; + char *tmp = realloc (globals.out_str, N); + if (!tmp) + { + PRINT_ERR ("cannot reallocate output buffer\n"); + abort (); + } + globals.out_str = tmp; + va_start (args, format); + vsnprintf (globals.out_str + n, N - n, format, args); + va_end (args); + } - n += m; - } + n += m; + } } -object * READ_FILES(allpars * ap){ - object * ret; - if(!globals.inp_mols){ - ret = read_files(ap); - } - else{ - ret = acs_from_var(globals.n_inp_mols, globals.inp_mols, globals.inp_vib, ap); - } - FREE0(ap->ip.input_files); +object * +READ_FILES (allpars *ap) +{ + object *ret; + if (!globals.inp_mols) + { + ret = read_files (ap); + } + else + { + ret = acs_from_var (globals.n_inp_mols, globals.inp_mols, + globals.inp_vib, ap); + } + FREE0 (ap->ip.input_files); return ret; } -int SHOULD_PRINT_MAN(int argc){ - if((argc==1) && (!globals.inp_mols)){ - return 1; - } +int +SHOULD_PRINT_MAN (int argc) +{ + if ((argc == 1) && (!globals.inp_mols)) + { + return 1; + } return 0; } diff --git a/src/math/3d.h b/src/math/3d.h index 4becc84..dd95236 100644 --- a/src/math/3d.h +++ b/src/math/3d.h @@ -1,14 +1,13 @@ #include "matrix.h" -#define DEG2RAD (M_PI/180.0) +#define DEG2RAD (M_PI / 180.0) -void rotmx0_update(double mx[9], double phi, int axis); -void rot3d(int n, double * v, const double * r, const double m[9]); -void rot3d_inplace(int n, double * r, const double m[9]); -void rotmx(double rot[9], const double u[3], double phi); -void rot_around_perp(double rot[9], double dx, double dy, double factor); -void mx3_lmultmx(const double A[9], double B[9]); +void rotmx0_update (double mx[9], double phi, int axis); +void rot3d (int n, double *v, const double *r, const double m[9]); +void rot3d_inplace (int n, double *r, const double m[9]); +void rotmx (double rot[9], const double u[3], double phi); +void rot_around_perp (double rot[9], double dx, double dy, double factor); +void mx3_lmultmx (const double A[9], double B[9]); -int zmat2cart(int n, double r[3], - const double a[3], const double b[3], const double c[3], - double R, double phi, double theta); +int zmat2cart (int n, double r[3], const double a[3], const double b[3], + const double c[3], double R, double phi, double theta); diff --git a/src/math/jacobi.c b/src/math/jacobi.c index 193c0a4..18630b8 100644 --- a/src/math/jacobi.c +++ b/src/math/jacobi.c @@ -1,94 +1,105 @@ #include "matrix.h" #include "mytime.h" -#define SIGN(X) ((X>=0.0 ? 1.0 : -1.0)) +#define SIGN(X) ((X >= 0.0 ? 1.0 : -1.0)) -static void givens(double * a, double * b, double * d, - double sinphi, double cosphi, - unsigned int n, unsigned int i, unsigned int j){ +static void +givens (double *a, double *b, double *d, double sinphi, double cosphi, + unsigned int n, unsigned int i, unsigned int j) +{ unsigned int l; double temp, g, h; /* rt * a * r: */ g = d[i]; h = d[j]; - temp = 2.0*cosphi*sinphi*a[mpos(i,j)]; - d[i] = cosphi*cosphi*g + sinphi*sinphi*h + temp; - d[j] = cosphi*cosphi*h + sinphi*sinphi*g - temp; - a[mpos(i,j)] = 0.0; - for (l=0; l #include #include -#include -#include "vecn.h" -#define symsize(M) (((M)*(M)+(M))/2) +#define symsize(M) (((M) * (M) + (M)) / 2) #ifndef MPOS_IS #define MPOS_IS -static inline unsigned int mpos(unsigned int i, unsigned int j){ -/* A[i+j*(j+1)/2], i <= j, 0 <= j < N */ - return (i)+(((j)*((j)+1))>>1); +static inline unsigned int +mpos (unsigned int i, unsigned int j) +{ + /* A[i+j*(j+1)/2], i <= j, 0 <= j < N */ + return (i) + (((j) * ((j) + 1)) >> 1); } -#define MPOSIF(i,j) ((i)<=(j)? mpos((i),(j)):mpos((j),(i))) +#define MPOSIF(i, j) ((i) <= (j) ? mpos ((i), (j)) : mpos ((j), (i))) #endif -void mx_id (unsigned int n, double * a); -void mx_multmx (unsigned int m, unsigned int n, unsigned int q, double * p, const double * a, const double * b); -int mx_inv (unsigned int n, unsigned int r, double * b, double * a, double eps); -void jacobi (double * a, double * b, double * d, unsigned int n, double eps, unsigned int rot, FILE * f); - +void mx_id (unsigned int n, double *a); +void mx_multmx (unsigned int m, unsigned int n, unsigned int q, double *p, + const double *a, const double *b); +int mx_inv (unsigned int n, unsigned int r, double *b, double *a, double eps); +void jacobi (double *a, double *b, double *d, unsigned int n, double eps, + unsigned int rot, FILE *f); diff --git a/src/math/mx_inv.c b/src/math/mx_inv.c index 5066ff9..4b7fbcd 100644 --- a/src/math/mx_inv.c +++ b/src/math/mx_inv.c @@ -4,61 +4,77 @@ * output: matrix B := A^(-1)*B */ -static inline void calc(double * a, double * b, - unsigned int n, unsigned int r, - unsigned int k, unsigned int j){ +static inline void +calc (double *a, double *b, unsigned int n, unsigned int r, unsigned int k, + unsigned int j) +{ unsigned int i; - double t = a[j*n+k]/a[k*n+k]; - a[j*n+k] = 0.0; - for(i=k+1; i fabs(a[m*n+k])){ - m = l; - } - } - if(fabs(a[m*n+k]) fabs (a[m * n + k])) + { + m = l; + } + } + if (fabs (a[m * n + k]) < eps) + { + return -1; + } - for(unsigned l=0; l= 0; k--) + { + for (int j = k - 1; j >= 0; j--) + { + calc (a, b, n, r, k, j); + } } - for(unsigned j=k+1; j eps) + { + double t = 1.0 / a[k * n + k]; + for (unsigned j = 0; j < r; j++) + { + b[k * r + j] *= t; + } + a[k * n + k] = 1.0; + } } - } - for(int k=n-1; k>=0; k--){ - for(int j=k-1; j>=0; j--){ - calc(a, b, n, r, k, j); - } - } - for(unsigned k=0; keps){ - double t = 1.0/a[k*n+k]; - for(unsigned j=0; j -#include #include +#include +#include -void vecset(size_t n, double * u, double s); -void vecsums(size_t n, double * w, const double * u, const double * v, double s); -void vecadds(size_t n, double * u, const double * v, double s); -void veccp(size_t n, double * u, const double * v); -void vecscal(size_t n, double * u, double s); +void vecset (size_t n, double *u, double s); +void vecsums (size_t n, double *w, const double *u, const double *v, double s); +void vecadds (size_t n, double *u, const double *v, double s); +void veccp (size_t n, double *u, const double *v); +void vecscal (size_t n, double *u, double s); diff --git a/src/math/zmat.c b/src/math/zmat.c index f1e8cca..c774804 100644 --- a/src/math/zmat.c +++ b/src/math/zmat.c @@ -3,60 +3,66 @@ #define EPS 1e-15 -int zmat2cart(int n, double r[3], - const double a[3], const double b[3], const double c[3], - double R, double phi, double theta){ - - if(n == 0){ - r[0] = r[1] = r[2] = 0.0; - } - - else if(n == 1){ - r[0] = a[0]; - r[1] = a[1] + R; - r[2] = a[2]; - } - - else if(n == 2){ - r[0] = a[0] + R * sqrt( 1 - cos(phi)*cos(phi) ); - r[1] = a[1] + ( (b[1] +#include #include +#include #include -#include -#define BA 0.5291772 -#define AB 1.88972616356109068947 +#define BA 0.5291772 +#define AB 1.88972616356109068947 #define S_TO_MS 1e6 -#define MS_TO_S (1.0/(S_TO_MS)) +#define MS_TO_S (1.0 / (S_TO_MS)) -#define CLOSE0(F) {if(F){ fclose(F); F = NULL; }} -#define FREE0(PTR) {if(PTR){ free(PTR); PTR = NULL; }} +#define CLOSE0(F) \ + { \ + if (F) \ + { \ + fclose (F); \ + F = NULL; \ + } \ + } +#define FREE0(PTR) \ + { \ + if (PTR) \ + { \ + free (PTR); \ + PTR = NULL; \ + } \ + } -#define MEM_END(S,X) ( (S)->X + (X##_size)/sizeof(*((S)->X)) ) +#define MEM_END(S, X) ((S)->X + (X##_size) / sizeof (*((S)->X))) -#define MAX(x,y) ( ((x) > (y)) ? (x) : (y) ) -#define MIN(x,y) ( ((x) < (y)) ? (x) : (y) ) +#define MAX(x, y) (((x) > (y)) ? (x) : (y)) +#define MIN(x, y) (((x) < (y)) ? (x) : (y)) -#define GOTOHELL { \ - fprintf(stderr, "%s:%d %s() -- ", \ - __FILE__, __LINE__, __FUNCTION__); \ - abort(); } +#define GOTOHELL \ + { \ + fprintf (stderr, "%s:%d %s() -- ", __FILE__, __LINE__, __FUNCTION__); \ + abort (); \ + } -#define printalive {printf("alive @ %s:%d\n", __FILE__, __LINE__); fflush(stdout);} +#define printalive \ + { \ + printf ("alive @ %s:%d\n", __FILE__, __LINE__); \ + fflush (stdout); \ + } -#define PRINT_ERR(...) {\ - fprintf(stderr, "\e[1;31m" "error: " "\e[0m" "\e[1;30m" "[%s:%d]" "\e[0m ", __FILE__, __LINE__);\ - fprintf(stderr, __VA_ARGS__ );\ -} -#define PRINT_WARN(...) {\ - fprintf(stderr, "\e[1;35m" "warning: " "\e[0m" "\e[1;30m" "[%s:%d]" "\e[0m ", __FILE__, __LINE__);\ - fprintf(stderr, __VA_ARGS__ );\ -} +#define PRINT_ERR(...) \ + { \ + fprintf (stderr, \ + "\e[1;31m" \ + "error: " \ + "\e[0m" \ + "\e[1;30m" \ + "[%s:%d]" \ + "\e[0m ", \ + __FILE__, __LINE__); \ + fprintf (stderr, __VA_ARGS__); \ + } +#define PRINT_WARN(...) \ + { \ + fprintf (stderr, \ + "\e[1;35m" \ + "warning: " \ + "\e[0m" \ + "\e[1;30m" \ + "[%s:%d]" \ + "\e[0m ", \ + __FILE__, __LINE__); \ + fprintf (stderr, __VA_ARGS__); \ + } typedef char styp[8]; - diff --git a/src/mol/elements.h b/src/mol/elements.h index 27f3597..24b1ddd 100644 --- a/src/mol/elements.h +++ b/src/mol/elements.h @@ -1,31 +1,32 @@ - [ 0] = "", - [ 1] = "H", [ 2] = "He", - [ 3] = "Li", [ 4] = "Be", [ 5] = "B", [ 6] = "C", [ 7] = "N", [ 8] = "O", [ 9] = "F", [ 10] = "Ne", - [ 11] = "Na", [ 12] = "Mg", [ 13] = "Al", [ 14] = "Si", [ 15] = "P", [ 16] = "S", [ 17] = "Cl", [ 18] = "Ar", - [ 19] = "K", [ 20] = "Ca", - - [ 21] = "Sc", [ 22] = "Ti", [ 23] = "V", [ 24] = "Cr", [ 25] = "Mn", [ 26] = "Fe", [ 27] = "Co", [ 28] = "Ni", - [ 29] = "Cu", [ 30] = "Zn", - - [ 31] = "Ga", [ 32] = "Ge", [ 33] = "As", [ 34] = "Se", [ 35] = "Br", [ 36] = "Kr", - [ 37] = "Rb", [ 38] = "Sr", - - [ 39] = "Y", [ 40] = "Zr", [ 41] = "Nb", [ 42] = "Mo", [ 43] = "Tc", [ 44] = "Ru", [ 45] = "Rh", [ 46] = "Pd", - [ 47] = "Ag", [ 48] = "Cd", - - [ 49] = "In", [ 50] = "Sn", [ 51] = "Sb", [ 52] = "Te", [ 53] = "I", [ 54] = "Xe", - [ 55] = "Cs", [ 56] = "Ba", - - [ 57] = "La", [ 58] = "Ce", [ 59] = "Pr", [ 60] = "Nd", [ 61] = "Pm", [ 62] = "Sm", [ 63] = "Eu", - [ 64] = "Gd", [ 65] = "Tb", [ 66] = "Dy", [ 67] = "Ho", [ 68] = "Er", [ 69] = "Tm", [ 70] = "Yb", - [ 71] = "Lu", [ 72] = "Hf", [ 73] = "Ta", [ 74] = "W", [ 75] = "Re", [ 76] = "Os", [ 77] = "Ir", [ 78] = "Pt", - [ 79] = "Au", [ 80] = "Hg", - - [ 81] = "Tl", [ 82] = "Pb", [ 83] = "Bi", [ 84] = "Po", [ 85] = "At", [ 86] = "Rn", - [ 87] = "Fr", [ 88] = "Ra", - [ 89] = "Ac", [ 90] = "Th", [ 91] = "Pa", [ 92] = "U", [ 93] = "Np", [ 94] = "Pu", [ 95] = "Am", - [ 96] = "Cm", [ 97] = "Bk", [ 98] = "Cf", [ 99] = "Es", [100] = "Fm", [101] = "Md", [102] = "No", - [103] = "Lr", [104] = "Rf", [105] = "Db", [106] = "Sg", [107] = "Bh", [108] = "Hs", [109] = "Mt", [110] = "Ds", - [111] = "Rg", [112] = "Cn", [113] = "Nh", [114] = "Fl", [115] = "Mc", [116] = "Lv", [117] = "Ts", [118] = "Og", - +[0] = "", [1] = "H", [2] = "He", [3] = "Li", [4] = "Be", [5] = "B", [6] = "C", + [7] = "N", [8] = "O", [9] = "F", [10] = "Ne", [11] = "Na", + [12] = "Mg", [13] = "Al", [14] = "Si", [15] = "P", [16] = "S", + [17] = "Cl", [18] = "Ar", [19] = "K", [20] = "Ca", + + [21] = "Sc", [22] = "Ti", [23] = "V", [24] = "Cr", [25] = "Mn", + [26] = "Fe", [27] = "Co", [28] = "Ni", [29] = "Cu", [30] = "Zn", + + [31] = "Ga", [32] = "Ge", [33] = "As", [34] = "Se", [35] = "Br", + [36] = "Kr", [37] = "Rb", [38] = "Sr", + + [39] = "Y", [40] = "Zr", [41] = "Nb", [42] = "Mo", [43] = "Tc", + [44] = "Ru", [45] = "Rh", [46] = "Pd", [47] = "Ag", [48] = "Cd", + + [49] = "In", [50] = "Sn", [51] = "Sb", [52] = "Te", [53] = "I", + [54] = "Xe", [55] = "Cs", [56] = "Ba", + + [57] = "La", [58] = "Ce", [59] = "Pr", [60] = "Nd", [61] = "Pm", + [62] = "Sm", [63] = "Eu", [64] = "Gd", [65] = "Tb", [66] = "Dy", + [67] = "Ho", [68] = "Er", [69] = "Tm", [70] = "Yb", [71] = "Lu", + [72] = "Hf", [73] = "Ta", [74] = "W", [75] = "Re", [76] = "Os", + [77] = "Ir", [78] = "Pt", [79] = "Au", [80] = "Hg", + + [81] = "Tl", [82] = "Pb", [83] = "Bi", [84] = "Po", [85] = "At", + [86] = "Rn", [87] = "Fr", [88] = "Ra", [89] = "Ac", [90] = "Th", + [91] = "Pa", [92] = "U", [93] = "Np", [94] = "Pu", [95] = "Am", + [96] = "Cm", [97] = "Bk", [98] = "Cf", [99] = "Es", [100] = "Fm", + [101] = "Md", [102] = "No", [103] = "Lr", [104] = "Rf", [105] = "Db", + [106] = "Sg", [107] = "Bh", [108] = "Hs", [109] = "Mt", [110] = "Ds", + [111] = "Rg", [112] = "Cn", [113] = "Nh", [114] = "Fl", [115] = "Mc", + [116] = "Lv", [117] = "Ts", [118] = "Og", diff --git a/src/mol/inertia.c b/src/mol/inertia.c index ba4e9b1..d3a7b77 100644 --- a/src/mol/inertia.c +++ b/src/mol/inertia.c @@ -1,94 +1,114 @@ -#include "mol.h" #include "matrix.h" +#include "mol.h" #include "vec3.h" #define EPS 1e-10 #define EIGEN_EPS 1e-15 #define EIGEN_NIT 20 -static inline void swap_ev(double d[3], double I_b[9], int i, int j){ +static inline void +swap_ev (double d[3], double I_b[9], int i, int j) +{ double td = d[i]; d[i] = d[j]; d[j] = td; double tb[3]; - r3cp(tb, I_b+i*3); - r3cp(I_b+i*3, I_b+j*3); - r3cp(I_b+j*3, tb); + r3cp (tb, I_b + i * 3); + r3cp (I_b + i * 3, I_b + j * 3); + r3cp (I_b + j * 3, tb); } -static const double amass[]={ - #include "masses.h" +static const double amass[] = { +#include "masses.h" }; -static double get_mass(int q){ - q = abs(q); - if(q < sizeof(amass)/sizeof(amass[0])){ - return amass[q]; - } - else{ - // fit for 86-111 - return 2.0795 * q + 44.9095; - } +static double +get_mass (int q) +{ + q = abs (q); + if (q < sizeof (amass) / sizeof (amass[0])) + { + return amass[q]; + } + else + { + // fit for 86-111 + return 2.0795 * q + 44.9095; + } } -void center_mol(int n, double * r, const int * q){ - double c[3] = {0,0,0}; +void +center_mol (int n, double *r, const int *q) +{ + double c[3] = { 0, 0, 0 }; double s = 0.0; - for(int i=0; in, m->r, m->q); - double I_t[6]={}; - for(int i=0; in; i++){ - double tm = get_mass(m->q[i]); - double x = m->r[3*i ]; - double y = m->r[3*i+1]; - double z = m->r[3*i+2]; - I_t[mpos(0,0)] += tm * (y*y + z*z); //Ixx - I_t[mpos(1,1)] += tm * (x*x + z*z); //Iyy - I_t[mpos(2,2)] += tm * (x*x + y*y); //Izz - I_t[mpos(0,1)] -= tm * (x*y); //Ixy - I_t[mpos(0,2)] -= tm * (x*z); //Ixz - I_t[mpos(1,2)] -= tm * (y*z); //Iyz - } - double I_b[9]={1,0,0, 0,1,0, 0,0,1}; - jacobi(I_t, I_b, d, 3, EIGEN_EPS, EIGEN_NIT, NULL); + if (!d) + { + d = _d; + } + center_mol (m->n, m->r, m->q); + double I_t[6] = {}; + for (int i = 0; i < m->n; i++) + { + double tm = get_mass (m->q[i]); + double x = m->r[3 * i]; + double y = m->r[3 * i + 1]; + double z = m->r[3 * i + 2]; + I_t[mpos (0, 0)] += tm * (y * y + z * z); // Ixx + I_t[mpos (1, 1)] += tm * (x * x + z * z); // Iyy + I_t[mpos (2, 2)] += tm * (x * x + y * y); // Izz + I_t[mpos (0, 1)] -= tm * (x * y); // Ixy + I_t[mpos (0, 2)] -= tm * (x * z); // Ixz + I_t[mpos (1, 2)] -= tm * (y * z); // Iyz + } + double I_b[9] = { 1, 0, 0, 0, 1, 0, 0, 0, 1 }; + jacobi (I_t, I_b, d, 3, EIGEN_EPS, EIGEN_NIT, NULL); - //sort ev - if(d[0]n; i++){ - double u[3]; - r3mx(u, m->r+i*3, I_b); - r3cp(m->r+i*3, u); - } + for (int i = 0; i < m->n; i++) + { + double u[3]; + r3mx (u, m->r + i * 3, I_b); + r3cp (m->r + i * 3, u); + } return; } diff --git a/src/mol/intcoord.c b/src/mol/intcoord.c index fed91a7..b2d58c1 100644 --- a/src/mol/intcoord.c +++ b/src/mol/intcoord.c @@ -1,78 +1,100 @@ #include "mol.h" #include "vec3.h" -#define SIGN(X) ((X>=0.0 ? 1.0 : -1.0)) +#define SIGN(X) ((X >= 0.0 ? 1.0 : -1.0)) -double intcoord_calc(int r_units_a, int check_n, const int z[5], const double * r){ - if(z[1]>check_n || z[2]>check_n || z[3]>check_n || z[4]>check_n){ - return -1.0; - } +double +intcoord_calc (int r_units_a, int check_n, const int z[5], const double *r) +{ + if (z[1] > check_n || z[2] > check_n || z[3] > check_n || z[4] > check_n) + { + return -1.0; + } double t; - const double * a1 = r+(z[1]-1)*3; - const double * a2 = r+(z[2]-1)*3; - const double * a3 = r+(z[3]-1)*3; - const double * a4 = r+(z[4]-1)*3; + const double *a1 = r + (z[1] - 1) * 3; + const double *a2 = r + (z[2] - 1) * 3; + const double *a3 = r + (z[3] - 1) * 3; + const double *a4 = r + (z[4] - 1) * 3; double v1[3], v2[3], v3[3], v4[3], v5[3], v1x3[3]; - switch(z[0]){ - case 3 : - r3diff(v1, a2, a1); - r3diff(v2, a2, a3); - r3diff(v3, a3, a4); - r3x(v4,v1,v2); - r3x(v5,v3,v2); - r3x(v1x3,v1,v3); - t = r3dot(v4,v5) / sqrt( r3dot(v4,v4)*r3dot(v5,v5) ); - if(t>1.0){ - t = 1.0; - } - else if(t<-1.0){ - t = -1.0; - } - return acos(t)*M_1_PI*180.0 * SIGN( r3dot(v2,v1x3) ); - case 2 : - r3diff(v4, a2, a1); - r3diff(v5, a2, a3); - t = r3dot(v4,v5) / sqrt( r3dot(v4,v4)*r3dot(v5,v5) ); - return acos(t)*M_1_PI*180.0; - case 1 : - return sqrt(r3d2(a1,a2))* (r_units_a?1.0:BA); /* return R12 in ångströms whatever units are in input */ + switch (z[0]) + { + case 3: + r3diff (v1, a2, a1); + r3diff (v2, a2, a3); + r3diff (v3, a3, a4); + r3x (v4, v1, v2); + r3x (v5, v3, v2); + r3x (v1x3, v1, v3); + t = r3dot (v4, v5) / sqrt (r3dot (v4, v4) * r3dot (v5, v5)); + if (t > 1.0) + { + t = 1.0; + } + else if (t < -1.0) + { + t = -1.0; + } + return acos (t) * M_1_PI * 180.0 * SIGN (r3dot (v2, v1x3)); + case 2: + r3diff (v4, a2, a1); + r3diff (v5, a2, a3); + t = r3dot (v4, v5) / sqrt (r3dot (v4, v4) * r3dot (v5, v5)); + return acos (t) * M_1_PI * 180.0; + case 1: + return sqrt (r3d2 (a1, a2)) + * (r_units_a ? 1.0 : BA); /* return R12 in ångströms whatever + units are in input */ default: return 0.0; - } + } } -int intcoord_check(int n, int z[5]){ - if(!(z[0]||z[1]||z[2]||z[3]||z[4])){ - return 0; - } - switch(z[0]){ - case 3 : - if (z[4] < 1 || z[4] > n) z[0] = 0; - if (z[4] == z[3]) z[0] = 0; - if (z[4] == z[2]) z[0] = 0; - if (z[4] == z[1]) z[0] = 0; - case 2 : - if (z[3] < 1 || z[3] > n) z[0] = 0; - if (z[3] == z[2]) z[0] = 0; - if (z[3] == z[1]) z[0] = 0; - case 1 : - if (z[1] < 1 || z[1] > n) z[0] = 0; - if (z[2] < 1 || z[2] > n) z[0] = 0; - if (z[1] == z[2]) z[0] = 0; +int +intcoord_check (int n, int z[5]) +{ + if (!(z[0] || z[1] || z[2] || z[3] || z[4])) + { + return 0; + } + switch (z[0]) + { + case 3: + if (z[4] < 1 || z[4] > n) + z[0] = 0; + if (z[4] == z[3]) + z[0] = 0; + if (z[4] == z[2]) + z[0] = 0; + if (z[4] == z[1]) + z[0] = 0; + case 2: + if (z[3] < 1 || z[3] > n) + z[0] = 0; + if (z[3] == z[2]) + z[0] = 0; + if (z[3] == z[1]) + z[0] = 0; + case 1: + if (z[1] < 1 || z[1] > n) + z[0] = 0; + if (z[2] < 1 || z[2] > n) + z[0] = 0; + if (z[1] == z[2]) + z[0] = 0; break; case 4: // TODO case 5: // TODO default: z[0] = 0; - } - switch(z[0]){ - case 0 : - PRINT_WARN("check the internal coordintate option ('z:')\n"); + } + switch (z[0]) + { + case 0: + PRINT_WARN ("check the internal coordintate option ('z:')\n"); return -1; - case 1 : + case 1: z[3] = 0; - case 2 : + case 2: z[4] = 0; - } + } return 0; } - diff --git a/src/mol/masses.h b/src/mol/masses.h index f2a3b41..4e06d5b 100644 --- a/src/mol/masses.h +++ b/src/mol/masses.h @@ -1,31 +1,36 @@ /* http://www.ciaaw.org/atomic-masses.htm */ -[ 0] = 0.0 , -[ 1] = 1.00782503226, [ 2] = 4.00260325414, [ 3] = 7.016003443 , [ 4] = 9.01218315 , -[ 5] = 11.0093053 , [ 6] = 12.0 , [ 7] = 14.0030740042 , [ 8] = 15.9949146202 , -[ 9] = 18.9984031636 , [ 10] = 19.992440182 , [ 11] = 22.989769282 , [ 12] = 23.985041709 , -[ 13] = 26.98153857 , [ 14] = 27.9769265353 , [ 15] = 30.9737619985 , [ 16] = 31.9720711749 , -[ 17] = 34.96885273 , [ 18] = 39.962383122 , [ 19] = 38.963706493 , [ 20] = 39.96259092 , -[ 21] = 44.9559085 , [ 22] = 47.9479423 , [ 23] = 50.9439576 , [ 24] = 51.9405064 , -[ 25] = 54.9380443 , [ 26] = 55.9349363 , [ 27] = 58.9331944 , [ 28] = 57.9353423 , -[ 29] = 62.9295984 , [ 30] = 63.9291425 , [ 31] = 68.9255748 , [ 32] = 73.921177769 , -[ 33] = 74.9215956 , [ 34] = 79.9165228 , [ 35] = 78.9183389 , [ 36] = 83.911497733 , -[ 37] = 84.911789743 , [ 38] = 87.9056138 , [ 39] = 88.905842 , [ 40] = 89.904702 , -[ 41] = 92.906372 , [ 42] = 97.9054053 , [ 43] = 97.907213 , [ 44] = 101.9043448 , -[ 45] = 102.905502 , [ 46] = 105.9034808 , [ 47] = 106.905092 , [ 48] = 113.9033653 , -[ 49] = 114.903878788 , [ 50] = 119.9022026 , [ 51] = 120.903812 , [ 52] = 129.906222758 , -[ 53] = 126.904473 , [ 54] = 131.904155094 , [ 55] = 132.905451966 , [ 56] = 137.9052472 , -[ 57] = 138.906362 , [ 58] = 139.905442 , [ 59] = 140.907662 , [ 60] = 141.907732 , -[ 61] = 144.912762 , [ 62] = 151.919742 , [ 63] = 152.921242 , [ 64] = 157.924112 , -[ 65] = 158.925352 , [ 66] = 163.929182 , [ 67] = 164.930332 , [ 68] = 165.930302 , -[ 69] = 168.934222 , [ 70] = 173.938872 , [ 71] = 174.940782 , [ 72] = 179.946562 , -[ 73] = 180.948002 , [ 74] = 183.9509316 , [ 75] = 186.955751 , [ 76] = 191.961482 , -[ 77] = 192.962922 , [ 78] = 194.9647926 , [ 79] = 196.9665695 , [ 80] = 201.9706435 , -[ 81] = 204.9744289 , [ 82] = 207.9766538 , [ 83] = 208.980401 , [ 84] = 208.982416 , -[ 85] = 209.987131 , [ 86] = 222.01757 , [ 87] = 223.019731 , [ 88] = 226.025403 , -[ 89] = 227.027747 , [ 90] = 232.038062 , [ 91] = 231.035882 , [ 92] = 238.050792 , -[ 93] = 237.048167 , [ 94] = 244.064198 , [ 95] = 243.061373 , [ 96] = 247.070347 , -[ 97] = 247.070299 , [ 98] = 251.07958 , [ 99] = 252.082972 , [100] = 257.095099 , -[101] = 258.098425 , [102] = 259.101024 , [103] = 262.109692 , [104] = 263.118313 , -[105] = 262.011437 , [106] = 266.012238 , [107] = 264.012496 , [108] = 269.001341 , -[109] = 268.001388 , [110] = 272.001463 , [111] = 272.001535 +[0] = 0.0, + [1] = 1.00782503226, [2] = 4.00260325414, [3] = 7.016003443, + [4] = 9.01218315, [5] = 11.0093053, [6] = 12.0, [7] = 14.0030740042, + [8] = 15.9949146202, [9] = 18.9984031636, [10] = 19.992440182, + [11] = 22.989769282, [12] = 23.985041709, [13] = 26.98153857, + [14] = 27.9769265353, [15] = 30.9737619985, [16] = 31.9720711749, + [17] = 34.96885273, [18] = 39.962383122, [19] = 38.963706493, + [20] = 39.96259092, [21] = 44.9559085, [22] = 47.9479423, + [23] = 50.9439576, [24] = 51.9405064, [25] = 54.9380443, [26] = 55.9349363, + [27] = 58.9331944, [28] = 57.9353423, [29] = 62.9295984, [30] = 63.9291425, + [31] = 68.9255748, [32] = 73.921177769, [33] = 74.9215956, + [34] = 79.9165228, [35] = 78.9183389, [36] = 83.911497733, + [37] = 84.911789743, [38] = 87.9056138, [39] = 88.905842, [40] = 89.904702, + [41] = 92.906372, [42] = 97.9054053, [43] = 97.907213, [44] = 101.9043448, + [45] = 102.905502, [46] = 105.9034808, [47] = 106.905092, + [48] = 113.9033653, [49] = 114.903878788, [50] = 119.9022026, + [51] = 120.903812, [52] = 129.906222758, [53] = 126.904473, + [54] = 131.904155094, [55] = 132.905451966, [56] = 137.9052472, + [57] = 138.906362, [58] = 139.905442, [59] = 140.907662, [60] = 141.907732, + [61] = 144.912762, [62] = 151.919742, [63] = 152.921242, [64] = 157.924112, + [65] = 158.925352, [66] = 163.929182, [67] = 164.930332, [68] = 165.930302, + [69] = 168.934222, [70] = 173.938872, [71] = 174.940782, [72] = 179.946562, + [73] = 180.948002, [74] = 183.9509316, [75] = 186.955751, + [76] = 191.961482, [77] = 192.962922, [78] = 194.9647926, + [79] = 196.9665695, [80] = 201.9706435, [81] = 204.9744289, + [82] = 207.9766538, [83] = 208.980401, [84] = 208.982416, + [85] = 209.987131, [86] = 222.01757, [87] = 223.019731, [88] = 226.025403, + [89] = 227.027747, [90] = 232.038062, [91] = 231.035882, [92] = 238.050792, + [93] = 237.048167, [94] = 244.064198, [95] = 243.061373, [96] = 247.070347, + [97] = 247.070299, [98] = 251.07958, [99] = 252.082972, [100] = 257.095099, + [101] = 258.098425, [102] = 259.101024, [103] = 262.109692, + [104] = 263.118313, [105] = 262.011437, [106] = 266.012238, + [107] = 264.012496, [108] = 269.001341, [109] = 268.001388, + [110] = 272.001463, [111] = 272.001535 diff --git a/src/mol/mol.h b/src/mol/mol.h index 62b3f42..b1a8e2e 100644 --- a/src/mol/mol.h +++ b/src/mol/mol.h @@ -3,29 +3,34 @@ #include "common.h" -typedef struct { - double * r; - int * q; - const char * name; - int n; +typedef struct +{ + double *r; + int *q; + const char *name; + int n; } mol; -static inline mol * alloc_mol(int n){ - size_t r_size = sizeof(double) * n*3; - size_t q_size = sizeof(int ) * n; - mol * m = calloc(sizeof(mol)+r_size+q_size, 1); - if(!m) GOTOHELL; - m->r = (double *) (m + 1); - m->q = (int *) MEM_END(m, r); // cppcheck-suppress invalidPointerCast +static inline mol * +alloc_mol (int n) +{ + size_t r_size = sizeof (double) * n * 3; + size_t q_size = sizeof (int) * n; + mol *m = calloc (sizeof (mol) + r_size + q_size, 1); + if (!m) + GOTOHELL; + m->r = (double *)(m + 1); + m->q = (int *)MEM_END (m, r); // cppcheck-suppress invalidPointerCast m->name = NULL; m->n = n; return m; } -void position(mol * m, double d[3], int preserve_chirality); -void center_mol(int n, double * r, const int * q); +void position (mol *m, double d[3], int preserve_chirality); +void center_mol (int n, double *r, const int *q); -int intcoord_check(int n, int z[5]); -double intcoord_calc (int r_units_a, int check_n, const int z[5], const double * r); +int intcoord_check (int n, int z[5]); +double intcoord_calc (int r_units_a, int check_n, const int z[5], + const double *r); #endif diff --git a/src/mol/mytime.h b/src/mol/mytime.h index 12c0375..80d2d95 100644 --- a/src/mol/mytime.h +++ b/src/mol/mytime.h @@ -1,9 +1,10 @@ -#include #include +#include -static inline double myutime(){ +static inline double +myutime () +{ struct rusage usage; - getrusage(RUSAGE_SELF, &usage); - return usage.ru_utime.tv_sec + usage.ru_utime.tv_usec*1e-6; + getrusage (RUSAGE_SELF, &usage); + return usage.ru_utime.tv_sec + usage.ru_utime.tv_usec * 1e-6; } - diff --git a/src/mol/palette_cpk.h b/src/mol/palette_cpk.h index 774284f..49311d7 100644 --- a/src/mol/palette_cpk.h +++ b/src/mol/palette_cpk.h @@ -1,110 +1,109 @@ - [ 0] = {0x9999, 0x9999, 0x9999}, - [ 1] = {0xBFFF, 0xBFFF, 0xBFFF}, /* H */ - [ 2] = {0xD9D9, 0xFFFF, 0xFFFF}, /* He */ - [ 3] = {0xCCCC, 0x8080, 0xFFFF}, /* Li */ - [ 4] = {0xC2C2, 0xFFFF, 0x0000}, /* Be */ - [ 5] = {0xFFFF, 0xB5B5, 0xB5B5}, /* B */ - [ 6] = {0x5FFF, 0x5FFF, 0x5FFF}, /* C */ - [ 7] = {0x1FFF, 0x1FFF, 0xBFFF}, /* N */ - [ 8] = {0xBFFF, 0x1FFF, 0x1FFF}, /* O */ - [ 9] = {0xF500, 0xFFFF, 0x8500}, /* F */ - [ 10] = {0xAAAA, 0xFFFF, 0xFFFF}, /* Ne */ - [ 11] = {0xABAB, 0x5C5C, 0xF2F2}, /* Na */ - [ 12] = {0x8A8A, 0xFFFF, 0x0000}, /* Mg */ - [ 13] = {0xBFBF, 0xA6A6, 0xA6A6}, /* Al */ - [ 14] = {0x5FFF, 0x5FFF, 0x5FFF}, /* Si */ - [ 15] = {0xFFFF, 0xCCCC, 0x9999}, /* P */ - [ 16] = {0xFFFF, 0xEEEE, 0x1111}, /* S */ - [ 17] = {0xCCCC, 0xFFFF, 0x9999}, /* Cl */ - [ 18] = {0xAAAA, 0xFFFF, 0xFFFF}, /* Ar */ - [ 19] = {0x8F8F, 0x4040, 0xD4D4}, /* K */ - [ 20] = {0x3D3D, 0xFFFF, 0x0000}, /* Ca */ - [ 21] = {0xE6E6, 0xE6E6, 0xE6E6}, /* Sc */ - [ 22] = {0xBFBF, 0xC2C2, 0xC7C7}, /* Ti */ - [ 23] = {0xA6A6, 0xA6A6, 0xABAB}, /* V */ - [ 24] = {0x8A8A, 0x9999, 0xC7C7}, /* Cr */ - [ 25] = {0x9C9C, 0x7A7A, 0xC7C7}, /* Mn */ - [ 26] = {0xDDDD, 0x6666, 0x3333}, /* Fe */ - [ 27] = {0xEEEE, 0x8888, 0x9999}, /* Co */ - [ 28] = {0x5050, 0xD0D0, 0x5050}, /* Ni */ - [ 29] = {0xBBBB, 0x7777, 0x3333}, /* Cu */ - [ 30] = {0x7D7D, 0x8080, 0xB0B0}, /* Zn */ - [ 31] = {0xC2C2, 0x8F8F, 0x8F8F}, /* Ga */ - [ 32] = {0x6666, 0x8F8F, 0x8F8F}, /* Ge */ - [ 33] = {0xBDBD, 0x8080, 0xE3E3}, /* As */ - [ 34] = {0xFFFF, 0xAAAA, 0x1111}, /* Se */ - [ 35] = {0xAAAA, 0x4444, 0x0000}, /* Br */ - [ 36] = {0xAAAA, 0xFFFF, 0xFFFF}, /* Kr */ - [ 37] = {0x7070, 0x2E2E, 0xB0B0}, /* Rb */ - [ 38] = {0x0000, 0xFFFF, 0x0000}, /* Sr */ - [ 39] = {0x9494, 0xFFFF, 0xFFFF}, /* Y */ - [ 40] = {0x9494, 0xE0E0, 0xE0E0}, /* Zr */ - [ 41] = {0x7373, 0xC2C2, 0xC9C9}, /* Nb */ - [ 42] = {0x5454, 0xB5B5, 0xB5B5}, /* Mo */ - [ 43] = {0x3B3B, 0x9E9E, 0x9E9E}, /* Tc */ - [ 44] = {0x2424, 0x8F8F, 0x8F8F}, /* Ru */ - [ 45] = {0x0A0A, 0x7D7D, 0x8C8C}, /* Rh */ - [ 46] = {0x0000, 0x6969, 0x8585}, /* Pd */ - [ 47] = {0xC0C0, 0xC0C0, 0xC0C0}, /* Ag */ - [ 48] = {0xFFFF, 0xD9D9, 0x8F8F}, /* Cd */ - [ 49] = {0xA6A6, 0x7575, 0x7373}, /* In */ - [ 50] = {0x6666, 0x8080, 0x8080}, /* Sn */ - [ 51] = {0x9E9E, 0x6363, 0xB5B5}, /* Sb */ - [ 52] = {0xD4D4, 0x7A7A, 0x0000}, /* Te */ - [ 53] = {0x9494, 0x0000, 0x9494}, /* I */ - [ 54] = {0x4242, 0x9E9E, 0xB0B0}, /* Xe */ - [ 55] = {0x5757, 0x1717, 0x8F8F}, /* Cs */ - [ 56] = {0x0000, 0xC9C9, 0x0000}, /* Ba */ - [ 57] = {0x7070, 0xD4D4, 0xFFFF}, /* La */ - [ 58] = {0xFFFF, 0xFFFF, 0xC7C7}, /* Ce */ - [ 59] = {0xD9D9, 0xFFFF, 0xC7C7}, /* Pr */ - [ 60] = {0xC7C7, 0xFFFF, 0xC7C7}, /* Nd */ - [ 61] = {0xA3A3, 0xFFFF, 0xC7C7}, /* Pm */ - [ 62] = {0x8F8F, 0xFFFF, 0xC7C7}, /* Sm */ - [ 63] = {0x6161, 0xFFFF, 0xC7C7}, /* Eu */ - [ 64] = {0x4545, 0xFFFF, 0xC7C7}, /* Gd */ - [ 65] = {0x3030, 0xFFFF, 0xC7C7}, /* Tb */ - [ 66] = {0x1F1F, 0xFFFF, 0xC7C7}, /* Dy */ - [ 67] = {0x0000, 0xFFFF, 0x9C9C}, /* Ho */ - [ 68] = {0x0000, 0xE6E6, 0x7575}, /* Er */ - [ 69] = {0x0000, 0xD4D4, 0x5252}, /* Tm */ - [ 70] = {0x0000, 0xBFBF, 0x3838}, /* Yb */ - [ 71] = {0x0000, 0xABAB, 0x2424}, /* Lu */ - [ 72] = {0x4D4D, 0xC2C2, 0xFFFF}, /* Hf */ - [ 73] = {0x4D4D, 0xA6A6, 0xFFFF}, /* Ta */ - [ 74] = {0x2121, 0x9494, 0xD6D6}, /* W */ - [ 75] = {0x2626, 0x7D7D, 0xABAB}, /* Re */ - [ 76] = {0x2626, 0x6666, 0x9696}, /* Os */ - [ 77] = {0x1717, 0x5454, 0x8787}, /* Ir */ - [ 78] = {0xD0D0, 0xD0D0, 0xE0E0}, /* Pt */ - [ 79] = {0xFFFF, 0xD1D1, 0x2323}, /* Au */ - [ 80] = {0xB8B8, 0xB8B8, 0xD0D0}, /* Hg */ - [ 81] = {0xA6A6, 0x5454, 0x4D4D}, /* Tl */ - [ 82] = {0x5757, 0x5959, 0x6161}, /* Pb */ - [ 83] = {0x9E9E, 0x4F4F, 0xB5B5}, /* Bi */ - [ 84] = {0xABAB, 0x5C5C, 0x0000}, /* Po */ - [ 85] = {0x7575, 0x4F4F, 0x4545}, /* At */ - [ 86] = {0x4242, 0x8282, 0x9696}, /* Rn */ - [ 87] = {0x4242, 0x0000, 0x6666}, /* Fr */ - [ 88] = {0x0000, 0x7D7D, 0x0000}, /* Ra */ - [ 89] = {0x7070, 0xABAB, 0xFAFA}, /* Ac */ - [ 90] = {0x0000, 0xBABA, 0xFFFF}, /* Th */ - [ 91] = {0x0000, 0xA1A1, 0xFFFF}, /* Pa */ - [ 92] = {0x0000, 0x8F8F, 0xFFFF}, /* U */ - [ 93] = {0x0000, 0x8080, 0xFFFF}, /* Np */ - [ 94] = {0x0000, 0x6B6B, 0xFFFF}, /* Pu */ - [ 95] = {0x5454, 0x5C5C, 0xF2F2}, /* Am */ - [ 96] = {0x7878, 0x5C5C, 0xE3E3}, /* Cm */ - [ 97] = {0x8A8A, 0x4F4F, 0xE3E3}, /* Bk */ - [ 98] = {0xA1A1, 0x3636, 0xD4D4}, /* Cf */ - [ 99] = {0xB3B3, 0x1F1F, 0xD4D4}, /* Es */ - [100] = {0xB3B3, 0x1F1F, 0xBABA}, /* Fm */ - [101] = {0xB3B3, 0x0D0D, 0xA6A6}, /* Md */ - [102] = {0xBDBD, 0x0D0D, 0x8787}, /* No */ - [103] = {0xC7C7, 0x0000, 0x6666}, /* Lr */ - [104] = {0xCCCC, 0x0000, 0x5959}, /* Rf */ - [105] = {0xD1D1, 0x0000, 0x4F4F}, /* Db */ - [106] = {0xD9D9, 0x0000, 0x4545}, /* Sg */ - [107] = {0xE0E0, 0x0000, 0x3838}, /* Bh */ - [108] = {0xE6E6, 0x0000, 0x2E2E}, /* Hs */ - [109] = {0xEBEB, 0x0000, 0x2626}, /* Mt */ +[0] = { 0x9999, 0x9999, 0x9999 }, [1] = { 0xBFFF, 0xBFFF, 0xBFFF }, /* H */ + [2] = { 0xD9D9, 0xFFFF, 0xFFFF }, /* He */ + [3] = { 0xCCCC, 0x8080, 0xFFFF }, /* Li */ + [4] = { 0xC2C2, 0xFFFF, 0x0000 }, /* Be */ + [5] = { 0xFFFF, 0xB5B5, 0xB5B5 }, /* B */ + [6] = { 0x5FFF, 0x5FFF, 0x5FFF }, /* C */ + [7] = { 0x1FFF, 0x1FFF, 0xBFFF }, /* N */ + [8] = { 0xBFFF, 0x1FFF, 0x1FFF }, /* O */ + [9] = { 0xF500, 0xFFFF, 0x8500 }, /* F */ + [10] = { 0xAAAA, 0xFFFF, 0xFFFF }, /* Ne */ + [11] = { 0xABAB, 0x5C5C, 0xF2F2 }, /* Na */ + [12] = { 0x8A8A, 0xFFFF, 0x0000 }, /* Mg */ + [13] = { 0xBFBF, 0xA6A6, 0xA6A6 }, /* Al */ + [14] = { 0x5FFF, 0x5FFF, 0x5FFF }, /* Si */ + [15] = { 0xFFFF, 0xCCCC, 0x9999 }, /* P */ + [16] = { 0xFFFF, 0xEEEE, 0x1111 }, /* S */ + [17] = { 0xCCCC, 0xFFFF, 0x9999 }, /* Cl */ + [18] = { 0xAAAA, 0xFFFF, 0xFFFF }, /* Ar */ + [19] = { 0x8F8F, 0x4040, 0xD4D4 }, /* K */ + [20] = { 0x3D3D, 0xFFFF, 0x0000 }, /* Ca */ + [21] = { 0xE6E6, 0xE6E6, 0xE6E6 }, /* Sc */ + [22] = { 0xBFBF, 0xC2C2, 0xC7C7 }, /* Ti */ + [23] = { 0xA6A6, 0xA6A6, 0xABAB }, /* V */ + [24] = { 0x8A8A, 0x9999, 0xC7C7 }, /* Cr */ + [25] = { 0x9C9C, 0x7A7A, 0xC7C7 }, /* Mn */ + [26] = { 0xDDDD, 0x6666, 0x3333 }, /* Fe */ + [27] = { 0xEEEE, 0x8888, 0x9999 }, /* Co */ + [28] = { 0x5050, 0xD0D0, 0x5050 }, /* Ni */ + [29] = { 0xBBBB, 0x7777, 0x3333 }, /* Cu */ + [30] = { 0x7D7D, 0x8080, 0xB0B0 }, /* Zn */ + [31] = { 0xC2C2, 0x8F8F, 0x8F8F }, /* Ga */ + [32] = { 0x6666, 0x8F8F, 0x8F8F }, /* Ge */ + [33] = { 0xBDBD, 0x8080, 0xE3E3 }, /* As */ + [34] = { 0xFFFF, 0xAAAA, 0x1111 }, /* Se */ + [35] = { 0xAAAA, 0x4444, 0x0000 }, /* Br */ + [36] = { 0xAAAA, 0xFFFF, 0xFFFF }, /* Kr */ + [37] = { 0x7070, 0x2E2E, 0xB0B0 }, /* Rb */ + [38] = { 0x0000, 0xFFFF, 0x0000 }, /* Sr */ + [39] = { 0x9494, 0xFFFF, 0xFFFF }, /* Y */ + [40] = { 0x9494, 0xE0E0, 0xE0E0 }, /* Zr */ + [41] = { 0x7373, 0xC2C2, 0xC9C9 }, /* Nb */ + [42] = { 0x5454, 0xB5B5, 0xB5B5 }, /* Mo */ + [43] = { 0x3B3B, 0x9E9E, 0x9E9E }, /* Tc */ + [44] = { 0x2424, 0x8F8F, 0x8F8F }, /* Ru */ + [45] = { 0x0A0A, 0x7D7D, 0x8C8C }, /* Rh */ + [46] = { 0x0000, 0x6969, 0x8585 }, /* Pd */ + [47] = { 0xC0C0, 0xC0C0, 0xC0C0 }, /* Ag */ + [48] = { 0xFFFF, 0xD9D9, 0x8F8F }, /* Cd */ + [49] = { 0xA6A6, 0x7575, 0x7373 }, /* In */ + [50] = { 0x6666, 0x8080, 0x8080 }, /* Sn */ + [51] = { 0x9E9E, 0x6363, 0xB5B5 }, /* Sb */ + [52] = { 0xD4D4, 0x7A7A, 0x0000 }, /* Te */ + [53] = { 0x9494, 0x0000, 0x9494 }, /* I */ + [54] = { 0x4242, 0x9E9E, 0xB0B0 }, /* Xe */ + [55] = { 0x5757, 0x1717, 0x8F8F }, /* Cs */ + [56] = { 0x0000, 0xC9C9, 0x0000 }, /* Ba */ + [57] = { 0x7070, 0xD4D4, 0xFFFF }, /* La */ + [58] = { 0xFFFF, 0xFFFF, 0xC7C7 }, /* Ce */ + [59] = { 0xD9D9, 0xFFFF, 0xC7C7 }, /* Pr */ + [60] = { 0xC7C7, 0xFFFF, 0xC7C7 }, /* Nd */ + [61] = { 0xA3A3, 0xFFFF, 0xC7C7 }, /* Pm */ + [62] = { 0x8F8F, 0xFFFF, 0xC7C7 }, /* Sm */ + [63] = { 0x6161, 0xFFFF, 0xC7C7 }, /* Eu */ + [64] = { 0x4545, 0xFFFF, 0xC7C7 }, /* Gd */ + [65] = { 0x3030, 0xFFFF, 0xC7C7 }, /* Tb */ + [66] = { 0x1F1F, 0xFFFF, 0xC7C7 }, /* Dy */ + [67] = { 0x0000, 0xFFFF, 0x9C9C }, /* Ho */ + [68] = { 0x0000, 0xE6E6, 0x7575 }, /* Er */ + [69] = { 0x0000, 0xD4D4, 0x5252 }, /* Tm */ + [70] = { 0x0000, 0xBFBF, 0x3838 }, /* Yb */ + [71] = { 0x0000, 0xABAB, 0x2424 }, /* Lu */ + [72] = { 0x4D4D, 0xC2C2, 0xFFFF }, /* Hf */ + [73] = { 0x4D4D, 0xA6A6, 0xFFFF }, /* Ta */ + [74] = { 0x2121, 0x9494, 0xD6D6 }, /* W */ + [75] = { 0x2626, 0x7D7D, 0xABAB }, /* Re */ + [76] = { 0x2626, 0x6666, 0x9696 }, /* Os */ + [77] = { 0x1717, 0x5454, 0x8787 }, /* Ir */ + [78] = { 0xD0D0, 0xD0D0, 0xE0E0 }, /* Pt */ + [79] = { 0xFFFF, 0xD1D1, 0x2323 }, /* Au */ + [80] = { 0xB8B8, 0xB8B8, 0xD0D0 }, /* Hg */ + [81] = { 0xA6A6, 0x5454, 0x4D4D }, /* Tl */ + [82] = { 0x5757, 0x5959, 0x6161 }, /* Pb */ + [83] = { 0x9E9E, 0x4F4F, 0xB5B5 }, /* Bi */ + [84] = { 0xABAB, 0x5C5C, 0x0000 }, /* Po */ + [85] = { 0x7575, 0x4F4F, 0x4545 }, /* At */ + [86] = { 0x4242, 0x8282, 0x9696 }, /* Rn */ + [87] = { 0x4242, 0x0000, 0x6666 }, /* Fr */ + [88] = { 0x0000, 0x7D7D, 0x0000 }, /* Ra */ + [89] = { 0x7070, 0xABAB, 0xFAFA }, /* Ac */ + [90] = { 0x0000, 0xBABA, 0xFFFF }, /* Th */ + [91] = { 0x0000, 0xA1A1, 0xFFFF }, /* Pa */ + [92] = { 0x0000, 0x8F8F, 0xFFFF }, /* U */ + [93] = { 0x0000, 0x8080, 0xFFFF }, /* Np */ + [94] = { 0x0000, 0x6B6B, 0xFFFF }, /* Pu */ + [95] = { 0x5454, 0x5C5C, 0xF2F2 }, /* Am */ + [96] = { 0x7878, 0x5C5C, 0xE3E3 }, /* Cm */ + [97] = { 0x8A8A, 0x4F4F, 0xE3E3 }, /* Bk */ + [98] = { 0xA1A1, 0x3636, 0xD4D4 }, /* Cf */ + [99] = { 0xB3B3, 0x1F1F, 0xD4D4 }, /* Es */ + [100] = { 0xB3B3, 0x1F1F, 0xBABA }, /* Fm */ + [101] = { 0xB3B3, 0x0D0D, 0xA6A6 }, /* Md */ + [102] = { 0xBDBD, 0x0D0D, 0x8787 }, /* No */ + [103] = { 0xC7C7, 0x0000, 0x6666 }, /* Lr */ + [104] = { 0xCCCC, 0x0000, 0x5959 }, /* Rf */ + [105] = { 0xD1D1, 0x0000, 0x4F4F }, /* Db */ + [106] = { 0xD9D9, 0x0000, 0x4545 }, /* Sg */ + [107] = { 0xE0E0, 0x0000, 0x3838 }, /* Bh */ + [108] = { 0xE6E6, 0x0000, 0x2E2E }, /* Hs */ + [109] = { 0xEBEB, 0x0000, 0x2626 }, /* Mt */ diff --git a/src/mol/palette_v.h b/src/mol/palette_v.h index d17b954..d37602e 100644 --- a/src/mol/palette_v.h +++ b/src/mol/palette_v.h @@ -1,25 +1,24 @@ - [ 0] = {0x9999, 0x9999, 0x9999}, - [ 1] = {0xBFFF, 0xBFFF, 0xBFFF}, /* H */ - [ 2] = {0xAAAA, 0xFFFF, 0xFFFF}, /* He */ - [ 6] = {0x5FFF, 0x5FFF, 0x5FFF}, /* C */ - [ 5] = {0xFFFF, 0xDDDD, 0xFFFF}, /* P */ - [ 7] = {0x1FFF, 0x1FFF, 0xBFFF}, /* N */ - [ 8] = {0xBFFF, 0x1FFF, 0x1FFF}, /* O */ - [ 9] = {0xF500, 0xFFFF, 0x8500}, /* F */ - [ 10] = {0xAAAA, 0xFFFF, 0xFFFF}, /* Ne */ - [ 14] = {0x5FFF, 0x5FFF, 0x5FFF}, /* Si */ - [ 15] = {0xFFFF, 0xCCCC, 0x9999}, /* P */ - [ 16] = {0xFFFF, 0xEEEE, 0x1111}, /* S */ - [ 17] = {0xCCCC, 0xFFFF, 0x9999}, /* Cl */ - [ 18] = {0xAAAA, 0xFFFF, 0xFFFF}, /* Ar */ - [ 28] = {0x9999, 0x5555, 0xFFFF}, /* Ni */ - [ 29] = {0xBBBB, 0x7777, 0x3333}, /* Cu */ - [ 34] = {0xFFFF, 0xAAAA, 0x1111}, /* Se */ - [ 35] = {0xAAAA, 0x4444, 0x0000}, /* Br */ - [ 36] = {0xAAAA, 0xFFFF, 0xFFFF}, /* Kr */ - [ 46] = {0x0000, 0x6666, 0x7777}, /* Pd */ - [ 47] = {0xAAAA, 0xAAAA, 0xAAAA}, /* Ag */ - [ 53] = {0xAAAA, 0x0000, 0xFFFF}, /* I */ - [ 54] = {0xAAAA, 0xFFFF, 0xFFFF}, /* Xe */ - [ 78] = {0x3333, 0x9999, 0xDDDD}, /* Pt */ - [ 79] = {0xFFFF, 0xCCCC, 0x0000}, /* Au */ +[0] = { 0x9999, 0x9999, 0x9999 }, [1] = { 0xBFFF, 0xBFFF, 0xBFFF }, /* H */ + [2] = { 0xAAAA, 0xFFFF, 0xFFFF }, /* He */ + [6] = { 0x5FFF, 0x5FFF, 0x5FFF }, /* C */ + [5] = { 0xFFFF, 0xDDDD, 0xFFFF }, /* P */ + [7] = { 0x1FFF, 0x1FFF, 0xBFFF }, /* N */ + [8] = { 0xBFFF, 0x1FFF, 0x1FFF }, /* O */ + [9] = { 0xF500, 0xFFFF, 0x8500 }, /* F */ + [10] = { 0xAAAA, 0xFFFF, 0xFFFF }, /* Ne */ + [14] = { 0x5FFF, 0x5FFF, 0x5FFF }, /* Si */ + [15] = { 0xFFFF, 0xCCCC, 0x9999 }, /* P */ + [16] = { 0xFFFF, 0xEEEE, 0x1111 }, /* S */ + [17] = { 0xCCCC, 0xFFFF, 0x9999 }, /* Cl */ + [18] = { 0xAAAA, 0xFFFF, 0xFFFF }, /* Ar */ + [28] = { 0x9999, 0x5555, 0xFFFF }, /* Ni */ + [29] = { 0xBBBB, 0x7777, 0x3333 }, /* Cu */ + [34] = { 0xFFFF, 0xAAAA, 0x1111 }, /* Se */ + [35] = { 0xAAAA, 0x4444, 0x0000 }, /* Br */ + [36] = { 0xAAAA, 0xFFFF, 0xFFFF }, /* Kr */ + [46] = { 0x0000, 0x6666, 0x7777 }, /* Pd */ + [47] = { 0xAAAA, 0xAAAA, 0xAAAA }, /* Ag */ + [53] = { 0xAAAA, 0x0000, 0xFFFF }, /* I */ + [54] = { 0xAAAA, 0xFFFF, 0xFFFF }, /* Xe */ + [78] = { 0x3333, 0x9999, 0xDDDD }, /* Pt */ + [79] = { 0xFFFF, 0xCCCC, 0x0000 }, /* Au */ diff --git a/src/sym/pointgroup.c b/src/sym/pointgroup.c index dcfd38a..e423460 100644 --- a/src/sym/pointgroup.c +++ b/src/sym/pointgroup.c @@ -1,605 +1,739 @@ #include "sym.h" -static inline molsym * alloc_molsym(int a, int mssize){ - size_t r_size = sizeof(double) * mssize*3; - size_t o_size = sizeof(int ) * mssize; - size_t e_size = sizeof(elsym ) * mssize; - molsym * ms = calloc(sizeof(molsym)+ e_size + o_size + r_size, 1); - if(!ms) GOTOHELL; - ms->r = (double *) (ms+1); - ms->o = (int *) MEM_END(ms,r); // cppcheck-suppress invalidPointerCast - ms->e = (elsym *) MEM_END(ms,o); +static inline molsym * +alloc_molsym (int a, int mssize) +{ + size_t r_size = sizeof (double) * mssize * 3; + size_t o_size = sizeof (int) * mssize; + size_t e_size = sizeof (elsym) * mssize; + molsym *ms = calloc (sizeof (molsym) + e_size + o_size + r_size, 1); + if (!ms) + GOTOHELL; + ms->r = (double *)(ms + 1); + ms->o = (int *)MEM_END (ms, r); // cppcheck-suppress invalidPointerCast + ms->e = (elsym *)MEM_END (ms, o); ms->a = a; return ms; } -static inline int isnew(int N, const double * R, const double r[3], double eps2){ - for(int i=0; in; j++){ - r3mx (r, m->r+3*j, R); - if(isnew(m->n, m->r, r, eps2)){ - break; + for (j = 0; j < m->n; j++) + { + r3mx (r, m->r + 3 * j, R); + if (isnew (m->n, m->r, r, eps2)) + { + break; + } + } + if (j == m->n) + { + return 1; + } + else + { + return 0; } - } - if(j==m->n){ - return 1; - } - else{ - return 0; - } } -static inline int isc5(const mol * m, const double u[3], double eps2){ +static inline int +isc5 (const mol *m, const double u[3], double eps2) +{ double R[9]; - rotmx(R, u, 0.4*M_PI); - return iscn(m, R, eps2); + rotmx (R, u, 0.4 * M_PI); + return iscn (m, R, eps2); } -static inline int isc4(const mol * m, const double u[3], double eps2){ +static inline int +isc4 (const mol *m, const double u[3], double eps2) +{ double R[9]; - rotmx(R, u, M_PI_2); - return iscn(m, R, eps2); + rotmx (R, u, M_PI_2); + return iscn (m, R, eps2); } -static inline int isc3(const mol * m, const double u[3], double eps2){ - const double s = sqrt(3.0)*0.5; - double R[9] = {-0.5 + u[0]*u[0]*1.5, -u[2]*s + u[0]*u[1]*1.5, u[1]*s + u[0]*u[2]*1.5, - u[2]*s + u[0]*u[1]*1.5, -0.5 + u[1]*u[1]*1.5, -u[0]*s + u[1]*u[2]*1.5, - -u[1]*s + u[0]*u[2]*1.5, u[0]*s + u[1]*u[2]*1.5, -0.5 + u[2]*u[2]*1.5 }; - return iscn(m, R, eps2); +static inline int +isc3 (const mol *m, const double u[3], double eps2) +{ + const double s = sqrt (3.0) * 0.5; + double R[9] = { -0.5 + u[0] * u[0] * 1.5, -u[2] * s + u[0] * u[1] * 1.5, + u[1] * s + u[0] * u[2] * 1.5, u[2] * s + u[0] * u[1] * 1.5, + -0.5 + u[1] * u[1] * 1.5, -u[0] * s + u[1] * u[2] * 1.5, + -u[1] * s + u[0] * u[2] * 1.5, u[0] * s + u[1] * u[2] * 1.5, + -0.5 + u[2] * u[2] * 1.5 }; + return iscn (m, R, eps2); } -static inline int isc2(const mol * m, const double u[3], double eps2){ - double R[9] = {2.0*u[0]*u[0]-1.0, 2.0*u[0]*u[1], 2.0*u[0]*u[2], - 2.0*u[0]*u[1], 2.0*u[1]*u[1]-1.0, 2.0*u[1]*u[2], - 2.0*u[0]*u[2], 2.0*u[1]*u[2], 2.0*u[2]*u[2]-1.0}; - return iscn(m, R, eps2); +static inline int +isc2 (const mol *m, const double u[3], double eps2) +{ + double R[9] = { 2.0 * u[0] * u[0] - 1.0, 2.0 * u[0] * u[1], + 2.0 * u[0] * u[2], 2.0 * u[0] * u[1], + 2.0 * u[1] * u[1] - 1.0, 2.0 * u[1] * u[2], + 2.0 * u[0] * u[2], 2.0 * u[1] * u[2], + 2.0 * u[2] * u[2] - 1.0 }; + return iscn (m, R, eps2); } -static void issigma(const mol * m, const molsym * ms, const double a[3], int S, double eps2){ +static void +issigma (const mol *m, const molsym *ms, const double a[3], int S, double eps2) +{ double r[3]; int j; - for(j=0; jn; j++){ - r3cp(r, m->r+j*3); - double t = r3dot(r, a); - if(fabs(t)n; j++) + { + r3cp (r, m->r + j * 3); + double t = r3dot (r, a); + if (fabs (t) < eps2) + { + continue; + } + r3adds (r, a, -2.0 * t); + if (isnew (m->n, m->r, r, eps2)) + { + break; + } } - r3adds(r, a, -2.0*t); - if(isnew(m->n, m->r, r, eps2)){ - break; + if (j == m->n) + { + ms->o[S] = 2; + r3cp (ms->r + S * 3, a); } - } - if(j==m->n){ - ms->o[S] = 2; - r3cp(ms->r+S*3, a); - } return; } -static inline void r3perp(double u[3], const double v[3], double eps){ - if((fabs(v[0])n; i++){ - for(int j=i+1; jn; j++){ - for(int k=j+1; kn; k++){ - double a[3], b[3], h[3]; - r3diff(a, m->r+3*i, m->r+3*j); - r3diff(b, m->r+3*k, m->r+3*j); - r3x(h,a,b); - double t = r3dot(h,h); - if(t eps2){ - continue; - } - if(!isnewaxis(n, axis, h, eps2)){ - continue; - } - r3scal(h, 1.0/sqrt(t)); - p = isc3(m, h, eps2); - if(p){ - if(n>=10){ // bad - return n+1; - } - r3cp(axis+n*3, h); - n++; +static int +findc3 (const mol *m, double axis[30], double eps2) +{ + int p = 0, n = 0; + for (int i = 0; i < m->n; i++) + { + for (int j = i + 1; j < m->n; j++) + { + for (int k = j + 1; k < m->n; k++) + { + double a[3], b[3], h[3]; + r3diff (a, m->r + 3 * i, m->r + 3 * j); + r3diff (b, m->r + 3 * k, m->r + 3 * j); + r3x (h, a, b); + double t = r3dot (h, h); + if (t < eps2) + { + continue; + } + double d[3]; + double dm[2]; + d[0] = r3dot (a, a); + d[1] = r3dot (b, b); + d[2] = r3d2 (a, b); + sort3 (d, dm); + double s = sqrt (dm[1]) - sqrt (dm[0]); + if (s * s > eps2) + { + continue; + } + if (!isnewaxis (n, axis, h, eps2)) + { + continue; + } + r3scal (h, 1.0 / sqrt (t)); + p = isc3 (m, h, eps2); + if (p) + { + if (n >= 10) + { // bad + return n + 1; + } + r3cp (axis + n * 3, h); + n++; + } + } } - } } - } return n; } -static int findc2inI(const mol * m, const double c3[30], double c2[3], double eps2){ - for(int i=0; i<10; i++){ - for(int j=0; j<10; j++){ - int mi, mj; - for(mi=-1; mi<2; mi+=2){ - for(mj=-1; mj<2; mj+=2){ - double ci[3], cj[3]; - r3cpsc(ci, c3+3*i, mi); - r3cpsc(cj, c3+3*j, mj); - r3sum(c2, ci, cj); - r3scal(c2, 1.0/sqrt(r3dot(c2,c2))); - int p = isc2(m, c2, eps2); - if(p){ - return p; - } +static int +findc2inI (const mol *m, const double c3[30], double c2[3], double eps2) +{ + for (int i = 0; i < 10; i++) + { + for (int j = 0; j < 10; j++) + { + int mi, mj; + for (mi = -1; mi < 2; mi += 2) + { + for (mj = -1; mj < 2; mj += 2) + { + double ci[3], cj[3]; + r3cpsc (ci, c3 + 3 * i, mi); + r3cpsc (cj, c3 + 3 * j, mj); + r3sum (c2, ci, cj); + r3scal (c2, 1.0 / sqrt (r3dot (c2, c2))); + int p = isc2 (m, c2, eps2); + if (p) + { + return p; + } + } + } } - } } - } return 0; } -static void findc2(const mol * m, molsym * ms, int Cn, int C2, double eps2){ - - double * mainaxis = ms->r+Cn*3; - double testaxis[3]; - r3perp(testaxis, mainaxis, EPS1); - - int stesp = PISTEPS / ms->o[Cn]; - double sector = M_PI / ms->o[Cn]; - double dphi = sector/(stesp+1); - - for(int i=0; io[C2] = 2; - r3cp(ms->r+C2*3, newtestaxis); - break; +static void +findc2 (const mol *m, molsym *ms, int Cn, int C2, double eps2) +{ + + double *mainaxis = ms->r + Cn * 3; + double testaxis[3]; + r3perp (testaxis, mainaxis, EPS1); + + int stesp = PISTEPS / ms->o[Cn]; + double sector = M_PI / ms->o[Cn]; + double dphi = sector / (stesp + 1); + + for (int i = 0; i < stesp; i++) + { + double rot[9]; + double newtestaxis[3]; + rotmx (rot, mainaxis, dphi * i); + r3mx (newtestaxis, testaxis, rot); + int p = isc2 (m, newtestaxis, eps2); + if (p) + { + ms->o[C2] = 2; + r3cp (ms->r + C2 * 3, newtestaxis); + break; + } } - } return; } -static void findsigmav(const mol * m, molsym * ms, int Cn, int C2, double eps2){ - - double * mainaxis = ms->r+Cn*3; - double testaxis[3]; - r3perp(testaxis, mainaxis, EPS1); - - int stesp = PISTEPS / ms->o[Cn]; - double sector = M_PI / ms->o[Cn]; - double dphi = sector/(stesp+1); - - for(int i=0; io[C2]){ - break; +static void +findsigmav (const mol *m, molsym *ms, int Cn, int C2, double eps2) +{ + + double *mainaxis = ms->r + Cn * 3; + double testaxis[3]; + r3perp (testaxis, mainaxis, EPS1); + + int stesp = PISTEPS / ms->o[Cn]; + double sector = M_PI / ms->o[Cn]; + double dphi = sector / (stesp + 1); + + for (int i = 0; i < stesp; i++) + { + double rot[9]; + double newtestaxis[3]; + rotmx (rot, mainaxis, dphi * i); + r3mx (newtestaxis, testaxis, rot); + issigma (m, ms, newtestaxis, C2, eps2); + if (ms->o[C2]) + { + break; + } } - } return; } -static void issn(const mol * m, molsym * ms, int n, double eps2){ - double * u = ms->r+n*3; +static void +issn (const mol *m, molsym *ms, int n, double eps2) +{ + double *u = ms->r + n * 3; double R[9]; double r[3]; - int j; - rotmx(R, u, M_PI/ms->o[n]); - for(j=0; jn; j++){ - r3mx (r, m->r+j*3, R); - double t = r3dot(r, u); - r3adds(r, u, -2.0*t); - if(isnew(m->n, m->r, r, eps2)){ - break; + int j; + rotmx (R, u, M_PI / ms->o[n]); + for (j = 0; j < m->n; j++) + { + r3mx (r, m->r + j * 3, R); + double t = r3dot (r, u); + r3adds (r, u, -2.0 * t); + if (isnew (m->n, m->r, r, eps2)) + { + break; + } + } + if (j == m->n) + { + ms->o[n] *= 2; + ms->e[n] = SN; } - } - if(j==m->n){ - ms->o[n] *= 2; - ms->e[n] = SN; - } return; } -static void hascn(const mol * m, molsym * cn, int k, double eps2){ - for(int i=MAXCN; i>1; i--){ - double f = 2.0*M_PI/i; - double c = cos(f); - double s = sin(f); - double Rx[9] = {1.0 , 0.0, 0.0, - 0.0, c , -s , - 0.0, s , c }; - double Ry[9] = { c , 0.0, s , - 0.0, 1.0, 0.0 , - -s , 0.0, c }; - double Rz[9] = { c , -s , 0.0, - s , c , 0.0, - 0.0, 0.0, 1.0 }; - - if(iscn(m, Rx, eps2)) { - cn->o[k] = i; - uv100(cn->r+k*3); - return; - } - if(iscn(m, Ry, eps2)) { - cn->o[k] = i; - uv010(cn->r+k*3); - return; - } - if(iscn(m, Rz, eps2)) { - cn->o[k] = i; - uv001(cn->r+k*3); - return; +static void +hascn (const mol *m, molsym *cn, int k, double eps2) +{ + for (int i = MAXCN; i > 1; i--) + { + double f = 2.0 * M_PI / i; + double c = cos (f); + double s = sin (f); + double Rx[9] = { 1.0, 0.0, 0.0, 0.0, c, -s, 0.0, s, c }; + double Ry[9] = { c, 0.0, s, 0.0, 1.0, 0.0, -s, 0.0, c }; + double Rz[9] = { c, -s, 0.0, s, c, 0.0, 0.0, 0.0, 1.0 }; + + if (iscn (m, Rx, eps2)) + { + cn->o[k] = i; + uv100 (cn->r + k * 3); + return; + } + if (iscn (m, Ry, eps2)) + { + cn->o[k] = i; + uv010 (cn->r + k * 3); + return; + } + if (iscn (m, Rz, eps2)) + { + cn->o[k] = i; + uv001 (cn->r + k * 3); + return; + } } - } return; } -static void hassigma(const mol * m, molsym * cn, int k, double eps2){ - int i,j; +static void +hassigma (const mol *m, molsym *cn, int k, double eps2) +{ + int i, j; double r[3]; - for(i=0; i<3; i++){ - for(j=0; jn; j++){ - r3cp(r, m->r+j*3); - r[i] = -r[i]; - if(isnew(m->n, m->r, r, eps2)){ - break; - } - } - if(j==m->n){ - cn->o[k] = 2; - switch(i){ - case 0: uv100(cn->r+k*3); return; - case 1: uv010(cn->r+k*3); return; - case 2: uv001(cn->r+k*3); return; - } + for (i = 0; i < 3; i++) + { + for (j = 0; j < m->n; j++) + { + r3cp (r, m->r + j * 3); + r[i] = -r[i]; + if (isnew (m->n, m->r, r, eps2)) + { + break; + } + } + if (j == m->n) + { + cn->o[k] = 2; + switch (i) + { + case 0: + uv100 (cn->r + k * 3); + return; + case 1: + uv010 (cn->r + k * 3); + return; + case 2: + uv001 (cn->r + k * 3); + return; + } + } } - } return; } -static int hasinv(const mol * m, double eps2){ - for(int i=0; in; i++){ - double r[3]; - r3cpsc(r, m->r+i*3, -1.0); - if(isnew(m->n, m->r, r, eps2)){ - return 0; +static int +hasinv (const mol *m, double eps2) +{ + for (int i = 0; i < m->n; i++) + { + double r[3]; + r3cpsc (r, m->r + i * 3, -1.0); + if (isnew (m->n, m->r, r, eps2)) + { + return 0; + } } - } return 1; } -static int findc5(const mol * m, const double c3[30], double c5[3], double eps2){ - for(int i=0; i<10; i++){ - for(int j=i+1; j<10; j++){ - for(int k=j+1; k<10; k++){ - double ci[3], cj[3], ck[3]; - int mi, mj, mk; - for(mi=-1; mi<2; mi+=2){ - for(mj=-1; mj<2; mj+=2){ - for(mk=-1; mk<2; mk+=2){ - r3cpsc(ci, c3+3*i, mi); - r3cpsc(cj, c3+3*j, mj); - r3cpsc(ck, c3+3*k, mk); - double a[3], b[3], h[3]; - r3diff(a, ci, cj); - r3diff(b, ck, cj); - r3x(h,a,b); - double t = r3dot(h,h); - if(te[(I)], MS->o[(I)], MS->r[(I)*3], MS->r[(I)*3+1], MS->r[(I)*3+2]); +#define PRINTSYMEL( \ + MS, I) // printf("\t%d %d %lf %lf %lf\n", MS->e[(I)], MS->o[(I)], + // MS->r[(I)*3], MS->r[(I)*3+1], MS->r[(I)*3+2]); #define MSSIZE 4 - molsym * ms = alloc_molsym(m->n, MSSIZE); + molsym *ms = alloc_molsym (m->n, MSSIZE); double d[3]; - position(m, d, 0); + position (m, d, 0); /* Kh, D*h, C*v */ - int dim0 = (d[0]s, sizeof(styp), "Kh"); - return ms; - } - if(dim0==1){ - if(hasinv(m, eps2)){ - snprintf(ms->s, sizeof(styp), "D*h"); + int dim0 = (d[0] < eps) + (d[1] < eps) + (d[2] < eps); + if (dim0 == 3) + { + snprintf (ms->s, sizeof (styp), "Kh"); return ms; } - else{ - snprintf(ms->s, sizeof(styp), "C*v"); - return ms; + if (dim0 == 1) + { + if (hasinv (m, eps2)) + { + snprintf (ms->s, sizeof (styp), "D*h"); + return ms; + } + else + { + snprintf (ms->s, sizeof (styp), "C*v"); + return ms; + } } - } double dm[2]; - sort3(d, dm); - if((dm[1]-dm[0])/dm[0]1)&&(p!=4)&&(p!=10))){ - break; - } - this_eps2 *= 2.0; - } + sort3 (d, dm); + if ((dm[1] - dm[0]) / dm[0] < eps) + { + double c3[30] = { 0.0 }; + int p = 0; + + double this_eps2 = eps2; + for (int i = 0; i < 16; i++) + { + p = findc3 (m, c3, this_eps2); + if (!((p > 1) && (p != 4) && (p != 10))) + { + break; + } + this_eps2 *= 2.0; + } - if(p==0){ - PRINT_WARN("The point group might be T*/O*/I*. Try different 'symtol' options\n") - } + if (p == 0) + { + PRINT_WARN ("The point group might be T*/O*/I*. Try different " + "'symtol' options\n") + } - ms->e[0] = CN; - ms->o[0] = 3; - r3cp(ms->r+0*3, c3+0*3); - if(p==4){ - /* T/Td/Th/O/Oh */ - int q; - double c4[3]; - r3diff(c4, c3+0*3, c3+1*3); - r3scal(c4, 1.0/sqrt(r3dot(c4,c4))); - q = isc4(m, c4, eps2); - if(q == 0){ - r3sum(c4, c3+0*3, c3+1*3); - r3scal(c4, 1.0/sqrt(r3dot(c4,c4))); - q = isc4(m, c4, eps2); - } - if(q != 0){ - /* O/Oh */ - ms->e[1] = CN; - ms->o[1] = 4; - r3cp(ms->r+1*3, c4); - if(hasinv(m, eps2)){ - ms->n = 3; - ms->e[2] = INV; + ms->e[0] = CN; + ms->o[0] = 3; + r3cp (ms->r + 0 * 3, c3 + 0 * 3); + if (p == 4) + { + /* T/Td/Th/O/Oh */ + int q; + double c4[3]; + r3diff (c4, c3 + 0 * 3, c3 + 1 * 3); + r3scal (c4, 1.0 / sqrt (r3dot (c4, c4))); + q = isc4 (m, c4, eps2); + if (q == 0) + { + r3sum (c4, c3 + 0 * 3, c3 + 1 * 3); + r3scal (c4, 1.0 / sqrt (r3dot (c4, c4))); + q = isc4 (m, c4, eps2); + } + if (q != 0) + { + /* O/Oh */ + ms->e[1] = CN; + ms->o[1] = 4; + r3cp (ms->r + 1 * 3, c4); + if (hasinv (m, eps2)) + { + ms->n = 3; + ms->e[2] = INV; + ms->o[2] = 2; + ms->r[2 * 3] = ms->r[2 * 3 + 1] = ms->r[2 * 3 + 2] = 0.0; + snprintf (ms->s, sizeof (styp), "Oh"); + return ms; + } + ms->n = 2; + snprintf (ms->s, sizeof (styp), "O"); + return ms; + } + /* T/Td/Th */ + double c2[3]; + r3diff (c2, c3 + 0 * 3, c3 + 1 * 3); + r3scal (c2, 1.0 / sqrt (r3dot (c2, c2))); + q = isc2 (m, c2, eps2); + if (q == 0) + { + r3sum (c2, c3 + 0 * 3, c3 + 1 * 3); + r3scal (c2, 1.0 / sqrt (r3dot (c2, c2))); + q = isc2 (m, c2, eps2); + } + if (q == 0) + { + snprintf (ms->s, sizeof (styp), "???"); + return ms; + } + ms->e[1] = CN; + ms->o[1] = 2; + r3cp (ms->r + 1 * 3, c2); + + issn (m, ms, 1, eps2); + if (ms->e[1] == SN) + { + ms->n = 2; + snprintf (ms->s, sizeof (styp), "Td"); + return ms; + } + if (hasinv (m, eps2)) + { + ms->n = 3; + ms->e[2] = INV; + ms->o[2] = 2; + ms->r[2 * 3] = ms->r[2 * 3 + 1] = ms->r[2 * 3 + 2] = 0.0; + snprintf (ms->s, sizeof (styp), "Th"); + return ms; + } + ms->n = 2; + snprintf (ms->s, sizeof (styp), "T"); + return ms; + } + else if (p == 10) + { + /* I/Ih */ + double c5[3]; + int q; + q = findc5 (m, c3, c5, eps2); + if (q == 0) + { + snprintf (ms->s, sizeof (styp), "???"); + return ms; + } + double c2[3]; + q = findc2inI (m, c3, c2, eps2); + if (q == 0) + { + snprintf (ms->s, sizeof (styp), "???"); + return ms; + } + ms->e[1] = CN; + ms->o[1] = 5; + r3cp (ms->r + 1 * 3, c5); + ms->e[2] = CN; ms->o[2] = 2; - ms->r[2*3] = ms->r[2*3+1] = ms->r[2*3+2] = 0.0; - snprintf(ms->s, sizeof(styp), "Oh"); + r3cp (ms->r + 2 * 3, c2); + if (hasinv (m, eps2)) + { + ms->n = 4; + ms->e[3] = INV; + ms->o[3] = 2; + ms->r[3 * 3] = ms->r[3 * 3 + 1] = ms->r[3 * 3 + 2] = 0.0; + snprintf (ms->s, sizeof (styp), "Ih"); + return ms; + } + ms->n = 3; + snprintf (ms->s, sizeof (styp), "I"); return ms; } - ms->n = 2; - snprintf(ms->s, sizeof(styp), "O"); - return ms; - } - /* T/Td/Th */ - double c2[3]; - r3diff(c2, c3+0*3, c3+1*3); - r3scal(c2, 1.0/sqrt(r3dot(c2,c2))); - q = isc2(m, c2, eps2); - if(q == 0){ - r3sum(c2, c3+0*3, c3+1*3); - r3scal(c2, 1.0/sqrt(r3dot(c2,c2))); - q = isc2(m, c2, eps2); - } - if(q == 0){ - snprintf(ms->s, sizeof(styp), "???"); - return ms; - } - ms->e[1] = CN; - ms->o[1] = 2; - r3cp(ms->r+1*3, c2); - - issn(m, ms, 1, eps2); - if(ms->e[1]==SN){ - ms->n = 2; - snprintf(ms->s, sizeof(styp), "Td"); - return ms; - } - if(hasinv(m, eps2)){ - ms->n = 3; - ms->e[2] = INV; - ms->o[2] = 2; - ms->r[2*3] = ms->r[2*3+1] = ms->r[2*3+2] = 0.0; - snprintf(ms->s, sizeof(styp), "Th"); - return ms; - } - ms->n = 2; - snprintf(ms->s, sizeof(styp), "T"); - return ms; - } - else if(p == 10){ - /* I/Ih */ - double c5[3]; - int q; - q = findc5(m, c3, c5, eps2); - if(q == 0){ - snprintf(ms->s, sizeof(styp), "???"); - return ms; - } - double c2[3]; - q = findc2inI(m, c3, c2, eps2); - if(q == 0){ - snprintf(ms->s, sizeof(styp), "???"); - return ms; - } - ms->e[1] = CN; - ms->o[1] = 5; - r3cp(ms->r+1*3, c5); - ms->e[2] = CN; - ms->o[2] = 2; - r3cp(ms->r+2*3, c2); - if(hasinv(m, eps2)){ - ms->n = 4; - ms->e[3] = INV; - ms->o[3] = 2; - ms->r[3*3] = ms->r[3*3+1] = ms->r[3*3+2] = 0.0; - snprintf(ms->s, sizeof(styp), "Ih"); - return ms; - } - ms->n = 3; - snprintf(ms->s, sizeof(styp), "I"); - return ms; } - } /* find a rotational axis || one of the principal axes */ ms->e[0] = CN; ms->o[0] = 0; - hascn(m, ms, 0, eps2); - if(ms->o[0]){ - ms->n++; - PRINTSYMEL(ms,0); - /* find C2' perpendicular the principal axis */ - ms->e[1] = CN; - ms->o[1] = 0; - findc2(m, ms, 0, 1, eps2); - if(ms->o[1]){ - /* Dn, Dnh, Dnd */ - ms->n++; - PRINTSYMEL(ms,1); - ms->e[2] = SIGMA; - ms->o[2] = 0; - issigma(m, ms, ms->r+3*0, 2, eps2); - if(ms->o[2]){ - ms->n++; - PRINTSYMEL(ms,2); - snprintf(ms->s, sizeof(styp), "D%dh", ms->o[0]); - return ms; - } - /* Dn, Dnd */ - ms->e[2] = SIGMA; - ms->o[2] = 0; - if(ms->o[0]%2){ - issigma(m, ms, ms->r+3*1, 2, eps2); - } - else{ - double R[9]; - double u[3]; - rotmx(R, ms->r+0*3, 0.5*M_PI/ms->o[0]); - r3mx(u, ms->r+1*3, R); - issigma(m, ms, u, 2, eps2); - } - if(ms->o[2]){ - ms->n++; - PRINTSYMEL(ms,2); - snprintf(ms->s, sizeof(styp), "D%dd", ms->o[0]); - return ms; - } - snprintf(ms->s, sizeof(styp), "D%d", ms->o[0]); - return ms; - } - /* Cn, Cnv, Cnh, S2n */ - ms->e[1] = SIGMA; - ms->o[1] = 0; - issigma(m, ms, ms->r+3*0, 1, eps2); - if(ms->o[1]){ - ms->n++; - PRINTSYMEL(ms,1); - snprintf(ms->s, sizeof(styp), "C%dh", ms->o[0]); - return ms; - } - /* Cn, Cnv, S2n */ - ms->e[1] = SIGMA; - ms->o[1] = 0; - findsigmav(m, ms, 0, 1, eps2); - if(ms->o[1]){ + hascn (m, ms, 0, eps2); + if (ms->o[0]) + { ms->n++; - PRINTSYMEL(ms,1); - snprintf(ms->s, sizeof(styp), "C%dv", ms->o[0]); - return ms; - } - /* Cn, S2n */ - issn(m, ms, 0, eps2); - if(ms->e[0]==SN){ - PRINTSYMEL(ms,1); - snprintf(ms->s, sizeof(styp), "S%d", ms->o[0]); - return ms; - } - snprintf(ms->s, sizeof(styp), "C%d", ms->o[0]); - return ms; - } - else{ - /* Cs, Ci, C1 */ - ms->o[0] = 0; - hassigma(m, ms, 0, eps2); - if(ms->o[0]){ - ms->n = 1; - ms->e[0] = SIGMA; - snprintf(ms->s, sizeof(styp), "Cs"); + PRINTSYMEL (ms, 0); + /* find C2' perpendicular the principal axis */ + ms->e[1] = CN; + ms->o[1] = 0; + findc2 (m, ms, 0, 1, eps2); + if (ms->o[1]) + { + /* Dn, Dnh, Dnd */ + ms->n++; + PRINTSYMEL (ms, 1); + ms->e[2] = SIGMA; + ms->o[2] = 0; + issigma (m, ms, ms->r + 3 * 0, 2, eps2); + if (ms->o[2]) + { + ms->n++; + PRINTSYMEL (ms, 2); + snprintf (ms->s, sizeof (styp), "D%dh", ms->o[0]); + return ms; + } + /* Dn, Dnd */ + ms->e[2] = SIGMA; + ms->o[2] = 0; + if (ms->o[0] % 2) + { + issigma (m, ms, ms->r + 3 * 1, 2, eps2); + } + else + { + double R[9]; + double u[3]; + rotmx (R, ms->r + 0 * 3, 0.5 * M_PI / ms->o[0]); + r3mx (u, ms->r + 1 * 3, R); + issigma (m, ms, u, 2, eps2); + } + if (ms->o[2]) + { + ms->n++; + PRINTSYMEL (ms, 2); + snprintf (ms->s, sizeof (styp), "D%dd", ms->o[0]); + return ms; + } + snprintf (ms->s, sizeof (styp), "D%d", ms->o[0]); + return ms; + } + /* Cn, Cnv, Cnh, S2n */ + ms->e[1] = SIGMA; + ms->o[1] = 0; + issigma (m, ms, ms->r + 3 * 0, 1, eps2); + if (ms->o[1]) + { + ms->n++; + PRINTSYMEL (ms, 1); + snprintf (ms->s, sizeof (styp), "C%dh", ms->o[0]); + return ms; + } + /* Cn, Cnv, S2n */ + ms->e[1] = SIGMA; + ms->o[1] = 0; + findsigmav (m, ms, 0, 1, eps2); + if (ms->o[1]) + { + ms->n++; + PRINTSYMEL (ms, 1); + snprintf (ms->s, sizeof (styp), "C%dv", ms->o[0]); + return ms; + } + /* Cn, S2n */ + issn (m, ms, 0, eps2); + if (ms->e[0] == SN) + { + PRINTSYMEL (ms, 1); + snprintf (ms->s, sizeof (styp), "S%d", ms->o[0]); + return ms; + } + snprintf (ms->s, sizeof (styp), "C%d", ms->o[0]); return ms; } - if(hasinv(m, eps2)){ - ms->n = 1; - ms->e[0] = INV; - ms->o[0] = 2; - ms->r[0] = ms->r[1] = ms->r[2] = 0.0; - snprintf(ms->s, sizeof(styp), "Ci"); + else + { + /* Cs, Ci, C1 */ + ms->o[0] = 0; + hassigma (m, ms, 0, eps2); + if (ms->o[0]) + { + ms->n = 1; + ms->e[0] = SIGMA; + snprintf (ms->s, sizeof (styp), "Cs"); + return ms; + } + if (hasinv (m, eps2)) + { + ms->n = 1; + ms->e[0] = INV; + ms->o[0] = 2; + ms->r[0] = ms->r[1] = ms->r[2] = 0.0; + snprintf (ms->s, sizeof (styp), "Ci"); + return ms; + } + snprintf (ms->s, sizeof (styp), "C1"); return ms; } - snprintf(ms->s, sizeof(styp), "C1"); - return ms; - } } - diff --git a/src/sym/sym.h b/src/sym/sym.h index ab50289..d75b03b 100644 --- a/src/sym/sym.h +++ b/src/sym/sym.h @@ -1,22 +1,28 @@ +#include "3d.h" #include "mol.h" #include "vec3.h" -#include "3d.h" #define EPS1 1e-15 -#define MAXCN 16 +#define MAXCN 16 #define PISTEPS 65536 -typedef enum {INV, SIGMA, CN, SN} elsym; +typedef enum +{ + INV, + SIGMA, + CN, + SN +} elsym; -typedef struct { - double * r; // vectors associated with generators - int * o; // orders of generators - elsym * e; // types of generators - styp s; // point group - int a; // number of atoms - int n; // number of group generators +typedef struct +{ + double *r; // vectors associated with generators + int *o; // orders of generators + elsym *e; // types of generators + styp s; // point group + int a; // number of atoms + int n; // number of group generators } molsym; -molsym * pointgroup(mol * m, double eps); - +molsym *pointgroup (mol *m, double eps); diff --git a/src/v.c b/src/v.c index fa126a3..7ae1f20 100644 --- a/src/v.c +++ b/src/v.c @@ -1,111 +1,129 @@ #include "v.h" -#include "x.h" #include "evr.h" +#include "x.h" draw_world_t world; -static void init_keys(ptf kp[NKP]){ - memset(kp, 0, sizeof(ptf)*NKP); -#define ASSIGN_KEY(KEY, ACTION) { kp[XKeysymToKeycode(world.dis, (KEY))] = (ACTION); } - ASSIGN_KEY( XK_Escape , kp_exit ); - ASSIGN_KEY( XK_period , kp_pg ); - ASSIGN_KEY( XK_1 , kp_rl_dec ); - ASSIGN_KEY( XK_2 , kp_rl_inc ); - ASSIGN_KEY( XK_3 , kp_r_dec ); - ASSIGN_KEY( XK_4 , kp_r_inc ); - ASSIGN_KEY( XK_0 , kp_goto_1st ); - ASSIGN_KEY( XK_equal , kp_goto_last ); - ASSIGN_KEY( XK_BackSpace , kp_frame_dec ); - ASSIGN_KEY( XK_Tab , kp_readmore ); - ASSIGN_KEY( XK_q , kp_exit ); - ASSIGN_KEY( XK_w , kp_move_u ); - ASSIGN_KEY( XK_r , kp_readagain ); - ASSIGN_KEY( XK_t , kp_t_toggle ); - ASSIGN_KEY( XK_u , kp_printrot ); - ASSIGN_KEY( XK_p , kp_print2fig ); - ASSIGN_KEY( XK_Return , kp_frame_inc ); - ASSIGN_KEY( XK_a , kp_move_l ); - ASSIGN_KEY( XK_s , kp_move_d ); - ASSIGN_KEY( XK_d , kp_move_r ); - ASSIGN_KEY( XK_f , kp_film ); - ASSIGN_KEY( XK_j , kp_jump ); - ASSIGN_KEY( XK_l , kp_l_toggle ); - ASSIGN_KEY( XK_z , kp_print_xyz ); - ASSIGN_KEY( XK_x , kp_print ); - ASSIGN_KEY( XK_b , kp_b_toggle ); - ASSIGN_KEY( XK_n , kp_n_toggle ); - ASSIGN_KEY( XK_m , kp_save_pic ); - ASSIGN_KEY( XK_End , kp_zoom_out ); - ASSIGN_KEY( XK_Up , kp_rotx_r ); - ASSIGN_KEY( XK_Page_Up , kp_rotz_l ); - ASSIGN_KEY( XK_Left , kp_roty_l ); - ASSIGN_KEY( XK_Right , kp_roty_r ); - ASSIGN_KEY( XK_Home , kp_zoom_in ); - ASSIGN_KEY( XK_Down , kp_rotx_l ); - ASSIGN_KEY( XK_Page_Down , kp_rotz_r ); - ASSIGN_KEY( XK_Insert , kp_fw_toggle ); - ASSIGN_KEY( XK_Delete , kp_bw_toggle ); - ASSIGN_KEY( XK_KP_Up , kp_move_u ); - ASSIGN_KEY( XK_KP_Left , kp_move_l ); - ASSIGN_KEY( XK_KP_Right , kp_move_r ); - ASSIGN_KEY( XK_KP_Down , kp_move_d ); +static void +init_keys (ptf kp[NKP]) +{ + memset (kp, 0, sizeof (ptf) * NKP); +#define ASSIGN_KEY(KEY, ACTION) \ + { \ + kp[XKeysymToKeycode (world.dis, (KEY))] = (ACTION); \ + } + ASSIGN_KEY (XK_Escape, kp_exit); + ASSIGN_KEY (XK_period, kp_pg); + ASSIGN_KEY (XK_1, kp_rl_dec); + ASSIGN_KEY (XK_2, kp_rl_inc); + ASSIGN_KEY (XK_3, kp_r_dec); + ASSIGN_KEY (XK_4, kp_r_inc); + ASSIGN_KEY (XK_0, kp_goto_1st); + ASSIGN_KEY (XK_equal, kp_goto_last); + ASSIGN_KEY (XK_BackSpace, kp_frame_dec); + ASSIGN_KEY (XK_Tab, kp_readmore); + ASSIGN_KEY (XK_q, kp_exit); + ASSIGN_KEY (XK_w, kp_move_u); + ASSIGN_KEY (XK_r, kp_readagain); + ASSIGN_KEY (XK_t, kp_t_toggle); + ASSIGN_KEY (XK_u, kp_printrot); + ASSIGN_KEY (XK_p, kp_print2fig); + ASSIGN_KEY (XK_Return, kp_frame_inc); + ASSIGN_KEY (XK_a, kp_move_l); + ASSIGN_KEY (XK_s, kp_move_d); + ASSIGN_KEY (XK_d, kp_move_r); + ASSIGN_KEY (XK_f, kp_film); + ASSIGN_KEY (XK_j, kp_jump); + ASSIGN_KEY (XK_l, kp_l_toggle); + ASSIGN_KEY (XK_z, kp_print_xyz); + ASSIGN_KEY (XK_x, kp_print); + ASSIGN_KEY (XK_b, kp_b_toggle); + ASSIGN_KEY (XK_n, kp_n_toggle); + ASSIGN_KEY (XK_m, kp_save_pic); + ASSIGN_KEY (XK_End, kp_zoom_out); + ASSIGN_KEY (XK_Up, kp_rotx_r); + ASSIGN_KEY (XK_Page_Up, kp_rotz_l); + ASSIGN_KEY (XK_Left, kp_roty_l); + ASSIGN_KEY (XK_Right, kp_roty_r); + ASSIGN_KEY (XK_Home, kp_zoom_in); + ASSIGN_KEY (XK_Down, kp_rotx_l); + ASSIGN_KEY (XK_Page_Down, kp_rotz_r); + ASSIGN_KEY (XK_Insert, kp_fw_toggle); + ASSIGN_KEY (XK_Delete, kp_bw_toggle); + ASSIGN_KEY (XK_KP_Up, kp_move_u); + ASSIGN_KEY (XK_KP_Left, kp_move_l); + ASSIGN_KEY (XK_KP_Right, kp_move_r); + ASSIGN_KEY (XK_KP_Down, kp_move_d); #undef ASSIGN_KEY return; } -static void version(FILE * f){ +static void +version (FILE *f) +{ // cppcheck-suppress unknownMacro - PRINTOUT(f, "built on "__TIMESTAMP__"\n" - "user: "BUILD_USER"\n" - "directory: "BUILD_DIRECTORY"\n" - "commit: "GIT_HASH" ("GIT_BRANCH")\n" - "\n"); + PRINTOUT (f, "built on "__TIMESTAMP__ + "\n" + "user: " BUILD_USER "\n" + "directory: " BUILD_DIRECTORY "\n" + "commit: " GIT_HASH " (" GIT_BRANCH ")\n" + "\n"); } -int main (int argc, char * argv[]) { +int +main (int argc, char *argv[]) +{ - if(SHOULD_PRINT_MAN(argc)){ - printman(stderr, argv[0]); - version(stderr); - return 0; - } + if (SHOULD_PRINT_MAN (argc)) + { + printman (stderr, argv[0]); + version (stderr); + return 0; + } - /*= Input ==================================================================*/ + /*= Input + * ==================================================================*/ - allpars ap = cli_parse(argc, argv); + allpars ap = cli_parse (argc, argv); - object * ent = READ_FILES(&ap); + object *ent = READ_FILES (&ap); - if(!ent){ - PRINT_ERR("no files to read\n"); - return 1; - } + if (!ent) + { + PRINT_ERR ("no files to read\n"); + return 1; + } - drawpars * dp = &ap.dp; - if(dp->n >= dp->N){ - dp->n = dp->n%dp->N; - } - else if(dp->n<0){ - dp->n = dp->N-((-dp->n-1)%dp->N); - } + drawpars *dp = &ap.dp; + if (dp->n >= dp->N) + { + dp->n = dp->n % dp->N; + } + else if (dp->n < 0) + { + dp->n = dp->N - ((-dp->n - 1) % dp->N); + } - if(dp->ui.gui==GUI_DISABLED){ - return headless(dp, ent); - } + if (dp->ui.gui == GUI_DISABLED) + { + return headless (dp, ent); + } - /*= X11 init ===============================================================*/ + /*= X11 init + * ===============================================================*/ ptf kp[NKP]; - init_x(dp->read.fname, ap.ip.colors); - init_keys(kp); - init_font(ap.ip.fontname); + init_x (dp->read.fname, ap.ip.colors); + init_keys (kp); + init_font (ap.ip.fontname); dp->ui.gui = GUI_TEMP_DISABLED; - wait_for_configure(ent, dp); - run_commands(NULL, ap.ip.on_startup, dp, ent); + wait_for_configure (ent, dp); + run_commands (NULL, ap.ip.on_startup, dp, ent); dp->ui.gui = GUI_ENABLED; - /*= Main loop ==============================================================*/ - main_loop(ent, dp, kp); + /*= Main loop + * ==============================================================*/ + main_loop (ent, dp, kp); return 0; } diff --git a/src/v/ac3_draw.c b/src/v/ac3_draw.c index 450b0d4..f765f7f 100644 --- a/src/v/ac3_draw.c +++ b/src/v/ac3_draw.c @@ -2,108 +2,141 @@ #include "x.h" #define EPS 1e-15 -#define BOND_OFFSET 0.666 // bond line starts this fraction of the atom radius away from the atom center -#define RESOL_SCALE (128.0/768.0) // reference resolution for atom sizes -#define XDRAWSTRING XDrawImageString // change to XDrawString to remove white boxes behind atom/bond labels +#define BOND_OFFSET \ + 0.666 // bond line starts this fraction of the atom radius away from the atom + // center +#define RESOL_SCALE (128.0 / 768.0) // reference resolution for atom sizes +#define XDRAWSTRING \ + XDrawImageString // change to XDrawString to remove white boxes behind + // atom/bond labels extern draw_world_t world; -static inline int getgci(int q){ - return abs(q)z - ((kzstr *)p2)->z ; + d = ((kzstr *)p1)->z - ((kzstr *)p2)->z; if (d > 0) - return 1; + return 1; else if (d < 0) return -1; else - return 0; + return 0; } -void ac3_draw(atcoord * ac, rendpars * rend){ +void +ac3_draw (atcoord *ac, rendpars *rend) +{ int n = ac->n; - kzstr * kz = malloc(sizeof(kzstr)*n); - int * ks = (rend->bonds>0) ? malloc(sizeof(int)*n) : NULL; - if(!kz) GOTOHELL; + kzstr *kz = malloc (sizeof (kzstr) * n); + int *ks = (rend->bonds > 0) ? malloc (sizeof (int) * n) : NULL; + if (!kz) + GOTOHELL; double resol = world.size * RESOL_SCALE; - double r1 = rend->r * resol * rend->scale; + double r1 = rend->r * resol * rend->scale; - for(int k=0; kr[k*3+2]; - } - qsort(kz, n, sizeof(kzstr), cmpz); - if(rend->bonds>0){ - if(!ks) GOTOHELL; - for(int i=0; ir[k * 3 + 2]; } - } - - for(int i=0; iq[k]; - int x = SCREEN_X(ac->r[k*3 ]); - int y = SCREEN_Y(ac->r[k*3+1]); - double rt = r1 * get_radius(ac->q[k]); - int r = MAX(1, rt); - - XFillArc (world.dis, world.canv, world.gcc[getgci(q)], x-r, y-r, 2*r, 2*r, 0, 360*64); - if(r>1){ - XDrawArc(world.dis, world.canv, q>0?world.gc_black:world.gc_dot[1], x-r, y-r, 2*r, 2*r, 0, 360*64); + qsort (kz, n, sizeof (kzstr), cmpz); + if (rend->bonds > 0) + { + if (!ks) + GOTOHELL; + for (int i = 0; i < n; i++) + { + ks[kz[i].k] = i; + } } - if(rend->num == SHOW_NUMBERS){ - char text[16]; - snprintf(text, sizeof(text), "%d", k+1); - XDRAWSTRING(world.dis, world.canv, world.gc_black, x, y, text, strlen(text)); - } - else if(rend->num == SHOW_TYPES){ - char text[16]; - const char * s = get_name(q); - s ? snprintf(text, sizeof(text), "%s", s) : snprintf(text, sizeof(text), "%d", q ); - XDRAWSTRING(world.dis, world.canv, world.gc_black, x, y, text, strlen(text)); - } + for (int i = 0; i < n; i++) + { - if(rend->bonds>0){ - for(int j=k*BONDS_MAX; j<(k+1)*BONDS_MAX; j++){ - int k1 = ac->bonds.a[j]; - if(k1 == -1 ){ - break; - } - if(i > ks[k1]){ - continue; + int k = kz[i].k; + int q = ac->q[k]; + int x = SCREEN_X (ac->r[k * 3]); + int y = SCREEN_Y (ac->r[k * 3 + 1]); + double rt = r1 * get_radius (ac->q[k]); + int r = MAX (1, rt); + + XFillArc (world.dis, world.canv, world.gcc[getgci (q)], x - r, y - r, + 2 * r, 2 * r, 0, 360 * 64); + if (r > 1) + { + XDrawArc (world.dis, world.canv, + q > 0 ? world.gc_black : world.gc_dot[1], x - r, y - r, + 2 * r, 2 * r, 0, 360 * 64); } - int x1 = SCREEN_X(ac->r[k1*3 ]); - int y1 = SCREEN_Y(ac->r[k1*3+1]); - int dx = x1-x; - int dy = y1-y; - double r2d = dx*dx+dy*dy; - if(r2d < EPS){ - continue; + + if (rend->num == SHOW_NUMBERS) + { + char text[16]; + snprintf (text, sizeof (text), "%d", k + 1); + XDRAWSTRING (world.dis, world.canv, world.gc_black, x, y, text, + strlen (text)); } - double dd = BOND_OFFSET * r / sqrt(r2d); - XDrawLine(world.dis, world.canv, world.gc_black, x+dd*dx, y+dd*dy, x1, y1); - if(rend->bonds==SHOW_LENGTHS){ + else if (rend->num == SHOW_TYPES) + { char text[16]; - snprintf(text, sizeof(text), "%.3lf", ac->bonds.r[j]); - XDRAWSTRING(world.dis, world.canv, world.gc_black, x+dx/2, y+dy/2, text, strlen(text)); + const char *s = get_name (q); + s ? snprintf (text, sizeof (text), "%s", s) + : snprintf (text, sizeof (text), "%d", q); + XDRAWSTRING (world.dis, world.canv, world.gc_black, x, y, text, + strlen (text)); + } + + if (rend->bonds > 0) + { + for (int j = k * BONDS_MAX; j < (k + 1) * BONDS_MAX; j++) + { + int k1 = ac->bonds.a[j]; + if (k1 == -1) + { + break; + } + if (i > ks[k1]) + { + continue; + } + int x1 = SCREEN_X (ac->r[k1 * 3]); + int y1 = SCREEN_Y (ac->r[k1 * 3 + 1]); + int dx = x1 - x; + int dy = y1 - y; + double r2d = dx * dx + dy * dy; + if (r2d < EPS) + { + continue; + } + double dd = BOND_OFFSET * r / sqrt (r2d); + XDrawLine (world.dis, world.canv, world.gc_black, x + dd * dx, + y + dd * dy, x1, y1); + if (rend->bonds == SHOW_LENGTHS) + { + char text[16]; + snprintf (text, sizeof (text), "%.3lf", ac->bonds.r[j]); + XDRAWSTRING (world.dis, world.canv, world.gc_black, + x + dx / 2, y + dy / 2, text, strlen (text)); + } + } } - } } - } - free(kz); - free(ks); + free (kz); + free (ks); return; } - diff --git a/src/v/ac3_print.c b/src/v/ac3_print.c index 9b82caf..314cbe4 100644 --- a/src/v/ac3_print.c +++ b/src/v/ac3_print.c @@ -1,107 +1,127 @@ -#include "v.h" #include "matrix.h" +#include "v.h" #include "vec3.h" -void ac3_print(atcoord * ac, rendpars * rend){ - PRINTOUT(stdout, "$molecule\ncart\n"); - for(int k=0; kn; k++){ - PRINTOUT(stdout, "%3d % lf % lf % lf", - ac->q[k], - rend->xy0[0] + ac->r[k*3 ], - rend->xy0[1] + ac->r[k*3+1], - ac->r[k*3+2]); - if(rend->bonds>0){ - for(int j=0; jbonds.a[k*BONDS_MAX+j]; - if(k1 == -1 ){ - break; +void +ac3_print (atcoord *ac, rendpars *rend) +{ + PRINTOUT (stdout, "$molecule\ncart\n"); + for (int k = 0; k < ac->n; k++) + { + PRINTOUT (stdout, "%3d % lf % lf % lf", ac->q[k], + rend->xy0[0] + ac->r[k * 3], rend->xy0[1] + ac->r[k * 3 + 1], + ac->r[k * 3 + 2]); + if (rend->bonds > 0) + { + for (int j = 0; j < BONDS_MAX; j++) + { + int k1 = ac->bonds.a[k * BONDS_MAX + j]; + if (k1 == -1) + { + break; + } + PRINTOUT (stdout, "%s%d", j ? "," : " k=", k1 + 1); + } } - PRINTOUT(stdout, "%s%d", j?",":" k=", k1+1); - } + PRINTOUT (stdout, "\n"); } - PRINTOUT(stdout, "\n"); - } - PRINTOUT(stdout, "$end\n"); + PRINTOUT (stdout, "$end\n"); return; } -void ac3_print_xyz(atcoord * ac, rendpars * rend){ - PRINTOUT(stdout, "%d\n", ac->n); - if(ac->cell.boundary==CELL){ - double C[9]; - mx_multmx(3,3,3, C, rend->ac3rmx, ac->cell.rot_to_lab_basis); - PRINTOUT(stdout, "Lattice=\"%lf %lf %lf %lf %lf %lf %lf %lf %lf\"\n", - C[0], C[3], C[6], - C[1], C[4], C[7], - C[2], C[5], C[8]); - } - else{ - PRINTOUT(stdout, "\n"); - } - - for(int k=0; kn; k++){ - const char * s = get_name(ac->q[k]); - int ok = s && s[0]; - if(ok){ - PRINTOUT(stdout, " %-3s", s); +void +ac3_print_xyz (atcoord *ac, rendpars *rend) +{ + PRINTOUT (stdout, "%d\n", ac->n); + if (ac->cell.boundary == CELL) + { + double C[9]; + mx_multmx (3, 3, 3, C, rend->ac3rmx, ac->cell.rot_to_lab_basis); + PRINTOUT (stdout, "Lattice=\"%lf %lf %lf %lf %lf %lf %lf %lf %lf\"\n", + C[0], C[3], C[6], C[1], C[4], C[7], C[2], C[5], C[8]); + } + else + { + PRINTOUT (stdout, "\n"); } - else{ - PRINTOUT(stdout, " %3d", ac->q[k]); + + for (int k = 0; k < ac->n; k++) + { + const char *s = get_name (ac->q[k]); + int ok = s && s[0]; + if (ok) + { + PRINTOUT (stdout, " %-3s", s); + } + else + { + PRINTOUT (stdout, " %3d", ac->q[k]); + } + PRINTOUT (stdout, " % lf % lf % lf\n", rend->xy0[0] + ac->r[k * 3], + rend->xy0[1] + ac->r[k * 3 + 1], ac->r[k * 3 + 2]); } - PRINTOUT(stdout, " % lf % lf % lf\n", - rend->xy0[0] + ac->r[k*3 ], - rend->xy0[1] + ac->r[k*3+1], - ac->r[k*3+2]); - } return; } -void ac3_print2fig(atcoord * ac, rendpars * rend){ +void +ac3_print2fig (atcoord *ac, rendpars *rend) +{ int n = ac->n; - for(int i=0; iq[i], - rend->xy0[0] + ac->r[i*3 ], - rend->xy0[1] + ac->r[i*3+1], - ac->r[i*3+2]); - } - - if(ac->cell.boundary==CELL){ - for(int i=0; i<8; i++){ - double v[3]; - r3mx(v, ac->cell.vertices+3*i, rend->ac3rmx); - PRINTOUT(stdout, "atom %3d% 13.7lf% 13.7lf% 13.7lf\n", 0, - rend->xy0[0] + v[0], rend->xy0[1] + v[1], v[2]); + for (int i = 0; i < n; i++) + { + PRINTOUT (stdout, "atom %3d% 13.7lf% 13.7lf% 13.7lf\n", ac->q[i], + rend->xy0[0] + ac->r[i * 3], rend->xy0[1] + ac->r[i * 3 + 1], + ac->r[i * 3 + 2]); } - } - if(rend->bonds>0){ - for(int k=0; kbonds.a[k*BONDS_MAX+j]; - if(k1 == -1 ){ - break; + if (ac->cell.boundary == CELL) + { + for (int i = 0; i < 8; i++) + { + double v[3]; + r3mx (v, ac->cell.vertices + 3 * i, rend->ac3rmx); + PRINTOUT (stdout, "atom %3d% 13.7lf% 13.7lf% 13.7lf\n", 0, + rend->xy0[0] + v[0], rend->xy0[1] + v[1], v[2]); } - if(k1 < k){ - PRINTOUT(stdout, "bond %3d %3d\n", k1+1, k+1); - } - } } - } - if(ac->cell.boundary==CELL){ -#define LINE(I,J) PRINTOUT(stdout, "bond %3d %3d % 3d\n", (J)+n+1, (I)+n+1, -1) - for(int i=0; i<8; i+=2){ - LINE(i,i+1); // || z-axis - } - for(int j=0; j<2; j++){ - for(int i=0; i<2; i++){ - LINE(i*4+j, i*4+2+j); // || y-axis - LINE(i*2+j, i*2+4+j); // || x-axis - } + if (rend->bonds > 0) + { + for (int k = 0; k < n; k++) + { + for (int j = 0; j < BONDS_MAX; j++) + { + int k1 = ac->bonds.a[k * BONDS_MAX + j]; + if (k1 == -1) + { + break; + } + if (k1 < k) + { + PRINTOUT (stdout, "bond %3d %3d\n", k1 + 1, k + 1); + } + } + } } + + if (ac->cell.boundary == CELL) + { +#define LINE(I, J) \ + PRINTOUT (stdout, "bond %3d %3d % 3d\n", (J) + n + 1, (I) + n + 1, -1) + for (int i = 0; i < 8; i += 2) + { + LINE (i, i + 1); // || z-axis + } + for (int j = 0; j < 2; j++) + { + for (int i = 0; i < 2; i++) + { + LINE (i * 4 + j, i * 4 + 2 + j); // || y-axis + LINE (i * 2 + j, i * 2 + 4 + j); // || x-axis + } + } #undef LINE - } + } return; } - diff --git a/src/v/ac3_read.c b/src/v/ac3_read.c index 12df4b4..b67bf65 100644 --- a/src/v/ac3_read.c +++ b/src/v/ac3_read.c @@ -1,162 +1,206 @@ +#include "matrix.h" #include "v.h" -#include "vecn.h" #include "vec3.h" -#include "matrix.h" +#include "vecn.h" #define EPS_INV 1e-15 -void mol2cell(atcoord * m){ +void +mol2cell (atcoord *m) +{ double rcell[3]; - for(int j=0; jn; j++){ - double * r = m->r0+j*3; - r3mx(rcell, r, m->cell.rot_to_cell_basis); - for(int i=0; i<3; i++){ - if(rcell[i]<-0.5){ - rcell[i] += 1.0; - } - else if(rcell[i]>0.5){ - rcell[i] -= 1.0; - } + for (int j = 0; j < m->n; j++) + { + double *r = m->r0 + j * 3; + r3mx (rcell, r, m->cell.rot_to_cell_basis); + for (int i = 0; i < 3; i++) + { + if (rcell[i] < -0.5) + { + rcell[i] += 1.0; + } + else if (rcell[i] > 0.5) + { + rcell[i] -= 1.0; + } + } + r3mx (r, rcell, m->cell.rot_to_lab_basis); + r3cp (m->r + j * 3, r); } - r3mx(r, rcell, m->cell.rot_to_lab_basis); - r3cp(m->r+j*3, r); - } return; } -static void cell_fill(cellpars * cell, const double abc[9]){ - const double * a = abc+0; - const double * b = abc+3; - const double * c = abc+6; - for(int i=0; i<2; i++){ - for(int j=0; j<2; j++){ - for(int k=0; k<2; k++){ - r3sums3(cell->vertices + (i*4+j*2+k)*3, a, i-0.5, b, j-0.5, c, k-0.5); - } +static void +cell_fill (cellpars *cell, const double abc[9]) +{ + const double *a = abc + 0; + const double *b = abc + 3; + const double *c = abc + 6; + for (int i = 0; i < 2; i++) + { + for (int j = 0; j < 2; j++) + { + for (int k = 0; k < 2; k++) + { + r3sums3 (cell->vertices + (i * 4 + j * 2 + k) * 3, a, i - 0.5, b, + j - 0.5, c, k - 0.5); + } + } } - } - double rot_to_lab_basis[9] = {a[0], b[0], c[0], - a[1], b[1], c[1], - a[2], b[2], c[2]}; - veccp(9, cell->rot_to_lab_basis, rot_to_lab_basis); - mx_id(3, cell->rot_to_cell_basis); - mx_inv(3, 3, cell->rot_to_cell_basis, rot_to_lab_basis, EPS_INV); + double rot_to_lab_basis[9] + = { a[0], b[0], c[0], a[1], b[1], c[1], a[2], b[2], c[2] }; + veccp (9, cell->rot_to_lab_basis, rot_to_lab_basis); + mx_id (3, cell->rot_to_cell_basis); + mx_inv (3, 3, cell->rot_to_cell_basis, rot_to_lab_basis, EPS_INV); cell->boundary = CELL; return; } -atcoord * atcoord_fill(mol * m0, const render_bonds_t b, const geompars geom, const double cell[9]){ +atcoord * +atcoord_fill (mol *m0, const render_bonds_t b, const geompars geom, + const double cell[9]) +{ int n = m0->n; - size_t q_size = sizeof(int ) * n; - size_t r_size = sizeof(double) * n*3; + size_t q_size = sizeof (int) * n; + size_t r_size = sizeof (double) * n * 3; size_t r0_size = r_size; - struct {size_t r_size; size_t a_size;} bonds = {0, 0}; - if(b!=DISABLE_BONDS){ - bonds.a_size = sizeof(int ) * n*BONDS_MAX; - bonds.r_size = sizeof(double) * n*BONDS_MAX; - } - size_t size = sizeof(atcoord) + q_size + r_size + r0_size + bonds.a_size + bonds.r_size; - atcoord * m = calloc(size, 1); - if(!m) GOTOHELL; - - if(b==DISABLE_BONDS){ - m->r = (double *) (m + 1); - m->r0 = (double *) MEM_END(m,r); - m->q = (int *) MEM_END(m,r0); // cppcheck-suppress invalidPointerCast - } - else{ - m->r = (double *) (m + 1); - m->r0 = (double *) MEM_END(m,r); - m->bonds.r = (double *) MEM_END(m,r0); - m->q = (int *) MEM_END(m,bonds.r); // cppcheck-suppress invalidPointerCast - m->bonds.a = (int *) MEM_END(m,q); - } + struct + { + size_t r_size; + size_t a_size; + } bonds = { 0, 0 }; + if (b != DISABLE_BONDS) + { + bonds.a_size = sizeof (int) * n * BONDS_MAX; + bonds.r_size = sizeof (double) * n * BONDS_MAX; + } + size_t size = sizeof (atcoord) + q_size + r_size + r0_size + bonds.a_size + + bonds.r_size; + atcoord *m = calloc (size, 1); + if (!m) + GOTOHELL; + + if (b == DISABLE_BONDS) + { + m->r = (double *)(m + 1); + m->r0 = (double *)MEM_END (m, r); + m->q = (int *)MEM_END (m, r0); // cppcheck-suppress invalidPointerCast + } + else + { + m->r = (double *)(m + 1); + m->r0 = (double *)MEM_END (m, r); + m->bonds.r = (double *)MEM_END (m, r0); + m->q = (int *)MEM_END (m, + bonds.r); // cppcheck-suppress invalidPointerCast + m->bonds.a = (int *)MEM_END (m, q); + } m->n = n; m->fname = m0->name; - for(int i=0; iq[i] = m0->q[i]; - } - veccp(n*3, m->r, m0->r); + for (int i = 0; i < n; i++) + { + m->q[i] = m0->q[i]; + } + veccp (n * 3, m->r, m0->r); - if(geom.bohr){ - vecscal(n*3, m->r, BA); - } - if(geom.inertia){ - // we should not change m0 - position(&((mol){.n=n, .q=m->q, .r=m->r}), NULL, 1); - } - if(geom.center!=NO_CENTER){ - center_mol(n, m->r, geom.center==CENTER_MASS ? m->q : NULL); - } - veccp(n*3, m->r0, m->r); + if (geom.bohr) + { + vecscal (n * 3, m->r, BA); + } + if (geom.inertia) + { + // we should not change m0 + position (&((mol){ .n = n, .q = m->q, .r = m->r }), NULL, 1); + } + if (geom.center != NO_CENTER) + { + center_mol (n, m->r, geom.center == CENTER_MASS ? m->q : NULL); + } + veccp (n * 3, m->r0, m->r); - if(geom.boundary == CELL){ - cell_fill(&m->cell, geom.cell); - } - else if(geom.boundary == SHELL){ - m->cell.vertices[0] = geom.shell[0]; - m->cell.vertices[1] = geom.shell[1]; - m->cell.boundary = SHELL; - } - else if(cell && geom.boundary!=CELL_DISABLED){ - cell_fill(&m->cell, cell); - } + if (geom.boundary == CELL) + { + cell_fill (&m->cell, geom.cell); + } + else if (geom.boundary == SHELL) + { + m->cell.vertices[0] = geom.shell[0]; + m->cell.vertices[1] = geom.shell[1]; + m->cell.boundary = SHELL; + } + else if (cell && geom.boundary != CELL_DISABLED) + { + cell_fill (&m->cell, cell); + } - if(m->cell.boundary==CELL){ - mol2cell(m); - } + if (m->cell.boundary == CELL) + { + mol2cell (m); + } return m; } -atcoord * ac3_read(readpars read, const render_bonds_t b, const geompars geom, format_t * format){ +atcoord * +ac3_read (readpars read, const render_bonds_t b, const geompars geom, + format_t *format) +{ - mol * m = NULL; - FILE * f = read.f; + mol *m = NULL; + FILE *f = read.f; int cell_found = 0; double cell[9] = {}; - switch(*format){ + switch (*format) + { case XYZ: - if((m=ac3_read_xyz(f, &cell_found, cell))){ - *format = XYZ; - } + if ((m = ac3_read_xyz (f, &cell_found, cell))) + { + *format = XYZ; + } break; case IN: - if((m=ac3_read_in(f))){ - *format = IN; - } + if ((m = ac3_read_in (f))) + { + *format = IN; + } break; case OUT: - if((m=ac3_read_out(f))){ - *format = OUT; - } + if ((m = ac3_read_out (f))) + { + *format = OUT; + } break; default: - if((m=ac3_read_xyz(f, &cell_found, cell))){ - *format = XYZ; - } - if(!m){ - if((m=ac3_read_in(f))){ - *format = IN; + if ((m = ac3_read_xyz (f, &cell_found, cell))) + { + *format = XYZ; } - } - if(!m){ - if((m=ac3_read_out(f))){ - *format = OUT; + if (!m) + { + if ((m = ac3_read_in (f))) + { + *format = IN; + } + } + if (!m) + { + if ((m = ac3_read_out (f))) + { + *format = OUT; + } } - } break; - } - if(!m){ - return NULL; - } + } + if (!m) + { + return NULL; + } m->name = read.fname; - atcoord * M = atcoord_fill(m, b, geom, cell_found ? cell : NULL); - free(m); + atcoord *M = atcoord_fill (m, b, geom, cell_found ? cell : NULL); + free (m); return M; } - diff --git a/src/v/ac3_read_in.c b/src/v/ac3_read_in.c index 3a3f036..74f5741 100644 --- a/src/v/ac3_read_in.c +++ b/src/v/ac3_read_in.c @@ -1,156 +1,195 @@ -#include -#include "v.h" #include "3d.h" +#include "v.h" #include "vec3.h" +#include -int read_cart_atom(FILE * f, int n, mol * m){ +int +read_cart_atom (FILE *f, int n, mol *m) +{ int q; double r[3]; - int res = (fscanf(f, "%d%lf%lf%lf", &q, r, r+1, r+2)==4); - if(res && m){ - m->q[n] = q; - r3cp(m->r+3*n, r); - } + int res = (fscanf (f, "%d%lf%lf%lf", &q, r, r + 1, r + 2) == 4); + if (res && m) + { + m->q[n] = q; + r3cp (m->r + 3 * n, r); + } return res; } -static int read_z_atom( FILE * f, int n, mol * m){ +static int +read_z_atom (FILE *f, int n, mol *m) +{ - int res, q, a, b, c; + int res, q, a, b, c; double R, phi, theta; - switch(n){ + switch (n) + { case 0: - res = (fscanf(f, "%d", &q) == 1); + res = (fscanf (f, "%d", &q) == 1); break; case 1: - res = (fscanf(f, "%d%d%lf", &q, &a, &R) == 3); + res = (fscanf (f, "%d%d%lf", &q, &a, &R) == 3); break; case 2: - res = (fscanf(f, "%d%d%lf%d%lf", &q, &a, &R, &b, &phi) == 5); + res = (fscanf (f, "%d%d%lf%d%lf", &q, &a, &R, &b, &phi) == 5); break; default: - res = (fscanf(f, "%d%d%lf%d%lf%d%lf", &q, &a, &R, &b, &phi, &c, &theta) == 7); + res = (fscanf (f, "%d%d%lf%d%lf%d%lf", &q, &a, &R, &b, &phi, &c, &theta) + == 7); break; - } + } - if(res && m){ - m->q[n] = q; - res = !zmat2cart(n, m->r+3*n, - m->r+3*(a-1), m->r+3*(b-1), m->r+3*(c-1), - R, phi*DEG2RAD, theta*DEG2RAD); - } + if (res && m) + { + m->q[n] = q; + res = !zmat2cart (n, m->r + 3 * n, m->r + 3 * (a - 1), + m->r + 3 * (b - 1), m->r + 3 * (c - 1), R, + phi * DEG2RAD, theta * DEG2RAD); + } return res; } -static inline int read_atom(FILE * f, int zmat, int n, mol * m){ - if(zmat){ - return read_z_atom(f, n, m); - } - else{ - return read_cart_atom(f, n, m); - } +static inline int +read_atom (FILE *f, int zmat, int n, mol *m) +{ + if (zmat) + { + return read_z_atom (f, n, m); + } + else + { + return read_cart_atom (f, n, m); + } } -static int read_atoms(FILE * f, int zmat, mol * m){ +static int +read_atoms (FILE *f, int zmat, mol *m) +{ char s[STRLEN]; int n = 0; - while (fscanf(f, " $%255s", s) != 1){ - if(fscanf(f, "set =%255s", s)==1){ - continue; - } - if(!read_atom(f, zmat, n, m)){ - return 0; - } - // ignore the rest of the line - int tc; - while((tc=getc(f))!='\n'){ - if(tc==EOF){ - return 0; - } + while (fscanf (f, " $%255s", s) != 1) + { + if (fscanf (f, "set =%255s", s) == 1) + { + continue; + } + if (!read_atom (f, zmat, n, m)) + { + return 0; + } + // ignore the rest of the line + int tc; + while ((tc = getc (f)) != '\n') + { + if (tc == EOF) + { + return 0; + } + } + n++; } - n++; - } return n; } -static inline int strlcmp(const char * const s1, const char * const s2){ - return strncmp(s1, s2, MIN(strlen(s1), strlen(s2))); +static inline int +strlcmp (const char *const s1, const char *const s2) +{ + return strncmp (s1, s2, MIN (strlen (s1), strlen (s2))); } -mol * ac3_read_in(FILE * f){ +mol * +ac3_read_in (FILE *f) +{ int bohr = 0; int zmat = 0; char s[STRLEN]; char key[STRLEN]; char val[STRLEN]; - long pos0 = ftell(f); + long pos0 = ftell (f); // find where the molecule begins - while(1){ - memset(s, '\0', sizeof(s)); - if(!fgets(s, sizeof(s), f)){ - goto hell; - } - const char * s0 = s; - while(s0[0] && (s0[0]==' ' || s[0]=='\t')){ - s0++; - } - if(!strcmp(s0, "$molecule\n")){ - break; + while (1) + { + memset (s, '\0', sizeof (s)); + if (!fgets (s, sizeof (s), f)) + { + goto hell; + } + const char *s0 = s; + while (s0[0] && (s0[0] == ' ' || s[0] == '\t')) + { + s0++; + } + if (!strcmp (s0, "$molecule\n")) + { + break; + } } - } // read the keyword block up until cart/zmat - while (fscanf(f, " %255[^$ \n]", s) == 1) { - for(int i=0; ir, BA); - } + mol *m = alloc_mol (n); + if (!read_atoms (f, zmat, m)) + { + // error in zmat conversion + free (m); + goto hell; + } + if (bohr) + { + vecscal (3 * n, m->r, BA); + } return m; hell: - fseek(f, pos0, SEEK_SET); + fseek (f, pos0, SEEK_SET); return NULL; } diff --git a/src/v/ac3_read_out.c b/src/v/ac3_read_out.c index 96365d5..c2f4073 100644 --- a/src/v/ac3_read_out.c +++ b/src/v/ac3_read_out.c @@ -1,41 +1,49 @@ +#include "mol.h" #include "v.h" #include "vec3.h" -#include "mol.h" -mol * ac3_read_out(FILE * f){ +mol * +ac3_read_out (FILE *f) +{ - long pos0 = ftell(f); + long pos0 = ftell (f); // find where the molecule begins char s[STRLEN]; - while(1){ - if(!fgets(s, sizeof(s), f)){ - goto hell; - } - if(strstr(s, "Atomic Coordinates:")){ - break; + while (1) + { + if (!fgets (s, sizeof (s), f)) + { + goto hell; + } + if (strstr (s, "Atomic Coordinates:")) + { + break; + } } - } // count atoms - long pos1 = ftell(f); - int n=0; - while(read_cart_atom(f, n, NULL)){ - n++; - } - if(!n){ - goto hell; - } - fseek(f, pos1, SEEK_SET); + long pos1 = ftell (f); + int n = 0; + while (read_cart_atom (f, n, NULL)) + { + n++; + } + if (!n) + { + goto hell; + } + fseek (f, pos1, SEEK_SET); // fill in - mol * m = alloc_mol(n); - for(int i=0; ir+3*i, m->r+3*i+1, m->r+3*i+2) != 4){ - free(m); + int r = read_header (f, tcell); + if (r == -1) + { return NULL; } - m->q[i] = get_element(type); + else if (r == 1) + { + veccp (9, cell, tcell); + *cell_found = 1; + } - if(eat_line(f)){ - free(m); - return NULL; + // fill in + mol *m = alloc_mol (n); + for (int i = 0; i < n; i++) + { + styp type; + if (fscanf (f, "%7s%lf%lf%lf", type, m->r + 3 * i, m->r + 3 * i + 1, + m->r + 3 * i + 2) + != 4) + { + free (m); + return NULL; + } + m->q[i] = get_element (type); + + if (eat_line (f)) + { + free (m); + return NULL; + } } - } return m; } diff --git a/src/v/bonds.c b/src/v/bonds.c index 6a92563..7713aee 100644 --- a/src/v/bonds.c +++ b/src/v/bonds.c @@ -1,189 +1,238 @@ #include "v.h" #include "vec3.h" -#define DMAX_SCALE 2.01 // look for bonds within max. atom diameter + eps -#define boxnumber(BOX,NB) (BOX[0]*NB[1]*NB[2] + BOX[1]*NB[2] + BOX[2]) +#define DMAX_SCALE 2.01 // look for bonds within max. atom diameter + eps +#define boxnumber(BOX, NB) (BOX[0] * NB[1] * NB[2] + BOX[1] * NB[2] + BOX[2]) -static int cmpint(const void * p1, const void * p2){ +static int +cmpint (const void *p1, const void *p2) +{ int d = *(int *)p1 - *(int *)p2; if (d > 0) - return 1; + return 1; else if (d < 0) return -1; else - return 0; + return 0; } -static void makelist(int bsize_max, int * bsize, int * list, - double d, const int box_n[3], const double rmin[3], const atcoord * ac){ - - for(int i=0; in; i++){ - double r[3]; - r3diff(r, ac->r+3*i, rmin); - int ind[3]; - ind[0] = r[0] / d; - ind[1] = r[1] / d; - ind[2] = r[2] / d; - int j = boxnumber(ind, box_n); - if(list){ - list[ bsize_max*j + bsize[j] ] = i; +static void +makelist (int bsize_max, int *bsize, int *list, double d, const int box_n[3], + const double rmin[3], const atcoord *ac) +{ + + for (int i = 0; i < ac->n; i++) + { + double r[3]; + r3diff (r, ac->r + 3 * i, rmin); + int ind[3]; + ind[0] = r[0] / d; + ind[1] = r[1] / d; + ind[2] = r[2] / d; + int j = boxnumber (ind, box_n); + if (list) + { + list[bsize_max * j + bsize[j]] = i; + } + bsize[j]++; } - bsize[j]++; - } return; } -static void bonds_add(bondpars bond, atcoord * ac){ +static void +bonds_add (bondpars bond, atcoord *ac) +{ double bmax = bond.bmax; - double rl = bond.rl; - double dmax = (bmax > 0.0) ? bmax : (DMAX_SCALE * rl * get_maxradius(ac->n, ac->q)); + double rl = bond.rl; + double dmax + = (bmax > 0.0) ? bmax : (DMAX_SCALE * rl * get_maxradius (ac->n, ac->q)); double rmin[3], rmax[3]; - r3cp(rmin, ac->r); - r3cp(rmax, ac->r); - for(int i=1; in; i++){ - rmin[0] = MIN(rmin[0], ac->r[i*3+0]); - rmin[1] = MIN(rmin[1], ac->r[i*3+1]); - rmin[2] = MIN(rmin[2], ac->r[i*3+2]); - rmax[0] = MAX(rmax[0], ac->r[i*3+0]); - rmax[1] = MAX(rmax[1], ac->r[i*3+1]); - rmax[2] = MAX(rmax[2], ac->r[i*3+2]); - } + r3cp (rmin, ac->r); + r3cp (rmax, ac->r); + for (int i = 1; i < ac->n; i++) + { + rmin[0] = MIN (rmin[0], ac->r[i * 3 + 0]); + rmin[1] = MIN (rmin[1], ac->r[i * 3 + 1]); + rmin[2] = MIN (rmin[2], ac->r[i * 3 + 2]); + rmax[0] = MAX (rmax[0], ac->r[i * 3 + 0]); + rmax[1] = MAX (rmax[1], ac->r[i * 3 + 1]); + rmax[2] = MAX (rmax[2], ac->r[i * 3 + 2]); + } int box_n[3]; - box_n[0] = (rmax[0]-rmin[0])/dmax + 1; - box_n[1] = (rmax[1]-rmin[1])/dmax + 1; - box_n[2] = (rmax[2]-rmin[2])/dmax + 1; + box_n[0] = (rmax[0] - rmin[0]) / dmax + 1; + box_n[1] = (rmax[1] - rmin[1]) / dmax + 1; + box_n[2] = (rmax[2] - rmin[2]) / dmax + 1; - int nboxes = box_n[0]*box_n[1]*box_n[2]; - int * bsize = calloc(sizeof(int)*nboxes, 1); - if(!bsize) GOTOHELL; + int nboxes = box_n[0] * box_n[1] * box_n[2]; + int *bsize = calloc (sizeof (int) * nboxes, 1); + if (!bsize) + GOTOHELL; - makelist(0, bsize, NULL, dmax, box_n, rmin, ac); + makelist (0, bsize, NULL, dmax, box_n, rmin, ac); int bsize_max = 0; - for(int i=0; ibonds.rl > 0.0 && ac->bonds.a[k1*BONDS_MAX+BONDS_MAX-1] != -1){ - // at the 1st time ac->bond->rl==0.0 - if(!warned){ - PRINT_WARN("too many bonds (>= %d)\n", BONDS_MAX); - warned = 1; - } - continue; - } - - for(int l=0; lbonds.a[k1*BONDS_MAX+l] = -1; - } - - int nb = 0; - double r1 = get_radius(ac->q[k1]); - - int b2[3]; - for(b2[0]=b1[0]+bra[0]; b2[0]q[k2]); - double s0 = rl * (r1 + r2); - if(bmax > 0.0){ - s0 = MIN(s0, bmax); - } - double s2 = r3d2(ac->r+k1*3, ac->r+k2*3); - if(s2 > s0*s0){ - continue; - } - if(nbbonds.a[k1*BONDS_MAX+nb] = k2; - nb++; - } - else{ - if(!warned){ - PRINT_WARN("too many bonds (> %d)\n", BONDS_MAX); - warned = 1; + for (b1[0] = 0; b1[0] < box_n[0]; b1[0]++) + { + for (b1[1] = 0; b1[1] < box_n[1]; b1[1]++) + { + for (b1[2] = 0; b1[2] < box_n[2]; b1[2]++) + { + int i = boxnumber (b1, box_n); + if (!bsize[i]) + continue; + + int bra[3], ket[3]; + bra[0] = b1[0] ? -1 : 0; + bra[1] = b1[1] ? -1 : 0; + bra[2] = b1[2] ? -1 : 0; + ket[0] = b1[0] == box_n[0] - 1 ? 1 : 2; + ket[1] = b1[1] == box_n[1] - 1 ? 1 : 2; + ket[2] = b1[2] == box_n[2] - 1 ? 1 : 2; + + for (int ii = 0; ii < bsize[i]; ii++) + { + int k1 = list[bsize_max * i + ii]; + + if (ac->bonds.rl > 0.0 + && ac->bonds.a[k1 * BONDS_MAX + BONDS_MAX - 1] != -1) + { + // at the 1st time ac->bond->rl==0.0 + if (!warned) + { + PRINT_WARN ("too many bonds (>= %d)\n", BONDS_MAX); + warned = 1; + } + continue; + } + + for (int l = 0; l < BONDS_MAX; l++) + { + ac->bonds.a[k1 * BONDS_MAX + l] = -1; + } + + int nb = 0; + double r1 = get_radius (ac->q[k1]); + + int b2[3]; + for (b2[0] = b1[0] + bra[0]; b2[0] < b1[0] + ket[0]; b2[0]++) + { + for (b2[1] = b1[1] + bra[1]; b2[1] < b1[1] + ket[1]; + b2[1]++) + { + for (b2[2] = b1[2] + bra[2]; b2[2] < b1[2] + ket[2]; + b2[2]++) + { + int j = boxnumber (b2, box_n); + + for (int jj = 0; jj < bsize[j]; jj++) + { + int k2 = list[bsize_max * j + jj]; + if (k2 == k1) + continue; + + double r2 = get_radius (ac->q[k2]); + double s0 = rl * (r1 + r2); + if (bmax > 0.0) + { + s0 = MIN (s0, bmax); + } + double s2 + = r3d2 (ac->r + k1 * 3, ac->r + k2 * 3); + if (s2 > s0 * s0) + { + continue; + } + if (nb < BONDS_MAX) + { + ac->bonds.a[k1 * BONDS_MAX + nb] = k2; + nb++; + } + else + { + if (!warned) + { + PRINT_WARN ( + "too many bonds (> %d)\n", + BONDS_MAX); + warned = 1; + } + goto toomany; + } + } + } + } + } + toomany: + qsort (ac->bonds.a + k1 * BONDS_MAX, nb, sizeof (int), + cmpint); + for (int l = 0; l < nb; l++) + { + int k2 = ac->bonds.a[k1 * BONDS_MAX + l]; + ac->bonds.r[k1 * BONDS_MAX + l] + = sqrt (r3d2 (ac->r + k1 * 3, ac->r + k2 * 3)); } - goto toomany; - } } - } } - } -toomany: - qsort(ac->bonds.a+k1*BONDS_MAX, nb, sizeof(int), cmpint); - for(int l=0; lbonds.a[k1*BONDS_MAX+l]; - ac->bonds.r[k1*BONDS_MAX+l] = sqrt(r3d2(ac->r+k1*3, ac->r+k2*3)); - } - } - } } - } - free(list); - free(bsize); + free (list); + free (bsize); return; } -static void bonds_reduce(bondpars bond, atcoord * ac){ - for(int k1=0; k1n; k1++){ - double r1 = get_radius(ac->q[k1]); - int nb = 0; - for(int j=0; jbonds.a[k1*BONDS_MAX+j]; - if(k2==-1) break; - double r = ac->bonds.r[k1*BONDS_MAX+j]; - double r2 = get_radius(ac->q[k2]); - if( r < bond.rl*(r1+r2) ){ - ac->bonds.a[k1*BONDS_MAX+nb] = k2; - ac->bonds.r[k1*BONDS_MAX+nb] = r; - nb++; - } - } - for(int j=nb; jbonds.a[k1*BONDS_MAX+j] = -1; +static void +bonds_reduce (bondpars bond, atcoord *ac) +{ + for (int k1 = 0; k1 < ac->n; k1++) + { + double r1 = get_radius (ac->q[k1]); + int nb = 0; + for (int j = 0; j < BONDS_MAX; j++) + { + int k2 = ac->bonds.a[k1 * BONDS_MAX + j]; + if (k2 == -1) + break; + double r = ac->bonds.r[k1 * BONDS_MAX + j]; + double r2 = get_radius (ac->q[k2]); + if (r < bond.rl * (r1 + r2)) + { + ac->bonds.a[k1 * BONDS_MAX + nb] = k2; + ac->bonds.r[k1 * BONDS_MAX + nb] = r; + nb++; + } + } + for (int j = nb; j < BONDS_MAX; j++) + { + ac->bonds.a[k1 * BONDS_MAX + j] = -1; + } } - } return; } -void bonds_fill(bondpars bond, atcoord * ac){ - if(ac->bonds.flag){ - return; - } - (bond.rl > ac->bonds.rl) ? bonds_add(bond, ac) : bonds_reduce(bond, ac); +void +bonds_fill (bondpars bond, atcoord *ac) +{ + if (ac->bonds.flag) + { + return; + } + (bond.rl > ac->bonds.rl) ? bonds_add (bond, ac) : bonds_reduce (bond, ac); ac->bonds.rl = bond.rl; ac->bonds.flag = 1; return; diff --git a/src/v/cli.c b/src/v/cli.c index 7e7fbe4..5479171 100644 --- a/src/v/cli.c +++ b/src/v/cli.c @@ -1,216 +1,273 @@ +#include "matrix.h" #include "v.h" #include "vecn.h" -#include "matrix.h" #define EPS 1e-15 -static int lazysscanf(char * const s, const char * const template, char ** ret){ +static int +lazysscanf (char *const s, const char *const template, char **ret) +{ // if the string `s` begins with the template, // assign *ret to the part of the string after the template, // otherwise do nothing - int n = strlen(template); - int r = !strncmp(template, s, n); - if(r){ - if(strlen(s)==n){ - PRINT_WARN("option %s needs an argument\n", template) - } - else{ - *ret = s+n; + int n = strlen (template); + int r = !strncmp (template, s, n); + if (r) + { + if (strlen (s) == n) + { + PRINT_WARN ("option %s needs an argument\n", template) + } + else + { + *ret = s + n; + } } - } return r; } -static int sscan_rot(const char * arg, double ac3rmx[9]){ +static int +sscan_rot (const char *arg, double ac3rmx[9]) +{ double rot[9]; - int count = sscanf(arg, "rot:%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", rot, rot+1, rot+2, rot+3, rot+4, rot+5, rot+6, rot+7, rot+8); - if(count <= 0){ - return 0; - } - else if(count == 9){ - veccp(9, ac3rmx, rot); // we don't check if it is unitary - } - else{ - PRINT_WARN("option `rot:` takes exactly 9 comma-separated arguments\n") - } + int count + = sscanf (arg, "rot:%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", rot, rot + 1, + rot + 2, rot + 3, rot + 4, rot + 5, rot + 6, rot + 7, rot + 8); + if (count <= 0) + { + return 0; + } + else if (count == 9) + { + veccp (9, ac3rmx, rot); // we don't check if it is unitary + } + else + { + PRINT_WARN ("option `rot:` takes exactly 9 comma-separated arguments\n") + } return 1; } -static int sscan_cell(const char * arg, geompars * geom){ +static int +sscan_cell (const char *arg, geompars *geom) +{ double cell[9]; - int count = sscanf(arg, "cell:b%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", cell, cell+1, cell+2, cell+3, cell+4, cell+5, cell+6, cell+7, cell+8); - if(count > 0){ - if(count==9 || count==3 || count==1){ - vecscal(count, cell, BA); + int count = sscanf (arg, "cell:b%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", cell, + cell + 1, cell + 2, cell + 3, cell + 4, cell + 5, + cell + 6, cell + 7, cell + 8); + if (count > 0) + { + if (count == 9 || count == 3 || count == 1) + { + vecscal (count, cell, BA); + } + else + { + PRINT_WARN ("option `cell:b` takes exactly 1, 3 or 9 " + "comma-separated arguments\n") + return 1; + } } - else{ - PRINT_WARN("option `cell:b` takes exactly 1, 3 or 9 comma-separated arguments\n") - return 1; + else + { + count = sscanf (arg, "cell:%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", cell, + cell + 1, cell + 2, cell + 3, cell + 4, cell + 5, + cell + 6, cell + 7, cell + 8); + if (count <= 0) + { + return 0; + } + else if (count != 3 && count != 9 && count != 1) + { + PRINT_WARN ("option `cell:` takes exactly 1, 3, or 9 " + "comma-separated arguments\n") + return 1; + } } - } - else{ - count = sscanf(arg, "cell:%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", cell, cell+1, cell+2, cell+3, cell+4, cell+5, cell+6, cell+7, cell+8); - if(count <= 0){ - return 0; + + double s = 0.0; + for (int i = 0; i < count; i++) + { + s += fabs (cell[i]); } - else if(count!=3 && count!=9 && count!=1){ - PRINT_WARN("option `cell:` takes exactly 1, 3, or 9 comma-separated arguments\n") + if (s < EPS) + { + geom->boundary = CELL_DISABLED; return 1; } - } - - double s=0.0; - for(int i=0; iboundary = CELL_DISABLED; - return 1; - } - - if(count==1){ - geom->cell[0] = cell[0]; - geom->cell[4] = cell[0]; - geom->cell[8] = cell[0]; - } - else if(count==3){ - geom->cell[0] = cell[0]; - geom->cell[4] = cell[1]; - geom->cell[8] = cell[2]; - } - else{ - veccp(9, geom->cell, cell); - } + + if (count == 1) + { + geom->cell[0] = cell[0]; + geom->cell[4] = cell[0]; + geom->cell[8] = cell[0]; + } + else if (count == 3) + { + geom->cell[0] = cell[0]; + geom->cell[4] = cell[1]; + geom->cell[8] = cell[2]; + } + else + { + veccp (9, geom->cell, cell); + } geom->boundary = CELL; return 1; } -static int sscan_shell(const char * arg, geompars * geom){ +static int +sscan_shell (const char *arg, geompars *geom) +{ double shell[2]; - int count = sscanf(arg, "shell:b%lf,%lf", shell, shell+1); - if(count > 0){ - vecscal(count, shell, BA); - } - else{ - count = sscanf(arg, "shell:%lf,%lf", shell, shell+1); - } - if(count>0){ - geom->shell[0] = shell[0]; - geom->shell[1] = shell[count>1]; - geom->boundary = SHELL; - return 1; - } - else{ - return 0; - } + int count = sscanf (arg, "shell:b%lf,%lf", shell, shell + 1); + if (count > 0) + { + vecscal (count, shell, BA); + } + else + { + count = sscanf (arg, "shell:%lf,%lf", shell, shell + 1); + } + if (count > 0) + { + geom->shell[0] = shell[0]; + geom->shell[1] = shell[count > 1]; + geom->boundary = SHELL; + return 1; + } + else + { + return 0; + } } -static int cli_parse_arg(char * arg, allpars * ap){ - drawpars * dp = &ap->dp; - initpars * ip = &ap->ip; +static int +cli_parse_arg (char *arg, allpars *ap) +{ + drawpars *dp = &ap->dp; + initpars *ip = &ap->ip; int vib = -1, bonds = -2, frame = 0; double tf = 0, bmax = 0; - char * ts = NULL; - - int cli = - sscanf (arg, "vib:%d", &vib) - || sscanf (arg, "bonds:%d", &bonds) - || sscanf (arg, "dt:%lf", &tf) - || sscanf (arg, "bmax:%lf", &bmax) - || sscanf (arg, "frame:%d", &frame) - || sscanf (arg, "symtol:%lf", &dp->anal.symtol) - || sscanf (arg, "gui:%d", &dp->ui.gui) - || sscanf (arg, "bohr:%d", &dp->geom.bohr) - || sscanf (arg, "center:%d", &dp->geom.center) - || sscanf (arg, "inertia:%d", &dp->geom.inertia) - || sscanf (arg, "z:%d,%d,%d,%d,%d", dp->anal.intcoord, dp->anal.intcoord+1, dp->anal.intcoord+2, dp->anal.intcoord+3, dp->anal.intcoord+4) - || lazysscanf(arg, "font:", &ip->fontname) - || lazysscanf(arg, "com:", &dp->ui.com) - || lazysscanf(arg, "exitcom:", &dp->ui.on_exit) - || lazysscanf(arg, "startcom:", &ip->on_startup) - || lazysscanf(arg, "colors:", &ts) - || sscan_rot (arg, dp->rend.ac3rmx) - || sscan_cell (arg, &dp->geom) - || sscan_shell(arg, &dp->geom) - ; - - if(vib==0){ - dp->task = AT3COORDS; - } - else if(vib==1){ - dp->task = VIBRO; - } - - if(bonds==0){ - dp->rend.bonds = DISABLE_BONDS; - } - - if(tf>0.0){ - dp->anim.dt = ceil(tf*S_TO_MS); - } - - if(bmax>0.0){ - dp->bond.bmax = bmax; - } - - if(frame){ - dp->n = frame-1; - } - - if(ts){ - const char * const colorscheme_names[] = {[V_COLORS] = "v", [CPK_COLORS] = "cpk"}; - int ncs = sizeof(colorscheme_names)/sizeof(colorscheme_names[0]); - for(int i=0; icolors = i; - break; - } - if(i==ncs-1){ - PRINT_WARN("unknown colorscheme %s. defaulting to %s\n", ts, colorscheme_names[V_COLORS]); - } - } - } - - if(!cli){ - ip->input_files[ip->input_files_n++] = arg; - } + char *ts = NULL; + + int cli = sscanf (arg, "vib:%d", &vib) || sscanf (arg, "bonds:%d", &bonds) + || sscanf (arg, "dt:%lf", &tf) || sscanf (arg, "bmax:%lf", &bmax) + || sscanf (arg, "frame:%d", &frame) + || sscanf (arg, "symtol:%lf", &dp->anal.symtol) + || sscanf (arg, "gui:%d", &dp->ui.gui) + || sscanf (arg, "bohr:%d", &dp->geom.bohr) + || sscanf (arg, "center:%d", &dp->geom.center) + || sscanf (arg, "inertia:%d", &dp->geom.inertia) + || sscanf (arg, "z:%d,%d,%d,%d,%d", dp->anal.intcoord, + dp->anal.intcoord + 1, dp->anal.intcoord + 2, + dp->anal.intcoord + 3, dp->anal.intcoord + 4) + || lazysscanf (arg, "font:", &ip->fontname) + || lazysscanf (arg, "com:", &dp->ui.com) + || lazysscanf (arg, "exitcom:", &dp->ui.on_exit) + || lazysscanf (arg, "startcom:", &ip->on_startup) + || lazysscanf (arg, "colors:", &ts) + || sscan_rot (arg, dp->rend.ac3rmx) || sscan_cell (arg, &dp->geom) + || sscan_shell (arg, &dp->geom); + + if (vib == 0) + { + dp->task = AT3COORDS; + } + else if (vib == 1) + { + dp->task = VIBRO; + } + + if (bonds == 0) + { + dp->rend.bonds = DISABLE_BONDS; + } + + if (tf > 0.0) + { + dp->anim.dt = ceil (tf * S_TO_MS); + } + + if (bmax > 0.0) + { + dp->bond.bmax = bmax; + } + + if (frame) + { + dp->n = frame - 1; + } + + if (ts) + { + const char *const colorscheme_names[] + = { [V_COLORS] = "v", [CPK_COLORS] = "cpk" }; + int ncs = sizeof (colorscheme_names) / sizeof (colorscheme_names[0]); + for (int i = 0; i < ncs; i++) + { + int l0 = strlen (colorscheme_names[i]); + int l1 = strlen (ts); + if ((l0 == l1) && (!strncmp (ts, colorscheme_names[i], l0))) + { + ip->colors = i; + break; + } + if (i == ncs - 1) + { + PRINT_WARN ("unknown colorscheme %s. defaulting to %s\n", ts, + colorscheme_names[V_COLORS]); + } + } + } + + if (!cli) + { + ip->input_files[ip->input_files_n++] = arg; + } return cli; } -static allpars allpars_init(void){ - allpars ap = {}; // everything not set below is 0 / 0.0 / NULL / '\0' +static allpars +allpars_init (void) +{ + allpars ap = {}; // everything not set below is 0 / 0.0 / NULL / '\0' ap.ip.colors = V_COLORS; - ap.dp.task = UNKNOWN; - ap.dp.anim.dt = DEFAULT_TIMEOUT; + ap.dp.task = UNKNOWN; + ap.dp.anim.dt = DEFAULT_TIMEOUT; ap.dp.anal.symtol = DEFAULT_SYMTOL; - ap.dp.bond.rl = 1.0; + ap.dp.bond.rl = 1.0; ap.dp.geom.center = CENTER_GEOM; - ap.dp.ui.gui = GUI_ENABLED; + ap.dp.ui.gui = GUI_ENABLED; - ap.dp.rend.r = 1.0; + ap.dp.rend.r = 1.0; ap.dp.rend.scale = 1.0; ap.dp.rend.bonds = SHOW_BONDS; - mx_id(3, ap.dp.rend.ac3rmx); + mx_id (3, ap.dp.rend.ac3rmx); return ap; } -allpars cli_parse(int argc, char ** argv){ - allpars ap = allpars_init(); - ap.ip.input_files = malloc(argc*sizeof(char*)); - for(int i=1; itask == AT3COORDS){ - if(!dp->read.f){ - PRINT_ERR("cannot read from the file '%s'\n", dp->read.fname); - return; +void +kp_readmore (object *ent, drawpars *dp) +{ + if (dp->task == AT3COORDS) + { + if (!dp->read.f) + { + PRINT_ERR ("cannot read from the file '%s'\n", dp->read.fname); + return; + } + fseek (dp->read.f, 0, SEEK_CUR); + acs_readmore (dp->read, dp->rend.bonds, dp->geom, ent); + dp->N = ent->n; + exp_redraw (ent, dp); } - fseek(dp->read.f, 0, SEEK_CUR); - acs_readmore(dp->read, dp->rend.bonds, dp->geom, ent); - dp->N = ent->n; - exp_redraw (ent, dp); - } return; } -void kp_readagain(object * ent, drawpars * dp){ - if(dp->task == AT3COORDS){ - - if(!dp->read.f || !(fclose(dp->read.f), dp->read.f = fopen(dp->read.fname, "r"))){ - PRINT_WARN("cannot reload the file '%s'\n", dp->read.fname); - return; - } - - for(int i=0; in; i++){ - free(ent->m[i]); +void +kp_readagain (object *ent, drawpars *dp) +{ + if (dp->task == AT3COORDS) + { + + if (!dp->read.f + || !(fclose (dp->read.f), dp->read.f = fopen (dp->read.fname, "r"))) + { + PRINT_WARN ("cannot reload the file '%s'\n", dp->read.fname); + return; + } + + for (int i = 0; i < ent->n; i++) + { + free (ent->m[i]); + } + ent->n = dp->N = dp->n = 0; + acs_readmore (dp->read, dp->rend.bonds, dp->geom, ent); + dp->N = ent->n; + exp_redraw (ent, dp); } - ent->n = dp->N = dp->n = 0; - acs_readmore(dp->read, dp->rend.bonds, dp->geom, ent); - dp->N = ent->n; - exp_redraw (ent, dp); - } return; } -void kp_print(object * ent, drawpars * dp){ - if (dp->task == AT3COORDS){ - ac3_print(ent->m[dp->n], &dp->rend); - } +void +kp_print (object *ent, drawpars *dp) +{ + if (dp->task == AT3COORDS) + { + ac3_print (ent->m[dp->n], &dp->rend); + } return; } -void kp_print_xyz(object * ent, drawpars * dp){ - if (dp->task == AT3COORDS){ - ac3_print_xyz(ent->m[dp->n], &dp->rend); - } +void +kp_print_xyz (object *ent, drawpars *dp) +{ + if (dp->task == AT3COORDS) + { + ac3_print_xyz (ent->m[dp->n], &dp->rend); + } return; } -void kp_print2fig(object * ent, drawpars * dp){ - if (dp->task == AT3COORDS){ - ac3_print2fig(ent->m[dp->n], &dp->rend); - } +void +kp_print2fig (object *ent, drawpars *dp) +{ + if (dp->task == AT3COORDS) + { + ac3_print2fig (ent->m[dp->n], &dp->rend); + } return; } -void kp_printrot(object * ent __attribute__ ((unused)), drawpars * dp){ - double * U = dp->rend.ac3rmx; - for(int i=0; i<3; i++){ - PRINTOUT(stdout, "rotation> % 20.15lf % 20.15lf % 20.15lf\n", U[i*3], U[i*3+1], U[i*3+2]); - } - PRINTOUT(stdout, "rot:%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf\n\n", - U[0], U[1], U[2], U[3], U[4], U[5], U[6], U[7], U[8]); +void +kp_printrot (object *ent __attribute__ ((unused)), drawpars *dp) +{ + double *U = dp->rend.ac3rmx; + for (int i = 0; i < 3; i++) + { + PRINTOUT (stdout, "rotation> % 20.15lf % 20.15lf % 20.15lf\n", U[i * 3], + U[i * 3 + 1], U[i * 3 + 2]); + } + PRINTOUT (stdout, "rot:%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf\n\n", U[0], U[1], + U[2], U[3], U[4], U[5], U[6], U[7], U[8]); return; } -static void rl_changed(object * ent, drawpars * dp){ - for(int i=0; in; i++){ - ent->m[i]->bonds.flag = 0; - } - exp_redraw(ent, dp); +static void +rl_changed (object *ent, drawpars *dp) +{ + for (int i = 0; i < ent->n; i++) + { + ent->m[i]->bonds.flag = 0; + } + exp_redraw (ent, dp); return; } -void kp_rl_dec(object * ent, drawpars * dp){ - if(dp->rend.bonds>0){ - dp->bond.rl /= STEP_R; - rl_changed(ent, dp); - } +void +kp_rl_dec (object *ent, drawpars *dp) +{ + if (dp->rend.bonds > 0) + { + dp->bond.rl /= STEP_R; + rl_changed (ent, dp); + } return; } -void kp_rl_inc(object * ent, drawpars * dp){ - if(dp->rend.bonds>0){ - dp->bond.rl *= STEP_R; - rl_changed(ent, dp); - } +void +kp_rl_inc (object *ent, drawpars *dp) +{ + if (dp->rend.bonds > 0) + { + dp->bond.rl *= STEP_R; + rl_changed (ent, dp); + } return; } -void kp_r_dec(object * ent, drawpars * dp){ +void +kp_r_dec (object *ent, drawpars *dp) +{ dp->rend.r /= STEP_R; - exp_redraw(ent, dp); + exp_redraw (ent, dp); return; } -void kp_r_inc(object * ent, drawpars * dp){ +void +kp_r_inc (object *ent, drawpars *dp) +{ dp->rend.r *= STEP_R; - exp_redraw(ent, dp); + exp_redraw (ent, dp); return; } -void kp_zoom_out(object * ent, drawpars * dp){ +void +kp_zoom_out (object *ent, drawpars *dp) +{ dp->rend.scale /= STEP_ZOOM; - exp_redraw(ent, dp); + exp_redraw (ent, dp); return; } -void kp_zoom_in(object * ent, drawpars * dp){ +void +kp_zoom_in (object *ent, drawpars *dp) +{ dp->rend.scale *= STEP_ZOOM; - exp_redraw(ent, dp); + exp_redraw (ent, dp); return; } -void kp_frame_inc(object * ent, drawpars * dp){ - if (dp->n < dp->N-1){ - dp->n++; - exp_redraw(ent, dp); - } - if (dp->n == dp->N-1 && dp->task == AT3COORDS){ - dp->anim.dir = 0; - } +void +kp_frame_inc (object *ent, drawpars *dp) +{ + if (dp->n < dp->N - 1) + { + dp->n++; + exp_redraw (ent, dp); + } + if (dp->n == dp->N - 1 && dp->task == AT3COORDS) + { + dp->anim.dir = 0; + } return; } -void kp_frame_dec(object * ent, drawpars * dp){ - if (dp->n > 0){ - dp->n--; - exp_redraw(ent, dp); - } - if (dp->n == 0 && dp->task == AT3COORDS){ - dp->anim.dir = 0; - } +void +kp_frame_dec (object *ent, drawpars *dp) +{ + if (dp->n > 0) + { + dp->n--; + exp_redraw (ent, dp); + } + if (dp->n == 0 && dp->task == AT3COORDS) + { + dp->anim.dir = 0; + } return; } -void rot_ent_pointer(object * ent, drawpars * dp, int dx, int dy, double speed){ +void +rot_ent_pointer (object *ent, drawpars *dp, int dx, int dy, double speed) +{ double mx[9]; - rot_around_perp(mx, (double)dx, (double)dy, speed); - mx3_lmultmx(mx, dp->rend.ac3rmx); - for(int i=0; in; i++){ - ent->m[i]->rotated = 0; - } + rot_around_perp (mx, (double)dx, (double)dy, speed); + mx3_lmultmx (mx, dp->rend.ac3rmx); + for (int i = 0; i < ent->n; i++) + { + ent->m[i]->rotated = 0; + } return; } -static void rot_ent(object * ent, drawpars * dp, int axis, double angle){ - if(dp->ui.modkey){ - angle *= STEP_MOD; - } - rotmx0_update(dp->rend.ac3rmx, angle, axis); - for(int i=0; in; i++){ - ent->m[i]->rotated = 0; - } +static void +rot_ent (object *ent, drawpars *dp, int axis, double angle) +{ + if (dp->ui.modkey) + { + angle *= STEP_MOD; + } + rotmx0_update (dp->rend.ac3rmx, angle, axis); + for (int i = 0; i < ent->n; i++) + { + ent->m[i]->rotated = 0; + } return; } -void kp_rotx_l(object * ent, drawpars * dp){ - rot_ent(ent, dp, 0, +STEP_ROT); - exp_redraw(ent, dp); +void +kp_rotx_l (object *ent, drawpars *dp) +{ + rot_ent (ent, dp, 0, +STEP_ROT); + exp_redraw (ent, dp); return; } -void kp_rotx_r(object * ent, drawpars * dp){ - rot_ent(ent, dp, 0, -STEP_ROT); - exp_redraw(ent, dp); +void +kp_rotx_r (object *ent, drawpars *dp) +{ + rot_ent (ent, dp, 0, -STEP_ROT); + exp_redraw (ent, dp); return; } -void kp_roty_l(object * ent, drawpars * dp){ - rot_ent(ent, dp, 1, +STEP_ROT); - exp_redraw(ent, dp); +void +kp_roty_l (object *ent, drawpars *dp) +{ + rot_ent (ent, dp, 1, +STEP_ROT); + exp_redraw (ent, dp); return; } -void kp_roty_r(object * ent, drawpars * dp){ - rot_ent(ent, dp, 1, -STEP_ROT); - exp_redraw(ent, dp); +void +kp_roty_r (object *ent, drawpars *dp) +{ + rot_ent (ent, dp, 1, -STEP_ROT); + exp_redraw (ent, dp); return; } -void kp_rotz_l(object * ent, drawpars * dp){ - rot_ent(ent, dp, 2, +STEP_ROT); - exp_redraw(ent, dp); +void +kp_rotz_l (object *ent, drawpars *dp) +{ + rot_ent (ent, dp, 2, +STEP_ROT); + exp_redraw (ent, dp); return; } -void kp_rotz_r(object * ent, drawpars * dp){ - rot_ent(ent, dp, 2, -STEP_ROT); - exp_redraw(ent, dp); +void +kp_rotz_r (object *ent, drawpars *dp) +{ + rot_ent (ent, dp, 2, -STEP_ROT); + exp_redraw (ent, dp); return; } -static void move_pbc(atcoord * m, const drawpars * dp, const double dr[3]){ - for(int j=0; jn; j++){ - r3add(m->r0+j*3, dr); - } - mol2cell(m); +static void +move_pbc (atcoord *m, const drawpars *dp, const double dr[3]) +{ + for (int j = 0; j < m->n; j++) + { + r3add (m->r0 + j * 3, dr); + } + mol2cell (m); m->rotated = 0; - if(dp->rend.bonds>0){ - m->bonds.flag = 0; - m->bonds.rl *= RL_MOVE_PBC_SCALE; - } + if (dp->rend.bonds > 0) + { + m->bonds.flag = 0; + m->bonds.rl *= RL_MOVE_PBC_SCALE; + } return; } -static void move_ent(object * ent, drawpars * dp, int dir, double step){ - atcoord * m = ent->m[dp->n]; +static void +move_ent (object *ent, drawpars *dp, int dir, double step) +{ + atcoord *m = ent->m[dp->n]; - if(dp->ui.modkey){ - step *= STEP_MOD; - } + if (dp->ui.modkey) + { + step *= STEP_MOD; + } - if((dp->task==VIBRO) || (m->cell.boundary != CELL)){ - dp->rend.xy0[dir] += step; - return; - } + if ((dp->task == VIBRO) || (m->cell.boundary != CELL)) + { + dp->rend.xy0[dir] += step; + return; + } double dr[3], v[3] = {}; - v[dir] = step; // translation in the view basis - r3mxt(dr, v, dp->rend.ac3rmx); // translation in the mol basis. - // not true if the initial "rotation" from CLI is not unitary, but ignore this - - if(dp->geom.boundary==CELL){ - // all have the same cell -> move together, otherwise move separately - for(int i=0; in; i++){ - move_pbc(ent->m[i], dp, dr); + v[dir] = step; // translation in the view basis + r3mxt (dr, v, dp->rend.ac3rmx); // translation in the mol basis. + // not true if the initial "rotation" from + // CLI is not unitary, but ignore this + + if (dp->geom.boundary == CELL) + { + // all have the same cell -> move together, otherwise move separately + for (int i = 0; i < ent->n; i++) + { + move_pbc (ent->m[i], dp, dr); + } + } + else + { + move_pbc (m, dp, dr); } - } - else{ - move_pbc(m, dp, dr); - } return; } -void kp_move_l(object * ent, drawpars * dp){ - move_ent(ent, dp, 0, -STEP_MOVE); - exp_redraw(ent, dp); +void +kp_move_l (object *ent, drawpars *dp) +{ + move_ent (ent, dp, 0, -STEP_MOVE); + exp_redraw (ent, dp); return; } -void kp_move_r(object * ent, drawpars * dp){ - move_ent(ent, dp, 0, +STEP_MOVE); - exp_redraw(ent, dp); +void +kp_move_r (object *ent, drawpars *dp) +{ + move_ent (ent, dp, 0, +STEP_MOVE); + exp_redraw (ent, dp); return; } -void kp_move_u(object * ent, drawpars * dp){ - move_ent(ent, dp, 1, +STEP_MOVE); - exp_redraw(ent, dp); +void +kp_move_u (object *ent, drawpars *dp) +{ + move_ent (ent, dp, 1, +STEP_MOVE); + exp_redraw (ent, dp); return; } -void kp_move_d(object * ent, drawpars * dp){ - move_ent(ent, dp, 1, -STEP_MOVE); - exp_redraw(ent, dp); +void +kp_move_d (object *ent, drawpars *dp) +{ + move_ent (ent, dp, 1, -STEP_MOVE); + exp_redraw (ent, dp); return; } -void kp_exit(object * ent, drawpars * dp){ - run_commands(NULL, dp->ui.on_exit, dp, ent); - obj_free(ent); - close_x(); - CLOSE0(dp->read.f); +void +kp_exit (object *ent, drawpars *dp) +{ + run_commands (NULL, dp->ui.on_exit, dp, ent); + obj_free (ent); + close_x (); + CLOSE0 (dp->read.f); dp->ui.closed = READY_TO_EXIT; } -void kp_fw_toggle(object * ent __attribute__ ((unused)), drawpars * dp){ +void +kp_fw_toggle (object *ent __attribute__ ((unused)), drawpars *dp) +{ dp->anim.dir = (dp->anim.dir == 1) ? 0 : 1; return; } -void kp_bw_toggle(object * ent __attribute__ ((unused)), drawpars * dp){ - if (dp->task == AT3COORDS){ - dp->anim.dir = (dp->anim.dir == -1) ? 0 : -1; - } +void +kp_bw_toggle (object *ent __attribute__ ((unused)), drawpars *dp) +{ + if (dp->task == AT3COORDS) + { + dp->anim.dir = (dp->anim.dir == -1) ? 0 : -1; + } return; } -void kp_l_toggle(object * ent, drawpars * dp){ - if(dp->rend.bonds>0){ - dp->rend.bonds = dp->rend.bonds==SHOW_BONDS ? SHOW_LENGTHS : SHOW_BONDS; - exp_redraw(ent, dp); - } +void +kp_l_toggle (object *ent, drawpars *dp) +{ + if (dp->rend.bonds > 0) + { + dp->rend.bonds + = dp->rend.bonds == SHOW_BONDS ? SHOW_LENGTHS : SHOW_BONDS; + exp_redraw (ent, dp); + } return; } -void kp_b_toggle(object * ent, drawpars * dp){ - if(dp->rend.bonds!=DISABLE_BONDS){ - dp->rend.bonds = dp->rend.bonds==NO_BONDS ? SHOW_BONDS : NO_BONDS; - exp_redraw(ent, dp); - } +void +kp_b_toggle (object *ent, drawpars *dp) +{ + if (dp->rend.bonds != DISABLE_BONDS) + { + dp->rend.bonds = dp->rend.bonds == NO_BONDS ? SHOW_BONDS : NO_BONDS; + exp_redraw (ent, dp); + } return; } -void kp_n_toggle(object * ent, drawpars * dp){ - dp->rend.num = (dp->rend.num == SHOW_NUMBERS) ? NO_ATOM_NUMBERS : SHOW_NUMBERS; - exp_redraw(ent, dp); +void +kp_n_toggle (object *ent, drawpars *dp) +{ + dp->rend.num + = (dp->rend.num == SHOW_NUMBERS) ? NO_ATOM_NUMBERS : SHOW_NUMBERS; + exp_redraw (ent, dp); return; } -void kp_t_toggle(object * ent, drawpars * dp){ - dp->rend.num = (dp->rend.num == SHOW_TYPES) ? NO_ATOM_NUMBERS : SHOW_TYPES; - exp_redraw(ent, dp); +void +kp_t_toggle (object *ent, drawpars *dp) +{ + dp->rend.num = (dp->rend.num == SHOW_TYPES) ? NO_ATOM_NUMBERS : SHOW_TYPES; + exp_redraw (ent, dp); return; } -void kp_goto_last(object * ent, drawpars * dp){ - if (dp->n < dp->N-1){ - dp->n=dp->N-1; - exp_redraw(ent, dp); - } +void +kp_goto_last (object *ent, drawpars *dp) +{ + if (dp->n < dp->N - 1) + { + dp->n = dp->N - 1; + exp_redraw (ent, dp); + } return; } -void kp_goto_1st(object * ent, drawpars * dp){ - if (dp->n > 0){ - dp->n = 0; - exp_redraw(ent, dp); - } +void +kp_goto_1st (object *ent, drawpars *dp) +{ + if (dp->n > 0) + { + dp->n = 0; + exp_redraw (ent, dp); + } return; } -void time_gone(object * ent, drawpars * dp){ - if(dp->task == VIBRO){ - if(dp->anim.t >= TMAX){ - dp->anim.t = dp->anim.t-TMAX; +void +time_gone (object *ent, drawpars *dp) +{ + if (dp->task == VIBRO) + { + if (dp->anim.t >= TMAX) + { + dp->anim.t = dp->anim.t - TMAX; + } + exp_redraw (ent, dp); } - exp_redraw(ent, dp); - } return; } -static void savevib(const drawpars * dp, int c){ +static void +savevib (const drawpars *dp, int c) +{ char s[STRLEN]; - int l = (int)(log10( dp->N + 0.5 )) + 1; - snprintf(s, sizeof(s), "%s_%0*d_%02d.xpm", dp->read.fname, l, dp->n+1, c); - if(save_pic(s)){ - fprintf(stderr, "%s\n", s); - } - else{ - PRINT_ERR("cannot save '%s'\n", s); - } + int l = (int)(log10 (dp->N + 0.5)) + 1; + snprintf (s, sizeof (s), "%s_%0*d_%02d.xpm", dp->read.fname, l, dp->n + 1, + c); + if (save_pic (s)) + { + fprintf (stderr, "%s\n", s); + } + else + { + PRINT_ERR ("cannot save '%s'\n", s); + } return; } -void kp_save_pic(object * ent, drawpars * dp){ +void +kp_save_pic (object *ent, drawpars *dp) +{ char s[STRLEN]; - int l = (int)(log10(dp->N+0.5))+1; - const atcoord * m = ent->m[dp->n]; - if(m->cell.boundary==CELL){ - static int i = 0; - snprintf(s, sizeof(s), "%s_%0*d.%02d.xpm", m->fname, l, dp->n+1, i++); - } - else{ - snprintf(s, sizeof(s), "%s_%0*d.xpm", m->fname, l, dp->n+1); - } - exp_redraw(ent, dp); - if(save_pic(s)){ - fprintf(stderr, "%s\n", s); - } - else{ - PRINT_ERR("cannot save '%s'\n", s); - } - return; -} - -void kp_film(object * ent, drawpars * dp){ - if(dp->task != VIBRO){ - kp_save_pic (ent, dp); - while(dp->nN-1){ - kp_frame_inc(ent, dp); - kp_save_pic (ent, dp); - } - } - else{ - int c = 0; - dp->anim.t = 0; - do{ - exp_redraw(ent, dp); - savevib(dp, c); - dp->anim.t++; - time_gone(ent, dp); - } while(++cm[MOL_IDX(dp)]; - if(!m->sym[0]){ - pg(m, dp->anal.symtol); - exp_redraw(ent, dp); - } - return; -} - -void kp_jump(object * ent, drawpars * dp){ - if(dp->ui.input==NO_INPUT){ - dp->ui.input = INPUT_JUMP; - exp_redraw(ent, dp); - } + int l = (int)(log10 (dp->N + 0.5)) + 1; + const atcoord *m = ent->m[dp->n]; + if (m->cell.boundary == CELL) + { + static int i = 0; + snprintf (s, sizeof (s), "%s_%0*d.%02d.xpm", m->fname, l, dp->n + 1, + i++); + } + else + { + snprintf (s, sizeof (s), "%s_%0*d.xpm", m->fname, l, dp->n + 1); + } + exp_redraw (ent, dp); + if (save_pic (s)) + { + fprintf (stderr, "%s\n", s); + } + else + { + PRINT_ERR ("cannot save '%s'\n", s); + } + return; +} + +void +kp_film (object *ent, drawpars *dp) +{ + if (dp->task != VIBRO) + { + kp_save_pic (ent, dp); + while (dp->n < dp->N - 1) + { + kp_frame_inc (ent, dp); + kp_save_pic (ent, dp); + } + } + else + { + int c = 0; + dp->anim.t = 0; + do + { + exp_redraw (ent, dp); + savevib (dp, c); + dp->anim.t++; + time_gone (ent, dp); + } + while (++c < TMAX); + } + return; +} + +void +kp_pg (object *ent, drawpars *dp) +{ + atcoord *m = ent->m[MOL_IDX (dp)]; + if (!m->sym[0]) + { + pg (m, dp->anal.symtol); + exp_redraw (ent, dp); + } + return; +} + +void +kp_jump (object *ent, drawpars *dp) +{ + if (dp->ui.input == NO_INPUT) + { + dp->ui.input = INPUT_JUMP; + exp_redraw (ent, dp); + } return; } diff --git a/src/v/evr.h b/src/v/evr.h index a9d726a..440912e 100644 --- a/src/v/evr.h +++ b/src/v/evr.h @@ -1,69 +1,75 @@ #include "3d.h" #define TMAX 20 -#define VIBR_AMP 0.1 -#define STEP_ROT (M_PI/90.0) -#define STEP_MOVE 0.2 -#define STEP_ZOOM 1.1 -#define STEP_R 1.1 -#define STEP_MOD 0.03125 +#define VIBR_AMP 0.1 +#define STEP_ROT (M_PI / 90.0) +#define STEP_MOVE 0.2 +#define STEP_ZOOM 1.1 +#define STEP_R 1.1 +#define STEP_MOD 0.03125 #define RL_MOVE_PBC_SCALE 0.9 #define MOL_IDX(DP) (DP->task == AT3COORDS ? DP->n : 0) -static inline void fill_bonds(atcoord * m, const drawpars * dp){ - if(dp->rend.bonds>0){ - bonds_fill(dp->bond, m); - } +static inline void +fill_bonds (atcoord *m, const drawpars *dp) +{ + if (dp->rend.bonds > 0) + { + bonds_fill (dp->bond, m); + } return; } -static inline void rotate_mol(atcoord * m, const drawpars * dp){ - if(!m->rotated){ - rot3d(m->n, m->r, m->r0, dp->rend.ac3rmx); - m->rotated = 1; - } +static inline void +rotate_mol (atcoord *m, const drawpars *dp) +{ + if (!m->rotated) + { + rot3d (m->n, m->r, m->r0, dp->rend.ac3rmx); + m->rotated = 1; + } return; } -void kp_readmore (object * ent, drawpars * dp); -void kp_readagain(object * ent, drawpars * dp); -void kp_print (object * ent, drawpars * dp); -void kp_print_xyz(object * ent, drawpars * dp); -void kp_print2fig(object * ent, drawpars * dp); -void kp_printrot (object * ent, drawpars * dp); -void kp_rl_inc (object * ent, drawpars * dp); -void kp_rl_dec (object * ent, drawpars * dp); -void kp_r_inc (object * ent, drawpars * dp); -void kp_r_dec (object * ent, drawpars * dp); -void kp_zoom_out (object * ent, drawpars * dp); -void kp_zoom_in (object * ent, drawpars * dp); -void kp_lat_dec (object * ent, drawpars * dp); -void kp_lat_inc (object * ent, drawpars * dp); -void kp_frame_inc(object * ent, drawpars * dp); -void kp_frame_dec(object * ent, drawpars * dp); -void kp_rotz_l (object * ent, drawpars * dp); -void kp_rotz_r (object * ent, drawpars * dp); -void kp_roty_l (object * ent, drawpars * dp); -void kp_roty_r (object * ent, drawpars * dp); -void kp_rotx_l (object * ent, drawpars * dp); -void kp_rotx_r (object * ent, drawpars * dp); -void kp_move_l (object * ent, drawpars * dp); -void kp_move_r (object * ent, drawpars * dp); -void kp_move_u (object * ent, drawpars * dp); -void kp_move_d (object * ent, drawpars * dp); -void kp_exit (object * ent, drawpars * dp); -void kp_l_toggle (object * ent, drawpars * dp); -void kp_b_toggle (object * ent, drawpars * dp); -void kp_t_toggle (object * ent, drawpars * dp); -void kp_n_toggle (object * ent, drawpars * dp); -void kp_fw_toggle(object * ent, drawpars * dp); -void kp_bw_toggle(object * ent, drawpars * dp); -void kp_goto_last(object * ent, drawpars * dp); -void kp_goto_1st (object * ent, drawpars * dp); -void time_gone (object * ent, drawpars * dp); -void kp_save_pic (object * ent, drawpars * dp); -void kp_film (object * ent, drawpars * dp); -void kp_pg (object * ent, drawpars * dp); -void kp_jump (object * ent, drawpars * dp); -void rot_ent_pointer(object * ent, drawpars * dp, int dx, int dy, double speed); +void kp_readmore (object *ent, drawpars *dp); +void kp_readagain (object *ent, drawpars *dp); +void kp_print (object *ent, drawpars *dp); +void kp_print_xyz (object *ent, drawpars *dp); +void kp_print2fig (object *ent, drawpars *dp); +void kp_printrot (object *ent, drawpars *dp); +void kp_rl_inc (object *ent, drawpars *dp); +void kp_rl_dec (object *ent, drawpars *dp); +void kp_r_inc (object *ent, drawpars *dp); +void kp_r_dec (object *ent, drawpars *dp); +void kp_zoom_out (object *ent, drawpars *dp); +void kp_zoom_in (object *ent, drawpars *dp); +void kp_lat_dec (object *ent, drawpars *dp); +void kp_lat_inc (object *ent, drawpars *dp); +void kp_frame_inc (object *ent, drawpars *dp); +void kp_frame_dec (object *ent, drawpars *dp); +void kp_rotz_l (object *ent, drawpars *dp); +void kp_rotz_r (object *ent, drawpars *dp); +void kp_roty_l (object *ent, drawpars *dp); +void kp_roty_r (object *ent, drawpars *dp); +void kp_rotx_l (object *ent, drawpars *dp); +void kp_rotx_r (object *ent, drawpars *dp); +void kp_move_l (object *ent, drawpars *dp); +void kp_move_r (object *ent, drawpars *dp); +void kp_move_u (object *ent, drawpars *dp); +void kp_move_d (object *ent, drawpars *dp); +void kp_exit (object *ent, drawpars *dp); +void kp_l_toggle (object *ent, drawpars *dp); +void kp_b_toggle (object *ent, drawpars *dp); +void kp_t_toggle (object *ent, drawpars *dp); +void kp_n_toggle (object *ent, drawpars *dp); +void kp_fw_toggle (object *ent, drawpars *dp); +void kp_bw_toggle (object *ent, drawpars *dp); +void kp_goto_last (object *ent, drawpars *dp); +void kp_goto_1st (object *ent, drawpars *dp); +void time_gone (object *ent, drawpars *dp); +void kp_save_pic (object *ent, drawpars *dp); +void kp_film (object *ent, drawpars *dp); +void kp_pg (object *ent, drawpars *dp); +void kp_jump (object *ent, drawpars *dp); +void rot_ent_pointer (object *ent, drawpars *dp, int dx, int dy, double speed); diff --git a/src/v/get_atpar.c b/src/v/get_atpar.c index f731bcc..ab5383d 100644 --- a/src/v/get_atpar.c +++ b/src/v/get_atpar.c @@ -1,72 +1,74 @@ -#include #include "v.h" +#include -#define NATOMS 118 -#define NRADII 92 +#define NATOMS 118 +#define NRADII 92 #define NAMELEN 3 -static const double ra[NRADII+1] = { - 1.0, - 0.455, 0.260, 1.885, 1.365, 1.105, - 0.910, 0.845, 0.780, 0.650, 0.520, - 2.340, 1.950, 1.625, 1.430, 1.300, - 1.300, 1.300, 1.170, 2.860, 2.340, - 2.080, 1.820, 1.755, 1.820, 1.820, - 1.820, 1.755, 1.755, 1.755, 1.755, - 1.690, 1.625, 1.495, 1.495, 1.495, - 1.300, 3.055, 2.600, 2.340, 2.015, - 1.885, 1.885, 1.755, 1.690, 1.755, - 1.820, 2.080, 2.015, 2.015, 1.885, - 1.885, 1.820, 1.820, 1.690, 3.055, - 2.574, 2.197, 2.145, 2.145, 2.132, - 2.145, 2.158, 2.405, 2.093, 2.067, - 2.067, 2.054, 2.041, 2.028, 2.210, - 2.028, 1.872, 1.742, 1.690, 1.664, - 1.638, 1.638, 1.677, 1.742, 1.872, - 2.015, 2.002, 1.976, 1.989, 1.989, - 1.950, 3.510, 2.899, 2.431, 2.314, - 2.093, 1.820 -}; +static const double ra[NRADII + 1] + = { 1.0, 0.455, 0.260, 1.885, 1.365, 1.105, 0.910, 0.845, 0.780, 0.650, + 0.520, 2.340, 1.950, 1.625, 1.430, 1.300, 1.300, 1.300, 1.170, 2.860, + 2.340, 2.080, 1.820, 1.755, 1.820, 1.820, 1.820, 1.755, 1.755, 1.755, + 1.755, 1.690, 1.625, 1.495, 1.495, 1.495, 1.300, 3.055, 2.600, 2.340, + 2.015, 1.885, 1.885, 1.755, 1.690, 1.755, 1.820, 2.080, 2.015, 2.015, + 1.885, 1.885, 1.820, 1.820, 1.690, 3.055, 2.574, 2.197, 2.145, 2.145, + 2.132, 2.145, 2.158, 2.405, 2.093, 2.067, 2.067, 2.054, 2.041, 2.028, + 2.210, 2.028, 1.872, 1.742, 1.690, 1.664, 1.638, 1.638, 1.677, 1.742, + 1.872, 2.015, 2.002, 1.976, 1.989, 1.989, 1.950, 3.510, 2.899, 2.431, + 2.314, 2.093, 1.820 }; -static const char aname[NATOMS+1][NAMELEN]={ - #include "elements.h" +static const char aname[NATOMS + 1][NAMELEN] = { +#include "elements.h" }; -double get_radius(int q){ - q = abs(q); - return ra[ q<=NRADII ? q : ( q<=NATOMS? NRADII : 0) ]; +double +get_radius (int q) +{ + q = abs (q); + return ra[q <= NRADII ? q : (q <= NATOMS ? NRADII : 0)]; } -double get_maxradius(int n, const int * q){ +double +get_maxradius (int n, const int *q) +{ double r = 0.0; - for(int i=0; iui.gui!=GUI_DISABLED){ - int gui = dp->ui.gui; - dp->ui.gui = GUI_ENABLED; - switch(c){ - case('f'): - kp_film(ent, dp); break; - case('m'): - kp_save_pic(ent, dp); break; +static void +run_with_gui (char c, drawpars *dp, object *ent) +{ + if (dp->ui.gui != GUI_DISABLED) + { + int gui = dp->ui.gui; + dp->ui.gui = GUI_ENABLED; + switch (c) + { + case ('f'): + kp_film (ent, dp); + break; + case ('m'): + kp_save_pic (ent, dp); + break; + } + dp->ui.gui = gui; + } + else + { + PRINT_WARN ("Ignoring command `%c` in the headless mode\n", c); } - dp->ui.gui = gui; - } - else{ - PRINT_WARN("Ignoring command `%c` in the headless mode\n", c); \ - } return; } -static void run_command(char c, drawpars * dp, object * ent){ - switch(c){ - case('>'): - kp_fw_toggle(ent, dp); break; - case('d'): - kp_move_r(ent, dp); break; - case('a'): - kp_move_l(ent, dp); break; - case('w'): - kp_move_u(ent, dp); break; - case('s'): - kp_move_d(ent, dp); break; - case('1'): - kp_rl_dec(ent, dp); break; - case('2'): - kp_rl_inc(ent, dp); break; - case('3'): - kp_r_dec(ent, dp); break; - case('4'): - kp_r_inc(ent, dp); break; - case('l'): - kp_l_toggle(ent, dp); break; - case('b'): - kp_b_toggle(ent, dp); break; - case('t'): - kp_t_toggle(ent, dp); break; - case('n'): - kp_n_toggle(ent, dp); break; - case('+'): - kp_zoom_in(ent, dp); break; - case('-'): - kp_zoom_out(ent, dp); break; +static void +run_command (char c, drawpars *dp, object *ent) +{ + switch (c) + { + case ('>'): + kp_fw_toggle (ent, dp); + break; + case ('d'): + kp_move_r (ent, dp); + break; + case ('a'): + kp_move_l (ent, dp); + break; + case ('w'): + kp_move_u (ent, dp); + break; + case ('s'): + kp_move_d (ent, dp); + break; + case ('1'): + kp_rl_dec (ent, dp); + break; + case ('2'): + kp_rl_inc (ent, dp); + break; + case ('3'): + kp_r_dec (ent, dp); + break; + case ('4'): + kp_r_inc (ent, dp); + break; + case ('l'): + kp_l_toggle (ent, dp); + break; + case ('b'): + kp_b_toggle (ent, dp); + break; + case ('t'): + kp_t_toggle (ent, dp); + break; + case ('n'): + kp_n_toggle (ent, dp); + break; + case ('+'): + kp_zoom_in (ent, dp); + break; + case ('-'): + kp_zoom_out (ent, dp); + break; - case('f'): - case('m'): - run_with_gui(c, dp, ent); break; + case ('f'): + case ('m'): + run_with_gui (c, dp, ent); + break; - case('q'): - dp->ui.closed = MUST_CLEANUP; break; + case ('q'): + dp->ui.closed = MUST_CLEANUP; + break; - case('p'): - kp_print2fig(ent, dp); break; - case('z'): - kp_print_xyz(ent, dp); break; - case('x'): - kp_print(ent, dp); break; - case('u'): - kp_printrot(ent, dp); break; - case('.'): - kp_pg(ent, dp); - PRINTOUT(stdout, "%s\n", ent->m[dp->n]->sym); - break; - case(' '): - case('\n'): + case ('p'): + kp_print2fig (ent, dp); + break; + case ('z'): + kp_print_xyz (ent, dp); + break; + case ('x'): + kp_print (ent, dp); + break; + case ('u'): + kp_printrot (ent, dp); + break; + case ('.'): + kp_pg (ent, dp); + PRINTOUT (stdout, "%s\n", ent->m[dp->n]->sym); + break; + case (' '): + case ('\n'): break; default: - PRINT_WARN("Unknown command `%c`\n", c); - } + PRINT_WARN ("Unknown command `%c`\n", c); + } return; } -void run_commands(FILE * f, char * command, drawpars * dp, object * ent){ - const char * com = command; +void +run_commands (FILE *f, char *command, drawpars *dp, object *ent) +{ + const char *com = command; int c; - while(1){ - if(command && command[0]){ - c = *(com++); - } - else if(f){ - c = getc(f); - } - else{ - c = 0; - } - if((!c) || (c == EOF)){ - break; + while (1) + { + if (command && command[0]) + { + c = *(com++); + } + else if (f) + { + c = getc (f); + } + else + { + c = 0; + } + if ((!c) || (c == EOF)) + { + break; + } + run_command (c, dp, ent); } - run_command(c, dp, ent); - } return; } -int headless(drawpars * dp, object * ent){ - fill_bonds(ent->m[dp->n], dp); - rotate_mol(ent->m[dp->n], dp); - run_commands(stdin, dp->ui.com, dp, ent); - obj_free(ent); - CLOSE0(dp->read.f); +int +headless (drawpars *dp, object *ent) +{ + fill_bonds (ent->m[dp->n], dp); + rotate_mol (ent->m[dp->n], dp); + run_commands (stdin, dp->ui.com, dp, ent); + obj_free (ent); + CLOSE0 (dp->read.f); return 0; } diff --git a/src/v/load.c b/src/v/load.c index 8f7806e..f55a64a 100644 --- a/src/v/load.c +++ b/src/v/load.c @@ -1,227 +1,277 @@ -#include #include "v.h" #include "vec3.h" #include "vecn.h" +#include #define N_MIN 256 -static inline void fill_nf(object * acs, int n0){ - for(int j=n0; jn; j++){ - acs->m[j]->nf[0] = j-n0; - acs->m[j]->nf[1] = acs->n-n0; - } +static inline void +fill_nf (object *acs, int n0) +{ + for (int j = n0; j < acs->n; j++) + { + acs->m[j]->nf[0] = j - n0; + acs->m[j]->nf[1] = acs->n - n0; + } return; } -void acs_readmore(readpars read, int b, geompars geom, object * acs){ +void +acs_readmore (readpars read, int b, geompars geom, object *acs) +{ // needed to reset nf int n0 = acs->n; - // if continue reading from a previously opened file, find the first molecule from it - if(ftell(read.f) && acs->n){ - for(int i=1; i<=acs->n; i++){ - int n1 = acs->n-i; - if(acs->m[n1]->nf[0]==0){ - n0 = n1; - break; - } - } - } - - atcoord * m; + // if continue reading from a previously opened file, find the first molecule + // from it + if (ftell (read.f) && acs->n) + { + for (int i = 1; i <= acs->n; i++) + { + int n1 = acs->n - i; + if (acs->m[n1]->nf[0] == 0) + { + n0 = n1; + break; + } + } + } + + atcoord *m; format_t format = UNKNOWN_FORMAT; - while((m = ac3_read(read, b, geom, &format))!=NULL){ - if(acs->n==acs->Nmem){ - int N = acs->Nmem ? acs->Nmem*2 : N_MIN; - atcoord ** ms = realloc(acs->m, N*sizeof(atcoord *)); - if(!ms){ - obj_free(acs); - free(m); - PRINT_ERR("cannot reallocate memory\n"); - abort(); - } - acs->m = ms; - acs->Nmem = N; - } - acs->m[acs->n++] = m; - } - fill_nf(acs, n0); + while ((m = ac3_read (read, b, geom, &format)) != NULL) + { + if (acs->n == acs->Nmem) + { + int N = acs->Nmem ? acs->Nmem * 2 : N_MIN; + atcoord **ms = realloc (acs->m, N * sizeof (atcoord *)); + if (!ms) + { + obj_free (acs); + free (m); + PRINT_ERR ("cannot reallocate memory\n"); + abort (); + } + acs->m = ms; + acs->Nmem = N; + } + acs->m[acs->n++] = m; + } + fill_nf (acs, n0); return; } -static object * mode_read_try(FILE * f, object * ent, drawpars * dp){ - - long pos = ftell(f); - rewind(f); - atcoord * m = ent->m[ent->n-1]; - vibr_t * vib = mode_read(f, m->n); - - if(!vib){ - fseek(f, pos, SEEK_SET); - return NULL; - } - else{ - for(int i=0; in-1; i++){ - free(ent->m[i]); - } - ent->Nmem = ent->n = 1; - ent->m = realloc(ent->m, sizeof(atcoord *)); - ent->m[0] = m; - ent->vib = vib; - dp->rend.scale = ac3_scale(m); - dp->N = vib->n; - return ent; - } -} +static object * +mode_read_try (FILE *f, object *ent, drawpars *dp) +{ + + long pos = ftell (f); + rewind (f); + atcoord *m = ent->m[ent->n - 1]; + vibr_t *vib = mode_read (f, m->n); -static FILE * acs_read_newfile(const char * fname, object * acs, const drawpars * dp){ - FILE * f; - if(!strcmp(fname, "-")){ - f = stdin; - } - else{ - f = fopen(fname, "r"); - if(!f){ + if (!vib) + { + fseek (f, pos, SEEK_SET); return NULL; } - } - acs_readmore((readpars){f, fname}, dp->rend.bonds, dp->geom, acs); + else + { + for (int i = 0; i < ent->n - 1; i++) + { + free (ent->m[i]); + } + ent->Nmem = ent->n = 1; + ent->m = realloc (ent->m, sizeof (atcoord *)); + ent->m[0] = m; + ent->vib = vib; + dp->rend.scale = ac3_scale (m); + dp->N = vib->n; + return ent; + } +} + +static FILE * +acs_read_newfile (const char *fname, object *acs, const drawpars *dp) +{ + FILE *f; + if (!strcmp (fname, "-")) + { + f = stdin; + } + else + { + f = fopen (fname, "r"); + if (!f) + { + return NULL; + } + } + acs_readmore ((readpars){ f, fname }, dp->rend.bonds, dp->geom, acs); return f; } -static object * ent_read(char * fname, drawpars * dp){ +static object * +ent_read (char *fname, drawpars *dp) +{ - object * acs = malloc(sizeof(object)); - if(!acs) GOTOHELL; + object *acs = malloc (sizeof (object)); + if (!acs) + GOTOHELL; acs->Nmem = 0; acs->n = 0; acs->m = NULL; acs->vib = NULL; - FILE * f = acs_read_newfile(fname, acs, dp); - if(!f || !acs->n){ - free(acs); - return NULL; - } + FILE *f = acs_read_newfile (fname, acs, dp); + if (!f || !acs->n) + { + free (acs); + return NULL; + } dp->read.fname = fname; - if(dp->task==UNKNOWN || dp->task==VIBRO){ - object * vib = mode_read_try(f, acs, dp); - if(vib){ - fclose(f); - dp->task = VIBRO; - return vib; + if (dp->task == UNKNOWN || dp->task == VIBRO) + { + object *vib = mode_read_try (f, acs, dp); + if (vib) + { + fclose (f); + dp->task = VIBRO; + return vib; + } + else + { + if (dp->task == VIBRO) + { + PRINT_WARN ("the file '%s' does not contain vibrations\n", + fname); + } + } } - else{ - if(dp->task==VIBRO){ - PRINT_WARN("the file '%s' does not contain vibrations\n", fname); - } - } - } dp->task = AT3COORDS; dp->read.f = f; return acs; } -object * read_files(allpars * ap){ - drawpars * dp = &ap->dp; - initpars * ip = &ap->ip; +object * +read_files (allpars *ap) +{ + drawpars *dp = &ap->dp; + initpars *ip = &ap->ip; int fn = ip->input_files_n; - char ** flist = ip->input_files; - object * ent = NULL; - int i=0; + char **flist = ip->input_files; + object *ent = NULL; + int i = 0; // read the first available file - while(itask == AT3COORDS)){ - object * acs = ent; - int n0 = acs->n; - for(i++; in){ - PRINT_WARN("cannot find molecules in file '%s'\n", flist[i]); - } - else{ - fclose(dp->read.f); - dp->read.f = f; - dp->read.fname = flist[i]; - n0 = acs->n; - } - } - dp->rend.scale = acs_scale(acs); - dp->N = acs->n; - intcoord_check(INT_MAX, dp->anal.intcoord); - } - else{ - dp->anal.intcoord[0] = 0; - for(i++; itask == AT3COORDS)) + { + object *acs = ent; + int n0 = acs->n; + for (i++; i < fn; i++) + { + FILE *f = acs_read_newfile (flist[i], acs, dp); + if (!f) + { + PRINT_WARN ("cannot read file '%s'\n", flist[i]); + } + else if (n0 == acs->n) + { + PRINT_WARN ("cannot find molecules in file '%s'\n", flist[i]); + } + else + { + fclose (dp->read.f); + dp->read.f = f; + dp->read.fname = flist[i]; + n0 = acs->n; + } + } + dp->rend.scale = acs_scale (acs); + dp->N = acs->n; + intcoord_check (INT_MAX, dp->anal.intcoord); + } + else + { + dp->anal.intcoord[0] = 0; + for (i++; i < fn; i++) + { + PRINT_WARN ("ignoring file '%s'\n", flist[i]); + } + } return ent; } -object * acs_from_var(int n, mol * m, vibr_t vib, allpars * ap){ - drawpars * dp = &ap->dp; - const initpars * ip = &ap->ip; - - for(int i=0; iinput_files_n; i++){ - PRINT_WARN("ignoring file '%s'\n", ip->input_files[i]); - } - if(dp->task==UNKNOWN){ - dp->task = vib.n ? VIBRO : AT3COORDS; - } - else if(!vib.n && dp->task==VIBRO){ - PRINT_WARN("the input does not contain vibrations\n"); - dp->task = AT3COORDS; - } - - object * ent = malloc(sizeof(object)); - - if(dp->task == AT3COORDS){ - ent->Nmem = ent->n = n; - ent->m = malloc(ent->Nmem*sizeof(atcoord *)); - ent->vib = NULL; - - for(int i=0; im[i] = atcoord_fill(m+i, dp->rend.bonds, dp->geom, NULL); - } - - dp->rend.scale = acs_scale(ent); - dp->N = ent->n; - - int natmax = 0; - for(int i=0; ianal.intcoord); - } - else{ - ent->Nmem = ent->n = 1; - ent->m = malloc(ent->Nmem*sizeof(atcoord *)); - ent->m[0] = atcoord_fill(m+n-1, dp->rend.bonds, dp->geom, NULL); - int nat = ent->m[0]->n; - ent->vib = make_vibr_t(vib.n, nat); - veccp(vib.n*nat*3, ent->vib->disp, vib.disp); - veccp(vib.n, ent->vib->freq, vib.freq); - veccp(vib.n, ent->vib->ints, vib.ints); - veccp(vib.n, ent->vib->mass, vib.mass); - dp->rend.scale = ac3_scale(ent->m[0]); - dp->N = ent->vib->n; - dp->anal.intcoord[0] = 0; - } - fill_nf(ent, 0); +object * +acs_from_var (int n, mol *m, vibr_t vib, allpars *ap) +{ + drawpars *dp = &ap->dp; + const initpars *ip = &ap->ip; + + for (int i = 0; i < ip->input_files_n; i++) + { + PRINT_WARN ("ignoring file '%s'\n", ip->input_files[i]); + } + if (dp->task == UNKNOWN) + { + dp->task = vib.n ? VIBRO : AT3COORDS; + } + else if (!vib.n && dp->task == VIBRO) + { + PRINT_WARN ("the input does not contain vibrations\n"); + dp->task = AT3COORDS; + } + + object *ent = malloc (sizeof (object)); + + if (dp->task == AT3COORDS) + { + ent->Nmem = ent->n = n; + ent->m = malloc (ent->Nmem * sizeof (atcoord *)); + ent->vib = NULL; + + for (int i = 0; i < n; i++) + { + ent->m[i] = atcoord_fill (m + i, dp->rend.bonds, dp->geom, NULL); + } + + dp->rend.scale = acs_scale (ent); + dp->N = ent->n; + + int natmax = 0; + for (int i = 0; i < n; i++) + { + natmax = MAX (natmax, m[i].n); + } + intcoord_check (natmax, dp->anal.intcoord); + } + else + { + ent->Nmem = ent->n = 1; + ent->m = malloc (ent->Nmem * sizeof (atcoord *)); + ent->m[0] = atcoord_fill (m + n - 1, dp->rend.bonds, dp->geom, NULL); + int nat = ent->m[0]->n; + ent->vib = make_vibr_t (vib.n, nat); + veccp (vib.n * nat * 3, ent->vib->disp, vib.disp); + veccp (vib.n, ent->vib->freq, vib.freq); + veccp (vib.n, ent->vib->ints, vib.ints); + veccp (vib.n, ent->vib->mass, vib.mass); + dp->rend.scale = ac3_scale (ent->m[0]); + dp->N = ent->vib->n; + dp->anal.intcoord[0] = 0; + } + fill_nf (ent, 0); dp->read.fname = ent->m[0]->fname; return ent; diff --git a/src/v/loop.c b/src/v/loop.c index 9c887f8..c506c5c 100644 --- a/src/v/loop.c +++ b/src/v/loop.c @@ -1,190 +1,237 @@ +#include "evr.h" #include "v.h" #include "x.h" -#include "evr.h" #define VIBRO_SUBSTEPS 4 extern draw_world_t world; -typedef struct { +typedef struct +{ int click; int x0; int y0; } mouse_state_t; -static void process_mouse(const XMotionEvent * event, object * ent, drawpars * dp, mouse_state_t * mouse){ - if(mouse->click){ - int x = event->x; - int y = event->y; - rot_ent_pointer(ent, dp, x-mouse->x0, y-mouse->y0, POINTER_SPEED/world.size); - exp_redraw(ent, dp); - mouse->x0 = x; - mouse->y0 = y; - } +static void +process_mouse (const XMotionEvent *event, object *ent, drawpars *dp, + mouse_state_t *mouse) +{ + if (mouse->click) + { + int x = event->x; + int y = event->y; + rot_ent_pointer (ent, dp, x - mouse->x0, y - mouse->y0, + POINTER_SPEED / world.size); + exp_redraw (ent, dp); + mouse->x0 = x; + mouse->y0 = y; + } return; } -static void process_input(const XKeyEvent * event, drawpars * dp){ - int stop_input = process_x_input(dp->ui.input_text, event->keycode); - if(stop_input){ - if(stop_input==1){ - switch(dp->ui.input){ - case(INPUT_JUMP): - { - int frame = atoi(dp->ui.input_text); - frame = MAX(1, MIN(frame, dp->N)); - dp->n = frame-1; - }; break; - case NO_INPUT: - default: - break; - } +static void +process_input (const XKeyEvent *event, drawpars *dp) +{ + int stop_input = process_x_input (dp->ui.input_text, event->keycode); + if (stop_input) + { + if (stop_input == 1) + { + switch (dp->ui.input) + { + case (INPUT_JUMP): + { + int frame = atoi (dp->ui.input_text); + frame = MAX (1, MIN (frame, dp->N)); + dp->n = frame - 1; + }; + break; + case NO_INPUT: + default: + break; + } + } + memset (dp->ui.input_text, 0, STRLEN); + dp->ui.input = NO_INPUT; } - memset(dp->ui.input_text, 0, STRLEN); - dp->ui.input = NO_INPUT; - } return; } -static void run_animation(object * ent, drawpars * dp, int * tr){ - if(dp->task == AT3COORDS){ - dp->anim.dir > 0 ? kp_frame_inc(ent, dp) : kp_frame_dec(ent, dp); - usleep(dp->anim.dt); - } - else{ - /* We draw 5 times for each dp->anim.t, - * because dt is too small to look good - * and 5*dt is too big to behave well (keyboard control). - * Also we cannot draw only when *tr==4, - * because we need an XEvent to reiterate the main loop. - * Alternatively, we can send an event manually. - */ - if(++*tr == VIBRO_SUBSTEPS){ - *tr = 0; - dp->anim.t++; +static void +run_animation (object *ent, drawpars *dp, int *tr) +{ + if (dp->task == AT3COORDS) + { + dp->anim.dir > 0 ? kp_frame_inc (ent, dp) : kp_frame_dec (ent, dp); + usleep (dp->anim.dt); + } + else + { + /* We draw 5 times for each dp->anim.t, + * because dt is too small to look good + * and 5*dt is too big to behave well (keyboard control). + * Also we cannot draw only when *tr==4, + * because we need an XEvent to reiterate the main loop. + * Alternatively, we can send an event manually. + */ + if (++*tr == VIBRO_SUBSTEPS) + { + *tr = 0; + dp->anim.t++; + } + usleep (dp->anim.dt); + time_gone (ent, dp); } - usleep(dp->anim.dt); - time_gone(ent, dp); - } return; } -static void configure_window(const XConfigureEvent * xconfigure, object * ent, drawpars * dp){ +static void +configure_window (const XConfigureEvent *xconfigure, object *ent, drawpars *dp) +{ world.W = xconfigure->width; world.H = xconfigure->height; - world.size = MIN(world.H, world.W); + world.size = MIN (world.H, world.W); dp->rend.xy0[0] = dp->rend.xy0[1] = 0.0; - exp_redraw(ent, dp); + exp_redraw (ent, dp); return; } -void wait_for_configure(object * ent, drawpars * dp){ +void +wait_for_configure (object *ent, drawpars *dp) +{ XEvent event_rec; - XEvent * event = &event_rec; - do{ - XNextEvent(world.dis, event); + XEvent *event = &event_rec; + do + { + XNextEvent (world.dis, event); #if 0 printf("%d\n", event_rec.type); #endif - if(event->type == ConfigureNotify){ - configure_window(&event->xconfigure, ent, dp); - break; + if (event->type == ConfigureNotify) + { + configure_window (&event->xconfigure, ent, dp); + break; + } } - } while(1); + while (1); return; } -void main_loop(object * ent, drawpars * dp, ptf kp[NKP]){ +void +main_loop (object *ent, drawpars *dp, ptf kp[NKP]) +{ - exp_redraw(ent, dp); + exp_redraw (ent, dp); // To handle window closing. Thanks to https://stackoverflow.com/a/1186544 - Atom wm_delete_window = XInternAtom(world.dis, "WM_DELETE_WINDOW", False); - XSetWMProtocols(world.dis, world.win, &wm_delete_window, 1); + Atom wm_delete_window = XInternAtom (world.dis, "WM_DELETE_WINDOW", False); + XSetWMProtocols (world.dis, world.win, &wm_delete_window, 1); - mouse_state_t mouse = {.click=0, .x0=0, .y0=0}; + mouse_state_t mouse = { .click = 0, .x0 = 0, .y0 = 0 }; int tr = 0; - while(1) { - XEvent event_rec; - XEvent * event = NULL; - do{ - XNextEvent(world.dis, &event_rec); + while (1) + { + XEvent event_rec; + XEvent *event = NULL; + do + { + XNextEvent (world.dis, &event_rec); #if 0 printf("%d\n", event_rec.type); #endif - if(event_rec.type != NoExpose || !event){ - event=&event_rec; - } - if(event->type == ButtonPress || event->type == ButtonRelease){ - break; - } - } while(XEventsQueued(world.dis, QueuedAlready)); - - if (event->type == ClientMessage) { - if ((Atom)event->xclient.data.l[0] == wm_delete_window) { - kp_exit(ent, dp); - } - } + if (event_rec.type != NoExpose || !event) + { + event = &event_rec; + } + if (event->type == ButtonPress || event->type == ButtonRelease) + { + break; + } + } + while (XEventsQueued (world.dis, QueuedAlready)); + + if (event->type == ClientMessage) + { + if ((Atom)event->xclient.data.l[0] == wm_delete_window) + { + kp_exit (ent, dp); + } + } - else if(event->type == Expose && event->xexpose.count == 0) { - exp_redraw(ent, dp); - } + else if (event->type == Expose && event->xexpose.count == 0) + { + exp_redraw (ent, dp); + } - else if(event->type == ConfigureNotify){ - configure_window(&event->xconfigure, ent, dp); - } + else if (event->type == ConfigureNotify) + { + configure_window (&event->xconfigure, ent, dp); + } - else if(event->type == KeyPress) { - if(dp->ui.input==NO_INPUT){ - if(kp[event->xkey.keycode]){ - dp->ui.modkey = event->xkey.state & (ShiftMask | ControlMask); - kp[event->xkey.keycode](ent, dp); - } - } - else{ - process_input(&(event->xkey), dp); - exp_redraw(ent, dp); - } - } + else if (event->type == KeyPress) + { + if (dp->ui.input == NO_INPUT) + { + if (kp[event->xkey.keycode]) + { + dp->ui.modkey + = event->xkey.state & (ShiftMask | ControlMask); + kp[event->xkey.keycode](ent, dp); + } + } + else + { + process_input (&(event->xkey), dp); + exp_redraw (ent, dp); + } + } - else if(event->type == ButtonPress && - (event->xbutton.button==Button1 || - event->xbutton.button==Button2 || - event->xbutton.button==Button3)){ - mouse.click = 1; - mouse.x0 = event->xbutton.x; - mouse.y0 = event->xbutton.y; - } + else if (event->type == ButtonPress + && (event->xbutton.button == Button1 + || event->xbutton.button == Button2 + || event->xbutton.button == Button3)) + { + mouse.click = 1; + mouse.x0 = event->xbutton.x; + mouse.y0 = event->xbutton.y; + } - else if(event->type == ButtonRelease && - (event->xbutton.button==Button1 || - event->xbutton.button==Button2 || - event->xbutton.button==Button3)){ - mouse.click = 0; - } + else if (event->type == ButtonRelease + && (event->xbutton.button == Button1 + || event->xbutton.button == Button2 + || event->xbutton.button == Button3)) + { + mouse.click = 0; + } - else if(event->type == ButtonPress && event->xbutton.button==Button4){ - kp_zoom_in(ent, dp); - } + else if (event->type == ButtonPress && event->xbutton.button == Button4) + { + kp_zoom_in (ent, dp); + } - else if(event->type == ButtonPress && event->xbutton.button==Button5){ - kp_zoom_out(ent, dp); - } + else if (event->type == ButtonPress && event->xbutton.button == Button5) + { + kp_zoom_out (ent, dp); + } - else if(event->type == MotionNotify){ - process_mouse(&(event->xmotion), ent, dp, &mouse); - } + else if (event->type == MotionNotify) + { + process_mouse (&(event->xmotion), ent, dp, &mouse); + } - if(dp->ui.closed==MUST_CLEANUP){ - kp_exit(ent, dp); - } + if (dp->ui.closed == MUST_CLEANUP) + { + kp_exit (ent, dp); + } - if(dp->ui.closed==READY_TO_EXIT){ - return; - } + if (dp->ui.closed == READY_TO_EXIT) + { + return; + } - if(dp->anim.dir){ - run_animation(ent, dp, &tr); + if (dp->anim.dir) + { + run_animation (ent, dp, &tr); + } } - } } - diff --git a/src/v/man.c b/src/v/man.c index 18603ce..b9ba4f3 100644 --- a/src/v/man.c +++ b/src/v/man.c @@ -1,7 +1,9 @@ #include "v.h" -void printman(FILE * f, char * exename){ - PRINTOUT(f, "\ +void +printman (FILE *f, char *exename) +{ + PRINTOUT (f, "\ \n\ USAGE:\n\ \n\ @@ -73,7 +75,7 @@ void printman(FILE * f, char * exename){ \n\ q / esc quit \n\ \n\ -", exename, DEFAULT_TIMEOUT*MS_TO_S, DEFAULT_SYMTOL); +", + exename, DEFAULT_TIMEOUT * MS_TO_S, DEFAULT_SYMTOL); return; } - diff --git a/src/v/mode_read.c b/src/v/mode_read.c index 74bec35..ac46818 100644 --- a/src/v/mode_read.c +++ b/src/v/mode_read.c @@ -5,44 +5,56 @@ #define DISPL_LINES_SKIP 5 #define SUMMARY_LINES_SKIP 4 -vibr_t * make_vibr_t(int n_modes, int n_atoms){ - size_t freq_size = sizeof(double) * n_modes; +vibr_t * +make_vibr_t (int n_modes, int n_atoms) +{ + size_t freq_size = sizeof (double) * n_modes; size_t ints_size = freq_size; size_t mass_size = freq_size; - size_t disp_size = sizeof(double) * n_modes*n_atoms*3; - size_t size = sizeof(vibr_t) + freq_size + disp_size + ints_size + mass_size; - vibr_t * v = malloc(size); - if(!v) GOTOHELL; - v->n = n_modes; - v->freq = (double *) (v + 1); - v->disp = (double *) MEM_END(v,freq); - v->ints = (double *) MEM_END(v,disp); - v->mass = (double *) MEM_END(v,ints); + size_t disp_size = sizeof (double) * n_modes * n_atoms * 3; + size_t size + = sizeof (vibr_t) + freq_size + disp_size + ints_size + mass_size; + vibr_t *v = malloc (size); + if (!v) + GOTOHELL; + v->n = n_modes; + v->freq = (double *)(v + 1); + v->disp = (double *)MEM_END (v, freq); + v->ints = (double *)MEM_END (v, disp); + v->mass = (double *)MEM_END (v, ints); return v; } -static int readb(FILE * f, int i, int Nmax, int N, int na, vibr_t * vib){ +static int +readb (FILE *f, int i, int Nmax, int N, int na, vibr_t *vib) +{ double d; - char s[STRLEN]; - int t,k,j; + char s[STRLEN]; + int t, k, j; - for (j=0; jdisp[3*na*(i*Nmax+j)+k] = d; + for (k = 0; k < na * 3; k++) + { + if (fscanf (f, "%d%c%c", &t, s, s + 1) != 3) + { + return -1; + } + for (j = 0; j < N; j++) + { + if (fscanf (f, "%lf", &d) != 1) + { + return -1; + } + vib->disp[3 * na * (i * Nmax + j) + k] = d; + } } - } #if 0 for (j=0; jn; i++){ - fgets(s, sizeof(s), f); - for(int j=0; jfreq[i]); - if(strchr(ts, 'i')){ - vib->freq[i] *= -1; - } - } - else if(j==3){ - TS_TO_DOUBLE(vib->mass[i]); - } - else if(j==4){ - TS_TO_DOUBLE(vib->ints[i]); - } + for (int i = 0; i < vib->n; i++) + { + fgets (s, sizeof (s), f); + for (int j = 0; j < SUMMARY_COLUMNS; j++) + { + char *s_end; + char *ts = strtok (j ? NULL : s, "|"); + if (!ts) + { + return -1; + } +#define TS_TO_DOUBLE(X) \ + { \ + X = strtod (ts, &s_end); \ + if (s_end == ts) \ + { \ + return -1; \ + } \ + } + else if (j == 2) + { + TS_TO_DOUBLE (vib->freq[i]); + if (strchr (ts, 'i')) + { + vib->freq[i] *= -1; + } + } + else if (j == 3) + { + TS_TO_DOUBLE (vib->mass[i]); + } + else if (j == 4) + { + TS_TO_DOUBLE (vib->ints[i]); + } #undef TS_TO_DOUBLE + } } - } - for (int i=0; icell.boundary==CELL){ - double v[8*3]; - rot3d(8, v, m->cell.vertices, rend->ac3rmx); - draw_vertices(v, rend); - } - else if(m->cell.boundary==SHELL){ - draw_shell(m->cell.vertices, rend); - } +static void +draw_boundary (atcoord *m, rendpars *rend) +{ + if (m->cell.boundary == CELL) + { + double v[8 * 3]; + rot3d (8, v, m->cell.vertices, rend->ac3rmx); + draw_vertices (v, rend); + } + else if (m->cell.boundary == SHELL) + { + draw_shell (m->cell.vertices, rend); + } return; } -static void screen_text(object * ent, drawpars * dp){ +static void +screen_text (object *ent, drawpars *dp) +{ char text[STRLEN]; char text_fname[STRLEN]; char text_input[STRLEN]; char text_coord[STRLEN]; char text_point[32]; - const char * lines[MAX_LINES] = {}; + const char *lines[MAX_LINES] = {}; int lines_red[MAX_LINES] = {}; - const atcoord * m = ent->m[MOL_IDX(dp)]; + const atcoord *m = ent->m[MOL_IDX (dp)]; int il = 0; - if(dp->task==AT3COORDS){ - set_caption(m->fname); - snprintf(text, sizeof(text), "%*d / %d", 1+(int)(log10(dp->N)), dp->n+1, dp->N); - } - else{ - double fq = ent->vib->freq[dp->n]; - char i = fq > 0.0 ? ' ' : 'i'; - snprintf(text, sizeof(text), - "%*d / %d freq = %.1lf%c cm-1 int = %.1lf km/mole mass = %.1lf amu", - 1+(int)(log10(ent->vib->n)), dp->n+1, ent->vib->n, fabs(fq), i, ent->vib->ints[dp->n], ent->vib->mass[dp->n]); - } + if (dp->task == AT3COORDS) + { + set_caption (m->fname); + snprintf (text, sizeof (text), "%*d / %d", 1 + (int)(log10 (dp->N)), + dp->n + 1, dp->N); + } + else + { + double fq = ent->vib->freq[dp->n]; + char i = fq > 0.0 ? ' ' : 'i'; + snprintf (text, sizeof (text), + "%*d / %d freq = %.1lf%c cm-1 int = %.1lf km/mole mass " + "= %.1lf amu", + 1 + (int)(log10 (ent->vib->n)), dp->n + 1, ent->vib->n, + fabs (fq), i, ent->vib->ints[dp->n], ent->vib->mass[dp->n]); + } lines[il++] = text; - if(m->nf[1]==ent->n){ - lines[il++] = m->fname; - } - else{ - snprintf(text_fname, sizeof(text_fname), "%s (%*d / %d)", m->fname, 1+(int)(log10(m->nf[1])), m->nf[0]+1, m->nf[1]); - lines[il++] = text_fname; - } + if (m->nf[1] == ent->n) + { + lines[il++] = m->fname; + } + else + { + snprintf (text_fname, sizeof (text_fname), "%s (%*d / %d)", m->fname, + 1 + (int)(log10 (m->nf[1])), m->nf[0] + 1, m->nf[1]); + lines[il++] = text_fname; + } - if(dp->anal.intcoord[0]){ - double z = intcoord_calc(1, m->n, dp->anal.intcoord, m->r); - switch(dp->anal.intcoord[0]){ - case 1: - snprintf(text_coord, sizeof(text_coord), "bond %d-%d: %.3lf", dp->anal.intcoord[1], dp->anal.intcoord[2], z); - break; - case 2: - snprintf(text_coord, sizeof(text_coord), "angle %d-%d-%d: %.1lf", dp->anal.intcoord[1], dp->anal.intcoord[2], dp->anal.intcoord[3], z); - break; - case 3: - snprintf(text_coord, sizeof(text_coord), "dihedral %d-%d-%d-%d: % .1lf", dp->anal.intcoord[1], dp->anal.intcoord[2], dp->anal.intcoord[3], dp->anal.intcoord[4], z); - break; - default: - break; + if (dp->anal.intcoord[0]) + { + double z = intcoord_calc (1, m->n, dp->anal.intcoord, m->r); + switch (dp->anal.intcoord[0]) + { + case 1: + snprintf (text_coord, sizeof (text_coord), "bond %d-%d: %.3lf", + dp->anal.intcoord[1], dp->anal.intcoord[2], z); + break; + case 2: + snprintf (text_coord, sizeof (text_coord), "angle %d-%d-%d: %.1lf", + dp->anal.intcoord[1], dp->anal.intcoord[2], + dp->anal.intcoord[3], z); + break; + case 3: + snprintf (text_coord, sizeof (text_coord), + "dihedral %d-%d-%d-%d: % .1lf", dp->anal.intcoord[1], + dp->anal.intcoord[2], dp->anal.intcoord[3], + dp->anal.intcoord[4], z); + break; + default: + break; + } + lines[il++] = text_coord; } - lines[il++] = text_coord; - } - if(m->sym[0]){ - snprintf(text_point, sizeof(text_point), "%spoint group: %s", dp->task==AT3COORDS? "":"molecule ", m->sym); - lines[il++] = text_point; - } + if (m->sym[0]) + { + snprintf (text_point, sizeof (text_point), "%spoint group: %s", + dp->task == AT3COORDS ? "" : "molecule ", m->sym); + lines[il++] = text_point; + } - if(dp->ui.input==INPUT_JUMP){ - snprintf(text_input, sizeof(text_input), "JUMP TO >>> %s", dp->ui.input_text); - lines_red[il] = 1; - lines[il++] = text_input; - } + if (dp->ui.input == INPUT_JUMP) + { + snprintf (text_input, sizeof (text_input), "JUMP TO >>> %s", + dp->ui.input_text); + lines_red[il] = 1; + lines[il++] = text_input; + } - put_text(lines, lines_red); + put_text (lines, lines_red); return; } -void exp_redraw(object * ent, drawpars * dp){ - atcoord * m = ent->m[MOL_IDX(dp)]; - fill_bonds(m, dp); - if(dp->task==AT3COORDS){ - rotate_mol(m, dp); - if(m->cell.boundary==CELL){ - dp->rend.xy0[0] = 0.0; - dp->rend.xy0[1] = 0.0; +void +exp_redraw (object *ent, drawpars *dp) +{ + atcoord *m = ent->m[MOL_IDX (dp)]; + fill_bonds (m, dp); + if (dp->task == AT3COORDS) + { + rotate_mol (m, dp); + if (m->cell.boundary == CELL) + { + dp->rend.xy0[0] = 0.0; + dp->rend.xy0[1] = 0.0; + } + } + else if (dp->task == VIBRO) + { + const double *dr = ent->vib->disp + dp->n * m->n * 3; + vecsums (m->n * 3, m->r, m->r0, dr, + VIBR_AMP * sqrt (m->n) * sin (dp->anim.t * 2.0 * M_PI / TMAX)); + rot3d_inplace (m->n, m->r, dp->rend.ac3rmx); } - } - else if(dp->task==VIBRO){ - const double * dr = ent->vib->disp + dp->n * m->n*3; - vecsums(m->n*3, m->r, m->r0, dr, VIBR_AMP*sqrt(m->n)*sin(dp->anim.t * 2.0*M_PI/TMAX)); - rot3d_inplace(m->n, m->r, dp->rend.ac3rmx); - } - if(dp->ui.gui!=1){ - return; - } + if (dp->ui.gui != 1) + { + return; + } - clear_canv(); - screen_text(ent, dp); - ac3_draw(m, &dp->rend); - draw_boundary(m, &dp->rend); - fill_canv(); + clear_canv (); + screen_text (ent, dp); + ac3_draw (m, &dp->rend); + draw_boundary (m, &dp->rend); + fill_canv (); return; } diff --git a/src/v/scale.c b/src/v/scale.c index 4cf5860..9ccbbc5 100644 --- a/src/v/scale.c +++ b/src/v/scale.c @@ -1,39 +1,49 @@ #include "v.h" #include "vec3.h" -#define VIEWPORT_FILL 0.5 // molecule fills this fraction of the viewport +#define VIEWPORT_FILL 0.5 // molecule fills this fraction of the viewport -double ac3_scale(atcoord * ac){ +double +ac3_scale (atcoord *ac) +{ double center[3] = {}; - for(int k=0; kn; k++){ - r3add(center, ac->r+3*k); - } - r3scal(center, 1.0/ac->n); + for (int k = 0; k < ac->n; k++) + { + r3add (center, ac->r + 3 * k); + } + r3scal (center, 1.0 / ac->n); double d2max = 0.0; - for(int k=0; kn; k++){ - double rad = get_radius(ac->q[k]); - double d2 = r3d2(center, ac->r+3*k); - d2max = MAX(d2max, d2+rad*rad); - } - if(ac->cell.boundary==SHELL){ - for(int i=0; i<2; i++){ - d2max = MAX(d2max, 2*ac->cell.vertices[i]*ac->cell.vertices[i]); + for (int k = 0; k < ac->n; k++) + { + double rad = get_radius (ac->q[k]); + double d2 = r3d2 (center, ac->r + 3 * k); + d2max = MAX (d2max, d2 + rad * rad); + } + if (ac->cell.boundary == SHELL) + { + for (int i = 0; i < 2; i++) + { + d2max = MAX (d2max, 2 * ac->cell.vertices[i] * ac->cell.vertices[i]); + } } - } - else if(ac->cell.boundary==CELL){ - for(int k=0; k<8; k++){ - double d2 = r3d2(center, ac->cell.vertices+3*k); - d2max = MAX(d2max, d2); + else if (ac->cell.boundary == CELL) + { + for (int k = 0; k < 8; k++) + { + double d2 = r3d2 (center, ac->cell.vertices + 3 * k); + d2max = MAX (d2max, d2); + } } - } - return VIEWPORT_FILL / sqrt(d2max); + return VIEWPORT_FILL / sqrt (d2max); } -double acs_scale(object * acs){ - double d2max = ac3_scale(acs->m[0]); - for(int i=1; in; i++){ - d2max = MIN(ac3_scale(acs->m[i]), d2max); - } +double +acs_scale (object *acs) +{ + double d2max = ac3_scale (acs->m[0]); + for (int i = 1; i < acs->n; i++) + { + d2max = MIN (ac3_scale (acs->m[i]), d2max); + } return d2max; } - diff --git a/src/v/tools.c b/src/v/tools.c index ca4ee08..bf11be1 100644 --- a/src/v/tools.c +++ b/src/v/tools.c @@ -1,29 +1,37 @@ -#include "v.h" #include "sym.h" +#include "v.h" -void obj_free(object * ent){ - if(ent->vib){ - free(ent->vib); - } - for(int i=0; in; i++){ - free(ent->m[i]); - } - free(ent->m); - free(ent); +void +obj_free (object *ent) +{ + if (ent->vib) + { + free (ent->vib); + } + for (int i = 0; i < ent->n; i++) + { + free (ent->m[i]); + } + free (ent->m); + free (ent); return; } -void pg(atcoord * a, double symtol){ +void +pg (atcoord *a, double symtol) +{ int n = a->n; - mol m = {.n = n, .q = a->q, .r=malloc(sizeof(double)*n*3), .name=NULL}; - veccp (n*3, m.r, a->r0); - vecscal(n*3, m.r, AB); + mol m = { + .n = n, .q = a->q, .r = malloc (sizeof (double) * n * 3), .name = NULL + }; + veccp (n * 3, m.r, a->r0); + vecscal (n * 3, m.r, AB); - molsym * ms = pointgroup(&m, symtol*AB); - snprintf(a->sym, sizeof(styp), "%s", ms->s); + molsym *ms = pointgroup (&m, symtol * AB); + snprintf (a->sym, sizeof (styp), "%s", ms->s); - free(m.r); - free(ms); + free (m.r); + free (ms); return; } diff --git a/src/v/v.h b/src/v/v.h index 58d42c0..fdd4e98 100644 --- a/src/v/v.h +++ b/src/v/v.h @@ -1,8 +1,8 @@ #include "mol.h" -#define DEFAULT_TIMEOUT 20000 -#define DEFAULT_SYMTOL 1e-3 -#define NKP 256 +#define DEFAULT_TIMEOUT 20000 +#define DEFAULT_SYMTOL 1e-3 +#define NKP 256 #define BONDS_MAX 32 #define POINTER_SPEED 2.0 #define STRLEN 256 @@ -10,124 +10,130 @@ #include "pars.h" -typedef void (* ptf )(); +typedef void (*ptf) (); -typedef enum { +typedef enum +{ UNKNOWN_FORMAT, XYZ, IN, OUT, } format_t; -typedef struct { - int flag; // whether bonds are up-to-date. 0: no, 1: yes - double rl; // the last used bond length scale factor - int * a; // lists of bonded atoms - double * r; // distances to the bonded atoms +typedef struct +{ + int flag; // whether bonds are up-to-date. 0: no, 1: yes + double rl; // the last used bond length scale factor + int *a; // lists of bonded atoms + double *r; // distances to the bonded atoms } bondstr; -typedef struct { - int n; // number of atoms - int * q; // atom charges - double * r; // atom coordinates (rotated) - const char * fname; // file name +typedef struct +{ + int n; // number of atoms + int *q; // atom charges + double *r; // atom coordinates (rotated) + const char *fname; // file name - int rotated; // is `r` up-to-date - double * r0; // atom coordinates (original) + int rotated; // is `r` up-to-date + double *r0; // atom coordinates (original) - int nf[2]; // number of molecule in file, file size - styp sym; // point group + int nf[2]; // number of molecule in file, file size + styp sym; // point group bondstr bonds; cellpars cell; } atcoord; -typedef struct { - double * freq; // frequencies (cm-1) - double * ints; // intensities - double * disp; // displacements - double * mass; // masses - int n; // number of modes +typedef struct +{ + double *freq; // frequencies (cm-1) + double *ints; // intensities + double *disp; // displacements + double *mass; // masses + int n; // number of modes } vibr_t; -typedef struct { +typedef struct +{ int n, Nmem; - atcoord ** m; - vibr_t * vib; + atcoord **m; + vibr_t *vib; } object; - // load.c -object * acs_from_var(int n, mol * m, vibr_t vib, allpars * ap); -void acs_readmore (readpars read, int b, geompars geom, object * acs); -object * read_files(allpars * ap); +object *acs_from_var (int n, mol *m, vibr_t vib, allpars *ap); +void acs_readmore (readpars read, int b, geompars geom, object *acs); +object *read_files (allpars *ap); // scale.c -double ac3_scale(atcoord * ac); -double acs_scale(object * acs); +double ac3_scale (atcoord *ac); +double acs_scale (object *acs); // mode_read.c -vibr_t * make_vibr_t(int n_modes, int n_atoms); -vibr_t * mode_read(FILE * f, int na); +vibr_t *make_vibr_t (int n_modes, int n_atoms); +vibr_t *mode_read (FILE *f, int na); // ac3_read*.c -void mol2cell(atcoord * m); -int read_cart_atom(FILE * f, int n, mol * m); -atcoord * atcoord_fill(mol * m0, const render_bonds_t b, const geompars geom, const double cell[9]); -atcoord * ac3_read(readpars read, const render_bonds_t b, const geompars geom, format_t * format); -mol * ac3_read_in (FILE * f); -mol * ac3_read_out(FILE * f); -mol * ac3_read_xyz(FILE * f, int * cell_found, double * cell); +void mol2cell (atcoord *m); +int read_cart_atom (FILE *f, int n, mol *m); +atcoord *atcoord_fill (mol *m0, const render_bonds_t b, const geompars geom, + const double cell[9]); +atcoord *ac3_read (readpars read, const render_bonds_t b, const geompars geom, + format_t *format); +mol *ac3_read_in (FILE *f); +mol *ac3_read_out (FILE *f); +mol *ac3_read_xyz (FILE *f, int *cell_found, double *cell); // man.c -void printman(FILE * f, char * exename); +void printman (FILE *f, char *exename); // cli.c -allpars cli_parse(int argc, char ** argv); +allpars cli_parse (int argc, char **argv); // loop.c -void wait_for_configure(object * ent, drawpars * dp); -void main_loop(object * ent, drawpars * dp, ptf kp[NKP]); +void wait_for_configure (object *ent, drawpars *dp); +void main_loop (object *ent, drawpars *dp, ptf kp[NKP]); // redraw.c -void exp_redraw(object * ent, drawpars * dp); +void exp_redraw (object *ent, drawpars *dp); // ac3_draw.c -void ac3_draw (atcoord * ac, rendpars * rend); +void ac3_draw (atcoord *ac, rendpars *rend); // ac3_print.c -void ac3_print (atcoord * ac, rendpars * rend); -void ac3_print_xyz(atcoord * ac, rendpars * rend); -void ac3_print2fig(atcoord * ac, rendpars * rend); +void ac3_print (atcoord *ac, rendpars *rend); +void ac3_print_xyz (atcoord *ac, rendpars *rend); +void ac3_print2fig (atcoord *ac, rendpars *rend); // bonds.c -void bonds_fill(bondpars bond, atcoord * ac); +void bonds_fill (bondpars bond, atcoord *ac); // get_atpar.c -double get_radius(int q); -double get_maxradius(int n, const int * q); -const char * get_name(int q); -int get_element(const char * s); +double get_radius (int q); +double get_maxradius (int n, const int *q); +const char *get_name (int q); +int get_element (const char *s); // x.c -void close_x (void); -void init_x (const char * const capt, const colorscheme_t colorscheme); -void init_font (char * fontname); -void put_text (const char * const lines[MAX_LINES], const int red[MAX_LINES]); -void set_caption (const char * const capt); -void draw_vertices (const double v[8*3], rendpars * rend); -void draw_shell (const double r[2], rendpars * rend); -int save_pic (char * s); -void clear_canv(); -void fill_canv(); +void close_x (void); +void init_x (const char *const capt, const colorscheme_t colorscheme); +void init_font (char *fontname); +void put_text (const char *const lines[MAX_LINES], const int red[MAX_LINES]); +void set_caption (const char *const capt); +void draw_vertices (const double v[8 * 3], rendpars *rend); +void draw_shell (const double r[2], rendpars *rend); +int save_pic (char *s); +void clear_canv (); +void fill_canv (); // xinput.c -int process_x_input(char input_text[STRLEN], unsigned int keycode); +int process_x_input (char input_text[STRLEN], unsigned int keycode); // tools.c -void obj_free(object * ent); -void pg(atcoord * a, double symtol); +void obj_free (object *ent); +void pg (atcoord *a, double symtol); // headless.c -void run_commands(FILE * f, char * command, drawpars * dp, object * ent); -int headless(drawpars * dp, object * ent); +void run_commands (FILE *f, char *command, drawpars *dp, object *ent); +int headless (drawpars *dp, object *ent); // main.c -int main (int argc, char * argv[]); +int main (int argc, char *argv[]); // api.c -void PRINTOUT(FILE * f, char * format, ...); -object * READ_FILES(allpars * ap); -int SHOULD_PRINT_MAN(int argc); +void PRINTOUT (FILE *f, char *format, ...); +object *READ_FILES (allpars *ap); +int SHOULD_PRINT_MAN (int argc); diff --git a/src/v/x.c b/src/v/x.c index dabd717..0a59af9 100644 --- a/src/v/x.c +++ b/src/v/x.c @@ -1,40 +1,48 @@ -#include "v.h" #include "x.h" +#include "v.h" extern draw_world_t world; -void close_x(void) { - XFreeGC(world.dis, world.gc_red); - XFreeGC(world.dis, world.gc_black); - XFreeGC(world.dis, world.gc_white); - XFreeGC(world.dis, world.gc_dot[0]); - XFreeGC(world.dis, world.gc_dot[1]); - for(int i=0; iscreen_sizes[i]){ - font_size = font_sizes[i]; - break; + for (int i = 0; i < sizeof (screen_sizes) / sizeof (screen_sizes[0]); i++) + { + if (world.size > screen_sizes[i]) + { + font_size = font_sizes[i]; + break; + } } - } - snprintf(fontname, size, "monospace:pixelsize=%d", font_size); + snprintf (fontname, size, "monospace:pixelsize=%d", font_size); return; } -void init_font(char * fontname){ +void +init_font (char *fontname) +{ styp s; - if(!fontname){ - fontname = s; - autosize_font(fontname, sizeof(s)); - } - world.fontInfo = XftFontOpenName(world.dis, DefaultScreen(world.dis), fontname); - if(!world.fontInfo){ - PRINT_WARN("cannot load font '%s'\n", fontname); - world.fontInfo = XftFontOpenName(world.dis, DefaultScreen(world.dis), "monospace:pixelsize=24"); - } - - world.xft_draw = XftDrawCreate(world.dis, world.canv, DefaultVisual(world.dis, DefaultScreen(world.dis)), DefaultColormap(world.dis, DefaultScreen(world.dis))); - XRenderColor color = {0, 0, 0, 65535}; - XftColorAllocValue(world.dis, DefaultVisual(world.dis, DefaultScreen(world.dis)), DefaultColormap(world.dis, DefaultScreen(world.dis)), &color, &world.xft_color); + if (!fontname) + { + fontname = s; + autosize_font (fontname, sizeof (s)); + } + world.fontInfo + = XftFontOpenName (world.dis, DefaultScreen (world.dis), fontname); + if (!world.fontInfo) + { + PRINT_WARN ("cannot load font '%s'\n", fontname); + world.fontInfo = XftFontOpenName (world.dis, DefaultScreen (world.dis), + "monospace:pixelsize=24"); + } + + world.xft_draw + = XftDrawCreate (world.dis, world.canv, + DefaultVisual (world.dis, DefaultScreen (world.dis)), + DefaultColormap (world.dis, DefaultScreen (world.dis))); + XRenderColor color = { 0, 0, 0, 65535 }; + XftColorAllocValue (world.dis, + DefaultVisual (world.dis, DefaultScreen (world.dis)), + DefaultColormap (world.dis, DefaultScreen (world.dis)), + &color, &world.xft_color); XGlyphInfo extents; - XftTextExtentsUtf8(world.dis, world.fontInfo, (const FcChar8 *)".", 1, &extents); + XftTextExtentsUtf8 (world.dis, world.fontInfo, (const FcChar8 *)".", 1, + &extents); world.font_height = world.fontInfo->ascent + world.fontInfo->descent; return; } -void put_text(const char * const lines[MAX_LINES], const int red[MAX_LINES]){ +void +put_text (const char *const lines[MAX_LINES], const int red[MAX_LINES]) +{ int voffset = world.font_height + 5; int hoffset = 10; - for(int i=0; iascent; - XftDrawStringUtf8(world.xft_draw, &(world.xft_color), world.fontInfo, x, y, (const FcChar8 *)lines[i], strlen(lines[i])); + for (int i = 0; i < MAX_LINES; i++) + { + if (lines[i]) + { + int x = hoffset; + int y = voffset + world.fontInfo->ascent; + XftDrawStringUtf8 (world.xft_draw, &(world.xft_color), + world.fontInfo, x, y, (const FcChar8 *)lines[i], + strlen (lines[i])); + } + voffset += world.fontInfo->height; } - voffset += world.fontInfo->height; - } return; } -void set_caption(const char * const capt){ - XStoreName(world.dis, world.win, capt); +void +set_caption (const char *const capt) +{ + XStoreName (world.dis, world.win, capt); return; } -static void draw_edge(const double vi[3], const double vj[3], rendpars * rend){ - int iw = (vi[2]>0.0 || vj[2]>0.0) ? 0 : 1; - XDrawLine(world.dis, world.canv, world.gc_dot[iw], - SCREEN_X(vi[0]), SCREEN_Y(vi[1]), SCREEN_X(vj[0]), SCREEN_Y(vj[1])); +static void +draw_edge (const double vi[3], const double vj[3], rendpars *rend) +{ + int iw = (vi[2] > 0.0 || vj[2] > 0.0) ? 0 : 1; + XDrawLine (world.dis, world.canv, world.gc_dot[iw], SCREEN_X (vi[0]), + SCREEN_Y (vi[1]), SCREEN_X (vj[0]), SCREEN_Y (vj[1])); return; } -void draw_vertices(const double v[8*3], rendpars * rend){ -#define LINE(i,j) draw_edge(v+(i)*3, v+(j)*3, rend) - for(int i=0; i<8; i+=2){ - LINE(i,i+1); // || z-axis - } - for(int j=0; j<2; j++){ - for(int i=0; i<2; i++){ - LINE(i*4+j, i*4+2+j); // || y-axis - LINE(i*2+j, i*2+4+j); // || x-axis +void +draw_vertices (const double v[8 * 3], rendpars *rend) +{ +#define LINE(i, j) draw_edge (v + (i) * 3, v + (j) * 3, rend) + for (int i = 0; i < 8; i += 2) + { + LINE (i, i + 1); // || z-axis + } + for (int j = 0; j < 2; j++) + { + for (int i = 0; i < 2; i++) + { + LINE (i * 4 + j, i * 4 + 2 + j); // || y-axis + LINE (i * 2 + j, i * 2 + 4 + j); // || x-axis + } } - } #undef LINE return; } -void draw_shell(const double r[2], rendpars * rend){ +void +draw_shell (const double r[2], rendpars *rend) +{ double d = world.size * rend->scale; - for(int i=0; i<2; i++){ - XDrawArc(world.dis, world.canv, world.gc_dot[1-i], - SCREEN_X(-r[i]), SCREEN_Y(r[i]), - 2*r[i]*d, 2*r[i]*d, 0, 360*64); - } + for (int i = 0; i < 2; i++) + { + XDrawArc (world.dis, world.canv, world.gc_dot[1 - i], SCREEN_X (-r[i]), + SCREEN_Y (r[i]), 2 * r[i] * d, 2 * r[i] * d, 0, 360 * 64); + } return; } -int save_pic(char * s){ +int +save_pic (char *s) +{ XpmAttributes a = { .valuemask = XpmSize, - .width = world.W, - .height = world.H, + .width = world.W, + .height = world.H, }; - return XpmWriteFileFromPixmap(world.dis, s, world.px, 0, &a)==XpmSuccess; + return XpmWriteFileFromPixmap (world.dis, s, world.px, 0, &a) == XpmSuccess; } -void clear_canv(){ // TODO other canvases? - if(world.canv == world.px){ - XFillRectangle(world.dis, world.canv, world.gc_white, 0, 0, world.W, world.H);\ - } +void +clear_canv () +{ // TODO other canvases? + if (world.canv == world.px) + { + XFillRectangle (world.dis, world.canv, world.gc_white, 0, 0, world.W, + world.H); + } return; } -void fill_canv(){ - if(world.canv == world.px){ // TODO other canvases? - XCopyArea(world.dis, world.canv, world.win, world.gc_white, 0, 0, world.W, world.H, 0, 0); - } +void +fill_canv () +{ + if (world.canv == world.px) + { // TODO other canvases? + XCopyArea (world.dis, world.canv, world.win, world.gc_white, 0, 0, + world.W, world.H, 0, 0); + } return; } diff --git a/src/v/x.h b/src/v/x.h index 364b69f..4dc4a65 100644 --- a/src/v/x.h +++ b/src/v/x.h @@ -1,25 +1,28 @@ #include #include -#include #include -#include +#include #include +#include #define NCOLORS 110 #define LINE_WIDTH 2 -#define SCREEN_X(X) (world.W/2 + world.size * rend->scale*(rend->xy0[0] + (X))) -#define SCREEN_Y(Y) (world.H/2 - world.size * rend->scale*(rend->xy0[1] + (Y))) +#define SCREEN_X(X) \ + (world.W / 2 + world.size * rend->scale * (rend->xy0[0] + (X))) +#define SCREEN_Y(Y) \ + (world.H / 2 - world.size * rend->scale * (rend->xy0[1] + (Y))) -typedef struct { - Display * dis; - Window win; - GC gc_white, gc_black, gc_red, gc_dot[2], gcc[NCOLORS]; - Pixmap px; - Drawable canv; - XftFont * fontInfo; - XftDraw * xft_draw; - XftColor xft_color; - int font_height; - int W, H, size; +typedef struct +{ + Display *dis; + Window win; + GC gc_white, gc_black, gc_red, gc_dot[2], gcc[NCOLORS]; + Pixmap px; + Drawable canv; + XftFont *fontInfo; + XftDraw *xft_draw; + XftColor xft_color; + int font_height; + int W, H, size; } draw_world_t; diff --git a/src/v/xinput.c b/src/v/xinput.c index 4ac1994..c710356 100644 --- a/src/v/xinput.c +++ b/src/v/xinput.c @@ -3,30 +3,41 @@ extern draw_world_t world; -int process_x_input(char input_text[STRLEN], unsigned int keycode){ +int +process_x_input (char input_text[STRLEN], unsigned int keycode) +{ int keysyms_per_keycode_return; - KeySym * keysym = XGetKeyboardMapping(world.dis, keycode, 1, &keysyms_per_keycode_return); - int input_length = strlen(input_text); - if(!((keysym[0]>='0' && keysym[0]<='9')||(keysym[0]>='a' && keysym[0]<='z'))){ - if(keysym[0]==XK_Escape){ - XFree(keysym); - return -1; // only stop input & clean + KeySym *keysym = XGetKeyboardMapping (world.dis, keycode, 1, + &keysyms_per_keycode_return); + int input_length = strlen (input_text); + if (!((keysym[0] >= '0' && keysym[0] <= '9') + || (keysym[0] >= 'a' && keysym[0] <= 'z'))) + { + if (keysym[0] == XK_Escape) + { + XFree (keysym); + return -1; // only stop input & clean + } + else if (keysym[0] == XK_Return) + { + XFree (keysym); + return 1; // use the input + } + else if (keysym[0] == XK_BackSpace) + { + if (input_length > 0) + { + input_text[input_length - 1] = 0; + } + } } - else if(keysym[0]==XK_Return){ - XFree(keysym); - return 1; // use the input + else + { + if (input_length < STRLEN - 1) + { + input_text[input_length] = keysym[0]; + } } - else if(keysym[0]==XK_BackSpace){ - if(input_length>0){ - input_text[input_length-1] = 0; - } - } - } - else{ - if(input_length Date: Wed, 29 Apr 2026 19:25:19 +0330 Subject: [PATCH 03/10] Revert "set coding format to GNU style" This reverts commit 6d9e5b2934415487b4122144394cbdf5803d1511. revert breaking change. --- .clang-format | 321 ------------ makefile | 3 - src/api.c | 165 +++--- src/math/3d.h | 19 +- src/math/jacobi.c | 151 +++--- src/math/matrix.c | 43 +- src/math/matrix.h | 27 +- src/math/mx_inv.c | 112 ++--- src/math/rot3d.c | 97 ++-- src/math/vec3.h | 196 +++----- src/math/vecn.c | 56 +-- src/math/vecn.h | 14 +- src/math/zmat.c | 102 ++-- src/mol/common.h | 82 +-- src/mol/elements.h | 61 ++- src/mol/inertia.c | 150 +++--- src/mol/intcoord.c | 140 +++--- src/mol/masses.h | 63 ++- src/mol/mol.h | 37 +- src/mol/mytime.h | 11 +- src/mol/palette_cpk.h | 219 ++++---- src/mol/palette_v.h | 49 +- src/sym/pointgroup.c | 1120 ++++++++++++++++++----------------------- src/sym/sym.h | 30 +- src/v.c | 184 +++---- src/v/ac3_draw.c | 183 +++---- src/v/ac3_print.c | 186 +++---- src/v/ac3_read.c | 276 +++++----- src/v/ac3_read_in.c | 237 ++++----- src/v/ac3_read_out.c | 56 +-- src/v/ac3_read_xyz.c | 136 ++--- src/v/bonds.c | 339 ++++++------- src/v/cli.c | 389 ++++++-------- src/v/evr.c | 671 ++++++++++-------------- src/v/evr.h | 118 +++-- src/v/get_atpar.c | 102 ++-- src/v/headless.c | 220 ++++---- src/v/load.c | 404 +++++++-------- src/v/loop.c | 313 +++++------- src/v/man.c | 10 +- src/v/mode_read.c | 216 ++++---- src/v/pars.h | 158 +++--- src/v/redraw.c | 191 +++---- src/v/scale.c | 64 +-- src/v/tools.c | 44 +- src/v/v.h | 158 +++--- src/v/x.c | 293 +++++------ src/v/x.h | 33 +- src/v/xinput.c | 55 +- 49 files changed, 3410 insertions(+), 4894 deletions(-) delete mode 100644 .clang-format diff --git a/.clang-format b/.clang-format deleted file mode 100644 index e3f753c..0000000 --- a/.clang-format +++ /dev/null @@ -1,321 +0,0 @@ ---- -Language: Cpp -AlignAfterOpenBracket: true -AccessModifierOffset: -2 -AlignArrayOfStructures: None -AlignConsecutiveAssignments: - Enabled: false - AcrossEmptyLines: false - AcrossComments: false - AlignCompound: false - AlignFunctionDeclarations: false - AlignFunctionPointers: false - PadOperators: true -AlignConsecutiveBitFields: - Enabled: false - AcrossEmptyLines: false - AcrossComments: false - AlignCompound: false - AlignFunctionDeclarations: false - AlignFunctionPointers: false - PadOperators: false -AlignConsecutiveDeclarations: - Enabled: false - AcrossEmptyLines: false - AcrossComments: false - AlignCompound: false - AlignFunctionDeclarations: true - AlignFunctionPointers: false - PadOperators: false -AlignConsecutiveMacros: - Enabled: false - AcrossEmptyLines: false - AcrossComments: false - AlignCompound: false - AlignFunctionDeclarations: false - AlignFunctionPointers: false - PadOperators: false -AlignConsecutiveShortCaseStatements: - Enabled: false - AcrossEmptyLines: false - AcrossComments: false - AlignCaseArrows: false - AlignCaseColons: false -AlignConsecutiveTableGenBreakingDAGArgColons: - Enabled: false - AcrossEmptyLines: false - AcrossComments: false - AlignCompound: false - AlignFunctionDeclarations: false - AlignFunctionPointers: false - PadOperators: false -AlignConsecutiveTableGenCondOperatorColons: - Enabled: false - AcrossEmptyLines: false - AcrossComments: false - AlignCompound: false - AlignFunctionDeclarations: false - AlignFunctionPointers: false - PadOperators: false -AlignConsecutiveTableGenDefinitionColons: - Enabled: false - AcrossEmptyLines: false - AcrossComments: false - AlignCompound: false - AlignFunctionDeclarations: false - AlignFunctionPointers: false - PadOperators: false -AlignEscapedNewlines: Right -AlignOperands: Align -AlignTrailingComments: - AlignPPAndNotPP: true - Kind: Always - OverEmptyLines: 0 -AllowAllArgumentsOnNextLine: true -AllowAllParametersOfDeclarationOnNextLine: true -AllowBreakBeforeNoexceptSpecifier: Never -AllowBreakBeforeQtProperty: false -AllowShortBlocksOnASingleLine: Never -AllowShortCaseExpressionOnASingleLine: true -AllowShortCaseLabelsOnASingleLine: false -AllowShortCompoundRequirementOnASingleLine: true -AllowShortEnumsOnASingleLine: true -AllowShortFunctionsOnASingleLine: All -AllowShortIfStatementsOnASingleLine: Never -AllowShortLambdasOnASingleLine: All -AllowShortLoopsOnASingleLine: false -AllowShortNamespacesOnASingleLine: false -AlwaysBreakAfterDefinitionReturnType: All -AlwaysBreakBeforeMultilineStrings: false -AttributeMacros: - - __capability -BinPackArguments: true -BinPackLongBracedList: true -BinPackParameters: BinPack -BitFieldColonSpacing: Both -BracedInitializerIndentWidth: -1 -BraceWrapping: - AfterCaseLabel: true - AfterClass: true - AfterControlStatement: Always - AfterEnum: true - AfterExternBlock: true - AfterFunction: true - AfterNamespace: true - AfterObjCDeclaration: true - AfterStruct: true - AfterUnion: true - BeforeCatch: true - BeforeElse: true - BeforeLambdaBody: true - BeforeWhile: true - IndentBraces: true - SplitEmptyFunction: true - SplitEmptyRecord: true - SplitEmptyNamespace: true -BreakAdjacentStringLiterals: true -BreakAfterAttributes: Leave -BreakAfterJavaFieldAnnotations: false -BreakAfterOpenBracketBracedList: false -BreakAfterOpenBracketFunction: false -BreakAfterOpenBracketIf: false -BreakAfterOpenBracketLoop: false -BreakAfterOpenBracketSwitch: false -BreakAfterReturnType: AllDefinitions -BreakArrays: true -BreakBeforeBinaryOperators: All -BreakBeforeCloseBracketBracedList: false -BreakBeforeCloseBracketFunction: false -BreakBeforeCloseBracketIf: false -BreakBeforeCloseBracketLoop: false -BreakBeforeCloseBracketSwitch: false -BreakBeforeConceptDeclarations: Always -BreakBeforeBraces: GNU -BreakBeforeInlineASMColon: OnlyMultiline -BreakBeforeTemplateCloser: false -BreakBeforeTernaryOperators: true -BreakBinaryOperations: Never -BreakConstructorInitializers: BeforeColon -BreakFunctionDefinitionParameters: false -BreakInheritanceList: BeforeColon -BreakStringLiterals: true -BreakTemplateDeclarations: MultiLine -ColumnLimit: 79 -CommentPragmas: '^ IWYU pragma:' -CompactNamespaces: false -ConstructorInitializerIndentWidth: 4 -ContinuationIndentWidth: 4 -Cpp11BracedListStyle: Block -DerivePointerAlignment: false -DisableFormat: false -EmptyLineAfterAccessModifier: Never -EmptyLineBeforeAccessModifier: LogicalBlock -EnumTrailingComma: Leave -ExperimentalAutoDetectBinPacking: false -FixNamespaceComments: false -ForEachMacros: - - foreach - - Q_FOREACH - - BOOST_FOREACH -IfMacros: - - KJ_IF_MAYBE -IncludeBlocks: Preserve -IncludeCategories: - - Regex: '^"(llvm|llvm-c|clang|clang-c)/' - Priority: 2 - SortPriority: 0 - CaseSensitive: false - - Regex: '^(<|"(gtest|gmock|isl|json)/)' - Priority: 3 - SortPriority: 0 - CaseSensitive: false - - Regex: '.*' - Priority: 1 - SortPriority: 0 - CaseSensitive: false -IncludeIsMainRegex: '(Test)?$' -IncludeIsMainSourceRegex: '' -IndentAccessModifiers: false -IndentCaseBlocks: false -IndentCaseLabels: false -IndentExportBlock: true -IndentExternBlock: AfterExternBlock -IndentGotoLabels: true -IndentPPDirectives: None -IndentRequiresClause: true -IndentWidth: 2 -IndentWrappedFunctionNames: false -InsertBraces: false -InsertNewlineAtEOF: false -InsertTrailingCommas: None -IntegerLiteralSeparator: - Binary: 0 - BinaryMinDigitsInsert: 0 - BinaryMaxDigitsRemove: 0 - Decimal: 0 - DecimalMinDigitsInsert: 0 - DecimalMaxDigitsRemove: 0 - Hex: 0 - HexMinDigitsInsert: 0 - HexMaxDigitsRemove: 0 - BinaryMinDigits: 0 - DecimalMinDigits: 0 - HexMinDigits: 0 -JavaScriptQuotes: Leave -JavaScriptWrapImports: true -KeepEmptyLines: - AtEndOfFile: false - AtStartOfBlock: true - AtStartOfFile: true -KeepFormFeed: true -LambdaBodyIndentation: Signature -LineEnding: DeriveLF -MacroBlockBegin: '' -MacroBlockEnd: '' -MainIncludeChar: Quote -MaxEmptyLinesToKeep: 1 -NamespaceIndentation: None -NumericLiteralCase: - ExponentLetter: Leave - HexDigit: Leave - Prefix: Leave - Suffix: Leave -ObjCBinPackProtocolList: Auto -ObjCBlockIndentWidth: 2 -ObjCBreakBeforeNestedBlockParam: true -ObjCSpaceAfterProperty: false -ObjCSpaceBeforeProtocolList: true -OneLineFormatOffRegex: '' -PackConstructorInitializers: BinPack -PenaltyBreakAssignment: 2 -PenaltyBreakBeforeFirstCallParameter: 19 -PenaltyBreakBeforeMemberAccess: 150 -PenaltyBreakComment: 300 -PenaltyBreakFirstLessLess: 120 -PenaltyBreakOpenParenthesis: 0 -PenaltyBreakScopeResolution: 500 -PenaltyBreakString: 1000 -PenaltyBreakTemplateDeclaration: 10 -PenaltyExcessCharacter: 1000000 -PenaltyIndentedWhitespace: 0 -PenaltyReturnTypeOnItsOwnLine: 60 -PointerAlignment: Right -PPIndentWidth: -1 -QualifierAlignment: Leave -ReferenceAlignment: Pointer -ReflowComments: Always -RemoveBracesLLVM: false -RemoveEmptyLinesInUnwrappedLines: false -RemoveParentheses: Leave -RemoveSemicolon: false -RequiresClausePosition: OwnLine -RequiresExpressionIndentation: OuterScope -SeparateDefinitionBlocks: Leave -ShortNamespaceLines: 1 -SkipMacroDefinitionBody: false -SortIncludes: - Enabled: true - IgnoreCase: false - IgnoreExtension: false -SortJavaStaticImport: Before -SortUsingDeclarations: LexicographicNumeric -SpaceAfterCStyleCast: false -SpaceAfterLogicalNot: false -SpaceAfterOperatorKeyword: false -SpaceAfterTemplateKeyword: true -SpaceAroundPointerQualifiers: Default -SpaceBeforeAssignmentOperators: true -SpaceBeforeCaseColon: false -SpaceBeforeCpp11BracedList: false -SpaceBeforeCtorInitializerColon: true -SpaceBeforeInheritanceColon: true -SpaceBeforeJsonColon: false -SpaceBeforeParens: Always -SpaceBeforeParensOptions: - AfterControlStatements: false - AfterForeachMacros: false - AfterFunctionDefinitionName: false - AfterFunctionDeclarationName: false - AfterIfMacros: false - AfterNot: false - AfterOverloadedOperator: false - AfterPlacementOperator: true - AfterRequiresInClause: false - AfterRequiresInExpression: false - BeforeNonEmptyParentheses: false -SpaceBeforeRangeBasedForLoopColon: true -SpaceBeforeSquareBrackets: false -SpaceInEmptyBraces: Never -SpacesBeforeTrailingComments: 1 -SpacesInAngles: Never -SpacesInContainerLiterals: true -SpacesInLineCommentPrefix: - Minimum: 1 - Maximum: -1 -SpacesInParens: Never -SpacesInParensOptions: - ExceptDoubleParentheses: false - InCStyleCasts: false - InConditionalStatements: false - InEmptyParentheses: false - Other: false -SpacesInSquareBrackets: false -Standard: Latest -StatementAttributeLikeMacros: - - Q_EMIT -StatementMacros: - - Q_UNUSED - - QT_REQUIRE_VERSION -TableGenBreakInsideDAGArg: DontBreak -TabWidth: 8 -UseTab: Never -VerilogBreakBetweenInstancePorts: true -WhitespaceSensitiveMacros: - - BOOST_PP_STRINGIZE - - CF_SWIFT_NAME - - NS_SWIFT_NAME - - PP_STRINGIZE - - STRINGIZE -WrapNamespaceBodyWithEmptyLines: Leave -... - diff --git a/makefile b/makefile index 2f785cc..beea043 100644 --- a/makefile +++ b/makefile @@ -98,6 +98,3 @@ include $(allmmd) cppcheck: cleancheck -.github/cppcheck.bash 2> errors.xml cppcheck-htmlreport --file=errors.xml --report-dir=cppcheck_html - -format: - git ls-files '*.c' '*.h' | xargs clang-format -i -style=file diff --git a/src/api.c b/src/api.c index 07357f7..da1cfab 100644 --- a/src/api.c +++ b/src/api.c @@ -1,136 +1,111 @@ -#include "v.h" #include +#include "v.h" -#define PRINTBUFLEN (1024 * 128) +#define PRINTBUFLEN (1024*128) -struct -{ - char *out_str; - mol *inp_mols; +struct { + char * out_str; + mol * inp_mols; vibr_t inp_vib; int n_inp_mols; } globals; -char * -main_wrap_out (int argc, char *argv[], int *ret) -{ - globals.out_str = calloc (PRINTBUFLEN, 1); - if (!globals.out_str) - { - *ret = -1; - return NULL; - } - *ret = main (argc, argv); +char * main_wrap_out(int argc, char * argv[], int * ret) { + globals.out_str = calloc(PRINTBUFLEN, 1); + if(!globals.out_str){ + *ret = -1; + return NULL; + } + *ret = main(argc, argv); return globals.out_str; } // cppcheck-suppress staticFunction -int -main_wrap_in (int argc, char *argv[], int n_inp_mols, mol *inp_mols, - vibr_t inp_vib) -{ +int main_wrap_in(int argc, char * argv[], int n_inp_mols, mol * inp_mols, vibr_t inp_vib) { globals.inp_mols = inp_mols; globals.n_inp_mols = n_inp_mols; globals.inp_vib = inp_vib; - int ret = main (argc, argv); + int ret = main(argc, argv); globals.inp_mols = NULL; globals.n_inp_mols = 0; return ret; } -char * -main_wrap_in_out (int argc, char *argv[], int n_inp_mols, mol *inp_mols, - vibr_t inp_vib, int *ret) -{ - globals.out_str = calloc (PRINTBUFLEN, 1); - if (!globals.out_str) - { - *ret = -1; - return NULL; - } - *ret = main_wrap_in (argc, argv, n_inp_mols, inp_mols, inp_vib); +char * main_wrap_in_out(int argc, char * argv[], + int n_inp_mols, mol * inp_mols, + vibr_t inp_vib, + int * ret){ + globals.out_str = calloc(PRINTBUFLEN, 1); + if(!globals.out_str){ + *ret = -1; + return NULL; + } + *ret = main_wrap_in(argc, argv, n_inp_mols, inp_mols, inp_vib); return globals.out_str; } -void -free_out_str (void) -{ - FREE0 (globals.out_str); - PRINTOUT (NULL, NULL); +void free_out_str(void){ + FREE0(globals.out_str); + PRINTOUT(NULL, NULL); } -void -PRINTOUT (FILE *f, char *format, ...) -{ +void PRINTOUT(FILE * f, char * format, ...){ va_list args; static size_t n = 0; static size_t N = PRINTBUFLEN; // call to reset n and N - if (!format) - { - n = 0; - N = PRINTBUFLEN; - return; - } + if(!format){ + n = 0; + N = PRINTBUFLEN; + return; + } - if (!globals.out_str) - { - va_start (args, format); - vfprintf (f, format, args); - va_end (args); - } - else - { + if(!globals.out_str){ + va_start(args, format); + vfprintf(f, format, args); + va_end(args); + } + else{ - va_start (args, format); - size_t size = N - n; - size_t m = vsnprintf (globals.out_str + n, size, format, args); - va_end (args); + va_start(args, format); + size_t size = N-n; + size_t m = vsnprintf(globals.out_str+n, size, format, args); + va_end(args); - if (m >= size) - { - N = m < N ? N * 2 : N + 2 * m; - char *tmp = realloc (globals.out_str, N); - if (!tmp) - { - PRINT_ERR ("cannot reallocate output buffer\n"); - abort (); - } - globals.out_str = tmp; - va_start (args, format); - vsnprintf (globals.out_str + n, N - n, format, args); - va_end (args); - } - - n += m; + if(m >= size){ + N = m < N ? N * 2 : N + 2*m; + char * tmp = realloc(globals.out_str, N); + if(!tmp){ + PRINT_ERR("cannot reallocate output buffer\n"); + abort(); + } + globals.out_str = tmp; + va_start(args, format); + vsnprintf(globals.out_str+n, N-n, format, args); + va_end(args); } + + n += m; + } } -object * -READ_FILES (allpars *ap) -{ - object *ret; - if (!globals.inp_mols) - { - ret = read_files (ap); - } - else - { - ret = acs_from_var (globals.n_inp_mols, globals.inp_mols, - globals.inp_vib, ap); - } - FREE0 (ap->ip.input_files); +object * READ_FILES(allpars * ap){ + object * ret; + if(!globals.inp_mols){ + ret = read_files(ap); + } + else{ + ret = acs_from_var(globals.n_inp_mols, globals.inp_mols, globals.inp_vib, ap); + } + FREE0(ap->ip.input_files); return ret; } -int -SHOULD_PRINT_MAN (int argc) -{ - if ((argc == 1) && (!globals.inp_mols)) - { - return 1; - } +int SHOULD_PRINT_MAN(int argc){ + if((argc==1) && (!globals.inp_mols)){ + return 1; + } return 0; } diff --git a/src/math/3d.h b/src/math/3d.h index dd95236..4becc84 100644 --- a/src/math/3d.h +++ b/src/math/3d.h @@ -1,13 +1,14 @@ #include "matrix.h" -#define DEG2RAD (M_PI / 180.0) +#define DEG2RAD (M_PI/180.0) -void rotmx0_update (double mx[9], double phi, int axis); -void rot3d (int n, double *v, const double *r, const double m[9]); -void rot3d_inplace (int n, double *r, const double m[9]); -void rotmx (double rot[9], const double u[3], double phi); -void rot_around_perp (double rot[9], double dx, double dy, double factor); -void mx3_lmultmx (const double A[9], double B[9]); +void rotmx0_update(double mx[9], double phi, int axis); +void rot3d(int n, double * v, const double * r, const double m[9]); +void rot3d_inplace(int n, double * r, const double m[9]); +void rotmx(double rot[9], const double u[3], double phi); +void rot_around_perp(double rot[9], double dx, double dy, double factor); +void mx3_lmultmx(const double A[9], double B[9]); -int zmat2cart (int n, double r[3], const double a[3], const double b[3], - const double c[3], double R, double phi, double theta); +int zmat2cart(int n, double r[3], + const double a[3], const double b[3], const double c[3], + double R, double phi, double theta); diff --git a/src/math/jacobi.c b/src/math/jacobi.c index 18630b8..193c0a4 100644 --- a/src/math/jacobi.c +++ b/src/math/jacobi.c @@ -1,105 +1,94 @@ #include "matrix.h" #include "mytime.h" -#define SIGN(X) ((X >= 0.0 ? 1.0 : -1.0)) +#define SIGN(X) ((X>=0.0 ? 1.0 : -1.0)) -static void -givens (double *a, double *b, double *d, double sinphi, double cosphi, - unsigned int n, unsigned int i, unsigned int j) -{ +static void givens(double * a, double * b, double * d, + double sinphi, double cosphi, + unsigned int n, unsigned int i, unsigned int j){ unsigned int l; double temp, g, h; /* rt * a * r: */ g = d[i]; h = d[j]; - temp = 2.0 * cosphi * sinphi * a[mpos (i, j)]; - d[i] = cosphi * cosphi * g + sinphi * sinphi * h + temp; - d[j] = cosphi * cosphi * h + sinphi * sinphi * g - temp; - a[mpos (i, j)] = 0.0; - for (l = 0; l < i; l++) - { - g = a[mpos (l, i)]; - h = a[mpos (l, j)]; - a[mpos (l, i)] = (g * cosphi) + (h * sinphi); - a[mpos (l, j)] = -(g * sinphi) + (h * cosphi); - } - for (l = i + 1; l < j; l++) - { - h = a[mpos (l, j)]; - g = a[mpos (i, l)]; - a[mpos (l, j)] = -(g * sinphi) + (h * cosphi); - a[mpos (i, l)] = (g * cosphi) + (sinphi * h); - } - for (l = j + 1; l < n; l++) - { - g = a[mpos (i, l)]; - h = a[mpos (j, l)]; - a[mpos (i, l)] = (cosphi * g) + (sinphi * h); - a[mpos (j, l)] = -(sinphi * g) + (cosphi * h); - } + temp = 2.0*cosphi*sinphi*a[mpos(i,j)]; + d[i] = cosphi*cosphi*g + sinphi*sinphi*h + temp; + d[j] = cosphi*cosphi*h + sinphi*sinphi*g - temp; + a[mpos(i,j)] = 0.0; + for (l=0; l #include #include +#include +#include "vecn.h" -#define symsize(M) (((M) * (M) + (M)) / 2) +#define symsize(M) (((M)*(M)+(M))/2) #ifndef MPOS_IS #define MPOS_IS -static inline unsigned int -mpos (unsigned int i, unsigned int j) -{ - /* A[i+j*(j+1)/2], i <= j, 0 <= j < N */ - return (i) + (((j) * ((j) + 1)) >> 1); +static inline unsigned int mpos(unsigned int i, unsigned int j){ +/* A[i+j*(j+1)/2], i <= j, 0 <= j < N */ + return (i)+(((j)*((j)+1))>>1); } -#define MPOSIF(i, j) ((i) <= (j) ? mpos ((i), (j)) : mpos ((j), (i))) +#define MPOSIF(i,j) ((i)<=(j)? mpos((i),(j)):mpos((j),(i))) #endif -void mx_id (unsigned int n, double *a); -void mx_multmx (unsigned int m, unsigned int n, unsigned int q, double *p, - const double *a, const double *b); -int mx_inv (unsigned int n, unsigned int r, double *b, double *a, double eps); -void jacobi (double *a, double *b, double *d, unsigned int n, double eps, - unsigned int rot, FILE *f); +void mx_id (unsigned int n, double * a); +void mx_multmx (unsigned int m, unsigned int n, unsigned int q, double * p, const double * a, const double * b); +int mx_inv (unsigned int n, unsigned int r, double * b, double * a, double eps); +void jacobi (double * a, double * b, double * d, unsigned int n, double eps, unsigned int rot, FILE * f); + diff --git a/src/math/mx_inv.c b/src/math/mx_inv.c index 4b7fbcd..5066ff9 100644 --- a/src/math/mx_inv.c +++ b/src/math/mx_inv.c @@ -4,77 +4,61 @@ * output: matrix B := A^(-1)*B */ -static inline void -calc (double *a, double *b, unsigned int n, unsigned int r, unsigned int k, - unsigned int j) -{ +static inline void calc(double * a, double * b, + unsigned int n, unsigned int r, + unsigned int k, unsigned int j){ unsigned int i; - double t = a[j * n + k] / a[k * n + k]; - a[j * n + k] = 0.0; - for (i = k + 1; i < n; i++) - { - a[j * n + i] -= a[k * n + i] * t; - } - for (i = 0; i < r; i++) - { - b[j * r + i] -= b[k * r + i] * t; - } + double t = a[j*n+k]/a[k*n+k]; + a[j*n+k] = 0.0; + for(i=k+1; i fabs (a[m * n + k])) - { - m = l; - } - } - if (fabs (a[m * n + k]) < eps) - { - return -1; - } +int mx_inv(unsigned int n, unsigned int r, double * b, double * a, double eps){ + for(unsigned k=0; k fabs(a[m*n+k])){ + m = l; + } + } + if(fabs(a[m*n+k])= 0; k--) - { - for (int j = k - 1; j >= 0; j--) - { - calc (a, b, n, r, k, j); - } + for(unsigned l=0; l eps) - { - double t = 1.0 / a[k * n + k]; - for (unsigned j = 0; j < r; j++) - { - b[k * r + j] *= t; - } - a[k * n + k] = 1.0; - } + for(unsigned j=k+1; j=0; k--){ + for(int j=k-1; j>=0; j--){ + calc(a, b, n, r, k, j); + } + } + for(unsigned k=0; keps){ + double t = 1.0/a[k*n+k]; + for(unsigned j=0; j -#include #include +#include +#include -void vecset (size_t n, double *u, double s); -void vecsums (size_t n, double *w, const double *u, const double *v, double s); -void vecadds (size_t n, double *u, const double *v, double s); -void veccp (size_t n, double *u, const double *v); -void vecscal (size_t n, double *u, double s); +void vecset(size_t n, double * u, double s); +void vecsums(size_t n, double * w, const double * u, const double * v, double s); +void vecadds(size_t n, double * u, const double * v, double s); +void veccp(size_t n, double * u, const double * v); +void vecscal(size_t n, double * u, double s); diff --git a/src/math/zmat.c b/src/math/zmat.c index c774804..f1e8cca 100644 --- a/src/math/zmat.c +++ b/src/math/zmat.c @@ -3,66 +3,60 @@ #define EPS 1e-15 -int -zmat2cart (int n, double r[3], const double a[3], const double b[3], - const double c[3], double R, double phi, double theta) -{ - - if (n == 0) - { - r[0] = r[1] = r[2] = 0.0; +int zmat2cart(int n, double r[3], + const double a[3], const double b[3], const double c[3], + double R, double phi, double theta){ + + if(n == 0){ + r[0] = r[1] = r[2] = 0.0; + } + + else if(n == 1){ + r[0] = a[0]; + r[1] = a[1] + R; + r[2] = a[2]; + } + + else if(n == 2){ + r[0] = a[0] + R * sqrt( 1 - cos(phi)*cos(phi) ); + r[1] = a[1] + ( (b[1] -#include #include +#include #include +#include -#define BA 0.5291772 -#define AB 1.88972616356109068947 +#define BA 0.5291772 +#define AB 1.88972616356109068947 #define S_TO_MS 1e6 -#define MS_TO_S (1.0 / (S_TO_MS)) +#define MS_TO_S (1.0/(S_TO_MS)) -#define CLOSE0(F) \ - { \ - if (F) \ - { \ - fclose (F); \ - F = NULL; \ - } \ - } -#define FREE0(PTR) \ - { \ - if (PTR) \ - { \ - free (PTR); \ - PTR = NULL; \ - } \ - } +#define CLOSE0(F) {if(F){ fclose(F); F = NULL; }} +#define FREE0(PTR) {if(PTR){ free(PTR); PTR = NULL; }} -#define MEM_END(S, X) ((S)->X + (X##_size) / sizeof (*((S)->X))) +#define MEM_END(S,X) ( (S)->X + (X##_size)/sizeof(*((S)->X)) ) -#define MAX(x, y) (((x) > (y)) ? (x) : (y)) -#define MIN(x, y) (((x) < (y)) ? (x) : (y)) +#define MAX(x,y) ( ((x) > (y)) ? (x) : (y) ) +#define MIN(x,y) ( ((x) < (y)) ? (x) : (y) ) -#define GOTOHELL \ - { \ - fprintf (stderr, "%s:%d %s() -- ", __FILE__, __LINE__, __FUNCTION__); \ - abort (); \ - } +#define GOTOHELL { \ + fprintf(stderr, "%s:%d %s() -- ", \ + __FILE__, __LINE__, __FUNCTION__); \ + abort(); } -#define printalive \ - { \ - printf ("alive @ %s:%d\n", __FILE__, __LINE__); \ - fflush (stdout); \ - } +#define printalive {printf("alive @ %s:%d\n", __FILE__, __LINE__); fflush(stdout);} -#define PRINT_ERR(...) \ - { \ - fprintf (stderr, \ - "\e[1;31m" \ - "error: " \ - "\e[0m" \ - "\e[1;30m" \ - "[%s:%d]" \ - "\e[0m ", \ - __FILE__, __LINE__); \ - fprintf (stderr, __VA_ARGS__); \ - } -#define PRINT_WARN(...) \ - { \ - fprintf (stderr, \ - "\e[1;35m" \ - "warning: " \ - "\e[0m" \ - "\e[1;30m" \ - "[%s:%d]" \ - "\e[0m ", \ - __FILE__, __LINE__); \ - fprintf (stderr, __VA_ARGS__); \ - } +#define PRINT_ERR(...) {\ + fprintf(stderr, "\e[1;31m" "error: " "\e[0m" "\e[1;30m" "[%s:%d]" "\e[0m ", __FILE__, __LINE__);\ + fprintf(stderr, __VA_ARGS__ );\ +} +#define PRINT_WARN(...) {\ + fprintf(stderr, "\e[1;35m" "warning: " "\e[0m" "\e[1;30m" "[%s:%d]" "\e[0m ", __FILE__, __LINE__);\ + fprintf(stderr, __VA_ARGS__ );\ +} typedef char styp[8]; + diff --git a/src/mol/elements.h b/src/mol/elements.h index 24b1ddd..27f3597 100644 --- a/src/mol/elements.h +++ b/src/mol/elements.h @@ -1,32 +1,31 @@ -[0] = "", [1] = "H", [2] = "He", [3] = "Li", [4] = "Be", [5] = "B", [6] = "C", - [7] = "N", [8] = "O", [9] = "F", [10] = "Ne", [11] = "Na", - [12] = "Mg", [13] = "Al", [14] = "Si", [15] = "P", [16] = "S", - [17] = "Cl", [18] = "Ar", [19] = "K", [20] = "Ca", - - [21] = "Sc", [22] = "Ti", [23] = "V", [24] = "Cr", [25] = "Mn", - [26] = "Fe", [27] = "Co", [28] = "Ni", [29] = "Cu", [30] = "Zn", - - [31] = "Ga", [32] = "Ge", [33] = "As", [34] = "Se", [35] = "Br", - [36] = "Kr", [37] = "Rb", [38] = "Sr", - - [39] = "Y", [40] = "Zr", [41] = "Nb", [42] = "Mo", [43] = "Tc", - [44] = "Ru", [45] = "Rh", [46] = "Pd", [47] = "Ag", [48] = "Cd", - - [49] = "In", [50] = "Sn", [51] = "Sb", [52] = "Te", [53] = "I", - [54] = "Xe", [55] = "Cs", [56] = "Ba", - - [57] = "La", [58] = "Ce", [59] = "Pr", [60] = "Nd", [61] = "Pm", - [62] = "Sm", [63] = "Eu", [64] = "Gd", [65] = "Tb", [66] = "Dy", - [67] = "Ho", [68] = "Er", [69] = "Tm", [70] = "Yb", [71] = "Lu", - [72] = "Hf", [73] = "Ta", [74] = "W", [75] = "Re", [76] = "Os", - [77] = "Ir", [78] = "Pt", [79] = "Au", [80] = "Hg", - - [81] = "Tl", [82] = "Pb", [83] = "Bi", [84] = "Po", [85] = "At", - [86] = "Rn", [87] = "Fr", [88] = "Ra", [89] = "Ac", [90] = "Th", - [91] = "Pa", [92] = "U", [93] = "Np", [94] = "Pu", [95] = "Am", - [96] = "Cm", [97] = "Bk", [98] = "Cf", [99] = "Es", [100] = "Fm", - [101] = "Md", [102] = "No", [103] = "Lr", [104] = "Rf", [105] = "Db", - [106] = "Sg", [107] = "Bh", [108] = "Hs", [109] = "Mt", [110] = "Ds", - [111] = "Rg", [112] = "Cn", [113] = "Nh", [114] = "Fl", [115] = "Mc", - [116] = "Lv", [117] = "Ts", [118] = "Og", + [ 0] = "", + [ 1] = "H", [ 2] = "He", + [ 3] = "Li", [ 4] = "Be", [ 5] = "B", [ 6] = "C", [ 7] = "N", [ 8] = "O", [ 9] = "F", [ 10] = "Ne", + [ 11] = "Na", [ 12] = "Mg", [ 13] = "Al", [ 14] = "Si", [ 15] = "P", [ 16] = "S", [ 17] = "Cl", [ 18] = "Ar", + [ 19] = "K", [ 20] = "Ca", + + [ 21] = "Sc", [ 22] = "Ti", [ 23] = "V", [ 24] = "Cr", [ 25] = "Mn", [ 26] = "Fe", [ 27] = "Co", [ 28] = "Ni", + [ 29] = "Cu", [ 30] = "Zn", + + [ 31] = "Ga", [ 32] = "Ge", [ 33] = "As", [ 34] = "Se", [ 35] = "Br", [ 36] = "Kr", + [ 37] = "Rb", [ 38] = "Sr", + + [ 39] = "Y", [ 40] = "Zr", [ 41] = "Nb", [ 42] = "Mo", [ 43] = "Tc", [ 44] = "Ru", [ 45] = "Rh", [ 46] = "Pd", + [ 47] = "Ag", [ 48] = "Cd", + + [ 49] = "In", [ 50] = "Sn", [ 51] = "Sb", [ 52] = "Te", [ 53] = "I", [ 54] = "Xe", + [ 55] = "Cs", [ 56] = "Ba", + + [ 57] = "La", [ 58] = "Ce", [ 59] = "Pr", [ 60] = "Nd", [ 61] = "Pm", [ 62] = "Sm", [ 63] = "Eu", + [ 64] = "Gd", [ 65] = "Tb", [ 66] = "Dy", [ 67] = "Ho", [ 68] = "Er", [ 69] = "Tm", [ 70] = "Yb", + [ 71] = "Lu", [ 72] = "Hf", [ 73] = "Ta", [ 74] = "W", [ 75] = "Re", [ 76] = "Os", [ 77] = "Ir", [ 78] = "Pt", + [ 79] = "Au", [ 80] = "Hg", + + [ 81] = "Tl", [ 82] = "Pb", [ 83] = "Bi", [ 84] = "Po", [ 85] = "At", [ 86] = "Rn", + [ 87] = "Fr", [ 88] = "Ra", + [ 89] = "Ac", [ 90] = "Th", [ 91] = "Pa", [ 92] = "U", [ 93] = "Np", [ 94] = "Pu", [ 95] = "Am", + [ 96] = "Cm", [ 97] = "Bk", [ 98] = "Cf", [ 99] = "Es", [100] = "Fm", [101] = "Md", [102] = "No", + [103] = "Lr", [104] = "Rf", [105] = "Db", [106] = "Sg", [107] = "Bh", [108] = "Hs", [109] = "Mt", [110] = "Ds", + [111] = "Rg", [112] = "Cn", [113] = "Nh", [114] = "Fl", [115] = "Mc", [116] = "Lv", [117] = "Ts", [118] = "Og", + diff --git a/src/mol/inertia.c b/src/mol/inertia.c index d3a7b77..ba4e9b1 100644 --- a/src/mol/inertia.c +++ b/src/mol/inertia.c @@ -1,114 +1,94 @@ -#include "matrix.h" #include "mol.h" +#include "matrix.h" #include "vec3.h" #define EPS 1e-10 #define EIGEN_EPS 1e-15 #define EIGEN_NIT 20 -static inline void -swap_ev (double d[3], double I_b[9], int i, int j) -{ +static inline void swap_ev(double d[3], double I_b[9], int i, int j){ double td = d[i]; d[i] = d[j]; d[j] = td; double tb[3]; - r3cp (tb, I_b + i * 3); - r3cp (I_b + i * 3, I_b + j * 3); - r3cp (I_b + j * 3, tb); + r3cp(tb, I_b+i*3); + r3cp(I_b+i*3, I_b+j*3); + r3cp(I_b+j*3, tb); } -static const double amass[] = { -#include "masses.h" +static const double amass[]={ + #include "masses.h" }; -static double -get_mass (int q) -{ - q = abs (q); - if (q < sizeof (amass) / sizeof (amass[0])) - { - return amass[q]; - } - else - { - // fit for 86-111 - return 2.0795 * q + 44.9095; - } +static double get_mass(int q){ + q = abs(q); + if(q < sizeof(amass)/sizeof(amass[0])){ + return amass[q]; + } + else{ + // fit for 86-111 + return 2.0795 * q + 44.9095; + } } -void -center_mol (int n, double *r, const int *q) -{ - double c[3] = { 0, 0, 0 }; +void center_mol(int n, double * r, const int * q){ + double c[3] = {0,0,0}; double s = 0.0; - for (int i = 0; i < n; i++) - { - double w = q ? get_mass (q[i]) : 1.0; - s += w; - r3adds (c, r + i * 3, w); - } - if (fabs (s) < EPS) - { - s = 1.0; - } - r3scal (c, 1.0 / s); + for(int i=0; in, m->r, m->q); - double I_t[6] = {}; - for (int i = 0; i < m->n; i++) - { - double tm = get_mass (m->q[i]); - double x = m->r[3 * i]; - double y = m->r[3 * i + 1]; - double z = m->r[3 * i + 2]; - I_t[mpos (0, 0)] += tm * (y * y + z * z); // Ixx - I_t[mpos (1, 1)] += tm * (x * x + z * z); // Iyy - I_t[mpos (2, 2)] += tm * (x * x + y * y); // Izz - I_t[mpos (0, 1)] -= tm * (x * y); // Ixy - I_t[mpos (0, 2)] -= tm * (x * z); // Ixz - I_t[mpos (1, 2)] -= tm * (y * z); // Iyz - } - double I_b[9] = { 1, 0, 0, 0, 1, 0, 0, 0, 1 }; - jacobi (I_t, I_b, d, 3, EIGEN_EPS, EIGEN_NIT, NULL); + if(!d){ + d = _d; + } + center_mol(m->n, m->r, m->q); + double I_t[6]={}; + for(int i=0; in; i++){ + double tm = get_mass(m->q[i]); + double x = m->r[3*i ]; + double y = m->r[3*i+1]; + double z = m->r[3*i+2]; + I_t[mpos(0,0)] += tm * (y*y + z*z); //Ixx + I_t[mpos(1,1)] += tm * (x*x + z*z); //Iyy + I_t[mpos(2,2)] += tm * (x*x + y*y); //Izz + I_t[mpos(0,1)] -= tm * (x*y); //Ixy + I_t[mpos(0,2)] -= tm * (x*z); //Ixz + I_t[mpos(1,2)] -= tm * (y*z); //Iyz + } + double I_b[9]={1,0,0, 0,1,0, 0,0,1}; + jacobi(I_t, I_b, d, 3, EIGEN_EPS, EIGEN_NIT, NULL); - // sort ev - if (d[0] < d[1]) - swap_ev (d, I_b, 0, 1); - if (d[1] < d[2]) - swap_ev (d, I_b, 1, 2); - if (d[0] < d[1]) - swap_ev (d, I_b, 0, 1); - swap_ev (d, I_b, 0, 2); + //sort ev + if(d[0]n; i++) - { - double u[3]; - r3mx (u, m->r + i * 3, I_b); - r3cp (m->r + i * 3, u); - } + for(int i=0; in; i++){ + double u[3]; + r3mx(u, m->r+i*3, I_b); + r3cp(m->r+i*3, u); + } return; } diff --git a/src/mol/intcoord.c b/src/mol/intcoord.c index b2d58c1..fed91a7 100644 --- a/src/mol/intcoord.c +++ b/src/mol/intcoord.c @@ -1,100 +1,78 @@ #include "mol.h" #include "vec3.h" -#define SIGN(X) ((X >= 0.0 ? 1.0 : -1.0)) +#define SIGN(X) ((X>=0.0 ? 1.0 : -1.0)) -double -intcoord_calc (int r_units_a, int check_n, const int z[5], const double *r) -{ - if (z[1] > check_n || z[2] > check_n || z[3] > check_n || z[4] > check_n) - { - return -1.0; - } +double intcoord_calc(int r_units_a, int check_n, const int z[5], const double * r){ + if(z[1]>check_n || z[2]>check_n || z[3]>check_n || z[4]>check_n){ + return -1.0; + } double t; - const double *a1 = r + (z[1] - 1) * 3; - const double *a2 = r + (z[2] - 1) * 3; - const double *a3 = r + (z[3] - 1) * 3; - const double *a4 = r + (z[4] - 1) * 3; + const double * a1 = r+(z[1]-1)*3; + const double * a2 = r+(z[2]-1)*3; + const double * a3 = r+(z[3]-1)*3; + const double * a4 = r+(z[4]-1)*3; double v1[3], v2[3], v3[3], v4[3], v5[3], v1x3[3]; - switch (z[0]) - { - case 3: - r3diff (v1, a2, a1); - r3diff (v2, a2, a3); - r3diff (v3, a3, a4); - r3x (v4, v1, v2); - r3x (v5, v3, v2); - r3x (v1x3, v1, v3); - t = r3dot (v4, v5) / sqrt (r3dot (v4, v4) * r3dot (v5, v5)); - if (t > 1.0) - { - t = 1.0; - } - else if (t < -1.0) - { - t = -1.0; - } - return acos (t) * M_1_PI * 180.0 * SIGN (r3dot (v2, v1x3)); - case 2: - r3diff (v4, a2, a1); - r3diff (v5, a2, a3); - t = r3dot (v4, v5) / sqrt (r3dot (v4, v4) * r3dot (v5, v5)); - return acos (t) * M_1_PI * 180.0; - case 1: - return sqrt (r3d2 (a1, a2)) - * (r_units_a ? 1.0 : BA); /* return R12 in ångströms whatever - units are in input */ + switch(z[0]){ + case 3 : + r3diff(v1, a2, a1); + r3diff(v2, a2, a3); + r3diff(v3, a3, a4); + r3x(v4,v1,v2); + r3x(v5,v3,v2); + r3x(v1x3,v1,v3); + t = r3dot(v4,v5) / sqrt( r3dot(v4,v4)*r3dot(v5,v5) ); + if(t>1.0){ + t = 1.0; + } + else if(t<-1.0){ + t = -1.0; + } + return acos(t)*M_1_PI*180.0 * SIGN( r3dot(v2,v1x3) ); + case 2 : + r3diff(v4, a2, a1); + r3diff(v5, a2, a3); + t = r3dot(v4,v5) / sqrt( r3dot(v4,v4)*r3dot(v5,v5) ); + return acos(t)*M_1_PI*180.0; + case 1 : + return sqrt(r3d2(a1,a2))* (r_units_a?1.0:BA); /* return R12 in ångströms whatever units are in input */ default: return 0.0; - } + } } -int -intcoord_check (int n, int z[5]) -{ - if (!(z[0] || z[1] || z[2] || z[3] || z[4])) - { - return 0; - } - switch (z[0]) - { - case 3: - if (z[4] < 1 || z[4] > n) - z[0] = 0; - if (z[4] == z[3]) - z[0] = 0; - if (z[4] == z[2]) - z[0] = 0; - if (z[4] == z[1]) - z[0] = 0; - case 2: - if (z[3] < 1 || z[3] > n) - z[0] = 0; - if (z[3] == z[2]) - z[0] = 0; - if (z[3] == z[1]) - z[0] = 0; - case 1: - if (z[1] < 1 || z[1] > n) - z[0] = 0; - if (z[2] < 1 || z[2] > n) - z[0] = 0; - if (z[1] == z[2]) - z[0] = 0; +int intcoord_check(int n, int z[5]){ + if(!(z[0]||z[1]||z[2]||z[3]||z[4])){ + return 0; + } + switch(z[0]){ + case 3 : + if (z[4] < 1 || z[4] > n) z[0] = 0; + if (z[4] == z[3]) z[0] = 0; + if (z[4] == z[2]) z[0] = 0; + if (z[4] == z[1]) z[0] = 0; + case 2 : + if (z[3] < 1 || z[3] > n) z[0] = 0; + if (z[3] == z[2]) z[0] = 0; + if (z[3] == z[1]) z[0] = 0; + case 1 : + if (z[1] < 1 || z[1] > n) z[0] = 0; + if (z[2] < 1 || z[2] > n) z[0] = 0; + if (z[1] == z[2]) z[0] = 0; break; case 4: // TODO case 5: // TODO default: z[0] = 0; - } - switch (z[0]) - { - case 0: - PRINT_WARN ("check the internal coordintate option ('z:')\n"); + } + switch(z[0]){ + case 0 : + PRINT_WARN("check the internal coordintate option ('z:')\n"); return -1; - case 1: + case 1 : z[3] = 0; - case 2: + case 2 : z[4] = 0; - } + } return 0; } + diff --git a/src/mol/masses.h b/src/mol/masses.h index 4e06d5b..f2a3b41 100644 --- a/src/mol/masses.h +++ b/src/mol/masses.h @@ -1,36 +1,31 @@ /* http://www.ciaaw.org/atomic-masses.htm */ -[0] = 0.0, - [1] = 1.00782503226, [2] = 4.00260325414, [3] = 7.016003443, - [4] = 9.01218315, [5] = 11.0093053, [6] = 12.0, [7] = 14.0030740042, - [8] = 15.9949146202, [9] = 18.9984031636, [10] = 19.992440182, - [11] = 22.989769282, [12] = 23.985041709, [13] = 26.98153857, - [14] = 27.9769265353, [15] = 30.9737619985, [16] = 31.9720711749, - [17] = 34.96885273, [18] = 39.962383122, [19] = 38.963706493, - [20] = 39.96259092, [21] = 44.9559085, [22] = 47.9479423, - [23] = 50.9439576, [24] = 51.9405064, [25] = 54.9380443, [26] = 55.9349363, - [27] = 58.9331944, [28] = 57.9353423, [29] = 62.9295984, [30] = 63.9291425, - [31] = 68.9255748, [32] = 73.921177769, [33] = 74.9215956, - [34] = 79.9165228, [35] = 78.9183389, [36] = 83.911497733, - [37] = 84.911789743, [38] = 87.9056138, [39] = 88.905842, [40] = 89.904702, - [41] = 92.906372, [42] = 97.9054053, [43] = 97.907213, [44] = 101.9043448, - [45] = 102.905502, [46] = 105.9034808, [47] = 106.905092, - [48] = 113.9033653, [49] = 114.903878788, [50] = 119.9022026, - [51] = 120.903812, [52] = 129.906222758, [53] = 126.904473, - [54] = 131.904155094, [55] = 132.905451966, [56] = 137.9052472, - [57] = 138.906362, [58] = 139.905442, [59] = 140.907662, [60] = 141.907732, - [61] = 144.912762, [62] = 151.919742, [63] = 152.921242, [64] = 157.924112, - [65] = 158.925352, [66] = 163.929182, [67] = 164.930332, [68] = 165.930302, - [69] = 168.934222, [70] = 173.938872, [71] = 174.940782, [72] = 179.946562, - [73] = 180.948002, [74] = 183.9509316, [75] = 186.955751, - [76] = 191.961482, [77] = 192.962922, [78] = 194.9647926, - [79] = 196.9665695, [80] = 201.9706435, [81] = 204.9744289, - [82] = 207.9766538, [83] = 208.980401, [84] = 208.982416, - [85] = 209.987131, [86] = 222.01757, [87] = 223.019731, [88] = 226.025403, - [89] = 227.027747, [90] = 232.038062, [91] = 231.035882, [92] = 238.050792, - [93] = 237.048167, [94] = 244.064198, [95] = 243.061373, [96] = 247.070347, - [97] = 247.070299, [98] = 251.07958, [99] = 252.082972, [100] = 257.095099, - [101] = 258.098425, [102] = 259.101024, [103] = 262.109692, - [104] = 263.118313, [105] = 262.011437, [106] = 266.012238, - [107] = 264.012496, [108] = 269.001341, [109] = 268.001388, - [110] = 272.001463, [111] = 272.001535 +[ 0] = 0.0 , +[ 1] = 1.00782503226, [ 2] = 4.00260325414, [ 3] = 7.016003443 , [ 4] = 9.01218315 , +[ 5] = 11.0093053 , [ 6] = 12.0 , [ 7] = 14.0030740042 , [ 8] = 15.9949146202 , +[ 9] = 18.9984031636 , [ 10] = 19.992440182 , [ 11] = 22.989769282 , [ 12] = 23.985041709 , +[ 13] = 26.98153857 , [ 14] = 27.9769265353 , [ 15] = 30.9737619985 , [ 16] = 31.9720711749 , +[ 17] = 34.96885273 , [ 18] = 39.962383122 , [ 19] = 38.963706493 , [ 20] = 39.96259092 , +[ 21] = 44.9559085 , [ 22] = 47.9479423 , [ 23] = 50.9439576 , [ 24] = 51.9405064 , +[ 25] = 54.9380443 , [ 26] = 55.9349363 , [ 27] = 58.9331944 , [ 28] = 57.9353423 , +[ 29] = 62.9295984 , [ 30] = 63.9291425 , [ 31] = 68.9255748 , [ 32] = 73.921177769 , +[ 33] = 74.9215956 , [ 34] = 79.9165228 , [ 35] = 78.9183389 , [ 36] = 83.911497733 , +[ 37] = 84.911789743 , [ 38] = 87.9056138 , [ 39] = 88.905842 , [ 40] = 89.904702 , +[ 41] = 92.906372 , [ 42] = 97.9054053 , [ 43] = 97.907213 , [ 44] = 101.9043448 , +[ 45] = 102.905502 , [ 46] = 105.9034808 , [ 47] = 106.905092 , [ 48] = 113.9033653 , +[ 49] = 114.903878788 , [ 50] = 119.9022026 , [ 51] = 120.903812 , [ 52] = 129.906222758 , +[ 53] = 126.904473 , [ 54] = 131.904155094 , [ 55] = 132.905451966 , [ 56] = 137.9052472 , +[ 57] = 138.906362 , [ 58] = 139.905442 , [ 59] = 140.907662 , [ 60] = 141.907732 , +[ 61] = 144.912762 , [ 62] = 151.919742 , [ 63] = 152.921242 , [ 64] = 157.924112 , +[ 65] = 158.925352 , [ 66] = 163.929182 , [ 67] = 164.930332 , [ 68] = 165.930302 , +[ 69] = 168.934222 , [ 70] = 173.938872 , [ 71] = 174.940782 , [ 72] = 179.946562 , +[ 73] = 180.948002 , [ 74] = 183.9509316 , [ 75] = 186.955751 , [ 76] = 191.961482 , +[ 77] = 192.962922 , [ 78] = 194.9647926 , [ 79] = 196.9665695 , [ 80] = 201.9706435 , +[ 81] = 204.9744289 , [ 82] = 207.9766538 , [ 83] = 208.980401 , [ 84] = 208.982416 , +[ 85] = 209.987131 , [ 86] = 222.01757 , [ 87] = 223.019731 , [ 88] = 226.025403 , +[ 89] = 227.027747 , [ 90] = 232.038062 , [ 91] = 231.035882 , [ 92] = 238.050792 , +[ 93] = 237.048167 , [ 94] = 244.064198 , [ 95] = 243.061373 , [ 96] = 247.070347 , +[ 97] = 247.070299 , [ 98] = 251.07958 , [ 99] = 252.082972 , [100] = 257.095099 , +[101] = 258.098425 , [102] = 259.101024 , [103] = 262.109692 , [104] = 263.118313 , +[105] = 262.011437 , [106] = 266.012238 , [107] = 264.012496 , [108] = 269.001341 , +[109] = 268.001388 , [110] = 272.001463 , [111] = 272.001535 diff --git a/src/mol/mol.h b/src/mol/mol.h index b1a8e2e..62b3f42 100644 --- a/src/mol/mol.h +++ b/src/mol/mol.h @@ -3,34 +3,29 @@ #include "common.h" -typedef struct -{ - double *r; - int *q; - const char *name; - int n; +typedef struct { + double * r; + int * q; + const char * name; + int n; } mol; -static inline mol * -alloc_mol (int n) -{ - size_t r_size = sizeof (double) * n * 3; - size_t q_size = sizeof (int) * n; - mol *m = calloc (sizeof (mol) + r_size + q_size, 1); - if (!m) - GOTOHELL; - m->r = (double *)(m + 1); - m->q = (int *)MEM_END (m, r); // cppcheck-suppress invalidPointerCast +static inline mol * alloc_mol(int n){ + size_t r_size = sizeof(double) * n*3; + size_t q_size = sizeof(int ) * n; + mol * m = calloc(sizeof(mol)+r_size+q_size, 1); + if(!m) GOTOHELL; + m->r = (double *) (m + 1); + m->q = (int *) MEM_END(m, r); // cppcheck-suppress invalidPointerCast m->name = NULL; m->n = n; return m; } -void position (mol *m, double d[3], int preserve_chirality); -void center_mol (int n, double *r, const int *q); +void position(mol * m, double d[3], int preserve_chirality); +void center_mol(int n, double * r, const int * q); -int intcoord_check (int n, int z[5]); -double intcoord_calc (int r_units_a, int check_n, const int z[5], - const double *r); +int intcoord_check(int n, int z[5]); +double intcoord_calc (int r_units_a, int check_n, const int z[5], const double * r); #endif diff --git a/src/mol/mytime.h b/src/mol/mytime.h index 80d2d95..12c0375 100644 --- a/src/mol/mytime.h +++ b/src/mol/mytime.h @@ -1,10 +1,9 @@ -#include #include +#include -static inline double -myutime () -{ +static inline double myutime(){ struct rusage usage; - getrusage (RUSAGE_SELF, &usage); - return usage.ru_utime.tv_sec + usage.ru_utime.tv_usec * 1e-6; + getrusage(RUSAGE_SELF, &usage); + return usage.ru_utime.tv_sec + usage.ru_utime.tv_usec*1e-6; } + diff --git a/src/mol/palette_cpk.h b/src/mol/palette_cpk.h index 49311d7..774284f 100644 --- a/src/mol/palette_cpk.h +++ b/src/mol/palette_cpk.h @@ -1,109 +1,110 @@ -[0] = { 0x9999, 0x9999, 0x9999 }, [1] = { 0xBFFF, 0xBFFF, 0xBFFF }, /* H */ - [2] = { 0xD9D9, 0xFFFF, 0xFFFF }, /* He */ - [3] = { 0xCCCC, 0x8080, 0xFFFF }, /* Li */ - [4] = { 0xC2C2, 0xFFFF, 0x0000 }, /* Be */ - [5] = { 0xFFFF, 0xB5B5, 0xB5B5 }, /* B */ - [6] = { 0x5FFF, 0x5FFF, 0x5FFF }, /* C */ - [7] = { 0x1FFF, 0x1FFF, 0xBFFF }, /* N */ - [8] = { 0xBFFF, 0x1FFF, 0x1FFF }, /* O */ - [9] = { 0xF500, 0xFFFF, 0x8500 }, /* F */ - [10] = { 0xAAAA, 0xFFFF, 0xFFFF }, /* Ne */ - [11] = { 0xABAB, 0x5C5C, 0xF2F2 }, /* Na */ - [12] = { 0x8A8A, 0xFFFF, 0x0000 }, /* Mg */ - [13] = { 0xBFBF, 0xA6A6, 0xA6A6 }, /* Al */ - [14] = { 0x5FFF, 0x5FFF, 0x5FFF }, /* Si */ - [15] = { 0xFFFF, 0xCCCC, 0x9999 }, /* P */ - [16] = { 0xFFFF, 0xEEEE, 0x1111 }, /* S */ - [17] = { 0xCCCC, 0xFFFF, 0x9999 }, /* Cl */ - [18] = { 0xAAAA, 0xFFFF, 0xFFFF }, /* Ar */ - [19] = { 0x8F8F, 0x4040, 0xD4D4 }, /* K */ - [20] = { 0x3D3D, 0xFFFF, 0x0000 }, /* Ca */ - [21] = { 0xE6E6, 0xE6E6, 0xE6E6 }, /* Sc */ - [22] = { 0xBFBF, 0xC2C2, 0xC7C7 }, /* Ti */ - [23] = { 0xA6A6, 0xA6A6, 0xABAB }, /* V */ - [24] = { 0x8A8A, 0x9999, 0xC7C7 }, /* Cr */ - [25] = { 0x9C9C, 0x7A7A, 0xC7C7 }, /* Mn */ - [26] = { 0xDDDD, 0x6666, 0x3333 }, /* Fe */ - [27] = { 0xEEEE, 0x8888, 0x9999 }, /* Co */ - [28] = { 0x5050, 0xD0D0, 0x5050 }, /* Ni */ - [29] = { 0xBBBB, 0x7777, 0x3333 }, /* Cu */ - [30] = { 0x7D7D, 0x8080, 0xB0B0 }, /* Zn */ - [31] = { 0xC2C2, 0x8F8F, 0x8F8F }, /* Ga */ - [32] = { 0x6666, 0x8F8F, 0x8F8F }, /* Ge */ - [33] = { 0xBDBD, 0x8080, 0xE3E3 }, /* As */ - [34] = { 0xFFFF, 0xAAAA, 0x1111 }, /* Se */ - [35] = { 0xAAAA, 0x4444, 0x0000 }, /* Br */ - [36] = { 0xAAAA, 0xFFFF, 0xFFFF }, /* Kr */ - [37] = { 0x7070, 0x2E2E, 0xB0B0 }, /* Rb */ - [38] = { 0x0000, 0xFFFF, 0x0000 }, /* Sr */ - [39] = { 0x9494, 0xFFFF, 0xFFFF }, /* Y */ - [40] = { 0x9494, 0xE0E0, 0xE0E0 }, /* Zr */ - [41] = { 0x7373, 0xC2C2, 0xC9C9 }, /* Nb */ - [42] = { 0x5454, 0xB5B5, 0xB5B5 }, /* Mo */ - [43] = { 0x3B3B, 0x9E9E, 0x9E9E }, /* Tc */ - [44] = { 0x2424, 0x8F8F, 0x8F8F }, /* Ru */ - [45] = { 0x0A0A, 0x7D7D, 0x8C8C }, /* Rh */ - [46] = { 0x0000, 0x6969, 0x8585 }, /* Pd */ - [47] = { 0xC0C0, 0xC0C0, 0xC0C0 }, /* Ag */ - [48] = { 0xFFFF, 0xD9D9, 0x8F8F }, /* Cd */ - [49] = { 0xA6A6, 0x7575, 0x7373 }, /* In */ - [50] = { 0x6666, 0x8080, 0x8080 }, /* Sn */ - [51] = { 0x9E9E, 0x6363, 0xB5B5 }, /* Sb */ - [52] = { 0xD4D4, 0x7A7A, 0x0000 }, /* Te */ - [53] = { 0x9494, 0x0000, 0x9494 }, /* I */ - [54] = { 0x4242, 0x9E9E, 0xB0B0 }, /* Xe */ - [55] = { 0x5757, 0x1717, 0x8F8F }, /* Cs */ - [56] = { 0x0000, 0xC9C9, 0x0000 }, /* Ba */ - [57] = { 0x7070, 0xD4D4, 0xFFFF }, /* La */ - [58] = { 0xFFFF, 0xFFFF, 0xC7C7 }, /* Ce */ - [59] = { 0xD9D9, 0xFFFF, 0xC7C7 }, /* Pr */ - [60] = { 0xC7C7, 0xFFFF, 0xC7C7 }, /* Nd */ - [61] = { 0xA3A3, 0xFFFF, 0xC7C7 }, /* Pm */ - [62] = { 0x8F8F, 0xFFFF, 0xC7C7 }, /* Sm */ - [63] = { 0x6161, 0xFFFF, 0xC7C7 }, /* Eu */ - [64] = { 0x4545, 0xFFFF, 0xC7C7 }, /* Gd */ - [65] = { 0x3030, 0xFFFF, 0xC7C7 }, /* Tb */ - [66] = { 0x1F1F, 0xFFFF, 0xC7C7 }, /* Dy */ - [67] = { 0x0000, 0xFFFF, 0x9C9C }, /* Ho */ - [68] = { 0x0000, 0xE6E6, 0x7575 }, /* Er */ - [69] = { 0x0000, 0xD4D4, 0x5252 }, /* Tm */ - [70] = { 0x0000, 0xBFBF, 0x3838 }, /* Yb */ - [71] = { 0x0000, 0xABAB, 0x2424 }, /* Lu */ - [72] = { 0x4D4D, 0xC2C2, 0xFFFF }, /* Hf */ - [73] = { 0x4D4D, 0xA6A6, 0xFFFF }, /* Ta */ - [74] = { 0x2121, 0x9494, 0xD6D6 }, /* W */ - [75] = { 0x2626, 0x7D7D, 0xABAB }, /* Re */ - [76] = { 0x2626, 0x6666, 0x9696 }, /* Os */ - [77] = { 0x1717, 0x5454, 0x8787 }, /* Ir */ - [78] = { 0xD0D0, 0xD0D0, 0xE0E0 }, /* Pt */ - [79] = { 0xFFFF, 0xD1D1, 0x2323 }, /* Au */ - [80] = { 0xB8B8, 0xB8B8, 0xD0D0 }, /* Hg */ - [81] = { 0xA6A6, 0x5454, 0x4D4D }, /* Tl */ - [82] = { 0x5757, 0x5959, 0x6161 }, /* Pb */ - [83] = { 0x9E9E, 0x4F4F, 0xB5B5 }, /* Bi */ - [84] = { 0xABAB, 0x5C5C, 0x0000 }, /* Po */ - [85] = { 0x7575, 0x4F4F, 0x4545 }, /* At */ - [86] = { 0x4242, 0x8282, 0x9696 }, /* Rn */ - [87] = { 0x4242, 0x0000, 0x6666 }, /* Fr */ - [88] = { 0x0000, 0x7D7D, 0x0000 }, /* Ra */ - [89] = { 0x7070, 0xABAB, 0xFAFA }, /* Ac */ - [90] = { 0x0000, 0xBABA, 0xFFFF }, /* Th */ - [91] = { 0x0000, 0xA1A1, 0xFFFF }, /* Pa */ - [92] = { 0x0000, 0x8F8F, 0xFFFF }, /* U */ - [93] = { 0x0000, 0x8080, 0xFFFF }, /* Np */ - [94] = { 0x0000, 0x6B6B, 0xFFFF }, /* Pu */ - [95] = { 0x5454, 0x5C5C, 0xF2F2 }, /* Am */ - [96] = { 0x7878, 0x5C5C, 0xE3E3 }, /* Cm */ - [97] = { 0x8A8A, 0x4F4F, 0xE3E3 }, /* Bk */ - [98] = { 0xA1A1, 0x3636, 0xD4D4 }, /* Cf */ - [99] = { 0xB3B3, 0x1F1F, 0xD4D4 }, /* Es */ - [100] = { 0xB3B3, 0x1F1F, 0xBABA }, /* Fm */ - [101] = { 0xB3B3, 0x0D0D, 0xA6A6 }, /* Md */ - [102] = { 0xBDBD, 0x0D0D, 0x8787 }, /* No */ - [103] = { 0xC7C7, 0x0000, 0x6666 }, /* Lr */ - [104] = { 0xCCCC, 0x0000, 0x5959 }, /* Rf */ - [105] = { 0xD1D1, 0x0000, 0x4F4F }, /* Db */ - [106] = { 0xD9D9, 0x0000, 0x4545 }, /* Sg */ - [107] = { 0xE0E0, 0x0000, 0x3838 }, /* Bh */ - [108] = { 0xE6E6, 0x0000, 0x2E2E }, /* Hs */ - [109] = { 0xEBEB, 0x0000, 0x2626 }, /* Mt */ + [ 0] = {0x9999, 0x9999, 0x9999}, + [ 1] = {0xBFFF, 0xBFFF, 0xBFFF}, /* H */ + [ 2] = {0xD9D9, 0xFFFF, 0xFFFF}, /* He */ + [ 3] = {0xCCCC, 0x8080, 0xFFFF}, /* Li */ + [ 4] = {0xC2C2, 0xFFFF, 0x0000}, /* Be */ + [ 5] = {0xFFFF, 0xB5B5, 0xB5B5}, /* B */ + [ 6] = {0x5FFF, 0x5FFF, 0x5FFF}, /* C */ + [ 7] = {0x1FFF, 0x1FFF, 0xBFFF}, /* N */ + [ 8] = {0xBFFF, 0x1FFF, 0x1FFF}, /* O */ + [ 9] = {0xF500, 0xFFFF, 0x8500}, /* F */ + [ 10] = {0xAAAA, 0xFFFF, 0xFFFF}, /* Ne */ + [ 11] = {0xABAB, 0x5C5C, 0xF2F2}, /* Na */ + [ 12] = {0x8A8A, 0xFFFF, 0x0000}, /* Mg */ + [ 13] = {0xBFBF, 0xA6A6, 0xA6A6}, /* Al */ + [ 14] = {0x5FFF, 0x5FFF, 0x5FFF}, /* Si */ + [ 15] = {0xFFFF, 0xCCCC, 0x9999}, /* P */ + [ 16] = {0xFFFF, 0xEEEE, 0x1111}, /* S */ + [ 17] = {0xCCCC, 0xFFFF, 0x9999}, /* Cl */ + [ 18] = {0xAAAA, 0xFFFF, 0xFFFF}, /* Ar */ + [ 19] = {0x8F8F, 0x4040, 0xD4D4}, /* K */ + [ 20] = {0x3D3D, 0xFFFF, 0x0000}, /* Ca */ + [ 21] = {0xE6E6, 0xE6E6, 0xE6E6}, /* Sc */ + [ 22] = {0xBFBF, 0xC2C2, 0xC7C7}, /* Ti */ + [ 23] = {0xA6A6, 0xA6A6, 0xABAB}, /* V */ + [ 24] = {0x8A8A, 0x9999, 0xC7C7}, /* Cr */ + [ 25] = {0x9C9C, 0x7A7A, 0xC7C7}, /* Mn */ + [ 26] = {0xDDDD, 0x6666, 0x3333}, /* Fe */ + [ 27] = {0xEEEE, 0x8888, 0x9999}, /* Co */ + [ 28] = {0x5050, 0xD0D0, 0x5050}, /* Ni */ + [ 29] = {0xBBBB, 0x7777, 0x3333}, /* Cu */ + [ 30] = {0x7D7D, 0x8080, 0xB0B0}, /* Zn */ + [ 31] = {0xC2C2, 0x8F8F, 0x8F8F}, /* Ga */ + [ 32] = {0x6666, 0x8F8F, 0x8F8F}, /* Ge */ + [ 33] = {0xBDBD, 0x8080, 0xE3E3}, /* As */ + [ 34] = {0xFFFF, 0xAAAA, 0x1111}, /* Se */ + [ 35] = {0xAAAA, 0x4444, 0x0000}, /* Br */ + [ 36] = {0xAAAA, 0xFFFF, 0xFFFF}, /* Kr */ + [ 37] = {0x7070, 0x2E2E, 0xB0B0}, /* Rb */ + [ 38] = {0x0000, 0xFFFF, 0x0000}, /* Sr */ + [ 39] = {0x9494, 0xFFFF, 0xFFFF}, /* Y */ + [ 40] = {0x9494, 0xE0E0, 0xE0E0}, /* Zr */ + [ 41] = {0x7373, 0xC2C2, 0xC9C9}, /* Nb */ + [ 42] = {0x5454, 0xB5B5, 0xB5B5}, /* Mo */ + [ 43] = {0x3B3B, 0x9E9E, 0x9E9E}, /* Tc */ + [ 44] = {0x2424, 0x8F8F, 0x8F8F}, /* Ru */ + [ 45] = {0x0A0A, 0x7D7D, 0x8C8C}, /* Rh */ + [ 46] = {0x0000, 0x6969, 0x8585}, /* Pd */ + [ 47] = {0xC0C0, 0xC0C0, 0xC0C0}, /* Ag */ + [ 48] = {0xFFFF, 0xD9D9, 0x8F8F}, /* Cd */ + [ 49] = {0xA6A6, 0x7575, 0x7373}, /* In */ + [ 50] = {0x6666, 0x8080, 0x8080}, /* Sn */ + [ 51] = {0x9E9E, 0x6363, 0xB5B5}, /* Sb */ + [ 52] = {0xD4D4, 0x7A7A, 0x0000}, /* Te */ + [ 53] = {0x9494, 0x0000, 0x9494}, /* I */ + [ 54] = {0x4242, 0x9E9E, 0xB0B0}, /* Xe */ + [ 55] = {0x5757, 0x1717, 0x8F8F}, /* Cs */ + [ 56] = {0x0000, 0xC9C9, 0x0000}, /* Ba */ + [ 57] = {0x7070, 0xD4D4, 0xFFFF}, /* La */ + [ 58] = {0xFFFF, 0xFFFF, 0xC7C7}, /* Ce */ + [ 59] = {0xD9D9, 0xFFFF, 0xC7C7}, /* Pr */ + [ 60] = {0xC7C7, 0xFFFF, 0xC7C7}, /* Nd */ + [ 61] = {0xA3A3, 0xFFFF, 0xC7C7}, /* Pm */ + [ 62] = {0x8F8F, 0xFFFF, 0xC7C7}, /* Sm */ + [ 63] = {0x6161, 0xFFFF, 0xC7C7}, /* Eu */ + [ 64] = {0x4545, 0xFFFF, 0xC7C7}, /* Gd */ + [ 65] = {0x3030, 0xFFFF, 0xC7C7}, /* Tb */ + [ 66] = {0x1F1F, 0xFFFF, 0xC7C7}, /* Dy */ + [ 67] = {0x0000, 0xFFFF, 0x9C9C}, /* Ho */ + [ 68] = {0x0000, 0xE6E6, 0x7575}, /* Er */ + [ 69] = {0x0000, 0xD4D4, 0x5252}, /* Tm */ + [ 70] = {0x0000, 0xBFBF, 0x3838}, /* Yb */ + [ 71] = {0x0000, 0xABAB, 0x2424}, /* Lu */ + [ 72] = {0x4D4D, 0xC2C2, 0xFFFF}, /* Hf */ + [ 73] = {0x4D4D, 0xA6A6, 0xFFFF}, /* Ta */ + [ 74] = {0x2121, 0x9494, 0xD6D6}, /* W */ + [ 75] = {0x2626, 0x7D7D, 0xABAB}, /* Re */ + [ 76] = {0x2626, 0x6666, 0x9696}, /* Os */ + [ 77] = {0x1717, 0x5454, 0x8787}, /* Ir */ + [ 78] = {0xD0D0, 0xD0D0, 0xE0E0}, /* Pt */ + [ 79] = {0xFFFF, 0xD1D1, 0x2323}, /* Au */ + [ 80] = {0xB8B8, 0xB8B8, 0xD0D0}, /* Hg */ + [ 81] = {0xA6A6, 0x5454, 0x4D4D}, /* Tl */ + [ 82] = {0x5757, 0x5959, 0x6161}, /* Pb */ + [ 83] = {0x9E9E, 0x4F4F, 0xB5B5}, /* Bi */ + [ 84] = {0xABAB, 0x5C5C, 0x0000}, /* Po */ + [ 85] = {0x7575, 0x4F4F, 0x4545}, /* At */ + [ 86] = {0x4242, 0x8282, 0x9696}, /* Rn */ + [ 87] = {0x4242, 0x0000, 0x6666}, /* Fr */ + [ 88] = {0x0000, 0x7D7D, 0x0000}, /* Ra */ + [ 89] = {0x7070, 0xABAB, 0xFAFA}, /* Ac */ + [ 90] = {0x0000, 0xBABA, 0xFFFF}, /* Th */ + [ 91] = {0x0000, 0xA1A1, 0xFFFF}, /* Pa */ + [ 92] = {0x0000, 0x8F8F, 0xFFFF}, /* U */ + [ 93] = {0x0000, 0x8080, 0xFFFF}, /* Np */ + [ 94] = {0x0000, 0x6B6B, 0xFFFF}, /* Pu */ + [ 95] = {0x5454, 0x5C5C, 0xF2F2}, /* Am */ + [ 96] = {0x7878, 0x5C5C, 0xE3E3}, /* Cm */ + [ 97] = {0x8A8A, 0x4F4F, 0xE3E3}, /* Bk */ + [ 98] = {0xA1A1, 0x3636, 0xD4D4}, /* Cf */ + [ 99] = {0xB3B3, 0x1F1F, 0xD4D4}, /* Es */ + [100] = {0xB3B3, 0x1F1F, 0xBABA}, /* Fm */ + [101] = {0xB3B3, 0x0D0D, 0xA6A6}, /* Md */ + [102] = {0xBDBD, 0x0D0D, 0x8787}, /* No */ + [103] = {0xC7C7, 0x0000, 0x6666}, /* Lr */ + [104] = {0xCCCC, 0x0000, 0x5959}, /* Rf */ + [105] = {0xD1D1, 0x0000, 0x4F4F}, /* Db */ + [106] = {0xD9D9, 0x0000, 0x4545}, /* Sg */ + [107] = {0xE0E0, 0x0000, 0x3838}, /* Bh */ + [108] = {0xE6E6, 0x0000, 0x2E2E}, /* Hs */ + [109] = {0xEBEB, 0x0000, 0x2626}, /* Mt */ diff --git a/src/mol/palette_v.h b/src/mol/palette_v.h index d37602e..d17b954 100644 --- a/src/mol/palette_v.h +++ b/src/mol/palette_v.h @@ -1,24 +1,25 @@ -[0] = { 0x9999, 0x9999, 0x9999 }, [1] = { 0xBFFF, 0xBFFF, 0xBFFF }, /* H */ - [2] = { 0xAAAA, 0xFFFF, 0xFFFF }, /* He */ - [6] = { 0x5FFF, 0x5FFF, 0x5FFF }, /* C */ - [5] = { 0xFFFF, 0xDDDD, 0xFFFF }, /* P */ - [7] = { 0x1FFF, 0x1FFF, 0xBFFF }, /* N */ - [8] = { 0xBFFF, 0x1FFF, 0x1FFF }, /* O */ - [9] = { 0xF500, 0xFFFF, 0x8500 }, /* F */ - [10] = { 0xAAAA, 0xFFFF, 0xFFFF }, /* Ne */ - [14] = { 0x5FFF, 0x5FFF, 0x5FFF }, /* Si */ - [15] = { 0xFFFF, 0xCCCC, 0x9999 }, /* P */ - [16] = { 0xFFFF, 0xEEEE, 0x1111 }, /* S */ - [17] = { 0xCCCC, 0xFFFF, 0x9999 }, /* Cl */ - [18] = { 0xAAAA, 0xFFFF, 0xFFFF }, /* Ar */ - [28] = { 0x9999, 0x5555, 0xFFFF }, /* Ni */ - [29] = { 0xBBBB, 0x7777, 0x3333 }, /* Cu */ - [34] = { 0xFFFF, 0xAAAA, 0x1111 }, /* Se */ - [35] = { 0xAAAA, 0x4444, 0x0000 }, /* Br */ - [36] = { 0xAAAA, 0xFFFF, 0xFFFF }, /* Kr */ - [46] = { 0x0000, 0x6666, 0x7777 }, /* Pd */ - [47] = { 0xAAAA, 0xAAAA, 0xAAAA }, /* Ag */ - [53] = { 0xAAAA, 0x0000, 0xFFFF }, /* I */ - [54] = { 0xAAAA, 0xFFFF, 0xFFFF }, /* Xe */ - [78] = { 0x3333, 0x9999, 0xDDDD }, /* Pt */ - [79] = { 0xFFFF, 0xCCCC, 0x0000 }, /* Au */ + [ 0] = {0x9999, 0x9999, 0x9999}, + [ 1] = {0xBFFF, 0xBFFF, 0xBFFF}, /* H */ + [ 2] = {0xAAAA, 0xFFFF, 0xFFFF}, /* He */ + [ 6] = {0x5FFF, 0x5FFF, 0x5FFF}, /* C */ + [ 5] = {0xFFFF, 0xDDDD, 0xFFFF}, /* P */ + [ 7] = {0x1FFF, 0x1FFF, 0xBFFF}, /* N */ + [ 8] = {0xBFFF, 0x1FFF, 0x1FFF}, /* O */ + [ 9] = {0xF500, 0xFFFF, 0x8500}, /* F */ + [ 10] = {0xAAAA, 0xFFFF, 0xFFFF}, /* Ne */ + [ 14] = {0x5FFF, 0x5FFF, 0x5FFF}, /* Si */ + [ 15] = {0xFFFF, 0xCCCC, 0x9999}, /* P */ + [ 16] = {0xFFFF, 0xEEEE, 0x1111}, /* S */ + [ 17] = {0xCCCC, 0xFFFF, 0x9999}, /* Cl */ + [ 18] = {0xAAAA, 0xFFFF, 0xFFFF}, /* Ar */ + [ 28] = {0x9999, 0x5555, 0xFFFF}, /* Ni */ + [ 29] = {0xBBBB, 0x7777, 0x3333}, /* Cu */ + [ 34] = {0xFFFF, 0xAAAA, 0x1111}, /* Se */ + [ 35] = {0xAAAA, 0x4444, 0x0000}, /* Br */ + [ 36] = {0xAAAA, 0xFFFF, 0xFFFF}, /* Kr */ + [ 46] = {0x0000, 0x6666, 0x7777}, /* Pd */ + [ 47] = {0xAAAA, 0xAAAA, 0xAAAA}, /* Ag */ + [ 53] = {0xAAAA, 0x0000, 0xFFFF}, /* I */ + [ 54] = {0xAAAA, 0xFFFF, 0xFFFF}, /* Xe */ + [ 78] = {0x3333, 0x9999, 0xDDDD}, /* Pt */ + [ 79] = {0xFFFF, 0xCCCC, 0x0000}, /* Au */ diff --git a/src/sym/pointgroup.c b/src/sym/pointgroup.c index e423460..dcfd38a 100644 --- a/src/sym/pointgroup.c +++ b/src/sym/pointgroup.c @@ -1,739 +1,605 @@ #include "sym.h" -static inline molsym * -alloc_molsym (int a, int mssize) -{ - size_t r_size = sizeof (double) * mssize * 3; - size_t o_size = sizeof (int) * mssize; - size_t e_size = sizeof (elsym) * mssize; - molsym *ms = calloc (sizeof (molsym) + e_size + o_size + r_size, 1); - if (!ms) - GOTOHELL; - ms->r = (double *)(ms + 1); - ms->o = (int *)MEM_END (ms, r); // cppcheck-suppress invalidPointerCast - ms->e = (elsym *)MEM_END (ms, o); +static inline molsym * alloc_molsym(int a, int mssize){ + size_t r_size = sizeof(double) * mssize*3; + size_t o_size = sizeof(int ) * mssize; + size_t e_size = sizeof(elsym ) * mssize; + molsym * ms = calloc(sizeof(molsym)+ e_size + o_size + r_size, 1); + if(!ms) GOTOHELL; + ms->r = (double *) (ms+1); + ms->o = (int *) MEM_END(ms,r); // cppcheck-suppress invalidPointerCast + ms->e = (elsym *) MEM_END(ms,o); ms->a = a; return ms; } -static inline int -isnew (int N, const double *R, const double r[3], double eps2) -{ - for (int i = 0; i < N; i++) - { - double t = fabs (r3d2 (R + i * 3, r)); - if (t < eps2) - { - return 0; - } +static inline int isnew(int N, const double * R, const double r[3], double eps2){ + for(int i=0; in; j++) - { - r3mx (r, m->r + 3 * j, R); - if (isnew (m->n, m->r, r, eps2)) - { - break; - } - } - if (j == m->n) - { - return 1; - } - else - { - return 0; + for(j=0; jn; j++){ + r3mx (r, m->r+3*j, R); + if(isnew(m->n, m->r, r, eps2)){ + break; } + } + if(j==m->n){ + return 1; + } + else{ + return 0; + } } -static inline int -isc5 (const mol *m, const double u[3], double eps2) -{ +static inline int isc5(const mol * m, const double u[3], double eps2){ double R[9]; - rotmx (R, u, 0.4 * M_PI); - return iscn (m, R, eps2); + rotmx(R, u, 0.4*M_PI); + return iscn(m, R, eps2); } -static inline int -isc4 (const mol *m, const double u[3], double eps2) -{ +static inline int isc4(const mol * m, const double u[3], double eps2){ double R[9]; - rotmx (R, u, M_PI_2); - return iscn (m, R, eps2); + rotmx(R, u, M_PI_2); + return iscn(m, R, eps2); } -static inline int -isc3 (const mol *m, const double u[3], double eps2) -{ - const double s = sqrt (3.0) * 0.5; - double R[9] = { -0.5 + u[0] * u[0] * 1.5, -u[2] * s + u[0] * u[1] * 1.5, - u[1] * s + u[0] * u[2] * 1.5, u[2] * s + u[0] * u[1] * 1.5, - -0.5 + u[1] * u[1] * 1.5, -u[0] * s + u[1] * u[2] * 1.5, - -u[1] * s + u[0] * u[2] * 1.5, u[0] * s + u[1] * u[2] * 1.5, - -0.5 + u[2] * u[2] * 1.5 }; - return iscn (m, R, eps2); +static inline int isc3(const mol * m, const double u[3], double eps2){ + const double s = sqrt(3.0)*0.5; + double R[9] = {-0.5 + u[0]*u[0]*1.5, -u[2]*s + u[0]*u[1]*1.5, u[1]*s + u[0]*u[2]*1.5, + u[2]*s + u[0]*u[1]*1.5, -0.5 + u[1]*u[1]*1.5, -u[0]*s + u[1]*u[2]*1.5, + -u[1]*s + u[0]*u[2]*1.5, u[0]*s + u[1]*u[2]*1.5, -0.5 + u[2]*u[2]*1.5 }; + return iscn(m, R, eps2); } -static inline int -isc2 (const mol *m, const double u[3], double eps2) -{ - double R[9] = { 2.0 * u[0] * u[0] - 1.0, 2.0 * u[0] * u[1], - 2.0 * u[0] * u[2], 2.0 * u[0] * u[1], - 2.0 * u[1] * u[1] - 1.0, 2.0 * u[1] * u[2], - 2.0 * u[0] * u[2], 2.0 * u[1] * u[2], - 2.0 * u[2] * u[2] - 1.0 }; - return iscn (m, R, eps2); +static inline int isc2(const mol * m, const double u[3], double eps2){ + double R[9] = {2.0*u[0]*u[0]-1.0, 2.0*u[0]*u[1], 2.0*u[0]*u[2], + 2.0*u[0]*u[1], 2.0*u[1]*u[1]-1.0, 2.0*u[1]*u[2], + 2.0*u[0]*u[2], 2.0*u[1]*u[2], 2.0*u[2]*u[2]-1.0}; + return iscn(m, R, eps2); } -static void -issigma (const mol *m, const molsym *ms, const double a[3], int S, double eps2) -{ +static void issigma(const mol * m, const molsym * ms, const double a[3], int S, double eps2){ double r[3]; int j; - for (j = 0; j < m->n; j++) - { - r3cp (r, m->r + j * 3); - double t = r3dot (r, a); - if (fabs (t) < eps2) - { - continue; - } - r3adds (r, a, -2.0 * t); - if (isnew (m->n, m->r, r, eps2)) - { - break; - } + for(j=0; jn; j++){ + r3cp(r, m->r+j*3); + double t = r3dot(r, a); + if(fabs(t)n) - { - ms->o[S] = 2; - r3cp (ms->r + S * 3, a); + r3adds(r, a, -2.0*t); + if(isnew(m->n, m->r, r, eps2)){ + break; } + } + if(j==m->n){ + ms->o[S] = 2; + r3cp(ms->r+S*3, a); + } return; } -static inline void -r3perp (double u[3], const double v[3], double eps) -{ - if ((fabs (v[0]) < eps) && (fabs (v[1]) < eps)) - { - uv100 (u); - } - else - { - u[0] = v[1]; - u[1] = -v[0]; - u[2] = 0.0; - } +static inline void r3perp(double u[3], const double v[3], double eps){ + if((fabs(v[0])n; i++) - { - for (int j = i + 1; j < m->n; j++) - { - for (int k = j + 1; k < m->n; k++) - { - double a[3], b[3], h[3]; - r3diff (a, m->r + 3 * i, m->r + 3 * j); - r3diff (b, m->r + 3 * k, m->r + 3 * j); - r3x (h, a, b); - double t = r3dot (h, h); - if (t < eps2) - { - continue; - } - double d[3]; - double dm[2]; - d[0] = r3dot (a, a); - d[1] = r3dot (b, b); - d[2] = r3d2 (a, b); - sort3 (d, dm); - double s = sqrt (dm[1]) - sqrt (dm[0]); - if (s * s > eps2) - { - continue; - } - if (!isnewaxis (n, axis, h, eps2)) - { - continue; - } - r3scal (h, 1.0 / sqrt (t)); - p = isc3 (m, h, eps2); - if (p) - { - if (n >= 10) - { // bad - return n + 1; - } - r3cp (axis + n * 3, h); - n++; - } - } +static int findc3(const mol * m, double axis[30], double eps2){ + int p=0, n=0; + for(int i=0; in; i++){ + for(int j=i+1; jn; j++){ + for(int k=j+1; kn; k++){ + double a[3], b[3], h[3]; + r3diff(a, m->r+3*i, m->r+3*j); + r3diff(b, m->r+3*k, m->r+3*j); + r3x(h,a,b); + double t = r3dot(h,h); + if(t eps2){ + continue; + } + if(!isnewaxis(n, axis, h, eps2)){ + continue; + } + r3scal(h, 1.0/sqrt(t)); + p = isc3(m, h, eps2); + if(p){ + if(n>=10){ // bad + return n+1; + } + r3cp(axis+n*3, h); + n++; } + } } + } return n; } -static int -findc2inI (const mol *m, const double c3[30], double c2[3], double eps2) -{ - for (int i = 0; i < 10; i++) - { - for (int j = 0; j < 10; j++) - { - int mi, mj; - for (mi = -1; mi < 2; mi += 2) - { - for (mj = -1; mj < 2; mj += 2) - { - double ci[3], cj[3]; - r3cpsc (ci, c3 + 3 * i, mi); - r3cpsc (cj, c3 + 3 * j, mj); - r3sum (c2, ci, cj); - r3scal (c2, 1.0 / sqrt (r3dot (c2, c2))); - int p = isc2 (m, c2, eps2); - if (p) - { - return p; - } - } - } +static int findc2inI(const mol * m, const double c3[30], double c2[3], double eps2){ + for(int i=0; i<10; i++){ + for(int j=0; j<10; j++){ + int mi, mj; + for(mi=-1; mi<2; mi+=2){ + for(mj=-1; mj<2; mj+=2){ + double ci[3], cj[3]; + r3cpsc(ci, c3+3*i, mi); + r3cpsc(cj, c3+3*j, mj); + r3sum(c2, ci, cj); + r3scal(c2, 1.0/sqrt(r3dot(c2,c2))); + int p = isc2(m, c2, eps2); + if(p){ + return p; + } } + } } + } return 0; } -static void -findc2 (const mol *m, molsym *ms, int Cn, int C2, double eps2) -{ - - double *mainaxis = ms->r + Cn * 3; - double testaxis[3]; - r3perp (testaxis, mainaxis, EPS1); - - int stesp = PISTEPS / ms->o[Cn]; - double sector = M_PI / ms->o[Cn]; - double dphi = sector / (stesp + 1); - - for (int i = 0; i < stesp; i++) - { - double rot[9]; - double newtestaxis[3]; - rotmx (rot, mainaxis, dphi * i); - r3mx (newtestaxis, testaxis, rot); - int p = isc2 (m, newtestaxis, eps2); - if (p) - { - ms->o[C2] = 2; - r3cp (ms->r + C2 * 3, newtestaxis); - break; - } +static void findc2(const mol * m, molsym * ms, int Cn, int C2, double eps2){ + + double * mainaxis = ms->r+Cn*3; + double testaxis[3]; + r3perp(testaxis, mainaxis, EPS1); + + int stesp = PISTEPS / ms->o[Cn]; + double sector = M_PI / ms->o[Cn]; + double dphi = sector/(stesp+1); + + for(int i=0; io[C2] = 2; + r3cp(ms->r+C2*3, newtestaxis); + break; } + } return; } -static void -findsigmav (const mol *m, molsym *ms, int Cn, int C2, double eps2) -{ - - double *mainaxis = ms->r + Cn * 3; - double testaxis[3]; - r3perp (testaxis, mainaxis, EPS1); - - int stesp = PISTEPS / ms->o[Cn]; - double sector = M_PI / ms->o[Cn]; - double dphi = sector / (stesp + 1); - - for (int i = 0; i < stesp; i++) - { - double rot[9]; - double newtestaxis[3]; - rotmx (rot, mainaxis, dphi * i); - r3mx (newtestaxis, testaxis, rot); - issigma (m, ms, newtestaxis, C2, eps2); - if (ms->o[C2]) - { - break; - } +static void findsigmav(const mol * m, molsym * ms, int Cn, int C2, double eps2){ + + double * mainaxis = ms->r+Cn*3; + double testaxis[3]; + r3perp(testaxis, mainaxis, EPS1); + + int stesp = PISTEPS / ms->o[Cn]; + double sector = M_PI / ms->o[Cn]; + double dphi = sector/(stesp+1); + + for(int i=0; io[C2]){ + break; } + } return; } -static void -issn (const mol *m, molsym *ms, int n, double eps2) -{ - double *u = ms->r + n * 3; +static void issn(const mol * m, molsym * ms, int n, double eps2){ + double * u = ms->r+n*3; double R[9]; double r[3]; - int j; - rotmx (R, u, M_PI / ms->o[n]); - for (j = 0; j < m->n; j++) - { - r3mx (r, m->r + j * 3, R); - double t = r3dot (r, u); - r3adds (r, u, -2.0 * t); - if (isnew (m->n, m->r, r, eps2)) - { - break; - } - } - if (j == m->n) - { - ms->o[n] *= 2; - ms->e[n] = SN; + int j; + rotmx(R, u, M_PI/ms->o[n]); + for(j=0; jn; j++){ + r3mx (r, m->r+j*3, R); + double t = r3dot(r, u); + r3adds(r, u, -2.0*t); + if(isnew(m->n, m->r, r, eps2)){ + break; } + } + if(j==m->n){ + ms->o[n] *= 2; + ms->e[n] = SN; + } return; } -static void -hascn (const mol *m, molsym *cn, int k, double eps2) -{ - for (int i = MAXCN; i > 1; i--) - { - double f = 2.0 * M_PI / i; - double c = cos (f); - double s = sin (f); - double Rx[9] = { 1.0, 0.0, 0.0, 0.0, c, -s, 0.0, s, c }; - double Ry[9] = { c, 0.0, s, 0.0, 1.0, 0.0, -s, 0.0, c }; - double Rz[9] = { c, -s, 0.0, s, c, 0.0, 0.0, 0.0, 1.0 }; - - if (iscn (m, Rx, eps2)) - { - cn->o[k] = i; - uv100 (cn->r + k * 3); - return; - } - if (iscn (m, Ry, eps2)) - { - cn->o[k] = i; - uv010 (cn->r + k * 3); - return; - } - if (iscn (m, Rz, eps2)) - { - cn->o[k] = i; - uv001 (cn->r + k * 3); - return; - } +static void hascn(const mol * m, molsym * cn, int k, double eps2){ + for(int i=MAXCN; i>1; i--){ + double f = 2.0*M_PI/i; + double c = cos(f); + double s = sin(f); + double Rx[9] = {1.0 , 0.0, 0.0, + 0.0, c , -s , + 0.0, s , c }; + double Ry[9] = { c , 0.0, s , + 0.0, 1.0, 0.0 , + -s , 0.0, c }; + double Rz[9] = { c , -s , 0.0, + s , c , 0.0, + 0.0, 0.0, 1.0 }; + + if(iscn(m, Rx, eps2)) { + cn->o[k] = i; + uv100(cn->r+k*3); + return; + } + if(iscn(m, Ry, eps2)) { + cn->o[k] = i; + uv010(cn->r+k*3); + return; } + if(iscn(m, Rz, eps2)) { + cn->o[k] = i; + uv001(cn->r+k*3); + return; + } + } return; } -static void -hassigma (const mol *m, molsym *cn, int k, double eps2) -{ - int i, j; +static void hassigma(const mol * m, molsym * cn, int k, double eps2){ + int i,j; double r[3]; - for (i = 0; i < 3; i++) - { - for (j = 0; j < m->n; j++) - { - r3cp (r, m->r + j * 3); - r[i] = -r[i]; - if (isnew (m->n, m->r, r, eps2)) - { - break; - } - } - if (j == m->n) - { - cn->o[k] = 2; - switch (i) - { - case 0: - uv100 (cn->r + k * 3); - return; - case 1: - uv010 (cn->r + k * 3); - return; - case 2: - uv001 (cn->r + k * 3); - return; - } - } + for(i=0; i<3; i++){ + for(j=0; jn; j++){ + r3cp(r, m->r+j*3); + r[i] = -r[i]; + if(isnew(m->n, m->r, r, eps2)){ + break; + } + } + if(j==m->n){ + cn->o[k] = 2; + switch(i){ + case 0: uv100(cn->r+k*3); return; + case 1: uv010(cn->r+k*3); return; + case 2: uv001(cn->r+k*3); return; + } } + } return; } -static int -hasinv (const mol *m, double eps2) -{ - for (int i = 0; i < m->n; i++) - { - double r[3]; - r3cpsc (r, m->r + i * 3, -1.0); - if (isnew (m->n, m->r, r, eps2)) - { - return 0; - } +static int hasinv(const mol * m, double eps2){ + for(int i=0; in; i++){ + double r[3]; + r3cpsc(r, m->r+i*3, -1.0); + if(isnew(m->n, m->r, r, eps2)){ + return 0; } + } return 1; } -static int -findc5 (const mol *m, const double c3[30], double c5[3], double eps2) -{ - for (int i = 0; i < 10; i++) - { - for (int j = i + 1; j < 10; j++) - { - for (int k = j + 1; k < 10; k++) - { - double ci[3], cj[3], ck[3]; - int mi, mj, mk; - for (mi = -1; mi < 2; mi += 2) - { - for (mj = -1; mj < 2; mj += 2) - { - for (mk = -1; mk < 2; mk += 2) - { - r3cpsc (ci, c3 + 3 * i, mi); - r3cpsc (cj, c3 + 3 * j, mj); - r3cpsc (ck, c3 + 3 * k, mk); - double a[3], b[3], h[3]; - r3diff (a, ci, cj); - r3diff (b, ck, cj); - r3x (h, a, b); - double t = r3dot (h, h); - if (t < eps2) - { - continue; - } - r3scal (h, 1.0 / sqrt (t)); - int p = isc5 (m, h, eps2); - if (p) - { - r3cp (c5, h); - return p; - } - } - } - } +static int findc5(const mol * m, const double c3[30], double c5[3], double eps2){ + for(int i=0; i<10; i++){ + for(int j=i+1; j<10; j++){ + for(int k=j+1; k<10; k++){ + double ci[3], cj[3], ck[3]; + int mi, mj, mk; + for(mi=-1; mi<2; mi+=2){ + for(mj=-1; mj<2; mj+=2){ + for(mk=-1; mk<2; mk+=2){ + r3cpsc(ci, c3+3*i, mi); + r3cpsc(cj, c3+3*j, mj); + r3cpsc(ck, c3+3*k, mk); + double a[3], b[3], h[3]; + r3diff(a, ci, cj); + r3diff(b, ck, cj); + r3x(h,a,b); + double t = r3dot(h,h); + if(te[(I)], MS->o[(I)], - // MS->r[(I)*3], MS->r[(I)*3+1], MS->r[(I)*3+2]); +#define PRINTSYMEL(MS,I) //printf("\t%d %d %lf %lf %lf\n", MS->e[(I)], MS->o[(I)], MS->r[(I)*3], MS->r[(I)*3+1], MS->r[(I)*3+2]); #define MSSIZE 4 - molsym *ms = alloc_molsym (m->n, MSSIZE); + molsym * ms = alloc_molsym(m->n, MSSIZE); double d[3]; - position (m, d, 0); + position(m, d, 0); /* Kh, D*h, C*v */ - int dim0 = (d[0] < eps) + (d[1] < eps) + (d[2] < eps); - if (dim0 == 3) - { - snprintf (ms->s, sizeof (styp), "Kh"); + int dim0 = (d[0]s, sizeof(styp), "Kh"); + return ms; + } + if(dim0==1){ + if(hasinv(m, eps2)){ + snprintf(ms->s, sizeof(styp), "D*h"); return ms; } - if (dim0 == 1) - { - if (hasinv (m, eps2)) - { - snprintf (ms->s, sizeof (styp), "D*h"); - return ms; - } - else - { - snprintf (ms->s, sizeof (styp), "C*v"); - return ms; - } + else{ + snprintf(ms->s, sizeof(styp), "C*v"); + return ms; } + } double dm[2]; - sort3 (d, dm); - if ((dm[1] - dm[0]) / dm[0] < eps) - { - double c3[30] = { 0.0 }; - int p = 0; - - double this_eps2 = eps2; - for (int i = 0; i < 16; i++) - { - p = findc3 (m, c3, this_eps2); - if (!((p > 1) && (p != 4) && (p != 10))) - { - break; - } - this_eps2 *= 2.0; - } + sort3(d, dm); + if((dm[1]-dm[0])/dm[0]1)&&(p!=4)&&(p!=10))){ + break; + } + this_eps2 *= 2.0; + } - if (p == 0) - { - PRINT_WARN ("The point group might be T*/O*/I*. Try different " - "'symtol' options\n") - } + if(p==0){ + PRINT_WARN("The point group might be T*/O*/I*. Try different 'symtol' options\n") + } - ms->e[0] = CN; - ms->o[0] = 3; - r3cp (ms->r + 0 * 3, c3 + 0 * 3); - if (p == 4) - { - /* T/Td/Th/O/Oh */ - int q; - double c4[3]; - r3diff (c4, c3 + 0 * 3, c3 + 1 * 3); - r3scal (c4, 1.0 / sqrt (r3dot (c4, c4))); - q = isc4 (m, c4, eps2); - if (q == 0) - { - r3sum (c4, c3 + 0 * 3, c3 + 1 * 3); - r3scal (c4, 1.0 / sqrt (r3dot (c4, c4))); - q = isc4 (m, c4, eps2); - } - if (q != 0) - { - /* O/Oh */ - ms->e[1] = CN; - ms->o[1] = 4; - r3cp (ms->r + 1 * 3, c4); - if (hasinv (m, eps2)) - { - ms->n = 3; - ms->e[2] = INV; - ms->o[2] = 2; - ms->r[2 * 3] = ms->r[2 * 3 + 1] = ms->r[2 * 3 + 2] = 0.0; - snprintf (ms->s, sizeof (styp), "Oh"); - return ms; - } - ms->n = 2; - snprintf (ms->s, sizeof (styp), "O"); - return ms; - } - /* T/Td/Th */ - double c2[3]; - r3diff (c2, c3 + 0 * 3, c3 + 1 * 3); - r3scal (c2, 1.0 / sqrt (r3dot (c2, c2))); - q = isc2 (m, c2, eps2); - if (q == 0) - { - r3sum (c2, c3 + 0 * 3, c3 + 1 * 3); - r3scal (c2, 1.0 / sqrt (r3dot (c2, c2))); - q = isc2 (m, c2, eps2); - } - if (q == 0) - { - snprintf (ms->s, sizeof (styp), "???"); - return ms; - } - ms->e[1] = CN; - ms->o[1] = 2; - r3cp (ms->r + 1 * 3, c2); - - issn (m, ms, 1, eps2); - if (ms->e[1] == SN) - { - ms->n = 2; - snprintf (ms->s, sizeof (styp), "Td"); - return ms; - } - if (hasinv (m, eps2)) - { - ms->n = 3; - ms->e[2] = INV; - ms->o[2] = 2; - ms->r[2 * 3] = ms->r[2 * 3 + 1] = ms->r[2 * 3 + 2] = 0.0; - snprintf (ms->s, sizeof (styp), "Th"); - return ms; - } - ms->n = 2; - snprintf (ms->s, sizeof (styp), "T"); - return ms; - } - else if (p == 10) - { - /* I/Ih */ - double c5[3]; - int q; - q = findc5 (m, c3, c5, eps2); - if (q == 0) - { - snprintf (ms->s, sizeof (styp), "???"); - return ms; - } - double c2[3]; - q = findc2inI (m, c3, c2, eps2); - if (q == 0) - { - snprintf (ms->s, sizeof (styp), "???"); - return ms; - } - ms->e[1] = CN; - ms->o[1] = 5; - r3cp (ms->r + 1 * 3, c5); - ms->e[2] = CN; + ms->e[0] = CN; + ms->o[0] = 3; + r3cp(ms->r+0*3, c3+0*3); + if(p==4){ + /* T/Td/Th/O/Oh */ + int q; + double c4[3]; + r3diff(c4, c3+0*3, c3+1*3); + r3scal(c4, 1.0/sqrt(r3dot(c4,c4))); + q = isc4(m, c4, eps2); + if(q == 0){ + r3sum(c4, c3+0*3, c3+1*3); + r3scal(c4, 1.0/sqrt(r3dot(c4,c4))); + q = isc4(m, c4, eps2); + } + if(q != 0){ + /* O/Oh */ + ms->e[1] = CN; + ms->o[1] = 4; + r3cp(ms->r+1*3, c4); + if(hasinv(m, eps2)){ + ms->n = 3; + ms->e[2] = INV; ms->o[2] = 2; - r3cp (ms->r + 2 * 3, c2); - if (hasinv (m, eps2)) - { - ms->n = 4; - ms->e[3] = INV; - ms->o[3] = 2; - ms->r[3 * 3] = ms->r[3 * 3 + 1] = ms->r[3 * 3 + 2] = 0.0; - snprintf (ms->s, sizeof (styp), "Ih"); - return ms; - } - ms->n = 3; - snprintf (ms->s, sizeof (styp), "I"); + ms->r[2*3] = ms->r[2*3+1] = ms->r[2*3+2] = 0.0; + snprintf(ms->s, sizeof(styp), "Oh"); return ms; } + ms->n = 2; + snprintf(ms->s, sizeof(styp), "O"); + return ms; + } + /* T/Td/Th */ + double c2[3]; + r3diff(c2, c3+0*3, c3+1*3); + r3scal(c2, 1.0/sqrt(r3dot(c2,c2))); + q = isc2(m, c2, eps2); + if(q == 0){ + r3sum(c2, c3+0*3, c3+1*3); + r3scal(c2, 1.0/sqrt(r3dot(c2,c2))); + q = isc2(m, c2, eps2); + } + if(q == 0){ + snprintf(ms->s, sizeof(styp), "???"); + return ms; + } + ms->e[1] = CN; + ms->o[1] = 2; + r3cp(ms->r+1*3, c2); + + issn(m, ms, 1, eps2); + if(ms->e[1]==SN){ + ms->n = 2; + snprintf(ms->s, sizeof(styp), "Td"); + return ms; + } + if(hasinv(m, eps2)){ + ms->n = 3; + ms->e[2] = INV; + ms->o[2] = 2; + ms->r[2*3] = ms->r[2*3+1] = ms->r[2*3+2] = 0.0; + snprintf(ms->s, sizeof(styp), "Th"); + return ms; + } + ms->n = 2; + snprintf(ms->s, sizeof(styp), "T"); + return ms; + } + else if(p == 10){ + /* I/Ih */ + double c5[3]; + int q; + q = findc5(m, c3, c5, eps2); + if(q == 0){ + snprintf(ms->s, sizeof(styp), "???"); + return ms; + } + double c2[3]; + q = findc2inI(m, c3, c2, eps2); + if(q == 0){ + snprintf(ms->s, sizeof(styp), "???"); + return ms; + } + ms->e[1] = CN; + ms->o[1] = 5; + r3cp(ms->r+1*3, c5); + ms->e[2] = CN; + ms->o[2] = 2; + r3cp(ms->r+2*3, c2); + if(hasinv(m, eps2)){ + ms->n = 4; + ms->e[3] = INV; + ms->o[3] = 2; + ms->r[3*3] = ms->r[3*3+1] = ms->r[3*3+2] = 0.0; + snprintf(ms->s, sizeof(styp), "Ih"); + return ms; + } + ms->n = 3; + snprintf(ms->s, sizeof(styp), "I"); + return ms; } + } /* find a rotational axis || one of the principal axes */ ms->e[0] = CN; ms->o[0] = 0; - hascn (m, ms, 0, eps2); - if (ms->o[0]) - { + hascn(m, ms, 0, eps2); + if(ms->o[0]){ + ms->n++; + PRINTSYMEL(ms,0); + /* find C2' perpendicular the principal axis */ + ms->e[1] = CN; + ms->o[1] = 0; + findc2(m, ms, 0, 1, eps2); + if(ms->o[1]){ + /* Dn, Dnh, Dnd */ ms->n++; - PRINTSYMEL (ms, 0); - /* find C2' perpendicular the principal axis */ - ms->e[1] = CN; - ms->o[1] = 0; - findc2 (m, ms, 0, 1, eps2); - if (ms->o[1]) - { - /* Dn, Dnh, Dnd */ - ms->n++; - PRINTSYMEL (ms, 1); - ms->e[2] = SIGMA; - ms->o[2] = 0; - issigma (m, ms, ms->r + 3 * 0, 2, eps2); - if (ms->o[2]) - { - ms->n++; - PRINTSYMEL (ms, 2); - snprintf (ms->s, sizeof (styp), "D%dh", ms->o[0]); - return ms; - } - /* Dn, Dnd */ - ms->e[2] = SIGMA; - ms->o[2] = 0; - if (ms->o[0] % 2) - { - issigma (m, ms, ms->r + 3 * 1, 2, eps2); - } - else - { - double R[9]; - double u[3]; - rotmx (R, ms->r + 0 * 3, 0.5 * M_PI / ms->o[0]); - r3mx (u, ms->r + 1 * 3, R); - issigma (m, ms, u, 2, eps2); - } - if (ms->o[2]) - { - ms->n++; - PRINTSYMEL (ms, 2); - snprintf (ms->s, sizeof (styp), "D%dd", ms->o[0]); - return ms; - } - snprintf (ms->s, sizeof (styp), "D%d", ms->o[0]); - return ms; - } - /* Cn, Cnv, Cnh, S2n */ - ms->e[1] = SIGMA; - ms->o[1] = 0; - issigma (m, ms, ms->r + 3 * 0, 1, eps2); - if (ms->o[1]) - { - ms->n++; - PRINTSYMEL (ms, 1); - snprintf (ms->s, sizeof (styp), "C%dh", ms->o[0]); - return ms; - } - /* Cn, Cnv, S2n */ - ms->e[1] = SIGMA; - ms->o[1] = 0; - findsigmav (m, ms, 0, 1, eps2); - if (ms->o[1]) - { - ms->n++; - PRINTSYMEL (ms, 1); - snprintf (ms->s, sizeof (styp), "C%dv", ms->o[0]); - return ms; - } - /* Cn, S2n */ - issn (m, ms, 0, eps2); - if (ms->e[0] == SN) - { - PRINTSYMEL (ms, 1); - snprintf (ms->s, sizeof (styp), "S%d", ms->o[0]); - return ms; - } - snprintf (ms->s, sizeof (styp), "C%d", ms->o[0]); + PRINTSYMEL(ms,1); + ms->e[2] = SIGMA; + ms->o[2] = 0; + issigma(m, ms, ms->r+3*0, 2, eps2); + if(ms->o[2]){ + ms->n++; + PRINTSYMEL(ms,2); + snprintf(ms->s, sizeof(styp), "D%dh", ms->o[0]); + return ms; + } + /* Dn, Dnd */ + ms->e[2] = SIGMA; + ms->o[2] = 0; + if(ms->o[0]%2){ + issigma(m, ms, ms->r+3*1, 2, eps2); + } + else{ + double R[9]; + double u[3]; + rotmx(R, ms->r+0*3, 0.5*M_PI/ms->o[0]); + r3mx(u, ms->r+1*3, R); + issigma(m, ms, u, 2, eps2); + } + if(ms->o[2]){ + ms->n++; + PRINTSYMEL(ms,2); + snprintf(ms->s, sizeof(styp), "D%dd", ms->o[0]); + return ms; + } + snprintf(ms->s, sizeof(styp), "D%d", ms->o[0]); return ms; } - else - { - /* Cs, Ci, C1 */ - ms->o[0] = 0; - hassigma (m, ms, 0, eps2); - if (ms->o[0]) - { - ms->n = 1; - ms->e[0] = SIGMA; - snprintf (ms->s, sizeof (styp), "Cs"); - return ms; - } - if (hasinv (m, eps2)) - { - ms->n = 1; - ms->e[0] = INV; - ms->o[0] = 2; - ms->r[0] = ms->r[1] = ms->r[2] = 0.0; - snprintf (ms->s, sizeof (styp), "Ci"); - return ms; - } - snprintf (ms->s, sizeof (styp), "C1"); + /* Cn, Cnv, Cnh, S2n */ + ms->e[1] = SIGMA; + ms->o[1] = 0; + issigma(m, ms, ms->r+3*0, 1, eps2); + if(ms->o[1]){ + ms->n++; + PRINTSYMEL(ms,1); + snprintf(ms->s, sizeof(styp), "C%dh", ms->o[0]); + return ms; + } + /* Cn, Cnv, S2n */ + ms->e[1] = SIGMA; + ms->o[1] = 0; + findsigmav(m, ms, 0, 1, eps2); + if(ms->o[1]){ + ms->n++; + PRINTSYMEL(ms,1); + snprintf(ms->s, sizeof(styp), "C%dv", ms->o[0]); + return ms; + } + /* Cn, S2n */ + issn(m, ms, 0, eps2); + if(ms->e[0]==SN){ + PRINTSYMEL(ms,1); + snprintf(ms->s, sizeof(styp), "S%d", ms->o[0]); + return ms; + } + snprintf(ms->s, sizeof(styp), "C%d", ms->o[0]); + return ms; + } + else{ + /* Cs, Ci, C1 */ + ms->o[0] = 0; + hassigma(m, ms, 0, eps2); + if(ms->o[0]){ + ms->n = 1; + ms->e[0] = SIGMA; + snprintf(ms->s, sizeof(styp), "Cs"); return ms; } + if(hasinv(m, eps2)){ + ms->n = 1; + ms->e[0] = INV; + ms->o[0] = 2; + ms->r[0] = ms->r[1] = ms->r[2] = 0.0; + snprintf(ms->s, sizeof(styp), "Ci"); + return ms; + } + snprintf(ms->s, sizeof(styp), "C1"); + return ms; + } } + diff --git a/src/sym/sym.h b/src/sym/sym.h index d75b03b..ab50289 100644 --- a/src/sym/sym.h +++ b/src/sym/sym.h @@ -1,28 +1,22 @@ -#include "3d.h" #include "mol.h" #include "vec3.h" +#include "3d.h" #define EPS1 1e-15 -#define MAXCN 16 +#define MAXCN 16 #define PISTEPS 65536 -typedef enum -{ - INV, - SIGMA, - CN, - SN -} elsym; +typedef enum {INV, SIGMA, CN, SN} elsym; -typedef struct -{ - double *r; // vectors associated with generators - int *o; // orders of generators - elsym *e; // types of generators - styp s; // point group - int a; // number of atoms - int n; // number of group generators +typedef struct { + double * r; // vectors associated with generators + int * o; // orders of generators + elsym * e; // types of generators + styp s; // point group + int a; // number of atoms + int n; // number of group generators } molsym; -molsym *pointgroup (mol *m, double eps); +molsym * pointgroup(mol * m, double eps); + diff --git a/src/v.c b/src/v.c index 7ae1f20..fa126a3 100644 --- a/src/v.c +++ b/src/v.c @@ -1,129 +1,111 @@ #include "v.h" -#include "evr.h" #include "x.h" +#include "evr.h" draw_world_t world; -static void -init_keys (ptf kp[NKP]) -{ - memset (kp, 0, sizeof (ptf) * NKP); -#define ASSIGN_KEY(KEY, ACTION) \ - { \ - kp[XKeysymToKeycode (world.dis, (KEY))] = (ACTION); \ - } - ASSIGN_KEY (XK_Escape, kp_exit); - ASSIGN_KEY (XK_period, kp_pg); - ASSIGN_KEY (XK_1, kp_rl_dec); - ASSIGN_KEY (XK_2, kp_rl_inc); - ASSIGN_KEY (XK_3, kp_r_dec); - ASSIGN_KEY (XK_4, kp_r_inc); - ASSIGN_KEY (XK_0, kp_goto_1st); - ASSIGN_KEY (XK_equal, kp_goto_last); - ASSIGN_KEY (XK_BackSpace, kp_frame_dec); - ASSIGN_KEY (XK_Tab, kp_readmore); - ASSIGN_KEY (XK_q, kp_exit); - ASSIGN_KEY (XK_w, kp_move_u); - ASSIGN_KEY (XK_r, kp_readagain); - ASSIGN_KEY (XK_t, kp_t_toggle); - ASSIGN_KEY (XK_u, kp_printrot); - ASSIGN_KEY (XK_p, kp_print2fig); - ASSIGN_KEY (XK_Return, kp_frame_inc); - ASSIGN_KEY (XK_a, kp_move_l); - ASSIGN_KEY (XK_s, kp_move_d); - ASSIGN_KEY (XK_d, kp_move_r); - ASSIGN_KEY (XK_f, kp_film); - ASSIGN_KEY (XK_j, kp_jump); - ASSIGN_KEY (XK_l, kp_l_toggle); - ASSIGN_KEY (XK_z, kp_print_xyz); - ASSIGN_KEY (XK_x, kp_print); - ASSIGN_KEY (XK_b, kp_b_toggle); - ASSIGN_KEY (XK_n, kp_n_toggle); - ASSIGN_KEY (XK_m, kp_save_pic); - ASSIGN_KEY (XK_End, kp_zoom_out); - ASSIGN_KEY (XK_Up, kp_rotx_r); - ASSIGN_KEY (XK_Page_Up, kp_rotz_l); - ASSIGN_KEY (XK_Left, kp_roty_l); - ASSIGN_KEY (XK_Right, kp_roty_r); - ASSIGN_KEY (XK_Home, kp_zoom_in); - ASSIGN_KEY (XK_Down, kp_rotx_l); - ASSIGN_KEY (XK_Page_Down, kp_rotz_r); - ASSIGN_KEY (XK_Insert, kp_fw_toggle); - ASSIGN_KEY (XK_Delete, kp_bw_toggle); - ASSIGN_KEY (XK_KP_Up, kp_move_u); - ASSIGN_KEY (XK_KP_Left, kp_move_l); - ASSIGN_KEY (XK_KP_Right, kp_move_r); - ASSIGN_KEY (XK_KP_Down, kp_move_d); +static void init_keys(ptf kp[NKP]){ + memset(kp, 0, sizeof(ptf)*NKP); +#define ASSIGN_KEY(KEY, ACTION) { kp[XKeysymToKeycode(world.dis, (KEY))] = (ACTION); } + ASSIGN_KEY( XK_Escape , kp_exit ); + ASSIGN_KEY( XK_period , kp_pg ); + ASSIGN_KEY( XK_1 , kp_rl_dec ); + ASSIGN_KEY( XK_2 , kp_rl_inc ); + ASSIGN_KEY( XK_3 , kp_r_dec ); + ASSIGN_KEY( XK_4 , kp_r_inc ); + ASSIGN_KEY( XK_0 , kp_goto_1st ); + ASSIGN_KEY( XK_equal , kp_goto_last ); + ASSIGN_KEY( XK_BackSpace , kp_frame_dec ); + ASSIGN_KEY( XK_Tab , kp_readmore ); + ASSIGN_KEY( XK_q , kp_exit ); + ASSIGN_KEY( XK_w , kp_move_u ); + ASSIGN_KEY( XK_r , kp_readagain ); + ASSIGN_KEY( XK_t , kp_t_toggle ); + ASSIGN_KEY( XK_u , kp_printrot ); + ASSIGN_KEY( XK_p , kp_print2fig ); + ASSIGN_KEY( XK_Return , kp_frame_inc ); + ASSIGN_KEY( XK_a , kp_move_l ); + ASSIGN_KEY( XK_s , kp_move_d ); + ASSIGN_KEY( XK_d , kp_move_r ); + ASSIGN_KEY( XK_f , kp_film ); + ASSIGN_KEY( XK_j , kp_jump ); + ASSIGN_KEY( XK_l , kp_l_toggle ); + ASSIGN_KEY( XK_z , kp_print_xyz ); + ASSIGN_KEY( XK_x , kp_print ); + ASSIGN_KEY( XK_b , kp_b_toggle ); + ASSIGN_KEY( XK_n , kp_n_toggle ); + ASSIGN_KEY( XK_m , kp_save_pic ); + ASSIGN_KEY( XK_End , kp_zoom_out ); + ASSIGN_KEY( XK_Up , kp_rotx_r ); + ASSIGN_KEY( XK_Page_Up , kp_rotz_l ); + ASSIGN_KEY( XK_Left , kp_roty_l ); + ASSIGN_KEY( XK_Right , kp_roty_r ); + ASSIGN_KEY( XK_Home , kp_zoom_in ); + ASSIGN_KEY( XK_Down , kp_rotx_l ); + ASSIGN_KEY( XK_Page_Down , kp_rotz_r ); + ASSIGN_KEY( XK_Insert , kp_fw_toggle ); + ASSIGN_KEY( XK_Delete , kp_bw_toggle ); + ASSIGN_KEY( XK_KP_Up , kp_move_u ); + ASSIGN_KEY( XK_KP_Left , kp_move_l ); + ASSIGN_KEY( XK_KP_Right , kp_move_r ); + ASSIGN_KEY( XK_KP_Down , kp_move_d ); #undef ASSIGN_KEY return; } -static void -version (FILE *f) -{ +static void version(FILE * f){ // cppcheck-suppress unknownMacro - PRINTOUT (f, "built on "__TIMESTAMP__ - "\n" - "user: " BUILD_USER "\n" - "directory: " BUILD_DIRECTORY "\n" - "commit: " GIT_HASH " (" GIT_BRANCH ")\n" - "\n"); + PRINTOUT(f, "built on "__TIMESTAMP__"\n" + "user: "BUILD_USER"\n" + "directory: "BUILD_DIRECTORY"\n" + "commit: "GIT_HASH" ("GIT_BRANCH")\n" + "\n"); } -int -main (int argc, char *argv[]) -{ +int main (int argc, char * argv[]) { - if (SHOULD_PRINT_MAN (argc)) - { - printman (stderr, argv[0]); - version (stderr); - return 0; - } + if(SHOULD_PRINT_MAN(argc)){ + printman(stderr, argv[0]); + version(stderr); + return 0; + } - /*= Input - * ==================================================================*/ + /*= Input ==================================================================*/ - allpars ap = cli_parse (argc, argv); + allpars ap = cli_parse(argc, argv); - object *ent = READ_FILES (&ap); + object * ent = READ_FILES(&ap); - if (!ent) - { - PRINT_ERR ("no files to read\n"); - return 1; - } + if(!ent){ + PRINT_ERR("no files to read\n"); + return 1; + } - drawpars *dp = &ap.dp; - if (dp->n >= dp->N) - { - dp->n = dp->n % dp->N; - } - else if (dp->n < 0) - { - dp->n = dp->N - ((-dp->n - 1) % dp->N); - } + drawpars * dp = &ap.dp; + if(dp->n >= dp->N){ + dp->n = dp->n%dp->N; + } + else if(dp->n<0){ + dp->n = dp->N-((-dp->n-1)%dp->N); + } - if (dp->ui.gui == GUI_DISABLED) - { - return headless (dp, ent); - } + if(dp->ui.gui==GUI_DISABLED){ + return headless(dp, ent); + } - /*= X11 init - * ===============================================================*/ + /*= X11 init ===============================================================*/ ptf kp[NKP]; - init_x (dp->read.fname, ap.ip.colors); - init_keys (kp); - init_font (ap.ip.fontname); + init_x(dp->read.fname, ap.ip.colors); + init_keys(kp); + init_font(ap.ip.fontname); dp->ui.gui = GUI_TEMP_DISABLED; - wait_for_configure (ent, dp); - run_commands (NULL, ap.ip.on_startup, dp, ent); + wait_for_configure(ent, dp); + run_commands(NULL, ap.ip.on_startup, dp, ent); dp->ui.gui = GUI_ENABLED; - /*= Main loop - * ==============================================================*/ - main_loop (ent, dp, kp); + /*= Main loop ==============================================================*/ + main_loop(ent, dp, kp); return 0; } diff --git a/src/v/ac3_draw.c b/src/v/ac3_draw.c index f765f7f..450b0d4 100644 --- a/src/v/ac3_draw.c +++ b/src/v/ac3_draw.c @@ -2,141 +2,108 @@ #include "x.h" #define EPS 1e-15 -#define BOND_OFFSET \ - 0.666 // bond line starts this fraction of the atom radius away from the atom - // center -#define RESOL_SCALE (128.0 / 768.0) // reference resolution for atom sizes -#define XDRAWSTRING \ - XDrawImageString // change to XDrawString to remove white boxes behind - // atom/bond labels +#define BOND_OFFSET 0.666 // bond line starts this fraction of the atom radius away from the atom center +#define RESOL_SCALE (128.0/768.0) // reference resolution for atom sizes +#define XDRAWSTRING XDrawImageString // change to XDrawString to remove white boxes behind atom/bond labels extern draw_world_t world; -static inline int -getgci (int q) -{ - return abs (q) < NCOLORS ? abs (q) : 0; +static inline int getgci(int q){ + return abs(q)z - ((kzstr *)p2)->z; + d = ((kzstr *)p1)->z - ((kzstr *)p2)->z ; if (d > 0) - return 1; + return 1; else if (d < 0) return -1; else - return 0; + return 0; } -void -ac3_draw (atcoord *ac, rendpars *rend) -{ +void ac3_draw(atcoord * ac, rendpars * rend){ int n = ac->n; - kzstr *kz = malloc (sizeof (kzstr) * n); - int *ks = (rend->bonds > 0) ? malloc (sizeof (int) * n) : NULL; - if (!kz) - GOTOHELL; + kzstr * kz = malloc(sizeof(kzstr)*n); + int * ks = (rend->bonds>0) ? malloc(sizeof(int)*n) : NULL; + if(!kz) GOTOHELL; double resol = world.size * RESOL_SCALE; - double r1 = rend->r * resol * rend->scale; + double r1 = rend->r * resol * rend->scale; - for (int k = 0; k < n; k++) - { - kz[k].k = k; - kz[k].z = ac->r[k * 3 + 2]; - } - qsort (kz, n, sizeof (kzstr), cmpz); - if (rend->bonds > 0) - { - if (!ks) - GOTOHELL; - for (int i = 0; i < n; i++) - { - ks[kz[i].k] = i; - } + for(int k=0; kr[k*3+2]; + } + qsort(kz, n, sizeof(kzstr), cmpz); + if(rend->bonds>0){ + if(!ks) GOTOHELL; + for(int i=0; iq[k]; - int x = SCREEN_X (ac->r[k * 3]); - int y = SCREEN_Y (ac->r[k * 3 + 1]); - double rt = r1 * get_radius (ac->q[k]); - int r = MAX (1, rt); + int k = kz[i].k; + int q = ac->q[k]; + int x = SCREEN_X(ac->r[k*3 ]); + int y = SCREEN_Y(ac->r[k*3+1]); + double rt = r1 * get_radius(ac->q[k]); + int r = MAX(1, rt); - XFillArc (world.dis, world.canv, world.gcc[getgci (q)], x - r, y - r, - 2 * r, 2 * r, 0, 360 * 64); - if (r > 1) - { - XDrawArc (world.dis, world.canv, - q > 0 ? world.gc_black : world.gc_dot[1], x - r, y - r, - 2 * r, 2 * r, 0, 360 * 64); - } + XFillArc (world.dis, world.canv, world.gcc[getgci(q)], x-r, y-r, 2*r, 2*r, 0, 360*64); + if(r>1){ + XDrawArc(world.dis, world.canv, q>0?world.gc_black:world.gc_dot[1], x-r, y-r, 2*r, 2*r, 0, 360*64); + } - if (rend->num == SHOW_NUMBERS) - { - char text[16]; - snprintf (text, sizeof (text), "%d", k + 1); - XDRAWSTRING (world.dis, world.canv, world.gc_black, x, y, text, - strlen (text)); + if(rend->num == SHOW_NUMBERS){ + char text[16]; + snprintf(text, sizeof(text), "%d", k+1); + XDRAWSTRING(world.dis, world.canv, world.gc_black, x, y, text, strlen(text)); + } + else if(rend->num == SHOW_TYPES){ + char text[16]; + const char * s = get_name(q); + s ? snprintf(text, sizeof(text), "%s", s) : snprintf(text, sizeof(text), "%d", q ); + XDRAWSTRING(world.dis, world.canv, world.gc_black, x, y, text, strlen(text)); + } + + if(rend->bonds>0){ + for(int j=k*BONDS_MAX; j<(k+1)*BONDS_MAX; j++){ + int k1 = ac->bonds.a[j]; + if(k1 == -1 ){ + break; } - else if (rend->num == SHOW_TYPES) - { - char text[16]; - const char *s = get_name (q); - s ? snprintf (text, sizeof (text), "%s", s) - : snprintf (text, sizeof (text), "%d", q); - XDRAWSTRING (world.dis, world.canv, world.gc_black, x, y, text, - strlen (text)); + if(i > ks[k1]){ + continue; } - - if (rend->bonds > 0) - { - for (int j = k * BONDS_MAX; j < (k + 1) * BONDS_MAX; j++) - { - int k1 = ac->bonds.a[j]; - if (k1 == -1) - { - break; - } - if (i > ks[k1]) - { - continue; - } - int x1 = SCREEN_X (ac->r[k1 * 3]); - int y1 = SCREEN_Y (ac->r[k1 * 3 + 1]); - int dx = x1 - x; - int dy = y1 - y; - double r2d = dx * dx + dy * dy; - if (r2d < EPS) - { - continue; - } - double dd = BOND_OFFSET * r / sqrt (r2d); - XDrawLine (world.dis, world.canv, world.gc_black, x + dd * dx, - y + dd * dy, x1, y1); - if (rend->bonds == SHOW_LENGTHS) - { - char text[16]; - snprintf (text, sizeof (text), "%.3lf", ac->bonds.r[j]); - XDRAWSTRING (world.dis, world.canv, world.gc_black, - x + dx / 2, y + dy / 2, text, strlen (text)); - } - } + int x1 = SCREEN_X(ac->r[k1*3 ]); + int y1 = SCREEN_Y(ac->r[k1*3+1]); + int dx = x1-x; + int dy = y1-y; + double r2d = dx*dx+dy*dy; + if(r2d < EPS){ + continue; } + double dd = BOND_OFFSET * r / sqrt(r2d); + XDrawLine(world.dis, world.canv, world.gc_black, x+dd*dx, y+dd*dy, x1, y1); + if(rend->bonds==SHOW_LENGTHS){ + char text[16]; + snprintf(text, sizeof(text), "%.3lf", ac->bonds.r[j]); + XDRAWSTRING(world.dis, world.canv, world.gc_black, x+dx/2, y+dy/2, text, strlen(text)); + } + } } - free (kz); - free (ks); + } + free(kz); + free(ks); return; } + diff --git a/src/v/ac3_print.c b/src/v/ac3_print.c index 314cbe4..9b82caf 100644 --- a/src/v/ac3_print.c +++ b/src/v/ac3_print.c @@ -1,127 +1,107 @@ -#include "matrix.h" #include "v.h" +#include "matrix.h" #include "vec3.h" -void -ac3_print (atcoord *ac, rendpars *rend) -{ - PRINTOUT (stdout, "$molecule\ncart\n"); - for (int k = 0; k < ac->n; k++) - { - PRINTOUT (stdout, "%3d % lf % lf % lf", ac->q[k], - rend->xy0[0] + ac->r[k * 3], rend->xy0[1] + ac->r[k * 3 + 1], - ac->r[k * 3 + 2]); - if (rend->bonds > 0) - { - for (int j = 0; j < BONDS_MAX; j++) - { - int k1 = ac->bonds.a[k * BONDS_MAX + j]; - if (k1 == -1) - { - break; - } - PRINTOUT (stdout, "%s%d", j ? "," : " k=", k1 + 1); - } +void ac3_print(atcoord * ac, rendpars * rend){ + PRINTOUT(stdout, "$molecule\ncart\n"); + for(int k=0; kn; k++){ + PRINTOUT(stdout, "%3d % lf % lf % lf", + ac->q[k], + rend->xy0[0] + ac->r[k*3 ], + rend->xy0[1] + ac->r[k*3+1], + ac->r[k*3+2]); + if(rend->bonds>0){ + for(int j=0; jbonds.a[k*BONDS_MAX+j]; + if(k1 == -1 ){ + break; } - PRINTOUT (stdout, "\n"); + PRINTOUT(stdout, "%s%d", j?",":" k=", k1+1); + } } - PRINTOUT (stdout, "$end\n"); + PRINTOUT(stdout, "\n"); + } + PRINTOUT(stdout, "$end\n"); return; } -void -ac3_print_xyz (atcoord *ac, rendpars *rend) -{ - PRINTOUT (stdout, "%d\n", ac->n); - if (ac->cell.boundary == CELL) - { - double C[9]; - mx_multmx (3, 3, 3, C, rend->ac3rmx, ac->cell.rot_to_lab_basis); - PRINTOUT (stdout, "Lattice=\"%lf %lf %lf %lf %lf %lf %lf %lf %lf\"\n", - C[0], C[3], C[6], C[1], C[4], C[7], C[2], C[5], C[8]); - } - else - { - PRINTOUT (stdout, "\n"); - } +void ac3_print_xyz(atcoord * ac, rendpars * rend){ + PRINTOUT(stdout, "%d\n", ac->n); + if(ac->cell.boundary==CELL){ + double C[9]; + mx_multmx(3,3,3, C, rend->ac3rmx, ac->cell.rot_to_lab_basis); + PRINTOUT(stdout, "Lattice=\"%lf %lf %lf %lf %lf %lf %lf %lf %lf\"\n", + C[0], C[3], C[6], + C[1], C[4], C[7], + C[2], C[5], C[8]); + } + else{ + PRINTOUT(stdout, "\n"); + } - for (int k = 0; k < ac->n; k++) - { - const char *s = get_name (ac->q[k]); - int ok = s && s[0]; - if (ok) - { - PRINTOUT (stdout, " %-3s", s); - } - else - { - PRINTOUT (stdout, " %3d", ac->q[k]); - } - PRINTOUT (stdout, " % lf % lf % lf\n", rend->xy0[0] + ac->r[k * 3], - rend->xy0[1] + ac->r[k * 3 + 1], ac->r[k * 3 + 2]); + for(int k=0; kn; k++){ + const char * s = get_name(ac->q[k]); + int ok = s && s[0]; + if(ok){ + PRINTOUT(stdout, " %-3s", s); } + else{ + PRINTOUT(stdout, " %3d", ac->q[k]); + } + PRINTOUT(stdout, " % lf % lf % lf\n", + rend->xy0[0] + ac->r[k*3 ], + rend->xy0[1] + ac->r[k*3+1], + ac->r[k*3+2]); + } return; } -void -ac3_print2fig (atcoord *ac, rendpars *rend) -{ +void ac3_print2fig(atcoord * ac, rendpars * rend){ int n = ac->n; - for (int i = 0; i < n; i++) - { - PRINTOUT (stdout, "atom %3d% 13.7lf% 13.7lf% 13.7lf\n", ac->q[i], - rend->xy0[0] + ac->r[i * 3], rend->xy0[1] + ac->r[i * 3 + 1], - ac->r[i * 3 + 2]); - } + for(int i=0; iq[i], + rend->xy0[0] + ac->r[i*3 ], + rend->xy0[1] + ac->r[i*3+1], + ac->r[i*3+2]); + } - if (ac->cell.boundary == CELL) - { - for (int i = 0; i < 8; i++) - { - double v[3]; - r3mx (v, ac->cell.vertices + 3 * i, rend->ac3rmx); - PRINTOUT (stdout, "atom %3d% 13.7lf% 13.7lf% 13.7lf\n", 0, - rend->xy0[0] + v[0], rend->xy0[1] + v[1], v[2]); - } + if(ac->cell.boundary==CELL){ + for(int i=0; i<8; i++){ + double v[3]; + r3mx(v, ac->cell.vertices+3*i, rend->ac3rmx); + PRINTOUT(stdout, "atom %3d% 13.7lf% 13.7lf% 13.7lf\n", 0, + rend->xy0[0] + v[0], rend->xy0[1] + v[1], v[2]); } + } - if (rend->bonds > 0) - { - for (int k = 0; k < n; k++) - { - for (int j = 0; j < BONDS_MAX; j++) - { - int k1 = ac->bonds.a[k * BONDS_MAX + j]; - if (k1 == -1) - { - break; - } - if (k1 < k) - { - PRINTOUT (stdout, "bond %3d %3d\n", k1 + 1, k + 1); - } - } + if(rend->bonds>0){ + for(int k=0; kbonds.a[k*BONDS_MAX+j]; + if(k1 == -1 ){ + break; + } + if(k1 < k){ + PRINTOUT(stdout, "bond %3d %3d\n", k1+1, k+1); } + } } + } - if (ac->cell.boundary == CELL) - { -#define LINE(I, J) \ - PRINTOUT (stdout, "bond %3d %3d % 3d\n", (J) + n + 1, (I) + n + 1, -1) - for (int i = 0; i < 8; i += 2) - { - LINE (i, i + 1); // || z-axis - } - for (int j = 0; j < 2; j++) - { - for (int i = 0; i < 2; i++) - { - LINE (i * 4 + j, i * 4 + 2 + j); // || y-axis - LINE (i * 2 + j, i * 2 + 4 + j); // || x-axis - } - } -#undef LINE + if(ac->cell.boundary==CELL){ +#define LINE(I,J) PRINTOUT(stdout, "bond %3d %3d % 3d\n", (J)+n+1, (I)+n+1, -1) + for(int i=0; i<8; i+=2){ + LINE(i,i+1); // || z-axis + } + for(int j=0; j<2; j++){ + for(int i=0; i<2; i++){ + LINE(i*4+j, i*4+2+j); // || y-axis + LINE(i*2+j, i*2+4+j); // || x-axis + } } +#undef LINE + } return; } + diff --git a/src/v/ac3_read.c b/src/v/ac3_read.c index b67bf65..12df4b4 100644 --- a/src/v/ac3_read.c +++ b/src/v/ac3_read.c @@ -1,206 +1,162 @@ -#include "matrix.h" #include "v.h" -#include "vec3.h" #include "vecn.h" +#include "vec3.h" +#include "matrix.h" #define EPS_INV 1e-15 -void -mol2cell (atcoord *m) -{ +void mol2cell(atcoord * m){ double rcell[3]; - for (int j = 0; j < m->n; j++) - { - double *r = m->r0 + j * 3; - r3mx (rcell, r, m->cell.rot_to_cell_basis); - for (int i = 0; i < 3; i++) - { - if (rcell[i] < -0.5) - { - rcell[i] += 1.0; - } - else if (rcell[i] > 0.5) - { - rcell[i] -= 1.0; - } - } - r3mx (r, rcell, m->cell.rot_to_lab_basis); - r3cp (m->r + j * 3, r); + for(int j=0; jn; j++){ + double * r = m->r0+j*3; + r3mx(rcell, r, m->cell.rot_to_cell_basis); + for(int i=0; i<3; i++){ + if(rcell[i]<-0.5){ + rcell[i] += 1.0; + } + else if(rcell[i]>0.5){ + rcell[i] -= 1.0; + } } + r3mx(r, rcell, m->cell.rot_to_lab_basis); + r3cp(m->r+j*3, r); + } return; } -static void -cell_fill (cellpars *cell, const double abc[9]) -{ - const double *a = abc + 0; - const double *b = abc + 3; - const double *c = abc + 6; - for (int i = 0; i < 2; i++) - { - for (int j = 0; j < 2; j++) - { - for (int k = 0; k < 2; k++) - { - r3sums3 (cell->vertices + (i * 4 + j * 2 + k) * 3, a, i - 0.5, b, - j - 0.5, c, k - 0.5); - } - } +static void cell_fill(cellpars * cell, const double abc[9]){ + const double * a = abc+0; + const double * b = abc+3; + const double * c = abc+6; + for(int i=0; i<2; i++){ + for(int j=0; j<2; j++){ + for(int k=0; k<2; k++){ + r3sums3(cell->vertices + (i*4+j*2+k)*3, a, i-0.5, b, j-0.5, c, k-0.5); + } } - double rot_to_lab_basis[9] - = { a[0], b[0], c[0], a[1], b[1], c[1], a[2], b[2], c[2] }; - veccp (9, cell->rot_to_lab_basis, rot_to_lab_basis); - mx_id (3, cell->rot_to_cell_basis); - mx_inv (3, 3, cell->rot_to_cell_basis, rot_to_lab_basis, EPS_INV); + } + double rot_to_lab_basis[9] = {a[0], b[0], c[0], + a[1], b[1], c[1], + a[2], b[2], c[2]}; + veccp(9, cell->rot_to_lab_basis, rot_to_lab_basis); + mx_id(3, cell->rot_to_cell_basis); + mx_inv(3, 3, cell->rot_to_cell_basis, rot_to_lab_basis, EPS_INV); cell->boundary = CELL; return; } -atcoord * -atcoord_fill (mol *m0, const render_bonds_t b, const geompars geom, - const double cell[9]) -{ +atcoord * atcoord_fill(mol * m0, const render_bonds_t b, const geompars geom, const double cell[9]){ int n = m0->n; - size_t q_size = sizeof (int) * n; - size_t r_size = sizeof (double) * n * 3; + size_t q_size = sizeof(int ) * n; + size_t r_size = sizeof(double) * n*3; size_t r0_size = r_size; - struct - { - size_t r_size; - size_t a_size; - } bonds = { 0, 0 }; - if (b != DISABLE_BONDS) - { - bonds.a_size = sizeof (int) * n * BONDS_MAX; - bonds.r_size = sizeof (double) * n * BONDS_MAX; - } - size_t size = sizeof (atcoord) + q_size + r_size + r0_size + bonds.a_size - + bonds.r_size; - atcoord *m = calloc (size, 1); - if (!m) - GOTOHELL; - - if (b == DISABLE_BONDS) - { - m->r = (double *)(m + 1); - m->r0 = (double *)MEM_END (m, r); - m->q = (int *)MEM_END (m, r0); // cppcheck-suppress invalidPointerCast - } - else - { - m->r = (double *)(m + 1); - m->r0 = (double *)MEM_END (m, r); - m->bonds.r = (double *)MEM_END (m, r0); - m->q = (int *)MEM_END (m, - bonds.r); // cppcheck-suppress invalidPointerCast - m->bonds.a = (int *)MEM_END (m, q); - } + struct {size_t r_size; size_t a_size;} bonds = {0, 0}; + if(b!=DISABLE_BONDS){ + bonds.a_size = sizeof(int ) * n*BONDS_MAX; + bonds.r_size = sizeof(double) * n*BONDS_MAX; + } + size_t size = sizeof(atcoord) + q_size + r_size + r0_size + bonds.a_size + bonds.r_size; + atcoord * m = calloc(size, 1); + if(!m) GOTOHELL; + + if(b==DISABLE_BONDS){ + m->r = (double *) (m + 1); + m->r0 = (double *) MEM_END(m,r); + m->q = (int *) MEM_END(m,r0); // cppcheck-suppress invalidPointerCast + } + else{ + m->r = (double *) (m + 1); + m->r0 = (double *) MEM_END(m,r); + m->bonds.r = (double *) MEM_END(m,r0); + m->q = (int *) MEM_END(m,bonds.r); // cppcheck-suppress invalidPointerCast + m->bonds.a = (int *) MEM_END(m,q); + } m->n = n; m->fname = m0->name; - for (int i = 0; i < n; i++) - { - m->q[i] = m0->q[i]; - } - veccp (n * 3, m->r, m0->r); + for(int i=0; iq[i] = m0->q[i]; + } + veccp(n*3, m->r, m0->r); - if (geom.bohr) - { - vecscal (n * 3, m->r, BA); - } - if (geom.inertia) - { - // we should not change m0 - position (&((mol){ .n = n, .q = m->q, .r = m->r }), NULL, 1); - } - if (geom.center != NO_CENTER) - { - center_mol (n, m->r, geom.center == CENTER_MASS ? m->q : NULL); - } - veccp (n * 3, m->r0, m->r); + if(geom.bohr){ + vecscal(n*3, m->r, BA); + } + if(geom.inertia){ + // we should not change m0 + position(&((mol){.n=n, .q=m->q, .r=m->r}), NULL, 1); + } + if(geom.center!=NO_CENTER){ + center_mol(n, m->r, geom.center==CENTER_MASS ? m->q : NULL); + } + veccp(n*3, m->r0, m->r); - if (geom.boundary == CELL) - { - cell_fill (&m->cell, geom.cell); - } - else if (geom.boundary == SHELL) - { - m->cell.vertices[0] = geom.shell[0]; - m->cell.vertices[1] = geom.shell[1]; - m->cell.boundary = SHELL; - } - else if (cell && geom.boundary != CELL_DISABLED) - { - cell_fill (&m->cell, cell); - } + if(geom.boundary == CELL){ + cell_fill(&m->cell, geom.cell); + } + else if(geom.boundary == SHELL){ + m->cell.vertices[0] = geom.shell[0]; + m->cell.vertices[1] = geom.shell[1]; + m->cell.boundary = SHELL; + } + else if(cell && geom.boundary!=CELL_DISABLED){ + cell_fill(&m->cell, cell); + } - if (m->cell.boundary == CELL) - { - mol2cell (m); - } + if(m->cell.boundary==CELL){ + mol2cell(m); + } return m; } -atcoord * -ac3_read (readpars read, const render_bonds_t b, const geompars geom, - format_t *format) -{ +atcoord * ac3_read(readpars read, const render_bonds_t b, const geompars geom, format_t * format){ - mol *m = NULL; - FILE *f = read.f; + mol * m = NULL; + FILE * f = read.f; int cell_found = 0; double cell[9] = {}; - switch (*format) - { + switch(*format){ case XYZ: - if ((m = ac3_read_xyz (f, &cell_found, cell))) - { - *format = XYZ; - } + if((m=ac3_read_xyz(f, &cell_found, cell))){ + *format = XYZ; + } break; case IN: - if ((m = ac3_read_in (f))) - { - *format = IN; - } + if((m=ac3_read_in(f))){ + *format = IN; + } break; case OUT: - if ((m = ac3_read_out (f))) - { - *format = OUT; - } + if((m=ac3_read_out(f))){ + *format = OUT; + } break; default: - if ((m = ac3_read_xyz (f, &cell_found, cell))) - { - *format = XYZ; - } - if (!m) - { - if ((m = ac3_read_in (f))) - { - *format = IN; - } + if((m=ac3_read_xyz(f, &cell_found, cell))){ + *format = XYZ; + } + if(!m){ + if((m=ac3_read_in(f))){ + *format = IN; } - if (!m) - { - if ((m = ac3_read_out (f))) - { - *format = OUT; - } + } + if(!m){ + if((m=ac3_read_out(f))){ + *format = OUT; } + } break; - } - if (!m) - { - return NULL; - } + } + if(!m){ + return NULL; + } m->name = read.fname; - atcoord *M = atcoord_fill (m, b, geom, cell_found ? cell : NULL); - free (m); + atcoord * M = atcoord_fill(m, b, geom, cell_found ? cell : NULL); + free(m); return M; } + diff --git a/src/v/ac3_read_in.c b/src/v/ac3_read_in.c index 74f5741..3a3f036 100644 --- a/src/v/ac3_read_in.c +++ b/src/v/ac3_read_in.c @@ -1,195 +1,156 @@ -#include "3d.h" +#include #include "v.h" +#include "3d.h" #include "vec3.h" -#include -int -read_cart_atom (FILE *f, int n, mol *m) -{ +int read_cart_atom(FILE * f, int n, mol * m){ int q; double r[3]; - int res = (fscanf (f, "%d%lf%lf%lf", &q, r, r + 1, r + 2) == 4); - if (res && m) - { - m->q[n] = q; - r3cp (m->r + 3 * n, r); - } + int res = (fscanf(f, "%d%lf%lf%lf", &q, r, r+1, r+2)==4); + if(res && m){ + m->q[n] = q; + r3cp(m->r+3*n, r); + } return res; } -static int -read_z_atom (FILE *f, int n, mol *m) -{ +static int read_z_atom( FILE * f, int n, mol * m){ - int res, q, a, b, c; + int res, q, a, b, c; double R, phi, theta; - switch (n) - { + switch(n){ case 0: - res = (fscanf (f, "%d", &q) == 1); + res = (fscanf(f, "%d", &q) == 1); break; case 1: - res = (fscanf (f, "%d%d%lf", &q, &a, &R) == 3); + res = (fscanf(f, "%d%d%lf", &q, &a, &R) == 3); break; case 2: - res = (fscanf (f, "%d%d%lf%d%lf", &q, &a, &R, &b, &phi) == 5); + res = (fscanf(f, "%d%d%lf%d%lf", &q, &a, &R, &b, &phi) == 5); break; default: - res = (fscanf (f, "%d%d%lf%d%lf%d%lf", &q, &a, &R, &b, &phi, &c, &theta) - == 7); + res = (fscanf(f, "%d%d%lf%d%lf%d%lf", &q, &a, &R, &b, &phi, &c, &theta) == 7); break; - } + } - if (res && m) - { - m->q[n] = q; - res = !zmat2cart (n, m->r + 3 * n, m->r + 3 * (a - 1), - m->r + 3 * (b - 1), m->r + 3 * (c - 1), R, - phi * DEG2RAD, theta * DEG2RAD); - } + if(res && m){ + m->q[n] = q; + res = !zmat2cart(n, m->r+3*n, + m->r+3*(a-1), m->r+3*(b-1), m->r+3*(c-1), + R, phi*DEG2RAD, theta*DEG2RAD); + } return res; } -static inline int -read_atom (FILE *f, int zmat, int n, mol *m) -{ - if (zmat) - { - return read_z_atom (f, n, m); - } - else - { - return read_cart_atom (f, n, m); - } +static inline int read_atom(FILE * f, int zmat, int n, mol * m){ + if(zmat){ + return read_z_atom(f, n, m); + } + else{ + return read_cart_atom(f, n, m); + } } -static int -read_atoms (FILE *f, int zmat, mol *m) -{ +static int read_atoms(FILE * f, int zmat, mol * m){ char s[STRLEN]; int n = 0; - while (fscanf (f, " $%255s", s) != 1) - { - if (fscanf (f, "set =%255s", s) == 1) - { - continue; - } - if (!read_atom (f, zmat, n, m)) - { - return 0; - } - // ignore the rest of the line - int tc; - while ((tc = getc (f)) != '\n') - { - if (tc == EOF) - { - return 0; - } - } - n++; + while (fscanf(f, " $%255s", s) != 1){ + if(fscanf(f, "set =%255s", s)==1){ + continue; } + if(!read_atom(f, zmat, n, m)){ + return 0; + } + // ignore the rest of the line + int tc; + while((tc=getc(f))!='\n'){ + if(tc==EOF){ + return 0; + } + } + n++; + } return n; } -static inline int -strlcmp (const char *const s1, const char *const s2) -{ - return strncmp (s1, s2, MIN (strlen (s1), strlen (s2))); +static inline int strlcmp(const char * const s1, const char * const s2){ + return strncmp(s1, s2, MIN(strlen(s1), strlen(s2))); } -mol * -ac3_read_in (FILE *f) -{ +mol * ac3_read_in(FILE * f){ int bohr = 0; int zmat = 0; char s[STRLEN]; char key[STRLEN]; char val[STRLEN]; - long pos0 = ftell (f); + long pos0 = ftell(f); // find where the molecule begins - while (1) - { - memset (s, '\0', sizeof (s)); - if (!fgets (s, sizeof (s), f)) - { - goto hell; - } - const char *s0 = s; - while (s0[0] && (s0[0] == ' ' || s[0] == '\t')) - { - s0++; - } - if (!strcmp (s0, "$molecule\n")) - { - break; - } + while(1){ + memset(s, '\0', sizeof(s)); + if(!fgets(s, sizeof(s), f)){ + goto hell; + } + const char * s0 = s; + while(s0[0] && (s0[0]==' ' || s[0]=='\t')){ + s0++; + } + if(!strcmp(s0, "$molecule\n")){ + break; } + } // read the keyword block up until cart/zmat - while (fscanf (f, " %255[^$ \n]", s) == 1) - { - for (int i = 0; i < strlen (s); i++) - { - s[i] = tolower (s[i]); - } - if (sscanf (s, "%255[^=]=%255s", key, val) == 2) - { - if (!strlcmp (key, "units")) - { - if (!strlcmp (val, "bohr")) - { - bohr = 1; - } - else if (!strlcmp (val, "angstrom")) - { - bohr = 0; - } - else - { - PRINT_WARN ("Unknown units in '%s'\n", s); - } - } + while (fscanf(f, " %255[^$ \n]", s) == 1) { + for(int i=0; ir, BA); - } + mol * m = alloc_mol(n); + if(!read_atoms(f, zmat, m)){ + // error in zmat conversion + free(m); + goto hell; + } + if(bohr){ + vecscal(3*n, m->r, BA); + } return m; hell: - fseek (f, pos0, SEEK_SET); + fseek(f, pos0, SEEK_SET); return NULL; } diff --git a/src/v/ac3_read_out.c b/src/v/ac3_read_out.c index c2f4073..96365d5 100644 --- a/src/v/ac3_read_out.c +++ b/src/v/ac3_read_out.c @@ -1,49 +1,41 @@ -#include "mol.h" #include "v.h" #include "vec3.h" +#include "mol.h" -mol * -ac3_read_out (FILE *f) -{ +mol * ac3_read_out(FILE * f){ - long pos0 = ftell (f); + long pos0 = ftell(f); // find where the molecule begins char s[STRLEN]; - while (1) - { - if (!fgets (s, sizeof (s), f)) - { - goto hell; - } - if (strstr (s, "Atomic Coordinates:")) - { - break; - } + while(1){ + if(!fgets(s, sizeof(s), f)){ + goto hell; + } + if(strstr(s, "Atomic Coordinates:")){ + break; } + } // count atoms - long pos1 = ftell (f); - int n = 0; - while (read_cart_atom (f, n, NULL)) - { - n++; - } - if (!n) - { - goto hell; - } - fseek (f, pos1, SEEK_SET); + long pos1 = ftell(f); + int n=0; + while(read_cart_atom(f, n, NULL)){ + n++; + } + if(!n){ + goto hell; + } + fseek(f, pos1, SEEK_SET); // fill in - mol *m = alloc_mol (n); - for (int i = 0; i < n; i++) - { - read_cart_atom (f, i, m); - } + mol * m = alloc_mol(n); + for(int i=0; ir + 3 * i, m->r + 3 * i + 1, - m->r + 3 * i + 2) - != 4) - { - free (m); - return NULL; - } - m->q[i] = get_element (type); + mol * m = alloc_mol(n); + for(int i=0; ir+3*i, m->r+3*i+1, m->r+3*i+2) != 4){ + free(m); + return NULL; + } + m->q[i] = get_element(type); - if (eat_line (f)) - { - free (m); - return NULL; - } + if(eat_line(f)){ + free(m); + return NULL; } + } return m; } diff --git a/src/v/bonds.c b/src/v/bonds.c index 7713aee..6a92563 100644 --- a/src/v/bonds.c +++ b/src/v/bonds.c @@ -1,238 +1,189 @@ #include "v.h" #include "vec3.h" -#define DMAX_SCALE 2.01 // look for bonds within max. atom diameter + eps -#define boxnumber(BOX, NB) (BOX[0] * NB[1] * NB[2] + BOX[1] * NB[2] + BOX[2]) +#define DMAX_SCALE 2.01 // look for bonds within max. atom diameter + eps +#define boxnumber(BOX,NB) (BOX[0]*NB[1]*NB[2] + BOX[1]*NB[2] + BOX[2]) -static int -cmpint (const void *p1, const void *p2) -{ +static int cmpint(const void * p1, const void * p2){ int d = *(int *)p1 - *(int *)p2; if (d > 0) - return 1; + return 1; else if (d < 0) return -1; else - return 0; + return 0; } -static void -makelist (int bsize_max, int *bsize, int *list, double d, const int box_n[3], - const double rmin[3], const atcoord *ac) -{ - - for (int i = 0; i < ac->n; i++) - { - double r[3]; - r3diff (r, ac->r + 3 * i, rmin); - int ind[3]; - ind[0] = r[0] / d; - ind[1] = r[1] / d; - ind[2] = r[2] / d; - int j = boxnumber (ind, box_n); - if (list) - { - list[bsize_max * j + bsize[j]] = i; - } - bsize[j]++; +static void makelist(int bsize_max, int * bsize, int * list, + double d, const int box_n[3], const double rmin[3], const atcoord * ac){ + + for(int i=0; in; i++){ + double r[3]; + r3diff(r, ac->r+3*i, rmin); + int ind[3]; + ind[0] = r[0] / d; + ind[1] = r[1] / d; + ind[2] = r[2] / d; + int j = boxnumber(ind, box_n); + if(list){ + list[ bsize_max*j + bsize[j] ] = i; } + bsize[j]++; + } return; } -static void -bonds_add (bondpars bond, atcoord *ac) -{ +static void bonds_add(bondpars bond, atcoord * ac){ double bmax = bond.bmax; - double rl = bond.rl; - double dmax - = (bmax > 0.0) ? bmax : (DMAX_SCALE * rl * get_maxradius (ac->n, ac->q)); + double rl = bond.rl; + double dmax = (bmax > 0.0) ? bmax : (DMAX_SCALE * rl * get_maxradius(ac->n, ac->q)); double rmin[3], rmax[3]; - r3cp (rmin, ac->r); - r3cp (rmax, ac->r); - for (int i = 1; i < ac->n; i++) - { - rmin[0] = MIN (rmin[0], ac->r[i * 3 + 0]); - rmin[1] = MIN (rmin[1], ac->r[i * 3 + 1]); - rmin[2] = MIN (rmin[2], ac->r[i * 3 + 2]); - rmax[0] = MAX (rmax[0], ac->r[i * 3 + 0]); - rmax[1] = MAX (rmax[1], ac->r[i * 3 + 1]); - rmax[2] = MAX (rmax[2], ac->r[i * 3 + 2]); - } + r3cp(rmin, ac->r); + r3cp(rmax, ac->r); + for(int i=1; in; i++){ + rmin[0] = MIN(rmin[0], ac->r[i*3+0]); + rmin[1] = MIN(rmin[1], ac->r[i*3+1]); + rmin[2] = MIN(rmin[2], ac->r[i*3+2]); + rmax[0] = MAX(rmax[0], ac->r[i*3+0]); + rmax[1] = MAX(rmax[1], ac->r[i*3+1]); + rmax[2] = MAX(rmax[2], ac->r[i*3+2]); + } int box_n[3]; - box_n[0] = (rmax[0] - rmin[0]) / dmax + 1; - box_n[1] = (rmax[1] - rmin[1]) / dmax + 1; - box_n[2] = (rmax[2] - rmin[2]) / dmax + 1; + box_n[0] = (rmax[0]-rmin[0])/dmax + 1; + box_n[1] = (rmax[1]-rmin[1])/dmax + 1; + box_n[2] = (rmax[2]-rmin[2])/dmax + 1; - int nboxes = box_n[0] * box_n[1] * box_n[2]; - int *bsize = calloc (sizeof (int) * nboxes, 1); - if (!bsize) - GOTOHELL; + int nboxes = box_n[0]*box_n[1]*box_n[2]; + int * bsize = calloc(sizeof(int)*nboxes, 1); + if(!bsize) GOTOHELL; - makelist (0, bsize, NULL, dmax, box_n, rmin, ac); + makelist(0, bsize, NULL, dmax, box_n, rmin, ac); int bsize_max = 0; - for (int i = 0; i < nboxes; i++) - { - bsize_max = MAX (bsize_max, bsize[i]); - bsize[i] = 0; - } - int *list = malloc (sizeof (int) * nboxes * bsize_max); - if (!list) - GOTOHELL; + for(int i=0; ibonds.rl > 0.0 - && ac->bonds.a[k1 * BONDS_MAX + BONDS_MAX - 1] != -1) - { - // at the 1st time ac->bond->rl==0.0 - if (!warned) - { - PRINT_WARN ("too many bonds (>= %d)\n", BONDS_MAX); - warned = 1; - } - continue; - } - - for (int l = 0; l < BONDS_MAX; l++) - { - ac->bonds.a[k1 * BONDS_MAX + l] = -1; - } - - int nb = 0; - double r1 = get_radius (ac->q[k1]); - - int b2[3]; - for (b2[0] = b1[0] + bra[0]; b2[0] < b1[0] + ket[0]; b2[0]++) - { - for (b2[1] = b1[1] + bra[1]; b2[1] < b1[1] + ket[1]; - b2[1]++) - { - for (b2[2] = b1[2] + bra[2]; b2[2] < b1[2] + ket[2]; - b2[2]++) - { - int j = boxnumber (b2, box_n); - - for (int jj = 0; jj < bsize[j]; jj++) - { - int k2 = list[bsize_max * j + jj]; - if (k2 == k1) - continue; - - double r2 = get_radius (ac->q[k2]); - double s0 = rl * (r1 + r2); - if (bmax > 0.0) - { - s0 = MIN (s0, bmax); - } - double s2 - = r3d2 (ac->r + k1 * 3, ac->r + k2 * 3); - if (s2 > s0 * s0) - { - continue; - } - if (nb < BONDS_MAX) - { - ac->bonds.a[k1 * BONDS_MAX + nb] = k2; - nb++; - } - else - { - if (!warned) - { - PRINT_WARN ( - "too many bonds (> %d)\n", - BONDS_MAX); - warned = 1; - } - goto toomany; - } - } - } - } - } - toomany: - qsort (ac->bonds.a + k1 * BONDS_MAX, nb, sizeof (int), - cmpint); - for (int l = 0; l < nb; l++) - { - int k2 = ac->bonds.a[k1 * BONDS_MAX + l]; - ac->bonds.r[k1 * BONDS_MAX + l] - = sqrt (r3d2 (ac->r + k1 * 3, ac->r + k2 * 3)); + for(b1[0]=0; b1[0]bonds.rl > 0.0 && ac->bonds.a[k1*BONDS_MAX+BONDS_MAX-1] != -1){ + // at the 1st time ac->bond->rl==0.0 + if(!warned){ + PRINT_WARN("too many bonds (>= %d)\n", BONDS_MAX); + warned = 1; + } + continue; + } + + for(int l=0; lbonds.a[k1*BONDS_MAX+l] = -1; + } + + int nb = 0; + double r1 = get_radius(ac->q[k1]); + + int b2[3]; + for(b2[0]=b1[0]+bra[0]; b2[0]q[k2]); + double s0 = rl * (r1 + r2); + if(bmax > 0.0){ + s0 = MIN(s0, bmax); + } + double s2 = r3d2(ac->r+k1*3, ac->r+k2*3); + if(s2 > s0*s0){ + continue; + } + if(nbbonds.a[k1*BONDS_MAX+nb] = k2; + nb++; + } + else{ + if(!warned){ + PRINT_WARN("too many bonds (> %d)\n", BONDS_MAX); + warned = 1; } + goto toomany; + } } + } } + } +toomany: + qsort(ac->bonds.a+k1*BONDS_MAX, nb, sizeof(int), cmpint); + for(int l=0; lbonds.a[k1*BONDS_MAX+l]; + ac->bonds.r[k1*BONDS_MAX+l] = sqrt(r3d2(ac->r+k1*3, ac->r+k2*3)); + } + } + } } + } - free (list); - free (bsize); + free(list); + free(bsize); return; } -static void -bonds_reduce (bondpars bond, atcoord *ac) -{ - for (int k1 = 0; k1 < ac->n; k1++) - { - double r1 = get_radius (ac->q[k1]); - int nb = 0; - for (int j = 0; j < BONDS_MAX; j++) - { - int k2 = ac->bonds.a[k1 * BONDS_MAX + j]; - if (k2 == -1) - break; - double r = ac->bonds.r[k1 * BONDS_MAX + j]; - double r2 = get_radius (ac->q[k2]); - if (r < bond.rl * (r1 + r2)) - { - ac->bonds.a[k1 * BONDS_MAX + nb] = k2; - ac->bonds.r[k1 * BONDS_MAX + nb] = r; - nb++; - } - } - for (int j = nb; j < BONDS_MAX; j++) - { - ac->bonds.a[k1 * BONDS_MAX + j] = -1; - } +static void bonds_reduce(bondpars bond, atcoord * ac){ + for(int k1=0; k1n; k1++){ + double r1 = get_radius(ac->q[k1]); + int nb = 0; + for(int j=0; jbonds.a[k1*BONDS_MAX+j]; + if(k2==-1) break; + double r = ac->bonds.r[k1*BONDS_MAX+j]; + double r2 = get_radius(ac->q[k2]); + if( r < bond.rl*(r1+r2) ){ + ac->bonds.a[k1*BONDS_MAX+nb] = k2; + ac->bonds.r[k1*BONDS_MAX+nb] = r; + nb++; + } + } + for(int j=nb; jbonds.a[k1*BONDS_MAX+j] = -1; } + } return; } -void -bonds_fill (bondpars bond, atcoord *ac) -{ - if (ac->bonds.flag) - { - return; - } - (bond.rl > ac->bonds.rl) ? bonds_add (bond, ac) : bonds_reduce (bond, ac); +void bonds_fill(bondpars bond, atcoord * ac){ + if(ac->bonds.flag){ + return; + } + (bond.rl > ac->bonds.rl) ? bonds_add(bond, ac) : bonds_reduce(bond, ac); ac->bonds.rl = bond.rl; ac->bonds.flag = 1; return; diff --git a/src/v/cli.c b/src/v/cli.c index 5479171..7e7fbe4 100644 --- a/src/v/cli.c +++ b/src/v/cli.c @@ -1,273 +1,216 @@ -#include "matrix.h" #include "v.h" #include "vecn.h" +#include "matrix.h" #define EPS 1e-15 -static int -lazysscanf (char *const s, const char *const template, char **ret) -{ +static int lazysscanf(char * const s, const char * const template, char ** ret){ // if the string `s` begins with the template, // assign *ret to the part of the string after the template, // otherwise do nothing - int n = strlen (template); - int r = !strncmp (template, s, n); - if (r) - { - if (strlen (s) == n) - { - PRINT_WARN ("option %s needs an argument\n", template) - } - else - { - *ret = s + n; - } + int n = strlen(template); + int r = !strncmp(template, s, n); + if(r){ + if(strlen(s)==n){ + PRINT_WARN("option %s needs an argument\n", template) + } + else{ + *ret = s+n; } + } return r; } -static int -sscan_rot (const char *arg, double ac3rmx[9]) -{ +static int sscan_rot(const char * arg, double ac3rmx[9]){ double rot[9]; - int count - = sscanf (arg, "rot:%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", rot, rot + 1, - rot + 2, rot + 3, rot + 4, rot + 5, rot + 6, rot + 7, rot + 8); - if (count <= 0) - { - return 0; - } - else if (count == 9) - { - veccp (9, ac3rmx, rot); // we don't check if it is unitary - } - else - { - PRINT_WARN ("option `rot:` takes exactly 9 comma-separated arguments\n") - } + int count = sscanf(arg, "rot:%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", rot, rot+1, rot+2, rot+3, rot+4, rot+5, rot+6, rot+7, rot+8); + if(count <= 0){ + return 0; + } + else if(count == 9){ + veccp(9, ac3rmx, rot); // we don't check if it is unitary + } + else{ + PRINT_WARN("option `rot:` takes exactly 9 comma-separated arguments\n") + } return 1; } -static int -sscan_cell (const char *arg, geompars *geom) -{ +static int sscan_cell(const char * arg, geompars * geom){ double cell[9]; - int count = sscanf (arg, "cell:b%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", cell, - cell + 1, cell + 2, cell + 3, cell + 4, cell + 5, - cell + 6, cell + 7, cell + 8); - if (count > 0) - { - if (count == 9 || count == 3 || count == 1) - { - vecscal (count, cell, BA); - } - else - { - PRINT_WARN ("option `cell:b` takes exactly 1, 3 or 9 " - "comma-separated arguments\n") - return 1; - } - } - else - { - count = sscanf (arg, "cell:%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", cell, - cell + 1, cell + 2, cell + 3, cell + 4, cell + 5, - cell + 6, cell + 7, cell + 8); - if (count <= 0) - { - return 0; - } - else if (count != 3 && count != 9 && count != 1) - { - PRINT_WARN ("option `cell:` takes exactly 1, 3, or 9 " - "comma-separated arguments\n") - return 1; - } - } - - double s = 0.0; - for (int i = 0; i < count; i++) - { - s += fabs (cell[i]); + int count = sscanf(arg, "cell:b%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", cell, cell+1, cell+2, cell+3, cell+4, cell+5, cell+6, cell+7, cell+8); + if(count > 0){ + if(count==9 || count==3 || count==1){ + vecscal(count, cell, BA); } - if (s < EPS) - { - geom->boundary = CELL_DISABLED; + else{ + PRINT_WARN("option `cell:b` takes exactly 1, 3 or 9 comma-separated arguments\n") return 1; } - - if (count == 1) - { - geom->cell[0] = cell[0]; - geom->cell[4] = cell[0]; - geom->cell[8] = cell[0]; - } - else if (count == 3) - { - geom->cell[0] = cell[0]; - geom->cell[4] = cell[1]; - geom->cell[8] = cell[2]; + } + else{ + count = sscanf(arg, "cell:%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", cell, cell+1, cell+2, cell+3, cell+4, cell+5, cell+6, cell+7, cell+8); + if(count <= 0){ + return 0; } - else - { - veccp (9, geom->cell, cell); + else if(count!=3 && count!=9 && count!=1){ + PRINT_WARN("option `cell:` takes exactly 1, 3, or 9 comma-separated arguments\n") + return 1; } + } + + double s=0.0; + for(int i=0; iboundary = CELL_DISABLED; + return 1; + } + + if(count==1){ + geom->cell[0] = cell[0]; + geom->cell[4] = cell[0]; + geom->cell[8] = cell[0]; + } + else if(count==3){ + geom->cell[0] = cell[0]; + geom->cell[4] = cell[1]; + geom->cell[8] = cell[2]; + } + else{ + veccp(9, geom->cell, cell); + } geom->boundary = CELL; return 1; } -static int -sscan_shell (const char *arg, geompars *geom) -{ +static int sscan_shell(const char * arg, geompars * geom){ double shell[2]; - int count = sscanf (arg, "shell:b%lf,%lf", shell, shell + 1); - if (count > 0) - { - vecscal (count, shell, BA); - } - else - { - count = sscanf (arg, "shell:%lf,%lf", shell, shell + 1); - } - if (count > 0) - { - geom->shell[0] = shell[0]; - geom->shell[1] = shell[count > 1]; - geom->boundary = SHELL; - return 1; - } - else - { - return 0; - } + int count = sscanf(arg, "shell:b%lf,%lf", shell, shell+1); + if(count > 0){ + vecscal(count, shell, BA); + } + else{ + count = sscanf(arg, "shell:%lf,%lf", shell, shell+1); + } + if(count>0){ + geom->shell[0] = shell[0]; + geom->shell[1] = shell[count>1]; + geom->boundary = SHELL; + return 1; + } + else{ + return 0; + } } -static int -cli_parse_arg (char *arg, allpars *ap) -{ - drawpars *dp = &ap->dp; - initpars *ip = &ap->ip; +static int cli_parse_arg(char * arg, allpars * ap){ + drawpars * dp = &ap->dp; + initpars * ip = &ap->ip; int vib = -1, bonds = -2, frame = 0; double tf = 0, bmax = 0; - char *ts = NULL; - - int cli = sscanf (arg, "vib:%d", &vib) || sscanf (arg, "bonds:%d", &bonds) - || sscanf (arg, "dt:%lf", &tf) || sscanf (arg, "bmax:%lf", &bmax) - || sscanf (arg, "frame:%d", &frame) - || sscanf (arg, "symtol:%lf", &dp->anal.symtol) - || sscanf (arg, "gui:%d", &dp->ui.gui) - || sscanf (arg, "bohr:%d", &dp->geom.bohr) - || sscanf (arg, "center:%d", &dp->geom.center) - || sscanf (arg, "inertia:%d", &dp->geom.inertia) - || sscanf (arg, "z:%d,%d,%d,%d,%d", dp->anal.intcoord, - dp->anal.intcoord + 1, dp->anal.intcoord + 2, - dp->anal.intcoord + 3, dp->anal.intcoord + 4) - || lazysscanf (arg, "font:", &ip->fontname) - || lazysscanf (arg, "com:", &dp->ui.com) - || lazysscanf (arg, "exitcom:", &dp->ui.on_exit) - || lazysscanf (arg, "startcom:", &ip->on_startup) - || lazysscanf (arg, "colors:", &ts) - || sscan_rot (arg, dp->rend.ac3rmx) || sscan_cell (arg, &dp->geom) - || sscan_shell (arg, &dp->geom); - - if (vib == 0) - { - dp->task = AT3COORDS; - } - else if (vib == 1) - { - dp->task = VIBRO; - } - - if (bonds == 0) - { - dp->rend.bonds = DISABLE_BONDS; - } - - if (tf > 0.0) - { - dp->anim.dt = ceil (tf * S_TO_MS); - } - - if (bmax > 0.0) - { - dp->bond.bmax = bmax; - } - - if (frame) - { - dp->n = frame - 1; - } - - if (ts) - { - const char *const colorscheme_names[] - = { [V_COLORS] = "v", [CPK_COLORS] = "cpk" }; - int ncs = sizeof (colorscheme_names) / sizeof (colorscheme_names[0]); - for (int i = 0; i < ncs; i++) - { - int l0 = strlen (colorscheme_names[i]); - int l1 = strlen (ts); - if ((l0 == l1) && (!strncmp (ts, colorscheme_names[i], l0))) - { - ip->colors = i; - break; - } - if (i == ncs - 1) - { - PRINT_WARN ("unknown colorscheme %s. defaulting to %s\n", ts, - colorscheme_names[V_COLORS]); - } - } - } - - if (!cli) - { - ip->input_files[ip->input_files_n++] = arg; - } + char * ts = NULL; + + int cli = + sscanf (arg, "vib:%d", &vib) + || sscanf (arg, "bonds:%d", &bonds) + || sscanf (arg, "dt:%lf", &tf) + || sscanf (arg, "bmax:%lf", &bmax) + || sscanf (arg, "frame:%d", &frame) + || sscanf (arg, "symtol:%lf", &dp->anal.symtol) + || sscanf (arg, "gui:%d", &dp->ui.gui) + || sscanf (arg, "bohr:%d", &dp->geom.bohr) + || sscanf (arg, "center:%d", &dp->geom.center) + || sscanf (arg, "inertia:%d", &dp->geom.inertia) + || sscanf (arg, "z:%d,%d,%d,%d,%d", dp->anal.intcoord, dp->anal.intcoord+1, dp->anal.intcoord+2, dp->anal.intcoord+3, dp->anal.intcoord+4) + || lazysscanf(arg, "font:", &ip->fontname) + || lazysscanf(arg, "com:", &dp->ui.com) + || lazysscanf(arg, "exitcom:", &dp->ui.on_exit) + || lazysscanf(arg, "startcom:", &ip->on_startup) + || lazysscanf(arg, "colors:", &ts) + || sscan_rot (arg, dp->rend.ac3rmx) + || sscan_cell (arg, &dp->geom) + || sscan_shell(arg, &dp->geom) + ; + + if(vib==0){ + dp->task = AT3COORDS; + } + else if(vib==1){ + dp->task = VIBRO; + } + + if(bonds==0){ + dp->rend.bonds = DISABLE_BONDS; + } + + if(tf>0.0){ + dp->anim.dt = ceil(tf*S_TO_MS); + } + + if(bmax>0.0){ + dp->bond.bmax = bmax; + } + + if(frame){ + dp->n = frame-1; + } + + if(ts){ + const char * const colorscheme_names[] = {[V_COLORS] = "v", [CPK_COLORS] = "cpk"}; + int ncs = sizeof(colorscheme_names)/sizeof(colorscheme_names[0]); + for(int i=0; icolors = i; + break; + } + if(i==ncs-1){ + PRINT_WARN("unknown colorscheme %s. defaulting to %s\n", ts, colorscheme_names[V_COLORS]); + } + } + } + + if(!cli){ + ip->input_files[ip->input_files_n++] = arg; + } return cli; } -static allpars -allpars_init (void) -{ - allpars ap = {}; // everything not set below is 0 / 0.0 / NULL / '\0' +static allpars allpars_init(void){ + allpars ap = {}; // everything not set below is 0 / 0.0 / NULL / '\0' ap.ip.colors = V_COLORS; - ap.dp.task = UNKNOWN; - ap.dp.anim.dt = DEFAULT_TIMEOUT; + ap.dp.task = UNKNOWN; + ap.dp.anim.dt = DEFAULT_TIMEOUT; ap.dp.anal.symtol = DEFAULT_SYMTOL; - ap.dp.bond.rl = 1.0; + ap.dp.bond.rl = 1.0; ap.dp.geom.center = CENTER_GEOM; - ap.dp.ui.gui = GUI_ENABLED; + ap.dp.ui.gui = GUI_ENABLED; - ap.dp.rend.r = 1.0; + ap.dp.rend.r = 1.0; ap.dp.rend.scale = 1.0; ap.dp.rend.bonds = SHOW_BONDS; - mx_id (3, ap.dp.rend.ac3rmx); + mx_id(3, ap.dp.rend.ac3rmx); return ap; } -allpars -cli_parse (int argc, char **argv) -{ - allpars ap = allpars_init (); - ap.ip.input_files = malloc (argc * sizeof (char *)); - for (int i = 1; i < argc; i++) - { - cli_parse_arg (argv[i], &ap); - } +allpars cli_parse(int argc, char ** argv){ + allpars ap = allpars_init(); + ap.ip.input_files = malloc(argc*sizeof(char*)); + for(int i=1; itask == AT3COORDS) - { - if (!dp->read.f) - { - PRINT_ERR ("cannot read from the file '%s'\n", dp->read.fname); - return; - } - fseek (dp->read.f, 0, SEEK_CUR); - acs_readmore (dp->read, dp->rend.bonds, dp->geom, ent); - dp->N = ent->n; - exp_redraw (ent, dp); +void kp_readmore(object * ent, drawpars * dp){ + if(dp->task == AT3COORDS){ + if(!dp->read.f){ + PRINT_ERR("cannot read from the file '%s'\n", dp->read.fname); + return; } + fseek(dp->read.f, 0, SEEK_CUR); + acs_readmore(dp->read, dp->rend.bonds, dp->geom, ent); + dp->N = ent->n; + exp_redraw (ent, dp); + } return; } -void -kp_readagain (object *ent, drawpars *dp) -{ - if (dp->task == AT3COORDS) - { - - if (!dp->read.f - || !(fclose (dp->read.f), dp->read.f = fopen (dp->read.fname, "r"))) - { - PRINT_WARN ("cannot reload the file '%s'\n", dp->read.fname); - return; - } - - for (int i = 0; i < ent->n; i++) - { - free (ent->m[i]); - } - ent->n = dp->N = dp->n = 0; - acs_readmore (dp->read, dp->rend.bonds, dp->geom, ent); - dp->N = ent->n; - exp_redraw (ent, dp); +void kp_readagain(object * ent, drawpars * dp){ + if(dp->task == AT3COORDS){ + + if(!dp->read.f || !(fclose(dp->read.f), dp->read.f = fopen(dp->read.fname, "r"))){ + PRINT_WARN("cannot reload the file '%s'\n", dp->read.fname); + return; + } + + for(int i=0; in; i++){ + free(ent->m[i]); } + ent->n = dp->N = dp->n = 0; + acs_readmore(dp->read, dp->rend.bonds, dp->geom, ent); + dp->N = ent->n; + exp_redraw (ent, dp); + } return; } -void -kp_print (object *ent, drawpars *dp) -{ - if (dp->task == AT3COORDS) - { - ac3_print (ent->m[dp->n], &dp->rend); - } +void kp_print(object * ent, drawpars * dp){ + if (dp->task == AT3COORDS){ + ac3_print(ent->m[dp->n], &dp->rend); + } return; } -void -kp_print_xyz (object *ent, drawpars *dp) -{ - if (dp->task == AT3COORDS) - { - ac3_print_xyz (ent->m[dp->n], &dp->rend); - } +void kp_print_xyz(object * ent, drawpars * dp){ + if (dp->task == AT3COORDS){ + ac3_print_xyz(ent->m[dp->n], &dp->rend); + } return; } -void -kp_print2fig (object *ent, drawpars *dp) -{ - if (dp->task == AT3COORDS) - { - ac3_print2fig (ent->m[dp->n], &dp->rend); - } +void kp_print2fig(object * ent, drawpars * dp){ + if (dp->task == AT3COORDS){ + ac3_print2fig(ent->m[dp->n], &dp->rend); + } return; } -void -kp_printrot (object *ent __attribute__ ((unused)), drawpars *dp) -{ - double *U = dp->rend.ac3rmx; - for (int i = 0; i < 3; i++) - { - PRINTOUT (stdout, "rotation> % 20.15lf % 20.15lf % 20.15lf\n", U[i * 3], - U[i * 3 + 1], U[i * 3 + 2]); - } - PRINTOUT (stdout, "rot:%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf\n\n", U[0], U[1], - U[2], U[3], U[4], U[5], U[6], U[7], U[8]); +void kp_printrot(object * ent __attribute__ ((unused)), drawpars * dp){ + double * U = dp->rend.ac3rmx; + for(int i=0; i<3; i++){ + PRINTOUT(stdout, "rotation> % 20.15lf % 20.15lf % 20.15lf\n", U[i*3], U[i*3+1], U[i*3+2]); + } + PRINTOUT(stdout, "rot:%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf\n\n", + U[0], U[1], U[2], U[3], U[4], U[5], U[6], U[7], U[8]); return; } -static void -rl_changed (object *ent, drawpars *dp) -{ - for (int i = 0; i < ent->n; i++) - { - ent->m[i]->bonds.flag = 0; - } - exp_redraw (ent, dp); +static void rl_changed(object * ent, drawpars * dp){ + for(int i=0; in; i++){ + ent->m[i]->bonds.flag = 0; + } + exp_redraw(ent, dp); return; } -void -kp_rl_dec (object *ent, drawpars *dp) -{ - if (dp->rend.bonds > 0) - { - dp->bond.rl /= STEP_R; - rl_changed (ent, dp); - } +void kp_rl_dec(object * ent, drawpars * dp){ + if(dp->rend.bonds>0){ + dp->bond.rl /= STEP_R; + rl_changed(ent, dp); + } return; } -void -kp_rl_inc (object *ent, drawpars *dp) -{ - if (dp->rend.bonds > 0) - { - dp->bond.rl *= STEP_R; - rl_changed (ent, dp); - } +void kp_rl_inc(object * ent, drawpars * dp){ + if(dp->rend.bonds>0){ + dp->bond.rl *= STEP_R; + rl_changed(ent, dp); + } return; } -void -kp_r_dec (object *ent, drawpars *dp) -{ +void kp_r_dec(object * ent, drawpars * dp){ dp->rend.r /= STEP_R; - exp_redraw (ent, dp); + exp_redraw(ent, dp); return; } -void -kp_r_inc (object *ent, drawpars *dp) -{ +void kp_r_inc(object * ent, drawpars * dp){ dp->rend.r *= STEP_R; - exp_redraw (ent, dp); + exp_redraw(ent, dp); return; } -void -kp_zoom_out (object *ent, drawpars *dp) -{ +void kp_zoom_out(object * ent, drawpars * dp){ dp->rend.scale /= STEP_ZOOM; - exp_redraw (ent, dp); + exp_redraw(ent, dp); return; } -void -kp_zoom_in (object *ent, drawpars *dp) -{ +void kp_zoom_in(object * ent, drawpars * dp){ dp->rend.scale *= STEP_ZOOM; - exp_redraw (ent, dp); + exp_redraw(ent, dp); return; } -void -kp_frame_inc (object *ent, drawpars *dp) -{ - if (dp->n < dp->N - 1) - { - dp->n++; - exp_redraw (ent, dp); - } - if (dp->n == dp->N - 1 && dp->task == AT3COORDS) - { - dp->anim.dir = 0; - } +void kp_frame_inc(object * ent, drawpars * dp){ + if (dp->n < dp->N-1){ + dp->n++; + exp_redraw(ent, dp); + } + if (dp->n == dp->N-1 && dp->task == AT3COORDS){ + dp->anim.dir = 0; + } return; } -void -kp_frame_dec (object *ent, drawpars *dp) -{ - if (dp->n > 0) - { - dp->n--; - exp_redraw (ent, dp); - } - if (dp->n == 0 && dp->task == AT3COORDS) - { - dp->anim.dir = 0; - } +void kp_frame_dec(object * ent, drawpars * dp){ + if (dp->n > 0){ + dp->n--; + exp_redraw(ent, dp); + } + if (dp->n == 0 && dp->task == AT3COORDS){ + dp->anim.dir = 0; + } return; } -void -rot_ent_pointer (object *ent, drawpars *dp, int dx, int dy, double speed) -{ +void rot_ent_pointer(object * ent, drawpars * dp, int dx, int dy, double speed){ double mx[9]; - rot_around_perp (mx, (double)dx, (double)dy, speed); - mx3_lmultmx (mx, dp->rend.ac3rmx); - for (int i = 0; i < ent->n; i++) - { - ent->m[i]->rotated = 0; - } + rot_around_perp(mx, (double)dx, (double)dy, speed); + mx3_lmultmx(mx, dp->rend.ac3rmx); + for(int i=0; in; i++){ + ent->m[i]->rotated = 0; + } return; } -static void -rot_ent (object *ent, drawpars *dp, int axis, double angle) -{ - if (dp->ui.modkey) - { - angle *= STEP_MOD; - } - rotmx0_update (dp->rend.ac3rmx, angle, axis); - for (int i = 0; i < ent->n; i++) - { - ent->m[i]->rotated = 0; - } +static void rot_ent(object * ent, drawpars * dp, int axis, double angle){ + if(dp->ui.modkey){ + angle *= STEP_MOD; + } + rotmx0_update(dp->rend.ac3rmx, angle, axis); + for(int i=0; in; i++){ + ent->m[i]->rotated = 0; + } return; } -void -kp_rotx_l (object *ent, drawpars *dp) -{ - rot_ent (ent, dp, 0, +STEP_ROT); - exp_redraw (ent, dp); +void kp_rotx_l(object * ent, drawpars * dp){ + rot_ent(ent, dp, 0, +STEP_ROT); + exp_redraw(ent, dp); return; } -void -kp_rotx_r (object *ent, drawpars *dp) -{ - rot_ent (ent, dp, 0, -STEP_ROT); - exp_redraw (ent, dp); +void kp_rotx_r(object * ent, drawpars * dp){ + rot_ent(ent, dp, 0, -STEP_ROT); + exp_redraw(ent, dp); return; } -void -kp_roty_l (object *ent, drawpars *dp) -{ - rot_ent (ent, dp, 1, +STEP_ROT); - exp_redraw (ent, dp); +void kp_roty_l(object * ent, drawpars * dp){ + rot_ent(ent, dp, 1, +STEP_ROT); + exp_redraw(ent, dp); return; } -void -kp_roty_r (object *ent, drawpars *dp) -{ - rot_ent (ent, dp, 1, -STEP_ROT); - exp_redraw (ent, dp); +void kp_roty_r(object * ent, drawpars * dp){ + rot_ent(ent, dp, 1, -STEP_ROT); + exp_redraw(ent, dp); return; } -void -kp_rotz_l (object *ent, drawpars *dp) -{ - rot_ent (ent, dp, 2, +STEP_ROT); - exp_redraw (ent, dp); +void kp_rotz_l(object * ent, drawpars * dp){ + rot_ent(ent, dp, 2, +STEP_ROT); + exp_redraw(ent, dp); return; } -void -kp_rotz_r (object *ent, drawpars *dp) -{ - rot_ent (ent, dp, 2, -STEP_ROT); - exp_redraw (ent, dp); +void kp_rotz_r(object * ent, drawpars * dp){ + rot_ent(ent, dp, 2, -STEP_ROT); + exp_redraw(ent, dp); return; } -static void -move_pbc (atcoord *m, const drawpars *dp, const double dr[3]) -{ - for (int j = 0; j < m->n; j++) - { - r3add (m->r0 + j * 3, dr); - } - mol2cell (m); +static void move_pbc(atcoord * m, const drawpars * dp, const double dr[3]){ + for(int j=0; jn; j++){ + r3add(m->r0+j*3, dr); + } + mol2cell(m); m->rotated = 0; - if (dp->rend.bonds > 0) - { - m->bonds.flag = 0; - m->bonds.rl *= RL_MOVE_PBC_SCALE; - } + if(dp->rend.bonds>0){ + m->bonds.flag = 0; + m->bonds.rl *= RL_MOVE_PBC_SCALE; + } return; } -static void -move_ent (object *ent, drawpars *dp, int dir, double step) -{ - atcoord *m = ent->m[dp->n]; +static void move_ent(object * ent, drawpars * dp, int dir, double step){ + atcoord * m = ent->m[dp->n]; - if (dp->ui.modkey) - { - step *= STEP_MOD; - } + if(dp->ui.modkey){ + step *= STEP_MOD; + } - if ((dp->task == VIBRO) || (m->cell.boundary != CELL)) - { - dp->rend.xy0[dir] += step; - return; - } + if((dp->task==VIBRO) || (m->cell.boundary != CELL)){ + dp->rend.xy0[dir] += step; + return; + } double dr[3], v[3] = {}; - v[dir] = step; // translation in the view basis - r3mxt (dr, v, dp->rend.ac3rmx); // translation in the mol basis. - // not true if the initial "rotation" from - // CLI is not unitary, but ignore this - - if (dp->geom.boundary == CELL) - { - // all have the same cell -> move together, otherwise move separately - for (int i = 0; i < ent->n; i++) - { - move_pbc (ent->m[i], dp, dr); - } - } - else - { - move_pbc (m, dp, dr); + v[dir] = step; // translation in the view basis + r3mxt(dr, v, dp->rend.ac3rmx); // translation in the mol basis. + // not true if the initial "rotation" from CLI is not unitary, but ignore this + + if(dp->geom.boundary==CELL){ + // all have the same cell -> move together, otherwise move separately + for(int i=0; in; i++){ + move_pbc(ent->m[i], dp, dr); } + } + else{ + move_pbc(m, dp, dr); + } return; } -void -kp_move_l (object *ent, drawpars *dp) -{ - move_ent (ent, dp, 0, -STEP_MOVE); - exp_redraw (ent, dp); +void kp_move_l(object * ent, drawpars * dp){ + move_ent(ent, dp, 0, -STEP_MOVE); + exp_redraw(ent, dp); return; } -void -kp_move_r (object *ent, drawpars *dp) -{ - move_ent (ent, dp, 0, +STEP_MOVE); - exp_redraw (ent, dp); +void kp_move_r(object * ent, drawpars * dp){ + move_ent(ent, dp, 0, +STEP_MOVE); + exp_redraw(ent, dp); return; } -void -kp_move_u (object *ent, drawpars *dp) -{ - move_ent (ent, dp, 1, +STEP_MOVE); - exp_redraw (ent, dp); +void kp_move_u(object * ent, drawpars * dp){ + move_ent(ent, dp, 1, +STEP_MOVE); + exp_redraw(ent, dp); return; } -void -kp_move_d (object *ent, drawpars *dp) -{ - move_ent (ent, dp, 1, -STEP_MOVE); - exp_redraw (ent, dp); +void kp_move_d(object * ent, drawpars * dp){ + move_ent(ent, dp, 1, -STEP_MOVE); + exp_redraw(ent, dp); return; } -void -kp_exit (object *ent, drawpars *dp) -{ - run_commands (NULL, dp->ui.on_exit, dp, ent); - obj_free (ent); - close_x (); - CLOSE0 (dp->read.f); +void kp_exit(object * ent, drawpars * dp){ + run_commands(NULL, dp->ui.on_exit, dp, ent); + obj_free(ent); + close_x(); + CLOSE0(dp->read.f); dp->ui.closed = READY_TO_EXIT; } -void -kp_fw_toggle (object *ent __attribute__ ((unused)), drawpars *dp) -{ +void kp_fw_toggle(object * ent __attribute__ ((unused)), drawpars * dp){ dp->anim.dir = (dp->anim.dir == 1) ? 0 : 1; return; } -void -kp_bw_toggle (object *ent __attribute__ ((unused)), drawpars *dp) -{ - if (dp->task == AT3COORDS) - { - dp->anim.dir = (dp->anim.dir == -1) ? 0 : -1; - } +void kp_bw_toggle(object * ent __attribute__ ((unused)), drawpars * dp){ + if (dp->task == AT3COORDS){ + dp->anim.dir = (dp->anim.dir == -1) ? 0 : -1; + } return; } -void -kp_l_toggle (object *ent, drawpars *dp) -{ - if (dp->rend.bonds > 0) - { - dp->rend.bonds - = dp->rend.bonds == SHOW_BONDS ? SHOW_LENGTHS : SHOW_BONDS; - exp_redraw (ent, dp); - } +void kp_l_toggle(object * ent, drawpars * dp){ + if(dp->rend.bonds>0){ + dp->rend.bonds = dp->rend.bonds==SHOW_BONDS ? SHOW_LENGTHS : SHOW_BONDS; + exp_redraw(ent, dp); + } return; } -void -kp_b_toggle (object *ent, drawpars *dp) -{ - if (dp->rend.bonds != DISABLE_BONDS) - { - dp->rend.bonds = dp->rend.bonds == NO_BONDS ? SHOW_BONDS : NO_BONDS; - exp_redraw (ent, dp); - } +void kp_b_toggle(object * ent, drawpars * dp){ + if(dp->rend.bonds!=DISABLE_BONDS){ + dp->rend.bonds = dp->rend.bonds==NO_BONDS ? SHOW_BONDS : NO_BONDS; + exp_redraw(ent, dp); + } return; } -void -kp_n_toggle (object *ent, drawpars *dp) -{ - dp->rend.num - = (dp->rend.num == SHOW_NUMBERS) ? NO_ATOM_NUMBERS : SHOW_NUMBERS; - exp_redraw (ent, dp); +void kp_n_toggle(object * ent, drawpars * dp){ + dp->rend.num = (dp->rend.num == SHOW_NUMBERS) ? NO_ATOM_NUMBERS : SHOW_NUMBERS; + exp_redraw(ent, dp); return; } -void -kp_t_toggle (object *ent, drawpars *dp) -{ - dp->rend.num = (dp->rend.num == SHOW_TYPES) ? NO_ATOM_NUMBERS : SHOW_TYPES; - exp_redraw (ent, dp); +void kp_t_toggle(object * ent, drawpars * dp){ + dp->rend.num = (dp->rend.num == SHOW_TYPES) ? NO_ATOM_NUMBERS : SHOW_TYPES; + exp_redraw(ent, dp); return; } -void -kp_goto_last (object *ent, drawpars *dp) -{ - if (dp->n < dp->N - 1) - { - dp->n = dp->N - 1; - exp_redraw (ent, dp); - } +void kp_goto_last(object * ent, drawpars * dp){ + if (dp->n < dp->N-1){ + dp->n=dp->N-1; + exp_redraw(ent, dp); + } return; } -void -kp_goto_1st (object *ent, drawpars *dp) -{ - if (dp->n > 0) - { - dp->n = 0; - exp_redraw (ent, dp); - } +void kp_goto_1st(object * ent, drawpars * dp){ + if (dp->n > 0){ + dp->n = 0; + exp_redraw(ent, dp); + } return; } -void -time_gone (object *ent, drawpars *dp) -{ - if (dp->task == VIBRO) - { - if (dp->anim.t >= TMAX) - { - dp->anim.t = dp->anim.t - TMAX; - } - exp_redraw (ent, dp); +void time_gone(object * ent, drawpars * dp){ + if(dp->task == VIBRO){ + if(dp->anim.t >= TMAX){ + dp->anim.t = dp->anim.t-TMAX; } + exp_redraw(ent, dp); + } return; } -static void -savevib (const drawpars *dp, int c) -{ +static void savevib(const drawpars * dp, int c){ char s[STRLEN]; - int l = (int)(log10 (dp->N + 0.5)) + 1; - snprintf (s, sizeof (s), "%s_%0*d_%02d.xpm", dp->read.fname, l, dp->n + 1, - c); - if (save_pic (s)) - { - fprintf (stderr, "%s\n", s); - } - else - { - PRINT_ERR ("cannot save '%s'\n", s); - } + int l = (int)(log10( dp->N + 0.5 )) + 1; + snprintf(s, sizeof(s), "%s_%0*d_%02d.xpm", dp->read.fname, l, dp->n+1, c); + if(save_pic(s)){ + fprintf(stderr, "%s\n", s); + } + else{ + PRINT_ERR("cannot save '%s'\n", s); + } return; } -void -kp_save_pic (object *ent, drawpars *dp) -{ +void kp_save_pic(object * ent, drawpars * dp){ char s[STRLEN]; - int l = (int)(log10 (dp->N + 0.5)) + 1; - const atcoord *m = ent->m[dp->n]; - if (m->cell.boundary == CELL) - { - static int i = 0; - snprintf (s, sizeof (s), "%s_%0*d.%02d.xpm", m->fname, l, dp->n + 1, - i++); - } - else - { - snprintf (s, sizeof (s), "%s_%0*d.xpm", m->fname, l, dp->n + 1); - } - exp_redraw (ent, dp); - if (save_pic (s)) - { - fprintf (stderr, "%s\n", s); - } - else - { - PRINT_ERR ("cannot save '%s'\n", s); - } - return; -} - -void -kp_film (object *ent, drawpars *dp) -{ - if (dp->task != VIBRO) - { - kp_save_pic (ent, dp); - while (dp->n < dp->N - 1) - { - kp_frame_inc (ent, dp); - kp_save_pic (ent, dp); - } - } - else - { - int c = 0; - dp->anim.t = 0; - do - { - exp_redraw (ent, dp); - savevib (dp, c); - dp->anim.t++; - time_gone (ent, dp); - } - while (++c < TMAX); - } - return; -} - -void -kp_pg (object *ent, drawpars *dp) -{ - atcoord *m = ent->m[MOL_IDX (dp)]; - if (!m->sym[0]) - { - pg (m, dp->anal.symtol); - exp_redraw (ent, dp); - } - return; -} - -void -kp_jump (object *ent, drawpars *dp) -{ - if (dp->ui.input == NO_INPUT) - { - dp->ui.input = INPUT_JUMP; - exp_redraw (ent, dp); - } + int l = (int)(log10(dp->N+0.5))+1; + const atcoord * m = ent->m[dp->n]; + if(m->cell.boundary==CELL){ + static int i = 0; + snprintf(s, sizeof(s), "%s_%0*d.%02d.xpm", m->fname, l, dp->n+1, i++); + } + else{ + snprintf(s, sizeof(s), "%s_%0*d.xpm", m->fname, l, dp->n+1); + } + exp_redraw(ent, dp); + if(save_pic(s)){ + fprintf(stderr, "%s\n", s); + } + else{ + PRINT_ERR("cannot save '%s'\n", s); + } + return; +} + +void kp_film(object * ent, drawpars * dp){ + if(dp->task != VIBRO){ + kp_save_pic (ent, dp); + while(dp->nN-1){ + kp_frame_inc(ent, dp); + kp_save_pic (ent, dp); + } + } + else{ + int c = 0; + dp->anim.t = 0; + do{ + exp_redraw(ent, dp); + savevib(dp, c); + dp->anim.t++; + time_gone(ent, dp); + } while(++cm[MOL_IDX(dp)]; + if(!m->sym[0]){ + pg(m, dp->anal.symtol); + exp_redraw(ent, dp); + } + return; +} + +void kp_jump(object * ent, drawpars * dp){ + if(dp->ui.input==NO_INPUT){ + dp->ui.input = INPUT_JUMP; + exp_redraw(ent, dp); + } return; } diff --git a/src/v/evr.h b/src/v/evr.h index 440912e..a9d726a 100644 --- a/src/v/evr.h +++ b/src/v/evr.h @@ -1,75 +1,69 @@ #include "3d.h" #define TMAX 20 -#define VIBR_AMP 0.1 -#define STEP_ROT (M_PI / 90.0) -#define STEP_MOVE 0.2 -#define STEP_ZOOM 1.1 -#define STEP_R 1.1 -#define STEP_MOD 0.03125 +#define VIBR_AMP 0.1 +#define STEP_ROT (M_PI/90.0) +#define STEP_MOVE 0.2 +#define STEP_ZOOM 1.1 +#define STEP_R 1.1 +#define STEP_MOD 0.03125 #define RL_MOVE_PBC_SCALE 0.9 #define MOL_IDX(DP) (DP->task == AT3COORDS ? DP->n : 0) -static inline void -fill_bonds (atcoord *m, const drawpars *dp) -{ - if (dp->rend.bonds > 0) - { - bonds_fill (dp->bond, m); - } +static inline void fill_bonds(atcoord * m, const drawpars * dp){ + if(dp->rend.bonds>0){ + bonds_fill(dp->bond, m); + } return; } -static inline void -rotate_mol (atcoord *m, const drawpars *dp) -{ - if (!m->rotated) - { - rot3d (m->n, m->r, m->r0, dp->rend.ac3rmx); - m->rotated = 1; - } +static inline void rotate_mol(atcoord * m, const drawpars * dp){ + if(!m->rotated){ + rot3d(m->n, m->r, m->r0, dp->rend.ac3rmx); + m->rotated = 1; + } return; } -void kp_readmore (object *ent, drawpars *dp); -void kp_readagain (object *ent, drawpars *dp); -void kp_print (object *ent, drawpars *dp); -void kp_print_xyz (object *ent, drawpars *dp); -void kp_print2fig (object *ent, drawpars *dp); -void kp_printrot (object *ent, drawpars *dp); -void kp_rl_inc (object *ent, drawpars *dp); -void kp_rl_dec (object *ent, drawpars *dp); -void kp_r_inc (object *ent, drawpars *dp); -void kp_r_dec (object *ent, drawpars *dp); -void kp_zoom_out (object *ent, drawpars *dp); -void kp_zoom_in (object *ent, drawpars *dp); -void kp_lat_dec (object *ent, drawpars *dp); -void kp_lat_inc (object *ent, drawpars *dp); -void kp_frame_inc (object *ent, drawpars *dp); -void kp_frame_dec (object *ent, drawpars *dp); -void kp_rotz_l (object *ent, drawpars *dp); -void kp_rotz_r (object *ent, drawpars *dp); -void kp_roty_l (object *ent, drawpars *dp); -void kp_roty_r (object *ent, drawpars *dp); -void kp_rotx_l (object *ent, drawpars *dp); -void kp_rotx_r (object *ent, drawpars *dp); -void kp_move_l (object *ent, drawpars *dp); -void kp_move_r (object *ent, drawpars *dp); -void kp_move_u (object *ent, drawpars *dp); -void kp_move_d (object *ent, drawpars *dp); -void kp_exit (object *ent, drawpars *dp); -void kp_l_toggle (object *ent, drawpars *dp); -void kp_b_toggle (object *ent, drawpars *dp); -void kp_t_toggle (object *ent, drawpars *dp); -void kp_n_toggle (object *ent, drawpars *dp); -void kp_fw_toggle (object *ent, drawpars *dp); -void kp_bw_toggle (object *ent, drawpars *dp); -void kp_goto_last (object *ent, drawpars *dp); -void kp_goto_1st (object *ent, drawpars *dp); -void time_gone (object *ent, drawpars *dp); -void kp_save_pic (object *ent, drawpars *dp); -void kp_film (object *ent, drawpars *dp); -void kp_pg (object *ent, drawpars *dp); -void kp_jump (object *ent, drawpars *dp); -void rot_ent_pointer (object *ent, drawpars *dp, int dx, int dy, double speed); +void kp_readmore (object * ent, drawpars * dp); +void kp_readagain(object * ent, drawpars * dp); +void kp_print (object * ent, drawpars * dp); +void kp_print_xyz(object * ent, drawpars * dp); +void kp_print2fig(object * ent, drawpars * dp); +void kp_printrot (object * ent, drawpars * dp); +void kp_rl_inc (object * ent, drawpars * dp); +void kp_rl_dec (object * ent, drawpars * dp); +void kp_r_inc (object * ent, drawpars * dp); +void kp_r_dec (object * ent, drawpars * dp); +void kp_zoom_out (object * ent, drawpars * dp); +void kp_zoom_in (object * ent, drawpars * dp); +void kp_lat_dec (object * ent, drawpars * dp); +void kp_lat_inc (object * ent, drawpars * dp); +void kp_frame_inc(object * ent, drawpars * dp); +void kp_frame_dec(object * ent, drawpars * dp); +void kp_rotz_l (object * ent, drawpars * dp); +void kp_rotz_r (object * ent, drawpars * dp); +void kp_roty_l (object * ent, drawpars * dp); +void kp_roty_r (object * ent, drawpars * dp); +void kp_rotx_l (object * ent, drawpars * dp); +void kp_rotx_r (object * ent, drawpars * dp); +void kp_move_l (object * ent, drawpars * dp); +void kp_move_r (object * ent, drawpars * dp); +void kp_move_u (object * ent, drawpars * dp); +void kp_move_d (object * ent, drawpars * dp); +void kp_exit (object * ent, drawpars * dp); +void kp_l_toggle (object * ent, drawpars * dp); +void kp_b_toggle (object * ent, drawpars * dp); +void kp_t_toggle (object * ent, drawpars * dp); +void kp_n_toggle (object * ent, drawpars * dp); +void kp_fw_toggle(object * ent, drawpars * dp); +void kp_bw_toggle(object * ent, drawpars * dp); +void kp_goto_last(object * ent, drawpars * dp); +void kp_goto_1st (object * ent, drawpars * dp); +void time_gone (object * ent, drawpars * dp); +void kp_save_pic (object * ent, drawpars * dp); +void kp_film (object * ent, drawpars * dp); +void kp_pg (object * ent, drawpars * dp); +void kp_jump (object * ent, drawpars * dp); +void rot_ent_pointer(object * ent, drawpars * dp, int dx, int dy, double speed); diff --git a/src/v/get_atpar.c b/src/v/get_atpar.c index ab5383d..f731bcc 100644 --- a/src/v/get_atpar.c +++ b/src/v/get_atpar.c @@ -1,74 +1,72 @@ -#include "v.h" #include +#include "v.h" -#define NATOMS 118 -#define NRADII 92 +#define NATOMS 118 +#define NRADII 92 #define NAMELEN 3 -static const double ra[NRADII + 1] - = { 1.0, 0.455, 0.260, 1.885, 1.365, 1.105, 0.910, 0.845, 0.780, 0.650, - 0.520, 2.340, 1.950, 1.625, 1.430, 1.300, 1.300, 1.300, 1.170, 2.860, - 2.340, 2.080, 1.820, 1.755, 1.820, 1.820, 1.820, 1.755, 1.755, 1.755, - 1.755, 1.690, 1.625, 1.495, 1.495, 1.495, 1.300, 3.055, 2.600, 2.340, - 2.015, 1.885, 1.885, 1.755, 1.690, 1.755, 1.820, 2.080, 2.015, 2.015, - 1.885, 1.885, 1.820, 1.820, 1.690, 3.055, 2.574, 2.197, 2.145, 2.145, - 2.132, 2.145, 2.158, 2.405, 2.093, 2.067, 2.067, 2.054, 2.041, 2.028, - 2.210, 2.028, 1.872, 1.742, 1.690, 1.664, 1.638, 1.638, 1.677, 1.742, - 1.872, 2.015, 2.002, 1.976, 1.989, 1.989, 1.950, 3.510, 2.899, 2.431, - 2.314, 2.093, 1.820 }; +static const double ra[NRADII+1] = { + 1.0, + 0.455, 0.260, 1.885, 1.365, 1.105, + 0.910, 0.845, 0.780, 0.650, 0.520, + 2.340, 1.950, 1.625, 1.430, 1.300, + 1.300, 1.300, 1.170, 2.860, 2.340, + 2.080, 1.820, 1.755, 1.820, 1.820, + 1.820, 1.755, 1.755, 1.755, 1.755, + 1.690, 1.625, 1.495, 1.495, 1.495, + 1.300, 3.055, 2.600, 2.340, 2.015, + 1.885, 1.885, 1.755, 1.690, 1.755, + 1.820, 2.080, 2.015, 2.015, 1.885, + 1.885, 1.820, 1.820, 1.690, 3.055, + 2.574, 2.197, 2.145, 2.145, 2.132, + 2.145, 2.158, 2.405, 2.093, 2.067, + 2.067, 2.054, 2.041, 2.028, 2.210, + 2.028, 1.872, 1.742, 1.690, 1.664, + 1.638, 1.638, 1.677, 1.742, 1.872, + 2.015, 2.002, 1.976, 1.989, 1.989, + 1.950, 3.510, 2.899, 2.431, 2.314, + 2.093, 1.820 +}; -static const char aname[NATOMS + 1][NAMELEN] = { -#include "elements.h" +static const char aname[NATOMS+1][NAMELEN]={ + #include "elements.h" }; -double -get_radius (int q) -{ - q = abs (q); - return ra[q <= NRADII ? q : (q <= NATOMS ? NRADII : 0)]; +double get_radius(int q){ + q = abs(q); + return ra[ q<=NRADII ? q : ( q<=NATOMS? NRADII : 0) ]; } -double -get_maxradius (int n, const int *q) -{ +double get_maxradius(int n, const int * q){ double r = 0.0; - for (int i = 0; i < n; i++) - { - r = MAX (r, get_radius (q[i])); - } + for(int i=0; iui.gui != GUI_DISABLED) - { - int gui = dp->ui.gui; - dp->ui.gui = GUI_ENABLED; - switch (c) - { - case ('f'): - kp_film (ent, dp); - break; - case ('m'): - kp_save_pic (ent, dp); - break; - } - dp->ui.gui = gui; - } - else - { - PRINT_WARN ("Ignoring command `%c` in the headless mode\n", c); +static void run_with_gui(char c, drawpars * dp, object * ent){ + if(dp->ui.gui!=GUI_DISABLED){ + int gui = dp->ui.gui; + dp->ui.gui = GUI_ENABLED; + switch(c){ + case('f'): + kp_film(ent, dp); break; + case('m'): + kp_save_pic(ent, dp); break; } + dp->ui.gui = gui; + } + else{ + PRINT_WARN("Ignoring command `%c` in the headless mode\n", c); \ + } return; } -static void -run_command (char c, drawpars *dp, object *ent) -{ - switch (c) - { - case ('>'): - kp_fw_toggle (ent, dp); - break; - case ('d'): - kp_move_r (ent, dp); - break; - case ('a'): - kp_move_l (ent, dp); - break; - case ('w'): - kp_move_u (ent, dp); - break; - case ('s'): - kp_move_d (ent, dp); - break; - case ('1'): - kp_rl_dec (ent, dp); - break; - case ('2'): - kp_rl_inc (ent, dp); - break; - case ('3'): - kp_r_dec (ent, dp); - break; - case ('4'): - kp_r_inc (ent, dp); - break; - case ('l'): - kp_l_toggle (ent, dp); - break; - case ('b'): - kp_b_toggle (ent, dp); - break; - case ('t'): - kp_t_toggle (ent, dp); - break; - case ('n'): - kp_n_toggle (ent, dp); - break; - case ('+'): - kp_zoom_in (ent, dp); - break; - case ('-'): - kp_zoom_out (ent, dp); - break; +static void run_command(char c, drawpars * dp, object * ent){ + switch(c){ + case('>'): + kp_fw_toggle(ent, dp); break; + case('d'): + kp_move_r(ent, dp); break; + case('a'): + kp_move_l(ent, dp); break; + case('w'): + kp_move_u(ent, dp); break; + case('s'): + kp_move_d(ent, dp); break; + case('1'): + kp_rl_dec(ent, dp); break; + case('2'): + kp_rl_inc(ent, dp); break; + case('3'): + kp_r_dec(ent, dp); break; + case('4'): + kp_r_inc(ent, dp); break; + case('l'): + kp_l_toggle(ent, dp); break; + case('b'): + kp_b_toggle(ent, dp); break; + case('t'): + kp_t_toggle(ent, dp); break; + case('n'): + kp_n_toggle(ent, dp); break; + case('+'): + kp_zoom_in(ent, dp); break; + case('-'): + kp_zoom_out(ent, dp); break; - case ('f'): - case ('m'): - run_with_gui (c, dp, ent); - break; + case('f'): + case('m'): + run_with_gui(c, dp, ent); break; - case ('q'): - dp->ui.closed = MUST_CLEANUP; - break; + case('q'): + dp->ui.closed = MUST_CLEANUP; break; - case ('p'): - kp_print2fig (ent, dp); - break; - case ('z'): - kp_print_xyz (ent, dp); - break; - case ('x'): - kp_print (ent, dp); - break; - case ('u'): - kp_printrot (ent, dp); - break; - case ('.'): - kp_pg (ent, dp); - PRINTOUT (stdout, "%s\n", ent->m[dp->n]->sym); - break; - case (' '): - case ('\n'): + case('p'): + kp_print2fig(ent, dp); break; + case('z'): + kp_print_xyz(ent, dp); break; + case('x'): + kp_print(ent, dp); break; + case('u'): + kp_printrot(ent, dp); break; + case('.'): + kp_pg(ent, dp); + PRINTOUT(stdout, "%s\n", ent->m[dp->n]->sym); + break; + case(' '): + case('\n'): break; default: - PRINT_WARN ("Unknown command `%c`\n", c); - } + PRINT_WARN("Unknown command `%c`\n", c); + } return; } -void -run_commands (FILE *f, char *command, drawpars *dp, object *ent) -{ - const char *com = command; +void run_commands(FILE * f, char * command, drawpars * dp, object * ent){ + const char * com = command; int c; - while (1) - { - if (command && command[0]) - { - c = *(com++); - } - else if (f) - { - c = getc (f); - } - else - { - c = 0; - } - if ((!c) || (c == EOF)) - { - break; - } - run_command (c, dp, ent); + while(1){ + if(command && command[0]){ + c = *(com++); + } + else if(f){ + c = getc(f); + } + else{ + c = 0; + } + if((!c) || (c == EOF)){ + break; } + run_command(c, dp, ent); + } return; } -int -headless (drawpars *dp, object *ent) -{ - fill_bonds (ent->m[dp->n], dp); - rotate_mol (ent->m[dp->n], dp); - run_commands (stdin, dp->ui.com, dp, ent); - obj_free (ent); - CLOSE0 (dp->read.f); +int headless(drawpars * dp, object * ent){ + fill_bonds(ent->m[dp->n], dp); + rotate_mol(ent->m[dp->n], dp); + run_commands(stdin, dp->ui.com, dp, ent); + obj_free(ent); + CLOSE0(dp->read.f); return 0; } diff --git a/src/v/load.c b/src/v/load.c index f55a64a..8f7806e 100644 --- a/src/v/load.c +++ b/src/v/load.c @@ -1,277 +1,227 @@ +#include #include "v.h" #include "vec3.h" #include "vecn.h" -#include #define N_MIN 256 -static inline void -fill_nf (object *acs, int n0) -{ - for (int j = n0; j < acs->n; j++) - { - acs->m[j]->nf[0] = j - n0; - acs->m[j]->nf[1] = acs->n - n0; - } +static inline void fill_nf(object * acs, int n0){ + for(int j=n0; jn; j++){ + acs->m[j]->nf[0] = j-n0; + acs->m[j]->nf[1] = acs->n-n0; + } return; } -void -acs_readmore (readpars read, int b, geompars geom, object *acs) -{ +void acs_readmore(readpars read, int b, geompars geom, object * acs){ // needed to reset nf int n0 = acs->n; - // if continue reading from a previously opened file, find the first molecule - // from it - if (ftell (read.f) && acs->n) - { - for (int i = 1; i <= acs->n; i++) - { - int n1 = acs->n - i; - if (acs->m[n1]->nf[0] == 0) - { - n0 = n1; - break; - } - } - } - - atcoord *m; + // if continue reading from a previously opened file, find the first molecule from it + if(ftell(read.f) && acs->n){ + for(int i=1; i<=acs->n; i++){ + int n1 = acs->n-i; + if(acs->m[n1]->nf[0]==0){ + n0 = n1; + break; + } + } + } + + atcoord * m; format_t format = UNKNOWN_FORMAT; - while ((m = ac3_read (read, b, geom, &format)) != NULL) - { - if (acs->n == acs->Nmem) - { - int N = acs->Nmem ? acs->Nmem * 2 : N_MIN; - atcoord **ms = realloc (acs->m, N * sizeof (atcoord *)); - if (!ms) - { - obj_free (acs); - free (m); - PRINT_ERR ("cannot reallocate memory\n"); - abort (); - } - acs->m = ms; - acs->Nmem = N; - } - acs->m[acs->n++] = m; - } - fill_nf (acs, n0); + while((m = ac3_read(read, b, geom, &format))!=NULL){ + if(acs->n==acs->Nmem){ + int N = acs->Nmem ? acs->Nmem*2 : N_MIN; + atcoord ** ms = realloc(acs->m, N*sizeof(atcoord *)); + if(!ms){ + obj_free(acs); + free(m); + PRINT_ERR("cannot reallocate memory\n"); + abort(); + } + acs->m = ms; + acs->Nmem = N; + } + acs->m[acs->n++] = m; + } + fill_nf(acs, n0); return; } -static object * -mode_read_try (FILE *f, object *ent, drawpars *dp) -{ - - long pos = ftell (f); - rewind (f); - atcoord *m = ent->m[ent->n - 1]; - vibr_t *vib = mode_read (f, m->n); - - if (!vib) - { - fseek (f, pos, SEEK_SET); - return NULL; - } - else - { - for (int i = 0; i < ent->n - 1; i++) - { - free (ent->m[i]); - } - ent->Nmem = ent->n = 1; - ent->m = realloc (ent->m, sizeof (atcoord *)); - ent->m[0] = m; - ent->vib = vib; - dp->rend.scale = ac3_scale (m); - dp->N = vib->n; - return ent; - } +static object * mode_read_try(FILE * f, object * ent, drawpars * dp){ + + long pos = ftell(f); + rewind(f); + atcoord * m = ent->m[ent->n-1]; + vibr_t * vib = mode_read(f, m->n); + + if(!vib){ + fseek(f, pos, SEEK_SET); + return NULL; + } + else{ + for(int i=0; in-1; i++){ + free(ent->m[i]); + } + ent->Nmem = ent->n = 1; + ent->m = realloc(ent->m, sizeof(atcoord *)); + ent->m[0] = m; + ent->vib = vib; + dp->rend.scale = ac3_scale(m); + dp->N = vib->n; + return ent; + } } -static FILE * -acs_read_newfile (const char *fname, object *acs, const drawpars *dp) -{ - FILE *f; - if (!strcmp (fname, "-")) - { - f = stdin; - } - else - { - f = fopen (fname, "r"); - if (!f) - { - return NULL; - } +static FILE * acs_read_newfile(const char * fname, object * acs, const drawpars * dp){ + FILE * f; + if(!strcmp(fname, "-")){ + f = stdin; + } + else{ + f = fopen(fname, "r"); + if(!f){ + return NULL; } - acs_readmore ((readpars){ f, fname }, dp->rend.bonds, dp->geom, acs); + } + acs_readmore((readpars){f, fname}, dp->rend.bonds, dp->geom, acs); return f; } -static object * -ent_read (char *fname, drawpars *dp) -{ +static object * ent_read(char * fname, drawpars * dp){ - object *acs = malloc (sizeof (object)); - if (!acs) - GOTOHELL; + object * acs = malloc(sizeof(object)); + if(!acs) GOTOHELL; acs->Nmem = 0; acs->n = 0; acs->m = NULL; acs->vib = NULL; - FILE *f = acs_read_newfile (fname, acs, dp); - if (!f || !acs->n) - { - free (acs); - return NULL; - } + FILE * f = acs_read_newfile(fname, acs, dp); + if(!f || !acs->n){ + free(acs); + return NULL; + } dp->read.fname = fname; - if (dp->task == UNKNOWN || dp->task == VIBRO) - { - object *vib = mode_read_try (f, acs, dp); - if (vib) - { - fclose (f); - dp->task = VIBRO; - return vib; - } - else - { - if (dp->task == VIBRO) - { - PRINT_WARN ("the file '%s' does not contain vibrations\n", - fname); - } - } + if(dp->task==UNKNOWN || dp->task==VIBRO){ + object * vib = mode_read_try(f, acs, dp); + if(vib){ + fclose(f); + dp->task = VIBRO; + return vib; } + else{ + if(dp->task==VIBRO){ + PRINT_WARN("the file '%s' does not contain vibrations\n", fname); + } + } + } dp->task = AT3COORDS; dp->read.f = f; return acs; } -object * -read_files (allpars *ap) -{ - drawpars *dp = &ap->dp; - initpars *ip = &ap->ip; +object * read_files(allpars * ap){ + drawpars * dp = &ap->dp; + initpars * ip = &ap->ip; int fn = ip->input_files_n; - char **flist = ip->input_files; - object *ent = NULL; - int i = 0; + char ** flist = ip->input_files; + object * ent = NULL; + int i=0; // read the first available file - while (i < fn && !(ent = ent_read (flist[i], dp))) - { - PRINT_WARN ("cannot read file '%s'\n", flist[i]); - i++; - } + while(itask == AT3COORDS)) - { - object *acs = ent; - int n0 = acs->n; - for (i++; i < fn; i++) - { - FILE *f = acs_read_newfile (flist[i], acs, dp); - if (!f) - { - PRINT_WARN ("cannot read file '%s'\n", flist[i]); - } - else if (n0 == acs->n) - { - PRINT_WARN ("cannot find molecules in file '%s'\n", flist[i]); - } - else - { - fclose (dp->read.f); - dp->read.f = f; - dp->read.fname = flist[i]; - n0 = acs->n; - } - } - dp->rend.scale = acs_scale (acs); - dp->N = acs->n; - intcoord_check (INT_MAX, dp->anal.intcoord); - } - else - { - dp->anal.intcoord[0] = 0; - for (i++; i < fn; i++) - { - PRINT_WARN ("ignoring file '%s'\n", flist[i]); - } - } + if(ent && (dp->task == AT3COORDS)){ + object * acs = ent; + int n0 = acs->n; + for(i++; in){ + PRINT_WARN("cannot find molecules in file '%s'\n", flist[i]); + } + else{ + fclose(dp->read.f); + dp->read.f = f; + dp->read.fname = flist[i]; + n0 = acs->n; + } + } + dp->rend.scale = acs_scale(acs); + dp->N = acs->n; + intcoord_check(INT_MAX, dp->anal.intcoord); + } + else{ + dp->anal.intcoord[0] = 0; + for(i++; idp; - const initpars *ip = &ap->ip; - - for (int i = 0; i < ip->input_files_n; i++) - { - PRINT_WARN ("ignoring file '%s'\n", ip->input_files[i]); - } - if (dp->task == UNKNOWN) - { - dp->task = vib.n ? VIBRO : AT3COORDS; - } - else if (!vib.n && dp->task == VIBRO) - { - PRINT_WARN ("the input does not contain vibrations\n"); - dp->task = AT3COORDS; - } - - object *ent = malloc (sizeof (object)); - - if (dp->task == AT3COORDS) - { - ent->Nmem = ent->n = n; - ent->m = malloc (ent->Nmem * sizeof (atcoord *)); - ent->vib = NULL; - - for (int i = 0; i < n; i++) - { - ent->m[i] = atcoord_fill (m + i, dp->rend.bonds, dp->geom, NULL); - } - - dp->rend.scale = acs_scale (ent); - dp->N = ent->n; - - int natmax = 0; - for (int i = 0; i < n; i++) - { - natmax = MAX (natmax, m[i].n); - } - intcoord_check (natmax, dp->anal.intcoord); - } - else - { - ent->Nmem = ent->n = 1; - ent->m = malloc (ent->Nmem * sizeof (atcoord *)); - ent->m[0] = atcoord_fill (m + n - 1, dp->rend.bonds, dp->geom, NULL); - int nat = ent->m[0]->n; - ent->vib = make_vibr_t (vib.n, nat); - veccp (vib.n * nat * 3, ent->vib->disp, vib.disp); - veccp (vib.n, ent->vib->freq, vib.freq); - veccp (vib.n, ent->vib->ints, vib.ints); - veccp (vib.n, ent->vib->mass, vib.mass); - dp->rend.scale = ac3_scale (ent->m[0]); - dp->N = ent->vib->n; - dp->anal.intcoord[0] = 0; - } - fill_nf (ent, 0); +object * acs_from_var(int n, mol * m, vibr_t vib, allpars * ap){ + drawpars * dp = &ap->dp; + const initpars * ip = &ap->ip; + + for(int i=0; iinput_files_n; i++){ + PRINT_WARN("ignoring file '%s'\n", ip->input_files[i]); + } + if(dp->task==UNKNOWN){ + dp->task = vib.n ? VIBRO : AT3COORDS; + } + else if(!vib.n && dp->task==VIBRO){ + PRINT_WARN("the input does not contain vibrations\n"); + dp->task = AT3COORDS; + } + + object * ent = malloc(sizeof(object)); + + if(dp->task == AT3COORDS){ + ent->Nmem = ent->n = n; + ent->m = malloc(ent->Nmem*sizeof(atcoord *)); + ent->vib = NULL; + + for(int i=0; im[i] = atcoord_fill(m+i, dp->rend.bonds, dp->geom, NULL); + } + + dp->rend.scale = acs_scale(ent); + dp->N = ent->n; + + int natmax = 0; + for(int i=0; ianal.intcoord); + } + else{ + ent->Nmem = ent->n = 1; + ent->m = malloc(ent->Nmem*sizeof(atcoord *)); + ent->m[0] = atcoord_fill(m+n-1, dp->rend.bonds, dp->geom, NULL); + int nat = ent->m[0]->n; + ent->vib = make_vibr_t(vib.n, nat); + veccp(vib.n*nat*3, ent->vib->disp, vib.disp); + veccp(vib.n, ent->vib->freq, vib.freq); + veccp(vib.n, ent->vib->ints, vib.ints); + veccp(vib.n, ent->vib->mass, vib.mass); + dp->rend.scale = ac3_scale(ent->m[0]); + dp->N = ent->vib->n; + dp->anal.intcoord[0] = 0; + } + fill_nf(ent, 0); dp->read.fname = ent->m[0]->fname; return ent; diff --git a/src/v/loop.c b/src/v/loop.c index c506c5c..9c887f8 100644 --- a/src/v/loop.c +++ b/src/v/loop.c @@ -1,237 +1,190 @@ -#include "evr.h" #include "v.h" #include "x.h" +#include "evr.h" #define VIBRO_SUBSTEPS 4 extern draw_world_t world; -typedef struct -{ +typedef struct { int click; int x0; int y0; } mouse_state_t; -static void -process_mouse (const XMotionEvent *event, object *ent, drawpars *dp, - mouse_state_t *mouse) -{ - if (mouse->click) - { - int x = event->x; - int y = event->y; - rot_ent_pointer (ent, dp, x - mouse->x0, y - mouse->y0, - POINTER_SPEED / world.size); - exp_redraw (ent, dp); - mouse->x0 = x; - mouse->y0 = y; - } +static void process_mouse(const XMotionEvent * event, object * ent, drawpars * dp, mouse_state_t * mouse){ + if(mouse->click){ + int x = event->x; + int y = event->y; + rot_ent_pointer(ent, dp, x-mouse->x0, y-mouse->y0, POINTER_SPEED/world.size); + exp_redraw(ent, dp); + mouse->x0 = x; + mouse->y0 = y; + } return; } -static void -process_input (const XKeyEvent *event, drawpars *dp) -{ - int stop_input = process_x_input (dp->ui.input_text, event->keycode); - if (stop_input) - { - if (stop_input == 1) - { - switch (dp->ui.input) - { - case (INPUT_JUMP): - { - int frame = atoi (dp->ui.input_text); - frame = MAX (1, MIN (frame, dp->N)); - dp->n = frame - 1; - }; - break; - case NO_INPUT: - default: - break; - } - } - memset (dp->ui.input_text, 0, STRLEN); - dp->ui.input = NO_INPUT; +static void process_input(const XKeyEvent * event, drawpars * dp){ + int stop_input = process_x_input(dp->ui.input_text, event->keycode); + if(stop_input){ + if(stop_input==1){ + switch(dp->ui.input){ + case(INPUT_JUMP): + { + int frame = atoi(dp->ui.input_text); + frame = MAX(1, MIN(frame, dp->N)); + dp->n = frame-1; + }; break; + case NO_INPUT: + default: + break; + } } + memset(dp->ui.input_text, 0, STRLEN); + dp->ui.input = NO_INPUT; + } return; } -static void -run_animation (object *ent, drawpars *dp, int *tr) -{ - if (dp->task == AT3COORDS) - { - dp->anim.dir > 0 ? kp_frame_inc (ent, dp) : kp_frame_dec (ent, dp); - usleep (dp->anim.dt); - } - else - { - /* We draw 5 times for each dp->anim.t, - * because dt is too small to look good - * and 5*dt is too big to behave well (keyboard control). - * Also we cannot draw only when *tr==4, - * because we need an XEvent to reiterate the main loop. - * Alternatively, we can send an event manually. - */ - if (++*tr == VIBRO_SUBSTEPS) - { - *tr = 0; - dp->anim.t++; - } - usleep (dp->anim.dt); - time_gone (ent, dp); +static void run_animation(object * ent, drawpars * dp, int * tr){ + if(dp->task == AT3COORDS){ + dp->anim.dir > 0 ? kp_frame_inc(ent, dp) : kp_frame_dec(ent, dp); + usleep(dp->anim.dt); + } + else{ + /* We draw 5 times for each dp->anim.t, + * because dt is too small to look good + * and 5*dt is too big to behave well (keyboard control). + * Also we cannot draw only when *tr==4, + * because we need an XEvent to reiterate the main loop. + * Alternatively, we can send an event manually. + */ + if(++*tr == VIBRO_SUBSTEPS){ + *tr = 0; + dp->anim.t++; } + usleep(dp->anim.dt); + time_gone(ent, dp); + } return; } -static void -configure_window (const XConfigureEvent *xconfigure, object *ent, drawpars *dp) -{ +static void configure_window(const XConfigureEvent * xconfigure, object * ent, drawpars * dp){ world.W = xconfigure->width; world.H = xconfigure->height; - world.size = MIN (world.H, world.W); + world.size = MIN(world.H, world.W); dp->rend.xy0[0] = dp->rend.xy0[1] = 0.0; - exp_redraw (ent, dp); + exp_redraw(ent, dp); return; } -void -wait_for_configure (object *ent, drawpars *dp) -{ +void wait_for_configure(object * ent, drawpars * dp){ XEvent event_rec; - XEvent *event = &event_rec; - do - { - XNextEvent (world.dis, event); + XEvent * event = &event_rec; + do{ + XNextEvent(world.dis, event); #if 0 printf("%d\n", event_rec.type); #endif - if (event->type == ConfigureNotify) - { - configure_window (&event->xconfigure, ent, dp); - break; - } + if(event->type == ConfigureNotify){ + configure_window(&event->xconfigure, ent, dp); + break; } - while (1); + } while(1); return; } -void -main_loop (object *ent, drawpars *dp, ptf kp[NKP]) -{ +void main_loop(object * ent, drawpars * dp, ptf kp[NKP]){ - exp_redraw (ent, dp); + exp_redraw(ent, dp); // To handle window closing. Thanks to https://stackoverflow.com/a/1186544 - Atom wm_delete_window = XInternAtom (world.dis, "WM_DELETE_WINDOW", False); - XSetWMProtocols (world.dis, world.win, &wm_delete_window, 1); + Atom wm_delete_window = XInternAtom(world.dis, "WM_DELETE_WINDOW", False); + XSetWMProtocols(world.dis, world.win, &wm_delete_window, 1); - mouse_state_t mouse = { .click = 0, .x0 = 0, .y0 = 0 }; + mouse_state_t mouse = {.click=0, .x0=0, .y0=0}; int tr = 0; - while (1) - { - XEvent event_rec; - XEvent *event = NULL; - do - { - XNextEvent (world.dis, &event_rec); + while(1) { + XEvent event_rec; + XEvent * event = NULL; + do{ + XNextEvent(world.dis, &event_rec); #if 0 printf("%d\n", event_rec.type); #endif - if (event_rec.type != NoExpose || !event) - { - event = &event_rec; - } - if (event->type == ButtonPress || event->type == ButtonRelease) - { - break; - } - } - while (XEventsQueued (world.dis, QueuedAlready)); - - if (event->type == ClientMessage) - { - if ((Atom)event->xclient.data.l[0] == wm_delete_window) - { - kp_exit (ent, dp); - } - } + if(event_rec.type != NoExpose || !event){ + event=&event_rec; + } + if(event->type == ButtonPress || event->type == ButtonRelease){ + break; + } + } while(XEventsQueued(world.dis, QueuedAlready)); + + if (event->type == ClientMessage) { + if ((Atom)event->xclient.data.l[0] == wm_delete_window) { + kp_exit(ent, dp); + } + } - else if (event->type == Expose && event->xexpose.count == 0) - { - exp_redraw (ent, dp); - } + else if(event->type == Expose && event->xexpose.count == 0) { + exp_redraw(ent, dp); + } - else if (event->type == ConfigureNotify) - { - configure_window (&event->xconfigure, ent, dp); - } + else if(event->type == ConfigureNotify){ + configure_window(&event->xconfigure, ent, dp); + } - else if (event->type == KeyPress) - { - if (dp->ui.input == NO_INPUT) - { - if (kp[event->xkey.keycode]) - { - dp->ui.modkey - = event->xkey.state & (ShiftMask | ControlMask); - kp[event->xkey.keycode](ent, dp); - } - } - else - { - process_input (&(event->xkey), dp); - exp_redraw (ent, dp); - } - } + else if(event->type == KeyPress) { + if(dp->ui.input==NO_INPUT){ + if(kp[event->xkey.keycode]){ + dp->ui.modkey = event->xkey.state & (ShiftMask | ControlMask); + kp[event->xkey.keycode](ent, dp); + } + } + else{ + process_input(&(event->xkey), dp); + exp_redraw(ent, dp); + } + } - else if (event->type == ButtonPress - && (event->xbutton.button == Button1 - || event->xbutton.button == Button2 - || event->xbutton.button == Button3)) - { - mouse.click = 1; - mouse.x0 = event->xbutton.x; - mouse.y0 = event->xbutton.y; - } + else if(event->type == ButtonPress && + (event->xbutton.button==Button1 || + event->xbutton.button==Button2 || + event->xbutton.button==Button3)){ + mouse.click = 1; + mouse.x0 = event->xbutton.x; + mouse.y0 = event->xbutton.y; + } - else if (event->type == ButtonRelease - && (event->xbutton.button == Button1 - || event->xbutton.button == Button2 - || event->xbutton.button == Button3)) - { - mouse.click = 0; - } + else if(event->type == ButtonRelease && + (event->xbutton.button==Button1 || + event->xbutton.button==Button2 || + event->xbutton.button==Button3)){ + mouse.click = 0; + } - else if (event->type == ButtonPress && event->xbutton.button == Button4) - { - kp_zoom_in (ent, dp); - } + else if(event->type == ButtonPress && event->xbutton.button==Button4){ + kp_zoom_in(ent, dp); + } - else if (event->type == ButtonPress && event->xbutton.button == Button5) - { - kp_zoom_out (ent, dp); - } + else if(event->type == ButtonPress && event->xbutton.button==Button5){ + kp_zoom_out(ent, dp); + } - else if (event->type == MotionNotify) - { - process_mouse (&(event->xmotion), ent, dp, &mouse); - } + else if(event->type == MotionNotify){ + process_mouse(&(event->xmotion), ent, dp, &mouse); + } - if (dp->ui.closed == MUST_CLEANUP) - { - kp_exit (ent, dp); - } + if(dp->ui.closed==MUST_CLEANUP){ + kp_exit(ent, dp); + } - if (dp->ui.closed == READY_TO_EXIT) - { - return; - } + if(dp->ui.closed==READY_TO_EXIT){ + return; + } - if (dp->anim.dir) - { - run_animation (ent, dp, &tr); - } + if(dp->anim.dir){ + run_animation(ent, dp, &tr); } + } } + diff --git a/src/v/man.c b/src/v/man.c index b9ba4f3..18603ce 100644 --- a/src/v/man.c +++ b/src/v/man.c @@ -1,9 +1,7 @@ #include "v.h" -void -printman (FILE *f, char *exename) -{ - PRINTOUT (f, "\ +void printman(FILE * f, char * exename){ + PRINTOUT(f, "\ \n\ USAGE:\n\ \n\ @@ -75,7 +73,7 @@ printman (FILE *f, char *exename) \n\ q / esc quit \n\ \n\ -", - exename, DEFAULT_TIMEOUT * MS_TO_S, DEFAULT_SYMTOL); +", exename, DEFAULT_TIMEOUT*MS_TO_S, DEFAULT_SYMTOL); return; } + diff --git a/src/v/mode_read.c b/src/v/mode_read.c index ac46818..74bec35 100644 --- a/src/v/mode_read.c +++ b/src/v/mode_read.c @@ -5,56 +5,44 @@ #define DISPL_LINES_SKIP 5 #define SUMMARY_LINES_SKIP 4 -vibr_t * -make_vibr_t (int n_modes, int n_atoms) -{ - size_t freq_size = sizeof (double) * n_modes; +vibr_t * make_vibr_t(int n_modes, int n_atoms){ + size_t freq_size = sizeof(double) * n_modes; size_t ints_size = freq_size; size_t mass_size = freq_size; - size_t disp_size = sizeof (double) * n_modes * n_atoms * 3; - size_t size - = sizeof (vibr_t) + freq_size + disp_size + ints_size + mass_size; - vibr_t *v = malloc (size); - if (!v) - GOTOHELL; - v->n = n_modes; - v->freq = (double *)(v + 1); - v->disp = (double *)MEM_END (v, freq); - v->ints = (double *)MEM_END (v, disp); - v->mass = (double *)MEM_END (v, ints); + size_t disp_size = sizeof(double) * n_modes*n_atoms*3; + size_t size = sizeof(vibr_t) + freq_size + disp_size + ints_size + mass_size; + vibr_t * v = malloc(size); + if(!v) GOTOHELL; + v->n = n_modes; + v->freq = (double *) (v + 1); + v->disp = (double *) MEM_END(v,freq); + v->ints = (double *) MEM_END(v,disp); + v->mass = (double *) MEM_END(v,ints); return v; } -static int -readb (FILE *f, int i, int Nmax, int N, int na, vibr_t *vib) -{ +static int readb(FILE * f, int i, int Nmax, int N, int na, vibr_t * vib){ double d; - char s[STRLEN]; - int t, k, j; + char s[STRLEN]; + int t,k,j; - for (j = 0; j < DISPL_LINES_SKIP; j++) - { - if (!fgets (s, sizeof (s), f)) - { - return -1; - } + for (j=0; jdisp[3 * na * (i * Nmax + j) + k] = d; - } + for (k=0; kdisp[3*na*(i*Nmax+j)+k] = d; } + } #if 0 for (j=0; jn; i++) - { - fgets (s, sizeof (s), f); - for (int j = 0; j < SUMMARY_COLUMNS; j++) - { - char *s_end; - char *ts = strtok (j ? NULL : s, "|"); - if (!ts) - { - return -1; - } -#define TS_TO_DOUBLE(X) \ - { \ - X = strtod (ts, &s_end); \ - if (s_end == ts) \ - { \ - return -1; \ - } \ - } - else if (j == 2) - { - TS_TO_DOUBLE (vib->freq[i]); - if (strchr (ts, 'i')) - { - vib->freq[i] *= -1; - } - } - else if (j == 3) - { - TS_TO_DOUBLE (vib->mass[i]); - } - else if (j == 4) - { - TS_TO_DOUBLE (vib->ints[i]); - } -#undef TS_TO_DOUBLE + for(int i=0; in; i++){ + fgets(s, sizeof(s), f); + for(int j=0; jfreq[i]); + if(strchr(ts, 'i')){ + vib->freq[i] *= -1; } + } + else if(j==3){ + TS_TO_DOUBLE(vib->mass[i]); + } + else if(j==4){ + TS_TO_DOUBLE(vib->ints[i]); + } +#undef TS_TO_DOUBLE } - for (int i = 0; i < SUMMARY_LINES_SKIP; i++) - { - if (!fgets (s, sizeof (s), f)) - { - return -1; - } + } + for (int i=0; icell.boundary == CELL) - { - double v[8 * 3]; - rot3d (8, v, m->cell.vertices, rend->ac3rmx); - draw_vertices (v, rend); - } - else if (m->cell.boundary == SHELL) - { - draw_shell (m->cell.vertices, rend); - } +static void draw_boundary(atcoord * m , rendpars * rend){ + if(m->cell.boundary==CELL){ + double v[8*3]; + rot3d(8, v, m->cell.vertices, rend->ac3rmx); + draw_vertices(v, rend); + } + else if(m->cell.boundary==SHELL){ + draw_shell(m->cell.vertices, rend); + } return; } -static void -screen_text (object *ent, drawpars *dp) -{ +static void screen_text(object * ent, drawpars * dp){ char text[STRLEN]; char text_fname[STRLEN]; char text_input[STRLEN]; char text_coord[STRLEN]; char text_point[32]; - const char *lines[MAX_LINES] = {}; + const char * lines[MAX_LINES] = {}; int lines_red[MAX_LINES] = {}; - const atcoord *m = ent->m[MOL_IDX (dp)]; + const atcoord * m = ent->m[MOL_IDX(dp)]; int il = 0; - if (dp->task == AT3COORDS) - { - set_caption (m->fname); - snprintf (text, sizeof (text), "%*d / %d", 1 + (int)(log10 (dp->N)), - dp->n + 1, dp->N); - } - else - { - double fq = ent->vib->freq[dp->n]; - char i = fq > 0.0 ? ' ' : 'i'; - snprintf (text, sizeof (text), - "%*d / %d freq = %.1lf%c cm-1 int = %.1lf km/mole mass " - "= %.1lf amu", - 1 + (int)(log10 (ent->vib->n)), dp->n + 1, ent->vib->n, - fabs (fq), i, ent->vib->ints[dp->n], ent->vib->mass[dp->n]); - } + if(dp->task==AT3COORDS){ + set_caption(m->fname); + snprintf(text, sizeof(text), "%*d / %d", 1+(int)(log10(dp->N)), dp->n+1, dp->N); + } + else{ + double fq = ent->vib->freq[dp->n]; + char i = fq > 0.0 ? ' ' : 'i'; + snprintf(text, sizeof(text), + "%*d / %d freq = %.1lf%c cm-1 int = %.1lf km/mole mass = %.1lf amu", + 1+(int)(log10(ent->vib->n)), dp->n+1, ent->vib->n, fabs(fq), i, ent->vib->ints[dp->n], ent->vib->mass[dp->n]); + } lines[il++] = text; - if (m->nf[1] == ent->n) - { - lines[il++] = m->fname; - } - else - { - snprintf (text_fname, sizeof (text_fname), "%s (%*d / %d)", m->fname, - 1 + (int)(log10 (m->nf[1])), m->nf[0] + 1, m->nf[1]); - lines[il++] = text_fname; - } + if(m->nf[1]==ent->n){ + lines[il++] = m->fname; + } + else{ + snprintf(text_fname, sizeof(text_fname), "%s (%*d / %d)", m->fname, 1+(int)(log10(m->nf[1])), m->nf[0]+1, m->nf[1]); + lines[il++] = text_fname; + } - if (dp->anal.intcoord[0]) - { - double z = intcoord_calc (1, m->n, dp->anal.intcoord, m->r); - switch (dp->anal.intcoord[0]) - { - case 1: - snprintf (text_coord, sizeof (text_coord), "bond %d-%d: %.3lf", - dp->anal.intcoord[1], dp->anal.intcoord[2], z); - break; - case 2: - snprintf (text_coord, sizeof (text_coord), "angle %d-%d-%d: %.1lf", - dp->anal.intcoord[1], dp->anal.intcoord[2], - dp->anal.intcoord[3], z); - break; - case 3: - snprintf (text_coord, sizeof (text_coord), - "dihedral %d-%d-%d-%d: % .1lf", dp->anal.intcoord[1], - dp->anal.intcoord[2], dp->anal.intcoord[3], - dp->anal.intcoord[4], z); - break; - default: - break; - } - lines[il++] = text_coord; + if(dp->anal.intcoord[0]){ + double z = intcoord_calc(1, m->n, dp->anal.intcoord, m->r); + switch(dp->anal.intcoord[0]){ + case 1: + snprintf(text_coord, sizeof(text_coord), "bond %d-%d: %.3lf", dp->anal.intcoord[1], dp->anal.intcoord[2], z); + break; + case 2: + snprintf(text_coord, sizeof(text_coord), "angle %d-%d-%d: %.1lf", dp->anal.intcoord[1], dp->anal.intcoord[2], dp->anal.intcoord[3], z); + break; + case 3: + snprintf(text_coord, sizeof(text_coord), "dihedral %d-%d-%d-%d: % .1lf", dp->anal.intcoord[1], dp->anal.intcoord[2], dp->anal.intcoord[3], dp->anal.intcoord[4], z); + break; + default: + break; } + lines[il++] = text_coord; + } - if (m->sym[0]) - { - snprintf (text_point, sizeof (text_point), "%spoint group: %s", - dp->task == AT3COORDS ? "" : "molecule ", m->sym); - lines[il++] = text_point; - } + if(m->sym[0]){ + snprintf(text_point, sizeof(text_point), "%spoint group: %s", dp->task==AT3COORDS? "":"molecule ", m->sym); + lines[il++] = text_point; + } - if (dp->ui.input == INPUT_JUMP) - { - snprintf (text_input, sizeof (text_input), "JUMP TO >>> %s", - dp->ui.input_text); - lines_red[il] = 1; - lines[il++] = text_input; - } + if(dp->ui.input==INPUT_JUMP){ + snprintf(text_input, sizeof(text_input), "JUMP TO >>> %s", dp->ui.input_text); + lines_red[il] = 1; + lines[il++] = text_input; + } - put_text (lines, lines_red); + put_text(lines, lines_red); return; } -void -exp_redraw (object *ent, drawpars *dp) -{ - atcoord *m = ent->m[MOL_IDX (dp)]; - fill_bonds (m, dp); - if (dp->task == AT3COORDS) - { - rotate_mol (m, dp); - if (m->cell.boundary == CELL) - { - dp->rend.xy0[0] = 0.0; - dp->rend.xy0[1] = 0.0; - } - } - else if (dp->task == VIBRO) - { - const double *dr = ent->vib->disp + dp->n * m->n * 3; - vecsums (m->n * 3, m->r, m->r0, dr, - VIBR_AMP * sqrt (m->n) * sin (dp->anim.t * 2.0 * M_PI / TMAX)); - rot3d_inplace (m->n, m->r, dp->rend.ac3rmx); +void exp_redraw(object * ent, drawpars * dp){ + atcoord * m = ent->m[MOL_IDX(dp)]; + fill_bonds(m, dp); + if(dp->task==AT3COORDS){ + rotate_mol(m, dp); + if(m->cell.boundary==CELL){ + dp->rend.xy0[0] = 0.0; + dp->rend.xy0[1] = 0.0; } + } + else if(dp->task==VIBRO){ + const double * dr = ent->vib->disp + dp->n * m->n*3; + vecsums(m->n*3, m->r, m->r0, dr, VIBR_AMP*sqrt(m->n)*sin(dp->anim.t * 2.0*M_PI/TMAX)); + rot3d_inplace(m->n, m->r, dp->rend.ac3rmx); + } - if (dp->ui.gui != 1) - { - return; - } + if(dp->ui.gui!=1){ + return; + } - clear_canv (); - screen_text (ent, dp); - ac3_draw (m, &dp->rend); - draw_boundary (m, &dp->rend); - fill_canv (); + clear_canv(); + screen_text(ent, dp); + ac3_draw(m, &dp->rend); + draw_boundary(m, &dp->rend); + fill_canv(); return; } diff --git a/src/v/scale.c b/src/v/scale.c index 9ccbbc5..4cf5860 100644 --- a/src/v/scale.c +++ b/src/v/scale.c @@ -1,49 +1,39 @@ #include "v.h" #include "vec3.h" -#define VIEWPORT_FILL 0.5 // molecule fills this fraction of the viewport +#define VIEWPORT_FILL 0.5 // molecule fills this fraction of the viewport -double -ac3_scale (atcoord *ac) -{ +double ac3_scale(atcoord * ac){ double center[3] = {}; - for (int k = 0; k < ac->n; k++) - { - r3add (center, ac->r + 3 * k); - } - r3scal (center, 1.0 / ac->n); + for(int k=0; kn; k++){ + r3add(center, ac->r+3*k); + } + r3scal(center, 1.0/ac->n); double d2max = 0.0; - for (int k = 0; k < ac->n; k++) - { - double rad = get_radius (ac->q[k]); - double d2 = r3d2 (center, ac->r + 3 * k); - d2max = MAX (d2max, d2 + rad * rad); - } - if (ac->cell.boundary == SHELL) - { - for (int i = 0; i < 2; i++) - { - d2max = MAX (d2max, 2 * ac->cell.vertices[i] * ac->cell.vertices[i]); - } + for(int k=0; kn; k++){ + double rad = get_radius(ac->q[k]); + double d2 = r3d2(center, ac->r+3*k); + d2max = MAX(d2max, d2+rad*rad); + } + if(ac->cell.boundary==SHELL){ + for(int i=0; i<2; i++){ + d2max = MAX(d2max, 2*ac->cell.vertices[i]*ac->cell.vertices[i]); } - else if (ac->cell.boundary == CELL) - { - for (int k = 0; k < 8; k++) - { - double d2 = r3d2 (center, ac->cell.vertices + 3 * k); - d2max = MAX (d2max, d2); - } + } + else if(ac->cell.boundary==CELL){ + for(int k=0; k<8; k++){ + double d2 = r3d2(center, ac->cell.vertices+3*k); + d2max = MAX(d2max, d2); } - return VIEWPORT_FILL / sqrt (d2max); + } + return VIEWPORT_FILL / sqrt(d2max); } -double -acs_scale (object *acs) -{ - double d2max = ac3_scale (acs->m[0]); - for (int i = 1; i < acs->n; i++) - { - d2max = MIN (ac3_scale (acs->m[i]), d2max); - } +double acs_scale(object * acs){ + double d2max = ac3_scale(acs->m[0]); + for(int i=1; in; i++){ + d2max = MIN(ac3_scale(acs->m[i]), d2max); + } return d2max; } + diff --git a/src/v/tools.c b/src/v/tools.c index bf11be1..ca4ee08 100644 --- a/src/v/tools.c +++ b/src/v/tools.c @@ -1,37 +1,29 @@ -#include "sym.h" #include "v.h" +#include "sym.h" -void -obj_free (object *ent) -{ - if (ent->vib) - { - free (ent->vib); - } - for (int i = 0; i < ent->n; i++) - { - free (ent->m[i]); - } - free (ent->m); - free (ent); +void obj_free(object * ent){ + if(ent->vib){ + free(ent->vib); + } + for(int i=0; in; i++){ + free(ent->m[i]); + } + free(ent->m); + free(ent); return; } -void -pg (atcoord *a, double symtol) -{ +void pg(atcoord * a, double symtol){ int n = a->n; - mol m = { - .n = n, .q = a->q, .r = malloc (sizeof (double) * n * 3), .name = NULL - }; - veccp (n * 3, m.r, a->r0); - vecscal (n * 3, m.r, AB); + mol m = {.n = n, .q = a->q, .r=malloc(sizeof(double)*n*3), .name=NULL}; + veccp (n*3, m.r, a->r0); + vecscal(n*3, m.r, AB); - molsym *ms = pointgroup (&m, symtol * AB); - snprintf (a->sym, sizeof (styp), "%s", ms->s); + molsym * ms = pointgroup(&m, symtol*AB); + snprintf(a->sym, sizeof(styp), "%s", ms->s); - free (m.r); - free (ms); + free(m.r); + free(ms); return; } diff --git a/src/v/v.h b/src/v/v.h index fdd4e98..58d42c0 100644 --- a/src/v/v.h +++ b/src/v/v.h @@ -1,8 +1,8 @@ #include "mol.h" -#define DEFAULT_TIMEOUT 20000 -#define DEFAULT_SYMTOL 1e-3 -#define NKP 256 +#define DEFAULT_TIMEOUT 20000 +#define DEFAULT_SYMTOL 1e-3 +#define NKP 256 #define BONDS_MAX 32 #define POINTER_SPEED 2.0 #define STRLEN 256 @@ -10,130 +10,124 @@ #include "pars.h" -typedef void (*ptf) (); +typedef void (* ptf )(); -typedef enum -{ +typedef enum { UNKNOWN_FORMAT, XYZ, IN, OUT, } format_t; -typedef struct -{ - int flag; // whether bonds are up-to-date. 0: no, 1: yes - double rl; // the last used bond length scale factor - int *a; // lists of bonded atoms - double *r; // distances to the bonded atoms +typedef struct { + int flag; // whether bonds are up-to-date. 0: no, 1: yes + double rl; // the last used bond length scale factor + int * a; // lists of bonded atoms + double * r; // distances to the bonded atoms } bondstr; -typedef struct -{ - int n; // number of atoms - int *q; // atom charges - double *r; // atom coordinates (rotated) - const char *fname; // file name +typedef struct { + int n; // number of atoms + int * q; // atom charges + double * r; // atom coordinates (rotated) + const char * fname; // file name - int rotated; // is `r` up-to-date - double *r0; // atom coordinates (original) + int rotated; // is `r` up-to-date + double * r0; // atom coordinates (original) - int nf[2]; // number of molecule in file, file size - styp sym; // point group + int nf[2]; // number of molecule in file, file size + styp sym; // point group bondstr bonds; cellpars cell; } atcoord; -typedef struct -{ - double *freq; // frequencies (cm-1) - double *ints; // intensities - double *disp; // displacements - double *mass; // masses - int n; // number of modes +typedef struct { + double * freq; // frequencies (cm-1) + double * ints; // intensities + double * disp; // displacements + double * mass; // masses + int n; // number of modes } vibr_t; -typedef struct -{ +typedef struct { int n, Nmem; - atcoord **m; - vibr_t *vib; + atcoord ** m; + vibr_t * vib; } object; + // load.c -object *acs_from_var (int n, mol *m, vibr_t vib, allpars *ap); -void acs_readmore (readpars read, int b, geompars geom, object *acs); -object *read_files (allpars *ap); +object * acs_from_var(int n, mol * m, vibr_t vib, allpars * ap); +void acs_readmore (readpars read, int b, geompars geom, object * acs); +object * read_files(allpars * ap); // scale.c -double ac3_scale (atcoord *ac); -double acs_scale (object *acs); +double ac3_scale(atcoord * ac); +double acs_scale(object * acs); // mode_read.c -vibr_t *make_vibr_t (int n_modes, int n_atoms); -vibr_t *mode_read (FILE *f, int na); +vibr_t * make_vibr_t(int n_modes, int n_atoms); +vibr_t * mode_read(FILE * f, int na); // ac3_read*.c -void mol2cell (atcoord *m); -int read_cart_atom (FILE *f, int n, mol *m); -atcoord *atcoord_fill (mol *m0, const render_bonds_t b, const geompars geom, - const double cell[9]); -atcoord *ac3_read (readpars read, const render_bonds_t b, const geompars geom, - format_t *format); -mol *ac3_read_in (FILE *f); -mol *ac3_read_out (FILE *f); -mol *ac3_read_xyz (FILE *f, int *cell_found, double *cell); +void mol2cell(atcoord * m); +int read_cart_atom(FILE * f, int n, mol * m); +atcoord * atcoord_fill(mol * m0, const render_bonds_t b, const geompars geom, const double cell[9]); +atcoord * ac3_read(readpars read, const render_bonds_t b, const geompars geom, format_t * format); +mol * ac3_read_in (FILE * f); +mol * ac3_read_out(FILE * f); +mol * ac3_read_xyz(FILE * f, int * cell_found, double * cell); // man.c -void printman (FILE *f, char *exename); +void printman(FILE * f, char * exename); // cli.c -allpars cli_parse (int argc, char **argv); +allpars cli_parse(int argc, char ** argv); // loop.c -void wait_for_configure (object *ent, drawpars *dp); -void main_loop (object *ent, drawpars *dp, ptf kp[NKP]); +void wait_for_configure(object * ent, drawpars * dp); +void main_loop(object * ent, drawpars * dp, ptf kp[NKP]); // redraw.c -void exp_redraw (object *ent, drawpars *dp); +void exp_redraw(object * ent, drawpars * dp); // ac3_draw.c -void ac3_draw (atcoord *ac, rendpars *rend); +void ac3_draw (atcoord * ac, rendpars * rend); // ac3_print.c -void ac3_print (atcoord *ac, rendpars *rend); -void ac3_print_xyz (atcoord *ac, rendpars *rend); -void ac3_print2fig (atcoord *ac, rendpars *rend); +void ac3_print (atcoord * ac, rendpars * rend); +void ac3_print_xyz(atcoord * ac, rendpars * rend); +void ac3_print2fig(atcoord * ac, rendpars * rend); // bonds.c -void bonds_fill (bondpars bond, atcoord *ac); +void bonds_fill(bondpars bond, atcoord * ac); // get_atpar.c -double get_radius (int q); -double get_maxradius (int n, const int *q); -const char *get_name (int q); -int get_element (const char *s); +double get_radius(int q); +double get_maxradius(int n, const int * q); +const char * get_name(int q); +int get_element(const char * s); // x.c -void close_x (void); -void init_x (const char *const capt, const colorscheme_t colorscheme); -void init_font (char *fontname); -void put_text (const char *const lines[MAX_LINES], const int red[MAX_LINES]); -void set_caption (const char *const capt); -void draw_vertices (const double v[8 * 3], rendpars *rend); -void draw_shell (const double r[2], rendpars *rend); -int save_pic (char *s); -void clear_canv (); -void fill_canv (); +void close_x (void); +void init_x (const char * const capt, const colorscheme_t colorscheme); +void init_font (char * fontname); +void put_text (const char * const lines[MAX_LINES], const int red[MAX_LINES]); +void set_caption (const char * const capt); +void draw_vertices (const double v[8*3], rendpars * rend); +void draw_shell (const double r[2], rendpars * rend); +int save_pic (char * s); +void clear_canv(); +void fill_canv(); // xinput.c -int process_x_input (char input_text[STRLEN], unsigned int keycode); +int process_x_input(char input_text[STRLEN], unsigned int keycode); // tools.c -void obj_free (object *ent); -void pg (atcoord *a, double symtol); +void obj_free(object * ent); +void pg(atcoord * a, double symtol); // headless.c -void run_commands (FILE *f, char *command, drawpars *dp, object *ent); -int headless (drawpars *dp, object *ent); +void run_commands(FILE * f, char * command, drawpars * dp, object * ent); +int headless(drawpars * dp, object * ent); // main.c -int main (int argc, char *argv[]); +int main (int argc, char * argv[]); // api.c -void PRINTOUT (FILE *f, char *format, ...); -object *READ_FILES (allpars *ap); -int SHOULD_PRINT_MAN (int argc); +void PRINTOUT(FILE * f, char * format, ...); +object * READ_FILES(allpars * ap); +int SHOULD_PRINT_MAN(int argc); diff --git a/src/v/x.c b/src/v/x.c index 0a59af9..dabd717 100644 --- a/src/v/x.c +++ b/src/v/x.c @@ -1,48 +1,40 @@ -#include "x.h" #include "v.h" +#include "x.h" extern draw_world_t world; -void -close_x (void) -{ - XFreeGC (world.dis, world.gc_red); - XFreeGC (world.dis, world.gc_black); - XFreeGC (world.dis, world.gc_white); - XFreeGC (world.dis, world.gc_dot[0]); - XFreeGC (world.dis, world.gc_dot[1]); - for (int i = 0; i < NCOLORS; i++) - { - XFreeGC (world.dis, world.gcc[i]); - } +void close_x(void) { + XFreeGC(world.dis, world.gc_red); + XFreeGC(world.dis, world.gc_black); + XFreeGC(world.dis, world.gc_white); + XFreeGC(world.dis, world.gc_dot[0]); + XFreeGC(world.dis, world.gc_dot[1]); + for(int i=0; i screen_sizes[i]) - { - font_size = font_sizes[i]; - break; - } + for(int i=0; iscreen_sizes[i]){ + font_size = font_sizes[i]; + break; } - snprintf (fontname, size, "monospace:pixelsize=%d", font_size); + } + snprintf(fontname, size, "monospace:pixelsize=%d", font_size); return; } -void -init_font (char *fontname) -{ +void init_font(char * fontname){ styp s; - if (!fontname) - { - fontname = s; - autosize_font (fontname, sizeof (s)); - } - world.fontInfo - = XftFontOpenName (world.dis, DefaultScreen (world.dis), fontname); - if (!world.fontInfo) - { - PRINT_WARN ("cannot load font '%s'\n", fontname); - world.fontInfo = XftFontOpenName (world.dis, DefaultScreen (world.dis), - "monospace:pixelsize=24"); - } - - world.xft_draw - = XftDrawCreate (world.dis, world.canv, - DefaultVisual (world.dis, DefaultScreen (world.dis)), - DefaultColormap (world.dis, DefaultScreen (world.dis))); - XRenderColor color = { 0, 0, 0, 65535 }; - XftColorAllocValue (world.dis, - DefaultVisual (world.dis, DefaultScreen (world.dis)), - DefaultColormap (world.dis, DefaultScreen (world.dis)), - &color, &world.xft_color); + if(!fontname){ + fontname = s; + autosize_font(fontname, sizeof(s)); + } + world.fontInfo = XftFontOpenName(world.dis, DefaultScreen(world.dis), fontname); + if(!world.fontInfo){ + PRINT_WARN("cannot load font '%s'\n", fontname); + world.fontInfo = XftFontOpenName(world.dis, DefaultScreen(world.dis), "monospace:pixelsize=24"); + } + + world.xft_draw = XftDrawCreate(world.dis, world.canv, DefaultVisual(world.dis, DefaultScreen(world.dis)), DefaultColormap(world.dis, DefaultScreen(world.dis))); + XRenderColor color = {0, 0, 0, 65535}; + XftColorAllocValue(world.dis, DefaultVisual(world.dis, DefaultScreen(world.dis)), DefaultColormap(world.dis, DefaultScreen(world.dis)), &color, &world.xft_color); XGlyphInfo extents; - XftTextExtentsUtf8 (world.dis, world.fontInfo, (const FcChar8 *)".", 1, - &extents); + XftTextExtentsUtf8(world.dis, world.fontInfo, (const FcChar8 *)".", 1, &extents); world.font_height = world.fontInfo->ascent + world.fontInfo->descent; return; } -void -put_text (const char *const lines[MAX_LINES], const int red[MAX_LINES]) -{ +void put_text(const char * const lines[MAX_LINES], const int red[MAX_LINES]){ int voffset = world.font_height + 5; int hoffset = 10; - for (int i = 0; i < MAX_LINES; i++) - { - if (lines[i]) - { - int x = hoffset; - int y = voffset + world.fontInfo->ascent; - XftDrawStringUtf8 (world.xft_draw, &(world.xft_color), - world.fontInfo, x, y, (const FcChar8 *)lines[i], - strlen (lines[i])); - } - voffset += world.fontInfo->height; + for(int i=0; iascent; + XftDrawStringUtf8(world.xft_draw, &(world.xft_color), world.fontInfo, x, y, (const FcChar8 *)lines[i], strlen(lines[i])); } + voffset += world.fontInfo->height; + } return; } -void -set_caption (const char *const capt) -{ - XStoreName (world.dis, world.win, capt); +void set_caption(const char * const capt){ + XStoreName(world.dis, world.win, capt); return; } -static void -draw_edge (const double vi[3], const double vj[3], rendpars *rend) -{ - int iw = (vi[2] > 0.0 || vj[2] > 0.0) ? 0 : 1; - XDrawLine (world.dis, world.canv, world.gc_dot[iw], SCREEN_X (vi[0]), - SCREEN_Y (vi[1]), SCREEN_X (vj[0]), SCREEN_Y (vj[1])); +static void draw_edge(const double vi[3], const double vj[3], rendpars * rend){ + int iw = (vi[2]>0.0 || vj[2]>0.0) ? 0 : 1; + XDrawLine(world.dis, world.canv, world.gc_dot[iw], + SCREEN_X(vi[0]), SCREEN_Y(vi[1]), SCREEN_X(vj[0]), SCREEN_Y(vj[1])); return; } -void -draw_vertices (const double v[8 * 3], rendpars *rend) -{ -#define LINE(i, j) draw_edge (v + (i) * 3, v + (j) * 3, rend) - for (int i = 0; i < 8; i += 2) - { - LINE (i, i + 1); // || z-axis - } - for (int j = 0; j < 2; j++) - { - for (int i = 0; i < 2; i++) - { - LINE (i * 4 + j, i * 4 + 2 + j); // || y-axis - LINE (i * 2 + j, i * 2 + 4 + j); // || x-axis - } +void draw_vertices(const double v[8*3], rendpars * rend){ +#define LINE(i,j) draw_edge(v+(i)*3, v+(j)*3, rend) + for(int i=0; i<8; i+=2){ + LINE(i,i+1); // || z-axis + } + for(int j=0; j<2; j++){ + for(int i=0; i<2; i++){ + LINE(i*4+j, i*4+2+j); // || y-axis + LINE(i*2+j, i*2+4+j); // || x-axis } + } #undef LINE return; } -void -draw_shell (const double r[2], rendpars *rend) -{ +void draw_shell(const double r[2], rendpars * rend){ double d = world.size * rend->scale; - for (int i = 0; i < 2; i++) - { - XDrawArc (world.dis, world.canv, world.gc_dot[1 - i], SCREEN_X (-r[i]), - SCREEN_Y (r[i]), 2 * r[i] * d, 2 * r[i] * d, 0, 360 * 64); - } + for(int i=0; i<2; i++){ + XDrawArc(world.dis, world.canv, world.gc_dot[1-i], + SCREEN_X(-r[i]), SCREEN_Y(r[i]), + 2*r[i]*d, 2*r[i]*d, 0, 360*64); + } return; } -int -save_pic (char *s) -{ +int save_pic(char * s){ XpmAttributes a = { .valuemask = XpmSize, - .width = world.W, - .height = world.H, + .width = world.W, + .height = world.H, }; - return XpmWriteFileFromPixmap (world.dis, s, world.px, 0, &a) == XpmSuccess; + return XpmWriteFileFromPixmap(world.dis, s, world.px, 0, &a)==XpmSuccess; } -void -clear_canv () -{ // TODO other canvases? - if (world.canv == world.px) - { - XFillRectangle (world.dis, world.canv, world.gc_white, 0, 0, world.W, - world.H); - } +void clear_canv(){ // TODO other canvases? + if(world.canv == world.px){ + XFillRectangle(world.dis, world.canv, world.gc_white, 0, 0, world.W, world.H);\ + } return; } -void -fill_canv () -{ - if (world.canv == world.px) - { // TODO other canvases? - XCopyArea (world.dis, world.canv, world.win, world.gc_white, 0, 0, - world.W, world.H, 0, 0); - } +void fill_canv(){ + if(world.canv == world.px){ // TODO other canvases? + XCopyArea(world.dis, world.canv, world.win, world.gc_white, 0, 0, world.W, world.H, 0, 0); + } return; } diff --git a/src/v/x.h b/src/v/x.h index 4dc4a65..364b69f 100644 --- a/src/v/x.h +++ b/src/v/x.h @@ -1,28 +1,25 @@ #include #include -#include #include -#include +#include #include +#include #define NCOLORS 110 #define LINE_WIDTH 2 -#define SCREEN_X(X) \ - (world.W / 2 + world.size * rend->scale * (rend->xy0[0] + (X))) -#define SCREEN_Y(Y) \ - (world.H / 2 - world.size * rend->scale * (rend->xy0[1] + (Y))) +#define SCREEN_X(X) (world.W/2 + world.size * rend->scale*(rend->xy0[0] + (X))) +#define SCREEN_Y(Y) (world.H/2 - world.size * rend->scale*(rend->xy0[1] + (Y))) -typedef struct -{ - Display *dis; - Window win; - GC gc_white, gc_black, gc_red, gc_dot[2], gcc[NCOLORS]; - Pixmap px; - Drawable canv; - XftFont *fontInfo; - XftDraw *xft_draw; - XftColor xft_color; - int font_height; - int W, H, size; +typedef struct { + Display * dis; + Window win; + GC gc_white, gc_black, gc_red, gc_dot[2], gcc[NCOLORS]; + Pixmap px; + Drawable canv; + XftFont * fontInfo; + XftDraw * xft_draw; + XftColor xft_color; + int font_height; + int W, H, size; } draw_world_t; diff --git a/src/v/xinput.c b/src/v/xinput.c index c710356..4ac1994 100644 --- a/src/v/xinput.c +++ b/src/v/xinput.c @@ -3,41 +3,30 @@ extern draw_world_t world; -int -process_x_input (char input_text[STRLEN], unsigned int keycode) -{ +int process_x_input(char input_text[STRLEN], unsigned int keycode){ int keysyms_per_keycode_return; - KeySym *keysym = XGetKeyboardMapping (world.dis, keycode, 1, - &keysyms_per_keycode_return); - int input_length = strlen (input_text); - if (!((keysym[0] >= '0' && keysym[0] <= '9') - || (keysym[0] >= 'a' && keysym[0] <= 'z'))) - { - if (keysym[0] == XK_Escape) - { - XFree (keysym); - return -1; // only stop input & clean - } - else if (keysym[0] == XK_Return) - { - XFree (keysym); - return 1; // use the input - } - else if (keysym[0] == XK_BackSpace) - { - if (input_length > 0) - { - input_text[input_length - 1] = 0; - } - } + KeySym * keysym = XGetKeyboardMapping(world.dis, keycode, 1, &keysyms_per_keycode_return); + int input_length = strlen(input_text); + if(!((keysym[0]>='0' && keysym[0]<='9')||(keysym[0]>='a' && keysym[0]<='z'))){ + if(keysym[0]==XK_Escape){ + XFree(keysym); + return -1; // only stop input & clean } - else - { - if (input_length < STRLEN - 1) - { - input_text[input_length] = keysym[0]; - } + else if(keysym[0]==XK_Return){ + XFree(keysym); + return 1; // use the input } - XFree (keysym); + else if(keysym[0]==XK_BackSpace){ + if(input_length>0){ + input_text[input_length-1] = 0; + } + } + } + else{ + if(input_length Date: Wed, 29 Apr 2026 20:13:00 +0330 Subject: [PATCH 04/10] fix minor bug --- src/v/x.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/v/x.c b/src/v/x.c index dabd717..20b6fb1 100644 --- a/src/v/x.c +++ b/src/v/x.c @@ -106,7 +106,7 @@ void init_x(const char * const capt, const colorscheme_t colorscheme){ return; }; -static void autosize_font(char * fontname, size_t size){ +static void autosize_font(char * fontname, size_t fontname_size){ const int screen_sizes[] = {1200, 1080, 960, 900, 840, 768}; const int font_sizes[] = { 24, 20, 18, 16, 15, 14}; // font_size='ceil'(world.size) / 60 int font_size = 24; @@ -116,7 +116,7 @@ static void autosize_font(char * fontname, size_t size){ break; } } - snprintf(fontname, size, "monospace:pixelsize=%d", font_size); + snprintf(fontname, fontname_size, "monospace:pixelsize=%d", font_size); return; } From a97112b3ab2a3bdc7ec309c088fbf07c2d3a7df7 Mon Sep 17 00:00:00 2001 From: zerg Date: Wed, 29 Apr 2026 20:34:05 +0330 Subject: [PATCH 05/10] fix labels font and size. --- src/v/ac3_draw.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/v/ac3_draw.c b/src/v/ac3_draw.c index 450b0d4..4813b57 100644 --- a/src/v/ac3_draw.c +++ b/src/v/ac3_draw.c @@ -4,10 +4,15 @@ #define EPS 1e-15 #define BOND_OFFSET 0.666 // bond line starts this fraction of the atom radius away from the atom center #define RESOL_SCALE (128.0/768.0) // reference resolution for atom sizes -#define XDRAWSTRING XDrawImageString // change to XDrawString to remove white boxes behind atom/bond labels extern draw_world_t world; +static void draw_label(Display *dpy, Drawable drawable, int x, int y, const char *text) { + XftDrawStringUtf8(world.xft_draw, &world.xft_color, world.fontInfo, + x, y + world.fontInfo->ascent, (const FcChar8 *)text, strlen(text)); + return; +} + static inline int getgci(int q){ return abs(q)num == SHOW_NUMBERS){ char text[16]; snprintf(text, sizeof(text), "%d", k+1); - XDRAWSTRING(world.dis, world.canv, world.gc_black, x, y, text, strlen(text)); + draw_label(world.dis, world.canv, x, y, text); } else if(rend->num == SHOW_TYPES){ char text[16]; const char * s = get_name(q); s ? snprintf(text, sizeof(text), "%s", s) : snprintf(text, sizeof(text), "%d", q ); - XDRAWSTRING(world.dis, world.canv, world.gc_black, x, y, text, strlen(text)); + draw_label(world.dis, world.canv, x, y, text); } if(rend->bonds>0){ @@ -97,7 +102,7 @@ void ac3_draw(atcoord * ac, rendpars * rend){ if(rend->bonds==SHOW_LENGTHS){ char text[16]; snprintf(text, sizeof(text), "%.3lf", ac->bonds.r[j]); - XDRAWSTRING(world.dis, world.canv, world.gc_black, x+dx/2, y+dy/2, text, strlen(text)); + draw_label(world.dis, world.canv, x+dx/2, y+dy/2, text); } } } From 70dbd5c7eb252e6229d48ebec484a298b3a566a7 Mon Sep 17 00:00:00 2001 From: zerg Date: Wed, 29 Apr 2026 20:57:34 +0330 Subject: [PATCH 06/10] center lables --- src/v/ac3_draw.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/v/ac3_draw.c b/src/v/ac3_draw.c index 4813b57..718cdae 100644 --- a/src/v/ac3_draw.c +++ b/src/v/ac3_draw.c @@ -8,8 +8,10 @@ extern draw_world_t world; static void draw_label(Display *dpy, Drawable drawable, int x, int y, const char *text) { + XGlyphInfo extents; + XftTextExtentsUtf8(world.dis, world.fontInfo, (const FcChar8*) text, strlen(text), &extents); XftDrawStringUtf8(world.xft_draw, &world.xft_color, world.fontInfo, - x, y + world.fontInfo->ascent, (const FcChar8 *)text, strlen(text)); + x - extents.xOff / 2, y + ((world.fontInfo->ascent - world.fontInfo->descent) / 2), (const FcChar8 *)text, strlen(text)); return; } From f6e4f9a101348000eb2eacb4b7f5ffc151c2edbb Mon Sep 17 00:00:00 2001 From: zerg Date: Wed, 29 Apr 2026 21:10:40 +0330 Subject: [PATCH 07/10] fix center lables. --- src/v/ac3_draw.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/v/ac3_draw.c b/src/v/ac3_draw.c index 718cdae..236d6af 100644 --- a/src/v/ac3_draw.c +++ b/src/v/ac3_draw.c @@ -11,7 +11,7 @@ static void draw_label(Display *dpy, Drawable drawable, int x, int y, const char XGlyphInfo extents; XftTextExtentsUtf8(world.dis, world.fontInfo, (const FcChar8*) text, strlen(text), &extents); XftDrawStringUtf8(world.xft_draw, &world.xft_color, world.fontInfo, - x - extents.xOff / 2, y + ((world.fontInfo->ascent - world.fontInfo->descent) / 2), (const FcChar8 *)text, strlen(text)); + x - extents.xOff / 2, y + extents.height / 2, (const FcChar8 *)text, strlen(text)); return; } From d30d97fc83e024e32fe69cb83b3da9b438b62de2 Mon Sep 17 00:00:00 2001 From: zerg Date: Thu, 30 Apr 2026 00:32:41 +0330 Subject: [PATCH 08/10] yellow for warnings, red for errors and white for message body. --- src/mol/common.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mol/common.h b/src/mol/common.h index f25a54e..87f2b17 100644 --- a/src/mol/common.h +++ b/src/mol/common.h @@ -25,11 +25,11 @@ #define printalive {printf("alive @ %s:%d\n", __FILE__, __LINE__); fflush(stdout);} #define PRINT_ERR(...) {\ - fprintf(stderr, "\e[1;31m" "error: " "\e[0m" "\e[1;30m" "[%s:%d]" "\e[0m ", __FILE__, __LINE__);\ + fprintf(stderr, "\e[1;31m" "error: " "\e[0m" "\e[1;37m" "[%s:%d]" "\e[0m ", __FILE__, __LINE__);\ fprintf(stderr, __VA_ARGS__ );\ } #define PRINT_WARN(...) {\ - fprintf(stderr, "\e[1;35m" "warning: " "\e[0m" "\e[1;30m" "[%s:%d]" "\e[0m ", __FILE__, __LINE__);\ + fprintf(stderr, "\e[1;33m" "warning: " "\e[0m" "\e[1;37m" "[%s:%d]" "\e[0m ", __FILE__, __LINE__);\ fprintf(stderr, __VA_ARGS__ );\ } From 5b1d8b8b2d3479b26e9a7254410a30cb0e8d08b8 Mon Sep 17 00:00:00 2001 From: zerg Date: Thu, 30 Apr 2026 01:36:22 +0330 Subject: [PATCH 09/10] port to Xft completed. cleanup. --- src/v/ac3_draw.c | 17 ++++++++++------- src/v/x.c | 49 ++++++++++++++++++++---------------------------- src/v/x.h | 3 +-- 3 files changed, 31 insertions(+), 38 deletions(-) diff --git a/src/v/ac3_draw.c b/src/v/ac3_draw.c index 236d6af..20a6fe4 100644 --- a/src/v/ac3_draw.c +++ b/src/v/ac3_draw.c @@ -7,11 +7,14 @@ extern draw_world_t world; -static void draw_label(Display *dpy, Drawable drawable, int x, int y, const char *text) { +static void draw_label(int x, int y, const char *text) { XGlyphInfo extents; - XftTextExtentsUtf8(world.dis, world.fontInfo, (const FcChar8*) text, strlen(text), &extents); - XftDrawStringUtf8(world.xft_draw, &world.xft_color, world.fontInfo, - x - extents.xOff / 2, y + extents.height / 2, (const FcChar8 *)text, strlen(text)); + XftTextExtentsUtf8(world.dis, world.font_info, (const FcChar8*) text, + strlen(text), &extents); + + XftDrawStringUtf8(world.xft_draw, &world.xft_color, world.font_info, + x - extents.xOff / 2, y + extents.height / 2, + (const FcChar8 *)text, strlen(text)); return; } @@ -73,13 +76,13 @@ void ac3_draw(atcoord * ac, rendpars * rend){ if(rend->num == SHOW_NUMBERS){ char text[16]; snprintf(text, sizeof(text), "%d", k+1); - draw_label(world.dis, world.canv, x, y, text); + draw_label(x, y, text); } else if(rend->num == SHOW_TYPES){ char text[16]; const char * s = get_name(q); s ? snprintf(text, sizeof(text), "%s", s) : snprintf(text, sizeof(text), "%d", q ); - draw_label(world.dis, world.canv, x, y, text); + draw_label(x, y, text); } if(rend->bonds>0){ @@ -104,7 +107,7 @@ void ac3_draw(atcoord * ac, rendpars * rend){ if(rend->bonds==SHOW_LENGTHS){ char text[16]; snprintf(text, sizeof(text), "%.3lf", ac->bonds.r[j]); - draw_label(world.dis, world.canv, x+dx/2, y+dy/2, text); + draw_label(x+dx/2, y+dy/2, text); } } } diff --git a/src/v/x.c b/src/v/x.c index 20b6fb1..196a96f 100644 --- a/src/v/x.c +++ b/src/v/x.c @@ -14,8 +14,8 @@ void close_x(void) { } XDestroyWindow (world.dis, world.win); XFreePixmap (world.dis, world.px); - if(world.fontInfo){ - XftFontClose (world.dis, world.fontInfo); + if(world.font_info){ + XftFontClose (world.dis, world.font_info); } if (world.xft_draw) { XftDrawDestroy(world.xft_draw); @@ -106,51 +106,42 @@ void init_x(const char * const capt, const colorscheme_t colorscheme){ return; }; -static void autosize_font(char * fontname, size_t fontname_size){ - const int screen_sizes[] = {1200, 1080, 960, 900, 840, 768}; - const int font_sizes[] = { 24, 20, 18, 16, 15, 14}; // font_size='ceil'(world.size) / 60 - int font_size = 24; - for(int i=0; iscreen_sizes[i]){ - font_size = font_sizes[i]; - break; - } - } - snprintf(fontname, fontname_size, "monospace:pixelsize=%d", font_size); - return; -} - void init_font(char * fontname){ - styp s; - if(!fontname){ - fontname = s; - autosize_font(fontname, sizeof(s)); + if(!fontname){ // if fontname is empty string, it causes segfaults. + PRINT_ERR("option font: cannot be empty string\n"); + exit(1); } - world.fontInfo = XftFontOpenName(world.dis, DefaultScreen(world.dis), fontname); - if(!world.fontInfo){ + // if fontname does not match, it falls back on default system font + world.font_info = XftFontOpenName(world.dis, DefaultScreen(world.dis), fontname); + if(!world.font_info){ // this rarely happens PRINT_WARN("cannot load font '%s'\n", fontname); - world.fontInfo = XftFontOpenName(world.dis, DefaultScreen(world.dis), "monospace:pixelsize=24"); + // TODO: should fallback on default hardcoded font + world.font_info = XftFontOpenName(world.dis, DefaultScreen(world.dis), "monospace:size=12"); + + if(!world.font_info){ // extreme case like there is no font on system + PRINT_ERR("cannot load any font"); + exit(1); + } } world.xft_draw = XftDrawCreate(world.dis, world.canv, DefaultVisual(world.dis, DefaultScreen(world.dis)), DefaultColormap(world.dis, DefaultScreen(world.dis))); XRenderColor color = {0, 0, 0, 65535}; XftColorAllocValue(world.dis, DefaultVisual(world.dis, DefaultScreen(world.dis)), DefaultColormap(world.dis, DefaultScreen(world.dis)), &color, &world.xft_color); XGlyphInfo extents; - XftTextExtentsUtf8(world.dis, world.fontInfo, (const FcChar8 *)".", 1, &extents); - world.font_height = world.fontInfo->ascent + world.fontInfo->descent; + XftTextExtentsUtf8(world.dis, world.font_info, (const FcChar8 *)".", 1, &extents); return; } void put_text(const char * const lines[MAX_LINES], const int red[MAX_LINES]){ - int voffset = world.font_height + 5; + int voffset = world.font_info->height + 10; int hoffset = 10; for(int i=0; iascent; - XftDrawStringUtf8(world.xft_draw, &(world.xft_color), world.fontInfo, x, y, (const FcChar8 *)lines[i], strlen(lines[i])); + int y = voffset + world.font_info->ascent; + XftDrawStringUtf8(world.xft_draw, &(world.xft_color), world.font_info, x, y, (const FcChar8 *)lines[i], strlen(lines[i])); } - voffset += world.fontInfo->height; + voffset += world.font_info->height; } return; } diff --git a/src/v/x.h b/src/v/x.h index 364b69f..dc1a3d4 100644 --- a/src/v/x.h +++ b/src/v/x.h @@ -17,9 +17,8 @@ typedef struct { GC gc_white, gc_black, gc_red, gc_dot[2], gcc[NCOLORS]; Pixmap px; Drawable canv; - XftFont * fontInfo; + XftFont * font_info; XftDraw * xft_draw; XftColor xft_color; - int font_height; int W, H, size; } draw_world_t; From 4d6a925712c108f70c5f93e9931f4e9b11e78608 Mon Sep 17 00:00:00 2001 From: zerg Date: Thu, 30 Apr 2026 02:35:10 +0330 Subject: [PATCH 10/10] fix problem with empty font: option --- src/v/x.c | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/src/v/x.c b/src/v/x.c index 196a96f..7a203f5 100644 --- a/src/v/x.c +++ b/src/v/x.c @@ -107,21 +107,16 @@ void init_x(const char * const capt, const colorscheme_t colorscheme){ }; void init_font(char * fontname){ - if(!fontname){ // if fontname is empty string, it causes segfaults. - PRINT_ERR("option font: cannot be empty string\n"); - exit(1); - } - // if fontname does not match, it falls back on default system font - world.font_info = XftFontOpenName(world.dis, DefaultScreen(world.dis), fontname); - if(!world.font_info){ // this rarely happens - PRINT_WARN("cannot load font '%s'\n", fontname); - // TODO: should fallback on default hardcoded font + if(!fontname){ + PRINT_WARN("using system default monospace font\n"); world.font_info = XftFontOpenName(world.dis, DefaultScreen(world.dis), "monospace:size=12"); + } else { + world.font_info = XftFontOpenName(world.dis, DefaultScreen(world.dis), fontname); + } - if(!world.font_info){ // extreme case like there is no font on system - PRINT_ERR("cannot load any font"); - exit(1); - } + if(!world.font_info){ + PRINT_ERR("cannot load font %s\n", fontname); + exit(1); } world.xft_draw = XftDrawCreate(world.dis, world.canv, DefaultVisual(world.dis, DefaultScreen(world.dis)), DefaultColormap(world.dis, DefaultScreen(world.dis))); @@ -133,8 +128,8 @@ void init_font(char * fontname){ } void put_text(const char * const lines[MAX_LINES], const int red[MAX_LINES]){ - int voffset = world.font_info->height + 10; - int hoffset = 10; + int voffset = world.font_info->height; + int hoffset = 16; for(int i=0; i