static Bool try_get_reply (Display *xdisplay, AgGetPropertyTask *task) { if (ag_task_have_reply (task)) { int result; Atom actual_type; int actual_format; unsigned long n_items; unsigned long bytes_after; unsigned char *data; char *name; struct timeval current_time; gettimeofday (¤t_time, NULL); printf (" %gms (we have a reply for property %ld)\n", ELAPSED (program_start_time, current_time), ag_task_get_property (task)); data = NULL; name = atom_name (xdisplay, ag_task_get_property (task)); printf (" %s on 0x%lx:\n", name, ag_task_get_window (task)); free (name); result = ag_task_get_reply_and_free (task, &actual_type, &actual_format, &n_items, &bytes_after, &data); task = NULL; if (result != Success) { fprintf (stderr, " error code %d getting reply\n", result); } else { name = atom_name (xdisplay, actual_type); printf (" actual_type = %s\n", name); free (name); printf (" actual_format = %d\n", actual_format); printf (" n_items = %lu\n", n_items); printf (" bytes_after = %lu\n", bytes_after); printf (" data = \"%s\"\n", data ? (char*) data : "NULL"); } return True; } return False; }
/* * Check if an argument needs brackets or not. */ static bool show_needs_brackets(atom_t atom, term_t t, size_t idx, assoc_t assoc, unsigned priority, bool ac) { if (type(t) != FUNC) return false; func_t f = func(t); if (atom_arity(f->atom) != 2) return false; unsigned priority_1; if (!binop_lookup(opinfo_init(), atom_name(f->atom), NULL, &priority_1, NULL, NULL)) return false; if (priority_1 < priority) return false; if (priority_1 > priority) return true; if (atom == f->atom && ac) return false; switch (assoc) { case XFX: return true; case XFY: return (idx == 1); case YFX: return (idx == 0); } return true; }
/* * Test if a given atom is an equality. */ static bool is_eq(atom_t atom) { if (atom_arity(atom) != 2) return false; const char *name = atom_name(atom); size_t len = strlen(name); if (len <= 3) return false; if (name[len-3] == '_' && name[len-2] == 'e' && name[len-1] == 'q') return true; return false; }
/* \return an array of Atoms from the current frame. * Assumes file has already been opened. */ std::vector<Atom> TinkerFile::ReadTinkerAtoms(double* XYZ, std::vector<int>& bonds) { std::vector<Atom> atoms; if (XYZ == 0) { mprinterr("Internal Error: No space allocated for reading Tinker atom coordinates.\n"); return atoms; } // Title line if (file_.Line() == 0) return atoms; if (CheckTitleLine()) return atoms; // Box line if (hasBox_) { if (file_.Line() == 0) return atoms; } // Read atoms atoms.reserve( natom_ ); for (int atidx = 0; atidx < natom_; atidx++) { if (file_.Line() == 0) return std::vector<Atom>(0); int ncol = file_.TokenizeLine(" "); if (ncol < 6) { mprinterr("Error: In Tinker file line %i expected at least 5 columns for atom, got %i\n", file_.LineNumber(), ncol); return std::vector<Atom>(0); } file_.NextToken(); // Atom index NameType atom_name( file_.NextToken() ); XYZ[0] = atof( file_.NextToken() ); // X XYZ[1] = atof( file_.NextToken() ); // Y XYZ[2] = atof( file_.NextToken() ); // Z XYZ += 3; const char* at_type_ptr = file_.NextToken(); // Atom Type Index int atom_type_index = atoi( at_type_ptr ); NameType atom_type( at_type_ptr ); // Read in any bonded partners. for (int col = 6; col != ncol; col++) { int bonded_atom = atoi(file_.NextToken()) - 1; // Tinker atoms start from 1 if (atidx < bonded_atom) { bonds.push_back( atidx ); bonds.push_back( bonded_atom ); } } atoms.push_back( Atom(atom_name, atom_type, atom_type_index) ); } return atoms; }
void MoleculeGroup::WriteGro(const std::string& gro, const arma::rowvec& box, const std::string description) { std::ofstream gro_file; gro_file.open(gro.c_str()); assert(gro_file.is_open()); gro_file << description << std::endl; gro_file << group_size_ << std::endl; for (int i_atom = 0; i_atom < group_size_; i_atom++) { gro_file << boost::format("%5d%-5s%5s%5d%8.3f%8.3f%8.3f%8.4f%8.4f%8.4f") % (index_to_molecular_index_[i_atom]+1) % molecule_name(index_to_molecular_index_[i_atom]) % atom_name(i_atom) % (indices_[i_atom]+1) % positions_(i_atom,0) % positions_(i_atom,1) % positions_(i_atom,2) % velocities_(i_atom,0) % velocities_(i_atom,1) % velocities_(i_atom,2) << std::endl; } gro_file << boost::format("%10.5f%10.5f%10.5f") % box(0) % box(1) % box(2); gro_file.close(); }
wxString wxDataFormat::GetId() const { wxGtkString atom_name(gdk_atom_name(m_format)); return wxString::FromAscii(atom_name); }
/* * Write an atom. */ extern char *show_buf_atom(char *start, char *end, atom_t a) { start = show_buf_char(start, end, '@'); start = show_buf_str(start, end, atom_name(a)); return start; }
/* * Write a functor. */ extern char *show_buf_func(char *start, char *end, func_t f) { show_buf_func_restart: {} const char *name = atom_name(f->atom); uint_t a = atom_arity(f->atom); assoc_t assoc; unsigned priority; bool ac, space; if (a == 1 && unop_lookup(opinfo_init(), name, &priority, &space)) { // A unary operator. bool b2 = show_needs_brackets(f->atom, f->args[0], 0, XFX, priority, false); start = show_buf_str(start, end, name); if (space) start = show_buf_char(start, end, ' '); if (!b2 && type(f->args[0]) == FUNC) { f = func(f->args[0]); goto show_buf_func_restart; // Tail call optimization. } if (b2) start = show_buf_char(start, end, '('); start = show_buf(start, end, f->args[0]); if (b2) start = show_buf_char(start, end, ')'); return start; } if (a == 2 && binop_lookup(opinfo_init(), name, &assoc, &priority, &ac, &space)) { // A binary operator. bool b1 = show_needs_brackets(f->atom, f->args[0], 0, assoc, priority, ac); bool b2 = show_needs_brackets(f->atom, f->args[1], 1, assoc, priority, ac); if (b1) start = show_buf_char(start, end, '('); start = show_buf(start, end, f->args[0]); if (b1) start = show_buf_char(start, end, ')'); if (space) start = show_buf_char(start, end, ' '); start = show_buf_str(start, end, name); if (space) start = show_buf_char(start, end, ' '); if (!b2 && type(f->args[1]) == FUNC) { f = func(f->args[1]); goto show_buf_func_restart; // Tail call optimization. } if (b2) start = show_buf_char(start, end, '('); start = show_buf(start, end, f->args[1]); if (b2) start = show_buf_char(start, end, ')'); return start; } // Not an operator: start = show_buf_name(start, end, name); if (a == 0) { start = show_buf_str(start, end, "()"); return start; } start = show_buf_char(start, end, '('); for (uint_t i = 0; i < a-1; i++) { start = show_buf(start, end, f->args[i]); start = show_buf_char(start, end, ','); } start = show_buf(start, end, f->args[a-1]); start = show_buf_char(start, end, ')'); return start; }
/* * Flatten an equality expression `x = y'. Assumes x and y are already * flattened. */ static expr_t flatten_eq_to_builtin(exprop_t op, expr_t x, expr_t y, bool toplevel, context_t cxt) { if (expr_gettype(x) == EXPRTYPE_VAR && expr_gettype(y) == EXPRTYPE_VAR) return expr_make(op, x, y); if (expr_gettype(y) == EXPRTYPE_VAR) { expr_t t = x; x = y; y = t; } if (expr_gettype(x) != EXPRTYPE_VAR) x = context_update(cxt, x); if (!toplevel) y = context_update(cxt, y); // Special-case handling of constants and variables: switch (expr_gettype(y)) { case EXPRTYPE_VAR: if (expr_compare(x, y) < 0) return expr_make(op, x, y); else return expr_make(op, y, x); case EXPRTYPE_NUM: return expr_make(exprop_atom_make(ATOM_INT_EQ_C), x, y); case EXPRTYPE_NIL: return expr_make(exprop_atom_make(ATOM_NIL_EQ_C), x, y); case EXPRTYPE_STR: return expr_make(exprop_atom_make(ATOM_STR_EQ_C), x, y); case EXPRTYPE_ATOM: return expr_make(exprop_atom_make(ATOM_ATOM_EQ_C), x, y); case EXPRTYPE_OP: break; default: panic("unexpected expr type (%d)", expr_gettype(y)); } // Special-case handling of add/mul: exprop_t fop = expr_op(y); switch (fop) { case EXPROP_ADD: { expr_t a = expr_arg(y, 0); expr_t b = expr_arg(y, 1); if (expr_gettype(a) == EXPRTYPE_NUM) { expr_t t = a; a = b; b = t; } if (expr_gettype(b) == EXPRTYPE_NUM) { num_t c = expr_getnum(b); if (c < 0) return expr_make(exprop_atom_make(ATOM_INT_EQ_PLUS_C), a, x, expr_num(-c)); else return expr_make(exprop_atom_make(ATOM_INT_EQ_PLUS_C), x, a, b); } else return expr_make(exprop_atom_make(ATOM_INT_EQ_PLUS), x, a, b); } case EXPROP_MUL: { expr_t a = expr_arg(y, 0); expr_t b = expr_arg(y, 1); if (expr_gettype(a) == EXPRTYPE_NUM) { expr_t t = a; a = b; b = t; } if (expr_gettype(b) == EXPRTYPE_NUM) return expr_make(exprop_atom_make(ATOM_INT_EQ_MUL_C), x, a, b); else return expr_make(exprop_atom_make(ATOM_INT_EQ_MUL), x, a, b); } case EXPROP_POW: { expr_t a = expr_arg(y, 0); expr_t b = expr_arg(y, 1); return expr_make(exprop_atom_make(ATOM_INT_EQ_POW_C), x, a, b); } default: break; } // Generic function calls: atom_t atom = expr_sym(y); const char *name = atom_name(atom); size_t arity = atom_arity(atom); size_t len = strlen(name); char buf[len + 32]; typesig_t sig = typeinst_lookup_typesig(atom); typeinst_t type = (sig == TYPESIG_DEFAULT? TYPEINST_NUM: typeinst_make_ground(sig->type)); const char *type_name = typeinst_show(type); int r = snprintf(buf, sizeof(buf)-1, "%s_eq_call_%s", type_name, name); if (r <= 0 || r >= sizeof(buf)-1) panic("failed to create function constraint name"); op = exprop_make(buf, arity+1); expr_t args[arity+1]; expr_args(y, args+1); args[0] = x; expr_t e = expr(op, args); if (sig == TYPESIG_DEFAULT) return e; atom = expr_sym(e); typeinst_t sig_args[arity+1]; memcpy(sig_args+1, sig->args, arity * sizeof(typeinst_t)); sig_args[0] = typeinst_make_var(sig->type); sig = typeinst_make_typesig(arity+1, TYPEINST_BOOL, sig_args); if (!typeinst_declare(atom, sig)) { error("(%s: %zu) failed to declare implied type for %s/%zu", cxt->file, cxt->line, atom_name(atom), atom_arity(arity)); cxt->error = true; } return e; }