• R/O
  • HTTP
  • SSH
  • HTTPS

Molby: コミット

Molecular Modeling Software


コミットメタ情報

リビジョンd36e14f18952caec63b23b00de4d35d7e1f57796 (tree)
日時2010-02-20 15:40:58
作者toshinagata1964 <toshinagata1964@a2be...>
コミッターtoshinagata1964

ログメッセージ

Ruby commands find_angles and find_dihedrals are made obsolete. remove_bonds is implemented. create_bond (create_bonds) now returns the number of newly added bonds instead of self.

git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/molby/trunk@12 a2be9bc6-48de-4e38-9406-05402d4bc13c

変更サマリ

差分

--- a/MolLib/MolAction.c
+++ b/MolLib/MolAction.c
@@ -589,7 +589,7 @@ MolActionPerform(Molecule *mol, MolAction *action)
589589 int n1, result, natoms;
590590 Molecule *mol2;
591591 IntGroup *ig;
592- MolAction *act2;
592+ MolAction *act2 = NULL;
593593 int needsSymmetryAmendment = 0;
594594 int needsRebuildMDArena = 0;
595595 Int *ip;
@@ -775,9 +775,14 @@ MolActionPerform(Molecule *mol, MolAction *action)
775775 } else if (strcmp(action->name, gMolActionAddBonds) == 0) {
776776 ip = (Int *)action->args[0].u.arval.ptr;
777777 n1 = action->args[0].u.arval.nitems / 2;
778- if ((result = MoleculeAddBonds(mol, n1, ip)) < 0)
778+ if ((result = MoleculeAddBonds(mol, n1, ip)) <= 0)
779779 return result;
780- act2 = MolActionNew(gMolActionDeleteBonds, n1 * 2, ip);
780+ ip = (Int *)malloc(sizeof(Int) * 2 * result);
781+ if (ip == NULL)
782+ return -4;
783+ memmove(ip, mol->bonds - result * 2, sizeof(Int) * 2 * result);
784+ act2 = MolActionNew(gMolActionDeleteBonds, result * 2, ip);
785+ free(ip);
781786 needsRebuildMDArena = 1;
782787 } else if (strcmp(action->name, gMolActionDeleteBonds) == 0) {
783788 ip = (Int *)action->args[0].u.arval.ptr;
--- a/MolLib/Molecule.c
+++ b/MolLib/Molecule.c
@@ -5792,14 +5792,20 @@ MoleculeExtract(Molecule *src, Molecule **dstp, IntGroup *where, int dummyFlag)
57925792 int
57935793 MoleculeAddBonds(Molecule *mp, Int nbonds, const Int *bonds)
57945794 {
5795- int i, j, n1, n2;
5795+ int i, j, n1, n2, n;
57965796 Atom *ap;
5797+ Int *bonds_tmp;
5798+
57975799 if (mp == NULL || bonds == NULL || nbonds <= 0)
57985800 return 0;
57995801 if (mp->noModifyTopology)
58005802 return -4; /* Prohibited operation */
58015803
58025804 /* Check the bonds */
5805+ bonds_tmp = (Int *)malloc(sizeof(Int) * nbonds * 2);
5806+ if (bonds_tmp == NULL)
5807+ return -4; /* Out of memory */
5808+ n = 0;
58035809 for (i = 0; i < nbonds; i++) {
58045810 n1 = bonds[i * 2];
58055811 n2 = bonds[i * 2 + 1];
@@ -5808,18 +5814,29 @@ MoleculeAddBonds(Molecule *mp, Int nbonds, const Int *bonds)
58085814 ap = ATOM_AT_INDEX(mp->atoms, n1);
58095815 if (ap->nconnects >= ATOMS_MAX_CONNECTS - 1 || ATOM_AT_INDEX(mp->atoms, n2)->nconnects >= ATOMS_MAX_CONNECTS - 1)
58105816 return -2; /* Too many bonds */
5817+ /* Check duplicates */
58115818 for (j = 0; j < ap->nconnects; j++) {
58125819 if (ap->connects[j] == n2)
5813- return -3; /* Duplicate bond */
5820+ break;
58145821 }
5822+ if (j == ap->nconnects) {
5823+ bonds_tmp[n * 2] = n1;
5824+ bonds_tmp[n * 2 + 1] = n2;
5825+ n++;
5826+ }
5827+ }
5828+ if (n == 0) {
5829+ /* No bonds to add */
5830+ free(bonds_tmp);
5831+ return 0;
58155832 }
58165833
58175834 __MoleculeLock(mp);
58185835
58195836 /* Add connects[] */
5820- for (i = 0; i < nbonds; i++) {
5821- n1 = bonds[i * 2];
5822- n2 = bonds[i * 2 + 1];
5837+ for (i = 0; i < n; i++) {
5838+ n1 = bonds_tmp[i * 2];
5839+ n2 = bonds_tmp[i * 2 + 1];
58235840 ap = ATOM_AT_INDEX(mp->atoms, n1);
58245841 ap->connects[ap->nconnects++] = n2;
58255842 ap = ATOM_AT_INDEX(mp->atoms, n2);
@@ -5830,9 +5847,9 @@ MoleculeAddBonds(Molecule *mp, Int nbonds, const Int *bonds)
58305847 n1 = mp->nbonds;
58315848 /* if (AssignArray(&(mp->bonds), &(mp->nbonds), sizeof(Int) * 2, mp->nbonds + nb - 1, NULL) == NULL
58325849 || sInsertElementsToArrayAtPositions(mp->bonds, n1, bonds, nb, sizeof(Int) * 2, where) != 0) */
5833- if (AssignArray(&(mp->bonds), &(mp->nbonds), sizeof(Int) * 2, mp->nbonds + nbonds - 1, NULL) == NULL)
5850+ if (AssignArray(&(mp->bonds), &(mp->nbonds), sizeof(Int) * 2, mp->nbonds + n - 1, NULL) == NULL)
58345851 goto panic;
5835- memmove(mp->bonds + n1 * 2, bonds, sizeof(Int) * 2 * nbonds);
5852+ memmove(mp->bonds + n1 * 2, bonds_tmp, sizeof(Int) * 2 * n);
58365853
58375854 /* Add angles, dihedrals, impropers */
58385855 {
@@ -5846,9 +5863,9 @@ MoleculeAddBonds(Molecule *mp, Int nbonds, const Int *bonds)
58465863 angles = dihedrals = impropers = NULL;
58475864 nangles = ndihedrals = nimpropers = 0;
58485865
5849- for (i = 0; i < nbonds; i++) {
5850- n1 = bonds[i * 2];
5851- n2 = bonds[i * 2 + 1];
5866+ for (i = 0; i < n; i++) {
5867+ n1 = bonds_tmp[i * 2];
5868+ n2 = bonds_tmp[i * 2 + 1];
58525869 ap1 = ATOM_AT_INDEX(mp->atoms, n1);
58535870 ap2 = ATOM_AT_INDEX(mp->atoms, n2);
58545871 /* Angles X-n1-n2 */
@@ -5930,7 +5947,8 @@ MoleculeAddBonds(Molecule *mp, Int nbonds, const Int *bonds)
59305947 mp->needsMDRebuild = 1;
59315948 __MoleculeUnlock(mp);
59325949
5933- return nbonds;
5950+ free(bonds_tmp);
5951+ return n;
59345952
59355953 panic:
59365954 __MoleculeUnlock(mp);
--- a/MolLib/Ruby_bind/ruby_bind.c
+++ b/MolLib/Ruby_bind/ruby_bind.c
@@ -4728,6 +4728,7 @@ s_Molecule_SetPsPerStep(VALUE self, VALUE val)
47284728 *
47294729 * Find the angles from the bonds. Returns the number of angles newly created.
47304730 */
4731+/*
47314732 static VALUE
47324733 s_Molecule_FindAngles(VALUE self)
47334734 {
@@ -4758,13 +4759,14 @@ s_Molecule_FindAngles(VALUE self)
47584759 }
47594760 return INT2NUM(nip);
47604761 }
4761-
4762+*/
47624763 /*
47634764 * call-seq:
47644765 * find_dihedrals -> Integer
47654766 *
47664767 * Find the dihedrals from the bonds. Returns the number of dihedrals newly created.
47674768 */
4769+/*
47684770 static VALUE
47694771 s_Molecule_FindDihedrals(VALUE self)
47704772 {
@@ -4806,6 +4808,7 @@ s_Molecule_FindDihedrals(VALUE self)
48064808 }
48074809 return INT2NUM(nip);
48084810 }
4811+*/
48094812
48104813 /*
48114814 * call-seq:
@@ -5438,16 +5441,17 @@ s_Molecule_DuplicateAnAtom(int argc, VALUE *argv, VALUE self)
54385441
54395442 /*
54405443 * call-seq:
5441- * create_bond(n1, n2, ...) -> Molecule
5444+ * create_bond(n1, n2, ...) -> Integer
54425445 *
5443- * Create bonds between atoms n1 and n2, n3 and n4, and so on. Returns self.
5446+ * Create bonds between atoms n1 and n2, n3 and n4, and so on. If the corresponding bond is already present for a particular pair,
5447+ * do nothing for that pair. Returns the number of bonds actually created.
54445448 * This operation is undoable.
54455449 */
54465450 static VALUE
54475451 s_Molecule_CreateBond(int argc, VALUE *argv, VALUE self)
54485452 {
54495453 Molecule *mol;
5450- Int i, *ip;
5454+ Int i, *ip, old_nbonds;
54515455 if (argc == 0)
54525456 rb_raise(rb_eMolbyError, "missing arguments");
54535457 if (argc % 2 != 0)
@@ -5457,7 +5461,7 @@ s_Molecule_CreateBond(int argc, VALUE *argv, VALUE self)
54575461 for (i = 0; i < argc; i++)
54585462 ip[i] = s_Molecule_AtomIndexFromValue(mol, argv[i]);
54595463 ip[argc] = kInvalidIndex;
5460-// i = MoleculeAddBonds(mol, ip, NULL);
5464+ old_nbonds = mol->nbonds;
54615465 i = MolActionCreateAndPerform(mol, gMolActionAddBonds, argc, ip);
54625466 if (i == -1)
54635467 rb_raise(rb_eMolbyError, "atom index out of range");
@@ -5467,7 +5471,34 @@ s_Molecule_CreateBond(int argc, VALUE *argv, VALUE self)
54675471 rb_raise(rb_eMolbyError, "duplicate bonds");
54685472 else if (i != 0)
54695473 rb_raise(rb_eMolbyError, "error in creating bonds");
5470- return self;
5474+ return INT2NUM(mol->nbonds - old_nbonds);
5475+}
5476+
5477+/*
5478+ * call-seq:
5479+ * molecule.remove_bonds(n1, n2, ...) -> Integer
5480+ *
5481+ * Remove bonds between atoms n1 and n2, n3 and n4, and so on. If the corresponding bond is not present for
5482+ * a particular pair, do nothing for that pair. Returns the number of bonds actually removed.
5483+ * This operation is undoable.
5484+ */
5485+static VALUE
5486+s_Molecule_RemoveBond(int argc, VALUE *argv, VALUE self)
5487+{
5488+ Molecule *mol;
5489+ Int i, *ip, old_nbonds;
5490+ if (argc == 0)
5491+ rb_raise(rb_eMolbyError, "missing arguments");
5492+ if (argc % 2 != 0)
5493+ rb_raise(rb_eMolbyError, "bonds should be specified by pairs of atom indices");
5494+ Data_Get_Struct(self, Molecule, mol);
5495+ ip = ALLOC_N(Int, argc + 1);
5496+ for (i = 0; i < argc; i++)
5497+ ip[i] = s_Molecule_AtomIndexFromValue(mol, argv[i]);
5498+ ip[argc] = kInvalidIndex;
5499+ old_nbonds = mol->nbonds;
5500+ MolActionCreateAndPerform(mol, gMolActionDeleteBonds, argc, ip);
5501+ return INT2NUM(old_nbonds - mol->nbonds);
54715502 }
54725503
54735504 /*
@@ -7491,8 +7522,8 @@ Init_Molby(void)
74917522 rb_define_method(rb_cMolecule, "ps_per_step", s_Molecule_PsPerStep, 0);
74927523 rb_define_method(rb_cMolecule, "ps_per_step=", s_Molecule_SetPsPerStep, 1);
74937524
7494- rb_define_method(rb_cMolecule, "find_angles", s_Molecule_FindAngles, 0);
7495- rb_define_method(rb_cMolecule, "find_dihedrals", s_Molecule_FindDihedrals, 0);
7525+/* rb_define_method(rb_cMolecule, "find_angles", s_Molecule_FindAngles, 0);
7526+ rb_define_method(rb_cMolecule, "find_dihedrals", s_Molecule_FindDihedrals, 0); */
74967527 rb_define_method(rb_cMolecule, "nresidues", s_Molecule_Nresidues, 0);
74977528 rb_define_method(rb_cMolecule, "nresidues=", s_Molecule_ChangeNresidues, 1);
74987529 rb_define_method(rb_cMolecule, "max_residue_number", s_Molecule_MaxResSeq, -1);
@@ -7520,6 +7551,9 @@ Init_Molby(void)
75207551 rb_define_method(rb_cMolecule, "create_atom", s_Molecule_CreateAnAtom, -1);
75217552 rb_define_method(rb_cMolecule, "duplicate_atom", s_Molecule_DuplicateAnAtom, -1);
75227553 rb_define_method(rb_cMolecule, "create_bond", s_Molecule_CreateBond, -1);
7554+ rb_define_alias(rb_cMolecule, "create_bonds", "create_bond");
7555+ rb_define_method(rb_cMolecule, "remove_bond", s_Molecule_RemoveBond, -1);
7556+ rb_define_alias(rb_cMolecule, "remove_bonds", "remove_bond");
75237557 rb_define_method(rb_cMolecule, "add_angle", s_Molecule_AddAngle, 3);
75247558 rb_define_method(rb_cMolecule, "remove_angle", s_Molecule_RemoveAngle, 3);
75257559 rb_define_method(rb_cMolecule, "add_dihedral", s_Molecule_AddDihedral, 4);
旧リポジトリブラウザで表示