}
/* Update parameters */
+ /*
if (mol->par != NULL) {
Int *ip = (Int *)malloc(sizeof(Int) * old_natoms);
if (is_insert) {
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);
}
free(ip);
}
+ */
+
IntGroupRelease(orig_atoms);
}
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);
/* 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)
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]);
}
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);
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);