mol.c

来自「最经典的分子对结软件」· C语言 代码 · 共 2,539 行 · 第 1/5 页

C
2,539
字号
  efree ((void **) &atom->name);  efree ((void **) &atom->type);  free_atom_neighbors (atom);}/* ///////////////////////////////////////////////////////////// */void free_atom_neighbors (ATOM *atom){  efree ((void **) &atom->neighbor);  atom->neighbor_max = 0;}/* ///////////////////////////////////////////////////////////// */void reallocate_atoms (MOLECULE *molecule){  if (molecule->total.atoms > molecule->max.atoms)  {    free_atoms (molecule);    molecule->max.atoms = molecule->total.atoms;    allocate_atoms (molecule);  }}/* ///////////////////////////////////////////////////////////// */void reallocate_atom_neighbors (ATOM *atom){  if (atom->neighbor_total > atom->neighbor_max)  {    free_atom_neighbors (atom);    atom->neighbor_max = atom->neighbor_total;    allocate_atom_neighbors (atom);  }}/* ///////////////////////////////////////////////////////////// */void copy_atoms (MOLECULE *copy, MOLECULE *original){  int i;  copy->total.atoms = original->total.atoms;  reallocate_atoms (copy);  for (i = 0; i < original->total.atoms; i++)  {    copy_atom (&copy->atom[i], &original->atom[i]);    copy_coord (copy->coord[i], original->coord[i]);  }}/* ///////////////////////////////////////////////////////////// */void copy_atom (ATOM *copy, ATOM *original){  copy->number = original->number;  copy->subst_id = original->subst_id;  copy->chem_id = original->chem_id;  copy->vdw_id = original->vdw_id;  copy->heavy_flag = original->heavy_flag;  copy->centrality = original->centrality;  copy->segment_id = original->segment_id;  copy->flag = original->flag;  copy->charge = original->charge;  vstrcpy (&copy->name, original->name);  vstrcpy (&copy->type, original->type);  copy_atom_neighbors (copy, original);}/* ///////////////////////////////////////////////////////////// */void copy_atom_neighbors (ATOM *copy, ATOM *original){  copy->neighbor_total = original->neighbor_total;  reallocate_atom_neighbors (copy);  memcpy    (copy->neighbor, original->neighbor,    original->neighbor_total * sizeof (LINK));  copy->neighbor_total = original->neighbor_total;}/* ///////////////////////////////////////////////////////////// */void copy_coords (MOLECULE *copy, MOLECULE *original){  int i;  if (copy->info.input_id != original->info.input_id)    exit (fprintf (global.outfile,      "ERROR copy_coords: "      "Error copying coordinates to out-of-date molecule structure.\n"));  for (i = 0; i < original->total.atoms; i++)    copy_coord (copy->coord[i], original->coord[i]);}/* ///////////////////////////////////////////////////////////// */void copy_coord (XYZ copy, XYZ original){  copy[0] = original[0];  copy[1] = original[1];  copy[2] = original[2];}/* ///////////////////////////////////////////////////////////// */void save_atoms (MOLECULE *molecule, FILE *file){  int i;  if (molecule->max.atoms > 0)  {    for (i = 0; i < molecule->max.atoms; i++)      save_atom (&molecule->atom[i], file);    efwrite    (      molecule->coord,      sizeof (XYZ),      molecule->max.atoms,      file    );  }}/* ///////////////////////////////////////////////////////////// */void save_atom (ATOM *atom, FILE *file){  efwrite (atom, sizeof (ATOM), 1, file);  save_string (&atom->name, file);  save_string (&atom->type, file);  save_atom_neighbors (atom, file);}/* ///////////////////////////////////////////////////////////// */void save_atom_neighbors (ATOM *atom, FILE *file){  efwrite (&atom->neighbor_total, sizeof (int), 1, file);  efwrite (&atom->neighbor_max, sizeof (int), 1, file);  efwrite (atom->neighbor, sizeof (LINK), atom->neighbor_total, file);}/* ///////////////////////////////////////////////////////////// */void load_atoms (MOLECULE *molecule, FILE *file){  int i;  if (molecule->max.atoms > 0)  {    for (i = 0; i < molecule->max.atoms; i++)      load_atom (&molecule->atom[i], file);    efread    (      molecule->coord,      sizeof (XYZ),      molecule->max.atoms,      file    );  }}/* ///////////////////////////////////////////////////////////// */void load_atom (ATOM *atom, FILE *file){  efread (atom, sizeof (ATOM), 1, file);  atom->name = NULL;  atom->type = NULL;  atom->neighbor = NULL;  load_string (&atom->name, file);  load_string (&atom->type, file);  load_atom_neighbors (atom, file);}/* ///////////////////////////////////////////////////////////// */void load_atom_neighbors (ATOM *atom, FILE *file){  efread (&atom->neighbor_total, sizeof (int), 1, file);  efread (&atom->neighbor_max, sizeof (int), 1, file);  allocate_atom_neighbors (atom);  efread (atom->neighbor, sizeof (LINK), atom->neighbor_total, file);}/* ///////////////////////////////////////////////////////////// */int get_atom_neighbor(  void		*atom,  int		atom_id,  int		neighbor_id){  if (neighbor_id < ((ATOM *) atom)[atom_id].neighbor_total)    return ((ATOM *) atom)[atom_id].neighbor[neighbor_id].id;  else    return EOF;}/* ///////////////////////////////////////////////////////////// *//* ///////////////////////////////////////////////////////////// */void allocate_bonds (MOLECULE *molecule){  int i;  if (molecule->max.bonds > 0)    ecalloc    (      (void **) &molecule->bond,      molecule->max.bonds,      sizeof (BOND),      molecule->info.name,      global.outfile    );  for (i = 0; i < molecule->max.bonds; i++)    reset_bond (&molecule->bond[i]);}/* ///////////////////////////////////////////////////////////// */void reset_bonds (MOLECULE *molecule){  int i;  for (i = 0; i < molecule->max.bonds; i++)    reset_bond (&molecule->bond[i]);  molecule->total.bonds = 0;}/* ///////////////////////////////////////////////////////////// */void reset_bond (BOND *bond){  bond->id = 0;  bond->origin = NEITHER;  bond->target = NEITHER;  bond->ring_flag = 0;  bond->flex_id = 0;  efree ((void **) &bond->type);}/* ///////////////////////////////////////////////////////////// */void free_bonds (MOLECULE *molecule){  int i;  for (i = 0; i < molecule->max.bonds; i++)    free_bond (&molecule->bond[i]);  efree ((void **) &molecule->bond);  molecule->max.bonds = 0;}/* ///////////////////////////////////////////////////////////// */void free_bond (BOND *bond){  efree ((void **) &bond->type);}/* ///////////////////////////////////////////////////////////// */void reallocate_bonds (MOLECULE *molecule){  if (molecule->total.bonds > molecule->max.bonds)  {    free_bonds (molecule);    molecule->max.bonds = molecule->total.bonds;    allocate_bonds (molecule);  }}/* ///////////////////////////////////////////////////////////// */void copy_bonds (MOLECULE *copy, MOLECULE *original){  int i;  copy->total.bonds = original->total.bonds;  reallocate_bonds (copy);  for (i = 0; i < original->total.bonds; i++)    copy_bond (&copy->bond[i], &original->bond[i]);  copy->total.bonds = original->total.bonds;}/* ///////////////////////////////////////////////////////////// */void copy_bond (BOND *copy, BOND *original){  copy->id = original->id;  copy->origin = original->origin;  copy->target = original->target;  copy->ring_flag = original->ring_flag;  copy->flex_id = original->flex_id;  vstrcpy (&copy->type, original->type);}/* ///////////////////////////////////////////////////////////// */void save_bonds (MOLECULE *molecule, FILE *file){  int i;  for (i = 0; i < molecule->max.bonds; i++)    save_bond (&molecule->bond[i], file);}/* ///////////////////////////////////////////////////////////// */void save_bond (BOND *bond, FILE *file){  efwrite (bond, sizeof (BOND), 1, file);  save_string (&bond->type, file);}/* ///////////////////////////////////////////////////////////// */void load_bonds (MOLECULE *molecule, FILE *file){  int i;  for (i = 0; i < molecule->max.bonds; i++)    load_bond (&molecule->bond[i], file);}/* ///////////////////////////////////////////////////////////// */void load_bond (BOND *bond, FILE *file){  efread (bond, sizeof (BOND), 1, file);  bond->type = NULL;  load_string (&bond->type, file);}/* ///////////////////////////////////////////////////////////// *//* ///////////////////////////////////////////////////////////// */void allocate_torsions (MOLECULE *molecule){  int i;  if (molecule->max.torsions > 0)    ecalloc    (      (void **) &molecule->torsion,      molecule->max.torsions,      sizeof (TORSION),      molecule->info.name,      global.outfile    );  for (i = 0; i < molecule->max.torsions; i++)    reset_torsion (&molecule->torsion[i]);}/* ///////////////////////////////////////////////////////////// */void reset_torsions (MOLECULE *molecule){  int i;  for (i = 0; i < molecule->max.torsions; i++)    reset_torsion (&molecule->torsion[i]);  molecule->total.torsions = 0;}/* ///////////////////////////////////////////////////////////// */void reset_torsion (TORSION *torsion){  torsion->flex_id = 0;  torsion->bond_id = NEITHER;  torsion->segment_id = NEITHER;  torsion->periph_flag = 0;  torsion->reverse_flag = 0;  torsion->origin = NEITHER;  torsion->target = NEITHER;  torsion->origin_neighbor = NEITHER;  torsion->target_neighbor = NEITHER;  torsion->current_angle = 0;  torsion->target_angle = 0;}/* ///////////////////////////////////////////////////////////// */void free_torsions (MOLECULE *molecule){  efree ((void **) &molecule->torsion);  molecule->max.torsions = 0;}/* ///////////////////////////////////////////////////////////// */void reallocate_torsions (MOLECULE *molecule){  if (molecule->total.torsions > molecule->max.torsions)  {    free_torsions (molecule);    molecule->max.torsions = molecule->total.torsions;    allocate_torsions (molecule);  }}/* ///////////////////////////////////////////////////////////// */void copy_torsions (MOLECULE *copy, MOLECULE *original){  int i;  copy->total.torsions = original->total.torsions;  reallocate_torsions (copy);  for (i = 0; i < original->total.torsions; i++)    copy_torsion (&copy->torsion[i], &original->torsion[i]);  copy->total.torsions = original->total.torsions;}/* ///////////////////////////////////////////////////////////// */void copy_torsion (TORSION *copy, TORSION *original){  copy->flex_id = original->flex_id;  copy->bond_id = original->bond_id;  copy->segment_id = original->segment_id;  copy->periph_flag = original->periph_flag;  copy->reverse_flag = original->reverse_flag;  copy->origin = original->origin;  copy->target = original->target;  copy->origin_neighbor = original->origin_neighbor;  copy->target_neighbor = original->target_neighbor;  copy->current_angle = original->current_angle;  copy->target_angle = original->target_angle;}/* ///////////////////////////////////////////////////////////// */void save_torsions (MOLECULE *molecule, FILE *file){  if (molecule->max.torsions > 0)    efwrite (molecule->torsion, sizeof (TORSION), molecule->max.torsions, file);}/* ///////////////////////////////////////////////////////////// */void load_torsions (MOLECULE *molecule, FILE *file){  if (molecule->max.torsions > 0)    efread (molecule->torsion, sizeof (TORSION), molecule->max.torsions, file);}/* ///////////////////////////////////////////////////////////// *//* ///////////////////////////////////////////////////////////// */void allocate_substs (MOLECULE *molecule){  int i;  if (molecule->max.substs > 0)    ecalloc    (      (void **) &molecule->subst,      molecule->max.substs,      sizeof (SUBST),      molecule->info.name,      global.outfile    );  for (i = 0; i < molecule->max.substs; i++)    reset_subst (&molecule->subst[i]);}/* ///////////////////////////////////////////////////////////// */void reset_substs (MOLECULE *molecule){  int i;  for (i = 0; i < molecule->max.substs; i++)    reset_subst (&molecule->subst[i]);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?