OSDN Git Service

Handling of parameters are being improved, but still not complete
authortoshinagata1964 <toshinagata1964@a2be9bc6-48de-4e38-9406-05402d4bc13c>
Mon, 7 May 2012 16:36:02 +0000 (16:36 +0000)
committertoshinagata1964 <toshinagata1964@a2be9bc6-48de-4e38-9406-05402d4bc13c>
Mon, 7 May 2012 16:36:02 +0000 (16:36 +0000)
git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/molby/trunk@197 a2be9bc6-48de-4e38-9406-05402d4bc13c

MolLib/MolAction.c
MolLib/Molecule.c
MolLib/Parameter.c
MolLib/Ruby_bind/ruby_bind.c

index 0fbb7a2..beb397d 100644 (file)
@@ -545,6 +545,7 @@ sMolActionUpdateSelectionAndParameterNumbering(Molecule *mol, const IntGroup *ig
        }
        
        /*  Update parameters  */
+       /*
        if (mol->par != NULL) {
                Int *ip = (Int *)malloc(sizeof(Int) * old_natoms);
                if (is_insert) {
@@ -561,14 +562,14 @@ sMolActionUpdateSelectionAndParameterNumbering(Molecule *mol, const IntGroup *ig
                        if (!is_insert)
                                ig3 = IntGroupNew();
                        for (j = 0; (up = ParameterGetUnionParFromTypeAndIndex(mol->par, i, j)) != NULL; j++) {
-                               ParameterCopyOneWithType(&usave, up, i);  /*  Don't say usave = *up  */
+                               ParameterCopyOneWithType(&usave, up, i);  //  Don't say usave = *up
                                if (ParameterRenumberAtoms(i, up, old_natoms, ip) && !is_insert) {
-                                       IntGroupAdd(ig3, j, 1);  /*  This parameter is to be restored on undo  */
+                                       IntGroupAdd(ig3, j, 1);  //  This parameter is to be restored on undo
                                        AssignArray(&upary, &count_upary, sizeof(UnionPar), count_upary, &usave);
                                }
                        }
                        if (count_upary > 0) {
-                               /*  Register undo for modifying parameters  */
+                               //  Register undo for modifying parameters
                                act = MolActionNew(gMolActionAddParameters, i, ig3, count_upary, upary);
                                MolActionCallback_registerUndo(mol, act);
                                MolActionRelease(act);
@@ -582,6 +583,8 @@ sMolActionUpdateSelectionAndParameterNumbering(Molecule *mol, const IntGroup *ig
                }
                free(ip);
        }
+        */
+       
        IntGroupRelease(orig_atoms);
 }
 
index cfdaa50..55c7996 100755 (executable)
@@ -6333,9 +6333,19 @@ MoleculeMerge(Molecule *dst, Molecule *src, IntGroup *where, int resSeqOffset)
                UnionPar *up1, *up2;
                int type;
                IntGroup *ig;
-               ig = IntGroupNew();
                if (dst->par == NULL)
                        dst->par = ParameterNew();
+               else {
+                       /*  Renumber existing parameters  */
+                       for (type = kFirstParType; type <= kLastParType; type++) {
+                               n1 = ParameterGetCountForType(dst->par, type);
+                               for (i = 0; i < n1; i++) {
+                                       up1 = ParameterGetUnionParFromTypeAndIndex(dst->par, type, i);
+                                       ParameterRenumberAtoms(type, up1, ndst, old2new);
+                               }
+                       }
+               }
+               ig = IntGroupNew();
                for (type = kFirstParType; type <= kLastParType; type++) {
                        n1 = ParameterGetCountForType(src->par, type);
                        n2 = ParameterGetCountForType(dst->par, type);
@@ -6687,10 +6697,10 @@ sMoleculeUnmergeSub(Molecule *src, Molecule **dstp, IntGroup *where, int resSeqO
        /*  Copy the parameters to dst */
        if (dst != NULL && dst_par_g != NULL && (n2 = IntGroupGetCount(dst_par_g)) > 0) {
                IntGroup *dst_new_g = IntGroupNew();
-               Int dst_par_count[kLastParType - kFirstParType];
+               Int dst_par_count[kLastParType - kFirstParType + 1];
                if (dst_new_g == NULL)
                        goto panic;
-               for (i = 0; i < kLastParType - kFirstParType; i++)
+               for (i = 0; i <= kLastParType - kFirstParType; i++)
                        dst_par_count[i] = 0;
                up = (UnionPar *)calloc(sizeof(UnionPar), n2);
                if (up == NULL)
@@ -6710,7 +6720,7 @@ sMoleculeUnmergeSub(Molecule *src, Molecule **dstp, IntGroup *where, int resSeqO
                        old2new[i] += nsrcnew;
                if (dst->par == NULL)
                        dst->par = ParameterNew();
-               for (i = 0; i < kLastParType - kFirstParType; i++) {
+               for (i = 0; i <= kLastParType - kFirstParType; i++) {
                        if (dst_par_count[i] > 0)
                                IntGroupAdd(dst_new_g, i * kParameterIndexOffset, dst_par_count[i]);
                }
@@ -6725,48 +6735,15 @@ sMoleculeUnmergeSub(Molecule *src, Molecule **dstp, IntGroup *where, int resSeqO
        if (remove_par_g != NULL && (n2 = IntGroupGetCount(remove_par_g)) > 0) {
                ParameterDelete(src->par, kFirstParType, NULL, remove_par_g);
        }
-               
-       /*
-               for (n1 = kFirstParType; n1 <= kLastParType; n1++) {
-                       n2 = ParameterGetCountForType(src->par, n1);
-                       if (n2 == 0)
-                               continue;
-                       //  Find parameters to be copied to dst
-                       for (i = 0; i < n2; i++) {
-                               up = ParameterGetUnionParFromTypeAndIndex(src->par, n1, i);
-                               for (j = 0, ap = dst->atoms; j < dst->natoms; j++, ap = ATOM_NEXT(ap)) {
-                                       if (ParameterDoesContainAtom(n1, up, new2old[j + nsrcnew], kParameterLookupNoWildcard) || ParameterDoesContainAtom(n1, up, ap->type, kParameterLookupNoWildcard)) {
-                                               IntGroupAdd(move_g, i, 1);
-                                               break;
-                                       }
-                               }
-                       }
-                       n2 = IntGroupGetCount(move_g);
-                       if (n2 == 0)
-                               continue;
-                       upary = (UnionPar *)calloc(sizeof(UnionPar), n2);
-                       if (upary == NULL)
-                               goto panic;
-                       //  Copy parameters and renumber indices if necessary
-                       for (i = 0; i < n2; i++) {
-                               up = ParameterGetUnionParFromTypeAndIndex(src->par, n1, IntGroupGetNthPoint(move_g, i));
-                               upary[i] = *up;
-                               ParameterRenumberAtoms(n1, upary + i, nsrc, old2new);
-                       }
-                       IntGroupClear(move_g);
-                       IntGroupAdd(move_g, ParameterGetCountForType(dst->par, n1), n2);
-                       //  Insert new parameters
-                       if (ParameterInsert(dst->par, n1, upary, move_g) < n2)
-                               goto panic;
-                       IntGroupClear(move_g);
-                       free(upary);
-               }
-               for (i = 0; i < nsrc; i++) {
-                       old2new[i] += nsrcnew;  //  Restore indices
+       
+       /*  Renumber the parameter records remaining in the src  */
+       for (n1 = kFirstParType; n1 <= kLastParType; n1++) {
+               n2 = ParameterGetCountForType(src->par, n1);
+               for (i = 0; i < n2; i++) {
+                       up = ParameterGetUnionParFromTypeAndIndex(src->par, n1, i);
+                       ParameterRenumberAtoms(n1, up, nsrc, old2new);
                }
-               IntGroupRelease(move_g);
-        }
-       */
+       }
        
        /*  Clean up  */
        MoleculeCleanUpResidueTable(src);
index 4d7d33e..f2eb302 100755 (executable)
@@ -389,8 +389,7 @@ sParameterDeleteOrCopy(Parameter *par, Int type, UnionPar *up, struct IntGroup *
                        if (up != NULL)
                                memmove(up + i, *p + size * n1, size);
                } else {
-                       if (DeleteArray(p, ip, size, n1, 1, (up ? up + i : NULL)) == NULL)
-                               return n2;
+                       DeleteArray(p, ip, size, n1, 1, (up ? up + i : NULL));
                }
                n2++;
        }
@@ -1348,7 +1347,7 @@ ParameterIsRelevantToAtomGroup(Int type, const UnionPar *up, const struct Atom *
                for (j = 0; j < n; j++) {
                        if (types[j] < kAtomTypeMinimum)
                                continue;
-                       if (types[j] == kAtomTypeWildcard || types[j] == api->type) {
+                       if (types[j] == kAtomTypeWildcard || types[j] == api->type || types[j] == api->type % kAtomTypeVariantBase) {
                                retval = 1;
                                break;
                        }
index 8b32470..f1dee12 100644 (file)
@@ -2775,13 +2775,45 @@ s_Parameter_Lookup_sub(int argc, VALUE *argv, int parType, Molecule *mol)
                if ((flags & 256) == 0 || mol == NULL || mol->par == NULL)
                        return Qnil;            
                else {
-                       /*  Insert a new (empty) parameter record  */
+                       /*  Insert a new parameter record  */
+                       UnionPar *up;
                        Int count = ParameterGetCountForType(mol->par, parType);
                        IntGroup *ig = IntGroupNewWithPoints(count, 1, -1);
                        MolActionCreateAndPerform(mol, gMolActionAddParameters, parType, ig, 0, NULL);
                        IntGroupRelease(ig);
                        is_global = 0;
                        idx = count;
+                       /*  Set atom types  */
+                       up = ParameterGetUnionParFromTypeAndIndex(mol->par, parType, idx);
+                       if (up == NULL)
+                               return Qnil;
+                       switch (parType) {
+                               case kBondParType:
+                                       up->bond.type1 = t[0];
+                                       up->bond.type2 = t[1];
+                                       break;
+                               case kAngleParType:
+                                       up->angle.type1 = t[0];
+                                       up->angle.type2 = t[1];
+                                       up->angle.type3 = t[2];
+                                       break;
+                               case kDihedralParType:
+                               case kImproperParType:
+                                       up->torsion.type1 = t[0];
+                                       up->torsion.type2 = t[1];
+                                       up->torsion.type3 = t[2];
+                                       up->torsion.type4 = t[3];
+                                       break;
+                               case kVdwParType:
+                                       up->vdw.type1 = t[0];
+                                       break;
+                               case kVdwPairParType:
+                                       up->vdwp.type1 = t[0];
+                                       up->vdwp.type2 = t[1];
+                                       break;
+                               default:
+                                       return Qnil;
+                       }
                }
        }
        return ValueFromMoleculeWithParameterTypeAndIndex(mol, parType, idx);