Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PeptFold2D.jl #27

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open

PeptFold2D.jl #27

wants to merge 19 commits into from

Conversation

vandeveldet
Copy link

No description provided.

@vandeveldet vandeveldet changed the title Code review 03/01/22 PeptFold2D.jl Jan 2, 2022
@MichielStock
Copy link
Owner

I think the project has a nice start but it can and should be greatly simplified. Remember, it is an exploratory exercise, not an attempt to generate a realistic protein folder!

I would just use a simple ball-and-stick model, where the AAs are at the joints and the distances between them are fixed and constant. So, your optimization only works on the angles between these. Furthermore, the user can give a list of charges (positive vs negative vs neutral) as a way of building your chain (I don't know by heart the charges of the amino acids anymore). I like the electrostatic and van der Waals forces, keep them, though you can abstract away the constants. So, I would allow a peptide to be defined from "0++-0-++" as a string with charged and neutral residues.

Your code is not very efficient, because the compiler cannot guess the type of your arrays in e.g. create_peptide, it will use Any as element type.

While mentally going through the code, I don't immediately see the best way of going from the angles to the loss in a way that is differentiable and generic. My (strong) recommendation is doing it by hand for an example of 5 point charges (or so). Otherwise, you might need to use metaprogramming. Here is how I would do it for three points:

function distances((a1, a2),l=1) # fixed length and two angles
    x0, y0 = 0.0, 0.0
    x1, y1 = x0 + l * cos(a1), y0 + l * sin(a1)
    x2, y2 = x1 + l * cos(a2), y1 + l * sin(a2)
    # compute energie based on the pairwise distances
end

It will be blazingly fast so.

@vandeveldet
Copy link
Author

Thanks for your feedback. I found an alternative for the differentiation of the loss function by using Zygote.Buffer() to allow mutation of the distance matrix.

function distances_θ::Vector{Float64};l=1)
	n=length(θ)
	x=Zygote.Buffer(zeros(n))
	y=Zygote.Buffer(zeros(n))
	distance=Zygote.Buffer(zeros(n,n))
        x[1],y[1]=0.0, 0.0
	n=length(θ)
	for i in 2:n
		x[i],y[i]=x[i-1] + l * cos(θ[i-1]),y[i-1] + l * sin(θ[i-1])
	end
	for i in 1:n
		for j in i+1:n
			distance[i,j]=sqrt((x[i]-x[j])^2+(y[i]-y[j])^2)
		end
	end
	return copy(distance)
end

@Jordiverbruggen
Copy link

Hey, nice project to follow! A very small remark, I would maybe recommend to display the coulomb law and Lennard-Jones in the text and explain the terms.(look photo). it is a small addition and improves the structure. For the rest very well done!!
Schermafbeelding 2022-01-31 om 09 51 20

@vandeveldet
Copy link
Author

Thanks @Jordiverbruggen, I've adapted the notebook accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants